[Mlir-commits] [mlir] 5e50dd0 - [mlir] Rework the implementation of TypeID

River Riddle llvmlistbot at llvm.org
Mon Apr 4 13:52:40 PDT 2022


Author: River Riddle
Date: 2022-04-04T13:52:26-07:00
New Revision: 5e50dd048e3a20cde5da5d7a754dfee775ef35d6

URL: https://github.com/llvm/llvm-project/commit/5e50dd048e3a20cde5da5d7a754dfee775ef35d6
DIFF: https://github.com/llvm/llvm-project/commit/5e50dd048e3a20cde5da5d7a754dfee775ef35d6.diff

LOG: [mlir] Rework the implementation of TypeID

This commit restructures how TypeID is implemented to ideally avoid
the current problems related to shared libraries. This is done by changing
the "implicit" fallback path to use the name of the type, instead of using
a static template variable (which breaks shared libraries). The major downside to this
is that it adds some additional initialization costs for the implicit path. Given the
use of type names for uniqueness in the fallback, we also no longer allow types
defined in anonymous namespaces to have an implicit TypeID. To simplify defining
an ID for these classes, a new `MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID` macro
was added to allow for explicitly defining a TypeID directly on an internal class.

To help identify when types are using the fallback, `-debug-only=typeid` can be
used to log which types are using implicit ids.

This change generally only requires changes to the test passes, which are all defined
in anonymous namespaces, and thus can't use the fallback any longer.

Differential Revision: https://reviews.llvm.org/D122775

Added: 
    mlir/lib/Support/TypeID.cpp

Modified: 
    flang/lib/Optimizer/CodeGen/CodeGen.cpp
    flang/lib/Optimizer/Transforms/ArrayValueCopy.cpp
    flang/lib/Optimizer/Transforms/MemoryAllocation.cpp
    mlir/examples/toy/Ch4/mlir/ShapeInferencePass.cpp
    mlir/examples/toy/Ch5/mlir/LowerToAffineLoops.cpp
    mlir/examples/toy/Ch5/mlir/ShapeInferencePass.cpp
    mlir/examples/toy/Ch6/mlir/LowerToAffineLoops.cpp
    mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp
    mlir/examples/toy/Ch6/mlir/ShapeInferencePass.cpp
    mlir/examples/toy/Ch7/mlir/LowerToAffineLoops.cpp
    mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp
    mlir/examples/toy/Ch7/mlir/ShapeInferencePass.cpp
    mlir/include/mlir/Conversion/SCFToGPU/SCFToGPUPass.h
    mlir/include/mlir/Pass/AnalysisManager.h
    mlir/include/mlir/Support/TypeID.h
    mlir/include/mlir/Tools/PDLL/AST/Types.h
    mlir/lib/Conversion/PassDetail.h
    mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp
    mlir/lib/Dialect/SPIRV/Transforms/UnifyAliasedResourcePass.cpp
    mlir/lib/Parser/Parser.cpp
    mlir/lib/Support/CMakeLists.txt
    mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
    mlir/lib/Tools/PDLL/AST/Types.cpp
    mlir/test/CAPI/ir.c
    mlir/test/lib/Analysis/TestAliasAnalysis.cpp
    mlir/test/lib/Analysis/TestCallGraph.cpp
    mlir/test/lib/Analysis/TestLiveness.cpp
    mlir/test/lib/Analysis/TestMatchReduction.cpp
    mlir/test/lib/Analysis/TestMemRefBoundCheck.cpp
    mlir/test/lib/Analysis/TestMemRefDependenceCheck.cpp
    mlir/test/lib/Analysis/TestMemRefStrideCalculation.cpp
    mlir/test/lib/Analysis/TestSlice.cpp
    mlir/test/lib/Conversion/FuncToLLVM/TestConvertCallOp.cpp
    mlir/test/lib/Dialect/Affine/TestAffineDataCopy.cpp
    mlir/test/lib/Dialect/Affine/TestAffineLoopParametricTiling.cpp
    mlir/test/lib/Dialect/Affine/TestAffineLoopUnswitching.cpp
    mlir/test/lib/Dialect/Affine/TestLoopFusion.cpp
    mlir/test/lib/Dialect/Affine/TestLoopMapping.cpp
    mlir/test/lib/Dialect/Affine/TestLoopPermutation.cpp
    mlir/test/lib/Dialect/Affine/TestVectorizationUtils.cpp
    mlir/test/lib/Dialect/DLTI/TestDataLayoutQuery.cpp
    mlir/test/lib/Dialect/Func/TestDecomposeCallGraphTypes.cpp
    mlir/test/lib/Dialect/GPU/TestConvertGPUKernelToCubin.cpp
    mlir/test/lib/Dialect/GPU/TestConvertGPUKernelToHsaco.cpp
    mlir/test/lib/Dialect/GPU/TestGpuMemoryPromotion.cpp
    mlir/test/lib/Dialect/GPU/TestGpuParallelLoopMapping.cpp
    mlir/test/lib/Dialect/GPU/TestGpuRewrite.cpp
    mlir/test/lib/Dialect/Linalg/TestLinalgCodegenStrategy.cpp
    mlir/test/lib/Dialect/Linalg/TestLinalgElementwiseFusion.cpp
    mlir/test/lib/Dialect/Linalg/TestLinalgFusionTransforms.cpp
    mlir/test/lib/Dialect/Linalg/TestLinalgHoisting.cpp
    mlir/test/lib/Dialect/Linalg/TestLinalgTransforms.cpp
    mlir/test/lib/Dialect/Linalg/TestPadFusion.cpp
    mlir/test/lib/Dialect/Math/TestAlgebraicSimplification.cpp
    mlir/test/lib/Dialect/Math/TestExpandTanh.cpp
    mlir/test/lib/Dialect/Math/TestPolynomialApproximation.cpp
    mlir/test/lib/Dialect/MemRef/TestComposeSubView.cpp
    mlir/test/lib/Dialect/MemRef/TestMultiBuffer.cpp
    mlir/test/lib/Dialect/SCF/TestLoopParametricTiling.cpp
    mlir/test/lib/Dialect/SCF/TestLoopUnrolling.cpp
    mlir/test/lib/Dialect/SCF/TestSCFUtils.cpp
    mlir/test/lib/Dialect/SPIRV/TestAvailability.cpp
    mlir/test/lib/Dialect/SPIRV/TestEntryPointAbi.cpp
    mlir/test/lib/Dialect/SPIRV/TestModuleCombiner.cpp
    mlir/test/lib/Dialect/Shape/TestShapeFunctions.cpp
    mlir/test/lib/Dialect/Tensor/TestTensorTransforms.cpp
    mlir/test/lib/Dialect/Test/TestDialect.cpp
    mlir/test/lib/Dialect/Test/TestPatterns.cpp
    mlir/test/lib/Dialect/Test/TestTraits.cpp
    mlir/test/lib/Dialect/Tosa/TosaTestPasses.cpp
    mlir/test/lib/Dialect/Vector/TestVectorTransforms.cpp
    mlir/test/lib/IR/TestBuiltinAttributeInterfaces.cpp
    mlir/test/lib/IR/TestDiagnostics.cpp
    mlir/test/lib/IR/TestDominance.cpp
    mlir/test/lib/IR/TestFunc.cpp
    mlir/test/lib/IR/TestInterfaces.cpp
    mlir/test/lib/IR/TestMatchers.cpp
    mlir/test/lib/IR/TestOpaqueLoc.cpp
    mlir/test/lib/IR/TestOperationEquals.cpp
    mlir/test/lib/IR/TestPrintDefUse.cpp
    mlir/test/lib/IR/TestPrintInvalid.cpp
    mlir/test/lib/IR/TestPrintNesting.cpp
    mlir/test/lib/IR/TestSideEffects.cpp
    mlir/test/lib/IR/TestSlicing.cpp
    mlir/test/lib/IR/TestSymbolUses.cpp
    mlir/test/lib/IR/TestTypes.cpp
    mlir/test/lib/IR/TestVisitors.cpp
    mlir/test/lib/IR/TestVisitorsGeneric.cpp
    mlir/test/lib/Pass/TestDynamicPipeline.cpp
    mlir/test/lib/Pass/TestPassManager.cpp
    mlir/test/lib/Reducer/MLIRTestReducer.cpp
    mlir/test/lib/Rewrite/TestPDLByteCode.cpp
    mlir/test/lib/Transforms/TestConstantFold.cpp
    mlir/test/lib/Transforms/TestControlFlowSink.cpp
    mlir/test/lib/Transforms/TestInlining.cpp
    mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
    mlir/tools/mlir-tblgen/DialectGen.cpp
    mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
    mlir/tools/mlir-tblgen/PassGen.cpp
    mlir/unittests/IR/DialectTest.cpp
    mlir/unittests/Interfaces/DataLayoutInterfacesTest.cpp
    mlir/unittests/Pass/AnalysisManagerTest.cpp
    mlir/unittests/Pass/PassManagerTest.cpp
    mlir/unittests/Transforms/Canonicalizer.cpp
    mlir/unittests/Transforms/DialectConversion.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
