diff --git a/mlir/include/mlir/Dialect/GPU/IR/CMakeLists.txt b/mlir/include/mlir/Dialect/GPU/IR/CMakeLists.txt --- a/mlir/include/mlir/Dialect/GPU/IR/CMakeLists.txt +++ b/mlir/include/mlir/Dialect/GPU/IR/CMakeLists.txt @@ -6,11 +6,6 @@ mlir_tablegen(GPUOpInterfaces.cpp.inc -gen-op-interface-defs) add_public_tablegen_target(MLIRGPUOpInterfacesIncGen) -set(LLVM_TARGET_DEFINITIONS ParallelLoopMapperAttr.td) -mlir_tablegen(ParallelLoopMapperAttr.h.inc -gen-struct-attr-decls) -mlir_tablegen(ParallelLoopMapperAttr.cpp.inc -gen-struct-attr-defs) -add_public_tablegen_target(MLIRParallelLoopMapperAttrGen) - set(LLVM_TARGET_DEFINITIONS ParallelLoopMapperAttr.td) mlir_tablegen(ParallelLoopMapperEnums.h.inc -gen-enum-decls) mlir_tablegen(ParallelLoopMapperEnums.cpp.inc -gen-enum-defs) diff --git a/mlir/include/mlir/Dialect/LLVMIR/CMakeLists.txt b/mlir/include/mlir/Dialect/LLVMIR/CMakeLists.txt --- a/mlir/include/mlir/Dialect/LLVMIR/CMakeLists.txt +++ b/mlir/include/mlir/Dialect/LLVMIR/CMakeLists.txt @@ -46,8 +46,6 @@ mlir_tablegen(NVVMConversions.inc -gen-llvmir-conversions) mlir_tablegen(NVVMOpsEnums.h.inc -gen-enum-decls) mlir_tablegen(NVVMOpsEnums.cpp.inc -gen-enum-defs) -mlir_tablegen(NVVMOpsStructs.h.inc -gen-struct-attr-decls) -mlir_tablegen(NVVMOpsStructs.cpp.inc -gen-struct-attr-defs) mlir_tablegen(NVVMOpsAttributes.h.inc -gen-attrdef-decls -attrdefs-dialect=nvvm) mlir_tablegen(NVVMOpsAttributes.cpp.inc -gen-attrdef-defs -attrdefs-dialect=nvvm) add_public_tablegen_target(MLIRNVVMConversionsIncGen) diff --git a/mlir/include/mlir/Dialect/LLVMIR/NVVMDialect.h b/mlir/include/mlir/Dialect/LLVMIR/NVVMDialect.h --- a/mlir/include/mlir/Dialect/LLVMIR/NVVMDialect.h +++ b/mlir/include/mlir/Dialect/LLVMIR/NVVMDialect.h @@ -21,7 +21,6 @@ #include "llvm/IR/IntrinsicsNVPTX.h" #include "mlir/Dialect/LLVMIR/NVVMOpsEnums.h.inc" -#include "mlir/Dialect/LLVMIR/NVVMOpsStructs.h.inc" namespace mlir { namespace NVVM { diff --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td --- a/mlir/include/mlir/IR/OpBase.td +++ b/mlir/include/mlir/IR/OpBase.td @@ -1447,45 +1447,6 @@ def IndexListArrayAttr : TypedArrayAttrBase; -// Attribute information for an Attribute field within a StructAttr. -class StructFieldAttr - : Deprecated<"StructAttr is being removed on June 20"> { - // Name of this field in the StructAttr. - string name = thisName; - - // Attribute type wrapped by the struct attr. - Attr type = thisType; -} - -// Structured attribute that wraps a DictionaryAttr and provides both a -// validation method and set of accessors for a fixed set of fields. This is -// useful when representing data that would normally be in a structure. -class StructAttr attributes> : - Deprecated<"StructAttr is being removed on June 20">, - DictionaryAttrBase()">, - "DictionaryAttr with field(s): " # - !interleave(!foreach(a, attributes, "'" # a.name # "'"), ", ") # - " (each field having its own constraints)"> { - // Name for this StructAttr. - string className = name; - - // Return type should match the name of the structure. - let returnType = d.cppNamespace # "::" # name; - - // Storage type should match the name of the structure. - let storageType = d.cppNamespace # "::" # name; - - // The dialect this StructAttr belongs to. - Dialect dialect = d; - - let cppNamespace = d.cppNamespace; - - // List of fields that the StructAttr contains. - list fields = attributes; -} - // Attributes containing symbol references. def SymbolRefAttr : Attr()">, "symbol reference attribute"> { diff --git a/mlir/include/mlir/TableGen/Attribute.h b/mlir/include/mlir/TableGen/Attribute.h --- a/mlir/include/mlir/TableGen/Attribute.h +++ b/mlir/include/mlir/TableGen/Attribute.h @@ -206,36 +206,6 @@ bool printBitEnumPrimaryGroups() const; }; -class StructFieldAttr { -public: - explicit StructFieldAttr(const llvm::Record *record); - explicit StructFieldAttr(const llvm::Record &record); - explicit StructFieldAttr(const llvm::DefInit *init); - - StringRef getName() const; - Attribute getType() const; - -private: - const llvm::Record *def; -}; - -// Wrapper class providing helper methods for accessing struct attributes -// defined in TableGen. -class StructAttr : public Attribute { -public: - explicit StructAttr(const llvm::Record *record); - explicit StructAttr(const llvm::Record &record) : StructAttr(&record){}; - explicit StructAttr(const llvm::DefInit *init); - - // Returns the struct class name. - StringRef getStructClassName() const; - - // Returns the C++ namespaces this struct class should be placed in. - StringRef getCppNamespace() const; - - std::vector getAllFields() const; -}; - // Name of infer type op interface. extern const char *inferTypeOpInterface; diff --git a/mlir/lib/Dialect/GPU/CMakeLists.txt b/mlir/lib/Dialect/GPU/CMakeLists.txt --- a/mlir/lib/Dialect/GPU/CMakeLists.txt +++ b/mlir/lib/Dialect/GPU/CMakeLists.txt @@ -61,7 +61,6 @@ DEPENDS MLIRGPUPassIncGen - MLIRParallelLoopMapperAttrGen MLIRParallelLoopMapperEnumsGen LINK_LIBS PUBLIC diff --git a/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp --- a/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp @@ -34,7 +34,6 @@ #include "mlir/Dialect/LLVMIR/NVVMOpsDialect.cpp.inc" #include "mlir/Dialect/LLVMIR/NVVMOpsEnums.cpp.inc" -#include "mlir/Dialect/LLVMIR/NVVMOpsStructs.cpp.inc" //===----------------------------------------------------------------------===// // Printing/parsing for NVVM ops diff --git a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp --- a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp +++ b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp @@ -33,7 +33,7 @@ #include "mlir/Dialect/Tosa/IR/TosaOpsDialect.cpp.inc" //===----------------------------------------------------------------------===// -// Tosa dialect structs and interface includes. +// Tosa dialect interface includes. //===----------------------------------------------------------------------===// #include "mlir/Dialect/Tosa/IR/TosaInterfaces.cpp.inc" diff --git a/mlir/lib/TableGen/Attribute.cpp b/mlir/lib/TableGen/Attribute.cpp --- a/mlir/lib/TableGen/Attribute.cpp +++ b/mlir/lib/TableGen/Attribute.cpp @@ -239,54 +239,4 @@ return def->getValueAsBit("printBitEnumPrimaryGroups"); } -StructFieldAttr::StructFieldAttr(const llvm::Record *record) : def(record) { - assert(def->isSubClassOf("StructFieldAttr") && - "must be subclass of TableGen 'StructFieldAttr' class"); -} - -StructFieldAttr::StructFieldAttr(const llvm::Record &record) - : StructFieldAttr(&record) {} - -StructFieldAttr::StructFieldAttr(const llvm::DefInit *init) - : StructFieldAttr(init->getDef()) {} - -StringRef StructFieldAttr::getName() const { - return def->getValueAsString("name"); -} - -Attribute StructFieldAttr::getType() const { - auto *init = def->getValueInit("type"); - return Attribute(cast(init)); -} - -StructAttr::StructAttr(const llvm::Record *record) : Attribute(record) { - assert(isSubClassOf("StructAttr") && - "must be subclass of TableGen 'StructAttr' class"); -} - -StructAttr::StructAttr(const llvm::DefInit *init) - : StructAttr(init->getDef()) {} - -StringRef StructAttr::getStructClassName() const { - return def->getValueAsString("className"); -} - -StringRef StructAttr::getCppNamespace() const { - Dialect dialect(def->getValueAsDef("dialect")); - return dialect.getCppNamespace(); -} - -std::vector StructAttr::getAllFields() const { - std::vector attributes; - - const auto *inits = def->getValueAsListInit("fields"); - attributes.reserve(inits->size()); - - for (const llvm::Init *init : *inits) { - attributes.emplace_back(cast(init)); - } - - return attributes; -} - const char * ::mlir::tblgen::inferTypeOpInterface = "InferTypeOpInterface"; diff --git a/mlir/test/IR/attribute.mlir b/mlir/test/IR/attribute.mlir --- a/mlir/test/IR/attribute.mlir +++ b/mlir/test/IR/attribute.mlir @@ -643,3 +643,4 @@ // expected-error @+1 {{invalid dialect namespace '"string with space"'}} #invalid_dialect = opaque<"string with space", "0xDEADBEEF"> : tensor<100xi32> + diff --git a/mlir/test/lib/Dialect/Test/CMakeLists.txt b/mlir/test/lib/Dialect/Test/CMakeLists.txt --- a/mlir/test/lib/Dialect/Test/CMakeLists.txt +++ b/mlir/test/lib/Dialect/Test/CMakeLists.txt @@ -30,8 +30,6 @@ mlir_tablegen(TestOpsDialect.cpp.inc -gen-dialect-defs -dialect=test) mlir_tablegen(TestOpEnums.h.inc -gen-enum-decls) mlir_tablegen(TestOpEnums.cpp.inc -gen-enum-defs) -mlir_tablegen(TestOpStructs.h.inc -gen-struct-attr-decls) -mlir_tablegen(TestOpStructs.cpp.inc -gen-struct-attr-defs) mlir_tablegen(TestPatterns.inc -gen-rewriters) add_public_tablegen_target(MLIRTestOpsIncGen) diff --git a/mlir/test/lib/Dialect/Test/TestDialect.h b/mlir/test/lib/Dialect/Test/TestDialect.h --- a/mlir/test/lib/Dialect/Test/TestDialect.h +++ b/mlir/test/lib/Dialect/Test/TestDialect.h @@ -45,7 +45,6 @@ } // namespace mlir #include "TestOpInterfaces.h.inc" -#include "TestOpStructs.h.inc" #include "TestOpsDialect.h.inc" #define GET_OP_CLASSES diff --git a/mlir/test/lib/Dialect/Test/TestDialect.cpp b/mlir/test/lib/Dialect/Test/TestDialect.cpp --- a/mlir/test/lib/Dialect/Test/TestDialect.cpp +++ b/mlir/test/lib/Dialect/Test/TestDialect.cpp @@ -1465,7 +1465,6 @@ #include "TestOpEnums.cpp.inc" #include "TestOpInterfaces.cpp.inc" -#include "TestOpStructs.cpp.inc" #include "TestTypeInterfaces.cpp.inc" #define GET_OP_CLASSES diff --git a/mlir/test/mlir-tblgen/op-attribute.td b/mlir/test/mlir-tblgen/op-attribute.td --- a/mlir/test/mlir-tblgen/op-attribute.td +++ b/mlir/test/mlir-tblgen/op-attribute.td @@ -480,19 +480,3 @@ // RECORD-LABEL: def SomeTypedArrayAttr // RECORD: Attr elementAttr = SomeAttr; - -def Test_Dialect_2 : Dialect { - let name = "dialect_2"; -} -def MyStruct : StructAttr<"MyStruct", Test_Dialect_2, -[StructFieldAttr<"potatoes", I64ElementsAttr>]> { - let summary = "A structure describing a number of potatoes."; -} - -def StructAttrOp : NS_Op<"struct_attr_op", []> { - let arguments = (ins - MyStruct:$potatoes - ); -} - -// DECL: dialect_2::MyStruct potatoes(); diff --git a/mlir/tools/mlir-tblgen/CMakeLists.txt b/mlir/tools/mlir-tblgen/CMakeLists.txt --- a/mlir/tools/mlir-tblgen/CMakeLists.txt +++ b/mlir/tools/mlir-tblgen/CMakeLists.txt @@ -27,7 +27,6 @@ PassGen.cpp RewriterGen.cpp SPIRVUtilsGen.cpp - StructsGen.cpp ) set_target_properties(mlir-tblgen PROPERTIES FOLDER "Tablegenning") diff --git a/mlir/tools/mlir-tblgen/StructsGen.cpp b/mlir/tools/mlir-tblgen/StructsGen.cpp deleted file mode 100644 --- a/mlir/tools/mlir-tblgen/StructsGen.cpp +++ /dev/null @@ -1,308 +0,0 @@ -//===- StructsGen.cpp - MLIR struct utility generator ---------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// -// StructsGen generates common utility functions for grouping attributes into a -// set of structured data. -// -//===----------------------------------------------------------------------===// - -#include "mlir/TableGen/Attribute.h" -#include "mlir/TableGen/Format.h" -#include "mlir/TableGen/GenInfo.h" -#include "mlir/TableGen/Operator.h" -#include "llvm/ADT/SmallVector.h" -#include "llvm/ADT/StringExtras.h" -#include "llvm/Support/FormatVariadic.h" -#include "llvm/Support/raw_ostream.h" -#include "llvm/TableGen/Error.h" -#include "llvm/TableGen/Record.h" -#include "llvm/TableGen/TableGenBackend.h" - -using llvm::raw_ostream; -using llvm::Record; -using llvm::RecordKeeper; -using llvm::StringRef; -using mlir::tblgen::FmtContext; -using mlir::tblgen::StructAttr; - -static void -emitStructClass(const Record &structDef, StringRef structName, - llvm::ArrayRef fields, - StringRef description, raw_ostream &os) { - const char *structInfo = R"( -// {0} -class {1} : public ::mlir::DictionaryAttr)"; - const char *structInfoEnd = R"( { -public: - using ::mlir::DictionaryAttr::DictionaryAttr; - static bool classof(::mlir::Attribute attr); -)"; - os << formatv(structInfo, description, structName) << structInfoEnd; - - // Declares a constructor function for the tablegen structure. - // TblgenStruct::get(MLIRContext context, Type1 Field1, Type2 Field2, ...); - const char *getInfoDecl = " static {0} get(\n"; - const char *getInfoDeclArg = " {0} {1},\n"; - const char *getInfoDeclEnd = " ::mlir::MLIRContext* context);\n\n"; - - os << llvm::formatv(getInfoDecl, structName); - - for (auto field : fields) { - auto name = field.getName(); - auto type = field.getType(); - auto storage = type.getStorageType(); - os << llvm::formatv(getInfoDeclArg, storage, name); - } - os << getInfoDeclEnd; - - // Declares an accessor for the fields owned by the tablegen structure. - // namespace::storage TblgenStruct::field1() const; - const char *fieldInfo = R"( {0} {1}() const; -)"; - for (auto field : fields) { - auto name = field.getName(); - auto type = field.getType(); - auto storage = type.getStorageType(); - os << formatv(fieldInfo, storage, name); - } - - os << "};\n\n"; -} - -static void emitStructDecl(const Record &structDef, raw_ostream &os) { - StructAttr structAttr(&structDef); - StringRef structName = structAttr.getStructClassName(); - StringRef cppNamespace = structAttr.getCppNamespace(); - StringRef description = structAttr.getSummary(); - auto fields = structAttr.getAllFields(); - - // Wrap in the appropriate namespace. - llvm::SmallVector namespaces; - llvm::SplitString(cppNamespace, namespaces, "::"); - - for (auto ns : namespaces) - os << "namespace " << ns << " {\n"; - - // Emit the struct class definition - emitStructClass(structDef, structName, fields, description, os); - - // Close the declared namespace. - for (auto ns : namespaces) - os << "} // namespace " << ns << "\n"; -} - -static bool emitStructDecls(const RecordKeeper &recordKeeper, raw_ostream &os) { - llvm::emitSourceFileHeader("Struct Utility Declarations", os); - - auto defs = recordKeeper.getAllDerivedDefinitions("StructAttr"); - for (const auto *def : defs) { - emitStructDecl(*def, os); - } - - return false; -} - -static void emitFactoryDef(llvm::StringRef structName, - llvm::ArrayRef fields, - raw_ostream &os) { - const char *getInfoDecl = "{0} {0}::get(\n"; - const char *getInfoDeclArg = " {0} {1},\n"; - const char *getInfoDeclEnd = " ::mlir::MLIRContext* context) {"; - - os << llvm::formatv(getInfoDecl, structName); - - for (auto field : fields) { - auto name = field.getName(); - auto type = field.getType(); - auto storage = type.getStorageType(); - os << llvm::formatv(getInfoDeclArg, storage, name); - } - os << getInfoDeclEnd; - - const char *fieldStart = R"( - ::llvm::SmallVector<::mlir::NamedAttribute, {0}> fields; -)"; - os << llvm::formatv(fieldStart, fields.size()); - - const char *getFieldInfo = R"( - assert({0}); - auto {0}_id = ::mlir::StringAttr::get(context, "{0}"); - fields.emplace_back({0}_id, {0}); -)"; - - const char *getFieldInfoOptional = R"( - if ({0}) { - auto {0}_id = ::mlir::StringAttr::get(context, "{0}"); - fields.emplace_back({0}_id, {0}); - } -)"; - - for (auto field : fields) { - if (field.getType().isOptional() || field.getType().hasDefaultValue()) - os << llvm::formatv(getFieldInfoOptional, field.getName()); - else - os << llvm::formatv(getFieldInfo, field.getName()); - } - - const char *getEndInfo = R"( - ::mlir::Attribute dict = ::mlir::DictionaryAttr::get(context, fields); - return dict.dyn_cast<{0}>(); -} -)"; - os << llvm::formatv(getEndInfo, structName); -} - -static void emitClassofDef(llvm::StringRef structName, - llvm::ArrayRef fields, - raw_ostream &os) { - const char *classofInfo = R"( -bool {0}::classof(::mlir::Attribute attr))"; - - const char *classofInfoHeader = R"( - if (!attr) - return false; - auto derived = attr.dyn_cast<::mlir::DictionaryAttr>(); - if (!derived) - return false; - int num_absent_attrs = 0; -)"; - - os << llvm::formatv(classofInfo, structName) << " {"; - os << llvm::formatv(classofInfoHeader); - - FmtContext fctx; - const char *classofArgInfo = R"( - auto {0} = derived.get("{0}"); - if (!{0} || !({1})) - return false; -)"; - const char *classofArgInfoOptional = R"( - auto {0} = derived.get("{0}"); - if (!{0}) - ++num_absent_attrs; - else if (!({1})) - return false; -)"; - for (auto field : fields) { - auto name = field.getName(); - auto type = field.getType(); - std::string condition = - std::string(tgfmt(type.getConditionTemplate(), &fctx.withSelf(name))); - if (type.isOptional() || type.hasDefaultValue()) - os << llvm::formatv(classofArgInfoOptional, name, condition); - else - os << llvm::formatv(classofArgInfo, name, condition); - } - - const char *classofEndInfo = R"( - return derived.size() + num_absent_attrs == {0}; -} -)"; - os << llvm::formatv(classofEndInfo, fields.size()); -} - -static void -emitAccessorDef(llvm::StringRef structName, - llvm::ArrayRef fields, - raw_ostream &os) { - const char *fieldInfo = R"( -{0} {2}::{1}() const { - auto derived = this->cast<::mlir::DictionaryAttr>(); - auto {1} = derived.get("{1}"); - assert({1} && "attribute not found."); - assert({1}.isa<{0}>() && "incorrect Attribute type found."); - return {1}.cast<{0}>(); -} -)"; - const char *fieldInfoOptional = R"( -{0} {2}::{1}() const { - auto derived = this->cast<::mlir::DictionaryAttr>(); - auto {1} = derived.get("{1}"); - if (!{1}) - return nullptr; - assert({1}.isa<{0}>() && "incorrect Attribute type found."); - return {1}.cast<{0}>(); -} -)"; - const char *fieldInfoDefaultValued = R"( -{0} {2}::{1}() const { - auto derived = this->cast<::mlir::DictionaryAttr>(); - auto {1} = derived.get("{1}"); - if (!{1}) { - ::mlir::Builder builder(getContext()); - return {3}; - } - assert({1}.isa<{0}>() && "incorrect Attribute type found."); - return {1}.cast<{0}>(); -} -)"; - FmtContext fmtCtx; - fmtCtx.withBuilder("builder"); - - for (auto field : fields) { - auto name = field.getName(); - auto type = field.getType(); - auto storage = type.getStorageType(); - if (type.isOptional()) { - os << llvm::formatv(fieldInfoOptional, storage, name, structName); - } else if (type.hasDefaultValue()) { - std::string defaultValue = tgfmt(type.getConstBuilderTemplate(), &fmtCtx, - type.getDefaultValue()); - os << llvm::formatv(fieldInfoDefaultValued, storage, name, structName, - defaultValue); - } else { - os << llvm::formatv(fieldInfo, storage, name, structName); - } - } -} - -static void emitStructDef(const Record &structDef, raw_ostream &os) { - StructAttr structAttr(&structDef); - StringRef cppNamespace = structAttr.getCppNamespace(); - StringRef structName = structAttr.getStructClassName(); - mlir::tblgen::FmtContext ctx; - auto fields = structAttr.getAllFields(); - - llvm::SmallVector namespaces; - llvm::SplitString(cppNamespace, namespaces, "::"); - - for (auto ns : namespaces) - os << "namespace " << ns << " {\n"; - - emitFactoryDef(structName, fields, os); - emitClassofDef(structName, fields, os); - emitAccessorDef(structName, fields, os); - - for (auto ns : llvm::reverse(namespaces)) - os << "} // namespace " << ns << "\n"; -} - -static bool emitStructDefs(const RecordKeeper &recordKeeper, raw_ostream &os) { - llvm::emitSourceFileHeader("Struct Utility Definitions", os); - - auto defs = recordKeeper.getAllDerivedDefinitions("StructAttr"); - for (const auto *def : defs) - emitStructDef(*def, os); - - return false; -} - -// Registers the struct utility generator to mlir-tblgen. -static mlir::GenRegistration - genStructDecls("gen-struct-attr-decls", - "Generate struct utility declarations", - [](const RecordKeeper &records, raw_ostream &os) { - return emitStructDecls(records, os); - }); - -// Registers the struct utility generator to mlir-tblgen. -static mlir::GenRegistration - genStructDefs("gen-struct-attr-defs", "Generate struct utility definitions", - [](const RecordKeeper &records, raw_ostream &os) { - return emitStructDefs(records, os); - }); diff --git a/mlir/unittests/TableGen/CMakeLists.txt b/mlir/unittests/TableGen/CMakeLists.txt --- a/mlir/unittests/TableGen/CMakeLists.txt +++ b/mlir/unittests/TableGen/CMakeLists.txt @@ -3,27 +3,18 @@ mlir_tablegen(EnumsGenTest.cpp.inc -gen-enum-defs) add_public_tablegen_target(MLIRTableGenEnumsIncGen) -# FIXME: This test is for deprecated feature being remove so warnings are -# disabled on it. -set(LLVM_TARGET_DEFINITIONS structs.td) -mlir_tablegen(StructAttrGenTest.h.inc -gen-struct-attr-decls --on-deprecated=none) -mlir_tablegen(StructAttrGenTest.cpp.inc -gen-struct-attr-defs --on-deprecated=none) -add_public_tablegen_target(MLIRTableGenStructAttrIncGen) - set(LLVM_TARGET_DEFINITIONS passes.td) mlir_tablegen(PassGenTest.h.inc -gen-pass-decls -name TableGenTest) add_public_tablegen_target(MLIRTableGenTestPassIncGen) add_mlir_unittest(MLIRTableGenTests EnumsGenTest.cpp - StructsGenTest.cpp FormatTest.cpp OpBuildGen.cpp PassGenTest.cpp ) add_dependencies(MLIRTableGenTests MLIRTableGenEnumsIncGen) -add_dependencies(MLIRTableGenTests MLIRTableGenStructAttrIncGen) add_dependencies(MLIRTableGenTests MLIRTableGenTestPassIncGen) add_dependencies(MLIRTableGenTests MLIRTestDialect) diff --git a/mlir/unittests/TableGen/StructsGenTest.cpp b/mlir/unittests/TableGen/StructsGenTest.cpp deleted file mode 100644 --- a/mlir/unittests/TableGen/StructsGenTest.cpp +++ /dev/null @@ -1,179 +0,0 @@ -//===- StructsGenTest.cpp - TableGen StructsGen Tests ---------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "mlir/IR/Attributes.h" -#include "mlir/IR/Builders.h" -#include "mlir/IR/BuiltinTypes.h" -#include "llvm/ADT/DenseMap.h" -#include "llvm/ADT/Optional.h" -#include "llvm/ADT/StringSwitch.h" -#include "gmock/gmock.h" -#include - -namespace mlir { - -/// Pull in generated enum utility declarations and definitions. -#include "StructAttrGenTest.h.inc" // NOLINT -#include "StructAttrGenTest.cpp.inc" - -/// Helper that returns an example test::TestStruct for testing its -/// implementation. -static test::TestStruct getTestStruct(mlir::MLIRContext *context) { - auto integerType = mlir::IntegerType::get(context, 32); - auto integerAttr = mlir::IntegerAttr::get(integerType, 127); - - auto floatType = mlir::FloatType::getF32(context); - auto floatAttr = mlir::FloatAttr::get(floatType, 0.25); - - auto elementsType = mlir::RankedTensorType::get({2, 3}, integerType); - auto elementsAttr = - mlir::DenseIntElementsAttr::get(elementsType, {1, 2, 3, 4, 5, 6}); - auto optionalAttr = nullptr; - auto defaultValuedAttr = nullptr; - - return test::TestStruct::get(integerAttr, floatAttr, elementsAttr, - optionalAttr, defaultValuedAttr, context); -} - -/// Validates that test::TestStruct::classof correctly identifies a valid -/// test::TestStruct. -TEST(StructsGenTest, ClassofTrue) { - mlir::MLIRContext context; - auto structAttr = getTestStruct(&context); - ASSERT_TRUE(test::TestStruct::classof(structAttr)); -} - -/// Validates that test::TestStruct::classof fails when an extra attribute is in -/// the class. -TEST(StructsGenTest, ClassofExtraFalse) { - mlir::MLIRContext context; - mlir::DictionaryAttr structAttr = getTestStruct(&context); - auto expectedValues = structAttr.getValue(); - ASSERT_EQ(expectedValues.size(), 3u); - - // Copy the set of named attributes. - llvm::SmallVector newValues(expectedValues.begin(), - expectedValues.end()); - - // Add an extra NamedAttribute. - auto wrongId = mlir::StringAttr::get(&context, "wrong"); - auto wrongAttr = mlir::NamedAttribute(wrongId, expectedValues[0].getValue()); - newValues.push_back(wrongAttr); - - // Make a new DictionaryAttr and validate. - auto badDictionary = mlir::DictionaryAttr::get(&context, newValues); - ASSERT_FALSE(test::TestStruct::classof(badDictionary)); -} - -/// Validates that test::TestStruct::classof fails when a NamedAttribute has an -/// incorrect name. -TEST(StructsGenTest, ClassofBadNameFalse) { - mlir::MLIRContext context; - mlir::DictionaryAttr structAttr = getTestStruct(&context); - auto expectedValues = structAttr.getValue(); - ASSERT_EQ(expectedValues.size(), 3u); - - // Create a copy of all but the first NamedAttributes. - llvm::SmallVector newValues( - expectedValues.begin() + 1, expectedValues.end()); - - // Add a copy of the first attribute with the wrong name. - auto wrongId = mlir::StringAttr::get(&context, "wrong"); - auto wrongAttr = mlir::NamedAttribute(wrongId, expectedValues[0].getValue()); - newValues.push_back(wrongAttr); - - auto badDictionary = mlir::DictionaryAttr::get(&context, newValues); - ASSERT_FALSE(test::TestStruct::classof(badDictionary)); -} - -/// Validates that test::TestStruct::classof fails when a NamedAttribute has an -/// incorrect type. -TEST(StructsGenTest, ClassofBadTypeFalse) { - mlir::MLIRContext context; - mlir::DictionaryAttr structAttr = getTestStruct(&context); - auto expectedValues = structAttr.getValue(); - ASSERT_EQ(expectedValues.size(), 3u); - - // Create a copy of all but the last NamedAttributes. - llvm::SmallVector newValues( - expectedValues.begin(), expectedValues.end() - 1); - - // Add a copy of the last attribute with the wrong type. - auto i64Type = mlir::IntegerType::get(&context, 64); - auto elementsType = mlir::RankedTensorType::get({3}, i64Type); - auto elementsAttr = - mlir::DenseIntElementsAttr::get(elementsType, ArrayRef{1, 2, 3}); - mlir::StringAttr id = expectedValues.back().getName(); - auto wrongAttr = mlir::NamedAttribute(id, elementsAttr); - newValues.push_back(wrongAttr); - - auto badDictionary = mlir::DictionaryAttr::get(&context, newValues); - ASSERT_FALSE(test::TestStruct::classof(badDictionary)); -} - -/// Validates that test::TestStruct::classof fails when a NamedAttribute is -/// missing. -TEST(StructsGenTest, ClassofMissingFalse) { - mlir::MLIRContext context; - mlir::DictionaryAttr structAttr = getTestStruct(&context); - auto expectedValues = structAttr.getValue(); - ASSERT_EQ(expectedValues.size(), 3u); - - // Copy a subset of the structures Named Attributes. - llvm::SmallVector newValues( - expectedValues.begin() + 1, expectedValues.end()); - - // Make a new DictionaryAttr and validate it is not a validate TestStruct. - auto badDictionary = mlir::DictionaryAttr::get(&context, newValues); - ASSERT_FALSE(test::TestStruct::classof(badDictionary)); -} - -/// Validate the accessor for the FloatAttr value. -TEST(StructsGenTest, GetFloat) { - mlir::MLIRContext context; - auto structAttr = getTestStruct(&context); - auto returnedAttr = structAttr.sample_float(); - EXPECT_EQ(returnedAttr.getValueAsDouble(), 0.25); -} - -/// Validate the accessor for the IntegerAttr value. -TEST(StructsGenTest, GetInteger) { - mlir::MLIRContext context; - auto structAttr = getTestStruct(&context); - auto returnedAttr = structAttr.sample_integer(); - EXPECT_EQ(returnedAttr.getInt(), 127); -} - -/// Validate the accessor for the ElementsAttr value. -TEST(StructsGenTest, GetElements) { - mlir::MLIRContext context; - auto structAttr = getTestStruct(&context); - auto returnedAttr = structAttr.sample_elements(); - auto denseAttr = returnedAttr.dyn_cast(); - ASSERT_TRUE(denseAttr); - - for (const auto &valIndexIt : llvm::enumerate(denseAttr.getValues())) { - EXPECT_EQ(valIndexIt.value(), valIndexIt.index() + 1); - } -} - -TEST(StructsGenTest, EmptyOptional) { - mlir::MLIRContext context; - auto structAttr = getTestStruct(&context); - EXPECT_EQ(structAttr.sample_optional_integer(), nullptr); -} - -TEST(StructsGenTest, GetDefaultValuedAttr) { - mlir::MLIRContext context; - mlir::Builder builder(&context); - auto structAttr = getTestStruct(&context); - EXPECT_EQ(structAttr.sample_default_valued_integer(), - builder.getI32IntegerAttr(42)); -} - -} // namespace mlir diff --git a/mlir/unittests/TableGen/structs.td b/mlir/unittests/TableGen/structs.td deleted file mode 100644 --- a/mlir/unittests/TableGen/structs.td +++ /dev/null @@ -1,24 +0,0 @@ -//===-- structs.td - StructsGen test definition file -------*- tablegen -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -include "mlir/IR/OpBase.td" - -def Test_Dialect : Dialect { - let name = "test"; -} - -def Test_Struct : StructAttr<"TestStruct", Test_Dialect, [ - StructFieldAttr<"sample_integer", I32Attr>, - StructFieldAttr<"sample_float", F32Attr>, - StructFieldAttr<"sample_elements", I32ElementsAttr>, - StructFieldAttr<"sample_optional_integer", - OptionalAttr>, - StructFieldAttr<"sample_default_valued_integer", - DefaultValuedAttr>] > { - let summary = "Structure for test data"; -} diff --git a/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel b/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel --- a/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel @@ -4148,14 +4148,6 @@ ["-gen-enum-defs"], "include/mlir/Dialect/LLVMIR/NVVMOpsEnums.cpp.inc", ), - ( - ["-gen-struct-attr-decls"], - "include/mlir/Dialect/LLVMIR/NVVMOpsStructs.h.inc", - ), - ( - ["-gen-struct-attr-defs"], - "include/mlir/Dialect/LLVMIR/NVVMOpsStructs.cpp.inc", - ), ( [ "-gen-attrdef-decls", @@ -7746,14 +7738,6 @@ ["-gen-op-defs"], "include/mlir/Dialect/Tosa/IR/TosaOps.cpp.inc", ), - ( - ["-gen-struct-attr-decls"], - "include/mlir/Dialect/Tosa/IR/TosaStructs.h.inc", - ), - ( - ["-gen-struct-attr-defs"], - "include/mlir/Dialect/Tosa/IR/TosaStructs.cpp.inc", - ), ( ["-gen-dialect-decls"], "include/mlir/Dialect/Tosa/IR/TosaOpsDialect.h.inc", diff --git a/utils/bazel/llvm-project-overlay/mlir/test/BUILD.bazel b/utils/bazel/llvm-project-overlay/mlir/test/BUILD.bazel --- a/utils/bazel/llvm-project-overlay/mlir/test/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/mlir/test/BUILD.bazel @@ -86,14 +86,6 @@ ["-gen-enum-defs"], "lib/Dialect/Test/TestOpEnums.cpp.inc", ), - ( - ["-gen-struct-attr-decls"], - "lib/Dialect/Test/TestOpStructs.h.inc", - ), - ( - ["-gen-struct-attr-defs"], - "lib/Dialect/Test/TestOpStructs.cpp.inc", - ), ( ["-gen-rewriters"], "lib/Dialect/Test/TestPatterns.inc", diff --git a/utils/bazel/llvm-project-overlay/mlir/unittests/BUILD.bazel b/utils/bazel/llvm-project-overlay/mlir/unittests/BUILD.bazel --- a/utils/bazel/llvm-project-overlay/mlir/unittests/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/mlir/unittests/BUILD.bazel @@ -214,25 +214,6 @@ ], ) -gentbl_cc_library( - name = "StructsIncGen", - tbl_outs = [ - ( - ["-gen-struct-attr-decls"], - "TableGen/StructAttrGenTest.h.inc", - ), - ( - ["-gen-struct-attr-defs"], - "TableGen/StructAttrGenTest.cpp.inc", - ), - ], - tblgen = "//mlir:mlir-tblgen", - td_file = "TableGen/structs.td", - deps = [ - "//mlir:OpBaseTdFiles", - ], -) - cc_test( name = "tablegen_tests", size = "small", @@ -242,14 +223,11 @@ ]) + [ "TableGen/EnumsGenTest.cpp.inc", "TableGen/EnumsGenTest.h.inc", - "TableGen/StructAttrGenTest.cpp.inc", - "TableGen/StructAttrGenTest.h.inc", ], includes = ["TableGen/"], deps = [ ":EnumsIncGen", ":PassIncGen", - ":StructsIncGen", "//llvm:Support", "//llvm:TestingSupport", "//llvm:gtest_main",