1 //===- AMDGPUMCInstLower.cpp - Lower AMDGPU MachineInstr to an MCInst -----===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// \brief Code to lower AMDGPU MachineInstrs to their corresponding MCInst.
13 //===----------------------------------------------------------------------===//
16 #include "AMDGPUMCInstLower.h"
17 #include "AMDGPUAsmPrinter.h"
18 #include "R600InstrInfo.h"
19 #include "llvm/CodeGen/MachineBasicBlock.h"
20 #include "llvm/CodeGen/MachineInstr.h"
21 #include "llvm/IR/Constants.h"
22 #include "llvm/MC/MCExpr.h"
23 #include "llvm/MC/MCInst.h"
24 #include "llvm/MC/MCStreamer.h"
25 #include "llvm/Support/ErrorHandling.h"
29 AMDGPUMCInstLower::AMDGPUMCInstLower(MCContext &ctx):
33 void AMDGPUMCInstLower::lower(const MachineInstr *MI, MCInst &OutMI) const {
34 OutMI.setOpcode(MI->getOpcode());
36 for (unsigned i = 0, e = MI->getNumExplicitOperands(); i != e; ++i) {
37 const MachineOperand &MO = MI->getOperand(i);
40 switch (MO.getType()) {
42 llvm_unreachable("unknown operand type");
43 case MachineOperand::MO_FPImmediate: {
44 const APFloat &FloatValue = MO.getFPImm()->getValueAPF();
45 assert(&FloatValue.getSemantics() == &APFloat::IEEEsingle &&
46 "Only floating point immediates are supported at the moment.");
47 MCOp = MCOperand::CreateFPImm(FloatValue.convertToFloat());
50 case MachineOperand::MO_Immediate:
51 MCOp = MCOperand::CreateImm(MO.getImm());
53 case MachineOperand::MO_Register:
54 MCOp = MCOperand::CreateReg(MO.getReg());
56 case MachineOperand::MO_MachineBasicBlock:
57 MCOp = MCOperand::CreateExpr(MCSymbolRefExpr::Create(
58 MO.getMBB()->getSymbol(), Ctx));
60 OutMI.addOperand(MCOp);
64 void AMDGPUAsmPrinter::EmitInstruction(const MachineInstr *MI) {
65 AMDGPUMCInstLower MCInstLowering(OutContext);
68 const MachineBasicBlock *MBB = MI->getParent();
69 MachineBasicBlock::const_instr_iterator I = MI;
71 while (I != MBB->end() && I->isInsideBundle()) {
73 const MachineInstr *BundledInst = I;
74 MCInstLowering.lower(BundledInst, MCBundleInst);
75 OutStreamer.EmitInstruction(MCBundleInst);
80 MCInstLowering.lower(MI, TmpInst);
81 OutStreamer.EmitInstruction(TmpInst);