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 75480093f4SDimitry Andric static cl::opt<bool> EnableSubRegLiveness("arm-enable-subreg-liveness", 76480093f4SDimitry Andric cl::init(false), cl::Hidden); 77480093f4SDimitry Andric 780b57cec5SDimitry Andric /// initializeSubtargetDependencies - Initializes using a CPU and feature string 790b57cec5SDimitry Andric /// so that we can use initializer lists for subtarget initialization. 800b57cec5SDimitry Andric ARMSubtarget &ARMSubtarget::initializeSubtargetDependencies(StringRef CPU, 810b57cec5SDimitry Andric StringRef FS) { 820b57cec5SDimitry Andric initializeEnvironment(); 830b57cec5SDimitry Andric initSubtargetFeatures(CPU, FS); 840b57cec5SDimitry Andric return *this; 850b57cec5SDimitry Andric } 860b57cec5SDimitry Andric 870b57cec5SDimitry Andric ARMFrameLowering *ARMSubtarget::initializeFrameLowering(StringRef CPU, 880b57cec5SDimitry Andric StringRef FS) { 890b57cec5SDimitry Andric ARMSubtarget &STI = initializeSubtargetDependencies(CPU, FS); 900b57cec5SDimitry Andric if (STI.isThumb1Only()) 910b57cec5SDimitry Andric return (ARMFrameLowering *)new Thumb1FrameLowering(STI); 920b57cec5SDimitry Andric 930b57cec5SDimitry Andric return new ARMFrameLowering(STI); 940b57cec5SDimitry Andric } 950b57cec5SDimitry Andric 960b57cec5SDimitry Andric ARMSubtarget::ARMSubtarget(const Triple &TT, const std::string &CPU, 970b57cec5SDimitry Andric const std::string &FS, 980b57cec5SDimitry Andric const ARMBaseTargetMachine &TM, bool IsLittle, 990b57cec5SDimitry Andric bool MinSize) 100e8d8bef9SDimitry Andric : ARMGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS), 101e8d8bef9SDimitry Andric UseMulOps(UseFusedMulOps), CPUString(CPU), OptMinSize(MinSize), 102e8d8bef9SDimitry Andric IsLittle(IsLittle), TargetTriple(TT), Options(TM.Options), TM(TM), 1030b57cec5SDimitry Andric FrameLowering(initializeFrameLowering(CPU, FS)), 1040b57cec5SDimitry Andric // At this point initializeSubtargetDependencies has been called so 1050b57cec5SDimitry Andric // we can query directly. 1060b57cec5SDimitry Andric InstrInfo(isThumb1Only() 1070b57cec5SDimitry Andric ? (ARMBaseInstrInfo *)new Thumb1InstrInfo(*this) 1080b57cec5SDimitry Andric : !isThumb() 1090b57cec5SDimitry Andric ? (ARMBaseInstrInfo *)new ARMInstrInfo(*this) 1100b57cec5SDimitry Andric : (ARMBaseInstrInfo *)new Thumb2InstrInfo(*this)), 1110b57cec5SDimitry Andric TLInfo(TM, *this) { 1120b57cec5SDimitry Andric 1130b57cec5SDimitry Andric CallLoweringInfo.reset(new ARMCallLowering(*getTargetLowering())); 1140b57cec5SDimitry Andric Legalizer.reset(new ARMLegalizerInfo(*this)); 1150b57cec5SDimitry Andric 1160b57cec5SDimitry Andric auto *RBI = new ARMRegisterBankInfo(*getRegisterInfo()); 1170b57cec5SDimitry Andric 1180b57cec5SDimitry Andric // FIXME: At this point, we can't rely on Subtarget having RBI. 1190b57cec5SDimitry Andric // It's awkward to mix passing RBI and the Subtarget; should we pass 1200b57cec5SDimitry Andric // TII/TRI as well? 1210b57cec5SDimitry Andric InstSelector.reset(createARMInstructionSelector( 1220b57cec5SDimitry Andric *static_cast<const ARMBaseTargetMachine *>(&TM), *this, *RBI)); 1230b57cec5SDimitry Andric 1240b57cec5SDimitry Andric RegBankInfo.reset(RBI); 1250b57cec5SDimitry Andric } 1260b57cec5SDimitry Andric 1270b57cec5SDimitry Andric const CallLowering *ARMSubtarget::getCallLowering() const { 1280b57cec5SDimitry Andric return CallLoweringInfo.get(); 1290b57cec5SDimitry Andric } 1300b57cec5SDimitry Andric 1318bcb0991SDimitry Andric InstructionSelector *ARMSubtarget::getInstructionSelector() const { 1320b57cec5SDimitry Andric return InstSelector.get(); 1330b57cec5SDimitry Andric } 1340b57cec5SDimitry Andric 1350b57cec5SDimitry Andric const LegalizerInfo *ARMSubtarget::getLegalizerInfo() const { 1360b57cec5SDimitry Andric return Legalizer.get(); 1370b57cec5SDimitry Andric } 1380b57cec5SDimitry Andric 1390b57cec5SDimitry Andric const RegisterBankInfo *ARMSubtarget::getRegBankInfo() const { 1400b57cec5SDimitry Andric return RegBankInfo.get(); 1410b57cec5SDimitry Andric } 1420b57cec5SDimitry Andric 1430b57cec5SDimitry Andric bool ARMSubtarget::isXRaySupported() const { 1440b57cec5SDimitry Andric // We don't currently suppport Thumb, but Windows requires Thumb. 1450b57cec5SDimitry Andric return hasV6Ops() && hasARMOps() && !isTargetWindows(); 1460b57cec5SDimitry Andric } 1470b57cec5SDimitry Andric 1480b57cec5SDimitry Andric void ARMSubtarget::initializeEnvironment() { 1490b57cec5SDimitry Andric // MCAsmInfo isn't always present (e.g. in opt) so we can't initialize this 1500b57cec5SDimitry Andric // directly from it, but we can try to make sure they're consistent when both 1510b57cec5SDimitry Andric // available. 1520b57cec5SDimitry Andric UseSjLjEH = (isTargetDarwin() && !isTargetWatchABI() && 1530b57cec5SDimitry Andric Options.ExceptionModel == ExceptionHandling::None) || 1540b57cec5SDimitry Andric Options.ExceptionModel == ExceptionHandling::SjLj; 1550b57cec5SDimitry Andric assert((!TM.getMCAsmInfo() || 1560b57cec5SDimitry Andric (TM.getMCAsmInfo()->getExceptionHandlingType() == 1570b57cec5SDimitry Andric ExceptionHandling::SjLj) == UseSjLjEH) && 1580b57cec5SDimitry Andric "inconsistent sjlj choice between CodeGen and MC"); 1590b57cec5SDimitry Andric } 1600b57cec5SDimitry Andric 1610b57cec5SDimitry Andric void ARMSubtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) { 1620b57cec5SDimitry Andric if (CPUString.empty()) { 1630b57cec5SDimitry Andric CPUString = "generic"; 1640b57cec5SDimitry Andric 1650b57cec5SDimitry Andric if (isTargetDarwin()) { 1660b57cec5SDimitry Andric StringRef ArchName = TargetTriple.getArchName(); 1670b57cec5SDimitry Andric ARM::ArchKind AK = ARM::parseArch(ArchName); 1680b57cec5SDimitry Andric if (AK == ARM::ArchKind::ARMV7S) 1690b57cec5SDimitry Andric // Default to the Swift CPU when targeting armv7s/thumbv7s. 1700b57cec5SDimitry Andric CPUString = "swift"; 1710b57cec5SDimitry Andric else if (AK == ARM::ArchKind::ARMV7K) 1720b57cec5SDimitry Andric // Default to the Cortex-a7 CPU when targeting armv7k/thumbv7k. 1730b57cec5SDimitry Andric // ARMv7k does not use SjLj exception handling. 1740b57cec5SDimitry Andric CPUString = "cortex-a7"; 1750b57cec5SDimitry Andric } 1760b57cec5SDimitry Andric } 1770b57cec5SDimitry Andric 1780b57cec5SDimitry Andric // Insert the architecture feature derived from the target triple into the 1790b57cec5SDimitry Andric // feature string. This is important for setting features that are implied 1800b57cec5SDimitry Andric // based on the architecture version. 1810b57cec5SDimitry Andric std::string ArchFS = ARM_MC::ParseARMTriple(TargetTriple, CPUString); 1820b57cec5SDimitry Andric if (!FS.empty()) { 1830b57cec5SDimitry Andric if (!ArchFS.empty()) 1840b57cec5SDimitry Andric ArchFS = (Twine(ArchFS) + "," + FS).str(); 1850b57cec5SDimitry Andric else 1865ffd83dbSDimitry Andric ArchFS = std::string(FS); 1870b57cec5SDimitry Andric } 188e8d8bef9SDimitry Andric ParseSubtargetFeatures(CPUString, /*TuneCPU*/ CPUString, ArchFS); 1890b57cec5SDimitry Andric 1900b57cec5SDimitry Andric // FIXME: This used enable V6T2 support implicitly for Thumb2 mode. 1910b57cec5SDimitry Andric // Assert this for now to make the change obvious. 1920b57cec5SDimitry Andric assert(hasV6T2Ops() || !hasThumb2()); 1930b57cec5SDimitry Andric 1940b57cec5SDimitry Andric // Execute only support requires movt support 1950b57cec5SDimitry Andric if (genExecuteOnly()) { 1960b57cec5SDimitry Andric NoMovt = false; 1970b57cec5SDimitry Andric assert(hasV8MBaselineOps() && "Cannot generate execute-only code for this target"); 1980b57cec5SDimitry Andric } 1990b57cec5SDimitry Andric 2000b57cec5SDimitry Andric // Keep a pointer to static instruction cost data for the specified CPU. 2010b57cec5SDimitry Andric SchedModel = getSchedModelForCPU(CPUString); 2020b57cec5SDimitry Andric 2030b57cec5SDimitry Andric // Initialize scheduling itinerary for the specified CPU. 2040b57cec5SDimitry Andric InstrItins = getInstrItineraryForCPU(CPUString); 2050b57cec5SDimitry Andric 2060b57cec5SDimitry Andric // FIXME: this is invalid for WindowsCE 2070b57cec5SDimitry Andric if (isTargetWindows()) 2080b57cec5SDimitry Andric NoARM = true; 2090b57cec5SDimitry Andric 2100b57cec5SDimitry Andric if (isAAPCS_ABI()) 2118bcb0991SDimitry Andric stackAlignment = Align(8); 2120b57cec5SDimitry Andric if (isTargetNaCl() || isAAPCS16_ABI()) 2138bcb0991SDimitry Andric stackAlignment = Align(16); 2140b57cec5SDimitry Andric 2150b57cec5SDimitry Andric // FIXME: Completely disable sibcall for Thumb1 since ThumbRegisterInfo:: 2160b57cec5SDimitry Andric // emitEpilogue is not ready for them. Thumb tail calls also use t2B, as 2170b57cec5SDimitry Andric // the Thumb1 16-bit unconditional branch doesn't have sufficient relocation 2180b57cec5SDimitry Andric // support in the assembler and linker to be used. This would need to be 2190b57cec5SDimitry Andric // fixed to fully support tail calls in Thumb1. 2200b57cec5SDimitry Andric // 2210b57cec5SDimitry Andric // For ARMv8-M, we /do/ implement tail calls. Doing this is tricky for v8-M 2220b57cec5SDimitry Andric // baseline, since the LDM/POP instruction on Thumb doesn't take LR. This 2230b57cec5SDimitry Andric // means if we need to reload LR, it takes extra instructions, which outweighs 2240b57cec5SDimitry Andric // the value of the tail call; but here we don't know yet whether LR is going 2250b57cec5SDimitry Andric // to be used. We take the optimistic approach of generating the tail call and 2260b57cec5SDimitry Andric // perhaps taking a hit if we need to restore the LR. 2270b57cec5SDimitry Andric 2280b57cec5SDimitry Andric // Thumb1 PIC calls to external symbols use BX, so they can be tail calls, 2290b57cec5SDimitry Andric // but we need to make sure there are enough registers; the only valid 2300b57cec5SDimitry Andric // registers are the 4 used for parameters. We don't currently do this 2310b57cec5SDimitry Andric // case. 2320b57cec5SDimitry Andric 233fe6060f1SDimitry Andric SupportsTailCall = !isThumb1Only() || hasV8MBaselineOps(); 2340b57cec5SDimitry Andric 2350b57cec5SDimitry Andric if (isTargetMachO() && isTargetIOS() && getTargetTriple().isOSVersionLT(5, 0)) 2360b57cec5SDimitry Andric SupportsTailCall = false; 2370b57cec5SDimitry Andric 2380b57cec5SDimitry Andric switch (IT) { 2390b57cec5SDimitry Andric case DefaultIT: 240e8d8bef9SDimitry Andric RestrictIT = hasV8Ops() && !hasMinSize(); 2410b57cec5SDimitry Andric break; 2420b57cec5SDimitry Andric case RestrictedIT: 2430b57cec5SDimitry Andric RestrictIT = true; 2440b57cec5SDimitry Andric break; 2450b57cec5SDimitry Andric case NoRestrictedIT: 2460b57cec5SDimitry Andric RestrictIT = false; 2470b57cec5SDimitry Andric break; 2480b57cec5SDimitry Andric } 2490b57cec5SDimitry Andric 2500b57cec5SDimitry Andric // NEON f32 ops are non-IEEE 754 compliant. Darwin is ok with it by default. 2510b57cec5SDimitry Andric const FeatureBitset &Bits = getFeatureBits(); 2520b57cec5SDimitry Andric if ((Bits[ARM::ProcA5] || Bits[ARM::ProcA8]) && // Where this matters 2530b57cec5SDimitry Andric (Options.UnsafeFPMath || isTargetDarwin())) 2540b57cec5SDimitry Andric UseNEONForSinglePrecisionFP = true; 2550b57cec5SDimitry Andric 2560b57cec5SDimitry Andric if (isRWPI()) 2570b57cec5SDimitry Andric ReserveR9 = true; 2580b57cec5SDimitry Andric 2598bcb0991SDimitry Andric // If MVEVectorCostFactor is still 0 (has not been set to anything else), default it to 2 2608bcb0991SDimitry Andric if (MVEVectorCostFactor == 0) 2618bcb0991SDimitry Andric MVEVectorCostFactor = 2; 2628bcb0991SDimitry Andric 2630b57cec5SDimitry Andric // FIXME: Teach TableGen to deal with these instead of doing it manually here. 2640b57cec5SDimitry Andric switch (ARMProcFamily) { 2650b57cec5SDimitry Andric case Others: 2660b57cec5SDimitry Andric case CortexA5: 2670b57cec5SDimitry Andric break; 2680b57cec5SDimitry Andric case CortexA7: 2690b57cec5SDimitry Andric LdStMultipleTiming = DoubleIssue; 2700b57cec5SDimitry Andric break; 2710b57cec5SDimitry Andric case CortexA8: 2720b57cec5SDimitry Andric LdStMultipleTiming = DoubleIssue; 2730b57cec5SDimitry Andric break; 2740b57cec5SDimitry Andric case CortexA9: 2750b57cec5SDimitry Andric LdStMultipleTiming = DoubleIssueCheckUnalignedAccess; 2760b57cec5SDimitry Andric PreISelOperandLatencyAdjustment = 1; 2770b57cec5SDimitry Andric break; 2780b57cec5SDimitry Andric case CortexA12: 2790b57cec5SDimitry Andric break; 2800b57cec5SDimitry Andric case CortexA15: 2810b57cec5SDimitry Andric MaxInterleaveFactor = 2; 2820b57cec5SDimitry Andric PreISelOperandLatencyAdjustment = 1; 2830b57cec5SDimitry Andric PartialUpdateClearance = 12; 2840b57cec5SDimitry Andric break; 2850b57cec5SDimitry Andric case CortexA17: 2860b57cec5SDimitry Andric case CortexA32: 2870b57cec5SDimitry Andric case CortexA35: 2880b57cec5SDimitry Andric case CortexA53: 2890b57cec5SDimitry Andric case CortexA55: 2900b57cec5SDimitry Andric case CortexA57: 2910b57cec5SDimitry Andric case CortexA72: 2920b57cec5SDimitry Andric case CortexA73: 2930b57cec5SDimitry Andric case CortexA75: 2940b57cec5SDimitry Andric case CortexA76: 2955ffd83dbSDimitry Andric case CortexA77: 2965ffd83dbSDimitry Andric case CortexA78: 297e8d8bef9SDimitry Andric case CortexA78C: 298*349cc55cSDimitry Andric case CortexA710: 2990b57cec5SDimitry Andric case CortexR4: 3000b57cec5SDimitry Andric case CortexR4F: 3010b57cec5SDimitry Andric case CortexR5: 3020b57cec5SDimitry Andric case CortexR7: 3030b57cec5SDimitry Andric case CortexM3: 304e8d8bef9SDimitry Andric case CortexM7: 3050b57cec5SDimitry Andric case CortexR52: 3065ffd83dbSDimitry Andric case CortexX1: 3070b57cec5SDimitry Andric break; 3080b57cec5SDimitry Andric case Exynos: 3090b57cec5SDimitry Andric LdStMultipleTiming = SingleIssuePlusExtras; 3100b57cec5SDimitry Andric MaxInterleaveFactor = 4; 3110b57cec5SDimitry Andric if (!isThumb()) 3128bcb0991SDimitry Andric PrefLoopLogAlignment = 3; 3130b57cec5SDimitry Andric break; 3140b57cec5SDimitry Andric case Kryo: 3150b57cec5SDimitry Andric break; 3160b57cec5SDimitry Andric case Krait: 3170b57cec5SDimitry Andric PreISelOperandLatencyAdjustment = 1; 3180b57cec5SDimitry Andric break; 3198bcb0991SDimitry Andric case NeoverseN1: 320e8d8bef9SDimitry Andric case NeoverseN2: 321e8d8bef9SDimitry Andric case NeoverseV1: 3228bcb0991SDimitry Andric break; 3230b57cec5SDimitry Andric case Swift: 3240b57cec5SDimitry Andric MaxInterleaveFactor = 2; 3250b57cec5SDimitry Andric LdStMultipleTiming = SingleIssuePlusExtras; 3260b57cec5SDimitry Andric PreISelOperandLatencyAdjustment = 1; 3270b57cec5SDimitry Andric PartialUpdateClearance = 12; 3280b57cec5SDimitry Andric break; 3290b57cec5SDimitry Andric } 3300b57cec5SDimitry Andric } 3310b57cec5SDimitry Andric 3320b57cec5SDimitry Andric bool ARMSubtarget::isTargetHardFloat() const { return TM.isTargetHardFloat(); } 3330b57cec5SDimitry Andric 3340b57cec5SDimitry Andric bool ARMSubtarget::isAPCS_ABI() const { 3350b57cec5SDimitry Andric assert(TM.TargetABI != ARMBaseTargetMachine::ARM_ABI_UNKNOWN); 3360b57cec5SDimitry Andric return TM.TargetABI == ARMBaseTargetMachine::ARM_ABI_APCS; 3370b57cec5SDimitry Andric } 3380b57cec5SDimitry Andric bool ARMSubtarget::isAAPCS_ABI() const { 3390b57cec5SDimitry Andric assert(TM.TargetABI != ARMBaseTargetMachine::ARM_ABI_UNKNOWN); 3400b57cec5SDimitry Andric return TM.TargetABI == ARMBaseTargetMachine::ARM_ABI_AAPCS || 3410b57cec5SDimitry Andric TM.TargetABI == ARMBaseTargetMachine::ARM_ABI_AAPCS16; 3420b57cec5SDimitry Andric } 3430b57cec5SDimitry Andric bool ARMSubtarget::isAAPCS16_ABI() const { 3440b57cec5SDimitry Andric assert(TM.TargetABI != ARMBaseTargetMachine::ARM_ABI_UNKNOWN); 3450b57cec5SDimitry Andric return TM.TargetABI == ARMBaseTargetMachine::ARM_ABI_AAPCS16; 3460b57cec5SDimitry Andric } 3470b57cec5SDimitry Andric 3480b57cec5SDimitry Andric bool ARMSubtarget::isROPI() const { 3490b57cec5SDimitry Andric return TM.getRelocationModel() == Reloc::ROPI || 3500b57cec5SDimitry Andric TM.getRelocationModel() == Reloc::ROPI_RWPI; 3510b57cec5SDimitry Andric } 3520b57cec5SDimitry Andric bool ARMSubtarget::isRWPI() const { 3530b57cec5SDimitry Andric return TM.getRelocationModel() == Reloc::RWPI || 3540b57cec5SDimitry Andric TM.getRelocationModel() == Reloc::ROPI_RWPI; 3550b57cec5SDimitry Andric } 3560b57cec5SDimitry Andric 3570b57cec5SDimitry Andric bool ARMSubtarget::isGVIndirectSymbol(const GlobalValue *GV) const { 3580b57cec5SDimitry Andric if (!TM.shouldAssumeDSOLocal(*GV->getParent(), GV)) 3590b57cec5SDimitry Andric return true; 3600b57cec5SDimitry Andric 3610b57cec5SDimitry Andric // 32 bit macho has no relocation for a-b if a is undefined, even if b is in 3620b57cec5SDimitry Andric // the section that is being relocated. This means we have to use o load even 3630b57cec5SDimitry Andric // for GVs that are known to be local to the dso. 3640b57cec5SDimitry Andric if (isTargetMachO() && TM.isPositionIndependent() && 3650b57cec5SDimitry Andric (GV->isDeclarationForLinker() || GV->hasCommonLinkage())) 3660b57cec5SDimitry Andric return true; 3670b57cec5SDimitry Andric 3680b57cec5SDimitry Andric return false; 3690b57cec5SDimitry Andric } 3700b57cec5SDimitry Andric 3710b57cec5SDimitry Andric bool ARMSubtarget::isGVInGOT(const GlobalValue *GV) const { 3720b57cec5SDimitry Andric return isTargetELF() && TM.isPositionIndependent() && 3730b57cec5SDimitry Andric !TM.shouldAssumeDSOLocal(*GV->getParent(), GV); 3740b57cec5SDimitry Andric } 3750b57cec5SDimitry Andric 3760b57cec5SDimitry Andric unsigned ARMSubtarget::getMispredictionPenalty() const { 3770b57cec5SDimitry Andric return SchedModel.MispredictPenalty; 3780b57cec5SDimitry Andric } 3790b57cec5SDimitry Andric 3800b57cec5SDimitry Andric bool ARMSubtarget::enableMachineScheduler() const { 3810b57cec5SDimitry Andric // The MachineScheduler can increase register usage, so we use more high 3820b57cec5SDimitry Andric // registers and end up with more T2 instructions that cannot be converted to 3830b57cec5SDimitry Andric // T1 instructions. At least until we do better at converting to thumb1 3840b57cec5SDimitry Andric // instructions, on cortex-m at Oz where we are size-paranoid, don't use the 3850b57cec5SDimitry Andric // Machine scheduler, relying on the DAG register pressure scheduler instead. 3860b57cec5SDimitry Andric if (isMClass() && hasMinSize()) 3870b57cec5SDimitry Andric return false; 3880b57cec5SDimitry Andric // Enable the MachineScheduler before register allocation for subtargets 3890b57cec5SDimitry Andric // with the use-misched feature. 3900b57cec5SDimitry Andric return useMachineScheduler(); 3910b57cec5SDimitry Andric } 3920b57cec5SDimitry Andric 393*349cc55cSDimitry Andric bool ARMSubtarget::enableSubRegLiveness() const { 394*349cc55cSDimitry Andric if (EnableSubRegLiveness.getNumOccurrences()) 395*349cc55cSDimitry Andric return EnableSubRegLiveness; 396*349cc55cSDimitry Andric // Enable SubRegLiveness for MVE to better optimize s subregs for mqpr regs 397*349cc55cSDimitry Andric // and q subregs for qqqqpr regs. 398*349cc55cSDimitry Andric return hasMVEIntegerOps(); 399*349cc55cSDimitry Andric } 400480093f4SDimitry Andric 4010b57cec5SDimitry Andric // This overrides the PostRAScheduler bit in the SchedModel for any CPU. 4020b57cec5SDimitry Andric bool ARMSubtarget::enablePostRAScheduler() const { 403480093f4SDimitry Andric if (enableMachineScheduler()) 404480093f4SDimitry Andric return false; 4050b57cec5SDimitry Andric if (disablePostRAScheduler()) 4060b57cec5SDimitry Andric return false; 407480093f4SDimitry Andric // Thumb1 cores will generally not benefit from post-ra scheduling 408480093f4SDimitry Andric return !isThumb1Only(); 409480093f4SDimitry Andric } 410480093f4SDimitry Andric 411480093f4SDimitry Andric bool ARMSubtarget::enablePostRAMachineScheduler() const { 412480093f4SDimitry Andric if (!enableMachineScheduler()) 413480093f4SDimitry Andric return false; 414480093f4SDimitry Andric if (disablePostRAScheduler()) 415480093f4SDimitry Andric return false; 4160b57cec5SDimitry Andric return !isThumb1Only(); 4170b57cec5SDimitry Andric } 4180b57cec5SDimitry Andric 4190b57cec5SDimitry Andric bool ARMSubtarget::enableAtomicExpand() const { return hasAnyDataBarrier(); } 4200b57cec5SDimitry Andric 4210b57cec5SDimitry Andric bool ARMSubtarget::useStride4VFPs() const { 4220b57cec5SDimitry Andric // For general targets, the prologue can grow when VFPs are allocated with 4230b57cec5SDimitry Andric // stride 4 (more vpush instructions). But WatchOS uses a compact unwind 4240b57cec5SDimitry Andric // format which it's more important to get right. 4250b57cec5SDimitry Andric return isTargetWatchABI() || 4260b57cec5SDimitry Andric (useWideStrideVFP() && !OptMinSize); 4270b57cec5SDimitry Andric } 4280b57cec5SDimitry Andric 4290b57cec5SDimitry Andric bool ARMSubtarget::useMovt() const { 4300b57cec5SDimitry Andric // NOTE Windows on ARM needs to use mov.w/mov.t pairs to materialise 32-bit 4310b57cec5SDimitry Andric // immediates as it is inherently position independent, and may be out of 4320b57cec5SDimitry Andric // range otherwise. 4330b57cec5SDimitry Andric return !NoMovt && hasV8MBaselineOps() && 4340b57cec5SDimitry Andric (isTargetWindows() || !OptMinSize || genExecuteOnly()); 4350b57cec5SDimitry Andric } 4360b57cec5SDimitry Andric 4370b57cec5SDimitry Andric bool ARMSubtarget::useFastISel() const { 4380b57cec5SDimitry Andric // Enable fast-isel for any target, for testing only. 4390b57cec5SDimitry Andric if (ForceFastISel) 4400b57cec5SDimitry Andric return true; 4410b57cec5SDimitry Andric 4420b57cec5SDimitry Andric // Limit fast-isel to the targets that are or have been tested. 4430b57cec5SDimitry Andric if (!hasV6Ops()) 4440b57cec5SDimitry Andric return false; 4450b57cec5SDimitry Andric 4460b57cec5SDimitry Andric // Thumb2 support on iOS; ARM support on iOS, Linux and NaCl. 4470b57cec5SDimitry Andric return TM.Options.EnableFastISel && 4480b57cec5SDimitry Andric ((isTargetMachO() && !isThumb1Only()) || 4490b57cec5SDimitry Andric (isTargetLinux() && !isThumb()) || (isTargetNaCl() && !isThumb())); 4500b57cec5SDimitry Andric } 4510b57cec5SDimitry Andric 4520b57cec5SDimitry Andric unsigned ARMSubtarget::getGPRAllocationOrder(const MachineFunction &MF) const { 4530b57cec5SDimitry Andric // The GPR register class has multiple possible allocation orders, with 4540b57cec5SDimitry Andric // tradeoffs preferred by different sub-architectures and optimisation goals. 4550b57cec5SDimitry Andric // The allocation orders are: 4560b57cec5SDimitry Andric // 0: (the default tablegen order, not used) 4570b57cec5SDimitry Andric // 1: r14, r0-r13 4580b57cec5SDimitry Andric // 2: r0-r7 4590b57cec5SDimitry Andric // 3: r0-r7, r12, lr, r8-r11 4600b57cec5SDimitry Andric // Note that the register allocator will change this order so that 4610b57cec5SDimitry Andric // callee-saved registers are used later, as they require extra work in the 4620b57cec5SDimitry Andric // prologue/epilogue (though we sometimes override that). 4630b57cec5SDimitry Andric 4640b57cec5SDimitry Andric // For thumb1-only targets, only the low registers are allocatable. 4650b57cec5SDimitry Andric if (isThumb1Only()) 4660b57cec5SDimitry Andric return 2; 4670b57cec5SDimitry Andric 4680b57cec5SDimitry Andric // Allocate low registers first, so we can select more 16-bit instructions. 4690b57cec5SDimitry Andric // We also (in ignoreCSRForAllocationOrder) override the default behaviour 4700b57cec5SDimitry Andric // with regards to callee-saved registers, because pushing extra registers is 4710b57cec5SDimitry Andric // much cheaper (in terms of code size) than using high registers. After 4720b57cec5SDimitry Andric // that, we allocate r12 (doesn't need to be saved), lr (saving it means we 4730b57cec5SDimitry Andric // can return with the pop, don't need an extra "bx lr") and then the rest of 4740b57cec5SDimitry Andric // the high registers. 4750b57cec5SDimitry Andric if (isThumb2() && MF.getFunction().hasMinSize()) 4760b57cec5SDimitry Andric return 3; 4770b57cec5SDimitry Andric 4780b57cec5SDimitry Andric // Otherwise, allocate in the default order, using LR first because saving it 4790b57cec5SDimitry Andric // allows a shorter epilogue sequence. 4800b57cec5SDimitry Andric return 1; 4810b57cec5SDimitry Andric } 4820b57cec5SDimitry Andric 4830b57cec5SDimitry Andric bool ARMSubtarget::ignoreCSRForAllocationOrder(const MachineFunction &MF, 4840b57cec5SDimitry Andric unsigned PhysReg) const { 4850b57cec5SDimitry Andric // To minimize code size in Thumb2, we prefer the usage of low regs (lower 4860b57cec5SDimitry Andric // cost per use) so we can use narrow encoding. By default, caller-saved 4870b57cec5SDimitry Andric // registers (e.g. lr, r12) are always allocated first, regardless of 4880b57cec5SDimitry Andric // their cost per use. When optForMinSize, we prefer the low regs even if 4890b57cec5SDimitry Andric // they are CSR because usually push/pop can be folded into existing ones. 4900b57cec5SDimitry Andric return isThumb2() && MF.getFunction().hasMinSize() && 4910b57cec5SDimitry Andric ARM::GPRRegClass.contains(PhysReg); 4920b57cec5SDimitry Andric } 493