LLVM  14.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"
16 #include "R600AsmPrinter.h"
17 #include "R600Subtarget.h"
19 #include "llvm/MC/MCContext.h"
20 #include "llvm/MC/MCExpr.h"
21 
23 public:
24  R600MCInstLower(MCContext &ctx, const R600Subtarget &ST,
25  const AsmPrinter &AP);
26 
27  /// Lower a MachineInstr to an MCInst
28  void lower(const MachineInstr *MI, MCInst &OutMI) const;
29 };
30 
32  const AsmPrinter &AP)
33  : AMDGPUMCInstLower(Ctx, ST, AP) {}
34 
35 void R600MCInstLower::lower(const MachineInstr *MI, MCInst &OutMI) const {
36  OutMI.setOpcode(MI->getOpcode());
37  for (const MachineOperand &MO : MI->explicit_operands()) {
38  MCOperand MCOp;
39  lowerOperand(MO, MCOp);
40  OutMI.addOperand(MCOp);
41  }
42 }
43 
44 void R600AsmPrinter::emitInstruction(const MachineInstr *MI) {
45  const R600Subtarget &STI = MF->getSubtarget<R600Subtarget>();
46  R600MCInstLower MCInstLowering(OutContext, STI, *this);
47 
48  StringRef Err;
49  if (!STI.getInstrInfo()->verifyInstruction(*MI, Err)) {
50  LLVMContext &C = MI->getParent()->getParent()->getFunction().getContext();
51  C.emitError("Illegal instruction detected: " + Err);
52  MI->print(errs());
53  }
54 
55  if (MI->isBundle()) {
56  const MachineBasicBlock *MBB = MI->getParent();
57  MachineBasicBlock::const_instr_iterator I = ++MI->getIterator();
58  while (I != MBB->instr_end() && I->isInsideBundle()) {
59  emitInstruction(&*I);
60  ++I;
61  }
62  } else {
63  MCInst TmpInst;
64  MCInstLowering.lower(MI, TmpInst);
65  EmitToStreamer(*OutStreamer, TmpInst);
66  }
67 }
68 
70  if (const MCExpr *E = lowerAddrSpaceCast(TM, CV, OutContext))
71  return E;
72  return AsmPrinter::lowerConstant(CV);
73 }
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:105
llvm::AsmPrinter::lowerConstant
virtual const MCExpr * lowerConstant(const Constant *CV)
Lower the specified LLVM Constant to an MCExpr.
Definition: AsmPrinter.cpp:2487
AMDGPUMCInstLower::lowerOperand
bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp) const
Definition: AMDGPUMCInstLower.cpp:65
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:72
AMDGPUMCInstLower
Definition: AMDGPUMCInstLower.h:29
llvm::R600Subtarget::getInstrInfo
const R600InstrInfo * getInstrInfo() const override
Definition: R600Subtarget.h:56
R600MCInstLower::lower
void lower(const MachineInstr *MI, MCInst &OutMI) const
Lower a MachineInstr to an MCInst.
Definition: R600MCInstLower.cpp:35
llvm::errs
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Definition: raw_ostream.cpp:893
llvm::MCInst
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
llvm::AsmPrinter::EmitToStreamer
void EmitToStreamer(MCStreamer &S, const MCInst &Inst)
Definition: AsmPrinter.cpp:242
llvm::MCInst::setOpcode
void setOpcode(unsigned Op)
Definition: MCInst.h:197
R600AsmPrinter.h
llvm::R600AsmPrinter::lowerConstant
const MCExpr * lowerConstant(const Constant *CV) override
Lower the specified LLVM Constant to an MCExpr.
Definition: R600MCInstLower.cpp:69
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::AsmPrinter::OutStreamer
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:96
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
MCContext.h
llvm::MachineOperand
MachineOperand class - Representation of each machine instruction operand.
Definition: MachineOperand.h:49
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:95
llvm::MCInst::addOperand
void addOperand(const MCOperand Op)
Definition: MCInst.h:210
llvm::Pass::print
virtual void print(raw_ostream &OS, const Module *M) const
print - Print out the internal state of the pass.
Definition: Pass.cpp:125
llvm::R600AsmPrinter::emitInstruction
void emitInstruction(const MachineInstr *MI) override
Implemented in AMDGPUMCInstLower.cpp.
Definition: R600MCInstLower.cpp:44
llvm::MachineFunction::getSubtarget
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Definition: MachineFunction.h:634
llvm::R600Subtarget
Definition: R600Subtarget.h:35
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:64
R600MCInstLower
Definition: R600MCInstLower.cpp:22
llvm::ARM_MB::ST
@ ST
Definition: ARMBaseInfo.h:73
llvm::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::AsmPrinter::MF
MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:99
llvm::AsmPrinter::OutContext
MCContext & OutContext
This is the context for the output file that we are streaming.
Definition: AsmPrinter.h:91
AMDGPUMCInstLower.h
llvm::MachineBasicBlock::instr_end
instr_iterator instr_end()
Definition: MachineBasicBlock.h:254
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
MBB
MachineBasicBlock & MBB
Definition: AArch64SLSHardening.cpp:74
llvm::ilist_iterator
Iterator for intrusive lists based on ilist_node.
Definition: ilist_iterator.h:57
R600MCInstLower::R600MCInstLower
R600MCInstLower(MCContext &ctx, const R600Subtarget &ST, const AsmPrinter &AP)
Definition: R600MCInstLower.cpp:31
R600Subtarget.h
llvm::AsmPrinter
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:81
llvm::AsmPrinter::TM
TargetMachine & TM
Target machine description.
Definition: AsmPrinter.h:84
MachineOperand.h
llvm::MCOperand
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:36
MCExpr.h
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35