[llvm] eee620b - [LLParser] Use SmallVector instead of std::vector (#100916)

via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 28 01:37:15 PDT 2024


Author: Kazu Hirata
Date: 2024-07-28T01:37:12-07:00
New Revision: eee620b890ad7e2e139d44fee95bd5049fa48f5c

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

LOG: [LLParser] Use SmallVector instead of std::vector (#100916)

The use of SmallVector here saves 1.03% of heap allocations during the
compilation of X86ISelLowering.cpp.ll, a .ll version of
X86ISelLowering.cpp.  The 8 inline elements cover greater than 99% of
invocations encountered here.

While I am it, the patch changes the parameter type to ArrayRef to
allow callers to use any vector type.

Added: 
    

Modified: 
    llvm/include/llvm/AsmParser/LLParser.h
    llvm/lib/AsmParser/LLParser.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/AsmParser/LLParser.h b/llvm/include/llvm/AsmParser/LLParser.h
index e381295802009..9e551d3ae2bbe 100644
--- a/llvm/include/llvm/AsmParser/LLParser.h
+++ b/llvm/include/llvm/AsmParser/LLParser.h
@@ -560,8 +560,7 @@ namespace llvm {
     bool parseExceptionArgs(SmallVectorImpl<Value *> &Args,
                             PerFunctionState &PFS);
 
-    bool resolveFunctionType(Type *RetType,
-                             const SmallVector<ParamInfo, 16> &ArgList,
+    bool resolveFunctionType(Type *RetType, ArrayRef<ParamInfo> ArgList,
                              FunctionType *&FuncTy);
 
     // Constant Parsing.

diff  --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index a886f6e3a4b93..9358f89e2bf9d 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -7260,13 +7260,13 @@ bool LLParser::parseIndirectBr(Instruction *&Inst, PerFunctionState &PFS) {
 // If RetType is a non-function pointer type, then this is the short syntax
 // for the call, which means that RetType is just the return type.  Infer the
 // rest of the function argument types from the arguments that are present.
-bool LLParser::resolveFunctionType(Type *RetType,
-                                   const SmallVector<ParamInfo, 16> &ArgList,
+bool LLParser::resolveFunctionType(Type *RetType, ArrayRef<ParamInfo> ArgList,
                                    FunctionType *&FuncTy) {
   FuncTy = dyn_cast<FunctionType>(RetType);
   if (!FuncTy) {
     // Pull out the types of all of the arguments...
-    std::vector<Type*> ParamTypes;
+    SmallVector<Type *, 8> ParamTypes;
+    ParamTypes.reserve(ArgList.size());
     for (const ParamInfo &Arg : ArgList)
       ParamTypes.push_back(Arg.V->getType());
 


        


More information about the llvm-commits mailing list