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 "ARMLegalizerInfo.h" 170b57cec5SDimitry Andric #include "ARMRegisterBankInfo.h" 180b57cec5SDimitry Andric #include "ARMSubtarget.h" 190b57cec5SDimitry Andric #include "ARMFrameLowering.h" 200b57cec5SDimitry Andric #include "ARMInstrInfo.h" 210b57cec5SDimitry Andric #include "ARMSubtarget.h" 220b57cec5SDimitry Andric #include "ARMTargetMachine.h" 230b57cec5SDimitry Andric #include "MCTargetDesc/ARMMCTargetDesc.h" 240b57cec5SDimitry Andric #include "Thumb1FrameLowering.h" 250b57cec5SDimitry Andric #include "Thumb1InstrInfo.h" 260b57cec5SDimitry Andric #include "Thumb2InstrInfo.h" 270b57cec5SDimitry Andric #include "llvm/ADT/StringRef.h" 280b57cec5SDimitry Andric #include "llvm/ADT/Triple.h" 290b57cec5SDimitry Andric #include "llvm/ADT/Twine.h" 300b57cec5SDimitry Andric #include "llvm/CodeGen/GlobalISel/InstructionSelect.h" 310b57cec5SDimitry Andric #include "llvm/CodeGen/MachineFunction.h" 320b57cec5SDimitry Andric #include "llvm/IR/Function.h" 330b57cec5SDimitry Andric #include "llvm/IR/GlobalValue.h" 340b57cec5SDimitry Andric #include "llvm/MC/MCAsmInfo.h" 350b57cec5SDimitry Andric #include "llvm/MC/MCTargetOptions.h" 360b57cec5SDimitry Andric #include "llvm/Support/CodeGen.h" 370b57cec5SDimitry Andric #include "llvm/Support/CommandLine.h" 380b57cec5SDimitry Andric #include "llvm/Support/TargetParser.h" 390b57cec5SDimitry Andric #include "llvm/Target/TargetOptions.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, 550b57cec5SDimitry Andric RestrictedIT, 560b57cec5SDimitry Andric NoRestrictedIT 570b57cec5SDimitry Andric }; 580b57cec5SDimitry Andric 590b57cec5SDimitry Andric static cl::opt<ITMode> 600b57cec5SDimitry Andric IT(cl::desc("IT block support"), cl::Hidden, cl::init(DefaultIT), 610b57cec5SDimitry Andric cl::ZeroOrMore, 620b57cec5SDimitry Andric cl::values(clEnumValN(DefaultIT, "arm-default-it", 630b57cec5SDimitry Andric "Generate IT block based on arch"), 640b57cec5SDimitry Andric clEnumValN(RestrictedIT, "arm-restrict-it", 650b57cec5SDimitry Andric "Disallow deprecated IT based on ARMv8"), 660b57cec5SDimitry Andric clEnumValN(NoRestrictedIT, "arm-no-restrict-it", 670b57cec5SDimitry Andric "Allow IT blocks based on ARMv7"))); 680b57cec5SDimitry Andric 690b57cec5SDimitry Andric /// ForceFastISel - Use the fast-isel, even for subtargets where it is not 700b57cec5SDimitry Andric /// currently supported (for testing only). 710b57cec5SDimitry Andric static cl::opt<bool> 720b57cec5SDimitry Andric ForceFastISel("arm-force-fast-isel", 730b57cec5SDimitry Andric cl::init(false), cl::Hidden); 740b57cec5SDimitry Andric 750b57cec5SDimitry Andric /// initializeSubtargetDependencies - Initializes using a CPU and feature string 760b57cec5SDimitry Andric /// so that we can use initializer lists for subtarget initialization. 770b57cec5SDimitry Andric ARMSubtarget &ARMSubtarget::initializeSubtargetDependencies(StringRef CPU, 780b57cec5SDimitry Andric StringRef FS) { 790b57cec5SDimitry Andric initializeEnvironment(); 800b57cec5SDimitry Andric initSubtargetFeatures(CPU, FS); 810b57cec5SDimitry Andric return *this; 820b57cec5SDimitry Andric } 830b57cec5SDimitry Andric 840b57cec5SDimitry Andric ARMFrameLowering *ARMSubtarget::initializeFrameLowering(StringRef CPU, 850b57cec5SDimitry Andric StringRef FS) { 860b57cec5SDimitry Andric ARMSubtarget &STI = initializeSubtargetDependencies(CPU, FS); 870b57cec5SDimitry Andric if (STI.isThumb1Only()) 880b57cec5SDimitry Andric return (ARMFrameLowering *)new Thumb1FrameLowering(STI); 890b57cec5SDimitry Andric 900b57cec5SDimitry Andric return new ARMFrameLowering(STI); 910b57cec5SDimitry Andric } 920b57cec5SDimitry Andric 930b57cec5SDimitry Andric ARMSubtarget::ARMSubtarget(const Triple &TT, const std::string &CPU, 940b57cec5SDimitry Andric const std::string &FS, 950b57cec5SDimitry Andric const ARMBaseTargetMachine &TM, bool IsLittle, 960b57cec5SDimitry Andric bool MinSize) 970b57cec5SDimitry Andric : ARMGenSubtargetInfo(TT, CPU, FS), UseMulOps(UseFusedMulOps), 980b57cec5SDimitry Andric CPUString(CPU), OptMinSize(MinSize), IsLittle(IsLittle), 990b57cec5SDimitry Andric TargetTriple(TT), Options(TM.Options), TM(TM), 1000b57cec5SDimitry Andric FrameLowering(initializeFrameLowering(CPU, FS)), 1010b57cec5SDimitry Andric // At this point initializeSubtargetDependencies has been called so 1020b57cec5SDimitry Andric // we can query directly. 1030b57cec5SDimitry Andric InstrInfo(isThumb1Only() 1040b57cec5SDimitry Andric ? (ARMBaseInstrInfo *)new Thumb1InstrInfo(*this) 1050b57cec5SDimitry Andric : !isThumb() 1060b57cec5SDimitry Andric ? (ARMBaseInstrInfo *)new ARMInstrInfo(*this) 1070b57cec5SDimitry Andric : (ARMBaseInstrInfo *)new Thumb2InstrInfo(*this)), 1080b57cec5SDimitry Andric TLInfo(TM, *this) { 1090b57cec5SDimitry Andric 1100b57cec5SDimitry Andric CallLoweringInfo.reset(new ARMCallLowering(*getTargetLowering())); 1110b57cec5SDimitry Andric Legalizer.reset(new ARMLegalizerInfo(*this)); 1120b57cec5SDimitry Andric 1130b57cec5SDimitry Andric auto *RBI = new ARMRegisterBankInfo(*getRegisterInfo()); 1140b57cec5SDimitry Andric 1150b57cec5SDimitry Andric // FIXME: At this point, we can't rely on Subtarget having RBI. 1160b57cec5SDimitry Andric // It's awkward to mix passing RBI and the Subtarget; should we pass 1170b57cec5SDimitry Andric // TII/TRI as well? 1180b57cec5SDimitry Andric InstSelector.reset(createARMInstructionSelector( 1190b57cec5SDimitry Andric *static_cast<const ARMBaseTargetMachine *>(&TM), *this, *RBI)); 1200b57cec5SDimitry Andric 1210b57cec5SDimitry Andric RegBankInfo.reset(RBI); 1220b57cec5SDimitry Andric } 1230b57cec5SDimitry Andric 1240b57cec5SDimitry Andric const CallLowering *ARMSubtarget::getCallLowering() const { 1250b57cec5SDimitry Andric return CallLoweringInfo.get(); 1260b57cec5SDimitry Andric } 1270b57cec5SDimitry Andric 128*8bcb0991SDimitry Andric InstructionSelector *ARMSubtarget::getInstructionSelector() const { 1290b57cec5SDimitry Andric return InstSelector.get(); 1300b57cec5SDimitry Andric } 1310b57cec5SDimitry Andric 1320b57cec5SDimitry Andric const LegalizerInfo *ARMSubtarget::getLegalizerInfo() const { 1330b57cec5SDimitry Andric return Legalizer.get(); 1340b57cec5SDimitry Andric } 1350b57cec5SDimitry Andric 1360b57cec5SDimitry Andric const RegisterBankInfo *ARMSubtarget::getRegBankInfo() const { 1370b57cec5SDimitry Andric return RegBankInfo.get(); 1380b57cec5SDimitry Andric } 1390b57cec5SDimitry Andric 1400b57cec5SDimitry Andric bool ARMSubtarget::isXRaySupported() const { 1410b57cec5SDimitry Andric // We don't currently suppport Thumb, but Windows requires Thumb. 1420b57cec5SDimitry Andric return hasV6Ops() && hasARMOps() && !isTargetWindows(); 1430b57cec5SDimitry Andric } 1440b57cec5SDimitry Andric 1450b57cec5SDimitry Andric void ARMSubtarget::initializeEnvironment() { 1460b57cec5SDimitry Andric // MCAsmInfo isn't always present (e.g. in opt) so we can't initialize this 1470b57cec5SDimitry Andric // directly from it, but we can try to make sure they're consistent when both 1480b57cec5SDimitry Andric // available. 1490b57cec5SDimitry Andric UseSjLjEH = (isTargetDarwin() && !isTargetWatchABI() && 1500b57cec5SDimitry Andric Options.ExceptionModel == ExceptionHandling::None) || 1510b57cec5SDimitry Andric Options.ExceptionModel == ExceptionHandling::SjLj; 1520b57cec5SDimitry Andric assert((!TM.getMCAsmInfo() || 1530b57cec5SDimitry Andric (TM.getMCAsmInfo()->getExceptionHandlingType() == 1540b57cec5SDimitry Andric ExceptionHandling::SjLj) == UseSjLjEH) && 1550b57cec5SDimitry Andric "inconsistent sjlj choice between CodeGen and MC"); 1560b57cec5SDimitry Andric } 1570b57cec5SDimitry Andric 1580b57cec5SDimitry Andric void ARMSubtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) { 1590b57cec5SDimitry Andric if (CPUString.empty()) { 1600b57cec5SDimitry Andric CPUString = "generic"; 1610b57cec5SDimitry Andric 1620b57cec5SDimitry Andric if (isTargetDarwin()) { 1630b57cec5SDimitry Andric StringRef ArchName = TargetTriple.getArchName(); 1640b57cec5SDimitry Andric ARM::ArchKind AK = ARM::parseArch(ArchName); 1650b57cec5SDimitry Andric if (AK == ARM::ArchKind::ARMV7S) 1660b57cec5SDimitry Andric // Default to the Swift CPU when targeting armv7s/thumbv7s. 1670b57cec5SDimitry Andric CPUString = "swift"; 1680b57cec5SDimitry Andric else if (AK == ARM::ArchKind::ARMV7K) 1690b57cec5SDimitry Andric // Default to the Cortex-a7 CPU when targeting armv7k/thumbv7k. 1700b57cec5SDimitry Andric // ARMv7k does not use SjLj exception handling. 1710b57cec5SDimitry Andric CPUString = "cortex-a7"; 1720b57cec5SDimitry Andric } 1730b57cec5SDimitry Andric } 1740b57cec5SDimitry Andric 1750b57cec5SDimitry Andric // Insert the architecture feature derived from the target triple into the 1760b57cec5SDimitry Andric // feature string. This is important for setting features that are implied 1770b57cec5SDimitry Andric // based on the architecture version. 1780b57cec5SDimitry Andric std::string ArchFS = ARM_MC::ParseARMTriple(TargetTriple, CPUString); 1790b57cec5SDimitry Andric if (!FS.empty()) { 1800b57cec5SDimitry Andric if (!ArchFS.empty()) 1810b57cec5SDimitry Andric ArchFS = (Twine(ArchFS) + "," + FS).str(); 1820b57cec5SDimitry Andric else 1830b57cec5SDimitry Andric ArchFS = FS; 1840b57cec5SDimitry Andric } 1850b57cec5SDimitry Andric ParseSubtargetFeatures(CPUString, ArchFS); 1860b57cec5SDimitry Andric 1870b57cec5SDimitry Andric // FIXME: This used enable V6T2 support implicitly for Thumb2 mode. 1880b57cec5SDimitry Andric // Assert this for now to make the change obvious. 1890b57cec5SDimitry Andric assert(hasV6T2Ops() || !hasThumb2()); 1900b57cec5SDimitry Andric 1910b57cec5SDimitry Andric // Execute only support requires movt support 1920b57cec5SDimitry Andric if (genExecuteOnly()) { 1930b57cec5SDimitry Andric NoMovt = false; 1940b57cec5SDimitry Andric assert(hasV8MBaselineOps() && "Cannot generate execute-only code for this target"); 1950b57cec5SDimitry Andric } 1960b57cec5SDimitry Andric 1970b57cec5SDimitry Andric // Keep a pointer to static instruction cost data for the specified CPU. 1980b57cec5SDimitry Andric SchedModel = getSchedModelForCPU(CPUString); 1990b57cec5SDimitry Andric 2000b57cec5SDimitry Andric // Initialize scheduling itinerary for the specified CPU. 2010b57cec5SDimitry Andric InstrItins = getInstrItineraryForCPU(CPUString); 2020b57cec5SDimitry Andric 2030b57cec5SDimitry Andric // FIXME: this is invalid for WindowsCE 2040b57cec5SDimitry Andric if (isTargetWindows()) 2050b57cec5SDimitry Andric NoARM = true; 2060b57cec5SDimitry Andric 2070b57cec5SDimitry Andric if (isAAPCS_ABI()) 208*8bcb0991SDimitry Andric stackAlignment = Align(8); 2090b57cec5SDimitry Andric if (isTargetNaCl() || isAAPCS16_ABI()) 210*8bcb0991SDimitry Andric stackAlignment = Align(16); 2110b57cec5SDimitry Andric 2120b57cec5SDimitry Andric // FIXME: Completely disable sibcall for Thumb1 since ThumbRegisterInfo:: 2130b57cec5SDimitry Andric // emitEpilogue is not ready for them. Thumb tail calls also use t2B, as 2140b57cec5SDimitry Andric // the Thumb1 16-bit unconditional branch doesn't have sufficient relocation 2150b57cec5SDimitry Andric // support in the assembler and linker to be used. This would need to be 2160b57cec5SDimitry Andric // fixed to fully support tail calls in Thumb1. 2170b57cec5SDimitry Andric // 2180b57cec5SDimitry Andric // For ARMv8-M, we /do/ implement tail calls. Doing this is tricky for v8-M 2190b57cec5SDimitry Andric // baseline, since the LDM/POP instruction on Thumb doesn't take LR. This 2200b57cec5SDimitry Andric // means if we need to reload LR, it takes extra instructions, which outweighs 2210b57cec5SDimitry Andric // the value of the tail call; but here we don't know yet whether LR is going 2220b57cec5SDimitry Andric // to be used. We take the optimistic approach of generating the tail call and 2230b57cec5SDimitry Andric // perhaps taking a hit if we need to restore the LR. 2240b57cec5SDimitry Andric 2250b57cec5SDimitry Andric // Thumb1 PIC calls to external symbols use BX, so they can be tail calls, 2260b57cec5SDimitry Andric // but we need to make sure there are enough registers; the only valid 2270b57cec5SDimitry Andric // registers are the 4 used for parameters. We don't currently do this 2280b57cec5SDimitry Andric // case. 2290b57cec5SDimitry Andric 2300b57cec5SDimitry Andric SupportsTailCall = !isThumb() || hasV8MBaselineOps(); 2310b57cec5SDimitry Andric 2320b57cec5SDimitry Andric if (isTargetMachO() && isTargetIOS() && getTargetTriple().isOSVersionLT(5, 0)) 2330b57cec5SDimitry Andric SupportsTailCall = false; 2340b57cec5SDimitry Andric 2350b57cec5SDimitry Andric switch (IT) { 2360b57cec5SDimitry Andric case DefaultIT: 2370b57cec5SDimitry Andric RestrictIT = hasV8Ops(); 2380b57cec5SDimitry Andric break; 2390b57cec5SDimitry Andric case RestrictedIT: 2400b57cec5SDimitry Andric RestrictIT = true; 2410b57cec5SDimitry Andric break; 2420b57cec5SDimitry Andric case NoRestrictedIT: 2430b57cec5SDimitry Andric RestrictIT = false; 2440b57cec5SDimitry Andric break; 2450b57cec5SDimitry Andric } 2460b57cec5SDimitry Andric 2470b57cec5SDimitry Andric // NEON f32 ops are non-IEEE 754 compliant. Darwin is ok with it by default. 2480b57cec5SDimitry Andric const FeatureBitset &Bits = getFeatureBits(); 2490b57cec5SDimitry Andric if ((Bits[ARM::ProcA5] || Bits[ARM::ProcA8]) && // Where this matters 2500b57cec5SDimitry Andric (Options.UnsafeFPMath || isTargetDarwin())) 2510b57cec5SDimitry Andric UseNEONForSinglePrecisionFP = true; 2520b57cec5SDimitry Andric 2530b57cec5SDimitry Andric if (isRWPI()) 2540b57cec5SDimitry Andric ReserveR9 = true; 2550b57cec5SDimitry Andric 256*8bcb0991SDimitry Andric // If MVEVectorCostFactor is still 0 (has not been set to anything else), default it to 2 257*8bcb0991SDimitry Andric if (MVEVectorCostFactor == 0) 258*8bcb0991SDimitry Andric MVEVectorCostFactor = 2; 259*8bcb0991SDimitry Andric 2600b57cec5SDimitry Andric // FIXME: Teach TableGen to deal with these instead of doing it manually here. 2610b57cec5SDimitry Andric switch (ARMProcFamily) { 2620b57cec5SDimitry Andric case Others: 2630b57cec5SDimitry Andric case CortexA5: 2640b57cec5SDimitry Andric break; 2650b57cec5SDimitry Andric case CortexA7: 2660b57cec5SDimitry Andric LdStMultipleTiming = DoubleIssue; 2670b57cec5SDimitry Andric break; 2680b57cec5SDimitry Andric case CortexA8: 2690b57cec5SDimitry Andric LdStMultipleTiming = DoubleIssue; 2700b57cec5SDimitry Andric break; 2710b57cec5SDimitry Andric case CortexA9: 2720b57cec5SDimitry Andric LdStMultipleTiming = DoubleIssueCheckUnalignedAccess; 2730b57cec5SDimitry Andric PreISelOperandLatencyAdjustment = 1; 2740b57cec5SDimitry Andric break; 2750b57cec5SDimitry Andric case CortexA12: 2760b57cec5SDimitry Andric break; 2770b57cec5SDimitry Andric case CortexA15: 2780b57cec5SDimitry Andric MaxInterleaveFactor = 2; 2790b57cec5SDimitry Andric PreISelOperandLatencyAdjustment = 1; 2800b57cec5SDimitry Andric PartialUpdateClearance = 12; 2810b57cec5SDimitry Andric break; 2820b57cec5SDimitry Andric case CortexA17: 2830b57cec5SDimitry Andric case CortexA32: 2840b57cec5SDimitry Andric case CortexA35: 2850b57cec5SDimitry Andric case CortexA53: 2860b57cec5SDimitry Andric case CortexA55: 2870b57cec5SDimitry Andric case CortexA57: 2880b57cec5SDimitry Andric case CortexA72: 2890b57cec5SDimitry Andric case CortexA73: 2900b57cec5SDimitry Andric case CortexA75: 2910b57cec5SDimitry Andric case CortexA76: 2920b57cec5SDimitry Andric case CortexR4: 2930b57cec5SDimitry Andric case CortexR4F: 2940b57cec5SDimitry Andric case CortexR5: 2950b57cec5SDimitry Andric case CortexR7: 2960b57cec5SDimitry Andric case CortexM3: 2970b57cec5SDimitry Andric case CortexR52: 2980b57cec5SDimitry Andric break; 2990b57cec5SDimitry Andric case Exynos: 3000b57cec5SDimitry Andric LdStMultipleTiming = SingleIssuePlusExtras; 3010b57cec5SDimitry Andric MaxInterleaveFactor = 4; 3020b57cec5SDimitry Andric if (!isThumb()) 303*8bcb0991SDimitry Andric PrefLoopLogAlignment = 3; 3040b57cec5SDimitry Andric break; 3050b57cec5SDimitry Andric case Kryo: 3060b57cec5SDimitry Andric break; 3070b57cec5SDimitry Andric case Krait: 3080b57cec5SDimitry Andric PreISelOperandLatencyAdjustment = 1; 3090b57cec5SDimitry Andric break; 310*8bcb0991SDimitry Andric case NeoverseN1: 311*8bcb0991SDimitry Andric break; 3120b57cec5SDimitry Andric case Swift: 3130b57cec5SDimitry Andric MaxInterleaveFactor = 2; 3140b57cec5SDimitry Andric LdStMultipleTiming = SingleIssuePlusExtras; 3150b57cec5SDimitry Andric PreISelOperandLatencyAdjustment = 1; 3160b57cec5SDimitry Andric PartialUpdateClearance = 12; 3170b57cec5SDimitry Andric break; 3180b57cec5SDimitry Andric } 3190b57cec5SDimitry Andric } 3200b57cec5SDimitry Andric 3210b57cec5SDimitry Andric bool ARMSubtarget::isTargetHardFloat() const { return TM.isTargetHardFloat(); } 3220b57cec5SDimitry Andric 3230b57cec5SDimitry Andric bool ARMSubtarget::isAPCS_ABI() const { 3240b57cec5SDimitry Andric assert(TM.TargetABI != ARMBaseTargetMachine::ARM_ABI_UNKNOWN); 3250b57cec5SDimitry Andric return TM.TargetABI == ARMBaseTargetMachine::ARM_ABI_APCS; 3260b57cec5SDimitry Andric } 3270b57cec5SDimitry Andric bool ARMSubtarget::isAAPCS_ABI() const { 3280b57cec5SDimitry Andric assert(TM.TargetABI != ARMBaseTargetMachine::ARM_ABI_UNKNOWN); 3290b57cec5SDimitry Andric return TM.TargetABI == ARMBaseTargetMachine::ARM_ABI_AAPCS || 3300b57cec5SDimitry Andric TM.TargetABI == ARMBaseTargetMachine::ARM_ABI_AAPCS16; 3310b57cec5SDimitry Andric } 3320b57cec5SDimitry Andric bool ARMSubtarget::isAAPCS16_ABI() const { 3330b57cec5SDimitry Andric assert(TM.TargetABI != ARMBaseTargetMachine::ARM_ABI_UNKNOWN); 3340b57cec5SDimitry Andric return TM.TargetABI == ARMBaseTargetMachine::ARM_ABI_AAPCS16; 3350b57cec5SDimitry Andric } 3360b57cec5SDimitry Andric 3370b57cec5SDimitry Andric bool ARMSubtarget::isROPI() const { 3380b57cec5SDimitry Andric return TM.getRelocationModel() == Reloc::ROPI || 3390b57cec5SDimitry Andric TM.getRelocationModel() == Reloc::ROPI_RWPI; 3400b57cec5SDimitry Andric } 3410b57cec5SDimitry Andric bool ARMSubtarget::isRWPI() const { 3420b57cec5SDimitry Andric return TM.getRelocationModel() == Reloc::RWPI || 3430b57cec5SDimitry Andric TM.getRelocationModel() == Reloc::ROPI_RWPI; 3440b57cec5SDimitry Andric } 3450b57cec5SDimitry Andric 3460b57cec5SDimitry Andric bool ARMSubtarget::isGVIndirectSymbol(const GlobalValue *GV) const { 3470b57cec5SDimitry Andric if (!TM.shouldAssumeDSOLocal(*GV->getParent(), GV)) 3480b57cec5SDimitry Andric return true; 3490b57cec5SDimitry Andric 3500b57cec5SDimitry Andric // 32 bit macho has no relocation for a-b if a is undefined, even if b is in 3510b57cec5SDimitry Andric // the section that is being relocated. This means we have to use o load even 3520b57cec5SDimitry Andric // for GVs that are known to be local to the dso. 3530b57cec5SDimitry Andric if (isTargetMachO() && TM.isPositionIndependent() && 3540b57cec5SDimitry Andric (GV->isDeclarationForLinker() || GV->hasCommonLinkage())) 3550b57cec5SDimitry Andric return true; 3560b57cec5SDimitry Andric 3570b57cec5SDimitry Andric return false; 3580b57cec5SDimitry Andric } 3590b57cec5SDimitry Andric 3600b57cec5SDimitry Andric bool ARMSubtarget::isGVInGOT(const GlobalValue *GV) const { 3610b57cec5SDimitry Andric return isTargetELF() && TM.isPositionIndependent() && 3620b57cec5SDimitry Andric !TM.shouldAssumeDSOLocal(*GV->getParent(), GV); 3630b57cec5SDimitry Andric } 3640b57cec5SDimitry Andric 3650b57cec5SDimitry Andric unsigned ARMSubtarget::getMispredictionPenalty() const { 3660b57cec5SDimitry Andric return SchedModel.MispredictPenalty; 3670b57cec5SDimitry Andric } 3680b57cec5SDimitry Andric 3690b57cec5SDimitry Andric bool ARMSubtarget::enableMachineScheduler() const { 3700b57cec5SDimitry Andric // The MachineScheduler can increase register usage, so we use more high 3710b57cec5SDimitry Andric // registers and end up with more T2 instructions that cannot be converted to 3720b57cec5SDimitry Andric // T1 instructions. At least until we do better at converting to thumb1 3730b57cec5SDimitry Andric // instructions, on cortex-m at Oz where we are size-paranoid, don't use the 3740b57cec5SDimitry Andric // Machine scheduler, relying on the DAG register pressure scheduler instead. 3750b57cec5SDimitry Andric if (isMClass() && hasMinSize()) 3760b57cec5SDimitry Andric return false; 3770b57cec5SDimitry Andric // Enable the MachineScheduler before register allocation for subtargets 3780b57cec5SDimitry Andric // with the use-misched feature. 3790b57cec5SDimitry Andric return useMachineScheduler(); 3800b57cec5SDimitry Andric } 3810b57cec5SDimitry Andric 3820b57cec5SDimitry Andric // This overrides the PostRAScheduler bit in the SchedModel for any CPU. 3830b57cec5SDimitry Andric bool ARMSubtarget::enablePostRAScheduler() const { 3840b57cec5SDimitry Andric if (disablePostRAScheduler()) 3850b57cec5SDimitry Andric return false; 3860b57cec5SDimitry Andric // Don't reschedule potential IT blocks. 3870b57cec5SDimitry Andric return !isThumb1Only(); 3880b57cec5SDimitry Andric } 3890b57cec5SDimitry Andric 3900b57cec5SDimitry Andric bool ARMSubtarget::enableAtomicExpand() const { return hasAnyDataBarrier(); } 3910b57cec5SDimitry Andric 3920b57cec5SDimitry Andric bool ARMSubtarget::useStride4VFPs() const { 3930b57cec5SDimitry Andric // For general targets, the prologue can grow when VFPs are allocated with 3940b57cec5SDimitry Andric // stride 4 (more vpush instructions). But WatchOS uses a compact unwind 3950b57cec5SDimitry Andric // format which it's more important to get right. 3960b57cec5SDimitry Andric return isTargetWatchABI() || 3970b57cec5SDimitry Andric (useWideStrideVFP() && !OptMinSize); 3980b57cec5SDimitry Andric } 3990b57cec5SDimitry Andric 4000b57cec5SDimitry Andric bool ARMSubtarget::useMovt() const { 4010b57cec5SDimitry Andric // NOTE Windows on ARM needs to use mov.w/mov.t pairs to materialise 32-bit 4020b57cec5SDimitry Andric // immediates as it is inherently position independent, and may be out of 4030b57cec5SDimitry Andric // range otherwise. 4040b57cec5SDimitry Andric return !NoMovt && hasV8MBaselineOps() && 4050b57cec5SDimitry Andric (isTargetWindows() || !OptMinSize || genExecuteOnly()); 4060b57cec5SDimitry Andric } 4070b57cec5SDimitry Andric 4080b57cec5SDimitry Andric bool ARMSubtarget::useFastISel() const { 4090b57cec5SDimitry Andric // Enable fast-isel for any target, for testing only. 4100b57cec5SDimitry Andric if (ForceFastISel) 4110b57cec5SDimitry Andric return true; 4120b57cec5SDimitry Andric 4130b57cec5SDimitry Andric // Limit fast-isel to the targets that are or have been tested. 4140b57cec5SDimitry Andric if (!hasV6Ops()) 4150b57cec5SDimitry Andric return false; 4160b57cec5SDimitry Andric 4170b57cec5SDimitry Andric // Thumb2 support on iOS; ARM support on iOS, Linux and NaCl. 4180b57cec5SDimitry Andric return TM.Options.EnableFastISel && 4190b57cec5SDimitry Andric ((isTargetMachO() && !isThumb1Only()) || 4200b57cec5SDimitry Andric (isTargetLinux() && !isThumb()) || (isTargetNaCl() && !isThumb())); 4210b57cec5SDimitry Andric } 4220b57cec5SDimitry Andric 4230b57cec5SDimitry Andric unsigned ARMSubtarget::getGPRAllocationOrder(const MachineFunction &MF) const { 4240b57cec5SDimitry Andric // The GPR register class has multiple possible allocation orders, with 4250b57cec5SDimitry Andric // tradeoffs preferred by different sub-architectures and optimisation goals. 4260b57cec5SDimitry Andric // The allocation orders are: 4270b57cec5SDimitry Andric // 0: (the default tablegen order, not used) 4280b57cec5SDimitry Andric // 1: r14, r0-r13 4290b57cec5SDimitry Andric // 2: r0-r7 4300b57cec5SDimitry Andric // 3: r0-r7, r12, lr, r8-r11 4310b57cec5SDimitry Andric // Note that the register allocator will change this order so that 4320b57cec5SDimitry Andric // callee-saved registers are used later, as they require extra work in the 4330b57cec5SDimitry Andric // prologue/epilogue (though we sometimes override that). 4340b57cec5SDimitry Andric 4350b57cec5SDimitry Andric // For thumb1-only targets, only the low registers are allocatable. 4360b57cec5SDimitry Andric if (isThumb1Only()) 4370b57cec5SDimitry Andric return 2; 4380b57cec5SDimitry Andric 4390b57cec5SDimitry Andric // Allocate low registers first, so we can select more 16-bit instructions. 4400b57cec5SDimitry Andric // We also (in ignoreCSRForAllocationOrder) override the default behaviour 4410b57cec5SDimitry Andric // with regards to callee-saved registers, because pushing extra registers is 4420b57cec5SDimitry Andric // much cheaper (in terms of code size) than using high registers. After 4430b57cec5SDimitry Andric // that, we allocate r12 (doesn't need to be saved), lr (saving it means we 4440b57cec5SDimitry Andric // can return with the pop, don't need an extra "bx lr") and then the rest of 4450b57cec5SDimitry Andric // the high registers. 4460b57cec5SDimitry Andric if (isThumb2() && MF.getFunction().hasMinSize()) 4470b57cec5SDimitry Andric return 3; 4480b57cec5SDimitry Andric 4490b57cec5SDimitry Andric // Otherwise, allocate in the default order, using LR first because saving it 4500b57cec5SDimitry Andric // allows a shorter epilogue sequence. 4510b57cec5SDimitry Andric return 1; 4520b57cec5SDimitry Andric } 4530b57cec5SDimitry Andric 4540b57cec5SDimitry Andric bool ARMSubtarget::ignoreCSRForAllocationOrder(const MachineFunction &MF, 4550b57cec5SDimitry Andric unsigned PhysReg) const { 4560b57cec5SDimitry Andric // To minimize code size in Thumb2, we prefer the usage of low regs (lower 4570b57cec5SDimitry Andric // cost per use) so we can use narrow encoding. By default, caller-saved 4580b57cec5SDimitry Andric // registers (e.g. lr, r12) are always allocated first, regardless of 4590b57cec5SDimitry Andric // their cost per use. When optForMinSize, we prefer the low regs even if 4600b57cec5SDimitry Andric // they are CSR because usually push/pop can be folded into existing ones. 4610b57cec5SDimitry Andric return isThumb2() && MF.getFunction().hasMinSize() && 4620b57cec5SDimitry Andric ARM::GPRRegClass.contains(PhysReg); 4630b57cec5SDimitry Andric } 464