LLVM  16.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"
24 #include "llvm/MC/MCRegisterInfo.h"
26 #include "llvm/MC/TargetRegistry.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 
38 using 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);
48  MAI->addInitialFrameState(Inst);
49  return MAI;
50 }
51 
53  MCInstrInfo *Info = new MCInstrInfo();
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 
80 static 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  bool RelaxAll) {
93  CSKYELFStreamer *S = new CSKYELFStreamer(Ctx, std::move(MAB), std::move(OW),
95 
96  if (RelaxAll)
97  S->getAssembler().setRelaxAll(true);
98  return S;
99 }
100 
103  MCInstPrinter *InstPrinter,
104  bool isVerboseAsm) {
105  return new CSKYTargetAsmStreamer(S, OS);
106 }
107 
109  return new CSKYTargetStreamer(S);
110 }
111 
112 namespace {
113 
114 class CSKYMCInstrAnalysis : public MCInstrAnalysis {
115 public:
116  explicit CSKYMCInstrAnalysis(const MCInstrInfo *Info)
117  : MCInstrAnalysis(Info) {}
118 
119  bool evaluateBranch(const MCInst &Inst, uint64_t Addr, uint64_t Size,
120  uint64_t &Target) const override {
121  if (isConditionalBranch(Inst) || isUnconditionalBranch(Inst)) {
122  int64_t Imm;
123  Imm = Inst.getOperand(Inst.getNumOperands() - 1).getImm();
124  Target = Addr + Imm;
125  return true;
126  }
127 
128  if (Inst.getOpcode() == CSKY::BSR32) {
129  Target = Addr + Inst.getOperand(0).getImm();
130  return true;
131  }
132 
133  switch (Inst.getOpcode()) {
134  default:
135  return false;
136  case CSKY::LRW16:
137  case CSKY::LRW32:
138  case CSKY::JSRI32:
139  case CSKY::JMPI32:
140  int64_t Imm = Inst.getOperand(Inst.getNumOperands() - 1).getImm();
141  Target = ((Addr + Imm) & 0xFFFFFFFC);
142  return true;
143  }
144 
145  return false;
146  }
147 };
148 
149 } // end anonymous namespace
150 
152  return new CSKYMCInstrAnalysis(Info);
153 }
154 
156  auto &CSKYTarget = getTheCSKYTarget();
170  // Register the null target streamer.
174 }
llvm::CSKYTargetELFStreamer
Definition: CSKYELFStreamer.h:19
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::CSKYMCAsmInfo
Definition: CSKYMCAsmInfo.h:21
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:76
llvm::Target
Target - Wrapper for Target specific information.
Definition: TargetRegistry.h:149
llvm::MCAsmInfo
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
llvm::X86Disassembler::Reg
Reg
All possible values of the reg field in the ModR/M byte.
Definition: X86DisassemblerDecoder.h:462
llvm::TargetRegistry::RegisterAsmTargetStreamer
static void RegisterAsmTargetStreamer(Target &T, Target::AsmTargetStreamerCtorTy Fn)
Definition: TargetRegistry.h:1038
llvm::TargetRegistry::RegisterMCInstrAnalysis
static void RegisterMCInstrAnalysis(Target &T, Target::MCInstrAnalysisCtorFnTy Fn)
RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for the given target.
Definition: TargetRegistry.h:881
llvm::createCSKYMCCodeEmitter
MCCodeEmitter * createCSKYMCCodeEmitter(const MCInstrInfo &MCII, MCContext &Ctx)
Definition: CSKYMCCodeEmitter.cpp:330
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
MCAssembler.h
createCSKYMCSubtargetInfo
static MCSubtargetInfo * createCSKYMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS)
Definition: CSKYMCTargetDesc.cpp:72
llvm::X86AS::FS
@ FS
Definition: X86.h:200
llvm::MCInst
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
llvm::TargetRegistry::RegisterMCInstPrinter
static void RegisterMCInstPrinter(Target &T, Target::MCInstPrinterCtorTy Fn)
RegisterMCInstPrinter - Register a MCInstPrinter implementation for the given target.
Definition: TargetRegistry.h:988
llvm::MCInst::getNumOperands
unsigned getNumOperands() const
Definition: MCInst.h:208
llvm::getTheCSKYTarget
Target & getTheCSKYTarget()
Definition: CSKYTargetInfo.cpp:13
llvm::MCStreamer
Streaming machine code generation interface.
Definition: MCStreamer.h:212
Emitter
dxil DXContainer Global Emitter
Definition: DXContainerGlobals.cpp:67
CSKYAsmBackend.h
llvm::MCSubtargetInfo::getTargetTriple
const Triple & getTargetTriple() const
Definition: MCSubtargetInfo.h:108
MCInstrInfo.h
llvm::MCOperand::getImm
int64_t getImm() const
Definition: MCInst.h:80
llvm::MCInstrAnalysis
Definition: MCInstrAnalysis.h:30
MCSubtargetInfo.h
llvm::createCSKYAsmBackend
MCAsmBackend * createCSKYAsmBackend(const Target &T, const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options)
Definition: CSKYAsmBackend.cpp:353
Options
const char LLVMTargetMachineRef LLVMPassBuilderOptionsRef Options
Definition: PassBuilderBindings.cpp:48
CSKYTargetStreamer.h
llvm::MCTargetStreamer
Target specific streamer interface.
Definition: MCStreamer.h:93
Info
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
CSKYMCCodeEmitter.h
createCSKYObjectTargetStreamer
static MCTargetStreamer * createCSKYObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI)
Definition: CSKYMCTargetDesc.cpp:81
llvm::CSKYTargetStreamer
Definition: CSKYTargetStreamer.h:45
llvm::MCCFIInstruction
Definition: MCDwarf.h:478
llvm::TargetRegistry::RegisterMCAsmBackend
static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn)
RegisterMCAsmBackend - Register a MCAsmBackend implementation for the given target.
Definition: TargetRegistry.h:935
uint64_t
llvm::MCInstPrinter
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
Definition: MCInstPrinter.h:43
LLVM_EXTERNAL_VISIBILITY
#define LLVM_EXTERNAL_VISIBILITY
Definition: Compiler.h:127
Addr
uint64_t Addr
Definition: ELFObjHandler.cpp:79
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::TargetRegistry::RegisterObjectTargetStreamer
static void RegisterObjectTargetStreamer(Target &T, Target::ObjectTargetStreamerCtorTy Fn)
Definition: TargetRegistry.h:1044
MCRegisterInfo.h
llvm::formatted_raw_ostream
formatted_raw_ostream - A raw_ostream that wraps another one and keeps track of line and column posit...
Definition: FormattedStream.h:30
llvm::CSKYTargetAsmStreamer
Definition: CSKYTargetStreamer.h:96
createCSKYMCAsmInfo
static MCAsmInfo * createCSKYMCAsmInfo(const MCRegisterInfo &MRI, const Triple &TT, const MCTargetOptions &Options)
Definition: CSKYMCTargetDesc.cpp:40
llvm::TargetRegistry::RegisterMCAsmInfo
static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn)
RegisterMCAsmInfo - Register a MCAsmInfo implementation for the given target.
Definition: TargetRegistry.h:849
CSKYMCTargetDesc.h
llvm::MCCFIInstruction::cfiDefCfa
static MCCFIInstruction cfiDefCfa(MCSymbol *L, unsigned Register, int Offset)
.cfi_def_cfa defines a rule for computing CFA as: take address from Register and add Offset to it.
Definition: MCDwarf.h:532
llvm::MCAsmInfo::addInitialFrameState
void addInitialFrameState(const MCCFIInstruction &Inst)
Definition: MCAsmInfo.cpp:86
llvm::TargetRegistry::RegisterMCSubtargetInfo
static void RegisterMCSubtargetInfo(Target &T, Target::MCSubtargetInfoCtorFnTy Fn)
RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for the given target.
Definition: TargetRegistry.h:908
llvm::MCTargetOptions
Definition: MCTargetOptions.h:37
createCSKYMCRegisterInfo
static MCRegisterInfo * createCSKYMCRegisterInfo(const Triple &TT)
Definition: CSKYMCTargetDesc.cpp:66
MCInstrAnalysis.h
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::MCRegisterInfo
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Definition: MCRegisterInfo.h:135
CSKYMCAsmInfo.h
CSKYInstPrinter.h
MRI
unsigned const MachineRegisterInfo * MRI
Definition: AArch64AdvSIMDScalarPass.cpp:105
isUnconditionalBranch
static bool isUnconditionalBranch(Instruction *Term)
Definition: ADCE.cpp:211
LLVMInitializeCSKYTargetMC
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeCSKYTargetMC()
Definition: CSKYMCTargetDesc.cpp:155
llvm::createELFStreamer
MCStreamer * createELFStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE, bool RelaxAll)
Definition: MCELFStreamer.cpp:887
llvm::TargetRegistry::RegisterMCInstrInfo
static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn)
RegisterMCInstrInfo - Register a MCInstrInfo implementation for the given target.
Definition: TargetRegistry.h:875
llvm::TargetRegistry::RegisterMCCodeEmitter
static void RegisterMCCodeEmitter(Target &T, Target::MCCodeEmitterCtorTy Fn)
RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the given target.
Definition: TargetRegistry.h:1001
llvm::MCInstrInfo
Interface to description of machine instruction set.
Definition: MCInstrInfo.h:26
llvm::CSKYInstPrinter
Definition: CSKYInstPrinter.h:21
llvm::TargetRegistry::RegisterMCRegInfo
static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn)
RegisterMCRegInfo - Register a MCRegisterInfo implementation for the given target.
Definition: TargetRegistry.h:895
createCSKYMCInstPrinter
static MCInstPrinter * createCSKYMCInstPrinter(const Triple &T, unsigned SyntaxVariant, const MCAsmInfo &MAI, const MCInstrInfo &MII, const MCRegisterInfo &MRI)
Definition: CSKYMCTargetDesc.cpp:58
llvm::TargetRegistry::RegisterELFStreamer
static void RegisterELFStreamer(Target &T, Target::ELFStreamerCtorTy Fn)
Definition: TargetRegistry.h:1013
llvm::MCInst::getOpcode
unsigned getOpcode() const
Definition: MCInst.h:198
createCSKYAsmTargetStreamer
static MCTargetStreamer * createCSKYAsmTargetStreamer(MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrinter, bool isVerboseAsm)
Definition: CSKYMCTargetDesc.cpp:101
createCSKYNullTargetStreamer
static MCTargetStreamer * createCSKYNullTargetStreamer(MCStreamer &S)
Definition: CSKYMCTargetDesc.cpp:108
llvm::TargetRegistry::RegisterNullTargetStreamer
static void RegisterNullTargetStreamer(Target &T, Target::NullTargetStreamerCtorTy Fn)
Definition: TargetRegistry.h:1033
llvm::RISCVMatInt::Imm
@ Imm
Definition: RISCVMatInt.h:23
createCSKYMCInstrInfo
static MCInstrInfo * createCSKYMCInstrInfo()
Definition: CSKYMCTargetDesc.cpp:52
llvm::CSKYELFStreamer
Definition: CSKYELFStreamer.h:101
llvm::MCInst::getOperand
const MCOperand & getOperand(unsigned i) const
Definition: MCInst.h:206
CSKYELFStreamer.h
createCSKYInstrAnalysis
static MCInstrAnalysis * createCSKYInstrAnalysis(const MCInstrInfo *Info)
Definition: CSKYMCTargetDesc.cpp:151
CSKYTargetInfo.h
TargetRegistry.h
llvm::MCSubtargetInfo
Generic base class for all target subtargets.
Definition: MCSubtargetInfo.h:76