summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/MachineSink.cpp
diff options
context:
space:
mode:
authorPaul Robinson <paul.robinson@sony.com>2017-11-20 18:42:17 +0000
committerPaul Robinson <paul.robinson@sony.com>2017-11-20 18:42:17 +0000
commitf0b02965e4736af445505a30840fe2b63fa3d2f7 (patch)
tree222eb77bc18d28bd3b7b2ff1290d42a43221f52a /llvm/lib/CodeGen/MachineSink.cpp
parent3669061298f694d9c060e530fb9b4ec633b7b0e6 (diff)
downloadbcm5719-llvm-f0b02965e4736af445505a30840fe2b63fa3d2f7.tar.gz
bcm5719-llvm-f0b02965e4736af445505a30840fe2b63fa3d2f7.zip
Fix out-of-order stepping behavior in programs with sunk instructions.
MachineSink attempts to place instructions near the basic blocks where they are needed. Once an instruction has been sunk, its location relative to other instructions is no longer consistent with the original source code. In order to ensure correct single-stepping and profiling, the debug location for sunk instructions is either merged with the insertion point or erased if the target successor block is empty. Patch by Matthew Voss! Differential Revision: https://reviews.llvm.org/D39933 llvm-svn: 318679
Diffstat (limited to 'llvm/lib/CodeGen/MachineSink.cpp')
-rw-r--r--llvm/lib/CodeGen/MachineSink.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/MachineSink.cpp b/llvm/lib/CodeGen/MachineSink.cpp
index 6f3753e88b8..262d3db22e5 100644
--- a/llvm/lib/CodeGen/MachineSink.cpp
+++ b/llvm/lib/CodeGen/MachineSink.cpp
@@ -38,6 +38,7 @@
#include "llvm/CodeGen/TargetSubtargetInfo.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/Pass.h"
#include "llvm/Support/BranchProbability.h"
#include "llvm/Support/CommandLine.h"
@@ -868,6 +869,16 @@ bool MachineSinking::SinkInstruction(MachineInstr &MI, bool &SawStore,
SmallVector<MachineInstr *, 2> DbgValuesToSink;
collectDebugValues(MI, DbgValuesToSink);
+ // Merge or erase debug location to ensure consistent stepping in profilers
+ // and debuggers.
+ if (!SuccToSinkTo->empty()) {
+ MI.setDebugLoc(DILocation::getMergedLocation(MI.getDebugLoc(),
+ InsertPos->getDebugLoc()));
+ } else {
+ MI.setDebugLoc(DebugLoc());
+ }
+
+
// Move the instruction.
SuccToSinkTo->splice(InsertPos, ParentBlock, MI,
++MachineBasicBlock::iterator(MI));
OpenPOWER on IntegriCloud