@@ -120,11 +120,18 @@ static SPIRVType *deduceTypeFromOperandRange(MachineInstr *I,
120120 MachineIRBuilder &MIB,
121121 SPIRVGlobalRegistry *GR,
122122 unsigned StartOp, unsigned EndOp) {
123+ SPIRVType *ResType = nullptr ;
123124 for (unsigned i = StartOp; i < EndOp; ++i) {
124- if (SPIRVType *Type = deduceTypeFromSingleOperand (I, MIB, GR, i))
125+ if (SPIRVType *Type = deduceTypeFromSingleOperand (I, MIB, GR, i)) {
126+ #ifdef EXPENSIVE_CHECKS
127+ assert (!ResType || Type == ResType && " Conflicting type from operands." );
128+ ResType = Type;
129+ #else
125130 return Type;
131+ #endif
132+ }
126133 }
127- return nullptr ;
134+ return ResType ;
128135}
129136
130137static SPIRVType *deduceTypeForResultRegister (MachineInstr *Use,
@@ -281,28 +288,29 @@ static void registerSpirvTypeForNewInstructions(MachineFunction &MF,
281288 NextWorklist.push_back (I);
282289 }
283290 }
284- Worklist = NextWorklist;
291+ Worklist = std::move ( NextWorklist) ;
285292 LLVM_DEBUG (dbgs () << " Worklist size: " << Worklist.size () << " \n " );
286293 } while (Changed);
287294
288- if (!Worklist.empty ()) {
289- LLVM_DEBUG (dbgs () << " Remaining worklist:\n " ;
290- for (auto *I : Worklist) { I->dump (); });
291- for (auto *I : Worklist) {
292- MachineIRBuilder MIB (*I);
293- Register ResVReg = I->getOperand (0 ).getReg ();
294- const LLT &ResLLT = MRI.getType (ResVReg);
295- SPIRVType *ResType = nullptr ;
296- if (ResLLT.isVector ()) {
297- SPIRVType *CompType = GR->getOrCreateSPIRVIntegerType (
298- ResLLT.getElementType ().getSizeInBits (), MIB);
299- ResType = GR->getOrCreateSPIRVVectorType (
300- CompType, ResLLT.getNumElements (), MIB, false );
301- } else {
302- ResType = GR->getOrCreateSPIRVIntegerType (ResLLT.getSizeInBits (), MIB);
303- }
304- setRegClassType (ResVReg, ResType, GR, &MRI, MF, true );
295+ if (Worklist.empty ())
296+ return ;
297+
298+ for (auto *I : Worklist) {
299+ MachineIRBuilder MIB (*I);
300+ Register ResVReg = I->getOperand (0 ).getReg ();
301+ const LLT &ResLLT = MRI.getType (ResVReg);
302+ SPIRVType *ResType = nullptr ;
303+ if (ResLLT.isVector ()) {
304+ SPIRVType *CompType = GR->getOrCreateSPIRVIntegerType (
305+ ResLLT.getElementType ().getSizeInBits (), MIB);
306+ ResType = GR->getOrCreateSPIRVVectorType (
307+ CompType, ResLLT.getNumElements (), MIB, false );
308+ } else {
309+ ResType = GR->getOrCreateSPIRVIntegerType (ResLLT.getSizeInBits (), MIB);
305310 }
311+ LLVM_DEBUG (dbgs () << " Could not determine type for " << *I
312+ << " , defaulting to " << *ResType << " \n " );
313+ setRegClassType (ResVReg, ResType, GR, &MRI, MF, true );
306314 }
307315}
308316
0 commit comments