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 //===----------------------------------------------------------------------===//
10 // This file contains code to lower AMDGPU MachineInstrs to their corresponding
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/Constants.h"
22 #include "llvm/MC/MCInst.h"
23 #include "llvm/MC/MCStreamer.h"
24 #include "llvm/Support/ErrorHandling.h"
28 AMDGPUMCInstLower::AMDGPUMCInstLower() { }
30 void AMDGPUMCInstLower::lower(const MachineInstr
*MI
, MCInst
&OutMI
) const {
31 OutMI
.setOpcode(MI
->getOpcode());
33 for (unsigned i
= 0, e
= MI
->getNumExplicitOperands(); i
!= e
; ++i
) {
34 const MachineOperand
&MO
= MI
->getOperand(i
);
37 switch (MO
.getType()) {
39 llvm_unreachable("unknown operand type");
40 case MachineOperand::MO_FPImmediate
: {
41 const APFloat
&FloatValue
= MO
.getFPImm()->getValueAPF();
42 assert(&FloatValue
.getSemantics() == &APFloat::IEEEsingle
&&
43 "Only floating point immediates are supported at the moment.");
44 MCOp
= MCOperand::CreateFPImm(FloatValue
.convertToFloat());
47 case MachineOperand::MO_Immediate
:
48 MCOp
= MCOperand::CreateImm(MO
.getImm());
50 case MachineOperand::MO_Register
:
51 MCOp
= MCOperand::CreateReg(MO
.getReg());
54 OutMI
.addOperand(MCOp
);
58 void AMDGPUAsmPrinter::EmitInstruction(const MachineInstr
*MI
) {
59 AMDGPUMCInstLower MCInstLowering
;
61 // Ignore placeholder instructions:
62 if (MI
->getOpcode() == AMDGPU::MASK_WRITE
) {
67 const MachineBasicBlock
*MBB
= MI
->getParent();
68 MachineBasicBlock::const_instr_iterator I
= MI
;
70 while (I
!= MBB
->end() && I
->isInsideBundle()) {
72 const MachineInstr
*BundledInst
= I
;
73 MCInstLowering
.lower(BundledInst
, MCBundleInst
);
74 OutStreamer
.EmitInstruction(MCBundleInst
);
79 MCInstLowering
.lower(MI
, TmpInst
);
80 OutStreamer
.EmitInstruction(TmpInst
);