Migrate to td_library (#6449)

This encapsulates includes and dependencies within a rule.
diff --git a/build_tools/bazel/iree_tablegen_doc.bzl b/build_tools/bazel/iree_tablegen_doc.bzl
index 2fe91d8..225b763 100644
--- a/build_tools/bazel/iree_tablegen_doc.bzl
+++ b/build_tools/bazel/iree_tablegen_doc.bzl
@@ -4,7 +4,7 @@
 # See https://llvm.org/LICENSE.txt for license information.
 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 
-load("//build_tools/bazel:tblgen.bzl", "gentbl_cc_library")
+load("//build_tools/bazel:tblgen.bzl", "gentbl_filegroup")
 
 def iree_tablegen_doc(*args, **kwargs):
     """iree_tablegen_doc() generates documentation from a table definition file.
@@ -13,5 +13,4 @@
     documentation and others. See gentbl() for details regarding arguments.
     """
 
-    # TODO(gcmn): consider using gentbl_filegroup instead
-    gentbl_cc_library(*args, **kwargs)
+    gentbl_filegroup(*args, **kwargs)
diff --git a/build_tools/bazel_to_cmake/bazel_to_cmake_converter.py b/build_tools/bazel_to_cmake/bazel_to_cmake_converter.py
index 32351ca..d5bf21b 100644
--- a/build_tools/bazel_to_cmake/bazel_to_cmake_converter.py
+++ b/build_tools/bazel_to_cmake/bazel_to_cmake_converter.py
@@ -228,6 +228,9 @@
   def exports_files(self, *args, **kwargs):
     pass
 
+  def td_library(self, *args, **kwargs):
+    pass
+
   # Technically we could do something with a CMake equivalent but we have no use
   # case.
   def py_binary(self, *args, **kwargs):
@@ -238,14 +241,9 @@
     # attribute and pass them along to any targets that depend on the filegroup.
     # Cross-package dependencies and complicated globs could be hard to handle.
 
-    # We have a bunch of filegroups that just contain TD files. CMake doesn't
-    # model this at all, so we'll just hardcode this special case.
-    # TODO(gcmn): Handle this robustly
-    if name == "td_files":
-      return
-
     self._convert_unimplemented_function("filegroup", name)
 
+
   def sh_binary(self, name, **kwargs):
     self._convert_unimplemented_function("sh_binary", name)
 
@@ -475,7 +473,8 @@
                         td_file,
                         tbl_outs,
                         td_srcs=None,
-                        td_includes=None,
+                        deps=None,
+                        includes=None,
                         strip_include_prefix=None,
                         test=None):
     name_block = _convert_string_arg_block("NAME", name, quote=False)
@@ -496,8 +495,9 @@
                         td_file,
                         tbl_outs,
                         td_srcs=None,
-                        td_includes=None,
-                        strip_include_prefix=None):
+                        includes=None,
+                        deps=None,
+                        test=None):
     name_block = _convert_string_arg_block("NAME", name, quote=False)
     tblgen_block = _convert_tblgen_block(tblgen)
     td_file_block = _convert_td_file_block(td_file)
diff --git a/iree/compiler/Codegen/BUILD b/iree/compiler/Codegen/BUILD
index 7034811..e68856b 100644
--- a/iree/compiler/Codegen/BUILD
+++ b/iree/compiler/Codegen/BUILD
@@ -22,9 +22,7 @@
     ],
     tblgen = "@llvm-project//mlir:mlir-tblgen",
     td_file = "Passes.td",
-    td_srcs = [
-        "@llvm-project//mlir:PassBaseTdFiles",
-    ],
+    deps = ["@llvm-project//mlir:PassBaseTdFiles"],
 )
 
 cc_library(
diff --git a/iree/compiler/Codegen/Common/BUILD b/iree/compiler/Codegen/Common/BUILD
index 6e6b5c7..c9e7290 100644
--- a/iree/compiler/Codegen/Common/BUILD
+++ b/iree/compiler/Codegen/Common/BUILD
@@ -22,9 +22,9 @@
     ],
     tblgen = "@llvm-project//mlir:mlir-tblgen",
     td_file = "FoldTensorExtractOp.td",
-    td_srcs = [
-        "@llvm-project//mlir:OpBaseTdFiles",
+    deps = [
         "@llvm-project//mlir:MemRefOpsTdFiles",
+        "@llvm-project//mlir:OpBaseTdFiles",
         "@llvm-project//mlir:TensorOpsTdFiles",
     ],
 )
diff --git a/iree/compiler/Dialect/Flow/IR/BUILD b/iree/compiler/Dialect/Flow/IR/BUILD
index e1cbe54..1e89071 100644
--- a/iree/compiler/Dialect/Flow/IR/BUILD
+++ b/iree/compiler/Dialect/Flow/IR/BUILD
@@ -5,7 +5,7 @@
 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 
 load("//build_tools/bazel:iree_tablegen_doc.bzl", "iree_tablegen_doc")
