16 Commits

Author SHA1 Message Date
Henrich Lauko
3bc216c29c
[CIR] Split CIR_UnaryOp into individual operations (#185280)
Split the monolithic cir.unary operation (which dispatched on a
UnaryOpKind enum) into four separate operations: cir.inc, cir.dec,
cir.minus, and cir.not.

Changes:
- Add CIR_UnaryOpInterface with getInput()/getResult() methods
- Add CIR_UnaryOp and CIR_UnaryOpWithOverflowFlag base classes
- Define IncOp, DecOp, MinusOp, NotOp with per-op folds
- Add Involution trait to NotOp for not(not(x)) -> x folding
- Replace createUnaryOp() with createInc/Dec/Minus/Not builders
- Split LLVM lowering into four separate patterns
- Split LoweringPrepare complex-type handling per unary op
- Update CIRCanonicalize and CIRSimplify for new op types
- Update all codegen files to use bool params instead of UnaryOpKind
- Remove CIR_UnaryOpKind enum and old CIR_UnaryOp definition

Assembly format change:
  cir.unary(inc, %x) nsw : !s32i, !s32i  ->  cir.inc nsw %x : !s32i
  cir.unary(not, %x) : !u32i, !u32i      ->  cir.not %x : !u32i
2026-03-14 23:50:43 +01:00
Henrich Lauko
89a4bcf023
[CIR] Split cir.binop into separate per-operation binary ops (#184227)
Replace the single `cir.binop` operation (dispatched via a `BinOpKind`
enum) with nine distinct ops — `cir.add`, `cir.sub`, `cir.mul`,
`cir.div`, `cir.rem`, `cir.and`, `cir.or`, `cir.xor`, and `cir.max` —
each with precise type constraints and only the attributes it needs
(nsw/nuw/sat on add/sub via `BinaryOverflowOp`).

A new `BinaryOpInterface` provides uniform `getLhs`/`getRhs`/`getResult`
access for passes and analyses.

The monolithic switch-based CIRToLLVMBinOpLowering is replaced by per-op
patterns generated through the existing CIRLowering.inc TableGen
infrastructure, with shared dispatch factored into two helpers:
`lowerSaturatableArithOp` for add/sub and `lowerIntFPBinaryOp` for
div/rem.
2026-03-03 22:34:18 +01:00
Andres-Salamanca
217f0e54c9
[CIR][NFC] Update TypeCache file to use MLIR-style camel case (#165060)
This PR updates the file `CIRGenTypeCache` to use MLIR-style camel case
naming.The change was inspired by the discussion here:
https://github.com/llvm/llvm-project/pull/164180#discussion_r2461444730
2025-10-28 19:26:33 -05:00
Erich Keane
ac0bc20c94
[OpenACC][CIR] Reduction combiner lowering for min/max (#163656)
These two are lowered as if they are the expression: LHS = (LHS < RHS )
? RHS : LHS;
and
LHS = (LHS < RHS ) ? LHS : RHS;

This patch generates these expressions and ensures they are properly
emitted into IR.

Note: this is dependent on
https://github.com/llvm/llvm-project/pull/163580
and cannot be merged until that one is (or the tests will fail).
2025-10-20 18:02:06 +00:00
erichkeane
b936f2ceeb [OpenACC] Call 'cleanup' on lexical scopes before yield
When creating a 'yield', we have to make sure that the lexical scope we
created gets cleaned up.  This isn't really testable until a followup
patch, but I got this wrong in quite a few places.
2025-10-15 13:59:25 -07:00
Erich Keane
b604562cfa
[OpenACC][CIR] Implement 'reduction' combiner lowering for 5 ops (#162906)
Following on the Sema changes, this does the lowering for all of the
operators that can be done as a compound operator. Lowering is very
simply looping through the objects based on array/compound/etc, and
doing a call to the operation.
2025-10-14 07:14:33 -07:00
Erich Keane
542cba8930
[OpenACC][CIR] Handle firstprivate bounds recipe lowering (#161873)
These work the same as the other two (private and reduction) except that
the expression for the 'init' is a copy instead of a default/value init,
and in a separate region. This patch gets all of that correct, and
ensures we generate these as expected.

There is a little extra work to make sure that the bounds-loop
generation does 2 separate array index operations, otherwise this is
very much like the reduction implementation.
2025-10-06 06:46:21 -07:00
Erich Keane
4845b3e3eb
[OpenACC][CIR] Impl reduction recipe pointer/array bound lowering (#161726)
Just like with private, the lowering for these bounds are all pretty
trivial. This patch enables them for reduction, which has everything in
common except the init pattern, but that is handled/managed by Sema.

This also adds sufficient testing to spot-check the
allocation/initialization/destruction/etc.
2025-10-03 05:46:28 -07:00
Erich Keane
819f34a6e0
[NFC][OpenACC] Remove 'initExpr' from AST/etc. (#161674)
I originally expected that we were going to need the initExpr stored
separately from the allocaDecl when doing arrays/pointers, however after
implementing it, we found that the idea of having the allocaDecl just
store its init directly still works perfectly. This patch removes the
extra field from the AST.
2025-10-02 12:09:15 -07:00
Erich Keane
e394df39c6
[NFC] Rename members in AutoVarEmission (#161668)
It was brought up by Andy in a different review that AutoVarEmission's
member variables didn't follow our naming standard. This patch corrects
that and fixes all references.
2025-10-02 09:56:34 -07:00
Erich Keane
119cdf7e1b
[OpenACC][CIR] Finish 'private' recipe lowering by doing 'init' (#161540)
Private only does 'init' when a constructor needs to be called, so this
patch adds that. The logic of what to init is caused by Sema, but the
tests show that types that are pointers or non-class-types or class
types without a constructor aren't actually initialized.
2025-10-02 06:10:08 -07:00
Erich Keane
13ce5f249e
[OpenACC] Remove unnecessary uses of getResult, fix cast tests (#161526)
A previous review comment pointed out that operations with only a single
result implicitly convert to `mlir::Value`. This patch removes the
explicit use of `getResult` where it is unnecessary in OpenACC lowering.

However, there ARE a few cases where it is necessary where the
`mlir::ValueRange` implicit constructor from a single value is being
used, so those are untouched.

Additionally, while the previous patch was being committed (#161382), a
second patch (#161431) changed the format of cir.casts, so this patch
fixes the additional test lines for that as well.
2025-10-01 14:42:37 +00:00
Erich Keane
a33544b83c
[OpenACC][CIR] Implement 'alloca copying' for private lowering (#161382)
The previous patch ensured that we correctly got the allocas put in
place. This patch takes the address of each element of each alloca, and
copies it to the previous one. This allows us to re-form the
pointer-structure for a recipe.
2025-10-01 06:16:39 -07:00
Henrich Lauko
fe9fba8d24
[OpenACC][CIR] Fix transform inclusive scan init parameter (#161428)
This fixes macos build, where otherwise the compilation yields an error: `no viable conversion from 'bool' to 'typename iterator_traits<const QualType *>::value_type`
2025-09-30 22:25:00 +02:00
Erich Keane
0d91e6daa1
[OpenACC][CIR] Generate private recipe pointer/array 'alloca's (#160911)
As a next step to generating pointer/array recipes, this patch generates
just the 'alloca' lines that are necessary. Copying pointers over to
restore the structure is held off to the next patch.

In the case of a pointer, we need to allocate the level 'below' it (if
we index into it), then copy the values into the pointers. In the case
of an array, we skip the alloca (since the array's alloca contains the
value).

After this, we'll need a patch that copies the pointers into place, and
finally one that does the initialization of these values.
2025-09-30 06:09:12 -07:00
Erich Keane
69194be748
[NFC][OpenACC][CIR] Extract 'base' class for Recipe generation (#160603)
It was brought up on a previous review that the CIRGenOpenACCRecipe.h
file was getting too large. I noticed that the 'dependent on template
argument' parts were actually quite small, so I extract a base class in
this patch that allows me to implement it in the .cpp file, plus
minimize the amount of code that needs instantiating.
2025-09-26 13:33:41 +00:00