From b46256b0b4ce0746b7d9c121a2572c17765cffea Mon Sep 17 00:00:00 2001 From: Paul Robinson Date: Thu, 9 Nov 2017 20:01:31 +0000 Subject: Fix out-of-order stepping behavior in programs with hoisted constants. When the Constant Hoisting pass moves expensive constants into a common block, it would assign a debug location equal to the last use of that constant. While this is certainly intuitive, it places the constant in an out-of-order location, according to the debug location information. This produces out-of-order stepping when debugging programs affected by this pass. This patch creates in-order stepping behavior by merging the debug locations for hoisted constants, and the new insertion point. Patch by Matthew Voss! Differential Revision: https://reviews.llvm.org/D38088 llvm-svn: 317827 --- llvm/lib/Transforms/Scalar/ConstantHoisting.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'llvm/lib/Transforms/Scalar/ConstantHoisting.cpp') diff --git a/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp b/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp index 58a910ded21..e4b08c5ed30 100644 --- a/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp +++ b/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp @@ -60,6 +60,7 @@ #include "llvm/Support/raw_ostream.h" #include "llvm/Transforms/Scalar.h" #include "llvm/Transforms/Utils/Local.h" +#include "llvm/IR/DebugInfoMetadata.h" #include #include #include @@ -716,6 +717,9 @@ bool ConstantHoistingPass::emitBaseConstants() { IntegerType *Ty = ConstInfo.BaseConstant->getType(); Instruction *Base = new BitCastInst(ConstInfo.BaseConstant, Ty, "const", IP); + + Base->setDebugLoc(IP->getDebugLoc()); + DEBUG(dbgs() << "Hoist constant (" << *ConstInfo.BaseConstant << ") to BB " << IP->getParent()->getName() << '\n' << *Base << '\n'); @@ -734,6 +738,8 @@ bool ConstantHoistingPass::emitBaseConstants() { emitBaseConstants(Base, RCI.Offset, U); ReBasesNum++; } + + Base->setDebugLoc(DILocation::getMergedLocation(Base->getDebugLoc(), U.Inst->getDebugLoc())); } } UsesNum = Uses; @@ -742,7 +748,6 @@ bool ConstantHoistingPass::emitBaseConstants() { assert(!Base->use_empty() && "The use list is empty!?"); assert(isa(Base->user_back()) && "All uses should be instructions."); - Base->setDebugLoc(cast(Base->user_back())->getDebugLoc()); } (void)UsesNum; (void)ReBasesNum; -- cgit v1.2.3