LLVM 22.0.0git
SPIRVMCInstLower.cpp
Go to the documentation of this file.
1//=- SPIRVMCInstLower.cpp - Convert SPIR-V MachineInstr to MCInst -*- C++ -*-=//
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// This file contains code to lower SPIR-V MachineInstrs to their corresponding
10// MCInst records.
11//
12//===----------------------------------------------------------------------===//
13
14#include "SPIRVMCInstLower.h"
15#include "SPIRVModuleAnalysis.h"
16#include "SPIRVUtils.h"
18#include "llvm/IR/Constants.h"
19
20using namespace llvm;
21
23 SPIRV::ModuleAnalysisInfo *MAI) const {
24 OutMI.setOpcode(MI->getOpcode());
25 // Propagate previously set flags
26 if (MI->getAsmPrinterFlags() & SPIRV::ASM_PRINTER_WIDTH16)
28 const MachineFunction *MF = MI->getMF();
29 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
30 const MachineOperand &MO = MI->getOperand(i);
31 MCOperand MCOp;
32 switch (MO.getType()) {
33 default:
34 llvm_unreachable("unknown operand type");
37 if (!FuncReg.isValid()) {
38 std::string DiagMsg;
39 raw_string_ostream OS(DiagMsg);
40 MI->print(OS);
41 DiagMsg = "Unknown function in:" + DiagMsg;
42 report_fatal_error(DiagMsg.c_str());
43 }
44 MCOp = MCOperand::createReg(FuncReg);
45 break;
46 }
49 break;
51 MCRegister NewReg = MAI->getRegisterAlias(MF, MO.getReg());
52 MCOp = MCOperand::createReg(NewReg.isValid() ? NewReg
53 : MO.getReg().asMCReg());
54 break;
55 }
57 if (MI->getOpcode() == SPIRV::OpExtInst && i == 2) {
58 MCRegister Reg = MAI->getExtInstSetReg(MO.getImm());
59 MCOp = MCOperand::createReg(Reg);
60 } else {
61 MCOp = MCOperand::createImm(MO.getImm());
62 }
63 break;
67 break;
68 }
69
70 OutMI.addOperand(MCOp);
71 }
72}
This file contains the declarations for the subclasses of Constant, which represent the different fla...
IRTranslator LLVM IR MI
LLVM_ABI float convertToFloat() const
Converts this APFloat to host float value.
Definition APFloat.cpp:6143
const APFloat & getValueAPF() const
Definition Constants.h:320
Instances of this class represent a single low-level machine instruction.
Definition MCInst.h:188
void setFlags(unsigned F)
Definition MCInst.h:204
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
static MCOperand createReg(MCRegister Reg)
Definition MCInst.h:138
static MCOperand createImm(int64_t Val)
Definition MCInst.h:145
static MCOperand createDFPImm(uint64_t Val)
Definition MCInst.h:159
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:33
constexpr bool isValid() const
Definition MCRegister.h:76
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
const GlobalValue * getGlobal() const
int64_t getImm() const
MachineBasicBlock * getMBB() const
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
Register getReg() const
getReg - Returns the register number.
const ConstantFP * getFPImm() const
@ MO_Immediate
Immediate operand.
@ MO_GlobalAddress
Address of a global value.
@ MO_MachineBasicBlock
MachineBasicBlock reference.
@ MO_Register
Register operand.
@ MO_FPImmediate
Floating-point immediate operand.
MCRegister asMCReg() const
Utility to check-convert this value to a MCRegister.
Definition Register.h:102
void lower(const MachineInstr *MI, MCInst &OutMI, SPIRV::ModuleAnalysisInfo *MAI) const
A raw_ostream that writes to an std::string.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:649
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:167
MCRegister getExtInstSetReg(unsigned SetNum)
MCRegister getRegisterAlias(const MachineFunction *MF, Register Reg)
MCRegister getOrCreateMBBRegister(const MachineBasicBlock &MBB)
MCRegister getFuncReg(const Function *F)