diff options
author | Vedant Kumar <vsk@apple.com> | 2018-10-05 21:44:15 +0000 |
---|---|---|
committer | Vedant Kumar <vsk@apple.com> | 2018-10-05 21:44:15 +0000 |
commit | 8c46668b6e0715bd20980b6bb9169359c0811621 (patch) | |
tree | 95f3a0e58c0bdd5ef66f1f511269a2f1ae0737aa /llvm/lib/CodeGen/LiveDebugValues.cpp | |
parent | 9b558380ddd2796be7dd4e350c2682d4a4862ac8 (diff) | |
download | llvm-8c46668b6e0715bd20980b6bb9169359c0811621.zip llvm-8c46668b6e0715bd20980b6bb9169359c0811621.tar.gz llvm-8c46668b6e0715bd20980b6bb9169359c0811621.tar.bz2 |
[LiveDebugValues] Extend var ranges through artificial blocks
ASan often introduces basic blocks consisting exclusively of
instructions without debug locations, or with line 0 debug locations.
LiveDebugValues needs to extend variable ranges through these artificial
blocks. Otherwise, a lot of variables disappear -- even at -O0.
Typically, LiveDebugValues does not extend a variable's range into a
block unless the block is essentially "part of" the variable's scope
(for a precise definition, see LexicalScopes::dominates). This patch
relaxes the lexical dominance check for artificial blocks.
This makes the following Swift program debuggable at -O0:
```
1| var x = 100
2| print("x = \(x)")
```
rdar://39127144
Differential Revision: https://reviews.llvm.org/D52921
llvm-svn: 343890
Diffstat (limited to 'llvm/lib/CodeGen/LiveDebugValues.cpp')
-rw-r--r-- | llvm/lib/CodeGen/LiveDebugValues.cpp | 44 |
1 files changed, 32 insertions, 12 deletions
diff --git a/llvm/lib/CodeGen/LiveDebugValues.cpp b/llvm/lib/CodeGen/LiveDebugValues.cpp index 22e6c30..fc0ebea 100644 --- a/llvm/lib/CodeGen/LiveDebugValues.cpp +++ b/llvm/lib/CodeGen/LiveDebugValues.cpp @@ -258,7 +258,8 @@ private: bool join(MachineBasicBlock &MBB, VarLocInMBB &OutLocs, VarLocInMBB &InLocs, const VarLocMap &VarLocIDs, - SmallPtrSet<const MachineBasicBlock *, 16> &Visited); + SmallPtrSet<const MachineBasicBlock *, 16> &Visited, + SmallPtrSetImpl<const MachineBasicBlock *> &ArtificialBlocks); bool ExtendRanges(MachineFunction &MF); @@ -633,9 +634,11 @@ bool LiveDebugValues::process(MachineInstr &MI, OpenRangesSet &OpenRanges, /// This routine joins the analysis results of all incoming edges in @MBB by /// inserting a new DBG_VALUE instruction at the start of the @MBB - if the same /// source variable in all the predecessors of @MBB reside in the same location. -bool LiveDebugValues::join(MachineBasicBlock &MBB, VarLocInMBB &OutLocs, - VarLocInMBB &InLocs, const VarLocMap &VarLocIDs, - SmallPtrSet<const MachineBasicBlock *, 16> &Visited) { +bool LiveDebugValues::join( + MachineBasicBlock &MBB, VarLocInMBB &OutLocs, VarLocInMBB &InLocs, + const VarLocMap &VarLocIDs, + SmallPtrSet<const MachineBasicBlock *, 16> &Visited, + SmallPtrSetImpl<const MachineBasicBlock *> &ArtificialBlocks) { LLVM_DEBUG(dbgs() << "join MBB: " << MBB.getNumber() << "\n"); bool Changed = false; @@ -678,13 +681,16 @@ bool LiveDebugValues::join(MachineBasicBlock &MBB, VarLocInMBB &OutLocs, // Filter out DBG_VALUES that are out of scope. VarLocSet KillSet; - for (auto ID : InLocsT) { - if (!VarLocIDs[ID].dominates(MBB)) { - KillSet.set(ID); - LLVM_DEBUG({ - auto Name = VarLocIDs[ID].Var.getVar()->getName(); - dbgs() << " killing " << Name << ", it doesn't dominate MBB\n"; - }); + bool IsArtificial = ArtificialBlocks.count(&MBB); + if (!IsArtificial) { + for (auto ID : InLocsT) { + if (!VarLocIDs[ID].dominates(MBB)) { + KillSet.set(ID); + LLVM_DEBUG({ + auto Name = VarLocIDs[ID].Var.getVar()->getName(); + dbgs() << " killing " << Name << ", it doesn't dominate MBB\n"; + }); + } } } InLocsT.intersectWithComplement(KillSet); @@ -737,6 +743,10 @@ bool LiveDebugValues::ExtendRanges(MachineFunction &MF) { VarLocInMBB InLocs; // Ranges that are incoming after joining. TransferMap Transfers; // DBG_VALUEs associated with spills. + // Blocks which are artificial, i.e. blocks which exclusively contain + // instructions without locations, or with line 0 locations. + SmallPtrSet<const MachineBasicBlock *, 16> ArtificialBlocks; + DenseMap<unsigned int, MachineBasicBlock *> OrderToBB; DenseMap<MachineBasicBlock *, unsigned int> BBToOrder; std::priority_queue<unsigned int, std::vector<unsigned int>, @@ -758,6 +768,15 @@ bool LiveDebugValues::ExtendRanges(MachineFunction &MF) { process(MI, OpenRanges, OutLocs, VarLocIDs, Transfers, dontTransferChanges); + auto hasNonArtificialLocation = [](const MachineInstr &MI) -> bool { + if (const DebugLoc &DL = MI.getDebugLoc()) + return DL.getLine() != 0; + return false; + }; + for (auto &MBB : MF) + if (none_of(MBB.instrs(), hasNonArtificialLocation)) + ArtificialBlocks.insert(&MBB); + LLVM_DEBUG(printVarLocInMBB(MF, OutLocs, VarLocIDs, "OutLocs after initialization", dbgs())); @@ -783,7 +802,8 @@ bool LiveDebugValues::ExtendRanges(MachineFunction &MF) { while (!Worklist.empty()) { MachineBasicBlock *MBB = OrderToBB[Worklist.top()]; Worklist.pop(); - MBBJoined = join(*MBB, OutLocs, InLocs, VarLocIDs, Visited); + MBBJoined = + join(*MBB, OutLocs, InLocs, VarLocIDs, Visited, ArtificialBlocks); Visited.insert(MBB); if (MBBJoined) { MBBJoined = false; |