84 Commits

Author SHA1 Message Date
Andy Kaylor
c5466c64d4
[CIR] Add CIR vtable attribute (#154415)
This adds the #cir.vtable attribute definition and verification.
Generation of the vtable will be implemented in a later change.
2025-08-21 09:52:14 -07: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
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
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
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
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
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
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
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
32779cd698
[CIR] Add proper handling for no prototype function calls (#150553)
This adds standard-comforming handling for calls to functions that were
declared in C source in the no prototype form.
2025-07-29 09:16:17 -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
Sirui Mu
2b3ca68401
[CIR] Add folders for bit manipulation operations (#150235)
This patch adds folders for the bit manipulation operations, namely:
`clrsb`, `clz`, `ctz`, `parity`, `popcount`, `bitreverse`, `byte_swap`,
and `rotate`.
2025-07-26 00:07:36 +08:00
Amr Hesham
eb817c7950
[CIR] Upstream Cast kinds for ComplexType (#149717)
This change adds support for cast kinds for ComplexType

https://github.com/llvm/llvm-project/issues/141365
2025-07-23 19:22:39 +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
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
Amr Hesham
53183be294
[CIR] Fold ComplexRealOp from ComplexCreateOp (#147592)
Folding ComplexRealOp if the operand is ComplexCreateOp, inspired by
MLIR Complex dialect

https://github.com/llvm/llvm-project/issues/141365
2025-07-11 19:27:54 +02:00
Amr Hesham
df10df8b0c
[CIR] Fold ComplexImagOp from ComplexCreateOp (#148010)
Folding ComplexImagOp if the operand is ComplexCreateOp, inspired by
MLIR Complex dialect

https://github.com/llvm/llvm-project/issues/141365
2025-07-11 19:18:08 +02: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
Andy Kaylor
3e9fd4966d
[CIR] Add support for constructor aliases (#145792)
This change adds support for handling the -mconstructor-aliases option
in CIR. Aliases are not yet correctly lowered to LLVM IR. That will be
implemented in a future change.
2025-06-27 09:43:05 -07: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
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
Henrich Lauko
97e8266172
[CIR] Remove redundant operation trait and use AllTypesMatch instead (#144950)
This mirrors incubator changes from https://github.com/llvm/clangir/pull/1679
2025-06-23 20:42:00 +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
Amr Hesham
267b859fc6
[CIR] Implement folder for VecCmpOp (#143322)
This change adds a folder for the VecCmpOp

Issue https://github.com/llvm/llvm-project/issues/136487
2025-06-16 19:35:34 +02: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
f62a8ab930
[CIR] Extend VecShuffleOp verifier to catch invalid index (#143262)
Extend the verifier to catch index larger than the size of vector
elements in VecShuffleOp

Issue https://github.com/llvm/llvm-project/issues/136487
2025-06-13 22:51:33 +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
Amr Hesham
84710b49f2
[CIR] Implement folder for VecShuffleOp (#143260)
This change adds a folder for the VecShuffleOp

Issue https://github.com/llvm/llvm-project/issues/136487
2025-06-10 19:33:06 +02:00
Amr Hesham
995d74f866
[CIR] Implement folder for VecTernaryOp (#142946)
This change adds a folder for the VecTernaryOp

Issue https://github.com/llvm/llvm-project/issues/136487
2025-06-07 13:58:54 +02:00
Amr Hesham
bf51d583e4
[CIR] Upstream ShuffleOp for VectorType (#142288)
This change adds support for the Shuffle op for VectorType

Issue https://github.com/llvm/llvm-project/issues/136487
2025-06-07 13:56:36 +02:00
Henrich Lauko
f10c7d9f5a
[CIR][NFC] Use getType() instead of more verbose getResult().getType() (#143024)
This mirrors incubator changes from https://github.com/llvm/clangir/pull/1662
2025-06-06 09:58:13 +02:00
Amr Hesham
36dd1993a8
[CIR] Upstream global initialization for ComplexType (#141369)
This change adds support for zero and global init for ComplexType

#141365
2025-06-05 22:06:43 +02:00
Amr Hesham
aa71344acd
[CIR] Implement folder for VecShuffleDynamicOp (#142315)
This change adds a folder for the VecShuffleDynamicOp

Issue https://github.com/llvm/llvm-project/issues/136487
2025-06-05 10:41:19 +02:00
Amr Hesham
5e21f2b696
[CIR] Upstream TernaryOp for VectorType (#142393)
This change adds support for the Ternary op for VectorType

Issue https://github.com/llvm/llvm-project/issues/136487
2025-06-05 10:36:31 +02:00
Sirui Mu
628a3f0a48
[CIR] Call to variadic functions (#141942) 2025-05-31 09:59:41 +08:00
Amr Hesham
459de736a0
[CIR] Upstream converting vector types (#142012)
This change adds support for ConvertVectorExpr to convert between vector
types with the same size

Issue https://github.com/llvm/llvm-project/issues/136487
2025-05-30 23:14:11 +02:00
Andy Kaylor
0e90a846d6
[CIR] Add support for global linkage and visibility (#141973)
This change adds support for the CIRGlobalValueInterface and attributes
for visibility and comdat to GlobalOp.

The comdat attribute isn't correctly calculated yet, but it was required
for the CIRGlobalValueInterface interface. There are also some cases
where dso_local isn't set correctly, but it is better than it was before
this change. Those issues will be addressed in a future patch.
2025-05-30 13:36:48 -07:00
Amr Hesham
4dcfcd3a66
[CIR] Upstream ShuffleDynamicOp for VectorType (#141411)
This change adds support for the Dynamic Shuffle op for VectorType

Issue https://github.com/llvm/llvm-project/issues/136487
2025-05-30 20:13:23 +02:00
Amr Hesham
6e5f9bb693
[CIR] Allow use different Int types together in Vec Shift Op (#141111)
Update the verification of ShiftOp for Vector to allow performing shift
op between signed and unsigned integers, similar to LLVM IR

Issue https://github.com/llvm/llvm-project/issues/136487
2025-05-28 20:16:20 +02:00
Sirui Mu
838ddc28f2
[CIR] Add support for indirect calls (#139748)
This PR adds support for indirect calls to the `cir.call` operation.
2025-05-20 18:11:19 +08:00
Andres-Salamanca
114e4508b2
[CIR] Remove the empty verifier in cir.ifOp (#140457)
The empty verifier is redundant because cir::IfOp has no constraints to
enforce its verify() always succeeds.
2025-05-19 13:52:21 -07:00
Andres-Salamanca
ec44c74fe7
[CIR] Upstream support for FlattenCFG switch and SwitchFlatOp (#139154)
This PR adds support for the `FlattenCFG` transformation on `switch`
statements. It also introduces the `SwitchFlatOp`, which is necessary
for subsequent lowering to LLVM.
2025-05-16 09:38:56 -07:00
Amr Hesham
377cb7fb26
[CIR] Upstream shift operators for VectorType (#139465)
This change adds support for shift ops for VectorType

Issue https://github.com/llvm/llvm-project/issues/136487
2025-05-13 20:17:51 +02:00
Amr Hesham
d9380ec637
[CIR] Implement folder for VecExtractOp (#139304)
This change adds a folder for the VecExtractOp

Issue https://github.com/llvm/llvm-project/issues/136487
2025-05-13 11:01:48 -07:00
Morris Hafner
2eb6545b3e
[CIR] Add cir-simplify pass (#138317)
This patch adds the cir-simplify pass for SelectOp and TernaryOp. It
also adds the SelectOp folder and adds the constant materializer for the
CIR dialect.
2025-05-07 18:50:39 +02:00