-load("//build_tools/bazel:tblgen.bzl", "gentbl_cc_library")
+load("//build_tools/bazel:tblgen.bzl", "gentbl_cc_library", "td_library")
 load("//build_tools/bazel:enforce_glob.bzl", "enforce_glob")
 
 package(
@@ -14,7 +14,7 @@
     licenses = ["notice"],  # Apache 2.0
 )
 
-filegroup(
+td_library(
     name = "td_files",
     srcs = enforce_glob(
         [
@@ -24,6 +24,15 @@
         ],
         include = ["*.td"],
     ),
+    deps = [
+        "//iree/compiler/Dialect/IREE/IR:td_files",
+        "//iree/compiler/Dialect/Shape/IR:td_files",
+        "@llvm-project//mlir:InferTypeOpInterfaceTdFiles",
+        "@llvm-project//mlir:OpBaseTdFiles",
+        "@llvm-project//mlir:SideEffectTdFiles",
+        "@llvm-project//mlir:StdOpsTdFiles",
+        "@llvm-project//mlir:ViewLikeInterfaceTdFiles",
+    ],
 )
 
 cc_library(
@@ -80,15 +89,7 @@
     ],
     tblgen = "@llvm-project//mlir:mlir-tblgen",
     td_file = "FlowBase.td",
-    td_srcs = [
-        ":td_files",
-        "//iree/compiler/Dialect/IREE/IR:td_files",
-        "//iree/compiler/Dialect/Shape/IR:td_files",
-        "@llvm-project//mlir:OpBaseTdFiles",
-        "@llvm-project//mlir:StdOpsTdFiles",
-        "@llvm-project//mlir:ViewLikeInterfaceTdFiles",
-        "@llvm-project//mlir:include/mlir/Interfaces/InferTypeOpInterface.td",
-    ],
+    deps = [":td_files"],
 )
 
 gentbl_cc_library(
@@ -105,15 +106,7 @@
     ],
     tblgen = "@llvm-project//mlir:mlir-tblgen",
     td_file = "FlowInterfaces.td",
-    td_srcs = [
-        ":td_files",
-        "//iree/compiler/Dialect/IREE/IR:td_files",
-        "//iree/compiler/Dialect/Shape/IR:td_files",
-        "@llvm-project//mlir:OpBaseTdFiles",
-        "@llvm-project//mlir:StdOpsTdFiles",
-        "@llvm-project//mlir:ViewLikeInterfaceTdFiles",
-        "@llvm-project//mlir:include/mlir/Interfaces/InferTypeOpInterface.td",
-    ],
+    deps = [":td_files"],
 )
 
 gentbl_cc_library(
@@ -130,16 +123,7 @@
     ],
     tblgen = "@llvm-project//mlir:mlir-tblgen",
     td_file = "FlowOps.td",
-    td_srcs = [
-        ":td_files",
-        "//iree/compiler/Dialect/IREE/IR:td_files",
-        "//iree/compiler/Dialect/Shape/IR:td_files",
-        "@llvm-project//mlir:OpBaseTdFiles",
-        "@llvm-project//mlir:SideEffectTdFiles",
-        "@llvm-project//mlir:StdOpsTdFiles",
-        "@llvm-project//mlir:ViewLikeInterfaceTdFiles",
-        "@llvm-project//mlir:include/mlir/Interfaces/InferTypeOpInterface.td",
-    ],
+    deps = [":td_files"],
 )
 
 iree_tablegen_doc(
@@ -152,14 +136,5 @@
     ],
     tblgen = "@llvm-project//mlir:mlir-tblgen",
     td_file = "FlowOps.td",
-    td_srcs = [
-        ":td_files",
-        "//iree/compiler/Dialect/IREE/IR:td_files",
-        "//iree/compiler/Dialect/Shape/IR:td_files",
-        "@llvm-project//mlir:OpBaseTdFiles",
-        "@llvm-project//mlir:SideEffectTdFiles",
-        "@llvm-project//mlir:StdOpsTdFiles",
-        "@llvm-project//mlir:ViewLikeInterfaceTdFiles",
-        "@llvm-project//mlir:include/mlir/Interfaces/InferTypeOpInterface.td",
-    ],
+    deps = [":td_files"],
 )
diff --git a/iree/compiler/Dialect/Flow/Transforms/BUILD b/iree/compiler/Dialect/Flow/Transforms/BUILD
index 1fe8a58..78c3b45 100644
--- a/iree/compiler/Dialect/Flow/Transforms/BUILD
+++ b/iree/compiler/Dialect/Flow/Transforms/BUILD
@@ -23,7 +23,7 @@
     ],
     tblgen = "@llvm-project//mlir:mlir-tblgen",
     td_file = "Passes.td",
-    td_srcs = [
+    deps = [
         "@llvm-project//mlir:PassBaseTdFiles",
     ],
 )
diff --git a/iree/compiler/Dialect/HAL/IR/BUILD b/iree/compiler/Dialect/HAL/IR/BUILD
index 2f70267..5062050 100644
--- a/iree/compiler/Dialect/HAL/IR/BUILD
+++ b/iree/compiler/Dialect/HAL/IR/BUILD
@@ -5,7 +5,7 @@
 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 
 load("//build_tools/bazel:iree_tablegen_doc.bzl", "iree_tablegen_doc")
