ARM64: diagnose use of v16-v31 in certain indexed NEON instructions.
[oota-llvm.git] / lib / Target / ARM64 / ARM64Subtarget.cpp
1 //===-- ARM64Subtarget.cpp - ARM64 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 ARM64 specific subclass of TargetSubtarget.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "ARM64InstrInfo.h"
15 #include "ARM64Subtarget.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 "arm64-subtarget"
24
25 #define GET_SUBTARGETINFO_CTOR
26 #define GET_SUBTARGETINFO_TARGET_DESC
27 #include "ARM64GenSubtargetInfo.inc"
28
29 ARM64Subtarget::ARM64Subtarget(const std::string &TT, const std::string &CPU,
30                                const std::string &FS, bool LittleEndian)
31     : ARM64GenSubtargetInfo(TT, CPU, FS), ARMProcFamily(Others),
32       HasFPARMv8(false), HasNEON(false), HasCrypto(false), HasCRC(false),
33       HasZeroCycleRegMove(false), HasZeroCycleZeroing(false),
34       CPUString(CPU), TargetTriple(TT), IsLittleEndian(LittleEndian) {
35   // Determine default and user-specified characteristics
36
37   if (CPUString.empty())
38     CPUString = "generic";
39
40   ParseSubtargetFeatures(CPUString, FS);
41 }
42
43 /// ClassifyGlobalReference - Find the target operand flags that describe
44 /// how a global value should be referenced for the current subtarget.
45 unsigned char
46 ARM64Subtarget::ClassifyGlobalReference(const GlobalValue *GV,
47                                         const TargetMachine &TM) const {
48
49   // Determine whether this is a reference to a definition or a declaration.
50   // Materializable GVs (in JIT lazy compilation mode) do not require an extra
51   // load from stub.
52   bool isDecl = GV->hasAvailableExternallyLinkage();
53   if (GV->isDeclaration() && !GV->isMaterializable())
54     isDecl = true;
55
56   // MachO large model always goes via a GOT, simply to get a single 8-byte
57   // absolute relocation on all global addresses.
58   if (TM.getCodeModel() == CodeModel::Large && isTargetMachO())
59     return ARM64II::MO_GOT;
60
61   // The small code mode's direct accesses use ADRP, which cannot necessarily
62   // produce the value 0 (if the code is above 4GB). Therefore they must use the
63   // GOT.
64   if (TM.getCodeModel() == CodeModel::Small && GV->isWeakForLinker() && isDecl)
65     return ARM64II::MO_GOT;
66
67   // If symbol visibility is hidden, the extra load is not needed if
68   // the symbol is definitely defined in the current translation unit.
69
70   // The handling of non-hidden symbols in PIC mode is rather target-dependent:
71   //   + On MachO, if the symbol is defined in this module the GOT can be
72   //     skipped.
73   //   + On ELF, the R_AARCH64_COPY relocation means that even symbols actually
74   //     defined could end up in unexpected places. Use a GOT.
75   if (TM.getRelocationModel() != Reloc::Static && GV->hasDefaultVisibility()) {
76     if (isTargetMachO())
77       return (isDecl || GV->isWeakForLinker()) ? ARM64II::MO_GOT
78                                                : ARM64II::MO_NO_FLAG;
79     else
80       // No need to go through the GOT for local symbols on ELF.
81       return GV->hasLocalLinkage() ? ARM64II::MO_NO_FLAG : ARM64II::MO_GOT;
82   }
83
84   return ARM64II::MO_NO_FLAG;
85 }
86
87 /// This function returns the name of a function which has an interface
88 /// like the non-standard bzero function, if such a function exists on
89 /// the current subtarget and it is considered prefereable over
90 /// memset with zero passed as the second argument. Otherwise it
91 /// returns null.
92 const char *ARM64Subtarget::getBZeroEntry() const {
93   // At the moment, always prefer bzero.
94   return "bzero";
95 }
96
97 void ARM64Subtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
98                                          MachineInstr *begin, MachineInstr *end,
99                                          unsigned NumRegionInstrs) const {
100   // LNT run (at least on Cyclone) showed reasonably significant gains for
101   // bi-directional scheduling. 253.perlbmk.
102   Policy.OnlyTopDown = false;
103   Policy.OnlyBottomUp = false;
104 }