[cleanup] Lift using directives, DEBUG_TYPE definitions, and even some
[oota-llvm.git] / lib / Target / AArch64 / AArch64Subtarget.cpp
1 //===-- AArch64Subtarget.cpp - AArch64 Subtarget Information --------------===//
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 TargetSubtargetInfo.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "AArch64Subtarget.h"
15 #include "AArch64RegisterInfo.h"
16 #include "MCTargetDesc/AArch64MCTargetDesc.h"
17 #include "llvm/ADT/SmallVector.h"
18 #include "llvm/IR/GlobalValue.h"
19 #include "llvm/Support/CommandLine.h"
20 #include "llvm/Target/TargetSubtargetInfo.h"
21
22 using namespace llvm;
23
24 #define DEBUG_TYPE "aarch64-subtarget"
25
26 #define GET_SUBTARGETINFO_TARGET_DESC
27 #define GET_SUBTARGETINFO_CTOR
28 #include "AArch64GenSubtargetInfo.inc"
29
30 enum AlignMode {
31   DefaultAlign,
32   StrictAlign,
33   NoStrictAlign
34 };
35
36 static cl::opt<AlignMode>
37 Align(cl::desc("Load/store alignment support"),
38       cl::Hidden, cl::init(DefaultAlign),
39       cl::values(
40           clEnumValN(DefaultAlign,  "aarch64-default-align",
41                      "Generate unaligned accesses only on hardware/OS "
42                      "combinations that are known to support them"),
43           clEnumValN(StrictAlign,   "aarch64-strict-align",
44                      "Disallow all unaligned memory accesses"),
45           clEnumValN(NoStrictAlign, "aarch64-no-strict-align",
46                      "Allow unaligned memory accesses"),
47           clEnumValEnd));
48
49 // Pin the vtable to this file.
50 void AArch64Subtarget::anchor() {}
51
52 AArch64Subtarget::AArch64Subtarget(StringRef TT, StringRef CPU, StringRef FS,
53                                    bool LittleEndian)
54     : AArch64GenSubtargetInfo(TT, CPU, FS), ARMProcFamily(Others),
55       HasFPARMv8(false), HasNEON(false), HasCrypto(false), TargetTriple(TT),
56       CPUString(CPU), IsLittleEndian(LittleEndian) {
57
58   initializeSubtargetFeatures(CPU, FS);
59 }
60
61 void AArch64Subtarget::initializeSubtargetFeatures(StringRef CPU,
62                                                    StringRef FS) {
63   AllowsUnalignedMem = false;
64
65   if (CPU.empty())
66     CPUString = "generic";
67
68   std::string FullFS = FS;
69   if (CPUString == "generic") {
70     // Enable FP by default.
71     if (FullFS.empty())
72       FullFS = "+fp-armv8";
73     else
74       FullFS = "+fp-armv8," + FullFS;
75   }
76
77   ParseSubtargetFeatures(CPU, FullFS);
78
79   switch (Align) {
80     case DefaultAlign:
81       // Linux targets support unaligned accesses on AARCH64
82       AllowsUnalignedMem = isTargetLinux();
83       break;
84     case StrictAlign:
85       AllowsUnalignedMem = false;
86       break;
87     case NoStrictAlign:
88       AllowsUnalignedMem = true;
89       break;
90   }
91 }
92
93 bool AArch64Subtarget::GVIsIndirectSymbol(const GlobalValue *GV,
94                                           Reloc::Model RelocM) const {
95   if (RelocM == Reloc::Static)
96     return false;
97
98   return !GV->hasLocalLinkage() && !GV->hasHiddenVisibility();
99 }