120
|
1 //===-- LanaiMCTargetDesc.cpp - Lanai Target Descriptions -----------------===//
|
|
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 // This file provides Lanai specific target descriptions.
|
|
11 //
|
|
12 //===----------------------------------------------------------------------===//
|
|
13
|
|
14 #include "LanaiMCTargetDesc.h"
|
|
15
|
|
16 #include "InstPrinter/LanaiInstPrinter.h"
|
|
17 #include "LanaiMCAsmInfo.h"
|
|
18 #include "llvm/MC/MCInstrAnalysis.h"
|
|
19 #include "llvm/MC/MCInstrInfo.h"
|
|
20 #include "llvm/MC/MCStreamer.h"
|
|
21 #include "llvm/MC/MCSubtargetInfo.h"
|
|
22 #include "llvm/Support/ErrorHandling.h"
|
|
23 #include "llvm/Support/TargetRegistry.h"
|
|
24
|
|
25 #define GET_INSTRINFO_MC_DESC
|
|
26 #include "LanaiGenInstrInfo.inc"
|
|
27
|
|
28 #define GET_SUBTARGETINFO_MC_DESC
|
|
29 #include "LanaiGenSubtargetInfo.inc"
|
|
30
|
|
31 #define GET_REGINFO_MC_DESC
|
|
32 #include "LanaiGenRegisterInfo.inc"
|
|
33
|
|
34 using namespace llvm;
|
|
35
|
|
36 static MCInstrInfo *createLanaiMCInstrInfo() {
|
|
37 MCInstrInfo *X = new MCInstrInfo();
|
|
38 InitLanaiMCInstrInfo(X);
|
|
39 return X;
|
|
40 }
|
|
41
|
|
42 static MCRegisterInfo *createLanaiMCRegisterInfo(const Triple & /*TT*/) {
|
|
43 MCRegisterInfo *X = new MCRegisterInfo();
|
|
44 InitLanaiMCRegisterInfo(X, Lanai::RCA, 0, 0, Lanai::PC);
|
|
45 return X;
|
|
46 }
|
|
47
|
|
48 static MCSubtargetInfo *
|
|
49 createLanaiMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS) {
|
|
50 std::string CPUName = CPU;
|
|
51 if (CPUName.empty())
|
|
52 CPUName = "generic";
|
|
53
|
|
54 return createLanaiMCSubtargetInfoImpl(TT, CPUName, FS);
|
|
55 }
|
|
56
|
|
57 static MCStreamer *createMCStreamer(const Triple &T, MCContext &Context,
|
|
58 MCAsmBackend &MAB, raw_pwrite_stream &OS,
|
|
59 MCCodeEmitter *Emitter, bool RelaxAll) {
|
|
60 if (!T.isOSBinFormatELF())
|
|
61 llvm_unreachable("OS not supported");
|
|
62
|
|
63 return createELFStreamer(Context, MAB, OS, Emitter, RelaxAll);
|
|
64 }
|
|
65
|
|
66 static MCInstPrinter *createLanaiMCInstPrinter(const Triple & /*T*/,
|
|
67 unsigned SyntaxVariant,
|
|
68 const MCAsmInfo &MAI,
|
|
69 const MCInstrInfo &MII,
|
|
70 const MCRegisterInfo &MRI) {
|
|
71 if (SyntaxVariant == 0)
|
|
72 return new LanaiInstPrinter(MAI, MII, MRI);
|
|
73 return 0;
|
|
74 }
|
|
75
|
|
76 static MCRelocationInfo *createLanaiElfRelocation(const Triple &TheTriple,
|
|
77 MCContext &Ctx) {
|
|
78 return createMCRelocationInfo(TheTriple, Ctx);
|
|
79 }
|
|
80
|
|
81 namespace {
|
|
82 class LanaiMCInstrAnalysis : public MCInstrAnalysis {
|
|
83 public:
|
|
84 explicit LanaiMCInstrAnalysis(const MCInstrInfo *Info)
|
|
85 : MCInstrAnalysis(Info) {}
|
|
86
|
|
87 bool evaluateBranch(const MCInst &Inst, uint64_t Addr, uint64_t Size,
|
|
88 uint64_t &Target) const override {
|
|
89 if (Inst.getNumOperands() == 0)
|
|
90 return false;
|
|
91
|
|
92 if (Info->get(Inst.getOpcode()).OpInfo[0].OperandType ==
|
|
93 MCOI::OPERAND_PCREL) {
|
|
94 int64_t Imm = Inst.getOperand(0).getImm();
|
|
95 Target = Addr + Size + Imm;
|
|
96 return true;
|
|
97 } else {
|
|
98 int64_t Imm = Inst.getOperand(0).getImm();
|
|
99
|
|
100 // Skip case where immediate is 0 as that occurs in file that isn't linked
|
|
101 // and the branch target inferred would be wrong.
|
|
102 if (Imm == 0)
|
|
103 return false;
|
|
104
|
|
105 Target = Imm;
|
|
106 return true;
|
|
107 }
|
|
108 }
|
|
109 };
|
|
110 } // end anonymous namespace
|
|
111
|
|
112 static MCInstrAnalysis *createLanaiInstrAnalysis(const MCInstrInfo *Info) {
|
|
113 return new LanaiMCInstrAnalysis(Info);
|
|
114 }
|
|
115
|
|
116 extern "C" void LLVMInitializeLanaiTargetMC() {
|
|
117 // Register the MC asm info.
|
|
118 RegisterMCAsmInfo<LanaiMCAsmInfo> X(getTheLanaiTarget());
|
|
119
|
|
120 // Register the MC instruction info.
|
|
121 TargetRegistry::RegisterMCInstrInfo(getTheLanaiTarget(),
|
|
122 createLanaiMCInstrInfo);
|
|
123
|
|
124 // Register the MC register info.
|
|
125 TargetRegistry::RegisterMCRegInfo(getTheLanaiTarget(),
|
|
126 createLanaiMCRegisterInfo);
|
|
127
|
|
128 // Register the MC subtarget info.
|
|
129 TargetRegistry::RegisterMCSubtargetInfo(getTheLanaiTarget(),
|
|
130 createLanaiMCSubtargetInfo);
|
|
131
|
|
132 // Register the MC code emitter
|
|
133 TargetRegistry::RegisterMCCodeEmitter(getTheLanaiTarget(),
|
|
134 llvm::createLanaiMCCodeEmitter);
|
|
135
|
|
136 // Register the ASM Backend
|
|
137 TargetRegistry::RegisterMCAsmBackend(getTheLanaiTarget(),
|
|
138 createLanaiAsmBackend);
|
|
139
|
|
140 // Register the MCInstPrinter.
|
|
141 TargetRegistry::RegisterMCInstPrinter(getTheLanaiTarget(),
|
|
142 createLanaiMCInstPrinter);
|
|
143
|
|
144 // Register the ELF streamer.
|
|
145 TargetRegistry::RegisterELFStreamer(getTheLanaiTarget(), createMCStreamer);
|
|
146
|
|
147 // Register the MC relocation info.
|
|
148 TargetRegistry::RegisterMCRelocationInfo(getTheLanaiTarget(),
|
|
149 createLanaiElfRelocation);
|
|
150
|
|
151 // Register the MC instruction analyzer.
|
|
152 TargetRegistry::RegisterMCInstrAnalysis(getTheLanaiTarget(),
|
|
153 createLanaiInstrAnalysis);
|
|
154 }
|