[Mlir-commits] [mlir] fae7b98 - [Support] Change SetVector's default template parameter to SmallVector<*, 0>

Fangrui Song llvmlistbot at llvm.org
Tue Jul 25 00:39:22 PDT 2023


Author: Fangrui Song
Date: 2023-07-25T00:39:17-07:00
New Revision: fae7b98c221b5b28797f7b56b656b6b819d99f27

URL: https://github.com/llvm/llvm-project/commit/fae7b98c221b5b28797f7b56b656b6b819d99f27
DIFF: https://github.com/llvm/llvm-project/commit/fae7b98c221b5b28797f7b56b656b6b819d99f27.diff

LOG: [Support] Change SetVector's default template parameter to SmallVector<*, 0>

Similar to D156016 for MapVector.

Added: 
    

Modified: 
    clang/lib/CodeGen/CodeGenModule.cpp
    clang/lib/CodeGen/CodeGenModule.h
    llvm/include/llvm/ADT/SetVector.h
    llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
    llvm/tools/llvm-reduce/deltas/ReduceOperandsSkip.cpp
    mlir/include/mlir/Support/LLVM.h
    mlir/lib/Analysis/SliceAnalysis.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 07a9dec12f6f25..908dec42afabeb 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -2236,7 +2236,7 @@ static bool requiresMemberFunctionPointerTypeMetadata(CodeGenModule &CGM,
          !isa<CXXDestructorDecl>(MD);
 }
 
