Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 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 | |
Rafael Espindola | 6b4baa5 | 2016-05-25 21:37:29 +0000 | [diff] [blame] | 14 | #include "AArch64Subtarget.h" |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 15 | #include "AArch64InstrInfo.h" |
Lang Hames | 8f31f44 | 2014-10-09 18:20:51 +0000 | [diff] [blame] | 16 | #include "AArch64PBQPRegAlloc.h" |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 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 | |
Tim Northover | 339c83e | 2015-11-10 00:44:23 +0000 | [diff] [blame] | 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 | |
Eric Christopher | 7c9d4e0 | 2014-06-11 00:46:34 +0000 | [diff] [blame] | 38 | AArch64Subtarget & |
Matthias Braun | a827ed8 | 2016-10-03 20:17:02 +0000 | [diff] [blame] | 39 | AArch64Subtarget::initializeSubtargetDependencies(StringRef FS, |
| 40 | StringRef CPUString) { |
Eric Christopher | 7c9d4e0 | 2014-06-11 00:46:34 +0000 | [diff] [blame] | 41 | // Determine default and user-specified characteristics |
| 42 | |
| 43 | if (CPUString.empty()) |
| 44 | CPUString = "generic"; |
| 45 | |
| 46 | ParseSubtargetFeatures(CPUString, FS); |
Matthias Braun | 651cff4 | 2016-06-02 18:03:53 +0000 | [diff] [blame] | 47 | initializeProperties(); |
| 48 | |
Eric Christopher | 7c9d4e0 | 2014-06-11 00:46:34 +0000 | [diff] [blame] | 49 | return *this; |
| 50 | } |
| 51 | |
Matthias Braun | 651cff4 | 2016-06-02 18:03:53 +0000 | [diff] [blame] | 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; |
Evandro Menezes | a3a0a60 | 2016-06-10 16:00:18 +0000 | [diff] [blame] | 66 | case ExynosM1: |
Abderrazek Zaafrani | 9daf811 | 2016-10-21 16:28:27 +0000 | [diff] [blame] | 67 | MaxInterleaveFactor = 4; |
Evandro Menezes | 7696dc0 | 2016-10-25 20:05:42 +0000 | [diff] [blame] | 68 | MaxJumpTableSize = 8; |
Evandro Menezes | a3a0a60 | 2016-06-10 16:00:18 +0000 | [diff] [blame] | 69 | PrefFunctionAlignment = 4; |
| 70 | PrefLoopAlignment = 3; |
| 71 | break; |
Chad Rosier | ecc7727 | 2016-11-22 14:25:02 +0000 | [diff] [blame] | 72 | case Falkor: |
| 73 | MaxInterleaveFactor = 4; |
| 74 | break; |
Matthias Braun | 651cff4 | 2016-06-02 18:03:53 +0000 | [diff] [blame] | 75 | case Kryo: |
| 76 | MaxInterleaveFactor = 4; |
| 77 | VectorInsertExtractBaseCost = 2; |
Haicheng Wu | a783bac | 2016-06-21 22:47:56 +0000 | [diff] [blame] | 78 | CacheLineSize = 128; |
| 79 | PrefetchDistance = 740; |
| 80 | MinPrefetchStride = 1024; |
| 81 | MaxPrefetchIterationsAhead = 11; |
Matthias Braun | 651cff4 | 2016-06-02 18:03:53 +0000 | [diff] [blame] | 82 | break; |
Junmo Park | 5e4bd2e | 2016-07-06 23:15:18 +0000 | [diff] [blame] | 83 | case Vulcan: |
Pankaj Gode | f4b2554 | 2016-06-30 06:42:31 +0000 | [diff] [blame] | 84 | MaxInterleaveFactor = 4; |
| 85 | break; |
Matthias Braun | 651cff4 | 2016-06-02 18:03:53 +0000 | [diff] [blame] | 86 | case CortexA35: break; |
| 87 | case CortexA53: break; |
Silviu Baranga | aee40fc | 2016-06-21 15:53:54 +0000 | [diff] [blame] | 88 | case CortexA72: break; |
| 89 | case CortexA73: break; |
Evandro Menezes | a3a0a60 | 2016-06-10 16:00:18 +0000 | [diff] [blame] | 90 | case Others: break; |
Matthias Braun | 651cff4 | 2016-06-02 18:03:53 +0000 | [diff] [blame] | 91 | } |
| 92 | } |
| 93 | |
Daniel Sanders | a73f1fd | 2015-06-10 12:11:26 +0000 | [diff] [blame] | 94 | AArch64Subtarget::AArch64Subtarget(const Triple &TT, const std::string &CPU, |
Eric Christopher | f12e1ab | 2014-10-03 00:42:41 +0000 | [diff] [blame] | 95 | const std::string &FS, |
Eric Christopher | a0de253 | 2015-03-18 20:37:30 +0000 | [diff] [blame] | 96 | const TargetMachine &TM, bool LittleEndian) |
Matthias Braun | 27b6692 | 2016-05-27 22:14:09 +0000 | [diff] [blame] | 97 | : AArch64GenSubtargetInfo(TT, CPU, FS), ReserveX18(TT.isOSDarwin()), |
Matthias Braun | a827ed8 | 2016-10-03 20:17:02 +0000 | [diff] [blame] | 98 | IsLittle(LittleEndian), TargetTriple(TT), FrameLowering(), |
| 99 | InstrInfo(initializeSubtargetDependencies(FS, CPU)), TSInfo(), |
Tom Stellard | cef0fe4 | 2016-04-14 17:45:38 +0000 | [diff] [blame] | 100 | TLInfo(TM, *this), GISel() {} |
Quentin Colombet | ba2a016 | 2016-02-16 19:26:02 +0000 | [diff] [blame] | 101 | |
| 102 | const CallLowering *AArch64Subtarget::getCallLowering() const { |
Tom Stellard | cef0fe4 | 2016-04-14 17:45:38 +0000 | [diff] [blame] | 103 | assert(GISel && "Access to GlobalISel APIs not set"); |
| 104 | return GISel->getCallLowering(); |
Quentin Colombet | c17f744 | 2016-04-06 17:26:03 +0000 | [diff] [blame] | 105 | } |
| 106 | |
Ahmed Bougacha | 6756a2c | 2016-07-27 14:31:55 +0000 | [diff] [blame] | 107 | const InstructionSelector *AArch64Subtarget::getInstructionSelector() const { |
| 108 | assert(GISel && "Access to GlobalISel APIs not set"); |
| 109 | return GISel->getInstructionSelector(); |
| 110 | } |
| 111 | |
Tim Northover | 69fa84a | 2016-10-14 22:18:18 +0000 | [diff] [blame] | 112 | const LegalizerInfo *AArch64Subtarget::getLegalizerInfo() const { |
Tim Northover | 33b07d6 | 2016-07-22 20:03:43 +0000 | [diff] [blame] | 113 | assert(GISel && "Access to GlobalISel APIs not set"); |
Tim Northover | 69fa84a | 2016-10-14 22:18:18 +0000 | [diff] [blame] | 114 | return GISel->getLegalizerInfo(); |
Tim Northover | 33b07d6 | 2016-07-22 20:03:43 +0000 | [diff] [blame] | 115 | } |
| 116 | |
Quentin Colombet | c17f744 | 2016-04-06 17:26:03 +0000 | [diff] [blame] | 117 | const RegisterBankInfo *AArch64Subtarget::getRegBankInfo() const { |
Tom Stellard | cef0fe4 | 2016-04-14 17:45:38 +0000 | [diff] [blame] | 118 | assert(GISel && "Access to GlobalISel APIs not set"); |
| 119 | return GISel->getRegBankInfo(); |
Quentin Colombet | ba2a016 | 2016-02-16 19:26:02 +0000 | [diff] [blame] | 120 | } |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 121 | |
Rafael Espindola | 6b93bf5 | 2016-05-25 22:44:06 +0000 | [diff] [blame] | 122 | /// Find the target operand flags that describe how a global value should be |
| 123 | /// referenced for the current subtarget. |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 124 | unsigned char |
| 125 | AArch64Subtarget::ClassifyGlobalReference(const GlobalValue *GV, |
Rafael Espindola | 6b93bf5 | 2016-05-25 22:44:06 +0000 | [diff] [blame] | 126 | const TargetMachine &TM) const { |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 127 | // MachO large model always goes via a GOT, simply to get a single 8-byte |
| 128 | // absolute relocation on all global addresses. |
| 129 | if (TM.getCodeModel() == CodeModel::Large && isTargetMachO()) |
| 130 | return AArch64II::MO_GOT; |
| 131 | |
Rafael Espindola | 3beef8d | 2016-06-27 23:15:57 +0000 | [diff] [blame] | 132 | if (!TM.shouldAssumeDSOLocal(*GV->getParent(), GV)) |
Rafael Espindola | a224de0 | 2016-05-26 12:42:55 +0000 | [diff] [blame] | 133 | return AArch64II::MO_GOT; |
| 134 | |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 135 | // The small code mode's direct accesses use ADRP, which cannot necessarily |
Asiri Rathnayake | 369c030 | 2014-09-10 13:54:38 +0000 | [diff] [blame] | 136 | // produce the value 0 (if the code is above 4GB). |
Rafael Espindola | 4d29099 | 2016-05-31 18:31:14 +0000 | [diff] [blame] | 137 | if (TM.getCodeModel() == CodeModel::Small && GV->hasExternalWeakLinkage()) |
| 138 | return AArch64II::MO_GOT; |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 139 | |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 140 | return AArch64II::MO_NO_FLAG; |
| 141 | } |
| 142 | |
| 143 | /// This function returns the name of a function which has an interface |
| 144 | /// like the non-standard bzero function, if such a function exists on |
| 145 | /// the current subtarget and it is considered prefereable over |
| 146 | /// memset with zero passed as the second argument. Otherwise it |
| 147 | /// returns null. |
| 148 | const char *AArch64Subtarget::getBZeroEntry() const { |
| 149 | // Prefer bzero on Darwin only. |
| 150 | if(isTargetDarwin()) |
| 151 | return "bzero"; |
| 152 | |
| 153 | return nullptr; |
| 154 | } |
| 155 | |
| 156 | void AArch64Subtarget::overrideSchedPolicy(MachineSchedPolicy &Policy, |
Duncan P. N. Exon Smith | 6329872 | 2016-07-01 00:23:27 +0000 | [diff] [blame] | 157 | unsigned NumRegionInstrs) const { |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 158 | // LNT run (at least on Cyclone) showed reasonably significant gains for |
| 159 | // bi-directional scheduling. 253.perlbmk. |
| 160 | Policy.OnlyTopDown = false; |
| 161 | Policy.OnlyBottomUp = false; |
Matthias Braun | d276de6 | 2015-10-22 18:07:38 +0000 | [diff] [blame] | 162 | // Enabling or Disabling the latency heuristic is a close call: It seems to |
| 163 | // help nearly no benchmark on out-of-order architectures, on the other hand |
| 164 | // it regresses register pressure on a few benchmarking. |
Matthias Braun | 651cff4 | 2016-06-02 18:03:53 +0000 | [diff] [blame] | 165 | Policy.DisableLatencyHeuristic = DisableLatencySchedHeuristic; |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | bool AArch64Subtarget::enableEarlyIfConversion() const { |
| 169 | return EnableEarlyIfConvert; |
| 170 | } |
Lang Hames | 8f31f44 | 2014-10-09 18:20:51 +0000 | [diff] [blame] | 171 | |
Tim Northover | 339c83e | 2015-11-10 00:44:23 +0000 | [diff] [blame] | 172 | bool AArch64Subtarget::supportsAddressTopByteIgnored() const { |
| 173 | if (!UseAddressTopByteIgnored) |
| 174 | return false; |
| 175 | |
| 176 | if (TargetTriple.isiOS()) { |
| 177 | unsigned Major, Minor, Micro; |
| 178 | TargetTriple.getiOSVersion(Major, Minor, Micro); |
| 179 | return Major >= 8; |
| 180 | } |
| 181 | |
| 182 | return false; |
| 183 | } |
| 184 | |
Lang Hames | 8f31f44 | 2014-10-09 18:20:51 +0000 | [diff] [blame] | 185 | std::unique_ptr<PBQPRAConstraint> |
| 186 | AArch64Subtarget::getCustomPBQPConstraints() const { |
Matthias Braun | 651cff4 | 2016-06-02 18:03:53 +0000 | [diff] [blame] | 187 | return balanceFPOps() ? llvm::make_unique<A57ChainingConstraint>() : nullptr; |
Lang Hames | 8f31f44 | 2014-10-09 18:20:51 +0000 | [diff] [blame] | 188 | } |