-load("//build_tools/bazel:tblgen.bzl", "gentbl_cc_library")
+load("//build_tools/bazel:tblgen.bzl", "gentbl_cc_library", "td_library")
 load("//build_tools/bazel:enforce_glob.bzl", "enforce_glob")
 
 package(
@@ -19,7 +19,7 @@
     "HALDialect.td",
 ])
 
-filegroup(
+td_library(
     name = "td_files",
     srcs = enforce_glob(
         [
@@ -31,6 +31,13 @@
         ],
         include = ["*.td"],
     ),
+    deps = [
+        "//iree/compiler/Dialect/IREE/IR:td_files",
+        "//iree/compiler/Dialect/Shape/IR:td_files",
+        "@llvm-project//mlir:OpBaseTdFiles",
+        "@llvm-project//mlir:StdOpsTdFiles",
+        "@llvm-project//mlir:ViewLikeInterfaceTdFiles",
+    ],
 )
 
 cc_library(
@@ -140,13 +147,7 @@
     ],
     tblgen = "@llvm-project//mlir:mlir-tblgen",
     td_file = "HALInterfaces.td",
-    td_srcs = [
-        ":td_files",
-        "//iree/compiler/Dialect/IREE/IR:td_files",
-        "@llvm-project//mlir:OpBaseTdFiles",
-        "@llvm-project//mlir:StdOpsTdFiles",
-        "@llvm-project//mlir:ViewLikeInterfaceTdFiles",
-    ],
+    deps = [":td_files"],
 )
 
 gentbl_cc_library(
@@ -163,15 +164,7 @@
     ],
     tblgen = "@llvm-project//mlir:mlir-tblgen",
     td_file = "HALOps.td",
-    td_srcs = [
-        ":td_files",
-        "//iree/compiler/Dialect/IREE/IR:td_files",
-        "//iree/compiler/Dialect/Shape/IR:td_files",
-        "@llvm-project//mlir:include/mlir/IR/SymbolInterfaces.td",
-        "@llvm-project//mlir:OpBaseTdFiles",
-        "@llvm-project//mlir:StdOpsTdFiles",
-        "@llvm-project//mlir:ViewLikeInterfaceTdFiles",
-    ],
+    deps = [":td_files"],
 )
 
 gentbl_cc_library(
@@ -188,11 +181,7 @@
     ],
     tblgen = "//iree/tools:iree-tblgen",
     td_file = "HALBase.td",
-    td_srcs = [
-        ":td_files",
-        "//iree/compiler/Dialect/IREE/IR:td_files",
-        "@llvm-project//mlir:OpBaseTdFiles",
-    ],
+    deps = [":td_files"],
 )
 
 gentbl_cc_library(
@@ -217,12 +206,7 @@
     ],
     tblgen = "@llvm-project//mlir:mlir-tblgen",
     td_file = "HALBase.td",
-    td_srcs = [
-        ":td_files",
-        "//iree/compiler/Dialect/IREE/IR:td_files",
-        "@llvm-project//mlir:OpBaseTdFiles",
-        "@llvm-project//mlir:StdOpsTdFiles",
-    ],
+    deps = [":td_files"],
 )
 
 iree_tablegen_doc(
@@ -235,14 +219,7 @@
     ],
     tblgen = "@llvm-project//mlir:mlir-tblgen",
     td_file = "HALOps.td",
-    td_srcs = [
-        ":td_files",
-        "//iree/compiler/Dialect/IREE/IR:td_files",
-        "//iree/compiler/Dialect/Shape/IR:td_files",
-        "@llvm-project//mlir:include/mlir/IR/SymbolInterfaces.td",
-        "@llvm-project//mlir:StdOpsTdFiles",
-        "@llvm-project//mlir:ViewLikeInterfaceTdFiles",
-    ],
+    deps = [":td_files"],
 )
 
 gentbl_cc_library(
@@ -259,11 +236,7 @@
     ],
     tblgen = "@llvm-project//mlir:mlir-tblgen",
     td_file = "LoweringConfig.td",
-    td_srcs = [
-        ":td_files",
-        "//iree/compiler/Dialect/IREE/IR:td_files",
-        "@llvm-project//mlir:OpBaseTdFiles",
-    ],
+    deps = [":td_files"],
 )
 
 gentbl_cc_library(
@@ -280,9 +253,5 @@
     ],
     tblgen = "@llvm-project//mlir:mlir-tblgen",
     td_file = "LoweringConfig.td",
-    td_srcs = [
-        ":td_files",
-        "//iree/compiler/Dialect/IREE/IR:td_files",
-        "@llvm-project//mlir:OpBaseTdFiles",
-    ],
+    deps = [":td_files"],
 )
diff --git a/iree/compiler/Dialect/IREE/IR/BUILD b/iree/compiler/Dialect/IREE/IR/BUILD
index 720f252..aabfcf9 100644
--- a/iree/compiler/Dialect/IREE/IR/BUILD
+++ b/iree/compiler/Dialect/IREE/IR/BUILD
@@ -5,7 +5,7 @@
 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 
 load("//build_tools/bazel:iree_tablegen_doc.bzl", "iree_tablegen_doc")
