Skip to content

Commit 1429628

Browse files
authored
[flang][cuf] Add to cuf.alloc/cuf.allocate mem alloc effect (#167414)
Add MemAlloc effect to the result so that cuf.alloc/cuf.allocate can be recognized by FIR alias analysis.
1 parent c40a694 commit 1429628

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

flang/include/flang/Optimizer/Dialect/CUF/CUFOps.td

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ include "mlir/IR/BuiltinAttributes.td"
2626
class cuf_Op<string mnemonic, list<Trait> traits>
2727
: Op<CUFDialect, mnemonic, traits>;
2828

29-
def cuf_AllocOp : cuf_Op<"alloc", [AttrSizedOperandSegments,
30-
MemoryEffects<[MemAlloc]>]> {
29+
def cuf_AllocOp : cuf_Op<"alloc", [AttrSizedOperandSegments]> {
3130
let summary = "Allocate an object on device";
3231

3332
let description = [{
@@ -47,7 +46,9 @@ def cuf_AllocOp : cuf_Op<"alloc", [AttrSizedOperandSegments,
4746
cuf_DataAttributeAttr:$data_attr
4847
);
4948

50-
let results = (outs fir_ReferenceType:$ptr);
49+
// Value-scoped Allocate on the returned reference
50+
let results =
51+
(outs Res<fir_ReferenceType, "", [MemAlloc<DefaultResource>]>:$ptr);
5152

5253
let assemblyFormat = [{
5354
$in_type (`(` $typeparams^ `:` type($typeparams) `)`)?
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// REQUIRES: asserts
2+
// RUN: fir-opt %s -pass-pipeline='builtin.module(func.func(test-fir-alias-analysis))' -debug-only=fir-alias-analysis --mlir-disable-threading 2>&1 | FileCheck %s
3+
4+
// Verify that a CUF allocation is recognized as SourceKind::Allocate by
5+
// fir::AliasAnalysis::getSource.
6+
7+
module {
8+
func.func @_QQmain() attributes {fir.bindc_name = "TEST"} {
9+
// Allocate two independent device arrays and tag the results; with
10+
// value-scoped MemAlloc handling in AA, these should be classified as
11+
// Allocate and not alias.
12+
%a = cuf.alloc !fir.box<!fir.heap<!fir.array<?xf32>>> {bindc_name = "a1", data_attr = #cuf.cuda<device>, uniq_name = "_QFEa1", test.ptr = "cuf_alloc_a"} -> !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>
13+
%b = cuf.alloc !fir.box<!fir.heap<!fir.array<?xf32>>> {bindc_name = "a2", data_attr = #cuf.cuda<device>, uniq_name = "_QFEa2", test.ptr = "cuf_alloc_b"} -> !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>
14+
return
15+
}
16+
}
17+
18+
// CHECK-LABEL: Testing : "_QQmain"
19+
// Distinct allocations should not alias.
20+
// CHECK: cuf_alloc_a#0 <-> cuf_alloc_b#0: NoAlias
21+
22+

0 commit comments

Comments
 (0)