blob: 31a2bfff9463c1558ed1c75aaf71c73913ecaedd [file] [log] [blame]
Ulrich Weigand5f613df2013-05-06 16:15:19 +00001//===-- 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"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000011#include "MCTargetDesc/SystemZMCTargetDesc.h"
Ulrich Weigand5f613df2013-05-06 16:15:19 +000012#include "llvm/IR/GlobalValue.h"
Richard Sandifordf834ea12013-10-31 12:14:17 +000013#include "llvm/Support/Host.h"
Ulrich Weigand5f613df2013-05-06 16:15:19 +000014
Chandler Carruthd174b722014-04-22 02:03:14 +000015using namespace llvm;
16
Chandler Carruthe96dd892014-04-21 22:55:11 +000017#define DEBUG_TYPE "systemz-subtarget"
18
Ulrich Weigand5f613df2013-05-06 16:15:19 +000019#define GET_SUBTARGETINFO_TARGET_DESC
20#define GET_SUBTARGETINFO_CTOR
21#include "SystemZGenSubtargetInfo.inc"
22
Eric Christopher0eaa5412014-07-02 22:05:40 +000023// Pin the vtable to this file.
Juergen Ributzkad12ccbd2013-11-19 00:57:56 +000024void SystemZSubtarget::anchor() {}
25
Eric Christopher52349952014-07-01 20:19:02 +000026SystemZSubtarget &
27SystemZSubtarget::initializeSubtargetDependencies(StringRef CPU, StringRef FS) {
Ulrich Weigand5f613df2013-05-06 16:15:19 +000028 std::string CPUName = CPU;
29 if (CPUName.empty())
Richard Sandifordf834ea12013-10-31 12:14:17 +000030 CPUName = "generic";
31#if defined(__linux__) && defined(__s390x__)
32 if (CPUName == "generic")
33 CPUName = sys::getHostCPUName();
34#endif
Ulrich Weigand5f613df2013-05-06 16:15:19 +000035 // Parse features string.
36 ParseSubtargetFeatures(CPUName, FS);
Eric Christopher52349952014-07-01 20:19:02 +000037 return *this;
Ulrich Weigand5f613df2013-05-06 16:15:19 +000038}
39
Eric Christopher52349952014-07-01 20:19:02 +000040SystemZSubtarget::SystemZSubtarget(const std::string &TT,
41 const std::string &CPU,
42 const std::string &FS,
43 const TargetMachine &TM)
44 : SystemZGenSubtargetInfo(TT, CPU, FS), HasDistinctOps(false),
45 HasLoadStoreOnCond(false), HasHighWord(false), HasFPExtension(false),
46 HasFastSerialization(false), HasInterlockedAccess1(false),
Eric Christopher8b770652015-01-26 19:03:15 +000047 TargetTriple(TT), InstrInfo(initializeSubtargetDependencies(CPU, FS)),
Eric Christophera6734172015-01-31 00:06:45 +000048 TLInfo(TM, *this), TSInfo(*TM.getDataLayout()), FrameLowering() {}
Eric Christopher52349952014-07-01 20:19:02 +000049
Ulrich Weigand5f613df2013-05-06 16:15:19 +000050// Return true if GV binds locally under reloc model RM.
51static bool bindsLocally(const GlobalValue *GV, Reloc::Model RM) {
52 // For non-PIC, all symbols bind locally.
53 if (RM == Reloc::Static)
54 return true;
55
56 return GV->hasLocalLinkage() || !GV->hasDefaultVisibility();
57}
58
59bool SystemZSubtarget::isPC32DBLSymbol(const GlobalValue *GV,
60 Reloc::Model RM,
61 CodeModel::Model CM) const {
62 // PC32DBL accesses require the low bit to be clear. Note that a zero
63 // value selects the default alignment and is therefore OK.
64 if (GV->getAlignment() == 1)
65 return false;
66
67 // For the small model, all locally-binding symbols are in range.
68 if (CM == CodeModel::Small)
69 return bindsLocally(GV, RM);
70
71 // For Medium and above, assume that the symbol is not within the 4GB range.
72 // Taking the address of locally-defined text would be OK, but that
73 // case isn't easy to detect.
74 return false;
75}