LLVM  16.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 "SPIRV.h"
16 #include "SPIRVModuleAnalysis.h"
17 #include "SPIRVUtils.h"
19 #include "llvm/IR/Constants.h"
20 
21 using namespace llvm;
22 
24  SPIRV::ModuleAnalysisInfo *MAI) const {
25  OutMI.setOpcode(MI->getOpcode());
26  const MachineFunction *MF = MI->getMF();
27  for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
28  const MachineOperand &MO = MI->getOperand(i);
29  MCOperand MCOp;
30  switch (MO.getType()) {
31  default:
32  llvm_unreachable("unknown operand type");
34  Register FuncReg = MAI->getFuncReg(MO.getGlobal()->getGlobalIdentifier());
35  assert(FuncReg.isValid() && "Cannot find function Id");
36  MCOp = MCOperand::createReg(FuncReg);
37  break;
38  }
41  break;
43  Register NewReg = MAI->getRegisterAlias(MF, MO.getReg());
44  MCOp = MCOperand::createReg(NewReg.isValid() ? NewReg : MO.getReg());
45  break;
46  }
48  if (MI->getOpcode() == SPIRV::OpExtInst && i == 2) {
49  Register Reg = MAI->getExtInstSetReg(MO.getImm());
50  MCOp = MCOperand::createReg(Reg);
51  } else {
52  MCOp = MCOperand::createImm(MO.getImm());
53  }
54  break;
58  break;
59  }
60 
61  OutMI.addOperand(MCOp);
62  }
63 }
i
i
Definition: README.txt:29
llvm::APFloat::convertToFloat
float convertToFloat() const
Converts this APFloat to host float value.
Definition: APFloat.cpp:4915
llvm::GlobalValue::getGlobalIdentifier
static std::string getGlobalIdentifier(StringRef Name, GlobalValue::LinkageTypes Linkage, StringRef FileName)
Return the modified name for a global value suitable to be used as the key for a global lookup (e....
Definition: Globals.cpp:142
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:105
MachineInstr.h
llvm::MachineOperand::MO_Immediate
@ MO_Immediate
Immediate operand.
Definition: MachineOperand.h:52
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
SPIRVModuleAnalysis.h
llvm::MachineOperand::getGlobal
const GlobalValue * getGlobal() const
Definition: MachineOperand.h:572
llvm::MCOperand::createImm
static MCOperand createImm(int64_t Val)
Definition: MCInst.h:141
llvm::X86Disassembler::Reg
Reg
All possible values of the reg field in the ModR/M byte.
Definition: X86DisassemblerDecoder.h:462
llvm::ConstantFP::getValueAPF
const APFloat & getValueAPF() const
Definition: Constants.h:298
llvm::SPIRV::ModuleAnalysisInfo
Definition: SPIRVModuleAnalysis.h:123
llvm::MCInst
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
llvm::SPIRVMCInstLower::lower
void lower(const MachineInstr *MI, MCInst &OutMI, SPIRV::ModuleAnalysisInfo *MAI) const
Definition: SPIRVMCInstLower.cpp:23
llvm::MachineOperand::MO_Register
@ MO_Register
Register operand.
Definition: MachineOperand.h:51
llvm::MCInst::setOpcode
void setOpcode(unsigned Op)
Definition: MCInst.h:197
Constants.h
llvm::MachineOperand::MO_GlobalAddress
@ MO_GlobalAddress
Address of a global value.
Definition: MachineOperand.h:61
llvm::MachineOperand::getImm
int64_t getImm() const
Definition: MachineOperand.h:546
llvm::MachineOperand
MachineOperand class - Representation of each machine instruction operand.
Definition: MachineOperand.h:48
SPIRVUtils.h
llvm::MCInst::addOperand
void addOperand(const MCOperand Op)
Definition: MCInst.h:210
llvm::SPIRV::ModuleAnalysisInfo::getFuncReg
Register getFuncReg(std::string FuncName)
Definition: SPIRVModuleAnalysis.h:153
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:66
llvm::numbers::e
constexpr double e
Definition: MathExtras.h:53
llvm::MachineOperand::getType
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
Definition: MachineOperand.h:218
llvm::MachineOperand::getFPImm
const ConstantFP * getFPImm() const
Definition: MachineOperand.h:556
SPIRV.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::MachineOperand::MO_FPImmediate
@ MO_FPImmediate
Floating-point immediate operand.
Definition: MachineOperand.h:54
llvm::MachineOperand::getReg
Register getReg() const
getReg - Returns the register number.
Definition: MachineOperand.h:359
llvm::MachineFunction
Definition: MachineFunction.h:257
llvm::MachineOperand::getMBB
MachineBasicBlock * getMBB() const
Definition: MachineOperand.h:561
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
llvm::MCOperand::createReg
static MCOperand createReg(unsigned Reg)
Definition: MCInst.h:134
llvm::MachineOperand::MO_MachineBasicBlock
@ MO_MachineBasicBlock
MachineBasicBlock reference.
Definition: MachineOperand.h:55
llvm::SPIRV::ModuleAnalysisInfo::getRegisterAlias
Register getRegisterAlias(const MachineFunction *MF, Register Reg)
Definition: SPIRVModuleAnalysis.h:168
llvm::SPIRV::ModuleAnalysisInfo::getExtInstSetReg
Register getExtInstSetReg(unsigned SetNum)
Definition: SPIRVModuleAnalysis.h:158
llvm::MCOperand::createDFPImm
static MCOperand createDFPImm(uint64_t Val)
Definition: MCInst.h:155
llvm::Register
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
SPIRVMCInstLower.h
llvm::Register::isValid
bool isValid() const
Definition: Register.h:126
llvm::MCOperand
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:36
llvm::SPIRV::ModuleAnalysisInfo::getOrCreateMBBRegister
Register getOrCreateMBBRegister(const MachineBasicBlock &MBB)
Definition: SPIRVModuleAnalysis.h:184