[llvm-branch-commits] [mlir] 67a339e - [MLIR] Disallow `sym_visibility`, `sym_name` and `type` attributes in the parsed attribute dictionary.
Author: Rahul Joshi Date: 2021-01-12T09:11:02-08:00 New Revision: 67a339e96839cdecb5efad0e2731ab20a4ee458e URL: https://github.com/llvm/llvm-project/commit/67a339e96839cdecb5efad0e2731ab20a4ee458e DIFF: https://github.com/llvm/llvm-project/commit/67a339e96839cdecb5efad0e2731ab20a4ee458e.diff LOG: [MLIR] Disallow `sym_visibility`, `sym_name` and `type` attributes in the parsed attribute dictionary. Differential Revision: https://reviews.llvm.org/D94200 Added: Modified: mlir/lib/IR/FunctionImplementation.cpp mlir/test/Dialect/Tosa/inlining.mlir mlir/test/IR/core-ops.mlir mlir/test/IR/invalid-func-op.mlir Removed: diff --git a/mlir/lib/IR/FunctionImplementation.cpp b/mlir/lib/IR/FunctionImplementation.cpp index 90ea91d49fb6..4bec1684b5ee 100644 --- a/mlir/lib/IR/FunctionImplementation.cpp +++ b/mlir/lib/IR/FunctionImplementation.cpp @@ -180,7 +180,7 @@ mlir::impl::parseFunctionLikeOp(OpAsmParser &parser, OperationState &result, return failure(); // Parse the function signature. - auto signatureLocation = parser.getCurrentLocation(); + llvm::SMLoc signatureLocation = parser.getCurrentLocation(); bool isVariadic = false; if (parseFunctionSignature(parser, allowVariadic, entryArgs, argTypes, argAttrs, isVariadic, resultTypes, resultAttrs)) @@ -196,9 +196,24 @@ mlir::impl::parseFunctionLikeOp(OpAsmParser &parser, OperationState &result, << (errorMessage.empty() ? "" : ": ") << errorMessage; // If function attributes are present, parse them. - if (parser.parseOptionalAttrDictWithKeyword(result.attributes)) + NamedAttrList parsedAttributes; + llvm::SMLoc attributeDictLocation = parser.getCurrentLocation(); + if (parser.parseOptionalAttrDictWithKeyword(parsedAttributes)) return failure(); + // Disallow attributes that are inferred from elsewhere in the attribute + // dictionary. + for (StringRef disallowed : + {SymbolTable::getVisibilityAttrName(), SymbolTable::getSymbolAttrName(), +getTypeAttrName()}) { +if (parsedAttributes.get(disallowed)) + return parser.emitError(attributeDictLocation, "'") + << disallowed + << "' is an inferred attribute and should not be specified in the " +"explicit attribute dictionary"; + } + result.attributes.append(parsedAttributes); + // Add the attributes to the function arguments. assert(argAttrs.size() == argTypes.size()); assert(resultAttrs.size() == resultTypes.size()); diff --git a/mlir/test/Dialect/Tosa/inlining.mlir b/mlir/test/Dialect/Tosa/inlining.mlir index 363358b0781b..f6789fafe3ed 100644 --- a/mlir/test/Dialect/Tosa/inlining.mlir +++ b/mlir/test/Dialect/Tosa/inlining.mlir @@ -19,11 +19,11 @@ func @inlined_if_fn(%arg0: tensor, %arg1: tensor, %arg2: tensor) - }) : (tensor, tensor, tensor) -> tensor return %0 : tensor } -func @add(%arg0: tensor, %arg1: tensor) -> tensor attributes {sym_visibility = "private"} { +func private @add(%arg0: tensor, %arg1: tensor) -> tensor { %0 = "tosa.add"(%arg0, %arg1) : (tensor, tensor) -> tensor return %0 : tensor } -func @sub(%arg0: tensor, %arg1: tensor) -> tensor attributes {sym_visibility = "private"} { +func private @sub(%arg0: tensor, %arg1: tensor) -> tensor { %0 = "tosa.sub"(%arg0, %arg1) : (tensor, tensor) -> tensor return %0 : tensor } @@ -45,12 +45,12 @@ func @inlined_while_fn(%arg0: tensor, %arg1: tensor, %arg2: tensor, tensor, tensor, tensor<10xi32>) -> (tensor, tensor, tensor, tensor<10xi32>) return %1#3 : tensor<10xi32> } -func @while_body_50(%arg0: tensor, %arg1: tensor, %arg2: tensor, %arg3: tensor<10xi32>) -> (tensor, tensor, tensor, tensor<10xi32>) attributes {sym_visibility = "private"} { +func private @while_body_50(%arg0: tensor, %arg1: tensor, %arg2: tensor, %arg3: tensor<10xi32>) -> (tensor, tensor, tensor, tensor<10xi32>) { %1 = "tosa.add"(%arg0, %arg1) : (tensor, tensor) -> tensor %2 = "tosa.add"(%arg3, %1) : (tensor<10xi32>, tensor) -> tensor<10xi32> return %1, %arg1, %arg2, %2: tensor, tensor, tensor, tensor<10xi32> } -func @while_cond_40(%arg0: tensor, %arg1: tensor, %arg2: tensor, %arg3: tensor<10xi32>) -> tensor attributes {sym_visibility = "private"} { +func private @while_cond_40(%arg0: tensor, %arg1: tensor, %arg2: tensor, %arg3: tensor<10xi32>) -> tensor { %0 = "tosa.greater_equal"(%arg0, %arg1) : (tensor, tensor) -> tensor %1 = "tosa.logical_not"(%0) : (tensor) -> tensor return %1 : tensor diff --git a/mlir/test/IR/core-ops.mlir b/mlir/test/IR/core-ops.mlir index fc712d4939ba..396211c10430 100644 --- a/mlir/test/IR/core-ops.mlir +++ b/mlir/test/IR/core-ops.mlir @@ -942,6 +942,3 @@ func @subtensor_insert(%t: tensor<8x16x4xf32>, %t2: tensor<16x32x8xf32>, %idx : return } - -// CHECK-LABEL: func private @legacy_visibility_syntax -func @legacy_visibility_syntax() attri
[llvm-branch-commits] [mlir] 25007b4 - [MLIR][NFC] Change FunctionLike::setAllArgAttrs/setAllResultAttrs to do a one-shot attribute update.
Author: Rahul Joshi Date: 2020-12-28T14:15:47-08:00 New Revision: 25007b4d7e094c569d512770bd2397d8667fd3db URL: https://github.com/llvm/llvm-project/commit/25007b4d7e094c569d512770bd2397d8667fd3db DIFF: https://github.com/llvm/llvm-project/commit/25007b4d7e094c569d512770bd2397d8667fd3db.diff LOG: [MLIR][NFC] Change FunctionLike::setAllArgAttrs/setAllResultAttrs to do a one-shot attribute update. - Change FunctionLike::setAllArgAttrs() and setAllResultAttrs() to rebuild the new list of function attributes locally and call setAttr() just once instead of calling setArgAttr()/setResultAttrs() for each argument which incrementally build the attribute dictionary and can end up creating a lot of unused DictionaryAttr's (which are uniqued and nor garbage collected). Differential Revision: https://reviews.llvm.org/D93870 Added: Modified: mlir/include/mlir/IR/FunctionSupport.h Removed: diff --git a/mlir/include/mlir/IR/FunctionSupport.h b/mlir/include/mlir/IR/FunctionSupport.h index fd50e0dbb512..481dc5a6986f 100644 --- a/mlir/include/mlir/IR/FunctionSupport.h +++ b/mlir/include/mlir/IR/FunctionSupport.h @@ -333,11 +333,7 @@ class FunctionLike : public OpTrait::TraitBase { /// Set the attributes held by the argument at 'index'. `attributes` may be /// null, in which case any existing argument attributes are removed. void setArgAttrs(unsigned index, DictionaryAttr attributes); - void setAllArgAttrs(ArrayRef attributes) { -assert(attributes.size() == getNumArguments()); -for (unsigned i = 0, e = attributes.size(); i != e; ++i) - setArgAttrs(i, attributes[i]); - } + void setAllArgAttrs(ArrayRef attributes); /// If the an attribute exists with the specified name, change it to the new /// value. Otherwise, add a new attribute with the specified name/value. @@ -400,11 +396,7 @@ class FunctionLike : public OpTrait::TraitBase { /// Set the attributes held by the result at 'index'. `attributes` may be /// null, in which case any existing argument attributes are removed. void setResultAttrs(unsigned index, DictionaryAttr attributes); - void setAllResultAttrs(ArrayRef attributes) { -assert(attributes.size() == getNumResults()); -for (unsigned i = 0, e = attributes.size(); i != e; ++i) - setResultAttrs(i, attributes[i]); - } + void setAllResultAttrs(ArrayRef attributes); /// If the an attribute exists with the specified name, change it to the new /// value. Otherwise, add a new attribute with the specified name/value. @@ -591,6 +583,26 @@ void FunctionLike::setArgAttrs(unsigned index, attributes); } +template +void FunctionLike::setAllArgAttrs( +ArrayRef attributes) { + assert(attributes.size() == getNumArguments()); + NamedAttrList attrs = this->getOperation()->getAttrs(); + + // Instead of calling setArgAttrs() multiple times, which rebuild the + // attribute dictionary every time, build a new list of attributes for the + // operation so that we rebuild the attribute dictionary in one shot. + SmallString<8> argAttrName; + for (unsigned i = 0, e = attributes.size(); i != e; ++i) { +StringRef attrName = getArgAttrName(i, argAttrName); +if (!attributes[i] || attributes[i].empty()) + attrs.erase(attrName); +else + attrs.set(attrName, attributes[i]); + } + this->getOperation()->setAttrs(attrs); +} + /// If the an attribute exists with the specified name, change it to the new /// value. Otherwise, add a new attribute with the specified name/value. template @@ -648,6 +660,26 @@ void FunctionLike::setResultAttrs(unsigned index, attributes); } +template +void FunctionLike::setAllResultAttrs( +ArrayRef attributes) { + assert(attributes.size() == getNumResults()); + NamedAttrList attrs = this->getOperation()->getAttrs(); + + // Instead of calling setResultAttrs() multiple times, which rebuild the + // attribute dictionary every time, build a new list of attributes for the + // operation so that we rebuild the attribute dictionary in one shot. + SmallString<8> resultAttrName; + for (unsigned i = 0, e = attributes.size(); i != e; ++i) { +StringRef attrName = getResultAttrName(i, resultAttrName); +if (!attributes[i] || attributes[i].empty()) + attrs.erase(attrName); +else + attrs.set(attrName, attributes[i]); + } + this->getOperation()->setAttrs(attrs); +} + /// If the an attribute exists with the specified name, change it to the new /// value. Otherwise, add a new attribute with the specified name/value. template ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] 6b043ec - [MLIR] Fix genTypeInterfaceMethods() to work correctly with InferTypeOpInterface
Author: Rahul Joshi Date: 2020-12-01T13:36:25-08:00 New Revision: 6b043ecdb71bb0354cbd64d766cc21b7d20dca84 URL: https://github.com/llvm/llvm-project/commit/6b043ecdb71bb0354cbd64d766cc21b7d20dca84 DIFF: https://github.com/llvm/llvm-project/commit/6b043ecdb71bb0354cbd64d766cc21b7d20dca84.diff LOG: [MLIR] Fix genTypeInterfaceMethods() to work correctly with InferTypeOpInterface - Change InferTypeOpInterface::inferResultTypes to use fully qualified types matching the ones generated by genTypeInterfaceMethods, so the redundancy can be detected. - Move genTypeInterfaceMethods() before genOpInterfaceMethods() so that the inferResultTypes method generated by genTypeInterfaceMethods() takes precedence over the declaration that might be generated by genOpInterfaceMethods() - Modified an op in the test dialect to exercise this (the modified op would fail to generate valid C++ code due to duplicate inferResultTypes methods). Differential Revision: https://reviews.llvm.org/D92414 Added: Modified: mlir/include/mlir/Interfaces/InferTypeOpInterface.td mlir/test/lib/Dialect/Test/TestOps.td mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp Removed: diff --git a/mlir/include/mlir/Interfaces/InferTypeOpInterface.td b/mlir/include/mlir/Interfaces/InferTypeOpInterface.td index c5132986ec97..ed62e9015bde 100644 --- a/mlir/include/mlir/Interfaces/InferTypeOpInterface.td +++ b/mlir/include/mlir/Interfaces/InferTypeOpInterface.td @@ -38,19 +38,20 @@ def InferTypeOpInterface : OpInterface<"InferTypeOpInterface"> { }], /*retTy=*/"LogicalResult", /*methodName=*/"inferReturnTypes", - /*args=*/(ins "MLIRContext*":$context, -"Optional":$location, -"ValueRange":$operands, -"DictionaryAttr":$attributes, -"RegionRange":$regions, -"SmallVectorImpl&":$inferredReturnTypes) + /*args=*/(ins "::mlir::MLIRContext *":$context, +"::llvm::Optional<::mlir::Location>":$location, +"::mlir::ValueRange":$operands, +"::mlir::DictionaryAttr":$attributes, +"::mlir::RegionRange":$regions, + "::llvm::SmallVectorImpl<::mlir::Type>&":$inferredReturnTypes) >, StaticInterfaceMethod< /*desc=*/"Returns whether two array of types are compatible result types" " for an op.", /*retTy=*/"bool", /*methodName=*/"isCompatibleReturnTypes", - /*args=*/(ins "ArrayRef":$lhs, "ArrayRef":$rhs), + /*args=*/(ins "::llvm::ArrayRef<::mlir::Type>":$lhs, +"::llvm::ArrayRef<::mlir::Type>":$rhs), /*methodBody=*/[{ return ConcreteOp::isCompatibleReturnTypes(lhs, rhs); }], diff --git a/mlir/test/lib/Dialect/Test/TestOps.td b/mlir/test/lib/Dialect/Test/TestOps.td index 5a17eebfd32c..995022ab2115 100644 --- a/mlir/test/lib/Dialect/Test/TestOps.td +++ b/mlir/test/lib/Dialect/Test/TestOps.td @@ -1000,7 +1000,7 @@ def ThreeResultOp : TEST_Op<"three_result"> { let results = (outs I32:$result1, F32:$result2, F32:$result3); } -def AnotherThreeResultOp : TEST_Op<"another_three_result"> { +def AnotherThreeResultOp : TEST_Op<"another_three_result", [DeclareOpInterfaceMethods]> { let arguments = (ins MultiResultOpEnum:$kind); let results = (outs I32:$result1, F32:$result2, F32:$result3); } diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp index 65ae32f4f5a4..eabdd06fad5d 100644 --- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp +++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp @@ -453,10 +453,10 @@ OpEmitter::OpEmitter(const Operator &op) genVerifier(); genCanonicalizerDecls(); genFolderDecls(); + genTypeInterfaceMethods(); genOpInterfaceMethods(); generateOpFormat(op, opClass); genSideEffectInterfaceMethods(); - genTypeInterfaceMethods(); } void OpEmitter::emitDecl(const Operator &op, raw_ostream &os) { @@ -1739,7 +1739,6 @@ void OpEmitter::genTypeInterfaceMethods() { auto *method = opClass.addMethodAndPrune("::mlir::LogicalResult", "inferReturnTypes", OpMethod::MP_Static, std::move(paramList)); - auto &body = method->body(); body << " inferredReturnTypes.resize(" << op.getNumResults() << ");\n"; ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] fe7fdca - [MLIR] Fix parseFunctionLikeOp() to fail parsing empty regions
Author: Rahul Joshi Date: 2020-12-04T09:09:59-08:00 New Revision: fe7fdcac87be4ad3de34901eb6fb5746437610e8 URL: https://github.com/llvm/llvm-project/commit/fe7fdcac87be4ad3de34901eb6fb5746437610e8 DIFF: https://github.com/llvm/llvm-project/commit/fe7fdcac87be4ad3de34901eb6fb5746437610e8.diff LOG: [MLIR] Fix parseFunctionLikeOp() to fail parsing empty regions - Change parseOptionalRegion to return an OptionalParseResult. - Change parseFunctionLikeOp() to fail parsing if the function body was parsed but was empty. - See https://llvm.discourse.group/t/funcop-parsing-bug/2164 Differential Revision: https://reviews.llvm.org/D91886 Added: Modified: flang/include/flang/Optimizer/Dialect/FIROps.td mlir/include/mlir/IR/OpImplementation.h mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp mlir/lib/Dialect/SPIRV/SPIRVOps.cpp mlir/lib/IR/FunctionImplementation.cpp mlir/lib/Parser/Parser.cpp mlir/test/Dialect/SCF/canonicalize.mlir mlir/test/IR/invalid.mlir mlir/test/IR/traits.mlir mlir/tools/mlir-tblgen/OpFormatGen.cpp Removed: diff --git a/flang/include/flang/Optimizer/Dialect/FIROps.td b/flang/include/flang/Optimizer/Dialect/FIROps.td index c0448eca03dc..74471cf6f222 100644 --- a/flang/include/flang/Optimizer/Dialect/FIROps.td +++ b/flang/include/flang/Optimizer/Dialect/FIROps.td @@ -2856,7 +2856,8 @@ def fir_DispatchTableOp : fir_Op<"dispatch_table", // Parse the optional table body. mlir::Region *body = result.addRegion(); -if (parser.parseOptionalRegion(*body, llvm::None, llvm::None)) +OptionalParseResult parseResult = parser.parseOptionalRegion(*body); +if (parseResult.hasValue() && failed(*parseResult)) return mlir::failure(); ensureTerminator(*body, parser.getBuilder(), result.location); diff --git a/mlir/include/mlir/IR/OpImplementation.h b/mlir/include/mlir/IR/OpImplementation.h index 5cf05e058166..a7e87dc0ab06 100644 --- a/mlir/include/mlir/IR/OpImplementation.h +++ b/mlir/include/mlir/IR/OpImplementation.h @@ -646,23 +646,23 @@ class OpAsmParser { // Region Parsing //======// - /// Parses a region. Any parsed blocks are appended to "region" and must be + /// Parses a region. Any parsed blocks are appended to 'region' and must be /// moved to the op regions after the op is created. The first block of the - /// region takes "arguments" of types "argTypes". If "enableNameShadowing" is + /// region takes 'arguments' of types 'argTypes'. If 'enableNameShadowing' is /// set to true, the argument names are allowed to shadow the names of other - /// existing SSA values defined above the region scope. "enableNameShadowing" + /// existing SSA values defined above the region scope. 'enableNameShadowing' /// can only be set to true for regions attached to operations that are - /// "IsolatedFromAbove". + /// 'IsolatedFromAbove. virtual ParseResult parseRegion(Region ®ion, ArrayRef arguments = {}, ArrayRef argTypes = {}, bool enableNameShadowing = false) = 0; /// Parses a region if present. - virtual ParseResult parseOptionalRegion(Region ®ion, - ArrayRef arguments = {}, - ArrayRef argTypes = {}, - bool enableNameShadowing = false) = 0; + virtual OptionalParseResult + parseOptionalRegion(Region ®ion, ArrayRef arguments = {}, + ArrayRef argTypes = {}, + bool enableNameShadowing = false) = 0; /// Parses a region if present. If the region is present, a new region is /// allocated and placed in `region`. If no region is present or on failure, diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp index 76182c7868d7..f481b702822b 100644 --- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp @@ -1187,9 +1187,12 @@ static ParseResult parseGlobalOp(OpAsmParser &parser, OperationState &result) { return parser.emitError(parser.getNameLoc(), "type can only be omitted for string globals"); } - } else if (parser.parseOptionalRegion(initRegion, /*arguments=*/{}, -/*argTypes=*/{})) { -return failure(); + } else { +OptionalParseResult parseResult = +parser.parseOptionalRegion(initRegion, /*arguments=*/{}, + /*argTypes=*/{}); +if (parseResult.hasValue() && failed(*parseResult)) + return failure(); } result.addAttribute("type", TypeAttr::get(types[0])); @@ -1398,8 +1401,9 @@ static ParseResult parseLLVMFuncOp(OpAsmParser &parser,
[llvm-branch-commits] [mlir] 2452334 - [MLIR] Generate inferReturnTypes declaration using InferTypeOpInterface trait.
Author: Rahul Joshi Date: 2020-12-04T09:05:53-08:00 New Revision: 245233423e466979e11b39cbed676903892d07f8 URL: https://github.com/llvm/llvm-project/commit/245233423e466979e11b39cbed676903892d07f8 DIFF: https://github.com/llvm/llvm-project/commit/245233423e466979e11b39cbed676903892d07f8.diff LOG: [MLIR] Generate inferReturnTypes declaration using InferTypeOpInterface trait. - Instead of hardcoding the parameters and return types of 'inferReturnTypes', use the InferTypeOpInterface trait to generate the method declaration. - Fix InferTypeOfInterface to use fully qualified type for inferReturnTypes results. Differential Revision: https://reviews.llvm.org/D92585 Added: Modified: mlir/include/mlir/Interfaces/InferTypeOpInterface.td mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp Removed: diff --git a/mlir/include/mlir/Interfaces/InferTypeOpInterface.td b/mlir/include/mlir/Interfaces/InferTypeOpInterface.td index ed62e9015bde..9de087b1b4ca 100644 --- a/mlir/include/mlir/Interfaces/InferTypeOpInterface.td +++ b/mlir/include/mlir/Interfaces/InferTypeOpInterface.td @@ -36,7 +36,7 @@ def InferTypeOpInterface : OpInterface<"InferTypeOpInterface"> { which an Operation would be created (e.g., as used in Operation::create) and the regions of the op. }], - /*retTy=*/"LogicalResult", + /*retTy=*/"::mlir::LogicalResult", /*methodName=*/"inferReturnTypes", /*args=*/(ins "::mlir::MLIRContext *":$context, "::llvm::Optional<::mlir::Location>":$location, diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp index c96fde648eb2..ccfb13fa3436 100644 --- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp +++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp @@ -290,11 +290,16 @@ class OpEmitter { // Generates the traits used by the object. void genTraits(); - // Generate the OpInterface methods. + // Generate the OpInterface methods for all interfaces. void genOpInterfaceMethods(); - // Generate op interface method. - void genOpInterfaceMethod(const tblgen::InterfaceOpTrait *trait); + // Generate op interface methods for the given interface. + void genOpInterfaceMethods(const tblgen::InterfaceOpTrait *trait); + + // Generate op interface method for the given interface method. If + // 'declaration' is true, generates a declaration, else a definition. + OpMethod *genOpInterfaceMethod(const tblgen::InterfaceMethod &method, + bool declaration = true); // Generate the side effect interface methods. void genSideEffectInterfaceMethods(); @@ -1588,7 +1593,7 @@ void OpEmitter::genFolderDecls() { } } -void OpEmitter::genOpInterfaceMethod(const tblgen::InterfaceOpTrait *opTrait) { +void OpEmitter::genOpInterfaceMethods(const tblgen::InterfaceOpTrait *opTrait) { auto interface = opTrait->getOpInterface(); // Get the set of methods that should always be declared. @@ -1606,23 +1611,29 @@ void OpEmitter::genOpInterfaceMethod(const tblgen::InterfaceOpTrait *opTrait) { if (method.getDefaultImplementation() && !alwaysDeclaredMethods.count(method.getName())) continue; - -SmallVector paramList; -for (const InterfaceMethod::Argument &arg : method.getArguments()) - paramList.emplace_back(arg.type, arg.name); - -auto properties = method.isStatic() ? OpMethod::MP_StaticDeclaration -: OpMethod::MP_Declaration; -opClass.addMethodAndPrune(method.getReturnType(), method.getName(), - properties, std::move(paramList)); +genOpInterfaceMethod(method); } } +OpMethod *OpEmitter::genOpInterfaceMethod(const InterfaceMethod &method, + bool declaration) { + SmallVector paramList; + for (const InterfaceMethod::Argument &arg : method.getArguments()) +paramList.emplace_back(arg.type, arg.name); + + auto properties = method.isStatic() ? OpMethod::MP_Static : OpMethod::MP_None; + if (declaration) +properties = +static_cast(properties | OpMethod::MP_Declaration); + return opClass.addMethodAndPrune(method.getReturnType(), method.getName(), + properties, std::move(paramList)); +} + void OpEmitter::genOpInterfaceMethods() { for (const auto &trait : op.getTraits()) { if (const auto *opTrait = dyn_cast(&trait)) if (opTrait->shouldDeclareMethods()) -genOpInterfaceMethod(opTrait); +genOpInterfaceMethods(opTrait); } } @@ -1727,18 +1738,20 @@ void OpEmitter::genSideEffectInterfaceMethods() { void OpEmitter::genTypeInterfaceMethods() { if (!op.allResultTypesKnown()) return; - - SmallVector paramList; - paramList.emplace_back("::mlir::MLIRContext *", "context"); - paramList.emplace_back("::llvm::Optional<::mlir::Location>",
[llvm-branch-commits] [mlir] b0d02b6 - [MLIR] Minor cleanup for Shape dialect.
Author: Rahul Joshi Date: 2020-12-09T14:21:35-08:00 New Revision: b0d02b698b94d2fc5f7fbd430f5e9d3b032f8523 URL: https://github.com/llvm/llvm-project/commit/b0d02b698b94d2fc5f7fbd430f5e9d3b032f8523 DIFF: https://github.com/llvm/llvm-project/commit/b0d02b698b94d2fc5f7fbd430f5e9d3b032f8523.diff LOG: [MLIR] Minor cleanup for Shape dialect. - Remove some unused types from the Shape dialect - Fix from_extent_tensor to only allow 1D index tensors - Fix assuming_yield to only allow shape.assuming as the parent op. - Fix some documentation typos and reword some things. Differential Revision: https://reviews.llvm.org/D92901 Added: Modified: mlir/include/mlir/Dialect/Shape/IR/Shape.h mlir/include/mlir/Dialect/Shape/IR/ShapeBase.td mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td mlir/lib/Dialect/Shape/IR/Shape.cpp Removed: diff --git a/mlir/include/mlir/Dialect/Shape/IR/Shape.h b/mlir/include/mlir/Dialect/Shape/IR/Shape.h index eab3c6f67ca0..db2862141ea9 100644 --- a/mlir/include/mlir/Dialect/Shape/IR/Shape.h +++ b/mlir/include/mlir/Dialect/Shape/IR/Shape.h @@ -31,18 +31,6 @@ namespace shape { /// Alias type for extent tensors. RankedTensorType getExtentTensorType(MLIRContext *ctx); -/// The component type corresponding to shape, element type and attribute. -class ComponentType : public Type::TypeBase { -public: - using Base::Base; -}; - -/// The element type of the shaped type. -class ElementType : public Type::TypeBase { -public: - using Base::Base; -}; - /// The shape descriptor type represents rank and dimension sizes. class ShapeType : public Type::TypeBase { public: diff --git a/mlir/include/mlir/Dialect/Shape/IR/ShapeBase.td b/mlir/include/mlir/Dialect/Shape/IR/ShapeBase.td index c9103a2b8b63..a7868e74c65f 100644 --- a/mlir/include/mlir/Dialect/Shape/IR/ShapeBase.td +++ b/mlir/include/mlir/Dialect/Shape/IR/ShapeBase.td @@ -39,29 +39,11 @@ def ShapeDialect : Dialect { let hasConstantMaterializer = 1; } -def Shape_ComponentType : DialectType()">, "component type">, -BuildableType<"$_builder.getType<::mlir::shape::ComponentType>()"> { - let typeDescription = [{ -`shape.component_type` represents the tuple of shape, element type and -attribute. - }]; -} - -def Shape_ElementType : DialectType()">, "element type">, -BuildableType<"$_builder.getType<::mlir::shape::ElementType>()"> { - let typeDescription = [{ -`shape.element_type` represents the element type of the ShapedType. It may -be unknown, error or regular element type supported by ShapedType. - }]; -} - def Shape_ShapeType : DialectType()">, "shape">, BuildableType<"$_builder.getType<::mlir::shape::ShapeType>()"> { let typeDescription = [{ -`shape.type` represents either an unranked shape, a ranked shape with +`shape.shape` represents either an unranked shape, a ranked shape with possibly unknown dimensions or an invalid shape. The rank is of type `shape.size` and, if rank is known, the extent is a 1D tensor of type `shape.size`. @@ -96,12 +78,12 @@ def Shape_ValueShapeType : DialectType())"> { let typeDescription = [{ The extent tensor is a tensor of rank one with arbitrarily many index -elements. Like `!shape.shape`, it is used to represent shapes with the - diff erence that it is guaranteed to be error-free. +elements (tensor). Like `!shape.shape`, it is used to represent +shapes with the diff erence that it is guaranteed to be error-free. }]; } diff --git a/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td b/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td index 552de7e78f91..0cbb910e062c 100644 --- a/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td +++ b/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td @@ -34,7 +34,9 @@ def Shape_AddOp : Shape_Op<"add", [Commutative, NoSideEffect]> { Adds two sizes or indices. If either operand is an error it will be propagated to the result. The operands can be of type `size` or `index`. If at least one of the operands can hold an error, i.e. if it is of type `size`, -then also the result must be of type `size`. +the result must be of type `size`. If error propagation is not possible +because both operands are of type `index` then the result may be of type +`size` or `index`. }]; let arguments = (ins Shape_SizeOrIndexType:$lhs, Shape_SizeOrIndexType:$rhs); @@ -177,7 +179,7 @@ def Shape_FromExtentTensorOp : Shape_Op<"from_extent_tensor", [NoSideEffect]> { extents match the values of the elements. }]; - let arguments = (ins IndexTensor:$input); + let arguments = (ins 1DTensorOf<[Index]>:$input); let results = (outs Shape_ShapeType:$result); let assemblyFormat = "$input attr-dict `:` type($input)"; @@ -247,7 +249,7 @@ def Shape_GetExtentOp : Shape_Op<"get_extent", [NoSideEffect]> { let summary = "Gets the specified extent from a shape or
[llvm-branch-commits] [mlir] 563879b - [NFC] Use ConvertOpToLLVMPattern instead of ConvertToLLVMPattern.
Author: Rahul Joshi Date: 2020-12-10T09:33:43-08:00 New Revision: 563879b6f9465982b422a69a901e3d84e7cb7764 URL: https://github.com/llvm/llvm-project/commit/563879b6f9465982b422a69a901e3d84e7cb7764 DIFF: https://github.com/llvm/llvm-project/commit/563879b6f9465982b422a69a901e3d84e7cb7764.diff LOG: [NFC] Use ConvertOpToLLVMPattern instead of ConvertToLLVMPattern. - use ConvertOpToLLVMPattern to avoid explicit casting and in most cases the constructor can be reused to save a few lines of code. Differential Revision: https://reviews.llvm.org/D92989 Added: Modified: mlir/include/mlir/Conversion/LinalgToLLVM/LinalgToLLVM.h mlir/include/mlir/Conversion/OpenMPToLLVM/ConvertOpenMPToLLVM.h mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h mlir/lib/Conversion/AVX512ToLLVM/ConvertAVX512ToLLVM.cpp mlir/lib/Conversion/GPUCommon/GPUOpsLowering.h mlir/lib/Conversion/GPUCommon/IndexIntrinsicsOpLowering.h mlir/lib/Conversion/GPUCommon/OpToFuncCallLowering.h mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp mlir/lib/Conversion/LinalgToLLVM/LinalgToLLVM.cpp mlir/lib/Conversion/OpenMPToLLVM/OpenMPToLLVM.cpp mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp mlir/lib/Conversion/VectorToROCDL/VectorToROCDL.cpp Removed: diff --git a/mlir/include/mlir/Conversion/LinalgToLLVM/LinalgToLLVM.h b/mlir/include/mlir/Conversion/LinalgToLLVM/LinalgToLLVM.h index b7c9d0016d65..948c2a4be6f2 100644 --- a/mlir/include/mlir/Conversion/LinalgToLLVM/LinalgToLLVM.h +++ b/mlir/include/mlir/Conversion/LinalgToLLVM/LinalgToLLVM.h @@ -18,8 +18,7 @@ template class OperationPass; /// Populate the given list with patterns that convert from Linalg to LLVM. void populateLinalgToLLVMConversionPatterns(LLVMTypeConverter &converter, -OwningRewritePatternList &patterns, -MLIRContext *ctx); +OwningRewritePatternList &patterns); /// Create a pass to convert Linalg operations to the LLVMIR dialect. std::unique_ptr> createConvertLinalgToLLVMPass(); diff --git a/mlir/include/mlir/Conversion/OpenMPToLLVM/ConvertOpenMPToLLVM.h b/mlir/include/mlir/Conversion/OpenMPToLLVM/ConvertOpenMPToLLVM.h index ace07ac7223b..4eae84cd0135 100644 --- a/mlir/include/mlir/Conversion/OpenMPToLLVM/ConvertOpenMPToLLVM.h +++ b/mlir/include/mlir/Conversion/OpenMPToLLVM/ConvertOpenMPToLLVM.h @@ -19,8 +19,7 @@ class OperationPass; class OwningRewritePatternList; /// Populate the given list with patterns that convert from OpenMP to LLVM. -void populateOpenMPToLLVMConversionPatterns(MLIRContext *context, -LLVMTypeConverter &converter, +void populateOpenMPToLLVMConversionPatterns(LLVMTypeConverter &converter, OwningRewritePatternList &patterns); /// Create a pass to convert OpenMP operations to the LLVMIR dialect. diff --git a/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h b/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h index bf41f29749de..7c069c9cd556 100644 --- a/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h +++ b/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h @@ -565,8 +565,8 @@ class ConvertToLLVMPattern : public ConversionPattern { template class ConvertOpToLLVMPattern : public ConvertToLLVMPattern { public: - ConvertOpToLLVMPattern(LLVMTypeConverter &typeConverter, - PatternBenefit benefit = 1) + explicit ConvertOpToLLVMPattern(LLVMTypeConverter &typeConverter, + PatternBenefit benefit = 1) : ConvertToLLVMPattern(SourceOp::getOperationName(), &typeConverter.getContext(), typeConverter, benefit) {} diff --git a/mlir/lib/Conversion/AVX512ToLLVM/ConvertAVX512ToLLVM.cpp b/mlir/lib/Conversion/AVX512ToLLVM/ConvertAVX512ToLLVM.cpp index fe06e12c8f21..06a19b057f71 100644 --- a/mlir/lib/Conversion/AVX512ToLLVM/ConvertAVX512ToLLVM.cpp +++ b/mlir/lib/Conversion/AVX512ToLLVM/ConvertAVX512ToLLVM.cpp @@ -34,8 +34,7 @@ static Type getSrcVectorElementType(OpTy op) { /// operands as is, preserve attributes. template static LogicalResult -matchAndRewriteOneToOne(const ConvertToLLVMPattern &lowering, -LLVMTypeConverter &typeConverter, Operation *op, +matchAndRewriteOneToOne(LLVMTypeConverter &typeConverter, Operation *op, ArrayRef operands, ConversionPatternRewriter &rewriter) { unsigned numResults = op->getNumResults(); @@ -73,71 +72,61 @@ namespace { // TODO: Patterns are too verbose due to the fact that we have 1 op (e.g. // MaskRndScaleOp) and diff erent possible target ops. It wou
[llvm-branch-commits] [llvm] release/20.x: [TableGen] Don't use inline storage for ReferenceLocs (NFC) (#125231) (PR #125287)
https://github.com/jurahul approved this pull request. LGTM but also let @arsenm take a look for the GISel match tables changes (I did not review that PR). https://github.com/llvm/llvm-project/pull/125287 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [utils][TableGen] Unify converting names to upper-camel case (PR #141762)
@@ -113,14 +113,39 @@ class BaseRecord { // Returns the name of the directive formatted for output. Whitespace are // replaced with underscores. - static std::string formatName(StringRef Name) { + static std::string getSnakeName(StringRef Name) { std::string N = Name.str(); llvm::replace(N, ' ', '_'); return N; } + static std::string getUpperCamelName(StringRef Name, StringRef Sep) { jurahul wrote: Can you add a small comment describing what the function does and maybe a sample input/output? https://github.com/llvm/llvm-project/pull/141762 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [utils][TableGen] Unify converting names to upper-camel case (PR #141762)
https://github.com/jurahul approved this pull request. LGTM with a small comment https://github.com/llvm/llvm-project/pull/141762 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits