Skip to content

Commit 75de5bc

Browse files
committed
Changes from code review.
1 parent 4f7f51c commit 75de5bc

File tree

1 file changed

+12
-38
lines changed

1 file changed

+12
-38
lines changed

llvm/lib/Target/SPIRV/SPIRVPostLegalizer.cpp

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -207,17 +207,17 @@ static bool deduceAndAssignSpirvType(MachineInstr *I, MachineFunction &MF,
207207
ResType = deduceTypeFromUses(ResVReg, MF, GR, MIB);
208208
}
209209

210-
if (ResType) {
211-
LLVM_DEBUG(dbgs() << "Assigned type to " << *I << ": " << *ResType);
212-
GR->assignSPIRVTypeToVReg(ResType, ResVReg, MF);
210+
if (!ResType)
211+
return false;
213212

214-
if (!MRI.getRegClassOrNull(ResVReg)) {
215-
LLVM_DEBUG(dbgs() << "Updating the register class.\n");
216-
setRegClassType(ResVReg, ResType, GR, &MRI, *GR->CurMF, true);
217-
}
218-
return true;
213+
LLVM_DEBUG(dbgs() << "Assigned type to " << *I << ": " << *ResType);
214+
GR->assignSPIRVTypeToVReg(ResType, ResVReg, MF);
215+
216+
if (!MRI.getRegClassOrNull(ResVReg)) {
217+
LLVM_DEBUG(dbgs() << "Updating the register class.\n");
218+
setRegClassType(ResVReg, ResType, GR, &MRI, *GR->CurMF, true);
219219
}
220-
return false;
220+
return true;
221221
}
222222

223223
static bool requiresSpirvType(MachineInstr &I, SPIRVGlobalRegistry *GR,
@@ -268,8 +268,8 @@ static void registerSpirvTypeForNewInstructions(MachineFunction &MF,
268268
LLVM_DEBUG(dbgs() << "Initial worklist:\n";
269269
for (auto *I : Worklist) { I->dump(); });
270270

271-
bool Changed = true;
272-
while (Changed) {
271+
bool Changed;
272+
do {
273273
Changed = false;
274274
SmallVector<MachineInstr *, 8> NextWorklist;
275275

@@ -283,7 +283,7 @@ static void registerSpirvTypeForNewInstructions(MachineFunction &MF,
283283
}
284284
Worklist = NextWorklist;
285285
LLVM_DEBUG(dbgs() << "Worklist size: " << Worklist.size() << "\n");
286-
}
286+
} while (Changed);
287287

288288
if (!Worklist.empty()) {
289289
LLVM_DEBUG(dbgs() << "Remaining worklist:\n";
@@ -348,30 +348,6 @@ static void ensureAssignTypeForTypeFolding(MachineFunction &MF,
348348
}
349349
}
350350

351-
static void lowerExtractVectorElements(MachineFunction &MF) {
352-
SmallVector<MachineInstr *, 8> ExtractInstrs;
353-
for (MachineBasicBlock &MBB : MF) {
354-
for (MachineInstr &MI : MBB) {
355-
if (MI.getOpcode() == TargetOpcode::G_EXTRACT_VECTOR_ELT) {
356-
ExtractInstrs.push_back(&MI);
357-
}
358-
}
359-
}
360-
361-
for (MachineInstr *MI : ExtractInstrs) {
362-
MachineIRBuilder MIB(*MI);
363-
Register Dst = MI->getOperand(0).getReg();
364-
Register Vec = MI->getOperand(1).getReg();
365-
Register Idx = MI->getOperand(2).getReg();
366-
367-
auto Intr = MIB.buildIntrinsic(Intrinsic::spv_extractelt, Dst, true, false);
368-
Intr.addUse(Vec);
369-
Intr.addUse(Idx);
370-
371-
MI->eraseFromParent();
372-
}
373-
}
374-
375351
// Do a preorder traversal of the CFG starting from the BB |Start|.
376352
// point. Calls |op| on each basic block encountered during the traversal.
377353
void visit(MachineFunction &MF, MachineBasicBlock &Start,
@@ -409,8 +385,6 @@ bool SPIRVPostLegalizer::runOnMachineFunction(MachineFunction &MF) {
409385
GR->setCurrentFunc(MF);
410386
registerSpirvTypeForNewInstructions(MF, GR);
411387
ensureAssignTypeForTypeFolding(MF, GR);
412-
lowerExtractVectorElements(MF);
413-
414388
return true;
415389
}
416390

0 commit comments

Comments
 (0)