Rollup of fixes for MSVC and CMake build.
With these changes iree-translate can build with Clang and MSVC through CMake!
There's still some cleanup required for ALWAYSLINK in the CMake rules however this is enough to at least verify we can build and start setting up CI.
Progress on issue #6.
PiperOrigin-RevId: 272693901
diff --git a/.clang-format b/.clang-format
index d37983a..2c73cd8 100644
--- a/.clang-format
+++ b/.clang-format
@@ -1,3 +1,4 @@
# All of IREE is in the Google style except for iree/compiler/, which follows
-# the LLVM style (along with MLIR).
+# mostly LLVM style (for naming/etc) but the Google formatting (because internal
+# tooling has... issues).
BasedOnStyle: Google
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f37b16d..41f5af9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -29,6 +29,7 @@
option(IREE_BUILD_COMPILER "Builds the IREE compiler." OFF)
option(IREE_BUILD_TESTS "Builds IREE unit tests." ON)
+option(IREE_BUILD_SAMPLES "Builds IREE sample projects." ON)
option(IREE_BUILD_DEBUGGER "Builds the IREE debugger app." OFF)
#-------------------------------------------------------------------------------
@@ -42,6 +43,7 @@
include(iree_macros)
include(iree_copts)
+include(iree_cc_binary)
include(iree_cc_library)
include(iree_cc_test)
include(iree_tablegen_library)
@@ -60,7 +62,6 @@
include(flatbuffer_cc_library)
add_subdirectory(build_tools/third_party/ruy EXCLUDE_FROM_ALL)
-add_subdirectory(build_tools/third_party/tensorflow EXCLUDE_FROM_ALL)
add_subdirectory(build_tools/third_party/vulkan_memory_allocator EXCLUDE_FROM_ALL)
add_subdirectory(third_party/abseil-cpp EXCLUDE_FROM_ALL)
@@ -70,6 +71,8 @@
if(${IREE_BUILD_COMPILER})
add_subdirectory(third_party/llvm-project/llvm EXCLUDE_FROM_ALL)
+ include(external_tablegen_library)
+ add_subdirectory(build_tools/third_party/tensorflow/tensorflow/compiler/mlir/xla EXCLUDE_FROM_ALL)
endif()
#-------------------------------------------------------------------------------
@@ -78,11 +81,15 @@
add_subdirectory(iree/base)
add_subdirectory(iree/hal)
-add_subdirectory(iree/samples)
add_subdirectory(iree/schemas)
-add_subdirectory(iree/tools)
add_subdirectory(iree/vm)
if(${IREE_BUILD_COMPILER})
add_subdirectory(iree/compiler)
endif()
+
+add_subdirectory(iree/tools)
+
+if(${IREE_BUILD_SAMPLES})
+ add_subdirectory(iree/samples)
+endif()
diff --git a/build_tools/cmake/external_cc_library.cmake b/build_tools/cmake/external_cc_library.cmake
index 3d60bc2..74adf07 100644
--- a/build_tools/cmake/external_cc_library.cmake
+++ b/build_tools/cmake/external_cc_library.cmake
@@ -31,14 +31,16 @@
# DEFINES: List of public defines
# INCLUDES: Include directories to add to dependencies
# LINKOPTS: List of link options
-# PUBLIC: Add this so that this library will be exported under iree::
-# Also in IDE, target will appear in IREE folder while non PUBLIC will be in IREE/internal.
-# TESTONLY: When added, this target will only be built if user passes -DIREE_BUILD_TESTS=ON to CMake.
+# PUBLIC: Add this so that this library will be exported under ${PACKAGE}::
+# Also in IDE, target will appear in ${PACKAGE} folder while non PUBLIC will be
+# in ${PACKAGE}/internal.
+# TESTONLY: When added, this target will only be built if user passes
+# -DIREE_BUILD_TESTS=ON to CMake.
#
# Note:
-# By default, external_cc_library will always create a library named ${PACKAGE}_${NAME},
-# and alias target ${PACKAGE}::${NAME}. The ${PACKAGE}:: form should always be used.
-# This is to reduce namespace pollution.
+# By default, external_cc_library will always create a library named
+# ${PACKAGE}_${NAME}, and alias target ${PACKAGE}::${NAME}. The ${PACKAGE}::
+# form should always be used. This is to reduce namespace pollution.
#
# external_cc_library(
# PACKAGE
@@ -76,71 +78,71 @@
#
# TODO: Implement "ALWAYSLINK"
function(external_cc_library)
- cmake_parse_arguments(EXTERNAL_CC_LIB
+ cmake_parse_arguments(_RULE
"PUBLIC;TESTONLY"
"PACKAGE;NAME;ROOT"
"HDRS;SRCS;COPTS;DEFINES;LINKOPTS;DEPS;INCLUDES"
${ARGN}
)
- if(NOT EXTERNAL_CC_LIB_TESTONLY OR IREE_BUILD_TESTS)
+ if(NOT _RULE_TESTONLY OR IREE_BUILD_TESTS)
# Prefix the library with the package name.
- string(REPLACE "::" "_" _PACKAGE_NAME ${EXTERNAL_CC_LIB_PACKAGE})
- set(_NAME "${_PACKAGE_NAME}_${EXTERNAL_CC_LIB_NAME}")
+ string(REPLACE "::" "_" _PACKAGE_NAME ${_RULE_PACKAGE})
+ set(_NAME "${_PACKAGE_NAME}_${_RULE_NAME}")
# Prefix paths with the root.
- list(TRANSFORM EXTERNAL_CC_LIB_HDRS PREPEND ${EXTERNAL_CC_LIB_ROOT})
- list(TRANSFORM EXTERNAL_CC_LIB_SRCS PREPEND ${EXTERNAL_CC_LIB_ROOT})
+ list(TRANSFORM _RULE_HDRS PREPEND ${_RULE_ROOT})
+ list(TRANSFORM _RULE_SRCS PREPEND ${_RULE_ROOT})
# Check if this is a header-only library.
# Note that as of February 2019, many popular OS's (for example, Ubuntu
# 16.04 LTS) only come with cmake 3.5 by default. For this reason, we can't
# use list(FILTER...)
- set(_CC_SRCS "${EXTERNAL_CC_LIB_SRCS}")
+ set(_CC_SRCS "${_RULE_SRCS}")
foreach(src_file IN LISTS _CC_SRCS)
if(${src_file} MATCHES ".*\\.(h|inc)")
list(REMOVE_ITEM _CC_SRCS "${src_file}")
endif()
endforeach()
if("${_CC_SRCS}" STREQUAL "")
- set(EXTERNAL_CC_LIB_IS_INTERFACE 1)
+ set(_RULE_IS_INTERFACE 1)
else()
- set(EXTERNAL_CC_LIB_IS_INTERFACE 0)
+ set(_RULE_IS_INTERFACE 0)
endif()
- if(NOT EXTERNAL_CC_LIB_IS_INTERFACE)
+ if(NOT _RULE_IS_INTERFACE)
add_library(${_NAME} STATIC "")
target_sources(${_NAME}
PRIVATE
- ${EXTERNAL_CC_LIB_SRCS}
- ${EXTERNAL_CC_LIB_HDRS}
+ ${_RULE_SRCS}
+ ${_RULE_HDRS}
)
target_include_directories(${_NAME}
PUBLIC
"$<BUILD_INTERFACE:${IREE_COMMON_INCLUDE_DIRS}>"
- "$<BUILD_INTERFACE:${EXTERNAL_CC_LIB_INCLUDES}>"
+ "$<BUILD_INTERFACE:${_RULE_INCLUDES}>"
)
target_compile_options(${_NAME}
PRIVATE
- ${EXTERNAL_CC_LIB_COPTS}
+ ${_RULE_COPTS}
${IREE_DEFAULT_COPTS}
)
target_link_libraries(${_NAME}
PUBLIC
- ${EXTERNAL_CC_LIB_DEPS}
+ ${_RULE_DEPS}
PRIVATE
- ${EXTERNAL_CC_LIB_LINKOPTS}
+ ${_RULE_LINKOPTS}
${IREE_DEFAULT_LINKOPTS}
)
target_compile_definitions(${_NAME}
PUBLIC
- ${EXTERNAL_CC_LIB_DEFINES}
+ ${_RULE_DEFINES}
)
# Add all external targets to a a folder in the IDE for organization.
- if(EXTERNAL_CC_LIB_PUBLIC)
+ if(_RULE_PUBLIC)
set_property(TARGET ${_NAME} PROPERTY FOLDER third_party)
- elseif(EXTERNAL_CC_LIB_TESTONLY)
+ elseif(_RULE_TESTONLY)
set_property(TARGET ${_NAME} PROPERTY FOLDER third_party/test)
else()
set_property(TARGET ${_NAME} PROPERTY FOLDER third_party/internal)
@@ -155,28 +157,28 @@
target_include_directories(${_NAME}
INTERFACE
"$<BUILD_INTERFACE:${IREE_COMMON_INCLUDE_DIRS}>"
- "$<BUILD_INTERFACE:${EXTERNAL_CC_LIB_INCLUDES}>"
+ "$<BUILD_INTERFACE:${_RULE_INCLUDES}>"
)
target_compile_options(${_NAME}
INTERFACE
- ${EXTERNAL_CC_LIB_COPTS}
+ ${_RULE_COPTS}
${IREE_DEFAULT_COPTS}
)
target_link_libraries(${_NAME}
INTERFACE
- ${EXTERNAL_CC_LIB_DEPS}
- ${EXTERNAL_CC_LIB_LINKOPTS}
+ ${_RULE_DEPS}
+ ${_RULE_LINKOPTS}
${IREE_DEFAULT_LINKOPTS}
)
target_compile_definitions(${_NAME}
INTERFACE
- ${EXTERNAL_CC_LIB_DEFINES}
+ ${_RULE_DEFINES}
)
endif()
- add_library(${EXTERNAL_CC_LIB_PACKAGE}::${EXTERNAL_CC_LIB_NAME} ALIAS ${_NAME})
- if(${EXTERNAL_CC_LIB_PACKAGE} STREQUAL ${EXTERNAL_CC_LIB_NAME})
- add_library(${EXTERNAL_CC_LIB_PACKAGE} ALIAS ${_NAME})
+ add_library(${_RULE_PACKAGE}::${_RULE_NAME} ALIAS ${_NAME})
+ if(${_RULE_PACKAGE} STREQUAL ${_RULE_NAME})
+ add_library(${_RULE_PACKAGE} ALIAS ${_NAME})
endif()
endif()
endfunction()
diff --git a/build_tools/cmake/external_tablegen_library.cmake b/build_tools/cmake/external_tablegen_library.cmake
new file mode 100644
index 0000000..72f682a
--- /dev/null
+++ b/build_tools/cmake/external_tablegen_library.cmake
@@ -0,0 +1,58 @@
+# 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(CMakeParseArguments)
+
+# external_tablegen_library()
+#
+# Runs ${TBLGEN} to produce some artifacts.
+function(external_tablegen_library)
+ cmake_parse_arguments(
+ _RULE
+ "TESTONLY"
+ "PACKAGE;NAME;ROOT;TBLGEN"
+ "SRCS;OUTS"
+ ${ARGN}
+ )
+
+ if(NOT _RULE_TESTONLY OR IREE_BUILD_TESTS)
+ # Prefix the library with the package name.
+ string(REPLACE "::" "_" _PACKAGE_NAME ${_RULE_PACKAGE})
+ set(_NAME "${_PACKAGE_NAME}_${_RULE_NAME}")
+
+ # Prefix source paths with the root.
+ list(TRANSFORM _RULE_SRCS PREPEND ${_RULE_ROOT})
+
+ set(LLVM_TARGET_DEFINITIONS ${_RULE_SRCS})
+ set(_INCLUDE_DIRS ${IREE_COMMON_INCLUDE_DIRS})
+ list(APPEND _INCLUDE_DIRS ${_RULE_ROOT})
+ list(TRANSFORM _INCLUDE_DIRS PREPEND "-I")
+ set(_OUTPUTS)
+ while(_RULE_OUTS)
+ list(GET _RULE_OUTS 0 _COMMAND)
+ list(REMOVE_AT _RULE_OUTS 0)
+ list(GET _RULE_OUTS 0 _FILE)
+ list(REMOVE_AT _RULE_OUTS 0)
+ tablegen(${_RULE_TBLGEN} ${_FILE} ${_COMMAND} ${_INCLUDE_DIRS})
+ list(APPEND _OUTPUTS ${CMAKE_CURRENT_BINARY_DIR}/${_FILE})
+ endwhile()
+ add_custom_target(${_NAME}_target DEPENDS ${_OUTPUTS})
+ set_target_properties(${_NAME}_target PROPERTIES FOLDER "Tablegenning")
+
+ add_library(${_NAME} INTERFACE)
+ add_dependencies(${_NAME} ${_NAME}_target)
+
+ add_library(${_RULE_PACKAGE}::${_RULE_NAME} ALIAS ${_NAME})
+ endif()
+endfunction()
diff --git a/build_tools/cmake/flatbuffer_cc_library.cmake b/build_tools/cmake/flatbuffer_cc_library.cmake
index 2d4f20a..ea39045 100644
--- a/build_tools/cmake/flatbuffer_cc_library.cmake
+++ b/build_tools/cmake/flatbuffer_cc_library.cmake
@@ -59,17 +59,17 @@
# iree::schemas::other_schemas
# )
function(flatbuffer_cc_library)
- cmake_parse_arguments(FLATBUFFER_CC_LIB
+ cmake_parse_arguments(_RULE
"PUBLIC;TESTONLY"
"NAME"
"SRCS;COPTS;DEFINES;LINKOPTS;DEPS"
${ARGN}
)
- if(NOT FLATBUFFER_CC_LIB_TESTONLY OR IREE_BUILD_TESTS)
+ if(NOT _RULE_TESTONLY OR IREE_BUILD_TESTS)
# Prefix the library with the package name, so we get: iree_package_name
iree_package_name(_PACKAGE_NAME)
- set(_NAME "${_PACKAGE_NAME}_${FLATBUFFER_CC_LIB_NAME}")
+ set(_NAME "${_PACKAGE_NAME}_${_RULE_NAME}")
set(FLATBUFFERS_FLATC_SCHEMA_EXTRA_ARGS
# Preserve root-relative include paths in generated code.
@@ -83,10 +83,10 @@
"--gen-object-api"
)
build_flatbuffers(
- "${FLATBUFFER_CC_LIB_SRCS}"
+ "${_RULE_SRCS}"
"${IREE_ROOT_DIR}"
"${_NAME}_gen" # custom_target_name
- "${FLATBUFFER_CC_LIB_DEPS}" # additional_dependencies
+ "${_RULE_DEPS}" # additional_dependencies
"${CMAKE_CURRENT_BINARY_DIR}" # generated_include_dir
"${CMAKE_CURRENT_BINARY_DIR}" # binary_schemas_dir
"" # copy_text_schemas_dir
@@ -102,18 +102,18 @@
target_link_libraries(${_NAME}
INTERFACE
flatbuffers
- ${FLATBUFFER_CC_LIB_LINKOPTS}
+ ${_RULE_LINKOPTS}
${IREE_DEFAULT_LINKOPTS}
)
target_compile_definitions(${_NAME}
INTERFACE
- ${FLATBUFFER_CC_LIB_DEFINES}
+ ${_RULE_DEFINES}
)
# Alias the iree_package_name library to iree::package::name.
# This lets us more clearly map to Bazel and makes it possible to
# disambiguate the underscores in paths vs. the separators.
iree_package_ns(_PACKAGE_NS)
- add_library(${_PACKAGE_NS}::${FLATBUFFER_CC_LIB_NAME} ALIAS ${_NAME})
+ add_library(${_PACKAGE_NS}::${_RULE_NAME} ALIAS ${_NAME})
endif()
endfunction()
diff --git a/build_tools/cmake/iree_cc_binary.cmake b/build_tools/cmake/iree_cc_binary.cmake
new file mode 100644
index 0000000..4cf95a8
--- /dev/null
+++ b/build_tools/cmake/iree_cc_binary.cmake
@@ -0,0 +1,110 @@
+# 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(CMakeParseArguments)
+
+# iree_cc_binary()
+#
+# CMake function to imitate Bazel's cc_binary rule.
+#
+# Parameters:
+# NAME: name of target (see Usage below)
+# SRCS: List of source files for the binary
+# DEPS: List of other libraries to be linked in to the binary targets
+# COPTS: List of private compile options
+# DEFINES: List of public defines
+# LINKOPTS: List of link options
+#
+# Note:
+# By default, iree_cc_binary will always create a binary named iree_${NAME}.
+#
+# Usage:
+# iree_cc_library(
+# NAME
+# awesome
+# HDRS
+# "a.h"
+# SRCS
+# "a.cc"
+# PUBLIC
+# )
+#
+# iree_cc_binary(
+# NAME
+# awesome_tool
+# OUT
+# awesome-tool
+# SRCS
+# "awesome_tool_main.cc"
+# DEPS
+# iree::awesome
+# )
+function(iree_cc_binary)
+ cmake_parse_arguments(
+ _RULE
+ ""
+ "NAME;OUT"
+ "SRCS;COPTS;DEFINES;LINKOPTS;DEPS"
+ ${ARGN}
+ )
+
+ # Prefix the library with the package name, so we get: iree_package_name
+ iree_package_name(_PACKAGE_NAME)
+ set(_NAME "${_PACKAGE_NAME}_${_RULE_NAME}")
+
+ add_executable(${_NAME} "")
+ if(_RULE_SRCS)
+ target_sources(${_NAME}
+ PRIVATE
+ ${_RULE_SRCS}
+ )
+ else()
+ set(_DUMMY_SRC "${CMAKE_CURRENT_BINARY_DIR}/${_NAME}_dummy.cc")
+ file(WRITE ${_DUMMY_SRC} "")
+ target_sources(${_NAME}
+ PRIVATE
+ ${_DUMMY_SRC}
+ )
+ endif()
+ if(_RULE_OUT)
+ set_target_properties(${_NAME} PROPERTIES OUTPUT_NAME "${_RULE_OUT}")
+ endif()
+ target_include_directories(${_NAME}
+ PUBLIC
+ ${IREE_COMMON_INCLUDE_DIRS}
+ PRIVATE
+ ${GTEST_INCLUDE_DIRS}
+ )
+ target_compile_definitions(${_NAME}
+ PUBLIC
+ ${_RULE_DEFINES}
+ )
+ target_compile_options(${_NAME}
+ PRIVATE
+ ${_RULE_COPTS}
+ )
+ target_link_libraries(${_NAME}
+ PUBLIC
+ ${_RULE_DEPS}
+ PRIVATE
+ ${_RULE_LINKOPTS}
+ )
+
+ # Add all IREE targets to a a folder in the IDE for organization.
+ set_property(TARGET ${_NAME} PROPERTY FOLDER ${IREE_IDE_FOLDER}/binaries)
+
+ set_property(TARGET ${_NAME} PROPERTY CXX_STANDARD ${IREE_CXX_STANDARD})
+ set_property(TARGET ${_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
+
+endfunction()
diff --git a/build_tools/cmake/iree_cc_library.cmake b/build_tools/cmake/iree_cc_library.cmake
index 96482bb..bb8c74e 100644
--- a/build_tools/cmake/iree_cc_library.cmake
+++ b/build_tools/cmake/iree_cc_library.cmake
@@ -26,6 +26,7 @@
# COPTS: List of private compile options
# DEFINES: List of public defines
# LINKOPTS: List of link options
+# ALWAYSLINK: Always link the library into any binary with a transitive dep.
# PUBLIC: Add this so that this library will be exported under iree::
# Also in IDE, target will appear in IREE folder while non PUBLIC will be in IREE/internal.
# TESTONLY: When added, this target will only be built if user passes -DIREE_BUILD_TESTS=ON to CMake.
@@ -60,44 +61,42 @@
# DEPS
# iree::package::fantastic_lib
# )
-#
-# TODO: Implement "ALWAYSLINK"
function(iree_cc_library)
cmake_parse_arguments(
- IREE_CC_LIB
- "PUBLIC;TESTONLY"
+ _RULE
+ "PUBLIC;ALWAYSLINK;TESTONLY"
"NAME"
"HDRS;SRCS;COPTS;DEFINES;LINKOPTS;DEPS"
${ARGN}
)
- if(NOT IREE_CC_LIB_TESTONLY OR IREE_BUILD_TESTS)
- # Prefix the library with the package name, so we get: iree_package_name
+ if(NOT _RULE_TESTONLY OR IREE_BUILD_TESTS)
+ # Prefix the library with the package name, so we get: iree_package_name.
iree_package_name(_PACKAGE_NAME)
- set(_NAME "${_PACKAGE_NAME}_${IREE_CC_LIB_NAME}")
+ set(_NAME "${_PACKAGE_NAME}_${_RULE_NAME}")
# Check if this is a header-only library.
# Note that as of February 2019, many popular OS's (for example, Ubuntu
# 16.04 LTS) only come with cmake 3.5 by default. For this reason, we can't
# use list(FILTER...)
- set(IREE_CC_SRCS "${IREE_CC_LIB_SRCS}")
- foreach(src_file IN LISTS IREE_CC_SRCS)
+ set(_CC_SRCS "${_RULE_SRCS}")
+ foreach(src_file IN LISTS _CC_SRCS)
if(${src_file} MATCHES ".*\\.(h|inc)")
- list(REMOVE_ITEM IREE_CC_SRCS "${src_file}")
+ list(REMOVE_ITEM _CC_SRCS "${src_file}")
endif()
endforeach()
- if("${IREE_CC_SRCS}" STREQUAL "")
- set(IREE_CC_LIB_IS_INTERFACE 1)
+ if("${_CC_SRCS}" STREQUAL "")
+ set(_RULE_IS_INTERFACE 1)
else()
- set(IREE_CC_LIB_IS_INTERFACE 0)
+ set(_RULE_IS_INTERFACE 0)
endif()
- if(NOT IREE_CC_LIB_IS_INTERFACE)
+ if(NOT _RULE_IS_INTERFACE)
add_library(${_NAME} STATIC "")
target_sources(${_NAME}
PRIVATE
- ${IREE_CC_LIB_SRCS}
- ${IREE_CC_LIB_HDRS}
+ ${_RULE_SRCS}
+ ${_RULE_HDRS}
)
target_include_directories(${_NAME}
PUBLIC
@@ -105,35 +104,35 @@
)
target_compile_options(${_NAME}
PRIVATE
- ${IREE_CC_LIB_COPTS}
+ ${_RULE_COPTS}
${IREE_DEFAULT_COPTS}
)
target_link_libraries(${_NAME}
PUBLIC
- ${IREE_CC_LIB_DEPS}
+ ${_RULE_DEPS}
PRIVATE
- ${IREE_CC_LIB_LINKOPTS}
+ ${_RULE_LINKOPTS}
${IREE_DEFAULT_LINKOPTS}
)
target_compile_definitions(${_NAME}
PUBLIC
- ${IREE_CC_LIB_DEFINES}
+ ${_RULE_DEFINES}
)
# Add all IREE targets to a a folder in the IDE for organization.
- if(IREE_CC_LIB_PUBLIC)
+ if(_RULE_PUBLIC)
set_property(TARGET ${_NAME} PROPERTY FOLDER ${IREE_IDE_FOLDER})
- elseif(IREE_CC_LIB_TESTONLY)
+ elseif(_RULE_TESTONLY)
set_property(TARGET ${_NAME} PROPERTY FOLDER ${IREE_IDE_FOLDER}/test)
else()
set_property(TARGET ${_NAME} PROPERTY FOLDER ${IREE_IDE_FOLDER}/internal)
endif()
- # INTERFACE libraries can't have the CXX_STANDARD property set
+ # INTERFACE libraries can't have the CXX_STANDARD property set.
set_property(TARGET ${_NAME} PROPERTY CXX_STANDARD ${IREE_CXX_STANDARD})
set_property(TARGET ${_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
else()
- # Generating header-only library
+ # Generating header-only library.
add_library(${_NAME} INTERFACE)
target_include_directories(${_NAME}
INTERFACE
@@ -141,18 +140,18 @@
)
target_compile_options(${_NAME}
INTERFACE
- ${IREE_CC_LIB_COPTS}
+ ${_RULE_COPTS}
${IREE_DEFAULT_COPTS}
)
target_link_libraries(${_NAME}
INTERFACE
- ${IREE_CC_LIB_DEPS}
- ${IREE_CC_LIB_LINKOPTS}
+ ${_RULE_DEPS}
+ ${_RULE_LINKOPTS}
${IREE_DEFAULT_LINKOPTS}
)
target_compile_definitions(${_NAME}
INTERFACE
- ${IREE_CC_LIB_DEFINES}
+ ${_RULE_DEFINES}
)
endif()
@@ -160,9 +159,9 @@
# This lets us more clearly map to Bazel and makes it possible to
# disambiguate the underscores in paths vs. the separators.
iree_package_ns(_PACKAGE_NS)
- add_library(${_PACKAGE_NS}::${IREE_CC_LIB_NAME} ALIAS ${_NAME})
+ add_library(${_PACKAGE_NS}::${_RULE_NAME} ALIAS ${_NAME})
iree_package_dir(_PACKAGE_DIR)
- if(${IREE_CC_LIB_NAME} STREQUAL ${_PACKAGE_DIR})
+ if(${_RULE_NAME} STREQUAL ${_PACKAGE_DIR})
# If the library name matches the package then treat it as a default.
# For example, foo/bar/ library 'bar' would end up as 'foo::bar'.
add_library(${_PACKAGE_NS} ALIAS ${_NAME})
diff --git a/build_tools/cmake/iree_cc_test.cmake b/build_tools/cmake/iree_cc_test.cmake
index 3a6b3c1..a159665 100644
--- a/build_tools/cmake/iree_cc_test.cmake
+++ b/build_tools/cmake/iree_cc_test.cmake
@@ -55,7 +55,8 @@
return()
endif()
- cmake_parse_arguments(IREE_CC_TEST
+ cmake_parse_arguments(
+ _RULE
""
"NAME"
"SRCS;COPTS;DEFINES;LINKOPTS;DEPS"
@@ -64,12 +65,12 @@
# Prefix the library with the package name, so we get: iree_package_name
iree_package_name(_PACKAGE_NAME)
- set(_NAME "${_PACKAGE_NAME}_${IREE_CC_TEST_NAME}")
+ set(_NAME "${_PACKAGE_NAME}_${_RULE_NAME}")
add_executable(${_NAME} "")
target_sources(${_NAME}
PRIVATE
- ${IREE_CC_TEST_SRCS}
+ ${_RULE_SRCS}
)
target_include_directories(${_NAME}
PUBLIC
@@ -79,18 +80,18 @@
)
target_compile_definitions(${_NAME}
PUBLIC
- ${IREE_CC_TEST_DEFINES}
+ ${_RULE_DEFINES}
)
target_compile_options(${_NAME}
PRIVATE
- ${IREE_CC_TEST_COPTS}
+ ${_RULE_COPTS}
)
target_link_libraries(${_NAME}
PUBLIC
- ${IREE_CC_TEST_DEPS}
+ ${_RULE_DEPS}
gmock
PRIVATE
- ${IREE_CC_TEST_LINKOPTS}
+ ${_RULE_LINKOPTS}
)
# Add all IREE targets to a a folder in the IDE for organization.
set_property(TARGET ${_NAME} PROPERTY FOLDER ${IREE_IDE_FOLDER}/test)
diff --git a/build_tools/cmake/iree_copts.cmake b/build_tools/cmake/iree_copts.cmake
index 1645be0..85b6e8e 100644
--- a/build_tools/cmake/iree_copts.cmake
+++ b/build_tools/cmake/iree_copts.cmake
@@ -42,6 +42,8 @@
"-Wno-gnu-zero-variadic-macro-arguments"
MSVC_OR_CLANG_CL
"/DWIN32_LEAN_AND_MEAN"
+ # TODO(benvanik): figure out if really required or accidentally enabled.
+ "/EHsc"
)
set(IREE_DEFAULT_LINKOPTS "${ABSL_DEFAULT_LINKOPTS}")
set(IREE_TEST_COPTS "${ABSL_TEST_COPTS}")
@@ -130,11 +132,13 @@
set(MLIR_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/mlir)
set(MLIR_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/third_party/llvm-project/llvm/tools/MLIR)
-function(mlir_tablegen1 ofn)
- tablegen(MLIR ${ARGV} "-I${MLIR_SOURCE_DIR}" "-I${MLIR_INCLUDE_DIR}")
- set(TABLEGEN_OUTPUT ${TABLEGEN_OUTPUT} ${CMAKE_CURRENT_BINARY_DIR}/${ofn}
- PARENT_SCOPE)
-endfunction()
+#-------------------------------------------------------------------------------
+# Third party: tensorflow
+#-------------------------------------------------------------------------------
+
+list(APPEND IREE_COMMON_INCLUDE_DIRS
+ ${CMAKE_CURRENT_SOURCE_DIR}/third_party/tensorflow
+)
#-------------------------------------------------------------------------------
# Third party: vulkan
diff --git a/build_tools/cmake/iree_tablegen_library.cmake b/build_tools/cmake/iree_tablegen_library.cmake
index 2e0a862..705e214 100644
--- a/build_tools/cmake/iree_tablegen_library.cmake
+++ b/build_tools/cmake/iree_tablegen_library.cmake
@@ -19,28 +19,28 @@
# Runs iree-tablegen to produce some artifacts.
function(iree_tablegen_library)
cmake_parse_arguments(
- IREE_TBLGEN_LIB
+ _RULE
"TESTONLY"
"NAME"
"SRCS;OUTS"
${ARGN}
)
- if(NOT IREE_TBLGEN_LIB_TESTONLY OR IREE_BUILD_TESTS)
+ if(NOT _RULE_TESTONLY OR IREE_BUILD_TESTS)
# Prefix the library with the package name, so we get: iree_package_name
iree_package_name(_PACKAGE_NAME)
- set(_NAME "${_PACKAGE_NAME}_${IREE_TBLGEN_LIB_NAME}")
+ set(_NAME "${_PACKAGE_NAME}_${_RULE_NAME}")
- set(LLVM_TARGET_DEFINITIONS ${IREE_TBLGEN_LIB_SRCS})
+ set(LLVM_TARGET_DEFINITIONS ${_RULE_SRCS})
set(_INCLUDE_DIRS ${IREE_COMMON_INCLUDE_DIRS})
list(APPEND _INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR})
list(TRANSFORM _INCLUDE_DIRS PREPEND "-I")
set(_OUTPUTS)
- while(IREE_TBLGEN_LIB_OUTS)
- list(GET IREE_TBLGEN_LIB_OUTS 0 _COMMAND)
- list(REMOVE_AT IREE_TBLGEN_LIB_OUTS 0)
- list(GET IREE_TBLGEN_LIB_OUTS 0 _FILE)
- list(REMOVE_AT IREE_TBLGEN_LIB_OUTS 0)
+ while(_RULE_OUTS)
+ list(GET _RULE_OUTS 0 _COMMAND)
+ list(REMOVE_AT _RULE_OUTS 0)
+ list(GET _RULE_OUTS 0 _FILE)
+ list(REMOVE_AT _RULE_OUTS 0)
tablegen(MLIR ${_FILE} ${_COMMAND} ${_INCLUDE_DIRS})
list(APPEND _OUTPUTS ${CMAKE_CURRENT_BINARY_DIR}/${_FILE})
endwhile()
@@ -52,6 +52,6 @@
# Alias the iree_package_name library to iree::package::name.
iree_package_ns(_PACKAGE_NS)
- add_library(${_PACKAGE_NS}::${IREE_TBLGEN_LIB_NAME} ALIAS ${_NAME})
+ add_library(${_PACKAGE_NS}::${_RULE_NAME} ALIAS ${_NAME})
endif()
endfunction()
diff --git a/build_tools/third_party/ruy/CMakeLists.txt b/build_tools/third_party/ruy/CMakeLists.txt
index bd8c1e9..dd19f95 100644
--- a/build_tools/third_party/ruy/CMakeLists.txt
+++ b/build_tools/third_party/ruy/CMakeLists.txt
@@ -30,8 +30,6 @@
"-Wno-shadow"
"-Wno-missing-noreturn"
"-Wno-unused-local-typedef"
- MSVC_OR_CLANG_CL
- "/O3"
)
set(RUY_COPTS_AVX2)
set(RUY_COPTS_SKYLAKE)
diff --git a/build_tools/third_party/tensorflow/tensorflow/compiler/mlir/xla/CMakeLists.txt b/build_tools/third_party/tensorflow/tensorflow/compiler/mlir/xla/CMakeLists.txt
new file mode 100644
index 0000000..445cd1e
--- /dev/null
+++ b/build_tools/third_party/tensorflow/tensorflow/compiler/mlir/xla/CMakeLists.txt
@@ -0,0 +1,125 @@
+# 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.
+
+set(TF_MLIR_XLA_SRC_ROOT
+ "${IREE_ROOT_DIR}/third_party/tensorflow/tensorflow/compiler/mlir/xla/"
+)
+
+set(TF_MLIR_XLA_COPTS_BASE
+ "-I${IREE_ROOT_DIR}/third_party/tensorflow/"
+ "-I${CMAKE_BINARY_DIR}/build_tools/third_party/tensorflow/"
+)
+
+external_cc_library(
+ PACKAGE
+ tensorflow
+ NAME
+ mlir_xla
+ ROOT
+ ${TF_MLIR_XLA_SRC_ROOT}
+ SRCS
+ "ir/dialect_registration.cc"
+ "ir/hlo_ops.cc"
+ "ir/lhlo_ops.cc"
+ "transforms/legalize_control_flow.cc"
+ "transforms/legalize_to_standard.cc"
+ "transforms/lower_general_dot.cc"
+ HDRS
+ "ir/hlo_ops.h"
+ "ir/lhlo_ops.h"
+ "transforms/passes.h"
+ "transforms/rewriters.h"
+ COPTS
+ ${TF_MLIR_XLA_COPTS_BASE}
+ INCLUDES
+ ${IREE_ROOT_DIR}/third_party/tensorflow/
+ ${CMAKE_BINARY_DIR}/build_tools/third_party/tensorflow/
+ DEPS
+ absl::core_headers
+ tensorflow_mlir_xla_hlo_ops_gen
+ tensorflow_mlir_xla_hlo_ops_base_gen
+ tensorflow_mlir_xla_legalize_to_standard_patterns_gen
+ tensorflow_mlir_xla_lhlo_ops_gen
+ LLVMSupport
+ MLIRAnalysis
+ MLIRIR
+ MLIRPass
+ MLIRTransformUtils
+ PUBLIC
+)
+
+external_tablegen_library(
+ PACKAGE
+ tensorflow
+ NAME
+ mlir_xla_hlo_ops_gen
+ TBLGEN
+ MLIR
+ ROOT
+ ${TF_MLIR_XLA_SRC_ROOT}
+ SRCS
+ "ir/hlo_ops.td"
+ OUTS
+ -gen-op-decls ir/hlo_ops.h.inc
+ -gen-op-defs ir/hlo_ops.cc.inc
+ -gen-struct-attr-decls ir/hlo_structs.h.inc
+ -gen-struct-attr-defs ir/hlo_structs.cc.inc
+)
+
+external_tablegen_library(
+ PACKAGE
+ tensorflow
+ NAME
+ mlir_xla_hlo_ops_base_gen
+ TBLGEN
+ MLIR
+ ROOT
+ ${TF_MLIR_XLA_SRC_ROOT}
+ SRCS
+ "ir/hlo_ops_base.td"
+ OUTS
+ -gen-op-decls ir/hlo_ops_base.h.inc
+ -gen-op-defs ir/hlo_ops_base.cc.inc
+)
+
+external_tablegen_library(
+ PACKAGE
+ tensorflow
+ NAME
+ mlir_xla_legalize_to_standard_patterns_gen
+ TBLGEN
+ MLIR
+ ROOT
+ ${TF_MLIR_XLA_SRC_ROOT}
+ SRCS
+ "transforms/legalize_to_standard_patterns.td"
+ OUTS
+ -gen-rewriters transforms/generated_legalize_to_standard.inc
+)
+
+external_tablegen_library(
+ PACKAGE
+ tensorflow
+ NAME
+ mlir_xla_lhlo_ops_gen
+ TBLGEN
+ MLIR
+ ROOT
+ ${TF_MLIR_XLA_SRC_ROOT}
+ SRCS
+ "ir/lhlo_ops.td"
+ OUTS
+ -gen-op-decls ir/lhlo_ops.h.inc
+ -gen-op-defs ir/lhlo_ops.cc.inc
+)
diff --git a/iree/base/CMakeLists.txt b/iree/base/CMakeLists.txt
index abfbe02..79e27aa 100644
--- a/iree/base/CMakeLists.txt
+++ b/iree/base/CMakeLists.txt
@@ -59,16 +59,33 @@
iree_cc_library(
NAME
+ file_handle
+ SRCS
+ "internal/file_handle_win32.cc"
+ HDRS
+ "internal/file_handle_win32.h"
+ DEPS
+ absl::memory
+ absl::strings
+ iree::base::status
+ iree::base::tracing
+ iree::base::target_platform
+ PUBLIC
+)
+
+iree_cc_library(
+ NAME
file_io
SRCS
- "file_io_posix.cc"
- "file_io_win32.cc"
+ "internal/file_io_posix.cc"
+ "internal/file_io_win32.cc"
HDRS
"file_io.h"
DEPS
absl::memory
absl::strings
absl::span
+ iree::base::file_handle
iree::base::ref_ptr
iree::base::status
iree::base::target_platform
@@ -79,14 +96,15 @@
NAME
file_mapping
SRCS
- "file_io_posix.cc"
- "file_io_win32.cc"
+ "internal/file_mapping_posix.cc"
+ "internal/file_mapping_win32.cc"
HDRS
"file_mapping.h"
DEPS
absl::memory
absl::strings
absl::span
+ iree::base::file_handle
iree::base::ref_ptr
iree::base::status
iree::base::tracing
diff --git a/iree/base/file_path.cc b/iree/base/file_path.cc
index c0a67f0..13230ce 100644
--- a/iree/base/file_path.cc
+++ b/iree/base/file_path.cc
@@ -23,7 +23,7 @@
std::pair<absl::string_view, absl::string_view> SplitPath(
absl::string_view path) {
- ssize_t pos = path.find_last_of('/');
+ size_t pos = path.find_last_of('/');
// Handle the case with no '/' in 'path'.
if (pos == absl::string_view::npos) {
return std::make_pair(path.substr(0, 0), path);
@@ -42,7 +42,7 @@
std::pair<absl::string_view, absl::string_view> SplitBasename(
absl::string_view path) {
path = Basename(path);
- ssize_t pos = path.find_last_of('.');
+ size_t pos = path.find_last_of('.');
if (pos == absl::string_view::npos)
return std::make_pair(path, absl::ClippedSubstr(path, path.size(), 0));
return std::make_pair(path.substr(0, pos),
diff --git a/iree/base/internal/file_handle_win32.cc b/iree/base/internal/file_handle_win32.cc
new file mode 100644
index 0000000..efbf975
--- /dev/null
+++ b/iree/base/internal/file_handle_win32.cc
@@ -0,0 +1,61 @@
+// 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/base/internal/file_handle_win32.h"
+
+#include "absl/memory/memory.h"
+#include "iree/base/target_platform.h"
+#include "iree/base/tracing.h"
+
+#if defined(IREE_PLATFORM_WINDOWS)
+
+#include <windows.h>
+
+namespace iree {
+
+// static
+StatusOr<std::unique_ptr<FileHandle>> FileHandle::OpenRead(std::string path,
+ DWORD file_flags) {
+ IREE_TRACE_SCOPE0("FileHandle::OpenRead");
+
+ HANDLE handle = ::CreateFileA(
+ /*lpFileName=*/path.c_str(), /*dwDesiredAccess=*/GENERIC_READ,
+ /*dwShareMode=*/FILE_SHARE_READ, /*lpSecurityAttributes=*/nullptr,
+ /*dwCreationDisposition=*/OPEN_EXISTING,
+ /*dwFlagsAndAttributes=*/FILE_ATTRIBUTE_NORMAL | file_flags,
+ /*hTemplateFile=*/nullptr);
+ if (handle == INVALID_HANDLE_VALUE) {
+ return Win32ErrorToCanonicalStatusBuilder(GetLastError(), IREE_LOC)
+ << "Unable to open file " << path;
+ }
+
+ BY_HANDLE_FILE_INFORMATION file_info;
+ if (::GetFileInformationByHandle(handle, &file_info) == FALSE) {
+ return Win32ErrorToCanonicalStatusBuilder(GetLastError(), IREE_LOC)
+ << "Unable to query file info for " << path;
+ }
+
+ uint64_t file_size = (static_cast<uint64_t>(file_info.nFileSizeHigh) << 32) |
+ file_info.nFileSizeLow;
+ return absl::make_unique<FileHandle>(handle, file_size);
+}
+
+FileHandle::~FileHandle() {
+ IREE_TRACE_SCOPE0("FileHandle::~dtor");
+ ::CloseHandle(handle_);
+}
+
+} // namespace iree
+
+#endif // IREE_PLATFORM_WINDOWS
diff --git a/iree/base/internal/file_handle_win32.h b/iree/base/internal/file_handle_win32.h
new file mode 100644
index 0000000..793e5c6
--- /dev/null
+++ b/iree/base/internal/file_handle_win32.h
@@ -0,0 +1,57 @@
+// 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_BASE_INTERNAL_FILE_HANDLE_WIN32_H_
+#define IREE_BASE_INTERNAL_FILE_HANDLE_WIN32_H_
+
+#include <memory>
+#include <string>
+
+#include "absl/memory/memory.h"
+#include "absl/strings/string_view.h"
+#include "iree/base/status.h"
+#include "iree/base/target_platform.h"
+
+#if defined(IREE_PLATFORM_WINDOWS)
+
+#include <windows.h>
+
+namespace iree {
+
+class FileHandle {
+ public:
+ static StatusOr<std::unique_ptr<FileHandle>> OpenRead(std::string path,
+ DWORD file_flags);
+
+ FileHandle(HANDLE handle, size_t size) : handle_(handle), size_(size) {}
+ ~FileHandle();
+
+ absl::string_view path() const { return path_; }
+ HANDLE handle() const { return handle_; }
+ size_t size() const { return size_; }
+
+ private:
+ FileHandle(const FileHandle&) = delete;
+ FileHandle& operator=(const FileHandle&) = delete;
+
+ std::string path_;
+ HANDLE handle_;
+ size_t size_;
+};
+
+} // namespace iree
+
+#endif // IREE_PLATFORM_WINDOWS
+
+#endif // IREE_BASE_INTERNAL_FILE_HANDLE_WIN32_H_
diff --git a/iree/base/internal/file_io_win32.cc b/iree/base/internal/file_io_win32.cc
index 4b33d4e..bb06b5f 100644
--- a/iree/base/internal/file_io_win32.cc
+++ b/iree/base/internal/file_io_win32.cc
@@ -15,6 +15,7 @@
#include "absl/memory/memory.h"
#include "absl/strings/str_cat.h"
#include "iree/base/file_io.h"
+#include "iree/base/internal/file_handle_win32.h"
#include "iree/base/target_platform.h"
#if defined(IREE_PLATFORM_WINDOWS)
diff --git a/iree/base/internal/file_mapping_win32.cc b/iree/base/internal/file_mapping_win32.cc
index bb6ef30..ebe8fb7 100644
--- a/iree/base/internal/file_mapping_win32.cc
+++ b/iree/base/internal/file_mapping_win32.cc
@@ -15,6 +15,7 @@
#include "absl/memory/memory.h"
#include "absl/strings/str_cat.h"
#include "iree/base/file_mapping.h"
+#include "iree/base/internal/file_handle_win32.h"
#include "iree/base/target_platform.h"
#include "iree/base/tracing.h"
@@ -26,49 +27,6 @@
namespace {
-class FileHandle {
- public:
- static StatusOr<std::unique_ptr<FileHandle>> OpenRead(std::string path,
- DWORD file_flags) {
- HANDLE handle = ::CreateFileA(
- /*lpFileName=*/path.c_str(), /*dwDesiredAccess=*/GENERIC_READ,
- /*dwShareMode=*/FILE_SHARE_READ, /*lpSecurityAttributes=*/nullptr,
- /*dwCreationDisposition=*/OPEN_EXISTING,
- /*dwFlagsAndAttributes=*/FILE_ATTRIBUTE_NORMAL | file_flags,
- /*hTemplateFile=*/nullptr);
- if (handle == INVALID_HANDLE_VALUE) {
- return Win32ErrorToCanonicalStatusBuilder(GetLastError(), IREE_LOC)
- << "Unable to open file " << path;
- }
-
- BY_HANDLE_FILE_INFORMATION file_info;
- if (::GetFileInformationByHandle(handle, &file_info) == FALSE) {
- return Win32ErrorToCanonicalStatusBuilder(GetLastError(), IREE_LOC)
- << "Unable to query file info for " << path;
- }
-
- uint64_t file_size =
- (static_cast<uint64_t>(file_info.nFileSizeHigh) << 32) |
- file_info.nFileSizeLow;
- return absl::make_unique<FileHandle>(handle, file_size);
- }
-
- FileHandle(HANDLE handle, size_t size) : handle_(handle), size_(size) {}
- ~FileHandle() { ::CloseHandle(handle_); }
-
- absl::string_view path() const { return path_; }
- HANDLE handle() const { return handle_; }
- size_t size() const { return size_; }
-
- private:
- FileHandle(const FileHandle&) = delete;
- FileHandle& operator=(const FileHandle&) = delete;
-
- std::string path_;
- HANDLE handle_;
- size_t size_;
-};
-
class Win32FileMapping : public FileMapping {
public:
Win32FileMapping(HANDLE mapping_handle, void* data, size_t data_size)
diff --git a/iree/base/intrusive_list.h b/iree/base/intrusive_list.h
index 68a6f45..ce31c54 100644
--- a/iree/base/intrusive_list.h
+++ b/iree/base/intrusive_list.h
@@ -689,7 +689,7 @@
tail_ = nullptr;
// Repeatedly merge sublists.
int merge_count = 0;
- while (p) {
+ do {
++merge_count;
q = p;
// Determine the size of the first part and find the second.
@@ -736,7 +736,7 @@
tail = e;
}
p = q;
- }
+ } while (p);
tail->next = nullptr;
if (merge_count <= 1) {
// List is now sorted; stash and return.
diff --git a/iree/base/time.h b/iree/base/time.h
index 350d830..81f9809 100644
--- a/iree/base/time.h
+++ b/iree/base/time.h
@@ -15,6 +15,9 @@
#ifndef IREE_BASE_TIME_H_
#define IREE_BASE_TIME_H_
+#include <chrono> // NOLINT
+#include <thread> // NOLINT
+
#include "absl/time/clock.h"
#include "absl/time/time.h"
@@ -32,6 +35,13 @@
return absl::Now() + timeout;
}
+// Suspends execution of the calling thread for the given |duration|.
+// Depending on platform this may have an extremely coarse resolution (upwards
+// of several to dozens of milliseconds).
+inline void Sleep(absl::Duration duration) {
+ std::this_thread::sleep_for(absl::ToChronoMilliseconds(duration));
+}
+
} // namespace iree
#endif // IREE_BASE_TIME_H_
diff --git a/iree/compiler/IR/CMakeLists.txt b/iree/compiler/IR/CMakeLists.txt
index ceee341..f46c72b 100644
--- a/iree/compiler/IR/CMakeLists.txt
+++ b/iree/compiler/IR/CMakeLists.txt
@@ -45,8 +45,9 @@
iree::compiler::IR::StructureOpsGen
iree::schemas::executable_def_cc_fbs
LLVMSupport
- MLIR
+ MLIRIR
MLIRStandardOps
+ ALWAYSLINK
PUBLIC
)
diff --git a/iree/compiler/IR/Interpreter/CMakeLists.txt b/iree/compiler/IR/Interpreter/CMakeLists.txt
index 2a12c2e..a578942 100644
--- a/iree/compiler/IR/Interpreter/CMakeLists.txt
+++ b/iree/compiler/IR/Interpreter/CMakeLists.txt
@@ -38,7 +38,8 @@
iree::compiler::Serialization
iree::compiler::Utils
LLVMSupport
- MLIR
+ MLIRIR
+ ALWAYSLINK
PUBLIC
)
diff --git a/iree/compiler/IR/Sequencer/CMakeLists.txt b/iree/compiler/IR/Sequencer/CMakeLists.txt
index a8952fc..27b568d 100644
--- a/iree/compiler/IR/Sequencer/CMakeLists.txt
+++ b/iree/compiler/IR/Sequencer/CMakeLists.txt
@@ -38,7 +38,8 @@
iree::compiler::Serialization
iree::compiler::Utils
LLVMSupport
- MLIR
+ MLIRIR
+ ALWAYSLINK
PUBLIC
)
diff --git a/iree/compiler/Serialization/BytecodeWriter.cpp b/iree/compiler/Serialization/BytecodeWriter.cpp
index a5b848a..a357c3a 100644
--- a/iree/compiler/Serialization/BytecodeWriter.cpp
+++ b/iree/compiler/Serialization/BytecodeWriter.cpp
@@ -218,7 +218,7 @@
if (!ordinal.hasValue()) {
return failure();
}
- if (ordinal > UINT16_MAX) {
+ if (ordinal.getValue() > UINT16_MAX) {
// TODO(benvanik): varints?
return emitError(UnknownLoc::get(value->getContext()))
<< "Too many locals: " << ordinal.getValue()
diff --git a/iree/compiler/Serialization/CMakeLists.txt b/iree/compiler/Serialization/CMakeLists.txt
index ebf3175..22416bb 100644
--- a/iree/compiler/Serialization/CMakeLists.txt
+++ b/iree/compiler/Serialization/CMakeLists.txt
@@ -41,6 +41,6 @@
iree::schemas::bytecode::interpreter_bytecode_v0
iree::schemas::bytecode::sequencer_bytecode_v0
LLVMSupport
- MLIR
+ MLIRIR
PUBLIC
)
diff --git a/iree/compiler/Transforms/CMakeLists.txt b/iree/compiler/Transforms/CMakeLists.txt
index fc7b090..37316e1 100644
--- a/iree/compiler/Transforms/CMakeLists.txt
+++ b/iree/compiler/Transforms/CMakeLists.txt
@@ -35,6 +35,8 @@
iree::compiler::Utils
tensorflow::mlir_xla
LLVMSupport
- MLIR
+ MLIRIR
+ MLIRPass
+ MLIRTransformUtils
PUBLIC
)
diff --git a/iree/compiler/Transforms/Interpreter/CMakeLists.txt b/iree/compiler/Transforms/Interpreter/CMakeLists.txt
index f9de474..b96054e 100644
--- a/iree/compiler/Transforms/Interpreter/CMakeLists.txt
+++ b/iree/compiler/Transforms/Interpreter/CMakeLists.txt
@@ -17,12 +17,14 @@
Interpreter
HDRS
"Passes.h"
+ "Rewrites.h"
SRCS
"ExpandReductionsToOps.cpp"
"LegalizeInterpreterOps.cpp"
"LoadStoreDataFlowOpt.cpp"
"LowerInterpreterDialect.cpp"
"LowerStdToInterpreterDialect.cpp"
+ "LowerToInterpreterDialect.cpp"
"LowerXLAToInterpreterDialect.cpp"
"MakeExecutableABI.cpp"
DEPS
@@ -31,6 +33,8 @@
iree::compiler::Utils
tensorflow::mlir_xla
LLVMSupport
- MLIR
+ MLIRIR
+ MLIRPass
+ MLIRTransformUtils
PUBLIC
)
diff --git a/iree/compiler/Transforms/Interpreter/LegalizeInterpreterOps.cpp b/iree/compiler/Transforms/Interpreter/LegalizeInterpreterOps.cpp
index 302565b..c7c5134 100644
--- a/iree/compiler/Transforms/Interpreter/LegalizeInterpreterOps.cpp
+++ b/iree/compiler/Transforms/Interpreter/LegalizeInterpreterOps.cpp
@@ -27,10 +27,6 @@
namespace mlir {
namespace iree_compiler {
-namespace optimize_patterns {
-#include "iree/compiler/Transforms/Interpreter/LegalizeInterpreterOps.inc"
-} // namespace optimize_patterns
-
void tryElideClone(IREEInterp::HL::CloneOp *cloneOp,
std::vector<Operation *> *deadOperations) {
cloneOp->replaceAllUsesWith(cloneOp->src());
@@ -56,10 +52,7 @@
public:
void runOnFunction() override {
OwningRewritePatternList patterns;
- auto *context = getFunction().getContext();
- optimize_patterns::populateWithGenerated(context, &patterns);
applyPatternsGreedily(getFunction(), patterns);
-
removeIdentityClones(getFunction());
}
};
diff --git a/iree/compiler/Transforms/Interpreter/LegalizeInterpreterOps.td b/iree/compiler/Transforms/Interpreter/LegalizeInterpreterOps.td
deleted file mode 100644
index fe59764..0000000
--- a/iree/compiler/Transforms/Interpreter/LegalizeInterpreterOps.td
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifdef IREE_INTERPRETER_HL_OPS
-#else
-include "iree/compiler/IR/Interpreter/HLOps.td"
-#endif // IREE_INTERPRETER_HL_OPS
-
-// TODO(benvanik): fun patterns.
diff --git a/iree/compiler/Transforms/Interpreter/LowerToInterpreterDialect.cpp b/iree/compiler/Transforms/Interpreter/LowerToInterpreterDialect.cpp
index 1bb28a3..564d3ab 100644
--- a/iree/compiler/Transforms/Interpreter/LowerToInterpreterDialect.cpp
+++ b/iree/compiler/Transforms/Interpreter/LowerToInterpreterDialect.cpp
@@ -33,8 +33,8 @@
OwningRewritePatternList patterns;
auto* ctx = &getContext();
xla_hlo::PopulateGeneralDotOpLoweringPatterns(&patterns, ctx);
- populateLowerStdToInterpreterPatterns(patterns, ctx);
xla_hlo::PopulateXlaToStdPatterns(&patterns, ctx);
+ populateLowerStdToInterpreterPatterns(patterns, ctx);
populateLowerXlaToInterpreterPatterns(patterns, ctx);
ConversionTarget target(getContext());
diff --git a/iree/compiler/Transforms/Sequencer/CMakeLists.txt b/iree/compiler/Transforms/Sequencer/CMakeLists.txt
index 4b446a4..1396a6e 100644
--- a/iree/compiler/Transforms/Sequencer/CMakeLists.txt
+++ b/iree/compiler/Transforms/Sequencer/CMakeLists.txt
@@ -17,13 +17,13 @@
Sequencer
HDRS
"Passes.h"
+ "Rewrites.h"
SRCS
"AssignExecutableOrdinals.cpp"
"AssignExecutableWorkloadAttrs.cpp"
"FoldCompatibleDispatchRegions.cpp"
"IdentifyDispatchRegions.cpp"
"IdentifyReductionRegions.cpp"
- "LoadStoreDataFlowOpt.cpp"
"LowerSequencerDialect.cpp"
"LowerStdToSequencerDialect.cpp"
"LowerToSequencerDialect.cpp"
@@ -37,6 +37,8 @@
iree::compiler::Utils
tensorflow::mlir_xla
LLVMSupport
- MLIR
+ MLIRIR
+ MLIRPass
+ MLIRTransformUtils
PUBLIC
)
diff --git a/iree/compiler/Translation/CMakeLists.txt b/iree/compiler/Translation/CMakeLists.txt
index a096629..036be3a 100644
--- a/iree/compiler/Translation/CMakeLists.txt
+++ b/iree/compiler/Translation/CMakeLists.txt
@@ -15,3 +15,4 @@
add_subdirectory(Interpreter)
add_subdirectory(SPIRV)
add_subdirectory(Sequencer)
+
diff --git a/iree/compiler/Translation/Interpreter/CMakeLists.txt b/iree/compiler/Translation/Interpreter/CMakeLists.txt
index b20164d..85d6ee5 100644
--- a/iree/compiler/Translation/Interpreter/CMakeLists.txt
+++ b/iree/compiler/Translation/Interpreter/CMakeLists.txt
@@ -26,11 +26,14 @@
iree::compiler::IR::Interpreter
iree::compiler::Serialization
iree::compiler::Transforms
- iree::compiler::Transforms::Sequencer
+ iree::compiler::Transforms::Interpreter
iree::compiler::Utils
iree::schemas
tensorflow::mlir_xla
LLVMSupport
- MLIR
+ MLIRIR
+ MLIRTransforms
+ MLIRTranslation
+ ALWAYSLINK
PUBLIC
)
diff --git a/iree/compiler/Translation/SPIRV/CMakeLists.txt b/iree/compiler/Translation/SPIRV/CMakeLists.txt
index a2ba78d..3bf540d 100644
--- a/iree/compiler/Translation/SPIRV/CMakeLists.txt
+++ b/iree/compiler/Translation/SPIRV/CMakeLists.txt
@@ -48,6 +48,11 @@
iree::schemas::spirv_executable_def_cc_fbs
tensorflow::mlir_xla
LLVMSupport
- MLIR
+ MLIRIR
+ MLIRSPIRV
+ MLIRSPIRVSerialization
+ MLIRTransforms
+ MLIRTranslation
+ ALWAYSLINK
PUBLIC
)
diff --git a/iree/compiler/Translation/Sequencer/CMakeLists.txt b/iree/compiler/Translation/Sequencer/CMakeLists.txt
index 747b83c..ac531f2 100644
--- a/iree/compiler/Translation/Sequencer/CMakeLists.txt
+++ b/iree/compiler/Translation/Sequencer/CMakeLists.txt
@@ -31,6 +31,9 @@
iree::schemas
tensorflow::mlir_xla
LLVMSupport
- MLIR
+ MLIRIR
+ MLIRTransforms
+ MLIRTranslation
+ ALWAYSLINK
PUBLIC
)
diff --git a/iree/compiler/Utils/CMakeLists.txt b/iree/compiler/Utils/CMakeLists.txt
index 65953c7..b946f5f 100644
--- a/iree/compiler/Utils/CMakeLists.txt
+++ b/iree/compiler/Utils/CMakeLists.txt
@@ -36,6 +36,6 @@
iree::schemas::executable_def_cc_fbs
tensorflow::mlir_xla
LLVMSupport
- MLIR
+ MLIRIR
PUBLIC
)
diff --git a/iree/hal/CMakeLists.txt b/iree/hal/CMakeLists.txt
index 2d20d14..0a622d6 100644
--- a/iree/hal/CMakeLists.txt
+++ b/iree/hal/CMakeLists.txt
@@ -327,8 +327,6 @@
iree::base::bitfield
iree::base::ref_ptr
iree::base::status
- iree::base::tracing
- iree::base::wait_handle
iree::hal::executable
iree::hal::executable_format
iree::hal::executable_spec
diff --git a/iree/hal/executable_cache.cc b/iree/hal/executable_cache.cc
index c39ae00..26ce40c 100644
--- a/iree/hal/executable_cache.cc
+++ b/iree/hal/executable_cache.cc
@@ -14,10 +14,6 @@
#include "iree/hal/executable_cache.h"
-#include "iree/base/source_location.h"
-#include "iree/base/status.h"
-#include "iree/base/tracing.h"
-
namespace iree {
namespace hal {
@@ -25,32 +21,5 @@
ExecutableCache::~ExecutableCache() = default;
-StatusOr<WaitHandle> ExecutableCache::PrepareExecutables(
- ExecutableCachingModeBitfield mode, absl::Span<const ExecutableSpec> specs,
- absl::Span<ref_ptr<Executable>> out_executables) {
- IREE_TRACE_SCOPE0("ExecutableCache::PrepareExecutables");
- if (specs.size() != out_executables.size()) {
- return InvalidArgumentErrorBuilder(IREE_LOC)
- << "1:1 specs:out_executables required";
- }
-
- ManualResetEvent fence("ExecutableCachePreparation");
- auto wait_handle = fence.OnSet();
-
- // TODO(benvanik): make async (spin up thread, etc).
- for (int i = 0; i < specs.size(); ++i) {
- auto executable_or = PrepareExecutable(mode, specs[i]);
- if (!executable_or.ok()) {
- // TODO(benvanik): propagate executable error.
- RETURN_IF_ERROR(fence.Set());
- return wait_handle;
- }
- out_executables[i] = add_ref(std::move(executable_or).ValueOrDie());
- }
-
- RETURN_IF_ERROR(fence.Set());
- return wait_handle;
-}
-
} // namespace hal
} // namespace iree
diff --git a/iree/hal/executable_cache.h b/iree/hal/executable_cache.h
index 95a527e..3e31831 100644
--- a/iree/hal/executable_cache.h
+++ b/iree/hal/executable_cache.h
@@ -18,7 +18,6 @@
#include "iree/base/bitfield.h"
#include "iree/base/ref_ptr.h"
#include "iree/base/status.h"
-#include "iree/base/wait_handle.h"
#include "iree/hal/executable.h"
#include "iree/hal/executable_format.h"
#include "iree/hal/executable_spec.h"
@@ -117,24 +116,6 @@
virtual StatusOr<ref_ptr<Executable>> PrepareExecutable(
ExecutableCachingModeBitfield mode, const ExecutableSpec& spec) = 0;
- // Prepares one or more executables asynchronously on a worker thread (maybe).
- // When the WaitHandle is signaled successfully |out_executables| will contain
- // one Executable for each ExecutableSpec provided in |specs|, in order.
- // The backing memory of |out_executables| must remain valid until the
- // WaitHandle resolves. Preparation errors will be returned on the WaitHandle.
- // If more than one preparation errors occurs only one will be returned (from
- // an undefined order).
- //
- // Note: not all implementations will actually perform preparation
- // asynchronously. This method just allows drivers to do so as possible.
- //
- // If applications already have their own preparation threads it is better to
- // use PrepareExecutable in a loop to avoid the creation of new threads.
- virtual StatusOr<WaitHandle> PrepareExecutables(
- ExecutableCachingModeBitfield mode,
- absl::Span<const ExecutableSpec> specs,
- absl::Span<ref_ptr<Executable>> out_executables);
-
protected:
ExecutableCache();
};
diff --git a/iree/hal/host/CMakeLists.txt b/iree/hal/host/CMakeLists.txt
index bff14e4..2341df7 100644
--- a/iree/hal/host/CMakeLists.txt
+++ b/iree/hal/host/CMakeLists.txt
@@ -36,6 +36,7 @@
gtest_main
iree::base::status
iree::base::status_matchers
+ iree::base::time
iree::hal::command_queue
iree::hal::host::async_command_queue
iree::hal::host::host_submission_queue
diff --git a/iree/hal/host/async_command_queue_test.cc b/iree/hal/host/async_command_queue_test.cc
index 8eea660..256aee7 100644
--- a/iree/hal/host/async_command_queue_test.cc
+++ b/iree/hal/host/async_command_queue_test.cc
@@ -14,8 +14,6 @@
#include "iree/hal/host/async_command_queue.h"
-#include <unistd.h>
-
#include <cstdint>
#include <memory>
#include <utility>
@@ -26,6 +24,7 @@
#include "absl/time/time.h"
#include "iree/base/status.h"
#include "iree/base/status_matchers.h"
+#include "iree/base/time.h"
#include "iree/hal/command_queue.h"
#include "iree/hal/host/host_submission_queue.h"
#include "iree/hal/testing/mock_command_buffer.h"
@@ -113,7 +112,7 @@
EXPECT_CALL(*mock_target_queue, Submit(_, _))
.WillOnce(
[](absl::Span<const SubmissionBatch> batches, FenceValue fence) {
- usleep(100000); // 100ms
+ Sleep(absl::Milliseconds(100));
return OkStatus();
});
HostFence fence(0u);
@@ -135,7 +134,7 @@
EXPECT_CALL(*mock_target_queue, Submit(_, _))
.WillRepeatedly(
[](absl::Span<const SubmissionBatch> batches, FenceValue fence) {
- usleep(100000); // 100ms
+ Sleep(absl::Milliseconds(100));
return OkStatus();
});
@@ -169,7 +168,7 @@
EXPECT_CALL(*mock_target_queue, Submit(_, _))
.WillOnce(
[](absl::Span<const SubmissionBatch> batches, FenceValue fence) {
- usleep(100000); // 100ms
+ Sleep(absl::Milliseconds(100));
return DataLossErrorBuilder(IREE_LOC);
});
auto cmd_buffer_0 = make_ref<MockCommandBuffer>(
@@ -201,7 +200,7 @@
EXPECT_CALL(*mock_target_queue, Submit(_, _))
.WillOnce(
[](absl::Span<const SubmissionBatch> batches, FenceValue fence) {
- usleep(100000); // 100ms
+ Sleep(absl::Milliseconds(100));
return DataLossErrorBuilder(IREE_LOC);
});
diff --git a/iree/hal/host/host_fence_test.cc b/iree/hal/host/host_fence_test.cc
index 27d5886..3223d4a 100644
--- a/iree/hal/host/host_fence_test.cc
+++ b/iree/hal/host/host_fence_test.cc
@@ -22,6 +22,7 @@
#include "absl/time/time.h"
#include "iree/base/status.h"
#include "iree/base/status_matchers.h"
+
namespace iree {
namespace hal {
namespace {
diff --git a/iree/hal/interpreter/bytecode_kernels_test.cc b/iree/hal/interpreter/bytecode_kernels_test.cc
index 67e42f9..db9a63b 100644
--- a/iree/hal/interpreter/bytecode_kernels_test.cc
+++ b/iree/hal/interpreter/bytecode_kernels_test.cc
@@ -30,7 +30,7 @@
template <typename T>
std::vector<T> MakeIota(int size) {
std::vector<T> v(size);
- std::iota(v.begin(), v.end(), 1);
+ std::iota(v.begin(), v.end(), static_cast<T>(1));
return v;
}
diff --git a/iree/hal/vulkan/CMakeLists.txt b/iree/hal/vulkan/CMakeLists.txt
index bfe0e0c..5ace69e 100644
--- a/iree/hal/vulkan/CMakeLists.txt
+++ b/iree/hal/vulkan/CMakeLists.txt
@@ -91,6 +91,7 @@
absl::memory
iree::base::ref_ptr
iree::base::status
+ iree::base::target_platform
iree::base::tracing
Vulkan::Headers
PUBLIC
diff --git a/iree/hal/vulkan/dynamic_symbols.cc b/iree/hal/vulkan/dynamic_symbols.cc
index c379f53..6b96876 100644
--- a/iree/hal/vulkan/dynamic_symbols.cc
+++ b/iree/hal/vulkan/dynamic_symbols.cc
@@ -14,8 +14,6 @@
#include "iree/hal/vulkan/dynamic_symbols.h"
-#include <dlfcn.h>
-
#include <cstddef>
#include "absl/base/attributes.h"
@@ -23,9 +21,16 @@
#include "absl/memory/memory.h"
#include "iree/base/source_location.h"
#include "iree/base/status.h"
+#include "iree/base/target_platform.h"
#include "iree/base/tracing.h"
#include "iree/hal/vulkan/dynamic_symbol_tables.h"
+#if defined(IREE_PLATFORM_WINDOWS)
+#include <windows.h>
+#else
+#include <dlfcn.h>
+#endif // IREE_PLATFORM_WINDOWS
+
namespace iree {
namespace hal {
namespace vulkan {
@@ -45,8 +50,6 @@
// member is located.
uint32_t member_offset : 30;
} ABSL_ATTRIBUTE_PACKED;
-static_assert(sizeof(FunctionPtrInfo) == sizeof(const char*) + sizeof(uint32_t),
- "Alignment on FunctionPtrInfo struct is wrong");
namespace {
@@ -118,7 +121,26 @@
StatusOr<ref_ptr<DynamicSymbols>> DynamicSymbols::CreateFromSystemLoader() {
IREE_TRACE_SCOPE0("DynamicSymbols::CreateFromSystemLoader");
- // TODO(benvanik): abstract out for other platforms.
+// NOTE: we could factor this out into base, but this is the only place we use
+// it right now so it's fine.
+#if defined(IREE_PLATFORM_WINDOWS)
+ HMODULE library = ::LoadLibraryA("vulkan-1.dll");
+ if (!library) {
+ return UnavailableErrorBuilder(IREE_LOC)
+ << "Unable to open vulkan-1.dll; driver not installed/on PATH";
+ }
+ ASSIGN_OR_RETURN(auto syms, Create([library](const char* function_name) {
+ return reinterpret_cast<PFN_vkVoidFunction>(
+ ::GetProcAddress(library, function_name));
+ }));
+ syms->close_fn_ = [library]() {
+ // TODO(benvanik): disable if we want to get profiling results. Sometimes
+ // closing the library can prevent proper symbolization on crashes or
+ // in sampling profilers.
+ ::FreeLibrary(library);
+ };
+ return syms;
+#else
void* library = ::dlopen("libvulkan.so.1", RTLD_LAZY | RTLD_LOCAL);
if (!library) {
return UnavailableErrorBuilder(IREE_LOC)
@@ -136,6 +158,7 @@
::dlclose(library);
};
return syms;
+#endif // IREE_PLATFORM_WINDOWS
}
Status DynamicSymbols::LoadFromInstance(VkInstance instance) {
diff --git a/iree/tools/CMakeLists.txt b/iree/tools/CMakeLists.txt
index a47f210..08a729b 100644
--- a/iree/tools/CMakeLists.txt
+++ b/iree/tools/CMakeLists.txt
@@ -11,3 +11,43 @@
# 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.
+
+if(${IREE_BUILD_COMPILER})
+
+ # TODO(benvanik): fix the ALWAYSLINK property and force MLIR libs.
+ set(_ALWAYSLINK_LIBS
+ MLIRAffineOps
+ MLIRAnalysis
+ MLIREDSC
+ MLIRParser
+ MLIRPass
+ MLIRSPIRV
+ MLIRSPIRVSerialization
+ MLIRStandardOps
+ MLIRTransforms
+ MLIRTranslation
+ MLIRSupport
+ MLIRVectorOps
+ iree::compiler::IR
+ iree::compiler::IR::Sequencer
+ iree::compiler::IR::Interpreter
+ tensorflow::mlir_xla
+ )
+
+ iree_cc_binary(
+ NAME
+ iree_translate
+ OUT
+ iree-translate
+ SRCS
+ "${IREE_ROOT_DIR}/third_party/mlir/tools/mlir-translate/mlir-translate.cpp"
+ DEPS
+ ${_ALWAYSLINK_LIBS}
+ iree::compiler::Translation::Interpreter
+ iree::compiler::Translation::Sequencer
+ # TODO(benvanik): get the SPIR-V translation working.
+ #iree::compiler::Translation::SPIRV
+ MLIRTranslateClParser
+ )
+
+endif()