9 Commits

Author SHA1 Message Date
Susan Tan (ス-ザン タン)
55111e8d17
[flang] use fir.bitcast for FIRToMemRef scalar reinterpretation (#188328)
Use fir.bitcast in FIR-to-MemRef casts so bit patterns are preserved
(e.g. TRANSFER), while keeping fir.convert for memref/reference
marshaling and non-bitcast-compatible cases.
2026-03-25 15:27:43 -04:00
khaki3
4219fb8a21
[flang] Fix FIRToMemRef index computation for array_coor with shape_shift and slice (#186523)
When fir.array_coor carries an explicit shape_shift (non-default lower
bounds) and an explicit slice, the indices are Fortran indices rather
than 1-based section indices. The FIRToMemRef pass was unconditionally
subtracting 1 from sliced indices, which is only correct for 1-based
section indices (the embox-with-embedded-slice case).

For shape_shift + explicit slice, the correct adjustment is to subtract
the slice lower bound instead of 1. This produces proper 0-based memref
indices.

This pattern arises after the FIR inliner canonicalizes
fir.embox(shape_shift, slice) + fir.array_coor(box) into a single
fir.array_coor with explicit shape_shift and slice operands, where the
indices become Fortran indices.

Without this fix, arrays with non-default lower bounds (e.g., A(0:N) or
A(-1:N)) produce negative memref indices, writing before the array
allocation and causing a segfault.
2026-03-23 10:35:27 -07:00
Scott Manley
965ee6c91f
[FIRToMemRef] copy ACC Variable Name attribute (#187724)
When converting from fir.alloca to memref.alloca, also copy the acc
variable name attribute if it exists
2026-03-20 12:29:41 -05:00
Susan Tan (ス-ザン タン)
97cf8bf220
[flang] materialize fir.box when it is from a block argument (#184898)
We have to materialize `fir.box` before adding a `fir.convert` to a
memref type. Otherwise we get:
`'fir.convert' op invalid type conversion'!fir.box<!fir.array<?xi32>>' /
'memref<?xi32, strided<[?], offset: ?>>'`
2026-03-06 16:02:09 -05:00
Susan Tan (ス-ザン タン)
2b074823e4
Reapply "[flang] Lowering a ArrayCoorOp to arithmetic computations" (#182585)
Reapplying the changes. Reverted it wrongly yesterday

This reverts commit 3c6523dcb8ebc0396f69c578285599b66e16dce7.
2026-02-20 15:33:26 -05:00
Susan Tan (ス-ザン タン)
3c6523dcb8
Revert "[flang] Lowering a ArrayCoorOp to arithmetic computations whe… (#182365)
This reverts commit 2bd23d3fa688d0e25c8492ceeaa251af4759d559.
2026-02-19 20:43:05 +00:00
Susan Tan (ス-ザン タン)
2bd23d3fa6
[flang] Lowering a ArrayCoorOp to arithmetic computations when a fir memref is a block argument (#182139)
Remove the special-case that handled `fir.array_coor` with a
block-argument base by converting the element ref result (!fir.ref<i32>
-> memref<i32>) and leaving fir.array_coor alive.

Instead, we now always convert the base (!fir.ref<!fir.array<...>> ->
memref<...>) and compute the memref indices from the fir.array_coor
operands, so loads/stores become memref.load/store base[indices] and
fir.array_coor can be erased when it’s only used by memory ops.
2026-02-19 11:46:17 -05:00
Razvan Lupusoru
ab7217a089
[acc][flang] Add isDeviceData APIs for device data detection (#176219)
Add comprehensive APIs to detect device-resident data across OpenACC
type and operation interfaces. This enables passes to identify data that
is already on the device (e.g., CUF device/managed/constant memory, GPU
address spaces) and handle it appropriately.

New interface methods:
- PointerLikeType::isDeviceData(Value): Returns true if the pointer
points to device data.
- MappableType::isDeviceData(Value): Returns true if the variable
represents device data.
- GlobalVariableOpInterface::isDeviceData(): Returns true if the global
variable is device data.

New utilities in OpenACCUtils:
- acc::isDeviceValue(Value): Checks if a value represents device data by
querying type interfaces, PartialEntityAccessOpInterface for base
entities, and AddressOfGlobalOpInterface for global symbols.
- acc::isValidValueUse(Value, Region): Checks if a value is legal in an
OpenACC region by verifying it comes from a data operation, is only used
by private clauses, or is device data.

Updated isValidSymbolUse to check
GlobalVariableOpInterface::isDeviceData()
for symbols referencing device-resident globals.

FIR implementations check for CUF data attributes (device, managed,
constant, shared, unified) on operations, block arguments, and globals.
The implementation traces through fir.rebox, fir.embox, fir.declare,
hlfir.declare, and fir.address_of to find the underlying data source.

Memref implementations check for gpu::AddressSpaceAttr on the memref
type.

Updated ACCImplicitData to use acc::isDeviceValue for generating
acc.deviceptr clauses for device-resident data instead of
copyin/copyout.

Updated OpenACCSupport::isValidValueUse to fallback to the new
acc::isValidValueUse utility.
2026-01-15 20:56:26 +00:00
Susan Tan (ス-ザン タン)
2698d15664
[flang] Lowering FIR memory ops to MemRef dialect (#173507)
This patch introduces FIRToMemRef, a lowering pass that converts FIR
memory operations to the MemRef dialect, including support for slices,
shifts, and descriptor-style access patterns. To support partial
lowering, where FIR and MemRef types can coexist, we extend the handling
of fir.convert to correctly marshal between FIR reference-like types and
MemRef descriptors. The patch also factors the type conversion logic
into a reusable FIRToMemRefTypeConverter, which centralizes the rules
for converting FIR types (e.g. !fir.ref, !fir.box, sequences, logicals)
to their corresponding memref types, and is used throughout the new
pass.

---------

Co-authored-by: Scott Manley <rscottmanley@gmail.com>
Co-authored-by: jeanPerier <jean.perier.polytechnique@gmail.com>
2026-01-14 10:46:50 -05:00