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 MaxJumpTableSize = 8; 69 PrefFunctionAlignment = 4; 70 PrefLoopAlignment = 3; 71 break; 72 case Falkor: 73 MaxInterleaveFactor = 4; 74 VectorInsertExtractBaseCost = 2; 75 break; 76 case Kryo: 77 MaxInterleaveFactor = 4; 78 VectorInsertExtractBaseCost = 2; 79 CacheLineSize = 128; 80 PrefetchDistance = 740; 81 MinPrefetchStride = 1024; 82 MaxPrefetchIterationsAhead = 11; 83 break; 84 case Vulcan: 85 MaxInterleaveFactor = 4; 86 break; 87 case ThunderX: 88 case ThunderXT88: 89 case ThunderXT81: 90 case ThunderXT83: 91 CacheLineSize = 128; 92 PrefFunctionAlignment = 4; 93 PrefLoopAlignment = 4; 94 break; 95 case CortexA35: break; 96 case CortexA53: break; 97 case CortexA72: break; 98 case CortexA73: break; 99 case Others: break; 100 } 101 } 102 103 AArch64Subtarget::AArch64Subtarget(const Triple &TT, const std::string &CPU, 104 const std::string &FS, 105 const TargetMachine &TM, bool LittleEndian) 106 : AArch64GenSubtargetInfo(TT, CPU, FS), ReserveX18(TT.isOSDarwin()), 107 IsLittle(LittleEndian), TargetTriple(TT), FrameLowering(), 108 InstrInfo(initializeSubtargetDependencies(FS, CPU)), TSInfo(), 109 TLInfo(TM, *this), GISel() {} 110 111 const CallLowering *AArch64Subtarget::getCallLowering() const { 112 assert(GISel && "Access to GlobalISel APIs not set"); 113 return GISel->getCallLowering(); 114 } 115 116 const InstructionSelector *AArch64Subtarget::getInstructionSelector() const { 117 assert(GISel && "Access to GlobalISel APIs not set"); 118 return GISel->getInstructionSelector(); 119 } 120 121 const LegalizerInfo *AArch64Subtarget::getLegalizerInfo() const { 122 assert(GISel && "Access to GlobalISel APIs not set"); 123 return GISel->getLegalizerInfo(); 124 } 125 126 const RegisterBankInfo *AArch64Subtarget::getRegBankInfo() const { 127 assert(GISel && "Access to GlobalISel APIs not set"); 128 return GISel->getRegBankInfo(); 129 } 130 131 /// Find the target operand flags that describe how a global value should be 132 /// referenced for the current subtarget. 133 unsigned char 134 AArch64Subtarget::ClassifyGlobalReference(const GlobalValue *GV, 135 const TargetMachine &TM) const { 136 // MachO large model always goes via a GOT, simply to get a single 8-byte 137 // absolute relocation on all global addresses. 138 if (TM.getCodeModel() == CodeModel::Large && isTargetMachO()) 139 return AArch64II::MO_GOT; 140 141 if (!TM.shouldAssumeDSOLocal(*GV->getParent(), GV)) 142 return AArch64II::MO_GOT; 143 144 // The small code mode's direct accesses use ADRP, which cannot necessarily 145 // produce the value 0 (if the code is above 4GB). 146 if (TM.getCodeModel() == CodeModel::Small && GV->hasExternalWeakLinkage()) 147 return AArch64II::MO_GOT; 148 149 return AArch64II::MO_NO_FLAG; 150 } 151 152 /// This function returns the name of a function which has an interface 153 /// like the non-standard bzero function, if such a function exists on 154 /// the current subtarget and it is considered prefereable over 155 /// memset with zero passed as the second argument. Otherwise it 156 /// returns null. 157 const char *AArch64Subtarget::getBZeroEntry() const { 158 // Prefer bzero on Darwin only. 159 if(isTargetDarwin()) 160 return "bzero"; 161 162 return nullptr; 163 } 164 165 void AArch64Subtarget::overrideSchedPolicy(MachineSchedPolicy &Policy, 166 unsigned NumRegionInstrs) const { 167 // LNT run (at least on Cyclone) showed reasonably significant gains for 168 // bi-directional scheduling. 253.perlbmk. 169 Policy.OnlyTopDown = false; 170 Policy.OnlyBottomUp = false; 171 // Enabling or Disabling the latency heuristic is a close call: It seems to 172 // help nearly no benchmark on out-of-order architectures, on the other hand 173 // it regresses register pressure on a few benchmarking. 174 Policy.DisableLatencyHeuristic = DisableLatencySchedHeuristic; 175 } 176 177 bool AArch64Subtarget::enableEarlyIfConversion() const { 178 return EnableEarlyIfConvert; 179 } 180 181 bool AArch64Subtarget::supportsAddressTopByteIgnored() const { 182 if (!UseAddressTopByteIgnored) 183 return false; 184 185 if (TargetTriple.isiOS()) { 186 unsigned Major, Minor, Micro; 187 TargetTriple.getiOSVersion(Major, Minor, Micro); 188 return Major >= 8; 189 } 190 191 return false; 192 } 193 194 std::unique_ptr<PBQPRAConstraint> 195 AArch64Subtarget::getCustomPBQPConstraints() const { 196 return balanceFPOps() ? llvm::make_unique<A57ChainingConstraint>() : nullptr; 197 } 198