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/CodeGen/TargetLoweringObjectFileImpl.h" 12 #include "llvm/IR/GlobalValue.h" 13 #include "llvm/Target/TargetMachine.h" 14 15 using namespace llvm; 16 17 #define DEBUG_TYPE "systemz-subtarget" 18 19 #define GET_SUBTARGETINFO_TARGET_DESC 20 #define GET_SUBTARGETINFO_CTOR 21 #include "SystemZGenSubtargetInfo.inc" 22 23 static cl::opt<bool> UseSubRegLiveness( 24 "systemz-subreg-liveness", 25 cl::desc("Enable subregister liveness tracking for SystemZ (experimental)"), 26 cl::Hidden); 27 28 // Pin the vtable to this file. 29 void SystemZSubtarget::anchor() {} 30 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); 39 40 // -msoft-float implies -mno-vx. 41 if (HasSoftFloat) 42 HasVector = false; 43 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; 51 } 52 53 return *this; 54 } 55 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!"); 64 } 65 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)) {} 74 75 bool SystemZSubtarget::enableSubRegLiveness() const { 76 return UseSubRegLiveness; 77 } 78 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; 87 } 88 89 // getKindForGlobal only works with definitions 90 if (GO->isDeclaration()) { 91 return true; 92 } 93 94 // check AvailableExternallyLinkage here as getKindForGlobal() asserts 95 if (GO->hasAvailableExternallyLinkage()) { 96 return true; 97 } 98 99 SectionKind GOKind = TargetLoweringObjectFile::getKindForGlobal( 100 GO, TLInfo.getTargetMachine()); 101 if (!GOKind.isReadOnly()) { 102 return true; 103 } 104 105 return false; // R/O variable with multiple of 2 byte alignment 106 } 107 return true; 108 } 109 110 bool SystemZSubtarget::isPC32DBLSymbol(const GlobalValue *GV, 111 CodeModel::Model CM) const { 112 if (isTargetzOS()) 113 return !isAddressedViaADA(GV); 114 115 // PC32DBL accesses require the low bit to be clear. 116 // 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; 122 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); 126 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; 131 } 132