[PATCH] D136633: [clang][AST] avoid unnecessary FunctionProtoTypes.FindNodeOrInsertPos call
Troy Johnson via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 24 11:57:17 PDT 2022
troyj created this revision.
troyj added a reviewer: bruno.
Herald added a project: All.
troyj requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
getFunctionTypeInternal forms a FoldingSetNodeID and then calls FunctionProtoTypes.FindNodeOrInsertPos(). Later, upon returning from recursion, it calls FunctionProtoTypes.FindNodeOrInsertPos() again with the same ID. This second call will yield the same InsertPos unless the recursion caused FunctionProtoTypes to rebucket. The rebucketing can be detected by comparing the capacity of the set before and after the recursion, which allows us to skip the redundant call.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D136633
Files:
clang/lib/AST/ASTContext.cpp
Index: clang/lib/AST/ASTContext.cpp
===================================================================
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -4514,13 +4514,17 @@
// Adjust the canonical function result type.
CanQualType CanResultTy = getCanonicalFunctionResultType(ResultTy);
+ const auto OrigCapacity = FunctionProtoTypes.capacity();
Canonical =
getFunctionTypeInternal(CanResultTy, CanonicalArgs, CanonicalEPI, true);
- // Get the new insert position for the node we care about.
- FunctionProtoType *NewIP =
- FunctionProtoTypes.FindNodeOrInsertPos(ID, InsertPos);
- assert(!NewIP && "Shouldn't be in the map!"); (void)NewIP;
+ // Get the new insert position for the node we care about, if the recursive
+ // call invalidated InsertPos.
+ if (FunctionProtoTypes.capacity() != OrigCapacity) {
+ FunctionProtoType *NewIP =
+ FunctionProtoTypes.FindNodeOrInsertPos(ID, InsertPos);
+ assert(!NewIP && "Shouldn't be in the map!"); (void)NewIP;
+ }
}
// Compute the needed size to hold this FunctionProtoType and the
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136633.470233.patch
Type: text/x-patch
Size: 1127 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221024/c2404685/attachment.bin>
More information about the cfe-commits
mailing list