diff options
author | David Spickett <david.spickett@linaro.org> | 2022-12-09 15:21:28 +0000 |
---|---|---|
committer | David Spickett <david.spickett@linaro.org> | 2022-12-09 15:36:48 +0000 |
commit | cf98e8273c5f1c84afcfdd9bcea486ec22f26768 (patch) | |
tree | 5e54b0b2cc27e9a3c2c8e41ded79774c8af91d63 /mlir/include | |
parent | f79d941575cca6adb547a2eb23bbab01ad6f7044 (diff) | |
download | llvm-cf98e8273c5f1c84afcfdd9bcea486ec22f26768.zip llvm-cf98e8273c5f1c84afcfdd9bcea486ec22f26768.tar.gz llvm-cf98e8273c5f1c84afcfdd9bcea486ec22f26768.tar.bz2 |
Revert "[mlir] FunctionOpInterface: make get/setFunctionType interface methods"
and "[mlir] Fix examples build"
This reverts commit fbc253fe81da4e1d6bfa2519e01e03f21d8c40a8 and
96cf183bccd7d1c3083f169a89a6af1f263b3aae.
Which I missed in the first revert in f3379feabe38fd3711b13ffcf6de4aab03b7ccdc.
Diffstat (limited to 'mlir/include')
-rw-r--r-- | mlir/include/mlir/IR/FunctionImplementation.h | 11 | ||||
-rw-r--r-- | mlir/include/mlir/IR/FunctionInterfaces.h | 23 | ||||
-rw-r--r-- | mlir/include/mlir/IR/FunctionInterfaces.td | 26 |
3 files changed, 34 insertions, 26 deletions
diff --git a/mlir/include/mlir/IR/FunctionImplementation.h b/mlir/include/mlir/IR/FunctionImplementation.h index f4c0cc0..5265f78 100644 --- a/mlir/include/mlir/IR/FunctionImplementation.h +++ b/mlir/include/mlir/IR/FunctionImplementation.h @@ -69,19 +69,17 @@ Type getFunctionType(Builder &builder, ArrayRef<OpAsmParser::Argument> argAttrs, /// Parser implementation for function-like operations. Uses /// `funcTypeBuilder` to construct the custom function type given lists of -/// input and output types. The parser sets the `typeAttrName` attribute to the -/// resulting function type. If `allowVariadic` is set, the parser will accept +/// input and output types. If `allowVariadic` is set, the parser will accept /// trailing ellipsis in the function signature and indicate to the builder /// whether the function is variadic. If the builder returns a null type, /// `result` will not contain the `type` attribute. The caller can then add a /// type, report the error or delegate the reporting to the op's verifier. ParseResult parseFunctionOp(OpAsmParser &parser, OperationState &result, - bool allowVariadic, StringAttr typeAttrName, + bool allowVariadic, FuncTypeBuilder funcTypeBuilder); /// Printer implementation for function-like operations. -void printFunctionOp(OpAsmPrinter &p, FunctionOpInterface op, bool isVariadic, - StringRef typeAttrName); +void printFunctionOp(OpAsmPrinter &p, FunctionOpInterface op, bool isVariadic); /// Prints the signature of the function-like operation `op`. Assumes `op` has /// is a FunctionOpInterface and has passed verification. @@ -94,7 +92,8 @@ void printFunctionSignature(OpAsmPrinter &p, Operation *op, /// function-like operation internally are not printed. Nothing is printed /// if all attributes are elided. Assumes `op` is a FunctionOpInterface and /// has passed verification. -void printFunctionAttributes(OpAsmPrinter &p, Operation *op, +void printFunctionAttributes(OpAsmPrinter &p, Operation *op, unsigned numInputs, + unsigned numResults, ArrayRef<StringRef> elided = {}); } // namespace function_interface_impl diff --git a/mlir/include/mlir/IR/FunctionInterfaces.h b/mlir/include/mlir/IR/FunctionInterfaces.h index bc2ec47..23fd884 100644 --- a/mlir/include/mlir/IR/FunctionInterfaces.h +++ b/mlir/include/mlir/IR/FunctionInterfaces.h @@ -22,10 +22,12 @@ #include "llvm/ADT/SmallString.h" namespace mlir { -class FunctionOpInterface; namespace function_interface_impl { +/// Return the name of the attribute used for function types. +inline StringRef getTypeAttrName() { return "function_type"; } + /// Return the name of the attribute used for function argument attributes. inline StringRef getArgDictAttrName() { return "arg_attrs"; } @@ -70,29 +72,28 @@ inline ArrayRef<NamedAttribute> getResultAttrs(Operation *op, unsigned index) { } /// Insert the specified arguments and update the function type attribute. -void insertFunctionArguments(FunctionOpInterface op, - ArrayRef<unsigned> argIndices, TypeRange argTypes, +void insertFunctionArguments(Operation *op, ArrayRef<unsigned> argIndices, + TypeRange argTypes, ArrayRef<DictionaryAttr> argAttrs, ArrayRef<Location> argLocs, unsigned originalNumArgs, Type newType); /// Insert the specified results and update the function type attribute. -void insertFunctionResults(FunctionOpInterface op, - ArrayRef<unsigned> resultIndices, +void insertFunctionResults(Operation *op, ArrayRef<unsigned> resultIndices, TypeRange resultTypes, ArrayRef<DictionaryAttr> resultAttrs, unsigned originalNumResults, Type newType); /// Erase the specified arguments and update the function type attribute. -void eraseFunctionArguments(FunctionOpInterface op, const BitVector &argIndices, +void eraseFunctionArguments(Operation *op, const BitVector &argIndices, Type newType); /// Erase the specified results and update the function type attribute. -void eraseFunctionResults(FunctionOpInterface op, - const BitVector &resultIndices, Type newType); +void eraseFunctionResults(Operation *op, const BitVector &resultIndices, + Type newType); /// Set a FunctionOpInterface operation's type signature. -void setFunctionType(FunctionOpInterface op, Type newType); +void setFunctionType(Operation *op, Type newType); /// Insert a set of `newTypes` into `oldTypes` at the given `indices`. If any /// types are inserted, `storage` is used to hold the new type list. The new @@ -206,6 +207,10 @@ Attribute removeResultAttr(ConcreteType op, unsigned index, StringAttr name) { /// method on FunctionOpInterface::Trait. template <typename ConcreteOp> LogicalResult verifyTrait(ConcreteOp op) { + if (!op.getFunctionTypeAttr()) + return op.emitOpError("requires a type attribute '") + << function_interface_impl::getTypeAttrName() << '\''; + if (failed(op.verifyType())) return failure(); diff --git a/mlir/include/mlir/IR/FunctionInterfaces.td b/mlir/include/mlir/IR/FunctionInterfaces.td index e86057a..c56129e 100644 --- a/mlir/include/mlir/IR/FunctionInterfaces.td +++ b/mlir/include/mlir/IR/FunctionInterfaces.td @@ -50,16 +50,6 @@ def FunctionOpInterface : OpInterface<"FunctionOpInterface"> { }]; let methods = [ InterfaceMethod<[{ - Returns the type of the function. - }], - "::mlir::Type", "getFunctionType">, - InterfaceMethod<[{ - Set the type of the function. This method should perform an unsafe - modification to the function type; it should not update argument or - result attributes. - }], - "void", "setFunctionTypeAttr", (ins "::mlir::TypeAttr":$type)>, - InterfaceMethod<[{ Returns the function argument types based exclusively on the type (to allow for this method may be called on function declarations). @@ -149,7 +139,7 @@ def FunctionOpInterface : OpInterface<"FunctionOpInterface"> { ArrayRef<NamedAttribute> attrs, TypeRange inputTypes) { state.addAttribute(SymbolTable::getSymbolAttrName(), builder.getStringAttr(name)); - state.addAttribute(ConcreteOp::getFunctionTypeAttrName(state.name), + state.addAttribute(function_interface_impl::getTypeAttrName(), TypeAttr::get(type)); state.attributes.append(attrs.begin(), attrs.end()); @@ -254,6 +244,11 @@ def FunctionOpInterface : OpInterface<"FunctionOpInterface"> { // the derived operation, which should already have these defined // (via ODS). + /// Returns the name of the attribute used for function types. + static StringRef getTypeAttrName() { + return function_interface_impl::getTypeAttrName(); + } + /// Returns the name of the attribute used for function argument attributes. static StringRef getArgDictAttrName() { return function_interface_impl::getArgDictAttrName(); @@ -264,6 +259,15 @@ def FunctionOpInterface : OpInterface<"FunctionOpInterface"> { return function_interface_impl::getResultDictAttrName(); } + /// Return the attribute containing the type of this function. + TypeAttr getFunctionTypeAttr() { + return this->getOperation()->template getAttrOfType<TypeAttr>( + getTypeAttrName()); + } + + /// Return the type of this function. + Type getFunctionType() { return getFunctionTypeAttr().getValue(); } + //===------------------------------------------------------------------===// // Argument and Result Handling //===------------------------------------------------------------------===// |