-std::vector<const CXXRecordDecl *>
+SmallVector<const CXXRecordDecl *, 0>
 CodeGenModule::getMostBaseClasses(const CXXRecordDecl *RD) {
   llvm::SetVector<const CXXRecordDecl *> MostBases;
 

diff  --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h
index f5fd94492540f2..c5de947687ea61 100644
--- a/clang/lib/CodeGen/CodeGenModule.h
+++ b/clang/lib/CodeGen/CodeGenModule.h
@@ -1505,7 +1505,7 @@ class CodeGenModule : public CodeGenTypeCache {
   ///
   /// A most-base class of a class C is defined as a recursive base class of C,
   /// including C itself, that does not have any bases.
-  std::vector<const CXXRecordDecl *>
+  SmallVector<const CXXRecordDecl *, 0>
   getMostBaseClasses(const CXXRecordDecl *RD);
 
   /// Get the declaration of std::terminate for the platform.

diff  --git a/llvm/include/llvm/ADT/SetVector.h b/llvm/include/llvm/ADT/SetVector.h
index 781ca367b97e48..ff083556cf1694 100644
--- a/llvm/include/llvm/ADT/SetVector.h
+++ b/llvm/include/llvm/ADT/SetVector.h
@@ -23,10 +23,10 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Compiler.h"
 #include <cassert>
 #include <iterator>
-#include <vector>
 
 namespace llvm {
 
@@ -52,7 +52,7 @@ namespace llvm {
 /// when searching for elements instead of checking Set, due to it being better
 /// for performance. A value of 0 means that this mode of operation is not used,
 /// and is the default value.
-template <typename T, typename Vector = std::vector<T>,
+template <typename T, typename Vector = SmallVector<T, 0>,
           typename Set = DenseSet<T>, unsigned N = 0>
 class SetVector {
   // Much like in SmallPtrSet, this value should not be too high to prevent

diff  --git a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
index 2076ed48ea342a..775bb95fdda7b0 100644
--- a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -93,7 +93,7 @@ extern cl::opt<bool> ScalePartialSampleProfileWorkingSetSize;
 // instruction in it takes an address of any basic block, because instruction
 // can only take an address of basic block located in the same function.
 static bool findRefEdges(ModuleSummaryIndex &Index, const User *CurUser,
-                         SetVector<ValueInfo> &RefEdges,
+                         SetVector<ValueInfo, std::vector<ValueInfo>> &RefEdges,
                          SmallPtrSet<const User *, 8> &Visited) {
   bool HasBlockAddress = false;
   SmallVector<const User *, 32> Worklist;
@@ -144,9 +144,12 @@ static bool isNonRenamableLocal(const GlobalValue &GV) {
 
 /// Determine whether this call has all constant integer arguments (excluding
 /// "this") and summarize it to VCalls or ConstVCalls as appropriate.
-static void addVCallToSet(DevirtCallSite Call, GlobalValue::GUID Guid,
-                          SetVector<FunctionSummary::VFuncId> &VCalls,
-                          SetVector<FunctionSummary::ConstVCall> &ConstVCalls) {
+static void addVCallToSet(
+    DevirtCallSite Call, GlobalValue::GUID Guid,
+    SetVector<FunctionSummary::VFuncId, std::vector<FunctionSummary::VFuncId>>
+        &VCalls,
+    SetVector<FunctionSummary::ConstVCall,
+              std::vector<FunctionSummary::ConstVCall>> &ConstVCalls) {
   std::vector<uint64_t> Args;
   // Start from the second argument to skip the "this" pointer.
   for (auto &Arg : drop_begin(Call.CB.args())) {
@@ -163,11 +166,18 @@ static void addVCallToSet(DevirtCallSite Call, GlobalValue::GUID Guid,
 /// If this intrinsic call requires that we add information to the function
 /// summary, do so via the non-constant reference arguments.
 static void addIntrinsicToSummary(
-    const CallInst *CI, SetVector<GlobalValue::GUID> &TypeTests,
-    SetVector<FunctionSummary::VFuncId> &TypeTestAssumeVCalls,
-    SetVector<FunctionSummary::VFuncId> &TypeCheckedLoadVCalls,
-    SetVector<FunctionSummary::ConstVCall> &TypeTestAssumeConstVCalls,
-    SetVector<FunctionSummary::ConstVCall> &TypeCheckedLoadConstVCalls,
+    const CallInst *CI,
+    SetVector<GlobalValue::GUID, std::vector<GlobalValue::GUID>> &TypeTests,
+    SetVector<FunctionSummary::VFuncId, std::vector<FunctionSummary::VFuncId>>
+        &TypeTestAssumeVCalls,
+    SetVector<FunctionSummary::VFuncId, std::vector<FunctionSummary::VFuncId>>
+        &TypeCheckedLoadVCalls,
+    SetVector<FunctionSummary::ConstVCall,
+              std::vector<FunctionSummary::ConstVCall>>
+        &TypeTestAssumeConstVCalls,
+    SetVector<FunctionSummary::ConstVCall,
+              std::vector<FunctionSummary::ConstVCall>>
+        &TypeCheckedLoadConstVCalls,
     DominatorTree &DT) {
   switch (CI->getCalledFunction()->getIntrinsicID()) {
   case Intrinsic::type_test:
@@ -269,12 +279,14 @@ static void computeFunctionSummary(
   MapVector<ValueInfo, CalleeInfo, DenseMap<ValueInfo, unsigned>,
             std::vector<std::pair<ValueInfo, CalleeInfo>>>
       CallGraphEdges;
-  SetVector<ValueInfo> RefEdges, LoadRefEdges, StoreRefEdges;
-  SetVector<GlobalValue::GUID> TypeTests;
-  SetVector<FunctionSummary::VFuncId> TypeTestAssumeVCalls,
-      TypeCheckedLoadVCalls;
-  SetVector<FunctionSummary::ConstVCall> TypeTestAssumeConstVCalls,
-      TypeCheckedLoadConstVCalls;
+  SetVector<ValueInfo, std::vector<ValueInfo>> RefEdges, LoadRefEdges,
+      StoreRefEdges;
+  SetVector<GlobalValue::GUID, std::vector<GlobalValue::GUID>> TypeTests;
+  SetVector<FunctionSummary::VFuncId, std::vector<FunctionSummary::VFuncId>>
+      TypeTestAssumeVCalls, TypeCheckedLoadVCalls;
+  SetVector<FunctionSummary::ConstVCall,
+            std::vector<FunctionSummary::ConstVCall>>
+      TypeTestAssumeConstVCalls, TypeCheckedLoadConstVCalls;
   ICallPromotionAnalysis ICallAnalysis;
   SmallPtrSet<const User *, 8> Visited;
 
@@ -505,7 +517,7 @@ static void computeFunctionSummary(
   std::vector<ValueInfo> Refs;
   if (IsThinLTO) {
     auto AddRefEdges = [&](const std::vector<const Instruction *> &Instrs,
-                           SetVector<ValueInfo> &Edges,
+                           SetVector<ValueInfo, std::vector<ValueInfo>> &Edges,
                            SmallPtrSet<const User *, 8> &Cache) {
       for (const auto *I : Instrs) {
         Cache.erase(I);
@@ -710,7 +722,7 @@ static void computeVariableSummary(ModuleSummaryIndex &Index,
                                    DenseSet<GlobalValue::GUID> &CantBePromoted,
                                    const Module &M,
                                    SmallVectorImpl<MDNode *> &Types) {
-  SetVector<ValueInfo> RefEdges;
+  SetVector<ValueInfo, std::vector<ValueInfo>> RefEdges;
   SmallPtrSet<const User *, 8> Visited;
   bool HasBlockAddress = findRefEdges(Index, &V, RefEdges, Visited);
   bool NonRenamableLocal = isNonRenamableLocal(V);

diff  --git a/llvm/tools/llvm-reduce/deltas/ReduceOperandsSkip.cpp b/llvm/tools/llvm-reduce/deltas/ReduceOperandsSkip.cpp
index 52679f8ba0b003..29863e06f174ba 100644
--- a/llvm/tools/llvm-reduce/deltas/ReduceOperandsSkip.cpp
+++ b/llvm/tools/llvm-reduce/deltas/ReduceOperandsSkip.cpp
@@ -155,7 +155,7 @@ opportunities(Function &F,
 
       // After all candidates have been added, it doesn't need to be a set
       // anymore.
-      std::vector<Value *> Candidates = ReferencedVals.takeVector();
+      auto Candidates = ReferencedVals.takeVector();
 
       // Remove ineligible candidates.
       llvm::erase_if(Candidates, [&, OpVal](Value *V) {

diff  --git a/mlir/include/mlir/Support/LLVM.h b/mlir/include/mlir/Support/LLVM.h
index fec0debc716699..235d84c5beff12 100644
--- a/mlir/include/mlir/Support/LLVM.h
+++ b/mlir/include/mlir/Support/LLVM.h
@@ -122,7 +122,7 @@ template <typename KeyT, typename ValueT,
 using DenseMap = llvm::DenseMap<KeyT, ValueT, KeyInfoT, BucketT>;
 template <typename ValueT, typename ValueInfoT = DenseMapInfo<ValueT>>
 using DenseSet = llvm::DenseSet<ValueT, ValueInfoT>;
-template <typename T, typename Vector = std::vector<T>,
+template <typename T, typename Vector = llvm::SmallVector<T, 0>,
           typename Set = DenseSet<T>, unsigned N = 0>
 using SetVector = llvm::SetVector<T, Vector, Set, N>;
 template <typename AllocatorTy = llvm::MallocAllocator>

diff  --git a/mlir/lib/Analysis/SliceAnalysis.cpp b/mlir/lib/Analysis/SliceAnalysis.cpp
index 9a5821da6343d4..95ec6ab2bd7a49 100644
--- a/mlir/lib/Analysis/SliceAnalysis.cpp
+++ b/mlir/lib/Analysis/SliceAnalysis.cpp
@@ -62,7 +62,7 @@ void mlir::getForwardSlice(Operation *op, SetVector<Operation *> *forwardSlice,
   // Reverse to get back the actual topological order.
   // std::reverse does not work out of the box on SetVector and I want an
   // in-place swap based thing (the real std::reverse, not the LLVM adapter).
-  std::vector<Operation *> v(forwardSlice->takeVector());
+  SmallVector<Operation *, 0> v(forwardSlice->takeVector());
   forwardSlice->insert(v.rbegin(), v.rend());
 }
 
@@ -74,7 +74,7 @@ void mlir::getForwardSlice(Value root, SetVector<Operation *> *forwardSlice,
   // Reverse to get back the actual topological order.
   // std::reverse does not work out of the box on SetVector and I want an
   // in-place swap based thing (the real std::reverse, not the LLVM adapter).
-  std::vector<Operation *> v(forwardSlice->takeVector());
+  SmallVector<Operation *, 0> v(forwardSlice->takeVector());
   forwardSlice->insert(v.rbegin(), v.rend());
 }
 


        


More information about the Mlir-commits mailing list