14#ifndef MLIR_SUPPORT_NAMESPACE_H
15#define MLIR_SUPPORT_NAMESPACE_H
19#include "llvm/ADT/SmallString.h"
20#include "llvm/ADT/StringSet.h"
21#include "llvm/ADT/Twine.h"
47 void add(mlir::ModuleOp module) {
48 assert(module->getNumRegions() == 1);
49 for (
auto &op : module.getBody(0)->getOperations())
50 if (
auto symbol = op.getAttrOfType<mlir::StringAttr>(
58 for (
auto &&[attr, _] : symCache)
59 if (
auto strAttr = dyn_cast<mlir::StringAttr>(attr))
60 nextIndex.insert({strAttr.getValue(), 0});
68 bool erase(llvm::StringRef symbol) {
69 assert(!
locked &&
"Cannot erase names from a locked namespace");
86 llvm::StringRef
newName(
const llvm::Twine &name) {
97 name.toVector(tryName);
102 tryName.push_back(
'_');
103 size_t baseLength = tryName.size();
105 tryName.resize(baseLength);
106 llvm::Twine(i++).toVector(tryName);
120 llvm::StringRef
newName(
const llvm::Twine &name,
const llvm::Twine &suffix) {
126 {name.concat(
"_").concat(suffix).toStringRef(tryName), 0});
132 name.toVector(tryName);
133 tryName.push_back(
'_');
134 size_t baseLength = tryName.size();
139 tryName.push_back(
':');
140 suffix.toVector(tryName);
146 tryName.resize(baseLength);
147 llvm::Twine(i++).toVector(tryName);
148 tryName.push_back(
'_');
149 suffix.toVector(tryName);
*if copies could not be generated due to yet unimplemented cases *copyInPlacementStart and copyOutPlacementStart in copyPlacementBlock *specify the insertion points where the incoming copies and outgoing should be inserted(the insertion happens right before the *insertion point). Since `begin` can itself be invalidated due to the memref *rewriting done from this method
llvm::StringMap< size_t > nextIndex
void add(SymbolCache &symCache)
SymbolCache initializer; initialize from every key that is convertible to a StringAttr in the SymbolC...
llvm::StringRef newName(const llvm::Twine &name, const llvm::Twine &suffix)
Return a unique name, derived from the input name and ensure the returned name has the input suffix.
Namespace & operator=(const Namespace &other)=default
Namespace(Namespace &&other)
bool erase(llvm::StringRef symbol)
Removes a symbol from the namespace.
void add(mlir::ModuleOp module)
Namespace & operator=(Namespace &&other)
void add(llvm::StringRef name)
void clear()
Empty the namespace.
llvm::StringRef newName(const llvm::Twine &name)
Return a unique name, derived from the input name, and add the new name to the internal namespace.
Namespace(const Namespace &other)=default
Default symbol cache implementation; stores associations between names (StringAttr's) to mlir::Operat...
static StringRef getSymbolAttrName()
Return the name of the attribute used for symbol names.
Include the generated interface declarations.