-load("//build_tools/bazel:tblgen.bzl", "gentbl_cc_library")
+load("//build_tools/bazel:tblgen.bzl", "gentbl_cc_library", "td_library")
 load("//build_tools/bazel:enforce_glob.bzl", "enforce_glob")
 
 package(
@@ -16,7 +16,7 @@
 
 exports_files(["IREEBase.td"])
 
-filegroup(
+td_library(
     name = "td_files",
     srcs = enforce_glob(
         [
@@ -26,6 +26,10 @@
         ],
         include = ["*.td"],
     ),
+    deps = [
+        "@llvm-project//mlir:OpBaseTdFiles",
+        "@llvm-project//mlir:SideEffectTdFiles",
+    ],
 )
 
 cc_library(
@@ -71,10 +75,7 @@
     ],
     tblgen = "@llvm-project//mlir:mlir-tblgen",
     td_file = "IREEInterfaces.td",
-    td_srcs = [
-        ":td_files",
-        "@llvm-project//mlir:OpBaseTdFiles",
-    ],
+    deps = [":td_files"],
 )
 
 gentbl_cc_library(
@@ -91,11 +92,7 @@
     ],
     tblgen = "@llvm-project//mlir:mlir-tblgen",
     td_file = "IREEOps.td",
-    td_srcs = [
-        ":td_files",
-        "@llvm-project//mlir:OpBaseTdFiles",
-        "@llvm-project//mlir:SideEffectTdFiles",
-    ],
+    deps = [":td_files"],
 )
 
 iree_tablegen_doc(
@@ -108,9 +105,5 @@
     ],
     tblgen = "@llvm-project//mlir:mlir-tblgen",
     td_file = "IREEOps.td",
-    td_srcs = [
-        ":td_files",
-        "@llvm-project//mlir:OpBaseTdFiles",
-        "@llvm-project//mlir:SideEffectTdFiles",
-    ],
+    deps = [":td_files"],
 )
diff --git a/iree/compiler/Dialect/LinalgExt/IR/BUILD b/iree/compiler/Dialect/LinalgExt/IR/BUILD
index 23c4f1e..0eb950b 100644
--- a/iree/compiler/Dialect/LinalgExt/IR/BUILD
+++ b/iree/compiler/Dialect/LinalgExt/IR/BUILD
@@ -5,7 +5,7 @@
 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 
 load("//build_tools/bazel:iree_tablegen_doc.bzl", "iree_tablegen_doc")
-load("//build_tools/bazel:tblgen.bzl", "gentbl_cc_library")
+load("//build_tools/bazel:tblgen.bzl", "gentbl_cc_library", "td_library")
 load("//build_tools/bazel:enforce_glob.bzl", "enforce_glob")
 
 package(
@@ -16,7 +16,7 @@
 
 exports_files(["LinalgExtBase.td"])
 
-filegroup(
+td_library(
     name = "td_files",
     srcs = enforce_glob(
         [
@@ -27,6 +27,11 @@
         ],
         include = ["*.td"],
     ),
+    deps = [
+        "@llvm-project//mlir:ControlFlowInterfacesTdFiles",
+        "@llvm-project//mlir:OpBaseTdFiles",
+        "@llvm-project//mlir:SideEffectTdFiles",
+    ],
 )
 
 cc_library(
@@ -76,12 +81,7 @@
     ],
     tblgen = "@llvm-project//mlir:mlir-tblgen",
     td_file = "LinalgExtOps.td",
-    td_srcs = [
-        ":td_files",
-        "@llvm-project//mlir:OpBaseTdFiles",
-        "@llvm-project//mlir:SideEffectTdFiles",
-        "@llvm-project//mlir:ControlFlowInterfacesTdFiles",
-    ],
+    deps = [":td_files"],
 )
 
 gentbl_cc_library(
@@ -98,10 +98,7 @@
     ],
     tblgen = "@llvm-project//mlir:mlir-tblgen",
     td_file = "LinalgExtInterfaces.td",
-    td_srcs = [
-        ":td_files",
-        "@llvm-project//mlir:OpBaseTdFiles",
-    ],
+    deps = [":td_files"],
 )
 
 iree_tablegen_doc(
@@ -114,12 +111,7 @@
     ],
     tblgen = "@llvm-project//mlir:mlir-tblgen",
     td_file = "LinalgExtOps.td",
-    td_srcs = [
-        ":td_files",
-        "@llvm-project//mlir:OpBaseTdFiles",
-        "@llvm-project//mlir:SideEffectTdFiles",
-        "@llvm-project//mlir:ControlFlowInterfacesTdFiles",
-    ],
+    deps = [":td_files"],
 )
 
 gentbl_cc_library(
@@ -136,9 +128,7 @@
     ],
     tblgen = "@llvm-project//mlir:mlir-tblgen",
     td_file = "TiledOpInterface.td",
