23 Commits

Author SHA1 Message Date
Timm Baeder
dcaab6dd99
[clang][bytecode] Add source info to jump ops (#188003)
The attached test case otherwise results in a function with one jump op
but no source info at all.
2026-03-23 11:45:34 +01:00
Timm Baeder
78f267f01d
Reapply "[clang][bytecode] Allocate local variables in InterpFrame … (#187644)
…tail storage" (#187410)

This reverts commit bf1db77fc87ce9d2ca7744565321b09a5d23692f.

Avoid using an `InterpFrame` member after calling its destructor this
time. I hope that was the only problem.
2026-03-20 10:11:21 +01:00
Timm Baeder
bf1db77fc8
Revert "[clang][bytecode] Allocate local variables in InterpFrame tail storage" (#187410)
Reverts llvm/llvm-project#185835

Looks like this broke two msan builders:
https://lab.llvm.org/buildbot/#/builders/164/builds/19819
https://lab.llvm.org/buildbot/#/builders/94/builds/16257
2026-03-19 19:29:56 -07:00
Timm Baeder
63b44decb5
[clang][bytecode] Allocate local variables in InterpFrame tail storage (#185835)
Instead of heap-allocating an `InterpFrame` and then immediately
heap-allocating more space for the local variables, do only one
heap-allocation and use tail storage for the local variables.
We already know how many bytes we need to for the tail storage after
all.
This also makes `InterpFrame` a little smaller since we don't need to
save an explicit pointer for the local variable memory.






For an artificial test case doing lots of function calls with local
variables like:
```c++
constexpr int plus(int a, int b) {
        int x = a;
        int y = b;
        int z = x + y;
        return z;
}

constexpr int minus(int a, int b) {
        int x = a;
        int y = b;
        int z = x - y;
        return z;
}
constexpr int foo() {
        int a = 0;
        for (unsigned I = 0; I != 1'000'000; ++I) {
                int b = I;
                a = plus(a,b );
                a = minus(a,I);
        }
        return a;
}
static_assert(foo() == 0);
```
this saves us over 6%.

We also eliminate the per-argument `Block` heap allocation on the first
pointer-access to an argument the same way. To make this work, we change
the param ops to use the parameter index instead of the offset.
2026-03-18 17:08:23 +01:00
Timm Baeder
afb2e4f2e2
[clang][bytecode] Clean up interp::Function parameter handling (#178621)
Replace the multiple data structures with a vector + a map holding all
`ParamDescriptor`s. Update docs.
2026-01-30 10:07:23 +01:00
Timm Baeder
f0982d5d44
[clang][bytecode] Fix calling lambdas with broken instance pointers (#175511)
Clang will make the instance pointer be of type 'int' if it is invalid,
which trips up later logic. Mark functions as invalid if any of their
parameters is and compile + check them early in CallPtr.

Fixes https://github.com/llvm/llvm-project/issues/175425
2026-01-12 12:34:22 +01:00
Timm Baeder
18d6d67067
[clang][bytecode] Check for invalid function decls (#175312)
If the function decl is invalid, the `interp::Function` shouldn't ever
be valid.

Fixes https://github.com/llvm/llvm-project/issues/175280
2026-01-10 16:52:54 +01:00
Timm Baeder
f5ffedf81a
[clang][bytecode] Pass SourceInfo objects by value (#159532)
They are only pointer-sized and copying them is cheaper than taking the
const ref.
2025-09-18 13:08:42 +02:00
Timm Baeder
fefe670be0
[clang][bytecode] Compile the definition, not the most recent decl (#158093) 2025-09-12 07:12:09 +02:00
Timm Baeder
dc7c3c2b2b
[clang][bytecode] Disable location tracking for implicit field inits (#150190) 2025-08-05 13:14:01 +02:00
Timm Baeder
105963ad5e
[clang][bytecode] Use SmallVector for Function::Code (#151821)
This way we can use resize_for_overwrite, which is slightly more
efficient:

https://llvm-compile-time-tracker.com/compare.php?from=7bdab76350970a3ac471da6a30035dd5b7ef14f3&to=b55bd2c74f230e2150e54b0523db6a8426eab54d&stat=instructions:u
2025-08-04 17:03:58 +02:00
Timm Baeder
c304a2bb0c
[clang][bytecode][NFC] Code size is always aligned (#151824)
We don't need to align Code.size(), since we always resize it to aligned
values, so Code.size() is always aligned.
2025-08-02 17:29:11 +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
32fc625a3f
Reapply "Reapply "[clang][bytecode] Allocate IntegralAP and Floating … (#145014)
…types usi… (#144676)"

This reverts commit 68471d29eed2c49f9b439e505b3f24d387d54f97.

IntegralAP contains a union:
  union {
    uint64_t *Memory = nullptr;
    uint64_t Val;
  };

On 64bit systems, both Memory and Val have the same size. However, on 32
bit system, Val is 64bit and Memory only 32bit. Which means the default
initializer for Memory will only zero half of Val. We fixed this by
zero-initializing Val explicitly in the IntegralAP(unsigned BitWidth)
constructor.


See also the discussion in
https://github.com/llvm/llvm-project/pull/144246
2025-06-20 18:06:01 +02:00
Timm Baeder
83356f3b62
[clang][bytecode] Compile functions lazily (#131596)
Create the Function* handles for all functions we see, but delay the
actual compilation until we really call the function. This speeds up
compile times with the new interpreter a bit.
2025-03-17 15:58:35 +01:00
Timm Baeder
d08cf7900d
[clang][bytecode] Implement __builtin_constant_p (#130143)
Use the regular code paths for interpreting.

Add new instructions: `StartSpeculation` will reset the diagnostics
pointers to `nullptr`, which will keep us from reporting any diagnostics
during speculation. `EndSpeculation` will undo this.

The rest depends on what `Emitter` we use.

For `EvalEmitter`, we have no bytecode, so we implement `speculate()` by
simply visiting the first argument of `__builtin_constant_p`. If the
evaluation fails, we push a `0` on the stack, otherwise a `1`.

For `ByteCodeEmitter`, add another instrucion called `BCP`, that
interprets all the instructions following it until the next
`EndSpeculation` instruction. If any of those instructions fails, we
jump to the `EndLabel`, which brings us right before the
`EndSpeculation`. We then push the result on the stack.
2025-03-08 06:06:14 +01:00
Timm Baeder
cf893baf02
[clang][bytecode][NFC] Add a FunctionKind enum (#125391)
Some function types are special to us, so add an enum and determinte the
function kind once when creating the function, instead of looking at the
Decl every time we need the information.
2025-02-02 12:09:30 +01:00
Timm Baeder
b5c9cba3f3
[clang][bytecode] Don't memcpy() FixedPoint values (#123599)
llvm::FixedPoint is not trivially copyable.
2025-01-20 15:10:12 +01: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
048bc67276
[clang][bytecode] Start implementing fixed point types (#110216)
Add the primitive type and implement to-bool casts.
2024-09-27 11:32:43 +02:00
Timm Baeder
3745a2e8ab
[clang][bytecode][NFC] Cache the BuiltinID in Function (#106745)
FunctionDecl::getBuiltinID() is surprisingly slow and we tend to call it
quite a bit, especially when interpreting builtin functions. Caching the
BuiltinID here reduces the time I need to compile the
floating_comparison namespace from builtin-functions.cpp from 7.2s to
6.3s locally.
2024-08-31 01:50:59 +02:00
Timm Baeder
ca148b2150
[clang][bytecode] Support ObjC blocks (#104551)
I started out by adding a new pointer type for blocks, and I was fully
prepared to compile their AST to bytecode and later call them.

... then I found out that the current interpreter doesn't support
calling blocks at all. So we reuse `Function` to support sources other
than `FunctionDecl`s and classify `BlockPointerType` as `PT_FnPtr`.
2024-08-20 06:08:53 +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