[llvm] [Transforms][IPO] Add func suffix in ArgumentPromotion and DeadArgume… (PR #105742)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 23 16:59:21 PDT 2024
================
@@ -200,6 +200,7 @@ doPromotion(Function *F, FunctionAnalysisManager &FAM,
F->getParent()->getFunctionList().insert(F->getIterator(), NF);
NF->takeName(F);
----------------
yonghong-song wrote:
The following is takeName() implementation:
```
void Value::takeName(Value *V) {
assert(V != this && "Illegal call to this->takeName(this)!");
ValueSymbolTable *ST = nullptr;
// If this value has a name, drop it.
if (hasName()) {
// Get the symtab this is in.
if (getSymTab(this, ST)) {
// We can't set a name on this value, but we need to clear V's name if
// it has one.
if (V->hasName()) V->setName("");
return; // Cannot set a name on this value (e.g. constant).
}
// Remove old name.
if (ST)
ST->removeValueName(getValueName());
destroyValueName();
}
// Now we know that this has no name.
// If V has no name either, we're done.
if (!V->hasName()) return;
// Get this's symtab if we didn't before.
if (!ST) {
if (getSymTab(this, ST)) {
// Clear V's name.
V->setName("");
return; // Cannot set a name on this value (e.g. constant).
}
}
// Get V's ST, this should always succeed, because V has a name.
ValueSymbolTable *VST;
bool Failure = getSymTab(V, VST);
assert(!Failure && "V has a name, so it should have a ST!"); (void)Failure;
// If these values are both in the same symtab, we can do this very fast.
// This works even if both values have no symtab yet.
if (ST == VST) {
// Take the name!
setValueName(V->getValueName());
V->setValueName(nullptr);
getValueName()->setValue(this);
return;
}
// Otherwise, things are slightly more complex. Remove V's name from VST and
// then reinsert it into ST.
if (VST)
VST->removeValueName(V->getValueName());
setValueName(V->getValueName());
V->setValueName(nullptr);
getValueName()->setValue(this);
if (ST)
ST->reinsertValue(this);
}
```
I think this is needed since it is a little bit complicated e.g. checking duplicated symbol etc. NF->takeName(F) provides the new func name and we just need to add suffix on top of that.
https://github.com/llvm/llvm-project/pull/105742
More information about the llvm-commits
mailing list