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 | |
| 14 | #include "AArch64InstrInfo.h" |
| 15 | #include "AArch64Subtarget.h" |
| 16 | #include "llvm/ADT/SmallVector.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 | |
Eric Christopher | 7c9d4e0 | 2014-06-11 00:46:34 +0000 | [diff] [blame^] | 33 | AArch64Subtarget & |
| 34 | AArch64Subtarget::initializeSubtargetDependencies(StringRef FS) { |
| 35 | // Determine default and user-specified characteristics |
| 36 | |
| 37 | if (CPUString.empty()) |
| 38 | CPUString = "generic"; |
| 39 | |
| 40 | ParseSubtargetFeatures(CPUString, FS); |
| 41 | return *this; |
| 42 | } |
| 43 | |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 44 | AArch64Subtarget::AArch64Subtarget(const std::string &TT, |
| 45 | const std::string &CPU, |
Eric Christopher | 841da85 | 2014-06-10 23:26:45 +0000 | [diff] [blame] | 46 | const std::string &FS, TargetMachine &TM, |
| 47 | bool LittleEndian) |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 48 | : AArch64GenSubtargetInfo(TT, CPU, FS), ARMProcFamily(Others), |
| 49 | HasFPARMv8(false), HasNEON(false), HasCrypto(false), HasCRC(false), |
| 50 | HasZeroCycleRegMove(false), HasZeroCycleZeroing(false), CPUString(CPU), |
Eric Christopher | 17254ee | 2014-06-10 18:11:20 +0000 | [diff] [blame] | 51 | TargetTriple(TT), |
Eric Christopher | 6f2a203 | 2014-06-10 18:06:23 +0000 | [diff] [blame] | 52 | // This nested ternary is horrible, but DL needs to be properly |
| 53 | // initialized |
| 54 | // before TLInfo is constructed. |
| 55 | DL(isTargetMachO() |
| 56 | ? "e-m:o-i64:64-i128:128-n32:64-S128" |
Eric Christopher | 17254ee | 2014-06-10 18:11:20 +0000 | [diff] [blame] | 57 | : (LittleEndian ? "e-m:e-i64:64-i128:128-n32:64-S128" |
| 58 | : "E-m:e-i64:64-i128:128-n32:64-S128")), |
Eric Christopher | 7c9d4e0 | 2014-06-11 00:46:34 +0000 | [diff] [blame^] | 59 | FrameLowering(), InstrInfo(initializeSubtargetDependencies(FS)), |
| 60 | TSInfo(&DL), TLInfo(TM) {} |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 61 | |
| 62 | /// ClassifyGlobalReference - Find the target operand flags that describe |
| 63 | /// how a global value should be referenced for the current subtarget. |
| 64 | unsigned char |
| 65 | AArch64Subtarget::ClassifyGlobalReference(const GlobalValue *GV, |
| 66 | const TargetMachine &TM) const { |
| 67 | |
| 68 | // Determine whether this is a reference to a definition or a declaration. |
| 69 | // Materializable GVs (in JIT lazy compilation mode) do not require an extra |
| 70 | // load from stub. |
| 71 | bool isDecl = GV->hasAvailableExternallyLinkage(); |
| 72 | if (GV->isDeclaration() && !GV->isMaterializable()) |
| 73 | isDecl = true; |
| 74 | |
| 75 | // MachO large model always goes via a GOT, simply to get a single 8-byte |
| 76 | // absolute relocation on all global addresses. |
| 77 | if (TM.getCodeModel() == CodeModel::Large && isTargetMachO()) |
| 78 | return AArch64II::MO_GOT; |
| 79 | |
| 80 | // The small code mode's direct accesses use ADRP, which cannot necessarily |
| 81 | // produce the value 0 (if the code is above 4GB). Therefore they must use the |
| 82 | // GOT. |
| 83 | if (TM.getCodeModel() == CodeModel::Small && GV->isWeakForLinker() && isDecl) |
| 84 | return AArch64II::MO_GOT; |
| 85 | |
| 86 | // If symbol visibility is hidden, the extra load is not needed if |
| 87 | // the symbol is definitely defined in the current translation unit. |
| 88 | |
| 89 | // The handling of non-hidden symbols in PIC mode is rather target-dependent: |
| 90 | // + On MachO, if the symbol is defined in this module the GOT can be |
| 91 | // skipped. |
| 92 | // + On ELF, the R_AARCH64_COPY relocation means that even symbols actually |
| 93 | // defined could end up in unexpected places. Use a GOT. |
| 94 | if (TM.getRelocationModel() != Reloc::Static && GV->hasDefaultVisibility()) { |
| 95 | if (isTargetMachO()) |
| 96 | return (isDecl || GV->isWeakForLinker()) ? AArch64II::MO_GOT |
| 97 | : AArch64II::MO_NO_FLAG; |
| 98 | else |
| 99 | // No need to go through the GOT for local symbols on ELF. |
| 100 | return GV->hasLocalLinkage() ? AArch64II::MO_NO_FLAG : AArch64II::MO_GOT; |
| 101 | } |
| 102 | |
| 103 | return AArch64II::MO_NO_FLAG; |
| 104 | } |
| 105 | |
| 106 | /// This function returns the name of a function which has an interface |
| 107 | /// like the non-standard bzero function, if such a function exists on |
| 108 | /// the current subtarget and it is considered prefereable over |
| 109 | /// memset with zero passed as the second argument. Otherwise it |
| 110 | /// returns null. |
| 111 | const char *AArch64Subtarget::getBZeroEntry() const { |
| 112 | // Prefer bzero on Darwin only. |
| 113 | if(isTargetDarwin()) |
| 114 | return "bzero"; |
| 115 | |
| 116 | return nullptr; |
| 117 | } |
| 118 | |
| 119 | void AArch64Subtarget::overrideSchedPolicy(MachineSchedPolicy &Policy, |
| 120 | MachineInstr *begin, MachineInstr *end, |
| 121 | unsigned NumRegionInstrs) const { |
| 122 | // LNT run (at least on Cyclone) showed reasonably significant gains for |
| 123 | // bi-directional scheduling. 253.perlbmk. |
| 124 | Policy.OnlyTopDown = false; |
| 125 | Policy.OnlyBottomUp = false; |
| 126 | } |
| 127 | |
| 128 | bool AArch64Subtarget::enableEarlyIfConversion() const { |
| 129 | return EnableEarlyIfConvert; |
| 130 | } |