diff options
author | Bjorn Pettersson <bjorn.a.pettersson@ericsson.com> | 2017-11-02 11:55:14 +0000 |
---|---|---|
committer | Bjorn Pettersson <bjorn.a.pettersson@ericsson.com> | 2017-11-02 11:55:14 +0000 |
commit | e73b85d1abfe7363164c5a7e5f58c1ceaeeb62f9 (patch) | |
tree | 13a4befded85a9a0c8ee9b8924db6e9947f50324 /llvm/lib/Transforms/Utils/SimplifyCFG.cpp | |
parent | 242052c6b4bb1090178e23e6d3ca8284474d17cd (diff) | |
download | llvm-e73b85d1abfe7363164c5a7e5f58c1ceaeeb62f9.zip llvm-e73b85d1abfe7363164c5a7e5f58c1ceaeeb62f9.tar.gz llvm-e73b85d1abfe7363164c5a7e5f58c1ceaeeb62f9.tar.bz2 |
[SimplifyCFG] Discard speculated dbg intrinsics
Summary:
SpeculativelyExecuteBB can flatten the CFG by doing
speculative execution followed by a select instruction.
When the speculatively executed BB contained dbg intrinsics
the result could be a little bit weird, since those dbg
intrinsics were inserted before the select in the flattened
CFG. So when single stepping in the debugger, printing the
value of the variable referenced in the dbg intrinsic, it
could happen that it looked like the variable had values
that never actually were assigned to the variable.
This patch simply discards all dbg intrinsics that were found
in the speculatively executed BB.
Reviewers: aprantl, chandlerc, craig.topper
Reviewed By: aprantl
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D39494
llvm-svn: 317198
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyCFG.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp index c71cc76..3c4dae9 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -1920,6 +1920,8 @@ static bool SpeculativelyExecuteBB(BranchInst *BI, BasicBlock *ThenBB, // - All of their uses are in CondBB. SmallDenseMap<Instruction *, unsigned, 4> SinkCandidateUseCounts; + SmallVector<Instruction *, 4> SpeculatedDbgIntrinsics; + unsigned SpeculationCost = 0; Value *SpeculatedStoreValue = nullptr; StoreInst *SpeculatedStore = nullptr; @@ -1928,8 +1930,10 @@ static bool SpeculativelyExecuteBB(BranchInst *BI, BasicBlock *ThenBB, BBI != BBE; ++BBI) { Instruction *I = &*BBI; // Skip debug info. - if (isa<DbgInfoIntrinsic>(I)) + if (isa<DbgInfoIntrinsic>(I)) { + SpeculatedDbgIntrinsics.push_back(I); continue; + } // Only speculatively execute a single instruction (not counting the // terminator) for now. @@ -2074,6 +2078,12 @@ static bool SpeculativelyExecuteBB(BranchInst *BI, BasicBlock *ThenBB, PN->setIncomingValue(ThenI, V); } + // Remove speculated dbg intrinsics. + // FIXME: Is it possible to do this in a more elegant way? Moving/merging the + // dbg value for the different flows and inserting it after the select. + for (Instruction *I : SpeculatedDbgIntrinsics) + I->eraseFromParent(); + ++NumSpeculations; return true; } |