31 Commits

Author SHA1 Message Date
Timm Baeder
0d05c42b6a
[clang][bytecode] Improve __builtin_{,dynamic_}object_size implementation (#153601) 2025-08-18 11:12:33 +02:00
Timm Baeder
7a6c9813d6
[clang][bytecode] Add AccessFlags to Block (#152590)
This way, we can check a single uint8_t for != 0 to know whether this
block is accessible or not. If not, we still need to figure out why not
and diagnose appropriately of course.
2025-08-09 15:46:28 +02:00
Matheus Izvekov
91cdd35008
[clang] Improve nested name specifier AST representation (#147835)
This is a major change on how we represent nested name qualifications in
the AST.

* The nested name specifier itself and how it's stored is changed. The
prefixes for types are handled within the type hierarchy, which makes
canonicalization for them super cheap, no memory allocation required.
Also translating a type into nested name specifier form becomes a no-op.
An identifier is stored as a DependentNameType. The nested name
specifier gains a lightweight handle class, to be used instead of
passing around pointers, which is similar to what is implemented for
TemplateName. There is still one free bit available, and this handle can
be used within a PointerUnion and PointerIntPair, which should keep
bit-packing aficionados happy.
* The ElaboratedType node is removed, all type nodes in which it could
previously apply to can now store the elaborated keyword and name
qualifier, tail allocating when present.
* TagTypes can now point to the exact declaration found when producing
these, as opposed to the previous situation of there only existing one
TagType per entity. This increases the amount of type sugar retained,
and can have several applications, for example in tracking module
ownership, and other tools which care about source file origins, such as
IWYU. These TagTypes are lazily allocated, in order to limit the
increase in AST size.

This patch offers a great performance benefit.

It greatly improves compilation time for
[stdexec](https://github.com/NVIDIA/stdexec). For one datapoint, for
`test_on2.cpp` in that project, which is the slowest compiling test,
this patch improves `-c` compilation time by about 7.2%, with the
`-fsyntax-only` improvement being at ~12%.

This has great results on compile-time-tracker as well:

![image](https://github.com/user-attachments/assets/700dce98-2cab-4aa8-97d1-b038c0bee831)

This patch also further enables other optimziations in the future, and
will reduce the performance impact of template specialization resugaring
when that lands.

It has some other miscelaneous drive-by fixes.

About the review: Yes the patch is huge, sorry about that. Part of the
reason is that I started by the nested name specifier part, before the
ElaboratedType part, but that had a huge performance downside, as
ElaboratedType is a big performance hog. I didn't have the steam to go
back and change the patch after the fact.

There is also a lot of internal API changes, and it made sense to remove
ElaboratedType in one go, versus removing it from one type at a time, as
that would present much more churn to the users. Also, the nested name
specifier having a different API avoids missing changes related to how
prefixes work now, which could make existing code compile but not work.

How to review: The important changes are all in
`clang/include/clang/AST` and `clang/lib/AST`, with also important
changes in `clang/lib/Sema/TreeTransform.h`.

The rest and bulk of the changes are mostly consequences of the changes
in API.

PS: TagType::getDecl is renamed to `getOriginalDecl` in this patch, just
for easier to rebasing. I plan to rename it back after this lands.

Fixes #136624
Fixes https://github.com/llvm/llvm-project/issues/43179
Fixes https://github.com/llvm/llvm-project/issues/68670
Fixes https://github.com/llvm/llvm-project/issues/92757
2025-08-09 05:06:53 -03:00
Timm Baeder
8259be65c7
[clang][bytecode] Remove unused includes (#151848)
UnsignedOrNone.h from PrimType.h and ASTLambda.h from Function.h.
2025-08-03 08:52:03 +02:00
Timm Baeder
904de95e71
[clang][bytecode][NFC] Fix a few clang-tidy complaints (#150940) 2025-07-28 15:57:49 +02:00
Timm Baeder
e39ee62c5b
[clang][bytecode] Use OptPrimType instead of std::optional<PrimType> (#149812)
We use this construct a lot. Use something similar to clang's
UnsignedOrNone.

This results in some slighy compile time improvements:
https://llvm-compile-time-tracker.com/compare.php?from=17a4b0399d161a3b89d8f0ce82add1638f23f5d4&to=a251d81ecd0ed45dd190462663155fdb303ef04d&stat=instructions:u
2025-07-21 17:16:13 +02:00
Timm Baeder
5b0935f1f0
[clang][bytecode] Reintroduce Pointer::elem() (#149693)
As a way of writing atIndex(I).deref<T>(), which creates an intermediate
Pointer, which in turn adds (and removes) that pointer from the pointer
list of the Block. This way we can avoid that.
2025-07-20 10:59:50 +02:00
Timm Baeder
645846d43b
[clang][bytecode] Initialize global strings via memcpy (#140789)
If we know the char width is 1, we can just copy
the data over instead of going through the Pointer API.
2025-05-21 07:56:15 +02:00
Timm Baeder
211b51e471
[clang][bytecode] Propagate IsVolatile bit to subobjects (#137293)
For
```c++
  struct S {
    constexpr S(int=0) : i(1) {}
    int i;
  };
  constexpr volatile S vs;
```

reading from `vs.i` is not allowed, even though `i` is not volatile
qualified. Propagate the IsVolatile bit down the hierarchy, so we know
reading from `vs.i` is a volatile read.
2025-04-25 11:23:34 +02:00
Timm Baeder
5eca2ddeba
[clang][bytecode] Don't diagnose const extern reads in CPCE mode (#137285)
They might become constexpr later.
2025-04-25 08:54:34 +02:00
Timm Baeder
05eafd9f2b
[clang][bytecode] Explicitly mark constexpr-unknown variables as such (#135806)
Instead of trying to figure out what's constexpr-unknown later on.
2025-04-16 09:00:52 +02:00
Timm Baeder
c51d396f4d
[clang][bytecode] Fix __builtin_memmove type diagnostics (#132544)
Set the source type when allocating primitives so we can later retrieve
it.
2025-03-22 14:58:32 +01:00
Kazu Hirata
c38ef58557
[ByteCode] Avoid repeated hash lookups (NFC) (#132141) 2025-03-20 09:09:57 -07:00
Timm Baeder
06fc7d68ff
[clang][bytecode] Don't error out on incomplete declarations (#129685)
Later operations on these are invalid, but the declaration is fine, if
extern.
2025-03-04 12:41:34 +01:00
Timm Baeder
2c1e9f14be
[clang][bytecode] Explicit composite array descriptor types (#129376)
When creating descriptor for array element types, we only save the
original source, e.g. int[2][2][2]. So later calls to getType() of the
element descriptors will also return int[2][2][2], instead of e.g.
int[2][2] for the second dimension.
Fix this by explicitly tracking the array types.
The last attached test case used to have an lvalue offset of 32 instead
of 24.

We should do this for more desriptor types though and not just composite
array, but I'm leaving that to a later patch.
2025-03-02 09:40:56 +01:00
Timm Baeder
e8d848824b
[clang][bytecode] Fix dynamic array allocation return values (#127387)
We need to return a pointer to the first element, not the array itself.
2025-02-16 12:24:35 +01:00
Kazu Hirata
2fee5ef235
[ByteCode] Avoid repeated hash lookups (NFC) (#126379) 2025-02-08 11:35:45 -08:00
Timm Baeder
f7f3dfce3d
[clang][bytecode] Refactor Program::createGlobalString (#125467)
Remove unnecesary narrow() calls, rename a variable and initialize the
array as a whole instead of each element individually.
2025-02-03 09:42:12 +01:00
Timm Baeder
a34a087fc5
[clang][bytecode] Handle non-primitive vector element types (#124926)
By rejecting them. We would crash before.
2025-01-29 16:39:02 +01:00
Kazu Hirata
80e0cbafba
[ByteCode] Migrate away from PointerUnion::dyn_cast (NFC) (#123445)
Note that PointerUnion::dyn_cast has been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //        isa<T>, cast<T> and the llvm::dyn_cast<T>

Literal migration would result in dyn_cast_if_present (see the
definition of PointerUnion::dyn_cast), but this patch uses dyn_cast
because we expect D to be nonnull.
2025-01-18 09:43:17 -08:00
Kazu Hirata
63d9ef5e37
[AST] Migrate away from PointerUnion::{is,get} (NFC) (#117469)
Note that PointerUnion::{is,get} have been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //        isa<T>, cast<T> and the llvm::dyn_cast<T>

I'm not touching PointerUnion::dyn_cast for now because it's a bit
complicated; we could blindly migrate it to dyn_cast_if_present, but
we should probably use dyn_cast when the operand is known to be
non-null.
2024-11-24 07:28:20 -08:00
Kazu Hirata
dec6324cb0
[AST] Remove unused includes (NFC) (#116549)
Identified with misc-include-cleaner.
2024-11-17 09:36:48 -08:00
Timm Baeder
05910b44c9
[clang][bytecode][NFC] Use const auto* for Type cast result (#114405) 2024-10-31 16:37:53 +01:00
Timm Baeder
9ae41c24b3
[clang][bytecode] Create dummy pointers for non-reference DeclRefExprs (#113202)
... with non-constant initializers.
2024-10-22 10:38:13 +02:00
Timm Baeder
ff04bb8f40
[clang][bytecode] Use PredefinedExpr as base for its variable (#111956)
This fixes the error message generated.
2024-10-11 09:31:49 +02:00
Kazu Hirata
93f7fce397
[ByteCode] Avoid repeated hash lookups (NFC) (#111273) 2024-10-06 09:22:13 -07:00
Timm Baeder
4e5f8a8f0b
[clang][bytecode] Save a per-Block IsWeak bit (#111248)
Checking the decl for every load is rather expensive.
2024-10-05 17:35:52 +02:00
Timm Baeder
8e2dbab242
[clang][bytecode] Fix defining extern variables (#108940)
At the point of defintion of the variable, a function might already
refert to the variable by its index. Replace the index with the new one.
2024-09-17 15:21:28 +02:00
Timm Baeder
bd8d432d7b
[clang][bytecode] Add support for creating dummies for expressions (#108394)
And use that to fix VisitObjCBoxedExprs.
2024-09-12 17:25:40 +02:00
Timm Baeder
3e999bbc2d
[clang][bytecode] Use first FieldDecl instead of asserting (#104760)
This assertion fails sometimes. We use the first decl for lookup later,
so let's use the first decl here as well.
2024-08-19 15:14:44 +02:00
Timm Baeder
a07aba5d44
[clang] Rename all AST/Interp stuff to AST/ByteCode (#104552)
"Interp" clashes with the clang interpreter and people often confuse
this.
2024-08-16 17:13:12 +02:00