LLVM  6.0.0svn
SparcTargetMachine.cpp
Go to the documentation of this file.
1 //===-- SparcTargetMachine.cpp - Define TargetMachine for Sparc -----------===//
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 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "SparcTargetMachine.h"
14 #include "LeonPasses.h"
15 #include "Sparc.h"
16 #include "SparcTargetObjectFile.h"
17 #include "llvm/CodeGen/Passes.h"
21 using namespace llvm;
22 
23 extern "C" void LLVMInitializeSparcTarget() {
24  // Register the target.
28 }
29 
30 static std::string computeDataLayout(const Triple &T, bool is64Bit) {
31  // Sparc is typically big endian, but some are little.
32  std::string Ret = T.getArch() == Triple::sparcel ? "e" : "E";
33  Ret += "-m:e";
34 
35  // Some ABIs have 32bit pointers.
36  if (!is64Bit)
37  Ret += "-p:32:32";
38 
39  // Alignments for 64 bit integers.
40  Ret += "-i64:64";
41 
42  // On SparcV9 128 floats are aligned to 128 bits, on others only to 64.
43  // On SparcV9 registers can hold 64 or 32 bits, on others only 32.
44  if (is64Bit)
45  Ret += "-n32:64";
46  else
47  Ret += "-f128:64-n32";
48 
49  if (is64Bit)
50  Ret += "-S128";
51  else
52  Ret += "-S64";
53 
54  return Ret;
55 }
56 
58  if (!RM.hasValue())
59  return Reloc::Static;
60  return *RM;
61 }
62 
63 // Code models. Some only make sense for 64-bit code.
64 //
65 // SunCC Reloc CodeModel Constraints
66 // abs32 Static Small text+data+bss linked below 2^32 bytes
67 // abs44 Static Medium text+data+bss linked below 2^44 bytes
68 // abs64 Static Large text smaller than 2^31 bytes
69 // pic13 PIC_ Small GOT < 2^13 bytes
70 // pic32 PIC_ Medium GOT < 2^32 bytes
71 //
72 // All code models require that the text segment is smaller than 2GB.
74  Reloc::Model RM, bool Is64Bit,
75  bool JIT) {
76  if (CM)
77  return *CM;
78  if (Is64Bit) {
79  if (JIT)
80  return CodeModel::Large;
82  }
83  return CodeModel::Small;
84 }
85 
86 /// Create an ILP32 architecture model
88  const Target &T, const Triple &TT, StringRef CPU, StringRef FS,
89  const TargetOptions &Options, Optional<Reloc::Model> RM,
90  Optional<CodeModel::Model> CM, CodeGenOpt::Level OL, bool JIT, bool is64bit)
92  T, computeDataLayout(TT, is64bit), TT, CPU, FS, Options,
94  getEffectiveCodeModel(CM, getEffectiveRelocModel(RM), is64bit, JIT),
95  OL),
97  Subtarget(TT, CPU, FS, *this, is64bit), is64Bit(is64bit) {
98  initAsmInfo();
99 }
100 
102 
103 const SparcSubtarget *
105  Attribute CPUAttr = F.getFnAttribute("target-cpu");
106  Attribute FSAttr = F.getFnAttribute("target-features");
107 
108  std::string CPU = !CPUAttr.hasAttribute(Attribute::None)
109  ? CPUAttr.getValueAsString().str()
110  : TargetCPU;
111  std::string FS = !FSAttr.hasAttribute(Attribute::None)
112  ? FSAttr.getValueAsString().str()
113  : TargetFS;
114 
115  // FIXME: This is related to the code below to reset the target options,
116  // we need to know whether or not the soft float flag is set on the
117  // function, so we can enable it as a subtarget feature.
118  bool softFloat =
119  F.hasFnAttribute("use-soft-float") &&
120  F.getFnAttribute("use-soft-float").getValueAsString() == "true";
121 
122  if (softFloat)
123  FS += FS.empty() ? "+soft-float" : ",+soft-float";
124 
125  auto &I = SubtargetMap[CPU + FS];
126  if (!I) {
127  // This needs to be done before we create a new subtarget since any
128  // creation will depend on the TM and the code generation flags on the
129  // function that reside in TargetOptions.
131  I = llvm::make_unique<SparcSubtarget>(TargetTriple, CPU, FS, *this,
132  this->is64Bit);
133  }
134  return I.get();
135 }
136 
137 namespace {
138 /// Sparc Code Generator Pass Configuration Options.
139 class SparcPassConfig : public TargetPassConfig {
140 public:
141  SparcPassConfig(SparcTargetMachine &TM, PassManagerBase &PM)
142  : TargetPassConfig(TM, PM) {}
143 
144  SparcTargetMachine &getSparcTargetMachine() const {
145  return getTM<SparcTargetMachine>();
146  }
147 
148  void addIRPasses() override;
149  bool addInstSelector() override;
150  void addPreEmitPass() override;
151 };
152 } // namespace
153 
155  return new SparcPassConfig(*this, PM);
156 }
157 
158 void SparcPassConfig::addIRPasses() {
159  addPass(createAtomicExpandPass());
160 
162 }
163 
164 bool SparcPassConfig::addInstSelector() {
165  addPass(createSparcISelDag(getSparcTargetMachine()));
166  return false;
167 }
168 
169 void SparcPassConfig::addPreEmitPass(){
171 
172  if (this->getSparcTargetMachine().getSubtargetImpl()->insertNOPLoad())
173  {
174  addPass(new InsertNOPLoad());
175  }
176  if (this->getSparcTargetMachine().getSubtargetImpl()->detectRoundChange()) {
177  addPass(new DetectRoundChange());
178  }
179  if (this->getSparcTargetMachine().getSubtargetImpl()->fixAllFDIVSQRT())
180  {
181  addPass(new FixAllFDIVSQRT());
182  }
183 }
184 
185 void SparcV8TargetMachine::anchor() { }
186 
188  StringRef CPU, StringRef FS,
189  const TargetOptions &Options,
192  CodeGenOpt::Level OL, bool JIT)
193  : SparcTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, JIT, false) {}
194 
195 void SparcV9TargetMachine::anchor() { }
196 
198  StringRef CPU, StringRef FS,
199  const TargetOptions &Options,
202  CodeGenOpt::Level OL, bool JIT)
203  : SparcTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, JIT, true) {}
204 
205 void SparcelTargetMachine::anchor() {}
206 
208  StringRef CPU, StringRef FS,
209  const TargetOptions &Options,
212  CodeGenOpt::Level OL, bool JIT)
213  : SparcTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, JIT, false) {}
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:228
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
FunctionPass * createSparcDelaySlotFillerPass()
createSparcDelaySlotFillerPass - Returns a pass that fills in delay slots in Sparc MachineFunctions ...
virtual void addIRPasses()
Add common target configurable passes that perform LLVM IR to IR transforms following machine indepen...
Triple TargetTriple
Triple string, CPU name, and target feature strings the TargetMachine instance is created with...
Definition: TargetMachine.h:76
SparcelTargetMachine(const Target &T, const Triple &TT, StringRef CPU, StringRef FS, const TargetOptions &Options, Optional< Reloc::Model > RM, Optional< CodeModel::Model > CM, CodeGenOpt::Level OL, bool JIT)
SparcV8TargetMachine(const Target &T, const Triple &TT, StringRef CPU, StringRef FS, const TargetOptions &Options, Optional< Reloc::Model > RM, Optional< CodeModel::Model > CM, CodeGenOpt::Level OL, bool JIT)
const SparcSubtarget * getSubtargetImpl() const
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition: Function.h:262
F(f)
std::enable_if<!std::is_array< T >::value, std::unique_ptr< T > >::type make_unique(Args &&... args)
Constructs a new T() with the given args and returns a unique_ptr<T> which owns the object...
Definition: STLExtras.h:944
void LLVMInitializeSparcTarget()
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
void resetTargetOptions(const Function &F) const
Reset the target options based on the function&#39;s attributes.
No attributes have been set.
Definition: Attributes.h:72
Target-Independent Code Generator Pass Configuration Options.
RegisterTargetMachine - Helper template for registering a target machine implementation, for use in the target machine initialization function.
ArchType getArch() const
getArch - Get the parsed architecture type of this triple.
Definition: Triple.h:285
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:133
Target & getTheSparcTarget()
static CodeModel::Model getEffectiveCodeModel(Optional< CodeModel::Model > CM)
bool hasAttribute(AttrKind Val) const
Return true if the attribute is present.
Definition: Attributes.cpp:202
static Reloc::Model getEffectiveRelocModel(Optional< Reloc::Model > RM)
static bool is64Bit(const char *name)
Target & getTheSparcelTarget()
This class describes a target machine that is implemented with the LLVM target-independent code gener...
FunctionPass * createSparcISelDag(SparcTargetMachine &TM)
createSparcISelDag - This pass converts a legalized DAG into a SPARC-specific DAG, ready for instruction scheduling.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
PassManagerBase - An abstract interface to allow code to add passes to a pass manager without having ...
SparcTargetMachine(const Target &T, const Triple &TT, StringRef CPU, StringRef FS, const TargetOptions &Options, Optional< Reloc::Model > RM, Optional< CodeModel::Model > CM, CodeGenOpt::Level OL, bool JIT, bool is64bit)
Create an ILP32 architecture model.
Target - Wrapper for Target specific information.
std::string TargetCPU
Definition: TargetMachine.h:77
Target & getTheSparcV9Target()
static std::string computeDataLayout(const Triple &T, bool is64Bit)
Basic Alias true
bool hasValue() const
Definition: Optional.h:137
StringRef getValueAsString() const
Return the attribute&#39;s value as a string.
Definition: Attributes.cpp:195
TargetOptions Options
Definition: TargetMachine.h:96
#define I(x, y, z)
Definition: MD5.cpp:58
std::string TargetFS
Definition: TargetMachine.h:78
TargetPassConfig * createPassConfig(PassManagerBase &PM) override
Create a pass configuration object to be used by addPassToEmitX methods for generating a pipeline of ...
SparcV9TargetMachine(const Target &T, const Triple &TT, StringRef CPU, StringRef FS, const TargetOptions &Options, Optional< Reloc::Model > RM, Optional< CodeModel::Model > CM, CodeGenOpt::Level OL, bool JIT)
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
Definition: Function.h:270
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
FunctionPass * createAtomicExpandPass()