Fix documentation to build TensorFlow against a local LLVM repository
PiperOrigin-RevId: 438154649
diff --git a/tensorflow/compiler/mlir/README.md b/tensorflow/compiler/mlir/README.md
index c415edc..02001d8 100644
--- a/tensorflow/compiler/mlir/README.md
+++ b/tensorflow/compiler/mlir/README.md
@@ -18,22 +18,28 @@
### Using local LLVM repo
To develop across MLIR core and TensorFlow, it is useful to override the repo
-to use a local version instead of fetching from head. This can be achieved as
-below but note, the BUILD files are not automatically generated from or CMake
-used, so if your change requires a BUILD file change (or you are using a
-different version of LLVM than set in tensorflow/workspace.bzl's LLVM_COMMIT)
-then manual BUILD file changes may be required.
+to use a local version instead of fetching from head. This can be achieved by
+setting up your local repository for Bazel build. For this you will need a
+temporary directory that will be "overlaid" with you LLVM source directory and
+the Bazel files:
```sh
-LLVM_SRC=...
+LLVM_SRC=... # this the path to the LLVM local source directory you intend to use.
+LLVM_BAZEL_OVERLAY=${LLVM_SRC}/bazel # Note: this can be anywhere
+mkdir -p ${LLVM_BAZEL_OVERLAY}
+# This will symlink your LLVM sources with the BUILD files to be usable by Bazel.
+python ${LLVM_SRC}/utils/bazel/overlay_directories.py \
+ --src ${LLVM_SRC} \
+ --overlay ${LLVM_SRC}/utils/bazel/llvm-project-overlay/ \
+ --target ${LLVM_BAZEL_OVERLAY}
+touch ${LLVM_BAZEL_OVERLAY}/BUILD.bazel ${LLVM_BAZEL_OVERLAY}/WORKSPACE
+# The complete list is "AArch64", "AMDGPU", "ARM", "NVPTX", "PowerPC", "RISCV", "SystemZ", "X86"
+echo 'llvm_targets = ["X86"]' > ${LLVM_BAZEL_OVERLAY}/llvm/targets.bzl
+```
-# Create basic workspace file
-echo 'workspace(name = "llvm-project")' > $LLVM_SRC/WORKSPACE
-# and copy over the bazel BUILD files.
-cp third_party/llvm/llvm.autogenerated.BUILD $LLVM_SRC/llvm/BUILD
-cp third_party/mlir/BUILD $LLVM_SRC/mlir
-cp third_party/mlir/test.BUILD $LLVM_SRC/mlir/test/BUILD
+You can then use this overlay to build TensorFlow:
-bazel build --override_repository=llvm-project=$LLVM_SRC \
+```
+bazel build --override_repository=llvm-project=$LLVM_BAZEL_OVERLAY \
-c opt tensorflow/compiler/mlir:tf-opt
```