-    td_srcs = [
-        "@llvm-project//mlir:OpBaseTdFiles",
-    ],
+    deps = [":td_files"],
 )
 
 cc_library(
diff --git a/iree/compiler/Dialect/LinalgExt/Transforms/BUILD b/iree/compiler/Dialect/LinalgExt/Transforms/BUILD
index e48f8ef..09e70fd 100644
--- a/iree/compiler/Dialect/LinalgExt/Transforms/BUILD
+++ b/iree/compiler/Dialect/LinalgExt/Transforms/BUILD
@@ -22,7 +22,7 @@
     ],
     tblgen = "@llvm-project//mlir:mlir-tblgen",
     td_file = "Passes.td",
-    td_srcs = [
+    deps = [
         "@llvm-project//mlir:PassBaseTdFiles",
     ],
 )
diff --git a/iree/compiler/Dialect/Modules/Check/IR/BUILD b/iree/compiler/Dialect/Modules/Check/IR/BUILD
index 36fa93c..151c20b 100644
--- a/iree/compiler/Dialect/Modules/Check/IR/BUILD
+++ b/iree/compiler/Dialect/Modules/Check/IR/BUILD
@@ -5,7 +5,7 @@
 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 
 load("//build_tools/bazel:iree_tablegen_doc.bzl", "iree_tablegen_doc")
-load("//build_tools/bazel:tblgen.bzl", "gentbl_cc_library")
+load("//build_tools/bazel:tblgen.bzl", "gentbl_cc_library", "td_library")
 load("//build_tools/bazel:enforce_glob.bzl", "enforce_glob")
 
 package(
@@ -14,12 +14,17 @@
     licenses = ["notice"],  # Apache 2.0
 )
 
-filegroup(
+td_library(
     name = "td_files",
     srcs = enforce_glob(
         ["CheckOps.td"],
         include = ["*.td"],
     ),
+    deps = [
+        "//iree/compiler/Dialect/HAL/IR:td_files",
+        "//iree/compiler/Dialect/IREE/IR:td_files",
+        "@llvm-project//mlir:OpBaseTdFiles",
+    ],
 )
 
 cc_library(
@@ -75,12 +80,7 @@
     ],
     tblgen = "@llvm-project//mlir:mlir-tblgen",
     td_file = "CheckOps.td",
-    td_srcs = [
-        ":td_files",
-        "@llvm-project//mlir:OpBaseTdFiles",
-        "//iree/compiler/Dialect/HAL/IR:td_files",
-        "//iree/compiler/Dialect/IREE/IR:td_files",
-    ],
+    deps = [":td_files"],
 )
 
 iree_tablegen_doc(
@@ -93,10 +93,5 @@
     ],
     tblgen = "@llvm-project//mlir:mlir-tblgen",
     td_file = "CheckOps.td",
-    td_srcs = [
-        ":td_files",
-        "@llvm-project//mlir:OpBaseTdFiles",
-        "//iree/compiler/Dialect/HAL/IR:td_files",
-        "//iree/compiler/Dialect/IREE/IR:td_files",
-    ],
+    deps = [":td_files"],
 )
diff --git a/iree/compiler/Dialect/Modules/VMVX/IR/BUILD b/iree/compiler/Dialect/Modules/VMVX/IR/BUILD
index 40e5dd9..f6862ce 100644
--- a/iree/compiler/Dialect/Modules/VMVX/IR/BUILD
+++ b/iree/compiler/Dialect/Modules/VMVX/IR/BUILD
@@ -5,7 +5,7 @@
 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 
 load("//build_tools/bazel:iree_tablegen_doc.bzl", "iree_tablegen_doc")
-load("//build_tools/bazel:tblgen.bzl", "gentbl_cc_library")
+load("//build_tools/bazel:tblgen.bzl", "gentbl_cc_library", "td_library")
 load("//build_tools/bazel:enforce_glob.bzl", "enforce_glob")
 
 package(
@@ -16,7 +16,7 @@
 
 exports_files(["VMLXOps.td"])
 
-filegroup(
+td_library(
     name = "td_files",
     srcs = enforce_glob(
         [
@@ -25,6 +25,12 @@
         ],
         include = ["*.td"],
     ),
+    deps = [
+        "//iree/compiler/Dialect/IREE/IR:td_files",
+        "//iree/compiler/Dialect/Shape/IR:td_files",
+        "@llvm-project//mlir:OpBaseTdFiles",
+        "@llvm-project//mlir:StdOpsTdFiles",
+    ],
 )
 
 cc_library(
@@ -94,13 +100,7 @@
     ],
     tblgen = "@llvm-project//mlir:mlir-tblgen",
     td_file = "VMVXBase.td",
-    td_srcs = [
-        ":td_files",
-        "//iree/compiler/Dialect/IREE/IR:td_files",
-        "//iree/compiler/Dialect/Shape/IR:td_files",
-        "@llvm-project//mlir:OpBaseTdFiles",
-        "@llvm-project//mlir:StdOpsTdFiles",
-    ],
+    deps = [":td_files"],
 )
 
 gentbl_cc_library(
@@ -117,13 +117,7 @@
     ],
     tblgen = "@llvm-project//mlir:mlir-tblgen",
     td_file = "VMVXOps.td",
-    td_srcs = [
-        ":td_files",
-        "//iree/compiler/Dialect/IREE/IR:td_files",
-        "//iree/compiler/Dialect/Shape/IR:td_files",
-        "@llvm-project//mlir:OpBaseTdFiles",
-        "@llvm-project//mlir:StdOpsTdFiles",
-    ],
+    deps = [":td_files"],
 )
 
 gentbl_cc_library(
@@ -140,12 +134,7 @@
     ],
     tblgen = "@llvm-project//mlir:mlir-tblgen",
     td_file = "VMVXBase.td",
