LLVM  9.0.0svn
MipsMCTargetDesc.cpp
Go to the documentation of this file.
1 //===-- MipsMCTargetDesc.cpp - Mips 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 Mips specific target descriptions.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "MipsMCTargetDesc.h"
14 #include "MipsAsmBackend.h"
15 #include "MipsELFStreamer.h"
16 #include "MipsInstPrinter.h"
17 #include "MipsMCAsmInfo.h"
18 #include "MipsMCNaCl.h"
19 #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") {
51  if (TT.isMIPS32())
52  CPU = "mips32r6";
53  else
54  CPU = "mips64r6";
55  } else {
56  if (TT.isMIPS32())
57  CPU = "mips32";
58  else
59  CPU = "mips64";
60  }
61  }
62  return CPU;
63 }
64 
66  MCInstrInfo *X = new MCInstrInfo();
67  InitMipsMCInstrInfo(X);
68  return X;
69 }
70 
73  InitMipsMCRegisterInfo(X, Mips::RA);
74  return X;
75 }
76 
78  StringRef CPU, StringRef FS) {
79  CPU = MIPS_MC::selectMipsCPU(TT, CPU);
80  return createMipsMCSubtargetInfoImpl(TT, CPU, FS);
81 }
82 
84  const Triple &TT) {
85  MCAsmInfo *MAI = new MipsMCAsmInfo(TT);
86 
87  unsigned SP = MRI.getDwarfRegNum(Mips::SP, true);
89  MAI->addInitialFrameState(Inst);
90 
91  return MAI;
92 }
93 
95  unsigned SyntaxVariant,
96  const MCAsmInfo &MAI,
97  const MCInstrInfo &MII,
98  const MCRegisterInfo &MRI) {
99  return new MipsInstPrinter(MAI, MII, MRI);
100 }
101 
103  std::unique_ptr<MCAsmBackend> &&MAB,
104  std::unique_ptr<MCObjectWriter> &&OW,
105  std::unique_ptr<MCCodeEmitter> &&Emitter,
106  bool RelaxAll) {
107  MCStreamer *S;
108  if (!T.isOSNaCl())
109  S = createMipsELFStreamer(Context, std::move(MAB), std::move(OW),
110  std::move(Emitter), RelaxAll);
111  else
112  S = createMipsNaClELFStreamer(Context, std::move(MAB), std::move(OW),
113  std::move(Emitter), RelaxAll);
114  return S;
115 }
116 
119  MCInstPrinter *InstPrint,
120  bool isVerboseAsm) {
121  return new MipsTargetAsmStreamer(S, OS);
122 }
123 
125  return new MipsTargetStreamer(S);
126 }
127 
128 static MCTargetStreamer *
130  return new MipsTargetELFStreamer(S, STI);
131 }
132 
133 namespace {
134 
135 class MipsMCInstrAnalysis : public MCInstrAnalysis {
136 public:
137  MipsMCInstrAnalysis(const MCInstrInfo *Info) : MCInstrAnalysis(Info) {}
138 
139  bool evaluateBranch(const MCInst &Inst, uint64_t Addr, uint64_t Size,
140  uint64_t &Target) const override {
141  unsigned NumOps = Inst.getNumOperands();
142  if (NumOps == 0)
143  return false;
144  switch (Info->get(Inst.getOpcode()).OpInfo[NumOps - 1].OperandType) {
147  // jal, bal ...
148  Target = Inst.getOperand(NumOps - 1).getImm();
149  return true;
150  case MCOI::OPERAND_PCREL:
151  // b, j, beq ...
152  Target = Addr + Inst.getOperand(NumOps - 1).getImm();
153  return true;
154  default:
155  return false;
156  }
157  }
158 };
159 }
160 
162  return new MipsMCInstrAnalysis(Info);
163 }
164 
165 extern "C" void LLVMInitializeMipsTargetMC() {
168  // Register the MC asm info.
170 
171  // Register the MC instruction info.
173 
174  // Register the MC register info.
176 
177  // Register the elf streamer.
179 
180  // Register the asm target streamer.
182 
185 
186  // Register the MC subtarget info.
188 
189  // Register the MC instruction analyzer.
191 
192  // Register the MCInstPrinter.
194 
197 
198  // Register the asm backend.
200  }
201 
202  // Register the MC Code Emitter
203  for (Target *T : {&getTheMipsTarget(), &getTheMips64Target()})
205 
208 }
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
This class represents lattice values for constants.
Definition: AllocatorList.h:23
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:581
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)
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:126
MCAsmBackend * createMipsAsmBackend(const Target &T, const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options)
Context object for machine code objects.
Definition: MCContext.h:64
SubArchType getSubArch() const
getSubArch - get the parsed subarchitecture type for this triple.
Definition: Triple.h:299
Target & getTheMips64Target()
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:158
Analysis containing CSE Info
Definition: CSEInfo.cpp:20
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:75
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:188
static MCInstrInfo * createMipsMCInstrInfo()
Target & getTheMips64elTarget()
unsigned const MachineRegisterInfo * MRI
static MCCFIInstruction createDefCfaRegister(MCSymbol *L, unsigned Register)
.cfi_def_cfa_register modifies a rule for computing CFA.
Definition: MCDwarf.h:487
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:23
StringRef selectMipsCPU(const Triple &TT, StringRef CPU)
Select the Mips CPU for the given triple and cpu name.
unsigned getNumOperands() const
Definition: MCInst.h:181
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:43
void addInitialFrameState(const MCCFIInstruction &Inst)
Definition: MCAsmInfo.cpp:73
const MCOperand & getOperand(unsigned i) const
Definition: MCInst.h:179
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:709
OperandType
Operands are tagged with one of the values of this enum.
Definition: MCInstrDesc.h:43
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
Definition: MCInstPrinter.h:39
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
Definition: MCInstrInfo.h:44
static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn)
RegisterMCInstrInfo - Register a MCInstrInfo implementation for the given target. ...
Generic base class for all target subtargets.
uint32_t Size
Definition: Profile.cpp:46
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)
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
unsigned getOpcode() const
Definition: MCInst.h:171