Skip to content

Commit 4555bc4

Browse files
committed
Improve interface implementation to make adding clauses less error-prone
1 parent 32fdaf6 commit 4555bc4

File tree

1 file changed

+37
-9
lines changed

1 file changed

+37
-9
lines changed

mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,38 +47,66 @@ def BlockArgOpenMPOpInterface : OpInterface<"BlockArgOpenMPOpInterface"> {
4747
}]>,
4848

4949
// Unified access methods for clause-associated entry block arguments.
50+
InterfaceMethod<"Get start index of block arguments defined by `in_reduction`.",
51+
"unsigned", "getInReductionBlockArgsStart", (ins), [{
52+
return 0;
53+
}]>,
54+
InterfaceMethod<"Get start index of block arguments defined by `map`.",
55+
"unsigned", "getMapBlockArgsStart", (ins), [{
56+
auto iface = ::llvm::cast<BlockArgOpenMPOpInterface>(*$_op);
57+
return iface.getInReductionBlockArgsStart() +
58+
$_op.numInReductionBlockArgs();
59+
}]>,
60+
InterfaceMethod<"Get start index of block arguments defined by `private`.",
61+
"unsigned", "getPrivateBlockArgsStart", (ins), [{
62+
auto iface = ::llvm::cast<BlockArgOpenMPOpInterface>(*$_op);
63+
return iface.getMapBlockArgsStart() + $_op.numMapBlockArgs();
64+
}]>,
65+
InterfaceMethod<"Get start index of block arguments defined by `reduction`.",
66+
"unsigned", "getReductionBlockArgsStart", (ins), [{
67+
auto iface = ::llvm::cast<BlockArgOpenMPOpInterface>(*$_op);
68+
return iface.getPrivateBlockArgsStart() + $_op.numPrivateBlockArgs();
69+
}]>,
70+
InterfaceMethod<"Get start index of block arguments defined by `task_reduction`.",
71+
"unsigned", "getTaskReductionBlockArgsStart", (ins), [{
72+
auto iface = ::llvm::cast<BlockArgOpenMPOpInterface>(*$_op);
73+
return iface.getReductionBlockArgsStart() + $_op.numReductionBlockArgs();
74+
}]>,
75+
5076
InterfaceMethod<"Get block arguments defined by `in_reduction`.",
5177
"::llvm::MutableArrayRef<::mlir::BlockArgument>",
5278
"getInReductionBlockArgs", (ins), [{
53-
return $_op->getRegion(0).getArguments().take_front(
54-
$_op.numInReductionBlockArgs());
79+
auto iface = ::llvm::cast<BlockArgOpenMPOpInterface>(*$_op);
80+
return $_op->getRegion(0).getArguments().slice(
81+
iface.getInReductionBlockArgsStart(), $_op.numInReductionBlockArgs());
5582
}]>,
5683
InterfaceMethod<"Get block arguments defined by `map`.",
5784
"::llvm::MutableArrayRef<::mlir::BlockArgument>",
5885
"getMapBlockArgs", (ins), [{
86+
auto iface = ::llvm::cast<BlockArgOpenMPOpInterface>(*$_op);
5987
return $_op->getRegion(0).getArguments().slice(
60-
$_op.numInReductionBlockArgs(), $_op.numMapBlockArgs());
88+
iface.getMapBlockArgsStart(), $_op.numMapBlockArgs());
6189
}]>,
6290
InterfaceMethod<"Get block arguments defined by `private`.",
6391
"::llvm::MutableArrayRef<::mlir::BlockArgument>",
6492
"getPrivateBlockArgs", (ins), [{
93+
auto iface = ::llvm::cast<BlockArgOpenMPOpInterface>(*$_op);
6594
return $_op->getRegion(0).getArguments().slice(
66-
$_op.numInReductionBlockArgs() + $_op.numMapBlockArgs(),
67-
$_op.numPrivateBlockArgs());
95+
iface.getPrivateBlockArgsStart(), $_op.numPrivateBlockArgs());
6896
}]>,
6997
InterfaceMethod<"Get block arguments defined by `reduction`.",
7098
"::llvm::MutableArrayRef<::mlir::BlockArgument>",
7199
"getReductionBlockArgs", (ins), [{
100+
auto iface = ::llvm::cast<BlockArgOpenMPOpInterface>(*$_op);
72101
return $_op->getRegion(0).getArguments().slice(
73-
$_op.numInReductionBlockArgs() + $_op.numMapBlockArgs() +
74-
$_op.numPrivateBlockArgs(), $_op.numReductionBlockArgs());
102+
iface.getReductionBlockArgsStart(), $_op.numReductionBlockArgs());
75103
}]>,
76104
InterfaceMethod<"Get block arguments defined by `task_reduction`.",
77105
"::llvm::MutableArrayRef<::mlir::BlockArgument>",
78106
"getTaskReductionBlockArgs", (ins), [{
107+
auto iface = ::llvm::cast<BlockArgOpenMPOpInterface>(*$_op);
79108
return $_op->getRegion(0).getArguments().slice(
80-
$_op.numInReductionBlockArgs() + $_op.numMapBlockArgs() +
81-
$_op.numPrivateBlockArgs() + $_op.numReductionBlockArgs(),
109+
iface.getTaskReductionBlockArgsStart(),
82110
$_op.numTaskReductionBlockArgs());
83111
}]>,
84112
];

0 commit comments

Comments
 (0)