Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions flang/include/flang/Optimizer/Dialect/CUF/CUFOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ include "mlir/IR/BuiltinAttributes.td"
class cuf_Op<string mnemonic, list<Trait> traits>
: Op<CUFDialect, mnemonic, traits>;

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

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

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

let assemblyFormat = [{
$in_type (`(` $typeparams^ `:` type($typeparams) `)`)?
Expand Down
22 changes: 22 additions & 0 deletions flang/test/Analysis/AliasAnalysis/cuf-alloc-source-kind.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// REQUIRES: asserts
// 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

// Verify that a CUF allocation is recognized as SourceKind::Allocate by
// fir::AliasAnalysis::getSource.

module {
func.func @_QQmain() attributes {fir.bindc_name = "TEST"} {
// Allocate two independent device arrays and tag the results; with
// value-scoped MemAlloc handling in AA, these should be classified as
// Allocate and not alias.
%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>>>>
%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>>>>
return
}
}

// CHECK-LABEL: Testing : "_QQmain"
// Distinct allocations should not alias.
// CHECK: cuf_alloc_a#0 <-> cuf_alloc_b#0: NoAlias


Loading