23#define DEBUG_TYPE "spirv-postlegalizer"
48 case TargetOpcode::G_SMAX:
49 case TargetOpcode::G_UMAX:
50 case TargetOpcode::G_SMIN:
51 case TargetOpcode::G_UMIN:
52 case TargetOpcode::G_FMINNUM:
53 case TargetOpcode::G_FMINIMUM:
54 case TargetOpcode::G_FMAXNUM:
55 case TargetOpcode::G_FMAXIMUM:
68 const unsigned Opcode =
I.getOpcode();
69 if (Opcode == TargetOpcode::G_UNMERGE_VALUES) {
70 unsigned ArgI =
I.getNumOperands() - 1;
71 Register SrcReg =
I.getOperand(ArgI).isReg()
72 ?
I.getOperand(ArgI).getReg()
76 if (!DefType || DefType->
getOpcode() != SPIRV::OpTypeVector)
78 "cannot select G_UNMERGE_VALUES with a non-vector argument");
81 for (
unsigned i = 0; i <
I.getNumDefs(); ++i) {
82 Register ResVReg =
I.getOperand(i).getReg();
91 I.getNumOperands() > 1 &&
I.getOperand(1).isReg()) {
95 Register ResVReg =
I.getOperand(0).getReg();
99 bool IsKnownReg =
MRI.getRegClassOrNull(ResVReg);
101 IsKnownReg ? ResVReg :
I.getOperand(1).getReg());
111 if (IsKnownReg &&
MRI.hasOneUse(ResVReg)) {
113 if (
UseMI.getOpcode() == SPIRV::ASSIGN_TYPE)
127 std::stack<MachineBasicBlock *> ToVisit;
130 ToVisit.push(&Start);
131 Seen.
insert(ToVisit.top());
132 while (ToVisit.size() != 0) {
157 GR->setCurrentFunc(MF);
168char SPIRVPostLegalizer::
ID = 0;
171 return new SPIRVPostLegalizer();
unsigned const MachineRegisterInfo * MRI
MachineInstrBuilder & UseMI
This file contains the simple types necessary to represent the attributes associated with functions a...
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
void visit(MachineFunction &MF, MachineBasicBlock &Start, std::function< void(MachineBasicBlock *)> op)
static bool mayBeInserted(unsigned Opcode)
static void processNewInstrs(MachineFunction &MF, SPIRVGlobalRegistry *GR, MachineIRBuilder MIB)
FunctionPass class - This class is used to implement most global optimizations.
iterator_range< succ_iterator > successors()
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,...
Wrapper class representing virtual and physical registers.
constexpr bool isValid() const
SPIRVType * getSPIRVTypeForVReg(Register VReg, const MachineFunction *MF=nullptr) 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.
void 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,...
bool isTypeFoldingSupported(unsigned Opcode)
void processInstr(MachineInstr &MI, MachineIRBuilder &MIB, MachineRegisterInfo &MRI, SPIRVGlobalRegistry *GR, SPIRVType *KnownResType)
FunctionPass * createSPIRVPostLegalizerPass()
void setRegClassType(Register Reg, SPIRVType *SpvType, SPIRVGlobalRegistry *GR, MachineRegisterInfo *MRI, const MachineFunction &MF, bool Force)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)