Please use GitHub pull requests for new patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
llvm/lib/Transforms/Utils/Local.cpp
Show First 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | |||||
if (auto *DVI = dyn_cast<DbgValueInst>(U.getUser())) | if (auto *DVI = dyn_cast<DbgValueInst>(U.getUser())) | ||||
replaceOneDbgValueForAlloca(DVI, NewAllocaAddress, Builder, Offset); | replaceOneDbgValueForAlloca(DVI, NewAllocaAddress, Builder, Offset); | ||||
} | } | ||||
} | } | ||||
/// Wrap \p V in a ValueAsMetadata instance. | /// Wrap \p V in a ValueAsMetadata instance. | ||||
static MetadataAsValue *wrapValueInMetadata(LLVMContext &C, Value *V) { | static MetadataAsValue *wrapValueInMetadata(LLVMContext &C, Value *V) { | ||||
return MetadataAsValue::get(C, ValueAsMetadata::get(V)); | return MetadataAsValue::get(C, ValueAsMetadata::get(V)); | ||||
} | } | ||||
Orlando: While you're here you could updated salvaged -> Salvaged to match llvm style. | |||||
static bool attemptToSalvageDebugInfo(Instruction &I) { | /// Where possible to salvage debug information for \p I do so | ||||
/// and return True. If not possible mark undef and return False. | |||||
bool llvm::salvageDebugInfo(Instruction &I) { | |||||
SmallVector<DbgVariableIntrinsic *, 1> DbgUsers; | SmallVector<DbgVariableIntrinsic *, 1> DbgUsers; | ||||
findDbgUsers(DbgUsers, &I); | findDbgUsers(DbgUsers, &I); | ||||
if (DbgUsers.empty()) | |||||
return false; | |||||
return salvageDebugInfoForDbgValues(I, DbgUsers); | return salvageDebugInfoForDbgValues(I, DbgUsers); | ||||
} | } | ||||
bool llvm::salvageDebugInfo(Instruction &I) { | |||||
bool salvaged = attemptToSalvageDebugInfo(I); | |||||
if (!salvaged) | |||||
replaceDbgUsesWithUndef(&I); | |||||
return salvaged; | |||||
} | |||||
bool llvm::salvageDebugInfoForDbgValues( | bool llvm::salvageDebugInfoForDbgValues( | ||||
Instruction &I, ArrayRef<DbgVariableIntrinsic *> DbgUsers) { | Instruction &I, ArrayRef<DbgVariableIntrinsic *> DbgUsers) { | ||||
auto &Ctx = I.getContext(); | auto &Ctx = I.getContext(); | ||||
bool Salvaged = false; | |||||
auto wrapMD = [&](Value *V) { return wrapValueInMetadata(Ctx, V); }; | auto wrapMD = [&](Value *V) { return wrapValueInMetadata(Ctx, V); }; | ||||
for (auto *DII : DbgUsers) { | for (auto *DII : DbgUsers) { | ||||
// Do not add DW_OP_stack_value for DbgDeclare and DbgAddr, because they | // Do not add DW_OP_stack_value for DbgDeclare and DbgAddr, because they | ||||
// are implicitly pointing out the value as a DWARF memory location | // are implicitly pointing out the value as a DWARF memory location | ||||
// description. | // description. | ||||
bool StackValue = isa<DbgValueInst>(DII); | bool StackValue = isa<DbgValueInst>(DII); | ||||
DIExpression *DIExpr = | DIExpression *DIExpr = | ||||
salvageDebugInfoImpl(I, DII->getExpression(), StackValue); | salvageDebugInfoImpl(I, DII->getExpression(), StackValue); | ||||
// salvageDebugInfoImpl should fail on examining the first element of | // salvageDebugInfoImpl should fail on examining the first element of | ||||
// DbgUsers, or none of them. | // DbgUsers, or none of them. | ||||
if (!DIExpr) | if (!DIExpr) | ||||
return false; | break; | ||||
DII->setOperand(0, wrapMD(I.getOperand(0))); | DII->setOperand(0, wrapMD(I.getOperand(0))); | ||||
Not Done ReplyInline Actionsnit: I think this would be clearer, but not a strong opinion at all. if (salvaged) return true; // <undef-code> return false; Orlando: nit: I think this would be clearer, but not a strong opinion at all.
```
if (salvaged)… | |||||
Yes I prefer this too. chrisjackson: Yes I prefer this too. | |||||
DII->setOperand(2, MetadataAsValue::get(Ctx, DIExpr)); | DII->setOperand(2, MetadataAsValue::get(Ctx, DIExpr)); | ||||
LLVM_DEBUG(dbgs() << "SALVAGE: " << *DII << '\n'); | LLVM_DEBUG(dbgs() << "SALVAGE: " << *DII << '\n'); | ||||
Salvaged = true; | |||||
} | } | ||||
return true; | if (Salvaged) | ||||
return true; | |||||
for (auto *DII : DbgUsers) { | |||||
Value *Undef = UndefValue::get(I.getType()); | |||||
DII->setOperand(0, MetadataAsValue::get(DII->getContext(), | |||||
ValueAsMetadata::get(Undef))); | |||||
} | |||||
return false; | |||||
} | } | ||||
DIExpression *llvm::salvageDebugInfoImpl(Instruction &I, | DIExpression *llvm::salvageDebugInfoImpl(Instruction &I, | ||||
DIExpression *SrcDIExpr, | DIExpression *SrcDIExpr, | ||||
bool WithStackValue) { | bool WithStackValue) { | ||||
auto &M = *I.getModule(); | auto &M = *I.getModule(); | ||||
auto &DL = M.getDataLayout(); | auto &DL = M.getDataLayout(); | ||||
▲ Show 20 Lines • Show All 91 Lines • Show Last 20 Lines |
While you're here you could updated salvaged -> Salvaged to match llvm style.