add_subdirectory(EDSC)
add_subdirectory(mlir-cpu-runner)
add_subdirectory(SDBM)
+add_subdirectory(TestDialect)
llvm_canonicalize_cmake_booleans(
LLVM_BUILD_EXAMPLES
mlir-opt
mlir-sdbm-api-test
mlir-tblgen
+ mlir-test-opt
mlir-translate
sdot
)
--- /dev/null
+set(LLVM_TARGET_DEFINITIONS TestOps.td)
+mlir_tablegen(TestOps.h.inc -gen-op-decls)
+mlir_tablegen(TestOps.cpp.inc -gen-op-defs)
+mlir_tablegen(TestPatterns.inc -gen-rewriters)
+add_public_tablegen_target(MLIRTestOpsIncGen)
+
+add_llvm_library(MLIRTestDialect
+ TestDialect.cpp
+ TestPatterns.cpp
+)
+add_dependencies(MLIRTestDialect
+ MLIRTestOpsIncGen
+ LLVMSupport
+)
+target_link_libraries(MLIRTestDialect
+ LLVMSupport
+)
+
+add_executable(mlir-test-opt
+ ${MLIR_MAIN_SRC_DIR}/../tools/mlir-opt/mlir-opt.cpp
+)
+llvm_update_compile_flags(mlir-test-opt)
+whole_archive_link(mlir-test-opt
+ MLIRStandardOps
+ MLIRTestDialect
+)
+target_link_libraries(mlir-test-opt
+ MLIRTestDialect
+ MLIRMlirOptLib
+ LLVMSupport
+)
--- /dev/null
+//===- TestDialect.cpp - MLIR Dialect for Testing -------------------------===//
+//
+// Copyright 2019 The MLIR Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+// =============================================================================
+
+#include "TestDialect.h"
+#include "mlir/IR/PatternMatch.h"
+
+using namespace mlir;
+
+//===----------------------------------------------------------------------===//
+// TestDialect
+//===----------------------------------------------------------------------===//
+
+TestDialect::TestDialect(MLIRContext *context)
+ : Dialect(getDialectName(), context) {
+ addOperations<
+#define GET_OP_LIST
+#include "TestOps.cpp.inc"
+ >();
+}
+
+// Static initialization for Test dialect registration.
+static mlir::DialectRegistration<mlir::TestDialect> testDialect;
+
+#define GET_OP_CLASSES
+#include "TestOps.cpp.inc"
--- /dev/null
+//===- TestDialect.h - MLIR Dialect for testing -----------------*- C++ -*-===//
+//
+// Copyright 2019 The MLIR Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+// =============================================================================
+//
+// This file defines a fake 'test' dialect that can be used for testing things
+// that do not have a respective counterpart in the main source directories.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef MLIR_TESTDIALECT_H
+#define MLIR_TESTDIALECT_H
+
+#include "mlir/IR/Dialect.h"
+#include "mlir/IR/OpDefinition.h"
+
+namespace mlir {
+
+class TestDialect : public Dialect {
+public:
+ /// Create the dialect in the given `context`.
+ TestDialect(MLIRContext *context);
+
+ /// Get the canonical string name of the dialect.
+ static StringRef getDialectName() { return "test"; }
+};
+
+#define GET_OP_CLASSES
+#include "TestOps.h.inc"
+
+} // end namespace mlir
+
+#endif // MLIR_TESTDIALECT_H
--- /dev/null
+//===-- TestOps.td - Test dialect operation definitions ----*- tablegen -*-===//
+//
+// Copyright 2019 The MLIR Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+// =============================================================================
+
+#ifdef TEST_OPS
+#else
+#define TEST_OPS
+
+#ifdef OP_BASE
+#else
+include "mlir/IR/OpBase.td"
+#endif // OP_BASE
+
+def TEST_Dialect : Dialect {
+ let name = "test";
+ let cppNamespace = "";
+}
+
+class TEST_Op<string mnemonic, list<OpTrait> traits = []> :
+ Op<TEST_Dialect, mnemonic, traits>;
+
+//===----------------------------------------------------------------------===//
+// Test 'verifyUnusedValue'
+//===----------------------------------------------------------------------===//
+
+def VUVTwoResultOp : TEST_Op<"vuv_two_result_op", []> {
+ let arguments = (ins I32:$input);
+ let results = (outs I32:$r1, I32:$r2);
+}
+
+def VUVFoldTwoResultOp : Pattern<(VUVTwoResultOp $input), [
+ (verifyUnusedValue),
+ (replaceWithValue $input)
+ ]>;
+
+#endif // TEST_OPS
\ No newline at end of file
--- /dev/null
+//===- TestPatterns.cpp - Test dialect pattern driver ---------------------===//
+//
+// Copyright 2019 The MLIR Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+// =============================================================================
+
+#include "TestDialect.h"
+#include "mlir/IR/PatternMatch.h"
+#include "mlir/Pass/Pass.h"
+using namespace mlir;
+
+namespace {
+#include "TestPatterns.inc"
+
+struct TestPatternDriver : public FunctionPass<TestPatternDriver> {
+ void runOnFunction() {
+ mlir::OwningRewritePatternList patterns;
+ populateWithGenerated(&getContext(), &patterns);
+ applyPatternsGreedily(getFunction(), std::move(patterns));
+ }
+};
+} // end anonymous namespace
+
+static mlir::PassRegistration<TestPatternDriver>
+ pass("test-patterns", "Run test dialect patterns");
--- /dev/null
+config.suffixes.remove('.td')
\ No newline at end of file
tools = [
'mlir-opt',
'mlir-tblgen',
+ 'mlir-test-opt',
'mlir-translate',
'mlir-edsc-builder-api-test',
]
+++ /dev/null
-// RUN: mlir-tblgen -gen-rewriters -I %S/../../include %s | FileCheck %s
-
-include "mlir/IR/OpBase.td"
-
-def Test_Dialect : Dialect {
- let name = "test";
- let cppNamespace = "";
-}
-class NS_Op<string mnemonic, list<OpTrait> traits> :
- Op<Test_Dialect, mnemonic, traits>;
-
-def ThreeResultOp : NS_Op<"three_result_op", []> {
- let arguments = (ins I32:$input);
- let results = (outs I32:$r1, I32:$r2, I32:$r3);
-}
-
-def OneResultOp : NS_Op<"one_result_op", []> {
- let arguments = (ins I32:$input);
- let results = (outs I32:$r1);
-}
-
-def : Pattern<(ThreeResultOp $input), [
- (verifyUnusedValue),
- (OneResultOp $input),
- (verifyUnusedValue)
- ]>;
-
-// CHECK-LABEL: struct GeneratedConvert0
-
-// CHECK: PatternMatchResult match(
-// CHECK: if (!op0->getResult(0)->use_empty()) return matchFailure();
-// CHECK: if (!op0->getResult(2)->use_empty()) return matchFailure();
-
-// CHECK: void rewrite(
-// CHECK: auto vOneResultOp0 = rewriter.create<OneResultOp>(
-// CHECK: rewriter.replaceOp(op, {nullptr, vOneResultOp0, nullptr});
--- /dev/null
+// RUN: mlir-test-opt -test-patterns %s | FileCheck %s
+
+//===----------------------------------------------------------------------===//
+// Test 'verifyUnusedValue'
+//===----------------------------------------------------------------------===//
+
+// CHECK-LABEL: @match_success_on_unused_first_result
+func @match_success_on_unused_first_result(%arg0 : i32) -> i32 {
+ // CHECK-NEXT: return {{.*}} : i32
+ %result:2 = "test.vuv_two_result_op"(%arg0) : (i32) -> (i32, i32)
+ return %result#1 : i32
+}
+
+// CHECK-LABEL: @match_fail_on_used_first_result
+func @match_fail_on_used_first_result(%arg0 : i32) -> i32 {
+ // CHECK-NEXT: "test.vuv_two_result_op"(%arg0) : (i32) -> (i32, i32)
+ %result:2 = "test.vuv_two_result_op"(%arg0) : (i32) -> (i32, i32)
+ "foo.unknown_op"(%result#0) : (i32) -> ()
+ return %result#1 : i32
+}