26#include "llvm/IR/IntrinsicsSPIRV.h"
30#define DEBUG_TYPE "spirv-postlegalizer"
59 return Opcode == SPIRV::GET_ID || Opcode == SPIRV::GET_ID64 ||
60 Opcode == SPIRV::GET_fID || Opcode == SPIRV::GET_fID64 ||
61 Opcode == SPIRV::GET_pID32 || Opcode == SPIRV::GET_pID64 ||
62 Opcode == SPIRV::GET_vID || Opcode == SPIRV::GET_vfID ||
63 Opcode == SPIRV::GET_vpID32 || Opcode == SPIRV::GET_vpID64;
68 case TargetOpcode::G_SMAX:
69 case TargetOpcode::G_UMAX:
70 case TargetOpcode::G_SMIN:
71 case TargetOpcode::G_UMIN:
72 case TargetOpcode::G_FMINNUM:
73 case TargetOpcode::G_FMINIMUM:
74 case TargetOpcode::G_FMAXNUM:
75 case TargetOpcode::G_FMAXIMUM:
88 const unsigned Opcode =
I.getOpcode();
89 if (Opcode == TargetOpcode::G_UNMERGE_VALUES) {
90 unsigned ArgI =
I.getNumOperands() - 1;
91 Register SrcReg =
I.getOperand(ArgI).isReg()
92 ?
I.getOperand(ArgI).getReg()
96 if (!DefType || DefType->
getOpcode() != SPIRV::OpTypeVector)
98 "cannot select G_UNMERGE_VALUES with a non-vector argument");
101 for (
unsigned i = 0; i <
I.getNumDefs(); ++i) {
102 Register ResVReg =
I.getOperand(i).getReg();
106 ResType = ScalarType;
107 MRI.setRegClass(ResVReg, &SPIRV::iIDRegClass);
114 I.getNumOperands() > 1 &&
I.getOperand(1).isReg()) {
118 Register ResVReg =
I.getOperand(0).getReg();
129 MRI.setRegClass(ResVReg, &SPIRV::iIDRegClass);
143 MRI.setRegClass(ResVReg,
MRI.getType(ResVReg).isVector()
144 ? &SPIRV::iIDRegClass
145 : &SPIRV::ANYIDRegClass);
159 std::stack<MachineBasicBlock *> ToVisit;
162 ToVisit.push(&Start);
163 Seen.
insert(ToVisit.top());
164 while (ToVisit.size() != 0) {
189 std::unordered_map<MachineBasicBlock *, size_t> Order;
190 Order.reserve(MF.
size());
196 return Order[&
LHS] < Order[&
RHS];
206 GR->setCurrentFunc(MF);
218char SPIRVPostLegalizer::
ID = 0;
221 return new SPIRVPostLegalizer();
unsigned const MachineRegisterInfo * MRI
This file contains the simple types necessary to represent the attributes associated with functions a...
This file contains the declarations for the subclasses of Constant, which represent the different fla...
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file builds on the ADT/GraphTraits.h file to build a generic graph post order iterator.
void visit(MachineFunction &MF, MachineBasicBlock &Start, std::function< void(MachineBasicBlock *)> op)
bool isTypeFoldingSupported(unsigned Opcode)
static bool isMetaInstrGET(unsigned Opcode)
static bool mayBeInserted(unsigned Opcode)
static void processNewInstrs(MachineFunction &MF, SPIRVGlobalRegistry *GR, MachineIRBuilder MIB)
void sortBlocks(MachineFunction &MF)
FunctionPass class - This class is used to implement most global optimizations.
static constexpr LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
iterator_range< succ_iterator > successors()
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Helper class to build MachineInstr.
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const MachineOperand & getOperand(unsigned i) const
Register getReg() const
getReg - Returns the register number.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Wrapper class representing virtual and physical registers.
constexpr bool isValid() const
SPIRVType * getSPIRVTypeForVReg(Register VReg, const MachineFunction *MF=nullptr) const
void assignSPIRVTypeToVReg(SPIRVType *Type, Register VReg, MachineFunction &MF)
unsigned getScalarOrVectorBitWidth(const SPIRVType *Type) const
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool contains(ConstPtrType Ptr) const
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
The instances of the Type class are immutable: once they are created, they are never changed.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
This is an optimization pass for GlobalISel generic memory operations.
Register insertAssignInstr(Register Reg, Type *Ty, SPIRVType *SpirvTy, SPIRVGlobalRegistry *GR, MachineIRBuilder &MIB, MachineRegisterInfo &MRI)
Helper external function for inserting ASSIGN_TYPE instuction between Reg and its definition,...
FunctionPass * createSPIRVPostLegalizerPass()
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
void initializeSPIRVPostLegalizerPass(PassRegistry &)
void processInstr(MachineInstr &MI, MachineIRBuilder &MIB, MachineRegisterInfo &MRI, SPIRVGlobalRegistry *GR)