14 #ifndef CIRCT_SUPPORT_NAMESPACE_H
15 #define CIRCT_SUPPORT_NAMESPACE_H
19 #include "llvm/ADT/SmallString.h"
20 #include "llvm/ADT/StringSet.h"
21 #include "llvm/ADT/Twine.h"
48 for (
auto &&[attr, _] : symCache)
49 if (
auto strAttr = attr.dyn_cast<StringAttr>())
50 nextIndex.insert({strAttr.getValue(), 0});
66 llvm::SmallString<64> tryName;
67 auto inserted =
nextIndex.insert({name.toStringRef(tryName), 0});
69 return inserted.first->getKey();
73 name.toVector(tryName);
78 tryName.push_back(
'_');
79 size_t baseLength = tryName.size();
81 tryName.resize(baseLength);
82 Twine(i++).toVector(tryName);
83 inserted =
nextIndex.insert({tryName, 0});
84 }
while (!inserted.second);
86 return inserted.first->getKey();
96 StringRef
newName(
const Twine &name,
const Twine &suffix) {
99 llvm::SmallString<64> tryName;
101 {name.concat(
"_").
concat(suffix).toStringRef(tryName), 0});
103 return inserted.first->getKey();
107 name.toVector(tryName);
108 tryName.push_back(
'_');
109 size_t baseLength = tryName.size();
114 tryName.push_back(
':');
115 suffix.toVector(tryName);
121 tryName.resize(baseLength);
122 Twine(i++).toVector(tryName);
123 tryName.push_back(
'_');
124 suffix.toVector(tryName);
125 inserted =
nextIndex.insert({tryName, 0});
126 }
while (!inserted.second);
128 return inserted.first->getKey();
static SmallVector< T > concat(const SmallVectorImpl< T > &a, const SmallVectorImpl< T > &b)
Returns a new vector containing the concatenation of vectors a and b.
A namespace that is used to store existing names and generate new names in some scope within the IR.
Namespace & operator=(const Namespace &other)=default
void clear()
Empty the namespace.
Namespace & operator=(Namespace &&other)
llvm::StringMap< size_t > nextIndex
void add(SymbolCache &symCache)
SymbolCache initializer; initialize from every key that is convertible to a StringAttr in the SymbolC...
StringRef newName(const Twine &name, const Twine &suffix)
Return a unique name, derived from the input name and ensure the returned name has the input suffix.
Namespace(Namespace &&other)
Namespace(const Namespace &other)=default
StringRef newName(const Twine &name)
Return a unique name, derived from the input name, and add the new name to the internal namespace.
Default symbol cache implementation; stores associations between names (StringAttr's) to mlir::Operat...
This file defines an intermediate representation for circuits acting as an abstraction for constraint...