index de8bc84e8feb5..3c2ac9129e6f1 100644
--- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp
+++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
@@ -3391,6 +3391,8 @@ class FIRToLLVMLowering : public fir::FIRToLLVMLoweringBase<FIRToLLVMLowering> {
 struct LLVMIRLoweringPass
     : public mlir::PassWrapper<LLVMIRLoweringPass,
                                mlir::OperationPass<mlir::ModuleOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(LLVMIRLoweringPass)
+
   using Printer = fir::LLVMIRLoweringPrinter;
   LLVMIRLoweringPass(raw_ostream &output, Printer p)
       : output{output}, printer{p} {}

diff  --git a/flang/lib/Optimizer/Transforms/ArrayValueCopy.cpp b/flang/lib/Optimizer/Transforms/ArrayValueCopy.cpp
index 246eedf3a515d..0039f8377376c 100644
--- a/flang/lib/Optimizer/Transforms/ArrayValueCopy.cpp
+++ b/flang/lib/Optimizer/Transforms/ArrayValueCopy.cpp
@@ -63,6 +63,8 @@ namespace {
 /// loop-carried, then the arrays are conflict-free and no copies are required.
 class ArrayCopyAnalysis {
 public:
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(ArrayCopyAnalysis)
+
   using ConflictSetT = llvm::SmallPtrSet<mlir::Operation *, 16>;
   using UseSetT = llvm::SmallPtrSet<mlir::OpOperand *, 8>;
   using LoadMapSetsT = llvm::DenseMap<mlir::Operation *, UseSetT>;

diff  --git a/flang/lib/Optimizer/Transforms/MemoryAllocation.cpp b/flang/lib/Optimizer/Transforms/MemoryAllocation.cpp
index 408cdc6e2525f..d2a0c70575cf9 100644
--- a/flang/lib/Optimizer/Transforms/MemoryAllocation.cpp
+++ b/flang/lib/Optimizer/Transforms/MemoryAllocation.cpp
@@ -37,6 +37,8 @@ struct MemoryAllocationOptions {
 
 class ReturnAnalysis {
 public:
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(ReturnAnalysis)
+
   ReturnAnalysis(mlir::Operation *op) {
     if (auto func = mlir::dyn_cast<mlir::FuncOp>(op))
       for (mlir::Block &block : func)

diff  --git a/mlir/examples/toy/Ch4/mlir/ShapeInferencePass.cpp b/mlir/examples/toy/Ch4/mlir/ShapeInferencePass.cpp
index 8b8a55d69eabe..cf3e492989b0f 100644
--- a/mlir/examples/toy/Ch4/mlir/ShapeInferencePass.cpp
+++ b/mlir/examples/toy/Ch4/mlir/ShapeInferencePass.cpp
@@ -44,9 +44,10 @@ namespace {
 ///     d) infer the shape of its output from the argument types.
 ///   3) If the worklist is empty, the algorithm succeeded.
 ///
-class ShapeInferencePass
+struct ShapeInferencePass
     : public mlir::PassWrapper<ShapeInferencePass, OperationPass<toy::FuncOp>> {
-public:
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(ShapeInferencePass)
+
   void runOnOperation() override {
     auto f = getOperation();
 

diff  --git a/mlir/examples/toy/Ch5/mlir/LowerToAffineLoops.cpp b/mlir/examples/toy/Ch5/mlir/LowerToAffineLoops.cpp
index e459477ad7b31..000f99886b01c 100644
--- a/mlir/examples/toy/Ch5/mlir/LowerToAffineLoops.cpp
+++ b/mlir/examples/toy/Ch5/mlir/LowerToAffineLoops.cpp
@@ -310,6 +310,8 @@ struct TransposeOpLowering : public ConversionPattern {
 namespace {
 struct ToyToAffineLoweringPass
     : public PassWrapper<ToyToAffineLoweringPass, OperationPass<ModuleOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(ToyToAffineLoweringPass)
+
   void getDependentDialects(DialectRegistry &registry) const override {
     registry.insert<AffineDialect, func::FuncDialect, memref::MemRefDialect>();
   }

diff  --git a/mlir/examples/toy/Ch5/mlir/ShapeInferencePass.cpp b/mlir/examples/toy/Ch5/mlir/ShapeInferencePass.cpp
index 8b8a55d69eabe..cf3e492989b0f 100644
--- a/mlir/examples/toy/Ch5/mlir/ShapeInferencePass.cpp
+++ b/mlir/examples/toy/Ch5/mlir/ShapeInferencePass.cpp
@@ -44,9 +44,10 @@ namespace {
 ///     d) infer the shape of its output from the argument types.
 ///   3) If the worklist is empty, the algorithm succeeded.
 ///
-class ShapeInferencePass
+struct ShapeInferencePass
     : public mlir::PassWrapper<ShapeInferencePass, OperationPass<toy::FuncOp>> {
-public:
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(ShapeInferencePass)
+
   void runOnOperation() override {
     auto f = getOperation();
 

diff  --git a/mlir/examples/toy/Ch6/mlir/LowerToAffineLoops.cpp b/mlir/examples/toy/Ch6/mlir/LowerToAffineLoops.cpp
index e459477ad7b31..000f99886b01c 100644
--- a/mlir/examples/toy/Ch6/mlir/LowerToAffineLoops.cpp
+++ b/mlir/examples/toy/Ch6/mlir/LowerToAffineLoops.cpp
@@ -310,6 +310,8 @@ struct TransposeOpLowering : public ConversionPattern {
 namespace {
 struct ToyToAffineLoweringPass
     : public PassWrapper<ToyToAffineLoweringPass, OperationPass<ModuleOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(ToyToAffineLoweringPass)
+
   void getDependentDialects(DialectRegistry &registry) const override {
     registry.insert<AffineDialect, func::FuncDialect, memref::MemRefDialect>();
   }

diff  --git a/mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp b/mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp
index 83ee0104a32ab..09ef49a49bc6d 100644
--- a/mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp
+++ b/mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp
@@ -172,6 +172,8 @@ class PrintOpLowering : public ConversionPattern {
 namespace {
 struct ToyToLLVMLoweringPass
     : public PassWrapper<ToyToLLVMLoweringPass, OperationPass<ModuleOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(ToyToLLVMLoweringPass)
+
   void getDependentDialects(DialectRegistry &registry) const override {
     registry.insert<LLVM::LLVMDialect, scf::SCFDialect>();
   }

diff  --git a/mlir/examples/toy/Ch6/mlir/ShapeInferencePass.cpp b/mlir/examples/toy/Ch6/mlir/ShapeInferencePass.cpp
index 8b8a55d69eabe..cf3e492989b0f 100644
--- a/mlir/examples/toy/Ch6/mlir/ShapeInferencePass.cpp
+++ b/mlir/examples/toy/Ch6/mlir/ShapeInferencePass.cpp
@@ -44,9 +44,10 @@ namespace {
 ///     d) infer the shape of its output from the argument types.
 ///   3) If the worklist is empty, the algorithm succeeded.
 ///
-class ShapeInferencePass
+struct ShapeInferencePass
     : public mlir::PassWrapper<ShapeInferencePass, OperationPass<toy::FuncOp>> {
-public:
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(ShapeInferencePass)
+
   void runOnOperation() override {
     auto f = getOperation();
 

diff  --git a/mlir/examples/toy/Ch7/mlir/LowerToAffineLoops.cpp b/mlir/examples/toy/Ch7/mlir/LowerToAffineLoops.cpp
index e459477ad7b31..000f99886b01c 100644
--- a/mlir/examples/toy/Ch7/mlir/LowerToAffineLoops.cpp
+++ b/mlir/examples/toy/Ch7/mlir/LowerToAffineLoops.cpp
@@ -310,6 +310,8 @@ struct TransposeOpLowering : public ConversionPattern {
 namespace {
 struct ToyToAffineLoweringPass
     : public PassWrapper<ToyToAffineLoweringPass, OperationPass<ModuleOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(ToyToAffineLoweringPass)
+
   void getDependentDialects(DialectRegistry &registry) const override {
     registry.insert<AffineDialect, func::FuncDialect, memref::MemRefDialect>();
   }

diff  --git a/mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp b/mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp
index 83ee0104a32ab..09ef49a49bc6d 100644
--- a/mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp
+++ b/mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp
@@ -172,6 +172,8 @@ class PrintOpLowering : public ConversionPattern {
 namespace {
 struct ToyToLLVMLoweringPass
     : public PassWrapper<ToyToLLVMLoweringPass, OperationPass<ModuleOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(ToyToLLVMLoweringPass)
+
   void getDependentDialects(DialectRegistry &registry) const override {
     registry.insert<LLVM::LLVMDialect, scf::SCFDialect>();
   }

diff  --git a/mlir/examples/toy/Ch7/mlir/ShapeInferencePass.cpp b/mlir/examples/toy/Ch7/mlir/ShapeInferencePass.cpp
index 8b8a55d69eabe..cf3e492989b0f 100644
--- a/mlir/examples/toy/Ch7/mlir/ShapeInferencePass.cpp
+++ b/mlir/examples/toy/Ch7/mlir/ShapeInferencePass.cpp
@@ -44,9 +44,10 @@ namespace {
 ///     d) infer the shape of its output from the argument types.
 ///   3) If the worklist is empty, the algorithm succeeded.
 ///
-class ShapeInferencePass
+struct ShapeInferencePass
     : public mlir::PassWrapper<ShapeInferencePass, OperationPass<toy::FuncOp>> {
-public:
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(ShapeInferencePass)
+
   void runOnOperation() override {
     auto f = getOperation();
 

diff  --git a/mlir/include/mlir/Conversion/SCFToGPU/SCFToGPUPass.h b/mlir/include/mlir/Conversion/SCFToGPU/SCFToGPUPass.h
index c1b0eb0a60ea0..08f34b9e22f32 100644
--- a/mlir/include/mlir/Conversion/SCFToGPU/SCFToGPUPass.h
+++ b/mlir/include/mlir/Conversion/SCFToGPU/SCFToGPUPass.h
@@ -8,12 +8,12 @@
 #ifndef MLIR_CONVERSION_SCFTOGPU_SCFTOGPUPASS_H_
 #define MLIR_CONVERSION_SCFTOGPU_SCFTOGPUPASS_H_
 
+#include "mlir/IR/FunctionInterfaces.h"
 #include "mlir/Support/LLVM.h"
 
 #include <memory>
 
 namespace mlir {
-class FunctionOpInterface;
 template <typename T>
 class InterfacePass;
 class Pass;

diff  --git a/mlir/include/mlir/Pass/AnalysisManager.h b/mlir/include/mlir/Pass/AnalysisManager.h
index 9dab7b7b5950b..6a124dbc9321e 100644
--- a/mlir/include/mlir/Pass/AnalysisManager.h
+++ b/mlir/include/mlir/Pass/AnalysisManager.h
@@ -28,7 +28,7 @@ namespace detail {
 /// A utility class to represent the analyses that are known to be preserved.
 class PreservedAnalyses {
   /// A type used to represent all potential analyses.
-  struct AllAnalysesType;
+  struct AllAnalysesType {};
 
 public:
   /// Mark all analyses as preserved.

diff  --git a/mlir/include/mlir/Support/TypeID.h b/mlir/include/mlir/Support/TypeID.h
index 53b448f68b1d1..433ab12e539a1 100644
--- a/mlir/include/mlir/Support/TypeID.h
+++ b/mlir/include/mlir/Support/TypeID.h
@@ -17,14 +17,15 @@
 #include "mlir/Support/LLVM.h"
 #include "llvm/ADT/DenseMapInfo.h"
 #include "llvm/ADT/Hashing.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Allocator.h"
 #include "llvm/Support/PointerLikeTypeTraits.h"
+#include "llvm/Support/TypeName.h"
 
 namespace mlir {
-
-namespace detail {
-struct TypeIDExported;
-} // namespace detail
+//===----------------------------------------------------------------------===//
+// TypeID
+//===----------------------------------------------------------------------===//
 
 /// This class provides an efficient unique identifier for a specific C++ type.
 /// This allows for a C++ type to be compared, hashed, and stored in an opaque
@@ -50,6 +51,56 @@ struct TypeIDExported;
 ///       ...
 ///  }
 ///
+/// C++ RTTI is a notoriously 
diff icult topic; given the nature of shared
+/// libraries many 
diff erent approaches fundamentally break down in either the
+/// area of support (i.e. only certain types of classes are supported), or in
+/// terms of performance (e.g. by using string comparison). This class intends
+/// to strike a balance between performance and the setup required to enable its
+/// use.
+///
+/// Assume we are adding support for some class Foo, below are the set of ways
+/// in which a given c++ type may be supported:
+///
+///  * Explicitly via `MLIR_DECLARE_EXPLICIT_TYPE_ID` and
+///    `MLIR_DEFINE_EXPLICIT_TYPE_ID`
+///
+///    - This method explicitly defines the type ID for a given type using the
+///      given macros. These should be placed at the top-level of the file (i.e.
+///      not within any namespace or class). This is the most effective and
+///      efficient method, but requires explicit annotations for each type.
+///
+///      Example:
+///
+///        // Foo.h
+///        MLIR_DECLARE_EXPLICIT_TYPE_ID(Foo);
+///
+///        // Foo.cpp
+///        MLIR_DEFINE_EXPLICIT_TYPE_ID(Foo);
+///
+///  * Explicitly via `MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID`
+///   - This method explicitly defines the type ID for a given type by
+///     annotating the class directly. This has similar effectiveness and
+///     efficiency to the above method, but should only be used on internal
+///     classes; i.e. those with definitions constrained to a specific library
+///     (generally classes in anonymous namespaces).
+///
+///     Example:
+///
+///       namespace {
+///       class Foo {
+///       public:
+///         MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(Foo)
+///       };
+///       } // namespace
+///
+///  * Implicitly via a fallback using the type name
+///   - This method implicitly defines a type ID for a given type by using the
+///     type name. This method requires nothing explicitly from the user, but
+///     pays additional access and initialization cost. Given that this method
+///     uses the name of the type, it may not be used for types defined in
+///     anonymous namespaces (which is asserted when it can be detected). String
+///     names do not provide any guarantees on uniqueness in these contexts.
+///
 class TypeID {
   /// This class represents the storage of a type info object.
   /// Note: We specify an explicit alignment here to allow use with
@@ -91,9 +142,6 @@ class TypeID {
   /// The storage of this type info object.
   const Storage *storage;
 
-  // See TypeIDExported below for an explanation of the trampoline behavior.
-  friend struct detail::TypeIDExported;
-
   friend class TypeIDAllocator;
 };
 
@@ -102,45 +150,142 @@ inline ::llvm::hash_code hash_value(TypeID id) {
   return DenseMapInfo<const TypeID::Storage *>::getHashValue(id.storage);
 }
 
+//===----------------------------------------------------------------------===//
+// TypeIDResolver
+//===----------------------------------------------------------------------===//
+
 namespace detail {
+/// This class provides a fallback for resolving TypeIDs. It uses the string
+/// name of the type to perform the resolution, and as such does not allow the
+/// use of classes defined in "anonymous" contexts.
+class FallbackTypeIDResolver {
+protected:
+  /// Register an implicit type ID for the given type name.
+  static TypeID registerImplicitTypeID(StringRef name);
+};
+
+/// This class provides a resolver for getting the ID for a given class T. This
+/// allows for the derived type to specialize its resolution behavior. The
+/// default implementation uses the string name of the type to resolve the ID.
+/// This provides a strong definition, but at the cost of performance (we need
+/// to do an initial lookup) and is not usable by classes defined in anonymous
+/// contexts.
+///
+/// TODO: The use of the type name is only necessary when building in the
+/// presence of shared libraries. We could add a build flag that guarantees
+/// "static"-like environments and switch this to a more optimal implementation
+/// when that is enabled.
+template <typename T, typename Enable = void>
+class TypeIDResolver : public FallbackTypeIDResolver {
+public:
+  /// Trait to check if `U` is fully resolved. We use this to verify that `T` is
+  /// fully resolved when trying to resolve a TypeID. We don't technically need
+  /// to have the full definition of `T` for the fallback, but it does help
+  /// prevent situations where a forward declared type uses this fallback even
+  /// though there is a strong definition for the TypeID in the location where
+  /// `T` is defined.
+  template <typename U>
+  using is_fully_resolved_trait = decltype(sizeof(U));
+  template <typename U>
+  using is_fully_resolved = llvm::is_detected<is_fully_resolved_trait, U>;
+
+  static TypeID resolveTypeID() {
+    static_assert(is_fully_resolved<T>::value,
+                  "TypeID::get<> requires the complete definition of `T`");
+    static TypeID id = registerImplicitTypeID(llvm::getTypeName<T>());
+    return id;
+  }
+};
+
+/// This class provides utilities for resolving the TypeID of a class that
+/// provides a `static TypeID resolveTypeID()` method. This allows for
+/// simplifying situations when the class can resolve the ID itself. This
+/// functionality is separated from the corresponding `TypeIDResolver`
+/// specialization below to enable referencing it more easily in 
diff erent
+/// contexts.
+struct InlineTypeIDResolver {
+  /// Trait to check if `T` provides a static `resolveTypeID` method.
+  template <typename T>
+  using has_resolve_typeid_trait = decltype(T::resolveTypeID());
+  template <typename T>
+  using has_resolve_typeid = llvm::is_detected<has_resolve_typeid_trait, T>;
 
-/// The static local instance of each get method must be emitted with
-/// "default" (public) visibility across all shared libraries, regardless of
-/// whether they are compiled with hidden visibility or not. The only reliable
-/// way to make this happen is to set the visibility attribute at the
-/// containing namespace/struct scope. We don't do this on the TypeID (internal
-/// API) class in order to reduce the scope of what gets exported with
-/// public visibility. Instead, the get() methods on TypeID trampoline
-/// through those on this detail class with specific visibility controls
-/// applied, making visibility declarations on the internal TypeID class not
-/// required (all visibility relevant pieces are here).
-/// TODO: This currently won't work when using DLLs as it requires properly
-/// attaching dllimport and dllexport. Fix this when that information is
-/// available within LLVM.
-struct LLVM_EXTERNAL_VISIBILITY TypeIDExported {
   template <typename T>
-  static TypeID get() {
-    static TypeID::Storage instance;
-    return TypeID(&instance);
+  static TypeID resolveTypeID() {
+    return T::resolveTypeID();
   }
-  template <template <typename> class Trait>
-  static TypeID get() {
-    static TypeID::Storage instance;
-    return TypeID(&instance);
+};
+/// This class provides a resolver for getting the ID for a given class T, when
+/// the class provides a `static TypeID resolveTypeID()` method. This allows for
+/// simplifying situations when the class can resolve the ID itself.
+template <typename T>
+class TypeIDResolver<
+    T, std::enable_if_t<InlineTypeIDResolver::has_resolve_typeid<T>::value>> {
+public:
+  static TypeID resolveTypeID() {
+    return InlineTypeIDResolver::resolveTypeID<T>();
   }
 };
-
 } // namespace detail
 
 template <typename T>
 TypeID TypeID::get() {
-  return detail::TypeIDExported::get<T>();
+  return detail::TypeIDResolver<T>::resolveTypeID();
 }
 template <template <typename> class Trait>
 TypeID TypeID::get() {
-  return detail::TypeIDExported::get<Trait>();
+  // An empty class used to simplify the use of Trait types.
+  struct Empty {};
+  return TypeID::get<Trait<Empty>>();
 }
 
+// Declare/define an explicit specialization for TypeID: this forces the
+// compiler to emit a strong definition for a class and controls which
+// translation unit and shared object will actually have it.
+// This can be useful to turn to a link-time failure what would be in other
+// circumstances a hard-to-catch runtime bug when a TypeID is hidden in two
+// 
diff erent shared libraries and instances of the same class only gets the same
+// TypeID inside a given DSO.
+#define MLIR_DECLARE_EXPLICIT_TYPE_ID(CLASS_NAME)                              \
+  namespace mlir {                                                             \
+  namespace detail {                                                           \
+  template <>                                                                  \
+  class TypeIDResolver<CLASS_NAME> {                                           \
+  public:                                                                      \
+    static TypeID resolveTypeID() { return id; }                               \
+                                                                               \
+  private:                                                                     \
+    static SelfOwningTypeID id;                                                \
+  };                                                                           \
+  } /* namespace detail */                                                     \
+  } /* namespace mlir */
+
+#define MLIR_DEFINE_EXPLICIT_TYPE_ID(CLASS_NAME)                               \
+  namespace mlir {                                                             \
+  namespace detail {                                                           \
+  SelfOwningTypeID TypeIDResolver<CLASS_NAME>::id = {};                        \
+  } /* namespace detail */                                                     \
+  } /* namespace mlir */
+
+// Declare/define an explicit, **internal**, specialization of TypeID for the
+// given class. This is useful for providing an explicit specialization of
+// TypeID for a class that is known to be internal to a specific library. It
+// should be placed within a public section of the declaration of the class.
+#define MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(CLASS_NAME)               \
+  static ::mlir::TypeID resolveTypeID() {                                      \
+    static ::mlir::SelfOwningTypeID id;                                        \
+    return id;                                                                 \
+  }                                                                            \
+  static_assert(                                                               \
+      ::mlir::detail::InlineTypeIDResolver::has_resolve_typeid<                \
+          CLASS_NAME>::value,                                                  \
+      "`MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID` must be placed in a "    \
+      "public section of `" #CLASS_NAME "`");
+
+//===----------------------------------------------------------------------===//
+// TypeIDAllocator
+//===----------------------------------------------------------------------===//
+
 /// This class provides a way to define new TypeIDs at runtime.
 /// When the allocator is destructed, all allocated TypeIDs become invalid and
 /// therefore should not be used.
@@ -156,9 +301,15 @@ class TypeIDAllocator {
   llvm::SpecificBumpPtrAllocator<TypeID::Storage> ids;
 };
 
+//===----------------------------------------------------------------------===//
+// SelfOwningTypeID
+//===----------------------------------------------------------------------===//
+
 /// Defines a TypeID for each instance of this class by using a pointer to the
 /// instance. Thus, the copy and move constructor are deleted.
-class SelfOwningTypeID {
+/// Note: We align by 8 to match the alignment of TypeID::Storage, as we treat
+/// an instance of this class similarly to TypeID::Storage.
+class alignas(8) SelfOwningTypeID {
 public:
   SelfOwningTypeID() = default;
   SelfOwningTypeID(const SelfOwningTypeID &) = delete;
@@ -166,36 +317,21 @@ class SelfOwningTypeID {
   SelfOwningTypeID(SelfOwningTypeID &&) = delete;
   SelfOwningTypeID &operator=(SelfOwningTypeID &&) = delete;
 
+  /// Implicitly converts to the owned TypeID.
+  operator TypeID() const { return getTypeID(); }
+
+  /// Return the TypeID owned by this object.
   TypeID getTypeID() const { return TypeID::getFromOpaquePointer(this); }
 };
 
 } // namespace mlir
 
-// Declare/define an explicit specialization for TypeID: this forces the
-// compiler to emit a strong definition for a class and controls which
-// translation unit and shared object will actually have it.
-// This can be useful to turn to a link-time failure what would be in other
-// circumstances a hard-to-catch runtime bug when a TypeID is hidden in two
-// 
diff erent shared libraries and instances of the same class only gets the same
-// TypeID inside a given DSO.
-#define DECLARE_EXPLICIT_TYPE_ID(CLASS_NAME)                                   \
-  namespace mlir {                                                             \
-  namespace detail {                                                           \
-  template <>                                                                  \
-  LLVM_EXTERNAL_VISIBILITY TypeID TypeIDExported::get<CLASS_NAME>();           \
-  }                                                                            \
-  }
+//===----------------------------------------------------------------------===//
+// Builtin TypeIDs
+//===----------------------------------------------------------------------===//
 
-#define DEFINE_EXPLICIT_TYPE_ID(CLASS_NAME)                                    \
-  namespace mlir {                                                             \
-  namespace detail {                                                           \
-  template <>                                                                  \
-  LLVM_EXTERNAL_VISIBILITY TypeID TypeIDExported::get<CLASS_NAME>() {          \
-    static TypeID::Storage instance;                                           \
-    return TypeID(&instance);                                                  \
-  }                                                                            \
-  }                                                                            \
-  }
+/// Explicitly register a set of "builtin" types.
+MLIR_DECLARE_EXPLICIT_TYPE_ID(void)
 
 namespace llvm {
 template <> struct DenseMapInfo<mlir::TypeID> {

diff  --git a/mlir/include/mlir/Tools/PDLL/AST/Types.h b/mlir/include/mlir/Tools/PDLL/AST/Types.h
index 58a20801fb1b5..75a80b5bf92d4 100644
--- a/mlir/include/mlir/Tools/PDLL/AST/Types.h
+++ b/mlir/include/mlir/Tools/PDLL/AST/Types.h
@@ -277,6 +277,15 @@ class ValueType : public Type::TypeBase<detail::ValueTypeStorage> {
 } // namespace pdll
 } // namespace mlir
 
+MLIR_DECLARE_EXPLICIT_TYPE_ID(mlir::pdll::ast::detail::AttributeTypeStorage)
+MLIR_DECLARE_EXPLICIT_TYPE_ID(mlir::pdll::ast::detail::ConstraintTypeStorage)
+MLIR_DECLARE_EXPLICIT_TYPE_ID(mlir::pdll::ast::detail::OperationTypeStorage)
+MLIR_DECLARE_EXPLICIT_TYPE_ID(mlir::pdll::ast::detail::RangeTypeStorage)
+MLIR_DECLARE_EXPLICIT_TYPE_ID(mlir::pdll::ast::detail::RewriteTypeStorage)
+MLIR_DECLARE_EXPLICIT_TYPE_ID(mlir::pdll::ast::detail::TupleTypeStorage)
+MLIR_DECLARE_EXPLICIT_TYPE_ID(mlir::pdll::ast::detail::TypeTypeStorage)
+MLIR_DECLARE_EXPLICIT_TYPE_ID(mlir::pdll::ast::detail::ValueTypeStorage)
+
 namespace llvm {
 template <> struct DenseMapInfo<mlir::pdll::ast::Type> {
   static mlir::pdll::ast::Type getEmptyKey() {

diff  --git a/mlir/lib/Conversion/PassDetail.h b/mlir/lib/Conversion/PassDetail.h
index 8cb3166fed5b4..c6a0f56f27410 100644
--- a/mlir/lib/Conversion/PassDetail.h
+++ b/mlir/lib/Conversion/PassDetail.h
@@ -12,10 +12,10 @@
 #include "mlir/Pass/Pass.h"
 
 #include "mlir/Conversion/GPUToROCDL/Runtimes.h"
+#include "mlir/IR/FunctionInterfaces.h"
 
 namespace mlir {
 class AffineDialect;
-class FunctionOpInterface;
 
 // Forward declaration from Dialect.h
 template <typename ConcreteDialect>

diff  --git a/mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp b/mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp
index d33aa9dc931c0..c881d458afb8f 100644
--- a/mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp
+++ b/mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp
@@ -61,6 +61,8 @@ namespace {
 class SerializeToHsacoPass
     : public PassWrapper<SerializeToHsacoPass, gpu::SerializeToBlobPass> {
 public:
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(SerializeToHsacoPass)
+
   SerializeToHsacoPass(StringRef triple, StringRef arch, StringRef features,
                        int optLevel);
   SerializeToHsacoPass(const SerializeToHsacoPass &other);

diff  --git a/mlir/lib/Dialect/SPIRV/Transforms/UnifyAliasedResourcePass.cpp b/mlir/lib/Dialect/SPIRV/Transforms/UnifyAliasedResourcePass.cpp
index fa0e551f5d53e..5968cebfd3dd7 100644
--- a/mlir/lib/Dialect/SPIRV/Transforms/UnifyAliasedResourcePass.cpp
+++ b/mlir/lib/Dialect/SPIRV/Transforms/UnifyAliasedResourcePass.cpp
@@ -103,6 +103,8 @@ namespace {
 /// inside the struct.
 class ResourceAliasAnalysis {
 public:
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(ResourceAliasAnalysis)
+
   explicit ResourceAliasAnalysis(Operation *);
 
   /// Returns true if the given `op` can be rewritten to use a canonical

diff  --git a/mlir/lib/Parser/Parser.cpp b/mlir/lib/Parser/Parser.cpp
index 90d6a6c686a03..607d6bbd85f97 100644
--- a/mlir/lib/Parser/Parser.cpp
+++ b/mlir/lib/Parser/Parser.cpp
@@ -257,6 +257,10 @@ class OperationParser : public Parser {
     unsigned number; // Number, specified with #12
     SMLoc loc;       // Location of first definition or use.
   };
+  struct DeferredLocInfo {
+    SMLoc loc;
+    StringRef identifier;
+  };
 
   /// Push a new SSA name scope to the parser.
   void pushSSANameScope(bool isIsolated);
@@ -481,10 +485,6 @@ class OperationParser : public Parser {
   /// Deffered locations: when parsing `loc(#loc42)` we add an entry to this
   /// map. After parsing the definition `#loc42 = ...` we'll patch back users
   /// of this location.
-  struct DeferredLocInfo {
-    SMLoc loc;
-    StringRef identifier;
-  };
   std::vector<DeferredLocInfo> deferredLocsReferences;
 
   /// The builder used when creating parsed operation instances.
@@ -495,6 +495,9 @@ class OperationParser : public Parser {
 };
 } // namespace
 
+MLIR_DECLARE_EXPLICIT_TYPE_ID(OperationParser::DeferredLocInfo *)
+MLIR_DEFINE_EXPLICIT_TYPE_ID(OperationParser::DeferredLocInfo *)
+
 OperationParser::OperationParser(ParserState &state, ModuleOp topLevelOp)
     : Parser(state), opBuilder(topLevelOp.getRegion()), topLevelOp(topLevelOp) {
   // The top level operation starts a new name scope.

diff  --git a/mlir/lib/Support/CMakeLists.txt b/mlir/lib/Support/CMakeLists.txt
index aae02573c020f..64dd134047b9a 100644
--- a/mlir/lib/Support/CMakeLists.txt
+++ b/mlir/lib/Support/CMakeLists.txt
@@ -6,6 +6,7 @@ set(LLVM_OPTIONAL_SOURCES
   StorageUniquer.cpp
   Timing.cpp
   ToolUtilities.cpp
+  TypeID.cpp
 )
 
 add_mlir_library(MLIRSupport
@@ -16,6 +17,7 @@ add_mlir_library(MLIRSupport
   StorageUniquer.cpp
   Timing.cpp
   ToolUtilities.cpp
+  TypeID.cpp
 
   ADDITIONAL_HEADER_DIRS
   ${MLIR_MAIN_INCLUDE_DIR}/mlir/Support

diff  --git a/mlir/lib/Support/TypeID.cpp b/mlir/lib/Support/TypeID.cpp
new file mode 100644
index 0000000000000..8720706094900
--- /dev/null
+++ b/mlir/lib/Support/TypeID.cpp
@@ -0,0 +1,92 @@
+//===- TypeID.cpp - MLIR TypeID -------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "mlir/Support/TypeID.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Debug.h"
+#include "llvm/Support/RWMutex.h"
+
+#include "llvm/Support/Signals.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace mlir;
+
+#define DEBUG_TYPE "typeid"
+
+//===----------------------------------------------------------------------===//
+// TypeID Registry
+//===----------------------------------------------------------------------===//
+
+namespace {
+struct ImplicitTypeIDRegistry {
+  /// Lookup or insert a TypeID for the given type name.
+  TypeID lookupOrInsert(StringRef typeName) {
+    LLVM_DEBUG(llvm::dbgs() << "ImplicitTypeIDRegistry::lookupOrInsert("
+                            << typeName << ")\n");
+
+    // Perform a heuristic check to see if this type is in an anonymous
+    // namespace. String equality is not valid for anonymous types, so we try to
+    // abort whenever we see them.
+#ifndef NDEBUG
+#if defined(_MSC_VER)
+    if (typeName.contains("anonymous-namespace")) {
+#else
+    if (typeName.contains("anonymous namespace")) {
+#endif
+      std::string errorStr;
+      {
+        llvm::raw_string_ostream errorOS(errorStr);
+        errorOS << "TypeID::get<" << typeName
+                << ">(): Using TypeID on a class with an anonymous "
+                   "namespace requires an explicit TypeID definition. The "
+                   "implicit fallback uses string name, which does not "
+                   "guarantee uniqueness in anonymous contexts. Define an "
+                   "explicit TypeID instantiation for this type using "
+                   "`MLIR_DECLARE_EXPLICIT_TYPE_ID`/"
+                   "`MLIR_DEFINE_EXPLICIT_TYPE_ID` or "
+                   "`DEFINE_EXPLICIT_PRIVATE_INLINE_TYPE_ID`.\n";
+      }
+      llvm::report_fatal_error(errorStr);
+    }
+#endif
+
+    { // Try a read-only lookup first.
+      llvm::sys::SmartScopedReader<true> guard(mutex);
+      auto it = typeNameToID.find(typeName);
+      if (it != typeNameToID.end())
+        return it->second;
+    }
+    llvm::sys::SmartScopedWriter<true> guard(mutex);
+    auto it = typeNameToID.try_emplace(typeName, TypeID());
+    if (it.second)
+      it.first->second = typeIDAllocator.allocate();
+    return it.first->second;
+  }
+
+  /// A mutex that guards access to the registry.
+  llvm::sys::SmartRWMutex<true> mutex;
+
+  /// An allocator used for TypeID objects.
+  TypeIDAllocator typeIDAllocator;
+
+  /// A map type name to TypeID.
+  DenseMap<StringRef, TypeID> typeNameToID;
+};
+} // end namespace
+
+TypeID detail::FallbackTypeIDResolver::registerImplicitTypeID(StringRef name) {
+  static ImplicitTypeIDRegistry registry;
+  return registry.lookupOrInsert(name);
+}
+
+//===----------------------------------------------------------------------===//
+// Builtin TypeIDs
+//===----------------------------------------------------------------------===//
+
+MLIR_DEFINE_EXPLICIT_TYPE_ID(void)

diff  --git a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
index 2f30fc98b435f..83e8095a42cee 100644
--- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -31,6 +31,8 @@ namespace {
 class OpenMPAllocaStackFrame
     : public LLVM::ModuleTranslation::StackFrameBase<OpenMPAllocaStackFrame> {
 public:
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(OpenMPAllocaStackFrame)
+
   explicit OpenMPAllocaStackFrame(llvm::OpenMPIRBuilder::InsertPointTy allocaIP)
       : allocaInsertPoint(allocaIP) {}
   llvm::OpenMPIRBuilder::InsertPointTy allocaInsertPoint;
@@ -42,6 +44,8 @@ class OpenMPVarMappingStackFrame
     : public LLVM::ModuleTranslation::StackFrameBase<
           OpenMPVarMappingStackFrame> {
 public:
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(OpenMPVarMappingStackFrame)
+
   explicit OpenMPVarMappingStackFrame(
       const DenseMap<Value, llvm::Value *> &mapping)
       : mapping(mapping) {}

diff  --git a/mlir/lib/Tools/PDLL/AST/Types.cpp b/mlir/lib/Tools/PDLL/AST/Types.cpp
index cf0f0e918870b..4164cabac4dbc 100644
--- a/mlir/lib/Tools/PDLL/AST/Types.cpp
+++ b/mlir/lib/Tools/PDLL/AST/Types.cpp
@@ -13,6 +13,15 @@
 using namespace mlir;
 using namespace mlir::pdll::ast;
 
+MLIR_DEFINE_EXPLICIT_TYPE_ID(mlir::pdll::ast::detail::AttributeTypeStorage)
+MLIR_DEFINE_EXPLICIT_TYPE_ID(mlir::pdll::ast::detail::ConstraintTypeStorage)
+MLIR_DEFINE_EXPLICIT_TYPE_ID(mlir::pdll::ast::detail::OperationTypeStorage)
+MLIR_DEFINE_EXPLICIT_TYPE_ID(mlir::pdll::ast::detail::RangeTypeStorage)
+MLIR_DEFINE_EXPLICIT_TYPE_ID(mlir::pdll::ast::detail::RewriteTypeStorage)
+MLIR_DEFINE_EXPLICIT_TYPE_ID(mlir::pdll::ast::detail::TupleTypeStorage)
+MLIR_DEFINE_EXPLICIT_TYPE_ID(mlir::pdll::ast::detail::TypeTypeStorage)
+MLIR_DEFINE_EXPLICIT_TYPE_ID(mlir::pdll::ast::detail::ValueTypeStorage)
+
 //===----------------------------------------------------------------------===//
 // Type
 //===----------------------------------------------------------------------===//

diff  --git a/mlir/test/CAPI/ir.c b/mlir/test/CAPI/ir.c
index f3444a08e58d9..c12f525da2822 100644
--- a/mlir/test/CAPI/ir.c
+++ b/mlir/test/CAPI/ir.c
@@ -1753,15 +1753,13 @@ int testTypeID(MlirContext ctx) {
     return 2;
   }
 
-  if (mlirTypeIDEqual(i32ID, f32ID) ||
-      mlirTypeIDHashValue(i32ID) == mlirTypeIDHashValue(f32ID)) {
+  if (mlirTypeIDEqual(i32ID, f32ID)) {
     fprintf(stderr,
             "ERROR: Expected integer type id to not equal float type id\n");
     return 3;
   }
 
-  if (mlirTypeIDEqual(i32ID, i32AttrID) ||
-      mlirTypeIDHashValue(i32ID) == mlirTypeIDHashValue(i32AttrID)) {
+  if (mlirTypeIDEqual(i32ID, i32AttrID)) {
     fprintf(stderr, "ERROR: Expected integer type id to not equal integer "
                     "attribute type id\n");
     return 4;

diff  --git a/mlir/test/lib/Analysis/TestAliasAnalysis.cpp b/mlir/test/lib/Analysis/TestAliasAnalysis.cpp
index 01ab39503e9f0..284ea4cffeca4 100644
--- a/mlir/test/lib/Analysis/TestAliasAnalysis.cpp
+++ b/mlir/test/lib/Analysis/TestAliasAnalysis.cpp
@@ -46,6 +46,8 @@ static void printAliasOperand(Value value) {
 namespace {
 struct TestAliasAnalysisPass
     : public PassWrapper<TestAliasAnalysisPass, OperationPass<>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestAliasAnalysisPass)
+
   StringRef getArgument() const final { return "test-alias-analysis"; }
   StringRef getDescription() const final {
     return "Test alias analysis results.";
@@ -88,6 +90,8 @@ struct TestAliasAnalysisPass
 namespace {
 struct TestAliasAnalysisModRefPass
     : public PassWrapper<TestAliasAnalysisModRefPass, OperationPass<>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestAliasAnalysisModRefPass)
+
   StringRef getArgument() const final { return "test-alias-analysis-modref"; }
   StringRef getDescription() const final {
     return "Test alias analysis ModRef results.";

diff  --git a/mlir/test/lib/Analysis/TestCallGraph.cpp b/mlir/test/lib/Analysis/TestCallGraph.cpp
index e945e5518c43c..38b6777245814 100644
--- a/mlir/test/lib/Analysis/TestCallGraph.cpp
+++ b/mlir/test/lib/Analysis/TestCallGraph.cpp
@@ -19,6 +19,8 @@ using namespace mlir;
 namespace {
 struct TestCallGraphPass
     : public PassWrapper<TestCallGraphPass, OperationPass<ModuleOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestCallGraphPass)
+
   StringRef getArgument() const final { return "test-print-callgraph"; }
   StringRef getDescription() const final {
     return "Print the contents of a constructed callgraph.";

diff  --git a/mlir/test/lib/Analysis/TestLiveness.cpp b/mlir/test/lib/Analysis/TestLiveness.cpp
index 2af9e0c8dbfe1..07088c7ab9683 100644
--- a/mlir/test/lib/Analysis/TestLiveness.cpp
+++ b/mlir/test/lib/Analysis/TestLiveness.cpp
@@ -20,6 +20,8 @@ namespace {
 
 struct TestLivenessPass
     : public PassWrapper<TestLivenessPass, InterfacePass<SymbolOpInterface>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestLivenessPass)
+
   StringRef getArgument() const final { return "test-print-liveness"; }
   StringRef getDescription() const final {
     return "Print the contents of a constructed liveness information.";

diff  --git a/mlir/test/lib/Analysis/TestMatchReduction.cpp b/mlir/test/lib/Analysis/TestMatchReduction.cpp
index 1d84d0d468f2b..c410c128a9dea 100644
--- a/mlir/test/lib/Analysis/TestMatchReduction.cpp
+++ b/mlir/test/lib/Analysis/TestMatchReduction.cpp
@@ -37,6 +37,8 @@ void printReductionResult(Operation *redRegionOp, unsigned numOutput,
 struct TestMatchReductionPass
     : public PassWrapper<TestMatchReductionPass,
                          InterfacePass<FunctionOpInterface>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestMatchReductionPass)
+
   StringRef getArgument() const final { return "test-match-reduction"; }
   StringRef getDescription() const final {
     return "Test the match reduction utility.";

diff  --git a/mlir/test/lib/Analysis/TestMemRefBoundCheck.cpp b/mlir/test/lib/Analysis/TestMemRefBoundCheck.cpp
index 6abdc1f63588e..73ea6dddf2b29 100644
--- a/mlir/test/lib/Analysis/TestMemRefBoundCheck.cpp
+++ b/mlir/test/lib/Analysis/TestMemRefBoundCheck.cpp
@@ -29,6 +29,8 @@ namespace {
 /// Checks for out of bound memref access subscripts..
 struct TestMemRefBoundCheck
     : public PassWrapper<TestMemRefBoundCheck, OperationPass<>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestMemRefBoundCheck)
+
   StringRef getArgument() const final { return "test-memref-bound-check"; }
   StringRef getDescription() const final {
     return "Check memref access bounds";

diff  --git a/mlir/test/lib/Analysis/TestMemRefDependenceCheck.cpp b/mlir/test/lib/Analysis/TestMemRefDependenceCheck.cpp
index d8bd86d61c7af..eebd9e3631530 100644
--- a/mlir/test/lib/Analysis/TestMemRefDependenceCheck.cpp
+++ b/mlir/test/lib/Analysis/TestMemRefDependenceCheck.cpp
@@ -28,6 +28,8 @@ namespace {
 /// Checks dependences between all pairs of memref accesses in a Function.
 struct TestMemRefDependenceCheck
     : public PassWrapper<TestMemRefDependenceCheck, OperationPass<>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestMemRefDependenceCheck)
+
   StringRef getArgument() const final { return "test-memref-dependence-check"; }
   StringRef getDescription() const final {
     return "Checks dependences between all pairs of memref accesses.";

diff  --git a/mlir/test/lib/Analysis/TestMemRefStrideCalculation.cpp b/mlir/test/lib/Analysis/TestMemRefStrideCalculation.cpp
index a22f833cff0db..30bf50c76a70f 100644
--- a/mlir/test/lib/Analysis/TestMemRefStrideCalculation.cpp
+++ b/mlir/test/lib/Analysis/TestMemRefStrideCalculation.cpp
@@ -16,6 +16,8 @@ namespace {
 struct TestMemRefStrideCalculation
     : public PassWrapper<TestMemRefStrideCalculation,
                          InterfacePass<SymbolOpInterface>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestMemRefStrideCalculation)
+
   StringRef getArgument() const final {
     return "test-memref-stride-calculation";
   }

diff  --git a/mlir/test/lib/Analysis/TestSlice.cpp b/mlir/test/lib/Analysis/TestSlice.cpp
index 9b43e9f271d70..c62532740bade 100644
--- a/mlir/test/lib/Analysis/TestSlice.cpp
+++ b/mlir/test/lib/Analysis/TestSlice.cpp
@@ -18,6 +18,8 @@ namespace {
 struct TestTopologicalSortPass
     : public PassWrapper<TestTopologicalSortPass,
                          InterfacePass<SymbolOpInterface>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestTopologicalSortPass)
+
   StringRef getArgument() const final { return "test-print-topological-sort"; }
   StringRef getDescription() const final {
     return "Print operations in topological order";

diff  --git a/mlir/test/lib/Conversion/FuncToLLVM/TestConvertCallOp.cpp b/mlir/test/lib/Conversion/FuncToLLVM/TestConvertCallOp.cpp
index ddfe7971a1002..fff6cb79dbecf 100644
--- a/mlir/test/lib/Conversion/FuncToLLVM/TestConvertCallOp.cpp
+++ b/mlir/test/lib/Conversion/FuncToLLVM/TestConvertCallOp.cpp
@@ -32,9 +32,10 @@ class TestTypeProducerOpConverter
   }
 };
 
-class TestConvertCallOp
+struct TestConvertCallOp
     : public PassWrapper<TestConvertCallOp, OperationPass<ModuleOp>> {
-public:
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestConvertCallOp)
+
   void getDependentDialects(DialectRegistry &registry) const final {
     registry.insert<LLVM::LLVMDialect>();
   }

diff  --git a/mlir/test/lib/Dialect/Affine/TestAffineDataCopy.cpp b/mlir/test/lib/Dialect/Affine/TestAffineDataCopy.cpp
index a3831f903951b..f18b77fd6321e 100644
--- a/mlir/test/lib/Dialect/Affine/TestAffineDataCopy.cpp
+++ b/mlir/test/lib/Dialect/Affine/TestAffineDataCopy.cpp
@@ -28,6 +28,8 @@ namespace {
 
 struct TestAffineDataCopy
     : public PassWrapper<TestAffineDataCopy, OperationPass<FuncOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestAffineDataCopy)
+
   StringRef getArgument() const final { return PASS_NAME; }
   StringRef getDescription() const final {
     return "Tests affine data copy utility functions.";

diff  --git a/mlir/test/lib/Dialect/Affine/TestAffineLoopParametricTiling.cpp b/mlir/test/lib/Dialect/Affine/TestAffineLoopParametricTiling.cpp
index 8281b3e910478..0c938ca86bea3 100644
--- a/mlir/test/lib/Dialect/Affine/TestAffineLoopParametricTiling.cpp
+++ b/mlir/test/lib/Dialect/Affine/TestAffineLoopParametricTiling.cpp
@@ -24,6 +24,8 @@ namespace {
 struct TestAffineLoopParametricTiling
     : public PassWrapper<TestAffineLoopParametricTiling,
                          OperationPass<FuncOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestAffineLoopParametricTiling)
+
   StringRef getArgument() const final { return "test-affine-parametric-tile"; }
   StringRef getDescription() const final {
     return "Tile affine loops using SSA values as tile sizes";

diff  --git a/mlir/test/lib/Dialect/Affine/TestAffineLoopUnswitching.cpp b/mlir/test/lib/Dialect/Affine/TestAffineLoopUnswitching.cpp
index b2854f39bdf50..83b66f57a6e4f 100644
--- a/mlir/test/lib/Dialect/Affine/TestAffineLoopUnswitching.cpp
+++ b/mlir/test/lib/Dialect/Affine/TestAffineLoopUnswitching.cpp
@@ -25,6 +25,8 @@ namespace {
 /// This pass applies the permutation on the first maximal perfect nest.
 struct TestAffineLoopUnswitching
     : public PassWrapper<TestAffineLoopUnswitching, OperationPass<>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestAffineLoopUnswitching)
+
   StringRef getArgument() const final { return PASS_NAME; }
   StringRef getDescription() const final {
     return "Tests affine loop unswitching / if/else hoisting";

diff  --git a/mlir/test/lib/Dialect/Affine/TestLoopFusion.cpp b/mlir/test/lib/Dialect/Affine/TestLoopFusion.cpp
index 30a2e09cdbc3b..0d458cbf09807 100644
--- a/mlir/test/lib/Dialect/Affine/TestLoopFusion.cpp
+++ b/mlir/test/lib/Dialect/Affine/TestLoopFusion.cpp
@@ -42,6 +42,8 @@ namespace {
 
 struct TestLoopFusion
     : public PassWrapper<TestLoopFusion, OperationPass<FuncOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestLoopFusion)
+
   StringRef getArgument() const final { return "test-loop-fusion"; }
   StringRef getDescription() const final {
     return "Tests loop fusion utility functions.";

diff  --git a/mlir/test/lib/Dialect/Affine/TestLoopMapping.cpp b/mlir/test/lib/Dialect/Affine/TestLoopMapping.cpp
index cbdd1c7bf91ec..2ee10ab22df41 100644
--- a/mlir/test/lib/Dialect/Affine/TestLoopMapping.cpp
+++ b/mlir/test/lib/Dialect/Affine/TestLoopMapping.cpp
@@ -22,9 +22,10 @@
 using namespace mlir;
 
 namespace {
-class TestLoopMappingPass
+struct TestLoopMappingPass
     : public PassWrapper<TestLoopMappingPass, OperationPass<>> {
-public:
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestLoopMappingPass)
+
   StringRef getArgument() const final {
     return "test-mapping-to-processing-elements";
   }

diff  --git a/mlir/test/lib/Dialect/Affine/TestLoopPermutation.cpp b/mlir/test/lib/Dialect/Affine/TestLoopPermutation.cpp
index 0c65fc843578c..9183b3ee3c76f 100644
--- a/mlir/test/lib/Dialect/Affine/TestLoopPermutation.cpp
+++ b/mlir/test/lib/Dialect/Affine/TestLoopPermutation.cpp
@@ -24,6 +24,8 @@ namespace {
 /// This pass applies the permutation on the first maximal perfect nest.
 struct TestLoopPermutation
     : public PassWrapper<TestLoopPermutation, OperationPass<>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestLoopPermutation)
+
   StringRef getArgument() const final { return PASS_NAME; }
   StringRef getDescription() const final {
     return "Tests affine loop permutation utility";

diff  --git a/mlir/test/lib/Dialect/Affine/TestVectorizationUtils.cpp b/mlir/test/lib/Dialect/Affine/TestVectorizationUtils.cpp
index 4a3f06810a9f6..0dc27346fb362 100644
--- a/mlir/test/lib/Dialect/Affine/TestVectorizationUtils.cpp
+++ b/mlir/test/lib/Dialect/Affine/TestVectorizationUtils.cpp
@@ -71,6 +71,8 @@ static llvm::cl::opt<bool> clTestVecAffineLoopNest(
 namespace {
 struct VectorizerTestPass
     : public PassWrapper<VectorizerTestPass, OperationPass<FuncOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(VectorizerTestPass)
+
   static constexpr auto kTestAffineMapOpName = "test_affine_map";
   static constexpr auto kTestAffineMapAttrName = "affine_map";
   void getDependentDialects(DialectRegistry &registry) const override {

diff  --git a/mlir/test/lib/Dialect/DLTI/TestDataLayoutQuery.cpp b/mlir/test/lib/Dialect/DLTI/TestDataLayoutQuery.cpp
index 9f25ac79a087d..ad78588b4f454 100644
--- a/mlir/test/lib/Dialect/DLTI/TestDataLayoutQuery.cpp
+++ b/mlir/test/lib/Dialect/DLTI/TestDataLayoutQuery.cpp
@@ -21,6 +21,8 @@ namespace {
 /// result types.
 struct TestDataLayoutQuery
     : public PassWrapper<TestDataLayoutQuery, OperationPass<FuncOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestDataLayoutQuery)
+
   StringRef getArgument() const final { return "test-data-layout-query"; }
   StringRef getDescription() const final { return "Test data layout queries"; }
   void runOnOperation() override {

diff  --git a/mlir/test/lib/Dialect/Func/TestDecomposeCallGraphTypes.cpp b/mlir/test/lib/Dialect/Func/TestDecomposeCallGraphTypes.cpp
index 34e5516e3adf0..54470cf7d7291 100644
--- a/mlir/test/lib/Dialect/Func/TestDecomposeCallGraphTypes.cpp
+++ b/mlir/test/lib/Dialect/Func/TestDecomposeCallGraphTypes.cpp
@@ -23,6 +23,7 @@ namespace {
 /// For example, `tuple<T1, T2, T3> --> T1, T2, T3`.
 struct TestDecomposeCallGraphTypes
     : public PassWrapper<TestDecomposeCallGraphTypes, OperationPass<ModuleOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestDecomposeCallGraphTypes)
 
   void getDependentDialects(DialectRegistry &registry) const override {
     registry.insert<test::TestDialect>();

diff  --git a/mlir/test/lib/Dialect/GPU/TestConvertGPUKernelToCubin.cpp b/mlir/test/lib/Dialect/GPU/TestConvertGPUKernelToCubin.cpp
index 560263ae9b194..7644acd454327 100644
--- a/mlir/test/lib/Dialect/GPU/TestConvertGPUKernelToCubin.cpp
+++ b/mlir/test/lib/Dialect/GPU/TestConvertGPUKernelToCubin.cpp
@@ -20,6 +20,8 @@ namespace {
 class TestSerializeToCubinPass
     : public PassWrapper<TestSerializeToCubinPass, gpu::SerializeToBlobPass> {
 public:
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestSerializeToCubinPass)
+
   StringRef getArgument() const final { return "test-gpu-to-cubin"; }
   StringRef getDescription() const final {
     return "Lower GPU kernel function to CUBIN binary annotations";

diff  --git a/mlir/test/lib/Dialect/GPU/TestConvertGPUKernelToHsaco.cpp b/mlir/test/lib/Dialect/GPU/TestConvertGPUKernelToHsaco.cpp
index e6c296801859b..8f614d4b15b93 100644
--- a/mlir/test/lib/Dialect/GPU/TestConvertGPUKernelToHsaco.cpp
+++ b/mlir/test/lib/Dialect/GPU/TestConvertGPUKernelToHsaco.cpp
@@ -20,6 +20,8 @@ namespace {
 class TestSerializeToHsacoPass
     : public PassWrapper<TestSerializeToHsacoPass, gpu::SerializeToBlobPass> {
 public:
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestSerializeToHsacoPass)
+
   StringRef getArgument() const final { return "test-gpu-to-hsaco"; }
   StringRef getDescription() const final {
     return "Lower GPU kernel function to HSAco binary annotations";

diff  --git a/mlir/test/lib/Dialect/GPU/TestGpuMemoryPromotion.cpp b/mlir/test/lib/Dialect/GPU/TestGpuMemoryPromotion.cpp
index 030f1b64b4511..81e66f95270a2 100644
--- a/mlir/test/lib/Dialect/GPU/TestGpuMemoryPromotion.cpp
+++ b/mlir/test/lib/Dialect/GPU/TestGpuMemoryPromotion.cpp
@@ -27,9 +27,11 @@ namespace {
 /// Promotes all arguments with "gpu.test_promote_workgroup" attribute. This
 /// does not check whether the promotion is legal (e.g., amount of memory used)
 /// or beneficial (e.g., makes previously uncoalesced loads coalesced).
-class TestGpuMemoryPromotionPass
+struct TestGpuMemoryPromotionPass
     : public PassWrapper<TestGpuMemoryPromotionPass,
                          OperationPass<gpu::GPUFuncOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestGpuMemoryPromotionPass)
+
   void getDependentDialects(DialectRegistry &registry) const override {
     registry.insert<AffineDialect, memref::MemRefDialect, scf::SCFDialect>();
   }

diff  --git a/mlir/test/lib/Dialect/GPU/TestGpuParallelLoopMapping.cpp b/mlir/test/lib/Dialect/GPU/TestGpuParallelLoopMapping.cpp
index 9cf9de6a38c83..f53abba6a21b1 100644
--- a/mlir/test/lib/Dialect/GPU/TestGpuParallelLoopMapping.cpp
+++ b/mlir/test/lib/Dialect/GPU/TestGpuParallelLoopMapping.cpp
@@ -19,9 +19,12 @@ using namespace mlir;
 namespace {
 /// Simple pass for testing the mapping of parallel loops to hardware ids using
 /// a greedy mapping strategy.
-class TestGpuGreedyParallelLoopMappingPass
+struct TestGpuGreedyParallelLoopMappingPass
     : public PassWrapper<TestGpuGreedyParallelLoopMappingPass,
                          OperationPass<>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(
+      TestGpuGreedyParallelLoopMappingPass)
+
   StringRef getArgument() const final {
     return "test-gpu-greedy-parallel-loop-mapping";
   }

diff  --git a/mlir/test/lib/Dialect/GPU/TestGpuRewrite.cpp b/mlir/test/lib/Dialect/GPU/TestGpuRewrite.cpp
index 0a68509cf2df2..3d81a26c0bc6a 100644
--- a/mlir/test/lib/Dialect/GPU/TestGpuRewrite.cpp
+++ b/mlir/test/lib/Dialect/GPU/TestGpuRewrite.cpp
@@ -22,6 +22,8 @@ using namespace mlir;
 namespace {
 struct TestGpuRewritePass
     : public PassWrapper<TestGpuRewritePass, OperationPass<ModuleOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestGpuRewritePass)
+
   void getDependentDialects(DialectRegistry &registry) const override {
     registry.insert<arith::ArithmeticDialect, func::FuncDialect,
                     memref::MemRefDialect>();

diff  --git a/mlir/test/lib/Dialect/Linalg/TestLinalgCodegenStrategy.cpp b/mlir/test/lib/Dialect/Linalg/TestLinalgCodegenStrategy.cpp
index fa6a478a05f53..9340101a8bf3c 100644
--- a/mlir/test/lib/Dialect/Linalg/TestLinalgCodegenStrategy.cpp
+++ b/mlir/test/lib/Dialect/Linalg/TestLinalgCodegenStrategy.cpp
@@ -31,6 +31,8 @@ using namespace mlir::linalg;
 namespace {
 struct TestLinalgCodegenStrategy
     : public PassWrapper<TestLinalgCodegenStrategy, OperationPass<FuncOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestLinalgCodegenStrategy)
+
   StringRef getArgument() const final { return "test-linalg-codegen-strategy"; }
   StringRef getDescription() const final {
     return "Test Linalg Codegen Strategy.";

diff  --git a/mlir/test/lib/Dialect/Linalg/TestLinalgElementwiseFusion.cpp b/mlir/test/lib/Dialect/Linalg/TestLinalgElementwiseFusion.cpp
index 9a0604ef4aae9..5fa56d2ba05d1 100644
--- a/mlir/test/lib/Dialect/Linalg/TestLinalgElementwiseFusion.cpp
+++ b/mlir/test/lib/Dialect/Linalg/TestLinalgElementwiseFusion.cpp
@@ -18,7 +18,7 @@
 #include "mlir/Transforms/GreedyPatternRewriteDriver.h"
 #include "llvm/ADT/TypeSwitch.h"
 
-namespace mlir {
+using namespace mlir;
 
 static void addOperands(Operation *op, SetVector<Value> &operandSet) {
   if (!op)
@@ -48,6 +48,8 @@ static bool setFusedOpOperandLimit(const OpResult &producer,
 namespace {
 struct TestLinalgElementwiseFusion
     : public PassWrapper<TestLinalgElementwiseFusion, OperationPass<FuncOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestLinalgElementwiseFusion)
+
   TestLinalgElementwiseFusion() = default;
   TestLinalgElementwiseFusion(const TestLinalgElementwiseFusion &pass)
       : PassWrapper(pass) {}
@@ -168,10 +170,10 @@ struct TestLinalgElementwiseFusion
 
 } // namespace
 
+namespace mlir {
 namespace test {
 void registerTestLinalgElementwiseFusion() {
   PassRegistration<TestLinalgElementwiseFusion>();
 }
 } // namespace test
-
 } // namespace mlir

diff  --git a/mlir/test/lib/Dialect/Linalg/TestLinalgFusionTransforms.cpp b/mlir/test/lib/Dialect/Linalg/TestLinalgFusionTransforms.cpp
index 271837710ba4e..88ccc77ab59a2 100644
--- a/mlir/test/lib/Dialect/Linalg/TestLinalgFusionTransforms.cpp
+++ b/mlir/test/lib/Dialect/Linalg/TestLinalgFusionTransforms.cpp
@@ -114,6 +114,8 @@ template <LinalgTilingLoopType LoopType>
 struct TestLinalgFusionTransforms
     : public PassWrapper<TestLinalgFusionTransforms<LoopType>,
                          OperationPass<FuncOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestLinalgFusionTransforms)
+
   void getDependentDialects(DialectRegistry &registry) const override {
     registry.insert<AffineDialect, linalg::LinalgDialect, memref::MemRefDialect,
                     scf::SCFDialect>();
@@ -135,6 +137,9 @@ struct TestLinalgFusionTransforms
 
 struct TestLinalgFusionTransformsParallelLoops
     : public TestLinalgFusionTransforms<LinalgTilingLoopType::ParallelLoops> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(
+      TestLinalgFusionTransformsParallelLoops)
+
   StringRef getArgument() const final {
     return "test-linalg-fusion-transform-patterns";
   }
@@ -146,6 +151,8 @@ struct TestLinalgFusionTransformsParallelLoops
 
 struct TestLinalgFusionTransformsLoops
     : public TestLinalgFusionTransforms<LinalgTilingLoopType::Loops> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestLinalgFusionTransformsLoops)
+
   StringRef getArgument() const final {
     return "test-linalg-tensor-fusion-transform-patterns";
   }
@@ -157,6 +164,9 @@ struct TestLinalgFusionTransformsLoops
 
 struct TestLinalgFusionTransformsTiledLoops
     : public TestLinalgFusionTransforms<LinalgTilingLoopType::TiledLoops> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(
+      TestLinalgFusionTransformsTiledLoops)
+
   StringRef getArgument() const final {
     return "test-linalg-tiled-loop-fusion-transform-patterns";
   }
@@ -228,6 +238,8 @@ static LogicalResult fuseLinalgOpsGreedily(FuncOp f) {
 namespace {
 struct TestLinalgGreedyFusion
     : public PassWrapper<TestLinalgGreedyFusion, OperationPass<FuncOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestLinalgGreedyFusion)
+
   void getDependentDialects(DialectRegistry &registry) const override {
     registry.insert<AffineDialect, linalg::LinalgDialect, memref::MemRefDialect,
                     scf::SCFDialect>();
@@ -261,6 +273,9 @@ struct TestLinalgGreedyFusion
 struct TestLinalgTileAndFuseSequencePass
     : public PassWrapper<TestLinalgTileAndFuseSequencePass,
                          OperationPass<FuncOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(
+      TestLinalgTileAndFuseSequencePass)
+
   StringRef getArgument() const final { return "test-linalg-tile-and-fuse"; }
   StringRef getDescription() const final {
     return "Test Linalg tiling and fusion of a sequence of Linalg operations.";

diff  --git a/mlir/test/lib/Dialect/Linalg/TestLinalgHoisting.cpp b/mlir/test/lib/Dialect/Linalg/TestLinalgHoisting.cpp
index a05a1f8ca529f..c79983fc0668a 100644
--- a/mlir/test/lib/Dialect/Linalg/TestLinalgHoisting.cpp
+++ b/mlir/test/lib/Dialect/Linalg/TestLinalgHoisting.cpp
@@ -22,6 +22,8 @@ using namespace mlir::linalg;
 namespace {
 struct TestLinalgHoisting
     : public PassWrapper<TestLinalgHoisting, OperationPass<FuncOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestLinalgHoisting)
+
   TestLinalgHoisting() = default;
   TestLinalgHoisting(const TestLinalgHoisting &pass) : PassWrapper(pass) {}
   void getDependentDialects(DialectRegistry &registry) const override {

diff  --git a/mlir/test/lib/Dialect/Linalg/TestLinalgTransforms.cpp b/mlir/test/lib/Dialect/Linalg/TestLinalgTransforms.cpp
index 23df4439cab0a..a8c75bee62117 100644
--- a/mlir/test/lib/Dialect/Linalg/TestLinalgTransforms.cpp
+++ b/mlir/test/lib/Dialect/Linalg/TestLinalgTransforms.cpp
@@ -33,6 +33,8 @@ using namespace mlir::linalg;
 namespace {
 struct TestLinalgTransforms
     : public PassWrapper<TestLinalgTransforms, OperationPass<FuncOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestLinalgTransforms)
+
   TestLinalgTransforms() = default;
   TestLinalgTransforms(const TestLinalgTransforms &pass) : PassWrapper(pass) {}
 

diff  --git a/mlir/test/lib/Dialect/Linalg/TestPadFusion.cpp b/mlir/test/lib/Dialect/Linalg/TestPadFusion.cpp
index 079d406344508..8fbb62ac8df0d 100644
--- a/mlir/test/lib/Dialect/Linalg/TestPadFusion.cpp
+++ b/mlir/test/lib/Dialect/Linalg/TestPadFusion.cpp
@@ -16,11 +16,12 @@
 #include "mlir/Pass/PassManager.h"
 #include "mlir/Transforms/GreedyPatternRewriteDriver.h"
 
-namespace mlir {
+using namespace mlir;
 
 namespace {
 struct TestPadFusionPass
     : public PassWrapper<TestPadFusionPass, OperationPass<>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestPadFusionPass)
 
   void getDependentDialects(DialectRegistry &registry) const override {
     registry
@@ -41,8 +42,8 @@ struct TestPadFusionPass
 };
 } // namespace
 
+namespace mlir {
 namespace test {
 void registerTestPadFusion() { PassRegistration<TestPadFusionPass>(); }
 } // namespace test
-
 } // namespace mlir

diff  --git a/mlir/test/lib/Dialect/Math/TestAlgebraicSimplification.cpp b/mlir/test/lib/Dialect/Math/TestAlgebraicSimplification.cpp
index 540fbf5570fe3..084a592215241 100644
--- a/mlir/test/lib/Dialect/Math/TestAlgebraicSimplification.cpp
+++ b/mlir/test/lib/Dialect/Math/TestAlgebraicSimplification.cpp
@@ -21,6 +21,9 @@ using namespace mlir;
 namespace {
 struct TestMathAlgebraicSimplificationPass
     : public PassWrapper<TestMathAlgebraicSimplificationPass, OperationPass<>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(
+      TestMathAlgebraicSimplificationPass)
+
   void runOnOperation() override;
   void getDependentDialects(DialectRegistry &registry) const override {
     registry.insert<vector::VectorDialect, math::MathDialect>();

diff  --git a/mlir/test/lib/Dialect/Math/TestExpandTanh.cpp b/mlir/test/lib/Dialect/Math/TestExpandTanh.cpp
index 90dbb8649bbe8..fd83452bc4292 100644
--- a/mlir/test/lib/Dialect/Math/TestExpandTanh.cpp
+++ b/mlir/test/lib/Dialect/Math/TestExpandTanh.cpp
@@ -19,6 +19,8 @@ using namespace mlir;
 namespace {
 struct TestExpandTanhPass
     : public PassWrapper<TestExpandTanhPass, OperationPass<>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestExpandTanhPass)
+
   void runOnOperation() override;
   StringRef getArgument() const final { return "test-expand-tanh"; }
   StringRef getDescription() const final { return "Test expanding tanh"; }

diff  --git a/mlir/test/lib/Dialect/Math/TestPolynomialApproximation.cpp b/mlir/test/lib/Dialect/Math/TestPolynomialApproximation.cpp
index c26472c3d2984..97d2d038737e2 100644
--- a/mlir/test/lib/Dialect/Math/TestPolynomialApproximation.cpp
+++ b/mlir/test/lib/Dialect/Math/TestPolynomialApproximation.cpp
@@ -24,6 +24,9 @@ using namespace mlir;
 namespace {
 struct TestMathPolynomialApproximationPass
     : public PassWrapper<TestMathPolynomialApproximationPass, OperationPass<>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(
+      TestMathPolynomialApproximationPass)
+
   TestMathPolynomialApproximationPass() = default;
   TestMathPolynomialApproximationPass(
       const TestMathPolynomialApproximationPass &pass)

diff  --git a/mlir/test/lib/Dialect/MemRef/TestComposeSubView.cpp b/mlir/test/lib/Dialect/MemRef/TestComposeSubView.cpp
index 89a4e6c7d8a61..917b9d2342108 100644
--- a/mlir/test/lib/Dialect/MemRef/TestComposeSubView.cpp
+++ b/mlir/test/lib/Dialect/MemRef/TestComposeSubView.cpp
@@ -20,6 +20,8 @@ using namespace mlir;
 namespace {
 struct TestComposeSubViewPass
     : public PassWrapper<TestComposeSubViewPass, OperationPass<>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestComposeSubViewPass)
+
   StringRef getArgument() const final { return "test-compose-subview"; }
   StringRef getDescription() const final {
     return "Test combining composed subviews";

diff  --git a/mlir/test/lib/Dialect/MemRef/TestMultiBuffer.cpp b/mlir/test/lib/Dialect/MemRef/TestMultiBuffer.cpp
index bf5b2bec95616..30cf06b866697 100644
--- a/mlir/test/lib/Dialect/MemRef/TestMultiBuffer.cpp
+++ b/mlir/test/lib/Dialect/MemRef/TestMultiBuffer.cpp
@@ -17,6 +17,8 @@ using namespace mlir;
 namespace {
 struct TestMultiBufferingPass
     : public PassWrapper<TestMultiBufferingPass, OperationPass<>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestMultiBufferingPass)
+
   TestMultiBufferingPass() = default;
   TestMultiBufferingPass(const TestMultiBufferingPass &pass)
       : PassWrapper(pass) {}

diff  --git a/mlir/test/lib/Dialect/SCF/TestLoopParametricTiling.cpp b/mlir/test/lib/Dialect/SCF/TestLoopParametricTiling.cpp
index d34ce2421eac2..82a4473b0e640 100644
--- a/mlir/test/lib/Dialect/SCF/TestLoopParametricTiling.cpp
+++ b/mlir/test/lib/Dialect/SCF/TestLoopParametricTiling.cpp
@@ -24,6 +24,8 @@ namespace {
 class SimpleParametricLoopTilingPass
     : public PassWrapper<SimpleParametricLoopTilingPass, OperationPass<>> {
 public:
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(SimpleParametricLoopTilingPass)
+
   StringRef getArgument() const final {
     return "test-extract-fixed-outer-loops";
   }

diff  --git a/mlir/test/lib/Dialect/SCF/TestLoopUnrolling.cpp b/mlir/test/lib/Dialect/SCF/TestLoopUnrolling.cpp
index 77dc5edf8a01b..150f32af23991 100644
--- a/mlir/test/lib/Dialect/SCF/TestLoopUnrolling.cpp
+++ b/mlir/test/lib/Dialect/SCF/TestLoopUnrolling.cpp
@@ -30,9 +30,10 @@ static unsigned getNestingDepth(Operation *op) {
   return depth;
 }
 
-class TestLoopUnrollingPass
+struct TestLoopUnrollingPass
     : public PassWrapper<TestLoopUnrollingPass, OperationPass<>> {
-public:
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestLoopUnrollingPass)
+
   StringRef getArgument() const final { return "test-loop-unrolling"; }
   StringRef getDescription() const final {
     return "Tests loop unrolling transformation";

diff  --git a/mlir/test/lib/Dialect/SCF/TestSCFUtils.cpp b/mlir/test/lib/Dialect/SCF/TestSCFUtils.cpp
index 1cec4b2386922..320af3a3eefe2 100644
--- a/mlir/test/lib/Dialect/SCF/TestSCFUtils.cpp
+++ b/mlir/test/lib/Dialect/SCF/TestSCFUtils.cpp
@@ -25,9 +25,10 @@
 using namespace mlir;
 
 namespace {
-class TestSCFForUtilsPass
+struct TestSCFForUtilsPass
     : public PassWrapper<TestSCFForUtilsPass, OperationPass<FuncOp>> {
-public:
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestSCFForUtilsPass)
+
   StringRef getArgument() const final { return "test-scf-for-utils"; }
   StringRef getDescription() const final { return "test scf.for utils"; }
   explicit TestSCFForUtilsPass() = default;
@@ -57,9 +58,10 @@ class TestSCFForUtilsPass
   }
 };
 
-class TestSCFIfUtilsPass
+struct TestSCFIfUtilsPass
     : public PassWrapper<TestSCFIfUtilsPass, OperationPass<ModuleOp>> {
-public:
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestSCFIfUtilsPass)
+
   StringRef getArgument() const final { return "test-scf-if-utils"; }
   StringRef getDescription() const final { return "test scf.if utils"; }
   explicit TestSCFIfUtilsPass() = default;
@@ -95,9 +97,10 @@ static const StringLiteral kTestPipeliningAnnotationPart =
 static const StringLiteral kTestPipeliningAnnotationIteration =
     "__test_pipelining_iteration";
 
-class TestSCFPipeliningPass
+struct TestSCFPipeliningPass
     : public PassWrapper<TestSCFPipeliningPass, OperationPass<FuncOp>> {
-public:
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestSCFPipeliningPass)
+
   TestSCFPipeliningPass() = default;
   TestSCFPipeliningPass(const TestSCFPipeliningPass &) {}
   StringRef getArgument() const final { return "test-scf-pipelining"; }

diff  --git a/mlir/test/lib/Dialect/SPIRV/TestAvailability.cpp b/mlir/test/lib/Dialect/SPIRV/TestAvailability.cpp
index 8e9a3c9b4c78a..31eda369baefb 100644
--- a/mlir/test/lib/Dialect/SPIRV/TestAvailability.cpp
+++ b/mlir/test/lib/Dialect/SPIRV/TestAvailability.cpp
@@ -23,6 +23,8 @@ namespace {
 /// A pass for testing SPIR-V op availability.
 struct PrintOpAvailability
     : public PassWrapper<PrintOpAvailability, OperationPass<FuncOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(PrintOpAvailability)
+
   void runOnOperation() override;
   StringRef getArgument() const final { return "test-spirv-op-availability"; }
   StringRef getDescription() const final {
@@ -105,6 +107,8 @@ namespace {
 /// A pass for testing SPIR-V op availability.
 struct ConvertToTargetEnv
     : public PassWrapper<ConvertToTargetEnv, OperationPass<FuncOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(ConvertToTargetEnv)
+
   StringRef getArgument() const override { return "test-spirv-target-env"; }
   StringRef getDescription() const override {
     return "Test SPIR-V target environment";

diff  --git a/mlir/test/lib/Dialect/SPIRV/TestEntryPointAbi.cpp b/mlir/test/lib/Dialect/SPIRV/TestEntryPointAbi.cpp
index ab127c8918b77..69aa4f64d5047 100644
--- a/mlir/test/lib/Dialect/SPIRV/TestEntryPointAbi.cpp
+++ b/mlir/test/lib/Dialect/SPIRV/TestEntryPointAbi.cpp
@@ -20,10 +20,11 @@ using namespace mlir;
 
 namespace {
 /// Pass to set the spv.entry_point_abi
-class TestSpirvEntryPointABIPass
+struct TestSpirvEntryPointABIPass
     : public PassWrapper<TestSpirvEntryPointABIPass,
                          OperationPass<gpu::GPUModuleOp>> {
-public:
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestSpirvEntryPointABIPass)
+
   StringRef getArgument() const final { return "test-spirv-entry-point-abi"; }
   StringRef getDescription() const final {
     return "Set the spv.entry_point_abi attribute on GPU kernel function "

diff  --git a/mlir/test/lib/Dialect/SPIRV/TestModuleCombiner.cpp b/mlir/test/lib/Dialect/SPIRV/TestModuleCombiner.cpp
index 12054b1dc4549..56585d15f9dad 100644
--- a/mlir/test/lib/Dialect/SPIRV/TestModuleCombiner.cpp
+++ b/mlir/test/lib/Dialect/SPIRV/TestModuleCombiner.cpp
@@ -20,6 +20,8 @@ class TestModuleCombinerPass
     : public PassWrapper<TestModuleCombinerPass,
                          OperationPass<mlir::ModuleOp>> {
 public:
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestModuleCombinerPass)
+
   StringRef getArgument() const final { return "test-spirv-module-combiner"; }
   StringRef getDescription() const final {
     return "Tests SPIR-V module combiner library";

diff  --git a/mlir/test/lib/Dialect/Shape/TestShapeFunctions.cpp b/mlir/test/lib/Dialect/Shape/TestShapeFunctions.cpp
index 5bfec82f7db97..ca1baa4d69eec 100644
--- a/mlir/test/lib/Dialect/Shape/TestShapeFunctions.cpp
+++ b/mlir/test/lib/Dialect/Shape/TestShapeFunctions.cpp
@@ -19,6 +19,8 @@ namespace {
 /// This is a pass that reports shape functions associated with ops.
 struct ReportShapeFnPass
     : public PassWrapper<ReportShapeFnPass, OperationPass<ModuleOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(ReportShapeFnPass)
+
   void runOnOperation() override;
   StringRef getArgument() const final { return "test-shape-function-report"; }
   StringRef getDescription() const final {

diff  --git a/mlir/test/lib/Dialect/Tensor/TestTensorTransforms.cpp b/mlir/test/lib/Dialect/Tensor/TestTensorTransforms.cpp
index 46c5c34293f7c..790f4ae4c9d40 100644
--- a/mlir/test/lib/Dialect/Tensor/TestTensorTransforms.cpp
+++ b/mlir/test/lib/Dialect/Tensor/TestTensorTransforms.cpp
@@ -22,6 +22,8 @@ using namespace mlir;
 namespace {
 struct TestTensorTransforms
     : public PassWrapper<TestTensorTransforms, OperationPass<>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestTensorTransforms)
+
   TestTensorTransforms() = default;
   TestTensorTransforms(const TestTensorTransforms &pass) : PassWrapper(pass) {}
 

diff  --git a/mlir/test/lib/Dialect/Test/TestDialect.cpp b/mlir/test/lib/Dialect/Test/TestDialect.cpp
index ebd21a0893321..73119805fcdf0 100644
--- a/mlir/test/lib/Dialect/Test/TestDialect.cpp
+++ b/mlir/test/lib/Dialect/Test/TestDialect.cpp
@@ -1021,6 +1021,8 @@ LogicalResult OpWithResultShapePerDimInterfaceOp::reifyResultShapes(
 namespace {
 /// A test resource for side effects.
 struct TestResource : public SideEffects::Resource::Base<TestResource> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestResource)
+
   StringRef getName() final { return "<Test>"; }
 };
 } // namespace

diff  --git a/mlir/test/lib/Dialect/Test/TestPatterns.cpp b/mlir/test/lib/Dialect/Test/TestPatterns.cpp
index 5eb86be56759c..83e887b1f47bf 100644
--- a/mlir/test/lib/Dialect/Test/TestPatterns.cpp
+++ b/mlir/test/lib/Dialect/Test/TestPatterns.cpp
@@ -149,6 +149,8 @@ struct FolderCommutativeOp2WithConstant
 
 struct TestPatternDriver
     : public PassWrapper<TestPatternDriver, OperationPass<FuncOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestPatternDriver)
+
   StringRef getArgument() const final { return "test-patterns"; }
   StringRef getDescription() const final { return "Run test dialect patterns"; }
   void runOnOperation() override {
@@ -214,6 +216,8 @@ static void reifyReturnShape(Operation *op) {
 
 struct TestReturnTypeDriver
     : public PassWrapper<TestReturnTypeDriver, OperationPass<FuncOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestReturnTypeDriver)
+
   void getDependentDialects(DialectRegistry &registry) const override {
     registry.insert<tensor::TensorDialect>();
   }
@@ -254,6 +258,8 @@ struct TestReturnTypeDriver
 namespace {
 struct TestDerivedAttributeDriver
     : public PassWrapper<TestDerivedAttributeDriver, OperationPass<FuncOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestDerivedAttributeDriver)
+
   StringRef getArgument() const final { return "test-derived-attr"; }
   StringRef getDescription() const final {
     return "Run test derived attributes";
@@ -655,6 +661,8 @@ struct TestTypeConverter : public TypeConverter {
 
 struct TestLegalizePatternDriver
     : public PassWrapper<TestLegalizePatternDriver, OperationPass<ModuleOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestLegalizePatternDriver)
+
   StringRef getArgument() const final { return "test-legalize-patterns"; }
   StringRef getDescription() const final {
     return "Run test dialect legalization patterns";
@@ -864,6 +872,8 @@ struct TestRemapValueInRegion
 
 struct TestRemappedValue
     : public mlir::PassWrapper<TestRemappedValue, OperationPass<FuncOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestRemappedValue)
+
   StringRef getArgument() const final { return "test-remapped-value"; }
   StringRef getDescription() const final {
     return "Test public remapped value mechanism in ConversionPatternRewriter";
@@ -922,6 +932,8 @@ struct RemoveTestDialectOps : public RewritePattern {
 
 struct TestUnknownRootOpDriver
     : public mlir::PassWrapper<TestUnknownRootOpDriver, OperationPass<FuncOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestUnknownRootOpDriver)
+
   StringRef getArgument() const final {
     return "test-legalize-unknown-root-patterns";
   }
@@ -1041,6 +1053,8 @@ struct TestTypeConversionAnotherProducer
 
 struct TestTypeConversionDriver
     : public PassWrapper<TestTypeConversionDriver, OperationPass<ModuleOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestTypeConversionDriver)
+
   void getDependentDialects(DialectRegistry &registry) const override {
     registry.insert<TestDialect>();
   }
@@ -1177,6 +1191,9 @@ struct ForwardOperandPattern : public OpConversionPattern<TestTypeChangerOp> {
 struct TestTargetMaterializationWithNoUses
     : public PassWrapper<TestTargetMaterializationWithNoUses,
                          OperationPass<ModuleOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(
+      TestTargetMaterializationWithNoUses)
+
   StringRef getArgument() const final {
     return "test-target-materialization-with-no-uses";
   }
@@ -1283,6 +1300,8 @@ struct TestMergeSingleBlockOps
 struct TestMergeBlocksPatternDriver
     : public PassWrapper<TestMergeBlocksPatternDriver,
                          OperationPass<ModuleOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestMergeBlocksPatternDriver)
+
   StringRef getArgument() const final { return "test-merge-blocks"; }
   StringRef getDescription() const final {
     return "Test Merging operation in ConversionPatternRewriter";
@@ -1354,6 +1373,9 @@ struct TestSelectiveOpReplacementPattern : public OpRewritePattern<TestCastOp> {
 struct TestSelectiveReplacementPatternDriver
     : public PassWrapper<TestSelectiveReplacementPatternDriver,
                          OperationPass<>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(
+      TestSelectiveReplacementPatternDriver)
+
   StringRef getArgument() const final {
     return "test-pattern-selective-replacement";
   }

diff  --git a/mlir/test/lib/Dialect/Test/TestTraits.cpp b/mlir/test/lib/Dialect/Test/TestTraits.cpp
index 56a14049cbe52..312c10cc82306 100644
--- a/mlir/test/lib/Dialect/Test/TestTraits.cpp
+++ b/mlir/test/lib/Dialect/Test/TestTraits.cpp
@@ -33,6 +33,8 @@ OpFoldResult TestInvolutionTraitSuccesfulOperationFolderOp::fold(
 namespace {
 struct TestTraitFolder
     : public PassWrapper<TestTraitFolder, OperationPass<FuncOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestTraitFolder)
+
   StringRef getArgument() const final { return "test-trait-folder"; }
   StringRef getDescription() const final { return "Run trait folding"; }
   void runOnOperation() override {

diff  --git a/mlir/test/lib/Dialect/Tosa/TosaTestPasses.cpp b/mlir/test/lib/Dialect/Tosa/TosaTestPasses.cpp
index 299c48c9421e3..1295159b11948 100644
--- a/mlir/test/lib/Dialect/Tosa/TosaTestPasses.cpp
+++ b/mlir/test/lib/Dialect/Tosa/TosaTestPasses.cpp
@@ -179,6 +179,8 @@ namespace {
 
 struct TosaTestQuantUtilAPI
     : public PassWrapper<TosaTestQuantUtilAPI, OperationPass<FuncOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TosaTestQuantUtilAPI)
+
   StringRef getArgument() const final { return PASS_NAME; }
   StringRef getDescription() const final {
     return "TOSA Test: Exercise the APIs in QuantUtils.cpp.";

diff  --git a/mlir/test/lib/Dialect/Vector/TestVectorTransforms.cpp b/mlir/test/lib/Dialect/Vector/TestVectorTransforms.cpp
index 63f8060533fa7..73ff660014b75 100644
--- a/mlir/test/lib/Dialect/Vector/TestVectorTransforms.cpp
+++ b/mlir/test/lib/Dialect/Vector/TestVectorTransforms.cpp
@@ -30,6 +30,8 @@ namespace {
 
 struct TestVectorToVectorLowering
     : public PassWrapper<TestVectorToVectorLowering, OperationPass<FuncOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestVectorToVectorLowering)
+
   TestVectorToVectorLowering() = default;
   TestVectorToVectorLowering(const TestVectorToVectorLowering &pass)
       : PassWrapper(pass) {}
@@ -103,6 +105,8 @@ struct TestVectorToVectorLowering
 
 struct TestVectorContractionLowering
     : public PassWrapper<TestVectorContractionLowering, OperationPass<FuncOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestVectorContractionLowering)
+
   StringRef getArgument() const final {
     return "test-vector-contraction-lowering";
   }
@@ -176,6 +180,8 @@ struct TestVectorContractionLowering
 
 struct TestVectorTransposeLowering
     : public PassWrapper<TestVectorTransposeLowering, OperationPass<FuncOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestVectorTransposeLowering)
+
   StringRef getArgument() const final {
     return "test-vector-transpose-lowering";
   }
@@ -248,6 +254,8 @@ struct TestVectorTransposeLowering
 
 struct TestVectorUnrollingPatterns
     : public PassWrapper<TestVectorUnrollingPatterns, OperationPass<FuncOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestVectorUnrollingPatterns)
+
   StringRef getArgument() const final {
     return "test-vector-unrolling-patterns";
   }
@@ -315,6 +323,8 @@ struct TestVectorUnrollingPatterns
 
 struct TestVectorDistributePatterns
     : public PassWrapper<TestVectorDistributePatterns, OperationPass<FuncOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestVectorDistributePatterns)
+
   StringRef getArgument() const final {
     return "test-vector-distribute-patterns";
   }
@@ -372,6 +382,8 @@ struct TestVectorDistributePatterns
 
 struct TestVectorToLoopPatterns
     : public PassWrapper<TestVectorToLoopPatterns, OperationPass<FuncOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestVectorToLoopPatterns)
+
   StringRef getArgument() const final { return "test-vector-to-forloop"; }
   StringRef getDescription() const final {
     return "Test lowering patterns to break up a vector op into a for loop";
@@ -430,6 +442,9 @@ struct TestVectorToLoopPatterns
 struct TestVectorTransferUnrollingPatterns
     : public PassWrapper<TestVectorTransferUnrollingPatterns,
                          OperationPass<FuncOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(
+      TestVectorTransferUnrollingPatterns)
+
   void getDependentDialects(DialectRegistry &registry) const override {
     registry.insert<AffineDialect>();
   }
@@ -459,6 +474,9 @@ struct TestVectorTransferUnrollingPatterns
 struct TestVectorTransferFullPartialSplitPatterns
     : public PassWrapper<TestVectorTransferFullPartialSplitPatterns,
                          OperationPass<FuncOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(
+      TestVectorTransferFullPartialSplitPatterns)
+
   StringRef getArgument() const final {
     return "test-vector-transfer-full-partial-split";
   }
@@ -496,6 +514,8 @@ struct TestVectorTransferFullPartialSplitPatterns
 
 struct TestVectorTransferOpt
     : public PassWrapper<TestVectorTransferOpt, OperationPass<FuncOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestVectorTransferOpt)
+
   StringRef getArgument() const final { return "test-vector-transferop-opt"; }
   StringRef getDescription() const final {
     return "Test optimization transformations for transfer ops";
@@ -506,6 +526,9 @@ struct TestVectorTransferOpt
 struct TestVectorTransferLoweringPatterns
     : public PassWrapper<TestVectorTransferLoweringPatterns,
                          OperationPass<FuncOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(
+      TestVectorTransferLoweringPatterns)
+
   void getDependentDialects(DialectRegistry &registry) const override {
     registry.insert<tensor::TensorDialect, memref::MemRefDialect>();
   }
@@ -526,6 +549,9 @@ struct TestVectorTransferLoweringPatterns
 struct TestVectorMultiReductionLoweringPatterns
     : public PassWrapper<TestVectorMultiReductionLoweringPatterns,
                          OperationPass<FuncOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(
+      TestVectorMultiReductionLoweringPatterns)
+
   TestVectorMultiReductionLoweringPatterns() = default;
   TestVectorMultiReductionLoweringPatterns(
       const TestVectorMultiReductionLoweringPatterns &pass)
@@ -557,6 +583,9 @@ struct TestVectorMultiReductionLoweringPatterns
 struct TestVectorTransferCollapseInnerMostContiguousDims
     : public PassWrapper<TestVectorTransferCollapseInnerMostContiguousDims,
                          OperationPass<FuncOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(
+      TestVectorTransferCollapseInnerMostContiguousDims)
+
   TestVectorTransferCollapseInnerMostContiguousDims() = default;
   TestVectorTransferCollapseInnerMostContiguousDims(
       const TestVectorTransferCollapseInnerMostContiguousDims &pass) = default;
@@ -584,6 +613,9 @@ struct TestVectorTransferCollapseInnerMostContiguousDims
 struct TestVectorReduceToContractPatternsPatterns
     : public PassWrapper<TestVectorReduceToContractPatternsPatterns,
                          OperationPass<FuncOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(
+      TestVectorReduceToContractPatternsPatterns)
+
   StringRef getArgument() const final {
     return "test-vector-reduction-to-contract-patterns";
   }
@@ -601,6 +633,9 @@ struct TestVectorReduceToContractPatternsPatterns
 struct TestVectorTransferDropUnitDimsPatterns
     : public PassWrapper<TestVectorTransferDropUnitDimsPatterns,
                          OperationPass<FuncOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(
+      TestVectorTransferDropUnitDimsPatterns)
+
   StringRef getArgument() const final {
     return "test-vector-transfer-drop-unit-dims-patterns";
   }
@@ -617,6 +652,9 @@ struct TestVectorTransferDropUnitDimsPatterns
 struct TestFlattenVectorTransferPatterns
     : public PassWrapper<TestFlattenVectorTransferPatterns,
                          OperationPass<FuncOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(
+      TestFlattenVectorTransferPatterns)
+
   StringRef getArgument() const final {
     return "test-vector-transfer-flatten-patterns";
   }
@@ -636,6 +674,8 @@ struct TestFlattenVectorTransferPatterns
 
 struct TestVectorScanLowering
     : public PassWrapper<TestVectorScanLowering, OperationPass<FuncOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestVectorScanLowering)
+
   StringRef getArgument() const final { return "test-vector-scan-lowering"; }
   StringRef getDescription() const final {
     return "Test lowering patterns that lower the scan op in the vector "

diff  --git a/mlir/test/lib/IR/TestBuiltinAttributeInterfaces.cpp b/mlir/test/lib/IR/TestBuiltinAttributeInterfaces.cpp
index 96c162de775d3..05a1746436852 100644
--- a/mlir/test/lib/IR/TestBuiltinAttributeInterfaces.cpp
+++ b/mlir/test/lib/IR/TestBuiltinAttributeInterfaces.cpp
@@ -16,6 +16,8 @@ using namespace test;
 namespace {
 struct TestElementsAttrInterface
     : public PassWrapper<TestElementsAttrInterface, OperationPass<ModuleOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestElementsAttrInterface)
+
   StringRef getArgument() const final { return "test-elements-attr-interface"; }
   StringRef getDescription() const final {
     return "Test ElementsAttr interface support.";

diff  --git a/mlir/test/lib/IR/TestDiagnostics.cpp b/mlir/test/lib/IR/TestDiagnostics.cpp
index 123a2aa46442a..8995defe8a264 100644
--- a/mlir/test/lib/IR/TestDiagnostics.cpp
+++ b/mlir/test/lib/IR/TestDiagnostics.cpp
@@ -20,6 +20,8 @@ namespace {
 struct TestDiagnosticFilterPass
     : public PassWrapper<TestDiagnosticFilterPass,
                          InterfacePass<SymbolOpInterface>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestDiagnosticFilterPass)
+
   StringRef getArgument() const final { return "test-diagnostic-filter"; }
   StringRef getDescription() const final {
     return "Test diagnostic filtering support.";

diff  --git a/mlir/test/lib/IR/TestDominance.cpp b/mlir/test/lib/IR/TestDominance.cpp
index c450bfd855f0c..98f82388d5155 100644
--- a/mlir/test/lib/IR/TestDominance.cpp
+++ b/mlir/test/lib/IR/TestDominance.cpp
@@ -92,6 +92,8 @@ class DominanceTest {
 
 struct TestDominancePass
     : public PassWrapper<TestDominancePass, InterfacePass<SymbolOpInterface>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestDominancePass)
+
   StringRef getArgument() const final { return "test-print-dominance"; }
   StringRef getDescription() const final {
     return "Print the dominance information for multiple regions.";

diff  --git a/mlir/test/lib/IR/TestFunc.cpp b/mlir/test/lib/IR/TestFunc.cpp
index 9fb713857ea90..171d46abfde63 100644
--- a/mlir/test/lib/IR/TestFunc.cpp
+++ b/mlir/test/lib/IR/TestFunc.cpp
@@ -17,6 +17,8 @@ namespace {
 /// method.
 struct TestFuncInsertArg
     : public PassWrapper<TestFuncInsertArg, OperationPass<ModuleOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestFuncInsertArg)
+
   StringRef getArgument() const final { return "test-func-insert-arg"; }
   StringRef getDescription() const final { return "Test inserting func args."; }
   void runOnOperation() override {
@@ -52,6 +54,8 @@ struct TestFuncInsertArg
 /// This is a test pass for verifying FunctionOpInterface's insertResult method.
 struct TestFuncInsertResult
     : public PassWrapper<TestFuncInsertResult, OperationPass<ModuleOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestFuncInsertResult)
+
   StringRef getArgument() const final { return "test-func-insert-result"; }
   StringRef getDescription() const final {
     return "Test inserting func results.";
@@ -84,6 +88,8 @@ struct TestFuncInsertResult
 /// method.
 struct TestFuncEraseArg
     : public PassWrapper<TestFuncEraseArg, OperationPass<ModuleOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestFuncEraseArg)
+
   StringRef getArgument() const final { return "test-func-erase-arg"; }
   StringRef getDescription() const final { return "Test erasing func args."; }
   void runOnOperation() override {
@@ -102,6 +108,8 @@ struct TestFuncEraseArg
 /// This is a test pass for verifying FunctionOpInterface's eraseResult method.
 struct TestFuncEraseResult
     : public PassWrapper<TestFuncEraseResult, OperationPass<ModuleOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestFuncEraseResult)
+
   StringRef getArgument() const final { return "test-func-erase-result"; }
   StringRef getDescription() const final {
     return "Test erasing func results.";
@@ -122,6 +130,8 @@ struct TestFuncEraseResult
 /// This is a test pass for verifying FunctionOpInterface's setType method.
 struct TestFuncSetType
     : public PassWrapper<TestFuncSetType, OperationPass<ModuleOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestFuncSetType)
+
   StringRef getArgument() const final { return "test-func-set-type"; }
   StringRef getDescription() const final {
     return "Test FunctionOpInterface::setType.";

diff  --git a/mlir/test/lib/IR/TestInterfaces.cpp b/mlir/test/lib/IR/TestInterfaces.cpp
index 823c607435e06..28ed6542f6200 100644
--- a/mlir/test/lib/IR/TestInterfaces.cpp
+++ b/mlir/test/lib/IR/TestInterfaces.cpp
@@ -17,6 +17,8 @@ namespace {
 /// application.
 struct TestTypeInterfaces
     : public PassWrapper<TestTypeInterfaces, OperationPass<ModuleOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestTypeInterfaces)
+
   StringRef getArgument() const final { return "test-type-interfaces"; }
   StringRef getDescription() const final {
     return "Test type interface support.";

diff  --git a/mlir/test/lib/IR/TestMatchers.cpp b/mlir/test/lib/IR/TestMatchers.cpp
index bd8e7f5051912..03aa4f895efbb 100644
--- a/mlir/test/lib/IR/TestMatchers.cpp
+++ b/mlir/test/lib/IR/TestMatchers.cpp
@@ -18,6 +18,8 @@ namespace {
 /// This is a test pass for verifying matchers.
 struct TestMatchers
     : public PassWrapper<TestMatchers, InterfacePass<FunctionOpInterface>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestMatchers)
+
   void runOnOperation() override;
   StringRef getArgument() const final { return "test-matchers"; }
   StringRef getDescription() const final {

diff  --git a/mlir/test/lib/IR/TestOpaqueLoc.cpp b/mlir/test/lib/IR/TestOpaqueLoc.cpp
index 354f5bc997f09..56c3240b263b0 100644
--- a/mlir/test/lib/IR/TestOpaqueLoc.cpp
+++ b/mlir/test/lib/IR/TestOpaqueLoc.cpp
@@ -11,6 +11,21 @@
 
 using namespace mlir;
 
+namespace {
+/// A simple structure which is used for testing as an underlying location in
+/// OpaqueLoc.
+struct MyLocation {
+  MyLocation() = default;
+  MyLocation(int id) : id(id) {}
+  int getId() { return id; }
+
+  int id{42};
+};
+} // namespace
+
+MLIR_DECLARE_EXPLICIT_TYPE_ID(MyLocation *)
+MLIR_DEFINE_EXPLICIT_TYPE_ID(MyLocation *)
+
 namespace {
 /// Pass that changes locations to opaque locations for each operation.
 /// It also takes all operations that are not function operations or
@@ -18,21 +33,13 @@ namespace {
 /// locations.
 struct TestOpaqueLoc
     : public PassWrapper<TestOpaqueLoc, OperationPass<ModuleOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestOpaqueLoc)
+
   StringRef getArgument() const final { return "test-opaque-loc"; }
   StringRef getDescription() const final {
     return "Changes all leaf locations to opaque locations";
   }
 
-  /// A simple structure which is used for testing as an underlying location in
-  /// OpaqueLoc.
-  struct MyLocation {
-    MyLocation() = default;
-    MyLocation(int id) : id(id) {}
-    int getId() { return id; }
-
-    int id{42};
-  };
-
   void runOnOperation() override {
     std::vector<std::unique_ptr<MyLocation>> myLocs;
     int lastIt = 0;

diff  --git a/mlir/test/lib/IR/TestOperationEquals.cpp b/mlir/test/lib/IR/TestOperationEquals.cpp
index ede4da7775d86..6bfb59ef55533 100644
--- a/mlir/test/lib/IR/TestOperationEquals.cpp
+++ b/mlir/test/lib/IR/TestOperationEquals.cpp
@@ -15,6 +15,8 @@ namespace {
 /// This pass illustrates the IR def-use chains through printing.
 struct TestOperationEqualPass
     : public PassWrapper<TestOperationEqualPass, OperationPass<ModuleOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestOperationEqualPass)
+
   StringRef getArgument() const final { return "test-operations-equality"; }
   StringRef getDescription() const final { return "Test operations equality."; }
   void runOnOperation() override {

diff  --git a/mlir/test/lib/IR/TestPrintDefUse.cpp b/mlir/test/lib/IR/TestPrintDefUse.cpp
index bb180e0e19e59..0656036731a12 100644
--- a/mlir/test/lib/IR/TestPrintDefUse.cpp
+++ b/mlir/test/lib/IR/TestPrintDefUse.cpp
@@ -15,6 +15,8 @@ namespace {
 /// This pass illustrates the IR def-use chains through printing.
 struct TestPrintDefUsePass
     : public PassWrapper<TestPrintDefUsePass, OperationPass<>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestPrintDefUsePass)
+
   StringRef getArgument() const final { return "test-print-defuse"; }
   StringRef getDescription() const final { return "Test various printing."; }
   void runOnOperation() override {

diff  --git a/mlir/test/lib/IR/TestPrintInvalid.cpp b/mlir/test/lib/IR/TestPrintInvalid.cpp
index 9fec736307b4b..4b4322460428a 100644
--- a/mlir/test/lib/IR/TestPrintInvalid.cpp
+++ b/mlir/test/lib/IR/TestPrintInvalid.cpp
@@ -20,6 +20,8 @@ using namespace mlir;
 namespace {
 struct TestPrintInvalidPass
     : public PassWrapper<TestPrintInvalidPass, OperationPass<ModuleOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestPrintInvalidPass)
+
   StringRef getArgument() const final { return "test-print-invalid"; }
   StringRef getDescription() const final {
     return "Test printing invalid ops.";

diff  --git a/mlir/test/lib/IR/TestPrintNesting.cpp b/mlir/test/lib/IR/TestPrintNesting.cpp
index f50d917e79c6c..c66149b33371d 100644
--- a/mlir/test/lib/IR/TestPrintNesting.cpp
+++ b/mlir/test/lib/IR/TestPrintNesting.cpp
@@ -15,6 +15,8 @@ namespace {
 /// This pass illustrates the IR nesting through printing.
 struct TestPrintNestingPass
     : public PassWrapper<TestPrintNestingPass, OperationPass<>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestPrintNestingPass)
+
   StringRef getArgument() const final { return "test-print-nesting"; }
   StringRef getDescription() const final { return "Test various printing."; }
   // Entry point for the pass.

diff  --git a/mlir/test/lib/IR/TestSideEffects.cpp b/mlir/test/lib/IR/TestSideEffects.cpp
index d56414de744d4..09ad136322824 100644
--- a/mlir/test/lib/IR/TestSideEffects.cpp
+++ b/mlir/test/lib/IR/TestSideEffects.cpp
@@ -14,6 +14,8 @@ using namespace mlir;
 namespace {
 struct SideEffectsPass
     : public PassWrapper<SideEffectsPass, OperationPass<ModuleOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(SideEffectsPass)
+
   StringRef getArgument() const final { return "test-side-effects"; }
   StringRef getDescription() const final {
     return "Test side effects interfaces";

diff  --git a/mlir/test/lib/IR/TestSlicing.cpp b/mlir/test/lib/IR/TestSlicing.cpp
index f628d99e3c003..f64156d6f216e 100644
--- a/mlir/test/lib/IR/TestSlicing.cpp
+++ b/mlir/test/lib/IR/TestSlicing.cpp
@@ -47,6 +47,8 @@ namespace {
 /// Pass to test slice generated from slice analysis.
 struct SliceAnalysisTestPass
     : public PassWrapper<SliceAnalysisTestPass, OperationPass<ModuleOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(SliceAnalysisTestPass)
+
   StringRef getArgument() const final { return "slice-analysis-test"; }
   StringRef getDescription() const final {
     return "Test Slice analysis functionality.";

diff  --git a/mlir/test/lib/IR/TestSymbolUses.cpp b/mlir/test/lib/IR/TestSymbolUses.cpp
index 914dd25b067e3..34d84caeb1253 100644
--- a/mlir/test/lib/IR/TestSymbolUses.cpp
+++ b/mlir/test/lib/IR/TestSymbolUses.cpp
@@ -17,6 +17,8 @@ namespace {
 /// provided by the symbol table along with erasing from the symbol table.
 struct SymbolUsesPass
     : public PassWrapper<SymbolUsesPass, OperationPass<ModuleOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(SymbolUsesPass)
+
   StringRef getArgument() const final { return "test-symbol-uses"; }
   StringRef getDescription() const final {
     return "Test detection of symbol uses";
@@ -93,6 +95,8 @@ struct SymbolUsesPass
 /// functionality provided by the symbol table.
 struct SymbolReplacementPass
     : public PassWrapper<SymbolReplacementPass, OperationPass<ModuleOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(SymbolReplacementPass)
+
   StringRef getArgument() const final { return "test-symbol-rauw"; }
   StringRef getDescription() const final {
     return "Test replacement of symbol uses";

diff  --git a/mlir/test/lib/IR/TestTypes.cpp b/mlir/test/lib/IR/TestTypes.cpp
index 3127ee567a8f3..944075666fd7c 100644
--- a/mlir/test/lib/IR/TestTypes.cpp
+++ b/mlir/test/lib/IR/TestTypes.cpp
@@ -16,6 +16,8 @@ using namespace test;
 namespace {
 struct TestRecursiveTypesPass
     : public PassWrapper<TestRecursiveTypesPass, OperationPass<FuncOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestRecursiveTypesPass)
+
   LogicalResult createIRWithTypes();
 
   StringRef getArgument() const final { return "test-recursive-types"; }

diff  --git a/mlir/test/lib/IR/TestVisitors.cpp b/mlir/test/lib/IR/TestVisitors.cpp
index 23e72bb946fcc..a2ddff0c0f430 100644
--- a/mlir/test/lib/IR/TestVisitors.cpp
+++ b/mlir/test/lib/IR/TestVisitors.cpp
@@ -152,6 +152,8 @@ namespace {
 /// This pass exercises the 
diff erent configurations of the IR visitors.
 struct TestIRVisitorsPass
     : public PassWrapper<TestIRVisitorsPass, OperationPass<>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestIRVisitorsPass)
+
   StringRef getArgument() const final { return "test-ir-visitors"; }
   StringRef getDescription() const final { return "Test various visitors."; }
   void runOnOperation() override {

diff  --git a/mlir/test/lib/IR/TestVisitorsGeneric.cpp b/mlir/test/lib/IR/TestVisitorsGeneric.cpp
index 0a73c71061562..c51a0e0d392ad 100644
--- a/mlir/test/lib/IR/TestVisitorsGeneric.cpp
+++ b/mlir/test/lib/IR/TestVisitorsGeneric.cpp
@@ -22,9 +22,10 @@ static std::string getStageDescription(const WalkStage &stage) {
 namespace {
 /// This pass exercises generic visitor with void callbacks and prints the order
 /// and stage in which operations are visited.
-class TestGenericIRVisitorPass
+struct TestGenericIRVisitorPass
     : public PassWrapper<TestGenericIRVisitorPass, OperationPass<>> {
-public:
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestGenericIRVisitorPass)
+
   StringRef getArgument() const final { return "test-generic-ir-visitors"; }
   StringRef getDescription() const final { return "Test generic IR visitors."; }
   void runOnOperation() override {
@@ -46,9 +47,11 @@ class TestGenericIRVisitorPass
 /// This pass exercises the generic visitor with non-void callbacks and prints
 /// the order and stage in which operations are visited. It will interrupt the
 /// walk based on attributes peesent in the IR.
-class TestGenericIRVisitorInterruptPass
+struct TestGenericIRVisitorInterruptPass
     : public PassWrapper<TestGenericIRVisitorInterruptPass, OperationPass<>> {
-public:
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(
+      TestGenericIRVisitorInterruptPass)
+
   StringRef getArgument() const final {
     return "test-generic-ir-visitors-interrupt";
   }

diff  --git a/mlir/test/lib/Pass/TestDynamicPipeline.cpp b/mlir/test/lib/Pass/TestDynamicPipeline.cpp
index 114cf8c3b47b5..32ab8ec2b157d 100644
--- a/mlir/test/lib/Pass/TestDynamicPipeline.cpp
+++ b/mlir/test/lib/Pass/TestDynamicPipeline.cpp
@@ -20,6 +20,8 @@ namespace {
 class TestDynamicPipelinePass
     : public PassWrapper<TestDynamicPipelinePass, OperationPass<>> {
 public:
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestDynamicPipelinePass)
+
   StringRef getArgument() const final { return "test-dynamic-pipeline"; }
   StringRef getDescription() const final {
     return "Tests the dynamic pipeline feature by applying "

diff  --git a/mlir/test/lib/Pass/TestPassManager.cpp b/mlir/test/lib/Pass/TestPassManager.cpp
index cd0e4615cfa1d..4f3935b2bccdc 100644
--- a/mlir/test/lib/Pass/TestPassManager.cpp
+++ b/mlir/test/lib/Pass/TestPassManager.cpp
@@ -17,6 +17,8 @@ using namespace mlir;
 namespace {
 struct TestModulePass
     : public PassWrapper<TestModulePass, OperationPass<ModuleOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestModulePass)
+
   void runOnOperation() final {}
   StringRef getArgument() const final { return "test-module-pass"; }
   StringRef getDescription() const final {
@@ -25,15 +27,19 @@ struct TestModulePass
 };
 struct TestFunctionPass
     : public PassWrapper<TestFunctionPass, OperationPass<FuncOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestFunctionPass)
+
   void runOnOperation() final {}
   StringRef getArgument() const final { return "test-function-pass"; }
   StringRef getDescription() const final {
     return "Test a function pass in the pass manager";
   }
 };
-class TestInterfacePass
+struct TestInterfacePass
     : public PassWrapper<TestInterfacePass,
                          InterfacePass<FunctionOpInterface>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestInterfacePass)
+
   void runOnOperation() final {
     getOperation()->emitRemark() << "Executing interface pass on operation";
   }
@@ -43,9 +49,10 @@ class TestInterfacePass
            "pass manager";
   }
 };
-class TestOptionsPass
+struct TestOptionsPass
     : public PassWrapper<TestOptionsPass, OperationPass<FuncOp>> {
-public:
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestOptionsPass)
+
   struct Options : public PassPipelineOptions<Options> {
     ListOption<int> listOption{*this, "list",
                                llvm::cl::desc("Example list option")};
@@ -78,8 +85,10 @@ class TestOptionsPass
 
 /// A test pass that always aborts to enable testing the crash recovery
 /// mechanism of the pass manager.
-class TestCrashRecoveryPass
+struct TestCrashRecoveryPass
     : public PassWrapper<TestCrashRecoveryPass, OperationPass<>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestCrashRecoveryPass)
+
   void runOnOperation() final { abort(); }
   StringRef getArgument() const final { return "test-pass-crash"; }
   StringRef getDescription() const final {
@@ -89,7 +98,9 @@ class TestCrashRecoveryPass
 
 /// A test pass that always fails to enable testing the failure recovery
 /// mechanisms of the pass manager.
-class TestFailurePass : public PassWrapper<TestFailurePass, OperationPass<>> {
+struct TestFailurePass : public PassWrapper<TestFailurePass, OperationPass<>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestFailurePass)
+
   void runOnOperation() final { signalPassFailure(); }
   StringRef getArgument() const final { return "test-pass-failure"; }
   StringRef getDescription() const final {
@@ -99,9 +110,11 @@ class TestFailurePass : public PassWrapper<TestFailurePass, OperationPass<>> {
 
 /// A test pass that always fails to enable testing the failure recovery
 /// mechanisms of the pass manager.
-class TestInvalidParentPass
+struct TestInvalidParentPass
     : public PassWrapper<TestInvalidParentPass,
                          InterfacePass<FunctionOpInterface>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestInvalidParentPass)
+
   StringRef getArgument() const final { return "test-pass-invalid-parent"; }
   StringRef getDescription() const final {
     return "Test a pass in the pass manager that makes the parent operation "
@@ -121,6 +134,8 @@ class TestInvalidParentPass
 /// A test pass that contains a statistic.
 struct TestStatisticPass
     : public PassWrapper<TestStatisticPass, OperationPass<>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestStatisticPass)
+
   TestStatisticPass() = default;
   TestStatisticPass(const TestStatisticPass &) {}
   StringRef getArgument() const final { return "test-stats-pass"; }

diff  --git a/mlir/test/lib/Reducer/MLIRTestReducer.cpp b/mlir/test/lib/Reducer/MLIRTestReducer.cpp
index 77e8fc5b25314..ccfae10218441 100644
--- a/mlir/test/lib/Reducer/MLIRTestReducer.cpp
+++ b/mlir/test/lib/Reducer/MLIRTestReducer.cpp
@@ -22,6 +22,8 @@ namespace {
 /// "crashOp" in the input MLIR file and crashes the mlir-opt tool if the
 /// operation is found.
 struct TestReducer : public PassWrapper<TestReducer, OperationPass<>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestReducer)
+
   StringRef getArgument() const final { return "test-mlir-reducer"; }
   StringRef getDescription() const final {
     return "Tests MLIR Reduce tool by generating failures";

diff  --git a/mlir/test/lib/Rewrite/TestPDLByteCode.cpp b/mlir/test/lib/Rewrite/TestPDLByteCode.cpp
index c266bb71874a5..13465ba2865e0 100644
--- a/mlir/test/lib/Rewrite/TestPDLByteCode.cpp
+++ b/mlir/test/lib/Rewrite/TestPDLByteCode.cpp
@@ -67,6 +67,8 @@ static void customRewriter(ArrayRef<PDLValue> args, PatternRewriter &rewriter,
 namespace {
 struct TestPDLByteCodePass
     : public PassWrapper<TestPDLByteCodePass, OperationPass<ModuleOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestPDLByteCodePass)
+
   StringRef getArgument() const final { return "test-pdl-bytecode-pass"; }
   StringRef getDescription() const final {
     return "Test PDL ByteCode functionality";

diff  --git a/mlir/test/lib/Transforms/TestConstantFold.cpp b/mlir/test/lib/Transforms/TestConstantFold.cpp
index e2b20f12cc276..1af923e014d52 100644
--- a/mlir/test/lib/Transforms/TestConstantFold.cpp
+++ b/mlir/test/lib/Transforms/TestConstantFold.cpp
@@ -15,6 +15,8 @@ namespace {
 /// Simple constant folding pass.
 struct TestConstantFold
     : public PassWrapper<TestConstantFold, OperationPass<>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestConstantFold)
+
   StringRef getArgument() const final { return "test-constant-fold"; }
   StringRef getDescription() const final {
     return "Test operation constant folding";

diff  --git a/mlir/test/lib/Transforms/TestControlFlowSink.cpp b/mlir/test/lib/Transforms/TestControlFlowSink.cpp
index f6ec809341519..ab2eaea535e4c 100644
--- a/mlir/test/lib/Transforms/TestControlFlowSink.cpp
+++ b/mlir/test/lib/Transforms/TestControlFlowSink.cpp
@@ -24,6 +24,8 @@ namespace {
 /// `was_sunk` into the first region of `test.sink_target` ops.
 struct TestControlFlowSinkPass
     : public PassWrapper<TestControlFlowSinkPass, OperationPass<FuncOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestControlFlowSinkPass)
+
   /// Get the command-line argument of the test pass.
   StringRef getArgument() const final { return "test-control-flow-sink"; }
   /// Get the description of the test pass.

diff  --git a/mlir/test/lib/Transforms/TestInlining.cpp b/mlir/test/lib/Transforms/TestInlining.cpp
index f4d5eed024ab6..54ae63514717f 100644
--- a/mlir/test/lib/Transforms/TestInlining.cpp
+++ b/mlir/test/lib/Transforms/TestInlining.cpp
@@ -25,6 +25,8 @@ using namespace test;
 
 namespace {
 struct Inliner : public PassWrapper<Inliner, OperationPass<FuncOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(Inliner)
+
   StringRef getArgument() const final { return "test-inline"; }
   StringRef getDescription() const final {
     return "Test inlining region calls";

diff  --git a/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp b/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
index c9a512ae18e58..cd37655344c9a 100644
--- a/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
+++ b/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
@@ -663,8 +663,9 @@ bool DefGenerator::emitDecls(StringRef selectedDialect) {
   // each of these.
   for (const AttrOrTypeDef &def : defs)
     if (!def.getDialect().getCppNamespace().empty())
-      os << "DECLARE_EXPLICIT_TYPE_ID(" << def.getDialect().getCppNamespace()
-         << "::" << def.getCppClassName() << ")\n";
+      os << "MLIR_DECLARE_EXPLICIT_TYPE_ID("
+         << def.getDialect().getCppNamespace() << "::" << def.getCppClassName()
+         << ")\n";
 
   return false;
 }
@@ -827,8 +828,9 @@ bool DefGenerator::emitDefs(StringRef selectedDialect) {
     }
     // Emit the TypeID explicit specializations to have a single symbol def.
     if (!def.getDialect().getCppNamespace().empty())
-      os << "DEFINE_EXPLICIT_TYPE_ID(" << def.getDialect().getCppNamespace()
-         << "::" << def.getCppClassName() << ")\n";
+      os << "MLIR_DEFINE_EXPLICIT_TYPE_ID("
+         << def.getDialect().getCppNamespace() << "::" << def.getCppClassName()
+         << ")\n";
   }
 
   Dialect firstDialect = defs.front().getDialect();

diff  --git a/mlir/tools/mlir-tblgen/DialectGen.cpp b/mlir/tools/mlir-tblgen/DialectGen.cpp
index 6338cf19d1b96..c9f036b6a32cb 100644
--- a/mlir/tools/mlir-tblgen/DialectGen.cpp
+++ b/mlir/tools/mlir-tblgen/DialectGen.cpp
@@ -236,7 +236,7 @@ emitDialectDecl(Dialect &dialect,
     os << "};\n";
   }
   if (!dialect.getCppNamespace().empty())
-    os << "DECLARE_EXPLICIT_TYPE_ID(" << dialect.getCppNamespace()
+    os << "MLIR_DECLARE_EXPLICIT_TYPE_ID(" << dialect.getCppNamespace()
        << "::" << dialect.getCppClassName() << ")\n";
 }
 
@@ -273,7 +273,7 @@ static const char *const dialectDestructorStr = R"(
 static void emitDialectDef(Dialect &dialect, raw_ostream &os) {
   // Emit the TypeID explicit specializations to have a single symbol def.
   if (!dialect.getCppNamespace().empty())
-    os << "DEFINE_EXPLICIT_TYPE_ID(" << dialect.getCppNamespace()
+    os << "MLIR_DEFINE_EXPLICIT_TYPE_ID(" << dialect.getCppNamespace()
        << "::" << dialect.getCppClassName() << ")\n";
 
   // Emit all nested namespaces.

diff  --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
index 05a9f83aa6437..d54bd7e493ab7 100644
--- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
@@ -2778,7 +2778,7 @@ static void emitOpClasses(const RecordKeeper &recordKeeper,
       }
       // Emit the TypeID explicit specialization to have a single definition.
       if (!op.getCppNamespace().empty())
-        os << "DECLARE_EXPLICIT_TYPE_ID(" << op.getCppNamespace()
+        os << "MLIR_DECLARE_EXPLICIT_TYPE_ID(" << op.getCppNamespace()
            << "::" << op.getCppClassName() << ")\n\n";
     } else {
       {
@@ -2789,7 +2789,7 @@ static void emitOpClasses(const RecordKeeper &recordKeeper,
       }
       // Emit the TypeID explicit specialization to have a single definition.
       if (!op.getCppNamespace().empty())
-        os << "DEFINE_EXPLICIT_TYPE_ID(" << op.getCppNamespace()
+        os << "MLIR_DEFINE_EXPLICIT_TYPE_ID(" << op.getCppNamespace()
            << "::" << op.getCppClassName() << ")\n\n";
     }
   }

diff  --git a/mlir/tools/mlir-tblgen/PassGen.cpp b/mlir/tools/mlir-tblgen/PassGen.cpp
index 7d98a600519f8..1c734aba192a5 100644
--- a/mlir/tools/mlir-tblgen/PassGen.cpp
+++ b/mlir/tools/mlir-tblgen/PassGen.cpp
@@ -79,6 +79,11 @@ class {0}Base : public {1} {
     {4}
   }
 
+  /// Explicitly declare the TypeID for this class. We declare an explicit private
+  /// instantiation because Pass classes should only be visible by the current
+  /// library.
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID({0}Base<DerivedT>)
+
 protected:
 )";
 

diff  --git a/mlir/unittests/IR/DialectTest.cpp b/mlir/unittests/IR/DialectTest.cpp
index 1da7775d8eca9..a2b58bf731976 100644
--- a/mlir/unittests/IR/DialectTest.cpp
+++ b/mlir/unittests/IR/DialectTest.cpp
@@ -15,11 +15,15 @@ using namespace mlir::detail;
 
 namespace {
 struct TestDialect : public Dialect {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestDialect)
+
   static StringRef getDialectNamespace() { return "test"; };
   TestDialect(MLIRContext *context)
       : Dialect(getDialectNamespace(), context, TypeID::get<TestDialect>()) {}
 };
 struct AnotherTestDialect : public Dialect {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(AnotherTestDialect)
+
   static StringRef getDialectNamespace() { return "test"; };
   AnotherTestDialect(MLIRContext *context)
       : Dialect(getDialectNamespace(), context,
@@ -36,6 +40,8 @@ TEST(DialectDeathTest, MultipleDialectsWithSameNamespace) {
 }
 
 struct SecondTestDialect : public Dialect {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(SecondTestDialect)
+
   static StringRef getDialectNamespace() { return "test2"; }
   SecondTestDialect(MLIRContext *context)
       : Dialect(getDialectNamespace(), context,
@@ -44,16 +50,22 @@ struct SecondTestDialect : public Dialect {
 
 struct TestDialectInterfaceBase
     : public DialectInterface::Base<TestDialectInterfaceBase> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestDialectInterfaceBase)
+
   TestDialectInterfaceBase(Dialect *dialect) : Base(dialect) {}
   virtual int function() const { return 42; }
 };
 
 struct TestDialectInterface : public TestDialectInterfaceBase {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestDialectInterface)
+
   using TestDialectInterfaceBase::TestDialectInterfaceBase;
   int function() const final { return 56; }
 };
 
 struct SecondTestDialectInterface : public TestDialectInterfaceBase {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(SecondTestDialectInterface)
+
   using TestDialectInterfaceBase::TestDialectInterfaceBase;
   int function() const final { return 78; }
 };

diff  --git a/mlir/unittests/Interfaces/DataLayoutInterfacesTest.cpp b/mlir/unittests/Interfaces/DataLayoutInterfacesTest.cpp
index bfe21a45e39a1..4be64e494ab96 100644
--- a/mlir/unittests/Interfaces/DataLayoutInterfacesTest.cpp
+++ b/mlir/unittests/Interfaces/DataLayoutInterfacesTest.cpp
@@ -49,6 +49,8 @@ struct CustomDataLayoutSpec
     : public Attribute::AttrBase<CustomDataLayoutSpec, Attribute,
                                  DataLayoutSpecStorage,
                                  DataLayoutSpecInterface::Trait> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(CustomDataLayoutSpec)
+
   using Base::Base;
   static CustomDataLayoutSpec get(MLIRContext *ctx,
                                   ArrayRef<DataLayoutEntryInterface> entries) {
@@ -67,6 +69,8 @@ struct CustomDataLayoutSpec
 struct SingleQueryType
     : public Type::TypeBase<SingleQueryType, Type, TypeStorage,
                             DataLayoutTypeInterface::Trait> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(SingleQueryType)
+
   using Base::Base;
 
   static SingleQueryType get(MLIRContext *ctx) { return Base::get(ctx); }
@@ -104,6 +108,8 @@ struct SingleQueryType
 
 /// A types that is not subject to data layout.
 struct TypeNoLayout : public Type::TypeBase<TypeNoLayout, Type, TypeStorage> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TypeNoLayout)
+
   using Base::Base;
 
   static TypeNoLayout get(MLIRContext *ctx) { return Base::get(ctx); }
@@ -113,6 +119,8 @@ struct TypeNoLayout : public Type::TypeBase<TypeNoLayout, Type, TypeStorage> {
 /// attribute attached. This can handle data layout requests for the built-in
 /// types itself.
 struct OpWithLayout : public Op<OpWithLayout, DataLayoutOpInterface::Trait> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(OpWithLayout)
+
   using Op::Op;
   static ArrayRef<StringRef> getAttributeNames() { return {}; }
 
@@ -156,6 +164,8 @@ struct OpWithLayout : public Op<OpWithLayout, DataLayoutOpInterface::Trait> {
 
 struct OpWith7BitByte
     : public Op<OpWith7BitByte, DataLayoutOpInterface::Trait> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(OpWith7BitByte)
+
   using Op::Op;
   static ArrayRef<StringRef> getAttributeNames() { return {}; }
 
@@ -174,6 +184,8 @@ struct OpWith7BitByte
 
 /// A dialect putting all the above together.
 struct DLTestDialect : Dialect {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(DLTestDialect)
+
   explicit DLTestDialect(MLIRContext *ctx)
       : Dialect(getDialectNamespace(), ctx, TypeID::get<DLTestDialect>()) {
     ctx->getOrLoadDialect<DLTIDialect>();

diff  --git a/mlir/unittests/Pass/AnalysisManagerTest.cpp b/mlir/unittests/Pass/AnalysisManagerTest.cpp
index 036dc7c93f5d4..e6613b5ddf2be 100644
--- a/mlir/unittests/Pass/AnalysisManagerTest.cpp
+++ b/mlir/unittests/Pass/AnalysisManagerTest.cpp
@@ -20,12 +20,18 @@ using namespace mlir::detail;
 namespace {
 /// Minimal class definitions for two analyses.
 struct MyAnalysis {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(MyAnalysis)
+
   MyAnalysis(Operation *) {}
 };
 struct OtherAnalysis {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(OtherAnalysis)
+
   OtherAnalysis(Operation *) {}
 };
 struct OpSpecificAnalysis {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(OpSpecificAnalysis)
+
   OpSpecificAnalysis(ModuleOp) {}
 };
 
@@ -116,9 +122,13 @@ TEST(AnalysisManagerTest, FineGrainChildFunctionAnalysisPreservation) {
 }
 
 /// Test analyses with custom invalidation logic.
-struct TestAnalysisSet {};
+struct TestAnalysisSet {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestAnalysisSet)
+};
 
 struct CustomInvalidatingAnalysis {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(CustomInvalidatingAnalysis)
+
   CustomInvalidatingAnalysis(Operation *) {}
 
   bool isInvalidated(const AnalysisManager::PreservedAnalyses &pa) {
@@ -163,6 +173,8 @@ TEST(AnalysisManagerTest, OpSpecificAnalysis) {
 }
 
 struct AnalysisWithDependency {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(AnalysisWithDependency)
+
   AnalysisWithDependency(Operation *, AnalysisManager &am) {
     am.getAnalysis<MyAnalysis>();
   }
@@ -194,6 +206,8 @@ TEST(AnalysisManagerTest, DependentAnalysis) {
 }
 
 struct AnalysisWithNestedDependency {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(AnalysisWithNestedDependency)
+
   AnalysisWithNestedDependency(Operation *, AnalysisManager &am) {
     am.getAnalysis<AnalysisWithDependency>();
   }
@@ -228,6 +242,8 @@ TEST(AnalysisManagerTest, NestedDependentAnalysis) {
 }
 
 struct AnalysisWith2Ctors {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(AnalysisWith2Ctors)
+
   AnalysisWith2Ctors(Operation *) { ctor1called = true; }
 
   AnalysisWith2Ctors(Operation *, AnalysisManager &) { ctor2called = true; }

diff  --git a/mlir/unittests/Pass/PassManagerTest.cpp b/mlir/unittests/Pass/PassManagerTest.cpp
index 5227c91250b5c..0b08a848ed5d2 100644
--- a/mlir/unittests/Pass/PassManagerTest.cpp
+++ b/mlir/unittests/Pass/PassManagerTest.cpp
@@ -21,12 +21,16 @@ using namespace mlir::detail;
 namespace {
 /// Analysis that operates on any operation.
 struct GenericAnalysis {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(GenericAnalysis)
+
   GenericAnalysis(Operation *op) : isFunc(isa<FuncOp>(op)) {}
   const bool isFunc;
 };
 
 /// Analysis that operates on a specific operation.
 struct OpSpecificAnalysis {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(OpSpecificAnalysis)
+
   OpSpecificAnalysis(FuncOp op) : isSecret(op.getName() == "secret") {}
   const bool isSecret;
 };
@@ -34,6 +38,8 @@ struct OpSpecificAnalysis {
 /// Simple pass to annotate a FuncOp with the results of analysis.
 struct AnnotateFunctionPass
     : public PassWrapper<AnnotateFunctionPass, OperationPass<FuncOp>> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(AnnotateFunctionPass)
+
   void runOnOperation() override {
     FuncOp op = getOperation();
     Builder builder(op->getParentOfType<ModuleOp>());
@@ -80,6 +86,8 @@ TEST(PassManagerTest, OpSpecificAnalysis) {
 
 namespace {
 struct InvalidPass : Pass {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(InvalidPass)
+
   InvalidPass() : Pass(TypeID::get<InvalidPass>(), StringRef("invalid_op")) {}
   StringRef getName() const override { return "Invalid Pass"; }
   void runOnOperation() override {}

diff  --git a/mlir/unittests/Transforms/Canonicalizer.cpp b/mlir/unittests/Transforms/Canonicalizer.cpp
index d643237780311..4b94e0602b509 100644
--- a/mlir/unittests/Transforms/Canonicalizer.cpp
+++ b/mlir/unittests/Transforms/Canonicalizer.cpp
@@ -50,6 +50,8 @@ struct EnabledPattern : public RewritePattern {
 };
 
 struct TestDialect : public Dialect {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestDialect)
+
   static StringRef getDialectNamespace() { return "test"; }
 
   TestDialect(MLIRContext *context)

diff  --git a/mlir/unittests/Transforms/DialectConversion.cpp b/mlir/unittests/Transforms/DialectConversion.cpp
index 13ce43160f4e8..79a02702b48a6 100644
--- a/mlir/unittests/Transforms/DialectConversion.cpp
+++ b/mlir/unittests/Transforms/DialectConversion.cpp
@@ -20,6 +20,8 @@ static Operation *createOp(MLIRContext *context) {
 
 namespace {
 struct DummyOp {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(DummyOp)
+
   static StringRef getOperationName() { return "foo.bar"; }
 };
 


        


More information about the Mlir-commits mailing list