Skip to content

Commit 76f67cf

Browse files
committed
[variable-name-utils] Convert all gep like instructions except ref_element_addr to be put on the stack as StringRefs instead of values.
1 parent 765d3ba commit 76f67cf

File tree

2 files changed

+21
-46
lines changed

2 files changed

+21
-46
lines changed

include/swift/SILOptimizer/Utils/VariableNameUtils.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,18 @@ class VariableNameInferrer {
229229
/// DebugVariable provided name, attempt to find a root value from its
230230
/// initialization.
231231
SILValue getRootValueForTemporaryAllocation(AllocationInst *allocInst);
232+
233+
StringRef getStringRefForIndex(unsigned index) const {
234+
llvm::SmallString<64> indexString;
235+
{
236+
llvm::raw_svector_ostream stream(indexString);
237+
stream << index;
238+
}
239+
return rootValue->getFunction()
240+
->getASTContext()
241+
.getIdentifier(indexString)
242+
.str();
243+
}
232244
};
233245

234246
} // namespace swift

lib/SILOptimizer/Utils/VariableNameUtils.cpp

Lines changed: 9 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -454,38 +454,38 @@ SILValue VariableNameInferrer::findDebugInfoProvidingValueHelper(
454454
}
455455

456456
if (auto *sei = dyn_cast<StructExtractInst>(searchValue)) {
457-
variableNamePath.push_back(sei);
457+
variableNamePath.push_back(getNameFromDecl(sei->getField()));
458458
searchValue = sei->getOperand();
459459
continue;
460460
}
461461

462462
if (auto *uedi = dyn_cast<UncheckedEnumDataInst>(searchValue)) {
463-
variableNamePath.push_back(uedi);
463+
variableNamePath.push_back(getNameFromDecl(uedi->getElement()));
464464
searchValue = uedi->getOperand();
465465
continue;
466466
}
467467

468468
if (auto *tei = dyn_cast<TupleExtractInst>(searchValue)) {
469-
variableNamePath.push_back(tei);
469+
variableNamePath.push_back(getStringRefForIndex(tei->getFieldIndex()));
470470
searchValue = tei->getOperand();
471471
continue;
472472
}
473473

474474
if (auto *sei = dyn_cast<StructElementAddrInst>(searchValue)) {
475-
variableNamePath.push_back(sei);
475+
variableNamePath.push_back(getNameFromDecl(sei->getField()));
476476
searchValue = sei->getOperand();
477477
continue;
478478
}
479479

480480
if (auto *tei = dyn_cast<TupleElementAddrInst>(searchValue)) {
481-
variableNamePath.push_back(tei);
481+
variableNamePath.push_back(getStringRefForIndex(tei->getFieldIndex()));
482482
searchValue = tei->getOperand();
483483
continue;
484484
}
485485

486-
if (auto *e = dyn_cast<UncheckedTakeEnumDataAddrInst>(searchValue)) {
487-
variableNamePath.push_back(e);
488-
searchValue = e->getOperand();
486+
if (auto *utedai = dyn_cast<UncheckedTakeEnumDataAddrInst>(searchValue)) {
487+
variableNamePath.push_back(getNameFromDecl(utedai->getElement()));
488+
searchValue = utedai->getOperand();
489489
continue;
490490
}
491491

@@ -494,7 +494,7 @@ SILValue VariableNameInferrer::findDebugInfoProvidingValueHelper(
494494
// them and add the case to the variableNamePath.
495495
if (auto *e = dyn_cast<EnumInst>(searchValue)) {
496496
if (e->hasOperand()) {
497-
variableNamePath.push_back(e);
497+
variableNamePath.push_back(getNameFromDecl(e->getElement()));
498498
searchValue = e->getOperand();
499499
continue;
500500
}
@@ -687,43 +687,6 @@ void VariableNameInferrer::popSingleVariableName() {
687687
return;
688688
}
689689

690-
if (auto *sei = dyn_cast<StructExtractInst>(inst)) {
691-
resultingString += getNameFromDecl(sei->getField());
692-
return;
693-
}
694-
695-
if (auto *tei = dyn_cast<TupleExtractInst>(inst)) {
696-
llvm::raw_svector_ostream stream(resultingString);
697-
stream << tei->getFieldIndex();
698-
return;
699-
}
700-
701-
if (auto *uedi = dyn_cast<UncheckedEnumDataInst>(inst)) {
702-
resultingString += getNameFromDecl(uedi->getElement());
703-
return;
704-
}
705-
706-
if (auto *sei = dyn_cast<StructElementAddrInst>(inst)) {
707-
resultingString += getNameFromDecl(sei->getField());
708-
return;
709-
}
710-
711-
if (auto *tei = dyn_cast<TupleElementAddrInst>(inst)) {
712-
llvm::raw_svector_ostream stream(resultingString);
713-
stream << tei->getFieldIndex();
714-
return;
715-
}
716-
717-
if (auto *uedi = dyn_cast<UncheckedTakeEnumDataAddrInst>(inst)) {
718-
resultingString += getNameFromDecl(uedi->getElement());
719-
return;
720-
}
721-
722-
if (auto *ei = dyn_cast<EnumInst>(inst)) {
723-
resultingString += getNameFromDecl(ei->getElement());
724-
return;
725-
}
726-
727690
resultingString += "<unknown decl>";
728691
return;
729692
}

0 commit comments

Comments
 (0)