LLVM  16.0.0git
LanaiMCTargetDesc.cpp
Go to the documentation of this file.
1 //===-- LanaiMCTargetDesc.cpp - Lanai 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 Lanai specific target descriptions.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "LanaiMCTargetDesc.h"
14 #include "LanaiInstPrinter.h"
15 #include "LanaiMCAsmInfo.h"
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/ADT/Triple.h"
19 #include "llvm/MC/MCInst.h"
21 #include "llvm/MC/MCInstrInfo.h"
22 #include "llvm/MC/MCRegisterInfo.h"
23 #include "llvm/MC/MCStreamer.h"
25 #include "llvm/MC/TargetRegistry.h"
27 #include <cstdint>
28 #include <string>
29 
30 #define GET_INSTRINFO_MC_DESC
31 #define ENABLE_INSTR_PREDICATE_VERIFIER
32 #include "LanaiGenInstrInfo.inc"
33 
34 #define GET_SUBTARGETINFO_MC_DESC
35 #include "LanaiGenSubtargetInfo.inc"
36 
37 #define GET_REGINFO_MC_DESC
38 #include "LanaiGenRegisterInfo.inc"
39 
40 using namespace llvm;
41 
43  MCInstrInfo *X = new MCInstrInfo();
44  InitLanaiMCInstrInfo(X);
45  return X;
46 }
47 
50  InitLanaiMCRegisterInfo(X, Lanai::RCA, 0, 0, Lanai::PC);
51  return X;
52 }
53 
54 static MCSubtargetInfo *
56  std::string CPUName = std::string(CPU);
57  if (CPUName.empty())
58  CPUName = "generic";
59 
60  return createLanaiMCSubtargetInfoImpl(TT, CPUName, /*TuneCPU*/ CPUName, FS);
61 }
62 
64  std::unique_ptr<MCAsmBackend> &&MAB,
65  std::unique_ptr<MCObjectWriter> &&OW,
66  std::unique_ptr<MCCodeEmitter> &&Emitter,
67  bool RelaxAll) {
68  if (!T.isOSBinFormatELF())
69  llvm_unreachable("OS not supported");
70 
71  return createELFStreamer(Context, std::move(MAB), std::move(OW),
72  std::move(Emitter), RelaxAll);
73 }
74 
76  unsigned SyntaxVariant,
77  const MCAsmInfo &MAI,
78  const MCInstrInfo &MII,
79  const MCRegisterInfo &MRI) {
80  if (SyntaxVariant == 0)
81  return new LanaiInstPrinter(MAI, MII, MRI);
82  return nullptr;
83 }
84 
86  MCContext &Ctx) {
87  return createMCRelocationInfo(TheTriple, Ctx);
88 }
89 
90 namespace {
91 
92 class LanaiMCInstrAnalysis : public MCInstrAnalysis {
93 public:
94  explicit LanaiMCInstrAnalysis(const MCInstrInfo *Info)
95  : MCInstrAnalysis(Info) {}
96 
97  bool evaluateBranch(const MCInst &Inst, uint64_t Addr, uint64_t Size,
98  uint64_t &Target) const override {
99  if (Inst.getNumOperands() == 0)
100  return false;
101  if (!isConditionalBranch(Inst) && !isUnconditionalBranch(Inst) &&
102  !isCall(Inst))
103  return false;
104 
105  if (Info->get(Inst.getOpcode()).OpInfo[0].OperandType ==
107  int64_t Imm = Inst.getOperand(0).getImm();
108  Target = Addr + Size + Imm;
109  return true;
110  } else {
111  int64_t Imm = Inst.getOperand(0).getImm();
112 
113  // Skip case where immediate is 0 as that occurs in file that isn't linked
114  // and the branch target inferred would be wrong.
115  if (Imm == 0)
116  return false;
117 
118  Target = Imm;
119  return true;
120  }
121  }
122 };
123 
124 } // end anonymous namespace
125 
127  return new LanaiMCInstrAnalysis(Info);
128 }
129 
131  // Register the MC asm info.
133 
134  // Register the MC instruction info.
137 
138  // Register the MC register info.
141 
142  // Register the MC subtarget info.
145 
146  // Register the MC code emitter
149 
150  // Register the ASM Backend
153 
154  // Register the MCInstPrinter.
157 
158  // Register the ELF streamer.
160 
161  // Register the MC relocation info.
164 
165  // Register the MC instruction analyzer.
168 }
llvm::Check::Size
@ Size
Definition: FileCheck.h:77
LanaiMCAsmInfo.h
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
T
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:76
StringRef.h
llvm::Target
Target - Wrapper for Target specific information.
Definition: TargetRegistry.h:150
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::createLanaiMCCodeEmitter
MCCodeEmitter * createLanaiMCCodeEmitter(const MCInstrInfo &MCII, MCContext &Ctx)
Definition: LanaiMCCodeEmitter.cpp:306
llvm::MCRelocationInfo
Create MCExprs from relocations found in an object file.
Definition: MCRelocationInfo.h:24
ErrorHandling.h
llvm::TargetRegistry::RegisterMCInstrAnalysis
static void RegisterMCInstrAnalysis(Target &T, Target::MCInstrAnalysisCtorFnTy Fn)
RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for the given target.
Definition: TargetRegistry.h:880
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
createMCStreamer
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)
Definition: LanaiMCTargetDesc.cpp:63
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:987
llvm::MCInst::getNumOperands
unsigned getNumOperands() const
Definition: MCInst.h:208
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
llvm::MCStreamer
Streaming machine code generation interface.
Definition: MCStreamer.h:212
Emitter
dxil DXContainer Global Emitter
Definition: DXContainerGlobals.cpp:67
llvm::getTheLanaiTarget
Target & getTheLanaiTarget()
Definition: LanaiTargetInfo.cpp:14
createLanaiMCInstPrinter
static MCInstPrinter * createLanaiMCInstPrinter(const Triple &, unsigned SyntaxVariant, const MCAsmInfo &MAI, const MCInstrInfo &MII, const MCRegisterInfo &MRI)
Definition: LanaiMCTargetDesc.cpp:75
MCInstrInfo.h
llvm::MCOperand::getImm
int64_t getImm() const
Definition: MCInst.h:80
MCInst.h
llvm::MCInstrAnalysis
Definition: MCInstrAnalysis.h:30
MCSubtargetInfo.h
llvm::X86AS::FS
@ FS
Definition: X86.h:200
llvm::LanaiInstPrinter
Definition: LanaiInstPrinter.h:21
Info
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
llvm::createLanaiAsmBackend
MCAsmBackend * createLanaiAsmBackend(const Target &T, const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options)
Definition: LanaiAsmBackend.cpp:161
llvm::MCOI::OPERAND_PCREL
@ OPERAND_PCREL
Definition: MCInstrDesc.h:62
LLVMInitializeLanaiTargetMC
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeLanaiTargetMC()
Definition: LanaiMCTargetDesc.cpp:130
X
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
llvm::TargetRegistry::RegisterMCAsmBackend
static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn)
RegisterMCAsmBackend - Register a MCAsmBackend implementation for the given target.
Definition: TargetRegistry.h:934
uint64_t
LanaiTargetInfo.h
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
createLanaiInstrAnalysis
static MCInstrAnalysis * createLanaiInstrAnalysis(const MCInstrInfo *Info)
Definition: LanaiMCTargetDesc.cpp:126
MCRegisterInfo.h
createLanaiElfRelocation
static MCRelocationInfo * createLanaiElfRelocation(const Triple &TheTriple, MCContext &Ctx)
Definition: LanaiMCTargetDesc.cpp:85
llvm::TargetRegistry::RegisterMCSubtargetInfo
static void RegisterMCSubtargetInfo(Target &T, Target::MCSubtargetInfoCtorFnTy Fn)
RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for the given target.
Definition: TargetRegistry.h:907
Triple.h
llvm::createMCRelocationInfo
MCRelocationInfo * createMCRelocationInfo(const Triple &TT, MCContext &Ctx)
Definition: MCRelocationInfo.cpp:27
MCInstrAnalysis.h
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
createLanaiMCRegisterInfo
static MCRegisterInfo * createLanaiMCRegisterInfo(const Triple &)
Definition: LanaiMCTargetDesc.cpp:48
llvm::RegisterMCAsmInfo
RegisterMCAsmInfo - Helper template for registering a target assembly info implementation.
Definition: TargetRegistry.h:1157
llvm::MCRegisterInfo
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Definition: MCRegisterInfo.h:135
MRI
unsigned const MachineRegisterInfo * MRI
Definition: AArch64AdvSIMDScalarPass.cpp:105
isUnconditionalBranch
static bool isUnconditionalBranch(Instruction *Term)
Definition: ADCE.cpp:211
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:890
llvm::TargetRegistry::RegisterMCInstrInfo
static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn)
RegisterMCInstrInfo - Register a MCInstrInfo implementation for the given target.
Definition: TargetRegistry.h:874
llvm::TargetRegistry::RegisterMCCodeEmitter
static void RegisterMCCodeEmitter(Target &T, Target::MCCodeEmitterCtorTy Fn)
RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the given target.
Definition: TargetRegistry.h:1000
llvm::MCInstrInfo
Interface to description of machine instruction set.
Definition: MCInstrInfo.h:26
LanaiMCTargetDesc.h
llvm::TargetRegistry::RegisterMCRegInfo
static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn)
RegisterMCRegInfo - Register a MCRegisterInfo implementation for the given target.
Definition: TargetRegistry.h:894
llvm::TargetRegistry::RegisterELFStreamer
static void RegisterELFStreamer(Target &T, Target::ELFStreamerCtorTy Fn)
Definition: TargetRegistry.h:1012
llvm::MCInst::getOpcode
unsigned getOpcode() const
Definition: MCInst.h:198
llvm::RISCVMatInt::Imm
@ Imm
Definition: RISCVMatInt.h:23
createLanaiMCSubtargetInfo
static MCSubtargetInfo * createLanaiMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS)
Definition: LanaiMCTargetDesc.cpp:55
createLanaiMCInstrInfo
static MCInstrInfo * createLanaiMCInstrInfo()
Definition: LanaiMCTargetDesc.cpp:42
MCStreamer.h
llvm::MCInst::getOperand
const MCOperand & getOperand(unsigned i) const
Definition: MCInst.h:206
LanaiInstPrinter.h
TargetRegistry.h
llvm::MCSubtargetInfo
Generic base class for all target subtargets.
Definition: MCSubtargetInfo.h:77
llvm::TargetRegistry::RegisterMCRelocationInfo
static void RegisterMCRelocationInfo(Target &T, Target::MCRelocationInfoCtorTy Fn)
RegisterMCRelocationInfo - Register an MCRelocationInfo implementation for the given target.
Definition: TargetRegistry.h:1057