1 //===-- SystemZSubtarget.cpp - SystemZ subtarget information --------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "SystemZSubtarget.h"
10 #include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
11 #include "llvm/IR/GlobalValue.h"
12 #include "llvm/Target/TargetMachine.h"
16 #define DEBUG_TYPE "systemz-subtarget"
18 #define GET_SUBTARGETINFO_TARGET_DESC
19 #define GET_SUBTARGETINFO_CTOR
20 #include "SystemZGenSubtargetInfo.inc"
22 static cl::opt
<bool> UseSubRegLiveness(
23 "systemz-subreg-liveness",
24 cl::desc("Enable subregister liveness tracking for SystemZ (experimental)"),
27 // Pin the vtable to this file.
28 void SystemZSubtarget::anchor() {}
30 SystemZSubtarget
&SystemZSubtarget::initializeSubtargetDependencies(
31 StringRef CPU
, StringRef TuneCPU
, StringRef FS
) {
36 // Parse features string.
37 ParseSubtargetFeatures(CPU
, TuneCPU
, FS
);
39 // -msoft-float implies -mno-vx.
43 // -mno-vx implicitly disables all vector-related features.
45 HasVectorEnhancements1
= false;
46 HasVectorEnhancements2
= false;
47 HasVectorPackedDecimal
= false;
48 HasVectorPackedDecimalEnhancement
= false;
49 HasVectorPackedDecimalEnhancement2
= false;
55 SystemZCallingConventionRegisters
*
56 SystemZSubtarget::initializeSpecialRegisters() {
57 if (isTargetXPLINK64())
58 return new SystemZXPLINK64Registers
;
59 else if (isTargetELF())
60 return new SystemZELFRegisters
;
61 llvm_unreachable("Invalid Calling Convention. Cannot initialize Special "
65 SystemZSubtarget::SystemZSubtarget(const Triple
&TT
, const std::string
&CPU
,
66 const std::string
&TuneCPU
,
67 const std::string
&FS
,
68 const TargetMachine
&TM
)
69 : SystemZGenSubtargetInfo(TT
, CPU
, TuneCPU
, FS
), TargetTriple(TT
),
70 SpecialRegisters(initializeSpecialRegisters()),
71 InstrInfo(initializeSubtargetDependencies(CPU
, TuneCPU
, FS
)),
72 TLInfo(TM
, *this), FrameLowering(SystemZFrameLowering::create(*this)) {}
74 bool SystemZSubtarget::enableSubRegLiveness() const {
75 return UseSubRegLiveness
;
78 bool SystemZSubtarget::isAddressedViaADA(const GlobalValue
*GV
) const {
79 if (const auto *GO
= dyn_cast
<GlobalObject
>(GV
)) {
80 // A R/O variable is placed in code section. If the R/O variable has as
81 // least two byte alignment, then generated code can use relative
82 // instructions to address the variable. Otherwise, use the ADA to address
84 if (GO
->getAlignment() & 0x1) {
88 // getKindForGlobal only works with definitions
89 if (GO
->isDeclaration()) {
93 // check AvailableExternallyLinkage here as getKindForGlobal() asserts
94 if (GO
->hasAvailableExternallyLinkage()) {
98 SectionKind GOKind
= TargetLoweringObjectFile::getKindForGlobal(
99 GO
, TLInfo
.getTargetMachine());
100 if (!GOKind
.isReadOnly()) {
104 return false; // R/O variable with multiple of 2 byte alignment
109 bool SystemZSubtarget::isPC32DBLSymbol(const GlobalValue
*GV
,
110 CodeModel::Model CM
) const {
112 return !isAddressedViaADA(GV
);
114 // PC32DBL accesses require the low bit to be clear.
116 // FIXME: Explicitly check for functions: the datalayout is currently
117 // missing information about function pointers.
118 const DataLayout
&DL
= GV
->getDataLayout();
119 if (GV
->getPointerAlignment(DL
) == 1 && !GV
->getValueType()->isFunctionTy())
122 // For the small model, all locally-binding symbols are in range.
123 if (CM
== CodeModel::Small
)
124 return TLInfo
.getTargetMachine().shouldAssumeDSOLocal(GV
);
126 // For Medium and above, assume that the symbol is not within the 4GB range.
127 // Taking the address of locally-defined text would be OK, but that
128 // case isn't easy to detect.