LLVM 20.0.0git
R600MCInstLower.cpp
Go to the documentation of this file.
1//===- R600MCInstLower.cpp - Lower R600 MachineInstr to an MCInst ---------===//
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/// \file
10/// Code to lower R600 MachineInstrs to their corresponding MCInst.
11//
12//===----------------------------------------------------------------------===//
13//
14
15#include "AMDGPUMCInstLower.h"
17#include "R600AsmPrinter.h"
18#include "R600Subtarget.h"
20#include "llvm/MC/MCContext.h"
21#include "llvm/MC/MCExpr.h"
22
23namespace {
24class R600MCInstLower : public AMDGPUMCInstLower {
25public:
26 R600MCInstLower(MCContext &ctx, const R600Subtarget &ST,
27 const AsmPrinter &AP);
28
29 /// Lower a MachineInstr to an MCInst
30 void lower(const MachineInstr *MI, MCInst &OutMI) const;
31};
32} // namespace
33
34R600MCInstLower::R600MCInstLower(MCContext &Ctx, const R600Subtarget &ST,
35 const AsmPrinter &AP)
36 : AMDGPUMCInstLower(Ctx, ST, AP) {}
37
38void R600MCInstLower::lower(const MachineInstr *MI, MCInst &OutMI) const {
39 OutMI.setOpcode(MI->getOpcode());
40 for (const MachineOperand &MO : MI->explicit_operands()) {
41 MCOperand MCOp;
42 lowerOperand(MO, MCOp);
43 OutMI.addOperand(MCOp);
44 }
45}
46
48 R600_MC::verifyInstructionPredicates(MI->getOpcode(),
49 getSubtargetInfo().getFeatureBits());
50
52 R600MCInstLower MCInstLowering(OutContext, STI, *this);
53
54 StringRef Err;
55 if (!STI.getInstrInfo()->verifyInstruction(*MI, Err)) {
56 LLVMContext &C = MI->getParent()->getParent()->getFunction().getContext();
57 C.emitError("Illegal instruction detected: " + Err);
58 MI->print(errs());
59 }
60
61 if (MI->isBundle()) {
62 const MachineBasicBlock *MBB = MI->getParent();
64 while (I != MBB->instr_end() && I->isInsideBundle()) {
66 ++I;
67 }
68 } else {
69 MCInst TmpInst;
70 MCInstLowering.lower(MI, TmpInst);
71 EmitToStreamer(*OutStreamer, TmpInst);
72 }
73}
74
76 if (const MCExpr *E = lowerAddrSpaceCast(TM, CV, OutContext))
77 return E;
79}
Header of lower AMDGPU MachineInstrs to their corresponding MCInst.
MachineBasicBlock & MBB
IRTranslator LLVM IR MI
#define I(x, y, z)
Definition: MD5.cpp:58
R600 Assembly printer class.
Provides R600 specific target descriptions.
AMDGPU R600 specific subclass of TargetSubtarget.
static SDValue lowerAddrSpaceCast(SDValue Op, SelectionDAG &DAG)
void lower(const MachineInstr *MI, MCInst &OutMI) const
Lower a MachineInstr to an MCInst.
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:86
void EmitToStreamer(MCStreamer &S, const MCInst &Inst)
Definition: AsmPrinter.cpp:403
TargetMachine & TM
Target machine description.
Definition: AsmPrinter.h:89
MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:104
MCContext & OutContext
This is the context for the output file that we are streaming.
Definition: AsmPrinter.h:96
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:101
virtual const MCExpr * lowerConstant(const Constant *CV)
Lower the specified LLVM Constant to an MCExpr.
const MCSubtargetInfo & getSubtargetInfo() const
Return information about subtarget.
Definition: AsmPrinter.cpp:398
This is an important base class in LLVM.
Definition: Constant.h:42
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
Context object for machine code objects.
Definition: MCContext.h:83
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:34
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
void addOperand(const MCOperand Op)
Definition: MCInst.h:210
void setOpcode(unsigned Op)
Definition: MCInst.h:197
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:36
instr_iterator instr_end()
Instructions::const_iterator const_instr_iterator
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Representation of each machine instruction.
Definition: MachineInstr.h:69
MachineOperand class - Representation of each machine instruction operand.
virtual void print(raw_ostream &OS, const Module *M) const
print - Print out the internal state of the pass.
Definition: Pass.cpp:130
void emitInstruction(const MachineInstr *MI) override
Implemented in AMDGPUMCInstLower.cpp.
const MCExpr * lowerConstant(const Constant *CV) override
Lower the specified LLVM Constant to an MCExpr.
const R600InstrInfo * getInstrInfo() const override
Definition: R600Subtarget.h:50
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.