LLVM  7.0.0svn
Nios2TargetMachine.cpp
Go to the documentation of this file.
1 //===-- Nios2TargetMachine.cpp - Define TargetMachine for Nios2 -----------===//
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 // Implements the info about Nios2 target spec.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "Nios2TargetMachine.h"
15 #include "Nios2.h"
16 #include "Nios2TargetObjectFile.h"
17 
20 
21 using namespace llvm;
22 
23 #define DEBUG_TYPE "nios2"
24 
25 extern "C" void LLVMInitializeNios2Target() {
26  // Register the target.
28 }
29 
30 static std::string computeDataLayout() {
31  return "e-p:32:32:32-i8:8:32-i16:16:32-n32";
32 }
33 
35  if (!RM.hasValue())
36  return Reloc::Static;
37  return *RM;
38 }
39 
41  Reloc::Model RM, bool JIT) {
42  if (CM)
43  return *CM;
44  return CodeModel::Small;
45 }
46 
48  StringRef CPU, StringRef FS,
49  const TargetOptions &Options,
52  CodeGenOpt::Level OL, bool JIT)
54  T, computeDataLayout(), TT, CPU, FS, Options,
58  Subtarget(TT, CPU, FS, *this) {
59  initAsmInfo();
60 }
61 
63 
64 const Nios2Subtarget *
66  Attribute CPUAttr = F.getFnAttribute("target-cpu");
67  Attribute FSAttr = F.getFnAttribute("target-features");
68 
69  std::string CPU = !CPUAttr.hasAttribute(Attribute::None)
70  ? CPUAttr.getValueAsString().str()
71  : TargetCPU;
72  std::string FS = !FSAttr.hasAttribute(Attribute::None)
73  ? FSAttr.getValueAsString().str()
74  : TargetFS;
75 
76  auto &I = SubtargetMap[CPU + FS];
77  if (!I) {
78  // This needs to be done before we create a new subtarget since any
79  // creation will depend on the TM and the code generation flags on the
80  // function that reside in TargetOptions.
82  I = llvm::make_unique<Nios2Subtarget>(TargetTriple, CPU, FS, *this);
83  }
84  return I.get();
85 }
86 
87 namespace {
88 /// Nios2 Code Generator Pass Configuration Options.
89 class Nios2PassConfig : public TargetPassConfig {
90 public:
91  Nios2PassConfig(Nios2TargetMachine &TM, PassManagerBase *PM)
92  : TargetPassConfig(TM, *PM) {}
93 
94  Nios2TargetMachine &getNios2TargetMachine() const {
95  return getTM<Nios2TargetMachine>();
96  }
97 
98  void addCodeGenPrepare() override;
99  bool addInstSelector() override;
100  void addIRPasses() override;
101 };
102 } // namespace
103 
105  return new Nios2PassConfig(*this, &PM);
106 }
107 
108 void Nios2PassConfig::addCodeGenPrepare() {
110 }
111 
112 void Nios2PassConfig::addIRPasses() { TargetPassConfig::addIRPasses(); }
113 
114 // Install an instruction selector pass using
115 // the ISelDag to gen Nios2 code.
116 bool Nios2PassConfig::addInstSelector() {
117  addPass(createNios2ISelDag(getNios2TargetMachine(), getOptLevel()));
118  return false;
119 }
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
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:78
TargetPassConfig * createPassConfig(PassManagerBase &PM) override
Create a pass configuration object to be used by addPassToEmitX methods for generating a pipeline of ...
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:1056
void resetTargetOptions(const Function &F) const
Reset the target options based on the function&#39;s attributes.
Target & getTheNios2Target()
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.
void LLVMInitializeNios2Target()
static CodeModel::Model getEffectiveCodeModel(Optional< CodeModel::Model > CM)
bool hasAttribute(AttrKind Val) const
Return true if the attribute is present.
Definition: Attributes.cpp:202
CodeGenOpt::Level getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
static Reloc::Model getEffectiveRelocModel(Optional< Reloc::Model > RM)
This class describes a target machine that is implemented with the LLVM target-independent code gener...
Nios2TargetMachine(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)
virtual void addCodeGenPrepare()
Add pass to prepare the LLVM IR for code generation.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
const Nios2Subtarget * getSubtargetImpl() const
PassManagerBase - An abstract interface to allow code to add passes to a pass manager without having ...
FunctionPass * createNios2ISelDag(Nios2TargetMachine &TM, CodeGenOpt::Level OptLevel)
Target - Wrapper for Target specific information.
std::string TargetCPU
Definition: TargetMachine.h:79
bool hasValue() const
Definition: Optional.h:183
StringRef getValueAsString() const
Return the attribute&#39;s value as a string.
Definition: Attributes.cpp:195
#define I(x, y, z)
Definition: MD5.cpp:58
std::string TargetFS
Definition: TargetMachine.h:80
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
Definition: Function.h:317
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
static std::string computeDataLayout()