[llvm] r320203 - Generalize llvm::replaceDbgDeclare and actually support the use-case that
Adrian Prantl via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 8 13:58:18 PST 2017
Author: adrian
Date: Fri Dec 8 13:58:18 2017
New Revision: 320203
URL: http://llvm.org/viewvc/llvm-project?rev=320203&view=rev
Log:
Generalize llvm::replaceDbgDeclare and actually support the use-case that
is mentioned in the documentation (inserting a deref before the plus_uconst).
Modified:
llvm/trunk/include/llvm/IR/DebugInfoMetadata.h
llvm/trunk/include/llvm/Transforms/Utils/Local.h
llvm/trunk/lib/CodeGen/SafeStack.cpp
llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
llvm/trunk/lib/IR/DebugInfoMetadata.cpp
llvm/trunk/lib/Target/X86/X86OptimizeLEAs.cpp
llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp
llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp
llvm/trunk/lib/Transforms/Utils/Local.cpp
llvm/trunk/unittests/IR/MetadataTest.cpp
llvm/trunk/unittests/Transforms/Utils/Local.cpp
Modified: llvm/trunk/include/llvm/IR/DebugInfoMetadata.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DebugInfoMetadata.h?rev=320203&r1=320202&r2=320203&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/DebugInfoMetadata.h (original)
+++ llvm/trunk/include/llvm/IR/DebugInfoMetadata.h Fri Dec 8 13:58:18 2017
@@ -2297,8 +2297,9 @@ public:
/// Prepend \p DIExpr with a deref and offset operation and optionally turn it
/// into a stack value.
- static DIExpression *prepend(const DIExpression *DIExpr, bool Deref,
- int64_t Offset = 0, bool StackValue = false);
+ static DIExpression *prepend(const DIExpression *DIExpr, bool DerefBefore,
+ int64_t Offset = 0, bool DerefAfter = false,
+ bool StackValue = false);
/// Create a DIExpression to describe one part of an aggregate variable that
/// is fragmented across multiple Values. The DW_OP_LLVM_fragment operation
Modified: llvm/trunk/include/llvm/Transforms/Utils/Local.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Utils/Local.h?rev=320203&r1=320202&r2=320203&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/Utils/Local.h (original)
+++ llvm/trunk/include/llvm/Transforms/Utils/Local.h Fri Dec 8 13:58:18 2017
@@ -335,22 +335,24 @@ TinyPtrVector<DbgInfoIntrinsic *> FindDb
/// Finds the llvm.dbg.value intrinsics describing a value.
void findDbgValues(SmallVectorImpl<DbgValueInst *> &DbgValues, Value *V);
-/// 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
-/// is added to the expression (after the optional Deref). Offset can be
-/// negative.
+/// 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 is added to the expression
+/// (between the optional Deref operations). Offset can be negative.
bool replaceDbgDeclare(Value *Address, Value *NewAddress,
Instruction *InsertBefore, DIBuilder &Builder,
- bool Deref, int Offset);
+ bool DerefBefore, int Offset, bool DerefAfter);
/// Replaces llvm.dbg.declare instruction when the alloca 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
-/// is added to the expression (after the optional Deref). Offset can be
-/// negative. New llvm.dbg.declare is inserted immediately before AI.
+/// 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 is added to the expression (between the
+/// optional Deref operations). Offset can be negative. The new
+/// llvm.dbg.declare is inserted immediately before AI.
bool replaceDbgDeclareForAlloca(AllocaInst *AI, Value *NewAllocaAddress,
- DIBuilder &Builder, bool Deref, int Offset = 0);
+ DIBuilder &Builder, bool DerefBefore,
+ int Offset, bool DerefAfter);
/// Replaces multiple llvm.dbg.value instructions when the alloca it describes
/// is replaced with a new value. If Offset is non-zero, a constant displacement
Modified: llvm/trunk/lib/CodeGen/SafeStack.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SafeStack.cpp?rev=320203&r1=320202&r2=320203&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SafeStack.cpp (original)
+++ llvm/trunk/lib/CodeGen/SafeStack.cpp Fri Dec 8 13:58:18 2017
@@ -558,7 +558,7 @@ Value *SafeStack::moveStaticAllocasToUns
// Replace alloc with the new location.
replaceDbgDeclare(Arg, BasePointer, BasePointer->getNextNode(), DIB,
- /*Deref=*/false, -Offset);
+ DIExpression::NoDeref, -Offset, DIExpression::NoDeref);
Arg->replaceAllUsesWith(NewArg);
IRB.SetInsertPoint(cast<Instruction>(NewArg)->getNextNode());
IRB.CreateMemCpy(Off, Arg, Size, Arg->getParamAlignment());
@@ -573,7 +573,8 @@ Value *SafeStack::moveStaticAllocasToUns
if (Size == 0)
Size = 1; // Don't create zero-sized stack objects.
- replaceDbgDeclareForAlloca(AI, BasePointer, DIB, /*Deref=*/false, -Offset);
+ replaceDbgDeclareForAlloca(AI, BasePointer, DIB, DIExpression::NoDeref,
+ -Offset, DIExpression::NoDeref);
replaceDbgValueForAlloca(AI, BasePointer, DIB, -Offset);
// Replace uses of the alloca with the new location.
@@ -663,7 +664,8 @@ void SafeStack::moveDynamicAllocasToUnsa
if (AI->hasName() && isa<Instruction>(NewAI))
NewAI->takeName(AI);
- replaceDbgDeclareForAlloca(AI, NewAI, DIB, /*Deref=*/false);
+ replaceDbgDeclareForAlloca(AI, NewAI, DIB, DIExpression::NoDeref, 0,
+ DIExpression::NoDeref);
AI->replaceAllUsesWith(NewAI);
AI->eraseFromParent();
}
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp?rev=320203&r1=320202&r2=320203&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Fri Dec 8 13:58:18 2017
@@ -7130,6 +7130,7 @@ void SelectionDAG::salvageDebugInfo(SDNo
// DW_OP_stack_value.
auto *DIExpr = DV->getExpression();
DIExpr = DIExpression::prepend(DIExpr, DIExpression::NoDeref, Offset,
+ DIExpression::NoDeref,
DIExpression::WithStackValue);
SDDbgValue *Clone =
getDbgValue(DV->getVariable(), DIExpr, N0.getNode(), N0.getResNo(),
Modified: llvm/trunk/lib/IR/DebugInfoMetadata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DebugInfoMetadata.cpp?rev=320203&r1=320202&r2=320203&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DebugInfoMetadata.cpp (original)
+++ llvm/trunk/lib/IR/DebugInfoMetadata.cpp Fri Dec 8 13:58:18 2017
@@ -750,12 +750,17 @@ bool DIExpression::extractIfOffset(int64
return false;
}
-DIExpression *DIExpression::prepend(const DIExpression *Expr, bool Deref,
- int64_t Offset, bool StackValue) {
+DIExpression *DIExpression::prepend(const DIExpression *Expr, bool DerefBefore,
+ int64_t Offset, bool DerefAfter,
+ bool StackValue) {
SmallVector<uint64_t, 8> Ops;
+ if (DerefBefore)
+ Ops.push_back(dwarf::DW_OP_deref);
+
appendOffset(Ops, Offset);
- if (Deref)
+ if (DerefAfter)
Ops.push_back(dwarf::DW_OP_deref);
+
if (Expr)
for (auto Op : Expr->expr_ops()) {
// A DW_OP_stack_value comes at the end, but before a DW_OP_LLVM_fragment.
Modified: llvm/trunk/lib/Target/X86/X86OptimizeLEAs.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86OptimizeLEAs.cpp?rev=320203&r1=320202&r2=320203&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86OptimizeLEAs.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86OptimizeLEAs.cpp Fri Dec 8 13:58:18 2017
@@ -568,6 +568,7 @@ MachineInstr *OptimizeLEAPass::replaceDe
if (AddrDispShift != 0)
Expr = DIExpression::prepend(Expr, DIExpression::NoDeref, AddrDispShift,
+ DIExpression::NoDeref,
DIExpression::WithStackValue);
// Replace DBG_VALUE instruction with modified version.
Modified: llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp?rev=320203&r1=320202&r2=320203&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp Fri Dec 8 13:58:18 2017
@@ -2918,7 +2918,8 @@ void FunctionStackPoisoner::processStati
Value *NewAllocaPtr = IRB.CreateIntToPtr(
IRB.CreateAdd(LocalStackBase, ConstantInt::get(IntptrTy, Desc.Offset)),
AI->getType());
- replaceDbgDeclareForAlloca(AI, NewAllocaPtr, DIB, DIExpression::NoDeref);
+ replaceDbgDeclareForAlloca(AI, NewAllocaPtr, DIB, DIExpression::NoDeref,
+ 0, DIExpression::NoDeref);
AI->replaceAllUsesWith(NewAllocaPtr);
}
Modified: llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp?rev=320203&r1=320202&r2=320203&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp Fri Dec 8 13:58:18 2017
@@ -1810,7 +1810,8 @@ bool llvm::InlineFunction(CallSite CS, I
// Move any dbg.declares describing the allocas into the entry basic block.
DIBuilder DIB(*Caller->getParent());
for (auto &AI : IFI.StaticAllocas)
- replaceDbgDeclareForAlloca(AI, AI, DIB, /*Deref=*/false);
+ replaceDbgDeclareForAlloca(AI, AI, DIB, DIExpression::NoDeref, 0,
+ DIExpression::NoDeref);
}
SmallVector<Value*,4> VarArgsToForward;
Modified: llvm/trunk/lib/Transforms/Utils/Local.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/Local.cpp?rev=320203&r1=320202&r2=320203&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/Local.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/Local.cpp Fri Dec 8 13:58:18 2017
@@ -1304,14 +1304,14 @@ static void findDbgUsers(SmallVectorImpl
bool llvm::replaceDbgDeclare(Value *Address, Value *NewAddress,
Instruction *InsertBefore, DIBuilder &Builder,
- bool Deref, int Offset) {
+ bool DerefBefore, int Offset, bool DerefAfter) {
auto DbgAddrs = FindDbgAddrUses(Address);
for (DbgInfoIntrinsic *DII : DbgAddrs) {
DebugLoc Loc = DII->getDebugLoc();
auto *DIVar = DII->getVariable();
auto *DIExpr = DII->getExpression();
assert(DIVar && "Missing variable");
- DIExpr = DIExpression::prepend(DIExpr, Deref, Offset);
+ DIExpr = DIExpression::prepend(DIExpr, DerefBefore, Offset, DerefAfter);
// Insert llvm.dbg.declare immediately after InsertBefore, and remove old
// llvm.dbg.declare.
Builder.insertDeclare(NewAddress, DIVar, DIExpr, Loc, InsertBefore);
@@ -1323,9 +1323,10 @@ bool llvm::replaceDbgDeclare(Value *Addr
}
bool llvm::replaceDbgDeclareForAlloca(AllocaInst *AI, Value *NewAllocaAddress,
- DIBuilder &Builder, bool Deref, int Offset) {
+ DIBuilder &Builder, bool DerefBefore,
+ int Offset, bool DerefAfter) {
return replaceDbgDeclare(AI, NewAllocaAddress, AI->getNextNode(), Builder,
- Deref, Offset);
+ DerefBefore, Offset, DerefAfter);
}
static void replaceOneDbgValueForAlloca(DbgValueInst *DVI, Value *NewAddress,
@@ -1378,6 +1379,7 @@ void llvm::salvageDebugInfo(Instruction
auto applyOffset = [&](DbgValueInst *DVI, uint64_t Offset) {
auto *DIExpr = DVI->getExpression();
DIExpr = DIExpression::prepend(DIExpr, DIExpression::NoDeref, Offset,
+ DIExpression::NoDeref,
DIExpression::WithStackValue);
DVI->setOperand(0, wrapMD(I.getOperand(0)));
DVI->setOperand(2, MetadataAsValue::get(I.getContext(), DIExpr));
Modified: llvm/trunk/unittests/IR/MetadataTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/MetadataTest.cpp?rev=320203&r1=320202&r2=320203&view=diff
==============================================================================
--- llvm/trunk/unittests/IR/MetadataTest.cpp (original)
+++ llvm/trunk/unittests/IR/MetadataTest.cpp Fri Dec 8 13:58:18 2017
@@ -2031,6 +2031,18 @@ TEST_F(DIExpressionTest, get) {
TempDIExpression Temp = N->clone();
EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
+
+ // Test DIExpression::prepend().
+ uint64_t Elts0[] = {dwarf::DW_OP_LLVM_fragment, 0, 32};
+ auto *N0 = DIExpression::get(Context, Elts0);
+ N0 = DIExpression::prepend(N0, true, 64, true, true);
+ uint64_t Elts1[] = {dwarf::DW_OP_deref,
+ dwarf::DW_OP_plus_uconst, 64,
+ dwarf::DW_OP_deref,
+ dwarf::DW_OP_stack_value,
+ dwarf::DW_OP_LLVM_fragment, 0, 32};
+ auto *N1 = DIExpression::get(Context, Elts1);
+ EXPECT_EQ(N0, N1);
}
TEST_F(DIExpressionTest, isValid) {
Modified: llvm/trunk/unittests/Transforms/Utils/Local.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Transforms/Utils/Local.cpp?rev=320203&r1=320202&r2=320203&view=diff
==============================================================================
--- llvm/trunk/unittests/Transforms/Utils/Local.cpp (original)
+++ llvm/trunk/unittests/Transforms/Utils/Local.cpp Fri Dec 8 13:58:18 2017
@@ -157,7 +157,8 @@ TEST(Local, ReplaceDbgDeclare) {
ASSERT_TRUE(DII);
Value *NewBase = Constant::getNullValue(Type::getInt32PtrTy(C));
DIBuilder DIB(*M);
- replaceDbgDeclare(AI, NewBase, DII, DIB, /*Deref=*/false, /*Offset=*/0);
+ replaceDbgDeclare(AI, NewBase, DII, DIB, DIExpression::NoDeref, 0,
+ DIExpression::NoDeref);
// There should be exactly two dbg.declares.
int Declares = 0;
More information about the llvm-commits
mailing list