SystemZSubtarget.cpp revision eddfaad1ef9a208a8a9ee23c26fac4d980caa99a
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
18using namespace llvm;
19
20SystemZSubtarget::SystemZSubtarget(const std::string &TT,
21                                   const std::string &CPU,
22                                   const std::string &FS)
23  : SystemZGenSubtargetInfo(TT, CPU, FS), HasDistinctOps(false),
24    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.
34static 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
42bool 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}
59