121
|
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
|
|
17 #include "llvm/CodeGen/TargetPassConfig.h"
|
|
18 #include "llvm/Support/TargetRegistry.h"
|
|
19
|
|
20 using namespace llvm;
|
|
21
|
|
22 #define DEBUG_TYPE "nios2"
|
|
23
|
|
24 extern "C" void LLVMInitializeNios2Target() {
|
|
25 // Register the target.
|
|
26 RegisterTargetMachine<Nios2TargetMachine> X(getTheNios2Target());
|
|
27 }
|
|
28
|
|
29 static std::string computeDataLayout() {
|
|
30 return "e-p:32:32:32-i8:8:32-i16:16:32-n32";
|
|
31 }
|
|
32
|
|
33 static Reloc::Model getEffectiveRelocModel(Optional<Reloc::Model> RM) {
|
|
34 if (!RM.hasValue())
|
|
35 return Reloc::Static;
|
|
36 return *RM;
|
|
37 }
|
|
38
|
|
39 Nios2TargetMachine::Nios2TargetMachine(const Target &T, const Triple &TT,
|
|
40 StringRef CPU, StringRef FS,
|
|
41 const TargetOptions &Options,
|
|
42 Optional<Reloc::Model> RM,
|
|
43 Optional<CodeModel::Model> CM,
|
|
44 CodeGenOpt::Level OL, bool JIT)
|
|
45 : LLVMTargetMachine(T, computeDataLayout(), TT, CPU, FS, Options,
|
|
46 getEffectiveRelocModel(RM), *CM, OL) {}
|
|
47
|
|
48 Nios2TargetMachine::~Nios2TargetMachine() {}
|
|
49
|
|
50 const Nios2Subtarget *
|
|
51 Nios2TargetMachine::getSubtargetImpl(const Function &F) const {
|
|
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.
|
|
67 resetTargetOptions(F);
|
|
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
|
|
89 TargetPassConfig *Nios2TargetMachine::createPassConfig(PassManagerBase &PM) {
|
|
90 return new Nios2PassConfig(*this, &PM);
|
|
91 }
|
|
92
|
|
93 void Nios2PassConfig::addCodeGenPrepare() {
|
|
94 TargetPassConfig::addCodeGenPrepare();
|
|
95 }
|
|
96
|
|
97 void Nios2PassConfig::addIRPasses() { TargetPassConfig::addIRPasses(); }
|