NFC: Refactor SPIRV Translation to better segregate different components.
PiperOrigin-RevId: 288763695
diff --git a/iree/compiler/Dialect/HAL/Target/VulkanSPIRV/BUILD b/iree/compiler/Dialect/HAL/Target/VulkanSPIRV/BUILD
index 25b2cb8..eb51823 100644
--- a/iree/compiler/Dialect/HAL/Target/VulkanSPIRV/BUILD
+++ b/iree/compiler/Dialect/HAL/Target/VulkanSPIRV/BUILD
@@ -29,13 +29,15 @@
"//iree/compiler/Dialect/Flow/IR",
"//iree/compiler/Dialect/HAL/Target:ExecutableTarget",
"//iree/compiler/Dialect/IREE/IR",
- "//iree/compiler/Translation/SPIRV",
+ "//iree/compiler/Translation/SPIRV/EmbeddedKernels",
+ "//iree/compiler/Translation/SPIRV/XLAToSPIRV",
"//iree/schemas:spirv_executable_def_cc_fbs",
"@com_github_google_flatbuffers//:flatbuffers",
"@llvm-project//llvm:support",
"@llvm-project//mlir:IR",
"@llvm-project//mlir:Pass",
"@llvm-project//mlir:SPIRVDialect",
+ "@llvm-project//mlir:SPIRVDialectRegistration",
"@llvm-project//mlir:SPIRVLowering",
"@llvm-project//mlir:SPIRVSerialization",
"@llvm-project//mlir:Support",
diff --git a/iree/compiler/Dialect/HAL/Target/VulkanSPIRV/CMakeLists.txt b/iree/compiler/Dialect/HAL/Target/VulkanSPIRV/CMakeLists.txt
index 2eef9a5..6c962e5 100644
--- a/iree/compiler/Dialect/HAL/Target/VulkanSPIRV/CMakeLists.txt
+++ b/iree/compiler/Dialect/HAL/Target/VulkanSPIRV/CMakeLists.txt
@@ -23,14 +23,14 @@
iree::compiler::Dialect::Flow::IR
iree::compiler::Dialect::HAL::Target::ExecutableTarget
iree::compiler::Dialect::IREE::IR
- iree::compiler::Translation::SPIRV
+ iree::compiler::Translation::SPIRV::EmbeddedKernels
+ iree::compiler::Translation::SPIRV::XLAToSPIRV
iree::schemas::spirv_executable_def_cc_fbs
flatbuffers
LLVMSupport
MLIRIR
MLIRPass
- MLIRSPIRVDialect
- MLIRSPIRVLowering
+ MLIRSPIRV
MLIRSPIRVSerialization
MLIRSupport
MLIRTransforms
diff --git a/iree/compiler/Dialect/HAL/Target/VulkanSPIRV/VulkanSPIRVTarget.cpp b/iree/compiler/Dialect/HAL/Target/VulkanSPIRV/VulkanSPIRVTarget.cpp
index 4f941af..0a8178e 100644
--- a/iree/compiler/Dialect/HAL/Target/VulkanSPIRV/VulkanSPIRVTarget.cpp
+++ b/iree/compiler/Dialect/HAL/Target/VulkanSPIRV/VulkanSPIRVTarget.cpp
@@ -19,8 +19,8 @@
#include "flatbuffers/flatbuffers.h"
#include "iree/compiler/Dialect/Flow/IR/FlowOps.h"
#include "iree/compiler/Dialect/HAL/Target/LegacyUtil.h"
-#include "iree/compiler/Translation/SPIRV/EmbeddedKernels.h"
-#include "iree/compiler/Translation/SPIRV/IREEToSPIRVPass.h"
+#include "iree/compiler/Translation/SPIRV/EmbeddedKernels/EmbeddedKernels.h"
+#include "iree/compiler/Translation/SPIRV/XLAToSPIRV/IREEToSPIRVPass.h"
#include "iree/schemas/spirv_executable_def_generated.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/CommandLine.h"
@@ -140,15 +140,7 @@
// Lower module to spirv::ModuleOp.
PassManager conversionPassManager(moduleOp.getContext());
- conversionPassManager.addPass(xla_hlo::createLegalizeToStdPass());
- conversionPassManager.addPass(createPrepareReductionDispatchPass());
- conversionPassManager.addPass(createIndexComputationPass());
- conversionPassManager.addPass(createIREEToSPIRVPass());
-
- OpPassManager &spirvPasses = conversionPassManager.nest<spirv::ModuleOp>();
- spirvPasses.addPass(spirv::createLowerABIAttributesPass());
- spirvPasses.addPass(createInlinerPass());
- spirvPasses.addPass(createAdjustIntegerWidthPass());
+ addIREEToSPIRVPasses(conversionPassManager);
if (failed(conversionPassManager.run(moduleOp))) {
return moduleOp.emitError() << "failed to run conversion passes";
}
diff --git a/iree/compiler/Translation/SPIRV/CMakeLists.txt b/iree/compiler/Translation/SPIRV/CMakeLists.txt
index 7b966c1..4c551b7 100644
--- a/iree/compiler/Translation/SPIRV/CMakeLists.txt
+++ b/iree/compiler/Translation/SPIRV/CMakeLists.txt
@@ -12,53 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-add_subdirectory(Kernels)
-
-iree_cc_library(
- NAME
- SPIRV
- HDRS
- "EmbeddedKernels.h"
- "IndexComputation.h"
- "IndexComputationAttribute.h"
- "IREECodegenUtils.h"
- "IREEIndexComputation.h"
- "IREEToSPIRV.h"
- "IREEToSPIRVPass.h"
- "SPIRVLowering.h"
- "TensorIndexToScalarValueMap.h"
- "XLAIndexPropagation.h"
- "XLAToSPIRV.h"
- SRCS
- "AdjustIntegerWidthPass.cpp"
- "EmbeddedKernels.cpp"
- "IndexComputation.cpp"
- "IndexComputationAttribute.cpp"
- "IndexComputationPass.cpp"
- "IREEIndexComputation.cpp"
- "IREEToSPIRV.cpp"
- "IREEToSPIRVPass.cpp"
- "PrepareReductionDispatch.cpp"
- "ReductionFnLowering.cpp"
- "SPIRVLowering.cpp"
- "XLAIndexPropagation.cpp"
- "XLAToSPIRV.cpp"
- DEPS
- flatbuffers
- iree::compiler::Dialect::IREE::IR
- iree::compiler::Translation::SPIRV::Kernels
- iree::compiler::Utils
- iree::schemas::spirv_executable_def_cc_fbs
- tensorflow::mlir_xla
- LLVMSupport
- MLIRAffineOps
- MLIRAffineToStandard
- MLIRIR
- MLIRSPIRV
- MLIRSPIRVSerialization
- MLIRStandardToSPIRVTransforms
- MLIRTransforms
- MLIRTranslation
- ALWAYSLINK
- PUBLIC
-)
+add_subdirectory(EmbeddedKernels)
+add_subdirectory(IndexComputation)
+add_subdirectory(Passes)
+add_subdirectory(ReductionCodegen)
+add_subdirectory(XLAToSPIRV)
diff --git a/iree/compiler/Translation/SPIRV/EmbeddedKernels/BUILD b/iree/compiler/Translation/SPIRV/EmbeddedKernels/BUILD
new file mode 100644
index 0000000..184d9cf
--- /dev/null
+++ b/iree/compiler/Translation/SPIRV/EmbeddedKernels/BUILD
@@ -0,0 +1,37 @@
+# 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.
+
+package(
+ default_visibility = ["//visibility:public"],
+ licenses = ["notice"], # Apache 2.0
+)
+
+cc_library(
+ name = "EmbeddedKernels",
+ srcs = [
+ "EmbeddedKernels.cpp",
+ ],
+ hdrs = [
+ "EmbeddedKernels.h",
+ ],
+ deps = [
+ "//iree/compiler/Translation/SPIRV/EmbeddedKernels/Kernels",
+ "//iree/schemas:spirv_executable_def_cc_fbs",
+ "@com_github_google_flatbuffers//:flatbuffers",
+ "@llvm-project//mlir:IR",
+ "@llvm-project//mlir:Support",
+ "@org_tensorflow//tensorflow/compiler/mlir/xla:hlo",
+ ],
+ alwayslink = 1,
+)
diff --git a/iree/compiler/Translation/SPIRV/test/PrepareReductionDispatch/BUILD b/iree/compiler/Translation/SPIRV/EmbeddedKernels/CMakeLists.txt
similarity index 62%
copy from iree/compiler/Translation/SPIRV/test/PrepareReductionDispatch/BUILD
copy to iree/compiler/Translation/SPIRV/EmbeddedKernels/CMakeLists.txt
index 1cbffd1..745664f 100644
--- a/iree/compiler/Translation/SPIRV/test/PrepareReductionDispatch/BUILD
+++ b/iree/compiler/Translation/SPIRV/EmbeddedKernels/CMakeLists.txt
@@ -12,19 +12,22 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-# Tests for common transforms.
+add_subdirectory(Kernels)
-load("//iree:build_defs.bzl", "iree_glob_lit_tests", "iree_setup_lit_package")
-
-package(
- default_visibility = ["//visibility:public"],
- licenses = ["notice"], # Apache 2.0
+iree_cc_library(
+ NAME
+ EmbeddedKernels
+ HDRS
+ "EmbeddedKernels.h"
+ SRCS
+ "EmbeddedKernels.cpp"
+ DEPS
+ flatbuffers
+ iree::compiler::Translation::SPIRV::EmbeddedKernels::Kernels
+ iree::schemas::spirv_executable_def_cc_fbs
+ MLIRIR
+ MLIRSupport
+ tensorflow::mlir_xla
+ ALWAYSLINK
+ PUBLIC
)
-
-iree_setup_lit_package(
- data = [
- "//iree/tools:iree-opt",
- ],
-)
-
-iree_glob_lit_tests()
diff --git a/iree/compiler/Translation/SPIRV/EmbeddedKernels.cpp b/iree/compiler/Translation/SPIRV/EmbeddedKernels/EmbeddedKernels.cpp
similarity index 98%
rename from iree/compiler/Translation/SPIRV/EmbeddedKernels.cpp
rename to iree/compiler/Translation/SPIRV/EmbeddedKernels/EmbeddedKernels.cpp
index d8d2177..df94940 100644
--- a/iree/compiler/Translation/SPIRV/EmbeddedKernels.cpp
+++ b/iree/compiler/Translation/SPIRV/EmbeddedKernels/EmbeddedKernels.cpp
@@ -12,9 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include "iree/compiler/Translation/SPIRV/EmbeddedKernels.h"
+#include "iree/compiler/Translation/SPIRV/EmbeddedKernels/EmbeddedKernels.h"
-#include "iree/compiler/Translation/SPIRV/Kernels/Kernels.h"
+#include "iree/compiler/Translation/SPIRV/EmbeddedKernels/Kernels/Kernels.h"
#include "iree/schemas/spirv_executable_def_generated.h"
#include "mlir/IR/Function.h"
#include "mlir/IR/Module.h"
diff --git a/iree/compiler/Translation/SPIRV/EmbeddedKernels.h b/iree/compiler/Translation/SPIRV/EmbeddedKernels/EmbeddedKernels.h
similarity index 83%
rename from iree/compiler/Translation/SPIRV/EmbeddedKernels.h
rename to iree/compiler/Translation/SPIRV/EmbeddedKernels/EmbeddedKernels.h
index ce1784d..11c93f5 100644
--- a/iree/compiler/Translation/SPIRV/EmbeddedKernels.h
+++ b/iree/compiler/Translation/SPIRV/EmbeddedKernels/EmbeddedKernels.h
@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#ifndef IREE_COMPILER_TRANSLATION_SPIRV_EMBEDDEDKERNELS_H_
-#define IREE_COMPILER_TRANSLATION_SPIRV_EMBEDDEDKERNELS_H_
+#ifndef IREE_COMPILER_TRANSLATION_SPIRV_EMBEDDEDKERNELS_EMBEDDEDKERNELS_H_
+#define IREE_COMPILER_TRANSLATION_SPIRV_EMBEDDEDKERNELS_EMBEDDEDKERNELS_H_
#include "flatbuffers/flatbuffers.h"
#include "iree/schemas/spirv_executable_def_generated.h"
@@ -32,4 +32,4 @@
} // namespace iree_compiler
} // namespace mlir
-#endif // IREE_COMPILER_TRANSLATION_SPIRV_EMBEDDEDKERNELS_H_
+#endif // IREE_COMPILER_TRANSLATION_SPIRV_EMBEDDEDKERNELS_EMBEDDEDKERNELS_H_
diff --git a/iree/compiler/Translation/SPIRV/Kernels/BUILD b/iree/compiler/Translation/SPIRV/EmbeddedKernels/Kernels/BUILD
similarity index 100%
rename from iree/compiler/Translation/SPIRV/Kernels/BUILD
rename to iree/compiler/Translation/SPIRV/EmbeddedKernels/Kernels/BUILD
diff --git a/iree/compiler/Translation/SPIRV/Kernels/CMakeLists.txt b/iree/compiler/Translation/SPIRV/EmbeddedKernels/Kernels/CMakeLists.txt
similarity index 100%
rename from iree/compiler/Translation/SPIRV/Kernels/CMakeLists.txt
rename to iree/compiler/Translation/SPIRV/EmbeddedKernels/Kernels/CMakeLists.txt
diff --git a/iree/compiler/Translation/SPIRV/Kernels/conv2d_nhwc.comp b/iree/compiler/Translation/SPIRV/EmbeddedKernels/Kernels/conv2d_nhwc.comp
similarity index 100%
rename from iree/compiler/Translation/SPIRV/Kernels/conv2d_nhwc.comp
rename to iree/compiler/Translation/SPIRV/EmbeddedKernels/Kernels/conv2d_nhwc.comp
diff --git a/iree/compiler/Translation/SPIRV/Kernels/matmul.comp b/iree/compiler/Translation/SPIRV/EmbeddedKernels/Kernels/matmul.comp
similarity index 100%
rename from iree/compiler/Translation/SPIRV/Kernels/matmul.comp
rename to iree/compiler/Translation/SPIRV/EmbeddedKernels/Kernels/matmul.comp
diff --git a/iree/compiler/Translation/SPIRV/Kernels/reduce_untiled.comp b/iree/compiler/Translation/SPIRV/EmbeddedKernels/Kernels/reduce_untiled.comp
similarity index 100%
rename from iree/compiler/Translation/SPIRV/Kernels/reduce_untiled.comp
rename to iree/compiler/Translation/SPIRV/EmbeddedKernels/Kernels/reduce_untiled.comp
diff --git a/iree/compiler/Translation/SPIRV/Kernels/spirv_utils.bzl b/iree/compiler/Translation/SPIRV/EmbeddedKernels/Kernels/spirv_utils.bzl
similarity index 100%
rename from iree/compiler/Translation/SPIRV/Kernels/spirv_utils.bzl
rename to iree/compiler/Translation/SPIRV/EmbeddedKernels/Kernels/spirv_utils.bzl
diff --git a/iree/compiler/Translation/SPIRV/IREEToSPIRVPass.h b/iree/compiler/Translation/SPIRV/IREEToSPIRVPass.h
deleted file mode 100644
index eee1bd4..0000000
--- a/iree/compiler/Translation/SPIRV/IREEToSPIRVPass.h
+++ /dev/null
@@ -1,60 +0,0 @@
-// 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.
-
-//===- IREEToSPIRVPass.h ---------------------------------------*- C++//-*-===//
-//
-// Pass to translate iree executables for vulkan-spirv.
-//
-//===----------------------------------------------------------------------===//
-#ifndef IREE_COMPILER_TRANSLATION_SPIRV_IREETOSPIRVPASS_H
-#define IREE_COMPILER_TRANSLATION_SPIRV_IREETOSPIRVPASS_H
-
-#include "mlir/Pass/Pass.h"
-
-// TODO(ravishankarm): Rename this file to something more meaningful.
-
-namespace mlir {
-class FuncOp;
-namespace iree_compiler {
-
-/// Generates a spirv::ModuleOp from the module within an IREE Executable with
-/// target-config vulkan-spirv.
-std::unique_ptr<OpPassBase<ModuleOp>> createIREEToSPIRVPass();
-
-/// Performs analysis to compute affine maps that represent the index of the
-/// elements of tensor values needed within a workitem.
-std::unique_ptr<OpPassBase<FuncOp>> createIndexComputationPass();
-
-// Legalizes integer width from i1, i8 and i64 types to i32 type.
-std::unique_ptr<Pass> createAdjustIntegerWidthPass();
-
-/// A pass that convertes entry functions for reductions into a form
-/// that is convenient to lower to SPIR-V.
-// TODO(ravishankarm) : This is a placeholder pass. Eventually this pass should
-// not be needed.
-std::unique_ptr<Pass> createPrepareReductionDispatchPass();
-
-/// Method to legalize the apply function within a reduction dispatch. This is
-/// not a pass since lowering of the entry function and the reduction apply
-/// function has to happen simultaneously to avoid dangling symbols.
-// TODO(ravishankarm) : Can probably fix that by adding an empty function and
-// then materializing it. There is no need to do that right now, but maybe in
-// the future.
-LogicalResult lowerReductionApplyFunction(MLIRContext *context,
- ArrayRef<Operation *> fns);
-
-} // namespace iree_compiler
-} // namespace mlir
-
-#endif // IREE_COMPILER_TRANSLATION_SPIRV_IREETOSPIRVPASS_H
diff --git a/iree/compiler/Translation/SPIRV/IndexComputation/BUILD b/iree/compiler/Translation/SPIRV/IndexComputation/BUILD
new file mode 100644
index 0000000..1dda096
--- /dev/null
+++ b/iree/compiler/Translation/SPIRV/IndexComputation/BUILD
@@ -0,0 +1,47 @@
+# 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.
+
+package(
+ default_visibility = ["//visibility:public"],
+ licenses = ["notice"], # Apache 2.0
+)
+
+cc_library(
+ name = "IndexComputation",
+ srcs = [
+ "IREEIndexComputation.cpp",
+ "IndexComputation.cpp",
+ "IndexComputationAttribute.cpp",
+ "IndexComputationPass.cpp",
+ "XLAIndexPropagation.cpp",
+ ],
+ hdrs = [
+ "IREEIndexComputation.h",
+ "IndexComputation.h",
+ "IndexComputationAttribute.h",
+ "IndexComputationPass.h",
+ "XLAIndexPropagation.h",
+ ],
+ deps = [
+ "//iree/compiler/Dialect/IREE/IR",
+ "//iree/compiler/Utils",
+ "@llvm-project//llvm:support",
+ "@llvm-project//mlir:IR",
+ "@llvm-project//mlir:Pass",
+ "@llvm-project//mlir:SPIRVDialect",
+ "@llvm-project//mlir:StandardOps",
+ "@org_tensorflow//tensorflow/compiler/mlir/xla:hlo",
+ ],
+ alwayslink = 1,
+)
diff --git a/iree/compiler/Translation/SPIRV/IndexComputation/CMakeLists.txt b/iree/compiler/Translation/SPIRV/IndexComputation/CMakeLists.txt
new file mode 100644
index 0000000..9e9a7ec
--- /dev/null
+++ b/iree/compiler/Translation/SPIRV/IndexComputation/CMakeLists.txt
@@ -0,0 +1,41 @@
+# 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.
+
+iree_cc_library(
+ NAME
+ IndexComputation
+ HDRS
+ "IREEIndexComputation.h"
+ "IndexComputation.h"
+ "IndexComputationAttribute.h"
+ "IndexComputationPass.h"
+ "XLAIndexPropagation.h"
+ SRCS
+ "IREEIndexComputation.cpp"
+ "IndexComputation.cpp"
+ "IndexComputationAttribute.cpp"
+ "IndexComputationPass.cpp"
+ "XLAIndexPropagation.cpp"
+ DEPS
+ iree::compiler::Dialect::IREE::IR
+ iree::compiler::Utils
+ LLVMSupport
+ MLIRIR
+ MLIRPass
+ MLIRSPIRV
+ MLIRStandardOps
+ tensorflow::mlir_xla
+ ALWAYSLINK
+ PUBLIC
+)
diff --git a/iree/compiler/Translation/SPIRV/IREEIndexComputation.cpp b/iree/compiler/Translation/SPIRV/IndexComputation/IREEIndexComputation.cpp
similarity index 98%
rename from iree/compiler/Translation/SPIRV/IREEIndexComputation.cpp
rename to iree/compiler/Translation/SPIRV/IndexComputation/IREEIndexComputation.cpp
index 910f687..03e6ffe 100644
--- a/iree/compiler/Translation/SPIRV/IREEIndexComputation.cpp
+++ b/iree/compiler/Translation/SPIRV/IndexComputation/IREEIndexComputation.cpp
@@ -18,7 +18,7 @@
// dispatch functions.
//
//===----------------------------------------------------------------------===//
-#include "iree/compiler/Translation/SPIRV/IREEIndexComputation.h"
+#include "iree/compiler/Translation/SPIRV/IndexComputation/IREEIndexComputation.h"
namespace mlir {
namespace iree_compiler {
diff --git a/iree/compiler/Translation/SPIRV/IREEIndexComputation.h b/iree/compiler/Translation/SPIRV/IndexComputation/IREEIndexComputation.h
similarity index 88%
rename from iree/compiler/Translation/SPIRV/IREEIndexComputation.h
rename to iree/compiler/Translation/SPIRV/IndexComputation/IREEIndexComputation.h
index 69d6689..3a1ef6d 100644
--- a/iree/compiler/Translation/SPIRV/IREEIndexComputation.h
+++ b/iree/compiler/Translation/SPIRV/IndexComputation/IREEIndexComputation.h
@@ -17,11 +17,11 @@
// Index Propagation for IREE statements that are used in dispatch functions.
//
//===----------------------------------------------------------------------===//
-#ifndef IREE_COMPILER_TRANSLATION_SPIRV_H
-#define IREE_COMPILER_TRANSLATION_SPIRV_H
+#ifndef IREE_COMPILER_TRANSLATION_SPIRV_INDEXCOMPUTATION_IREEINDEXCOMP_H
+#define IREE_COMPILER_TRANSLATION_SPIRV_INDEXCOMPUTATION_IREEINDEXCOMP_H
-#include "iree/compiler/Translation/SPIRV/IREECodegenUtils.h"
-#include "iree/compiler/Translation/SPIRV/XLAIndexPropagation.h"
+#include "iree/compiler/Translation/SPIRV/IndexComputation/XLAIndexPropagation.h"
+#include "iree/compiler/Utils/IREECodegenUtils.h"
#include "mlir/IR/Function.h"
namespace mlir {
@@ -70,4 +70,4 @@
} // namespace iree_compiler
} // namespace mlir
-#endif // IREE_COMPILER_TRANSLATION_SPIRV_H
+#endif // IREE_COMPILER_TRANSLATION_SPIRV_INDEXCOMPUTATION_IREEINDEXCOMP_H
diff --git a/iree/compiler/Translation/SPIRV/IndexComputation.cpp b/iree/compiler/Translation/SPIRV/IndexComputation/IndexComputation.cpp
similarity index 98%
rename from iree/compiler/Translation/SPIRV/IndexComputation.cpp
rename to iree/compiler/Translation/SPIRV/IndexComputation/IndexComputation.cpp
index 4f777df..509355a 100644
--- a/iree/compiler/Translation/SPIRV/IndexComputation.cpp
+++ b/iree/compiler/Translation/SPIRV/IndexComputation/IndexComputation.cpp
@@ -18,9 +18,9 @@
// tensor computed within that workitem.
//
//===----------------------------------------------------------------------===//
-#include "iree/compiler/Translation/SPIRV/IndexComputation.h"
+#include "iree/compiler/Translation/SPIRV/IndexComputation/IndexComputation.h"
-#include "iree/compiler/Translation/SPIRV/IndexComputationAttribute.h"
+#include "iree/compiler/Translation/SPIRV/IndexComputation/IndexComputationAttribute.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/raw_ostream.h"
diff --git a/iree/compiler/Translation/SPIRV/IndexComputation.h b/iree/compiler/Translation/SPIRV/IndexComputation/IndexComputation.h
similarity index 97%
rename from iree/compiler/Translation/SPIRV/IndexComputation.h
rename to iree/compiler/Translation/SPIRV/IndexComputation/IndexComputation.h
index 44fbd7d..787c7ad 100644
--- a/iree/compiler/Translation/SPIRV/IndexComputation.h
+++ b/iree/compiler/Translation/SPIRV/IndexComputation/IndexComputation.h
@@ -18,11 +18,11 @@
// tensor computed within that workitem.
//
//===----------------------------------------------------------------------===//
-#ifndef IREE_COMPILER_TRANSLATION_SPIRV_INDEXCOMPUTATION_H
-#define IREE_COMPILER_TRANSLATION_SPIRV_INDEXCOMPUTATION_H
+#ifndef IREE_COMPILER_TRANSLATION_SPIRV_INDEXCOMPUTATION_INDEXCOMPUTATION_H
+#define IREE_COMPILER_TRANSLATION_SPIRV_INDEXCOMPUTATION_INDEXCOMPUTATION_H
-#include "iree/compiler/Translation/SPIRV/IREECodegenUtils.h"
-#include "iree/compiler/Translation/SPIRV/IndexComputationAttribute.h"
+#include "iree/compiler/Translation/SPIRV/IndexComputation/IndexComputationAttribute.h"
+#include "iree/compiler/Utils/IREECodegenUtils.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
@@ -342,4 +342,4 @@
} // namespace iree_compiler
} // namespace mlir
-#endif // IREE_COMPILER_TRANSLATION_SPIRV_INDEXCOMPUTATION_H
+#endif // IREE_COMPILER_TRANSLATION_SPIRV_INDEXCOMPUTATION_INDEXCOMPUTATION_H
diff --git a/iree/compiler/Translation/SPIRV/IndexComputationAttribute.cpp b/iree/compiler/Translation/SPIRV/IndexComputation/IndexComputationAttribute.cpp
similarity index 99%
rename from iree/compiler/Translation/SPIRV/IndexComputationAttribute.cpp
rename to iree/compiler/Translation/SPIRV/IndexComputation/IndexComputationAttribute.cpp
index 2d5cec3..634fc41 100644
--- a/iree/compiler/Translation/SPIRV/IndexComputationAttribute.cpp
+++ b/iree/compiler/Translation/SPIRV/IndexComputation/IndexComputationAttribute.cpp
@@ -18,7 +18,7 @@
// the result of the IndexComputation Analysis
//
//===----------------------------------------------------------------------===//
-#include "iree/compiler/Translation/SPIRV/IndexComputationAttribute.h"
+#include "iree/compiler/Translation/SPIRV/IndexComputation/IndexComputationAttribute.h"
#include "iree/compiler/Dialect/IREE/IR/IREEOps.h"
#include "mlir/IR/AffineMap.h"
diff --git a/iree/compiler/Translation/SPIRV/IndexComputationAttribute.h b/iree/compiler/Translation/SPIRV/IndexComputation/IndexComputationAttribute.h
similarity index 94%
rename from iree/compiler/Translation/SPIRV/IndexComputationAttribute.h
rename to iree/compiler/Translation/SPIRV/IndexComputation/IndexComputationAttribute.h
index 565e69f..5c3cb74 100644
--- a/iree/compiler/Translation/SPIRV/IndexComputationAttribute.h
+++ b/iree/compiler/Translation/SPIRV/IndexComputation/IndexComputationAttribute.h
@@ -18,8 +18,8 @@
// the result of the IndexComputation Analysis
//
//===----------------------------------------------------------------------===//
-#ifndef IREE_COMPILER_TRANSLATION_SPIRV_INDEXCOMPUTATIONATTRIBUTE_H
-#define IREE_COMPILER_TRANSLATION_SPIRV_INDEXCOMPUTATIONATTRIBUTE_H
+#ifndef IREE_COMPILER_TRANSLATION_SPIRV_INDEXCOMPUTATION_COMPUTATIONATTR_H
+#define IREE_COMPILER_TRANSLATION_SPIRV_INDEXCOMPUTATION_COMPUTATIONATTR_H
#include "mlir/IR/Attributes.h"
@@ -89,4 +89,4 @@
} // namespace index_computation_attribute
} // namespace iree_compiler
} // namespace mlir
-#endif // IREE_COMPILER_TRANSLATION_SPIRV_INDEXCOMPUTATIONATTRIBUTE_H
+#endif // IREE_COMPILER_TRANSLATION_SPIRV_INDEXCOMPUTATION_COMPUTATIONATTR_H
diff --git a/iree/compiler/Translation/SPIRV/IndexComputationPass.cpp b/iree/compiler/Translation/SPIRV/IndexComputation/IndexComputationPass.cpp
similarity index 98%
rename from iree/compiler/Translation/SPIRV/IndexComputationPass.cpp
rename to iree/compiler/Translation/SPIRV/IndexComputation/IndexComputationPass.cpp
index b23e06c..c08f2bb 100644
--- a/iree/compiler/Translation/SPIRV/IndexComputationPass.cpp
+++ b/iree/compiler/Translation/SPIRV/IndexComputation/IndexComputationPass.cpp
@@ -17,7 +17,7 @@
// Pass to perform index propagation in iree dispatch functions
//
//===----------------------------------------------------------------------===//
-#include "iree/compiler/Translation/SPIRV/IREEIndexComputation.h"
+#include "iree/compiler/Translation/SPIRV/IndexComputation/IREEIndexComputation.h"
#include "mlir/Dialect/SPIRV/SPIRVOps.h"
#include "mlir/Dialect/SPIRV/SPIRVTypes.h"
#include "mlir/Dialect/StandardOps/Ops.h"
diff --git a/iree/compiler/Translation/SPIRV/IndexComputation/IndexComputationPass.h b/iree/compiler/Translation/SPIRV/IndexComputation/IndexComputationPass.h
new file mode 100644
index 0000000..ad0e649
--- /dev/null
+++ b/iree/compiler/Translation/SPIRV/IndexComputation/IndexComputationPass.h
@@ -0,0 +1,34 @@
+// 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.
+
+//===- IndexComputationPass.h ----------------------------------*- C++//-*-===//
+//
+// Pass to perform index propagation in iree dispatch functions
+//
+//===----------------------------------------------------------------------===//
+#ifndef IREE_COMPILER_TRANSLATION_SPIRV_INDEXCOMPUTATION_COMPUTATIONPASS_H
+#define IREE_COMPILER_TRANSLATION_SPIRV_INDEXCOMPUTATION_COMPUTATIONPASS_H
+
+#include "mlir/Pass/Pass.h"
+
+namespace mlir {
+namespace iree_compiler {
+
+/// Pass to perform index computation on a dispatch function
+std::unique_ptr<OpPassBase<FuncOp>> createIndexComputationPass();
+
+} // namespace iree_compiler
+} // namespace mlir
+
+#endif // IREE_COMPILER_TRANSLATION_SPIRV_INDEXCOMPUTATION_COMPUTATIONPASS_H
diff --git a/iree/compiler/Translation/SPIRV/XLAIndexPropagation.cpp b/iree/compiler/Translation/SPIRV/IndexComputation/XLAIndexPropagation.cpp
similarity index 99%
rename from iree/compiler/Translation/SPIRV/XLAIndexPropagation.cpp
rename to iree/compiler/Translation/SPIRV/IndexComputation/XLAIndexPropagation.cpp
index 92a9fe7..d107499 100644
--- a/iree/compiler/Translation/SPIRV/XLAIndexPropagation.cpp
+++ b/iree/compiler/Translation/SPIRV/IndexComputation/XLAIndexPropagation.cpp
@@ -20,7 +20,7 @@
//
//===----------------------------------------------------------------------===//
-#include "iree/compiler/Translation/SPIRV/XLAIndexPropagation.h"
+#include "iree/compiler/Translation/SPIRV/IndexComputation/XLAIndexPropagation.h"
namespace mlir {
namespace iree_compiler {
diff --git a/iree/compiler/Translation/SPIRV/XLAIndexPropagation.h b/iree/compiler/Translation/SPIRV/IndexComputation/XLAIndexPropagation.h
similarity index 93%
rename from iree/compiler/Translation/SPIRV/XLAIndexPropagation.h
rename to iree/compiler/Translation/SPIRV/IndexComputation/XLAIndexPropagation.h
index f5c2b59..24ff6c7 100644
--- a/iree/compiler/Translation/SPIRV/XLAIndexPropagation.h
+++ b/iree/compiler/Translation/SPIRV/IndexComputation/XLAIndexPropagation.h
@@ -19,11 +19,11 @@
// index.
//
//===----------------------------------------------------------------------===//
-#ifndef IREE_COMPILER_TRANSLATION_SPIRV_XLAINDEXPROPOGATION_H
-#define IREE_COMPILER_TRANSLATION_SPIRV_XLAINDEXPROPOGATION_H
+#ifndef IREE_COMPILER_TRANSLATION_SPIRV_INDEXCOMPUTATION_XLAPROPOGATION_H
+#define IREE_COMPILER_TRANSLATION_SPIRV_INDEXCOMPUTATION_XLAPROPOGATION_H
-#include "iree/compiler/Translation/SPIRV/IndexComputation.h"
-#include "iree/compiler/Translation/SPIRV/IndexComputationAttribute.h"
+#include "iree/compiler/Translation/SPIRV/IndexComputation/IndexComputation.h"
+#include "iree/compiler/Translation/SPIRV/IndexComputation/IndexComputationAttribute.h"
#include "mlir/Dialect/StandardOps/Ops.h"
#include "mlir/IR/Function.h"
#include "tensorflow/compiler/mlir/xla/ir/hlo_ops.h"
@@ -155,4 +155,4 @@
} // namespace iree_compiler
} // namespace mlir
-#endif // IREE_COMPILER_TRANSLATION_SPIRV_XLAINDEXPROPOGATION_H
+#endif // IREE_COMPILER_TRANSLATION_SPIRV_INDEXCOMPUTATION_XLAPROPOGATION_H
diff --git a/iree/compiler/Translation/SPIRV/test/index_propagation/BUILD b/iree/compiler/Translation/SPIRV/IndexComputation/test/BUILD
similarity index 100%
rename from iree/compiler/Translation/SPIRV/test/index_propagation/BUILD
rename to iree/compiler/Translation/SPIRV/IndexComputation/test/BUILD
diff --git a/iree/compiler/Translation/SPIRV/test/index_propagation/broadcast.mlir b/iree/compiler/Translation/SPIRV/IndexComputation/test/broadcast.mlir
similarity index 100%
rename from iree/compiler/Translation/SPIRV/test/index_propagation/broadcast.mlir
rename to iree/compiler/Translation/SPIRV/IndexComputation/test/broadcast.mlir
diff --git a/iree/compiler/Translation/SPIRV/test/index_propagation/broadcast_in_dim.mlir b/iree/compiler/Translation/SPIRV/IndexComputation/test/broadcast_in_dim.mlir
similarity index 100%
rename from iree/compiler/Translation/SPIRV/test/index_propagation/broadcast_in_dim.mlir
rename to iree/compiler/Translation/SPIRV/IndexComputation/test/broadcast_in_dim.mlir
diff --git a/iree/compiler/Translation/SPIRV/test/index_propagation/concatenate.mlir b/iree/compiler/Translation/SPIRV/IndexComputation/test/concatenate.mlir
similarity index 100%
rename from iree/compiler/Translation/SPIRV/test/index_propagation/concatenate.mlir
rename to iree/compiler/Translation/SPIRV/IndexComputation/test/concatenate.mlir
diff --git a/iree/compiler/Translation/SPIRV/test/index_propagation/copy.mlir b/iree/compiler/Translation/SPIRV/IndexComputation/test/copy.mlir
similarity index 100%
rename from iree/compiler/Translation/SPIRV/test/index_propagation/copy.mlir
rename to iree/compiler/Translation/SPIRV/IndexComputation/test/copy.mlir
diff --git a/iree/compiler/Translation/SPIRV/test/index_propagation/extract_element.mlir b/iree/compiler/Translation/SPIRV/IndexComputation/test/extract_element.mlir
similarity index 100%
rename from iree/compiler/Translation/SPIRV/test/index_propagation/extract_element.mlir
rename to iree/compiler/Translation/SPIRV/IndexComputation/test/extract_element.mlir
diff --git a/iree/compiler/Translation/SPIRV/test/index_propagation/gather.mlir b/iree/compiler/Translation/SPIRV/IndexComputation/test/gather.mlir
similarity index 100%
rename from iree/compiler/Translation/SPIRV/test/index_propagation/gather.mlir
rename to iree/compiler/Translation/SPIRV/IndexComputation/test/gather.mlir
diff --git a/iree/compiler/Translation/SPIRV/test/index_propagation/pad.mlir b/iree/compiler/Translation/SPIRV/IndexComputation/test/pad.mlir
similarity index 100%
rename from iree/compiler/Translation/SPIRV/test/index_propagation/pad.mlir
rename to iree/compiler/Translation/SPIRV/IndexComputation/test/pad.mlir
diff --git a/iree/compiler/Translation/SPIRV/test/index_propagation/reverse.mlir b/iree/compiler/Translation/SPIRV/IndexComputation/test/reverse.mlir
similarity index 100%
rename from iree/compiler/Translation/SPIRV/test/index_propagation/reverse.mlir
rename to iree/compiler/Translation/SPIRV/IndexComputation/test/reverse.mlir
diff --git a/iree/compiler/Translation/SPIRV/test/index_propagation/slice.mlir b/iree/compiler/Translation/SPIRV/IndexComputation/test/slice.mlir
similarity index 100%
rename from iree/compiler/Translation/SPIRV/test/index_propagation/slice.mlir
rename to iree/compiler/Translation/SPIRV/IndexComputation/test/slice.mlir
diff --git a/iree/compiler/Translation/SPIRV/test/index_propagation/store_reduce.mlir b/iree/compiler/Translation/SPIRV/IndexComputation/test/store_reduce.mlir
similarity index 100%
rename from iree/compiler/Translation/SPIRV/test/index_propagation/store_reduce.mlir
rename to iree/compiler/Translation/SPIRV/IndexComputation/test/store_reduce.mlir
diff --git a/iree/compiler/Translation/SPIRV/test/index_propagation/transpose_add.mlir b/iree/compiler/Translation/SPIRV/IndexComputation/test/transpose_add.mlir
similarity index 100%
rename from iree/compiler/Translation/SPIRV/test/index_propagation/transpose_add.mlir
rename to iree/compiler/Translation/SPIRV/IndexComputation/test/transpose_add.mlir
diff --git a/iree/compiler/Translation/SPIRV/AdjustIntegerWidthPass.cpp b/iree/compiler/Translation/SPIRV/Passes/AdjustIntegerWidthPass.cpp
similarity index 99%
rename from iree/compiler/Translation/SPIRV/AdjustIntegerWidthPass.cpp
rename to iree/compiler/Translation/SPIRV/Passes/AdjustIntegerWidthPass.cpp
index f0cdc0d..626a807 100644
--- a/iree/compiler/Translation/SPIRV/AdjustIntegerWidthPass.cpp
+++ b/iree/compiler/Translation/SPIRV/Passes/AdjustIntegerWidthPass.cpp
@@ -17,13 +17,12 @@
// Pass to adjust integer widths of operations.
//
//===----------------------------------------------------------------------===//
-#include "iree/compiler/Translation/SPIRV/IREEToSPIRVPass.h"
-#include "iree/compiler/Utils/TypeConversionUtils.h"
#include "mlir/Dialect/SPIRV/LayoutUtils.h"
#include "mlir/Dialect/SPIRV/SPIRVOps.h"
#include "mlir/Dialect/StandardOps/Ops.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/IR/StandardTypes.h"
+#include "mlir/Pass/Pass.h"
#include "mlir/Transforms/DialectConversion.h"
namespace mlir {
diff --git a/iree/compiler/Translation/SPIRV/test/PrepareReductionDispatch/BUILD b/iree/compiler/Translation/SPIRV/Passes/BUILD
similarity index 62%
copy from iree/compiler/Translation/SPIRV/test/PrepareReductionDispatch/BUILD
copy to iree/compiler/Translation/SPIRV/Passes/BUILD
index 1cbffd1..95ba18b 100644
--- a/iree/compiler/Translation/SPIRV/test/PrepareReductionDispatch/BUILD
+++ b/iree/compiler/Translation/SPIRV/Passes/BUILD
@@ -12,19 +12,26 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-# Tests for common transforms.
-
-load("//iree:build_defs.bzl", "iree_glob_lit_tests", "iree_setup_lit_package")
-
package(
default_visibility = ["//visibility:public"],
licenses = ["notice"], # Apache 2.0
)
-iree_setup_lit_package(
- data = [
- "//iree/tools:iree-opt",
+cc_library(
+ name = "Passes",
+ srcs = [
+ "AdjustIntegerWidthPass.cpp",
],
+ hdrs = [
+ "Passes.h",
+ ],
+ deps = [
+ "@llvm-project//mlir:IR",
+ "@llvm-project//mlir:Pass",
+ "@llvm-project//mlir:SPIRVDialect",
+ "@llvm-project//mlir:SPIRVLowering",
+ "@llvm-project//mlir:StandardOps",
+ "@llvm-project//mlir:Transforms",
+ ],
+ alwayslink = 1,
)
-
-iree_glob_lit_tests()
diff --git a/iree/compiler/Translation/SPIRV/test/PrepareReductionDispatch/BUILD b/iree/compiler/Translation/SPIRV/Passes/CMakeLists.txt
similarity index 64%
rename from iree/compiler/Translation/SPIRV/test/PrepareReductionDispatch/BUILD
rename to iree/compiler/Translation/SPIRV/Passes/CMakeLists.txt
index 1cbffd1..1352de8 100644
--- a/iree/compiler/Translation/SPIRV/test/PrepareReductionDispatch/BUILD
+++ b/iree/compiler/Translation/SPIRV/Passes/CMakeLists.txt
@@ -12,19 +12,19 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-# Tests for common transforms.
-
-load("//iree:build_defs.bzl", "iree_glob_lit_tests", "iree_setup_lit_package")
-
-package(
- default_visibility = ["//visibility:public"],
- licenses = ["notice"], # Apache 2.0
+iree_cc_library(
+ NAME
+ Passes
+ HDRS
+ "Passes.h"
+ SRCS
+ "AdjustIntegerWidthPass.cpp"
+ DEPS
+ MLIRIR
+ MLIRPass
+ MLIRSPIRV
+ MLIRStandardOps
+ MLIRTransforms
+ ALWAYSLINK
+ PUBLIC
)
-
-iree_setup_lit_package(
- data = [
- "//iree/tools:iree-opt",
- ],
-)
-
-iree_glob_lit_tests()
diff --git a/iree/compiler/Translation/SPIRV/Passes/Passes.h b/iree/compiler/Translation/SPIRV/Passes/Passes.h
new file mode 100644
index 0000000..a6dda53
--- /dev/null
+++ b/iree/compiler/Translation/SPIRV/Passes/Passes.h
@@ -0,0 +1,35 @@
+// 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.
+
+//===- Passes.h ------------------------------------------------*- C++//-*-===//
+//
+// Utility passes used in SPIR-V lowering.
+//
+//===----------------------------------------------------------------------===//
+#ifndef IREE_COMPILER_TRANSLATION_SPIRV_PASSES_PASSES_H
+#define IREE_COMPILER_TRANSLATION_SPIRV_PASSES_PASSES_H
+
+#include "mlir/Pass/Pass.h"
+
+namespace mlir {
+class FuncOp;
+namespace iree_compiler {
+
+// Legalizes integer width from i1, i8 and i64 types to i32 type.
+std::unique_ptr<Pass> createAdjustIntegerWidthPass();
+
+} // namespace iree_compiler
+} // namespace mlir
+
+#endif // IREE_COMPILER_TRANSLATION_SPIRV_PASSES_PASSES_H
diff --git a/iree/compiler/Translation/SPIRV/ReductionCodegen/BUILD b/iree/compiler/Translation/SPIRV/ReductionCodegen/BUILD
new file mode 100644
index 0000000..a1d455e
--- /dev/null
+++ b/iree/compiler/Translation/SPIRV/ReductionCodegen/BUILD
@@ -0,0 +1,39 @@
+# 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.
+
+package(
+ default_visibility = ["//visibility:public"],
+ licenses = ["notice"], # Apache 2.0
+)
+
+cc_library(
+ name = "ReductionCodegen",
+ srcs = [
+ "PrepareReductionDispatch.cpp",
+ "ReductionFnLowering.cpp",
+ ],
+ hdrs = [
+ "ReductionCodegenPasses.h",
+ ],
+ deps = [
+ "//iree/compiler/Dialect/IREE/IR",
+ "//iree/compiler/Utils",
+ "@llvm-project//mlir:IR",
+ "@llvm-project//mlir:Pass",
+ "@llvm-project//mlir:SPIRVDialect",
+ "@llvm-project//mlir:StandardOps",
+ "@llvm-project//mlir:Transforms",
+ "@org_tensorflow//tensorflow/compiler/mlir/xla:hlo",
+ ],
+)
diff --git a/iree/compiler/Translation/SPIRV/test/PrepareReductionDispatch/BUILD b/iree/compiler/Translation/SPIRV/ReductionCodegen/CMakeLists.txt
similarity index 61%
copy from iree/compiler/Translation/SPIRV/test/PrepareReductionDispatch/BUILD
copy to iree/compiler/Translation/SPIRV/ReductionCodegen/CMakeLists.txt
index 1cbffd1..9153d38 100644
--- a/iree/compiler/Translation/SPIRV/test/PrepareReductionDispatch/BUILD
+++ b/iree/compiler/Translation/SPIRV/ReductionCodegen/CMakeLists.txt
@@ -12,19 +12,23 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-# Tests for common transforms.
-
-load("//iree:build_defs.bzl", "iree_glob_lit_tests", "iree_setup_lit_package")
-
-package(
- default_visibility = ["//visibility:public"],
- licenses = ["notice"], # Apache 2.0
+iree_cc_library(
+ NAME
+ ReductionCodegen
+ HDRS
+ "ReductionCodegenPasses.h"
+ SRCS
+ "PrepareReductionDispatch.cpp"
+ "ReductionFnLowering.cpp"
+ DEPS
+ iree::compiler::Dialect::IREE::IR
+ iree::compiler::Utils
+ MLIRIR
+ MLIRPass
+ MLIRSPIRV
+ MLIRStandardOps
+ MLIRTransforms
+ tensorflow::mlir_xla
+ ALWAYSLINK
+ PUBLIC
)
-
-iree_setup_lit_package(
- data = [
- "//iree/tools:iree-opt",
- ],
-)
-
-iree_glob_lit_tests()
diff --git a/iree/compiler/Translation/SPIRV/PrepareReductionDispatch.cpp b/iree/compiler/Translation/SPIRV/ReductionCodegen/PrepareReductionDispatch.cpp
similarity index 100%
rename from iree/compiler/Translation/SPIRV/PrepareReductionDispatch.cpp
rename to iree/compiler/Translation/SPIRV/ReductionCodegen/PrepareReductionDispatch.cpp
diff --git a/iree/compiler/Translation/SPIRV/ReductionCodegen/ReductionCodegenPasses.h b/iree/compiler/Translation/SPIRV/ReductionCodegen/ReductionCodegenPasses.h
new file mode 100644
index 0000000..75c9963
--- /dev/null
+++ b/iree/compiler/Translation/SPIRV/ReductionCodegen/ReductionCodegenPasses.h
@@ -0,0 +1,47 @@
+// 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.
+
+//===- ReductionCodegenPasses.h --------------------------------*- C++//-*-===//
+//
+// Passes used for reduction kernel generation.
+//
+//===----------------------------------------------------------------------===//
+#ifndef IREE_COMPILER_TRANSLATION_SPIRV_REDUCETIONCODEGEN_REDUCTIONCODEGEN_H
+#define IREE_COMPILER_TRANSLATION_SPIRV_REDUCETIONCODEGEN_REDUCTIONCODEGEN_H
+
+#include "mlir/Pass/Pass.h"
+
+namespace mlir {
+class FuncOp;
+namespace iree_compiler {
+
+/// Converts entry functions for reductions into a form convenient for SPIR-V
+/// lowering.
+// TODO(ravishankarm) : This is a placeholder pass. Eventually this
+// pass should not be needed.
+std::unique_ptr<Pass> createPrepareReductionDispatchPass();
+
+/// Legalizes the apply function within a reduction dispatch. This is not a pass
+/// since lowering of the entry function and the reduction apply function has to
+/// happen simultaneously to avoid dangling symbols.
+// TODO(ravishankarm) : Can probably fix that by adding an empty function and
+// then materializing it. There is no need to do that right now, but maybe in
+// the future.
+LogicalResult lowerReductionApplyFunction(MLIRContext *context,
+ ArrayRef<Operation *> fns);
+
+} // namespace iree_compiler
+} // namespace mlir
+
+#endif // IREE_COMPILER_TRANSLATION_SPIRV_REDUCETIONCODEGEN_REDUCTIONCODEGEN_H
diff --git a/iree/compiler/Translation/SPIRV/ReductionFnLowering.cpp b/iree/compiler/Translation/SPIRV/ReductionCodegen/ReductionFnLowering.cpp
similarity index 100%
rename from iree/compiler/Translation/SPIRV/ReductionFnLowering.cpp
rename to iree/compiler/Translation/SPIRV/ReductionCodegen/ReductionFnLowering.cpp
diff --git a/iree/compiler/Translation/SPIRV/test/BUILD b/iree/compiler/Translation/SPIRV/ReductionCodegen/test/BUILD
similarity index 100%
copy from iree/compiler/Translation/SPIRV/test/BUILD
copy to iree/compiler/Translation/SPIRV/ReductionCodegen/test/BUILD
diff --git a/iree/compiler/Translation/SPIRV/test/ReductionFnLowering/ops.mlir b/iree/compiler/Translation/SPIRV/ReductionCodegen/test/ops.mlir
similarity index 100%
rename from iree/compiler/Translation/SPIRV/test/ReductionFnLowering/ops.mlir
rename to iree/compiler/Translation/SPIRV/ReductionCodegen/test/ops.mlir
diff --git a/iree/compiler/Translation/SPIRV/test/PrepareReductionDispatch/simple.mlir b/iree/compiler/Translation/SPIRV/ReductionCodegen/test/simple.mlir
similarity index 100%
rename from iree/compiler/Translation/SPIRV/test/PrepareReductionDispatch/simple.mlir
rename to iree/compiler/Translation/SPIRV/ReductionCodegen/test/simple.mlir
diff --git a/iree/compiler/Translation/SPIRV/BUILD b/iree/compiler/Translation/SPIRV/XLAToSPIRV/BUILD
similarity index 64%
rename from iree/compiler/Translation/SPIRV/BUILD
rename to iree/compiler/Translation/SPIRV/XLAToSPIRV/BUILD
index a67a10c..1f8c2fe 100644
--- a/iree/compiler/Translation/SPIRV/BUILD
+++ b/iree/compiler/Translation/SPIRV/XLAToSPIRV/BUILD
@@ -18,56 +18,37 @@
)
cc_library(
- name = "SPIRV",
+ name = "XLAToSPIRV",
srcs = [
- "AdjustIntegerWidthPass.cpp",
- "EmbeddedKernels.cpp",
- "IREEIndexComputation.cpp",
"IREEToSPIRV.cpp",
"IREEToSPIRVPass.cpp",
- "IndexComputation.cpp",
- "IndexComputationAttribute.cpp",
- "IndexComputationPass.cpp",
- "PrepareReductionDispatch.cpp",
- "ReductionFnLowering.cpp",
"SPIRVLowering.cpp",
- "SPIRVLowering.h",
- "XLAIndexPropagation.cpp",
"XLAToSPIRV.cpp",
],
hdrs = [
- "EmbeddedKernels.h",
- "IREECodegenUtils.h",
- "IREEIndexComputation.h",
"IREEToSPIRV.h",
"IREEToSPIRVPass.h",
- "IndexComputation.h",
- "IndexComputationAttribute.h",
+ "SPIRVLowering.h",
"TensorIndexToScalarValueMap.h",
- "XLAIndexPropagation.h",
"XLAToSPIRV.h",
],
deps = [
"//iree/compiler/Dialect/IREE/IR",
- "//iree/compiler/Translation/SPIRV/Kernels",
+ "//iree/compiler/Translation/SPIRV/IndexComputation",
+ "//iree/compiler/Translation/SPIRV/Passes",
+ "//iree/compiler/Translation/SPIRV/ReductionCodegen",
"//iree/compiler/Utils",
- "//iree/schemas:spirv_executable_def_cc_fbs",
- "@com_github_google_flatbuffers//:flatbuffers",
"@llvm-project//llvm:support",
"@llvm-project//mlir:AffineOps",
"@llvm-project//mlir:AffineToStandardTransforms",
"@llvm-project//mlir:IR",
"@llvm-project//mlir:Pass",
"@llvm-project//mlir:SPIRVDialect",
- "@llvm-project//mlir:SPIRVDialectRegistration",
"@llvm-project//mlir:SPIRVLowering",
- "@llvm-project//mlir:SPIRVSerialization",
- "@llvm-project//mlir:StandardDialectRegistration",
"@llvm-project//mlir:StandardOps",
"@llvm-project//mlir:StandardToSPIRVConversions",
"@llvm-project//mlir:Support",
"@llvm-project//mlir:Transforms",
- "@llvm-project//mlir:Translation",
"@org_tensorflow//tensorflow/compiler/mlir/xla:hlo",
],
alwayslink = 1,
diff --git a/iree/compiler/Translation/SPIRV/XLAToSPIRV/CMakeLists.txt b/iree/compiler/Translation/SPIRV/XLAToSPIRV/CMakeLists.txt
new file mode 100644
index 0000000..19b8910
--- /dev/null
+++ b/iree/compiler/Translation/SPIRV/XLAToSPIRV/CMakeLists.txt
@@ -0,0 +1,48 @@
+# 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.
+
+iree_cc_library(
+ NAME
+ XLAToSPIRV
+ HDRS
+ "IREEToSPIRV.h"
+ "IREEToSPIRVPass.h"
+ "SPIRVLowering.h"
+ "TensorIndexToScalarValueMap.h"
+ "XLAToSPIRV.h"
+ SRCS
+ "IREEToSPIRV.cpp"
+ "IREEToSPIRVPass.cpp"
+ "SPIRVLowering.cpp"
+ "XLAToSPIRV.cpp"
+ DEPS
+ iree::compiler::Dialect::IREE::IR
+ iree::compiler::Translation::SPIRV::IndexComputation
+ iree::compiler::Translation::SPIRV::Passes
+ iree::compiler::Translation::SPIRV::ReductionCodegen
+ iree::compiler::Utils
+ LLVMSupport
+ MLIRAffineOps
+ MLIRAffineToStandard
+ MLIRIR
+ MLIRPass
+ MLIRSPIRV
+ MLIRStandardOps
+ MLIRStandardToSPIRVTransforms
+ MLIRSupport
+ MLIRTransforms
+ tensorflow::mlir_xla
+ ALWAYSLINK
+ PUBLIC
+)
diff --git a/iree/compiler/Translation/SPIRV/IREEToSPIRV.cpp b/iree/compiler/Translation/SPIRV/XLAToSPIRV/IREEToSPIRV.cpp
similarity index 98%
rename from iree/compiler/Translation/SPIRV/IREEToSPIRV.cpp
rename to iree/compiler/Translation/SPIRV/XLAToSPIRV/IREEToSPIRV.cpp
index 337633a..5009df9 100644
--- a/iree/compiler/Translation/SPIRV/IREEToSPIRV.cpp
+++ b/iree/compiler/Translation/SPIRV/XLAToSPIRV/IREEToSPIRV.cpp
@@ -17,7 +17,7 @@
// Translation of IREE statements in dispatch functions to SPIR-V.
//
//===----------------------------------------------------------------------===//
-#include "iree/compiler/Translation/SPIRV/IREEToSPIRV.h"
+#include "iree/compiler/Translation/SPIRV/XLAToSPIRV/IREEToSPIRV.h"
namespace mlir {
namespace iree_compiler {
diff --git a/iree/compiler/Translation/SPIRV/IREEToSPIRV.h b/iree/compiler/Translation/SPIRV/XLAToSPIRV/IREEToSPIRV.h
similarity index 90%
rename from iree/compiler/Translation/SPIRV/IREEToSPIRV.h
rename to iree/compiler/Translation/SPIRV/XLAToSPIRV/IREEToSPIRV.h
index 115836b..9bf9d5e 100644
--- a/iree/compiler/Translation/SPIRV/IREEToSPIRV.h
+++ b/iree/compiler/Translation/SPIRV/XLAToSPIRV/IREEToSPIRV.h
@@ -17,11 +17,11 @@
// Translation of IREE statements in dispatch functions to SPIR-V.
//
//===----------------------------------------------------------------------===//
-#ifndef IREE_COMPILER_TRANSLATION_SPIRV_IREETOSPIRV_H
-#define IREE_COMPILER_TRANSLATION_SPIRV_IREETOSPIRV_H
+#ifndef IREE_COMPILER_TRANSLATION_SPIRV_XLATOSPIRV_IREETOSPIRV_H
+#define IREE_COMPILER_TRANSLATION_SPIRV_XLATOSPIRV_IREETOSPIRV_H
#include "iree/compiler/Dialect/IREE/IR/IREEOps.h"
-#include "iree/compiler/Translation/SPIRV/SPIRVLowering.h"
+#include "iree/compiler/Translation/SPIRV/XLAToSPIRV/SPIRVLowering.h"
namespace mlir {
namespace iree_compiler {
@@ -74,4 +74,4 @@
} // namespace iree_compiler
} // namespace mlir
-#endif // IREE_COMPILER_TRANSLATION_SPIRV_IREETOSPIRV_H
+#endif // IREE_COMPILER_TRANSLATION_SPIRV_XLATOSPIRV_IREETOSPIRV_H
diff --git a/iree/compiler/Translation/SPIRV/IREEToSPIRVPass.cpp b/iree/compiler/Translation/SPIRV/XLAToSPIRV/IREEToSPIRVPass.cpp
similarity index 87%
rename from iree/compiler/Translation/SPIRV/IREEToSPIRVPass.cpp
rename to iree/compiler/Translation/SPIRV/XLAToSPIRV/IREEToSPIRVPass.cpp
index 0bed9d1..029971e 100644
--- a/iree/compiler/Translation/SPIRV/IREEToSPIRVPass.cpp
+++ b/iree/compiler/Translation/SPIRV/XLAToSPIRV/IREEToSPIRVPass.cpp
@@ -17,18 +17,23 @@
// Pass to translate iree executables for vulkan-spirv.
//
//===----------------------------------------------------------------------===//
-#include "iree/compiler/Translation/SPIRV/IREEToSPIRVPass.h"
+#include "iree/compiler/Translation/SPIRV/XLAToSPIRV/IREEToSPIRVPass.h"
-#include "iree/compiler/Translation/SPIRV/IREEIndexComputation.h"
-#include "iree/compiler/Translation/SPIRV/IREEToSPIRV.h"
-#include "iree/compiler/Translation/SPIRV/XLAToSPIRV.h"
+#include "iree/compiler/Translation/SPIRV/IndexComputation/IndexComputationPass.h"
+#include "iree/compiler/Translation/SPIRV/Passes/Passes.h"
+#include "iree/compiler/Translation/SPIRV/ReductionCodegen/ReductionCodegenPasses.h"
+#include "iree/compiler/Translation/SPIRV/XLAToSPIRV/IREEToSPIRV.h"
+#include "iree/compiler/Translation/SPIRV/XLAToSPIRV/XLAToSPIRV.h"
#include "llvm/ADT/StringSet.h"
#include "mlir/Conversion/AffineToStandard/AffineToStandard.h"
#include "mlir/Conversion/StandardToSPIRV/ConvertStandardToSPIRV.h"
+#include "mlir/Dialect/SPIRV/Passes.h"
#include "mlir/Dialect/SPIRV/SPIRVLowering.h"
#include "mlir/Dialect/SPIRV/SPIRVOps.h"
#include "mlir/Dialect/SPIRV/SPIRVTypes.h"
#include "mlir/Dialect/StandardOps/Ops.h"
+#include "mlir/Transforms/Passes.h"
+#include "tensorflow/compiler/mlir/xla/transforms/passes.h"
namespace mlir {
namespace iree_compiler {
@@ -198,5 +203,18 @@
static PassRegistration<IREEToSPIRVPass> pass(
"convert-iree-to-spirv",
"Convert IREE dispatch functions to SPIR-V dialect");
+
+void addIREEToSPIRVPasses(PassManager &conversionPassManager) {
+ conversionPassManager.addPass(xla_hlo::createLegalizeToStdPass());
+ conversionPassManager.addPass(createPrepareReductionDispatchPass());
+ conversionPassManager.addPass(createIndexComputationPass());
+ conversionPassManager.addPass(createIREEToSPIRVPass());
+
+ OpPassManager &spirvPasses = conversionPassManager.nest<spirv::ModuleOp>();
+ spirvPasses.addPass(spirv::createLowerABIAttributesPass());
+ spirvPasses.addPass(createInlinerPass());
+ spirvPasses.addPass(createAdjustIntegerWidthPass());
+}
+
} // namespace iree_compiler
} // namespace mlir
diff --git a/iree/compiler/Translation/SPIRV/XLAToSPIRV/IREEToSPIRVPass.h b/iree/compiler/Translation/SPIRV/XLAToSPIRV/IREEToSPIRVPass.h
new file mode 100644
index 0000000..13b372e
--- /dev/null
+++ b/iree/compiler/Translation/SPIRV/XLAToSPIRV/IREEToSPIRVPass.h
@@ -0,0 +1,39 @@
+// 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.
+
+//===- IREEToSPIRVPass.h ---------------------------------------*- C++//-*-===//
+//
+// Pass to translate iree executables for vulkan-spirv.
+//
+//===----------------------------------------------------------------------===//
+#ifndef IREE_COMPILER_TRANSLATION_SPIRV_XLATOSPIRV_IREETOSPIRVPASS_H
+#define IREE_COMPILER_TRANSLATION_SPIRV_XLATOSPIRV_IREETOSPIRVPASS_H
+
+#include "mlir/Pass/Pass.h"
+#include "mlir/Pass/PassManager.h"
+
+namespace mlir {
+namespace iree_compiler {
+
+/// Generates a spirv::ModuleOp from the module within an IREE Executable with
+/// target-config vulkan-spirv.
+std::unique_ptr<OpPassBase<ModuleOp>> createIREEToSPIRVPass();
+
+/// Adds all the passes needed to lower dispatch function to SPIR-V
+void addIREEToSPIRVPasses(PassManager &conversionPassManager);
+
+} // namespace iree_compiler
+} // namespace mlir
+
+#endif // IREE_COMPILER_TRANSLATION_SPIRV_XLATOSPIRV_IREETOSPIRVPASS_H
diff --git a/iree/compiler/Translation/SPIRV/SPIRVLowering.cpp b/iree/compiler/Translation/SPIRV/XLAToSPIRV/SPIRVLowering.cpp
similarity index 98%
rename from iree/compiler/Translation/SPIRV/SPIRVLowering.cpp
rename to iree/compiler/Translation/SPIRV/XLAToSPIRV/SPIRVLowering.cpp
index e6b81e4..dca1246 100644
--- a/iree/compiler/Translation/SPIRV/SPIRVLowering.cpp
+++ b/iree/compiler/Translation/SPIRV/XLAToSPIRV/SPIRVLowering.cpp
@@ -17,7 +17,7 @@
// SPIR-V Code-generation for XLA-HLO Ops within IREE Dispatch functions
//
//===----------------------------------------------------------------------===//
-#include "iree/compiler/Translation/SPIRV/SPIRVLowering.h"
+#include "iree/compiler/Translation/SPIRV/XLAToSPIRV/SPIRVLowering.h"
#include "mlir/Dialect/AffineOps/AffineOps.h"
#include "mlir/Dialect/SPIRV/SPIRVLowering.h"
@@ -31,8 +31,8 @@
Value genPointerOffset(OpBuilder &builder, Location loc,
TensorIndexToScalarValueMap &valueCache,
- AffineMap indexMap, ArrayRef<int64_t> shape,
- Value buffer) {
+ const AffineMap &indexMap, ArrayRef<int64_t> shape,
+ const Value &buffer) {
auto varPtrType =
buffer.getType().cast<spirv::PointerType>().getPointeeType();
// The variable has to be a struct type with a single element.
diff --git a/iree/compiler/Translation/SPIRV/SPIRVLowering.h b/iree/compiler/Translation/SPIRV/XLAToSPIRV/SPIRVLowering.h
similarity index 96%
rename from iree/compiler/Translation/SPIRV/SPIRVLowering.h
rename to iree/compiler/Translation/SPIRV/XLAToSPIRV/SPIRVLowering.h
index c969eda..62457ba 100644
--- a/iree/compiler/Translation/SPIRV/SPIRVLowering.h
+++ b/iree/compiler/Translation/SPIRV/XLAToSPIRV/SPIRVLowering.h
@@ -17,12 +17,12 @@
// SPIR-V Code-generation for tensor operations within IREE Dispatch functions
//
//===----------------------------------------------------------------------===//
-#ifndef IREE_COMPILER_TRANSLATION_SPIRV_SPIRVLOWERING_H
-#define IREE_COMPILER_TRANSLATION_SPIRV_SPIRVLOWERING_H
+#ifndef IREE_COMPILER_TRANSLATION_SPIRV_XLATOSPIRV_SPIRVLOWERING_H
+#define IREE_COMPILER_TRANSLATION_SPIRV_XLATOSPIRV_SPIRVLOWERING_H
-#include "iree/compiler/Translation/SPIRV/IREECodegenUtils.h"
-#include "iree/compiler/Translation/SPIRV/IndexComputationAttribute.h"
-#include "iree/compiler/Translation/SPIRV/TensorIndexToScalarValueMap.h"
+#include "iree/compiler/Translation/SPIRV/IndexComputation/IndexComputationAttribute.h"
+#include "iree/compiler/Translation/SPIRV/XLAToSPIRV/TensorIndexToScalarValueMap.h"
+#include "iree/compiler/Utils/IREECodegenUtils.h"
#include "mlir/Dialect/SPIRV/SPIRVDialect.h"
#include "mlir/Dialect/SPIRV/SPIRVOps.h"
#include "mlir/Dialect/StandardOps/Ops.h"
@@ -223,8 +223,8 @@
/// location of a spv.globalVariable.
Value genPointerOffset(OpBuilder &builder, Location loc,
TensorIndexToScalarValueMap &valueCache,
- AffineMap indexMap, ArrayRef<int64_t> shape,
- Value buffer);
+ const AffineMap &indexMap, ArrayRef<int64_t> shape,
+ const Value &buffer);
namespace detail {
/// Implementation class for generating SPIR-V kernel.
@@ -379,4 +379,4 @@
} // namespace iree_compiler
} // namespace mlir
-#endif // IREE_COMPILER_TRANSLATION_SPIRV_SPIRVLOWERING_H
+#endif // IREE_COMPILER_TRANSLATION_SPIRV_XLATOSPIRV_SPIRVLOWERING_H
diff --git a/iree/compiler/Translation/SPIRV/TensorIndexToScalarValueMap.h b/iree/compiler/Translation/SPIRV/XLAToSPIRV/TensorIndexToScalarValueMap.h
similarity index 92%
rename from iree/compiler/Translation/SPIRV/TensorIndexToScalarValueMap.h
rename to iree/compiler/Translation/SPIRV/XLAToSPIRV/TensorIndexToScalarValueMap.h
index 491afca..eb10452 100644
--- a/iree/compiler/Translation/SPIRV/TensorIndexToScalarValueMap.h
+++ b/iree/compiler/Translation/SPIRV/XLAToSPIRV/TensorIndexToScalarValueMap.h
@@ -18,8 +18,8 @@
// SPIR-V lowering.
//
//===----------------------------------------------------------------------===//
-#ifndef IREE_COMPILER_TRANSLATION_SPIRV_TENSORINDEXTOSCALARVALUEMAP_H
-#define IREE_COMPILER_TRANSLATION_SPIRV_TENSORINDEXTOSCALARVALUEMAP_H
+#ifndef IREE_COMPILER_TRANSLATION_SPIRV_XLATOSPIRV_TENSORINDEXTOSCALAR_H
+#define IREE_COMPILER_TRANSLATION_SPIRV_XLATOSPIRV_TENSORINDEXTOSCALAR_H
#include "mlir/Dialect/AffineOps/AffineOps.h"
#include "mlir/Dialect/SPIRV/SPIRVOps.h"
@@ -54,7 +54,7 @@
}
Value getAccessIndicesForIndexMap(OpBuilder &builder, Location loc,
- AffineMap indexMap,
+ const AffineMap &indexMap,
ArrayRef<int64_t> shape = {1}) {
assert(indexMap.getNumSymbols() <= symbolPosToValue.size() ||
(symbolPosToValue.empty() && indexMap.getNumSymbols() == 0));
@@ -109,7 +109,9 @@
/// Records the `value` to use for an AffineDimExpr while generating code for
/// AffineExpr trees.
- void setDimValue(unsigned dim, Value value) { threadDimToValue[dim] = value; }
+ void setDimValue(unsigned dim, const Value &value) {
+ threadDimToValue[dim] = value;
+ }
/// Records the `value` to use for an AffineSymbolExpr while generating code
/// for AffineExpr trees.
@@ -134,4 +136,4 @@
} // namespace iree_compiler
} // namespace mlir
-#endif // IREE_COMPILER_TRANSLATION_SPIRV_TENSORINDEXTOSCALARVALUEMAP_H
+#endif // IREE_COMPILER_TRANSLATION_SPIRV_XLATOSPIRV_TENSORINDEXTOSCALAR_H
diff --git a/iree/compiler/Translation/SPIRV/XLAToSPIRV.cpp b/iree/compiler/Translation/SPIRV/XLAToSPIRV/XLAToSPIRV.cpp
similarity index 99%
rename from iree/compiler/Translation/SPIRV/XLAToSPIRV.cpp
rename to iree/compiler/Translation/SPIRV/XLAToSPIRV/XLAToSPIRV.cpp
index 2bc5208..54402a4 100644
--- a/iree/compiler/Translation/SPIRV/XLAToSPIRV.cpp
+++ b/iree/compiler/Translation/SPIRV/XLAToSPIRV/XLAToSPIRV.cpp
@@ -18,7 +18,7 @@
// Dispatch functions
//
//===----------------------------------------------------------------------===//
-#include "iree/compiler/Translation/SPIRV/XLAToSPIRV.h"
+#include "iree/compiler/Translation/SPIRV/XLAToSPIRV/XLAToSPIRV.h"
#include "mlir/Dialect/SPIRV/SPIRVOps.h"
#include "mlir/IR/StandardTypes.h"
diff --git a/iree/compiler/Translation/SPIRV/XLAToSPIRV.h b/iree/compiler/Translation/SPIRV/XLAToSPIRV/XLAToSPIRV.h
similarity index 91%
rename from iree/compiler/Translation/SPIRV/XLAToSPIRV.h
rename to iree/compiler/Translation/SPIRV/XLAToSPIRV/XLAToSPIRV.h
index ab175af..472a329 100644
--- a/iree/compiler/Translation/SPIRV/XLAToSPIRV.h
+++ b/iree/compiler/Translation/SPIRV/XLAToSPIRV/XLAToSPIRV.h
@@ -17,10 +17,10 @@
// SPIR-V Code-generation for xla_hlo operations within IREE Dispatch functions
//
//===----------------------------------------------------------------------===//
-#ifndef IREE_COMPILER_TRANSLATION_SPIRV_XLATOSPIRV_H
-#define IREE_COMPILER_TRANSLATION_SPIRV_XLATOSPIRV_H
+#ifndef IREE_COMPILER_TRANSLATION_SPIRV_XLATOSPIRV_XLATOSPIRV_H
+#define IREE_COMPILER_TRANSLATION_SPIRV_XLATOSPIRV_XLATOSPIRV_H
-#include "iree/compiler/Translation/SPIRV/SPIRVLowering.h"
+#include "iree/compiler/Translation/SPIRV/XLAToSPIRV/SPIRVLowering.h"
#include "tensorflow/compiler/mlir/xla/ir/hlo_ops.h"
namespace mlir {
@@ -76,4 +76,4 @@
} // namespace iree_compiler
} // namespace mlir
-#endif // IREE_COMPILER_TRANSLATION_SPIRV_XLATOSPIRV_H
+#endif // IREE_COMPILER_TRANSLATION_SPIRV_XLATOSPIRV_XLATOSPIRV_H
diff --git a/iree/compiler/Translation/SPIRV/test/BUILD b/iree/compiler/Translation/SPIRV/XLAToSPIRV/test/BUILD
similarity index 100%
rename from iree/compiler/Translation/SPIRV/test/BUILD
rename to iree/compiler/Translation/SPIRV/XLAToSPIRV/test/BUILD
diff --git a/iree/compiler/Translation/SPIRV/test/adjust_integer_width.mlir b/iree/compiler/Translation/SPIRV/XLAToSPIRV/test/adjust_integer_width.mlir
similarity index 100%
rename from iree/compiler/Translation/SPIRV/test/adjust_integer_width.mlir
rename to iree/compiler/Translation/SPIRV/XLAToSPIRV/test/adjust_integer_width.mlir
diff --git a/iree/compiler/Translation/SPIRV/test/arithmetic_ops.mlir b/iree/compiler/Translation/SPIRV/XLAToSPIRV/test/arithmetic_ops.mlir
similarity index 100%
rename from iree/compiler/Translation/SPIRV/test/arithmetic_ops.mlir
rename to iree/compiler/Translation/SPIRV/XLAToSPIRV/test/arithmetic_ops.mlir
diff --git a/iree/compiler/Translation/SPIRV/test/broadcast.mlir b/iree/compiler/Translation/SPIRV/XLAToSPIRV/test/broadcast.mlir
similarity index 100%
rename from iree/compiler/Translation/SPIRV/test/broadcast.mlir
rename to iree/compiler/Translation/SPIRV/XLAToSPIRV/test/broadcast.mlir
diff --git a/iree/compiler/Translation/SPIRV/test/broadcast_in_dim.mlir b/iree/compiler/Translation/SPIRV/XLAToSPIRV/test/broadcast_in_dim.mlir
similarity index 100%
rename from iree/compiler/Translation/SPIRV/test/broadcast_in_dim.mlir
rename to iree/compiler/Translation/SPIRV/XLAToSPIRV/test/broadcast_in_dim.mlir
diff --git a/iree/compiler/Translation/SPIRV/test/concatenate.mlir b/iree/compiler/Translation/SPIRV/XLAToSPIRV/test/concatenate.mlir
similarity index 100%
rename from iree/compiler/Translation/SPIRV/test/concatenate.mlir
rename to iree/compiler/Translation/SPIRV/XLAToSPIRV/test/concatenate.mlir
diff --git a/iree/compiler/Translation/SPIRV/test/constant.mlir b/iree/compiler/Translation/SPIRV/XLAToSPIRV/test/constant.mlir
similarity index 100%
rename from iree/compiler/Translation/SPIRV/test/constant.mlir
rename to iree/compiler/Translation/SPIRV/XLAToSPIRV/test/constant.mlir
diff --git a/iree/compiler/Translation/SPIRV/test/convert.mlir b/iree/compiler/Translation/SPIRV/XLAToSPIRV/test/convert.mlir
similarity index 100%
rename from iree/compiler/Translation/SPIRV/test/convert.mlir
rename to iree/compiler/Translation/SPIRV/XLAToSPIRV/test/convert.mlir
diff --git a/iree/compiler/Translation/SPIRV/test/copy.mlir b/iree/compiler/Translation/SPIRV/XLAToSPIRV/test/copy.mlir
similarity index 100%
rename from iree/compiler/Translation/SPIRV/test/copy.mlir
rename to iree/compiler/Translation/SPIRV/XLAToSPIRV/test/copy.mlir
diff --git a/iree/compiler/Translation/SPIRV/test/exp_test.mlir b/iree/compiler/Translation/SPIRV/XLAToSPIRV/test/exp_test.mlir
similarity index 100%
rename from iree/compiler/Translation/SPIRV/test/exp_test.mlir
rename to iree/compiler/Translation/SPIRV/XLAToSPIRV/test/exp_test.mlir
diff --git a/iree/compiler/Translation/SPIRV/test/extract_element.mlir b/iree/compiler/Translation/SPIRV/XLAToSPIRV/test/extract_element.mlir
similarity index 100%
rename from iree/compiler/Translation/SPIRV/test/extract_element.mlir
rename to iree/compiler/Translation/SPIRV/XLAToSPIRV/test/extract_element.mlir
diff --git a/iree/compiler/Translation/SPIRV/test/gather.mlir b/iree/compiler/Translation/SPIRV/XLAToSPIRV/test/gather.mlir
similarity index 100%
rename from iree/compiler/Translation/SPIRV/test/gather.mlir
rename to iree/compiler/Translation/SPIRV/XLAToSPIRV/test/gather.mlir
diff --git a/iree/compiler/Translation/SPIRV/test/max.mlir b/iree/compiler/Translation/SPIRV/XLAToSPIRV/test/max.mlir
similarity index 100%
rename from iree/compiler/Translation/SPIRV/test/max.mlir
rename to iree/compiler/Translation/SPIRV/XLAToSPIRV/test/max.mlir
diff --git a/iree/compiler/Translation/SPIRV/test/pad.mlir b/iree/compiler/Translation/SPIRV/XLAToSPIRV/test/pad.mlir
similarity index 100%
rename from iree/compiler/Translation/SPIRV/test/pad.mlir
rename to iree/compiler/Translation/SPIRV/XLAToSPIRV/test/pad.mlir
diff --git a/iree/compiler/Translation/SPIRV/test/reshape.mlir b/iree/compiler/Translation/SPIRV/XLAToSPIRV/test/reshape.mlir
similarity index 100%
rename from iree/compiler/Translation/SPIRV/test/reshape.mlir
rename to iree/compiler/Translation/SPIRV/XLAToSPIRV/test/reshape.mlir
diff --git a/iree/compiler/Translation/SPIRV/test/reshape_dropdims.mlir b/iree/compiler/Translation/SPIRV/XLAToSPIRV/test/reshape_dropdims.mlir
similarity index 100%
rename from iree/compiler/Translation/SPIRV/test/reshape_dropdims.mlir
rename to iree/compiler/Translation/SPIRV/XLAToSPIRV/test/reshape_dropdims.mlir
diff --git a/iree/compiler/Translation/SPIRV/test/reverse.mlir b/iree/compiler/Translation/SPIRV/XLAToSPIRV/test/reverse.mlir
similarity index 100%
rename from iree/compiler/Translation/SPIRV/test/reverse.mlir
rename to iree/compiler/Translation/SPIRV/XLAToSPIRV/test/reverse.mlir
diff --git a/iree/compiler/Translation/SPIRV/test/select.mlir b/iree/compiler/Translation/SPIRV/XLAToSPIRV/test/select.mlir
similarity index 100%
rename from iree/compiler/Translation/SPIRV/test/select.mlir
rename to iree/compiler/Translation/SPIRV/XLAToSPIRV/test/select.mlir
diff --git a/iree/compiler/Translation/SPIRV/test/slice.mlir b/iree/compiler/Translation/SPIRV/XLAToSPIRV/test/slice.mlir
similarity index 100%
rename from iree/compiler/Translation/SPIRV/test/slice.mlir
rename to iree/compiler/Translation/SPIRV/XLAToSPIRV/test/slice.mlir
diff --git a/iree/compiler/Translation/SPIRV/test/store_reduce.mlir b/iree/compiler/Translation/SPIRV/XLAToSPIRV/test/store_reduce.mlir
similarity index 100%
rename from iree/compiler/Translation/SPIRV/test/store_reduce.mlir
rename to iree/compiler/Translation/SPIRV/XLAToSPIRV/test/store_reduce.mlir
diff --git a/iree/compiler/Translation/SPIRV/test/transpose_add.mlir b/iree/compiler/Translation/SPIRV/XLAToSPIRV/test/transpose_add.mlir
similarity index 100%
rename from iree/compiler/Translation/SPIRV/test/transpose_add.mlir
rename to iree/compiler/Translation/SPIRV/XLAToSPIRV/test/transpose_add.mlir
diff --git a/iree/compiler/Translation/SPIRV/test/ReductionFnLowering/BUILD b/iree/compiler/Translation/SPIRV/test/ReductionFnLowering/BUILD
deleted file mode 100644
index 1cbffd1..0000000
--- a/iree/compiler/Translation/SPIRV/test/ReductionFnLowering/BUILD
+++ /dev/null
@@ -1,30 +0,0 @@
-# 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.
-
-# Tests for common transforms.
-
-load("//iree:build_defs.bzl", "iree_glob_lit_tests", "iree_setup_lit_package")
-
-package(
- default_visibility = ["//visibility:public"],
- licenses = ["notice"], # Apache 2.0
-)
-
-iree_setup_lit_package(
- data = [
- "//iree/tools:iree-opt",
- ],
-)
-
-iree_glob_lit_tests()
diff --git a/iree/compiler/Utils/BUILD b/iree/compiler/Utils/BUILD
index c456773..fd96564 100644
--- a/iree/compiler/Utils/BUILD
+++ b/iree/compiler/Utils/BUILD
@@ -24,18 +24,19 @@
srcs = [
"DispatchUtils.cpp",
"GraphUtils.cpp",
+ "IREECodegenUtils.cpp",
"TypeConversionUtils.cpp",
],
hdrs = [
"DispatchUtils.h",
"GraphUtils.h",
+ "IREECodegenUtils.h",
"TypeConversionUtils.h",
],
deps = [
"//iree/compiler/Dialect/IREE/IR",
"@llvm-project//llvm:support",
"@llvm-project//mlir:IR",
- "@llvm-project//mlir:Pass",
"@llvm-project//mlir:StandardOps",
"@llvm-project//mlir:Support",
"@llvm-project//mlir:TransformUtils",
diff --git a/iree/compiler/Utils/CMakeLists.txt b/iree/compiler/Utils/CMakeLists.txt
index eb97871..a2a569d 100644
--- a/iree/compiler/Utils/CMakeLists.txt
+++ b/iree/compiler/Utils/CMakeLists.txt
@@ -18,10 +18,12 @@
HDRS
"DispatchUtils.h"
"GraphUtils.h"
+ "IREECodegenUtils.h"
"TypeConversionUtils.h"
SRCS
"DispatchUtils.cpp"
"GraphUtils.cpp"
+ "IREECodegenUtils.cpp"
"TypeConversionUtils.cpp"
DEPS
iree::compiler::Dialect::IREE::IR
diff --git a/iree/compiler/Translation/SPIRV/IREECodegenUtils.h b/iree/compiler/Utils/IREECodegenUtils.cpp
similarity index 73%
rename from iree/compiler/Translation/SPIRV/IREECodegenUtils.h
rename to iree/compiler/Utils/IREECodegenUtils.cpp
index 60c31c9..5d9156c 100644
--- a/iree/compiler/Translation/SPIRV/IREECodegenUtils.h
+++ b/iree/compiler/Utils/IREECodegenUtils.cpp
@@ -11,25 +11,14 @@
// 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.
-
-//===- IREECodegenUtils.h --------------------------------------*- C++//-*-===//
-//
-// Utility functions used during code-generation (for SPIR-V)
-//
-//===----------------------------------------------------------------------===//
-#ifndef IREE_COMPILER_TRANSLATION_SPIRV_IREECODEGENUTILS_H
-#define IREE_COMPILER_TRANSLATION_SPIRV_IREECODEGENUTILS_H
-
-#include "iree/compiler/Dialect/IREE/IR/IREEOps.h"
-#include "mlir/IR/Function.h"
-#include "mlir/Support/LogicalResult.h"
+#include "iree/compiler/Utils/IREECodegenUtils.h"
namespace mlir {
namespace iree_compiler {
/// Gets the launch size associated with the dispatch function.
-inline LogicalResult getLaunchSize(FuncOp funcOp,
- SmallVectorImpl<int64_t> &launchSize) {
+LogicalResult getLaunchSize(FuncOp funcOp,
+ SmallVectorImpl<int64_t> &launchSize) {
if (!funcOp.getAttr("iree.executable.export")) {
return funcOp.emitError(
"expected operation to be in dispatch function to get launch size");
@@ -58,8 +47,8 @@
}
/// Gets the workgroup size.
-inline LogicalResult getWorkGroupSize(FuncOp funcOp,
- SmallVectorImpl<int32_t> &workGroupSize) {
+LogicalResult getWorkGroupSize(FuncOp funcOp,
+ SmallVectorImpl<int32_t> &workGroupSize) {
if (!funcOp.getAttr("iree.executable.export")) {
return funcOp.emitError(
"expected operation to be in dispatch function to get launch size");
@@ -80,5 +69,3 @@
} // namespace iree_compiler
} // namespace mlir
-
-#endif // IREE_COMPILER_TRANSLATION_SPIRV_IREECODEGENUTILS_H
diff --git a/iree/compiler/Utils/IREECodegenUtils.h b/iree/compiler/Utils/IREECodegenUtils.h
new file mode 100644
index 0000000..9b5f4a7
--- /dev/null
+++ b/iree/compiler/Utils/IREECodegenUtils.h
@@ -0,0 +1,41 @@
+// 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.
+
+//===- IREECodegenUtils.h --------------------------------------*- C++//-*-===//
+//
+// Utility functions used during code-generation (for SPIR-V)
+//
+//===----------------------------------------------------------------------===//
+#ifndef IREE_COMPILER_UTILS_IREECODEGENUTILS_H
+#define IREE_COMPILER_UTILS_IREECODEGENUTILS_H
+
+#include "iree/compiler/Dialect/IREE/IR/IREEOps.h"
+#include "mlir/IR/Function.h"
+#include "mlir/Support/LogicalResult.h"
+
+namespace mlir {
+namespace iree_compiler {
+
+/// Gets the launch size associated with the dispatch function.
+LogicalResult getLaunchSize(FuncOp funcOp,
+ SmallVectorImpl<int64_t> &launchSize);
+
+/// Gets the workgroup size.
+LogicalResult getWorkGroupSize(FuncOp funcOp,
+ SmallVectorImpl<int32_t> &workGroupSize);
+
+} // namespace iree_compiler
+} // namespace mlir
+
+#endif // IREE_COMPILER_UTILS_IREECODEGENUTILS_H
diff --git a/iree/tools/BUILD b/iree/tools/BUILD
index 7ac38b1..cec8d96 100644
--- a/iree/tools/BUILD
+++ b/iree/tools/BUILD
@@ -62,11 +62,12 @@
"//iree/compiler/Dialect/VM/Transforms",
"//iree/compiler/Translation/Interpreter/Transforms",
"//iree/compiler/Translation:IREEVM",
- "//iree/compiler/Translation/SPIRV",
+ "//iree/compiler/Translation/SPIRV/XLAToSPIRV",
"@llvm-project//llvm:support",
"@llvm-project//mlir:AffineDialectRegistration",
"@llvm-project//mlir:MlirOptLib",
"@llvm-project//mlir:StandardDialectRegistration",
+ "@llvm-project//mlir:SPIRVDialectRegistration",
"@org_tensorflow//tensorflow/compiler/mlir/xla:hlo",
"@org_tensorflow//tensorflow/compiler/mlir/xla:xla_dialect_registration",
"@org_tensorflow//tensorflow/compiler/mlir/xla:xla_legalize_control_flow",
@@ -107,6 +108,7 @@
"@llvm-project//mlir:IR",
"@llvm-project//mlir:Parser",
"@llvm-project//mlir:Pass",
+ "@llvm-project//mlir:SPIRVDialectRegistration",
"@llvm-project//mlir:Support",
"//iree/base:init",
"//iree/base:status",
@@ -138,12 +140,13 @@
deps = [
"//iree/compiler/Dialect/VM/Target/Bytecode",
"//iree/compiler/Translation:IREEVM",
- "//iree/compiler/Translation/SPIRV",
+ "//iree/compiler/Translation/SPIRV/XLAToSPIRV",
"@llvm-project//llvm:support",
"@llvm-project//mlir:AffineDialectRegistration",
"@llvm-project//mlir:IR",
"@llvm-project//mlir:Pass",
"@llvm-project//mlir:StandardDialectRegistration",
+ "@llvm-project//mlir:SPIRVDialectRegistration",
"@llvm-project//mlir:Support",
"@llvm-project//mlir:TranslateClParser",
"@llvm-project//mlir:Translation",
diff --git a/iree/tools/CMakeLists.txt b/iree/tools/CMakeLists.txt
index 2a6c247..6bb4d24 100644
--- a/iree/tools/CMakeLists.txt
+++ b/iree/tools/CMakeLists.txt
@@ -89,7 +89,7 @@
# iree::base::init
# iree::base::status
# iree::compiler::Translation::Interpreter
-# iree::compiler::Translation::SPIRV
+# iree::compiler::Translation::SPIRV::XLAToSPIRV
# iree::compiler::Translation::IREEVM
# iree::hal::buffer_view_string_util
# iree::hal::driver_registry
@@ -109,7 +109,7 @@
DEPS
${_ALWAYSLINK_LIBS}
iree::compiler::Dialect::VM::Target::Bytecode
- iree::compiler::Translation::SPIRV
+ iree::compiler::Translation::SPIRV::XLAToSPIRV
MLIRTranslateClParser
)
add_executable(iree-translate ALIAS iree_tools_iree-translate)