10b57cec5SDimitry Andric //===-- ARMSubtarget.cpp - ARM Subtarget Information ----------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file implements the ARM specific subclass of TargetSubtargetInfo.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric
130b57cec5SDimitry Andric #include "ARM.h"
140b57cec5SDimitry Andric
150b57cec5SDimitry Andric #include "ARMCallLowering.h"
160b57cec5SDimitry Andric #include "ARMFrameLowering.h"
170b57cec5SDimitry Andric #include "ARMInstrInfo.h"
1806c3fb27SDimitry Andric #include "ARMLegalizerInfo.h"
1906c3fb27SDimitry Andric #include "ARMRegisterBankInfo.h"
200b57cec5SDimitry Andric #include "ARMSubtarget.h"
210b57cec5SDimitry Andric #include "ARMTargetMachine.h"
220b57cec5SDimitry Andric #include "MCTargetDesc/ARMMCTargetDesc.h"
230b57cec5SDimitry Andric #include "Thumb1FrameLowering.h"
240b57cec5SDimitry Andric #include "Thumb1InstrInfo.h"
250b57cec5SDimitry Andric #include "Thumb2InstrInfo.h"
260b57cec5SDimitry Andric #include "llvm/ADT/StringRef.h"
270b57cec5SDimitry Andric #include "llvm/ADT/Twine.h"
280b57cec5SDimitry Andric #include "llvm/CodeGen/GlobalISel/InstructionSelect.h"
2981ad6265SDimitry Andric #include "llvm/CodeGen/MachineFrameInfo.h"
300b57cec5SDimitry Andric #include "llvm/CodeGen/MachineFunction.h"
310b57cec5SDimitry Andric #include "llvm/IR/Function.h"
320b57cec5SDimitry Andric #include "llvm/IR/GlobalValue.h"
330b57cec5SDimitry Andric #include "llvm/MC/MCAsmInfo.h"
340b57cec5SDimitry Andric #include "llvm/MC/MCTargetOptions.h"
350b57cec5SDimitry Andric #include "llvm/Support/CodeGen.h"
360b57cec5SDimitry Andric #include "llvm/Support/CommandLine.h"
370b57cec5SDimitry Andric #include "llvm/Target/TargetOptions.h"
3806c3fb27SDimitry Andric #include "llvm/TargetParser/ARMTargetParser.h"
3906c3fb27SDimitry Andric #include "llvm/TargetParser/Triple.h"
400b57cec5SDimitry Andric
410b57cec5SDimitry Andric using namespace llvm;
420b57cec5SDimitry Andric
430b57cec5SDimitry Andric #define DEBUG_TYPE "arm-subtarget"
440b57cec5SDimitry Andric
450b57cec5SDimitry Andric #define GET_SUBTARGETINFO_TARGET_DESC
460b57cec5SDimitry Andric #define GET_SUBTARGETINFO_CTOR
470b57cec5SDimitry Andric #include "ARMGenSubtargetInfo.inc"
480b57cec5SDimitry Andric
490b57cec5SDimitry Andric static cl::opt<bool>
500b57cec5SDimitry Andric UseFusedMulOps("arm-use-mulops",
510b57cec5SDimitry Andric cl::init(true), cl::Hidden);
520b57cec5SDimitry Andric
530b57cec5SDimitry Andric enum ITMode {
540b57cec5SDimitry Andric DefaultIT,
5581ad6265SDimitry Andric RestrictedIT
560b57cec5SDimitry Andric };
570b57cec5SDimitry Andric
580b57cec5SDimitry Andric static cl::opt<ITMode>
590b57cec5SDimitry Andric IT(cl::desc("IT block support"), cl::Hidden, cl::init(DefaultIT),
600b57cec5SDimitry Andric cl::values(clEnumValN(DefaultIT, "arm-default-it",
6181ad6265SDimitry Andric "Generate any type of IT block"),
620b57cec5SDimitry Andric clEnumValN(RestrictedIT, "arm-restrict-it",
6381ad6265SDimitry Andric "Disallow complex IT blocks")));
640b57cec5SDimitry Andric
650b57cec5SDimitry Andric /// ForceFastISel - Use the fast-isel, even for subtargets where it is not
660b57cec5SDimitry Andric /// currently supported (for testing only).
670b57cec5SDimitry Andric static cl::opt<bool>
680b57cec5SDimitry Andric ForceFastISel("arm-force-fast-isel",
690b57cec5SDimitry Andric cl::init(false), cl::Hidden);
700b57cec5SDimitry Andric
710b57cec5SDimitry Andric /// initializeSubtargetDependencies - Initializes using a CPU and feature string
720b57cec5SDimitry Andric /// so that we can use initializer lists for subtarget initialization.
initializeSubtargetDependencies(StringRef CPU,StringRef FS)730b57cec5SDimitry Andric ARMSubtarget &ARMSubtarget::initializeSubtargetDependencies(StringRef CPU,
740b57cec5SDimitry Andric StringRef FS) {
750b57cec5SDimitry Andric initializeEnvironment();
760b57cec5SDimitry Andric initSubtargetFeatures(CPU, FS);
770b57cec5SDimitry Andric return *this;
780b57cec5SDimitry Andric }
790b57cec5SDimitry Andric
initializeFrameLowering(StringRef CPU,StringRef FS)800b57cec5SDimitry Andric ARMFrameLowering *ARMSubtarget::initializeFrameLowering(StringRef CPU,
810b57cec5SDimitry Andric StringRef FS) {
820b57cec5SDimitry Andric ARMSubtarget &STI = initializeSubtargetDependencies(CPU, FS);
830b57cec5SDimitry Andric if (STI.isThumb1Only())
840b57cec5SDimitry Andric return (ARMFrameLowering *)new Thumb1FrameLowering(STI);
850b57cec5SDimitry Andric
860b57cec5SDimitry Andric return new ARMFrameLowering(STI);
870b57cec5SDimitry Andric }
880b57cec5SDimitry Andric
ARMSubtarget(const Triple & TT,const std::string & CPU,const std::string & FS,const ARMBaseTargetMachine & TM,bool IsLittle,bool MinSize)890b57cec5SDimitry Andric ARMSubtarget::ARMSubtarget(const Triple &TT, const std::string &CPU,
900b57cec5SDimitry Andric const std::string &FS,
910b57cec5SDimitry Andric const ARMBaseTargetMachine &TM, bool IsLittle,
920b57cec5SDimitry Andric bool MinSize)
93e8d8bef9SDimitry Andric : ARMGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS),
94e8d8bef9SDimitry Andric UseMulOps(UseFusedMulOps), CPUString(CPU), OptMinSize(MinSize),
95e8d8bef9SDimitry Andric IsLittle(IsLittle), TargetTriple(TT), Options(TM.Options), TM(TM),
960b57cec5SDimitry Andric FrameLowering(initializeFrameLowering(CPU, FS)),
970b57cec5SDimitry Andric // At this point initializeSubtargetDependencies has been called so
980b57cec5SDimitry Andric // we can query directly.
990b57cec5SDimitry Andric InstrInfo(isThumb1Only()
1000b57cec5SDimitry Andric ? (ARMBaseInstrInfo *)new Thumb1InstrInfo(*this)
1010b57cec5SDimitry Andric : !isThumb()
1020b57cec5SDimitry Andric ? (ARMBaseInstrInfo *)new ARMInstrInfo(*this)
1030b57cec5SDimitry Andric : (ARMBaseInstrInfo *)new Thumb2InstrInfo(*this)),
1040b57cec5SDimitry Andric TLInfo(TM, *this) {
1050b57cec5SDimitry Andric
1060b57cec5SDimitry Andric CallLoweringInfo.reset(new ARMCallLowering(*getTargetLowering()));
1070b57cec5SDimitry Andric Legalizer.reset(new ARMLegalizerInfo(*this));
1080b57cec5SDimitry Andric
1090b57cec5SDimitry Andric auto *RBI = new ARMRegisterBankInfo(*getRegisterInfo());
1100b57cec5SDimitry Andric
1110b57cec5SDimitry Andric // FIXME: At this point, we can't rely on Subtarget having RBI.
1120b57cec5SDimitry Andric // It's awkward to mix passing RBI and the Subtarget; should we pass
1130b57cec5SDimitry Andric // TII/TRI as well?
114*0fca6ea1SDimitry Andric InstSelector.reset(createARMInstructionSelector(TM, *this, *RBI));
1150b57cec5SDimitry Andric
1160b57cec5SDimitry Andric RegBankInfo.reset(RBI);
1170b57cec5SDimitry Andric }
1180b57cec5SDimitry Andric
getCallLowering() const1190b57cec5SDimitry Andric const CallLowering *ARMSubtarget::getCallLowering() const {
1200b57cec5SDimitry Andric return CallLoweringInfo.get();
1210b57cec5SDimitry Andric }
1220b57cec5SDimitry Andric
getInstructionSelector() const1238bcb0991SDimitry Andric InstructionSelector *ARMSubtarget::getInstructionSelector() const {
1240b57cec5SDimitry Andric return InstSelector.get();
1250b57cec5SDimitry Andric }
1260b57cec5SDimitry Andric
getLegalizerInfo() const1270b57cec5SDimitry Andric const LegalizerInfo *ARMSubtarget::getLegalizerInfo() const {
1280b57cec5SDimitry Andric return Legalizer.get();
1290b57cec5SDimitry Andric }
1300b57cec5SDimitry Andric
getRegBankInfo() const1310b57cec5SDimitry Andric const RegisterBankInfo *ARMSubtarget::getRegBankInfo() const {
1320b57cec5SDimitry Andric return RegBankInfo.get();
1330b57cec5SDimitry Andric }
1340b57cec5SDimitry Andric
isXRaySupported() const1350b57cec5SDimitry Andric bool ARMSubtarget::isXRaySupported() const {
1360b57cec5SDimitry Andric // We don't currently suppport Thumb, but Windows requires Thumb.
1370b57cec5SDimitry Andric return hasV6Ops() && hasARMOps() && !isTargetWindows();
1380b57cec5SDimitry Andric }
1390b57cec5SDimitry Andric
initializeEnvironment()1400b57cec5SDimitry Andric void ARMSubtarget::initializeEnvironment() {
1410b57cec5SDimitry Andric // MCAsmInfo isn't always present (e.g. in opt) so we can't initialize this
1420b57cec5SDimitry Andric // directly from it, but we can try to make sure they're consistent when both
1430b57cec5SDimitry Andric // available.
1440b57cec5SDimitry Andric UseSjLjEH = (isTargetDarwin() && !isTargetWatchABI() &&
1450b57cec5SDimitry Andric Options.ExceptionModel == ExceptionHandling::None) ||
1460b57cec5SDimitry Andric Options.ExceptionModel == ExceptionHandling::SjLj;
1470b57cec5SDimitry Andric assert((!TM.getMCAsmInfo() ||
1480b57cec5SDimitry Andric (TM.getMCAsmInfo()->getExceptionHandlingType() ==
1490b57cec5SDimitry Andric ExceptionHandling::SjLj) == UseSjLjEH) &&
1500b57cec5SDimitry Andric "inconsistent sjlj choice between CodeGen and MC");
1510b57cec5SDimitry Andric }
1520b57cec5SDimitry Andric
initSubtargetFeatures(StringRef CPU,StringRef FS)1530b57cec5SDimitry Andric void ARMSubtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) {
1540b57cec5SDimitry Andric if (CPUString.empty()) {
1550b57cec5SDimitry Andric CPUString = "generic";
1560b57cec5SDimitry Andric
1570b57cec5SDimitry Andric if (isTargetDarwin()) {
1580b57cec5SDimitry Andric StringRef ArchName = TargetTriple.getArchName();
1590b57cec5SDimitry Andric ARM::ArchKind AK = ARM::parseArch(ArchName);
1600b57cec5SDimitry Andric if (AK == ARM::ArchKind::ARMV7S)
1610b57cec5SDimitry Andric // Default to the Swift CPU when targeting armv7s/thumbv7s.
1620b57cec5SDimitry Andric CPUString = "swift";
1630b57cec5SDimitry Andric else if (AK == ARM::ArchKind::ARMV7K)
1640b57cec5SDimitry Andric // Default to the Cortex-a7 CPU when targeting armv7k/thumbv7k.
1650b57cec5SDimitry Andric // ARMv7k does not use SjLj exception handling.
1660b57cec5SDimitry Andric CPUString = "cortex-a7";
1670b57cec5SDimitry Andric }
1680b57cec5SDimitry Andric }
1690b57cec5SDimitry Andric
1700b57cec5SDimitry Andric // Insert the architecture feature derived from the target triple into the
1710b57cec5SDimitry Andric // feature string. This is important for setting features that are implied
1720b57cec5SDimitry Andric // based on the architecture version.
1730b57cec5SDimitry Andric std::string ArchFS = ARM_MC::ParseARMTriple(TargetTriple, CPUString);
1740b57cec5SDimitry Andric if (!FS.empty()) {
1750b57cec5SDimitry Andric if (!ArchFS.empty())
1760b57cec5SDimitry Andric ArchFS = (Twine(ArchFS) + "," + FS).str();
1770b57cec5SDimitry Andric else
1785ffd83dbSDimitry Andric ArchFS = std::string(FS);
1790b57cec5SDimitry Andric }
180e8d8bef9SDimitry Andric ParseSubtargetFeatures(CPUString, /*TuneCPU*/ CPUString, ArchFS);
1810b57cec5SDimitry Andric
1820b57cec5SDimitry Andric // FIXME: This used enable V6T2 support implicitly for Thumb2 mode.
1830b57cec5SDimitry Andric // Assert this for now to make the change obvious.
1840b57cec5SDimitry Andric assert(hasV6T2Ops() || !hasThumb2());
1850b57cec5SDimitry Andric
1860b57cec5SDimitry Andric if (genExecuteOnly()) {
18706c3fb27SDimitry Andric // Execute only support for >= v8-M Baseline requires movt support
18806c3fb27SDimitry Andric if (hasV8MBaselineOps())
1890b57cec5SDimitry Andric NoMovt = false;
19006c3fb27SDimitry Andric if (!hasV6MOps())
19106c3fb27SDimitry Andric report_fatal_error("Cannot generate execute-only code for this target");
1920b57cec5SDimitry Andric }
1930b57cec5SDimitry Andric
1940b57cec5SDimitry Andric // Keep a pointer to static instruction cost data for the specified CPU.
1950b57cec5SDimitry Andric SchedModel = getSchedModelForCPU(CPUString);
1960b57cec5SDimitry Andric
1970b57cec5SDimitry Andric // Initialize scheduling itinerary for the specified CPU.
1980b57cec5SDimitry Andric InstrItins = getInstrItineraryForCPU(CPUString);
1990b57cec5SDimitry Andric
2000b57cec5SDimitry Andric // FIXME: this is invalid for WindowsCE
2010b57cec5SDimitry Andric if (isTargetWindows())
2020b57cec5SDimitry Andric NoARM = true;
2030b57cec5SDimitry Andric
2040b57cec5SDimitry Andric if (isAAPCS_ABI())
2058bcb0991SDimitry Andric stackAlignment = Align(8);
2060b57cec5SDimitry Andric if (isTargetNaCl() || isAAPCS16_ABI())
2078bcb0991SDimitry Andric stackAlignment = Align(16);
2080b57cec5SDimitry Andric
2090b57cec5SDimitry Andric // FIXME: Completely disable sibcall for Thumb1 since ThumbRegisterInfo::
2100b57cec5SDimitry Andric // emitEpilogue is not ready for them. Thumb tail calls also use t2B, as
2110b57cec5SDimitry Andric // the Thumb1 16-bit unconditional branch doesn't have sufficient relocation
2120b57cec5SDimitry Andric // support in the assembler and linker to be used. This would need to be
2130b57cec5SDimitry Andric // fixed to fully support tail calls in Thumb1.
2140b57cec5SDimitry Andric //
2150b57cec5SDimitry Andric // For ARMv8-M, we /do/ implement tail calls. Doing this is tricky for v8-M
2160b57cec5SDimitry Andric // baseline, since the LDM/POP instruction on Thumb doesn't take LR. This
2170b57cec5SDimitry Andric // means if we need to reload LR, it takes extra instructions, which outweighs
2180b57cec5SDimitry Andric // the value of the tail call; but here we don't know yet whether LR is going
2190b57cec5SDimitry Andric // to be used. We take the optimistic approach of generating the tail call and
2200b57cec5SDimitry Andric // perhaps taking a hit if we need to restore the LR.
2210b57cec5SDimitry Andric
2220b57cec5SDimitry Andric // Thumb1 PIC calls to external symbols use BX, so they can be tail calls,
2230b57cec5SDimitry Andric // but we need to make sure there are enough registers; the only valid
2240b57cec5SDimitry Andric // registers are the 4 used for parameters. We don't currently do this
2250b57cec5SDimitry Andric // case.
2260b57cec5SDimitry Andric
227fe6060f1SDimitry Andric SupportsTailCall = !isThumb1Only() || hasV8MBaselineOps();
2280b57cec5SDimitry Andric
2290b57cec5SDimitry Andric if (isTargetMachO() && isTargetIOS() && getTargetTriple().isOSVersionLT(5, 0))
2300b57cec5SDimitry Andric SupportsTailCall = false;
2310b57cec5SDimitry Andric
2320b57cec5SDimitry Andric switch (IT) {
2330b57cec5SDimitry Andric case DefaultIT:
23481ad6265SDimitry Andric RestrictIT = false;
2350b57cec5SDimitry Andric break;
2360b57cec5SDimitry Andric case RestrictedIT:
2370b57cec5SDimitry Andric RestrictIT = true;
2380b57cec5SDimitry Andric break;
2390b57cec5SDimitry Andric }
2400b57cec5SDimitry Andric
2410b57cec5SDimitry Andric // NEON f32 ops are non-IEEE 754 compliant. Darwin is ok with it by default.
2420b57cec5SDimitry Andric const FeatureBitset &Bits = getFeatureBits();
2430b57cec5SDimitry Andric if ((Bits[ARM::ProcA5] || Bits[ARM::ProcA8]) && // Where this matters
2440b57cec5SDimitry Andric (Options.UnsafeFPMath || isTargetDarwin()))
24581ad6265SDimitry Andric HasNEONForFP = true;
2460b57cec5SDimitry Andric
2470b57cec5SDimitry Andric if (isRWPI())
2480b57cec5SDimitry Andric ReserveR9 = true;
2490b57cec5SDimitry Andric
2508bcb0991SDimitry Andric // If MVEVectorCostFactor is still 0 (has not been set to anything else), default it to 2
2518bcb0991SDimitry Andric if (MVEVectorCostFactor == 0)
2528bcb0991SDimitry Andric MVEVectorCostFactor = 2;
2538bcb0991SDimitry Andric
2540b57cec5SDimitry Andric // FIXME: Teach TableGen to deal with these instead of doing it manually here.
2550b57cec5SDimitry Andric switch (ARMProcFamily) {
2560b57cec5SDimitry Andric case Others:
2570b57cec5SDimitry Andric case CortexA5:
2580b57cec5SDimitry Andric break;
2590b57cec5SDimitry Andric case CortexA7:
2600b57cec5SDimitry Andric LdStMultipleTiming = DoubleIssue;
2610b57cec5SDimitry Andric break;
2620b57cec5SDimitry Andric case CortexA8:
2630b57cec5SDimitry Andric LdStMultipleTiming = DoubleIssue;
2640b57cec5SDimitry Andric break;
2650b57cec5SDimitry Andric case CortexA9:
2660b57cec5SDimitry Andric LdStMultipleTiming = DoubleIssueCheckUnalignedAccess;
2670b57cec5SDimitry Andric PreISelOperandLatencyAdjustment = 1;
2680b57cec5SDimitry Andric break;
2690b57cec5SDimitry Andric case CortexA12:
2700b57cec5SDimitry Andric break;
2710b57cec5SDimitry Andric case CortexA15:
2720b57cec5SDimitry Andric MaxInterleaveFactor = 2;
2730b57cec5SDimitry Andric PreISelOperandLatencyAdjustment = 1;
2740b57cec5SDimitry Andric PartialUpdateClearance = 12;
2750b57cec5SDimitry Andric break;
2760b57cec5SDimitry Andric case CortexA17:
2770b57cec5SDimitry Andric case CortexA32:
2780b57cec5SDimitry Andric case CortexA35:
2790b57cec5SDimitry Andric case CortexA53:
2800b57cec5SDimitry Andric case CortexA55:
2810b57cec5SDimitry Andric case CortexA57:
2820b57cec5SDimitry Andric case CortexA72:
2830b57cec5SDimitry Andric case CortexA73:
2840b57cec5SDimitry Andric case CortexA75:
2850b57cec5SDimitry Andric case CortexA76:
2865ffd83dbSDimitry Andric case CortexA77:
2875ffd83dbSDimitry Andric case CortexA78:
288*0fca6ea1SDimitry Andric case CortexA78AE:
289e8d8bef9SDimitry Andric case CortexA78C:
290349cc55cSDimitry Andric case CortexA710:
2910b57cec5SDimitry Andric case CortexR4:
2920b57cec5SDimitry Andric case CortexR5:
2930b57cec5SDimitry Andric case CortexR7:
2940b57cec5SDimitry Andric case CortexM3:
295e8d8bef9SDimitry Andric case CortexM7:
2960b57cec5SDimitry Andric case CortexR52:
297*0fca6ea1SDimitry Andric case CortexR52plus:
2985ffd83dbSDimitry Andric case CortexX1:
2991fd87a68SDimitry Andric case CortexX1C:
3000b57cec5SDimitry Andric break;
3010b57cec5SDimitry Andric case Exynos:
3020b57cec5SDimitry Andric LdStMultipleTiming = SingleIssuePlusExtras;
3030b57cec5SDimitry Andric MaxInterleaveFactor = 4;
3040b57cec5SDimitry Andric if (!isThumb())
3058bcb0991SDimitry Andric PrefLoopLogAlignment = 3;
3060b57cec5SDimitry Andric break;
3070b57cec5SDimitry Andric case Kryo:
3080b57cec5SDimitry Andric break;
3090b57cec5SDimitry Andric case Krait:
3100b57cec5SDimitry Andric PreISelOperandLatencyAdjustment = 1;
3110b57cec5SDimitry Andric break;
312e8d8bef9SDimitry Andric case NeoverseV1:
3138bcb0991SDimitry Andric break;
3140b57cec5SDimitry Andric case Swift:
3150b57cec5SDimitry Andric MaxInterleaveFactor = 2;
3160b57cec5SDimitry Andric LdStMultipleTiming = SingleIssuePlusExtras;
3170b57cec5SDimitry Andric PreISelOperandLatencyAdjustment = 1;
3180b57cec5SDimitry Andric PartialUpdateClearance = 12;
3190b57cec5SDimitry Andric break;
3200b57cec5SDimitry Andric }
3210b57cec5SDimitry Andric }
3220b57cec5SDimitry Andric
isTargetHardFloat() const3230b57cec5SDimitry Andric bool ARMSubtarget::isTargetHardFloat() const { return TM.isTargetHardFloat(); }
3240b57cec5SDimitry Andric
isAPCS_ABI() const3250b57cec5SDimitry Andric bool ARMSubtarget::isAPCS_ABI() const {
3260b57cec5SDimitry Andric assert(TM.TargetABI != ARMBaseTargetMachine::ARM_ABI_UNKNOWN);
3270b57cec5SDimitry Andric return TM.TargetABI == ARMBaseTargetMachine::ARM_ABI_APCS;
3280b57cec5SDimitry Andric }
isAAPCS_ABI() const3290b57cec5SDimitry Andric bool ARMSubtarget::isAAPCS_ABI() const {
3300b57cec5SDimitry Andric assert(TM.TargetABI != ARMBaseTargetMachine::ARM_ABI_UNKNOWN);
3310b57cec5SDimitry Andric return TM.TargetABI == ARMBaseTargetMachine::ARM_ABI_AAPCS ||
3320b57cec5SDimitry Andric TM.TargetABI == ARMBaseTargetMachine::ARM_ABI_AAPCS16;
3330b57cec5SDimitry Andric }
isAAPCS16_ABI() const3340b57cec5SDimitry Andric bool ARMSubtarget::isAAPCS16_ABI() const {
3350b57cec5SDimitry Andric assert(TM.TargetABI != ARMBaseTargetMachine::ARM_ABI_UNKNOWN);
3360b57cec5SDimitry Andric return TM.TargetABI == ARMBaseTargetMachine::ARM_ABI_AAPCS16;
3370b57cec5SDimitry Andric }
3380b57cec5SDimitry Andric
isROPI() const3390b57cec5SDimitry Andric bool ARMSubtarget::isROPI() const {
3400b57cec5SDimitry Andric return TM.getRelocationModel() == Reloc::ROPI ||
3410b57cec5SDimitry Andric TM.getRelocationModel() == Reloc::ROPI_RWPI;
3420b57cec5SDimitry Andric }
isRWPI() const3430b57cec5SDimitry Andric bool ARMSubtarget::isRWPI() const {
3440b57cec5SDimitry Andric return TM.getRelocationModel() == Reloc::RWPI ||
3450b57cec5SDimitry Andric TM.getRelocationModel() == Reloc::ROPI_RWPI;
3460b57cec5SDimitry Andric }
3470b57cec5SDimitry Andric
isGVIndirectSymbol(const GlobalValue * GV) const3480b57cec5SDimitry Andric bool ARMSubtarget::isGVIndirectSymbol(const GlobalValue *GV) const {
349*0fca6ea1SDimitry Andric if (!TM.shouldAssumeDSOLocal(GV))
3500b57cec5SDimitry Andric return true;
3510b57cec5SDimitry Andric
3520b57cec5SDimitry Andric // 32 bit macho has no relocation for a-b if a is undefined, even if b is in
3530b57cec5SDimitry Andric // the section that is being relocated. This means we have to use o load even
3540b57cec5SDimitry Andric // for GVs that are known to be local to the dso.
3550b57cec5SDimitry Andric if (isTargetMachO() && TM.isPositionIndependent() &&
3560b57cec5SDimitry Andric (GV->isDeclarationForLinker() || GV->hasCommonLinkage()))
3570b57cec5SDimitry Andric return true;
3580b57cec5SDimitry Andric
3590b57cec5SDimitry Andric return false;
3600b57cec5SDimitry Andric }
3610b57cec5SDimitry Andric
isGVInGOT(const GlobalValue * GV) const3620b57cec5SDimitry Andric bool ARMSubtarget::isGVInGOT(const GlobalValue *GV) const {
363*0fca6ea1SDimitry Andric return isTargetELF() && TM.isPositionIndependent() && !GV->isDSOLocal();
3640b57cec5SDimitry Andric }
3650b57cec5SDimitry Andric
getMispredictionPenalty() const3660b57cec5SDimitry Andric unsigned ARMSubtarget::getMispredictionPenalty() const {
3670b57cec5SDimitry Andric return SchedModel.MispredictPenalty;
3680b57cec5SDimitry Andric }
3690b57cec5SDimitry Andric
enableMachineScheduler() const3700b57cec5SDimitry Andric bool ARMSubtarget::enableMachineScheduler() const {
3710b57cec5SDimitry Andric // The MachineScheduler can increase register usage, so we use more high
3720b57cec5SDimitry Andric // registers and end up with more T2 instructions that cannot be converted to
3730b57cec5SDimitry Andric // T1 instructions. At least until we do better at converting to thumb1
3740b57cec5SDimitry Andric // instructions, on cortex-m at Oz where we are size-paranoid, don't use the
3750b57cec5SDimitry Andric // Machine scheduler, relying on the DAG register pressure scheduler instead.
3760b57cec5SDimitry Andric if (isMClass() && hasMinSize())
3770b57cec5SDimitry Andric return false;
3780b57cec5SDimitry Andric // Enable the MachineScheduler before register allocation for subtargets
3790b57cec5SDimitry Andric // with the use-misched feature.
3800b57cec5SDimitry Andric return useMachineScheduler();
3810b57cec5SDimitry Andric }
3820b57cec5SDimitry Andric
enableSubRegLiveness() const383349cc55cSDimitry Andric bool ARMSubtarget::enableSubRegLiveness() const {
384349cc55cSDimitry Andric // Enable SubRegLiveness for MVE to better optimize s subregs for mqpr regs
385349cc55cSDimitry Andric // and q subregs for qqqqpr regs.
386349cc55cSDimitry Andric return hasMVEIntegerOps();
387349cc55cSDimitry Andric }
388480093f4SDimitry Andric
enableMachinePipeliner() const38981ad6265SDimitry Andric bool ARMSubtarget::enableMachinePipeliner() const {
39081ad6265SDimitry Andric // Enable the MachinePipeliner before register allocation for subtargets
39181ad6265SDimitry Andric // with the use-mipipeliner feature.
39281ad6265SDimitry Andric return getSchedModel().hasInstrSchedModel() && useMachinePipeliner();
39381ad6265SDimitry Andric }
39481ad6265SDimitry Andric
useDFAforSMS() const39581ad6265SDimitry Andric bool ARMSubtarget::useDFAforSMS() const { return false; }
39681ad6265SDimitry Andric
3970b57cec5SDimitry Andric // This overrides the PostRAScheduler bit in the SchedModel for any CPU.
enablePostRAScheduler() const3980b57cec5SDimitry Andric bool ARMSubtarget::enablePostRAScheduler() const {
399480093f4SDimitry Andric if (enableMachineScheduler())
400480093f4SDimitry Andric return false;
4010b57cec5SDimitry Andric if (disablePostRAScheduler())
4020b57cec5SDimitry Andric return false;
403480093f4SDimitry Andric // Thumb1 cores will generally not benefit from post-ra scheduling
404480093f4SDimitry Andric return !isThumb1Only();
405480093f4SDimitry Andric }
406480093f4SDimitry Andric
enablePostRAMachineScheduler() const407480093f4SDimitry Andric bool ARMSubtarget::enablePostRAMachineScheduler() const {
408480093f4SDimitry Andric if (!enableMachineScheduler())
409480093f4SDimitry Andric return false;
410480093f4SDimitry Andric if (disablePostRAScheduler())
411480093f4SDimitry Andric return false;
4120b57cec5SDimitry Andric return !isThumb1Only();
4130b57cec5SDimitry Andric }
4140b57cec5SDimitry Andric
useStride4VFPs() const4150b57cec5SDimitry Andric bool ARMSubtarget::useStride4VFPs() const {
4160b57cec5SDimitry Andric // For general targets, the prologue can grow when VFPs are allocated with
4170b57cec5SDimitry Andric // stride 4 (more vpush instructions). But WatchOS uses a compact unwind
4180b57cec5SDimitry Andric // format which it's more important to get right.
4190b57cec5SDimitry Andric return isTargetWatchABI() ||
4200b57cec5SDimitry Andric (useWideStrideVFP() && !OptMinSize);
4210b57cec5SDimitry Andric }
4220b57cec5SDimitry Andric
useMovt() const4230b57cec5SDimitry Andric bool ARMSubtarget::useMovt() const {
4240b57cec5SDimitry Andric // NOTE Windows on ARM needs to use mov.w/mov.t pairs to materialise 32-bit
4250b57cec5SDimitry Andric // immediates as it is inherently position independent, and may be out of
4260b57cec5SDimitry Andric // range otherwise.
4270b57cec5SDimitry Andric return !NoMovt && hasV8MBaselineOps() &&
4280b57cec5SDimitry Andric (isTargetWindows() || !OptMinSize || genExecuteOnly());
4290b57cec5SDimitry Andric }
4300b57cec5SDimitry Andric
useFastISel() const4310b57cec5SDimitry Andric bool ARMSubtarget::useFastISel() const {
4320b57cec5SDimitry Andric // Enable fast-isel for any target, for testing only.
4330b57cec5SDimitry Andric if (ForceFastISel)
4340b57cec5SDimitry Andric return true;
4350b57cec5SDimitry Andric
4360b57cec5SDimitry Andric // Limit fast-isel to the targets that are or have been tested.
4370b57cec5SDimitry Andric if (!hasV6Ops())
4380b57cec5SDimitry Andric return false;
4390b57cec5SDimitry Andric
4400b57cec5SDimitry Andric // Thumb2 support on iOS; ARM support on iOS, Linux and NaCl.
4410b57cec5SDimitry Andric return TM.Options.EnableFastISel &&
4420b57cec5SDimitry Andric ((isTargetMachO() && !isThumb1Only()) ||
4430b57cec5SDimitry Andric (isTargetLinux() && !isThumb()) || (isTargetNaCl() && !isThumb()));
4440b57cec5SDimitry Andric }
4450b57cec5SDimitry Andric
getGPRAllocationOrder(const MachineFunction & MF) const4460b57cec5SDimitry Andric unsigned ARMSubtarget::getGPRAllocationOrder(const MachineFunction &MF) const {
4470b57cec5SDimitry Andric // The GPR register class has multiple possible allocation orders, with
4480b57cec5SDimitry Andric // tradeoffs preferred by different sub-architectures and optimisation goals.
4490b57cec5SDimitry Andric // The allocation orders are:
4500b57cec5SDimitry Andric // 0: (the default tablegen order, not used)
4510b57cec5SDimitry Andric // 1: r14, r0-r13
4520b57cec5SDimitry Andric // 2: r0-r7
4530b57cec5SDimitry Andric // 3: r0-r7, r12, lr, r8-r11
4540b57cec5SDimitry Andric // Note that the register allocator will change this order so that
4550b57cec5SDimitry Andric // callee-saved registers are used later, as they require extra work in the
4560b57cec5SDimitry Andric // prologue/epilogue (though we sometimes override that).
4570b57cec5SDimitry Andric
4580b57cec5SDimitry Andric // For thumb1-only targets, only the low registers are allocatable.
4590b57cec5SDimitry Andric if (isThumb1Only())
4600b57cec5SDimitry Andric return 2;
4610b57cec5SDimitry Andric
4620b57cec5SDimitry Andric // Allocate low registers first, so we can select more 16-bit instructions.
4630b57cec5SDimitry Andric // We also (in ignoreCSRForAllocationOrder) override the default behaviour
4640b57cec5SDimitry Andric // with regards to callee-saved registers, because pushing extra registers is
4650b57cec5SDimitry Andric // much cheaper (in terms of code size) than using high registers. After
4660b57cec5SDimitry Andric // that, we allocate r12 (doesn't need to be saved), lr (saving it means we
4670b57cec5SDimitry Andric // can return with the pop, don't need an extra "bx lr") and then the rest of
4680b57cec5SDimitry Andric // the high registers.
4690b57cec5SDimitry Andric if (isThumb2() && MF.getFunction().hasMinSize())
4700b57cec5SDimitry Andric return 3;
4710b57cec5SDimitry Andric
4720b57cec5SDimitry Andric // Otherwise, allocate in the default order, using LR first because saving it
4730b57cec5SDimitry Andric // allows a shorter epilogue sequence.
4740b57cec5SDimitry Andric return 1;
4750b57cec5SDimitry Andric }
4760b57cec5SDimitry Andric
ignoreCSRForAllocationOrder(const MachineFunction & MF,unsigned PhysReg) const4770b57cec5SDimitry Andric bool ARMSubtarget::ignoreCSRForAllocationOrder(const MachineFunction &MF,
4780b57cec5SDimitry Andric unsigned PhysReg) const {
4790b57cec5SDimitry Andric // To minimize code size in Thumb2, we prefer the usage of low regs (lower
4800b57cec5SDimitry Andric // cost per use) so we can use narrow encoding. By default, caller-saved
4810b57cec5SDimitry Andric // registers (e.g. lr, r12) are always allocated first, regardless of
4820b57cec5SDimitry Andric // their cost per use. When optForMinSize, we prefer the low regs even if
4830b57cec5SDimitry Andric // they are CSR because usually push/pop can be folded into existing ones.
4840b57cec5SDimitry Andric return isThumb2() && MF.getFunction().hasMinSize() &&
4850b57cec5SDimitry Andric ARM::GPRRegClass.contains(PhysReg);
4860b57cec5SDimitry Andric }
48781ad6265SDimitry Andric
splitFramePointerPush(const MachineFunction & MF) const48881ad6265SDimitry Andric bool ARMSubtarget::splitFramePointerPush(const MachineFunction &MF) const {
48981ad6265SDimitry Andric const Function &F = MF.getFunction();
49081ad6265SDimitry Andric if (!MF.getTarget().getMCAsmInfo()->usesWindowsCFI() ||
49181ad6265SDimitry Andric !F.needsUnwindTableEntry())
49281ad6265SDimitry Andric return false;
49381ad6265SDimitry Andric const MachineFrameInfo &MFI = MF.getFrameInfo();
49481ad6265SDimitry Andric return MFI.hasVarSizedObjects() || getRegisterInfo()->hasStackRealignment(MF);
49581ad6265SDimitry Andric }
496