Skip to content

Commit f5a5142

Browse files
[openacc] Update acc.loop to expose data operands (llvm#70954)
The compute and data constructs implement getNumDataOperands and getDataOperand. The acc.loop operation similarly has multiple data operands - thus it makes sense to expose them the same way. For loop, only private and reduction operands are exposed this way. Technically, acc.loop also holds cache operands - but these are hints not a data attribute.
1 parent 5570d32 commit f5a5142

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

flang/lib/Lower/OpenACC.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1592,9 +1592,9 @@ createLoopOp(Fortran::lower::AbstractConverter &converter,
15921592
addOperand(operands, operandSegments, workerNum);
15931593
addOperand(operands, operandSegments, vectorNum);
15941594
addOperands(operands, operandSegments, tileOperands);
1595+
addOperands(operands, operandSegments, cacheOperands);
15951596
addOperands(operands, operandSegments, privateOperands);
15961597
addOperands(operands, operandSegments, reductionOperands);
1597-
addOperands(operands, operandSegments, cacheOperands);
15981598

15991599
auto loopOp = createRegionOp<mlir::acc::LoopOp, mlir::acc::YieldOp>(
16001600
builder, currentLocation, eval, operands, operandSegments);

mlir/include/mlir/Dialect/OpenACC/OpenACC.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,16 @@
4848
mlir::acc::CacheOp
4949
#define ACC_COMPUTE_CONSTRUCT_OPS \
5050
mlir::acc::ParallelOp, mlir::acc::KernelsOp, mlir::acc::SerialOp
51+
#define ACC_COMPUTE_CONSTRUCT_AND_LOOP_OPS \
52+
ACC_COMPUTE_CONSTRUCT_OPS, mlir::acc::LoopOp
5153
#define ACC_DATA_CONSTRUCT_OPS \
5254
mlir::acc::DataOp, mlir::acc::EnterDataOp, mlir::acc::ExitDataOp, \
5355
mlir::acc::UpdateOp, mlir::acc::HostDataOp, mlir::acc::DeclareEnterOp, \
5456
mlir::acc::DeclareExitOp, mlir::acc::DeclareOp
5557
#define ACC_COMPUTE_AND_DATA_CONSTRUCT_OPS \
5658
ACC_COMPUTE_CONSTRUCT_OPS, ACC_DATA_CONSTRUCT_OPS
59+
#define ACC_COMPUTE_LOOP_AND_DATA_CONSTRUCT_OPS \
60+
ACC_COMPUTE_CONSTRUCT_AND_LOOP_OPS, ACC_DATA_CONSTRUCT_OPS
5761

5862
namespace mlir {
5963
namespace acc {

mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,11 +1196,12 @@ def OpenACC_LoopOp : OpenACC_Op<"loop",
11961196
UnitAttr:$hasWorker,
11971197
UnitAttr:$hasVector,
11981198
Variadic<IntOrIndex>:$tileOperands,
1199+
Variadic<OpenACC_PointerLikeTypeInterface>:$cacheOperands,
11991200
Variadic<OpenACC_PointerLikeTypeInterface>:$privateOperands,
12001201
OptionalAttr<SymbolRefArrayAttr>:$privatizations,
12011202
Variadic<AnyType>:$reductionOperands,
1202-
OptionalAttr<SymbolRefArrayAttr>:$reductionRecipes,
1203-
Variadic<OpenACC_PointerLikeTypeInterface>:$cacheOperands);
1203+
OptionalAttr<SymbolRefArrayAttr>:$reductionRecipes
1204+
);
12041205

12051206
let results = (outs Variadic<AnyType>:$results);
12061207

@@ -1211,6 +1212,12 @@ def OpenACC_LoopOp : OpenACC_Op<"loop",
12111212
static StringRef getGangNumKeyword() { return "num"; }
12121213
static StringRef getGangDimKeyword() { return "dim"; }
12131214
static StringRef getGangStaticKeyword() { return "static"; }
1215+
1216+
/// The number of private and reduction operands.
1217+
unsigned getNumDataOperands();
1218+
1219+
/// The i-th data operand passed.
1220+
Value getDataOperand(unsigned i);
12141221
}];
12151222

12161223
let hasCustomAssemblyFormat = 1;

mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,22 @@ LogicalResult acc::LoopOp::verify() {
878878
return success();
879879
}
880880

881+
unsigned LoopOp::getNumDataOperands() {
882+
return getReductionOperands().size() + getPrivateOperands().size();
883+
}
884+
885+
Value LoopOp::getDataOperand(unsigned i) {
886+
unsigned numOptional = getGangNum() ? 1 : 0;
887+
numOptional += getGangDim() ? 1 : 0;
888+
numOptional += getGangStatic() ? 1 : 0;
889+
numOptional += getVectorLength() ? 1 : 0;
890+
numOptional += getWorkerNum() ? 1 : 0;
891+
numOptional += getVectorLength() ? 1 : 0;
892+
numOptional += getTileOperands().size();
893+
numOptional += getCacheOperands().size();
894+
return getOperand(numOptional + i);
895+
}
896+
881897
//===----------------------------------------------------------------------===//
882898
// DataOp
883899
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)