LLVM  7.0.0
MipsMCTargetDesc.cpp
Go to the documentation of this file.
1 //===-- MipsMCTargetDesc.cpp - Mips Target Descriptions -------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file provides Mips specific target descriptions.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "MipsMCTargetDesc.h"
16 #include "MipsAsmBackend.h"
17 #include "MipsELFStreamer.h"
18 #include "MipsMCAsmInfo.h"
19 #include "MipsMCNaCl.h"
20 #include "MipsTargetStreamer.h"
21 #include "llvm/ADT/Triple.h"
22 #include "llvm/MC/MCCodeEmitter.h"
23 #include "llvm/MC/MCELFStreamer.h"
25 #include "llvm/MC/MCInstrInfo.h"
26 #include "llvm/MC/MCObjectWriter.h"
27 #include "llvm/MC/MCRegisterInfo.h"
29 #include "llvm/MC/MCSymbol.h"
34 
35 using namespace llvm;
36 
37 #define GET_INSTRINFO_MC_DESC
38 #include "MipsGenInstrInfo.inc"
39 
40 #define GET_SUBTARGETINFO_MC_DESC
41 #include "MipsGenSubtargetInfo.inc"
42 
43 #define GET_REGINFO_MC_DESC
44 #include "MipsGenRegisterInfo.inc"
45 
46 /// Select the Mips CPU for the given triple and cpu name.
47 /// FIXME: Merge with the copy in MipsSubtarget.cpp
49  if (CPU.empty() || CPU == "generic") {
50  if (TT.isMIPS32())
51  CPU = "mips32";
52  else
53  CPU = "mips64";
54  }
55  return CPU;
56 }
57 
59  MCInstrInfo *X = new MCInstrInfo();
60  InitMipsMCInstrInfo(X);
61  return X;
62 }
63 
66  InitMipsMCRegisterInfo(X, Mips::RA);
67  return X;
68 }
69 
71  StringRef CPU, StringRef FS) {
72  CPU = MIPS_MC::selectMipsCPU(TT, CPU);
73  return createMipsMCSubtargetInfoImpl(TT, CPU, FS);
74 }
75 
77  const Triple &TT) {
78  MCAsmInfo *MAI = new MipsMCAsmInfo(TT);
79 
80  unsigned SP = MRI.getDwarfRegNum(Mips::SP, true);
81  MCCFIInstruction Inst = MCCFIInstruction::createDefCfa(nullptr, SP, 0);
82  MAI->addInitialFrameState(Inst);
83 
84  return MAI;
85 }
86 
88  unsigned SyntaxVariant,
89  const MCAsmInfo &MAI,
90  const MCInstrInfo &MII,
91  const MCRegisterInfo &MRI) {
92  return new MipsInstPrinter(MAI, MII, MRI);
93 }
94 
96  std::unique_ptr<MCAsmBackend> &&MAB,
97  std::unique_ptr<MCObjectWriter> &&OW,
98  std::unique_ptr<MCCodeEmitter> &&Emitter,
99  bool RelaxAll) {
100  MCStreamer *S;
101  if (!T.isOSNaCl())
102  S = createMipsELFStreamer(Context, std::move(MAB), std::move(OW),
103  std::move(Emitter), RelaxAll);
104  else
105  S = createMipsNaClELFStreamer(Context, std::move(MAB), std::move(OW),
106  std::move(Emitter), RelaxAll);
107  return S;
108 }
109 
112  MCInstPrinter *InstPrint,
113  bool isVerboseAsm) {
114  return new MipsTargetAsmStreamer(S, OS);
115 }
116 
118  return new MipsTargetStreamer(S);
119 }
120 
121 static MCTargetStreamer *
123  return new MipsTargetELFStreamer(S, STI);
124 }
125 
126 namespace {
127 
128 class MipsMCInstrAnalysis : public MCInstrAnalysis {
129 public:
130  MipsMCInstrAnalysis(const MCInstrInfo *Info) : MCInstrAnalysis(Info) {}
131 
132  bool evaluateBranch(const MCInst &Inst, uint64_t Addr, uint64_t Size,
133  uint64_t &Target) const override {
134  unsigned NumOps = Inst.getNumOperands();
135  if (NumOps == 0)
136  return false;
137  switch (Info->get(Inst.getOpcode()).OpInfo[NumOps - 1].OperandType) {
140  // jal, bal ...
141  Target = Inst.getOperand(NumOps - 1).getImm();
142  return true;
143  case MCOI::OPERAND_PCREL:
144  // b, j, beq ...
145  Target = Addr + Inst.getOperand(NumOps - 1).getImm();
146  return true;
147  default:
148  return false;
149  }
150  }
151 };
152 }
153 
155  return new MipsMCInstrAnalysis(Info);
156 }
157 
158 extern "C" void LLVMInitializeMipsTargetMC() {
161  // Register the MC asm info.
163 
164  // Register the MC instruction info.
166 
167  // Register the MC register info.
169 
170  // Register the elf streamer.
172 
173  // Register the asm target streamer.
175 
178 
179  // Register the MC subtarget info.
181 
182  // Register the MC instruction analyzer.
184 
185  // Register the MCInstPrinter.
187 
190 
191  // Register the asm backend.
193  }
194 
195  // Register the MC Code Emitter
196  for (Target *T : {&getTheMipsTarget(), &getTheMips64Target()})
198 
201 }
static MCInstPrinter * createMipsMCInstPrinter(const Triple &T, unsigned SyntaxVariant, const MCAsmInfo &MAI, const MCInstrInfo &MII, const MCRegisterInfo &MRI)
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
LLVMContext & Context
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
formatted_raw_ostream - A raw_ostream that wraps another one and keeps track of line and column posit...
static void RegisterMCInstrAnalysis(Target &T, Target::MCInstrAnalysisCtorFnTy Fn)
RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for the given target...
static MCTargetStreamer * createMipsNullTargetStreamer(MCStreamer &S)
Target specific streamer interface.
Definition: MCStreamer.h:83
bool isOSNaCl() const
Tests whether the OS is NaCl (Native Client)
Definition: Triple.h:567
Target & getTheMipselTarget()
static MCRegisterInfo * createMipsMCRegisterInfo(const Triple &TT)
static MCAsmInfo * createMipsMCAsmInfo(const MCRegisterInfo &MRI, const Triple &TT)
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)
SI optimize exec mask operations pre RA
static MCTargetStreamer * createMipsAsmTargetStreamer(MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrint, bool isVerboseAsm)
void LLVMInitializeMipsTargetMC()
static MCSubtargetInfo * createMipsMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS)
int getDwarfRegNum(unsigned RegNum, bool isEH) const
Map a target register to an equivalent dwarf register number.
MCELFStreamer * createMipsNaClELFStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > TAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > Emitter, bool RelaxAll)
MCAsmBackend * createMipsAsmBackend(const Target &T, const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options)
Context object for machine code objects.
Definition: MCContext.h:63
void addInitialFrameState(const MCCFIInstruction &Inst)
Definition: MCAsmInfo.h:601
Target & getTheMips64Target()
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:133
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:161
MCCodeEmitter * createMipsMCCodeEmitterEL(const MCInstrInfo &MCII, const MCRegisterInfo &MRI, MCContext &Ctx)
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
int64_t getImm() const
Definition: MCInst.h:76
static MCTargetStreamer * createMipsObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI)
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:183
static MCInstrInfo * createMipsMCInstrInfo()
Target & getTheMips64elTarget()
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:460
static MCStreamer * createMCStreamer(const Triple &T, MCContext &Context, std::unique_ptr< MCAsmBackend > &&MAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&Emitter, bool RelaxAll)
static MCInstrAnalysis * createMipsMCInstrAnalysis(const MCInstrInfo *Info)
Interface to description of machine instruction set.
Definition: MCInstrInfo.h:24
StringRef selectMipsCPU(const Triple &TT, StringRef CPU)
Select the Mips CPU for the given triple and cpu name.
unsigned getNumOperands() const
Definition: MCInst.h:184
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)
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
const MCOperand & getOperand(unsigned i) const
Definition: MCInst.h:182
static void RegisterMCCodeEmitter(Target &T, Target::MCCodeEmitterCtorTy Fn)
RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the given target.
static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn)
RegisterMCRegInfo - Register a MCRegisterInfo implementation for the given target.
Target - Wrapper for Target specific information.
MCCodeEmitter * createMipsMCCodeEmitterEB(const MCInstrInfo &MCII, const MCRegisterInfo &MRI, MCContext &Ctx)
Target & getTheMipsTarget()
bool isMIPS32() const
Tests whether the target is MIPS 32-bit (little and big endian).
Definition: Triple.h:664
OperandType
Operands are tagged with one of the values of this enum.
Definition: MCInstrDesc.h:44
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
Definition: MCInstPrinter.h:40
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
Definition: MCInstrInfo.h:45
static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn)
RegisterMCInstrInfo - Register a MCInstrInfo implementation for the given target. ...
Generic base class for all target subtargets.
MCELFStreamer * createMipsELFStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > MAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > Emitter, bool RelaxAll)
static void RegisterELFStreamer(Target &T, Target::ELFStreamerCtorTy Fn)
RegisterMCAsmInfoFn - Helper template for registering a target assembly info implementation.
static void RegisterNullTargetStreamer(Target &T, Target::NullTargetStreamerCtorTy Fn)
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
unsigned getOpcode() const
Definition: MCInst.h:174