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 = mlir::dyn_cast<mlir::SymbolOpInterface>(&op))
57 for (
auto &&[attr, _] : symCache)
58 if (
auto strAttr = dyn_cast<mlir::StringAttr>(attr))
59 nextIndex.insert({strAttr.getValue(), 0});
67 bool erase(llvm::StringRef symbol) {
68 assert(!
locked &&
"Cannot erase names from a locked namespace");
85 llvm::StringRef
newName(
const llvm::Twine &name) {
96 name.toVector(tryName);
101 tryName.push_back(
'_');
102 size_t baseLength = tryName.size();
104 tryName.resize(baseLength);
105 llvm::Twine(i++).toVector(tryName);
119 llvm::StringRef
newName(
const llvm::Twine &name,
const llvm::Twine &suffix) {
125 {name.concat(
"_").concat(suffix).toStringRef(tryName), 0});
131 name.toVector(tryName);
132 tryName.push_back(
'_');
133 size_t baseLength = tryName.size();
138 tryName.push_back(
':');
139 suffix.toVector(tryName);
145 tryName.resize(baseLength);
146 llvm::Twine(i++).toVector(tryName);
147 tryName.push_back(
'_');
148 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...
Include the generated interface declarations.