-    td_srcs = [
-        ":td_files",
-        "//iree/compiler/Dialect/IREE/IR:td_files",
-        "//iree/compiler/Dialect/Shape/IR:td_files",
-        "@llvm-project//mlir:OpBaseTdFiles",
-    ],
+    deps = [":td_files"],
 )
 
 iree_tablegen_doc(
@@ -158,11 +147,5 @@
     ],
     tblgen = "@llvm-project//mlir:mlir-tblgen",
     td_file = "VMVXOps.td",
-    td_srcs = [
-        ":td_files",
-        "//iree/compiler/Dialect/IREE/IR:td_files",
-        "//iree/compiler/Dialect/Shape/IR:td_files",
-        "@llvm-project//mlir:OpBaseTdFiles",
-        "@llvm-project//mlir:StdOpsTdFiles",
-    ],
+    deps = [":td_files"],
 )
diff --git a/iree/compiler/Dialect/Shape/IR/BUILD b/iree/compiler/Dialect/Shape/IR/BUILD
index d457555..dda59d4 100644
--- a/iree/compiler/Dialect/Shape/IR/BUILD
+++ b/iree/compiler/Dialect/Shape/IR/BUILD
@@ -5,7 +5,7 @@
 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 
 load("//build_tools/bazel:iree_tablegen_doc.bzl", "iree_tablegen_doc")
-load("//build_tools/bazel:tblgen.bzl", "gentbl_cc_library")
+load("//build_tools/bazel:tblgen.bzl", "gentbl_cc_library", "td_library")
 load("//build_tools/bazel:enforce_glob.bzl", "enforce_glob")
 
 package(
@@ -16,7 +16,7 @@
 
 exports_files(["ShapeBase.td"])
 
-filegroup(
+td_library(
     name = "td_files",
     srcs = enforce_glob(
         [
@@ -26,6 +26,14 @@
         ],
         include = ["*.td"],
     ),
+    deps = [
+        "//iree/compiler/Dialect/IREE/IR:td_files",
+        "@llvm-project//mlir:InferTypeOpInterfaceTdFiles",
+        "@llvm-project//mlir:OpBaseTdFiles",
+        "@llvm-project//mlir:SideEffectTdFiles",
+        "@llvm-project//mlir:StdOpsTdFiles",
+        "@llvm-project//mlir:ViewLikeInterfaceTdFiles",
+    ],
 )
 
 cc_library(
@@ -82,12 +90,7 @@
     ],
     tblgen = "@llvm-project//mlir:mlir-tblgen",
     td_file = "ShapeInterfaces.td",
-    td_srcs = [
-        ":td_files",
-        "@llvm-project//mlir:OpBaseTdFiles",
-        "@llvm-project//mlir:StdOpsTdFiles",
-        "@llvm-project//mlir:include/mlir/Interfaces/InferTypeOpInterface.td",
-    ],
+    deps = [":td_files"],
 )
 
 gentbl_cc_library(
@@ -104,15 +107,7 @@
     ],
     tblgen = "@llvm-project//mlir:mlir-tblgen",
     td_file = "ShapeOps.td",
-    td_srcs = [
-        ":td_files",
-        "//iree/compiler/Dialect/IREE/IR:td_files",
-        "@llvm-project//mlir:OpBaseTdFiles",
-        "@llvm-project//mlir:include/mlir/Interfaces/InferTypeOpInterface.td",
-        "@llvm-project//mlir:SideEffectTdFiles",
-        "@llvm-project//mlir:include/mlir/Interfaces/ViewLikeInterface.td",
-        "@llvm-project//mlir:include/mlir/IR/OpAsmInterface.td",
-    ],
+    deps = [":td_files"],
 )
 
 iree_tablegen_doc(
@@ -125,13 +120,5 @@
     ],
     tblgen = "@llvm-project//mlir:mlir-tblgen",
     td_file = "ShapeOps.td",
-    td_srcs = [
-        ":td_files",
-        "//iree/compiler/Dialect/IREE/IR:td_files",
-        "@llvm-project//mlir:OpBaseTdFiles",
-        "@llvm-project//mlir:include/mlir/Interfaces/InferTypeOpInterface.td",
-        "@llvm-project//mlir:SideEffectTdFiles",
-        "@llvm-project//mlir:include/mlir/Interfaces/ViewLikeInterface.td",
-        "@llvm-project//mlir:include/mlir/IR/OpAsmInterface.td",
-    ],
+    deps = [":td_files"],
 )
