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