Clean up DIExpression::prependDIExpr a little. (NFC)

llvm-svn: 301662
This commit is contained in:
Adrian Prantl 2017-04-28 17:51:05 +00:00
parent 2634d0ff5c
commit 109b236850
6 changed files with 20 additions and 27 deletions

View File

@ -2281,11 +2281,13 @@ public:
/// Append \p Ops with operations to apply the \p Offset.
static void appendOffset(SmallVectorImpl<uint64_t> &Ops, int64_t Offset);
/// Constants for DIExpression::prepend.
enum { NoDeref = false, WithDeref = true, WithStackValue = true };
/// Prepend \p DIExpr with a deref and offset operation and optionally turn it
/// into a stack value.
static DIExpression *prependDIExpr(DIBuilder &Builder, DIExpression *DIExpr,
bool Deref, int64_t Offset = 0,
bool StackValue = false);
static DIExpression *prepend(DIExpression *DIExpr, bool Deref,
int64_t Offset = 0, bool StackValue = false);
};
/// Global variables.

View File

@ -286,9 +286,6 @@ DbgDeclareInst *FindAllocaDbgDeclare(Value *V);
/// Finds the llvm.dbg.value intrinsics describing a value.
void findDbgValues(SmallVectorImpl<DbgValueInst *> &DbgValues, Value *V);
/// Constants for \p replaceDbgDeclare and friends.
enum { NoDeref = false, WithDeref = true };
/// Replaces llvm.dbg.declare instruction when the address it describes
/// is replaced with a new value. If Deref is true, an additional DW_OP_deref is
/// prepended to the expression. If Offset is non-zero, a constant displacement

View File

@ -672,19 +672,17 @@ void DIExpression::appendOffset(SmallVectorImpl<uint64_t> &Ops,
}
}
DIExpression *
DIExpression::prependDIExpr(DIBuilder &Builder, DIExpression *DIExpr,
bool Deref, int64_t Offset,
bool StackValue) {
DIExpression *DIExpression::prepend(DIExpression *Expr, bool Deref,
int64_t Offset, bool StackValue) {
if (!Deref && !Offset && !StackValue)
return DIExpr;
return Expr;
SmallVector<uint64_t, 8> Ops;
appendOffset(Ops, Offset);
if (Deref)
Ops.push_back(dwarf::DW_OP_deref);
if (DIExpr)
for (auto Op : DIExpr->expr_ops()) {
if (Expr)
for (auto Op : Expr->expr_ops()) {
// A DW_OP_stack_value comes at the end, but before a DW_OP_LLVM_fragment.
if (StackValue) {
if (Op.getOp() == dwarf::DW_OP_stack_value)
@ -700,7 +698,7 @@ DIExpression::prependDIExpr(DIBuilder &Builder, DIExpression *DIExpr,
}
if (StackValue)
Ops.push_back(dwarf::DW_OP_stack_value);
return Builder.createExpression(Ops);
return DIExpression::get(Expr->getContext(), Ops);
}
bool DIExpression::isConstant() const {

View File

@ -548,10 +548,9 @@ MachineInstr *OptimizeLEAPass::replaceDebugValue(MachineInstr &MI,
int64_t AddrDispShift) {
DIExpression *Expr = const_cast<DIExpression *>(MI.getDebugExpression());
if (AddrDispShift != 0) {
DIBuilder DIB(*TheModule);
Expr = DIExpression::prependDIExpr(DIB, Expr, false, AddrDispShift, true);
}
if (AddrDispShift != 0)
Expr = DIExpression::prepend(Expr, DIExpression::NoDeref, AddrDispShift,
DIExpression::WithStackValue);
// Replace DBG_VALUE instruction with modified version.
MachineBasicBlock *MBB = MI.getParent();

View File

@ -2723,7 +2723,7 @@ void FunctionStackPoisoner::processStaticAllocas() {
Value *NewAllocaPtr = IRB.CreateIntToPtr(
IRB.CreateAdd(LocalStackBase, ConstantInt::get(IntptrTy, Desc.Offset)),
AI->getType());
replaceDbgDeclareForAlloca(AI, NewAllocaPtr, DIB, /*Deref=*/false);
replaceDbgDeclareForAlloca(AI, NewAllocaPtr, DIB, DIExpression::NoDeref);
AI->replaceAllUsesWith(NewAllocaPtr);
}

View File

@ -1259,7 +1259,6 @@ void llvm::findDbgValues(SmallVectorImpl<DbgValueInst *> &DbgValues, Value *V) {
DbgValues.push_back(DVI);
}
enum { WithStackValue = true };
bool llvm::replaceDbgDeclare(Value *Address, Value *NewAddress,
Instruction *InsertBefore, DIBuilder &Builder,
@ -1271,9 +1270,7 @@ bool llvm::replaceDbgDeclare(Value *Address, Value *NewAddress,
auto *DIVar = DDI->getVariable();
auto *DIExpr = DDI->getExpression();
assert(DIVar && "Missing variable");
DIExpr = DIExpression::prependDIExpr(Builder, DIExpr, Deref, Offset);
DIExpr = DIExpression::prepend(DIExpr, Deref, Offset);
// Insert llvm.dbg.declare immediately after the original alloca, and remove
// old llvm.dbg.declare.
Builder.insertDeclare(NewAddress, DIVar, DIExpr, Loc, InsertBefore);
@ -1356,9 +1353,9 @@ void llvm::salvageDebugInfo(Instruction &I) {
auto *DIExpr = DVI->getExpression();
DIBuilder DIB(M, /*AllowUnresolved*/ false);
// GEP offsets are i32 and thus always fit into an int64_t.
DIExpr = DIExpression::prependDIExpr(DIB, DIExpr, NoDeref,
Offset.getSExtValue(),
WithStackValue);
DIExpr = DIExpression::prepend(DIExpr, DIExpression::NoDeref,
Offset.getSExtValue(),
DIExpression::WithStackValue);
DVI->setOperand(0, MDWrap(I.getOperand(0)));
DVI->setOperand(3, MetadataAsValue::get(I.getContext(), DIExpr));
DEBUG(dbgs() << "SALVAGE: " << *DVI << '\n');
@ -1370,7 +1367,7 @@ void llvm::salvageDebugInfo(Instruction &I) {
// Rewrite the load into DW_OP_deref.
auto *DIExpr = DVI->getExpression();
DIBuilder DIB(M, /*AllowUnresolved*/ false);
DIExpr = DIExpression::prependDIExpr(DIB, DIExpr, WithDeref);
DIExpr = DIExpression::prepend(DIExpr, DIExpression::WithDeref);
DVI->setOperand(0, MDWrap(I.getOperand(0)));
DVI->setOperand(3, MetadataAsValue::get(I.getContext(), DIExpr));
DEBUG(dbgs() << "SALVAGE: " << *DVI << '\n');