[llvm-shlib] Fix the version naming style of libLLVM for Windows (#85710)
[llvm-project.git] / llvm / lib / Target / SystemZ / SystemZSubtarget.cpp
blob491bff7f3c30f18371b18207e2a65090b78c1f55
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 //===----------------------------------------------------------------------===//
9 #include "SystemZSubtarget.h"
10 #include "MCTargetDesc/SystemZMCTargetDesc.h"
11 #include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
12 #include "llvm/IR/GlobalValue.h"
13 #include "llvm/Target/TargetMachine.h"
15 using namespace llvm;
17 #define DEBUG_TYPE "systemz-subtarget"
19 #define GET_SUBTARGETINFO_TARGET_DESC
20 #define GET_SUBTARGETINFO_CTOR
21 #include "SystemZGenSubtargetInfo.inc"
23 static cl::opt<bool> UseSubRegLiveness(
24 "systemz-subreg-liveness",
25 cl::desc("Enable subregister liveness tracking for SystemZ (experimental)"),
26 cl::Hidden);
28 // Pin the vtable to this file.
29 void SystemZSubtarget::anchor() {}
31 SystemZSubtarget &SystemZSubtarget::initializeSubtargetDependencies(
32 StringRef CPU, StringRef TuneCPU, StringRef FS) {
33 if (CPU.empty())
34 CPU = "generic";
35 if (TuneCPU.empty())
36 TuneCPU = CPU;
37 // Parse features string.
38 ParseSubtargetFeatures(CPU, TuneCPU, FS);
40 // -msoft-float implies -mno-vx.
41 if (HasSoftFloat)
42 HasVector = false;
44 // -mno-vx implicitly disables all vector-related features.
45 if (!HasVector) {
46 HasVectorEnhancements1 = false;
47 HasVectorEnhancements2 = false;
48 HasVectorPackedDecimal = false;
49 HasVectorPackedDecimalEnhancement = false;
50 HasVectorPackedDecimalEnhancement2 = false;
53 return *this;
56 SystemZCallingConventionRegisters *
57 SystemZSubtarget::initializeSpecialRegisters() {
58 if (isTargetXPLINK64())
59 return new SystemZXPLINK64Registers;
60 else if (isTargetELF())
61 return new SystemZELFRegisters;
62 llvm_unreachable("Invalid Calling Convention. Cannot initialize Special "
63 "Call Registers!");
66 SystemZSubtarget::SystemZSubtarget(const Triple &TT, const std::string &CPU,
67 const std::string &TuneCPU,
68 const std::string &FS,
69 const TargetMachine &TM)
70 : SystemZGenSubtargetInfo(TT, CPU, TuneCPU, FS), TargetTriple(TT),
71 SpecialRegisters(initializeSpecialRegisters()),
72 InstrInfo(initializeSubtargetDependencies(CPU, TuneCPU, FS)),
73 TLInfo(TM, *this), FrameLowering(SystemZFrameLowering::create(*this)) {}
75 bool SystemZSubtarget::enableSubRegLiveness() const {
76 return UseSubRegLiveness;
79 bool SystemZSubtarget::isAddressedViaADA(const GlobalValue *GV) const {
80 if (const auto *GO = dyn_cast<GlobalObject>(GV)) {
81 // A R/O variable is placed in code section. If the R/O variable has as
82 // least two byte alignment, then generated code can use relative
83 // instructions to address the variable. Otherwise, use the ADA to address
84 // the variable.
85 if (GO->getAlignment() & 0x1) {
86 return true;
89 // getKindForGlobal only works with definitions
90 if (GO->isDeclaration()) {
91 return true;
94 // check AvailableExternallyLinkage here as getKindForGlobal() asserts
95 if (GO->hasAvailableExternallyLinkage()) {
96 return true;
99 SectionKind GOKind = TargetLoweringObjectFile::getKindForGlobal(
100 GO, TLInfo.getTargetMachine());
101 if (!GOKind.isReadOnly()) {
102 return true;
105 return false; // R/O variable with multiple of 2 byte alignment
107 return true;
110 bool SystemZSubtarget::isPC32DBLSymbol(const GlobalValue *GV,
111 CodeModel::Model CM) const {
112 if (isTargetzOS())
113 return !isAddressedViaADA(GV);
115 // PC32DBL accesses require the low bit to be clear.
117 // FIXME: Explicitly check for functions: the datalayout is currently
118 // missing information about function pointers.
119 const DataLayout &DL = GV->getParent()->getDataLayout();
120 if (GV->getPointerAlignment(DL) == 1 && !GV->getValueType()->isFunctionTy())
121 return false;
123 // For the small model, all locally-binding symbols are in range.
124 if (CM == CodeModel::Small)
125 return TLInfo.getTargetMachine().shouldAssumeDSOLocal(*GV->getParent(), GV);
127 // For Medium and above, assume that the symbol is not within the 4GB range.
128 // Taking the address of locally-defined text would be OK, but that
129 // case isn't easy to detect.
130 return false;