Skip to content

Commit f3c74b7

Browse files
committed
[DSE] Make DSEState non-copyable (NFC)
As it contains a self-reference, the default copy/move ctors would not be safe. Move the DSEState::get() method into the ctor to make sure no move occurs here even without NRVO. This is a speculative fix for test failures on llvm-clang-x86_64-expensive-checks-win.
1 parent 8cf93a3 commit f3c74b7

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -898,30 +898,29 @@ struct DSEState {
898898
/// basic block.
899899
DenseMap<BasicBlock *, InstOverlapIntervalsTy> IOLs;
900900

901+
// Class contains self-reference, make sure it's not copied/moved.
902+
DSEState(const DSEState &) = delete;
903+
DSEState &operator=(const DSEState &) = delete;
904+
901905
DSEState(Function &F, AliasAnalysis &AA, MemorySSA &MSSA, DominatorTree &DT,
902906
PostDominatorTree &PDT, const TargetLibraryInfo &TLI,
903907
const LoopInfo &LI)
904908
: F(F), AA(AA), EI(DT, LI), BatchAA(AA, &EI), MSSA(MSSA), DT(DT),
905-
PDT(PDT), TLI(TLI), DL(F.getParent()->getDataLayout()), LI(LI) {}
906-
907-
static DSEState get(Function &F, AliasAnalysis &AA, MemorySSA &MSSA,
908-
DominatorTree &DT, PostDominatorTree &PDT,
909-
const TargetLibraryInfo &TLI, const LoopInfo &LI) {
910-
DSEState State(F, AA, MSSA, DT, PDT, TLI, LI);
909+
PDT(PDT), TLI(TLI), DL(F.getParent()->getDataLayout()), LI(LI) {
911910
// Collect blocks with throwing instructions not modeled in MemorySSA and
912911
// alloc-like objects.
913912
unsigned PO = 0;
914913
for (BasicBlock *BB : post_order(&F)) {
915-
State.PostOrderNumbers[BB] = PO++;
914+
PostOrderNumbers[BB] = PO++;
916915
for (Instruction &I : *BB) {
917916
MemoryAccess *MA = MSSA.getMemoryAccess(&I);
918917
if (I.mayThrow() && !MA)
919-
State.ThrowingBlocks.insert(I.getParent());
918+
ThrowingBlocks.insert(I.getParent());
920919

921920
auto *MD = dyn_cast_or_null<MemoryDef>(MA);
922-
if (MD && State.MemDefs.size() < MemorySSADefsPerBlockLimit &&
923-
(State.getLocForWriteEx(&I) || State.isMemTerminatorInst(&I)))
924-
State.MemDefs.push_back(MD);
921+
if (MD && MemDefs.size() < MemorySSADefsPerBlockLimit &&
922+
(getLocForWriteEx(&I) || isMemTerminatorInst(&I)))
923+
MemDefs.push_back(MD);
925924
}
926925
}
927926

@@ -931,14 +930,12 @@ struct DSEState {
931930
if (AI.hasPassPointeeByValueCopyAttr()) {
932931
// For byval, the caller doesn't know the address of the allocation.
933932
if (AI.hasByValAttr())
934-
State.InvisibleToCallerBeforeRet.insert({&AI, true});
935-
State.InvisibleToCallerAfterRet.insert({&AI, true});
933+
InvisibleToCallerBeforeRet.insert({&AI, true});
934+
InvisibleToCallerAfterRet.insert({&AI, true});
936935
}
937936

938937
// Collect whether there is any irreducible control flow in the function.
939-
State.ContainsIrreducibleLoops = mayContainIrreducibleControl(F, &LI);
940-
941-
return State;
938+
ContainsIrreducibleLoops = mayContainIrreducibleControl(F, &LI);
942939
}
943940

944941
/// Return 'OW_Complete' if a store to the 'KillingLoc' location (by \p
@@ -1935,7 +1932,7 @@ static bool eliminateDeadStores(Function &F, AliasAnalysis &AA, MemorySSA &MSSA,
19351932
const LoopInfo &LI) {
19361933
bool MadeChange = false;
19371934

1938-
DSEState State = DSEState::get(F, AA, MSSA, DT, PDT, TLI, LI);
1935+
DSEState State(F, AA, MSSA, DT, PDT, TLI, LI);
19391936
// For each store:
19401937
for (unsigned I = 0; I < State.MemDefs.size(); I++) {
19411938
MemoryDef *KillingDef = State.MemDefs[I];

0 commit comments

Comments
 (0)