Skip to content

Commit

Permalink
[Local] Add a convenient insertReplacementDbgValues overload, NFC
Browse files Browse the repository at this point in the history
Add an overload for the common case where the replacement dbg.values
have the same DIExpressions as the originals.

llvm-svn: 335643
  • Loading branch information
vedantk committed Jun 26, 2018
1 parent de46f65 commit c85ca4c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
5 changes: 5 additions & 0 deletions llvm/include/llvm/Transforms/Utils/Local.h
Expand Up @@ -346,6 +346,11 @@ void insertReplacementDbgValues(
Value &From, Value &To, Instruction &InsertBefore,
function_ref<DIExpression *(DbgInfoIntrinsic &OldDII)> RewriteExpr);

/// An overload of insertReplacementDbgValues() for the common case where
/// the replacement dbg.values have the same DIExpressions as the originals.
void insertReplacementDbgValues(Value &From, Value &To,
Instruction &InsertBefore);

/// Remove all instructions from a basic block other than it's terminator
/// and any present EH pad instructions.
unsigned removeAllNonTerminatorAndEHPadInstructions(BasicBlock *BB);
Expand Down
6 changes: 1 addition & 5 deletions llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
Expand Up @@ -267,13 +267,9 @@ Instruction *InstCombiner::commonCastTransforms(CastInst &CI) {
// The first cast (CSrc) is eliminable so we need to fix up or replace
// the second cast (CI). CSrc will then have a good chance of being dead.
auto *Res = CastInst::Create(NewOpc, CSrc->getOperand(0), CI.getType());

// Replace debug users of the eliminable cast by emitting debug values
// which refer to the new cast.
insertReplacementDbgValues(
*CSrc, *Res, *std::next(CI.getIterator()),
[](DbgInfoIntrinsic &OldDII) { return OldDII.getExpression(); });

insertReplacementDbgValues(*CSrc, *Res, *std::next(CI.getIterator()));
return Res;
}
}
Expand Down
16 changes: 13 additions & 3 deletions llvm/lib/Transforms/Utils/Local.cpp
Expand Up @@ -1717,9 +1717,19 @@ void llvm::insertReplacementDbgValues(
// that the old debug users will be erased later.
DIBuilder DIB(*InsertBefore.getModule());
for (auto *OldDII : Users)
if (DIExpression *Expr = RewriteExpr(*OldDII))
DIB.insertDbgValueIntrinsic(&To, OldDII->getVariable(), Expr,
OldDII->getDebugLoc().get(), &InsertBefore);
if (DIExpression *Expr = RewriteExpr(*OldDII)) {
auto *I = DIB.insertDbgValueIntrinsic(&To, OldDII->getVariable(), Expr,
OldDII->getDebugLoc().get(),
&InsertBefore);
LLVM_DEBUG(dbgs() << "REPLACE: " << *I << '\n');
}
}

void llvm::insertReplacementDbgValues(Value &From, Value &To,
Instruction &InsertBefore) {
return llvm::insertReplacementDbgValues(
From, To, InsertBefore,
[](DbgInfoIntrinsic &OldDII) { return OldDII.getExpression(); });
}

unsigned llvm::removeAllNonTerminatorAndEHPadInstructions(BasicBlock *BB) {
Expand Down

0 comments on commit c85ca4c

Please sign in to comment.