Please use GitHub pull requests for new patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
Show First 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | |||||
// Also sink all related debug uses from the source basic block. Otherwise we | // Also sink all related debug uses from the source basic block. Otherwise we | ||||
// get debug use before the def. Attempt to salvage debug uses first, to | // get debug use before the def. Attempt to salvage debug uses first, to | ||||
// maximise the range variables have location for. If we cannot salvage, then | // maximise the range variables have location for. If we cannot salvage, then | ||||
// mark the location undef: we know it was supposed to receive a new location | // mark the location undef: we know it was supposed to receive a new location | ||||
// here, but that computation has been sunk. | // here, but that computation has been sunk. | ||||
SmallVector<DbgVariableIntrinsic *, 2> DbgUsers; | SmallVector<DbgVariableIntrinsic *, 2> DbgUsers; | ||||
findDbgUsers(DbgUsers, I); | findDbgUsers(DbgUsers, I); | ||||
for (auto *DII : reverse(DbgUsers)) { | |||||
if (DII->getParent() == SrcBlock) { | |||||
if (isa<DbgDeclareInst>(DII)) { | |||||
// A dbg.declare instruction should not be cloned, since there can only be | |||||
// one per variable fragment. It should be left in the original place since | |||||
// sunk instruction is not an alloca(otherwise we could not be here). | |||||
// But we need to update arguments of dbg.declare instruction, so that it | |||||
// would not point into sunk instruction. | |||||
if (!isa<CastInst>(I)) | |||||
continue; // dbg.declare points at something it shouldn't | |||||
DII->setOperand( | |||||
0, MetadataAsValue::get(I->getContext(), | |||||
ValueAsMetadata::get(I->getOperand(0)))); | |||||
continue; | |||||
} | |||||
// dbg.value is in the same basic block as the sunk inst, see if we can | // Update the arguments of a dbg.declare instruction, so that it | ||||
Orlando: we -> We | |||||
// salvage it. Clone a new copy of the instruction: on success we need | // does not point into a sunk instruction. | ||||
// both salvaged and unsalvaged copies. | auto updateDbgDeclare = [&I](DbgVariableIntrinsic *DII) { | ||||
SmallVector<DbgVariableIntrinsic *, 1> TmpUser{ | if (!isa<DbgDeclareInst>(DII)) | ||||
cast<DbgVariableIntrinsic>(DII->clone())}; | return false; | ||||
if (!salvageDebugInfoForDbgValues(*I, TmpUser)) { | if (isa<CastInst>(I)) | ||||
// We are unable to salvage: sink the cloned dbg.value, and mark the | DII->setOperand( | ||||
// original as undef, terminating any earlier variable location. | 0, MetadataAsValue::get(I->getContext(), | ||||
LLVM_DEBUG(dbgs() << "SINK: " << *DII << '\n'); | ValueAsMetadata::get(I->getOperand(0)))); | ||||
TmpUser[0]->insertBefore(&*InsertPos); | return true; | ||||
Value *Undef = UndefValue::get(I->getType()); | }; | ||||
DII->setOperand(0, MetadataAsValue::get(DII->getContext(), | |||||
ValueAsMetadata::get(Undef))); | SmallVector<DbgVariableIntrinsic *, 2> DIIClones; | ||||
} else { | for (auto User : DbgUsers) { | ||||
// We successfully salvaged: place the salvaged dbg.value in the | // A dbg.declare instruction should not be cloned, since there can only be | ||||
// original location, and move the unmodified dbg.value to sink with | // one per variable fragment. It should be left in the original place | ||||
// the sunk inst. | // because the sunk instruction is not an alloca (otherwise we could not be | ||||
TmpUser[0]->insertBefore(DII); | // here). | ||||
DII->moveBefore(&*InsertPos); | if (User->getParent() != SrcBlock || updateDbgDeclare(User)) | ||||
} | continue; | ||||
DIIClones.emplace_back(cast<DbgVariableIntrinsic>(User->clone())); | |||||
LLVM_DEBUG(dbgs() << "CLONE: " << *DIIClones.back() << '\n'); | |||||
Not Done ReplyInline ActionsIs this just printing the address of the clones? Shouldn't it be << *DIClones.back()? Orlando: Is this just printing the address of the clones? Shouldn't it be `<< *DIClones.back()`? | |||||
} | |||||
// Perform salvaging without the clones, then sink the clones. | |||||
if (!DIIClones.empty()) { | |||||
salvageDebugInfoForDbgValues(*I, DbgUsers); | |||||
for (auto &DIIClone : DIIClones) { | |||||
Not Done ReplyInline ActionsSorry I didn't pick this up with my other comments. I think this should be auto *DIIClone (or DbgVariableIntrinsic *DIIClone) because DIIClones is SmallVector<DbgVariableIntrinsic *, 2>? Orlando: Sorry I didn't pick this up with my other comments. I think this should be `auto *DIIClone` (or… | |||||
DIIClone->insertBefore(&*InsertPos); | |||||
LLVM_DEBUG(dbgs() << "SINK: " << *DIIClone << '\n'); | |||||
} | } | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
bool InstCombiner::run() { | bool InstCombiner::run() { | ||||
while (!Worklist.isEmpty()) { | while (!Worklist.isEmpty()) { | ||||
// Walk deferred instructions in reverse order, and push them to the | // Walk deferred instructions in reverse order, and push them to the | ||||
// worklist, which means they'll end up popped from the worklist in-order. | // worklist, which means they'll end up popped from the worklist in-order. | ||||
while (Instruction *I = Worklist.popDeferred()) { | while (Instruction *I = Worklist.popDeferred()) { | ||||
▲ Show 20 Lines • Show All 91 Lines • Show Last 20 Lines |
we -> We