xref: /netbsd-src/external/apache2/llvm/dist/llvm/lib/Target/SystemZ/SystemZSubtarget.cpp (revision 82d56013d7b633d116a93943de88e08335357a7c)
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 "MCTargetDesc/SystemZMCTargetDesc.h"
11 #include "llvm/IR/GlobalValue.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.
anchor()28 void SystemZSubtarget::anchor() {}
29 
30 SystemZSubtarget &
initializeSubtargetDependencies(StringRef CPU,StringRef FS)31 SystemZSubtarget::initializeSubtargetDependencies(StringRef CPU, StringRef FS) {
32   StringRef CPUName = CPU;
33   if (CPUName.empty())
34     CPUName = "generic";
35   // Parse features string.
36   ParseSubtargetFeatures(CPUName, /*TuneCPU*/ CPUName, FS);
37 
38   // -msoft-float implies -mno-vx.
39   if (HasSoftFloat)
40     HasVector = false;
41 
42   // -mno-vx implicitly disables all vector-related features.
43   if (!HasVector) {
44     HasVectorEnhancements1 = false;
45     HasVectorEnhancements2 = false;
46     HasVectorPackedDecimal = false;
47     HasVectorPackedDecimalEnhancement = false;
48   }
49 
50   return *this;
51 }
52 
53 SystemZCallingConventionRegisters *
initializeSpecialRegisters()54 SystemZSubtarget::initializeSpecialRegisters() {
55   if (isTargetXPLINK64())
56     return new SystemZXPLINK64Registers;
57   else if (isTargetELF())
58     return new SystemZELFRegisters;
59   else {
60     llvm_unreachable("Invalid Calling Convention. Cannot initialize Special "
61                      "Call Registers!");
62   }
63 }
64 
SystemZSubtarget(const Triple & TT,const std::string & CPU,const std::string & FS,const TargetMachine & TM)65 SystemZSubtarget::SystemZSubtarget(const Triple &TT, const std::string &CPU,
66                                    const std::string &FS,
67                                    const TargetMachine &TM)
68     : SystemZGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS),
69       HasDistinctOps(false), HasLoadStoreOnCond(false), HasHighWord(false),
70       HasFPExtension(false), HasPopulationCount(false),
71       HasMessageSecurityAssist3(false), HasMessageSecurityAssist4(false),
72       HasResetReferenceBitsMultiple(false), HasFastSerialization(false),
73       HasInterlockedAccess1(false), HasMiscellaneousExtensions(false),
74       HasExecutionHint(false), HasLoadAndTrap(false),
75       HasTransactionalExecution(false), HasProcessorAssist(false),
76       HasDFPZonedConversion(false), HasEnhancedDAT2(false), HasVector(false),
77       HasLoadStoreOnCond2(false), HasLoadAndZeroRightmostByte(false),
78       HasMessageSecurityAssist5(false), HasDFPPackedConversion(false),
79       HasMiscellaneousExtensions2(false), HasGuardedStorage(false),
80       HasMessageSecurityAssist7(false), HasMessageSecurityAssist8(false),
81       HasVectorEnhancements1(false), HasVectorPackedDecimal(false),
82       HasInsertReferenceBitsMultiple(false), HasMiscellaneousExtensions3(false),
83       HasMessageSecurityAssist9(false), HasVectorEnhancements2(false),
84       HasVectorPackedDecimalEnhancement(false), HasEnhancedSort(false),
85       HasDeflateConversion(false), HasSoftFloat(false), TargetTriple(TT),
86       SpecialRegisters(initializeSpecialRegisters()),
87       InstrInfo(initializeSubtargetDependencies(CPU, FS)), TLInfo(TM, *this),
88       TSInfo(), FrameLowering() {}
89 
~SystemZSubtarget()90 SystemZSubtarget::~SystemZSubtarget() { delete getSpecialRegisters(); }
91 
enableSubRegLiveness() const92 bool SystemZSubtarget::enableSubRegLiveness() const {
93   return UseSubRegLiveness;
94 }
95 
isPC32DBLSymbol(const GlobalValue * GV,CodeModel::Model CM) const96 bool SystemZSubtarget::isPC32DBLSymbol(const GlobalValue *GV,
97                                        CodeModel::Model CM) const {
98   // PC32DBL accesses require the low bit to be clear.
99   //
100   // FIXME: Explicitly check for functions: the datalayout is currently
101   // missing information about function pointers.
102   const DataLayout &DL = GV->getParent()->getDataLayout();
103   if (GV->getPointerAlignment(DL) == 1 && !GV->getValueType()->isFunctionTy())
104     return false;
105 
106   // For the small model, all locally-binding symbols are in range.
107   if (CM == CodeModel::Small)
108     return TLInfo.getTargetMachine().shouldAssumeDSOLocal(*GV->getParent(), GV);
109 
110   // For Medium and above, assume that the symbol is not within the 4GB range.
111   // Taking the address of locally-defined text would be OK, but that
112   // case isn't easy to detect.
113   return false;
114 }
115