036ec05d93a83f22662d7b9f4af61f49e8cbb021
[oota-llvm.git] / lib / Target / SystemZ / SystemZSubtarget.cpp
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 "MCTargetDesc/SystemZMCTargetDesc.h"
13
14 #define GET_SUBTARGETINFO_TARGET_DESC
15 #define GET_SUBTARGETINFO_CTOR
16 #include "SystemZGenSubtargetInfo.inc"
17
18 using namespace llvm;
19
20 SystemZSubtarget::SystemZSubtarget(const std::string &TT,
21                                    const std::string &CPU,
22                                    const std::string &FS)
23   : SystemZGenSubtargetInfo(TT, CPU, FS), HasDistinctOps(false),
24     HasLoadStoreOnCond(false), HasHighWord(false), TargetTriple(TT) {
25   std::string CPUName = CPU;
26   if (CPUName.empty())
27     CPUName = "z10";
28
29   // Parse features string.
30   ParseSubtargetFeatures(CPUName, FS);
31 }
32
33 // Return true if GV binds locally under reloc model RM.
34 static bool bindsLocally(const GlobalValue *GV, Reloc::Model RM) {
35   // For non-PIC, all symbols bind locally.
36   if (RM == Reloc::Static)
37     return true;
38
39   return GV->hasLocalLinkage() || !GV->hasDefaultVisibility();
40 }
41
42 bool SystemZSubtarget::isPC32DBLSymbol(const GlobalValue *GV,
43                                        Reloc::Model RM,
44                                        CodeModel::Model CM) const {
45   // PC32DBL accesses require the low bit to be clear.  Note that a zero
46   // value selects the default alignment and is therefore OK.
47   if (GV->getAlignment() == 1)
48     return false;
49
50   // For the small model, all locally-binding symbols are in range.
51   if (CM == CodeModel::Small)
52     return bindsLocally(GV, RM);
53
54   // For Medium and above, assume that the symbol is not within the 4GB range.
55   // Taking the address of locally-defined text would be OK, but that
56   // case isn't easy to detect.
57   return false;
58 }