annotate lib/Target/Nios2/Nios2TargetMachine.cpp @ 121:803732b1fca8

LLVM 5.0
author kono
date Fri, 27 Oct 2017 17:07:41 +0900
parents
children 3a76565eade5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
1 //===-- Nios2TargetMachine.cpp - Define TargetMachine for Nios2 -----------===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
2 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
3 // The LLVM Compiler Infrastructure
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
4 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
5 // This file is distributed under the University of Illinois Open Source
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
6 // License. See LICENSE.TXT for details.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
7 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
8 //===----------------------------------------------------------------------===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
9 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
10 // Implements the info about Nios2 target spec.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
11 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
12 //===----------------------------------------------------------------------===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
13
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
14 #include "Nios2TargetMachine.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
15 #include "Nios2.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
16
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
17 #include "llvm/CodeGen/TargetPassConfig.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
18 #include "llvm/Support/TargetRegistry.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
19
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
20 using namespace llvm;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
21
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
22 #define DEBUG_TYPE "nios2"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
23
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
24 extern "C" void LLVMInitializeNios2Target() {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
25 // Register the target.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
26 RegisterTargetMachine<Nios2TargetMachine> X(getTheNios2Target());
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
27 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
28
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
29 static std::string computeDataLayout() {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
30 return "e-p:32:32:32-i8:8:32-i16:16:32-n32";
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
31 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
32
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
33 static Reloc::Model getEffectiveRelocModel(Optional<Reloc::Model> RM) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
34 if (!RM.hasValue())
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
35 return Reloc::Static;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
36 return *RM;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
37 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
38
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
39 Nios2TargetMachine::Nios2TargetMachine(const Target &T, const Triple &TT,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
40 StringRef CPU, StringRef FS,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
41 const TargetOptions &Options,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
42 Optional<Reloc::Model> RM,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
43 Optional<CodeModel::Model> CM,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
44 CodeGenOpt::Level OL, bool JIT)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
45 : LLVMTargetMachine(T, computeDataLayout(), TT, CPU, FS, Options,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
46 getEffectiveRelocModel(RM), *CM, OL) {}
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
47
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
48 Nios2TargetMachine::~Nios2TargetMachine() {}
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
49
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
50 const Nios2Subtarget *
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
51 Nios2TargetMachine::getSubtargetImpl(const Function &F) const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
52 Attribute CPUAttr = F.getFnAttribute("target-cpu");
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
53 Attribute FSAttr = F.getFnAttribute("target-features");
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
54
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
55 std::string CPU = !CPUAttr.hasAttribute(Attribute::None)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
56 ? CPUAttr.getValueAsString().str()
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
57 : TargetCPU;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
58 std::string FS = !FSAttr.hasAttribute(Attribute::None)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
59 ? FSAttr.getValueAsString().str()
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
60 : TargetFS;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
61
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
62 auto &I = SubtargetMap[CPU + FS];
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
63 if (!I) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
64 // This needs to be done before we create a new subtarget since any
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
65 // creation will depend on the TM and the code generation flags on the
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
66 // function that reside in TargetOptions.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
67 resetTargetOptions(F);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
68 I = llvm::make_unique<Nios2Subtarget>(TargetTriple, CPU, FS, *this);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
69 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
70 return I.get();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
71 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
72
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
73 namespace {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
74 /// Nios2 Code Generator Pass Configuration Options.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
75 class Nios2PassConfig : public TargetPassConfig {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
76 public:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
77 Nios2PassConfig(Nios2TargetMachine &TM, PassManagerBase *PM)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
78 : TargetPassConfig(TM, *PM) {}
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
79
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
80 Nios2TargetMachine &getNios2TargetMachine() const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
81 return getTM<Nios2TargetMachine>();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
82 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
83
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
84 void addCodeGenPrepare() override;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
85 void addIRPasses() override;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
86 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
87 } // namespace
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
88
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
89 TargetPassConfig *Nios2TargetMachine::createPassConfig(PassManagerBase &PM) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
90 return new Nios2PassConfig(*this, &PM);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
91 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
92
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
93 void Nios2PassConfig::addCodeGenPrepare() {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
94 TargetPassConfig::addCodeGenPrepare();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
95 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
96
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
97 void Nios2PassConfig::addIRPasses() { TargetPassConfig::addIRPasses(); }