Adding a VMLA dialect and conversion skeleton.
This is pure boilerplate. Future changes will define the ops and conversions between HLO->VMLA and VMLA->VM.
PiperOrigin-RevId: 292271559
diff --git a/iree/compiler/Dialect/IREE/IR/IREETypes.h b/iree/compiler/Dialect/IREE/IR/IREETypes.h
index 87501e5..4066f8c 100644
--- a/iree/compiler/Dialect/IREE/IR/IREETypes.h
+++ b/iree/compiler/Dialect/IREE/IR/IREETypes.h
@@ -42,6 +42,7 @@
FIRST_SEQ_TYPE = Type::FIRST_IREE_TYPE + 40,
FIRST_SHAPE_TYPE = Type::FIRST_IREE_TYPE + 60,
FIRST_STRING_TYPE = Type::FIRST_IREE_TYPE + 80,
+ FIRST_VMLA_TYPE = Type::FIRST_IREE_TYPE + 100,
};
} // namespace TypeKind
@@ -93,6 +94,14 @@
} // namespace TypeKind
} // namespace Strings
+namespace VMLA {
+namespace TypeKind {
+enum Kind {
+ Buffer = IREE::TypeKind::FIRST_VMLA_TYPE,
+};
+} // namespace TypeKind
+} // namespace VMLA
+
/// Base type for RefObject-derived types.
/// These can be wrapped in RefPtrType.
class RefObjectType : public Type {
diff --git a/iree/compiler/Dialect/VMLA/BUILD b/iree/compiler/Dialect/VMLA/BUILD
new file mode 100644
index 0000000..8ec7202
--- /dev/null
+++ b/iree/compiler/Dialect/VMLA/BUILD
@@ -0,0 +1,29 @@
+# Copyright 2020 Google LLC
+#
+# 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
+#
+# https://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.
+
+load("//build_tools/embed_data:build_defs.bzl", "cc_embed_data")
+
+package(
+ default_visibility = ["//visibility:public"],
+ licenses = ["notice"], # Apache 2.0
+)
+
+cc_embed_data(
+ name = "vmla_imports",
+ srcs = ["vmla.imports.mlir"],
+ cc_file_output = "vmla.imports.cc",
+ cpp_namespace = "mlir::iree_compiler",
+ flatten = True,
+ h_file_output = "vmla.imports.h",
+)
diff --git a/iree/compiler/Dialect/VMLA/CMakeLists.txt b/iree/compiler/Dialect/VMLA/CMakeLists.txt
new file mode 100644
index 0000000..e2294e7
--- /dev/null
+++ b/iree/compiler/Dialect/VMLA/CMakeLists.txt
@@ -0,0 +1,32 @@
+# Copyright 2020 Google LLC
+#
+# 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
+#
+# https://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.
+
+add_subdirectory(Conversion)
+add_subdirectory(IR)
+add_subdirectory(Transforms)
+
+iree_cc_embed_data(
+ NAME
+ vmla_imports
+ SRCS
+ "vmla.imports.mlir"
+ CC_FILE_OUTPUT
+ "vmla.imports.cc"
+ H_FILE_OUTPUT
+ "vmla.imports.h"
+ CPP_NAMESPACE
+ "mlir::iree_compiler"
+ FLATTEN
+ PUBLIC
+)
diff --git a/iree/compiler/Dialect/VMLA/Conversion/CMakeLists.txt b/iree/compiler/Dialect/VMLA/Conversion/CMakeLists.txt
new file mode 100644
index 0000000..069a839
--- /dev/null
+++ b/iree/compiler/Dialect/VMLA/Conversion/CMakeLists.txt
@@ -0,0 +1,16 @@
+# Copyright 2020 Google LLC
+#
+# 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
+#
+# https://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.
+
+add_subdirectory(HLOToVMLA)
+add_subdirectory(VMLAToVM)
diff --git a/iree/compiler/Dialect/VMLA/Conversion/HLOToVMLA/BUILD b/iree/compiler/Dialect/VMLA/Conversion/HLOToVMLA/BUILD
new file mode 100644
index 0000000..9d2d5e2
--- /dev/null
+++ b/iree/compiler/Dialect/VMLA/Conversion/HLOToVMLA/BUILD
@@ -0,0 +1,39 @@
+# Copyright 2020 Google LLC
+#
+# 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
+#
+# https://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.
+
+package(
+ default_visibility = ["//visibility:public"],
+ licenses = ["notice"], # Apache 2.0
+)
+
+cc_library(
+ name = "HLOToVMLA",
+ srcs = [
+ "ConvertHLOToVMLA.cpp",
+ ],
+ hdrs = [
+ "ConvertHLOToVMLA.h",
+ ],
+ deps = [
+ "//iree/compiler/Dialect/IREE/IR",
+ "//iree/compiler/Dialect/VMLA/IR",
+ "//iree/compiler/Dialect/VMLA/IR:VMLADialect",
+ "@llvm-project//mlir:IR",
+ "@llvm-project//mlir:Pass",
+ "@llvm-project//mlir:StandardOps",
+ "@llvm-project//mlir:Transforms",
+ "@org_tensorflow//tensorflow/compiler/mlir/xla:hlo",
+ ],
+ alwayslink = 1,
+)
diff --git a/iree/compiler/Dialect/VMLA/Conversion/HLOToVMLA/CMakeLists.txt b/iree/compiler/Dialect/VMLA/Conversion/HLOToVMLA/CMakeLists.txt
new file mode 100644
index 0000000..3bb8e13
--- /dev/null
+++ b/iree/compiler/Dialect/VMLA/Conversion/HLOToVMLA/CMakeLists.txt
@@ -0,0 +1,35 @@
+# Copyright 2020 Google LLC
+#
+# 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
+#
+# https://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.
+
+add_subdirectory(test)
+
+iree_cc_library(
+ NAME
+ HLOToVMLA
+ HDRS
+ "ConvertHLOToVMLA.h"
+ SRCS
+ "ConvertHLOToVMLA.cpp"
+ DEPS
+ iree::compiler::Dialect::IREE::IR
+ iree::compiler::Dialect::VMLA::IR
+ iree::compiler::Dialect::VMLA::IR::VMLADialect
+ MLIRIR
+ MLIRPass
+ MLIRStandardOps
+ MLIRTransforms
+ tensorflow::mlir_xla
+ ALWAYSLINK
+ PUBLIC
+)
diff --git a/iree/compiler/Dialect/VMLA/Conversion/HLOToVMLA/ConvertHLOToVMLA.cpp b/iree/compiler/Dialect/VMLA/Conversion/HLOToVMLA/ConvertHLOToVMLA.cpp
new file mode 100644
index 0000000..a0ba8df
--- /dev/null
+++ b/iree/compiler/Dialect/VMLA/Conversion/HLOToVMLA/ConvertHLOToVMLA.cpp
@@ -0,0 +1,40 @@
+// Copyright 2020 Google LLC
+//
+// 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
+//
+// https://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 "iree/compiler/Dialect/VMLA/Conversion/HLOToVMLA/ConvertHLOToVMLA.h"
+
+#include "iree/compiler/Dialect/IREE/IR/IREETypes.h"
+#include "iree/compiler/Dialect/VMLA/IR/VMLADialect.h"
+#include "iree/compiler/Dialect/VMLA/IR/VMLAOps.h"
+#include "iree/compiler/Dialect/VMLA/IR/VMLATypes.h"
+#include "mlir/Dialect/StandardOps/Ops.h"
+#include "mlir/IR/Attributes.h"
+#include "mlir/IR/Builders.h"
+#include "mlir/IR/Function.h"
+#include "mlir/IR/Matchers.h"
+#include "mlir/IR/Module.h"
+#include "mlir/IR/SymbolTable.h"
+#include "mlir/Transforms/DialectConversion.h"
+
+namespace mlir {
+namespace iree_compiler {
+
+void populateHLOToVMLAPatterns(MLIRContext *context,
+ OwningRewritePatternList &patterns,
+ TypeConverter &typeConverter) {
+ // TODO(benvanik): conversion patterns.
+}
+
+} // namespace iree_compiler
+} // namespace mlir
diff --git a/iree/compiler/Dialect/VMLA/Conversion/HLOToVMLA/ConvertHLOToVMLA.h b/iree/compiler/Dialect/VMLA/Conversion/HLOToVMLA/ConvertHLOToVMLA.h
new file mode 100644
index 0000000..4c71f38
--- /dev/null
+++ b/iree/compiler/Dialect/VMLA/Conversion/HLOToVMLA/ConvertHLOToVMLA.h
@@ -0,0 +1,33 @@
+// Copyright 2020 Google LLC
+//
+// 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
+//
+// https://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.
+
+#ifndef IREE_COMPILER_DIALECT_VMLA_CONVERSION_HLOTOVMLA_CONVERTHLOTOVMLA_H_
+#define IREE_COMPILER_DIALECT_VMLA_CONVERSION_HLOTOVMLA_CONVERTHLOTOVMLA_H_
+
+#include "iree/compiler/Dialect/VMLA/IR/VMLAOps.h"
+#include "mlir/Pass/Pass.h"
+#include "mlir/Transforms/DialectConversion.h"
+
+namespace mlir {
+namespace iree_compiler {
+
+// Populates conversion patterns from the XLA HLO dialect to the VMLA dialect.
+void populateHLOToVMLAPatterns(MLIRContext *context,
+ OwningRewritePatternList &patterns,
+ TypeConverter &typeConverter);
+
+} // namespace iree_compiler
+} // namespace mlir
+
+#endif // IREE_COMPILER_DIALECT_VMLA_CONVERSION_HLOTOVMLA_CONVERTHLOTOVMLA_H_
diff --git a/iree/compiler/Dialect/VMLA/Conversion/HLOToVMLA/test/BUILD b/iree/compiler/Dialect/VMLA/Conversion/HLOToVMLA/test/BUILD
new file mode 100644
index 0000000..14281d1
--- /dev/null
+++ b/iree/compiler/Dialect/VMLA/Conversion/HLOToVMLA/test/BUILD
@@ -0,0 +1,29 @@
+# Copyright 2020 Google LLC
+#
+# 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
+#
+# https://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.
+
+load("//iree:lit_test.bzl", "iree_lit_test_suite")
+
+package(
+ default_visibility = ["//visibility:public"],
+ licenses = ["notice"], # Apache 2.0
+)
+
+iree_lit_test_suite(
+ name = "lit",
+ srcs = glob(["*.mlir"]),
+ data = [
+ "//iree/tools:IreeFileCheck",
+ "//iree/tools:iree-opt",
+ ],
+)
diff --git a/iree/compiler/Dialect/VMLA/Conversion/HLOToVMLA/test/CMakeLists.txt b/iree/compiler/Dialect/VMLA/Conversion/HLOToVMLA/test/CMakeLists.txt
new file mode 100644
index 0000000..04f426a
--- /dev/null
+++ b/iree/compiler/Dialect/VMLA/Conversion/HLOToVMLA/test/CMakeLists.txt
@@ -0,0 +1,22 @@
+# Copyright 2020 Google LLC
+#
+# 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
+#
+# https://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.
+
+iree_lit_test_suite(
+ NAME
+ lit
+ SRCS
+ DATA
+ iree::tools::IreeFileCheck
+ iree::tools::iree-opt
+)
diff --git a/iree/compiler/Dialect/VMLA/Conversion/VMLAToVM/BUILD b/iree/compiler/Dialect/VMLA/Conversion/VMLAToVM/BUILD
new file mode 100644
index 0000000..59cb50a6
--- /dev/null
+++ b/iree/compiler/Dialect/VMLA/Conversion/VMLAToVM/BUILD
@@ -0,0 +1,41 @@
+# Copyright 2020 Google LLC
+#
+# 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
+#
+# https://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.
+
+package(
+ default_visibility = ["//visibility:public"],
+ licenses = ["notice"], # Apache 2.0
+)
+
+cc_library(
+ name = "VMLAToVM",
+ srcs = [
+ "ConvertVMLAToVM.cpp",
+ ],
+ hdrs = [
+ "ConvertVMLAToVM.h",
+ ],
+ deps = [
+ "//iree/compiler/Dialect/IREE/IR",
+ "//iree/compiler/Dialect/VM/Conversion",
+ "//iree/compiler/Dialect/VM/Conversion/StandardToVM",
+ "//iree/compiler/Dialect/VM/IR",
+ "//iree/compiler/Dialect/VMLA:vmla_imports",
+ "//iree/compiler/Dialect/VMLA/IR",
+ "@llvm-project//mlir:IR",
+ "@llvm-project//mlir:Pass",
+ "@llvm-project//mlir:StandardOps",
+ "@llvm-project//mlir:Transforms",
+ ],
+ alwayslink = 1,
+)
diff --git a/iree/compiler/Dialect/VMLA/Conversion/VMLAToVM/CMakeLists.txt b/iree/compiler/Dialect/VMLA/Conversion/VMLAToVM/CMakeLists.txt
new file mode 100644
index 0000000..70db8a0
--- /dev/null
+++ b/iree/compiler/Dialect/VMLA/Conversion/VMLAToVM/CMakeLists.txt
@@ -0,0 +1,37 @@
+# Copyright 2020 Google LLC
+#
+# 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
+#
+# https://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.
+
+add_subdirectory(test)
+
+iree_cc_library(
+ NAME
+ VMLAToVM
+ HDRS
+ "ConvertVMLAToVM.h"
+ SRCS
+ "ConvertVMLAToVM.cpp"
+ DEPS
+ iree::compiler::Dialect::IREE::IR
+ iree::compiler::Dialect::VM::Conversion
+ iree::compiler::Dialect::VM::Conversion::StandardToVM
+ iree::compiler::Dialect::VM::IR
+ iree::compiler::Dialect::VMLA::IR
+ iree::compiler::Dialect::VMLA::vmla_imports
+ MLIRIR
+ MLIRPass
+ MLIRStandardOps
+ MLIRTransforms
+ ALWAYSLINK
+ PUBLIC
+)
diff --git a/iree/compiler/Dialect/VMLA/Conversion/VMLAToVM/ConvertVMLAToVM.cpp b/iree/compiler/Dialect/VMLA/Conversion/VMLAToVM/ConvertVMLAToVM.cpp
new file mode 100644
index 0000000..b159ff1
--- /dev/null
+++ b/iree/compiler/Dialect/VMLA/Conversion/VMLAToVM/ConvertVMLAToVM.cpp
@@ -0,0 +1,89 @@
+// Copyright 2020 Google LLC
+//
+// 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
+//
+// https://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 "iree/compiler/Dialect/VMLA/Conversion/VMLAToVM/ConvertVMLAToVM.h"
+
+#include "iree/compiler/Dialect/IREE/IR/IREETypes.h"
+#include "iree/compiler/Dialect/VM/Conversion/ConversionTarget.h"
+#include "iree/compiler/Dialect/VM/Conversion/ImportUtils.h"
+#include "iree/compiler/Dialect/VM/Conversion/StandardToVM/ConvertStandardToVM.h"
+#include "iree/compiler/Dialect/VM/Conversion/TypeConverter.h"
+#include "iree/compiler/Dialect/VM/IR/VMOps.h"
+#include "iree/compiler/Dialect/VMLA/IR/VMLAOps.h"
+#include "iree/compiler/Dialect/VMLA/IR/VMLATypes.h"
+#include "iree/compiler/Dialect/VMLA/vmla.imports.h"
+#include "mlir/Dialect/StandardOps/Ops.h"
+#include "mlir/IR/Attributes.h"
+#include "mlir/IR/Builders.h"
+#include "mlir/IR/Function.h"
+#include "mlir/IR/Matchers.h"
+#include "mlir/IR/Module.h"
+#include "mlir/IR/SymbolTable.h"
+#include "mlir/Transforms/DialectConversion.h"
+
+namespace mlir {
+namespace iree_compiler {
+
+void populateVMLAToVMPatterns(MLIRContext *context, SymbolTable &importSymbols,
+ OwningRewritePatternList &patterns,
+ TypeConverter &typeConverter) {
+ // TODO(benvanik): conversion patterns.
+}
+
+namespace {
+
+// A pass converting the IREE flow dialect into the IREE VMLA dialect.
+class ConvertVMLAToVMPass : public ModulePass<ConvertVMLAToVMPass> {
+ public:
+ void runOnModule() override {
+ auto *context = &getContext();
+
+ VMConversionTarget conversionTarget(context);
+ VMTypeConverter typeConverter;
+
+ mlir::ModuleOp outerModuleOp, innerModuleOp;
+ std::tie(outerModuleOp, innerModuleOp) =
+ VMConversionTarget::nestModuleForConversion(getModule());
+
+ appendImportModule(
+ StringRef(vmla_imports_create()->data, vmla_imports_create()->size),
+ innerModuleOp);
+
+ OwningRewritePatternList conversionPatterns;
+ populateStandardToVMPatterns(context, conversionPatterns);
+
+ SymbolTable importSymbols(innerModuleOp);
+ populateVMLAToVMPatterns(context, importSymbols, conversionPatterns,
+ typeConverter);
+
+ if (failed(applyPartialConversion(outerModuleOp, conversionTarget,
+ conversionPatterns, &typeConverter))) {
+ outerModuleOp.emitError() << "conversion to vm.module failed";
+ return signalPassFailure();
+ }
+ }
+};
+
+} // namespace
+
+std::unique_ptr<OpPassBase<ModuleOp>> createConvertVMLAToVMPass() {
+ return std::make_unique<ConvertVMLAToVMPass>(); // NOLINT
+}
+
+static PassRegistration<ConvertVMLAToVMPass> pass(
+ "iree-convert-vmla-to-vm",
+ "Convert the IREE VMLA dialect to the IREE VM dialect");
+
+} // namespace iree_compiler
+} // namespace mlir
diff --git a/iree/compiler/Dialect/VMLA/Conversion/VMLAToVM/ConvertVMLAToVM.h b/iree/compiler/Dialect/VMLA/Conversion/VMLAToVM/ConvertVMLAToVM.h
new file mode 100644
index 0000000..cb14581
--- /dev/null
+++ b/iree/compiler/Dialect/VMLA/Conversion/VMLAToVM/ConvertVMLAToVM.h
@@ -0,0 +1,33 @@
+// Copyright 2020 Google LLC
+//
+// 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
+//
+// https://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.
+
+#ifndef IREE_COMPILER_DIALECT_VMLA_CONVERSION_VMLATOVM_CONVERTVMLATOVM_H_
+#define IREE_COMPILER_DIALECT_VMLA_CONVERSION_VMLATOVM_CONVERTVMLATOVM_H_
+
+#include "iree/compiler/Dialect/VMLA/IR/VMLAOps.h"
+#include "mlir/Pass/Pass.h"
+#include "mlir/Transforms/DialectConversion.h"
+
+namespace mlir {
+namespace iree_compiler {
+
+// Populates conversion patterns from the VMLA dialect to the VM dialect.
+void populateVMLAToVMPatterns(MLIRContext *context, SymbolTable &importSymbols,
+ OwningRewritePatternList &patterns,
+ TypeConverter &typeConverter);
+
+} // namespace iree_compiler
+} // namespace mlir
+
+#endif // IREE_COMPILER_DIALECT_VMLA_CONVERSION_VMLATOVM_CONVERTVMLATOVM_H_
diff --git a/iree/compiler/Dialect/VMLA/Conversion/VMLAToVM/test/BUILD b/iree/compiler/Dialect/VMLA/Conversion/VMLAToVM/test/BUILD
new file mode 100644
index 0000000..14281d1
--- /dev/null
+++ b/iree/compiler/Dialect/VMLA/Conversion/VMLAToVM/test/BUILD
@@ -0,0 +1,29 @@
+# Copyright 2020 Google LLC
+#
+# 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
+#
+# https://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.
+
+load("//iree:lit_test.bzl", "iree_lit_test_suite")
+
+package(
+ default_visibility = ["//visibility:public"],
+ licenses = ["notice"], # Apache 2.0
+)
+
+iree_lit_test_suite(
+ name = "lit",
+ srcs = glob(["*.mlir"]),
+ data = [
+ "//iree/tools:IreeFileCheck",
+ "//iree/tools:iree-opt",
+ ],
+)
diff --git a/iree/compiler/Dialect/VMLA/Conversion/VMLAToVM/test/CMakeLists.txt b/iree/compiler/Dialect/VMLA/Conversion/VMLAToVM/test/CMakeLists.txt
new file mode 100644
index 0000000..04f426a
--- /dev/null
+++ b/iree/compiler/Dialect/VMLA/Conversion/VMLAToVM/test/CMakeLists.txt
@@ -0,0 +1,22 @@
+# Copyright 2020 Google LLC
+#
+# 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
+#
+# https://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.
+
+iree_lit_test_suite(
+ NAME
+ lit
+ SRCS
+ DATA
+ iree::tools::IreeFileCheck
+ iree::tools::iree-opt
+)
diff --git a/iree/compiler/Dialect/VMLA/IR/BUILD b/iree/compiler/Dialect/VMLA/IR/BUILD
new file mode 100644
index 0000000..b0031c7
--- /dev/null
+++ b/iree/compiler/Dialect/VMLA/IR/BUILD
@@ -0,0 +1,109 @@
+# Copyright 2020 Google LLC
+#
+# 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
+#
+# https://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.
+
+load("//build_tools/bazel:tblgen.bzl", "gentbl")
+
+package(
+ default_visibility = ["//visibility:public"],
+ licenses = ["notice"], # Apache 2.0
+)
+
+exports_files(["VMLAOps.td"])
+
+filegroup(
+ name = "td_files",
+ srcs = glob(["*.td"]),
+)
+
+cc_library(
+ name = "IR",
+ srcs = [
+ "VMLAEnums.cpp.inc",
+ "VMLAOps.cpp",
+ "VMLATypes.cpp",
+ ],
+ hdrs = [
+ "VMLAEnums.h.inc",
+ "VMLAOps.h",
+ "VMLAOps.h.inc",
+ "VMLATypes.h",
+ ],
+ textual_hdrs = [
+ "VMLAOps.cpp.inc",
+ ],
+ deps = [
+ ":VMLAEnumsGen",
+ ":VMLAOpsGen",
+ "//iree/compiler/Dialect/IREE/IR",
+ "@llvm-project//llvm:support",
+ "@llvm-project//mlir:IR",
+ "@llvm-project//mlir:StandardOps",
+ "@llvm-project//mlir:Support",
+ "@llvm-project//mlir:TransformUtils",
+ "@llvm-project//mlir:Translation",
+ ],
+)
+
+cc_library(
+ name = "VMLADialect",
+ srcs = ["VMLADialect.cpp"],
+ hdrs = ["VMLADialect.h"],
+ deps = [
+ ":IR",
+ "//iree/compiler/Dialect/VM/Conversion",
+ "//iree/compiler/Dialect/VMLA:vmla_imports",
+ "//iree/compiler/Dialect/VMLA/Conversion/VMLAToVM",
+ "@llvm-project//llvm:support",
+ "@llvm-project//mlir:IR",
+ "@llvm-project//mlir:Parser",
+ "@llvm-project//mlir:StandardOps",
+ "@llvm-project//mlir:Support",
+ "@llvm-project//mlir:TransformUtils",
+ ],
+ alwayslink = 1,
+)
+
+gentbl(
+ name = "VMLAEnumsGen",
+ tbl_outs = [
+ ("-gen-enum-decls", "VMLAEnums.h.inc"),
+ ("-gen-enum-defs", "VMLAEnums.cpp.inc"),
+ ],
+ tblgen = "@llvm-project//mlir:mlir-tblgen",
+ td_file = "VMLABase.td",
+ td_srcs = [
+ ":td_files",
+ "//iree/compiler/Dialect/IREE/IR:td_files",
+ "@llvm-project//mlir:OpBaseTdFiles",
+ "@llvm-project//mlir:include/mlir/Analysis/CallInterfaces.td",
+ "@llvm-project//mlir:StdOpsTdFiles",
+ ],
+)
+
+gentbl(
+ name = "VMLAOpsGen",
+ tbl_outs = [
+ ("-gen-op-decls", "VMLAOps.h.inc"),
+ ("-gen-op-defs", "VMLAOps.cpp.inc"),
+ ],
+ tblgen = "@llvm-project//mlir:mlir-tblgen",
+ td_file = "VMLAOps.td",
+ td_srcs = [
+ ":td_files",
+ "//iree/compiler/Dialect/IREE/IR:td_files",
+ "@llvm-project//mlir:OpBaseTdFiles",
+ "@llvm-project//mlir:include/mlir/Analysis/CallInterfaces.td",
+ "@llvm-project//mlir:StdOpsTdFiles",
+ ],
+)
diff --git a/iree/compiler/Dialect/VMLA/IR/CMakeLists.txt b/iree/compiler/Dialect/VMLA/IR/CMakeLists.txt
new file mode 100644
index 0000000..0cf6e19
--- /dev/null
+++ b/iree/compiler/Dialect/VMLA/IR/CMakeLists.txt
@@ -0,0 +1,80 @@
+# Copyright 2020 Google LLC
+#
+# 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
+#
+# https://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.
+
+add_subdirectory(test)
+
+iree_cc_library(
+ NAME
+ IR
+ HDRS
+ "VMLAEnums.h.inc"
+ "VMLAOps.h"
+ "VMLAOps.h.inc"
+ "VMLATypes.h"
+ SRCS
+ "VMLAEnums.cpp.inc"
+ "VMLAOps.cpp"
+ "VMLAOps.cpp.inc"
+ "VMLATypes.cpp"
+ DEPS
+ iree::compiler::Dialect::IREE::IR
+ LLVMSupport
+ MLIRIR
+ MLIRStandardOps
+ MLIRSupport
+ MLIRTransformUtils
+ PUBLIC
+)
+
+iree_cc_library(
+ NAME
+ VMLADialect
+ HDRS
+ "VMLADialect.h"
+ SRCS
+ "VMLADialect.cpp"
+ DEPS
+ iree::compiler::Dialect::IREE::IR
+ iree::compiler::Dialect::VM::Conversion
+ iree::compiler::Dialect::VMLA::Conversion::VMLAToVM
+ iree::compiler::Dialect::VMLA::vmla_imports
+ LLVMSupport
+ MLIRIR
+ MLIRParser
+ MLIRStandardOps
+ MLIRSupport
+ MLIRTransformUtils
+ ALWAYSLINK
+ PUBLIC
+)
+
+iree_tablegen_library(
+ NAME
+ VMLAEnumsGen
+ TD_FILE
+ VMLABase.td
+ OUTS
+ -gen-enum-decls VMLAEnums.h.inc
+ -gen-enum-defs VMLAEnums.cpp.inc
+)
+
+iree_tablegen_library(
+ NAME
+ VMLAOpsGen
+ TD_FILE
+ VMLAOps.td
+ OUTS
+ -gen-op-decls VMLAOps.h.inc
+ -gen-op-defs VMLAOps.cpp.inc
+)
diff --git a/iree/compiler/Dialect/VMLA/IR/VMLABase.td b/iree/compiler/Dialect/VMLA/IR/VMLABase.td
new file mode 100644
index 0000000..051854b
--- /dev/null
+++ b/iree/compiler/Dialect/VMLA/IR/VMLABase.td
@@ -0,0 +1,83 @@
+// Copyright 2020 Google LLC
+//
+// 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
+//
+// https://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.
+
+#ifndef IREE_DIALECT_VMLA_BASE
+#define IREE_DIALECT_VMLA_BASE
+
+include "iree/compiler/Dialect/IREE/IR/IREEBase.td"
+
+//===----------------------------------------------------------------------===//
+// IREE VMLA (Virtual Machine-based Linear Algebra) dialect
+//===----------------------------------------------------------------------===//
+
+def VMLA_Dialect : Dialect {
+ let name = "vmla";
+ let cppNamespace = "IREE::VMLA";
+
+ let summary = [{
+ A dialect representing operations against the IREE VM-based backend.
+ }];
+ let description = [{
+ This is a reference dialect representing a simple IREE VM-based linear
+ algebra module that is used as a library at runtime. The ops in this dialect
+ map (roughly) 1:1 with the exported functions in the runtime module.
+
+ See `vmla.imports.mlir` for the full list of exported functions.
+ }];
+}
+
+//===----------------------------------------------------------------------===//
+// VMLA enums
+//===----------------------------------------------------------------------===//
+
+//===----------------------------------------------------------------------===//
+// VMLA types
+//===----------------------------------------------------------------------===//
+
+def VMLA_DeviceSize : TypeAlias<I32>;
+def VMLA_DeviceSizeAttr : IntegerAttrBase<I32, "device_size_t">;
+
+def VMLA_HostSize : TypeAlias<I32>;
+def VMLA_HostSizeAttr : IntegerAttrBase<I32, "size_t">;
+
+def VMLA_Dim : I<32>;
+def VMLA_Dims : Variadic<VMLA_Dim>;
+def VMLA_Shape : Variadic<VMLA_Dim>;
+
+def HAL_HostBufferRef : AnyTypeOf<[
+ RefPtrOf<ByteBufferType>,
+ RefPtrOf<MutableByteBufferType>,
+]>;
+
+//===----------------------------------------------------------------------===//
+// Base VMLA op classes
+//===----------------------------------------------------------------------===//
+
+def VMLA_OpInterface : OpInterface<"VMLAOp"> {
+ let description = [{
+ Interface for VMLA ops.
+ }];
+}
+
+class VMLA_Op<string mnemonic, list<OpTrait> traits = []> :
+ Op<VMLA_Dialect, mnemonic, !listconcat(traits, [VMLA_OpInterface])> {
+ // TODO(benvanik): use new tablegen printer/parser.
+ // let parser = [{ return parse$cppClass(parser, &result); }];
+ // let printer = [{ return print$cppClass(p, *this); }];
+}
+
+class VMLA_PureOp<string mnemonic, list<OpTrait> traits = []> :
+ VMLA_Op<mnemonic, !listconcat(traits, [NoSideEffect])>;
+
+#endif // IREE_DIALECT_VMLA_BASE
diff --git a/iree/compiler/Dialect/VMLA/IR/VMLADialect.cpp b/iree/compiler/Dialect/VMLA/IR/VMLADialect.cpp
new file mode 100644
index 0000000..a17e1c7
--- /dev/null
+++ b/iree/compiler/Dialect/VMLA/IR/VMLADialect.cpp
@@ -0,0 +1,97 @@
+// Copyright 2019 Google LLC
+//
+// 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
+//
+// https://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 "iree/compiler/Dialect/VMLA/IR/VMLADialect.h"
+
+#include "iree/compiler/Dialect/VM/Conversion/ConversionDialectInterface.h"
+#include "iree/compiler/Dialect/VMLA/Conversion/VMLAToVM/ConvertVMLAToVM.h"
+#include "iree/compiler/Dialect/VMLA/IR/VMLAOps.h"
+#include "iree/compiler/Dialect/VMLA/IR/VMLATypes.h"
+#include "iree/compiler/Dialect/VMLA/vmla.imports.h"
+#include "llvm/Support/SourceMgr.h"
+#include "mlir/IR/DialectImplementation.h"
+#include "mlir/IR/OpImplementation.h"
+#include "mlir/Parser.h"
+
+namespace mlir {
+namespace iree_compiler {
+namespace IREE {
+namespace VMLA {
+
+namespace {
+
+static DialectRegistration<VMLADialect> vmla_dialect;
+
+class VMLAToVMConversionInterface : public VMConversionDialectInterface {
+ public:
+ using VMConversionDialectInterface::VMConversionDialectInterface;
+
+ OwningModuleRef getVMImportModule() const override {
+ return mlir::parseSourceString(
+ StringRef(vmla_imports_create()->data, vmla_imports_create()->size),
+ getDialect()->getContext());
+ }
+
+ void populateVMConversionPatterns(
+ SymbolTable &importSymbols, OwningRewritePatternList &patterns,
+ TypeConverter &typeConverter) const override {
+ populateVMLAToVMPatterns(getDialect()->getContext(), importSymbols,
+ patterns, typeConverter);
+ }
+};
+
+} // namespace
+
+VMLADialect::VMLADialect(MLIRContext *context)
+ : Dialect(getDialectNamespace(), context) {
+ addInterfaces<VMLAToVMConversionInterface>();
+
+ addTypes<BufferType>();
+
+ // TODO(benvanik): add ops.
+ // #define GET_OP_LIST
+ // addOperations<
+ // #include "iree/compiler/Dialect/VMLA/IR/VMLAOps.cpp.inc"
+ // >();
+}
+
+//===----------------------------------------------------------------------===//
+// Type printing and parsing
+//===----------------------------------------------------------------------===//
+
+Type VMLADialect::parseType(DialectAsmParser &parser) const {
+ StringRef typeName;
+ if (parser.parseKeyword(&typeName)) return Type();
+ auto type = llvm::StringSwitch<Type>(typeName)
+ .Case("buffer", BufferType::get(getContext()))
+ .Default(nullptr);
+ if (!type) {
+ parser.emitError(parser.getCurrentLocation())
+ << "unknown VMLA type: " << typeName;
+ }
+ return type;
+}
+
+void VMLADialect::printType(Type type, DialectAsmPrinter &p) const {
+ if (type.isa<BufferType>()) {
+ p << "buffer";
+ } else {
+ llvm_unreachable("unknown VMLA type");
+ }
+}
+
+} // namespace VMLA
+} // namespace IREE
+} // namespace iree_compiler
+} // namespace mlir
diff --git a/iree/compiler/Dialect/VMLA/IR/VMLADialect.h b/iree/compiler/Dialect/VMLA/IR/VMLADialect.h
new file mode 100644
index 0000000..c567b66
--- /dev/null
+++ b/iree/compiler/Dialect/VMLA/IR/VMLADialect.h
@@ -0,0 +1,40 @@
+// Copyright 2020 Google LLC
+//
+// 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
+//
+// https://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.
+
+#ifndef IREE_COMPILER_DIALECT_VMLA_IR_VMLADIALECT_H_
+#define IREE_COMPILER_DIALECT_VMLA_IR_VMLADIALECT_H_
+
+#include "mlir/IR/Dialect.h"
+#include "mlir/IR/OpDefinition.h"
+
+namespace mlir {
+namespace iree_compiler {
+namespace IREE {
+namespace VMLA {
+
+class VMLADialect : public Dialect {
+ public:
+ explicit VMLADialect(MLIRContext *context);
+ static StringRef getDialectNamespace() { return "vmla"; }
+
+ Type parseType(DialectAsmParser &parser) const override;
+ void printType(Type type, DialectAsmPrinter &p) const override;
+};
+
+} // namespace VMLA
+} // namespace IREE
+} // namespace iree_compiler
+} // namespace mlir
+
+#endif // IREE_COMPILER_DIALECT_VMLA_IR_VMLADIALECT_H_
diff --git a/iree/compiler/Dialect/VMLA/IR/VMLAOps.cpp b/iree/compiler/Dialect/VMLA/IR/VMLAOps.cpp
new file mode 100644
index 0000000..f6e61b7
--- /dev/null
+++ b/iree/compiler/Dialect/VMLA/IR/VMLAOps.cpp
@@ -0,0 +1,42 @@
+// Copyright 2020 Google LLC
+//
+// 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
+//
+// https://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 "iree/compiler/Dialect/VMLA/IR/VMLAOps.h"
+
+#include "iree/compiler/Dialect/IREE/IR/IREETypes.h"
+#include "iree/compiler/Dialect/VMLA/IR/VMLATypes.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/SMLoc.h"
+#include "mlir/IR/Attributes.h"
+#include "mlir/IR/Builders.h"
+#include "mlir/IR/OpImplementation.h"
+#include "mlir/IR/SymbolTable.h"
+#include "mlir/IR/TypeUtilities.h"
+
+namespace mlir {
+namespace iree_compiler {
+namespace IREE {
+namespace VMLA {
+
+//===----------------------------------------------------------------------===//
+// TableGen definitions (intentionally last)
+//===----------------------------------------------------------------------===//
+
+#define GET_OP_CLASSES
+#include "iree/compiler/Dialect/VMLA/IR/VMLAOps.cpp.inc"
+
+} // namespace VMLA
+} // namespace IREE
+} // namespace iree_compiler
+} // namespace mlir
diff --git a/iree/compiler/Dialect/VMLA/IR/VMLAOps.h b/iree/compiler/Dialect/VMLA/IR/VMLAOps.h
new file mode 100644
index 0000000..0e839dc
--- /dev/null
+++ b/iree/compiler/Dialect/VMLA/IR/VMLAOps.h
@@ -0,0 +1,44 @@
+// Copyright 2020 Google LLC
+//
+// 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
+//
+// https://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.
+
+#ifndef IREE_COMPILER_DIALECT_VMLA_IR_VMLAOPS_H_
+#define IREE_COMPILER_DIALECT_VMLA_IR_VMLAOPS_H_
+
+#include <cstdint>
+
+#include "iree/compiler/Dialect/IREE/IR/IREETraits.h"
+#include "iree/compiler/Dialect/VMLA/IR/VMLATypes.h"
+#include "mlir/IR/Attributes.h"
+#include "mlir/IR/Dialect.h"
+#include "mlir/IR/Function.h"
+#include "mlir/IR/Module.h"
+#include "mlir/IR/OpDefinition.h"
+#include "mlir/IR/OpImplementation.h"
+#include "mlir/IR/StandardTypes.h"
+#include "mlir/IR/SymbolTable.h"
+
+namespace mlir {
+namespace iree_compiler {
+namespace IREE {
+namespace VMLA {
+
+#define GET_OP_CLASSES
+#include "iree/compiler/Dialect/VMLA/IR/VMLAOps.h.inc"
+
+} // namespace VMLA
+} // namespace IREE
+} // namespace iree_compiler
+} // namespace mlir
+
+#endif // IREE_COMPILER_DIALECT_VMLA_IR_VMLAOPS_H_
diff --git a/iree/compiler/Dialect/VMLA/IR/VMLAOps.td b/iree/compiler/Dialect/VMLA/IR/VMLAOps.td
new file mode 100644
index 0000000..c6fe9db
--- /dev/null
+++ b/iree/compiler/Dialect/VMLA/IR/VMLAOps.td
@@ -0,0 +1,25 @@
+// Copyright 2019 Google LLC
+//
+// 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
+//
+// https://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.
+
+#ifndef IREE_DIALECT_VMLA_OPS
+#define IREE_DIALECT_VMLA_OPS
+
+include "iree/compiler/Dialect/VMLA/IR/VMLABase.td"
+include "mlir/IR/OpAsmInterface.td"
+
+//===----------------------------------------------------------------------===//
+// TODO(benvanik): define ops.
+//===----------------------------------------------------------------------===//
+
+#endif // IREE_DIALECT_VMLA_OPS
diff --git a/iree/compiler/Dialect/VMLA/IR/VMLATypes.cpp b/iree/compiler/Dialect/VMLA/IR/VMLATypes.cpp
new file mode 100644
index 0000000..77c3ce2
--- /dev/null
+++ b/iree/compiler/Dialect/VMLA/IR/VMLATypes.cpp
@@ -0,0 +1,20 @@
+// Copyright 2020 Google LLC
+//
+// 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
+//
+// https://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 "iree/compiler/Dialect/VMLA/IR/VMLATypes.h"
+
+#include "llvm/ADT/StringExtras.h"
+
+// Order matters:
+#include "iree/compiler/Dialect/VMLA/IR/VMLAEnums.cpp.inc"
diff --git a/iree/compiler/Dialect/VMLA/IR/VMLATypes.h b/iree/compiler/Dialect/VMLA/IR/VMLATypes.h
new file mode 100644
index 0000000..e9cec10
--- /dev/null
+++ b/iree/compiler/Dialect/VMLA/IR/VMLATypes.h
@@ -0,0 +1,58 @@
+// Copyright 2020 Google LLC
+//
+// 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
+//
+// https://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.
+
+#ifndef IREE_COMPILER_DIALECT_VMLA_IR_VMLATYPES_H_
+#define IREE_COMPILER_DIALECT_VMLA_IR_VMLATYPES_H_
+
+#include <cstdint>
+
+#include "iree/compiler/Dialect/IREE/IR/IREETypes.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/DenseMapInfo.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "mlir/IR/OpDefinition.h"
+#include "mlir/IR/StandardTypes.h"
+#include "mlir/IR/TypeSupport.h"
+#include "mlir/IR/Types.h"
+#include "mlir/Support/LLVM.h"
+
+// Order matters.
+#include "iree/compiler/Dialect/VMLA/IR/VMLAEnums.h.inc"
+
+namespace mlir {
+namespace iree_compiler {
+namespace IREE {
+namespace VMLA {
+
+//===----------------------------------------------------------------------===//
+// RefObject types
+//===----------------------------------------------------------------------===//
+
+class BufferType : public Type::TypeBase<BufferType, RefObjectType> {
+ public:
+ using Base::Base;
+ static BufferType get(MLIRContext *context) {
+ return Base::get(context, TypeKind::Buffer);
+ }
+ static bool kindof(unsigned kind) { return kind == TypeKind::Buffer; }
+};
+
+} // namespace VMLA
+} // namespace IREE
+} // namespace iree_compiler
+} // namespace mlir
+
+#endif // IREE_COMPILER_DIALECT_VMLA_IR_VMLATYPES_H_
diff --git a/iree/compiler/Dialect/VMLA/IR/test/BUILD b/iree/compiler/Dialect/VMLA/IR/test/BUILD
new file mode 100644
index 0000000..14281d1
--- /dev/null
+++ b/iree/compiler/Dialect/VMLA/IR/test/BUILD
@@ -0,0 +1,29 @@
+# Copyright 2020 Google LLC
+#
+# 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
+#
+# https://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.
+
+load("//iree:lit_test.bzl", "iree_lit_test_suite")
+
+package(
+ default_visibility = ["//visibility:public"],
+ licenses = ["notice"], # Apache 2.0
+)
+
+iree_lit_test_suite(
+ name = "lit",
+ srcs = glob(["*.mlir"]),
+ data = [
+ "//iree/tools:IreeFileCheck",
+ "//iree/tools:iree-opt",
+ ],
+)
diff --git a/iree/compiler/Dialect/VMLA/IR/test/CMakeLists.txt b/iree/compiler/Dialect/VMLA/IR/test/CMakeLists.txt
new file mode 100644
index 0000000..04f426a
--- /dev/null
+++ b/iree/compiler/Dialect/VMLA/IR/test/CMakeLists.txt
@@ -0,0 +1,22 @@
+# Copyright 2020 Google LLC
+#
+# 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
+#
+# https://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.
+
+iree_lit_test_suite(
+ NAME
+ lit
+ SRCS
+ DATA
+ iree::tools::IreeFileCheck
+ iree::tools::iree-opt
+)
diff --git a/iree/compiler/Dialect/VMLA/Transforms/BUILD b/iree/compiler/Dialect/VMLA/Transforms/BUILD
new file mode 100644
index 0000000..06a1e63
--- /dev/null
+++ b/iree/compiler/Dialect/VMLA/Transforms/BUILD
@@ -0,0 +1,38 @@
+# Copyright 2020 Google LLC
+#
+# 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
+#
+# https://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.
+
+package(
+ default_visibility = ["//visibility:public"],
+ licenses = ["notice"], # Apache 2.0
+)
+
+cc_library(
+ name = "Transforms",
+ srcs = [
+ "Passes.cpp",
+ ],
+ hdrs = [
+ "Passes.h",
+ ],
+ deps = [
+ "//iree/compiler/Dialect/VMLA/IR",
+ "@llvm-project//llvm:support",
+ "@llvm-project//mlir:IR",
+ "@llvm-project//mlir:Pass",
+ "@llvm-project//mlir:Support",
+ "@llvm-project//mlir:Transforms",
+ "@org_tensorflow//tensorflow/compiler/mlir/xla:hlo",
+ ],
+ alwayslink = 1,
+)
diff --git a/iree/compiler/Dialect/VMLA/Transforms/CMakeLists.txt b/iree/compiler/Dialect/VMLA/Transforms/CMakeLists.txt
new file mode 100644
index 0000000..ed01a5a
--- /dev/null
+++ b/iree/compiler/Dialect/VMLA/Transforms/CMakeLists.txt
@@ -0,0 +1,37 @@
+# Copyright 2020 Google LLC
+#
+# 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
+#
+# https://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.
+
+add_subdirectory(test)
+
+iree_cc_library(
+ NAME
+ Transforms
+ HDRS
+ "Passes.h"
+ SRCS
+ "Passes.cpp"
+ DEPS
+ iree::compiler::Dialect::VMLA::IR
+ iree::compiler::Utils
+ LLVMSupport
+ MLIRIR
+ MLIRPass
+ MLIRStandardOps
+ MLIRSupport
+ MLIRTransformUtils
+ MLIRTransforms
+ tensorflow::mlir_xla
+ ALWAYSLINK
+ PUBLIC
+)
diff --git a/iree/compiler/Dialect/VMLA/Transforms/Passes.cpp b/iree/compiler/Dialect/VMLA/Transforms/Passes.cpp
new file mode 100644
index 0000000..d2a3341
--- /dev/null
+++ b/iree/compiler/Dialect/VMLA/Transforms/Passes.cpp
@@ -0,0 +1,64 @@
+// Copyright 2020 Google LLC
+//
+// 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
+//
+// https://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 "iree/compiler/Dialect/VMLA/Transforms/Passes.h"
+
+#include <memory>
+
+#include "mlir/Pass/PassRegistry.h"
+#include "mlir/Transforms/Passes.h"
+#include "tensorflow/compiler/mlir/xla/transforms/passes.h"
+
+namespace mlir {
+namespace iree_compiler {
+namespace IREE {
+namespace VMLA {
+
+void buildVMLATransformPassPipeline(OpPassManager &passManager) {
+ passManager.addPass(createCanonicalizerPass());
+
+ // Flatten structured control flow to our CFG.
+ passManager.addNestedPass<FuncOp>(xla_hlo::createLegalizeControlFlowPass());
+
+ // Perform inlining and cleanup after CFG manipulation.
+ passManager.addPass(createInlinerPass());
+ passManager.addNestedPass<FuncOp>(createCanonicalizerPass());
+ passManager.addNestedPass<FuncOp>(createCSEPass());
+
+ // Legalize input types.
+ // TODO(benvanik): legalize input.
+ // passManager.addPass(IREE::VMLA::createLegalizeInputTypesPass());
+
+ // TODO(benvanik): convert HLO->VMLA.
+ // TODO(benvanik): convert std->VMLA.
+ // TODO(benvanik): convert VMLA->VM.
+
+ // Cleanup identity ops that clutter up the IR and canonicalize.
+ passManager.addNestedPass<FuncOp>(createCSEPass());
+ passManager.addNestedPass<FuncOp>(createCanonicalizerPass());
+
+ // TODO(benvanik): run symbol DCE pass.
+}
+
+static PassPipelineRegistration<> transformPassPipeline(
+ "iree-vmla-transformation-pipeline",
+ "Runs the full IREE VMLA dialect transformation pipeline",
+ [](OpPassManager &passManager) {
+ buildVMLATransformPassPipeline(passManager);
+ });
+
+} // namespace VMLA
+} // namespace IREE
+} // namespace iree_compiler
+} // namespace mlir
diff --git a/iree/compiler/Dialect/VMLA/Transforms/Passes.h b/iree/compiler/Dialect/VMLA/Transforms/Passes.h
new file mode 100644
index 0000000..b123312
--- /dev/null
+++ b/iree/compiler/Dialect/VMLA/Transforms/Passes.h
@@ -0,0 +1,56 @@
+// Copyright 2020 Google LLC
+//
+// 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
+//
+// https://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.
+
+#ifndef IREE_COMPILER_DIALECT_VMLA_TRANSFORMS_PASSES_H_
+#define IREE_COMPILER_DIALECT_VMLA_TRANSFORMS_PASSES_H_
+
+#include "iree/compiler/Dialect/VMLA/IR/VMLAOps.h"
+#include "llvm/ADT/StringMap.h"
+#include "mlir/IR/Function.h"
+#include "mlir/IR/Module.h"
+#include "mlir/Pass/Pass.h"
+#include "mlir/Pass/PassManager.h"
+#include "mlir/Support/LLVM.h"
+
+namespace mlir {
+namespace iree_compiler {
+namespace IREE {
+namespace VMLA {
+
+//===----------------------------------------------------------------------===//
+// Helpers
+//===----------------------------------------------------------------------===//
+
+// Adds a set of passes to the given pass manager that run the required VMLA
+// transforms in the canonical order.
+//
+// Most translation code should prefer to use this instead of manually adding
+// the passes themselves to ensure that expected pass ordering is observed.
+//
+// The expected usage is:
+// <run conversion from TF/HLO/etc to flow>
+// buildVMLATransformPassPipeline & run
+// <serialize VM module>
+void buildVMLATransformPassPipeline(OpPassManager &passManager);
+
+//===----------------------------------------------------------------------===//
+// Input canonicalization and legalization
+//===----------------------------------------------------------------------===//
+
+} // namespace VMLA
+} // namespace IREE
+} // namespace iree_compiler
+} // namespace mlir
+
+#endif // IREE_COMPILER_DIALECT_VMLA_TRANSFORMS_PASSES_H_
diff --git a/iree/compiler/Dialect/VMLA/Transforms/test/BUILD b/iree/compiler/Dialect/VMLA/Transforms/test/BUILD
new file mode 100644
index 0000000..14281d1
--- /dev/null
+++ b/iree/compiler/Dialect/VMLA/Transforms/test/BUILD
@@ -0,0 +1,29 @@
+# Copyright 2020 Google LLC
+#
+# 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
+#
+# https://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.
+
+load("//iree:lit_test.bzl", "iree_lit_test_suite")
+
+package(
+ default_visibility = ["//visibility:public"],
+ licenses = ["notice"], # Apache 2.0
+)
+
+iree_lit_test_suite(
+ name = "lit",
+ srcs = glob(["*.mlir"]),
+ data = [
+ "//iree/tools:IreeFileCheck",
+ "//iree/tools:iree-opt",
+ ],
+)
diff --git a/iree/compiler/Dialect/VMLA/Transforms/test/CMakeLists.txt b/iree/compiler/Dialect/VMLA/Transforms/test/CMakeLists.txt
new file mode 100644
index 0000000..377fb35
--- /dev/null
+++ b/iree/compiler/Dialect/VMLA/Transforms/test/CMakeLists.txt
@@ -0,0 +1,23 @@
+# Copyright 2020 Google LLC
+#
+# 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
+#
+# https://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.
+
+iree_lit_test_suite(
+ NAME
+ lit
+ SRCS
+ "transformation.mlir"
+ DATA
+ iree::tools::IreeFileCheck
+ iree::tools::iree-opt
+)
diff --git a/iree/compiler/Dialect/VMLA/Transforms/test/transformation.mlir b/iree/compiler/Dialect/VMLA/Transforms/test/transformation.mlir
new file mode 100644
index 0000000..08a7ac6
--- /dev/null
+++ b/iree/compiler/Dialect/VMLA/Transforms/test/transformation.mlir
@@ -0,0 +1,7 @@
+// RUN: iree-opt -split-input-file -iree-vmla-transformation-pipeline %s | IreeFileCheck %s
+
+// CHECK-LABEL: @empty
+func @empty() {
+ // CHECK-NEXT: return
+ return
+}
diff --git a/iree/compiler/Dialect/VMLA/vmla.imports.mlir b/iree/compiler/Dialect/VMLA/vmla.imports.mlir
new file mode 100644
index 0000000..aea350f
--- /dev/null
+++ b/iree/compiler/Dialect/VMLA/vmla.imports.mlir
@@ -0,0 +1,6 @@
+// IREE VMLA (Virtual Machine-based Linear Algebra) runtime module imports.
+//
+// This is embedded in the compiler binary and inserted into any module
+// containing VMLA dialect ops (vmla.*) that is lowered to the VM dialect.
+vm.module @vmla {
+} // module
diff --git a/iree/tools/BUILD b/iree/tools/BUILD
index b3b12d4..b7e11d9 100644
--- a/iree/tools/BUILD
+++ b/iree/tools/BUILD
@@ -29,6 +29,7 @@
TARGET_COMPILER_BACKENDS = [
"//iree/compiler/Dialect/HAL/Target/LegacyInterpreter",
+ "//iree/compiler/Dialect/HAL/Target/VMLA",
"//iree/compiler/Dialect/HAL/Target/VulkanSPIRV",
]
@@ -62,6 +63,10 @@
"//iree/compiler/Dialect/VM/Conversion/StandardToVM",
"//iree/compiler/Dialect/VM/IR",
"//iree/compiler/Dialect/VM/Transforms",
+ "//iree/compiler/Dialect/VMLA/Conversion/HLOToVMLA",
+ "//iree/compiler/Dialect/VMLA/Conversion/VMLAToVM",
+ "//iree/compiler/Dialect/VMLA/IR",
+ "//iree/compiler/Dialect/VMLA/Transforms",
"//iree/compiler/Translation/Interpreter/Transforms",
"//iree/compiler/Translation:IREEVM",
"//iree/compiler/Translation/XLAToLinalg",
@@ -125,6 +130,7 @@
"//iree/hal/interpreter:interpreter_driver_module",
# TODO(b/142004903): enable when Dawn HAL implementation is functional
# "//iree/hal/dawn:dawn_driver_module",
+ "//iree/hal/vmla:vmla_driver_module",
"//iree/hal/vulkan:vulkan_driver_module",
],
)