1251607Sdim//===-- SystemZSubtarget.cpp - SystemZ subtarget information --------------===//
2251607Sdim//
3251607Sdim//                     The LLVM Compiler Infrastructure
4251607Sdim//
5251607Sdim// This file is distributed under the University of Illinois Open Source
6251607Sdim// License. See LICENSE.TXT for details.
7251607Sdim//
8251607Sdim//===----------------------------------------------------------------------===//
9251607Sdim
10251607Sdim#include "SystemZSubtarget.h"
11251607Sdim#include "llvm/IR/GlobalValue.h"
12263509Sdim#include "llvm/Support/Host.h"
13263509Sdim#include "MCTargetDesc/SystemZMCTargetDesc.h"
14251607Sdim
15251607Sdim#define GET_SUBTARGETINFO_TARGET_DESC
16251607Sdim#define GET_SUBTARGETINFO_CTOR
17251607Sdim#include "SystemZGenSubtargetInfo.inc"
18251607Sdim
19251607Sdimusing namespace llvm;
20251607Sdim
21263509Sdim// Pin the vtabel to this file.
22263509Sdimvoid SystemZSubtarget::anchor() {}
23263509Sdim
24251607SdimSystemZSubtarget::SystemZSubtarget(const std::string &TT,
25251607Sdim                                   const std::string &CPU,
26251607Sdim                                   const std::string &FS)
27263509Sdim  : SystemZGenSubtargetInfo(TT, CPU, FS), HasDistinctOps(false),
28263509Sdim    HasLoadStoreOnCond(false), HasHighWord(false), HasFPExtension(false),
29263509Sdim    TargetTriple(TT) {
30251607Sdim  std::string CPUName = CPU;
31251607Sdim  if (CPUName.empty())
32263509Sdim    CPUName = "generic";
33263509Sdim#if defined(__linux__) && defined(__s390x__)
34263509Sdim  if (CPUName == "generic")
35263509Sdim    CPUName = sys::getHostCPUName();
36263509Sdim#endif
37251607Sdim
38251607Sdim  // Parse features string.
39251607Sdim  ParseSubtargetFeatures(CPUName, FS);
40251607Sdim}
41251607Sdim
42251607Sdim// Return true if GV binds locally under reloc model RM.
43251607Sdimstatic bool bindsLocally(const GlobalValue *GV, Reloc::Model RM) {
44251607Sdim  // For non-PIC, all symbols bind locally.
45251607Sdim  if (RM == Reloc::Static)
46251607Sdim    return true;
47251607Sdim
48251607Sdim  return GV->hasLocalLinkage() || !GV->hasDefaultVisibility();
49251607Sdim}
50251607Sdim
51251607Sdimbool SystemZSubtarget::isPC32DBLSymbol(const GlobalValue *GV,
52251607Sdim                                       Reloc::Model RM,
53251607Sdim                                       CodeModel::Model CM) const {
54251607Sdim  // PC32DBL accesses require the low bit to be clear.  Note that a zero
55251607Sdim  // value selects the default alignment and is therefore OK.
56251607Sdim  if (GV->getAlignment() == 1)
57251607Sdim    return false;
58251607Sdim
59251607Sdim  // For the small model, all locally-binding symbols are in range.
60251607Sdim  if (CM == CodeModel::Small)
61251607Sdim    return bindsLocally(GV, RM);
62251607Sdim
63251607Sdim  // For Medium and above, assume that the symbol is not within the 4GB range.
64251607Sdim  // Taking the address of locally-defined text would be OK, but that
65251607Sdim  // case isn't easy to detect.
66251607Sdim  return false;
67251607Sdim}
68