LLVM  10.0.0svn
RISCVMCTargetDesc.cpp
Go to the documentation of this file.
1 //===-- RISCVMCTargetDesc.cpp - RISCV 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 RISCV-specific target descriptions.
10 ///
11 //===----------------------------------------------------------------------===//
12 
13 #include "RISCVMCTargetDesc.h"
14 #include "RISCVELFStreamer.h"
15 #include "RISCVInstPrinter.h"
16 #include "RISCVMCAsmInfo.h"
17 #include "RISCVTargetStreamer.h"
19 #include "llvm/ADT/STLExtras.h"
20 #include "llvm/CodeGen/Register.h"
21 #include "llvm/MC/MCAsmInfo.h"
22 #include "llvm/MC/MCInstrInfo.h"
23 #include "llvm/MC/MCRegisterInfo.h"
24 #include "llvm/MC/MCStreamer.h"
28 
29 #define GET_INSTRINFO_MC_DESC
30 #include "RISCVGenInstrInfo.inc"
31 
32 #define GET_REGINFO_MC_DESC
33 #include "RISCVGenRegisterInfo.inc"
34 
35 #define GET_SUBTARGETINFO_MC_DESC
36 #include "RISCVGenSubtargetInfo.inc"
37 
38 using namespace llvm;
39 
41  MCInstrInfo *X = new MCInstrInfo();
42  InitRISCVMCInstrInfo(X);
43  return X;
44 }
45 
48  InitRISCVMCRegisterInfo(X, RISCV::X1);
49  return X;
50 }
51 
53  const Triple &TT) {
54  MCAsmInfo *MAI = new RISCVMCAsmInfo(TT);
55 
56  Register SP = MRI.getDwarfRegNum(RISCV::X2, true);
57  MCCFIInstruction Inst = MCCFIInstruction::createDefCfa(nullptr, SP, 0);
58  MAI->addInitialFrameState(Inst);
59 
60  return MAI;
61 }
62 
64  StringRef CPU, StringRef FS) {
65  std::string CPUName = CPU;
66  if (CPUName.empty())
67  CPUName = TT.isArch64Bit() ? "generic-rv64" : "generic-rv32";
68  return createRISCVMCSubtargetInfoImpl(TT, CPUName, FS);
69 }
70 
72  unsigned SyntaxVariant,
73  const MCAsmInfo &MAI,
74  const MCInstrInfo &MII,
75  const MCRegisterInfo &MRI) {
76  return new RISCVInstPrinter(MAI, MII, MRI);
77 }
78 
79 static MCTargetStreamer *
81  const Triple &TT = STI.getTargetTriple();
82  if (TT.isOSBinFormatELF())
83  return new RISCVTargetELFStreamer(S, STI);
84  return nullptr;
85 }
86 
89  MCInstPrinter *InstPrint,
90  bool isVerboseAsm) {
91  return new RISCVTargetAsmStreamer(S, OS);
92 }
93 
94 extern "C" void LLVMInitializeRISCVTargetMC() {
105 
106  // Register the asm target streamer.
108  }
109 }
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
MCAsmBackend * createRISCVAsmBackend(const Target &T, const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options)
This class represents lattice values for constants.
Definition: AllocatorList.h:23
static MCSubtargetInfo * createRISCVMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS)
bool isOSBinFormatELF() const
Tests whether the OS uses the ELF binary format.
Definition: Triple.h:623
formatted_raw_ostream - A raw_ostream that wraps another one and keeps track of line and column posit...
Target specific streamer interface.
Definition: MCStreamer.h:84
static MCTargetStreamer * createRISCVAsmTargetStreamer(MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrint, bool isVerboseAsm)
static void RegisterMCInstPrinter(Target &T, Target::MCInstPrinterCtorTy Fn)
RegisterMCInstPrinter - Register a MCInstPrinter implementation for the given target.
static void RegisterAsmTargetStreamer(Target &T, Target::AsmTargetStreamerCtorTy Fn)
const Triple & getTargetTriple() const
Target & getTheRISCV32Target()
static MCTargetStreamer * createRISCVObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI)
MCCodeEmitter * createRISCVMCCodeEmitter(const MCInstrInfo &MCII, const MCRegisterInfo &MRI, MCContext &Ctx)
int getDwarfRegNum(MCRegister RegNum, bool isEH) const
Map a target register to an equivalent dwarf register number.
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn)
RegisterMCAsmBackend - Register a MCAsmBackend implementation for the given target.
Streaming machine code generation interface.
Definition: MCStreamer.h:189
unsigned const MachineRegisterInfo * MRI
static MCCFIInstruction createDefCfa(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:480
Target & getTheRISCV64Target()
Interface to description of machine instruction set.
Definition: MCInstrInfo.h:23
static MCAsmInfo * createRISCVMCAsmInfo(const MCRegisterInfo &MRI, const Triple &TT)
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 MCRegisterInfo * createRISCVMCRegisterInfo(const Triple &TT)
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:43
void addInitialFrameState(const MCCFIInstruction &Inst)
Definition: MCAsmInfo.cpp:73
static void RegisterMCCodeEmitter(Target &T, Target::MCCodeEmitterCtorTy Fn)
RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the given target.
static MCInstPrinter * createRISCVMCInstPrinter(const Triple &T, unsigned SyntaxVariant, const MCAsmInfo &MAI, const MCInstrInfo &MII, const MCRegisterInfo &MRI)
static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn)
RegisterMCRegInfo - Register a MCRegisterInfo implementation for the given target.
Target - Wrapper for Target specific information.
void LLVMInitializeRISCVTargetMC()
static MCInstrInfo * createRISCVMCInstrInfo()
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
Definition: MCInstPrinter.h:39
bool isArch64Bit() const
Test whether the architecture is 64-bit.
Definition: Triple.cpp:1292
static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn)
RegisterMCInstrInfo - Register a MCInstrInfo implementation for the given target. ...
Generic base class for all target subtargets.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
Wrapper class representing virtual and physical registers.
Definition: Register.h:19