LLVM  15.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 #include "CSKYGenInstrInfo.inc"
30 
31 #define GET_REGINFO_MC_DESC
32 #include "CSKYGenRegisterInfo.inc"
33 
34 #define GET_SUBTARGETINFO_MC_DESC
35 #include "CSKYGenSubtargetInfo.inc"
36 
37 using namespace llvm;
38 
40  const Triple &TT,
41  const MCTargetOptions &Options) {
42  MCAsmInfo *MAI = new CSKYMCAsmInfo(TT);
43 
44  // Initial state of the frame pointer is SP.
45  unsigned Reg = MRI.getDwarfRegNum(CSKY::R14, true);
47  MAI->addInitialFrameState(Inst);
48  return MAI;
49 }
50 
52  MCInstrInfo *Info = new MCInstrInfo();
53  InitCSKYMCInstrInfo(Info);
54  return Info;
55 }
56 
58  unsigned SyntaxVariant,
59  const MCAsmInfo &MAI,
60  const MCInstrInfo &MII,
61  const MCRegisterInfo &MRI) {
62  return new CSKYInstPrinter(MAI, MII, MRI);
63 }
64 
67  InitCSKYMCRegisterInfo(Info, CSKY::R15);
68  return Info;
69 }
70 
72  StringRef CPU, StringRef FS) {
73  std::string CPUName = std::string(CPU);
74  if (CPUName.empty())
75  CPUName = "generic";
76  return createCSKYMCSubtargetInfoImpl(TT, CPUName, /*TuneCPU=*/CPUName, FS);
77 }
78 
79 static MCTargetStreamer *
81  const Triple &TT = STI.getTargetTriple();
82  if (TT.isOSBinFormatELF())
83  return new CSKYTargetELFStreamer(S, STI);
84  return nullptr;
85 }
86 
88  std::unique_ptr<MCAsmBackend> &&MAB,
89  std::unique_ptr<MCObjectWriter> &&OW,
90  std::unique_ptr<MCCodeEmitter> &&Emitter,
91  bool RelaxAll) {
92  CSKYELFStreamer *S = new CSKYELFStreamer(Ctx, std::move(MAB), std::move(OW),
93  std::move(Emitter));
94 
95  if (RelaxAll)
96  S->getAssembler().setRelaxAll(true);
97  return S;
98 }
99 
102  MCInstPrinter *InstPrinter,
103  bool isVerboseAsm) {
104  return new CSKYTargetAsmStreamer(S, OS);
105 }
106 
108  return new CSKYTargetStreamer(S);
109 }
110 
111 namespace {
112 
113 class CSKYMCInstrAnalysis : public MCInstrAnalysis {
114 public:
115  explicit CSKYMCInstrAnalysis(const MCInstrInfo *Info)
116  : MCInstrAnalysis(Info) {}
117 
118  bool evaluateBranch(const MCInst &Inst, uint64_t Addr, uint64_t Size,
119  uint64_t &Target) const override {
120  if (isConditionalBranch(Inst) || isUnconditionalBranch(Inst)) {
121  int64_t Imm;
122  Imm = Inst.getOperand(Inst.getNumOperands() - 1).getImm();
123  Target = Addr + Imm;
124  return true;
125  }
126 
127  if (Inst.getOpcode() == CSKY::BSR32) {
128  Target = Addr + Inst.getOperand(0).getImm();
129  return true;
130  }
131 
132  switch (Inst.getOpcode()) {
133  default:
134  return false;
135  case CSKY::LRW16:
136  case CSKY::LRW32:
137  case CSKY::JSRI32:
138  case CSKY::JMPI32:
139  int64_t Imm = Inst.getOperand(Inst.getNumOperands() - 1).getImm();
140  Target = ((Addr + Imm) & 0xFFFFFFFC);
141  return true;
142  }
143 
144  return false;
145  }
146 };
147 
148 } // end anonymous namespace
149 
151  return new CSKYMCInstrAnalysis(Info);
152 }
153 
155  auto &CSKYTarget = getTheCSKYTarget();
169  // Register the null target streamer.
173 }
llvm::CSKYTargetELFStreamer
Definition: CSKYELFStreamer.h:19
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::CSKYMCAsmInfo
Definition: CSKYMCAsmInfo.h:21
T
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:74
llvm::Target
Target - Wrapper for Target specific information.
Definition: TargetRegistry.h:140
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:993
llvm::TargetRegistry::RegisterMCInstrAnalysis
static void RegisterMCInstrAnalysis(Target &T, Target::MCInstrAnalysisCtorFnTy Fn)
RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for the given target.
Definition: TargetRegistry.h:840
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:71
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:947
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:201
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:80
llvm::CSKYTargetStreamer
Definition: CSKYTargetStreamer.h:45
llvm::MCCFIInstruction
Definition: MCDwarf.h:472
llvm::TargetRegistry::RegisterMCAsmBackend
static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn)
RegisterMCAsmBackend - Register a MCAsmBackend implementation for the given target.
Definition: TargetRegistry.h:894
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:126
Addr
uint64_t Addr
Definition: ELFObjHandler.cpp:78
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:999
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:39
llvm::TargetRegistry::RegisterMCAsmInfo
static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn)
RegisterMCAsmInfo - Register a MCAsmInfo implementation for the given target.
Definition: TargetRegistry.h:808
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:526
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:867
llvm::MCTargetOptions
Definition: MCTargetOptions.h:36
createCSKYMCRegisterInfo
static MCRegisterInfo * createCSKYMCRegisterInfo(const Triple &TT)
Definition: CSKYMCTargetDesc.cpp:65
MCInstrAnalysis.h
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
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:210
LLVMInitializeCSKYTargetMC
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeCSKYTargetMC()
Definition: CSKYMCTargetDesc.cpp:154
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:886
llvm::TargetRegistry::RegisterMCInstrInfo
static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn)
RegisterMCInstrInfo - Register a MCInstrInfo implementation for the given target.
Definition: TargetRegistry.h:834
llvm::TargetRegistry::RegisterMCCodeEmitter
static void RegisterMCCodeEmitter(Target &T, Target::MCCodeEmitterCtorTy Fn)
RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the given target.
Definition: TargetRegistry.h:960
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:854
createCSKYMCInstPrinter
static MCInstPrinter * createCSKYMCInstPrinter(const Triple &T, unsigned SyntaxVariant, const MCAsmInfo &MAI, const MCInstrInfo &MII, const MCRegisterInfo &MRI)
Definition: CSKYMCTargetDesc.cpp:57
llvm::TargetRegistry::RegisterELFStreamer
static void RegisterELFStreamer(Target &T, Target::ELFStreamerCtorTy Fn)
Definition: TargetRegistry.h:972
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:100
createCSKYNullTargetStreamer
static MCTargetStreamer * createCSKYNullTargetStreamer(MCStreamer &S)
Definition: CSKYMCTargetDesc.cpp:107
llvm::TargetRegistry::RegisterNullTargetStreamer
static void RegisterNullTargetStreamer(Target &T, Target::NullTargetStreamerCtorTy Fn)
Definition: TargetRegistry.h:988
createCSKYMCInstrInfo
static MCInstrInfo * createCSKYMCInstrInfo()
Definition: CSKYMCTargetDesc.cpp:51
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:150
CSKYTargetInfo.h
llvm::X86AS::FS
@ FS
Definition: X86.h:188
TargetRegistry.h
llvm::MCSubtargetInfo
Generic base class for all target subtargets.
Definition: MCSubtargetInfo.h:76