From: Valentin Clement Date: Fri, 4 Jun 2021 14:25:50 +0000 (-0400) Subject: [mlir][openacc] Conversion of data operands in acc.data to LLVM IR dialect X-Git-Tag: llvmorg-14-init~4854 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fcb1547229454fcc814a58784495a7ef9ad991d2;p=platform%2Fupstream%2Fllvm.git [mlir][openacc] Conversion of data operands in acc.data to LLVM IR dialect Convert data operands from the acc.data operation using the same conversion pattern than D102170. Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D103332 --- diff --git a/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td b/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td index 74f53c5..2685cdc4 100644 --- a/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td +++ b/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td @@ -186,6 +186,14 @@ def OpenACC_DataOp : OpenACC_Op<"data", let regions = (region AnyRegion:$region); + let extraClassDeclaration = [{ + /// The number of data operands. + unsigned getNumDataOperands(); + + /// The i-th data operand passed. + Value getDataOperand(unsigned i); + }]; + let assemblyFormat = [{ ( `if` `(` $ifCond^ `)` )? ( `copy` `(` $copyOperands^ `:` type($copyOperands) `)` )? diff --git a/mlir/lib/Conversion/OpenACCToLLVM/OpenACCToLLVM.cpp b/mlir/lib/Conversion/OpenACCToLLVM/OpenACCToLLVM.cpp index bc60b52..eb34b0e 100644 --- a/mlir/lib/Conversion/OpenACCToLLVM/OpenACCToLLVM.cpp +++ b/mlir/lib/Conversion/OpenACCToLLVM/OpenACCToLLVM.cpp @@ -137,6 +137,7 @@ class LegalizeDataOpForLLVMTranslation : public ConvertOpToLLVMPattern { void mlir::populateOpenACCToLLVMConversionPatterns( LLVMTypeConverter &converter, OwningRewritePatternList &patterns) { + patterns.add>(converter); patterns.add>(converter); patterns.add>(converter); patterns.add>(converter); @@ -170,6 +171,21 @@ void ConvertOpenACCToLLVMPass::runOnOperation() { return true; }; + target.addDynamicallyLegalOp( + [allDataOperandsAreConverted](acc::DataOp op) { + return allDataOperandsAreConverted(op.copyOperands()) && + allDataOperandsAreConverted(op.copyinOperands()) && + allDataOperandsAreConverted(op.copyinReadonlyOperands()) && + allDataOperandsAreConverted(op.copyoutOperands()) && + allDataOperandsAreConverted(op.copyoutZeroOperands()) && + allDataOperandsAreConverted(op.createOperands()) && + allDataOperandsAreConverted(op.createZeroOperands()) && + allDataOperandsAreConverted(op.noCreateOperands()) && + allDataOperandsAreConverted(op.presentOperands()) && + allDataOperandsAreConverted(op.deviceptrOperands()) && + allDataOperandsAreConverted(op.attachOperands()); + }); + target.addDynamicallyLegalOp( [allDataOperandsAreConverted](acc::EnterDataOp op) { return allDataOperandsAreConverted(op.copyinOperands()) && diff --git a/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp b/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp index 33d6c23..974e67f 100644 --- a/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp +++ b/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp @@ -652,6 +652,20 @@ static LogicalResult verify(acc::DataOp dataOp) { return success(); } +unsigned DataOp::getNumDataOperands() { + return copyOperands().size() + copyinOperands().size() + + copyinReadonlyOperands().size() + copyoutOperands().size() + + copyoutZeroOperands().size() + createOperands().size() + + createZeroOperands().size() + noCreateOperands().size() + + presentOperands().size() + deviceptrOperands().size() + + attachOperands().size(); +} + +Value DataOp::getDataOperand(unsigned i) { + unsigned numOptional = ifCond() ? 1 : 0; + return getOperand(numOptional + i); +} + //===----------------------------------------------------------------------===// // ExitDataOp //===----------------------------------------------------------------------===// diff --git a/mlir/test/Conversion/OpenACCToLLVM/convert-standalone-data-to-llvmir.mlir b/mlir/test/Conversion/OpenACCToLLVM/convert-data-operands-to-llvmir.mlir similarity index 70% rename from mlir/test/Conversion/OpenACCToLLVM/convert-standalone-data-to-llvmir.mlir rename to mlir/test/Conversion/OpenACCToLLVM/convert-data-operands-to-llvmir.mlir index 0bc3493..b25f80b 100644 --- a/mlir/test/Conversion/OpenACCToLLVM/convert-standalone-data-to-llvmir.mlir +++ b/mlir/test/Conversion/OpenACCToLLVM/convert-data-operands-to-llvmir.mlir @@ -108,3 +108,54 @@ func @testupdateop(%a: memref<10xf32>, %b: memref<10xf32>) -> () { } // CHECK: acc.update if(%{{.*}}) host(%{{.*}} : !llvm.struct<"openacc_data", (struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>, ptr, i64)>) device(%{{.*}} : !llvm.struct<"openacc_data.1", (struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>, ptr, i64)>) + +// ----- + +func @testdataregion(%a: memref<10xf32>, %b: memref<10xf32>) -> () { + acc.data copy(%b : memref<10xf32>) copyout(%a : memref<10xf32>) { + } + return +} + +// CHECK: acc.data copy(%{{.*}} : !llvm.struct<"openacc_data", (struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>, ptr, i64)>) copyout(%{{.*}} : !llvm.struct<"openacc_data.1", (struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>, ptr, i64)>) + +// ----- + +func @testdataregion(%a: !llvm.ptr, %b: memref<10xf32>, %c: !llvm.ptr) -> () { + acc.data copyin(%b : memref<10xf32>) deviceptr(%c: !llvm.ptr) attach(%a : !llvm.ptr) { + } + return +} + +// CHECK: acc.data copyin(%{{.*}} : !llvm.struct<"openacc_data", (struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>, ptr, i64)>) deviceptr(%{{.*}} : !llvm.ptr) attach(%{{.*}} : !llvm.ptr) + +// ----- + +func @testdataregion(%a: memref<10xf32>, %b: memref<10xf32>) -> () { + %ifCond = constant true + acc.data if(%ifCond) copyin_readonly(%b : memref<10xf32>) copyout_zero(%a : memref<10xf32>) { + } + return +} + +// CHECK: acc.data if(%{{.*}}) copyin_readonly(%{{.*}} : !llvm.struct<"openacc_data", (struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>, ptr, i64)>) copyout_zero(%{{.*}} : !llvm.struct<"openacc_data.1", (struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>, ptr, i64)>) + +// ----- + +func @testdataregion(%a: !llvm.ptr, %b: memref<10xf32>, %c: !llvm.ptr) -> () { + acc.data create(%b : memref<10xf32>) create_zero(%c: !llvm.ptr) no_create(%a : !llvm.ptr) { + } + return +} + +// CHECK: acc.data create(%{{.*}} : !llvm.struct<"openacc_data", (struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>, ptr, i64)>) create_zero(%{{.*}} : !llvm.ptr) no_create(%{{.*}} : !llvm.ptr) + +// ----- + +func @testdataregion(%a: memref<10xf32>, %b: memref<10xf32>) -> () { + acc.data present(%a, %b : memref<10xf32>, memref<10xf32>) { + } + return +} + +// CHECK: acc.data present(%{{.*}}, %{{.*}} : !llvm.struct<"openacc_data", (struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>, ptr, i64)>, !llvm.struct<"openacc_data.1", (struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>, ptr, i64)>)