LLVM 20.0.0git
CSKYMCTargetDesc.cpp
Go to the documentation of this file.
1//===-- CSKYMCTargetDesc.cpp - CSKY 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 CSKY specific target descriptions.
10///
11//===----------------------------------------------------------------------===//
12
13#include "CSKYMCTargetDesc.h"
14#include "CSKYAsmBackend.h"
15#include "CSKYELFStreamer.h"
16#include "CSKYInstPrinter.h"
17#include "CSKYMCAsmInfo.h"
18#include "CSKYMCCodeEmitter.h"
19#include "CSKYTargetStreamer.h"
21#include "llvm/MC/MCAssembler.h"
23#include "llvm/MC/MCInstrInfo.h"
27
28#define GET_INSTRINFO_MC_DESC
29#define ENABLE_INSTR_PREDICATE_VERIFIER
30#include "CSKYGenInstrInfo.inc"
31
32#define GET_REGINFO_MC_DESC
33#include "CSKYGenRegisterInfo.inc"
34
35#define GET_SUBTARGETINFO_MC_DESC
36#include "CSKYGenSubtargetInfo.inc"
37
38using namespace llvm;
39
41 const Triple &TT,
42 const MCTargetOptions &Options) {
43 MCAsmInfo *MAI = new CSKYMCAsmInfo(TT);
44
45 // Initial state of the frame pointer is SP.
46 unsigned Reg = MRI.getDwarfRegNum(CSKY::R14, true);
47 MCCFIInstruction Inst = MCCFIInstruction::cfiDefCfa(nullptr, Reg, 0);
48 MAI->addInitialFrameState(Inst);
49 return MAI;
50}
51
54 InitCSKYMCInstrInfo(Info);
55 return Info;
56}
57
59 unsigned SyntaxVariant,
60 const MCAsmInfo &MAI,
61 const MCInstrInfo &MII,
62 const MCRegisterInfo &MRI) {
63 return new CSKYInstPrinter(MAI, MII, MRI);
64}
65
68 InitCSKYMCRegisterInfo(Info, CSKY::R15);
69 return Info;
70}
71
73 StringRef CPU, StringRef FS) {
74 std::string CPUName = std::string(CPU);
75 if (CPUName.empty())
76 CPUName = "generic";
77 return createCSKYMCSubtargetInfoImpl(TT, CPUName, /*TuneCPU=*/CPUName, FS);
78}
79
80static MCTargetStreamer *
82 const Triple &TT = STI.getTargetTriple();
83 if (TT.isOSBinFormatELF())
84 return new CSKYTargetELFStreamer(S, STI);
85 return nullptr;
86}
87
89 std::unique_ptr<MCAsmBackend> &&MAB,
90 std::unique_ptr<MCObjectWriter> &&OW,
91 std::unique_ptr<MCCodeEmitter> &&Emitter) {
92 CSKYELFStreamer *S = new CSKYELFStreamer(Ctx, std::move(MAB), std::move(OW),
93 std::move(Emitter));
94
95 return S;
96}
97
98static MCTargetStreamer *
100 MCInstPrinter *InstPrinter) {
101 return new CSKYTargetAsmStreamer(S, OS);
102}
103
105 return new CSKYTargetStreamer(S);
106}
107
108namespace {
109
110class CSKYMCInstrAnalysis : public MCInstrAnalysis {
111public:
112 explicit CSKYMCInstrAnalysis(const MCInstrInfo *Info)
114
115 bool evaluateBranch(const MCInst &Inst, uint64_t Addr, uint64_t Size,
116 uint64_t &Target) const override {
117 if (isConditionalBranch(Inst) || isUnconditionalBranch(Inst)) {
118 int64_t Imm;
119 Imm = Inst.getOperand(Inst.getNumOperands() - 1).getImm();
120 Target = Addr + Imm;
121 return true;
122 }
123
124 if (Inst.getOpcode() == CSKY::BSR32) {
125 Target = Addr + Inst.getOperand(0).getImm();
126 return true;
127 }
128
129 switch (Inst.getOpcode()) {
130 default:
131 return false;
132 case CSKY::LRW16:
133 case CSKY::LRW32:
134 case CSKY::JSRI32:
135 case CSKY::JMPI32:
136 int64_t Imm = Inst.getOperand(Inst.getNumOperands() - 1).getImm();
137 Target = ((Addr + Imm) & 0xFFFFFFFC);
138 return true;
139 }
140
141 return false;
142 }
143};
144
145} // end anonymous namespace
146
148 return new CSKYMCInstrAnalysis(Info);
149}
150
152 auto &CSKYTarget = getTheCSKYTarget();
166 // Register the null target streamer.
170}
unsigned const MachineRegisterInfo * MRI
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
static MCSubtargetInfo * createCSKYMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS)
static MCInstrInfo * createCSKYMCInstrInfo()
static MCTargetStreamer * createCSKYObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI)
static MCInstrAnalysis * createCSKYInstrAnalysis(const MCInstrInfo *Info)
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeCSKYTargetMC()
static MCRegisterInfo * createCSKYMCRegisterInfo(const Triple &TT)
static MCStreamer * createELFStreamer(const Triple &T, MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&MAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&Emitter)
static MCTargetStreamer * createCSKYAsmTargetStreamer(MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrinter)
static MCAsmInfo * createCSKYMCAsmInfo(const MCRegisterInfo &MRI, const Triple &TT, const MCTargetOptions &Options)
static MCInstPrinter * createCSKYMCInstPrinter(const Triple &T, unsigned SyntaxVariant, const MCAsmInfo &MAI, const MCInstrInfo &MII, const MCRegisterInfo &MRI)
static MCTargetStreamer * createCSKYNullTargetStreamer(MCStreamer &S)
#define LLVM_EXTERNAL_VISIBILITY
Definition: Compiler.h:131
dxil DXContainer Global Emitter
uint64_t Addr
uint64_t Size
static LVOptions Options
Definition: LVOptions.cpp:25
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 cfiDefCfa(MCSymbol *L, unsigned Register, int64_t Offset, SMLoc Loc={})
.cfi_def_cfa defines a rule for computing CFA as: take address from Register and add Offset to it.
Definition: MCDwarf.h:558
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:45
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
unsigned getNumOperands() const
Definition: MCInst.h:208
unsigned getOpcode() const
Definition: MCInst.h:198
const MCOperand & getOperand(unsigned i) const
Definition: MCInst.h:206
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:80
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:50
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
formatted_raw_ostream - A raw_ostream that wraps another one and keeps track of line and column posit...
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
MCAsmBackend * createCSKYAsmBackend(const Target &T, const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options)
MCCodeEmitter * createCSKYMCCodeEmitter(const MCInstrInfo &MCII, MCContext &Ctx)
Target & getTheCSKYTarget()
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 RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn)
RegisterMCAsmInfo - Register a MCAsmInfo 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 RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn)
RegisterMCInstrInfo - Register a MCInstrInfo implementation for the given target.
static void RegisterAsmTargetStreamer(Target &T, Target::AsmTargetStreamerCtorTy Fn)