diff --git a/iree/compiler/Dialect/VM/IR/BUILD b/iree/compiler/Dialect/VM/IR/BUILD
index 4d3a592..82a1b1e 100644
--- a/iree/compiler/Dialect/VM/IR/BUILD
+++ b/iree/compiler/Dialect/VM/IR/BUILD
@@ -5,7 +5,7 @@
 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 
 load("//build_tools/bazel:iree_tablegen_doc.bzl", "iree_tablegen_doc")
-load("//build_tools/bazel:tblgen.bzl", "gentbl_cc_library")
+load("//build_tools/bazel:tblgen.bzl", "gentbl_cc_library", "td_library")
 load("//build_tools/bazel:enforce_glob.bzl", "enforce_glob")
 
 package(
@@ -16,7 +16,7 @@
 
 exports_files(["VMOps.td"])
 
-filegroup(
+td_library(
     name = "td_files",
     srcs = enforce_glob(
         [
@@ -29,6 +29,13 @@
         ],
         include = ["*.td"],
     ),
+    deps = [
+        "//iree/compiler/Dialect/IREE/IR:td_files",
+        "@llvm-project//mlir:CallInterfacesTdFiles",
+        "@llvm-project//mlir:ControlFlowInterfacesTdFiles",
+        "@llvm-project//mlir:OpBaseTdFiles",
+        "@llvm-project//mlir:SideEffectTdFiles",
+    ],
 )
 
 cc_library(
@@ -87,12 +94,7 @@
     ],
     tblgen = "@llvm-project//mlir:mlir-tblgen",
     td_file = "VMBase.td",
-    td_srcs = [
-        ":td_files",
-        "//iree/compiler/Dialect/IREE/IR:td_files",
-        "@llvm-project//mlir:OpBaseTdFiles",
-        "@llvm-project//mlir:include/mlir/IR/SymbolInterfaces.td",
-    ],
+    deps = [":td_files"],
 )
 
 gentbl_cc_library(
@@ -109,15 +111,7 @@
     ],
     tblgen = "@llvm-project//mlir:mlir-tblgen",
     td_file = "VMOps.td",
-    td_srcs = [
-        ":td_files",
-        "//iree/compiler/Dialect/IREE/IR:td_files",
-        "@llvm-project//mlir:OpBaseTdFiles",
-        "@llvm-project//mlir:include/mlir/IR/SymbolInterfaces.td",
-        "@llvm-project//mlir:include/mlir/Interfaces/CallInterfaces.td",
-        "@llvm-project//mlir:include/mlir/Interfaces/ControlFlowInterfaces.td",
-        "@llvm-project//mlir:SideEffectTdFiles",
-    ],
+    deps = [":td_files"],
 )
 
 gentbl_cc_library(
@@ -130,15 +124,7 @@
     ],
     tblgen = "//iree/tools:iree-tblgen",
     td_file = "VMOps.td",
-    td_srcs = [
-        ":td_files",
-        "//iree/compiler/Dialect/IREE/IR:td_files",
-        "@llvm-project//mlir:OpBaseTdFiles",
-        "@llvm-project//mlir:include/mlir/IR/SymbolInterfaces.td",
-        "@llvm-project//mlir:include/mlir/Interfaces/CallInterfaces.td",
-        "@llvm-project//mlir:include/mlir/Interfaces/ControlFlowInterfaces.td",
-        "@llvm-project//mlir:SideEffectTdFiles",
-    ],
+    deps = [":td_files"],
 )
 
 gentbl_cc_library(
@@ -155,11 +141,7 @@
     ],
     tblgen = "@llvm-project//mlir:mlir-tblgen",
     td_file = "VMBase.td",
-    td_srcs = [
-        ":td_files",
-        "//iree/compiler/Dialect/IREE/IR:td_files",
-        "@llvm-project//mlir:OpBaseTdFiles",
-    ],
+    deps = [":td_files"],
 )
 
 gentbl_cc_library(
@@ -176,11 +158,7 @@
     ],
     tblgen = "//iree/tools:iree-tblgen",
     td_file = "VMBase.td",
-    td_srcs = [
-        ":td_files",
-        "//iree/compiler/Dialect/IREE/IR:td_files",
-        "@llvm-project//mlir:OpBaseTdFiles",
-    ],
+    deps = [":td_files"],
 )
 
 iree_tablegen_doc(
@@ -193,13 +171,5 @@
     ],
     tblgen = "@llvm-project//mlir:mlir-tblgen",
     td_file = "VMOps.td",
-    td_srcs = [
-        ":td_files",
-        "//iree/compiler/Dialect/IREE/IR:td_files",
-        "@llvm-project//mlir:OpBaseTdFiles",
-        "@llvm-project//mlir:include/mlir/IR/SymbolInterfaces.td",
-        "@llvm-project//mlir:include/mlir/Interfaces/CallInterfaces.td",
-        "@llvm-project//mlir:include/mlir/Interfaces/ControlFlowInterfaces.td",
-        "@llvm-project//mlir:SideEffectTdFiles",
-    ],
+    deps = [":td_files"],
 )
