LLVM 19.0.0git
Go to the documentation of this file.
1//===- R600MCInstLower.cpp - Lower R600 MachineInstr to an MCInst ---------===//
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
9/// \file
10/// Code to lower R600 MachineInstrs to their corresponding MCInst.
15#include "AMDGPUMCInstLower.h"
17#include "R600AsmPrinter.h"
18#include "R600Subtarget.h"
20#include "llvm/MC/MCContext.h"
21#include "llvm/MC/MCExpr.h"
23namespace {
24class R600MCInstLower : public AMDGPUMCInstLower {
26 R600MCInstLower(MCContext &ctx, const R600Subtarget &ST,
27 const AsmPrinter &AP);
29 /// Lower a MachineInstr to an MCInst
30 void lower(const MachineInstr *MI, MCInst &OutMI) const;
32} // namespace
34R600MCInstLower::R600MCInstLower(MCContext &Ctx, const R600Subtarget &ST,
35 const AsmPrinter &AP)
36 : AMDGPUMCInstLower(Ctx, ST, AP) {}
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 }
48 R600_MC::verifyInstructionPredicates(MI->getOpcode(),
49 getSubtargetInfo().getFeatureBits());
52 R600MCInstLower MCInstLowering(OutContext, STI, *this);
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 }
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 }
76 if (const MCExpr *E = lowerAddrSpaceCast(TM, CV, OutContext))
77 return E;
MachineBasicBlock & MBB
Header of lower AMDGPU MachineInstrs to their corresponding MCInst.
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.
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:85
void EmitToStreamer(MCStreamer &S, const MCInst &Inst)
Definition: AsmPrinter.cpp:419
TargetMachine & TM
Target machine description.
Definition: AsmPrinter.h:88
MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:103
MCContext & OutContext
This is the context for the output file that we are streaming.
Definition: AsmPrinter.h:95
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:100
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:414
This is an important base class in LLVM.
Definition: Constant.h:41
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:82
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
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.