summaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
diff options
context:
space:
mode:
authorJeremy Morse <jeremy.morse@sony.com>2025-07-16 14:13:53 +0100
committerGitHub <noreply@github.com>2025-07-16 14:13:53 +0100
commit5328c732a47705363cd289cb281cbd0d3ccbb8fc (patch)
tree6e3fafdc4edd881f9e3b9c60bd35bbda33caa311 /llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
parent9ea27b841cdf3c702b5e0bc696eb404492dbc79f (diff)
[DebugInfo] Strip more debug-intrinsic code from local utils (#149037)
SROA and a few other facilities use generic-lambdas and some overloaded functions to deal with both intrinsics and debug-records at the same time. As part of stripping out intrinsic support, delete a swathe of this code from things in the Utils directory. This is a large diff, but is mostly about removing functions that were duplicated during the migration to debug records. I've taken a few opportunities to replace comments about "intrinsics" with "records", and replace generic lambdas with plain lambdas (I believe this makes it more readable). All of this is chipping away at intrinsic-specific code until we get to removing parts of findDbgUsers, which is the final boss -- we can't remove that until almost everything else is gone.
Diffstat (limited to 'llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp108
1 files changed, 32 insertions, 76 deletions
diff --git a/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp b/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
index 46808a818cb2..ccd7ee360e01 100644
--- a/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
+++ b/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
@@ -115,29 +115,17 @@ static void createDebugValue(DIBuilder &DIB, Value *NewValue,
DbgVariableRecord::createDbgVariableRecord(NewValue, Variable, Expression, DI,
*InsertBefore);
}
-static void createDebugValue(DIBuilder &DIB, Value *NewValue,
- DILocalVariable *Variable,
- DIExpression *Expression, const DILocation *DI,
- Instruction *InsertBefore) {
- DIB.insertDbgValueIntrinsic(NewValue, Variable, Expression, DI,
- InsertBefore->getIterator());
-}
/// Helper for updating assignment tracking debug info when promoting allocas.
class AssignmentTrackingInfo {
/// DbgAssignIntrinsics linked to the alloca with at most one per variable
/// fragment. (i.e. not be a comprehensive set if there are multiple
/// dbg.assigns for one variable fragment).
- SmallVector<DbgVariableIntrinsic *> DbgAssigns;
SmallVector<DbgVariableRecord *> DVRAssigns;
public:
void init(AllocaInst *AI) {
SmallSet<DebugVariable, 2> Vars;
- for (DbgAssignIntrinsic *DAI : at::getAssignmentMarkers(AI)) {
- if (Vars.insert(DebugVariable(DAI)).second)
- DbgAssigns.push_back(DAI);
- }
for (DbgVariableRecord *DVR : at::getDVRAssignmentMarkers(AI)) {
if (Vars.insert(DebugVariable(DVR)).second)
DVRAssigns.push_back(DVR);
@@ -148,11 +136,10 @@ public:
/// \p ToDelete that stores to this alloca.
void updateForDeletedStore(
StoreInst *ToDelete, DIBuilder &DIB,
- SmallSet<DbgAssignIntrinsic *, 8> *DbgAssignsToDelete,
SmallSet<DbgVariableRecord *, 8> *DVRAssignsToDelete) const {
// There's nothing to do if the alloca doesn't have any variables using
// assignment tracking.
- if (DbgAssigns.empty() && DVRAssigns.empty())
+ if (DVRAssigns.empty())
return;
// Insert a dbg.value where the linked dbg.assign is and remember to delete
@@ -169,25 +156,22 @@ public:
DbgAssign->getExpression(), DbgAssign->getDebugLoc(),
DbgAssign);
};
- for (auto *Assign : at::getAssignmentMarkers(ToDelete))
- InsertValueForAssign(Assign, DbgAssignsToDelete);
for (auto *Assign : at::getDVRAssignmentMarkers(ToDelete))
InsertValueForAssign(Assign, DVRAssignsToDelete);
// It's possible for variables using assignment tracking to have no
- // dbg.assign linked to this store. These are variables in DbgAssigns that
+ // dbg.assign linked to this store. These are variables in DVRAssigns that
// are missing from VarHasDbgAssignForStore. Since there isn't a dbg.assign
// to mark the assignment - and the store is going to be deleted - insert a
// dbg.value to do that now. An untracked store may be either one that
// cannot be represented using assignment tracking (non-const offset or
// size) or one that is trackable but has had its DIAssignID attachment
// dropped accidentally.
- auto ConvertUnlinkedAssignToValue = [&](auto *Assign) {
+ auto ConvertUnlinkedAssignToValue = [&](DbgVariableRecord *Assign) {
if (VarHasDbgAssignForStore.contains(DebugVariableAggregate(Assign)))
return;
ConvertDebugDeclareToDebugValue(Assign, ToDelete, DIB);
};
- for_each(DbgAssigns, ConvertUnlinkedAssignToValue);
for_each(DVRAssigns, ConvertUnlinkedAssignToValue);
}
@@ -197,17 +181,12 @@ public:
// Regardless of the position of dbg.assigns relative to stores, the
// incoming values into a new PHI should be the same for the (imaginary)
// debug-phi.
- for (auto *DAI : DbgAssigns)
- ConvertDebugDeclareToDebugValue(DAI, NewPhi, DIB);
for (auto *DVR : DVRAssigns)
ConvertDebugDeclareToDebugValue(DVR, NewPhi, DIB);
}
- void clear() {
- DbgAssigns.clear();
- DVRAssigns.clear();
- }
- bool empty() { return DbgAssigns.empty() && DVRAssigns.empty(); }
+ void clear() { DVRAssigns.clear(); }
+ bool empty() { return DVRAssigns.empty(); }
};
struct AllocaInfo {
@@ -412,7 +391,6 @@ struct PromoteMem2Reg {
SmallVector<AssignmentTrackingInfo, 8> AllocaATInfo;
/// A set of dbg.assigns to delete because they've been demoted to
/// dbg.values. Call cleanUpDbgAssigns to delete them.
- SmallSet<DbgAssignIntrinsic *, 8> DbgAssignsToDelete;
SmallSet<DbgVariableRecord *, 8> DVRAssignsToDelete;
/// The set of basic blocks the renamer has already visited.
@@ -467,9 +445,6 @@ private:
/// Delete dbg.assigns that have been demoted to dbg.values.
void cleanUpDbgAssigns() {
- for (auto *DAI : DbgAssignsToDelete)
- DAI->eraseFromParent();
- DbgAssignsToDelete.clear();
for (auto *DVR : DVRAssignsToDelete)
DVR->eraseFromParent();
DVRAssignsToDelete.clear();
@@ -571,7 +546,6 @@ static bool
rewriteSingleStoreAlloca(AllocaInst *AI, AllocaInfo &Info, LargeBlockInfo &LBI,
const DataLayout &DL, DominatorTree &DT,
AssumptionCache *AC,
- SmallSet<DbgAssignIntrinsic *, 8> *DbgAssignsToDelete,
SmallSet<DbgVariableRecord *, 8> *DVRAssignsToDelete) {
StoreInst *OnlyStore = Info.OnlyStore;
Value *ReplVal = OnlyStore->getOperand(0);
@@ -637,27 +611,23 @@ rewriteSingleStoreAlloca(AllocaInst *AI, AllocaInfo &Info, LargeBlockInfo &LBI,
DIBuilder DIB(*AI->getModule(), /*AllowUnresolved*/ false);
// Update assignment tracking info for the store we're going to delete.
- Info.AssignmentTracking.updateForDeletedStore(
- Info.OnlyStore, DIB, DbgAssignsToDelete, DVRAssignsToDelete);
+ Info.AssignmentTracking.updateForDeletedStore(Info.OnlyStore, DIB,
+ DVRAssignsToDelete);
// Record debuginfo for the store and remove the declaration's
// debuginfo.
- auto ConvertDebugInfoForStore = [&](auto &Container) {
- for (auto *DbgItem : Container) {
- if (DbgItem->isAddressOfVariable()) {
- ConvertDebugDeclareToDebugValue(DbgItem, Info.OnlyStore, DIB);
- DbgItem->eraseFromParent();
- } else if (DbgItem->isValueOfVariable() &&
- DbgItem->getExpression()->startsWithDeref()) {
- InsertDebugValueAtStoreLoc(DbgItem, Info.OnlyStore, DIB);
- DbgItem->eraseFromParent();
- } else if (DbgItem->getExpression()->startsWithDeref()) {
- DbgItem->eraseFromParent();
- }
+ for (DbgVariableRecord *DbgItem : Info.DPUsers) {
+ if (DbgItem->isAddressOfVariable()) {
+ ConvertDebugDeclareToDebugValue(DbgItem, Info.OnlyStore, DIB);
+ DbgItem->eraseFromParent();
+ } else if (DbgItem->isValueOfVariable() &&
+ DbgItem->getExpression()->startsWithDeref()) {
+ InsertDebugValueAtStoreLoc(DbgItem, Info.OnlyStore, DIB);
+ DbgItem->eraseFromParent();
+ } else if (DbgItem->getExpression()->startsWithDeref()) {
+ DbgItem->eraseFromParent();
}
- };
- ConvertDebugInfoForStore(Info.DbgUsers);
- ConvertDebugInfoForStore(Info.DPUsers);
+ }
// Remove dbg.assigns linked to the alloca as these are now redundant.
at::deleteAssignmentMarkers(AI);
@@ -690,7 +660,6 @@ static bool
promoteSingleBlockAlloca(AllocaInst *AI, const AllocaInfo &Info,
LargeBlockInfo &LBI, const DataLayout &DL,
DominatorTree &DT, AssumptionCache *AC,
- SmallSet<DbgAssignIntrinsic *, 8> *DbgAssignsToDelete,
SmallSet<DbgVariableRecord *, 8> *DVRAssignsToDelete) {
// The trickiest case to handle is when we have large blocks. Because of this,
// this code is optimized assuming that large blocks happen. This does not
@@ -755,18 +724,13 @@ promoteSingleBlockAlloca(AllocaInst *AI, const AllocaInfo &Info,
while (!AI->use_empty()) {
StoreInst *SI = cast<StoreInst>(AI->user_back());
// Update assignment tracking info for the store we're going to delete.
- Info.AssignmentTracking.updateForDeletedStore(SI, DIB, DbgAssignsToDelete,
- DVRAssignsToDelete);
+ Info.AssignmentTracking.updateForDeletedStore(SI, DIB, DVRAssignsToDelete);
// Record debuginfo for the store before removing it.
- auto DbgUpdateForStore = [&](auto &Container) {
- for (auto *DbgItem : Container) {
- if (DbgItem->isAddressOfVariable()) {
- ConvertDebugDeclareToDebugValue(DbgItem, SI, DIB);
- }
+ for (DbgVariableRecord *DbgItem : Info.DPUsers) {
+ if (DbgItem->isAddressOfVariable()) {
+ ConvertDebugDeclareToDebugValue(DbgItem, SI, DIB);
}
- };
- DbgUpdateForStore(Info.DbgUsers);
- DbgUpdateForStore(Info.DPUsers);
+ }
SI->eraseFromParent();
LBI.deleteValue(SI);
@@ -830,7 +794,7 @@ void PromoteMem2Reg::run() {
// it that are directly dominated by the definition with the value stored.
if (Info.DefiningBlocks.size() == 1) {
if (rewriteSingleStoreAlloca(AI, Info, LBI, SQ.DL, DT, AC,
- &DbgAssignsToDelete, &DVRAssignsToDelete)) {
+ &DVRAssignsToDelete)) {
// The alloca has been processed, move on.
RemoveFromAllocasList(AllocaNum);
++NumSingleStore;
@@ -842,7 +806,7 @@ void PromoteMem2Reg::run() {
// linear sweep over the block to eliminate it.
if (Info.OnlyUsedInOneBlock &&
promoteSingleBlockAlloca(AI, Info, LBI, SQ.DL, DT, AC,
- &DbgAssignsToDelete, &DVRAssignsToDelete)) {
+ &DVRAssignsToDelete)) {
// The alloca has been processed, move on.
RemoveFromAllocasList(AllocaNum);
continue;
@@ -1182,13 +1146,9 @@ void PromoteMem2Reg::RenamePass(BasicBlock *BB, BasicBlock *Pred) {
// The currently active variable for this block is now the PHI.
IncomingVals.set(AllocaNo, APN);
AllocaATInfo[AllocaNo].updateForNewPhi(APN, DIB);
- auto ConvertDbgDeclares = [&](auto &Container) {
- for (auto *DbgItem : Container)
- if (DbgItem->isAddressOfVariable())
- ConvertDebugDeclareToDebugValue(DbgItem, APN, DIB);
- };
- ConvertDbgDeclares(AllocaDbgUsers[AllocaNo]);
- ConvertDbgDeclares(AllocaDPUsers[AllocaNo]);
+ for (DbgVariableRecord *DbgItem : AllocaDPUsers[AllocaNo])
+ if (DbgItem->isAddressOfVariable())
+ ConvertDebugDeclareToDebugValue(DbgItem, APN, DIB);
// Get the next phi node.
++PNI;
@@ -1242,15 +1202,11 @@ void PromoteMem2Reg::RenamePass(BasicBlock *BB, BasicBlock *Pred) {
// Record debuginfo for the store before removing it.
IncomingLocs.set(AllocaNo, SI->getDebugLoc());
- AllocaATInfo[AllocaNo].updateForDeletedStore(SI, DIB, &DbgAssignsToDelete,
+ AllocaATInfo[AllocaNo].updateForDeletedStore(SI, DIB,
&DVRAssignsToDelete);
- auto ConvertDbgDeclares = [&](auto &Container) {
- for (auto *DbgItem : Container)
- if (DbgItem->isAddressOfVariable())
- ConvertDebugDeclareToDebugValue(DbgItem, SI, DIB);
- };
- ConvertDbgDeclares(AllocaDbgUsers[ai->second]);
- ConvertDbgDeclares(AllocaDPUsers[ai->second]);
+ for (DbgVariableRecord *DbgItem : AllocaDPUsers[ai->second])
+ if (DbgItem->isAddressOfVariable())
+ ConvertDebugDeclareToDebugValue(DbgItem, SI, DIB);
SI->eraseFromParent();
}
}