return true;
}
+ /// Record that \p I is to be replaced with `unreachable` after information
+ /// was manifested.
+ void changeToUnreachableAfterManifest(Instruction *I) {
+ ToBeChangedToUnreachableInsts.insert(I);
+ }
+
/// Record that \p I is deleted after information was manifested. This also
/// triggers deletion of trivially dead istructions.
void deleteAfterManifest(Instruction &I) { ToBeDeletedInsts.insert(&I); }
/// then trivially dead instructions as well.
DenseMap<Use *, Value *> ToBeChangedUses;
+ /// Instructions we replace with `unreachable` insts after manifest is done.
+ SmallPtrSet<Instruction *, 8> ToBeChangedToUnreachableInsts;
+
/// Functions, blocks, and instructions we delete after manifest is done.
///
///{
if (!UBMemAccessInsts.size())
return ChangeStatus::UNCHANGED;
for (Instruction *I : UBMemAccessInsts)
- changeToUnreachable(I, /* UseLLVMTrap */ false);
+ A.changeToUnreachableAfterManifest(I);
return ChangeStatus::CHANGED;
}
BB = SplitPos->getParent();
SplitBlock(BB, SplitPos);
- changeToUnreachable(BB->getTerminator(), /* UseLLVMTrap */ false);
+ A.changeToUnreachableAfterManifest(BB->getTerminator());
HasChanged = ChangeStatus::CHANGED;
}
SmallVector<Instruction *, 32> DeadInsts;
SmallVector<Instruction *, 32> TerminatorsToFold;
- SmallVector<Instruction *, 32> UnreachablesToInsert;
for (auto &It : ToBeChangedUses) {
Use *U = It.first;
if (isa<Constant>(NewV) && isa<BranchInst>(U->getUser())) {
Instruction *UserI = cast<Instruction>(U->getUser());
if (isa<UndefValue>(NewV)) {
- UnreachablesToInsert.push_back(UserI);
+ ToBeChangedToUnreachableInsts.insert(UserI);
} else {
TerminatorsToFold.push_back(UserI);
}
}
}
- for (Instruction *I : UnreachablesToInsert)
+ for (Instruction *I : ToBeChangedToUnreachableInsts)
changeToUnreachable(I, /* UseLLVMTrap */ false);
for (Instruction *I : TerminatorsToFold)
ConstantFoldTerminator(I->getParent());