Skip to content

Commit 12ec26d

Browse files
committed
Use vector + weakvh
1 parent b1557d6 commit 12ec26d

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "llvm/IR/IntrinsicsAMDGPU.h"
3030
#include "llvm/IR/PatternMatch.h"
3131
#include "llvm/InitializePasses.h"
32+
#include "llvm/IR/ValueHandle.h"
3233
#include "llvm/Pass.h"
3334
#include "llvm/Support/KnownBits.h"
3435
#include "llvm/Support/KnownFPClass.h"
@@ -107,7 +108,7 @@ class AMDGPUCodeGenPrepareImpl
107108
bool FlowChanged = false;
108109
mutable Function *SqrtF32 = nullptr;
109110
mutable Function *LdexpF32 = nullptr;
110-
mutable SetVector<Value *> DeadVals;
111+
mutable SmallVector<WeakVH> DeadVals;
111112

112113
DenseMap<const PHINode *, bool> BreakPhiNodesCache;
113114

@@ -285,15 +286,14 @@ bool AMDGPUCodeGenPrepareImpl::run() {
285286

286287
for (BasicBlock &BB : reverse(F)) {
287288
for (Instruction &I : make_early_inc_range(reverse(BB))) {
288-
if (!DeadVals.contains(&I))
289+
if (!isInstructionTriviallyDead(&I, TLI))
289290
MadeChange |= visit(I);
290291
}
291292
}
292293

293294
while (!DeadVals.empty()) {
294-
RecursivelyDeleteTriviallyDeadInstructions(
295-
DeadVals.pop_back_val(), TLI, /*MSSAU*/ nullptr,
296-
[&](Value *V) { DeadVals.remove(V); });
295+
if (auto *I = dyn_cast_or_null<Instruction>(DeadVals.pop_back_val()))
296+
RecursivelyDeleteTriviallyDeadInstructions(I, TLI);
297297
}
298298

299299
return MadeChange;
@@ -415,7 +415,7 @@ bool AMDGPUCodeGenPrepareImpl::replaceMulWithMul24(BinaryOperator &I) const {
415415
Value *NewVal = insertValues(Builder, Ty, ResultVals);
416416
NewVal->takeName(&I);
417417
I.replaceAllUsesWith(NewVal);
418-
DeadVals.insert(&I);
418+
DeadVals.push_back(&I);
419419

420420
return true;
421421
}
@@ -489,10 +489,10 @@ bool AMDGPUCodeGenPrepareImpl::foldBinOpIntoSelect(BinaryOperator &BO) const {
489489
FoldedT, FoldedF);
490490
NewSelect->takeName(&BO);
491491
BO.replaceAllUsesWith(NewSelect);
492-
DeadVals.insert(&BO);
492+
DeadVals.push_back(&BO);
493493
if (CastOp)
494-
DeadVals.insert(CastOp);
495-
DeadVals.insert(Sel);
494+
DeadVals.push_back(CastOp);
495+
DeadVals.push_back(Sel);
496496
return true;
497497
}
498498

@@ -888,7 +888,7 @@ bool AMDGPUCodeGenPrepareImpl::visitFDiv(BinaryOperator &FDiv) {
888888
if (NewVal) {
889889
FDiv.replaceAllUsesWith(NewVal);
890890
NewVal->takeName(&FDiv);
891-
DeadVals.insert(&FDiv);
891+
DeadVals.push_back(&FDiv);
892892
}
893893

894894
return true;
@@ -1299,7 +1299,7 @@ static bool tryNarrowMathIfNoOverflow(Instruction *I,
12991299
const SITargetLowering *TLI,
13001300
const TargetTransformInfo &TTI,
13011301
const DataLayout &DL,
1302-
SetVector<Value *> &DeadVals) {
1302+
SmallVector<WeakVH> &DeadVals) {
13031303
unsigned Opc = I->getOpcode();
13041304
Type *OldType = I->getType();
13051305

@@ -1354,7 +1354,7 @@ static bool tryNarrowMathIfNoOverflow(Instruction *I,
13541354

13551355
Value *Zext = Builder.CreateZExt(Arith, OldType);
13561356
I->replaceAllUsesWith(Zext);
1357-
DeadVals.insert(I);
1357+
DeadVals.push_back(I);
13581358
return true;
13591359
}
13601360

@@ -1430,7 +1430,7 @@ bool AMDGPUCodeGenPrepareImpl::visitBinaryOperator(BinaryOperator &I) {
14301430

14311431
if (NewDiv) {
14321432
I.replaceAllUsesWith(NewDiv);
1433-
DeadVals.insert(&I);
1433+
DeadVals.push_back(&I);
14341434
Changed = true;
14351435
}
14361436
}
@@ -1486,7 +1486,7 @@ bool AMDGPUCodeGenPrepareImpl::visitLoadInst(LoadInst &I) {
14861486
Value *ValTrunc = Builder.CreateTrunc(WidenLoad, IntNTy);
14871487
Value *ValOrig = Builder.CreateBitCast(ValTrunc, I.getType());
14881488
I.replaceAllUsesWith(ValOrig);
1489-
DeadVals.insert(&I);
1489+
DeadVals.push_back(&I);
14901490
return true;
14911491
}
14921492

@@ -1528,7 +1528,7 @@ bool AMDGPUCodeGenPrepareImpl::visitSelectInst(SelectInst &I) {
15281528

15291529
Fract->takeName(&I);
15301530
I.replaceAllUsesWith(Fract);
1531-
DeadVals.insert(&I);
1531+
DeadVals.push_back(&I);
15321532
return true;
15331533
}
15341534

@@ -1816,7 +1816,7 @@ bool AMDGPUCodeGenPrepareImpl::visitPHINode(PHINode &I) {
18161816
}
18171817

18181818
I.replaceAllUsesWith(Vec);
1819-
DeadVals.insert(&I);
1819+
DeadVals.push_back(&I);
18201820
return true;
18211821
}
18221822

@@ -1897,7 +1897,7 @@ bool AMDGPUCodeGenPrepareImpl::visitAddrSpaceCastInst(AddrSpaceCastInst &I) {
18971897
auto *Intrin = B.CreateIntrinsic(
18981898
I.getType(), Intrinsic::amdgcn_addrspacecast_nonnull, {I.getOperand(0)});
18991899
I.replaceAllUsesWith(Intrin);
1900-
DeadVals.insert(&I);
1900+
DeadVals.push_back(&I);
19011901
return true;
19021902
}
19031903

@@ -1994,7 +1994,7 @@ bool AMDGPUCodeGenPrepareImpl::visitFMinLike(IntrinsicInst &I) {
19941994
Value *Fract = applyFractPat(Builder, FractArg);
19951995
Fract->takeName(&I);
19961996
I.replaceAllUsesWith(Fract);
1997-
DeadVals.insert(&I);
1997+
DeadVals.push_back(&I);
19981998
return true;
19991999
}
20002000

@@ -2041,7 +2041,7 @@ bool AMDGPUCodeGenPrepareImpl::visitSqrt(IntrinsicInst &Sqrt) {
20412041
Value *NewSqrt = insertValues(Builder, Sqrt.getType(), ResultVals);
20422042
NewSqrt->takeName(&Sqrt);
20432043
Sqrt.replaceAllUsesWith(NewSqrt);
2044-
DeadVals.insert(&Sqrt);
2044+
DeadVals.push_back(&Sqrt);
20452045
return true;
20462046
}
20472047

0 commit comments

Comments
 (0)