| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 1 | //===------ LiveDebugValues.cpp - Tracking Debug Value MIs ----------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | /// |
| 10 | /// This pass implements a data flow analysis that propagates debug location |
| 11 | /// information by inserting additional DBG_VALUE instructions into the machine |
| 12 | /// instruction stream. The pass internally builds debug location liveness |
| 13 | /// ranges to determine the points where additional DBG_VALUEs need to be |
| 14 | /// inserted. |
| 15 | /// |
| 16 | /// This is a separate pass from DbgValueHistoryCalculator to facilitate |
| 17 | /// testing and improve modularity. |
| 18 | /// |
| 19 | //===----------------------------------------------------------------------===// |
| 20 | |
| Daniel Berlin | 7256059 | 2016-01-10 18:08:32 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/PostOrderIterator.h" |
| 22 | #include "llvm/ADT/SmallPtrSet.h" |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/SparseBitVector.h" |
| Mehdi Amini | b550cb1 | 2016-04-18 09:17:29 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/Statistic.h" |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/UniqueVector.h" |
| Adrian Prantl | 7f5866c | 2016-09-28 17:51:14 +0000 | [diff] [blame] | 26 | #include "llvm/CodeGen/LexicalScopes.h" |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 27 | #include "llvm/CodeGen/MachineFunction.h" |
| 28 | #include "llvm/CodeGen/MachineFunctionPass.h" |
| 29 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
| 30 | #include "llvm/CodeGen/Passes.h" |
| Reid Kleckner | 2886580 | 2016-04-14 18:29:59 +0000 | [diff] [blame] | 31 | #include "llvm/IR/DebugInfo.h" |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 32 | #include "llvm/Support/Debug.h" |
| 33 | #include "llvm/Support/raw_ostream.h" |
| 34 | #include "llvm/Target/TargetInstrInfo.h" |
| Reid Kleckner | f6f04f8 | 2016-03-25 17:54:46 +0000 | [diff] [blame] | 35 | #include "llvm/Target/TargetLowering.h" |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 36 | #include "llvm/Target/TargetRegisterInfo.h" |
| 37 | #include "llvm/Target/TargetSubtargetInfo.h" |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 38 | #include <list> |
| Mehdi Amini | b550cb1 | 2016-04-18 09:17:29 +0000 | [diff] [blame] | 39 | #include <queue> |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 40 | |
| 41 | using namespace llvm; |
| 42 | |
| 43 | #define DEBUG_TYPE "live-debug-values" |
| 44 | |
| 45 | STATISTIC(NumInserted, "Number of DBG_VALUE instructions inserted"); |
| 46 | |
| 47 | namespace { |
| 48 | |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 49 | // \brief If @MI is a DBG_VALUE with debug value described by a defined |
| 50 | // register, returns the number of this register. In the other case, returns 0. |
| Adrian Prantl | 0069873 | 2016-05-25 22:37:29 +0000 | [diff] [blame] | 51 | static unsigned isDbgValueDescribedByReg(const MachineInstr &MI) { |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 52 | assert(MI.isDebugValue() && "expected a DBG_VALUE"); |
| 53 | assert(MI.getNumOperands() == 4 && "malformed DBG_VALUE"); |
| 54 | // If location of variable is described using a register (directly |
| 55 | // or indirectly), this register is always a first operand. |
| 56 | return MI.getOperand(0).isReg() ? MI.getOperand(0).getReg() : 0; |
| 57 | } |
| 58 | |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 59 | class LiveDebugValues : public MachineFunctionPass { |
| 60 | |
| 61 | private: |
| 62 | const TargetRegisterInfo *TRI; |
| 63 | const TargetInstrInfo *TII; |
| Adrian Prantl | 7f5866c | 2016-09-28 17:51:14 +0000 | [diff] [blame] | 64 | LexicalScopes LS; |
| 65 | |
| 66 | /// Keeps track of lexical scopes associated with a user value's source |
| 67 | /// location. |
| 68 | class UserValueScopes { |
| 69 | DebugLoc DL; |
| 70 | LexicalScopes &LS; |
| 71 | SmallPtrSet<const MachineBasicBlock *, 4> LBlocks; |
| 72 | |
| 73 | public: |
| 74 | UserValueScopes(DebugLoc D, LexicalScopes &L) : DL(std::move(D)), LS(L) {} |
| 75 | |
| 76 | /// Return true if current scope dominates at least one machine |
| 77 | /// instruction in a given machine basic block. |
| 78 | bool dominates(MachineBasicBlock *MBB) { |
| 79 | if (LBlocks.empty()) |
| 80 | LS.getMachineBasicBlocks(DL, LBlocks); |
| 81 | return LBlocks.count(MBB) != 0 || LS.dominates(DL, MBB); |
| 82 | } |
| 83 | }; |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 84 | |
| Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 85 | /// Based on std::pair so it can be used as an index into a DenseMap. |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 86 | typedef std::pair<const DILocalVariable *, const DILocation *> |
| Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 87 | DebugVariableBase; |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 88 | /// A potentially inlined instance of a variable. |
| Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 89 | struct DebugVariable : public DebugVariableBase { |
| 90 | DebugVariable(const DILocalVariable *Var, const DILocation *InlinedAt) |
| 91 | : DebugVariableBase(Var, InlinedAt) {} |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 92 | |
| Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 93 | const DILocalVariable *getVar() const { return this->first; }; |
| 94 | const DILocation *getInlinedAt() const { return this->second; }; |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 95 | |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 96 | bool operator<(const DebugVariable &DV) const { |
| Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 97 | if (getVar() == DV.getVar()) |
| 98 | return getInlinedAt() < DV.getInlinedAt(); |
| 99 | return getVar() < DV.getVar(); |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 100 | } |
| 101 | }; |
| 102 | |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 103 | /// A pair of debug variable and value location. |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 104 | struct VarLoc { |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 105 | const DebugVariable Var; |
| 106 | const MachineInstr &MI; ///< Only used for cloning a new DBG_VALUE. |
| Adrian Prantl | 7f5866c | 2016-09-28 17:51:14 +0000 | [diff] [blame] | 107 | mutable UserValueScopes UVS; |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 108 | enum { InvalidKind = 0, RegisterKind } Kind; |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 109 | |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 110 | /// The value location. Stored separately to avoid repeatedly |
| 111 | /// extracting it from MI. |
| 112 | union { |
| 113 | struct { |
| 114 | uint32_t RegNo; |
| 115 | uint32_t Offset; |
| 116 | } RegisterLoc; |
| 117 | uint64_t Hash; |
| 118 | } Loc; |
| 119 | |
| Adrian Prantl | 7f5866c | 2016-09-28 17:51:14 +0000 | [diff] [blame] | 120 | VarLoc(const MachineInstr &MI, LexicalScopes &LS) |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 121 | : Var(MI.getDebugVariable(), MI.getDebugLoc()->getInlinedAt()), MI(MI), |
| Adrian Prantl | 7f5866c | 2016-09-28 17:51:14 +0000 | [diff] [blame] | 122 | UVS(MI.getDebugLoc(), LS), Kind(InvalidKind) { |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 123 | static_assert((sizeof(Loc) == sizeof(uint64_t)), |
| 124 | "hash does not cover all members of Loc"); |
| 125 | assert(MI.isDebugValue() && "not a DBG_VALUE"); |
| 126 | assert(MI.getNumOperands() == 4 && "malformed DBG_VALUE"); |
| Adrian Prantl | 0069873 | 2016-05-25 22:37:29 +0000 | [diff] [blame] | 127 | if (int RegNo = isDbgValueDescribedByReg(MI)) { |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 128 | Kind = RegisterKind; |
| 129 | Loc.RegisterLoc.RegNo = RegNo; |
| Nico Weber | ee0b0ec | 2017-02-10 21:57:30 +0000 | [diff] [blame] | 130 | uint64_t Offset = |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 131 | MI.isIndirectDebugValue() ? MI.getOperand(1).getImm() : 0; |
| 132 | // We don't support offsets larger than 4GiB here. They are |
| 133 | // slated to be replaced with DIExpressions anyway. |
| Nico Weber | ee0b0ec | 2017-02-10 21:57:30 +0000 | [diff] [blame] | 134 | if (Offset >= (1ULL << 32)) |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 135 | Kind = InvalidKind; |
| 136 | else |
| 137 | Loc.RegisterLoc.Offset = Offset; |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | /// If this variable is described by a register, return it, |
| 142 | /// otherwise return 0. |
| 143 | unsigned isDescribedByReg() const { |
| 144 | if (Kind == RegisterKind) |
| 145 | return Loc.RegisterLoc.RegNo; |
| 146 | return 0; |
| 147 | } |
| 148 | |
| Adrian Prantl | 7f5866c | 2016-09-28 17:51:14 +0000 | [diff] [blame] | 149 | /// Determine whether the lexical scope of this value's debug location |
| 150 | /// dominates MBB. |
| 151 | bool dominates(MachineBasicBlock &MBB) const { return UVS.dominates(&MBB); } |
| 152 | |
| Matthias Braun | 194ded5 | 2017-01-28 06:53:55 +0000 | [diff] [blame] | 153 | #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) |
| 154 | LLVM_DUMP_METHOD void dump() const { MI.dump(); } |
| 155 | #endif |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 156 | |
| 157 | bool operator==(const VarLoc &Other) const { |
| 158 | return Var == Other.Var && Loc.Hash == Other.Loc.Hash; |
| 159 | } |
| 160 | |
| Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 161 | /// This operator guarantees that VarLocs are sorted by Variable first. |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 162 | bool operator<(const VarLoc &Other) const { |
| 163 | if (Var == Other.Var) |
| 164 | return Loc.Hash < Other.Loc.Hash; |
| 165 | return Var < Other.Var; |
| 166 | } |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 167 | }; |
| 168 | |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 169 | typedef UniqueVector<VarLoc> VarLocMap; |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 170 | typedef SparseBitVector<> VarLocSet; |
| 171 | typedef SmallDenseMap<const MachineBasicBlock *, VarLocSet> VarLocInMBB; |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 172 | |
| Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 173 | /// This holds the working set of currently open ranges. For fast |
| 174 | /// access, this is done both as a set of VarLocIDs, and a map of |
| 175 | /// DebugVariable to recent VarLocID. Note that a DBG_VALUE ends all |
| 176 | /// previous open ranges for the same variable. |
| 177 | class OpenRangesSet { |
| 178 | VarLocSet VarLocs; |
| 179 | SmallDenseMap<DebugVariableBase, unsigned, 8> Vars; |
| 180 | |
| 181 | public: |
| 182 | const VarLocSet &getVarLocs() const { return VarLocs; } |
| 183 | |
| 184 | /// Terminate all open ranges for Var by removing it from the set. |
| 185 | void erase(DebugVariable Var) { |
| 186 | auto It = Vars.find(Var); |
| 187 | if (It != Vars.end()) { |
| 188 | unsigned ID = It->second; |
| 189 | VarLocs.reset(ID); |
| 190 | Vars.erase(It); |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | /// Terminate all open ranges listed in \c KillSet by removing |
| 195 | /// them from the set. |
| 196 | void erase(const VarLocSet &KillSet, const VarLocMap &VarLocIDs) { |
| 197 | VarLocs.intersectWithComplement(KillSet); |
| 198 | for (unsigned ID : KillSet) |
| 199 | Vars.erase(VarLocIDs[ID].Var); |
| 200 | } |
| 201 | |
| 202 | /// Insert a new range into the set. |
| 203 | void insert(unsigned VarLocID, DebugVariableBase Var) { |
| 204 | VarLocs.set(VarLocID); |
| 205 | Vars.insert({Var, VarLocID}); |
| 206 | } |
| 207 | |
| 208 | /// Empty the set. |
| 209 | void clear() { |
| 210 | VarLocs.clear(); |
| 211 | Vars.clear(); |
| 212 | } |
| 213 | |
| 214 | /// Return whether the set is empty or not. |
| 215 | bool empty() const { |
| 216 | assert(Vars.empty() == VarLocs.empty() && "open ranges are inconsistent"); |
| 217 | return VarLocs.empty(); |
| 218 | } |
| 219 | }; |
| 220 | |
| 221 | void transferDebugValue(const MachineInstr &MI, OpenRangesSet &OpenRanges, |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 222 | VarLocMap &VarLocIDs); |
| Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 223 | void transferRegisterDef(MachineInstr &MI, OpenRangesSet &OpenRanges, |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 224 | const VarLocMap &VarLocIDs); |
| Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 225 | bool transferTerminatorInst(MachineInstr &MI, OpenRangesSet &OpenRanges, |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 226 | VarLocInMBB &OutLocs, const VarLocMap &VarLocIDs); |
| Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 227 | bool transfer(MachineInstr &MI, OpenRangesSet &OpenRanges, |
| Nico Weber | ee0b0ec | 2017-02-10 21:57:30 +0000 | [diff] [blame] | 228 | VarLocInMBB &OutLocs, VarLocMap &VarLocIDs); |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 229 | |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 230 | bool join(MachineBasicBlock &MBB, VarLocInMBB &OutLocs, VarLocInMBB &InLocs, |
| Keith Walker | 83ebef5 | 2016-09-27 16:46:07 +0000 | [diff] [blame] | 231 | const VarLocMap &VarLocIDs, |
| 232 | SmallPtrSet<const MachineBasicBlock *, 16> &Visited); |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 233 | |
| 234 | bool ExtendRanges(MachineFunction &MF); |
| 235 | |
| 236 | public: |
| 237 | static char ID; |
| 238 | |
| 239 | /// Default construct and initialize the pass. |
| 240 | LiveDebugValues(); |
| 241 | |
| 242 | /// Tell the pass manager which passes we depend on and what |
| 243 | /// information we preserve. |
| 244 | void getAnalysisUsage(AnalysisUsage &AU) const override; |
| 245 | |
| Derek Schuff | ad154c8 | 2016-03-28 17:05:30 +0000 | [diff] [blame] | 246 | MachineFunctionProperties getRequiredProperties() const override { |
| 247 | return MachineFunctionProperties().set( |
| Matthias Braun | 1eb4736 | 2016-08-25 01:27:13 +0000 | [diff] [blame] | 248 | MachineFunctionProperties::Property::NoVRegs); |
| Derek Schuff | ad154c8 | 2016-03-28 17:05:30 +0000 | [diff] [blame] | 249 | } |
| 250 | |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 251 | /// Print to ostream with a message. |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 252 | void printVarLocInMBB(const MachineFunction &MF, const VarLocInMBB &V, |
| 253 | const VarLocMap &VarLocIDs, const char *msg, |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 254 | raw_ostream &Out) const; |
| 255 | |
| 256 | /// Calculate the liveness information for the given machine function. |
| 257 | bool runOnMachineFunction(MachineFunction &MF) override; |
| 258 | }; |
| Adrian Prantl | 7f5866c | 2016-09-28 17:51:14 +0000 | [diff] [blame] | 259 | |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 260 | } // namespace |
| 261 | |
| 262 | //===----------------------------------------------------------------------===// |
| 263 | // Implementation |
| 264 | //===----------------------------------------------------------------------===// |
| 265 | |
| 266 | char LiveDebugValues::ID = 0; |
| 267 | char &llvm::LiveDebugValuesID = LiveDebugValues::ID; |
| 268 | INITIALIZE_PASS(LiveDebugValues, "livedebugvalues", "Live DEBUG_VALUE analysis", |
| 269 | false, false) |
| 270 | |
| 271 | /// Default construct and initialize the pass. |
| 272 | LiveDebugValues::LiveDebugValues() : MachineFunctionPass(ID) { |
| 273 | initializeLiveDebugValuesPass(*PassRegistry::getPassRegistry()); |
| 274 | } |
| 275 | |
| 276 | /// Tell the pass manager which passes we depend on and what information we |
| 277 | /// preserve. |
| 278 | void LiveDebugValues::getAnalysisUsage(AnalysisUsage &AU) const { |
| Matt Arsenault | b1630a1 | 2016-06-08 05:18:01 +0000 | [diff] [blame] | 279 | AU.setPreservesCFG(); |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 280 | MachineFunctionPass::getAnalysisUsage(AU); |
| 281 | } |
| 282 | |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 283 | //===----------------------------------------------------------------------===// |
| 284 | // Debug Range Extension Implementation |
| 285 | //===----------------------------------------------------------------------===// |
| 286 | |
| Matthias Braun | 194ded5 | 2017-01-28 06:53:55 +0000 | [diff] [blame] | 287 | #ifndef NDEBUG |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 288 | void LiveDebugValues::printVarLocInMBB(const MachineFunction &MF, |
| 289 | const VarLocInMBB &V, |
| 290 | const VarLocMap &VarLocIDs, |
| 291 | const char *msg, |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 292 | raw_ostream &Out) const { |
| Keith Walker | f83a19f | 2016-09-20 16:04:31 +0000 | [diff] [blame] | 293 | Out << '\n' << msg << '\n'; |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 294 | for (const MachineBasicBlock &BB : MF) { |
| 295 | const auto &L = V.lookup(&BB); |
| 296 | Out << "MBB: " << BB.getName() << ":\n"; |
| 297 | for (unsigned VLL : L) { |
| 298 | const VarLoc &VL = VarLocIDs[VLL]; |
| Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 299 | Out << " Var: " << VL.Var.getVar()->getName(); |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 300 | Out << " MI: "; |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 301 | VL.dump(); |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 302 | } |
| 303 | } |
| 304 | Out << "\n"; |
| 305 | } |
| Matthias Braun | 194ded5 | 2017-01-28 06:53:55 +0000 | [diff] [blame] | 306 | #endif |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 307 | |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 308 | /// End all previous ranges related to @MI and start a new range from @MI |
| 309 | /// if it is a DBG_VALUE instr. |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 310 | void LiveDebugValues::transferDebugValue(const MachineInstr &MI, |
| Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 311 | OpenRangesSet &OpenRanges, |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 312 | VarLocMap &VarLocIDs) { |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 313 | if (!MI.isDebugValue()) |
| 314 | return; |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 315 | const DILocalVariable *Var = MI.getDebugVariable(); |
| 316 | const DILocation *DebugLoc = MI.getDebugLoc(); |
| 317 | const DILocation *InlinedAt = DebugLoc->getInlinedAt(); |
| 318 | assert(Var->isValidLocationForIntrinsic(DebugLoc) && |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 319 | "Expected inlined-at fields to agree"); |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 320 | |
| 321 | // End all previous ranges of Var. |
| Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 322 | DebugVariable V(Var, InlinedAt); |
| 323 | OpenRanges.erase(V); |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 324 | |
| 325 | // Add the VarLoc to OpenRanges from this DBG_VALUE. |
| 326 | // TODO: Currently handles DBG_VALUE which has only reg as location. |
| Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 327 | if (isDbgValueDescribedByReg(MI)) { |
| Adrian Prantl | 7f5866c | 2016-09-28 17:51:14 +0000 | [diff] [blame] | 328 | VarLoc VL(MI, LS); |
| Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 329 | unsigned ID = VarLocIDs.insert(VL); |
| 330 | OpenRanges.insert(ID, VL.Var); |
| 331 | } |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | /// A definition of a register may mark the end of a range. |
| 335 | void LiveDebugValues::transferRegisterDef(MachineInstr &MI, |
| Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 336 | OpenRangesSet &OpenRanges, |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 337 | const VarLocMap &VarLocIDs) { |
| Reid Kleckner | f6f04f8 | 2016-03-25 17:54:46 +0000 | [diff] [blame] | 338 | MachineFunction *MF = MI.getParent()->getParent(); |
| 339 | const TargetLowering *TLI = MF->getSubtarget().getTargetLowering(); |
| 340 | unsigned SP = TLI->getStackPointerRegisterToSaveRestore(); |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 341 | SparseBitVector<> KillSet; |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 342 | for (const MachineOperand &MO : MI.operands()) { |
| Reid Kleckner | f6f04f8 | 2016-03-25 17:54:46 +0000 | [diff] [blame] | 343 | if (MO.isReg() && MO.isDef() && MO.getReg() && |
| 344 | TRI->isPhysicalRegister(MO.getReg())) { |
| 345 | // Remove ranges of all aliased registers. |
| 346 | for (MCRegAliasIterator RAI(MO.getReg(), TRI, true); RAI.isValid(); ++RAI) |
| Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 347 | for (unsigned ID : OpenRanges.getVarLocs()) |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 348 | if (VarLocIDs[ID].isDescribedByReg() == *RAI) |
| 349 | KillSet.set(ID); |
| Reid Kleckner | f6f04f8 | 2016-03-25 17:54:46 +0000 | [diff] [blame] | 350 | } else if (MO.isRegMask()) { |
| 351 | // Remove ranges of all clobbered registers. Register masks don't usually |
| 352 | // list SP as preserved. While the debug info may be off for an |
| 353 | // instruction or two around callee-cleanup calls, transferring the |
| 354 | // DEBUG_VALUE across the call is still a better user experience. |
| Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 355 | for (unsigned ID : OpenRanges.getVarLocs()) { |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 356 | unsigned Reg = VarLocIDs[ID].isDescribedByReg(); |
| 357 | if (Reg && Reg != SP && MO.clobbersPhysReg(Reg)) |
| 358 | KillSet.set(ID); |
| 359 | } |
| Reid Kleckner | f6f04f8 | 2016-03-25 17:54:46 +0000 | [diff] [blame] | 360 | } |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 361 | } |
| Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 362 | OpenRanges.erase(KillSet, VarLocIDs); |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | /// Terminate all open ranges at the end of the current basic block. |
| Daniel Berlin | ca4d93a | 2016-01-10 03:25:42 +0000 | [diff] [blame] | 366 | bool LiveDebugValues::transferTerminatorInst(MachineInstr &MI, |
| Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 367 | OpenRangesSet &OpenRanges, |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 368 | VarLocInMBB &OutLocs, |
| 369 | const VarLocMap &VarLocIDs) { |
| Daniel Berlin | ca4d93a | 2016-01-10 03:25:42 +0000 | [diff] [blame] | 370 | bool Changed = false; |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 371 | const MachineBasicBlock *CurMBB = MI.getParent(); |
| 372 | if (!(MI.isTerminator() || (&MI == &CurMBB->instr_back()))) |
| Daniel Berlin | ca4d93a | 2016-01-10 03:25:42 +0000 | [diff] [blame] | 373 | return false; |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 374 | |
| 375 | if (OpenRanges.empty()) |
| Daniel Berlin | ca4d93a | 2016-01-10 03:25:42 +0000 | [diff] [blame] | 376 | return false; |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 377 | |
| Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 378 | DEBUG(for (unsigned ID : OpenRanges.getVarLocs()) { |
| 379 | // Copy OpenRanges to OutLocs, if not already present. |
| 380 | dbgs() << "Add to OutLocs: "; VarLocIDs[ID].dump(); |
| 381 | }); |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 382 | VarLocSet &VLS = OutLocs[CurMBB]; |
| Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 383 | Changed = VLS |= OpenRanges.getVarLocs(); |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 384 | OpenRanges.clear(); |
| Daniel Berlin | ca4d93a | 2016-01-10 03:25:42 +0000 | [diff] [blame] | 385 | return Changed; |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | /// This routine creates OpenRanges and OutLocs. |
| Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 389 | bool LiveDebugValues::transfer(MachineInstr &MI, OpenRangesSet &OpenRanges, |
| Nico Weber | ee0b0ec | 2017-02-10 21:57:30 +0000 | [diff] [blame] | 390 | VarLocInMBB &OutLocs, VarLocMap &VarLocIDs) { |
| Daniel Berlin | ca4d93a | 2016-01-10 03:25:42 +0000 | [diff] [blame] | 391 | bool Changed = false; |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 392 | transferDebugValue(MI, OpenRanges, VarLocIDs); |
| 393 | transferRegisterDef(MI, OpenRanges, VarLocIDs); |
| 394 | Changed = transferTerminatorInst(MI, OpenRanges, OutLocs, VarLocIDs); |
| Daniel Berlin | ca4d93a | 2016-01-10 03:25:42 +0000 | [diff] [blame] | 395 | return Changed; |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | /// This routine joins the analysis results of all incoming edges in @MBB by |
| 399 | /// inserting a new DBG_VALUE instruction at the start of the @MBB - if the same |
| 400 | /// source variable in all the predecessors of @MBB reside in the same location. |
| Daniel Berlin | ca4d93a | 2016-01-10 03:25:42 +0000 | [diff] [blame] | 401 | bool LiveDebugValues::join(MachineBasicBlock &MBB, VarLocInMBB &OutLocs, |
| Keith Walker | 83ebef5 | 2016-09-27 16:46:07 +0000 | [diff] [blame] | 402 | VarLocInMBB &InLocs, const VarLocMap &VarLocIDs, |
| 403 | SmallPtrSet<const MachineBasicBlock *, 16> &Visited) { |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 404 | DEBUG(dbgs() << "join MBB: " << MBB.getName() << "\n"); |
| Daniel Berlin | ca4d93a | 2016-01-10 03:25:42 +0000 | [diff] [blame] | 405 | bool Changed = false; |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 406 | |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 407 | VarLocSet InLocsT; // Temporary incoming locations. |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 408 | |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 409 | // For all predecessors of this MBB, find the set of VarLocs that |
| 410 | // can be joined. |
| Keith Walker | 83ebef5 | 2016-09-27 16:46:07 +0000 | [diff] [blame] | 411 | int NumVisited = 0; |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 412 | for (auto p : MBB.predecessors()) { |
| Keith Walker | 83ebef5 | 2016-09-27 16:46:07 +0000 | [diff] [blame] | 413 | // Ignore unvisited predecessor blocks. As we are processing |
| 414 | // the blocks in reverse post-order any unvisited block can |
| 415 | // be considered to not remove any incoming values. |
| 416 | if (!Visited.count(p)) |
| 417 | continue; |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 418 | auto OL = OutLocs.find(p); |
| 419 | // Join is null in case of empty OutLocs from any of the pred. |
| 420 | if (OL == OutLocs.end()) |
| Daniel Berlin | ca4d93a | 2016-01-10 03:25:42 +0000 | [diff] [blame] | 421 | return false; |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 422 | |
| Keith Walker | 83ebef5 | 2016-09-27 16:46:07 +0000 | [diff] [blame] | 423 | // Just copy over the Out locs to incoming locs for the first visited |
| 424 | // predecessor, and for all other predecessors join the Out locs. |
| 425 | if (!NumVisited) |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 426 | InLocsT = OL->second; |
| Keith Walker | 83ebef5 | 2016-09-27 16:46:07 +0000 | [diff] [blame] | 427 | else |
| 428 | InLocsT &= OL->second; |
| 429 | NumVisited++; |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 430 | } |
| 431 | |
| Adrian Prantl | 7f5866c | 2016-09-28 17:51:14 +0000 | [diff] [blame] | 432 | // Filter out DBG_VALUES that are out of scope. |
| 433 | VarLocSet KillSet; |
| 434 | for (auto ID : InLocsT) |
| 435 | if (!VarLocIDs[ID].dominates(MBB)) |
| 436 | KillSet.set(ID); |
| 437 | InLocsT.intersectWithComplement(KillSet); |
| 438 | |
| Keith Walker | 83ebef5 | 2016-09-27 16:46:07 +0000 | [diff] [blame] | 439 | // As we are processing blocks in reverse post-order we |
| 440 | // should have processed at least one predecessor, unless it |
| 441 | // is the entry block which has no predecessor. |
| 442 | assert((NumVisited || MBB.pred_empty()) && |
| 443 | "Should have processed at least one predecessor"); |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 444 | if (InLocsT.empty()) |
| Daniel Berlin | ca4d93a | 2016-01-10 03:25:42 +0000 | [diff] [blame] | 445 | return false; |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 446 | |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 447 | VarLocSet &ILS = InLocs[&MBB]; |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 448 | |
| 449 | // Insert DBG_VALUE instructions, if not already inserted. |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 450 | VarLocSet Diff = InLocsT; |
| 451 | Diff.intersectWithComplement(ILS); |
| 452 | for (auto ID : Diff) { |
| 453 | // This VarLoc is not found in InLocs i.e. it is not yet inserted. So, a |
| 454 | // new range is started for the var from the mbb's beginning by inserting |
| 455 | // a new DBG_VALUE. transfer() will end this range however appropriate. |
| 456 | const VarLoc &DiffIt = VarLocIDs[ID]; |
| 457 | const MachineInstr *DMI = &DiffIt.MI; |
| 458 | MachineInstr *MI = |
| 459 | BuildMI(MBB, MBB.instr_begin(), DMI->getDebugLoc(), DMI->getDesc(), |
| 460 | DMI->isIndirectDebugValue(), DMI->getOperand(0).getReg(), 0, |
| 461 | DMI->getDebugVariable(), DMI->getDebugExpression()); |
| 462 | if (DMI->isIndirectDebugValue()) |
| 463 | MI->getOperand(1).setImm(DMI->getOperand(1).getImm()); |
| 464 | DEBUG(dbgs() << "Inserted: "; MI->dump();); |
| 465 | ILS.set(ID); |
| 466 | ++NumInserted; |
| 467 | Changed = true; |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 468 | } |
| Daniel Berlin | ca4d93a | 2016-01-10 03:25:42 +0000 | [diff] [blame] | 469 | return Changed; |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | /// Calculate the liveness information for the given machine function and |
| 473 | /// extend ranges across basic blocks. |
| 474 | bool LiveDebugValues::ExtendRanges(MachineFunction &MF) { |
| 475 | |
| 476 | DEBUG(dbgs() << "\nDebug Range Extension\n"); |
| 477 | |
| 478 | bool Changed = false; |
| Daniel Berlin | ca4d93a | 2016-01-10 03:25:42 +0000 | [diff] [blame] | 479 | bool OLChanged = false; |
| 480 | bool MBBJoined = false; |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 481 | |
| Nico Weber | ee0b0ec | 2017-02-10 21:57:30 +0000 | [diff] [blame] | 482 | VarLocMap VarLocIDs; // Map VarLoc<>unique ID for use in bitvectors. |
| Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 483 | OpenRangesSet OpenRanges; // Ranges that are open until end of bb. |
| Nico Weber | ee0b0ec | 2017-02-10 21:57:30 +0000 | [diff] [blame] | 484 | VarLocInMBB OutLocs; // Ranges that exist beyond bb. |
| 485 | VarLocInMBB InLocs; // Ranges that are incoming after joining. |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 486 | |
| Daniel Berlin | 7256059 | 2016-01-10 18:08:32 +0000 | [diff] [blame] | 487 | DenseMap<unsigned int, MachineBasicBlock *> OrderToBB; |
| 488 | DenseMap<MachineBasicBlock *, unsigned int> BBToOrder; |
| 489 | std::priority_queue<unsigned int, std::vector<unsigned int>, |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 490 | std::greater<unsigned int>> |
| 491 | Worklist; |
| Daniel Berlin | 7256059 | 2016-01-10 18:08:32 +0000 | [diff] [blame] | 492 | std::priority_queue<unsigned int, std::vector<unsigned int>, |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 493 | std::greater<unsigned int>> |
| 494 | Pending; |
| 495 | |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 496 | // Initialize every mbb with OutLocs. |
| 497 | for (auto &MBB : MF) |
| 498 | for (auto &MI : MBB) |
| Nico Weber | ee0b0ec | 2017-02-10 21:57:30 +0000 | [diff] [blame] | 499 | transfer(MI, OpenRanges, OutLocs, VarLocIDs); |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 500 | |
| 501 | DEBUG(printVarLocInMBB(MF, OutLocs, VarLocIDs, "OutLocs after initialization", |
| 502 | dbgs())); |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 503 | |
| Daniel Berlin | 7256059 | 2016-01-10 18:08:32 +0000 | [diff] [blame] | 504 | ReversePostOrderTraversal<MachineFunction *> RPOT(&MF); |
| 505 | unsigned int RPONumber = 0; |
| 506 | for (auto RI = RPOT.begin(), RE = RPOT.end(); RI != RE; ++RI) { |
| 507 | OrderToBB[RPONumber] = *RI; |
| 508 | BBToOrder[*RI] = RPONumber; |
| 509 | Worklist.push(RPONumber); |
| 510 | ++RPONumber; |
| 511 | } |
| Daniel Berlin | 7256059 | 2016-01-10 18:08:32 +0000 | [diff] [blame] | 512 | // This is a standard "union of predecessor outs" dataflow problem. |
| 513 | // To solve it, we perform join() and transfer() using the two worklist method |
| 514 | // until the ranges converge. |
| 515 | // Ranges have converged when both worklists are empty. |
| Keith Walker | 83ebef5 | 2016-09-27 16:46:07 +0000 | [diff] [blame] | 516 | SmallPtrSet<const MachineBasicBlock *, 16> Visited; |
| Daniel Berlin | 7256059 | 2016-01-10 18:08:32 +0000 | [diff] [blame] | 517 | while (!Worklist.empty() || !Pending.empty()) { |
| 518 | // We track what is on the pending worklist to avoid inserting the same |
| 519 | // thing twice. We could avoid this with a custom priority queue, but this |
| 520 | // is probably not worth it. |
| 521 | SmallPtrSet<MachineBasicBlock *, 16> OnPending; |
| Keith Walker | f83a19f | 2016-09-20 16:04:31 +0000 | [diff] [blame] | 522 | DEBUG(dbgs() << "Processing Worklist\n"); |
| Daniel Berlin | 7256059 | 2016-01-10 18:08:32 +0000 | [diff] [blame] | 523 | while (!Worklist.empty()) { |
| 524 | MachineBasicBlock *MBB = OrderToBB[Worklist.top()]; |
| 525 | Worklist.pop(); |
| Keith Walker | 83ebef5 | 2016-09-27 16:46:07 +0000 | [diff] [blame] | 526 | MBBJoined = join(*MBB, OutLocs, InLocs, VarLocIDs, Visited); |
| 527 | Visited.insert(MBB); |
| Daniel Berlin | 7256059 | 2016-01-10 18:08:32 +0000 | [diff] [blame] | 528 | if (MBBJoined) { |
| 529 | MBBJoined = false; |
| 530 | Changed = true; |
| 531 | for (auto &MI : *MBB) |
| Nico Weber | ee0b0ec | 2017-02-10 21:57:30 +0000 | [diff] [blame] | 532 | OLChanged |= transfer(MI, OpenRanges, OutLocs, VarLocIDs); |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 533 | |
| 534 | DEBUG(printVarLocInMBB(MF, OutLocs, VarLocIDs, |
| 535 | "OutLocs after propagating", dbgs())); |
| 536 | DEBUG(printVarLocInMBB(MF, InLocs, VarLocIDs, |
| 537 | "InLocs after propagating", dbgs())); |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 538 | |
| Daniel Berlin | 7256059 | 2016-01-10 18:08:32 +0000 | [diff] [blame] | 539 | if (OLChanged) { |
| 540 | OLChanged = false; |
| 541 | for (auto s : MBB->successors()) |
| Benjamin Kramer | 4dea8f5 | 2016-06-17 18:59:41 +0000 | [diff] [blame] | 542 | if (OnPending.insert(s).second) { |
| Daniel Berlin | 7256059 | 2016-01-10 18:08:32 +0000 | [diff] [blame] | 543 | Pending.push(BBToOrder[s]); |
| 544 | } |
| 545 | } |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 546 | } |
| 547 | } |
| Daniel Berlin | 7256059 | 2016-01-10 18:08:32 +0000 | [diff] [blame] | 548 | Worklist.swap(Pending); |
| 549 | // At this point, pending must be empty, since it was just the empty |
| 550 | // worklist |
| 551 | assert(Pending.empty() && "Pending should be empty"); |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 552 | } |
| Daniel Berlin | 7256059 | 2016-01-10 18:08:32 +0000 | [diff] [blame] | 553 | |
| Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 554 | DEBUG(printVarLocInMBB(MF, OutLocs, VarLocIDs, "Final OutLocs", dbgs())); |
| 555 | DEBUG(printVarLocInMBB(MF, InLocs, VarLocIDs, "Final InLocs", dbgs())); |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 556 | return Changed; |
| 557 | } |
| 558 | |
| 559 | bool LiveDebugValues::runOnMachineFunction(MachineFunction &MF) { |
| Adrian Prantl | 7f5866c | 2016-09-28 17:51:14 +0000 | [diff] [blame] | 560 | if (!MF.getFunction()->getSubprogram()) |
| 561 | // LiveDebugValues will already have removed all DBG_VALUEs. |
| 562 | return false; |
| 563 | |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 564 | TRI = MF.getSubtarget().getRegisterInfo(); |
| 565 | TII = MF.getSubtarget().getInstrInfo(); |
| Adrian Prantl | 7f5866c | 2016-09-28 17:51:14 +0000 | [diff] [blame] | 566 | LS.initialize(MF); |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 567 | |
| Adrian Prantl | 7f5866c | 2016-09-28 17:51:14 +0000 | [diff] [blame] | 568 | bool Changed = ExtendRanges(MF); |
| Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 569 | return Changed; |
| 570 | } |