LLVM  16.0.0git
LoongArchMCTargetDesc.cpp
Go to the documentation of this file.
1 //===-- LoongArchMCTargetDesc.cpp - LoongArch 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 LoongArch specific target descriptions.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "LoongArchMCTargetDesc.h"
14 #include "LoongArchBaseInfo.h"
15 #include "LoongArchELFStreamer.h"
16 #include "LoongArchInstPrinter.h"
17 #include "LoongArchMCAsmInfo.h"
19 #include "llvm/MC/MCAsmBackend.h"
20 #include "llvm/MC/MCAsmInfo.h"
21 #include "llvm/MC/MCCodeEmitter.h"
22 #include "llvm/MC/MCDwarf.h"
24 #include "llvm/MC/MCInstrInfo.h"
25 #include "llvm/MC/MCObjectWriter.h"
26 #include "llvm/MC/MCRegisterInfo.h"
28 #include "llvm/MC/TargetRegistry.h"
29 #include "llvm/Support/Compiler.h"
30 
31 #define GET_INSTRINFO_MC_DESC
32 #define ENABLE_INSTR_PREDICATE_VERIFIER
33 #include "LoongArchGenInstrInfo.inc"
34 
35 #define GET_REGINFO_MC_DESC
36 #include "LoongArchGenRegisterInfo.inc"
37 
38 #define GET_SUBTARGETINFO_MC_DESC
39 #include "LoongArchGenSubtargetInfo.inc"
40 
41 using namespace llvm;
42 
45  InitLoongArchMCRegisterInfo(X, LoongArch::R1);
46  return X;
47 }
48 
50  MCInstrInfo *X = new MCInstrInfo();
51  InitLoongArchMCInstrInfo(X);
52  return X;
53 }
54 
55 static MCSubtargetInfo *
57  if (CPU.empty() || CPU == "generic")
58  CPU = TT.isArch64Bit() ? "la464" : "generic-la32";
59  return createLoongArchMCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS);
60 }
61 
63  const Triple &TT,
64  const MCTargetOptions &Options) {
65  MCAsmInfo *MAI = new LoongArchMCAsmInfo(TT);
66 
67  // Initial state of the frame pointer is sp(r3).
68  MCRegister SP = MRI.getDwarfRegNum(LoongArch::R3, true);
69  MCCFIInstruction Inst = MCCFIInstruction::cfiDefCfa(nullptr, SP, 0);
70  MAI->addInitialFrameState(Inst);
71 
72  return MAI;
73 }
74 
76  unsigned SyntaxVariant,
77  const MCAsmInfo &MAI,
78  const MCInstrInfo &MII,
79  const MCRegisterInfo &MRI) {
80  return new LoongArchInstPrinter(MAI, MII, MRI);
81 }
82 
83 static MCTargetStreamer *
85  return STI.getTargetTriple().isOSBinFormatELF()
86  ? new LoongArchTargetELFStreamer(S, STI)
87  : nullptr;
88 }
89 
90 namespace {
91 
92 class LoongArchMCInstrAnalysis : public MCInstrAnalysis {
93 public:
94  explicit LoongArchMCInstrAnalysis(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  unsigned NumOps = Inst.getNumOperands();
100  if (isBranch(Inst) || Inst.getOpcode() == LoongArch::BL) {
101  Target = Addr + Inst.getOperand(NumOps - 1).getImm();
102  return true;
103  }
104 
105  return false;
106  }
107 };
108 
109 } // end namespace
110 
112  return new LoongArchMCInstrAnalysis(Info);
113 }
114 
115 namespace {
117  std::unique_ptr<MCAsmBackend> &&MAB,
118  std::unique_ptr<MCObjectWriter> &&MOW,
119  std::unique_ptr<MCCodeEmitter> &&MCE,
120  bool RelaxAll) {
122  std::move(MCE), RelaxAll);
123 }
124 } // end namespace
125 
139  }
140 }
MCDwarf.h
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::getTheLoongArch32Target
Target & getTheLoongArch32Target()
Definition: LoongArchTargetInfo.cpp:13
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:76
MCCodeEmitter.h
llvm::Target
Target - Wrapper for Target specific information.
Definition: TargetRegistry.h:149
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::TargetRegistry::RegisterMCInstrAnalysis
static void RegisterMCInstrAnalysis(Target &T, Target::MCInstrAnalysisCtorFnTy Fn)
RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for the given target.
Definition: TargetRegistry.h:881
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
llvm::X86AS::FS
@ FS
Definition: X86.h:200
T
#define T
Definition: Mips16ISelLowering.cpp:341
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:988
llvm::MCInst::getNumOperands
unsigned getNumOperands() const
Definition: MCInst.h:208
llvm::ARCISD::BL
@ BL
Definition: ARCISelLowering.h:34
LLVMInitializeLoongArchTargetMC
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeLoongArchTargetMC()
Definition: LoongArchMCTargetDesc.cpp:126
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
llvm::MCStreamer
Streaming machine code generation interface.
Definition: MCStreamer.h:212
llvm::Triple::isOSBinFormatELF
bool isOSBinFormatELF() const
Tests whether the OS uses the ELF binary format.
Definition: Triple.h:673
MCAsmBackend.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
createLoongArchObjectTargetStreamer
static MCTargetStreamer * createLoongArchObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI)
Definition: LoongArchMCTargetDesc.cpp:84
LoongArchELFStreamer.h
llvm::MCInstrAnalysis
Definition: MCInstrAnalysis.h:30
MCSubtargetInfo.h
Options
const char LLVMTargetMachineRef LLVMPassBuilderOptionsRef Options
Definition: PassBuilderBindings.cpp:48
llvm::MCTargetStreamer
Target specific streamer interface.
Definition: MCStreamer.h:93
Info
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
llvm::createLoongArchAsmBackend
MCAsmBackend * createLoongArchAsmBackend(const Target &T, const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options)
Definition: LoongArchAsmBackend.cpp:197
llvm::MCCFIInstruction
Definition: MCDwarf.h:478
X
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
createLoongArchInstrAnalysis
static MCInstrAnalysis * createLoongArchInstrAnalysis(const MCInstrInfo *Info)
Definition: LoongArchMCTargetDesc.cpp:111
llvm::StringRef::empty
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:134
llvm::TargetRegistry::RegisterMCAsmBackend
static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn)
RegisterMCAsmBackend - Register a MCAsmBackend implementation for the given target.
Definition: TargetRegistry.h:935
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::LoongArchMCAsmInfo
Definition: LoongArchMCAsmInfo.h:21
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
llvm::TargetRegistry::RegisterObjectTargetStreamer
static void RegisterObjectTargetStreamer(Target &T, Target::ObjectTargetStreamerCtorTy Fn)
Definition: TargetRegistry.h:1044
MCRegisterInfo.h
createLoongArchMCInstPrinter
static MCInstPrinter * createLoongArchMCInstPrinter(const Triple &T, unsigned SyntaxVariant, const MCAsmInfo &MAI, const MCInstrInfo &MII, const MCRegisterInfo &MRI)
Definition: LoongArchMCTargetDesc.cpp:75
LoongArchInstPrinter.h
llvm::TargetRegistry::RegisterMCAsmInfo
static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn)
RegisterMCAsmInfo - Register a MCAsmInfo implementation for the given target.
Definition: TargetRegistry.h:849
createLoongArchMCSubtargetInfo
static MCSubtargetInfo * createLoongArchMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS)
Definition: LoongArchMCTargetDesc.cpp:56
createLoongArchMCRegisterInfo
static MCRegisterInfo * createLoongArchMCRegisterInfo(const Triple &TT)
Definition: LoongArchMCTargetDesc.cpp:43
createLoongArchMCAsmInfo
static MCAsmInfo * createLoongArchMCAsmInfo(const MCRegisterInfo &MRI, const Triple &TT, const MCTargetOptions &Options)
Definition: LoongArchMCTargetDesc.cpp:62
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:532
llvm::MCAsmInfo::addInitialFrameState
void addInitialFrameState(const MCCFIInstruction &Inst)
Definition: MCAsmInfo.cpp:86
isBranch
static bool isBranch(unsigned Opcode)
Definition: R600InstrInfo.cpp:642
llvm::TargetRegistry::RegisterMCSubtargetInfo
static void RegisterMCSubtargetInfo(Target &T, Target::MCSubtargetInfoCtorFnTy Fn)
RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for the given target.
Definition: TargetRegistry.h:908
llvm::MCTargetOptions
Definition: MCTargetOptions.h:37
MCInstrAnalysis.h
MCAsmInfo.h
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
llvm::createLoongArchELFStreamer
MCELFStreamer * createLoongArchELFStreamer(MCContext &C, std::unique_ptr< MCAsmBackend > MAB, std::unique_ptr< MCObjectWriter > MOW, std::unique_ptr< MCCodeEmitter > MCE, bool RelaxAll)
Definition: LoongArchELFStreamer.cpp:80
Compiler.h
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
MRI
unsigned const MachineRegisterInfo * MRI
Definition: AArch64AdvSIMDScalarPass.cpp:105
llvm::LoongArchTargetELFStreamer
Definition: LoongArchELFStreamer.h:17
MCObjectWriter.h
llvm::TargetRegistry::RegisterMCInstrInfo
static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn)
RegisterMCInstrInfo - Register a MCInstrInfo implementation for the given target.
Definition: TargetRegistry.h:875
llvm::TargetRegistry::RegisterMCCodeEmitter
static void RegisterMCCodeEmitter(Target &T, Target::MCCodeEmitterCtorTy Fn)
RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the given target.
Definition: TargetRegistry.h:1001
llvm::MCInstrInfo
Interface to description of machine instruction set.
Definition: MCInstrInfo.h:26
llvm::TargetRegistry::RegisterMCRegInfo
static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn)
RegisterMCRegInfo - Register a MCRegisterInfo implementation for the given target.
Definition: TargetRegistry.h:895
LoongArchTargetInfo.h
llvm::TargetRegistry::RegisterELFStreamer
static void RegisterELFStreamer(Target &T, Target::ELFStreamerCtorTy Fn)
Definition: TargetRegistry.h:1013
LoongArchBaseInfo.h
LoongArchMCAsmInfo.h
llvm::MCInst::getOpcode
unsigned getOpcode() const
Definition: MCInst.h:198
llvm::LoongArchInstPrinter
Definition: LoongArchInstPrinter.h:21
llvm::createLoongArchMCCodeEmitter
MCCodeEmitter * createLoongArchMCCodeEmitter(const MCInstrInfo &MCII, MCContext &Ctx)
Definition: LoongArchMCCodeEmitter.cpp:294
LoongArchMCTargetDesc.h
llvm::MCInst::getOperand
const MCOperand & getOperand(unsigned i) const
Definition: MCInst.h:206
TargetRegistry.h
llvm::MCSubtargetInfo
Generic base class for all target subtargets.
Definition: MCSubtargetInfo.h:76
createLoongArchMCInstrInfo
static MCInstrInfo * createLoongArchMCInstrInfo()
Definition: LoongArchMCTargetDesc.cpp:49
llvm::getTheLoongArch64Target
Target & getTheLoongArch64Target()
Definition: LoongArchTargetInfo.cpp:18
llvm::MCRegister
Wrapper class representing physical registers. Should be passed by value.
Definition: MCRegister.h:24