Refactor to use upstream MHLO targets  (#3716)

* Drops the overlay external_tablegen_library() calls to generate MHLO
  tablegen targets and cleans up the custom hlo CMake config
* Refactors the custom tensorflow_mlir_hlo target to depend on the
  upstream MHLO targets
* Drops the external_tablegen_library CMake module

Depends on https://github.com/tensorflow/tensorflow/pull/44589.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index bbff376..e02be51 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -306,7 +306,11 @@
 # etc).
 function(add_bundled_mlir_dependent_projects)
   if(${IREE_ENABLE_EMITC})
-  add_subdirectory(third_party/mlir-emitc EXCLUDE_FROM_ALL)
+    add_subdirectory(third_party/mlir-emitc EXCLUDE_FROM_ALL)
+  endif()
+
+  if(${IREE_BUILD_COMPILER})
+    add_subdirectory(third_party/tensorflow/tensorflow/compiler/mlir/hlo EXCLUDE_FROM_ALL)
   endif()
 endfunction()
 
@@ -329,11 +333,25 @@
   if(${IREE_MLIR_DEP_MODE} STREQUAL "DISABLED")
     message(STATUS "Not adding MLIR/LLVM dep due to IREE_MLIR_DEP_MODE=DISABLED")
   elseif(${IREE_MLIR_DEP_MODE} STREQUAL "BUNDLED")
-    # TODO: See iree_copts.cmake where it sets include directories for this
-    # case. This should be cleaned up to be all in one place or the other for
-    # all modes.
     message(STATUS "Adding bundled LLVM source dependency")
     add_iree_mlir_src_dep("third_party/llvm-project")
+
+    # Extend module path to allow submodules to use LLVM and MLIR CMake modules
+    list(APPEND CMAKE_MODULE_PATH "${PROJECT_BINARY_DIR}/lib/cmake/mlir")
+    list(APPEND CMAKE_MODULE_PATH "${PROJECT_BINARY_DIR}/third_party/llvm-project/llvm/lib/cmake/llvm/")
+
+    # Set include directories
+    list(APPEND LLVM_INCLUDE_DIRS
+      ${PROJECT_SOURCE_DIR}/third_party/llvm-project/llvm/include
+      ${PROJECT_BINARY_DIR}/third_party/llvm-project/llvm/include
+    )
+    list(APPEND MLIR_INCLUDE_DIRS
+      ${PROJECT_SOURCE_DIR}/third_party/llvm-project/mlir/include
+      ${PROJECT_BINARY_DIR}/third_party/llvm-project/llvm/tools/mlir/include
+    )
+
+    # Set build option to use MHLO alongside with bundled MLIR
+    set(MHLO_BUILD_EMBEDDED ON)
   elseif(${IREE_MLIR_DEP_MODE} STREQUAL "INSTALLED")
     # Deps of installed MLIR/LLVM packages.
     find_package(ZLIB)  # See: https://reviews.llvm.org/D79219
@@ -357,7 +375,6 @@
     message(FATAL "Unsupported IREE_MLIR_DEP_MODE=${IREE_MLIR_DEP_MODE}")
   endif()
 
-  include(external_tablegen_library)
   add_bundled_mlir_dependent_projects()
 endif()