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

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 27 22:53:01 PDT 2024


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/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.


>From 5bdb864e19924ee73e6136a28955f4fbbb3c5ebd Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sat, 27 Jul 2024 22:23:46 -0700
Subject: [PATCH] [LLParser] Use SmallVector instead of std::vector

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.
---
 llvm/include/llvm/AsmParser/LLParser.h | 3 +--
 llvm/lib/AsmParser/LLParser.cpp        | 6 +++---
 2 files changed, 4 insertions(+), 5 deletions(-)

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