LLVM  6.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 
19 
20 using namespace llvm;
21 
22 #define DEBUG_TYPE "nios2"
23 
24 extern "C" void LLVMInitializeNios2Target() {
25  // Register the target.
27 }
28 
29 static std::string computeDataLayout() {
30  return "e-p:32:32:32-i8:8:32-i16:16:32-n32";
31 }
32 
34  if (!RM.hasValue())
35  return Reloc::Static;
36  return *RM;
37 }
38 
40  StringRef CPU, StringRef FS,
41  const TargetOptions &Options,
44  CodeGenOpt::Level OL, bool JIT)
45  : LLVMTargetMachine(T, computeDataLayout(), TT, CPU, FS, Options,
46  getEffectiveRelocModel(RM), *CM, OL) {}
47 
49 
50 const Nios2Subtarget *
52  Attribute CPUAttr = F.getFnAttribute("target-cpu");
53  Attribute FSAttr = F.getFnAttribute("target-features");
54 
55  std::string CPU = !CPUAttr.hasAttribute(Attribute::None)
56  ? CPUAttr.getValueAsString().str()
57  : TargetCPU;
58  std::string FS = !FSAttr.hasAttribute(Attribute::None)
59  ? FSAttr.getValueAsString().str()
60  : TargetFS;
61 
62  auto &I = SubtargetMap[CPU + FS];
63  if (!I) {
64  // This needs to be done before we create a new subtarget since any
65  // creation will depend on the TM and the code generation flags on the
66  // function that reside in TargetOptions.
68  I = llvm::make_unique<Nios2Subtarget>(TargetTriple, CPU, FS, *this);
69  }
70  return I.get();
71 }
72 
73 namespace {
74 /// Nios2 Code Generator Pass Configuration Options.
75 class Nios2PassConfig : public TargetPassConfig {
76 public:
77  Nios2PassConfig(Nios2TargetMachine &TM, PassManagerBase *PM)
78  : TargetPassConfig(TM, *PM) {}
79 
80  Nios2TargetMachine &getNios2TargetMachine() const {
81  return getTM<Nios2TargetMachine>();
82  }
83 
84  void addCodeGenPrepare() override;
85  void addIRPasses() override;
86 };
87 } // namespace
88 
90  return new Nios2PassConfig(*this, &PM);
91 }
92 
93 void Nios2PassConfig::addCodeGenPrepare() {
95 }
96 
97 void Nios2PassConfig::addIRPasses() { TargetPassConfig::addIRPasses(); }
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:76
TargetPassConfig * createPassConfig(PassManagerBase &PM) override
Create a pass configuration object to be used by addPassToEmitX methods for generating a pipeline of ...
F(f)
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
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 Function &F) const override
Virtual method implemented by subclasses that returns a reference to that target&#39;s TargetSubtargetInf...
PassManagerBase - An abstract interface to allow code to add passes to a pass manager without having ...
Target - Wrapper for Target specific information.
std::string TargetCPU
Definition: TargetMachine.h:77
bool hasValue() const
Definition: Optional.h:137
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:78
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
static std::string computeDataLayout()