ROCM HAL Maintenance (#6472)

-Moving Status/StatusOr to iree/base/status_cc.h.
-IWYU related changes
-Add option to specify where AMD bitcode is
diff --git a/experimental/rocm/CMakeLists.txt b/experimental/rocm/CMakeLists.txt
index db57bd3..185bd5c 100644
--- a/experimental/rocm/CMakeLists.txt
+++ b/experimental/rocm/CMakeLists.txt
@@ -51,8 +51,6 @@
     iree::base::internal
     iree::base::internal::flatcc
     iree::base::internal::synchronization
-    iree::base::logging
-    iree::base::status
     iree::base::tracing
     iree::hal
     iree::schemas::rocm_executable_def_c_fbs
@@ -88,6 +86,7 @@
     "dynamic_symbols_test.cc"
   DEPS
     ::dynamic_symbols
+    iree::base
     iree::testing::gtest
     iree::testing::gtest_main
   LABELS
diff --git a/experimental/rocm/api.h b/experimental/rocm/api.h
index 638fedd..68fa191 100644
--- a/experimental/rocm/api.h
+++ b/experimental/rocm/api.h
@@ -21,7 +21,7 @@
 //===----------------------------------------------------------------------===//
 
 // ROCM driver creation options.
-typedef struct {
+typedef struct iree_hal_rocm_driver_options_t {
   // Index of the default ROCM device to use within the list of available
   // devices.
   int default_device_index;
diff --git a/experimental/rocm/context_wrapper.h b/experimental/rocm/context_wrapper.h
index 514207d..2c51424 100644
--- a/experimental/rocm/context_wrapper.h
+++ b/experimental/rocm/context_wrapper.h
@@ -13,7 +13,7 @@
 
 // Structure to wrap all objects constant within a context. This makes it
 // simpler to pass it to the different objects and saves memory.
-typedef struct {
+typedef struct iree_hal_rocm_context_wrapper_t {
   hipCtx_t rocm_context;
   iree_allocator_t host_allocator;
   iree_hal_rocm_dynamic_symbols_t *syms;
diff --git a/experimental/rocm/descriptor_set_layout.c b/experimental/rocm/descriptor_set_layout.c
index 0ca1cc8..69fb4af 100644
--- a/experimental/rocm/descriptor_set_layout.c
+++ b/experimental/rocm/descriptor_set_layout.c
@@ -6,10 +6,12 @@
 
 #include "experimental/rocm/descriptor_set_layout.h"
 
-#include "experimental/rocm/status_util.h"
+#include <stddef.h>
+
+#include "iree/base/api.h"
 #include "iree/base/tracing.h"
 
-typedef struct {
+typedef struct iree_hal_rocm_descriptor_set_layout_t {
   iree_hal_resource_t resource;
   iree_hal_rocm_context_wrapper_t *context;
 } iree_hal_rocm_descriptor_set_layout_t;
diff --git a/experimental/rocm/descriptor_set_layout.h b/experimental/rocm/descriptor_set_layout.h
index 933c9c6..fb07b76 100644
--- a/experimental/rocm/descriptor_set_layout.h
+++ b/experimental/rocm/descriptor_set_layout.h
@@ -8,6 +8,7 @@
 #define IREE_HAL_ROCM_DESCRIPTOR_SET_LAYOUT_H_
 
 #include "experimental/rocm/context_wrapper.h"
+#include "iree/base/api.h"
 #include "iree/hal/api.h"
 
 #ifdef __cplusplus
diff --git a/experimental/rocm/direct_command_buffer.c b/experimental/rocm/direct_command_buffer.c
index 9d56001..d75c060 100644
--- a/experimental/rocm/direct_command_buffer.c
+++ b/experimental/rocm/direct_command_buffer.c
@@ -6,10 +6,15 @@
 
 #include "experimental/rocm/direct_command_buffer.h"
 
+#include <assert.h>
+#include <stddef.h>
+#include <stdint.h>
+
+#include "experimental/rocm/dynamic_symbols.h"
 #include "experimental/rocm/native_executable.h"
 #include "experimental/rocm/rocm_buffer.h"
-#include "experimental/rocm/rocm_event.h"
 #include "experimental/rocm/status_util.h"
+#include "iree/base/api.h"
 #include "iree/base/tracing.h"
 
 // Command buffer implementation that directly maps to rocm direct.
diff --git a/experimental/rocm/direct_command_buffer.h b/experimental/rocm/direct_command_buffer.h
index 70519c9..0145b15 100644
--- a/experimental/rocm/direct_command_buffer.h
+++ b/experimental/rocm/direct_command_buffer.h
@@ -10,6 +10,7 @@
 #include "experimental/rocm/context_wrapper.h"
 #include "experimental/rocm/dynamic_symbols.h"
 #include "experimental/rocm/rocm_headers.h"
+#include "iree/base/api.h"
 #include "iree/hal/api.h"
 
 #ifdef __cplusplus
diff --git a/experimental/rocm/dynamic_symbols.c b/experimental/rocm/dynamic_symbols.c
index 0643cf1..d676838 100644
--- a/experimental/rocm/dynamic_symbols.c
+++ b/experimental/rocm/dynamic_symbols.c
@@ -6,7 +6,7 @@
 
 #include "experimental/rocm/dynamic_symbols.h"
 
-#include <stddef.h>
+#include <string.h>
 
 #include "iree/base/internal/dynamic_library.h"
 #include "iree/base/target_platform.h"
@@ -29,7 +29,7 @@
         syms->loader_library, kName, (void **)&syms->rocmSymbolName)); \
   }
 #define RC_PFN_STR_DECL(rocmSymbolName, ...) RC_PFN_DECL(rocmSymbolName, ...)
-#include "experimental/rocm/dynamic_symbol_tables.h"
+#include "experimental/rocm/dynamic_symbol_tables.h"  // IWYU pragma: keep
 #undef RC_PFN_DECL
 #undef RC_PFN_STR_DECL
   return iree_ok_status();
diff --git a/experimental/rocm/dynamic_symbols.h b/experimental/rocm/dynamic_symbols.h
index 2894626..00a58b0 100644
--- a/experimental/rocm/dynamic_symbols.h
+++ b/experimental/rocm/dynamic_symbols.h
@@ -19,14 +19,14 @@
 // loads all the function declared in `dynamic_symbol_tables.def` and fail if
 // any of the symbol is not available. The functions signatures are matching
 // the declarations in `hipruntime.h`.
-typedef struct {
+typedef struct iree_hal_rocm_dynamic_symbols_t {
   iree_dynamic_library_t *loader_library;
 
 #define RC_PFN_DECL(rocmSymbolName, ...) \
   hipError_t (*rocmSymbolName)(__VA_ARGS__);
 #define RC_PFN_STR_DECL(rocmSymbolName, ...) \
   const char *(*rocmSymbolName)(__VA_ARGS__);
-#include "experimental/rocm/dynamic_symbol_tables.h"
+#include "experimental/rocm/dynamic_symbol_tables.h"  // IWYU pragma: export
 #undef RC_PFN_DECL
 #undef RC_PFN_STR_DECL
 } iree_hal_rocm_dynamic_symbols_t;
diff --git a/experimental/rocm/dynamic_symbols_test.cc b/experimental/rocm/dynamic_symbols_test.cc
index dd33e07..06ea00a 100644
--- a/experimental/rocm/dynamic_symbols_test.cc
+++ b/experimental/rocm/dynamic_symbols_test.cc
@@ -6,8 +6,10 @@
 
 #include "experimental/rocm/dynamic_symbols.h"
 
+#include <iostream>
+
+#include "iree/base/api.h"
 #include "iree/testing/gtest.h"
-#include "iree/testing/status_matchers.h"
 
 namespace iree {
 namespace hal {
@@ -25,7 +27,7 @@
   iree_status_t status = iree_hal_rocm_dynamic_symbols_initialize(
       iree_allocator_system(), &symbols);
   if (!iree_status_is_ok(status)) {
-    IREE_LOG(WARNING) << "Symbols cannot be loaded, skipping test.";
+    std::cerr << "Symbols cannot be loaded, skipping test.";
     GTEST_SKIP();
   }
 
diff --git a/experimental/rocm/event_semaphore.c b/experimental/rocm/event_semaphore.c
index b05bafe..7fe6860 100644
--- a/experimental/rocm/event_semaphore.c
+++ b/experimental/rocm/event_semaphore.c
@@ -6,10 +6,12 @@
 
 #include "experimental/rocm/event_semaphore.h"
 
-#include "experimental/rocm/status_util.h"
+#include <stddef.h>
+
+#include "iree/base/api.h"
 #include "iree/base/tracing.h"
 
-typedef struct {
+typedef struct iree_hal_rocm_semaphore_t {
   iree_hal_resource_t resource;
   iree_hal_rocm_context_wrapper_t *context;
   uint64_t initial_value;
diff --git a/experimental/rocm/event_semaphore.h b/experimental/rocm/event_semaphore.h
index 87ca683..5f32492 100644
--- a/experimental/rocm/event_semaphore.h
+++ b/experimental/rocm/event_semaphore.h
@@ -7,8 +7,11 @@
 #ifndef IREE_HAL_ROCM_SEMAPHORE_H_
 #define IREE_HAL_ROCM_SEMAPHORE_H_
 
+#include <stdint.h>
+
 #include "experimental/rocm/context_wrapper.h"
 #include "experimental/rocm/status_util.h"
+#include "iree/base/api.h"
 #include "iree/hal/api.h"
 
 #ifdef __cplusplus
diff --git a/experimental/rocm/executable_layout.c b/experimental/rocm/executable_layout.c
index ba88d32..6960cd2 100644
--- a/experimental/rocm/executable_layout.c
+++ b/experimental/rocm/executable_layout.c
@@ -6,10 +6,12 @@
 
 #include "experimental/rocm/executable_layout.h"
 
-#include "experimental/rocm/status_util.h"
+#include <stddef.h>
+
+#include "iree/base/api.h"
 #include "iree/base/tracing.h"
 
-typedef struct {
+typedef struct iree_hal_rocm_executable_layout_t {
   iree_hal_resource_t resource;
   iree_hal_rocm_context_wrapper_t *context;
   iree_host_size_t set_layout_count;
diff --git a/experimental/rocm/executable_layout.h b/experimental/rocm/executable_layout.h
index c0469aa..cd0fccf 100644
--- a/experimental/rocm/executable_layout.h
+++ b/experimental/rocm/executable_layout.h
@@ -8,6 +8,7 @@
 #define IREE_HAL_ROCM_EXECUTABLE_LAYOUT_H_
 
 #include "experimental/rocm/context_wrapper.h"
+#include "iree/base/api.h"
 #include "iree/hal/api.h"
 
 #ifdef __cplusplus
diff --git a/experimental/rocm/native_executable.c b/experimental/rocm/native_executable.c
index 0f1edf2..f72bd4f 100644
--- a/experimental/rocm/native_executable.c
+++ b/experimental/rocm/native_executable.c
@@ -6,7 +6,11 @@
 
 #include "experimental/rocm/native_executable.h"
 
+#include <stddef.h>
+
+#include "experimental/rocm/dynamic_symbols.h"
 #include "experimental/rocm/status_util.h"
+#include "iree/base/api.h"
 #include "iree/base/tracing.h"
 
 // flatcc schemas:
@@ -14,14 +18,14 @@
 #include "iree/schemas/rocm_executable_def_reader.h"
 #include "iree/schemas/rocm_executable_def_verifier.h"
 
-typedef struct {
+typedef struct iree_hal_rocm_native_executable_function_t {
   hipFunction_t rocm_function;
   uint32_t block_size_x;
   uint32_t block_size_y;
   uint32_t block_size_z;
 } iree_hal_rocm_native_executable_function_t;
 
-typedef struct {
+typedef struct iree_hal_rocm_native_executable_t {
   iree_hal_resource_t resource;
   iree_hal_rocm_context_wrapper_t *context;
   iree_host_size_t entry_count;
diff --git a/experimental/rocm/native_executable.h b/experimental/rocm/native_executable.h
index 0b33b33..7a9229a 100644
--- a/experimental/rocm/native_executable.h
+++ b/experimental/rocm/native_executable.h
@@ -7,8 +7,11 @@
 #ifndef IREE_HAL_ROCM_NATIVE_EXECUTABLE_H_
 #define IREE_HAL_ROCM_NATIVE_EXECUTABLE_H_
 
+#include <stdint.h>
+
 #include "experimental/rocm/context_wrapper.h"
 #include "experimental/rocm/rocm_headers.h"
+#include "iree/base/api.h"
 #include "iree/hal/api.h"
 
 #ifdef __cplusplus
diff --git a/experimental/rocm/nop_executable_cache.c b/experimental/rocm/nop_executable_cache.c
index 35ec16c..6592727 100644
--- a/experimental/rocm/nop_executable_cache.c
+++ b/experimental/rocm/nop_executable_cache.c
@@ -6,10 +6,14 @@
 
 #include "experimental/rocm/nop_executable_cache.h"
 
+#include <stdbool.h>
+#include <stddef.h>
+
 #include "experimental/rocm/native_executable.h"
+#include "iree/base/api.h"
 #include "iree/base/tracing.h"
 
-typedef struct {
+typedef struct iree_hal_rocm_nop_executable_cache_t {
   iree_hal_resource_t resource;
   iree_hal_rocm_context_wrapper_t *context;
 } iree_hal_rocm_nop_executable_cache_t;
diff --git a/experimental/rocm/nop_executable_cache.h b/experimental/rocm/nop_executable_cache.h
index 1262fea..d1b2fc1 100644
--- a/experimental/rocm/nop_executable_cache.h
+++ b/experimental/rocm/nop_executable_cache.h
@@ -8,6 +8,7 @@
 #define IREE_HAL_ROCM_NOP_EXECUTABLE_CACHE_H_
 
 #include "experimental/rocm/context_wrapper.h"
+#include "iree/base/api.h"
 #include "iree/hal/api.h"
 
 #ifdef __cplusplus
diff --git a/experimental/rocm/registration/CMakeLists.txt b/experimental/rocm/registration/CMakeLists.txt
index f184333..36042bc 100644
--- a/experimental/rocm/registration/CMakeLists.txt
+++ b/experimental/rocm/registration/CMakeLists.txt
@@ -16,8 +16,9 @@
   SRCS
     "driver_module.c"
   DEPS
+    iree::base
+    iree::base::cc
     iree::base::core_headers
-    iree::base::status
     iree::base::tracing
     iree::hal
     experimental::rocm
diff --git a/experimental/rocm/registration/driver_module.c b/experimental/rocm/registration/driver_module.c
index a9df558..2db41b4 100644
--- a/experimental/rocm/registration/driver_module.c
+++ b/experimental/rocm/registration/driver_module.c
@@ -7,9 +7,10 @@
 #include "experimental/rocm/registration/driver_module.h"
 
 #include <inttypes.h>
+#include <stddef.h>
 
 #include "experimental/rocm/api.h"
-#include "iree/base/target_platform.h"
+#include "iree/base/api.h"
 #include "iree/base/tracing.h"
 
 #define IREE_HAL_ROCM_DRIVER_ID 0x524f434d0au  // ROCM
diff --git a/experimental/rocm/registration/driver_module.h b/experimental/rocm/registration/driver_module.h
index 6c55fea..efc1a70 100644
--- a/experimental/rocm/registration/driver_module.h
+++ b/experimental/rocm/registration/driver_module.h
@@ -7,6 +7,7 @@
 #ifndef IREE_HAL_ROCM_REGISTRATION_DRIVER_MODULE_H_
 #define IREE_HAL_ROCM_REGISTRATION_DRIVER_MODULE_H_
 
+#include "iree/base/api.h"
 #include "iree/hal/api.h"
 
 #ifdef __cplusplus
diff --git a/experimental/rocm/rocm_allocator.c b/experimental/rocm/rocm_allocator.c
index c30f4f3..cccdc9f 100644
--- a/experimental/rocm/rocm_allocator.c
+++ b/experimental/rocm/rocm_allocator.c
@@ -6,11 +6,15 @@
 
 #include "experimental/rocm/rocm_allocator.h"
 
+#include <stddef.h>
+
+#include "experimental/rocm/dynamic_symbols.h"
 #include "experimental/rocm/rocm_buffer.h"
 #include "experimental/rocm/status_util.h"
+#include "iree/base/api.h"
 #include "iree/base/tracing.h"
 
-typedef struct iree_hal_rocm_allocator_s {
+typedef struct iree_hal_rocm_allocator_t {
   iree_hal_resource_t resource;
   iree_hal_rocm_context_wrapper_t *context;
 } iree_hal_rocm_allocator_t;
diff --git a/experimental/rocm/rocm_allocator.h b/experimental/rocm/rocm_allocator.h
index 1add674..a47480c 100644
--- a/experimental/rocm/rocm_allocator.h
+++ b/experimental/rocm/rocm_allocator.h
@@ -9,6 +9,7 @@
 
 #include "experimental/rocm/context_wrapper.h"
 #include "experimental/rocm/status_util.h"
+#include "iree/base/api.h"
 #include "iree/hal/api.h"
 
 #ifdef __cplusplus
diff --git a/experimental/rocm/rocm_buffer.c b/experimental/rocm/rocm_buffer.c
index 5269b4f..195e897 100644
--- a/experimental/rocm/rocm_buffer.c
+++ b/experimental/rocm/rocm_buffer.c
@@ -6,11 +6,15 @@
 
 #include "experimental/rocm/rocm_buffer.h"
 
+#include <stddef.h>
+#include <stdint.h>
+#include <string.h>
+
 #include "experimental/rocm/rocm_allocator.h"
-#include "experimental/rocm/status_util.h"
+#include "iree/base/api.h"
 #include "iree/base/tracing.h"
 
-typedef struct iree_hal_rocm_buffer_s {
+typedef struct iree_hal_rocm_buffer_t {
   iree_hal_buffer_t base;
   void *host_ptr;
   hipDeviceptr_t device_ptr;
diff --git a/experimental/rocm/rocm_buffer.h b/experimental/rocm/rocm_buffer.h
index 7e24bc7..e898630 100644
--- a/experimental/rocm/rocm_buffer.h
+++ b/experimental/rocm/rocm_buffer.h
@@ -8,6 +8,7 @@
 #define IREE_HAL_ROCM_BUFFER_H_
 
 #include "experimental/rocm/rocm_headers.h"
+#include "iree/base/api.h"
 #include "iree/hal/api.h"
 
 #ifdef __cplusplus
diff --git a/experimental/rocm/rocm_device.c b/experimental/rocm/rocm_device.c
index b84d2bc..67418f6 100644
--- a/experimental/rocm/rocm_device.c
+++ b/experimental/rocm/rocm_device.c
@@ -6,7 +6,11 @@
 
 #include "experimental/rocm/rocm_device.h"
 
-#include "experimental/rocm/api.h"
+#include <stddef.h>
+#include <stdint.h>
+#include <string.h>
+
+#include "experimental/rocm/context_wrapper.h"
 #include "experimental/rocm/descriptor_set_layout.h"
 #include "experimental/rocm/direct_command_buffer.h"
 #include "experimental/rocm/dynamic_symbols.h"
@@ -22,7 +26,7 @@
 // iree_hal_rocm_device_t
 //===----------------------------------------------------------------------===//
 
-typedef struct {
+typedef struct iree_hal_rocm_device_t {
   iree_hal_resource_t resource;
   iree_string_view_t identifier;
 
diff --git a/experimental/rocm/rocm_device.h b/experimental/rocm/rocm_device.h
index 545436d..67e2f9b 100644
--- a/experimental/rocm/rocm_device.h
+++ b/experimental/rocm/rocm_device.h
@@ -9,6 +9,7 @@
 
 #include "experimental/rocm/api.h"
 #include "experimental/rocm/dynamic_symbols.h"
+#include "iree/base/api.h"
 #include "iree/hal/api.h"
 
 #ifdef __cplusplus
diff --git a/experimental/rocm/rocm_driver.c b/experimental/rocm/rocm_driver.c
index 4bc3323..8bd8ae6 100644
--- a/experimental/rocm/rocm_driver.c
+++ b/experimental/rocm/rocm_driver.c
@@ -4,13 +4,18 @@
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 
+#include <stdint.h>
+#include <string.h>
+
 #include "experimental/rocm/api.h"
 #include "experimental/rocm/dynamic_symbols.h"
 #include "experimental/rocm/rocm_device.h"
 #include "experimental/rocm/status_util.h"
+#include "iree/base/api.h"
 #include "iree/base/tracing.h"
+#include "iree/hal/api.h"
 
-typedef struct {
+typedef struct iree_hal_rocm_driver_t {
   iree_hal_resource_t resource;
   iree_allocator_t host_allocator;
   // Identifier used for the driver in the IREE driver registry.
diff --git a/experimental/rocm/rocm_event.c b/experimental/rocm/rocm_event.c
index 2d17caa..48b20c3 100644
--- a/experimental/rocm/rocm_event.c
+++ b/experimental/rocm/rocm_event.c
@@ -6,11 +6,13 @@
 
 #include "experimental/rocm/rocm_event.h"
 
-#include "experimental/rocm/status_util.h"
+#include <stddef.h>
+
+#include "iree/base/api.h"
 #include "iree/base/tracing.h"
 
 // Dummy events for now, don't do anything.
-typedef struct {
+typedef struct iree_hal_rocm_event_t {
   iree_hal_resource_t resource;
   iree_hal_rocm_context_wrapper_t *context_wrapper;
 } iree_hal_rocm_event_t;
diff --git a/experimental/rocm/rocm_event.h b/experimental/rocm/rocm_event.h
index 6c1ece6..73041a4 100644
--- a/experimental/rocm/rocm_event.h
+++ b/experimental/rocm/rocm_event.h
@@ -9,6 +9,7 @@
 
 #include "experimental/rocm/context_wrapper.h"
 #include "experimental/rocm/rocm_headers.h"
+#include "iree/base/api.h"
 #include "iree/hal/api.h"
 
 #ifdef __cplusplus
diff --git a/experimental/rocm/rocm_headers.h b/experimental/rocm/rocm_headers.h
index 056e8c0..6f5da96 100644
--- a/experimental/rocm/rocm_headers.h
+++ b/experimental/rocm/rocm_headers.h
@@ -11,6 +11,6 @@
 #error 32-bit not supported on ROCm
 #endif  // defined(IREE_PTR_SIZE_32)
 
-#include "hip/hip_runtime.h"
+#include "hip/hip_runtime.h"  // IWYU pragma: export
 
 #endif  // IREE_HAL_ROCM_ROCM_HEADERS_H_
diff --git a/experimental/rocm/status_util.c b/experimental/rocm/status_util.c
index e1b6fd6..a084c3f 100644
--- a/experimental/rocm/status_util.c
+++ b/experimental/rocm/status_util.c
@@ -6,6 +6,8 @@
 
 #include "experimental/rocm/status_util.h"
 
+#include <stddef.h>
+
 #include "experimental/rocm/dynamic_symbols.h"
 
 iree_status_t iree_hal_rocm_result_to_status(
diff --git a/experimental/rocm/status_util.h b/experimental/rocm/status_util.h
index 31e9404..b459591 100644
--- a/experimental/rocm/status_util.h
+++ b/experimental/rocm/status_util.h
@@ -7,6 +7,8 @@
 #ifndef IREE_HAL_ROCM_STATUS_UTIL_H_
 #define IREE_HAL_ROCM_STATUS_UTIL_H_
 
+#include <stdint.h>
+
 #include "experimental/rocm/dynamic_symbols.h"
 #include "iree/base/api.h"
 
diff --git a/iree/compiler/Dialect/HAL/Target/ROCM/ROCMTarget.cpp b/iree/compiler/Dialect/HAL/Target/ROCM/ROCMTarget.cpp
index 9457a92..584f6d0 100644
--- a/iree/compiler/Dialect/HAL/Target/ROCM/ROCMTarget.cpp
+++ b/iree/compiler/Dialect/HAL/Target/ROCM/ROCMTarget.cpp
@@ -39,8 +39,13 @@
       llvm::cl::desc("Whether to try Linking to AMD Bitcodes"),
       llvm::cl::init(false));
 
+  static llvm::cl::opt<std::string> clROCMBitcodeDir(
+      "iree-rocm-bc-dir", llvm::cl::desc("Directory of ROCM Bitcode"),
+      llvm::cl::init("/opt/rocm/amdgcn/bitcode"));
+
   targetOptions.ROCMTargetChip = clROCMTargetChip;
   targetOptions.ROCMLinkBC = clROCMLinkBC;
+  targetOptions.ROCMBitcodeDir = clROCMBitcodeDir;
 
   return targetOptions;
 }
@@ -150,7 +155,8 @@
 
     // Link module to Device Library
     if (options_.ROCMLinkBC)
-      LinkROCDLIfNecessary(llvmModule.get(), options_.ROCMTargetChip);
+      LinkROCDLIfNecessary(llvmModule.get(), options_.ROCMTargetChip,
+                           options_.ROCMBitcodeDir);
 
     // Serialize hsaco kernel into the binary that we will embed in the
     // final flatbuffer.
diff --git a/iree/compiler/Dialect/HAL/Target/ROCM/ROCMTarget.h b/iree/compiler/Dialect/HAL/Target/ROCM/ROCMTarget.h
index 5a28c06..d4aa445 100644
--- a/iree/compiler/Dialect/HAL/Target/ROCM/ROCMTarget.h
+++ b/iree/compiler/Dialect/HAL/Target/ROCM/ROCMTarget.h
@@ -20,6 +20,8 @@
   std::string ROCMTargetChip;
   // Whether to try Linking to AMD Bitcodes
   bool ROCMLinkBC;
+  // AMD Bitcodes Directory
+  std::string ROCMBitcodeDir;
 };
 
 ROCMTargetOptions getROCMTargetOptionsFromFlags();
@@ -29,7 +31,8 @@
     std::function<ROCMTargetOptions()> queryOptions);
 
 // Links LLVM module to ROC Device Library Bit Code
-void LinkROCDLIfNecessary(llvm::Module *module, std::string targetChip);
+void LinkROCDLIfNecessary(llvm::Module *module, std::string targetChip,
+                          std::string bitCodeDir);
 
 // Compiles ISAToHsaco Code
 std::string createHsaco(const std::string isa, StringRef name);
diff --git a/iree/compiler/Dialect/HAL/Target/ROCM/ROCMTargetUtils.cpp b/iree/compiler/Dialect/HAL/Target/ROCM/ROCMTargetUtils.cpp
index d4b798b..37a605b 100644
--- a/iree/compiler/Dialect/HAL/Target/ROCM/ROCMTargetUtils.cpp
+++ b/iree/compiler/Dialect/HAL/Target/ROCM/ROCMTargetUtils.cpp
@@ -90,7 +90,8 @@
   return success();
 }
 
-static std::vector<std::string> GetROCDLPaths(std::string targetChip) {
+static std::vector<std::string> GetROCDLPaths(std::string targetChip,
+                                              std::string bitCodeDir) {
   // AMDGPU bitcodes.
   int lenOfChipPrefix = 3;
   std::string chipId = targetChip.substr(lenOfChipPrefix);
@@ -101,22 +102,22 @@
                                     "oclc_daz_opt_off.bc", chip_isa_bc});
 
   // Construct full path to ROCDL bitcode libraries.
-  std::string rocdl_dir_path = "/opt/rocm/amdgcn/bitcode";
   std::vector<std::string> result;
   std::string app = "/";
   for (auto &filename : *rocdl_filenames) {
-    result.push_back(rocdl_dir_path + app + filename);
+    result.push_back(bitCodeDir + app + filename);
   }
   return result;
 }
 
 // Links ROCm-Device-Libs into the given module if the module needs it.
-void LinkROCDLIfNecessary(llvm::Module *module, std::string targetChip) {
+void LinkROCDLIfNecessary(llvm::Module *module, std::string targetChip,
+                          std::string bitCodeDir) {
   if (!HAL::CouldNeedDeviceBitcode(*module)) {
     return;
   }
-  if (!succeeded(
-          HAL::LinkWithBitcodeVector(module, GetROCDLPaths(targetChip)))) {
+  if (!succeeded(HAL::LinkWithBitcodeVector(
+          module, GetROCDLPaths(targetChip, bitCodeDir)))) {
     llvm::WithColor::error(llvm::errs()) << "Fail to Link ROCDL.\n";
   };
 }