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 "ARMFrameLowering.h" 190b57cec5SDimitry Andric #include "ARMInstrInfo.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/Triple.h" 280b57cec5SDimitry Andric #include "llvm/ADT/Twine.h" 290b57cec5SDimitry Andric #include "llvm/CodeGen/GlobalISel/InstructionSelect.h" 30*81ad6265SDimitry Andric #include "llvm/CodeGen/MachineFrameInfo.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" 3804eeddc0SDimitry Andric #include "llvm/Support/ARMTargetParser.h" 390b57cec5SDimitry Andric #include "llvm/Support/TargetParser.h" 400b57cec5SDimitry Andric #include "llvm/Target/TargetOptions.h" 410b57cec5SDimitry Andric 420b57cec5SDimitry Andric using namespace llvm; 430b57cec5SDimitry Andric 440b57cec5SDimitry Andric #define DEBUG_TYPE "arm-subtarget" 450b57cec5SDimitry Andric 460b57cec5SDimitry Andric #define GET_SUBTARGETINFO_TARGET_DESC 470b57cec5SDimitry Andric #define GET_SUBTARGETINFO_CTOR 480b57cec5SDimitry Andric #include "ARMGenSubtargetInfo.inc" 490b57cec5SDimitry Andric 500b57cec5SDimitry Andric static cl::opt<bool> 510b57cec5SDimitry Andric UseFusedMulOps("arm-use-mulops", 520b57cec5SDimitry Andric cl::init(true), cl::Hidden); 530b57cec5SDimitry Andric 540b57cec5SDimitry Andric enum ITMode { 550b57cec5SDimitry Andric DefaultIT, 56*81ad6265SDimitry Andric RestrictedIT 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::values(clEnumValN(DefaultIT, "arm-default-it", 62*81ad6265SDimitry Andric "Generate any type of IT block"), 630b57cec5SDimitry Andric clEnumValN(RestrictedIT, "arm-restrict-it", 64*81ad6265SDimitry Andric "Disallow complex IT blocks"))); 650b57cec5SDimitry Andric 660b57cec5SDimitry Andric /// ForceFastISel - Use the fast-isel, even for subtargets where it is not 670b57cec5SDimitry Andric /// currently supported (for testing only). 680b57cec5SDimitry Andric static cl::opt<bool> 690b57cec5SDimitry Andric ForceFastISel("arm-force-fast-isel", 700b57cec5SDimitry Andric cl::init(false), cl::Hidden); 710b57cec5SDimitry Andric 72480093f4SDimitry Andric static cl::opt<bool> EnableSubRegLiveness("arm-enable-subreg-liveness", 73480093f4SDimitry Andric cl::init(false), cl::Hidden); 74480093f4SDimitry 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) 97e8d8bef9SDimitry Andric : ARMGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS), 98e8d8bef9SDimitry Andric UseMulOps(UseFusedMulOps), CPUString(CPU), OptMinSize(MinSize), 99e8d8bef9SDimitry Andric IsLittle(IsLittle), 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 1288bcb0991SDimitry 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 1835ffd83dbSDimitry Andric ArchFS = std::string(FS); 1840b57cec5SDimitry Andric } 185e8d8bef9SDimitry Andric ParseSubtargetFeatures(CPUString, /*TuneCPU*/ 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()) 2088bcb0991SDimitry Andric stackAlignment = Align(8); 2090b57cec5SDimitry Andric if (isTargetNaCl() || isAAPCS16_ABI()) 2108bcb0991SDimitry 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 230fe6060f1SDimitry Andric SupportsTailCall = !isThumb1Only() || 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: 237*81ad6265SDimitry Andric RestrictIT = false; 2380b57cec5SDimitry Andric break; 2390b57cec5SDimitry Andric case RestrictedIT: 2400b57cec5SDimitry Andric RestrictIT = true; 2410b57cec5SDimitry Andric break; 2420b57cec5SDimitry Andric } 2430b57cec5SDimitry Andric 2440b57cec5SDimitry Andric // NEON f32 ops are non-IEEE 754 compliant. Darwin is ok with it by default. 2450b57cec5SDimitry Andric const FeatureBitset &Bits = getFeatureBits(); 2460b57cec5SDimitry Andric if ((Bits[ARM::ProcA5] || Bits[ARM::ProcA8]) && // Where this matters 2470b57cec5SDimitry Andric (Options.UnsafeFPMath || isTargetDarwin())) 248*81ad6265SDimitry Andric HasNEONForFP = true; 2490b57cec5SDimitry Andric 2500b57cec5SDimitry Andric if (isRWPI()) 2510b57cec5SDimitry Andric ReserveR9 = true; 2520b57cec5SDimitry Andric 2538bcb0991SDimitry Andric // If MVEVectorCostFactor is still 0 (has not been set to anything else), default it to 2 2548bcb0991SDimitry Andric if (MVEVectorCostFactor == 0) 2558bcb0991SDimitry Andric MVEVectorCostFactor = 2; 2568bcb0991SDimitry Andric 2570b57cec5SDimitry Andric // FIXME: Teach TableGen to deal with these instead of doing it manually here. 2580b57cec5SDimitry Andric switch (ARMProcFamily) { 2590b57cec5SDimitry Andric case Others: 2600b57cec5SDimitry Andric case CortexA5: 2610b57cec5SDimitry Andric break; 2620b57cec5SDimitry Andric case CortexA7: 2630b57cec5SDimitry Andric LdStMultipleTiming = DoubleIssue; 2640b57cec5SDimitry Andric break; 2650b57cec5SDimitry Andric case CortexA8: 2660b57cec5SDimitry Andric LdStMultipleTiming = DoubleIssue; 2670b57cec5SDimitry Andric break; 2680b57cec5SDimitry Andric case CortexA9: 2690b57cec5SDimitry Andric LdStMultipleTiming = DoubleIssueCheckUnalignedAccess; 2700b57cec5SDimitry Andric PreISelOperandLatencyAdjustment = 1; 2710b57cec5SDimitry Andric break; 2720b57cec5SDimitry Andric case CortexA12: 2730b57cec5SDimitry Andric break; 2740b57cec5SDimitry Andric case CortexA15: 2750b57cec5SDimitry Andric MaxInterleaveFactor = 2; 2760b57cec5SDimitry Andric PreISelOperandLatencyAdjustment = 1; 2770b57cec5SDimitry Andric PartialUpdateClearance = 12; 2780b57cec5SDimitry Andric break; 2790b57cec5SDimitry Andric case CortexA17: 2800b57cec5SDimitry Andric case CortexA32: 2810b57cec5SDimitry Andric case CortexA35: 2820b57cec5SDimitry Andric case CortexA53: 2830b57cec5SDimitry Andric case CortexA55: 2840b57cec5SDimitry Andric case CortexA57: 2850b57cec5SDimitry Andric case CortexA72: 2860b57cec5SDimitry Andric case CortexA73: 2870b57cec5SDimitry Andric case CortexA75: 2880b57cec5SDimitry Andric case CortexA76: 2895ffd83dbSDimitry Andric case CortexA77: 2905ffd83dbSDimitry Andric case CortexA78: 291e8d8bef9SDimitry Andric case CortexA78C: 292349cc55cSDimitry Andric case CortexA710: 2930b57cec5SDimitry Andric case CortexR4: 2940b57cec5SDimitry Andric case CortexR4F: 2950b57cec5SDimitry Andric case CortexR5: 2960b57cec5SDimitry Andric case CortexR7: 2970b57cec5SDimitry Andric case CortexM3: 298e8d8bef9SDimitry Andric case CortexM7: 2990b57cec5SDimitry Andric case CortexR52: 3005ffd83dbSDimitry Andric case CortexX1: 3011fd87a68SDimitry Andric case CortexX1C: 3020b57cec5SDimitry Andric break; 3030b57cec5SDimitry Andric case Exynos: 3040b57cec5SDimitry Andric LdStMultipleTiming = SingleIssuePlusExtras; 3050b57cec5SDimitry Andric MaxInterleaveFactor = 4; 3060b57cec5SDimitry Andric if (!isThumb()) 3078bcb0991SDimitry Andric PrefLoopLogAlignment = 3; 3080b57cec5SDimitry Andric break; 3090b57cec5SDimitry Andric case Kryo: 3100b57cec5SDimitry Andric break; 3110b57cec5SDimitry Andric case Krait: 3120b57cec5SDimitry Andric PreISelOperandLatencyAdjustment = 1; 3130b57cec5SDimitry Andric break; 3148bcb0991SDimitry Andric case NeoverseN1: 315e8d8bef9SDimitry Andric case NeoverseN2: 316e8d8bef9SDimitry Andric case NeoverseV1: 3178bcb0991SDimitry Andric break; 3180b57cec5SDimitry Andric case Swift: 3190b57cec5SDimitry Andric MaxInterleaveFactor = 2; 3200b57cec5SDimitry Andric LdStMultipleTiming = SingleIssuePlusExtras; 3210b57cec5SDimitry Andric PreISelOperandLatencyAdjustment = 1; 3220b57cec5SDimitry Andric PartialUpdateClearance = 12; 3230b57cec5SDimitry Andric break; 3240b57cec5SDimitry Andric } 3250b57cec5SDimitry Andric } 3260b57cec5SDimitry Andric 3270b57cec5SDimitry Andric bool ARMSubtarget::isTargetHardFloat() const { return TM.isTargetHardFloat(); } 3280b57cec5SDimitry Andric 3290b57cec5SDimitry Andric bool ARMSubtarget::isAPCS_ABI() const { 3300b57cec5SDimitry Andric assert(TM.TargetABI != ARMBaseTargetMachine::ARM_ABI_UNKNOWN); 3310b57cec5SDimitry Andric return TM.TargetABI == ARMBaseTargetMachine::ARM_ABI_APCS; 3320b57cec5SDimitry Andric } 3330b57cec5SDimitry Andric bool ARMSubtarget::isAAPCS_ABI() const { 3340b57cec5SDimitry Andric assert(TM.TargetABI != ARMBaseTargetMachine::ARM_ABI_UNKNOWN); 3350b57cec5SDimitry Andric return TM.TargetABI == ARMBaseTargetMachine::ARM_ABI_AAPCS || 3360b57cec5SDimitry Andric TM.TargetABI == ARMBaseTargetMachine::ARM_ABI_AAPCS16; 3370b57cec5SDimitry Andric } 3380b57cec5SDimitry Andric bool ARMSubtarget::isAAPCS16_ABI() const { 3390b57cec5SDimitry Andric assert(TM.TargetABI != ARMBaseTargetMachine::ARM_ABI_UNKNOWN); 3400b57cec5SDimitry Andric return TM.TargetABI == ARMBaseTargetMachine::ARM_ABI_AAPCS16; 3410b57cec5SDimitry Andric } 3420b57cec5SDimitry Andric 3430b57cec5SDimitry Andric bool ARMSubtarget::isROPI() const { 3440b57cec5SDimitry Andric return TM.getRelocationModel() == Reloc::ROPI || 3450b57cec5SDimitry Andric TM.getRelocationModel() == Reloc::ROPI_RWPI; 3460b57cec5SDimitry Andric } 3470b57cec5SDimitry Andric bool ARMSubtarget::isRWPI() const { 3480b57cec5SDimitry Andric return TM.getRelocationModel() == Reloc::RWPI || 3490b57cec5SDimitry Andric TM.getRelocationModel() == Reloc::ROPI_RWPI; 3500b57cec5SDimitry Andric } 3510b57cec5SDimitry Andric 3520b57cec5SDimitry Andric bool ARMSubtarget::isGVIndirectSymbol(const GlobalValue *GV) const { 3530b57cec5SDimitry Andric if (!TM.shouldAssumeDSOLocal(*GV->getParent(), GV)) 3540b57cec5SDimitry Andric return true; 3550b57cec5SDimitry Andric 3560b57cec5SDimitry Andric // 32 bit macho has no relocation for a-b if a is undefined, even if b is in 3570b57cec5SDimitry Andric // the section that is being relocated. This means we have to use o load even 3580b57cec5SDimitry Andric // for GVs that are known to be local to the dso. 3590b57cec5SDimitry Andric if (isTargetMachO() && TM.isPositionIndependent() && 3600b57cec5SDimitry Andric (GV->isDeclarationForLinker() || GV->hasCommonLinkage())) 3610b57cec5SDimitry Andric return true; 3620b57cec5SDimitry Andric 3630b57cec5SDimitry Andric return false; 3640b57cec5SDimitry Andric } 3650b57cec5SDimitry Andric 3660b57cec5SDimitry Andric bool ARMSubtarget::isGVInGOT(const GlobalValue *GV) const { 3670b57cec5SDimitry Andric return isTargetELF() && TM.isPositionIndependent() && 3680b57cec5SDimitry Andric !TM.shouldAssumeDSOLocal(*GV->getParent(), GV); 3690b57cec5SDimitry Andric } 3700b57cec5SDimitry Andric 3710b57cec5SDimitry Andric unsigned ARMSubtarget::getMispredictionPenalty() const { 3720b57cec5SDimitry Andric return SchedModel.MispredictPenalty; 3730b57cec5SDimitry Andric } 3740b57cec5SDimitry Andric 3750b57cec5SDimitry Andric bool ARMSubtarget::enableMachineScheduler() const { 3760b57cec5SDimitry Andric // The MachineScheduler can increase register usage, so we use more high 3770b57cec5SDimitry Andric // registers and end up with more T2 instructions that cannot be converted to 3780b57cec5SDimitry Andric // T1 instructions. At least until we do better at converting to thumb1 3790b57cec5SDimitry Andric // instructions, on cortex-m at Oz where we are size-paranoid, don't use the 3800b57cec5SDimitry Andric // Machine scheduler, relying on the DAG register pressure scheduler instead. 3810b57cec5SDimitry Andric if (isMClass() && hasMinSize()) 3820b57cec5SDimitry Andric return false; 3830b57cec5SDimitry Andric // Enable the MachineScheduler before register allocation for subtargets 3840b57cec5SDimitry Andric // with the use-misched feature. 3850b57cec5SDimitry Andric return useMachineScheduler(); 3860b57cec5SDimitry Andric } 3870b57cec5SDimitry Andric 388349cc55cSDimitry Andric bool ARMSubtarget::enableSubRegLiveness() const { 389349cc55cSDimitry Andric if (EnableSubRegLiveness.getNumOccurrences()) 390349cc55cSDimitry Andric return EnableSubRegLiveness; 391349cc55cSDimitry Andric // Enable SubRegLiveness for MVE to better optimize s subregs for mqpr regs 392349cc55cSDimitry Andric // and q subregs for qqqqpr regs. 393349cc55cSDimitry Andric return hasMVEIntegerOps(); 394349cc55cSDimitry Andric } 395480093f4SDimitry Andric 396*81ad6265SDimitry Andric bool ARMSubtarget::enableMachinePipeliner() const { 397*81ad6265SDimitry Andric // Enable the MachinePipeliner before register allocation for subtargets 398*81ad6265SDimitry Andric // with the use-mipipeliner feature. 399*81ad6265SDimitry Andric return getSchedModel().hasInstrSchedModel() && useMachinePipeliner(); 400*81ad6265SDimitry Andric } 401*81ad6265SDimitry Andric 402*81ad6265SDimitry Andric bool ARMSubtarget::useDFAforSMS() const { return false; } 403*81ad6265SDimitry Andric 4040b57cec5SDimitry Andric // This overrides the PostRAScheduler bit in the SchedModel for any CPU. 4050b57cec5SDimitry Andric bool ARMSubtarget::enablePostRAScheduler() const { 406480093f4SDimitry Andric if (enableMachineScheduler()) 407480093f4SDimitry Andric return false; 4080b57cec5SDimitry Andric if (disablePostRAScheduler()) 4090b57cec5SDimitry Andric return false; 410480093f4SDimitry Andric // Thumb1 cores will generally not benefit from post-ra scheduling 411480093f4SDimitry Andric return !isThumb1Only(); 412480093f4SDimitry Andric } 413480093f4SDimitry Andric 414480093f4SDimitry Andric bool ARMSubtarget::enablePostRAMachineScheduler() const { 415480093f4SDimitry Andric if (!enableMachineScheduler()) 416480093f4SDimitry Andric return false; 417480093f4SDimitry Andric if (disablePostRAScheduler()) 418480093f4SDimitry Andric return false; 4190b57cec5SDimitry Andric return !isThumb1Only(); 4200b57cec5SDimitry Andric } 4210b57cec5SDimitry Andric 4220b57cec5SDimitry Andric bool ARMSubtarget::useStride4VFPs() const { 4230b57cec5SDimitry Andric // For general targets, the prologue can grow when VFPs are allocated with 4240b57cec5SDimitry Andric // stride 4 (more vpush instructions). But WatchOS uses a compact unwind 4250b57cec5SDimitry Andric // format which it's more important to get right. 4260b57cec5SDimitry Andric return isTargetWatchABI() || 4270b57cec5SDimitry Andric (useWideStrideVFP() && !OptMinSize); 4280b57cec5SDimitry Andric } 4290b57cec5SDimitry Andric 4300b57cec5SDimitry Andric bool ARMSubtarget::useMovt() const { 4310b57cec5SDimitry Andric // NOTE Windows on ARM needs to use mov.w/mov.t pairs to materialise 32-bit 4320b57cec5SDimitry Andric // immediates as it is inherently position independent, and may be out of 4330b57cec5SDimitry Andric // range otherwise. 4340b57cec5SDimitry Andric return !NoMovt && hasV8MBaselineOps() && 4350b57cec5SDimitry Andric (isTargetWindows() || !OptMinSize || genExecuteOnly()); 4360b57cec5SDimitry Andric } 4370b57cec5SDimitry Andric 4380b57cec5SDimitry Andric bool ARMSubtarget::useFastISel() const { 4390b57cec5SDimitry Andric // Enable fast-isel for any target, for testing only. 4400b57cec5SDimitry Andric if (ForceFastISel) 4410b57cec5SDimitry Andric return true; 4420b57cec5SDimitry Andric 4430b57cec5SDimitry Andric // Limit fast-isel to the targets that are or have been tested. 4440b57cec5SDimitry Andric if (!hasV6Ops()) 4450b57cec5SDimitry Andric return false; 4460b57cec5SDimitry Andric 4470b57cec5SDimitry Andric // Thumb2 support on iOS; ARM support on iOS, Linux and NaCl. 4480b57cec5SDimitry Andric return TM.Options.EnableFastISel && 4490b57cec5SDimitry Andric ((isTargetMachO() && !isThumb1Only()) || 4500b57cec5SDimitry Andric (isTargetLinux() && !isThumb()) || (isTargetNaCl() && !isThumb())); 4510b57cec5SDimitry Andric } 4520b57cec5SDimitry Andric 4530b57cec5SDimitry Andric unsigned ARMSubtarget::getGPRAllocationOrder(const MachineFunction &MF) const { 4540b57cec5SDimitry Andric // The GPR register class has multiple possible allocation orders, with 4550b57cec5SDimitry Andric // tradeoffs preferred by different sub-architectures and optimisation goals. 4560b57cec5SDimitry Andric // The allocation orders are: 4570b57cec5SDimitry Andric // 0: (the default tablegen order, not used) 4580b57cec5SDimitry Andric // 1: r14, r0-r13 4590b57cec5SDimitry Andric // 2: r0-r7 4600b57cec5SDimitry Andric // 3: r0-r7, r12, lr, r8-r11 4610b57cec5SDimitry Andric // Note that the register allocator will change this order so that 4620b57cec5SDimitry Andric // callee-saved registers are used later, as they require extra work in the 4630b57cec5SDimitry Andric // prologue/epilogue (though we sometimes override that). 4640b57cec5SDimitry Andric 4650b57cec5SDimitry Andric // For thumb1-only targets, only the low registers are allocatable. 4660b57cec5SDimitry Andric if (isThumb1Only()) 4670b57cec5SDimitry Andric return 2; 4680b57cec5SDimitry Andric 4690b57cec5SDimitry Andric // Allocate low registers first, so we can select more 16-bit instructions. 4700b57cec5SDimitry Andric // We also (in ignoreCSRForAllocationOrder) override the default behaviour 4710b57cec5SDimitry Andric // with regards to callee-saved registers, because pushing extra registers is 4720b57cec5SDimitry Andric // much cheaper (in terms of code size) than using high registers. After 4730b57cec5SDimitry Andric // that, we allocate r12 (doesn't need to be saved), lr (saving it means we 4740b57cec5SDimitry Andric // can return with the pop, don't need an extra "bx lr") and then the rest of 4750b57cec5SDimitry Andric // the high registers. 4760b57cec5SDimitry Andric if (isThumb2() && MF.getFunction().hasMinSize()) 4770b57cec5SDimitry Andric return 3; 4780b57cec5SDimitry Andric 4790b57cec5SDimitry Andric // Otherwise, allocate in the default order, using LR first because saving it 4800b57cec5SDimitry Andric // allows a shorter epilogue sequence. 4810b57cec5SDimitry Andric return 1; 4820b57cec5SDimitry Andric } 4830b57cec5SDimitry Andric 4840b57cec5SDimitry Andric bool ARMSubtarget::ignoreCSRForAllocationOrder(const MachineFunction &MF, 4850b57cec5SDimitry Andric unsigned PhysReg) const { 4860b57cec5SDimitry Andric // To minimize code size in Thumb2, we prefer the usage of low regs (lower 4870b57cec5SDimitry Andric // cost per use) so we can use narrow encoding. By default, caller-saved 4880b57cec5SDimitry Andric // registers (e.g. lr, r12) are always allocated first, regardless of 4890b57cec5SDimitry Andric // their cost per use. When optForMinSize, we prefer the low regs even if 4900b57cec5SDimitry Andric // they are CSR because usually push/pop can be folded into existing ones. 4910b57cec5SDimitry Andric return isThumb2() && MF.getFunction().hasMinSize() && 4920b57cec5SDimitry Andric ARM::GPRRegClass.contains(PhysReg); 4930b57cec5SDimitry Andric } 494*81ad6265SDimitry Andric 495*81ad6265SDimitry Andric bool ARMSubtarget::splitFramePointerPush(const MachineFunction &MF) const { 496*81ad6265SDimitry Andric const Function &F = MF.getFunction(); 497*81ad6265SDimitry Andric if (!MF.getTarget().getMCAsmInfo()->usesWindowsCFI() || 498*81ad6265SDimitry Andric !F.needsUnwindTableEntry()) 499*81ad6265SDimitry Andric return false; 500*81ad6265SDimitry Andric const MachineFrameInfo &MFI = MF.getFrameInfo(); 501*81ad6265SDimitry Andric return MFI.hasVarSizedObjects() || getRegisterInfo()->hasStackRealignment(MF); 502*81ad6265SDimitry Andric } 503