diff --git a/iree/compiler/Dialect/Vulkan/IR/BUILD b/iree/compiler/Dialect/Vulkan/IR/BUILD
index 9df9373..d7a2270 100644
--- a/iree/compiler/Dialect/Vulkan/IR/BUILD
+++ b/iree/compiler/Dialect/Vulkan/IR/BUILD
@@ -4,7 +4,7 @@
 # See https://llvm.org/LICENSE.txt for license information.
 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 
-load("//build_tools/bazel:tblgen.bzl", "gentbl_cc_library")
+load("//build_tools/bazel:tblgen.bzl", "gentbl_cc_library", "td_library")
 load("//build_tools/bazel:enforce_glob.bzl", "enforce_glob")
 
 package(
@@ -13,7 +13,7 @@
     licenses = ["notice"],  # Apache 2.0
 )
 
-filegroup(
+td_library(
     name = "td_files",
     srcs = enforce_glob(
         [
@@ -22,6 +22,7 @@
         ],
         include = ["*.td"],
     ),
+    deps = ["@llvm-project//mlir:OpBaseTdFiles"],
 )
 
 cc_library(
@@ -65,10 +66,7 @@
     ],
     tblgen = "@llvm-project//mlir:mlir-tblgen",
     td_file = "VulkanAttributes.td",
-    td_srcs = [
-        ":td_files",
-        "@llvm-project//mlir:OpBaseTdFiles",
-    ],
+    deps = [":td_files"],
 )
 
 gentbl_cc_library(
@@ -85,8 +83,5 @@
     ],
     tblgen = "@llvm-project//mlir:mlir-tblgen",
     td_file = "VulkanBase.td",
-    td_srcs = [
-        ":td_files",
-        "@llvm-project//mlir:OpBaseTdFiles",
-    ],
+    deps = [":td_files"],
 )
diff --git a/iree/compiler/InputConversion/Common/BUILD b/iree/compiler/InputConversion/Common/BUILD
index a0cecad..b10426e 100644
--- a/iree/compiler/InputConversion/Common/BUILD
+++ b/iree/compiler/InputConversion/Common/BUILD
@@ -22,7 +22,7 @@
     ],
     tblgen = "@llvm-project//mlir:mlir-tblgen",
     td_file = "Passes.td",
-    td_srcs = [
+    deps = [
         "@llvm-project//mlir:PassBaseTdFiles",
     ],
 )
diff --git a/iree/compiler/InputConversion/MHLO/BUILD b/iree/compiler/InputConversion/MHLO/BUILD
index 136e6ba..a50139d 100644
--- a/iree/compiler/InputConversion/MHLO/BUILD
+++ b/iree/compiler/InputConversion/MHLO/BUILD
@@ -22,7 +22,7 @@
     ],
     tblgen = "@llvm-project//mlir:mlir-tblgen",
     td_file = "Passes.td",
-    td_srcs = [
+    deps = [
         "@llvm-project//mlir:PassBaseTdFiles",
     ],
 )
diff --git a/iree/compiler/InputConversion/TOSA/BUILD b/iree/compiler/InputConversion/TOSA/BUILD
index 50bc1e5..8ee09a8 100644
--- a/iree/compiler/InputConversion/TOSA/BUILD
+++ b/iree/compiler/InputConversion/TOSA/BUILD
@@ -22,7 +22,7 @@
     ],
     tblgen = "@llvm-project//mlir:mlir-tblgen",
     td_file = "Passes.td",
-    td_srcs = [
+    deps = [
         "@llvm-project//mlir:PassBaseTdFiles",
     ],
 )
diff --git a/iree/samples/custom_modules/dialect/BUILD b/iree/samples/custom_modules/dialect/BUILD
index 50e2194..07bfb41 100644
--- a/iree/samples/custom_modules/dialect/BUILD
+++ b/iree/samples/custom_modules/dialect/BUILD
@@ -5,7 +5,7 @@
 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 
 load("//build_tools/embed_data:build_defs.bzl", "c_embed_data")
-load("//build_tools/bazel:tblgen.bzl", "gentbl_cc_library")
+load("//build_tools/bazel:tblgen.bzl", "gentbl_cc_library", "td_library")
 load("//build_tools/bazel:enforce_glob.bzl", "enforce_glob")
 
 package(
@@ -14,12 +14,17 @@
     licenses = ["notice"],  # Apache 2.0
 )
 
-filegroup(
+td_library(
     name = "td_files",
     srcs = enforce_glob(
         ["custom_ops.td"],
         include = ["*.td"],
     ),
+    deps = [
+        "//iree/compiler/Dialect/HAL/IR:td_files",
+        "//iree/compiler/Dialect/IREE/IR:td_files",
+        "@llvm-project//mlir:StdOpsTdFiles",
+    ],
 )
 
 cc_library(
@@ -64,12 +69,7 @@
     ],
     tblgen = "@llvm-project//mlir:mlir-tblgen",
     td_file = "custom_ops.td",
-    td_srcs = [
-        ":td_files",
-        "//iree/compiler/Dialect/IREE/IR:td_files",
-        "//iree/compiler/Dialect/HAL/IR:td_files",
-        "@llvm-project//mlir:StdOpsTdFiles",
-    ],
+    deps = [":td_files"],
 )
 
 c_embed_data(