Skip to content

Commit 90c779a

Browse files
nikicfhahn
authored andcommitted
[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. (cherry-picked from f3c74b7)
1 parent f3428d3 commit 90c779a

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
@@ -893,30 +893,29 @@ struct DSEState {
893893
/// basic block.
894894
DenseMap<BasicBlock *, InstOverlapIntervalsTy> IOLs;
895895

896+
// Class contains self-reference, make sure it's not copied/moved.
897+
DSEState(const DSEState &) = delete;
898+
DSEState &operator=(const DSEState &) = delete;
899+
896900
DSEState(Function &F, AliasAnalysis &AA, MemorySSA &MSSA, DominatorTree &DT,
897901
PostDominatorTree &PDT, const TargetLibraryInfo &TLI,
898902
const LoopInfo &LI)
899903
: F(F), AA(AA), EI(DT, LI), BatchAA(AA, &EI), MSSA(MSSA), DT(DT),
900-
PDT(PDT), TLI(TLI), DL(F.getParent()->getDataLayout()), LI(LI) {}
901-
902-
static DSEState get(Function &F, AliasAnalysis &AA, MemorySSA &MSSA,
903-
DominatorTree &DT, PostDominatorTree &PDT,
904-
const TargetLibraryInfo &TLI, const LoopInfo &LI) {
905-
DSEState State(F, AA, MSSA, DT, PDT, TLI, LI);
904+
PDT(PDT), TLI(TLI), DL(F.getParent()->getDataLayout()), LI(LI) {
906905
// Collect blocks with throwing instructions not modeled in MemorySSA and
907906
// alloc-like objects.
908907
unsigned PO = 0;
909908
for (BasicBlock *BB : post_order(&F)) {
910-
State.PostOrderNumbers[BB] = PO++;
909+
PostOrderNumbers[BB] = PO++;
911910
for (Instruction &I : *BB) {
912911
MemoryAccess *MA = MSSA.getMemoryAccess(&I);
913912
if (I.mayThrow() && !MA)
914-
State.ThrowingBlocks.insert(I.getParent());
913+
ThrowingBlocks.insert(I.getParent());
915914

916915
auto *MD = dyn_cast_or_null<MemoryDef>(MA);
917-
if (MD && State.MemDefs.size() < MemorySSADefsPerBlockLimit &&
918-
(State.getLocForWriteEx(&I) || State.isMemTerminatorInst(&I)))
919-
State.MemDefs.push_back(MD);
916+
if (MD && MemDefs.size() < MemorySSADefsPerBlockLimit &&
917+
(getLocForWriteEx(&I) || isMemTerminatorInst(&I)))
918+
MemDefs.push_back(MD);
920919
}
921920
}
922921

@@ -926,14 +925,12 @@ struct DSEState {
926925
if (AI.hasPassPointeeByValueCopyAttr()) {
927926
// For byval, the caller doesn't know the address of the allocation.
928927
if (AI.hasByValAttr())
929-
State.InvisibleToCallerBeforeRet.insert({&AI, true});
930-
State.InvisibleToCallerAfterRet.insert({&AI, true});
928+
InvisibleToCallerBeforeRet.insert({&AI, true});
929+
InvisibleToCallerAfterRet.insert({&AI, true});
931930
}
932931

933932
// Collect whether there is any irreducible control flow in the function.
934-
State.ContainsIrreducibleLoops = mayContainIrreducibleControl(F, &LI);
935-
936-
return State;
933+
ContainsIrreducibleLoops = mayContainIrreducibleControl(F, &LI);
937934
}
938935

939936
/// Return 'OW_Complete' if a store to the 'Later' location (by \p LaterI
@@ -1886,7 +1883,7 @@ static bool eliminateDeadStores(Function &F, AliasAnalysis &AA, MemorySSA &MSSA,
18861883
const LoopInfo &LI) {
18871884
bool MadeChange = false;
18881885

1889-
DSEState State = DSEState::get(F, AA, MSSA, DT, PDT, TLI, LI);
1886+
DSEState State(F, AA, MSSA, DT, PDT, TLI, LI);
18901887
// For each store:
18911888
for (unsigned I = 0; I < State.MemDefs.size(); I++) {
18921889
MemoryDef *KillingDef = State.MemDefs[I];

0 commit comments

Comments
 (0)