LLVM  8.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  StringRef CPU, StringRef FS,
42  const TargetOptions &Options,
45  CodeGenOpt::Level OL, bool JIT)
46  : LLVMTargetMachine(T, computeDataLayout(), TT, CPU, FS, Options,
48  getEffectiveCodeModel(CM, CodeModel::Small), OL),
50  Subtarget(TT, CPU, FS, *this) {
51  initAsmInfo();
52 }
53 
55 
56 const Nios2Subtarget *
58  Attribute CPUAttr = F.getFnAttribute("target-cpu");
59  Attribute FSAttr = F.getFnAttribute("target-features");
60 
61  std::string CPU = !CPUAttr.hasAttribute(Attribute::None)
62  ? CPUAttr.getValueAsString().str()
63  : TargetCPU;
64  std::string FS = !FSAttr.hasAttribute(Attribute::None)
65  ? FSAttr.getValueAsString().str()
66  : TargetFS;
67 
68  auto &I = SubtargetMap[CPU + FS];
69  if (!I) {
70  // This needs to be done before we create a new subtarget since any
71  // creation will depend on the TM and the code generation flags on the
72  // function that reside in TargetOptions.
74  I = llvm::make_unique<Nios2Subtarget>(TargetTriple, CPU, FS, *this);
75  }
76  return I.get();
77 }
78 
79 namespace {
80 /// Nios2 Code Generator Pass Configuration Options.
81 class Nios2PassConfig : public TargetPassConfig {
82 public:
83  Nios2PassConfig(Nios2TargetMachine &TM, PassManagerBase *PM)
84  : TargetPassConfig(TM, *PM) {}
85 
86  Nios2TargetMachine &getNios2TargetMachine() const {
87  return getTM<Nios2TargetMachine>();
88  }
89 
90  void addCodeGenPrepare() override;
91  bool addInstSelector() override;
92  void addIRPasses() override;
93 };
94 } // namespace
95 
97  return new Nios2PassConfig(*this, &PM);
98 }
99 
100 void Nios2PassConfig::addCodeGenPrepare() {
102 }
103 
104 void Nios2PassConfig::addIRPasses() { TargetPassConfig::addIRPasses(); }
105 
106 // Install an instruction selector pass using
107 // the ISelDag to gen Nios2 code.
108 bool Nios2PassConfig::addInstSelector() {
109  addPass(createNios2ISelDag(getNios2TargetMachine(), getOptLevel()));
110  return false;
111 }
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
CodeModel::Model getEffectiveCodeModel(Optional< CodeModel::Model > CM, CodeModel::Model Default)
Helper method for getting the code model, returning Default if CM does not have a value...
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:228
This class represents lattice values for constants.
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:1343
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()
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:165
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:331
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
static std::string computeDataLayout()