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" |
Rafael Espindola | a224de0 | 2016-05-26 12:42:55 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/Analysis.h" |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/MachineScheduler.h" |
| 19 | #include "llvm/IR/GlobalValue.h" |
| 20 | #include "llvm/Support/TargetRegistry.h" |
| 21 | |
| 22 | using namespace llvm; |
| 23 | |
| 24 | #define DEBUG_TYPE "aarch64-subtarget" |
| 25 | |
| 26 | #define GET_SUBTARGETINFO_CTOR |
| 27 | #define GET_SUBTARGETINFO_TARGET_DESC |
| 28 | #include "AArch64GenSubtargetInfo.inc" |
| 29 | |
| 30 | static cl::opt<bool> |
| 31 | EnableEarlyIfConvert("aarch64-early-ifcvt", cl::desc("Enable the early if " |
| 32 | "converter pass"), cl::init(true), cl::Hidden); |
| 33 | |
Tim Northover | 339c83e | 2015-11-10 00:44:23 +0000 | [diff] [blame] | 34 | // If OS supports TBI, use this flag to enable it. |
| 35 | static cl::opt<bool> |
| 36 | UseAddressTopByteIgnored("aarch64-use-tbi", cl::desc("Assume that top byte of " |
| 37 | "an address is ignored"), cl::init(false), cl::Hidden); |
| 38 | |
Eric Christopher | 7c9d4e0 | 2014-06-11 00:46:34 +0000 | [diff] [blame] | 39 | AArch64Subtarget & |
| 40 | AArch64Subtarget::initializeSubtargetDependencies(StringRef FS) { |
| 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: |
| 67 | PrefFunctionAlignment = 4; |
| 68 | PrefLoopAlignment = 3; |
| 69 | break; |
Matthias Braun | 651cff4 | 2016-06-02 18:03:53 +0000 | [diff] [blame] | 70 | case Kryo: |
| 71 | MaxInterleaveFactor = 4; |
| 72 | VectorInsertExtractBaseCost = 2; |
| 73 | break; |
Pankaj Gode | 0aab2e3 | 2016-06-20 11:13:31 +0000 | [diff] [blame] | 74 | case Vulcan: break; |
Matthias Braun | 651cff4 | 2016-06-02 18:03:53 +0000 | [diff] [blame] | 75 | case CortexA35: break; |
| 76 | case CortexA53: break; |
Silviu Baranga | aee40fc | 2016-06-21 15:53:54 +0000 | [diff] [blame^] | 77 | case CortexA72: break; |
| 78 | case CortexA73: break; |
Evandro Menezes | a3a0a60 | 2016-06-10 16:00:18 +0000 | [diff] [blame] | 79 | case Others: break; |
Matthias Braun | 651cff4 | 2016-06-02 18:03:53 +0000 | [diff] [blame] | 80 | } |
| 81 | } |
| 82 | |
Daniel Sanders | a73f1fd | 2015-06-10 12:11:26 +0000 | [diff] [blame] | 83 | AArch64Subtarget::AArch64Subtarget(const Triple &TT, const std::string &CPU, |
Eric Christopher | f12e1ab | 2014-10-03 00:42:41 +0000 | [diff] [blame] | 84 | const std::string &FS, |
Eric Christopher | a0de253 | 2015-03-18 20:37:30 +0000 | [diff] [blame] | 85 | const TargetMachine &TM, bool LittleEndian) |
Matthias Braun | 27b6692 | 2016-05-27 22:14:09 +0000 | [diff] [blame] | 86 | : AArch64GenSubtargetInfo(TT, CPU, FS), ReserveX18(TT.isOSDarwin()), |
| 87 | IsLittle(LittleEndian), CPUString(CPU), TargetTriple(TT), FrameLowering(), |
Mehdi Amini | 157e5a6 | 2015-07-09 02:10:08 +0000 | [diff] [blame] | 88 | InstrInfo(initializeSubtargetDependencies(FS)), TSInfo(), |
Tom Stellard | cef0fe4 | 2016-04-14 17:45:38 +0000 | [diff] [blame] | 89 | TLInfo(TM, *this), GISel() {} |
Quentin Colombet | ba2a016 | 2016-02-16 19:26:02 +0000 | [diff] [blame] | 90 | |
| 91 | const CallLowering *AArch64Subtarget::getCallLowering() const { |
Tom Stellard | cef0fe4 | 2016-04-14 17:45:38 +0000 | [diff] [blame] | 92 | assert(GISel && "Access to GlobalISel APIs not set"); |
| 93 | return GISel->getCallLowering(); |
Quentin Colombet | c17f744 | 2016-04-06 17:26:03 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | const RegisterBankInfo *AArch64Subtarget::getRegBankInfo() const { |
Tom Stellard | cef0fe4 | 2016-04-14 17:45:38 +0000 | [diff] [blame] | 97 | assert(GISel && "Access to GlobalISel APIs not set"); |
| 98 | return GISel->getRegBankInfo(); |
Quentin Colombet | ba2a016 | 2016-02-16 19:26:02 +0000 | [diff] [blame] | 99 | } |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 100 | |
Rafael Espindola | 6b93bf5 | 2016-05-25 22:44:06 +0000 | [diff] [blame] | 101 | /// Find the target operand flags that describe how a global value should be |
| 102 | /// referenced for the current subtarget. |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 103 | unsigned char |
| 104 | AArch64Subtarget::ClassifyGlobalReference(const GlobalValue *GV, |
Rafael Espindola | 6b93bf5 | 2016-05-25 22:44:06 +0000 | [diff] [blame] | 105 | const TargetMachine &TM) const { |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 106 | // MachO large model always goes via a GOT, simply to get a single 8-byte |
| 107 | // absolute relocation on all global addresses. |
| 108 | if (TM.getCodeModel() == CodeModel::Large && isTargetMachO()) |
| 109 | return AArch64II::MO_GOT; |
| 110 | |
Rafael Espindola | a224de0 | 2016-05-26 12:42:55 +0000 | [diff] [blame] | 111 | Reloc::Model RM = TM.getRelocationModel(); |
| 112 | if (!shouldAssumeDSOLocal(RM, TargetTriple, *GV->getParent(), GV)) |
| 113 | return AArch64II::MO_GOT; |
| 114 | |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 115 | // The small code mode's direct accesses use ADRP, which cannot necessarily |
Asiri Rathnayake | 369c030 | 2014-09-10 13:54:38 +0000 | [diff] [blame] | 116 | // produce the value 0 (if the code is above 4GB). |
Rafael Espindola | 4d29099 | 2016-05-31 18:31:14 +0000 | [diff] [blame] | 117 | if (TM.getCodeModel() == CodeModel::Small && GV->hasExternalWeakLinkage()) |
| 118 | return AArch64II::MO_GOT; |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 119 | |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 120 | return AArch64II::MO_NO_FLAG; |
| 121 | } |
| 122 | |
| 123 | /// This function returns the name of a function which has an interface |
| 124 | /// like the non-standard bzero function, if such a function exists on |
| 125 | /// the current subtarget and it is considered prefereable over |
| 126 | /// memset with zero passed as the second argument. Otherwise it |
| 127 | /// returns null. |
| 128 | const char *AArch64Subtarget::getBZeroEntry() const { |
| 129 | // Prefer bzero on Darwin only. |
| 130 | if(isTargetDarwin()) |
| 131 | return "bzero"; |
| 132 | |
| 133 | return nullptr; |
| 134 | } |
| 135 | |
| 136 | void AArch64Subtarget::overrideSchedPolicy(MachineSchedPolicy &Policy, |
| 137 | MachineInstr *begin, MachineInstr *end, |
| 138 | unsigned NumRegionInstrs) const { |
| 139 | // LNT run (at least on Cyclone) showed reasonably significant gains for |
| 140 | // bi-directional scheduling. 253.perlbmk. |
| 141 | Policy.OnlyTopDown = false; |
| 142 | Policy.OnlyBottomUp = false; |
Matthias Braun | d276de6 | 2015-10-22 18:07:38 +0000 | [diff] [blame] | 143 | // Enabling or Disabling the latency heuristic is a close call: It seems to |
| 144 | // help nearly no benchmark on out-of-order architectures, on the other hand |
| 145 | // it regresses register pressure on a few benchmarking. |
Matthias Braun | 651cff4 | 2016-06-02 18:03:53 +0000 | [diff] [blame] | 146 | Policy.DisableLatencyHeuristic = DisableLatencySchedHeuristic; |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | bool AArch64Subtarget::enableEarlyIfConversion() const { |
| 150 | return EnableEarlyIfConvert; |
| 151 | } |
Lang Hames | 8f31f44 | 2014-10-09 18:20:51 +0000 | [diff] [blame] | 152 | |
Tim Northover | 339c83e | 2015-11-10 00:44:23 +0000 | [diff] [blame] | 153 | bool AArch64Subtarget::supportsAddressTopByteIgnored() const { |
| 154 | if (!UseAddressTopByteIgnored) |
| 155 | return false; |
| 156 | |
| 157 | if (TargetTriple.isiOS()) { |
| 158 | unsigned Major, Minor, Micro; |
| 159 | TargetTriple.getiOSVersion(Major, Minor, Micro); |
| 160 | return Major >= 8; |
| 161 | } |
| 162 | |
| 163 | return false; |
| 164 | } |
| 165 | |
Lang Hames | 8f31f44 | 2014-10-09 18:20:51 +0000 | [diff] [blame] | 166 | std::unique_ptr<PBQPRAConstraint> |
| 167 | AArch64Subtarget::getCustomPBQPConstraints() const { |
Matthias Braun | 651cff4 | 2016-06-02 18:03:53 +0000 | [diff] [blame] | 168 | return balanceFPOps() ? llvm::make_unique<A57ChainingConstraint>() : nullptr; |
Lang Hames | 8f31f44 | 2014-10-09 18:20:51 +0000 | [diff] [blame] | 169 | } |