LLVM 20.0.0git
MipsMCTargetDesc.cpp
Go to the documentation of this file.
1//===-- MipsMCTargetDesc.cpp - Mips 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 Mips specific target descriptions.
10//
11//===----------------------------------------------------------------------===//
12
13#include "MipsMCTargetDesc.h"
14#include "MipsAsmBackend.h"
15#include "MipsBaseInfo.h"
16#include "MipsELFStreamer.h"
17#include "MipsInstPrinter.h"
18#include "MipsMCAsmInfo.h"
19#include "MipsMCNaCl.h"
20#include "MipsTargetStreamer.h"
25#include "llvm/MC/MCInstrInfo.h"
29#include "llvm/MC/MCSymbol.h"
34
35using namespace llvm;
36
37#define GET_INSTRINFO_MC_DESC
38#define ENABLE_INSTR_PREDICATE_VERIFIER
39#include "MipsGenInstrInfo.inc"
40
41#define GET_SUBTARGETINFO_MC_DESC
42#include "MipsGenSubtargetInfo.inc"
43
44#define GET_REGINFO_MC_DESC
45#include "MipsGenRegisterInfo.inc"
46
47namespace {
48class MipsWinCOFFTargetStreamer : public MipsTargetStreamer {
49public:
50 MipsWinCOFFTargetStreamer(MCStreamer &S) : MipsTargetStreamer(S) {}
51};
52} // end namespace
53
54/// Select the Mips CPU for the given triple and cpu name.
56 if (CPU.empty() || CPU == "generic") {
57 if (TT.getSubArch() == llvm::Triple::MipsSubArch_r6) {
58 if (TT.isMIPS32())
59 CPU = "mips32r6";
60 else
61 CPU = "mips64r6";
62 } else {
63 if (TT.isMIPS32())
64 CPU = "mips32";
65 else
66 CPU = "mips64";
67 }
68 }
69 return CPU;
70}
71
73 MCInstrInfo *X = new MCInstrInfo();
74 InitMipsMCInstrInfo(X);
75 return X;
76}
77
80 InitMipsMCRegisterInfo(X, Mips::RA);
81 return X;
82}
83
85 StringRef CPU, StringRef FS) {
86 CPU = MIPS_MC::selectMipsCPU(TT, CPU);
87 return createMipsMCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS);
88}
89
91 const Triple &TT,
92 const MCTargetOptions &Options) {
93 MCAsmInfo *MAI;
94
95 if (TT.isOSWindows())
96 MAI = new MipsCOFFMCAsmInfo();
97 else
98 MAI = new MipsELFMCAsmInfo(TT, Options);
99
100 unsigned SP = MRI.getDwarfRegNum(Mips::SP, true);
102 MAI->addInitialFrameState(Inst);
103
104 return MAI;
105}
106
108 unsigned SyntaxVariant,
109 const MCAsmInfo &MAI,
110 const MCInstrInfo &MII,
111 const MCRegisterInfo &MRI) {
112 return new MipsInstPrinter(MAI, MII, MRI);
113}
114
116 std::unique_ptr<MCAsmBackend> &&MAB,
117 std::unique_ptr<MCObjectWriter> &&OW,
118 std::unique_ptr<MCCodeEmitter> &&Emitter) {
119 MCStreamer *S;
120 if (!T.isOSNaCl())
121 S = createMipsELFStreamer(Context, std::move(MAB), std::move(OW),
122 std::move(Emitter));
123 else
124 S = createMipsNaClELFStreamer(Context, std::move(MAB), std::move(OW),
125 std::move(Emitter));
126 return S;
127}
128
131 MCInstPrinter *InstPrint) {
132 return new MipsTargetAsmStreamer(S, OS);
133}
134
136 return new MipsTargetStreamer(S);
137}
138
139static MCTargetStreamer *
142 return new MipsWinCOFFTargetStreamer(S);
143 return new MipsTargetELFStreamer(S, STI);
144}
145
146namespace {
147
148class MipsMCInstrAnalysis : public MCInstrAnalysis {
149public:
150 MipsMCInstrAnalysis(const MCInstrInfo *Info) : MCInstrAnalysis(Info) {}
151
152 bool evaluateBranch(const MCInst &Inst, uint64_t Addr, uint64_t Size,
153 uint64_t &Target) const override {
154 unsigned NumOps = Inst.getNumOperands();
155 if (NumOps == 0)
156 return false;
157 switch (Info->get(Inst.getOpcode()).operands()[NumOps - 1].OperandType) {
160 // j, jal, jalx, jals
161 // Absolute branch within the current 256 MB-aligned region
162 uint64_t Region = Addr & ~uint64_t(0xfffffff);
163 Target = Region + Inst.getOperand(NumOps - 1).getImm();
164 return true;
165 }
167 // b, beq ...
168 Target = Addr + Inst.getOperand(NumOps - 1).getImm();
169 return true;
170 default:
171 return false;
172 }
173 }
174};
175}
176
178 return new MipsMCInstrAnalysis(Info);
179}
180
184 // Register the MC asm info.
186
187 // Register the MC instruction info.
189
190 // Register the MC register info.
192
193 // Register the elf streamer.
195
196 // Register the asm target streamer.
198
201
203
204 // Register the MC subtarget info.
206
207 // Register the MC instruction analyzer.
209
210 // Register the MCInstPrinter.
212
215
216 // Register the asm backend.
218 }
219
220 // Register the MC Code Emitter
223
226}
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 LVOptions Options
Definition: LVOptions.cpp:25
static MCRegisterInfo * createMipsMCRegisterInfo(const Triple &TT)
static MCTargetStreamer * createMipsObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI)
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeMipsTargetMC()
static MCTargetStreamer * createMipsAsmTargetStreamer(MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrint)
static MCStreamer * createMCStreamer(const Triple &T, MCContext &Context, std::unique_ptr< MCAsmBackend > &&MAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&Emitter)
static MCSubtargetInfo * createMipsMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS)
static MCInstrInfo * createMipsMCInstrInfo()
static MCInstPrinter * createMipsMCInstPrinter(const Triple &T, unsigned SyntaxVariant, const MCAsmInfo &MAI, const MCInstrInfo &MII, const MCRegisterInfo &MRI)
static MCTargetStreamer * createMipsNullTargetStreamer(MCStreamer &S)
static MCAsmInfo * createMipsMCAsmInfo(const MCRegisterInfo &MRI, const Triple &TT, const MCTargetOptions &Options)
static MCInstrAnalysis * createMipsMCInstrAnalysis(const MCInstrInfo *Info)
raw_pwrite_stream & OS
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
void addInitialFrameState(const MCCFIInstruction &Inst)
Definition: MCAsmInfo.cpp:75
static MCCFIInstruction createDefCfaRegister(MCSymbol *L, unsigned Register, SMLoc Loc={})
.cfi_def_cfa_register modifies a rule for computing CFA.
Definition: MCDwarf.h:582
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 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.
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...
Streaming machine code generation interface.
Definition: MCStreamer.h:213
Generic base class for all target subtargets.
const Triple & getTargetTriple() const
Target specific streamer interface.
Definition: MCStreamer.h:94
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:147
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
bool isOSBinFormatCOFF() const
Tests whether the OS uses the COFF binary format.
Definition: Triple.h:735
@ MipsSubArch_r6
Definition: Triple.h:155
formatted_raw_ostream - A raw_ostream that wraps another one and keeps track of line and column posit...
@ OPERAND_IMMEDIATE
Definition: MCInstrDesc.h:60
@ OPERAND_UNKNOWN
Definition: MCInstrDesc.h:59
StringRef selectMipsCPU(const Triple &TT, StringRef CPU)
Select the Mips CPU for the given triple and cpu name.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
MCCodeEmitter * createMipsMCCodeEmitterEL(const MCInstrInfo &MCII, MCContext &Ctx)
MCCodeEmitter * createMipsMCCodeEmitterEB(const MCInstrInfo &MCII, MCContext &Ctx)
MCELFStreamer * createMipsELFStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > MAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > Emitter)
Target & getTheMips64Target()
MCStreamer * createMipsWinCOFFStreamer(MCContext &C, std::unique_ptr< MCAsmBackend > &&AB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE)
Construct an MIPS Windows COFF machine code streamer which will generate PE/COFF format object files.
Target & getTheMips64elTarget()
Target & getTheMipselTarget()
MCELFStreamer * createMipsNaClELFStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > TAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > Emitter)
Target & getTheMipsTarget()
MCAsmBackend * createMipsAsmBackend(const Target &T, const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options)
RegisterMCAsmInfoFn - 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 RegisterObjectTargetStreamer(Target &T, Target::ObjectTargetStreamerCtorTy Fn)
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 RegisterNullTargetStreamer(Target &T, Target::NullTargetStreamerCtorTy Fn)
static void RegisterMCInstPrinter(Target &T, Target::MCInstPrinterCtorTy Fn)
RegisterMCInstPrinter - Register a MCInstPrinter implementation for the given target.
static void RegisterCOFFStreamer(Target &T, Target::COFFStreamerCtorTy Fn)
static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn)
RegisterMCInstrInfo - Register a MCInstrInfo implementation for the given target.
static void RegisterAsmTargetStreamer(Target &T, Target::AsmTargetStreamerCtorTy Fn)