Skip to content

Commit 1b162fa

Browse files
committed
[Support] Change SetVector's default template parameter to SmallVector<*, 0>
Similar to D156016 for MapVector. This brings back commit fae7b98 with a fix to llvm/unittests/Support/ThreadPool.cpp's `_WIN32` code path.
1 parent a0b9f1f commit 1b162fa

File tree

8 files changed

+42
-31
lines changed

8 files changed

+42
-31
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2236,7 +2236,7 @@ static bool requiresMemberFunctionPointerTypeMetadata(CodeGenModule &CGM,
22362236
!isa<CXXDestructorDecl>(MD);
22372237
}
22382238

2239-
std::vector<const CXXRecordDecl *>
2239+
SmallVector<const CXXRecordDecl *, 0>
22402240
CodeGenModule::getMostBaseClasses(const CXXRecordDecl *RD) {
22412241
llvm::SetVector<const CXXRecordDecl *> MostBases;
22422242

clang/lib/CodeGen/CodeGenModule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1505,7 +1505,7 @@ class CodeGenModule : public CodeGenTypeCache {
15051505
///
15061506
/// A most-base class of a class C is defined as a recursive base class of C,
15071507
/// including C itself, that does not have any bases.
1508-
std::vector<const CXXRecordDecl *>
1508+
SmallVector<const CXXRecordDecl *, 0>
15091509
getMostBaseClasses(const CXXRecordDecl *RD);
15101510

15111511
/// Get the declaration of std::terminate for the platform.

llvm/include/llvm/ADT/SetVector.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
#include "llvm/ADT/ArrayRef.h"
2424
#include "llvm/ADT/DenseSet.h"
2525
#include "llvm/ADT/STLExtras.h"
26+
#include "llvm/ADT/SmallVector.h"
2627
#include "llvm/Support/Compiler.h"
2728
#include <cassert>
2829
#include <iterator>
29-
#include <vector>
3030

3131
namespace llvm {
3232

@@ -52,7 +52,7 @@ namespace llvm {
5252
/// when searching for elements instead of checking Set, due to it being better
5353
/// for performance. A value of 0 means that this mode of operation is not used,
5454
/// and is the default value.
55-
template <typename T, typename Vector = std::vector<T>,
55+
template <typename T, typename Vector = SmallVector<T, 0>,
5656
typename Set = DenseSet<T>, unsigned N = 0>
5757
class SetVector {
5858
// Much like in SmallPtrSet, this value should not be too high to prevent

llvm/lib/Analysis/ModuleSummaryAnalysis.cpp

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ extern cl::opt<bool> ScalePartialSampleProfileWorkingSetSize;
9393
// instruction in it takes an address of any basic block, because instruction
9494
// can only take an address of basic block located in the same function.
9595
static bool findRefEdges(ModuleSummaryIndex &Index, const User *CurUser,
96-
SetVector<ValueInfo> &RefEdges,
96+
SetVector<ValueInfo, std::vector<ValueInfo>> &RefEdges,
9797
SmallPtrSet<const User *, 8> &Visited) {
9898
bool HasBlockAddress = false;
9999
SmallVector<const User *, 32> Worklist;
@@ -144,9 +144,12 @@ static bool isNonRenamableLocal(const GlobalValue &GV) {
144144

145145
/// Determine whether this call has all constant integer arguments (excluding
146146
/// "this") and summarize it to VCalls or ConstVCalls as appropriate.
147-
static void addVCallToSet(DevirtCallSite Call, GlobalValue::GUID Guid,
148-
SetVector<FunctionSummary::VFuncId> &VCalls,
149-
SetVector<FunctionSummary::ConstVCall> &ConstVCalls) {
147+
static void addVCallToSet(
148+
DevirtCallSite Call, GlobalValue::GUID Guid,
149+
SetVector<FunctionSummary::VFuncId, std::vector<FunctionSummary::VFuncId>>
150+
&VCalls,
151+
SetVector<FunctionSummary::ConstVCall,
152+
std::vector<FunctionSummary::ConstVCall>> &ConstVCalls) {
150153
std::vector<uint64_t> Args;
151154
// Start from the second argument to skip the "this" pointer.
152155
for (auto &Arg : drop_begin(Call.CB.args())) {
@@ -163,11 +166,18 @@ static void addVCallToSet(DevirtCallSite Call, GlobalValue::GUID Guid,
163166
/// If this intrinsic call requires that we add information to the function
164167
/// summary, do so via the non-constant reference arguments.
165168
static void addIntrinsicToSummary(
166-
const CallInst *CI, SetVector<GlobalValue::GUID> &TypeTests,
167-
SetVector<FunctionSummary::VFuncId> &TypeTestAssumeVCalls,
168-
SetVector<FunctionSummary::VFuncId> &TypeCheckedLoadVCalls,
169-
SetVector<FunctionSummary::ConstVCall> &TypeTestAssumeConstVCalls,
170-
SetVector<FunctionSummary::ConstVCall> &TypeCheckedLoadConstVCalls,
169+
const CallInst *CI,
170+
SetVector<GlobalValue::GUID, std::vector<GlobalValue::GUID>> &TypeTests,
171+
SetVector<FunctionSummary::VFuncId, std::vector<FunctionSummary::VFuncId>>
172+
&TypeTestAssumeVCalls,
173+
SetVector<FunctionSummary::VFuncId, std::vector<FunctionSummary::VFuncId>>
174+
&TypeCheckedLoadVCalls,
175+
SetVector<FunctionSummary::ConstVCall,
176+
std::vector<FunctionSummary::ConstVCall>>
177+
&TypeTestAssumeConstVCalls,
178+
SetVector<FunctionSummary::ConstVCall,
179+
std::vector<FunctionSummary::ConstVCall>>
180+
&TypeCheckedLoadConstVCalls,
171181
DominatorTree &DT) {
172182
switch (CI->getCalledFunction()->getIntrinsicID()) {
173183
case Intrinsic::type_test:
@@ -269,12 +279,14 @@ static void computeFunctionSummary(
269279
MapVector<ValueInfo, CalleeInfo, DenseMap<ValueInfo, unsigned>,
270280
std::vector<std::pair<ValueInfo, CalleeInfo>>>
271281
CallGraphEdges;
272-
SetVector<ValueInfo> RefEdges, LoadRefEdges, StoreRefEdges;
273-
SetVector<GlobalValue::GUID> TypeTests;
274-
SetVector<FunctionSummary::VFuncId> TypeTestAssumeVCalls,
275-
TypeCheckedLoadVCalls;
276-
SetVector<FunctionSummary::ConstVCall> TypeTestAssumeConstVCalls,
277-
TypeCheckedLoadConstVCalls;
282+
SetVector<ValueInfo, std::vector<ValueInfo>> RefEdges, LoadRefEdges,
283+
StoreRefEdges;
284+
SetVector<GlobalValue::GUID, std::vector<GlobalValue::GUID>> TypeTests;
285+
SetVector<FunctionSummary::VFuncId, std::vector<FunctionSummary::VFuncId>>
286+
TypeTestAssumeVCalls, TypeCheckedLoadVCalls;
287+
SetVector<FunctionSummary::ConstVCall,
288+
std::vector<FunctionSummary::ConstVCall>>
289+
TypeTestAssumeConstVCalls, TypeCheckedLoadConstVCalls;
278290
ICallPromotionAnalysis ICallAnalysis;
279291
SmallPtrSet<const User *, 8> Visited;
280292

@@ -505,7 +517,7 @@ static void computeFunctionSummary(
505517
std::vector<ValueInfo> Refs;
506518
if (IsThinLTO) {
507519
auto AddRefEdges = [&](const std::vector<const Instruction *> &Instrs,
508-
SetVector<ValueInfo> &Edges,
520+
SetVector<ValueInfo, std::vector<ValueInfo>> &Edges,
509521
SmallPtrSet<const User *, 8> &Cache) {
510522
for (const auto *I : Instrs) {
511523
Cache.erase(I);
@@ -710,7 +722,7 @@ static void computeVariableSummary(ModuleSummaryIndex &Index,
710722
DenseSet<GlobalValue::GUID> &CantBePromoted,
711723
const Module &M,
712724
SmallVectorImpl<MDNode *> &Types) {
713-
SetVector<ValueInfo> RefEdges;
725+
SetVector<ValueInfo, std::vector<ValueInfo>> RefEdges;
714726
SmallPtrSet<const User *, 8> Visited;
715727
bool HasBlockAddress = findRefEdges(Index, &V, RefEdges, Visited);
716728
bool NonRenamableLocal = isNonRenamableLocal(V);

llvm/tools/llvm-reduce/deltas/ReduceOperandsSkip.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ opportunities(Function &F,
155155

156156
// After all candidates have been added, it doesn't need to be a set
157157
// anymore.
158-
std::vector<Value *> Candidates = ReferencedVals.takeVector();
158+
auto Candidates = ReferencedVals.takeVector();
159159

160160
// Remove ineligible candidates.
161161
llvm::erase_if(Candidates, [&, OpVal](Value *V) {

llvm/unittests/Support/ThreadPool.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class ThreadPoolTest : public testing::Test {
9999

100100
void SetUp() override { CurrentPhase = 0; }
101101

102-
std::vector<llvm::BitVector> RunOnAllSockets(ThreadPoolStrategy S);
102+
SmallVector<llvm::BitVector, 0> RunOnAllSockets(ThreadPoolStrategy S);
103103

104104
std::condition_variable CurrentPhaseCondition;
105105
std::mutex CurrentPhaseMutex;
@@ -346,7 +346,7 @@ TEST_F(ThreadPoolTest, RecursiveWaitDeadlock) {
346346
// isn't implemented for Unix (need AffinityMask in Support/Unix/Program.inc).
347347
#ifdef _WIN32
348348

349-
std::vector<llvm::BitVector>
349+
SmallVector<llvm::BitVector, 0>
350350
ThreadPoolTest::RunOnAllSockets(ThreadPoolStrategy S) {
351351
llvm::SetVector<llvm::BitVector> ThreadsUsed;
352352
std::mutex Lock;
@@ -387,7 +387,7 @@ TEST_F(ThreadPoolTest, AllThreads_UseAllRessources) {
387387
// therefore this test should not run.
388388
if (llvm::RunningWindows11OrGreater())
389389
GTEST_SKIP();
390-
std::vector<llvm::BitVector> ThreadsUsed = RunOnAllSockets({});
390+
auto ThreadsUsed = RunOnAllSockets({});
391391
ASSERT_EQ(llvm::get_cpus(), ThreadsUsed.size());
392392
}
393393

@@ -398,8 +398,7 @@ TEST_F(ThreadPoolTest, AllThreads_OneThreadPerCore) {
398398
// therefore this test should not run.
399399
if (llvm::RunningWindows11OrGreater())
400400
GTEST_SKIP();
401-
std::vector<llvm::BitVector> ThreadsUsed =
402-
RunOnAllSockets(llvm::heavyweight_hardware_concurrency());
401+
auto ThreadsUsed = RunOnAllSockets(llvm::heavyweight_hardware_concurrency());
403402
ASSERT_EQ(llvm::get_cpus(), ThreadsUsed.size());
404403
}
405404

@@ -422,7 +421,7 @@ TEST_F(ThreadPoolTest, AffinityMask) {
422421

423422
using namespace llvm::sys;
424423
if (getenv("LLVM_THREADPOOL_AFFINITYMASK")) {
425-
std::vector<llvm::BitVector> ThreadsUsed = RunOnAllSockets({});
424+
auto ThreadsUsed = RunOnAllSockets({});
426425
// Ensure the threads only ran on CPUs 0-3.
427426
// NOTE: Don't use ASSERT* here because this runs in a subprocess,
428427
// and will show up as un-executed in the parent.

mlir/include/mlir/Support/LLVM.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ template <typename KeyT, typename ValueT,
122122
using DenseMap = llvm::DenseMap<KeyT, ValueT, KeyInfoT, BucketT>;
123123
template <typename ValueT, typename ValueInfoT = DenseMapInfo<ValueT>>
124124
using DenseSet = llvm::DenseSet<ValueT, ValueInfoT>;
125-
template <typename T, typename Vector = std::vector<T>,
125+
template <typename T, typename Vector = llvm::SmallVector<T, 0>,
126126
typename Set = DenseSet<T>, unsigned N = 0>
127127
using SetVector = llvm::SetVector<T, Vector, Set, N>;
128128
template <typename AllocatorTy = llvm::MallocAllocator>

mlir/lib/Analysis/SliceAnalysis.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void mlir::getForwardSlice(Operation *op, SetVector<Operation *> *forwardSlice,
6262
// Reverse to get back the actual topological order.
6363
// std::reverse does not work out of the box on SetVector and I want an
6464
// in-place swap based thing (the real std::reverse, not the LLVM adapter).
65-
std::vector<Operation *> v(forwardSlice->takeVector());
65+
SmallVector<Operation *, 0> v(forwardSlice->takeVector());
6666
forwardSlice->insert(v.rbegin(), v.rend());
6767
}
6868

@@ -74,7 +74,7 @@ void mlir::getForwardSlice(Value root, SetVector<Operation *> *forwardSlice,
7474
// Reverse to get back the actual topological order.
7575
// std::reverse does not work out of the box on SetVector and I want an
7676
// in-place swap based thing (the real std::reverse, not the LLVM adapter).
77-
std::vector<Operation *> v(forwardSlice->takeVector());
77+
SmallVector<Operation *, 0> v(forwardSlice->takeVector());
7878
forwardSlice->insert(v.rbegin(), v.rend());
7979
}
8080

0 commit comments

Comments
 (0)