117 Commits

Author SHA1 Message Date
Andy Kaylor
59b33242af
[CIR][NFC] Fix warning in MemOrder lowering (#154609)
This fixes a warning about having a default case in a fully covered enum
switch statement.
2025-08-20 14:30:22 -07:00
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
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
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
Morris Hafner
b44e47a68f
[CIR] Upstream __builtin_va_start and __builtin_va_end (#153819)
Part of #153286
2025-08-19 09:16:11 +02: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
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
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
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
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
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
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
Sirui Mu
13600c72ce
[CIR] Add CIRGen for cir.unreachable and cir.trap (#151363) 2025-08-05 18:52:02 +08:00
Henrich Lauko
44500ae265
[CIR] Use getDefiningOp<OpTy>() instead of dyn_cast<OpTy>(getDefiningOp()) (NFC) (#151217)
This applies similar changes to llvm/llvm-project#150428
2025-08-02 09:21:05 +02:00
Henrich Lauko
4820b183a8
[CIR] Simplify ConstantOp accesses and its getDefiningOp (#151216)
- Replaces  dyn_cast<cir::ConstantOp>(v.getDefiningOp()) and similar with v.getDefiningOp<cir::ConstantOp>()
- Adds `getValueAttr` method to ConstantOp
2025-08-01 21:04:54 +02:00
Andy Kaylor
8a1b252a99
[CIR] Upstream proper function alias lowering (#150520)
This change implements correct lowering of function aliases to the LLVM
dialect.
2025-07-29 09:45:37 -07:00
Sirui Mu
1249ab9a03
[CIR] Add bit ffs operation (#150997)
This patch adds the `cir.ffs` operation which corresponds to the
`__builtin_ffs` family of builtin functions.

This operation was not included in the previous PRs because the call to
`__builtin_ffs` would be transformed into a library call to `ffs`. At
the time of authoring this patch, this behavior has been changed and now
we can properly lower calls to `__builtin_ffs` to `cir.ffs`.
2025-07-29 20:45:13 +08:00
Sirui Mu
e2b4ba0414
[CIR] Add poison attribute (#150760)
This patch adds the `#cir.poison` attribute which represents a poison
value. This patch also updates various operation folders to let them
propagate poison values from their inputs to their outputs.
2025-07-27 19:30:37 +08:00
Morris Hafner
3e9d369c5c
[CIR] Add support for array constructors (#149142)
This patch upstreams support for creating arrays of classes that require
calling a constructor.

* Adds the ArrayCtor operation
* New lowering pass for lowering ArrayCtor to a loop

---------

Co-authored-by: Andy Kaylor <akaylor@nvidia.com>
Co-authored-by: Henrich Lauko <xlauko@mail.muni.cz>
2025-07-24 17:15:34 +02:00
Sirui Mu
3371b9111f
[CIR] Add assume_separate_storage operation (#149696)
This patch adds the `cir.assume_separate_storage` operation for the
`__builtin_assume_separate_storage` builtin function.
2025-07-21 22:21:44 +08:00
Andres-Salamanca
b02787d33f
[CIR] Fix alignment when lowering set/get bitfield operations (#148999)
This PR fixes incorrect alignment when lowering `set` and `getBitField`
operations to LLVM IR. The issue occurred because during lowering, the
function was being called with an alignment of 0, which caused it to
default to the alignment of the packed member. For example, if the
bitfield was packed inside a `u64i`, it would use an alignment of 8.
With this change, the generated code now matches what the classic
codegen produces.
In the assembly format, I changed to be similar to how it's done in
loadOp. If there's a better approach, please feel free to point it out.
2025-07-18 16:13:34 -05:00
Sirui Mu
8519143a9f
[CIR] Add rotate operation (#148426)
This patch adds `cir.rotate` operation for the `__builtin_rotateleft`
and `__builtin_rotateright` families of builtin calls.
2025-07-17 00:41:28 +08:00
Amr Hesham
af99f18d91
[CIR] Upstream the basic structure of LoweringPrepare pass (#148545)
Upstream, the basic structure of the LoweringPrepare pass as a
prerequisite for other ComplexType PR's

https://github.com/llvm/llvm-project/issues/141365
2025-07-15 12:33:24 +02:00
Amr Hesham
22b221d4b7
[CIR] Upstream ComplexImagPtrOp for ComplexType (#144236)
This change adds support for ComplexImagPtrOp for ComplexType

https://github.com/llvm/llvm-project/issues/141365
2025-07-14 19:53:06 +02:00
Amr Hesham
647f02a02a
[CIR] Implement SubOp for ComplexType (#148025)
This change adds support for SubOp for ComplexType

https://github.com/llvm/llvm-project/issues/141365
2025-07-12 17:22:57 +02:00
Sirui Mu
265fb3605d
[CIR] Add bit reverse and byte reverse operations (#147200)
This patch adds support for the following two builtin functions:

- `__builtin_bswap`, represented by the `cir.byte_swap` operation.
- `__builtin_bitreverse`, represented by the `cir.bit.reverse`
operation.
2025-07-12 12:15:36 +08:00
Amr Hesham
ed8548796f
[CIR] Upstream ComplexRealPtrOp for ComplexType (#144235)
This change adds support for ComplexRealPtrOp for ComplexType

https://github.com/llvm/llvm-project/issues/141365
2025-07-11 21:06:05 +02:00
Andres-Salamanca
3d08a40959
[CIR] Upstream new SetBitfieldOp for handling C and C++ struct bitfields (#147609)
This PR upstreams the `set_bitfield` operation used to assign values to
bitfield members in C and C++ struct types.
Handling of AAPCS-specific volatile bitfield semantics will be addressed
in a future PR.
2025-07-10 15:16:29 -05:00
Amr Hesham
dd1105bcea
[CIR] Implement AddOp for ComplexType (#147578)
This change adds support for AddOp for ComplexType

https://github.com/llvm/llvm-project/issues/141365
2025-07-10 19:40:17 +02:00
Amr Hesham
bbefd33ae6
[CIR] Implement CXXScalarValueInitExpr for ComplexType (#147143)
Implement CXXScalarValueInitExpr support for ComplexType

https://github.com/llvm/llvm-project/issues/141365
2025-07-08 17:36:40 +02:00
Sirui Mu
4b9f622ca9
[CIR] Bit manipulation builtin functions (#146529)
This patch adds CIR support for the following families of bit
manipulation builtin functions:

- `__builtin_clrsb`, represented by the `cir.bit.clrsb` operation
- `__builtin_ctz`, represented by the `cir.bit.clz` operation
- `__builtin_clz`, represented by the `cir.bit.ctz` operation
- `__builtin_parity`, represented by the `cir.bit.parity` operation
- `__builtin_popcount`, represented by the `cir.bit.popcnt` operation

The `__builtin_ffs` builtin function is not included in this patch
because the current CIRGen would emit it as a library call to `@ffs`.
2025-07-03 23:08:49 +08:00
Sirui Mu
23104a74e7
[CIR] Add nothrow attribute to the call operation (#145178)
This patch adds extra function attributes to the `cir.call` operation.
The extra attributes now may contain a single `cir.nothrow` attribute
that indicates whether the callee throws.
2025-07-03 22:54:15 +08:00
Andres-Salamanca
717899ce86
[CIR] Upstream get_bitfield operation to load bit-field members from structs (#145971)
This PR adds support for loading bit-field members from structs using
the `get_bitfield` operation.
It enables retrieving the address of the bitfield-packed member but does
**not** yet support volatile bitfields this will be addressed in a
future PR.
2025-07-02 18:05:19 -05:00
Amr Hesham
e9be5286e1
[CIR] Implement NotEqualOp for ComplexType (#146129)
This change adds support for the not equal operation for ComplexType

https://github.com/llvm/llvm-project/issues/141365
2025-07-02 19:25:25 +02:00
Henrich Lauko
61c0a94a90
[CIR] Refactor type interfaces (#146044)
- Generalizes CIRFPTypeInterface files to CIRTypeInterfaces for future type interfaces additions.
- Renames CIRFPTypeInterface to FPTypeInterface.
- Fixes FPTypeInterface tablegen prefix.

This mirrors incubator changes from https://github.com/llvm/clangir/pull/1713
2025-06-27 16:47:58 +02:00
Amr Hesham
9d91b07e1e
[CIR] Implement EqualOp for ComplexType (#145769)
This change adds support for equal operation for ComplexType


https://github.com/llvm/llvm-project/issues/141365
2025-06-26 18:06:22 +02:00
Andy Kaylor
1e45ea12db
[CIR] Add support for function linkage and visibility (#145600)
This change adds support for function linkage and visibility and related
attributes. Most of the test changes are generalizations to allow
'dso_local' to be accepted where we aren't specifically testing for it.
Some tests based on CIR inputs have been updated to add 'private' to
function declarations where required by newly supported interfaces.

The dso-local.c test has been updated to add specific tests for
dso_local being set correctly, and a new test, func-linkage.cpp tests
other linkage settings.

This change sets `comdat` correctly in CIR, but it is not yet applied to
functions when lowering to LLVM IR. That will be handled in a later
change.
2025-06-25 10:59:30 -07:00
Amr Hesham
e4da49f018
[CIR] Upstream __imag__ for ComplexType (#144262)
This change adds support for `__imag__` for ComplexType

https://github.com/llvm/llvm-project/issues/141365
2025-06-25 19:39:34 +02:00
Amr Hesham
9a7720ad2f
[CIR] Upstream __real__ for ComplexType (#144261)
This change adds support for __real__ for ComplexType

https://github.com/llvm/llvm-project/issues/141365
2025-06-25 18:06:57 +02:00
Andy Kaylor
90828e00a0
[CIR] Restore the underscore in dso_local (#145551)
The CIR handling of `dso_local` for globals was upstreamed without the
underscore, making it inconsistent with the incubator and LLVM IR. This
change restores the underscore.
2025-06-24 10:44:15 -07:00
Sirui Mu
9291ad1c96
[CIR] Add support for __builtin_expect (#144726)
This patch adds support for the `__builtin_expect` and
`__builtin_expect_with_probability` builtin functions.
2025-06-24 10:17:12 -07:00
Amr Hesham
9ee55e7173
[CIR] Implement folder for VecSplatOp (#143771)
This change adds a folder for the VecSplatOp

Issue https://github.com/llvm/llvm-project/issues/136487
2025-06-19 09:01:51 +02:00
Sirui Mu
2bcdfa198a
[CIR] Add side effect attribute to call operations (#144201)
This patch adds `side_effect` attribute to `cir.call` operation.

Other function call attributes will be added in later patches.
2025-06-19 09:58:19 +08:00
Sirui Mu
8e157fdbb7
[CIR] Add support for __builtin_assume (#144376)
This patch adds support for the `__builtin_assume` builtin function.
2025-06-18 17:10:29 +08:00
Amr Hesham
6464066787
[CIR] Upstream CreateOp for ComplexType with folder (#143192)
This change adds support for the create op for ComplexType with folder
and support for empty init list

https://github.com/llvm/llvm-project/issues/141365
2025-06-14 13:26:03 +02:00
Amr Hesham
cd8facebab
[CIR] Implement folder for VecCreateOp (#143355)
This change adds a folder for the VecCreateOp

Issue https://github.com/llvm/llvm-project/issues/136487
2025-06-12 18:36:03 +02:00