Skip to content

Commit 538424c

Browse files
committed
change cuf
1 parent 163cda5 commit 538424c

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ include "flang/Optimizer/Dialect/FIRAttr.td"
2121
include "mlir/Dialect/GPU/IR/GPUBase.td"
2222
include "mlir/Dialect/LLVMIR/LLVMOpBase.td"
2323
include "mlir/Interfaces/LoopLikeInterface.td"
24+
include "mlir/Interfaces/SideEffectInterfaces.td"
2425
include "mlir/IR/BuiltinAttributes.td"
2526

2627
class cuf_Op<string mnemonic, list<Trait> traits>
2728
: Op<CUFDialect, mnemonic, traits>;
2829

2930
def cuf_AllocOp : cuf_Op<"alloc", [AttrSizedOperandSegments,
30-
MemoryEffects<[MemAlloc]>]> {
31+
MemoryEffectsOpInterface]> {
3132
let summary = "Allocate an object on device";
3233

3334
let description = [{
@@ -62,6 +63,11 @@ def cuf_AllocOp : cuf_Op<"alloc", [AttrSizedOperandSegments,
6263
CArg<"mlir::ValueRange", "{}">:$shape,
6364
CArg<"llvm::ArrayRef<mlir::NamedAttribute>", "{}">:$attributes)>];
6465

66+
let extraClassDeclaration = [{
67+
void getEffects(
68+
llvm::SmallVectorImpl<mlir::MemoryEffects::EffectInstance> &effects);
69+
}];
70+
6571
let hasVerifier = 1;
6672
}
6773

flang/lib/Optimizer/Dialect/CUF/CUFOps.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "mlir/IR/Matchers.h"
2525
#include "mlir/IR/OpDefinition.h"
2626
#include "mlir/IR/PatternMatch.h"
27+
#include "mlir/Interfaces/SideEffectInterfaces.h"
2728
#include "llvm/ADT/SmallVector.h"
2829

2930
//===----------------------------------------------------------------------===//
@@ -66,6 +67,14 @@ static llvm::LogicalResult checkCudaAttr(Op op) {
6667

6768
llvm::LogicalResult cuf::AllocOp::verify() { return checkCudaAttr(*this); }
6869

70+
// Attach value-scoped MemAlloc to the result value.
71+
void cuf::AllocOp::getEffects(
72+
llvm::SmallVectorImpl<mlir::MemoryEffects::EffectInstance> &effects) {
73+
effects.emplace_back(mlir::MemoryEffects::Allocate::get(),
74+
mlir::cast<mlir::OpResult>(getPtr()),
75+
mlir::SideEffects::DefaultResource::get());
76+
}
77+
6978
//===----------------------------------------------------------------------===//
7079
// FreeOp
7180
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)