355 Commits

Author SHA1 Message Date
Sirui Mu
318b0dda7c
[CIR] Add atomic load and store operations (#153814)
This patch adds support for atomic loads and stores. Specifically, it
adds support for the following intrinsic calls:

- `__atomic_load` and `__atomic_store`;
- `__c11_atomic_load` and `__c11_atomic_store`.
2025-08-20 21:49:04 +08:00
Morris Hafner
b01f05977c
[CIR] Add support for string literal lvalues in ConstantLValueEmitter (#154514) 2025-08-20 13:30:21 +02:00
Morris Hafner
0989ff5de8
[CIR] Add constant attribute to GlobalOp (#154359)
This patch adds the constant attribute to cir.global, the appropriate
lowering to LLVM constant and updates the tests.

---------

Co-authored-by: Andy Kaylor <akaylor@nvidia.com>
2025-08-20 12:53:00 +02:00
Morris Hafner
3b9664840b
[CIR] Implement__builtin_va_arg (#153834)
Part of https://github.com/llvm/llvm-project/issues/153286.
Depends on https://github.com/llvm/llvm-project/pull/153819.

This patch adds support for __builtin_va_arg by adding the cir.va.arg
operator. Unlike the incubator it doesn't depend on any target specific
lowering (yet) but maps to llvm.va_arg.
2025-08-20 12:52:11 +02:00
Morris Hafner
088555cf6b
[CIR] Add support for base classes in type conversion safety check (#154385)
This patch enables the record layout computation of types that are
derived more than once.
2025-08-20 12:44:26 +02:00
Amr Hesham
018c5ba161
[CIR] Implement MemberExpr with VarDecl for ComplexType (#154307)
This change adds support for MemberExpr with VarDecl ComplexType

Issue: https://github.com/llvm/llvm-project/issues/141365
2025-08-20 10:33:08 +02:00
Andres-Salamanca
577ee97d4e
[CIR] Fix access to bitfields inside a union (#154398)
This PR fixes the access to bitfields inside a union.
Previously, we were using a `getMemberOp` to access the field, but
because it is a union, `getMemberOp` would always use index `0`.

For example, given:
```c
typedef union {
  int x;
  int y : 4;
  int z : 8;
} demo;
```
```mlir
!rec_demo = !cir.record<union "demo" {!s32i, !u8i, !u8i}>
```

In the case of:

```c
d.y = 2;
```

It would generate:

```mlir
cir.get_member %0[0] {name = "y"} : !cir.ptr<!rec_demo> -> !cir.ptr<!s32i>
```

with a return type of `!s32i`, when it should be `!u8i`.
the get_member verifier would detect that the return type does not match
the `y` member.
To fix this, we now use `bitcast` to get the start of the union.
2025-08-19 17:43:13 -05:00
Andy Kaylor
6747139bc2
[CIR] Use zero-initializer for partial array fills (#154161)
If an array initializer list leaves eight or more elements that require
zero fill, we had been generating an individual zero element for every
one of them. This change instead follows the behavior of classic
codegen, which creates a constant structure with the specified elements
followed by a zero-initializer for the trailing zeros.
2025-08-19 12:14:05 -07:00
Andy Kaylor
0f34360915
[CIR] Fix var_arg.c test (again) (#154393)
We had competing fixes for this that weren't compatible. This should
pass now.
2025-08-19 11:04:56 -07:00
Michael Liao
1d1b60c6d5 [CIR] Fix codegen test after b44e47a68f9b49a6283b1beaab3af55fa39e8907 2025-08-19 11:38:47 -04:00
Erich Keane
dab8c88f15
[OpenACC] Implement 'firstprivate' clause copy lowering (#154150)
This patch is the last of the 'firstprivate' clause lowering patches. It
takes the already generated 'copy' init from Sema and uses it to
generate the IR for the copy section of the recipe.

However, one thing that this patch had to do, was come up with a way to
hijack the decl registration in CIRGenFunction. Because these decls are
being created in a 'different' place, we need to remove the things we've
added. We could alternatively generate these 'differently', but it seems
worth a little extra effort here to avoid having to re-implement
variable initialization.
2025-08-19 06:02:10 -07:00
Amr Hesham
5581e34bd9
[CIR] Implement MemberExpr support for ComplexType (#154027)
This change adds support for the MemberExpr ComplexType

Issue: https://github.com/llvm/llvm-project/issues/141365
2025-08-19 10:32:22 +02:00
Morris Hafner
b5e5794534
[CIR] Implement Statement Expressions (#153677)
Depends on #153625

This patch adds support for statement expressions. It also changes
emitCompoundStmt and emitCompoundStmtWithoutScope to accept an Address
that the optional result is written to. This allows the creation of the
alloca ahead of the creation of the scope which saves us from hoisting
the alloca to its parent scope.
2025-08-19 10:11:15 +02:00
Morris Hafner
b44e47a68f
[CIR] Upstream __builtin_va_start and __builtin_va_end (#153819)
Part of #153286
2025-08-19 09:16:11 +02:00
Iris Shi
cc68e45343
[CIR] Implement codegen for inline assembly without input and output operands (#153546)
- Part of #153267


https://github.com/llvm/clangir/blob/main/clang/lib/CIR/CodeGen/CIRAsm.cpp
2025-08-18 18:54:24 -07:00
Andy Kaylor
7ac4d9bd53
[CIR] Add support for calling virtual functions (#153893)
This change adds support for calling virtual functions. This includes
adding the cir.vtable.get_virtual_fn_addr operation to lookup the
address of the function being called from an object's vtable.
2025-08-18 15:56:33 -07:00
Andres-Salamanca
916218ccbd
[CIR] Upstream GotoOp (#153701)
This PR upstreams `GotoOp`. It moves some tests from the `goto` test
file to the `label` test file, and adds verify logic to `FuncOp`. The
gotosSolver, required for lowering, will be implemented in a future PR.
2025-08-18 10:25:40 -05:00
erichkeane
0dbcdf33b8 [OpenACC] Fix racing commit test failures for firstprivate lowering
The original patch to implement basic lowering for firstprivate didn't
have the Sema work to change the name of the variable being generated
from openacc.private.init to openacc.firstprivate.init. I forgot about
that when I merged the Sema changes this morning, so the tests now
failed.  This patch fixes those up.

Additionally, Suggested on #153622 post-commit, it seems like a good idea to
use a size of APInt that matches the size-type, so this changes us to use that
instead.
2025-08-18 07:26:50 -07:00
Erich Keane
340fa3e1bb
[OpenACC] Implement firstprivate lowering except init. (#153847)
This patch implements the basic lowering infrastructure, but does not
quite implement the copy initialization, which requires #153622.

It does however pass verification for the 'copy' section, which just
contains a yield.
2025-08-18 06:33:40 -07:00
Morris Hafner
df0e9f3a2d
[CIR] Implement __builtin_return_address and __builtin_frame_address (#153698)
This adds ReturnAddrOp and FrameAddrOp that represent
__builtin_return_address and __builtin_frame_address and the respective
lowering to LLVM parts.

---------

Co-authored-by: Andy Kaylor <akaylor@nvidia.com>
2025-08-16 00:47:04 +02:00
Andy Kaylor
0cd35e7afd
[CIR] Add cir.vtable.get_vptr operation (#153630)
This adds support for the cir.vtable.get_vptr operation and uses it to
initialize the vptr member during constructors of dynamic classes.
2025-08-15 15:14:51 -07:00
Andy Kaylor
a1529cd85a
[CIR] Add index support for global_view (#153254)
The #cir.global_view attribute was initially added without support for
the optional index list. This change adds index list support. This is
used when the address of an array or structure member is used as an
initializer.

This patch does not include support for taking the address of a
structure or class member. That will be added later.
2025-08-14 15:14:12 -07:00
Iris Shi
dc0becc4d0
[CIR] Add InlineAsmOp lowering to LLVM (#153387)
- Part of #153267

Added support for lowering `InlineAsmOp` directly to LLVM IR

---------
Co-authored-by: Morris Hafner <mhafner@nvidia.com>
2025-08-14 17:48:14 +00:00
Iris Shi
9a28783f5d
[CIR] Add InlineAsmOp (#153362)
- Part of #153267

---------

Co-authored-by: Andy Kaylor <akaylor@nvidia.com>
Co-authored-by: Morris Hafner <mmha@users.noreply.github.com>
2025-08-14 17:34:38 +00:00
Andy Kaylor
45066c2937
[CIR] Add lowering for the cir.vtable.address_point operation (#153243)
This adds support for lowering the cir.vtable.address_point operation to
the LLVM dialect, as well as type converter support for the cir.vptr
type.
2025-08-14 10:07:54 -07:00
Andy Kaylor
f2d76b58f8
[CIR] Use a loop for array initialization (#153499)
This updates the array initialization loop to use a do..while loop
rather than a fully serialized initialization. It also allows the
initialization of destructed objects when exception handling is not
enabled.

Array initialization when exception handling is enabled remains
unimplemented, but more precise messages are now emitted.
2025-08-13 16:14:32 -07:00
Morris Hafner
0045bfca9c
[CIR} Add support for static member variable instantiation (#153200)
This patch handles both implicit and explicit template instantiations of
template class static member variables.
2025-08-13 18:03:05 +02:00
Amr Hesham
dc84f3aea8
[CIR] Upstream builtin FAbs op (#151750)
Upstreaming FAbsOp as a prerequisite for upstreaming ComplexDivOp
2025-08-13 17:57:06 +02:00
Andres-Salamanca
4b112d23a5
[CIR] Upstream LabelOp (#152802)
This PR introduces the `LabelOp`, which is required for implementing
`GotoOp` lowering in the future.
Lowering to LLVM IR is **not** included in this patch, since it depends
on the upcoming `GotoSolver`.

The `GotoSolver` traverses the function body, and if it finds a
`LabelOp` without a matching `GotoOp`, it erases the label.
This means our implementation differs from the classic codegen approach,
where labels may be retained even if unused.

Example:
https://godbolt.org/z/37Mvr4MMr
2025-08-13 09:52:00 -05:00
erichkeane
9a698a67e2 [OpenACC] Implement new OpenACC device_type restriction
The OpenACC standard is going to change to clarify that init, shutdown,
    and set should only have a single architecture in each 'device_type'
    clause.  This patch implements that restriction.

    See: https://github.com/OpenACC/openacc-spec/pull/550
2025-08-13 07:47:39 -07:00
Sirui Mu
331a5db9de
[CIR] Add initial support for atomic types (#152923) 2025-08-13 09:22:48 +08:00
Sirui Mu
7b8189aab8
[CIR] Add CIRGen for pseudo destructor calls (#153014) 2025-08-13 09:21:40 +08:00
Andy Kaylor
54f53c988d
[CIR] Introduce the CIR global_view attribute (#153044)
This change introduces the #cir.global_view attribute and adds support
for using that attribute to handle initializing a global variable with
the address of another global variable.

This does not yet include support for the optional list of indices to
get an offset from the base address. Those will be added in a follow-up
patch.
2025-08-12 10:02:00 -07:00
Andy Kaylor
7f195b36ee
[CIR] Initialize vptr in dynamic classes (#152574)
This adds support for initializing the vptr member of a dynamic class in
the constructor of that class.

This does not include support for lowering the
`cir.vtable.address_point` operation to the LLVM dialect. That handling
will be added in a follow-up patch.
2025-08-12 10:00:38 -07:00
Amr Hesham
475aa1b1a1
[CIR] CompoundAssignment from ComplexType to ScalarType (#152915)
This change adds support for the CompoundAssignment for ComplexType and
updates our approach for emitting bin op between Complex & Scalar

https://github.com/llvm/llvm-project/issues/141365
2025-08-12 18:01:31 +02:00
Sirui Mu
b2cdd80411
[CIR] Add support for __builtin_assume_aligned (#152152)
This patch upstreams CIRGen and LLVM lowering support for the
`__builtin_assume_aligned` builtin function.
2025-08-10 12:25:45 +08:00
Andy Kaylor
1e2e903684
[CIR] Add VTableAddrPointOp (#148730)
This change adds the definition of VTableAddrPointOp and the related
AddressPointAttr to the CIR dialect, along with tests for the parsing
and verification of these elements.

Code to generate this operation will be added in a later change.
2025-08-07 11:25:40 -07:00
Amr Hesham
093395ca6b
[CIR] Mul CompoundAssignment support for ComplexType (#152354)
This change adds support for Mul CompoundAssignment for ComplexType

https://github.com/llvm/llvm-project/issues/141365
2025-08-07 19:42:15 +02:00
gitoleg
d97f0e9364
[CIR] add support for file scope assembly (#152093)
This PR adds a support for file scope assembly in CIR.
2025-08-07 10:12:58 -07:00
Amr Hesham
4c9bb65639
[CIR] Plus & Minus CompoundAssignment support for ComplexType (#150759)
This change adds support for Plus & Minus CompoundAssignment for
ComplexType

https://github.com/llvm/llvm-project/issues/141365
2025-08-06 18:13:48 +02:00
Morris Hafner
4f166513df
[CIR] Upstream support for variable template specializations (#151069) 2025-08-06 16:43:42 +02:00
Sirui Mu
13600c72ce
[CIR] Add CIRGen for cir.unreachable and cir.trap (#151363) 2025-08-05 18:52:02 +08:00
Andres-Salamanca
9f7f3d6548
[CIR] Implemented get/set for volatile bitfields (#151875)
This PR adds support for loading and storing volatile bit-field members
according to the AAPCS specification.

> A volatile bit-field must always be accessed using an access width
appropriate to the type of its container, except when any of the
following are true:
>
> * The bit-field container overlaps with a zero-length bit-field.
> * The bit-field container overlaps with a non-bit-field member.

For example, if a bit-field is declared as `int`, the load/store must
use a 32-bit access, even if the field itself is only 3 bits wide.
2025-08-04 17:29:25 -05:00
Erich Keane
66eadbb235
[OpenACC][CIR] Implement 'init' lowering for private clause vars (#151781)
Previously, #151360 implemented 'private' clause lowering, but didn't
properly initialize the variables. This patch adds that behavior to make
sure we correctly get the constructor or other init called.
2025-08-04 11:14:58 -07:00
Andres-Salamanca
7e9927127f
[CIR] Fix outdated bitfield iteration logic in accumulateFields (#151741)
This PR fixes the outdated logic for accumulating bitfields in
`accumulateFields`. The old approach remained after the algorithm was
updated. A non-bitfield member would act as a barrier, causing
`accumulateBitFields` to receive an incomplete range of fields. As a
result, it failed to accumulate them properly when clipping was
necessary.

For reference, in ClangIR we already handle this correctly:

[b647f4b97b/clang/lib/CIR/CodeGen/CIRRecordLayoutBuilder.cpp (L711-L714))
2025-08-02 09:39:51 -05:00
Andy Kaylor
c188e1db6a
[CIR] Add vptr type and generate vptr field when needed (#151377)
This adds a new CIR type, cir.vptr, and generates a field of that type
when a record is declared that requires a vptr member.
2025-08-01 12:10:04 -07:00
Andy Kaylor
a304e09fe7
[CIR] Handle expression with cleanups (#151600)
This adds code to handle expressions with cleanup, including
materializing a temporary object for the expression.
2025-08-01 11:38:35 -07:00
Erich Keane
25c07763f7
[OpenACC][CIR] Implement 'private' clause lowering. (#151360)
The private clause is the first with 'recipes', so a lot of
infrastructure is included here, including some MLIR dialect changes
that allow simple adding of a privatization. We'll likely get similar
for firstprivate and reduction.

Also, we have quite a bit of infrastructure in clause lowering to make
sure we have most cases we could think of covered.

At the moment, ONLY private is implemented, so all it requires is an
'init' segment (that doesn't call any copy operations), and potentially
a 'destroy' segment. However, actually calling 'init' functions on each
of the elements in them are not properly implemented, and will be in a
followup patch.

This patch implements all of that, and adds tests in a way that will be
useful for firstprivate as well.
2025-08-01 09:27:15 -07:00
Amr Hesham
03e54a148f
[CIR] Upstream MulOp for ComplexType (#150834)
This change adds support for mul op for ComplexType

https://github.com/llvm/llvm-project/issues/141365
2025-07-31 19:16:42 +02:00
Morris Hafner
8a5d363123
[CIR] Upstream support for function-level variable decompositions (#151073)
This implements support for structured bindings on a function scope
level. It does not add support for global structured bindings.
2025-07-31 17:34:41 +02:00