Skip to content

[mlir] load dialects for non-namespaced attrs #94838

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions mlir/test/Target/LLVMIR/test.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,17 @@ llvm.func @dialect_attr_translation_multi(%a: i64, %b: i64, %c: i64) -> i64 {
// CHECK-DAG: ![[MD_ID_ADD]] = !{!"annotation_from_test: add"}
// CHECK-DAG: ![[MD_ID_MUL]] = !{!"annotation_from_test: mul"}
// CHECK-DAG: ![[MD_ID_RET]] = !{!"annotation_from_test: ret"}


// -----

// This is a regression test for a bug where, during an mlir-translate call the
// parser would only load the dialect if the fully namespaced attribute was
// present in the IR.
#attr = #test.nested_polynomial<#polynomial.int_polynomial<1 + x**2>>
// CHECK-lABLE: @parse_correctly
llvm.func @parse_correctly() {
test.containing_int_polynomial_attr #attr
llvm.return
}

5 changes: 3 additions & 2 deletions mlir/test/lib/Dialect/Test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ mlir_tablegen(TestOpInterfaces.cpp.inc -gen-op-interface-defs)
add_public_tablegen_target(MLIRTestInterfaceIncGen)

set(LLVM_TARGET_DEFINITIONS TestOps.td)
mlir_tablegen(TestAttrDefs.h.inc -gen-attrdef-decls)
mlir_tablegen(TestAttrDefs.cpp.inc -gen-attrdef-defs)
mlir_tablegen(TestAttrDefs.h.inc -gen-attrdef-decls -attrdefs-dialect=test)
mlir_tablegen(TestAttrDefs.cpp.inc -gen-attrdef-defs -attrdefs-dialect=test)
add_public_tablegen_target(MLIRTestAttrDefIncGen)

set(LLVM_TARGET_DEFINITIONS TestTypeDefs.td)
Expand Down Expand Up @@ -86,6 +86,7 @@ add_mlir_library(MLIRTestDialect
MLIRLinalgTransforms
MLIRLLVMDialect
MLIRPass
MLIRPolynomialDialect
MLIRReduce
MLIRTensorDialect
MLIRTransformUtils
Expand Down
9 changes: 9 additions & 0 deletions mlir/test/lib/Dialect/Test/TestAttrDefs.td
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// To get the test dialect definition.
include "TestDialect.td"
include "TestEnumDefs.td"
include "mlir/Dialect/Polynomial/IR/PolynomialAttributes.td"
include "mlir/Dialect/Utils/StructuredOpsUtils.td"
include "mlir/IR/AttrTypeBase.td"
include "mlir/IR/BuiltinAttributeInterfaces.td"
Expand Down Expand Up @@ -351,4 +352,12 @@ def TestCustomFloatAttr : Test_Attr<"TestCustomFloat"> {
}];
}

def NestedPolynomialAttr : Test_Attr<"NestedPolynomialAttr"> {
let mnemonic = "nested_polynomial";
let parameters = (ins Polynomial_IntPolynomialAttr:$poly);
let assemblyFormat = [{
`<` qualified($poly) `>`
}];
}

#endif // TEST_ATTRDEFS
1 change: 1 addition & 0 deletions mlir/test/lib/Dialect/Test/TestAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <tuple>

#include "TestTraits.h"
#include "mlir/Dialect/Polynomial/IR/PolynomialAttributes.h"
#include "mlir/Dialect/Utils/StructuredOpsUtils.h"
#include "mlir/IR/Attributes.h"
#include "mlir/IR/Diagnostics.h"
Expand Down
7 changes: 6 additions & 1 deletion mlir/test/lib/Dialect/Test/TestOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@ def FloatElementsAttrOp : TEST_Op<"float_elements_attr"> {
);
}

def ContainingIntPolynomialAttrOp : TEST_Op<"containing_int_polynomial_attr"> {
let arguments = (ins NestedPolynomialAttr:$attr);
let assemblyFormat = "$attr attr-dict";
}

// A pattern that updates dense<[3.0, 4.0]> to dense<[5.0, 6.0]>.
// This tests both matching and generating float elements attributes.
def UpdateFloatElementsAttr : Pat<
Expand Down Expand Up @@ -2204,7 +2209,7 @@ def ForwardBufferOp : TEST_Op<"forward_buffer", [Pure]> {
def ReifyBoundOp : TEST_Op<"reify_bound", [Pure]> {
let description = [{
Reify a bound for the given index-typed value or dimension size of a shaped
value. "LB", "EQ" and "UB" bounds are supported. If `scalable` is set,
value. "LB", "EQ" and "UB" bounds are supported. If `scalable` is set,
`vscale_min` and `vscale_max` must be provided, which allows computing
a bound in terms of "vector.vscale" for a given range of vscale.
}];
Expand Down
6 changes: 6 additions & 0 deletions mlir/test/lib/Dialect/Test/TestToLLVMIRTranslation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "TestDialect.h"
#include "TestOps.h"
#include "mlir/Dialect/Polynomial/IR/PolynomialDialect.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinAttributes.h"
#include "mlir/IR/BuiltinOps.h"
Expand Down Expand Up @@ -106,6 +107,10 @@ LogicalResult TestDialectLLVMIRTranslationInterface::convertOperation(
mod->getOrInsertGlobal(symOp.getSymName(), i32Type);
return success();
})
.Case([&](test::ContainingIntPolynomialAttrOp polyOp) {
// Discardable, as this op existed only for testing parsin.
return success();
})
.Default([&](Operation *) {
return op->emitOpError("unsupported translation of test operation");
});
Expand All @@ -127,6 +132,7 @@ void registerTestToLLVMIR() {
},
[](DialectRegistry &registry) {
registry.insert<test::TestDialect>();
registry.insert<polynomial::PolynomialDialect>();
registerBuiltinDialectTranslation(registry);
registerLLVMDialectTranslation(registry);
registry.addExtension(
Expand Down
Loading