1 //===-- AArch64Subtarget.cpp - AArch64 Subtarget Information ----*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file implements the AArch64 specific subclass of TargetSubtarget. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "AArch64Subtarget.h" 15 #include "AArch64InstrInfo.h" 16 #include "AArch64PBQPRegAlloc.h" 17 #include "llvm/CodeGen/MachineScheduler.h" 18 #include "llvm/IR/GlobalValue.h" 19 #include "llvm/Support/TargetRegistry.h" 20 21 using namespace llvm; 22 23 #define DEBUG_TYPE "aarch64-subtarget" 24 25 #define GET_SUBTARGETINFO_CTOR 26 #define GET_SUBTARGETINFO_TARGET_DESC 27 #include "AArch64GenSubtargetInfo.inc" 28 29 static cl::opt<bool> 30 EnableEarlyIfConvert("aarch64-early-ifcvt", cl::desc("Enable the early if " 31 "converter pass"), cl::init(true), cl::Hidden); 32 33 // If OS supports TBI, use this flag to enable it. 34 static cl::opt<bool> 35 UseAddressTopByteIgnored("aarch64-use-tbi", cl::desc("Assume that top byte of " 36 "an address is ignored"), cl::init(false), cl::Hidden); 37 38 AArch64Subtarget & 39 AArch64Subtarget::initializeSubtargetDependencies(StringRef FS, 40 StringRef CPUString) { 41 // Determine default and user-specified characteristics 42 43 if (CPUString.empty()) 44 CPUString = "generic"; 45 46 ParseSubtargetFeatures(CPUString, FS); 47 initializeProperties(); 48 49 return *this; 50 } 51 52 void AArch64Subtarget::initializeProperties() { 53 // Initialize CPU specific properties. We should add a tablegen feature for 54 // this in the future so we can specify it together with the subtarget 55 // features. 56 switch (ARMProcFamily) { 57 case Cyclone: 58 CacheLineSize = 64; 59 PrefetchDistance = 280; 60 MinPrefetchStride = 2048; 61 MaxPrefetchIterationsAhead = 3; 62 break; 63 case CortexA57: 64 MaxInterleaveFactor = 4; 65 break; 66 case ExynosM1: 67 MaxInterleaveFactor = 4; 68 PrefFunctionAlignment = 4; 69 PrefLoopAlignment = 3; 70 MaxJumpTableSize = 12; 71 break; 72 case Kryo: 73 MaxInterleaveFactor = 4; 74 VectorInsertExtractBaseCost = 2; 75 CacheLineSize = 128; 76 PrefetchDistance = 740; 77 MinPrefetchStride = 1024; 78 MaxPrefetchIterationsAhead = 11; 79 break; 80 case Vulcan: 81 MaxInterleaveFactor = 4; 82 break; 83 case CortexA35: break; 84 case CortexA53: break; 85 case CortexA72: break; 86 case CortexA73: break; 87 case Others: break; 88 } 89 } 90 91 AArch64Subtarget::AArch64Subtarget(const Triple &TT, const std::string &CPU, 92 const std::string &FS, 93 const TargetMachine &TM, bool LittleEndian) 94 : AArch64GenSubtargetInfo(TT, CPU, FS), ReserveX18(TT.isOSDarwin()), 95 IsLittle(LittleEndian), TargetTriple(TT), FrameLowering(), 96 InstrInfo(initializeSubtargetDependencies(FS, CPU)), TSInfo(), 97 TLInfo(TM, *this), GISel() {} 98 99 const CallLowering *AArch64Subtarget::getCallLowering() const { 100 assert(GISel && "Access to GlobalISel APIs not set"); 101 return GISel->getCallLowering(); 102 } 103 104 const InstructionSelector *AArch64Subtarget::getInstructionSelector() const { 105 assert(GISel && "Access to GlobalISel APIs not set"); 106 return GISel->getInstructionSelector(); 107 } 108 109 const LegalizerInfo *AArch64Subtarget::getLegalizerInfo() const { 110 assert(GISel && "Access to GlobalISel APIs not set"); 111 return GISel->getLegalizerInfo(); 112 } 113 114 const RegisterBankInfo *AArch64Subtarget::getRegBankInfo() const { 115 assert(GISel && "Access to GlobalISel APIs not set"); 116 return GISel->getRegBankInfo(); 117 } 118 119 /// Find the target operand flags that describe how a global value should be 120 /// referenced for the current subtarget. 121 unsigned char 122 AArch64Subtarget::ClassifyGlobalReference(const GlobalValue *GV, 123 const TargetMachine &TM) const { 124 // MachO large model always goes via a GOT, simply to get a single 8-byte 125 // absolute relocation on all global addresses. 126 if (TM.getCodeModel() == CodeModel::Large && isTargetMachO()) 127 return AArch64II::MO_GOT; 128 129 if (!TM.shouldAssumeDSOLocal(*GV->getParent(), GV)) 130 return AArch64II::MO_GOT; 131 132 // The small code mode's direct accesses use ADRP, which cannot necessarily 133 // produce the value 0 (if the code is above 4GB). 134 if (TM.getCodeModel() == CodeModel::Small && GV->hasExternalWeakLinkage()) 135 return AArch64II::MO_GOT; 136 137 return AArch64II::MO_NO_FLAG; 138 } 139 140 /// This function returns the name of a function which has an interface 141 /// like the non-standard bzero function, if such a function exists on 142 /// the current subtarget and it is considered prefereable over 143 /// memset with zero passed as the second argument. Otherwise it 144 /// returns null. 145 const char *AArch64Subtarget::getBZeroEntry() const { 146 // Prefer bzero on Darwin only. 147 if(isTargetDarwin()) 148 return "bzero"; 149 150 return nullptr; 151 } 152 153 void AArch64Subtarget::overrideSchedPolicy(MachineSchedPolicy &Policy, 154 unsigned NumRegionInstrs) const { 155 // LNT run (at least on Cyclone) showed reasonably significant gains for 156 // bi-directional scheduling. 253.perlbmk. 157 Policy.OnlyTopDown = false; 158 Policy.OnlyBottomUp = false; 159 // Enabling or Disabling the latency heuristic is a close call: It seems to 160 // help nearly no benchmark on out-of-order architectures, on the other hand 161 // it regresses register pressure on a few benchmarking. 162 Policy.DisableLatencyHeuristic = DisableLatencySchedHeuristic; 163 } 164 165 bool AArch64Subtarget::enableEarlyIfConversion() const { 166 return EnableEarlyIfConvert; 167 } 168 169 bool AArch64Subtarget::supportsAddressTopByteIgnored() const { 170 if (!UseAddressTopByteIgnored) 171 return false; 172 173 if (TargetTriple.isiOS()) { 174 unsigned Major, Minor, Micro; 175 TargetTriple.getiOSVersion(Major, Minor, Micro); 176 return Major >= 8; 177 } 178 179 return false; 180 } 181 182 std::unique_ptr<PBQPRAConstraint> 183 AArch64Subtarget::getCustomPBQPConstraints() const { 184 return balanceFPOps() ? llvm::make_unique<A57ChainingConstraint>() : nullptr; 185 } 186