forked from OSchip/llvm-project
[mlir] Fix ssa values naming bug
Address comments in https://reviews.llvm.org/D102226 to fix the bug + style violations Differential Revision: https://reviews.llvm.org/D102368
This commit is contained in:
parent
cd01430ff1
commit
fb3a00c327
|
@ -842,54 +842,57 @@ SSANameState::SSANameState(
|
||||||
llvm::SaveAndRestore<unsigned> argumentIDSaver(nextArgumentID);
|
llvm::SaveAndRestore<unsigned> argumentIDSaver(nextArgumentID);
|
||||||
llvm::SaveAndRestore<unsigned> conflictIDSaver(nextConflictID);
|
llvm::SaveAndRestore<unsigned> conflictIDSaver(nextConflictID);
|
||||||
|
|
||||||
// The context includes nextValueID, nextArgumentID, nextConflictID and scoped
|
// The naming context includes `nextValueID`, `nextArgumentID`,
|
||||||
// HashTable.
|
// `nextConflictID` and `usedNames` scoped HashTable. This information is
|
||||||
using hashTableScopeTy = llvm::ScopedHashTable<StringRef, char>::ScopeTy;
|
// carried from the parent region.
|
||||||
// A namingContext carries the information inherits from parent region.
|
using UsedNamesScopeTy = llvm::ScopedHashTable<StringRef, char>::ScopeTy;
|
||||||
using namingContext =
|
using NamingContext =
|
||||||
std::tuple<Region *, unsigned, unsigned, unsigned, hashTableScopeTy *>;
|
std::tuple<Region *, unsigned, unsigned, unsigned, UsedNamesScopeTy *>;
|
||||||
// Allocator for hashTableScopeTy
|
|
||||||
|
// Allocator for UsedNamesScopeTy
|
||||||
llvm::BumpPtrAllocator allocator;
|
llvm::BumpPtrAllocator allocator;
|
||||||
|
|
||||||
SmallVector<namingContext, 8> nameContext;
|
// Add a scope for the top level operation.
|
||||||
|
auto *topLevelNamesScope =
|
||||||
|
new (allocator.Allocate<UsedNamesScopeTy>()) UsedNamesScopeTy(usedNames);
|
||||||
|
|
||||||
|
SmallVector<NamingContext, 8> nameContext;
|
||||||
for (Region ®ion : op->getRegions())
|
for (Region ®ion : op->getRegions())
|
||||||
nameContext.push_back(std::make_tuple(®ion, nextValueID, nextArgumentID,
|
nameContext.push_back(std::make_tuple(®ion, nextValueID, nextArgumentID,
|
||||||
nextConflictID, nullptr));
|
nextConflictID, topLevelNamesScope));
|
||||||
|
|
||||||
numberValuesInOp(*op, interfaces);
|
numberValuesInOp(*op, interfaces);
|
||||||
|
|
||||||
while (!nameContext.empty()) {
|
while (!nameContext.empty()) {
|
||||||
Region *region;
|
Region *region;
|
||||||
hashTableScopeTy *parentScope;
|
UsedNamesScopeTy *parentScope;
|
||||||
std::tie(region, nextValueID, nextArgumentID, nextConflictID, parentScope) =
|
std::tie(region, nextValueID, nextArgumentID, nextConflictID, parentScope) =
|
||||||
nameContext.pop_back_val();
|
nameContext.pop_back_val();
|
||||||
|
|
||||||
// When we switch from one subtree to another, pop the scopes(needless)
|
// When we switch from one subtree to another, pop the scopes(needless)
|
||||||
// until the parent scope.
|
// until the parent scope.
|
||||||
while (usedNames.getCurScope() != parentScope) {
|
while (usedNames.getCurScope() != parentScope) {
|
||||||
usedNames.getCurScope()->~hashTableScopeTy();
|
usedNames.getCurScope()->~UsedNamesScopeTy();
|
||||||
assert((usedNames.getCurScope() != nullptr || parentScope == nullptr) &&
|
assert((usedNames.getCurScope() != nullptr || parentScope == nullptr) &&
|
||||||
"top level parentScope must be a nullptr");
|
"top level parentScope must be a nullptr");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a scope for the current region.
|
// Add a scope for the current region.
|
||||||
auto *curNamesScope = allocator.Allocate<hashTableScopeTy>();
|
auto *curNamesScope = new (allocator.Allocate<UsedNamesScopeTy>())
|
||||||
new (curNamesScope) hashTableScopeTy(usedNames);
|
UsedNamesScopeTy(usedNames);
|
||||||
|
|
||||||
numberValuesInRegion(*region, interfaces);
|
numberValuesInRegion(*region, interfaces);
|
||||||
|
|
||||||
for (Block &block : *region) {
|
for (Operation &op : region->getOps())
|
||||||
for (Operation &op : block)
|
for (Region ®ion : op.getRegions())
|
||||||
for (Region ®ion : op.getRegions())
|
nameContext.push_back(std::make_tuple(®ion, nextValueID,
|
||||||
nameContext.push_back(std::make_tuple(®ion, nextValueID,
|
nextArgumentID, nextConflictID,
|
||||||
nextArgumentID, nextConflictID,
|
curNamesScope));
|
||||||
curNamesScope));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Manually remove all the scopes.
|
// Manually remove all the scopes.
|
||||||
while (usedNames.getCurScope() != nullptr)
|
while (usedNames.getCurScope() != nullptr)
|
||||||
usedNames.getCurScope()->~hashTableScopeTy();
|
usedNames.getCurScope()->~UsedNamesScopeTy();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SSANameState::printValueID(Value value, bool printResultNo,
|
void SSANameState::printValueID(Value value, bool printResultNo,
|
||||||
|
|
Loading…
Reference in New Issue