|
15 | 15 |
|
16 | 16 | include "mlir/IR/OpBase.td" |
17 | 17 |
|
| 18 | +def BlockArgOpenMPOpInterface : OpInterface<"BlockArgOpenMPOpInterface"> { |
| 19 | + let description = [{ |
| 20 | + OpenMP operations that define entry block arguments as part of the |
| 21 | + representation of its clauses. |
| 22 | + }]; |
| 23 | + |
| 24 | + let cppNamespace = "::mlir::omp"; |
| 25 | + |
| 26 | + let methods = [ |
| 27 | + // Default-implemented methods to be overriden by the corresponding clauses. |
| 28 | + InterfaceMethod<"Get number of block arguments defined by `in_reduction`.", |
| 29 | + "unsigned", "numInReductionBlockArgs", (ins), [{}], [{ |
| 30 | + return 0; |
| 31 | + }]>, |
| 32 | + InterfaceMethod<"Get number of block arguments defined by `map`.", |
| 33 | + "unsigned", "numMapBlockArgs", (ins), [{}], [{ |
| 34 | + return 0; |
| 35 | + }]>, |
| 36 | + InterfaceMethod<"Get number of block arguments defined by `private`.", |
| 37 | + "unsigned", "numPrivateBlockArgs", (ins), [{}], [{ |
| 38 | + return 0; |
| 39 | + }]>, |
| 40 | + InterfaceMethod<"Get number of block arguments defined by `reduction`.", |
| 41 | + "unsigned", "numReductionBlockArgs", (ins), [{}], [{ |
| 42 | + return 0; |
| 43 | + }]>, |
| 44 | + InterfaceMethod<"Get number of block arguments defined by `task_reduction`.", |
| 45 | + "unsigned", "numTaskReductionBlockArgs", (ins), [{}], [{ |
| 46 | + return 0; |
| 47 | + }]>, |
| 48 | + |
| 49 | + // 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 | + |
| 76 | + InterfaceMethod<"Get block arguments defined by `in_reduction`.", |
| 77 | + "::llvm::MutableArrayRef<::mlir::BlockArgument>", |
| 78 | + "getInReductionBlockArgs", (ins), [{ |
| 79 | + auto iface = ::llvm::cast<BlockArgOpenMPOpInterface>(*$_op); |
| 80 | + return $_op->getRegion(0).getArguments().slice( |
| 81 | + iface.getInReductionBlockArgsStart(), $_op.numInReductionBlockArgs()); |
| 82 | + }]>, |
| 83 | + InterfaceMethod<"Get block arguments defined by `map`.", |
| 84 | + "::llvm::MutableArrayRef<::mlir::BlockArgument>", |
| 85 | + "getMapBlockArgs", (ins), [{ |
| 86 | + auto iface = ::llvm::cast<BlockArgOpenMPOpInterface>(*$_op); |
| 87 | + return $_op->getRegion(0).getArguments().slice( |
| 88 | + iface.getMapBlockArgsStart(), $_op.numMapBlockArgs()); |
| 89 | + }]>, |
| 90 | + InterfaceMethod<"Get block arguments defined by `private`.", |
| 91 | + "::llvm::MutableArrayRef<::mlir::BlockArgument>", |
| 92 | + "getPrivateBlockArgs", (ins), [{ |
| 93 | + auto iface = ::llvm::cast<BlockArgOpenMPOpInterface>(*$_op); |
| 94 | + return $_op->getRegion(0).getArguments().slice( |
| 95 | + iface.getPrivateBlockArgsStart(), $_op.numPrivateBlockArgs()); |
| 96 | + }]>, |
| 97 | + InterfaceMethod<"Get block arguments defined by `reduction`.", |
| 98 | + "::llvm::MutableArrayRef<::mlir::BlockArgument>", |
| 99 | + "getReductionBlockArgs", (ins), [{ |
| 100 | + auto iface = ::llvm::cast<BlockArgOpenMPOpInterface>(*$_op); |
| 101 | + return $_op->getRegion(0).getArguments().slice( |
| 102 | + iface.getReductionBlockArgsStart(), $_op.numReductionBlockArgs()); |
| 103 | + }]>, |
| 104 | + InterfaceMethod<"Get block arguments defined by `task_reduction`.", |
| 105 | + "::llvm::MutableArrayRef<::mlir::BlockArgument>", |
| 106 | + "getTaskReductionBlockArgs", (ins), [{ |
| 107 | + auto iface = ::llvm::cast<BlockArgOpenMPOpInterface>(*$_op); |
| 108 | + return $_op->getRegion(0).getArguments().slice( |
| 109 | + iface.getTaskReductionBlockArgsStart(), |
| 110 | + $_op.numTaskReductionBlockArgs()); |
| 111 | + }]>, |
| 112 | + ]; |
| 113 | + |
| 114 | + let verify = [{ |
| 115 | + auto iface = ::llvm::cast<BlockArgOpenMPOpInterface>($_op); |
| 116 | + unsigned expectedArgs = iface.numInReductionBlockArgs() + |
| 117 | + iface.numMapBlockArgs() + iface.numPrivateBlockArgs() + |
| 118 | + iface.numReductionBlockArgs() + iface.numTaskReductionBlockArgs(); |
| 119 | + if ($_op->getRegion(0).getNumArguments() < expectedArgs) |
| 120 | + return $_op->emitOpError() << "expected at least " << expectedArgs |
| 121 | + << " entry block argument(s)"; |
| 122 | + return ::mlir::success(); |
| 123 | + }]; |
| 124 | +} |
| 125 | + |
18 | 126 | def OutlineableOpenMPOpInterface : OpInterface<"OutlineableOpenMPOpInterface"> { |
19 | 127 | let description = [{ |
20 | 128 | OpenMP operations whose region will be outlined will implement this |
|
0 commit comments