1 //===-- SystemZSubtarget.cpp - SystemZ subtarget information --------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "SystemZSubtarget.h"
11 #include "llvm/IR/GlobalValue.h"
12 #include "llvm/Support/Host.h"
13 #include "MCTargetDesc/SystemZMCTargetDesc.h"
14
15 #define GET_SUBTARGETINFO_TARGET_DESC
16 #define GET_SUBTARGETINFO_CTOR
17 #include "SystemZGenSubtargetInfo.inc"
18
19 using namespace llvm;
20
21 // Pin the vtabel to this file.
anchor()22 void SystemZSubtarget::anchor() {}
23
SystemZSubtarget(const std::string & TT,const std::string & CPU,const std::string & FS)24 SystemZSubtarget::SystemZSubtarget(const std::string &TT,
25 const std::string &CPU,
26 const std::string &FS)
27 : SystemZGenSubtargetInfo(TT, CPU, FS), HasDistinctOps(false),
28 HasLoadStoreOnCond(false), HasHighWord(false), HasFPExtension(false),
29 TargetTriple(TT) {
30 std::string CPUName = CPU;
31 if (CPUName.empty())
32 CPUName = "generic";
33 #if defined(__linux__) && defined(__s390x__)
34 if (CPUName == "generic")
35 CPUName = sys::getHostCPUName();
36 #endif
37
38 // Parse features string.
39 ParseSubtargetFeatures(CPUName, FS);
40 }
41
42 // Return true if GV binds locally under reloc model RM.
bindsLocally(const GlobalValue * GV,Reloc::Model RM)43 static bool bindsLocally(const GlobalValue *GV, Reloc::Model RM) {
44 // For non-PIC, all symbols bind locally.
45 if (RM == Reloc::Static)
46 return true;
47
48 return GV->hasLocalLinkage() || !GV->hasDefaultVisibility();
49 }
50
isPC32DBLSymbol(const GlobalValue * GV,Reloc::Model RM,CodeModel::Model CM) const51 bool SystemZSubtarget::isPC32DBLSymbol(const GlobalValue *GV,
52 Reloc::Model RM,
53 CodeModel::Model CM) const {
54 // PC32DBL accesses require the low bit to be clear. Note that a zero
55 // value selects the default alignment and is therefore OK.
56 if (GV->getAlignment() == 1)
57 return false;
58
59 // For the small model, all locally-binding symbols are in range.
60 if (CM == CodeModel::Small)
61 return bindsLocally(GV, RM);
62
63 // For Medium and above, assume that the symbol is not within the 4GB range.
64 // Taking the address of locally-defined text would be OK, but that
65 // case isn't easy to detect.
66 return false;
67 }
68