@@ -178,7 +178,6 @@ SPIRVType *SPIRVGlobalRegistry::getOpTypeVoid(MachineIRBuilder &MIRBuilder) {
178178
179179void SPIRVGlobalRegistry::invalidateMachineInstr (MachineInstr *MI) {
180180 // TODO:
181- // - take into account duplicate tracker case which is a known issue,
182181 // - review other data structure wrt. possible issues related to removal
183182 // of a machine instruction during instruction selection.
184183 const MachineFunction *MF = MI->getMF ();
@@ -187,6 +186,8 @@ void SPIRVGlobalRegistry::invalidateMachineInstr(MachineInstr *MI) {
187186 return ;
188187 if (It->second == MI)
189188 LastInsertedTypeMap.erase (MF);
189+ // remove from the duplicate tracker to avoid incorrect reuse
190+ erase (MI);
190191}
191192
192193SPIRVType *SPIRVGlobalRegistry::createOpType (
@@ -275,7 +276,7 @@ Register SPIRVGlobalRegistry::getOrCreateConstFP(APFloat Val, MachineInstr &I,
275276 .addDef (Res)
276277 .addUse (getSPIRVTypeID (SpvType));
277278 addNumImm (APInt (BitWidth,
278- CI ->getValueAPF ().bitcastToAPInt ().getZExtValue ()),
279+ CF ->getValueAPF ().bitcastToAPInt ().getZExtValue ()),
279280 MIB);
280281 }
281282 const auto &ST = CurMF->getSubtarget ();
@@ -284,7 +285,7 @@ Register SPIRVGlobalRegistry::getOrCreateConstFP(APFloat Val, MachineInstr &I,
284285 *ST.getRegBankInfo ());
285286 return MIB;
286287 });
287- add (CI , NewType);
288+ add (CF , NewType);
288289 return Res;
289290}
290291
@@ -367,18 +368,18 @@ Register SPIRVGlobalRegistry::buildConstantInt(uint64_t Val,
367368 *Subtarget.getRegBankInfo ());
368369 return MIB;
369370 });
370- add (ConstInt , NewType);
371+ add (CI , NewType);
371372 return Res;
372373}
373374
374375Register SPIRVGlobalRegistry::buildConstantFP (APFloat Val,
375376 MachineIRBuilder &MIRBuilder,
376377 SPIRVType *SpvType) {
377378 auto &MF = MIRBuilder.getMF ();
379+ LLVMContext &Ctx = MF.getFunction ().getContext ();
378380 if (!SpvType)
379- SpvType = getOrCreateSPIRVType (
380- Type::getFloatTy (MF.getFunction ().getContext ()), MIRBuilder,
381- SPIRV::AccessQualifier::ReadWrite, true );
381+ SpvType = getOrCreateSPIRVType (Type::getFloatTy (Ctx), MIRBuilder,
382+ SPIRV::AccessQualifier::ReadWrite, true );
382383 auto *const CF = ConstantFP::get (Ctx, Val);
383384 Register Res = find (CF, &MF);
384385 if (Res.isValid ())
@@ -1378,7 +1379,7 @@ SPIRVType *SPIRVGlobalRegistry::getOrCreateOpTypeCoopMatr(
13781379 .addUse (buildConstantInt (Columns, MIRBuilder, SpvTypeInt32, EmitIR))
13791380 .addUse (buildConstantInt (Use, MIRBuilder, SpvTypeInt32, EmitIR));
13801381 });
1381- add (Key , NewMI);
1382+ add (ExtensionType , NewMI);
13821383 return NewMI;
13831384}
13841385
@@ -1390,7 +1391,7 @@ SPIRVType *SPIRVGlobalRegistry::getOrCreateOpTypeByOpcode(
13901391 createOpType (MIRBuilder, [&](MachineIRBuilder &MIRBuilder) {
13911392 return MIRBuilder.buildInstr (Opcode).addDef (createTypeVReg (MIRBuilder));
13921393 });
1393- add (Key , NewMI);
1394+ add (Ty , NewMI);
13941395 return NewMI;
13951396}
13961397
@@ -1464,15 +1465,16 @@ SPIRVType *SPIRVGlobalRegistry::getOrCreateSPIRVType(unsigned BitWidth,
14641465 Type *Ty) {
14651466 if (const MachineInstr *MI = findMI (Ty, CurMF))
14661467 return MI;
1468+ MachineIRBuilder MIRBuilder (I);
14671469 const MachineInstr *NewMI =
14681470 createOpType (MIRBuilder, [&](MachineIRBuilder &MIRBuilder) {
14691471 return BuildMI (*I.getParent (), I, I.getDebugLoc (), TII.get (SPIRVOPcode))
14701472 .addDef (createTypeVReg (CurMF->getRegInfo ()))
14711473 .addImm (BitWidth)
14721474 .addImm (0 );
14731475 });
1474- add (LLVMTy , NewMI);
1475- return finishCreatingSPIRVType (LLVMTy, MIB );
1476+ add (Ty , NewMI);
1477+ return finishCreatingSPIRVType (Ty, NewMI );
14761478}
14771479
14781480SPIRVType *SPIRVGlobalRegistry::getOrCreateSPIRVIntegerType (
@@ -1520,6 +1522,7 @@ SPIRVGlobalRegistry::getOrCreateSPIRVBoolType(MachineInstr &I,
15201522 Type *Ty = IntegerType::get (CurMF->getFunction ().getContext (), 1 );
15211523 if (const MachineInstr *MI = findMI (Ty, CurMF))
15221524 return MI;
1525+ MachineIRBuilder MIRBuilder (I);
15231526 const MachineInstr *NewMI =
15241527 createOpType (MIRBuilder, [&](MachineIRBuilder &MIRBuilder) {
15251528 return BuildMI (*I.getParent (), I, I.getDebugLoc (),
@@ -1546,6 +1549,7 @@ SPIRVType *SPIRVGlobalRegistry::getOrCreateSPIRVVectorType(
15461549 const_cast <Type *>(getTypeForSPIRVType (BaseType)), NumElements);
15471550 if (const MachineInstr *MI = findMI (Ty, CurMF))
15481551 return MI;
1552+ MachineIRBuilder MIRBuilder (I);
15491553 const MachineInstr *NewMI =
15501554 createOpType (MIRBuilder, [&](MachineIRBuilder &MIRBuilder) {
15511555 return BuildMI (*I.getParent (), I, I.getDebugLoc (),
@@ -1567,6 +1571,7 @@ SPIRVType *SPIRVGlobalRegistry::getOrCreateSPIRVArrayType(
15671571 return MI;
15681572 SPIRVType *SpvTypeInt32 = getOrCreateSPIRVIntegerType (32 , I, TII);
15691573 Register Len = getOrCreateConstInt (NumElements, I, SpvTypeInt32, TII);
1574+ MachineIRBuilder MIRBuilder (I);
15701575 const MachineInstr *NewMI =
15711576 createOpType (MIRBuilder, [&](MachineIRBuilder &MIRBuilder) {
15721577 return BuildMI (*I.getParent (), I, I.getDebugLoc (),
@@ -1598,7 +1603,7 @@ SPIRVType *SPIRVGlobalRegistry::getOrCreateSPIRVPointerType(
15981603 .addUse (getSPIRVTypeID (BaseType));
15991604 });
16001605 add (PointerElementType, AddressSpace, NewMI);
1601- return finishCreatingSPIRVType (Ty, MIB );
1606+ return finishCreatingSPIRVType (Ty, NewMI );
16021607}
16031608
16041609SPIRVType *SPIRVGlobalRegistry::getOrCreateSPIRVPointerType (
@@ -1622,6 +1627,7 @@ Register SPIRVGlobalRegistry::getOrCreateUndef(MachineInstr &I,
16221627 CurMF->getRegInfo ().setRegClass (Res, &SPIRV::iIDRegClass);
16231628 assignSPIRVTypeToVReg (SpvType, Res, *CurMF);
16241629
1630+ MachineIRBuilder MIRBuilder (I);
16251631 const MachineInstr *NewMI =
16261632 createOpType (MIRBuilder, [&](MachineIRBuilder &MIRBuilder) {
16271633 auto MIB =
0 commit comments