Add a flag on the context to protect against creation of operations in unregistered...
authorMehdi Amini <joker.eph@gmail.com>
Sun, 29 Mar 2020 22:35:38 +0000 (22:35 +0000)
committerMehdi Amini <joker.eph@gmail.com>
Mon, 30 Mar 2020 19:37:31 +0000 (19:37 +0000)
Differential Revision: https://reviews.llvm.org/D76903

80 files changed:
mlir/include/mlir/IR/MLIRContext.h
mlir/include/mlir/Support/MlirOptMain.h
mlir/lib/Analysis/Verifier.cpp
mlir/lib/IR/MLIRContext.cpp
mlir/lib/Support/MlirOptMain.cpp
mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
mlir/test/Conversion/GPUToCUDA/lower-launch-func-to-cuda.mlir
mlir/test/Conversion/GPUToNVVM/memory-attrbution.mlir
mlir/test/Conversion/GPUToSPIRV/simple.mlir
mlir/test/Conversion/StandardToLLVM/standard-to-llvm.mlir
mlir/test/Conversion/StandardToSPIRV/std-to-spirv.mlir
mlir/test/Dialect/Affine/SuperVectorize/compose_maps.mlir
mlir/test/Dialect/Affine/canonicalize.mlir
mlir/test/Dialect/Affine/dma-generate.mlir
mlir/test/Dialect/Affine/inlining.mlir
mlir/test/Dialect/Affine/invalid.mlir
mlir/test/Dialect/Affine/loop-tiling.mlir
mlir/test/Dialect/Affine/ops.mlir
mlir/test/Dialect/Affine/parallelism-detection.mlir
mlir/test/Dialect/Affine/simplify-affine-structures.mlir
mlir/test/Dialect/Affine/slicing-utils.mlir
mlir/test/Dialect/Affine/unroll-jam.mlir
mlir/test/Dialect/Affine/unroll.mlir
mlir/test/Dialect/GPU/ops.mlir
mlir/test/Dialect/GPU/outlining.mlir
mlir/test/Dialect/GPU/promotion.mlir
mlir/test/Dialect/LLVMIR/invalid.mlir
mlir/test/Dialect/Loops/invalid.mlir
mlir/test/Dialect/Loops/parallel-loop-fusion.mlir
mlir/test/Dialect/Quant/parse-any.mlir
mlir/test/Dialect/Quant/parse-ops-invalid.mlir
mlir/test/Dialect/Quant/parse-uniform.mlir
mlir/test/Dialect/Quant/quant_region.mlir
mlir/test/Dialect/SPIRV/control-flow-ops.mlir
mlir/test/Dialect/SPIRV/ops.mlir
mlir/test/Dialect/SPIRV/structure-ops.mlir
mlir/test/EDSC/builder-api-test.cpp
mlir/test/IR/affine-map.mlir
mlir/test/IR/core-ops.mlir
mlir/test/IR/dense-elements-hex.mlir
mlir/test/IR/invalid-ops.mlir
mlir/test/IR/invalid.mlir
mlir/test/IR/locations.mlir
mlir/test/IR/module-op.mlir
mlir/test/IR/op-stats.mlir
mlir/test/IR/opaque_locations.mlir
mlir/test/IR/parser.mlir
mlir/test/IR/pretty-locations.mlir
mlir/test/IR/pretty-region-args.mlir
mlir/test/IR/print-op-local-scope.mlir
mlir/test/IR/region.mlir
mlir/test/IR/test-symbol-dce.mlir
mlir/test/IR/test-symbol-rauw.mlir
mlir/test/IR/test-symbol-uses.mlir
mlir/test/IR/traits.mlir
mlir/test/IR/wrapping_op.mlir
mlir/test/Transforms/canonicalize-dce.mlir
mlir/test/Transforms/canonicalize.mlir
mlir/test/Transforms/constant-fold.mlir
mlir/test/Transforms/cse.mlir
mlir/test/Transforms/inlining-dce.mlir
mlir/test/Transforms/location-snapshot.mlir
mlir/test/Transforms/loop-coalescing.mlir
mlir/test/Transforms/loop-fusion-dependence-check.mlir
mlir/test/Transforms/loop-fusion.mlir
mlir/test/Transforms/memref-dataflow-opt.mlir
mlir/test/Transforms/parallel-loop-collapsing.mlir
mlir/test/Transforms/parametric-mapping.mlir
mlir/test/Transforms/pipeline-data-transfer.mlir
mlir/test/Transforms/single-parallel-loop-collapsing.mlir
mlir/test/Transforms/strip-debuginfo.mlir
mlir/test/Transforms/test-canonicalize.mlir
mlir/test/Transforms/test-inlining.mlir
mlir/test/Transforms/test-legalizer-analysis.mlir
mlir/test/Transforms/test-legalizer-full.mlir
mlir/test/Transforms/test-legalizer.mlir
mlir/test/mlir-tblgen/op-format.mlir
mlir/tools/mlir-opt/mlir-opt.cpp
mlir/tools/mlir-translate/mlir-translate.cpp
mlir/unittests/IR/OperationSupportTest.cpp

