73 Commits

Author SHA1 Message Date
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
Morris Hafner
e56ae9651b
[CIR][NFC] Add Symbol Table to CIRGenFunction (#153625)
This patchs adds a symbol table to CIRGenFunction plus scopes and
insertions to the table where we were missing them previously.
2025-08-14 22:53:09 +02: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
Amr Hesham
dde474cfc4
[CIR] Make ClangIR compatible with latest nested name specifier AST representation (#152846)
After AST representation, new modifications landed in
(https://github.com/llvm/llvm-project/pull/147835). ClangIR requires
some changes in how we use Clang AST to be compatible with the new
changes
2025-08-11 20:08:37 +02:00
Michael Liao
c9b6242771 [CIR] Fix build after the improved nested name specifier AST repr (91cdd35008e9) 2025-08-09 16:38:49 -04: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
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
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
Andy Kaylor
ba2edbd0c8
[CIR] Fix warnings related to unused variables in release builds (#151412)
This fixes a number of warnings in release builds due to variables that
were only being used in asserts. Some of these variables will later be
used in non-debug code, but for now they are unused in release builds.
2025-07-31 14:54:56 -07: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
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
Amr Hesham
2762a079ee
[CIR] Implement LValueBitcast for ComplexType (#150668)
This change adds support for LValueBitcast for ComplexType

https://github.com/llvm/llvm-project/issues/141365
2025-07-28 20:29:38 +02: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
Amr Hesham
0aff1b6cdd
[CIR][NFC] Replace bool by cir::UnaryOpKind in emitComplexPrePostIncDec (#149566)
Replace bool by cir::UnaryOpKind in emitComplexPrePostIncDec
2025-07-19 15:19:42 +02:00
Amr Hesham
65bde89c9a
[CIR] Upstream CompoundLiteralExpr for Scalar (#148943)
Upstream CompoundLiteralExpr for Scalar as a prerequisite for
CompoundLiteralExpr for ComplexType
2025-07-19 15:13:36 +02: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
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
Andy Kaylor
13c897093f
[CIR] Add support for non-virtual base class initialization (#148080)
This change adds support for initializing non-virtual base classes
during the prologue of a derived class' constructor.
2025-07-11 09:57:15 -07: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
ddfc13c191
[CIR] Upstream __builtin_creal for ComplexType (#146927)
Upstream `__builtin_creal` support for ComplexType

https://github.com/llvm/llvm-project/issues/141365
2025-07-09 18:28:00 +02: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
418b409df8
[CIR] Add support for member initialization from constructors (#144583)
Upstream the code to handle member variable initialization in a
constructor. At this point only simple scalar values (including members
of anonymous unions) are handled.
2025-06-24 10:05:48 -07:00
Amr Hesham
4a4582dd78
[CIR] Upstream BinAssign for ComplexType (#144868)
This change adds support for the BinAssign op and LValueToRValue for
ComplexType

https://github.com/llvm/llvm-project/issues/141365
2025-06-21 10:30:59 +02:00
Morris Hafner
ed07b54b38
[CIR][NFCI] Represent Complex RValues As Single Value (#144519)
This patch removes one mlir::Value in the RValue class that has been
used to represent complex values in classic CG. In CIR we plan on
representing complex as a single value. It also removes some now
unnecessary member functions related to complex handling.
2025-06-17 18:35:49 +01: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
Andy Kaylor
36c710c40e
[CIR] Change default assumption about allowing builtins (#144004)
The code to read the "nobuiltins" attributes hasn't been implemented
yet, but we were defaulting to the assumption that use of builtins is
allowed for function calls that we recognize as standard C library calls
and have builtin equivalents of. This change reverses that assumption so
that when such calls are encountered, we just emit the call. This is a
better default assumption, and since our builtin handling for these
functions isn't implemented yet, it also allows us to compile more
programs.
2025-06-13 09:42:58 -07:00
Sirui Mu
8ba62fdb3d
[CIR] Function calls with aggregate arguments and return values (#143377)
This patch updates cir.call operation and allows function calls with
aggregate arguments and return values.

It seems that C++ class support is still at a minimum now. I tried to
make a call to a C++ function with an argument of aggregate type but it
failed because the initialization of C++ class / struct is NYI. I also
tried to inline this part of support into this patch, but the mixed
patch quickly blows in size and becomes unsuitable for review. Thus,
tests for calling functions with aggregate arguments are added only for
C for now.
2025-06-13 16:47:56 +08:00
Andy Kaylor
4a4035c86b
[CIR] Add support for delegating constructors (#143932)
This change adds the necessary support for handling delegating
constructors in ClangIR. The implementation is kept as small as possible
by not handling any other sort of initialization (members, base classes,
etc.). That will be added in a future commit.
2025-06-12 14:52:07 -07:00
Morris Hafner
8e4f0d8614
[CIR] Upstream minimal builtin function call support (#142981)
This patch adds all bits required to implement builtin function calls to
ClangIR. It doesn't actually implement any of the builtins except those
that fold to a constant ahead of CodeGen
(`__builtin_is_constant_evaluated()` being one example).
2025-06-11 18:24:46 +02:00
Andy Kaylor
b9329fe88e
[CIR] Upstream support for calling constructors (#143579)
This change adds support for calling C++ constructors. The support for
actually defining a constructor is still missing and will be added in a
later change.
2025-06-10 16:50:29 -07:00
Andy Kaylor
6559831025
[CIR] Add support for accessing members of base classes (#143195)
This change adds the support for accessing a member of a base class from
a derived class object.
2025-06-09 13:11:12 -07:00
Andy Kaylor
4ed0ff8756
[CIR] Add support for using enum constants (#143214)
Although support for declaring enums and using values whose type was an
enum was previously upstreamed, we didn't have support for referencing
the constant values declared in the enum. This change adds that support.
2025-06-09 09:19:31 -07:00
Morris Hafner
4b2cb118bc
[CIR] Upstream lowering of conditional operators to TernaryOp (#138156)
This patch adds visitors for BinLAnd, BinLOr and
AbstractConditionalOperator. Note that this patch still lacks visitation
of OpaqueValueExpr which is needed for the GNU ?: operator.

---------

Co-authored-by: Erich Keane <ekeane@nvidia.com>
2025-06-03 13:29:23 +02:00
Andy Kaylor
ea3c225786
[CIR] Add alignment support for global, store, and load ops (#141163)
This adds alignment support for GlobalOp, LoadOp, and StoreOp.

Tests which failed because cir.store/cir.load now print alignment were
updated with wildcard matches, except where the alignment was relevant
to the test. Tests which check for cir.store/cir.load in cases that
don't have explicit alignment were not updated.

New tests for alignment are alignment.c, align-load.c, and
align-store.c.
2025-05-23 15:34:59 -07:00
Andy Kaylor
3ce74c3b40
[CIR] Upstream support for string literals (#140796)
This adds the minimal support needed to handle string literals.
2025-05-21 11:32:50 -07:00
Andy Kaylor
cbcfe667bb
[CIR] Upstream support for iterator-based range for loops (#140636)
This change adds handling for C++ member operator calls, implicit no-op
casts, and l-value call expressions. Together, these changes enable
handling of range for loops based on iterators.
2025-05-20 10:52:15 -07: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
Andy Kaylor
a0c515a9ef
[CIR] Upstream support for C++ member function calls (#140290)
This change adds the support needed to handle a C++ member function
call, including arranging the function type with an argument added for
the 'this' parameter. It was necessary to introduce the class to handle
the CXXABI, but at this time no target-specific subclasses have been
added.
2025-05-19 14:42:50 -07:00
Amr Hesham
a6c4ca8e93
[CIR] Upstream insert op for VectorType (#139146)
This change adds an insert op for VectorType

Issue https://github.com/llvm/llvm-project/issues/136487
2025-05-12 20:22:02 +02:00
Henrich Lauko
68ee36a144
[CIR] Remove inferred context from pointer type getters (#138858)
This mirror incubator changes from https://github.com/llvm/clangir/pull/1600
2025-05-07 19:21:01 +02:00
Andy Kaylor
8d9f5160b4
[CIR] Unblock simple C++ structure support (#138368)
This change adds additional checks to a few places where a simple struct
in C++ code was triggering `errorNYI` in places where no additional
handling was needed, and adds a very small amount of trivial
initialization. The code now checks for the conditions that do require
extra handling before issuing the diagnostic.

New tests are added for declaring and using a simple struct in C++ code.
2025-05-07 09:21:01 -07:00
Amr Hesham
4fcbdb2c89
[CIR] Upstream local initialization for VectorType (#138107)
This change adds local initialization for VectorType

Issue https://github.com/llvm/llvm-project/issues/136487
2025-05-02 22:12:03 +02:00
Sirui Mu
44c4b4cef9
[CIR] Upstream cir.call with scalar arguments (#136810)
This PR upstreams support for scalar arguments in `cir.call` operation.

Related to #132487 .
2025-05-02 10:04:48 +08:00
Andy Kaylor
a76936f1c0
[CIR] Upstream support for range-based for loops (#138176)
This upstreams the code needed to handle CXXForRangeStmt.
2025-05-01 14:47:20 -07:00