Skip to content

Commit f5f6613

Browse files
[Scalar] Use SmallSetVector instead of SmallVector (NFC) (#154678)
insertParsePoints collects live variables and then deduplicate them while retaining the original insertion order, which is exactly what SetVector is designed for. This patch replaces SmallVector with SetSmallVector while deleting unique_unsorted. While we are at it, this patch reduces the number of inline elements to a reasonable level for linear search.
1 parent e45210a commit f5f6613

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2214,14 +2214,6 @@ static void relocationViaAlloca(
22142214
#endif
22152215
}
22162216

2217-
/// Implement a unique function which doesn't require we sort the input
2218-
/// vector. Doing so has the effect of changing the output of a couple of
2219-
/// tests in ways which make them less useful in testing fused safepoints.
2220-
template <typename T> static void unique_unsorted(SmallVectorImpl<T> &Vec) {
2221-
SmallPtrSet<T, 8> Seen;
2222-
erase_if(Vec, [&](const T &V) { return !Seen.insert(V).second; });
2223-
}
2224-
22252217
/// Insert holders so that each Value is obviously live through the entire
22262218
/// lifetime of the call.
22272219
static void insertUseHolderAfter(CallBase *Call, const ArrayRef<Value *> Values,
@@ -2839,15 +2831,17 @@ static bool insertParsePoints(Function &F, DominatorTree &DT,
28392831
}
28402832
PointerToBase.clear();
28412833

2842-
// Do all the fixups of the original live variables to their relocated selves
2843-
SmallVector<Value *, 128> Live;
2834+
// Do all the fixups of the original live variables to their relocated selves.
2835+
// A SmallSetVector is used to collect live variables while retaining the
2836+
// order in which we add them, which is important for reproducible tests.
2837+
SmallSetVector<Value *, 16> Live;
28442838
for (const PartiallyConstructedSafepointRecord &Info : Records) {
28452839
// We can't simply save the live set from the original insertion. One of
28462840
// the live values might be the result of a call which needs a safepoint.
28472841
// That Value* no longer exists and we need to use the new gc_result.
28482842
// Thankfully, the live set is embedded in the statepoint (and updated), so
28492843
// we just grab that.
2850-
llvm::append_range(Live, Info.StatepointToken->gc_live());
2844+
Live.insert_range(Info.StatepointToken->gc_live());
28512845
#ifndef NDEBUG
28522846
// Do some basic validation checking on our liveness results before
28532847
// performing relocation. Relocation can and will turn mistakes in liveness
@@ -2867,7 +2861,6 @@ static bool insertParsePoints(Function &F, DominatorTree &DT,
28672861
}
28682862
#endif
28692863
}
2870-
unique_unsorted(Live);
28712864

28722865
#ifndef NDEBUG
28732866
// Validation check
@@ -2876,7 +2869,7 @@ static bool insertParsePoints(Function &F, DominatorTree &DT,
28762869
"must be a gc pointer type");
28772870
#endif
28782871

2879-
relocationViaAlloca(F, DT, Live, Records);
2872+
relocationViaAlloca(F, DT, Live.getArrayRef(), Records);
28802873
return !Records.empty();
28812874
}
28822875

0 commit comments

Comments
 (0)