index 1cfeeee..6a65c4e 100644 (file)
@@ -49,6 +49,12 @@ public:
     return static_cast<T *>(getRegisteredDialect(T::getDialectNamespace()));
   }
 
+  /// Return true if we allow to create operation for unregistered dialects.
+  bool allowsUnregisteredDialects();
+
+  /// Enables creating operations in unregistered dialects.
+  void allowUnregisteredDialects(bool allow = true);
+
   /// Return information about all registered operations.  This isn't very
   /// efficient: typically you should ask the operations about their properties
   /// directly.
index 7eb6a43..f235ea3 100644 (file)
@@ -26,6 +26,6 @@ LogicalResult MlirOptMain(llvm::raw_ostream &os,
                           std::unique_ptr<llvm::MemoryBuffer> buffer,
                           const PassPipelineCLParser &passPipeline,
                           bool splitInputFile, bool verifyDiagnostics,
-                          bool verifyPasses);
+                          bool verifyPasses, bool allowUnregisteredDialects);
 
 } // end namespace mlir
index 161feb4..e15d351 100644 (file)
@@ -198,9 +198,18 @@ LogicalResult OperationVerifier::verifyOperation(Operation &op) {
       it = dialectAllowsUnknownOps
                .try_emplace(dialectPrefix, dialect->allowsUnknownOperations())
                .first;
-    // Otherwise, conservatively allow unknown operations.
-    else
+    // Otherwise, unregistered dialects (when allowed by the context)
+    // conservatively allow unknown operations.
+    else {
+      if (!op.getContext()->allowsUnregisteredDialects() && !op.getDialect())
+        return op.emitOpError()
+               << "created with unregistered dialect. If this is "
+                  "intended, please call allowUnregisteredDialects() on the "
+                  "MLIRContext, or use -allow-unregistered-dialect with "
+                  "mlir-opt";
+
       it = dialectAllowsUnknownOps.try_emplace(dialectPrefix, true).first;
+    }
   }
 
   if (!it->second) {
index dcd6895..df4ea9b 100644 (file)
@@ -162,6 +162,15 @@ public:
   DiagnosticEngine diagEngine;
 
   //===--------------------------------------------------------------------===//
+  // Options
+  //===--------------------------------------------------------------------===//
+
+  /// In most cases, creating operation in unregistered dialect is not desired
+  /// and indicate a misconfiguration of the compiler. This option enables to
+  /// detect such use cases
+  bool allowUnregisteredDialects = false;
+
+  //===--------------------------------------------------------------------===//
   // Other
   //===--------------------------------------------------------------------===//
 
@@ -349,6 +358,14 @@ void Dialect::registerDialect(MLIRContext *context) {
   impl.dialects.insert(insertPt, std::move(dialect));
 }
 
+bool MLIRContext::allowsUnregisteredDialects() {
+  return impl->allowUnregisteredDialects;
+}
+
+void MLIRContext::allowUnregisteredDialects(bool allowing) {
+  impl->allowUnregisteredDialects = allowing;
+}
+
 /// Return information about all registered operations.  This isn't very
 /// efficient, typically you should ask the operations about their properties
 /// directly.
index 5db824d..53e336a 100644 (file)
@@ -67,6 +67,7 @@ static LogicalResult performActions(raw_ostream &os, bool verifyDiagnostics,
 static LogicalResult processBuffer(raw_ostream &os,
                                    std::unique_ptr<MemoryBuffer> ownedBuffer,
                                    bool verifyDiagnostics, bool verifyPasses,
+                                   bool allowUnregisteredDialects,
                                    const PassPipelineCLParser &passPipeline) {
   // Tell sourceMgr about this buffer, which is what the parser will pick up.
   SourceMgr sourceMgr;
@@ -74,6 +75,7 @@ static LogicalResult processBuffer(raw_ostream &os,
 
   // Parse the input file.
   MLIRContext context;
+  context.allowUnregisteredDialects(allowUnregisteredDialects);
 
   // If we are in verify diagnostics mode then we have a lot of work to do,
   // otherwise just perform the actions without worrying about it.
@@ -100,7 +102,8 @@ LogicalResult mlir::MlirOptMain(raw_ostream &os,
                                 std::unique_ptr<MemoryBuffer> buffer,
                                 const PassPipelineCLParser &passPipeline,
                                 bool splitInputFile, bool verifyDiagnostics,
-                                bool verifyPasses) {
+                                bool verifyPasses,
+                                bool allowUnregisteredDialects) {
   // The split-input-file mode is a very specific mode that slices the file
   // up into small pieces and checks each independently.
   if (splitInputFile)
@@ -108,10 +111,11 @@ LogicalResult mlir::MlirOptMain(raw_ostream &os,
         std::move(buffer),
         [&](std::unique_ptr<MemoryBuffer> chunkBuffer, raw_ostream &os) {
           return processBuffer(os, std::move(chunkBuffer), verifyDiagnostics,
-                               verifyPasses, passPipeline);
+                               verifyPasses, allowUnregisteredDialects,
+                               passPipeline);
         },
         os);
 
   return processBuffer(os, std::move(buffer), verifyDiagnostics, verifyPasses,
-                       passPipeline);
+                       allowUnregisteredDialects, passPipeline);
 }
index 8a71762..6f051c0 100644 (file)
@@ -446,7 +446,7 @@ Value Importer::processValue(llvm::Value *value) {
   // We don't expect to see instructions in dominator order. If we haven't seen
   // this instruction yet, create an unknown op and remap it later.
   if (isa<llvm::Instruction>(value)) {
-    OperationState state(UnknownLoc::get(context), "unknown");
+    OperationState state(UnknownLoc::get(context), "llvm.unknown");
     LLVMType type = processType(value->getType());
     if (!type)
       return nullptr;
index bb02b5d..17244ce 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s --launch-func-to-cuda | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s --launch-func-to-cuda | FileCheck %s
 
 module attributes {gpu.container_module} {
 
index c6d080f..68b6157 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt --convert-gpu-to-nvvm --split-input-file %s | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect --convert-gpu-to-nvvm --split-input-file %s | FileCheck %s
 
 gpu.module @kernel {
   // CHECK-LABEL:  llvm.func @private
index 3076cd0..9cf0f50 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt -split-input-file -convert-gpu-to-spirv -verify-diagnostics %s -o - | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect -split-input-file -convert-gpu-to-spirv -verify-diagnostics %s -o - | FileCheck %s
 
 module attributes {gpu.container_module} {
   gpu.module @kernels {
index 6aec959..b6bc813 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -convert-std-to-llvm -split-input-file -verify-diagnostics | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s -convert-std-to-llvm -split-input-file -verify-diagnostics | FileCheck %s
 
 // CHECK-LABEL: func @address_space(
 // CHECK-SAME:    !llvm<"float addrspace(7)*">
index 91219ac..59e1c80 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt -split-input-file -convert-std-to-spirv %s -o - | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect -split-input-file -convert-std-to-spirv %s -o - | FileCheck %s
 
 //===----------------------------------------------------------------------===//
 // std arithmetic ops
index ca16417..126a176 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -affine-super-vectorizer-test -compose-maps 2>&1 |  FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s -affine-super-vectorizer-test -compose-maps 2>&1 |  FileCheck %s
 
 // For all these cases, the test traverses the `test_affine_map` ops and
 // composes them in order one-by-one.
index ede438e..9e9787e 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -split-input-file -pass-pipeline='func(canonicalize)' | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s -split-input-file -pass-pipeline='func(canonicalize)' | FileCheck %s
 
 // Affine maps for test case: compose_affine_maps_1dto2d_no_symbols
 // CHECK-DAG: [[MAP0:#map[0-9]+]] = affine_map<(d0) -> (d0 - 1)>
index b1e71e6..e2680a0 100644 (file)
@@ -1,5 +1,5 @@
-// RUN: mlir-opt %s -split-input-file -affine-data-copy-generate -affine-data-copy-generate-dma -affine-data-copy-generate-fast-mem-space=2 -affine-data-copy-generate-skip-non-unit-stride-loops -verify-diagnostics | FileCheck %s
-// RUN: mlir-opt %s -split-input-file -affine-data-copy-generate -affine-data-copy-generate-dma -affine-data-copy-generate-fast-mem-capacity=16 -affine-data-copy-generate-fast-mem-space=2 | FileCheck %s --check-prefix FAST-MEM-16KB
+// RUN: mlir-opt -allow-unregistered-dialect %s -split-input-file -affine-data-copy-generate -affine-data-copy-generate-dma -affine-data-copy-generate-fast-mem-space=2 -affine-data-copy-generate-skip-non-unit-stride-loops -verify-diagnostics | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s -split-input-file -affine-data-copy-generate -affine-data-copy-generate-dma -affine-data-copy-generate-fast-mem-capacity=16 -affine-data-copy-generate-fast-mem-space=2 | FileCheck %s --check-prefix FAST-MEM-16KB
 
 // We run most test cases with -copy-skip-non-unit-stride-loops to allow testing
 // DMA generation at inner levels easily - since the DMA generation would
index 43b6c24..a83ef37 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -inline -mlir-disable-inline-simplify | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s -inline -mlir-disable-inline-simplify | FileCheck %s
 
 // Basic test that functions within affine operations are inlined.
 func @func_with_affine_ops(%N: index) {
index ca0baa4..4ad8b7e 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -split-input-file -verify-diagnostics
+// RUN: mlir-opt -allow-unregistered-dialect %s -split-input-file -verify-diagnostics
 
 // -----
 
index 029c42a..110233a 100644 (file)
@@ -1,6 +1,6 @@
-// RUN: mlir-opt %s -split-input-file  -affine-loop-tile -affine-tile-size=32 | FileCheck %s
-// RUN: mlir-opt %s -split-input-file -affine-loop-tile -affine-tile-cache-size=512 | FileCheck %s --check-prefix=MODEL
-// RUN: mlir-opt %s -split-input-file -affine-loop-tile -affine-tile-size=32 -affine-tile-separate | FileCheck %s --check-prefix=SEPARATE
+// RUN: mlir-opt -allow-unregistered-dialect %s -split-input-file  -affine-loop-tile -affine-tile-size=32 | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s -split-input-file -affine-loop-tile -affine-tile-cache-size=512 | FileCheck %s --check-prefix=MODEL
+// RUN: mlir-opt -allow-unregistered-dialect %s -split-input-file -affine-loop-tile -affine-tile-size=32 -affine-tile-separate | FileCheck %s --check-prefix=SEPARATE
 
 // -----
 
index c48da1d..cd42980 100644 (file)
@@ -1,5 +1,5 @@
-// RUN: mlir-opt -split-input-file %s | FileCheck %s
-// RUN: mlir-opt %s -mlir-print-op-generic | FileCheck -check-prefix=GENERIC %s
+// RUN: mlir-opt -allow-unregistered-dialect -split-input-file %s | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s -mlir-print-op-generic | FileCheck -check-prefix=GENERIC %s
 
 // Check that the attributes for the affine operations are round-tripped.
 // Check that `affine.terminator` is visible in the generic form.
index fa08a89..0788e6f 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -test-detect-parallel -split-input-file -verify-diagnostics | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s -test-detect-parallel -split-input-file -verify-diagnostics | FileCheck %s
 
 // CHECK-LABEL: func @loop_nest_3d_outer_two_parallel
 func @loop_nest_3d_outer_two_parallel(%N : index) {
index 2f3ea34..c8d2fd4 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -split-input-file -simplify-affine-structures | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s -split-input-file -simplify-affine-structures | FileCheck %s
 
 // CHECK-DAG: [[SET_EMPTY_2D:#set[0-9]+]] = affine_set<(d0, d1) : (1 == 0)>
 // CHECK-DAG: #set1 = affine_set<(d0, d1) : (d0 - 100 == 0, d1 - 10 == 0, -d0 + 100 >= 0, d1 >= 0)>
index 251e400..defb49a 100644 (file)
@@ -1,6 +1,6 @@
-// RUN: mlir-opt %s -affine-super-vectorizer-test -forward-slicing=true 2>&1 | FileCheck %s --check-prefix=FWD
-// RUN: mlir-opt %s -affine-super-vectorizer-test -backward-slicing=true 2>&1 | FileCheck %s --check-prefix=BWD
-// RUN: mlir-opt %s -affine-super-vectorizer-test -slicing=true 2>&1 | FileCheck %s --check-prefix=FWDBWD
+// RUN: mlir-opt -allow-unregistered-dialect %s -affine-super-vectorizer-test -forward-slicing=true 2>&1 | FileCheck %s --check-prefix=FWD
+// RUN: mlir-opt -allow-unregistered-dialect %s -affine-super-vectorizer-test -backward-slicing=true 2>&1 | FileCheck %s --check-prefix=BWD
+// RUN: mlir-opt -allow-unregistered-dialect %s -affine-super-vectorizer-test -slicing=true 2>&1 | FileCheck %s --check-prefix=FWDBWD
 
 ///   1       2      3      4
 ///   |_______|      |______|
index 60de5f1..9d23f7a 100644 (file)
@@ -1,5 +1,5 @@
-// RUN: mlir-opt %s -affine-loop-unroll-jam -unroll-jam-factor=2 | FileCheck %s
-// RUN: mlir-opt %s -affine-loop-unroll-jam -unroll-jam-factor=4 | FileCheck --check-prefix=UJAM-FOUR %s
+// RUN: mlir-opt -allow-unregistered-dialect %s -affine-loop-unroll-jam -unroll-jam-factor=2 | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s -affine-loop-unroll-jam -unroll-jam-factor=4 | FileCheck --check-prefix=UJAM-FOUR %s
 
 // CHECK-DAG: [[MAP_PLUS_1:#map[0-9]+]] = affine_map<(d0) -> (d0 + 1)>
 // CHECK-DAG: [[MAP_DIV_OFFSET:#map[0-9]+]] = affine_map<()[s0] -> (((s0 - 1) floordiv 2) * 2 + 1)>
index 3414aa1..7a352ea 100644 (file)
@@ -1,7 +1,7 @@
-// RUN: mlir-opt %s -affine-loop-unroll -unroll-full | FileCheck %s --check-prefix UNROLL-FULL
-// RUN: mlir-opt %s -affine-loop-unroll -unroll-full -unroll-full-threshold=2 | FileCheck %s --check-prefix SHORT
-// RUN: mlir-opt %s -affine-loop-unroll -unroll-factor=4 | FileCheck %s --check-prefix UNROLL-BY-4
-// RUN: mlir-opt %s -affine-loop-unroll -unroll-factor=1 | FileCheck %s --check-prefix UNROLL-BY-1
+// RUN: mlir-opt -allow-unregistered-dialect %s -affine-loop-unroll -unroll-full | FileCheck %s --check-prefix UNROLL-FULL
+// RUN: mlir-opt -allow-unregistered-dialect %s -affine-loop-unroll -unroll-full -unroll-full-threshold=2 | FileCheck %s --check-prefix SHORT
+// RUN: mlir-opt -allow-unregistered-dialect %s -affine-loop-unroll -unroll-factor=4 | FileCheck %s --check-prefix UNROLL-BY-4
+// RUN: mlir-opt -allow-unregistered-dialect %s -affine-loop-unroll -unroll-factor=1 | FileCheck %s --check-prefix UNROLL-BY-1
 
 // UNROLL-FULL-DAG: [[MAP0:#map[0-9]+]] = affine_map<(d0) -> (d0 + 1)>
 // UNROLL-FULL-DAG: [[MAP1:#map[0-9]+]] = affine_map<(d0) -> (d0 + 2)>
index 60364ca..196513b 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s | FileCheck %s
 
 module attributes {gpu.container_module} {
 
index 7d9a601..0d87347 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt -gpu-kernel-outlining -split-input-file -verify-diagnostics %s | FileCheck %s -dump-input-on-failure
+// RUN: mlir-opt -allow-unregistered-dialect -gpu-kernel-outlining -split-input-file -verify-diagnostics %s | FileCheck %s -dump-input-on-failure
 
 // CHECK: module attributes {gpu.container_module}
 
index c06174e..bb5a93c 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt -test-gpu-memory-promotion -split-input-file %s | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect -test-gpu-memory-promotion -split-input-file %s | FileCheck %s
 
 module @foo attributes {gpu.kernel_module} {
   // Verify that the attribution was indeed introduced
index 710328c..0562cd4 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -split-input-file -verify-diagnostics
+// RUN: mlir-opt -allow-unregistered-dialect %s -split-input-file -verify-diagnostics
 
 // expected-error@+1{{llvm.noalias argument attribute of non boolean type}}
 func @invalid_noalias(%arg0: !llvm.i32 {llvm.noalias = 3}) {
index 6962387..e827a78 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -split-input-file -verify-diagnostics
+// RUN: mlir-opt -allow-unregistered-dialect %s -split-input-file -verify-diagnostics
 
 func @loop_for_lb(%arg0: f32, %arg1: index) {
   // expected-error@+1 {{operand #0 must be index}}
index 6625c12..1399330 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -pass-pipeline='func(parallel-loop-fusion)' -split-input-file | FileCheck %s --dump-input-on-failure
+// RUN: mlir-opt -allow-unregistered-dialect %s -pass-pipeline='func(parallel-loop-fusion)' -split-input-file | FileCheck %s --dump-input-on-failure
 
 func @fuse_empty_loops() {
   %c2 = constant 2 : index
index 90976e8..8dbd62c 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -split-input-file | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s -split-input-file | FileCheck %s
 
 // -----
 // CHECK-LABEL: parseFullySpecified
index 272c530..ead636f 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -split-input-file -verify-diagnostics
+// RUN: mlir-opt -allow-unregistered-dialect %s -split-input-file -verify-diagnostics
 
 // -----
 func @invalidStatisticsMismatchedLayerType(%arg0: tensor<8x4x3xf32>) ->
index 82d2ae6..0e609a7 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -split-input-file | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s -split-input-file | FileCheck %s
 
 // -----
 // All per-layer params specified:
index ee87421..7a7b644 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt -split-input-file -verify-diagnostics %s | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect -split-input-file -verify-diagnostics %s | FileCheck %s
 
 // CHECK-LABEL: @source
 func @source(%arg0: tensor<4xf32>, %arg1: tensor<4xf32>, %arg2: tensor<4xf32>) -> (tensor<4xf32>) {
index 9eab38c..4951171 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt -split-input-file -verify-diagnostics %s | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect -split-input-file -verify-diagnostics %s | FileCheck %s
 
 //===----------------------------------------------------------------------===//
 // spv.Branch
index aee4ff2..5cf91c0 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt -split-input-file -verify-diagnostics %s | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect -split-input-file -verify-diagnostics %s | FileCheck %s
 
 //===----------------------------------------------------------------------===//
 // spv.AccessChain
index 8a51ad5..8e0f447 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt -split-input-file -verify-diagnostics %s | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect -split-input-file -verify-diagnostics %s | FileCheck %s
 
 //===----------------------------------------------------------------------===//
 // spv._address_of
index a9bb0b6..9b578ac 100644 (file)
@@ -47,6 +47,7 @@ static MLIRContext &globalContext() {
   }();
   (void)init_once;
   static thread_local MLIRContext context;
+  context.allowUnregisteredDialects();
   return context;
 }
 
index d4c8004..f953c00 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s | FileCheck %s
 
 // Identity maps used in trivial compositions in MemRefs are optimized away.
 // CHECK-NOT: #map{{[0-9]+}} = affine_map<(d0, d1) -> (d0, d1)>
index 454ecfc..b50ffa6 100644 (file)
@@ -1,8 +1,8 @@
-// RUN: mlir-opt %s | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s | FileCheck %s
 // Verify the printed output can be parsed.
-// RUN: mlir-opt %s | mlir-opt | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s | mlir-opt -allow-unregistered-dialect | FileCheck %s
 // Verify the generic form can be parsed.
-// RUN: mlir-opt -mlir-print-op-generic %s | mlir-opt | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect -mlir-print-op-generic %s | mlir-opt -allow-unregistered-dialect | FileCheck %s
 
 // CHECK: #map0 = affine_map<(d0) -> (d0 + 1)>
 
index f2ce955..bfd1f1b 100644 (file)
@@ -1,5 +1,5 @@
-// RUN: mlir-opt %s -verify-diagnostics -split-input-file -mlir-print-elementsattrs-with-hex-if-larger=1 | FileCheck %s --check-prefix=HEX
-// RUN: mlir-opt %s -verify-diagnostics -split-input-file | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s -verify-diagnostics -split-input-file -mlir-print-elementsattrs-with-hex-if-larger=1 | FileCheck %s --check-prefix=HEX
+// RUN: mlir-opt -allow-unregistered-dialect %s -verify-diagnostics -split-input-file | FileCheck %s
 
 // HEX: dense<"0x00000000000024400000000000001440"> : tensor<2xf64>
 "foo.op"() {dense.attr = dense<[10.0, 5.0]> : tensor<2xf64>} : () -> ()
index 5f311f3..3f0804a 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -split-input-file -verify-diagnostics
+// RUN: mlir-opt -allow-unregistered-dialect %s -split-input-file -verify-diagnostics
 
 func @dim(tensor<1xf32>) {
 ^bb(%0: tensor<1xf32>):
index 4788884..cbd97cd 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -split-input-file -verify-diagnostics
+// RUN: mlir-opt -allow-unregistered-dialect %s -split-input-file -verify-diagnostics
 
 // Check different error cases.
 // -----
index b0039dd..6227ba5 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -mlir-print-debuginfo | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s -mlir-print-debuginfo | FileCheck %s
 // This test verifies that debug locations are round-trippable.
 
 #set0 = affine_set<(d0) : (1 == 0)>
index 84a404b..2d4ea83 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -split-input-file -mlir-print-debuginfo | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s -split-input-file -mlir-print-debuginfo | FileCheck %s
 
 // CHECK: module {
 module {
index 63abe6d..5c5b54d 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt -print-op-stats %s -o=/dev/null 2>&1 | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect -print-op-stats %s -o=/dev/null 2>&1 | FileCheck %s
 
 func @main(tensor<4xf32>, tensor<4xf32>) -> tensor<4xf32> {
 ^bb0(%arg0: tensor<4xf32>, %arg1: tensor<4xf32>):
index 3718d34..b33ca4c 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -test-opaque-loc -mlir-print-debuginfo | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s -test-opaque-loc -mlir-print-debuginfo | FileCheck %s
 // This test verifies that debug opaque locations can be printed.
 
 #set0 = affine_set<(d0) : (1 == 0)>
index 45ee1e1..a42bf32 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s | FileCheck %s
 
 // CHECK-DAG: #map{{[0-9]+}} = affine_map<(d0, d1, d2, d3, d4)[s0] -> (d0, d1, d2, d4, d3)>
 #map0 = affine_map<(d0, d1, d2, d3, d4)[s0] -> (d0, d1, d2, d4, d3)>
index 116bfa5..79d282f 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -mlir-print-debuginfo -mlir-pretty-debuginfo | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s -mlir-print-debuginfo -mlir-pretty-debuginfo | FileCheck %s
 
 #set0 = affine_set<(d0) : (1 == 0)>
 
index 6e980fa..caed369 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s | FileCheck %s
 
 // CHECK-LABEL: func @custom_region_names
 func @custom_region_names() -> () {
index b6f3605..93b25fc 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -mlir-print-local-scope | FileCheck %s --dump-input-on-failure
+// RUN: mlir-opt -allow-unregistered-dialect %s -mlir-print-local-scope | FileCheck %s --dump-input-on-failure
 
 // CHECK: "foo.op"() : () -> memref<?xf32, affine_map<(d0) -> (d0 * 2)>>
 "foo.op"() : () -> (memref<?xf32, affine_map<(d0) -> (2*d0)>>)
index 27e19d6..a32371c 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -split-input-file -verify-diagnostics | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s -split-input-file -verify-diagnostics | FileCheck %s
 
 //===----------------------------------------------------------------------===//
 // Test the number of regions
index cc75fec..9193c47 100644 (file)
@@ -1,5 +1,5 @@
-// RUN: mlir-opt %s -symbol-dce -split-input-file -verify-diagnostics | FileCheck %s
-// RUN: mlir-opt %s -pass-pipeline="module(symbol-dce)" -split-input-file | FileCheck %s --check-prefix=NESTED
+// RUN: mlir-opt -allow-unregistered-dialect %s -symbol-dce -split-input-file -verify-diagnostics | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s -pass-pipeline="module(symbol-dce)" -split-input-file | FileCheck %s --check-prefix=NESTED
 
 // Check that trivially dead and trivially live non-nested cases are handled.
 
index 25d22e4..2924c20 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -test-symbol-rauw -split-input-file | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s -test-symbol-rauw -split-input-file | FileCheck %s
 
 // Symbol references to the module itself don't affect uses of symbols within
 // its table.
index f95ac6b..17f4a30 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -test-symbol-uses -split-input-file -verify-diagnostics
+// RUN: mlir-opt -allow-unregistered-dialect %s -test-symbol-uses -split-input-file -verify-diagnostics
 
 // Symbol references to the module itself don't affect uses of symbols within
 // its table.
index 655fbb8..a076d8f 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -split-input-file -verify-diagnostics | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s -split-input-file -verify-diagnostics | FileCheck %s
 
 // CHECK: succeededSameOperandsElementType
 func @succeededSameOperandsElementType(%t10x10 : tensor<10x10xf32>, %t1f: tensor<1xf32>, %v1: vector<1xf32>, %t1i: tensor<1xi32>, %sf: f32) {
index 92918f1..661fb04 100644 (file)
@@ -1,5 +1,5 @@
-// RUN: mlir-opt %s | FileCheck %s
-// RUN: mlir-opt -mlir-print-op-generic -mlir-print-debuginfo %s | FileCheck %s --check-prefix=CHECK-GENERIC
+// RUN: mlir-opt -allow-unregistered-dialect %s | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect -mlir-print-op-generic -mlir-print-debuginfo %s | FileCheck %s --check-prefix=CHECK-GENERIC
 
 // CHECK-LABEL: func @wrapping_op
 // CHECK-GENERIC: "func"
index eee8355..b93af00 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -split-input-file -pass-pipeline='func(canonicalize)' | FileCheck %s --dump-input=fail
+// RUN: mlir-opt -allow-unregistered-dialect %s -split-input-file -pass-pipeline='func(canonicalize)' | FileCheck %s --dump-input=fail
 
 // Test case: Simple case of deleting a dead pure op.
 
index 877693b..5e54c62 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -pass-pipeline='func(canonicalize)' -split-input-file | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s -pass-pipeline='func(canonicalize)' -split-input-file | FileCheck %s
 
 // CHECK-LABEL: func @test_subi_zero
 func @test_subi_zero(%arg0: i32) -> i32 {
index b156ca9..304c987 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -split-input-file -test-constant-fold | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s -split-input-file -test-constant-fold | FileCheck %s
 
 // -----
 
index 8e52617..9be014d 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -pass-pipeline='func(cse)' | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s -pass-pipeline='func(cse)' | FileCheck %s
 
 // CHECK-DAG: #map0 = affine_map<(d0) -> (d0 mod 2)>
 #map0 = affine_map<(d0) -> (d0 mod 2)>
index d9c8bf9..73b6489 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -inline | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s -inline | FileCheck %s
 
 // This file tests the callgraph dead code elimination performed by the inliner.
 
index 4153998..cde2018 100644 (file)
@@ -1,5 +1,5 @@
-// RUN: mlir-opt -snapshot-op-locations='filename=%/t' -mlir-print-debuginfo %s | FileCheck %s -DFILE=%/t
-// RUN: mlir-opt -snapshot-op-locations='filename=%/t tag='tagged'' -mlir-print-debuginfo %s | FileCheck %s --check-prefix=TAG -DFILE=%/t
+// RUN: mlir-opt -allow-unregistered-dialect -snapshot-op-locations='filename=%/t' -mlir-print-debuginfo %s | FileCheck %s -DFILE=%/t
+// RUN: mlir-opt -allow-unregistered-dialect -snapshot-op-locations='filename=%/t tag='tagged'' -mlir-print-debuginfo %s | FileCheck %s --check-prefix=TAG -DFILE=%/t
 
 // CHECK-LABEL: func @function
 // CHECK-NEXT: loc("[[FILE]]":{{[0-9]+}}:{{[0-9]+}})
index d10cf19..b25f912 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt -loop-coalescing %s | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect -loop-coalescing %s | FileCheck %s
 
 // CHECK-LABEL: @one_3d_nest
 func @one_3d_nest() {
index 4b5c778..3d8f801 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -test-loop-fusion -test-loop-fusion-dependence-check -split-input-file -verify-diagnostics | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s -test-loop-fusion -test-loop-fusion-dependence-check -split-input-file -verify-diagnostics | FileCheck %s
 
 // -----
 
index 89140e4..d1e1587 100644 (file)
@@ -1,5 +1,5 @@
-// RUN: mlir-opt %s -affine-loop-fusion -split-input-file | FileCheck %s
-// RUN: mlir-opt %s -affine-loop-fusion -fusion-maximal -split-input-file | FileCheck %s --check-prefix=MAXIMAL
+// RUN: mlir-opt -allow-unregistered-dialect %s -affine-loop-fusion -split-input-file | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s -affine-loop-fusion -fusion-maximal -split-input-file | FileCheck %s --check-prefix=MAXIMAL
 
 // TODO(andydavis) Add more tests:
 // *) Add nested fusion test cases when non-constant loop bound support is
index 0fe8f71..deb193e 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -memref-dataflow-opt | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s -memref-dataflow-opt | FileCheck %s
 
 // CHECK-DAG: [[MAP0:#map[0-9]+]] = affine_map<(d0, d1) -> (d1 + 1)>
 // CHECK-DAG: [[MAP1:#map[0-9]+]] = affine_map<(d0, d1) -> (d0)>
index 68aa4b0..c674ef7 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -pass-pipeline='func(parallel-loop-collapsing{collapsed-indices-0=0,3 collapsed-indices-1=1,4 collapsed-indices-2=2}, canonicalize)' | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s -pass-pipeline='func(parallel-loop-collapsing{collapsed-indices-0=0,3 collapsed-indices-1=1,4 collapsed-indices-2=2}, canonicalize)' | FileCheck %s
 
 // CHECK-LABEL:   func @parallel_many_dims() {
 func @parallel_many_dims() {
index fdfd8cf..a7981e5 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt -test-mapping-to-processing-elements %s | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect -test-mapping-to-processing-elements %s | FileCheck %s
 
 // CHECK-LABEL: @map1d
 //       CHECK: (%[[lb:.*]]: index, %[[ub:.*]]: index, %[[step:.*]]: index) {
index a2ff126..842c1d6 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -split-input-file -affine-pipeline-data-transfer | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s -split-input-file -affine-pipeline-data-transfer | FileCheck %s
 
 // -----
 
index 0b05c61..d769300 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -pass-pipeline='func(parallel-loop-collapsing{collapsed-indices-0=0,1}, canonicalize)' | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s -pass-pipeline='func(parallel-loop-collapsing{collapsed-indices-0=0,1}, canonicalize)' | FileCheck %s
 
 // CHECK-LABEL:   func @collapse_to_single() {
 func @collapse_to_single() {
index 49bb220..f1bf62e 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -mlir-print-debuginfo -strip-debuginfo | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s -mlir-print-debuginfo -strip-debuginfo | FileCheck %s
 // This test verifies that debug locations are stripped.
 
 #set0 = affine_set<(d0) : (1 == 0)>
index 920fd8c..0cd308d 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -pass-pipeline='func(canonicalize)' | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s -pass-pipeline='func(canonicalize)' | FileCheck %s
 
 // CHECK-LABEL: func @remove_op_with_inner_ops_pattern
 func @remove_op_with_inner_ops_pattern() {
index d3a1c7c..099410e 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -test-inline | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s -test-inline | FileCheck %s
 
 // CHECK-LABEL: func @inline_with_arg
 func @inline_with_arg(%arg0 : i32) -> i32 {
index a53813a..cd0b936 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt -test-legalize-patterns -verify-diagnostics -test-legalize-mode=analysis %s | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect -test-legalize-patterns -verify-diagnostics -test-legalize-mode=analysis %s | FileCheck %s
 // expected-remark@-2 {{op 'module' is legalizable}}
 // expected-remark@-3 {{op 'module_terminator' is legalizable}}
 
index 6bbda4a..7652de4 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt -test-legalize-patterns -test-legalize-mode=full -split-input-file -verify-diagnostics %s | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect -test-legalize-patterns -test-legalize-mode=full -split-input-file -verify-diagnostics %s | FileCheck %s
 
 // CHECK-LABEL: func @multi_level_mapping
 func @multi_level_mapping() {
index dd83306..bd73cf3 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt -split-input-file -test-legalize-patterns -verify-diagnostics %s | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect -split-input-file -test-legalize-patterns -verify-diagnostics %s | FileCheck %s
 
 // CHECK-LABEL: verifyDirectPattern
 func @verifyDirectPattern() -> i32 {
index 6c53527..5e0e484 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s | mlir-opt -verify-diagnostics | FileCheck %s
+// RUN: mlir-opt -allow-unregistered-dialect %s | mlir-opt -allow-unregistered-dialect -verify-diagnostics | FileCheck %s
 
 // CHECK: %[[I64:.*]] =
 %i64 = "foo.op"() : () -> (i64)
index a2b3dfc..0aca9f6 100644 (file)
@@ -85,6 +85,10 @@ static cl::opt<bool>
                  cl::desc("Run the verifier after each transformation pass"),
                  cl::init(true));
 
+static cl::opt<bool> allowUnregisteredDialects(
+    "allow-unregistered-dialect",
+    cl::desc("Allow operation with no registered dialects"), cl::init(false));
+
 void registerTestPasses() {
   registerConvertToTargetEnvPass();
   registerInliner();
@@ -163,5 +167,6 @@ int main(int argc, char **argv) {
   }
 
   return failed(MlirOptMain(output->os(), std::move(file), passPipeline,
-                            splitInputFile, verifyDiagnostics, verifyPasses));
+                            splitInputFile, verifyDiagnostics, verifyPasses,
+                            allowUnregisteredDialects));
 }
index cd1b226..1efcaec 100644 (file)
@@ -73,6 +73,7 @@ int main(int argc, char **argv) {
   auto processBuffer = [&](std::unique_ptr<llvm::MemoryBuffer> ownedBuffer,
                            raw_ostream &os) {
     MLIRContext context;
+    context.allowUnregisteredDialects();
     llvm::SourceMgr sourceMgr;
     sourceMgr.AddNewSourceBuffer(std::move(ownedBuffer), llvm::SMLoc());
 
index ad3cac4..b1cd5ef 100644 (file)
 using namespace mlir;
 using namespace mlir::detail;
 
-namespace {
-Operation *createOp(MLIRContext *context, bool resizableOperands,
-                    ArrayRef<Value> operands = llvm::None,
-                    ArrayRef<Type> resultTypes = llvm::None) {
+static Operation *createOp(MLIRContext *context, bool resizableOperands,
+                           ArrayRef<Value> operands = llvm::None,
+                           ArrayRef<Type> resultTypes = llvm::None) {
+  context->allowUnregisteredDialects();
   return Operation::create(
       UnknownLoc::get(context), OperationName("foo.bar", context), resultTypes,
       operands, llvm::None, llvm::None, 0, resizableOperands);
 }
 
+namespace {
 TEST(OperandStorageTest, NonResizable) {
   MLIRContext context;
   Builder builder(&context);