10#include "llvm/ADT/DenseMap.h"
11#include "llvm/ADT/StringRef.h"
12#include "llvm/Support/Debug.h"
13#include "llvm/Support/RWMutex.h"
15#include "llvm/Support/Signals.h"
16#include "llvm/Support/raw_ostream.h"
20#define DEBUG_TYPE "typeid"
27struct ImplicitTypeIDRegistry {
29 TypeID lookupOrInsert(StringRef typeName) {
38 if (typeName.contains(
"anonymous namespace") ||
39 typeName.contains(
"{anonymous}") ||
40 typeName.contains(
"anonymous-namespace")) {
43 llvm::raw_string_ostream errorOS(errorStr);
44 errorOS <<
"TypeID::get<" << typeName
45 <<
">(): Using TypeID on a class with an anonymous "
46 "namespace requires an explicit TypeID definition. The "
47 "implicit fallback uses string name, which does not "
48 "guarantee uniqueness in anonymous contexts. Define an "
49 "explicit TypeID instantiation for this type using "
50 "`MLIR_DECLARE_EXPLICIT_TYPE_ID`/"
51 "`MLIR_DEFINE_EXPLICIT_TYPE_ID` or "
52 "`MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID`.\n";
54 llvm::report_fatal_error(llvm::StringRef(errorStr));
59 llvm::sys::SmartScopedReader<true> guard(mutex);
60 auto it = typeNameToID.find(typeName);
61 if (it != typeNameToID.end())
64 llvm::sys::SmartScopedWriter<true> guard(mutex);
65 auto it = typeNameToID.try_emplace(typeName,
TypeID());
67 it.first->second = typeIDAllocator.allocate();
68 return it.first->second;
72 llvm::sys::SmartRWMutex<true> mutex;
84 static ImplicitTypeIDRegistry registry;
85 return registry.lookupOrInsert(name);
#define MLIR_DEFINE_EXPLICIT_SELF_OWNING_TYPE_ID(CLASS_NAME)
This class provides a way to define new TypeIDs at runtime.
This class provides an efficient unique identifier for a specific C++ type.
static LLVM_ALWAYS_EXPORT TypeID registerImplicitTypeID(StringRef name)
Register an implicit type ID for the given type name.
Include the generated interface declarations.
llvm::DenseMap< KeyT, ValueT, KeyInfoT, BucketT > DenseMap