LLVM 22.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
23using namespace llvm;
24
25namespace {
26class R600MCInstLower : public AMDGPUMCInstLower {
27public:
28 R600MCInstLower(MCContext &ctx, const R600Subtarget &ST,
29 const AsmPrinter &AP);
30
31 /// Lower a MachineInstr to an MCInst
32 void lower(const MachineInstr *MI, MCInst &OutMI) const;
33};
34} // namespace
35
36R600MCInstLower::R600MCInstLower(MCContext &Ctx, const R600Subtarget &ST,
37 const AsmPrinter &AP)
38 : AMDGPUMCInstLower(Ctx, ST, AP) {}
39
40void R600MCInstLower::lower(const MachineInstr *MI, MCInst &OutMI) const {
41 OutMI.setOpcode(MI->getOpcode());
42 for (const MachineOperand &MO : MI->explicit_operands()) {
43 MCOperand MCOp;
44 lowerOperand(MO, MCOp);
45 OutMI.addOperand(MCOp);
46 }
47}
48
50 R600_MC::verifyInstructionPredicates(MI->getOpcode(),
51 getSubtargetInfo().getFeatureBits());
52
54 R600MCInstLower MCInstLowering(OutContext, STI, *this);
55
56 StringRef Err;
57 if (!STI.getInstrInfo()->verifyInstruction(*MI, Err)) {
58 LLVMContext &C = MI->getParent()->getParent()->getFunction().getContext();
59 C.emitError("Illegal instruction detected: " + Err);
60 MI->print(errs());
61 }
62
63 if (MI->isBundle()) {
64 const MachineBasicBlock *MBB = MI->getParent();
66 while (I != MBB->instr_end() && I->isInsideBundle()) {
68 ++I;
69 }
70 } else {
71 MCInst TmpInst;
72 MCInstLowering.lower(MI, TmpInst);
73 EmitToStreamer(*OutStreamer, TmpInst);
74 }
75}
76
78 const Constant *BaseCV,
80 if (const MCExpr *E = lowerAddrSpaceCast(TM, CV, OutContext))
81 return E;
82 return AsmPrinter::lowerConstant(CV, BaseCV, Offset);
83}
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:90
void EmitToStreamer(MCStreamer &S, const MCInst &Inst)
Definition: AsmPrinter.cpp:433
TargetMachine & TM
Target machine description.
Definition: AsmPrinter.h:93
MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:108
virtual const MCExpr * lowerConstant(const Constant *CV, const Constant *BaseCV=nullptr, uint64_t Offset=0)
Lower the specified LLVM Constant to an MCExpr.
MCContext & OutContext
This is the context for the output file that we are streaming.
Definition: AsmPrinter.h:100
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:105
const MCSubtargetInfo & getSubtargetInfo() const
Return information about subtarget.
Definition: AsmPrinter.cpp:428
This is an important base class in LLVM.
Definition: Constant.h:43
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
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:188
void addOperand(const MCOperand Op)
Definition: MCInst.h:215
void setOpcode(unsigned Op)
Definition: MCInst.h:201
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:40
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:72
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:140
const MCExpr * lowerConstant(const Constant *CV, const Constant *BaseCV, uint64_t Offset) override
Lower the specified LLVM Constant to an MCExpr.
void emitInstruction(const MachineInstr *MI) override
Implemented in AMDGPUMCInstLower.cpp.
const R600InstrInfo * getInstrInfo() const override
Definition: R600Subtarget.h:51
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:477
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.