|
| 1 | +//===-- WebAssemblySSAInterfaces.td - WebAssemblySSA Interfaces -*- tablegen -*-===// |
| 2 | +// |
| 3 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See https://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | +// |
| 9 | +// This file defines interfaces for the WebAssemblySSA dialect in MLIR. |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +#ifndef WEBASSEMBLYSSA_INTERFACES |
| 14 | +#define WEBASSEMBLYSSA_INTERFACES |
| 15 | + |
| 16 | +include "mlir/IR/OpBase.td" |
| 17 | +include "mlir/IR/BuiltinAttributes.td" |
| 18 | + |
| 19 | +def WasmSSALabelLevelInterface : OpInterface<"WasmSSALabelLevelInterface"> { |
| 20 | + let description = [{ |
| 21 | + Operation that defines one level of nesting for wasm branching. |
| 22 | + These operation region can be targeted by branch instructions. |
| 23 | + }]; |
| 24 | + let methods = [ |
| 25 | + InterfaceMethod< |
| 26 | + /*desc=*/ "Returns the target block address", |
| 27 | + /*returnType=*/ "::mlir::Block*", |
| 28 | + /*methodName=*/ "getLabelTarget", |
| 29 | + /*args=*/ (ins) |
| 30 | + > |
| 31 | + ]; |
| 32 | +} |
| 33 | + |
| 34 | +def WasmSSALabelBranchingInterface : OpInterface<"WasmSSALabelBranchingInterface"> { |
| 35 | + let description = [{ |
| 36 | + Wasm operation that targets a label for a jump. |
| 37 | + }]; |
| 38 | + let methods = [ |
| 39 | + InterfaceMethod< |
| 40 | + /*desc=*/ "Returns the number of context to break from", |
| 41 | + /*returnType=*/ "size_t", |
| 42 | + /*methodName=*/ "getExitLevel", |
| 43 | + /*args=*/ (ins) |
| 44 | + >, |
| 45 | + InterfaceMethod< |
| 46 | + /*desc=*/ "Returns the destination of this operation", |
| 47 | + /*returnType=*/ "WasmSSALabelLevelInterface", |
| 48 | + /*methodName=*/ "getTargetOp", |
| 49 | + /*args=*/ (ins), |
| 50 | + /*methodBody=*/ [{ |
| 51 | + return *WasmSSALabelBranchingInterface::getTargetOpFromBlock($_op.getOperation()->getBlock(), $_op.getExitLevel()); |
| 52 | + }] |
| 53 | + >, |
| 54 | + InterfaceMethod< |
| 55 | + /*desc=*/ "Return the target control flow ops that defined the label of this operation", |
| 56 | + /*returnType=*/ "::mlir::Block*", |
| 57 | + /*methodName=*/ "getTarget", |
| 58 | + /*args=*/ (ins), |
| 59 | + /*methodBody=*/ [{}], |
| 60 | + /*defaultImpl=*/ [{ |
| 61 | + auto op = mlir::cast<WasmSSALabelBranchingInterface>(this->getOperation()); |
| 62 | + return op.getTargetOp().getLabelTarget(); |
| 63 | + }] |
| 64 | + > |
| 65 | + ]; |
| 66 | + let extraClassDeclaration = [{ |
| 67 | + static ::llvm::FailureOr<WasmSSALabelLevelInterface> getTargetOpFromBlock(::mlir::Block *block, uint32_t level); |
| 68 | + }]; |
| 69 | + let verify = [{return verifyWasmSSALabelBranchingInterface($_op);}]; |
| 70 | +} |
| 71 | + |
| 72 | +def WasmSSAImportOpInterface : OpInterface<"WasmSSAImportOpInterface"> { |
| 73 | + let description = [{ |
| 74 | + Operation that imports a symbol from an external wasm module; |
| 75 | + }]; |
| 76 | + |
| 77 | + let methods = [ |
| 78 | + InterfaceMethod< |
| 79 | + /*desc=*/ "Returns the module name for the import", |
| 80 | + /*returnType=*/ "::llvm::StringRef", |
| 81 | + /*methodName=*/ "getModuleName", |
| 82 | + /*args=*/ (ins) |
| 83 | + >, |
| 84 | + InterfaceMethod< |
| 85 | + /*desc=*/ "Returns the import name for the import", |
| 86 | + /*returnType=*/ "::llvm::StringRef", |
| 87 | + /*methodName=*/ "getImportName", |
| 88 | + /*args=*/ (ins) |
| 89 | + >, |
| 90 | + InterfaceMethod< |
| 91 | + /*desc=*/ "Returns the wasm index based symbol of the op", |
| 92 | + /*returnType=*/ "::mlir::StringAttr", |
| 93 | + /*methodName=*/ "getSymbolName", |
| 94 | + /*args=*/ (ins), |
| 95 | + /*methodBody=*/ [{}], |
| 96 | + /*defaultImpl=*/ [{ |
| 97 | + auto op = mlir::cast<ConcreteOp>(this->getOperation()); |
| 98 | + return op.getSymNameAttr(); |
| 99 | + }] |
| 100 | + >, |
| 101 | + InterfaceMethod< |
| 102 | + /*desc=*/ "Returns the qualified name of the import", |
| 103 | + /*returnType=*/ "std::string", |
| 104 | + /*methodName=*/ "getQualifiedImportName", |
| 105 | + /*args=*/ (ins), |
| 106 | + /*methodBody=*/ [{ |
| 107 | + return ($_op.getModuleName() + llvm::Twine{"::"} + $_op.getImportName()).str(); |
| 108 | + }] |
| 109 | + >, |
| 110 | + ]; |
| 111 | +} |
| 112 | + |
| 113 | +def WasmSSAConstantExpressionInitializerInterface : |
| 114 | + OpInterface<"WasmSSAConstantExpressionInitializerInterface"> { |
| 115 | + let description = [{ |
| 116 | + Operation that must be constant initialized. This |
| 117 | + interface adds a verifier that checks that all ops |
| 118 | + within the initializer region are "constant expressions" |
| 119 | + as defined by the WASM standard. |
| 120 | + }]; |
| 121 | + |
| 122 | + let verify = [{ return detail::verifyConstantExpressionInterface($_op); }]; |
| 123 | +} |
| 124 | + |
| 125 | +def WasmSSAConstantExprCheckInterface : |
| 126 | + OpInterface<"WasmSSAConstantExprCheckInterface"> { |
| 127 | + let description = [{ |
| 128 | + Base interface for operations that can be used in a Wasm Constant Expression. |
| 129 | + It shouldn't be used directly, use one of the derived instead. |
| 130 | + }]; |
| 131 | + |
| 132 | + let methods = [ |
| 133 | + InterfaceMethod< |
| 134 | + /*desc=*/ [{ |
| 135 | + Returns success if the current operation is valid in a constant expression context. |
| 136 | + }], |
| 137 | + /*returnType=*/ "::mlir::LogicalResult", |
| 138 | + /*methodName=*/ "isValidInConstantExpr", |
| 139 | + /*args=*/ (ins), |
| 140 | + /*methodBody=*/ [{ |
| 141 | + return $_op.verifyConstantExprValidity(); |
| 142 | + }] |
| 143 | + > |
| 144 | + ]; |
| 145 | +} |
| 146 | + |
| 147 | +def WasmSSAContextuallyConstantExprInterface : |
| 148 | + OpInterface<"WasmSSAContextuallyConstantExprInterface", [WasmSSAConstantExprCheckInterface]> { |
| 149 | + let description = [{ |
| 150 | + Base interface for operations that can be used in a Wasm Constant Expression |
| 151 | + depending on the context. |
| 152 | + }]; |
| 153 | + |
| 154 | + let methods = [ |
| 155 | + InterfaceMethod< |
| 156 | + /*desc=*/ [{ |
| 157 | + Returns success if the current operation is valid in a constant expression context. |
| 158 | + }], |
| 159 | + /*returnType=*/ "::mlir::LogicalResult", |
| 160 | + /*methodName=*/ "verifyConstantExprValidity", |
| 161 | + /*args=*/ (ins) |
| 162 | + > |
| 163 | + ]; |
| 164 | +} |
| 165 | + |
| 166 | +def WasmSSAConstantExprInterface : |
| 167 | + OpInterface<"WasmSSAConstantExprInterface", [WasmSSAConstantExprCheckInterface]> { |
| 168 | + let description = [{ |
| 169 | + Base interface for operations that can always be used in a Wasm Constant Expression. |
| 170 | + }]; |
| 171 | + |
| 172 | + let methods = [ |
| 173 | + InterfaceMethod< |
| 174 | + /*desc=*/ [{ |
| 175 | + Returns success if the current operation is valid in a constant expression context. |
| 176 | + }], |
| 177 | + /*returnType=*/ "::mlir::LogicalResult", |
| 178 | + /*methodName=*/ "verifyConstantExprValidity", |
| 179 | + /*args=*/ (ins), |
| 180 | + /*methodBody=*/ [{}], |
| 181 | + /*DefaultImplementation=*/ [{ return success(); }] |
| 182 | + > |
| 183 | + ]; |
| 184 | +} |
| 185 | + |
| 186 | +#endif // WEBASSEMBLYSSA_INTERFACES |
0 commit comments