Skip to content

Commit 2a9afdb

Browse files
authored
[clang] Reduce the size of ParsedAttributesView and AttributePool (llvm#148726)
These objects are used as local stack variables during parsing, and they are not small. This patch reduces their sizes: * `ParsedAttributesView`: 72 → 40 bytes * `AttributePool`: 72 → 40 bytes No negative performance impact has been [observed](https://llvm-compile-time-tracker.com/compare.php?from=a709621cd545b061782b03136286227867b452a6&to=f50500b3c178e97c0c861301e853e6d5b859040b&stat=instructions:u). **Context:** We have some verilator-generated code with extremely deep nesting of parenthesized expressions, e.g.: ```cpp bool s = (...(bool)(i[0]) |(bool)(i[1])) |(bool)(i[2])) | ... |(bool)(i[n])); ``` Before this patch, on my local machine, Clang begins emitting `-Wstack-exhausted` when `n` is 715. After the patch, that threshold increases to `950`.
1 parent 57d81c2 commit 2a9afdb

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

clang/include/clang/Sema/ParsedAttr.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ class AttributePool {
678678
friend class AttributeFactory;
679679
friend class ParsedAttributes;
680680
AttributeFactory &Factory;
681-
llvm::SmallVector<ParsedAttr *> Attrs;
681+
llvm::SmallVector<ParsedAttr *, 2> Attrs;
682682

683683
void *allocate(size_t size) {
684684
return Factory.allocate(size);
@@ -808,7 +808,7 @@ class AttributePool {
808808

809809
class ParsedAttributesView {
810810
friend class AttributePool;
811-
using VecTy = llvm::SmallVector<ParsedAttr *>;
811+
using VecTy = llvm::SmallVector<ParsedAttr *, 2>;
812812
using SizeType = decltype(std::declval<VecTy>().size());
813813

814814
public:

0 commit comments

Comments
 (0)