LLVM  9.0.0svn
LanaiMCTargetDesc.cpp
Go to the documentation of this file.
1 //===-- LanaiMCTargetDesc.cpp - Lanai Target Descriptions -----------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file provides Lanai specific target descriptions.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "LanaiMCTargetDesc.h"
15 #include "LanaiMCAsmInfo.h"
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/ADT/Triple.h"
18 #include "llvm/MC/MCInst.h"
20 #include "llvm/MC/MCInstrInfo.h"
21 #include "llvm/MC/MCRegisterInfo.h"
22 #include "llvm/MC/MCStreamer.h"
26 #include <cstdint>
27 #include <string>
28 
29 #define GET_INSTRINFO_MC_DESC
30 #include "LanaiGenInstrInfo.inc"
31 
32 #define GET_SUBTARGETINFO_MC_DESC
33 #include "LanaiGenSubtargetInfo.inc"
34 
35 #define GET_REGINFO_MC_DESC
36 #include "LanaiGenRegisterInfo.inc"
37 
38 using namespace llvm;
39 
41  MCInstrInfo *X = new MCInstrInfo();
42  InitLanaiMCInstrInfo(X);
43  return X;
44 }
45 
48  InitLanaiMCRegisterInfo(X, Lanai::RCA, 0, 0, Lanai::PC);
49  return X;
50 }
51 
52 static MCSubtargetInfo *
54  std::string CPUName = CPU;
55  if (CPUName.empty())
56  CPUName = "generic";
57 
58  return createLanaiMCSubtargetInfoImpl(TT, CPUName, FS);
59 }
60 
62  std::unique_ptr<MCAsmBackend> &&MAB,
63  std::unique_ptr<MCObjectWriter> &&OW,
64  std::unique_ptr<MCCodeEmitter> &&Emitter,
65  bool RelaxAll) {
66  if (!T.isOSBinFormatELF())
67  llvm_unreachable("OS not supported");
68 
69  return createELFStreamer(Context, std::move(MAB), std::move(OW),
70  std::move(Emitter), RelaxAll);
71 }
72 
74  unsigned SyntaxVariant,
75  const MCAsmInfo &MAI,
76  const MCInstrInfo &MII,
77  const MCRegisterInfo &MRI) {
78  if (SyntaxVariant == 0)
79  return new LanaiInstPrinter(MAI, MII, MRI);
80  return nullptr;
81 }
82 
84  MCContext &Ctx) {
85  return createMCRelocationInfo(TheTriple, Ctx);
86 }
87 
88 namespace {
89 
90 class LanaiMCInstrAnalysis : public MCInstrAnalysis {
91 public:
92  explicit LanaiMCInstrAnalysis(const MCInstrInfo *Info)
93  : MCInstrAnalysis(Info) {}
94 
95  bool evaluateBranch(const MCInst &Inst, uint64_t Addr, uint64_t Size,
96  uint64_t &Target) const override {
97  if (Inst.getNumOperands() == 0)
98  return false;
99 
100  if (Info->get(Inst.getOpcode()).OpInfo[0].OperandType ==
102  int64_t Imm = Inst.getOperand(0).getImm();
103  Target = Addr + Size + Imm;
104  return true;
105  } else {
106  int64_t Imm = Inst.getOperand(0).getImm();
107 
108  // Skip case where immediate is 0 as that occurs in file that isn't linked
109  // and the branch target inferred would be wrong.
110  if (Imm == 0)
111  return false;
112 
113  Target = Imm;
114  return true;
115  }
116  }
117 };
118 
119 } // end anonymous namespace
120 
122  return new LanaiMCInstrAnalysis(Info);
123 }
124 
125 extern "C" void LLVMInitializeLanaiTargetMC() {
126  // Register the MC asm info.
128 
129  // Register the MC instruction info.
132 
133  // Register the MC register info.
136 
137  // Register the MC subtarget info.
140 
141  // Register the MC code emitter
144 
145  // Register the ASM Backend
148 
149  // Register the MCInstPrinter.
152 
153  // Register the ELF streamer.
155 
156  // Register the MC relocation info.
159 
160  // Register the MC instruction analyzer.
163 }
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
LLVMContext & Context
This class represents lattice values for constants.
Definition: AllocatorList.h:23
Target & getTheLanaiTarget()
bool isOSBinFormatELF() const
Tests whether the OS uses the ELF binary format.
Definition: Triple.h:608
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:62
static MCInstrAnalysis * createLanaiInstrAnalysis(const MCInstrInfo *Info)
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:158
Analysis containing CSE Info
Definition: CSEInfo.cpp:20
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:55
int64_t getImm() const
Definition: MCInst.h:75
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:188
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:23
static MCRegisterInfo * createLanaiMCRegisterInfo(const Triple &)
Create MCExprs from relocations found in an object file.
unsigned getNumOperands() const
Definition: MCInst.h:181
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:43
const MCOperand & getOperand(unsigned i) const
Definition: MCInst.h:179
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:43
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
Definition: MCInstPrinter.h:39
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
Definition: MCInstrInfo.h:44
static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn)
RegisterMCInstrInfo - Register a MCInstrInfo implementation for the given target. ...
Generic base class for all target subtargets.
uint32_t Size
Definition: Profile.cpp:46
void LLVMInitializeLanaiTargetMC()
static void RegisterELFStreamer(Target &T, Target::ELFStreamerCtorTy Fn)
RegisterMCAsmInfo - Helper template for registering a target assembly info implementation.
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:48
unsigned getOpcode() const
Definition: MCInst.h:171
MCAsmBackend * createLanaiAsmBackend(const Target &T, const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options)