1 | //===-- SystemZSubtarget.cpp - SystemZ subtarget information --------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #include "SystemZSubtarget.h" |
10 | #include "llvm/CodeGen/TargetLoweringObjectFileImpl.h" |
11 | #include "llvm/IR/GlobalVariable.h" |
12 | #include "llvm/Target/TargetMachine.h" |
13 | |
14 | using namespace llvm; |
15 | |
16 | #define DEBUG_TYPE "systemz-subtarget" |
17 | |
18 | #define GET_SUBTARGETINFO_TARGET_DESC |
19 | #define GET_SUBTARGETINFO_CTOR |
20 | #include "SystemZGenSubtargetInfo.inc" |
21 | |
22 | static cl::opt<bool> UseSubRegLiveness( |
23 | "systemz-subreg-liveness" , |
24 | cl::desc("Enable subregister liveness tracking for SystemZ (experimental)" ), |
25 | cl::Hidden); |
26 | |
27 | // Pin the vtable to this file. |
28 | void SystemZSubtarget::anchor() {} |
29 | |
30 | SystemZSubtarget &SystemZSubtarget::initializeSubtargetDependencies( |
31 | StringRef CPU, StringRef TuneCPU, StringRef FS) { |
32 | if (CPU.empty()) |
33 | CPU = "generic" ; |
34 | if (TuneCPU.empty()) |
35 | TuneCPU = CPU; |
36 | // Parse features string. |
37 | ParseSubtargetFeatures(CPU, TuneCPU, FS); |
38 | |
39 | // -msoft-float implies -mno-vx. |
40 | if (HasSoftFloat) |
41 | HasVector = false; |
42 | |
43 | // -mno-vx implicitly disables all vector-related features. |
44 | if (!HasVector) { |
45 | HasVectorEnhancements1 = false; |
46 | HasVectorEnhancements2 = false; |
47 | HasVectorEnhancements3 = false; |
48 | HasVectorPackedDecimal = false; |
49 | HasVectorPackedDecimalEnhancement = false; |
50 | HasVectorPackedDecimalEnhancement2 = false; |
51 | HasVectorPackedDecimalEnhancement3 = false; |
52 | } |
53 | |
54 | return *this; |
55 | } |
56 | |
57 | SystemZCallingConventionRegisters * |
58 | SystemZSubtarget::initializeSpecialRegisters() { |
59 | if (isTargetXPLINK64()) |
60 | return new SystemZXPLINK64Registers; |
61 | else if (isTargetELF()) |
62 | return new SystemZELFRegisters; |
63 | llvm_unreachable("Invalid Calling Convention. Cannot initialize Special " |
64 | "Call Registers!" ); |
65 | } |
66 | |
67 | SystemZSubtarget::SystemZSubtarget(const Triple &TT, const std::string &CPU, |
68 | const std::string &TuneCPU, |
69 | const std::string &FS, |
70 | const TargetMachine &TM) |
71 | : SystemZGenSubtargetInfo(TT, CPU, TuneCPU, FS), TargetTriple(TT), |
72 | SpecialRegisters(initializeSpecialRegisters()), |
73 | InstrInfo(initializeSubtargetDependencies(CPU, TuneCPU, FS)), |
74 | TLInfo(TM, *this), FrameLowering(SystemZFrameLowering::create(STI: *this)) {} |
75 | |
76 | bool SystemZSubtarget::enableSubRegLiveness() const { |
77 | return UseSubRegLiveness; |
78 | } |
79 | |
80 | bool SystemZSubtarget::isAddressedViaADA(const GlobalValue *GV) const { |
81 | if (const auto *GO = dyn_cast<GlobalObject>(Val: GV)) { |
82 | // A R/O variable is placed in code section. If the R/O variable has as |
83 | // least two byte alignment, then generated code can use relative |
84 | // instructions to address the variable. Otherwise, use the ADA to address |
85 | // the variable. |
86 | if (auto *GV = dyn_cast<GlobalVariable>(Val: GO)) |
87 | if (GV->getAlign() && (*GV->getAlign()).value() & 0x1) |
88 | return true; |
89 | |
90 | // getKindForGlobal only works with definitions |
91 | if (GO->isDeclaration()) { |
92 | return true; |
93 | } |
94 | |
95 | // check AvailableExternallyLinkage here as getKindForGlobal() asserts |
96 | if (GO->hasAvailableExternallyLinkage()) { |
97 | return true; |
98 | } |
99 | |
100 | SectionKind GOKind = TargetLoweringObjectFile::getKindForGlobal( |
101 | GO, TM: TLInfo.getTargetMachine()); |
102 | if (!GOKind.isReadOnly()) { |
103 | return true; |
104 | } |
105 | |
106 | return false; // R/O variable with multiple of 2 byte alignment |
107 | } |
108 | return true; |
109 | } |
110 | |
111 | bool SystemZSubtarget::isPC32DBLSymbol(const GlobalValue *GV, |
112 | CodeModel::Model CM) const { |
113 | if (isTargetzOS()) |
114 | return !isAddressedViaADA(GV); |
115 | |
116 | // PC32DBL accesses require the low bit to be clear. |
117 | // |
118 | // FIXME: Explicitly check for functions: the datalayout is currently |
119 | // missing information about function pointers. |
120 | const DataLayout &DL = GV->getDataLayout(); |
121 | if (GV->getPointerAlignment(DL) == 1 && !GV->getValueType()->isFunctionTy()) |
122 | return false; |
123 | |
124 | // For the small model, all locally-binding symbols are in range. |
125 | if (CM == CodeModel::Small) |
126 | return TLInfo.getTargetMachine().shouldAssumeDSOLocal(GV); |
127 | |
128 | // For Medium and above, assume that the symbol is not within the 4GB range. |
129 | // Taking the address of locally-defined text would be OK, but that |
130 | // case isn't easy to detect. |
131 | return false; |
132 | } |
133 | |