Changeset View
Changeset View
Standalone View
Standalone View
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
Show First 20 Lines • Show All 3,323 Lines • ▼ Show 20 Lines | I->dropDroppableUses([DestBlock](const Use *U) { | ||||
return true; | return true; | ||||
}); | }); | ||||
/// FIXME: We could remove droppable uses that are not dominated by | /// FIXME: We could remove droppable uses that are not dominated by | ||||
/// the new position. | /// the new position. | ||||
BasicBlock::iterator InsertPos = DestBlock->getFirstInsertionPt(); | BasicBlock::iterator InsertPos = DestBlock->getFirstInsertionPt(); | ||||
I->moveBefore(&*InsertPos); | I->moveBefore(&*InsertPos); | ||||
++NumSunkInst; | ++NumSunkInst; | ||||
Orlando: we -> We | |||||
// 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 | |||||
// Update the arguments of a dbg.declare instruction, so that it | |||||
// does not point into a sunk instruction. | |||||
auto updateDbgDeclare = [&I](DbgVariableIntrinsic *DII) { | |||||
if (!isa<DbgDeclareInst>(DII)) | |||||
return false; | |||||
if (isa<CastInst>(I)) | |||||
DII->setOperand( | DII->setOperand( | ||||
0, MetadataAsValue::get(I->getContext(), | 0, MetadataAsValue::get(I->getContext(), | ||||
ValueAsMetadata::get(I->getOperand(0)))); | ValueAsMetadata::get(I->getOperand(0)))); | ||||
continue; | return true; | ||||
} | }; | ||||
// dbg.value is in the same basic block as the sunk inst, see if we can | SmallVector<DbgVariableIntrinsic *, 2> DIIClones; | ||||
// salvage it. Clone a new copy of the instruction: on success we need | for (auto User : DbgUsers) { | ||||
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()`? | |||||
// both salvaged and unsalvaged copies. | // A dbg.declare instruction should not be cloned, since there can only be | ||||
SmallVector<DbgVariableIntrinsic *, 1> TmpUser{ | // one per variable fragment. It should be left in the original place | ||||
cast<DbgVariableIntrinsic>(DII->clone())}; | // because the sunk instruction is not an alloca (otherwise we could not be | ||||
// here). | |||||
if (!salvageDebugInfoForDbgValues(*I, TmpUser)) { | if (User->getParent() != SrcBlock || updateDbgDeclare(User)) | ||||
// We are unable to salvage: sink the cloned dbg.value, and mark the | continue; | ||||
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… | |||||
// original as undef, terminating any earlier variable location. | |||||
LLVM_DEBUG(dbgs() << "SINK: " << *DII << '\n'); | DIIClones.emplace_back(cast<DbgVariableIntrinsic>(User->clone())); | ||||
TmpUser[0]->insertBefore(&*InsertPos); | LLVM_DEBUG(dbgs() << "CLONE: " << *DIIClones.back() << '\n'); | ||||
Value *Undef = UndefValue::get(I->getType()); | } | ||||
DII->setOperand(0, MetadataAsValue::get(DII->getContext(), | |||||
ValueAsMetadata::get(Undef))); | // Perform salvaging without the clones, then sink the clones. | ||||
} else { | if (!DIIClones.empty()) { | ||||
// We successfully salvaged: place the salvaged dbg.value in the | salvageDebugInfoForDbgValues(*I, DbgUsers); | ||||
// original location, and move the unmodified dbg.value to sink with | for (auto &DIIClone : DIIClones) { | ||||
// the sunk inst. | DIIClone->insertBefore(&*InsertPos); | ||||
TmpUser[0]->insertBefore(DII); | LLVM_DEBUG(dbgs() << "SINK: " << *DIIClone << '\n'); | ||||
DII->moveBefore(&*InsertPos); | |||||
} | |||||
} | } | ||||
} | } | ||||
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 456 Lines • Show Last 20 Lines |
we -> We