LLVM 20.0.0git
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"
14#include "LanaiInstPrinter.h"
15#include "LanaiMCAsmInfo.h"
17#include "llvm/ADT/StringRef.h"
18#include "llvm/MC/MCInst.h"
20#include "llvm/MC/MCInstrInfo.h"
22#include "llvm/MC/MCStreamer.h"
27#include <cstdint>
28#include <string>
29
30#define GET_INSTRINFO_MC_DESC
31#define ENABLE_INSTR_PREDICATE_VERIFIER
32#include "LanaiGenInstrInfo.inc"
33
34#define GET_SUBTARGETINFO_MC_DESC
35#include "LanaiGenSubtargetInfo.inc"
36
37#define GET_REGINFO_MC_DESC
38#include "LanaiGenRegisterInfo.inc"
39
40using namespace llvm;
41
43 MCInstrInfo *X = new MCInstrInfo();
44 InitLanaiMCInstrInfo(X);
45 return X;
46}
47
50 InitLanaiMCRegisterInfo(X, Lanai::RCA, 0, 0, Lanai::PC);
51 return X;
52}
53
54static MCSubtargetInfo *
56 std::string CPUName = std::string(CPU);
57 if (CPUName.empty())
58 CPUName = "generic";
59
60 return createLanaiMCSubtargetInfoImpl(TT, CPUName, /*TuneCPU*/ CPUName, FS);
61}
62
63static MCStreamer *createMCStreamer(const Triple &T, MCContext &Context,
64 std::unique_ptr<MCAsmBackend> &&MAB,
65 std::unique_ptr<MCObjectWriter> &&OW,
66 std::unique_ptr<MCCodeEmitter> &&Emitter) {
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));
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
89namespace {
90
91class LanaiMCInstrAnalysis : public MCInstrAnalysis {
92public:
93 explicit LanaiMCInstrAnalysis(const MCInstrInfo *Info)
95
97 uint64_t &Target) const override {
98 if (Inst.getNumOperands() == 0)
99 return false;
100 if (!isConditionalBranch(Inst) && !isUnconditionalBranch(Inst) &&
101 !isCall(Inst))
102 return false;
103
104 if (Info->get(Inst.getOpcode()).operands()[0].OperandType ==
106 int64_t Imm = Inst.getOperand(0).getImm();
107 Target = Addr + Size + Imm;
108 return true;
109 } else {
110 int64_t Imm = Inst.getOperand(0).getImm();
111
112 // Skip case where immediate is 0 as that occurs in file that isn't linked
113 // and the branch target inferred would be wrong.
114 if (Imm == 0)
115 return false;
116
117 Target = Imm;
118 return true;
119 }
120 }
121};
122
123} // end anonymous namespace
124
126 return new LanaiMCInstrAnalysis(Info);
127}
128
130 // Register the MC asm info.
132
133 // Register the MC instruction info.
136
137 // Register the MC register info.
140
141 // Register the MC subtarget info.
144
145 // Register the MC code emitter
148
149 // Register the ASM Backend
152
153 // Register the MCInstPrinter.
156
157 // Register the ELF streamer.
159
160 // Register the MC relocation info.
163
164 // Register the MC instruction analyzer.
167}
unsigned const MachineRegisterInfo * MRI
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
#define LLVM_EXTERNAL_VISIBILITY
Definition: Compiler.h:128
dxil DXContainer Global Emitter
uint64_t Addr
uint64_t Size
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
static MCInstrAnalysis * createLanaiInstrAnalysis(const MCInstrInfo *Info)
static MCInstrInfo * createLanaiMCInstrInfo()
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeLanaiTargetMC()
static MCSubtargetInfo * createLanaiMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS)
static MCStreamer * createMCStreamer(const Triple &T, MCContext &Context, std::unique_ptr< MCAsmBackend > &&MAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&Emitter)
static MCInstPrinter * createLanaiMCInstPrinter(const Triple &, unsigned SyntaxVariant, const MCAsmInfo &MAI, const MCInstrInfo &MII, const MCRegisterInfo &MRI)
static MCRelocationInfo * createLanaiElfRelocation(const Triple &TheTriple, MCContext &Ctx)
static MCRegisterInfo * createLanaiMCRegisterInfo(const Triple &)
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
Context object for machine code objects.
Definition: MCContext.h:83
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
Definition: MCInstPrinter.h:46
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:185
unsigned getNumOperands() const
Definition: MCInst.h:209
unsigned getOpcode() const
Definition: MCInst.h:199
const MCOperand & getOperand(unsigned i) const
Definition: MCInst.h:207
virtual bool isCall(const MCInst &Inst) const
virtual bool isUnconditionalBranch(const MCInst &Inst) const
virtual bool evaluateBranch(const MCInst &Inst, uint64_t Addr, uint64_t Size, uint64_t &Target) const
Given a branch instruction try to get the address the branch targets.
virtual bool isConditionalBranch(const MCInst &Inst) const
Interface to description of machine instruction set.
Definition: MCInstrInfo.h:26
int64_t getImm() const
Definition: MCInst.h:81
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Create MCExprs from relocations found in an object file.
Streaming machine code generation interface.
Definition: MCStreamer.h:213
Generic base class for all target subtargets.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
MCCodeEmitter * createLanaiMCCodeEmitter(const MCInstrInfo &MCII, MCContext &Ctx)
MCStreamer * createELFStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE)
Target & getTheLanaiTarget()
MCRelocationInfo * createMCRelocationInfo(const Triple &TT, MCContext &Ctx)
MCAsmBackend * createLanaiAsmBackend(const Target &T, const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options)
RegisterMCAsmInfo - Helper template for registering a target assembly info implementation.
static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn)
RegisterMCRegInfo - Register a MCRegisterInfo implementation for the given target.
static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn)
RegisterMCAsmBackend - Register a MCAsmBackend implementation for the given target.
static void RegisterMCCodeEmitter(Target &T, Target::MCCodeEmitterCtorTy Fn)
RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the given target.
static void RegisterMCSubtargetInfo(Target &T, Target::MCSubtargetInfoCtorFnTy Fn)
RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for the given target.
static void RegisterMCInstrAnalysis(Target &T, Target::MCInstrAnalysisCtorFnTy Fn)
RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for the given target.
static void RegisterELFStreamer(Target &T, Target::ELFStreamerCtorTy Fn)
static void RegisterMCInstPrinter(Target &T, Target::MCInstPrinterCtorTy Fn)
RegisterMCInstPrinter - Register a MCInstPrinter implementation for the given target.
static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn)
RegisterMCInstrInfo - Register a MCInstrInfo implementation for the given target.
static void RegisterMCRelocationInfo(Target &T, Target::MCRelocationInfoCtorTy Fn)
RegisterMCRelocationInfo - Register an MCRelocationInfo implementation for the given target.