LLVM  15.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 "LoongArchInstPrinter.h"
16 #include "LoongArchMCAsmInfo.h"
18 #include "llvm/MC/MCAsmInfo.h"
19 #include "llvm/MC/MCDwarf.h"
21 #include "llvm/MC/MCInstrInfo.h"
22 #include "llvm/MC/MCRegisterInfo.h"
24 #include "llvm/MC/TargetRegistry.h"
25 #include "llvm/Support/Compiler.h"
26 
27 #define GET_INSTRINFO_MC_DESC
28 #include "LoongArchGenInstrInfo.inc"
29 
30 #define GET_REGINFO_MC_DESC
31 #include "LoongArchGenRegisterInfo.inc"
32 
33 #define GET_SUBTARGETINFO_MC_DESC
34 #include "LoongArchGenSubtargetInfo.inc"
35 
36 using namespace llvm;
37 
40  InitLoongArchMCRegisterInfo(X, LoongArch::R1);
41  return X;
42 }
43 
45  MCInstrInfo *X = new MCInstrInfo();
46  InitLoongArchMCInstrInfo(X);
47  return X;
48 }
49 
50 static MCSubtargetInfo *
52  if (CPU.empty())
53  CPU = TT.isArch64Bit() ? "la464" : "generic-la32";
54  return createLoongArchMCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS);
55 }
56 
58  const Triple &TT,
59  const MCTargetOptions &Options) {
60  MCAsmInfo *MAI = new LoongArchMCAsmInfo(TT);
61 
62  // Initial state of the frame pointer is sp(r3).
63  MCRegister SP = MRI.getDwarfRegNum(LoongArch::R3, true);
64  MCCFIInstruction Inst = MCCFIInstruction::cfiDefCfa(nullptr, SP, 0);
65  MAI->addInitialFrameState(Inst);
66 
67  return MAI;
68 }
69 
71  unsigned SyntaxVariant,
72  const MCAsmInfo &MAI,
73  const MCInstrInfo &MII,
74  const MCRegisterInfo &MRI) {
75  return new LoongArchInstPrinter(MAI, MII, MRI);
76 }
77 
78 namespace {
79 
80 class LoongArchMCInstrAnalysis : public MCInstrAnalysis {
81 public:
82  explicit LoongArchMCInstrAnalysis(const MCInstrInfo *Info)
83  : MCInstrAnalysis(Info) {}
84 
85  bool evaluateBranch(const MCInst &Inst, uint64_t Addr, uint64_t Size,
86  uint64_t &Target) const override {
87  unsigned NumOps = Inst.getNumOperands();
88  if (isBranch(Inst) || Inst.getOpcode() == LoongArch::BL) {
89  Target = Addr + Inst.getOperand(NumOps - 1).getImm();
90  return true;
91  }
92 
93  return false;
94  }
95 };
96 
97 } // end anonymous namespace
98 
100  return new LoongArchMCInstrAnalysis(Info);
101 }
102 
113  }
114 }
MCDwarf.h
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::getTheLoongArch32Target
Target & getTheLoongArch32Target()
Definition: LoongArchTargetInfo.cpp:13
T
llvm::Target
Target - Wrapper for Target specific information.
Definition: TargetRegistry.h:145
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:858
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
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:965
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:103
MCInstrInfo.h
llvm::MCOperand::getImm
int64_t getImm() const
Definition: MCInst.h:80
llvm::MCInstrAnalysis
Definition: MCInstrAnalysis.h:30
MCSubtargetInfo.h
Options
const char LLVMTargetMachineRef LLVMPassBuilderOptionsRef Options
Definition: PassBuilderBindings.cpp:48
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:61
llvm::MCCFIInstruction
Definition: MCDwarf.h:472
X
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
createLoongArchInstrAnalysis
static MCInstrAnalysis * createLoongArchInstrAnalysis(const MCInstrInfo *Info)
Definition: LoongArchMCTargetDesc.cpp:99
llvm::TargetRegistry::RegisterMCAsmBackend
static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn)
RegisterMCAsmBackend - Register a MCAsmBackend implementation for the given target.
Definition: TargetRegistry.h:912
llvm::StringRef::empty
constexpr LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:153
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:126
Addr
uint64_t Addr
Definition: ELFObjHandler.cpp:78
MCRegisterInfo.h
createLoongArchMCInstPrinter
static MCInstPrinter * createLoongArchMCInstPrinter(const Triple &T, unsigned SyntaxVariant, const MCAsmInfo &MAI, const MCInstrInfo &MII, const MCRegisterInfo &MRI)
Definition: LoongArchMCTargetDesc.cpp:70
LoongArchInstPrinter.h
llvm::X86AS::FS
@ FS
Definition: X86.h:192
llvm::TargetRegistry::RegisterMCAsmInfo
static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn)
RegisterMCAsmInfo - Register a MCAsmInfo implementation for the given target.
Definition: TargetRegistry.h:826
createLoongArchMCSubtargetInfo
static MCSubtargetInfo * createLoongArchMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS)
Definition: LoongArchMCTargetDesc.cpp:51
createLoongArchMCRegisterInfo
static MCRegisterInfo * createLoongArchMCRegisterInfo(const Triple &TT)
Definition: LoongArchMCTargetDesc.cpp:38
createLoongArchMCAsmInfo
static MCAsmInfo * createLoongArchMCAsmInfo(const MCRegisterInfo &MRI, const Triple &TT, const MCTargetOptions &Options)
Definition: LoongArchMCTargetDesc.cpp:57
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:526
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:885
llvm::MCTargetOptions
Definition: MCTargetOptions.h:42
MCInstrAnalysis.h
MCAsmInfo.h
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
Compiler.h
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::TargetRegistry::RegisterMCInstrInfo
static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn)
RegisterMCInstrInfo - Register a MCInstrInfo implementation for the given target.
Definition: TargetRegistry.h:852
llvm::TargetRegistry::RegisterMCCodeEmitter
static void RegisterMCCodeEmitter(Target &T, Target::MCCodeEmitterCtorTy Fn)
RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the given target.
Definition: TargetRegistry.h:978
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:872
LoongArchTargetInfo.h
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:122
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:44
llvm::getTheLoongArch64Target
Target & getTheLoongArch64Target()
Definition: LoongArchTargetInfo.cpp:18
llvm::MCRegister
Wrapper class representing physical registers. Should be passed by value.
Definition: MCRegister.h:24