LLVM  7.0.0svn
LanaiMCTargetDesc.cpp
Go to the documentation of this file.
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"
16 #include "LanaiMCAsmInfo.h"
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/ADT/Triple.h"
19 #include "llvm/MC/MCInst.h"
21 #include "llvm/MC/MCInstrInfo.h"
22 #include "llvm/MC/MCRegisterInfo.h"
23 #include "llvm/MC/MCStreamer.h"
27 #include <cstdint>
28 #include <string>
29 
30 #define GET_INSTRINFO_MC_DESC
31 #include "LanaiGenInstrInfo.inc"
32 
33 #define GET_SUBTARGETINFO_MC_DESC
34 #include "LanaiGenSubtargetInfo.inc"
35 
36 #define GET_REGINFO_MC_DESC
37 #include "LanaiGenRegisterInfo.inc"
38 
39 using namespace llvm;
40 
42  MCInstrInfo *X = new MCInstrInfo();
43  InitLanaiMCInstrInfo(X);
44  return X;
45 }
46 
49  InitLanaiMCRegisterInfo(X, Lanai::RCA, 0, 0, Lanai::PC);
50  return X;
51 }
52 
53 static MCSubtargetInfo *
55  std::string CPUName = CPU;
56  if (CPUName.empty())
57  CPUName = "generic";
58 
59  return createLanaiMCSubtargetInfoImpl(TT, CPUName, FS);
60 }
61 
63  std::unique_ptr<MCAsmBackend> &&MAB,
64  std::unique_ptr<MCObjectWriter> &&OW,
65  std::unique_ptr<MCCodeEmitter> &&Emitter,
66  bool RelaxAll) {
67  if (!T.isOSBinFormatELF())
68  llvm_unreachable("OS not supported");
69 
70  return createELFStreamer(Context, std::move(MAB), std::move(OW),
71  std::move(Emitter), RelaxAll);
72 }
73 
75  unsigned SyntaxVariant,
76  const MCAsmInfo &MAI,
77  const MCInstrInfo &MII,
78  const MCRegisterInfo &MRI) {
79  if (SyntaxVariant == 0)
80  return new LanaiInstPrinter(MAI, MII, MRI);
81  return nullptr;
82 }
83 
85  MCContext &Ctx) {
86  return createMCRelocationInfo(TheTriple, Ctx);
87 }
88 
89 namespace {
90 
91 class LanaiMCInstrAnalysis : public MCInstrAnalysis {
92 public:
93  explicit LanaiMCInstrAnalysis(const MCInstrInfo *Info)
94  : MCInstrAnalysis(Info) {}
95 
96  bool evaluateBranch(const MCInst &Inst, uint64_t Addr, uint64_t Size,
97  uint64_t &Target) const override {
98  if (Inst.getNumOperands() == 0)
99  return false;
100 
101  if (Info->get(Inst.getOpcode()).OpInfo[0].OperandType ==
103  int64_t Imm = Inst.getOperand(0).getImm();
104  Target = Addr + Size + Imm;
105  return true;
106  } else {
107  int64_t Imm = Inst.getOperand(0).getImm();
108 
109  // Skip case where immediate is 0 as that occurs in file that isn't linked
110  // and the branch target inferred would be wrong.
111  if (Imm == 0)
112  return false;
113 
114  Target = Imm;
115  return true;
116  }
117  }
118 };
119 
120 } // end anonymous namespace
121 
123  return new LanaiMCInstrAnalysis(Info);
124 }
125 
126 extern "C" void LLVMInitializeLanaiTargetMC() {
127  // Register the MC asm info.
129 
130  // Register the MC instruction info.
133 
134  // Register the MC register info.
137 
138  // Register the MC subtarget info.
141 
142  // Register the MC code emitter
145 
146  // Register the ASM Backend
149 
150  // Register the MCInstPrinter.
153 
154  // Register the ELF streamer.
156 
157  // Register the MC relocation info.
160 
161  // Register the MC instruction analyzer.
164 }
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
LLVMContext & Context
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
Target & getTheLanaiTarget()
bool isOSBinFormatELF() const
Tests whether the OS uses the ELF binary format.
Definition: Triple.h:588
static void RegisterMCInstrAnalysis(Target &T, Target::MCInstrAnalysisCtorFnTy Fn)
RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for the given target...
static MCStreamer * createMCStreamer(const Triple &T, MCContext &Context, std::unique_ptr< MCAsmBackend > &&MAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&Emitter, bool RelaxAll)
MCCodeEmitter * createLanaiMCCodeEmitter(const MCInstrInfo &MCII, const MCRegisterInfo &MRI, MCContext &Ctx)
static void RegisterMCInstPrinter(Target &T, Target::MCInstPrinterCtorTy Fn)
RegisterMCInstPrinter - Register a MCInstPrinter implementation for the given target.
Context object for machine code objects.
Definition: MCContext.h:63
static MCInstrAnalysis * createLanaiInstrAnalysis(const MCInstrInfo *Info)
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:161
MCRelocationInfo * createMCRelocationInfo(const Triple &TT, MCContext &Ctx)
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
int64_t getImm() const
Definition: MCInst.h:76
static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn)
RegisterMCAsmBackend - Register a MCAsmBackend implementation for the given target.
Streaming machine code generation interface.
Definition: MCStreamer.h:183
unsigned const MachineRegisterInfo * MRI
MCStreamer * createELFStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE, bool RelaxAll)
static MCInstPrinter * createLanaiMCInstPrinter(const Triple &, unsigned SyntaxVariant, const MCAsmInfo &MAI, const MCInstrInfo &MII, const MCRegisterInfo &MRI)
Interface to description of machine instruction set.
Definition: MCInstrInfo.h:24
static MCRegisterInfo * createLanaiMCRegisterInfo(const Triple &)
Create MCExprs from relocations found in an object file.
unsigned getNumOperands() const
Definition: MCInst.h:184
static void RegisterMCSubtargetInfo(Target &T, Target::MCSubtargetInfoCtorFnTy Fn)
RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for the given target...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
const MCOperand & getOperand(unsigned i) const
Definition: MCInst.h:182
static void RegisterMCCodeEmitter(Target &T, Target::MCCodeEmitterCtorTy Fn)
RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the given target.
static MCInstrInfo * createLanaiMCInstrInfo()
static MCSubtargetInfo * createLanaiMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS)
static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn)
RegisterMCRegInfo - Register a MCRegisterInfo implementation for the given target.
Target - Wrapper for Target specific information.
static MCRelocationInfo * createLanaiElfRelocation(const Triple &TheTriple, MCContext &Ctx)
OperandType
Operands are tagged with one of the values of this enum.
Definition: MCInstrDesc.h:44
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
Definition: MCInstPrinter.h:40
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
Definition: MCInstrInfo.h:45
static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn)
RegisterMCInstrInfo - Register a MCInstrInfo implementation for the given target. ...
Generic base class for all target subtargets.
void LLVMInitializeLanaiTargetMC()
static void RegisterELFStreamer(Target &T, Target::ELFStreamerCtorTy Fn)
RegisterMCAsmInfo - Helper template for registering a target assembly info implementation.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
static void RegisterMCRelocationInfo(Target &T, Target::MCRelocationInfoCtorTy Fn)
RegisterMCRelocationInfo - Register an MCRelocationInfo implementation for the given target...
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
unsigned getOpcode() const
Definition: MCInst.h:174
MCAsmBackend * createLanaiAsmBackend(const Target &T, const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options)