Jakob Stoklund Olesen | d4900a6 | 2010-11-30 02:17:10 +0000 | [diff] [blame] | 1 | //===- LiveDebugVariables.cpp - Tracking debug info variables -------------===// |
| 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 file implements the LiveDebugVariables analysis. |
| 11 | // |
| 12 | // Remove all DBG_VALUE instructions referencing virtual registers and replace |
| 13 | // them with a data structure tracking where live user variables are kept - in a |
| 14 | // virtual register or in a stack slot. |
| 15 | // |
| 16 | // Allow the data structure to be updated during register allocation when values |
| 17 | // are moved between registers and stack slots. Finally emit new DBG_VALUE |
| 18 | // instructions after register allocation is complete. |
| 19 | // |
| 20 | //===----------------------------------------------------------------------===// |
| 21 | |
| 22 | #include "LiveDebugVariables.h" |
Eugene Zelenko | 5df3d89 | 2017-08-24 21:21:39 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/ArrayRef.h" |
| 24 | #include "llvm/ADT/DenseMap.h" |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/IntervalMap.h" |
Eugene Zelenko | 5df3d89 | 2017-08-24 21:21:39 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/STLExtras.h" |
Robert Lougher | 10f740d | 2017-08-03 11:54:02 +0000 | [diff] [blame] | 27 | #include "llvm/ADT/SmallSet.h" |
Eugene Zelenko | 5df3d89 | 2017-08-24 21:21:39 +0000 | [diff] [blame] | 28 | #include "llvm/ADT/SmallVector.h" |
Devang Patel | b456866 | 2011-08-04 18:45:38 +0000 | [diff] [blame] | 29 | #include "llvm/ADT/Statistic.h" |
Eugene Zelenko | 5df3d89 | 2017-08-24 21:21:39 +0000 | [diff] [blame] | 30 | #include "llvm/ADT/StringRef.h" |
Robert Lougher | 10f740d | 2017-08-03 11:54:02 +0000 | [diff] [blame] | 31 | #include "llvm/CodeGen/LexicalScopes.h" |
Eugene Zelenko | 5df3d89 | 2017-08-24 21:21:39 +0000 | [diff] [blame] | 32 | #include "llvm/CodeGen/LiveInterval.h" |
Matthias Braun | f842297 | 2017-12-13 02:51:04 +0000 | [diff] [blame] | 33 | #include "llvm/CodeGen/LiveIntervals.h" |
Eugene Zelenko | 5df3d89 | 2017-08-24 21:21:39 +0000 | [diff] [blame] | 34 | #include "llvm/CodeGen/MachineBasicBlock.h" |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 35 | #include "llvm/CodeGen/MachineDominators.h" |
Jakob Stoklund Olesen | afc2bc2 | 2010-12-03 21:47:10 +0000 | [diff] [blame] | 36 | #include "llvm/CodeGen/MachineFunction.h" |
Eugene Zelenko | 5df3d89 | 2017-08-24 21:21:39 +0000 | [diff] [blame] | 37 | #include "llvm/CodeGen/MachineInstr.h" |
Jakob Stoklund Olesen | afc2bc2 | 2010-12-03 21:47:10 +0000 | [diff] [blame] | 38 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Eugene Zelenko | 5df3d89 | 2017-08-24 21:21:39 +0000 | [diff] [blame] | 39 | #include "llvm/CodeGen/MachineOperand.h" |
Jakob Stoklund Olesen | 816f5f4 | 2011-03-18 21:42:19 +0000 | [diff] [blame] | 40 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Eugene Zelenko | 5df3d89 | 2017-08-24 21:21:39 +0000 | [diff] [blame] | 41 | #include "llvm/CodeGen/SlotIndexes.h" |
David Blaikie | 3f833ed | 2017-11-08 01:01:31 +0000 | [diff] [blame] | 42 | #include "llvm/CodeGen/TargetInstrInfo.h" |
David Blaikie | b3bde2e | 2017-11-17 01:07:10 +0000 | [diff] [blame] | 43 | #include "llvm/CodeGen/TargetOpcodes.h" |
| 44 | #include "llvm/CodeGen/TargetRegisterInfo.h" |
| 45 | #include "llvm/CodeGen/TargetSubtargetInfo.h" |
Jakob Stoklund Olesen | 26c9d70 | 2012-11-28 19:13:06 +0000 | [diff] [blame] | 46 | #include "llvm/CodeGen/VirtRegMap.h" |
Nico Weber | 432a388 | 2018-04-30 14:59:11 +0000 | [diff] [blame] | 47 | #include "llvm/Config/llvm-config.h" |
Eugene Zelenko | 5df3d89 | 2017-08-24 21:21:39 +0000 | [diff] [blame] | 48 | #include "llvm/IR/DebugInfoMetadata.h" |
| 49 | #include "llvm/IR/DebugLoc.h" |
| 50 | #include "llvm/IR/Function.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 51 | #include "llvm/IR/Metadata.h" |
Eugene Zelenko | 5df3d89 | 2017-08-24 21:21:39 +0000 | [diff] [blame] | 52 | #include "llvm/MC/MCRegisterInfo.h" |
| 53 | #include "llvm/Pass.h" |
| 54 | #include "llvm/Support/Casting.h" |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 55 | #include "llvm/Support/CommandLine.h" |
Eugene Zelenko | 5df3d89 | 2017-08-24 21:21:39 +0000 | [diff] [blame] | 56 | #include "llvm/Support/Compiler.h" |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 57 | #include "llvm/Support/Debug.h" |
Benjamin Kramer | 799003b | 2015-03-23 19:32:43 +0000 | [diff] [blame] | 58 | #include "llvm/Support/raw_ostream.h" |
Eugene Zelenko | 5df3d89 | 2017-08-24 21:21:39 +0000 | [diff] [blame] | 59 | #include <algorithm> |
| 60 | #include <cassert> |
| 61 | #include <iterator> |
David Blaikie | 2b1dfa7 | 2014-04-21 20:37:07 +0000 | [diff] [blame] | 62 | #include <memory> |
Benjamin Kramer | 82de7d3 | 2016-05-27 14:27:24 +0000 | [diff] [blame] | 63 | #include <utility> |
David Blaikie | 2b1dfa7 | 2014-04-21 20:37:07 +0000 | [diff] [blame] | 64 | |
Jakob Stoklund Olesen | d4900a6 | 2010-11-30 02:17:10 +0000 | [diff] [blame] | 65 | using namespace llvm; |
| 66 | |
Matthias Braun | 1527baa | 2017-05-25 21:26:32 +0000 | [diff] [blame] | 67 | #define DEBUG_TYPE "livedebugvars" |
Chandler Carruth | 1b9dde0 | 2014-04-22 02:02:50 +0000 | [diff] [blame] | 68 | |
Devang Patel | acbee0b | 2011-01-07 22:33:41 +0000 | [diff] [blame] | 69 | static cl::opt<bool> |
Jakob Stoklund Olesen | 74ded57 | 2011-01-12 23:36:21 +0000 | [diff] [blame] | 70 | EnableLDV("live-debug-variables", cl::init(true), |
Devang Patel | acbee0b | 2011-01-07 22:33:41 +0000 | [diff] [blame] | 71 | cl::desc("Enable the live debug variables pass"), cl::Hidden); |
| 72 | |
Devang Patel | b456866 | 2011-08-04 18:45:38 +0000 | [diff] [blame] | 73 | STATISTIC(NumInsertedDebugValues, "Number of DBG_VALUEs inserted"); |
Eugene Zelenko | 5df3d89 | 2017-08-24 21:21:39 +0000 | [diff] [blame] | 74 | |
Jakob Stoklund Olesen | d4900a6 | 2010-11-30 02:17:10 +0000 | [diff] [blame] | 75 | char LiveDebugVariables::ID = 0; |
| 76 | |
Matthias Braun | 1527baa | 2017-05-25 21:26:32 +0000 | [diff] [blame] | 77 | INITIALIZE_PASS_BEGIN(LiveDebugVariables, DEBUG_TYPE, |
Jakob Stoklund Olesen | d4900a6 | 2010-11-30 02:17:10 +0000 | [diff] [blame] | 78 | "Debug Variable Analysis", false, false) |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 79 | INITIALIZE_PASS_DEPENDENCY(MachineDominatorTree) |
Jakob Stoklund Olesen | d4900a6 | 2010-11-30 02:17:10 +0000 | [diff] [blame] | 80 | INITIALIZE_PASS_DEPENDENCY(LiveIntervals) |
Matthias Braun | 1527baa | 2017-05-25 21:26:32 +0000 | [diff] [blame] | 81 | INITIALIZE_PASS_END(LiveDebugVariables, DEBUG_TYPE, |
Jakob Stoklund Olesen | d4900a6 | 2010-11-30 02:17:10 +0000 | [diff] [blame] | 82 | "Debug Variable Analysis", false, false) |
| 83 | |
| 84 | void LiveDebugVariables::getAnalysisUsage(AnalysisUsage &AU) const { |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 85 | AU.addRequired<MachineDominatorTree>(); |
Jakob Stoklund Olesen | d4900a6 | 2010-11-30 02:17:10 +0000 | [diff] [blame] | 86 | AU.addRequiredTransitive<LiveIntervals>(); |
| 87 | AU.setPreservesAll(); |
| 88 | MachineFunctionPass::getAnalysisUsage(AU); |
| 89 | } |
| 90 | |
Eugene Zelenko | 5df3d89 | 2017-08-24 21:21:39 +0000 | [diff] [blame] | 91 | LiveDebugVariables::LiveDebugVariables() : MachineFunctionPass(ID) { |
Jakob Stoklund Olesen | d4900a6 | 2010-11-30 02:17:10 +0000 | [diff] [blame] | 92 | initializeLiveDebugVariablesPass(*PassRegistry::getPassRegistry()); |
| 93 | } |
| 94 | |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 95 | enum : unsigned { UndefLocNo = ~0U }; |
| 96 | |
| 97 | /// Describes a location by number along with some flags about the original |
| 98 | /// usage of the location. |
| 99 | class DbgValueLocation { |
| 100 | public: |
| 101 | DbgValueLocation(unsigned LocNo, bool WasIndirect) |
| 102 | : LocNo(LocNo), WasIndirect(WasIndirect) { |
| 103 | static_assert(sizeof(*this) == sizeof(unsigned), "bad bitfield packing"); |
| 104 | assert(locNo() == LocNo && "location truncation"); |
| 105 | } |
| 106 | |
| 107 | DbgValueLocation() : LocNo(0), WasIndirect(0) {} |
| 108 | |
| 109 | unsigned locNo() const { |
| 110 | // Fix up the undef location number, which gets truncated. |
| 111 | return LocNo == INT_MAX ? UndefLocNo : LocNo; |
| 112 | } |
| 113 | bool wasIndirect() const { return WasIndirect; } |
| 114 | bool isUndef() const { return locNo() == UndefLocNo; } |
| 115 | |
| 116 | DbgValueLocation changeLocNo(unsigned NewLocNo) const { |
| 117 | return DbgValueLocation(NewLocNo, WasIndirect); |
| 118 | } |
| 119 | |
Reid Kleckner | b4569de7 | 2017-10-03 18:30:11 +0000 | [diff] [blame] | 120 | friend inline bool operator==(const DbgValueLocation &LHS, |
| 121 | const DbgValueLocation &RHS) { |
| 122 | return LHS.LocNo == RHS.LocNo && LHS.WasIndirect == RHS.WasIndirect; |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 123 | } |
Reid Kleckner | b4569de7 | 2017-10-03 18:30:11 +0000 | [diff] [blame] | 124 | |
| 125 | friend inline bool operator!=(const DbgValueLocation &LHS, |
| 126 | const DbgValueLocation &RHS) { |
| 127 | return !(LHS == RHS); |
| 128 | } |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 129 | |
| 130 | private: |
| 131 | unsigned LocNo : 31; |
| 132 | unsigned WasIndirect : 1; |
| 133 | }; |
| 134 | |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 135 | /// LocMap - Map of where a user value is live, and its location. |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 136 | using LocMap = IntervalMap<SlotIndex, DbgValueLocation, 4>; |
Eugene Zelenko | 5df3d89 | 2017-08-24 21:21:39 +0000 | [diff] [blame] | 137 | |
| 138 | namespace { |
| 139 | |
| 140 | class LDVImpl; |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 141 | |
| 142 | /// UserValue - A user value is a part of a debug info user variable. |
| 143 | /// |
| 144 | /// A DBG_VALUE instruction notes that (a sub-register of) a virtual register |
| 145 | /// holds part of a user variable. The part is identified by a byte offset. |
| 146 | /// |
| 147 | /// UserValues are grouped into equivalence classes for easier searching. Two |
| 148 | /// user values are related if they refer to the same variable, or if they are |
| 149 | /// held by the same virtual register. The equivalence class is the transitive |
| 150 | /// closure of that relation. |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 151 | class UserValue { |
Reid Kleckner | 4e04028 | 2017-09-20 18:19:08 +0000 | [diff] [blame] | 152 | const DILocalVariable *Variable; ///< The debug info variable we are part of. |
| 153 | const DIExpression *Expression; ///< Any complex address expression. |
Devang Patel | 26ffa01 | 2011-02-04 01:43:25 +0000 | [diff] [blame] | 154 | DebugLoc dl; ///< The debug location for the variable. This is |
| 155 | ///< used by dwarf writer to find lexical scope. |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 156 | UserValue *leader; ///< Equivalence class leader. |
Eugene Zelenko | 5df3d89 | 2017-08-24 21:21:39 +0000 | [diff] [blame] | 157 | UserValue *next = nullptr; ///< Next value in equivalence class, or null. |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 158 | |
| 159 | /// Numbered locations referenced by locmap. |
Jakob Stoklund Olesen | 9adf5e0 | 2011-01-09 05:33:21 +0000 | [diff] [blame] | 160 | SmallVector<MachineOperand, 4> locations; |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 161 | |
| 162 | /// Map of slot indices where this value is live. |
| 163 | LocMap locInts; |
| 164 | |
Robert Lougher | 10f740d | 2017-08-03 11:54:02 +0000 | [diff] [blame] | 165 | /// Set of interval start indexes that have been trimmed to the |
| 166 | /// lexical scope. |
| 167 | SmallSet<SlotIndex, 2> trimmedDefs; |
| 168 | |
Jakob Stoklund Olesen | afc2bc2 | 2010-12-03 21:47:10 +0000 | [diff] [blame] | 169 | /// insertDebugValue - Insert a DBG_VALUE into MBB at Idx for LocNo. |
Karl-Johan Karlsson | 8d8d201 | 2017-10-05 08:37:31 +0000 | [diff] [blame] | 170 | void insertDebugValue(MachineBasicBlock *MBB, SlotIndex StartIdx, |
| 171 | SlotIndex StopIdx, |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 172 | DbgValueLocation Loc, bool Spilled, LiveIntervals &LIS, |
Karl-Johan Karlsson | 8d8d201 | 2017-10-05 08:37:31 +0000 | [diff] [blame] | 173 | const TargetInstrInfo &TII, |
| 174 | const TargetRegisterInfo &TRI); |
Jakob Stoklund Olesen | afc2bc2 | 2010-12-03 21:47:10 +0000 | [diff] [blame] | 175 | |
Jakob Stoklund Olesen | f8da028 | 2011-05-06 18:00:02 +0000 | [diff] [blame] | 176 | /// splitLocation - Replace OldLocNo ranges with NewRegs ranges where NewRegs |
| 177 | /// is live. Returns true if any changes were made. |
Mark Lacey | f9ea885 | 2013-08-14 23:50:04 +0000 | [diff] [blame] | 178 | bool splitLocation(unsigned OldLocNo, ArrayRef<unsigned> NewRegs, |
| 179 | LiveIntervals &LIS); |
Jakob Stoklund Olesen | f8da028 | 2011-05-06 18:00:02 +0000 | [diff] [blame] | 180 | |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 181 | public: |
| 182 | /// UserValue - Create a new UserValue. |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 183 | UserValue(const DILocalVariable *var, const DIExpression *expr, DebugLoc L, |
| 184 | LocMap::Allocator &alloc) |
| 185 | : Variable(var), Expression(expr), dl(std::move(L)), leader(this), |
| 186 | locInts(alloc) {} |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 187 | |
| 188 | /// getLeader - Get the leader of this value's equivalence class. |
| 189 | UserValue *getLeader() { |
| 190 | UserValue *l = leader; |
| 191 | while (l != l->leader) |
| 192 | l = l->leader; |
| 193 | return leader = l; |
| 194 | } |
| 195 | |
| 196 | /// getNext - Return the next UserValue in the equivalence class. |
| 197 | UserValue *getNext() const { return next; } |
| 198 | |
Devang Patel | 338e432 | 2011-07-06 23:09:51 +0000 | [diff] [blame] | 199 | /// match - Does this UserValue match the parameters? |
Reid Kleckner | 4e04028 | 2017-09-20 18:19:08 +0000 | [diff] [blame] | 200 | bool match(const DILocalVariable *Var, const DIExpression *Expr, |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 201 | const DILocation *IA) const { |
| 202 | // FIXME: The fragment should be part of the equivalence class, but not |
| 203 | // other things in the expression like stack values. |
| 204 | return Var == Variable && Expr == Expression && dl->getInlinedAt() == IA; |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | /// merge - Merge equivalence classes. |
| 208 | static UserValue *merge(UserValue *L1, UserValue *L2) { |
| 209 | L2 = L2->getLeader(); |
| 210 | if (!L1) |
| 211 | return L2; |
| 212 | L1 = L1->getLeader(); |
| 213 | if (L1 == L2) |
| 214 | return L1; |
| 215 | // Splice L2 before L1's members. |
| 216 | UserValue *End = L2; |
Richard Trieu | 7a08381 | 2016-02-18 22:09:30 +0000 | [diff] [blame] | 217 | while (End->next) { |
| 218 | End->leader = L1; |
| 219 | End = End->next; |
| 220 | } |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 221 | End->leader = L1; |
| 222 | End->next = L1->next; |
| 223 | L1->next = L2; |
| 224 | return L1; |
| 225 | } |
| 226 | |
Mikael Holmen | 57b33f6 | 2018-06-21 07:02:46 +0000 | [diff] [blame] | 227 | /// Return the location number that matches Loc. |
| 228 | /// |
| 229 | /// For undef values we always return location number UndefLocNo without |
| 230 | /// inserting anything in locations. Since locations is a vector and the |
| 231 | /// location number is the position in the vector and UndefLocNo is ~0, |
| 232 | /// we would need a very big vector to put the value at the right position. |
Jakob Stoklund Olesen | 9adf5e0 | 2011-01-09 05:33:21 +0000 | [diff] [blame] | 233 | unsigned getLocationNo(const MachineOperand &LocMO) { |
Jakob Stoklund Olesen | 816f5f4 | 2011-03-18 21:42:19 +0000 | [diff] [blame] | 234 | if (LocMO.isReg()) { |
| 235 | if (LocMO.getReg() == 0) |
Reid Kleckner | eed0973 | 2017-09-15 22:08:50 +0000 | [diff] [blame] | 236 | return UndefLocNo; |
Jakob Stoklund Olesen | 816f5f4 | 2011-03-18 21:42:19 +0000 | [diff] [blame] | 237 | // For register locations we dont care about use/def and other flags. |
| 238 | for (unsigned i = 0, e = locations.size(); i != e; ++i) |
| 239 | if (locations[i].isReg() && |
| 240 | locations[i].getReg() == LocMO.getReg() && |
| 241 | locations[i].getSubReg() == LocMO.getSubReg()) |
| 242 | return i; |
| 243 | } else |
| 244 | for (unsigned i = 0, e = locations.size(); i != e; ++i) |
| 245 | if (LocMO.isIdenticalTo(locations[i])) |
| 246 | return i; |
Jakob Stoklund Olesen | 9adf5e0 | 2011-01-09 05:33:21 +0000 | [diff] [blame] | 247 | locations.push_back(LocMO); |
| 248 | // We are storing a MachineOperand outside a MachineInstr. |
| 249 | locations.back().clearParent(); |
Jakob Stoklund Olesen | 816f5f4 | 2011-03-18 21:42:19 +0000 | [diff] [blame] | 250 | // Don't store def operands. |
Geoff Berry | b3d126d | 2017-12-29 21:01:09 +0000 | [diff] [blame] | 251 | if (locations.back().isReg()) { |
| 252 | if (locations.back().isDef()) |
| 253 | locations.back().setIsDead(false); |
Jakob Stoklund Olesen | 816f5f4 | 2011-03-18 21:42:19 +0000 | [diff] [blame] | 254 | locations.back().setIsUse(); |
Geoff Berry | b3d126d | 2017-12-29 21:01:09 +0000 | [diff] [blame] | 255 | } |
Jakob Stoklund Olesen | 9adf5e0 | 2011-01-09 05:33:21 +0000 | [diff] [blame] | 256 | return locations.size() - 1; |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 257 | } |
| 258 | |
Jakob Stoklund Olesen | 816f5f4 | 2011-03-18 21:42:19 +0000 | [diff] [blame] | 259 | /// mapVirtRegs - Ensure that all virtual register locations are mapped. |
| 260 | void mapVirtRegs(LDVImpl *LDV); |
| 261 | |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 262 | /// addDef - Add a definition point to this value. |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 263 | void addDef(SlotIndex Idx, const MachineOperand &LocMO, bool IsIndirect) { |
| 264 | DbgValueLocation Loc(getLocationNo(LocMO), IsIndirect); |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 265 | // Add a singular (Idx,Idx) -> Loc mapping. |
| 266 | LocMap::iterator I = locInts.find(Idx); |
| 267 | if (!I.valid() || I.start() != Idx) |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 268 | I.insert(Idx, Idx.getNextSlot(), Loc); |
Jakob Stoklund Olesen | 2539af6 | 2011-08-03 23:44:31 +0000 | [diff] [blame] | 269 | else |
| 270 | // A later DBG_VALUE at the same SlotIndex overrides the old location. |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 271 | I.setValue(Loc); |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 272 | } |
| 273 | |
Adrian Prantl | f8d10ce | 2016-09-28 21:34:23 +0000 | [diff] [blame] | 274 | /// extendDef - Extend the current definition as far as possible down. |
| 275 | /// Stop when meeting an existing def or when leaving the live |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 276 | /// range of VNI. |
Jakob Stoklund Olesen | 816f5f4 | 2011-03-18 21:42:19 +0000 | [diff] [blame] | 277 | /// End points where VNI is no longer live are added to Kills. |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 278 | /// @param Idx Starting point for the definition. |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 279 | /// @param Loc Location number to propagate. |
Matthias Braun | 34e1be9 | 2013-10-10 21:29:02 +0000 | [diff] [blame] | 280 | /// @param LR Restrict liveness to where LR has the value VNI. May be null. |
| 281 | /// @param VNI When LR is not null, this is the value to restrict to. |
Jakob Stoklund Olesen | 816f5f4 | 2011-03-18 21:42:19 +0000 | [diff] [blame] | 282 | /// @param Kills Append end points of VNI's live range to Kills. |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 283 | /// @param LIS Live intervals analysis. |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 284 | void extendDef(SlotIndex Idx, DbgValueLocation Loc, |
Matthias Braun | 34e1be9 | 2013-10-10 21:29:02 +0000 | [diff] [blame] | 285 | LiveRange *LR, const VNInfo *VNI, |
Jakob Stoklund Olesen | 816f5f4 | 2011-03-18 21:42:19 +0000 | [diff] [blame] | 286 | SmallVectorImpl<SlotIndex> *Kills, |
Adrian Prantl | f8d10ce | 2016-09-28 21:34:23 +0000 | [diff] [blame] | 287 | LiveIntervals &LIS); |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 288 | |
Jakob Stoklund Olesen | 816f5f4 | 2011-03-18 21:42:19 +0000 | [diff] [blame] | 289 | /// addDefsFromCopies - The value in LI/LocNo may be copies to other |
| 290 | /// registers. Determine if any of the copies are available at the kill |
| 291 | /// points, and add defs if possible. |
| 292 | /// @param LI Scan for copies of the value in LI->reg. |
| 293 | /// @param LocNo Location number of LI->reg. |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 294 | /// @param WasIndirect Indicates if the original use of LI->reg was indirect |
Jakob Stoklund Olesen | 816f5f4 | 2011-03-18 21:42:19 +0000 | [diff] [blame] | 295 | /// @param Kills Points where the range of LocNo could be extended. |
| 296 | /// @param NewDefs Append (Idx, LocNo) of inserted defs here. |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 297 | void addDefsFromCopies( |
| 298 | LiveInterval *LI, unsigned LocNo, bool WasIndirect, |
| 299 | const SmallVectorImpl<SlotIndex> &Kills, |
| 300 | SmallVectorImpl<std::pair<SlotIndex, DbgValueLocation>> &NewDefs, |
| 301 | MachineRegisterInfo &MRI, LiveIntervals &LIS); |
Jakob Stoklund Olesen | 816f5f4 | 2011-03-18 21:42:19 +0000 | [diff] [blame] | 302 | |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 303 | /// computeIntervals - Compute the live intervals of all locations after |
| 304 | /// collecting all their def points. |
Jakob Stoklund Olesen | 3244963 | 2012-06-22 17:15:32 +0000 | [diff] [blame] | 305 | void computeIntervals(MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI, |
Robert Lougher | 10f740d | 2017-08-03 11:54:02 +0000 | [diff] [blame] | 306 | LiveIntervals &LIS, LexicalScopes &LS); |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 307 | |
Jakob Stoklund Olesen | f8da028 | 2011-05-06 18:00:02 +0000 | [diff] [blame] | 308 | /// splitRegister - Replace OldReg ranges with NewRegs ranges where NewRegs is |
| 309 | /// live. Returns true if any changes were made. |
Fangrui Song | cb0bab8 | 2018-07-16 18:51:40 +0000 | [diff] [blame] | 310 | bool splitRegister(unsigned OldReg, ArrayRef<unsigned> NewRegs, |
Mark Lacey | f9ea885 | 2013-08-14 23:50:04 +0000 | [diff] [blame] | 311 | LiveIntervals &LIS); |
Jakob Stoklund Olesen | f8da028 | 2011-05-06 18:00:02 +0000 | [diff] [blame] | 312 | |
Jakob Stoklund Olesen | afc2bc2 | 2010-12-03 21:47:10 +0000 | [diff] [blame] | 313 | /// rewriteLocations - Rewrite virtual register locations according to the |
Reid Kleckner | 4e04028 | 2017-09-20 18:19:08 +0000 | [diff] [blame] | 314 | /// provided virtual register map. Record which locations were spilled. |
| 315 | void rewriteLocations(VirtRegMap &VRM, const TargetRegisterInfo &TRI, |
| 316 | BitVector &SpilledLocations); |
Jakob Stoklund Olesen | afc2bc2 | 2010-12-03 21:47:10 +0000 | [diff] [blame] | 317 | |
Eric Christopher | bc67170 | 2013-02-13 02:29:18 +0000 | [diff] [blame] | 318 | /// emitDebugValues - Recreate DBG_VALUE instruction from data structures. |
Reid Kleckner | 4e04028 | 2017-09-20 18:19:08 +0000 | [diff] [blame] | 319 | void emitDebugValues(VirtRegMap *VRM, LiveIntervals &LIS, |
Karl-Johan Karlsson | 8d8d201 | 2017-10-05 08:37:31 +0000 | [diff] [blame] | 320 | const TargetInstrInfo &TII, |
| 321 | const TargetRegisterInfo &TRI, |
Reid Kleckner | 4e04028 | 2017-09-20 18:19:08 +0000 | [diff] [blame] | 322 | const BitVector &SpilledLocations); |
Jakob Stoklund Olesen | afc2bc2 | 2010-12-03 21:47:10 +0000 | [diff] [blame] | 323 | |
Devang Patel | f9e2ae9 | 2011-09-13 18:40:53 +0000 | [diff] [blame] | 324 | /// getDebugLoc - Return DebugLoc of this UserValue. |
| 325 | DebugLoc getDebugLoc() { return dl;} |
Eugene Zelenko | 5df3d89 | 2017-08-24 21:21:39 +0000 | [diff] [blame] | 326 | |
Eric Christopher | 1cdefae | 2015-02-27 00:11:34 +0000 | [diff] [blame] | 327 | void print(raw_ostream &, const TargetRegisterInfo *); |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 328 | }; |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 329 | |
| 330 | /// LDVImpl - Implementation of the LiveDebugVariables pass. |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 331 | class LDVImpl { |
| 332 | LiveDebugVariables &pass; |
| 333 | LocMap::Allocator allocator; |
Eugene Zelenko | 5df3d89 | 2017-08-24 21:21:39 +0000 | [diff] [blame] | 334 | MachineFunction *MF = nullptr; |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 335 | LiveIntervals *LIS; |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 336 | const TargetRegisterInfo *TRI; |
| 337 | |
Manman Ren | 7a4c8a7 | 2013-02-13 20:23:48 +0000 | [diff] [blame] | 338 | /// Whether emitDebugValues is called. |
Eugene Zelenko | 5df3d89 | 2017-08-24 21:21:39 +0000 | [diff] [blame] | 339 | bool EmitDone = false; |
| 340 | |
Manman Ren | 7a4c8a7 | 2013-02-13 20:23:48 +0000 | [diff] [blame] | 341 | /// Whether the machine function is modified during the pass. |
Eugene Zelenko | 5df3d89 | 2017-08-24 21:21:39 +0000 | [diff] [blame] | 342 | bool ModifiedMF = false; |
Manman Ren | 7a4c8a7 | 2013-02-13 20:23:48 +0000 | [diff] [blame] | 343 | |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 344 | /// userValues - All allocated UserValue instances. |
David Blaikie | 2b1dfa7 | 2014-04-21 20:37:07 +0000 | [diff] [blame] | 345 | SmallVector<std::unique_ptr<UserValue>, 8> userValues; |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 346 | |
| 347 | /// Map virtual register to eq class leader. |
Eugene Zelenko | 5df3d89 | 2017-08-24 21:21:39 +0000 | [diff] [blame] | 348 | using VRMap = DenseMap<unsigned, UserValue *>; |
Jakob Stoklund Olesen | 922e1fa | 2010-12-03 22:25:09 +0000 | [diff] [blame] | 349 | VRMap virtRegToEqClass; |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 350 | |
| 351 | /// Map user variable to eq class leader. |
Reid Kleckner | 4e04028 | 2017-09-20 18:19:08 +0000 | [diff] [blame] | 352 | using UVMap = DenseMap<const DILocalVariable *, UserValue *>; |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 353 | UVMap userVarMap; |
| 354 | |
| 355 | /// getUserValue - Find or create a UserValue. |
Reid Kleckner | 4e04028 | 2017-09-20 18:19:08 +0000 | [diff] [blame] | 356 | UserValue *getUserValue(const DILocalVariable *Var, const DIExpression *Expr, |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 357 | const DebugLoc &DL); |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 358 | |
Jakob Stoklund Olesen | 9ec2011 | 2010-12-02 18:15:44 +0000 | [diff] [blame] | 359 | /// lookupVirtReg - Find the EC leader for VirtReg or null. |
| 360 | UserValue *lookupVirtReg(unsigned VirtReg); |
| 361 | |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 362 | /// handleDebugValue - Add DBG_VALUE instruction to our maps. |
| 363 | /// @param MI DBG_VALUE instruction |
| 364 | /// @param Idx Last valid SLotIndex before instruction. |
| 365 | /// @return True if the DBG_VALUE instruction should be deleted. |
Duncan P. N. Exon Smith | fb612ac | 2016-06-30 23:13:38 +0000 | [diff] [blame] | 366 | bool handleDebugValue(MachineInstr &MI, SlotIndex Idx); |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 367 | |
| 368 | /// collectDebugValues - Collect and erase all DBG_VALUE instructions, adding |
| 369 | /// a UserValue def for each instruction. |
| 370 | /// @param mf MachineFunction to be scanned. |
| 371 | /// @return True if any debug values were found. |
| 372 | bool collectDebugValues(MachineFunction &mf); |
| 373 | |
| 374 | /// computeIntervals - Compute the live intervals of all user values after |
| 375 | /// collecting all their def points. |
| 376 | void computeIntervals(); |
| 377 | |
| 378 | public: |
Eugene Zelenko | 5df3d89 | 2017-08-24 21:21:39 +0000 | [diff] [blame] | 379 | LDVImpl(LiveDebugVariables *ps) : pass(*ps) {} |
| 380 | |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 381 | bool runOnMachineFunction(MachineFunction &mf); |
| 382 | |
Manman Ren | 7a4c8a7 | 2013-02-13 20:23:48 +0000 | [diff] [blame] | 383 | /// clear - Release all memory. |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 384 | void clear() { |
David Blaikie | 2f04011 | 2014-07-25 16:10:16 +0000 | [diff] [blame] | 385 | MF = nullptr; |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 386 | userValues.clear(); |
Jakob Stoklund Olesen | 922e1fa | 2010-12-03 22:25:09 +0000 | [diff] [blame] | 387 | virtRegToEqClass.clear(); |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 388 | userVarMap.clear(); |
Manman Ren | 7a4c8a7 | 2013-02-13 20:23:48 +0000 | [diff] [blame] | 389 | // Make sure we call emitDebugValues if the machine function was modified. |
| 390 | assert((!ModifiedMF || EmitDone) && |
| 391 | "Dbg values are not emitted in LDV"); |
| 392 | EmitDone = false; |
| 393 | ModifiedMF = false; |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 394 | } |
| 395 | |
Jakob Stoklund Olesen | 816f5f4 | 2011-03-18 21:42:19 +0000 | [diff] [blame] | 396 | /// mapVirtReg - Map virtual register to an equivalence class. |
| 397 | void mapVirtReg(unsigned VirtReg, UserValue *EC); |
| 398 | |
Jakob Stoklund Olesen | f8da028 | 2011-05-06 18:00:02 +0000 | [diff] [blame] | 399 | /// splitRegister - Replace all references to OldReg with NewRegs. |
Mark Lacey | f9ea885 | 2013-08-14 23:50:04 +0000 | [diff] [blame] | 400 | void splitRegister(unsigned OldReg, ArrayRef<unsigned> NewRegs); |
Jakob Stoklund Olesen | f8da028 | 2011-05-06 18:00:02 +0000 | [diff] [blame] | 401 | |
Eric Christopher | bc67170 | 2013-02-13 02:29:18 +0000 | [diff] [blame] | 402 | /// emitDebugValues - Recreate DBG_VALUE instruction from data structures. |
Jakob Stoklund Olesen | afc2bc2 | 2010-12-03 21:47:10 +0000 | [diff] [blame] | 403 | void emitDebugValues(VirtRegMap *VRM); |
| 404 | |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 405 | void print(raw_ostream&); |
| 406 | }; |
Eugene Zelenko | 5df3d89 | 2017-08-24 21:21:39 +0000 | [diff] [blame] | 407 | |
| 408 | } // end anonymous namespace |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 409 | |
Aaron Ballman | 615eb47 | 2017-10-15 14:32:27 +0000 | [diff] [blame] | 410 | #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) |
Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 411 | static void printDebugLoc(const DebugLoc &DL, raw_ostream &CommentOS, |
Duncan P. N. Exon Smith | 32e7f28 | 2015-04-14 02:09:32 +0000 | [diff] [blame] | 412 | const LLVMContext &Ctx) { |
| 413 | if (!DL) |
| 414 | return; |
| 415 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 416 | auto *Scope = cast<DIScope>(DL.getScope()); |
Duncan P. N. Exon Smith | 32e7f28 | 2015-04-14 02:09:32 +0000 | [diff] [blame] | 417 | // Omit the directory, because it's likely to be long and uninteresting. |
Duncan P. N. Exon Smith | b273d06 | 2015-04-16 01:37:00 +0000 | [diff] [blame] | 418 | CommentOS << Scope->getFilename(); |
Duncan P. N. Exon Smith | 32e7f28 | 2015-04-14 02:09:32 +0000 | [diff] [blame] | 419 | CommentOS << ':' << DL.getLine(); |
| 420 | if (DL.getCol() != 0) |
| 421 | CommentOS << ':' << DL.getCol(); |
| 422 | |
| 423 | DebugLoc InlinedAtDL = DL.getInlinedAt(); |
| 424 | if (!InlinedAtDL) |
| 425 | return; |
| 426 | |
| 427 | CommentOS << " @[ "; |
| 428 | printDebugLoc(InlinedAtDL, CommentOS, Ctx); |
| 429 | CommentOS << " ]"; |
| 430 | } |
| 431 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 432 | static void printExtendedName(raw_ostream &OS, const DILocalVariable *V, |
| 433 | const DILocation *DL) { |
Duncan P. N. Exon Smith | 32e7f28 | 2015-04-14 02:09:32 +0000 | [diff] [blame] | 434 | const LLVMContext &Ctx = V->getContext(); |
| 435 | StringRef Res = V->getName(); |
| 436 | if (!Res.empty()) |
| 437 | OS << Res << "," << V->getLine(); |
Duncan P. N. Exon Smith | 62e0f45 | 2015-04-15 22:29:27 +0000 | [diff] [blame] | 438 | if (auto *InlinedAt = DL->getInlinedAt()) { |
Duncan P. N. Exon Smith | 32e7f28 | 2015-04-14 02:09:32 +0000 | [diff] [blame] | 439 | if (DebugLoc InlinedAtDL = InlinedAt) { |
| 440 | OS << " @["; |
| 441 | printDebugLoc(InlinedAtDL, OS, Ctx); |
| 442 | OS << "]"; |
| 443 | } |
| 444 | } |
| 445 | } |
| 446 | |
Eric Christopher | 1cdefae | 2015-02-27 00:11:34 +0000 | [diff] [blame] | 447 | void UserValue::print(raw_ostream &OS, const TargetRegisterInfo *TRI) { |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 448 | auto *DV = cast<DILocalVariable>(Variable); |
Frederic Riss | e6bb187 | 2014-08-07 20:04:00 +0000 | [diff] [blame] | 449 | OS << "!\""; |
Duncan P. N. Exon Smith | 62e0f45 | 2015-04-15 22:29:27 +0000 | [diff] [blame] | 450 | printExtendedName(OS, DV, dl); |
Duncan P. N. Exon Smith | 32e7f28 | 2015-04-14 02:09:32 +0000 | [diff] [blame] | 451 | |
Devang Patel | 6c1ed31 | 2011-08-09 01:03:35 +0000 | [diff] [blame] | 452 | OS << "\"\t"; |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 453 | for (LocMap::const_iterator I = locInts.begin(); I.valid(); ++I) { |
| 454 | OS << " [" << I.start() << ';' << I.stop() << "):"; |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 455 | if (I.value().isUndef()) |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 456 | OS << "undef"; |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 457 | else { |
| 458 | OS << I.value().locNo(); |
| 459 | if (I.value().wasIndirect()) |
| 460 | OS << " ind"; |
| 461 | } |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 462 | } |
Jakob Stoklund Olesen | c86fe05 | 2011-05-06 17:59:59 +0000 | [diff] [blame] | 463 | for (unsigned i = 0, e = locations.size(); i != e; ++i) { |
| 464 | OS << " Loc" << i << '='; |
Eric Christopher | 1cdefae | 2015-02-27 00:11:34 +0000 | [diff] [blame] | 465 | locations[i].print(OS, TRI); |
Jakob Stoklund Olesen | c86fe05 | 2011-05-06 17:59:59 +0000 | [diff] [blame] | 466 | } |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 467 | OS << '\n'; |
| 468 | } |
| 469 | |
| 470 | void LDVImpl::print(raw_ostream &OS) { |
| 471 | OS << "********** DEBUG VARIABLES **********\n"; |
| 472 | for (unsigned i = 0, e = userValues.size(); i != e; ++i) |
Eric Christopher | 1cdefae | 2015-02-27 00:11:34 +0000 | [diff] [blame] | 473 | userValues[i]->print(OS, TRI); |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 474 | } |
Florian Hahn | 6b3216a | 2017-07-31 10:07:49 +0000 | [diff] [blame] | 475 | #endif |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 476 | |
Jakob Stoklund Olesen | 816f5f4 | 2011-03-18 21:42:19 +0000 | [diff] [blame] | 477 | void UserValue::mapVirtRegs(LDVImpl *LDV) { |
| 478 | for (unsigned i = 0, e = locations.size(); i != e; ++i) |
| 479 | if (locations[i].isReg() && |
| 480 | TargetRegisterInfo::isVirtualRegister(locations[i].getReg())) |
| 481 | LDV->mapVirtReg(locations[i].getReg(), this); |
| 482 | } |
| 483 | |
Reid Kleckner | 4e04028 | 2017-09-20 18:19:08 +0000 | [diff] [blame] | 484 | UserValue *LDVImpl::getUserValue(const DILocalVariable *Var, |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 485 | const DIExpression *Expr, const DebugLoc &DL) { |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 486 | UserValue *&Leader = userVarMap[Var]; |
| 487 | if (Leader) { |
| 488 | UserValue *UV = Leader->getLeader(); |
| 489 | Leader = UV; |
| 490 | for (; UV; UV = UV->getNext()) |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 491 | if (UV->match(Var, Expr, DL->getInlinedAt())) |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 492 | return UV; |
| 493 | } |
| 494 | |
David Blaikie | 2b1dfa7 | 2014-04-21 20:37:07 +0000 | [diff] [blame] | 495 | userValues.push_back( |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 496 | llvm::make_unique<UserValue>(Var, Expr, DL, allocator)); |
David Blaikie | 2b1dfa7 | 2014-04-21 20:37:07 +0000 | [diff] [blame] | 497 | UserValue *UV = userValues.back().get(); |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 498 | Leader = UserValue::merge(Leader, UV); |
| 499 | return UV; |
| 500 | } |
| 501 | |
| 502 | void LDVImpl::mapVirtReg(unsigned VirtReg, UserValue *EC) { |
| 503 | assert(TargetRegisterInfo::isVirtualRegister(VirtReg) && "Only map VirtRegs"); |
Jakob Stoklund Olesen | 922e1fa | 2010-12-03 22:25:09 +0000 | [diff] [blame] | 504 | UserValue *&Leader = virtRegToEqClass[VirtReg]; |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 505 | Leader = UserValue::merge(Leader, EC); |
| 506 | } |
| 507 | |
Jakob Stoklund Olesen | 9ec2011 | 2010-12-02 18:15:44 +0000 | [diff] [blame] | 508 | UserValue *LDVImpl::lookupVirtReg(unsigned VirtReg) { |
Jakob Stoklund Olesen | 922e1fa | 2010-12-03 22:25:09 +0000 | [diff] [blame] | 509 | if (UserValue *UV = virtRegToEqClass.lookup(VirtReg)) |
Jakob Stoklund Olesen | 9ec2011 | 2010-12-02 18:15:44 +0000 | [diff] [blame] | 510 | return UV->getLeader(); |
Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 511 | return nullptr; |
Jakob Stoklund Olesen | 9ec2011 | 2010-12-02 18:15:44 +0000 | [diff] [blame] | 512 | } |
| 513 | |
Duncan P. N. Exon Smith | fb612ac | 2016-06-30 23:13:38 +0000 | [diff] [blame] | 514 | bool LDVImpl::handleDebugValue(MachineInstr &MI, SlotIndex Idx) { |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 515 | // DBG_VALUE loc, offset, variable |
Duncan P. N. Exon Smith | fb612ac | 2016-06-30 23:13:38 +0000 | [diff] [blame] | 516 | if (MI.getNumOperands() != 4 || |
| 517 | !(MI.getOperand(1).isReg() || MI.getOperand(1).isImm()) || |
| 518 | !MI.getOperand(2).isMetadata()) { |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 519 | LLVM_DEBUG(dbgs() << "Can't handle " << MI); |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 520 | return false; |
| 521 | } |
| 522 | |
Bjorn Pettersson | bdf0c00 | 2018-03-06 08:47:07 +0000 | [diff] [blame] | 523 | // Detect invalid DBG_VALUE instructions, with a debug-use of a virtual |
| 524 | // register that hasn't been defined yet. If we do not remove those here, then |
| 525 | // the re-insertion of the DBG_VALUE instruction after register allocation |
| 526 | // will be incorrect. |
| 527 | // TODO: If earlier passes are corrected to generate sane debug information |
| 528 | // (and if the machine verifier is improved to catch this), then these checks |
| 529 | // could be removed or replaced by asserts. |
| 530 | bool Discard = false; |
| 531 | if (MI.getOperand(0).isReg() && |
| 532 | TargetRegisterInfo::isVirtualRegister(MI.getOperand(0).getReg())) { |
| 533 | const unsigned Reg = MI.getOperand(0).getReg(); |
| 534 | if (!LIS->hasInterval(Reg)) { |
| 535 | // The DBG_VALUE is described by a virtual register that does not have a |
| 536 | // live interval. Discard the DBG_VALUE. |
| 537 | Discard = true; |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 538 | LLVM_DEBUG(dbgs() << "Discarding debug info (no LIS interval): " << Idx |
| 539 | << " " << MI); |
Bjorn Pettersson | bdf0c00 | 2018-03-06 08:47:07 +0000 | [diff] [blame] | 540 | } else { |
| 541 | // The DBG_VALUE is only valid if either Reg is live out from Idx, or Reg |
| 542 | // is defined dead at Idx (where Idx is the slot index for the instruction |
| 543 | // preceeding the DBG_VALUE). |
| 544 | const LiveInterval &LI = LIS->getInterval(Reg); |
| 545 | LiveQueryResult LRQ = LI.Query(Idx); |
| 546 | if (!LRQ.valueOutOrDead()) { |
| 547 | // We have found a DBG_VALUE with the value in a virtual register that |
| 548 | // is not live. Discard the DBG_VALUE. |
| 549 | Discard = true; |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 550 | LLVM_DEBUG(dbgs() << "Discarding debug info (reg not live): " << Idx |
| 551 | << " " << MI); |
Bjorn Pettersson | bdf0c00 | 2018-03-06 08:47:07 +0000 | [diff] [blame] | 552 | } |
| 553 | } |
| 554 | } |
| 555 | |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 556 | // Get or create the UserValue for (variable,offset) here. |
Reid Kleckner | 4e04028 | 2017-09-20 18:19:08 +0000 | [diff] [blame] | 557 | bool IsIndirect = MI.getOperand(1).isImm(); |
Adrian Prantl | b2811e5 | 2017-07-28 23:06:50 +0000 | [diff] [blame] | 558 | if (IsIndirect) |
| 559 | assert(MI.getOperand(1).getImm() == 0 && "DBG_VALUE with nonzero offset"); |
Reid Kleckner | 4e04028 | 2017-09-20 18:19:08 +0000 | [diff] [blame] | 560 | const DILocalVariable *Var = MI.getDebugVariable(); |
| 561 | const DIExpression *Expr = MI.getDebugExpression(); |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 562 | UserValue *UV = |
| 563 | getUserValue(Var, Expr, MI.getDebugLoc()); |
Bjorn Pettersson | bdf0c00 | 2018-03-06 08:47:07 +0000 | [diff] [blame] | 564 | if (!Discard) |
| 565 | UV->addDef(Idx, MI.getOperand(0), IsIndirect); |
Bjorn Pettersson | e0050d7 | 2018-03-06 13:23:28 +0000 | [diff] [blame] | 566 | else { |
| 567 | MachineOperand MO = MachineOperand::CreateReg(0U, false); |
| 568 | MO.setIsDebug(); |
| 569 | UV->addDef(Idx, MO, false); |
| 570 | } |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 571 | return true; |
| 572 | } |
| 573 | |
| 574 | bool LDVImpl::collectDebugValues(MachineFunction &mf) { |
| 575 | bool Changed = false; |
| 576 | for (MachineFunction::iterator MFI = mf.begin(), MFE = mf.end(); MFI != MFE; |
| 577 | ++MFI) { |
Duncan P. N. Exon Smith | 5ae5939 | 2015-10-09 19:13:58 +0000 | [diff] [blame] | 578 | MachineBasicBlock *MBB = &*MFI; |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 579 | for (MachineBasicBlock::iterator MBBI = MBB->begin(), MBBE = MBB->end(); |
| 580 | MBBI != MBBE;) { |
Chandler Carruth | 8505dcf | 2018-08-23 05:39:02 +0000 | [diff] [blame] | 581 | if (!MBBI->isDebugValue()) { |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 582 | ++MBBI; |
| 583 | continue; |
| 584 | } |
Chandler Carruth | 8505dcf | 2018-08-23 05:39:02 +0000 | [diff] [blame] | 585 | // DBG_VALUE has no slot index, use the previous instruction instead. |
Duncan P. N. Exon Smith | 3ac9cc6 | 2016-02-27 06:40:41 +0000 | [diff] [blame] | 586 | SlotIndex Idx = |
| 587 | MBBI == MBB->begin() |
| 588 | ? LIS->getMBBStartIdx(MBB) |
| 589 | : LIS->getInstructionIndex(*std::prev(MBBI)).getRegSlot(); |
Chandler Carruth | 8505dcf | 2018-08-23 05:39:02 +0000 | [diff] [blame] | 590 | // Handle consecutive DBG_VALUE instructions with the same slot index. |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 591 | do { |
Chandler Carruth | 8505dcf | 2018-08-23 05:39:02 +0000 | [diff] [blame] | 592 | if (handleDebugValue(*MBBI, Idx)) { |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 593 | MBBI = MBB->erase(MBBI); |
| 594 | Changed = true; |
| 595 | } else |
| 596 | ++MBBI; |
Chandler Carruth | 8505dcf | 2018-08-23 05:39:02 +0000 | [diff] [blame] | 597 | } while (MBBI != MBBE && MBBI->isDebugValue()); |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 598 | } |
| 599 | } |
| 600 | return Changed; |
| 601 | } |
| 602 | |
Adrian Prantl | ce85813 | 2015-12-21 20:03:00 +0000 | [diff] [blame] | 603 | /// We only propagate DBG_VALUES locally here. LiveDebugValues performs a |
| 604 | /// data-flow analysis to propagate them beyond basic block boundaries. |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 605 | void UserValue::extendDef(SlotIndex Idx, DbgValueLocation Loc, LiveRange *LR, |
Adrian Prantl | ce85813 | 2015-12-21 20:03:00 +0000 | [diff] [blame] | 606 | const VNInfo *VNI, SmallVectorImpl<SlotIndex> *Kills, |
Adrian Prantl | f8d10ce | 2016-09-28 21:34:23 +0000 | [diff] [blame] | 607 | LiveIntervals &LIS) { |
Adrian Prantl | ce85813 | 2015-12-21 20:03:00 +0000 | [diff] [blame] | 608 | SlotIndex Start = Idx; |
| 609 | MachineBasicBlock *MBB = LIS.getMBBFromIndex(Start); |
| 610 | SlotIndex Stop = LIS.getMBBEndIdx(MBB); |
| 611 | LocMap::iterator I = locInts.find(Start); |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 612 | |
Adrian Prantl | ce85813 | 2015-12-21 20:03:00 +0000 | [diff] [blame] | 613 | // Limit to VNI's live range. |
| 614 | bool ToEnd = true; |
| 615 | if (LR && VNI) { |
| 616 | LiveInterval::Segment *Segment = LR->getSegmentContaining(Start); |
| 617 | if (!Segment || Segment->valno != VNI) { |
| 618 | if (Kills) |
| 619 | Kills->push_back(Start); |
| 620 | return; |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 621 | } |
Richard Trieu | 7a08381 | 2016-02-18 22:09:30 +0000 | [diff] [blame] | 622 | if (Segment->end < Stop) { |
| 623 | Stop = Segment->end; |
| 624 | ToEnd = false; |
| 625 | } |
Adrian Prantl | ce85813 | 2015-12-21 20:03:00 +0000 | [diff] [blame] | 626 | } |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 627 | |
Adrian Prantl | ce85813 | 2015-12-21 20:03:00 +0000 | [diff] [blame] | 628 | // There could already be a short def at Start. |
| 629 | if (I.valid() && I.start() <= Start) { |
| 630 | // Stop when meeting a different location or an already extended interval. |
| 631 | Start = Start.getNextSlot(); |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 632 | if (I.value() != Loc || I.stop() != Start) |
Adrian Prantl | ce85813 | 2015-12-21 20:03:00 +0000 | [diff] [blame] | 633 | return; |
| 634 | // This is a one-slot placeholder. Just skip it. |
| 635 | ++I; |
| 636 | } |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 637 | |
Adrian Prantl | ce85813 | 2015-12-21 20:03:00 +0000 | [diff] [blame] | 638 | // Limited by the next def. |
Richard Trieu | 7a08381 | 2016-02-18 22:09:30 +0000 | [diff] [blame] | 639 | if (I.valid() && I.start() < Stop) { |
| 640 | Stop = I.start(); |
| 641 | ToEnd = false; |
| 642 | } |
Adrian Prantl | ce85813 | 2015-12-21 20:03:00 +0000 | [diff] [blame] | 643 | // Limited by VNI's live range. |
| 644 | else if (!ToEnd && Kills) |
| 645 | Kills->push_back(Stop); |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 646 | |
Adrian Prantl | ce85813 | 2015-12-21 20:03:00 +0000 | [diff] [blame] | 647 | if (Start < Stop) |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 648 | I.insert(Start, Stop, Loc); |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 649 | } |
| 650 | |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 651 | void UserValue::addDefsFromCopies( |
| 652 | LiveInterval *LI, unsigned LocNo, bool WasIndirect, |
| 653 | const SmallVectorImpl<SlotIndex> &Kills, |
| 654 | SmallVectorImpl<std::pair<SlotIndex, DbgValueLocation>> &NewDefs, |
| 655 | MachineRegisterInfo &MRI, LiveIntervals &LIS) { |
Jakob Stoklund Olesen | 816f5f4 | 2011-03-18 21:42:19 +0000 | [diff] [blame] | 656 | if (Kills.empty()) |
| 657 | return; |
| 658 | // Don't track copies from physregs, there are too many uses. |
| 659 | if (!TargetRegisterInfo::isVirtualRegister(LI->reg)) |
| 660 | return; |
| 661 | |
| 662 | // Collect all the (vreg, valno) pairs that are copies of LI. |
| 663 | SmallVector<std::pair<LiveInterval*, const VNInfo*>, 8> CopyValues; |
Owen Anderson | b36376e | 2014-03-17 19:36:09 +0000 | [diff] [blame] | 664 | for (MachineOperand &MO : MRI.use_nodbg_operands(LI->reg)) { |
| 665 | MachineInstr *MI = MO.getParent(); |
Jakob Stoklund Olesen | 816f5f4 | 2011-03-18 21:42:19 +0000 | [diff] [blame] | 666 | // Copies of the full value. |
Owen Anderson | b36376e | 2014-03-17 19:36:09 +0000 | [diff] [blame] | 667 | if (MO.getSubReg() || !MI->isCopy()) |
Jakob Stoklund Olesen | 816f5f4 | 2011-03-18 21:42:19 +0000 | [diff] [blame] | 668 | continue; |
Jakob Stoklund Olesen | 816f5f4 | 2011-03-18 21:42:19 +0000 | [diff] [blame] | 669 | unsigned DstReg = MI->getOperand(0).getReg(); |
| 670 | |
Jakob Stoklund Olesen | ec0ac3c | 2011-03-22 22:33:08 +0000 | [diff] [blame] | 671 | // Don't follow copies to physregs. These are usually setting up call |
| 672 | // arguments, and the argument registers are always call clobbered. We are |
| 673 | // better off in the source register which could be a callee-saved register, |
| 674 | // or it could be spilled. |
| 675 | if (!TargetRegisterInfo::isVirtualRegister(DstReg)) |
| 676 | continue; |
| 677 | |
Jakob Stoklund Olesen | 816f5f4 | 2011-03-18 21:42:19 +0000 | [diff] [blame] | 678 | // Is LocNo extended to reach this copy? If not, another def may be blocking |
| 679 | // it, or we are looking at a wrong value of LI. |
Duncan P. N. Exon Smith | 3ac9cc6 | 2016-02-27 06:40:41 +0000 | [diff] [blame] | 680 | SlotIndex Idx = LIS.getInstructionIndex(*MI); |
Jakob Stoklund Olesen | 90b5e56 | 2011-11-13 20:45:27 +0000 | [diff] [blame] | 681 | LocMap::iterator I = locInts.find(Idx.getRegSlot(true)); |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 682 | if (!I.valid() || I.value().locNo() != LocNo) |
Jakob Stoklund Olesen | 816f5f4 | 2011-03-18 21:42:19 +0000 | [diff] [blame] | 683 | continue; |
| 684 | |
| 685 | if (!LIS.hasInterval(DstReg)) |
| 686 | continue; |
| 687 | LiveInterval *DstLI = &LIS.getInterval(DstReg); |
Jakob Stoklund Olesen | 90b5e56 | 2011-11-13 20:45:27 +0000 | [diff] [blame] | 688 | const VNInfo *DstVNI = DstLI->getVNInfoAt(Idx.getRegSlot()); |
| 689 | assert(DstVNI && DstVNI->def == Idx.getRegSlot() && "Bad copy value"); |
Jakob Stoklund Olesen | 816f5f4 | 2011-03-18 21:42:19 +0000 | [diff] [blame] | 690 | CopyValues.push_back(std::make_pair(DstLI, DstVNI)); |
| 691 | } |
| 692 | |
| 693 | if (CopyValues.empty()) |
| 694 | return; |
| 695 | |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 696 | LLVM_DEBUG(dbgs() << "Got " << CopyValues.size() << " copies of " << *LI |
| 697 | << '\n'); |
Jakob Stoklund Olesen | 816f5f4 | 2011-03-18 21:42:19 +0000 | [diff] [blame] | 698 | |
| 699 | // Try to add defs of the copied values for each kill point. |
| 700 | for (unsigned i = 0, e = Kills.size(); i != e; ++i) { |
| 701 | SlotIndex Idx = Kills[i]; |
| 702 | for (unsigned j = 0, e = CopyValues.size(); j != e; ++j) { |
| 703 | LiveInterval *DstLI = CopyValues[j].first; |
| 704 | const VNInfo *DstVNI = CopyValues[j].second; |
| 705 | if (DstLI->getVNInfoAt(Idx) != DstVNI) |
| 706 | continue; |
| 707 | // Check that there isn't already a def at Idx |
| 708 | LocMap::iterator I = locInts.find(Idx); |
| 709 | if (I.valid() && I.start() <= Idx) |
| 710 | continue; |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 711 | LLVM_DEBUG(dbgs() << "Kill at " << Idx << " covered by valno #" |
| 712 | << DstVNI->id << " in " << *DstLI << '\n'); |
Jakob Stoklund Olesen | 816f5f4 | 2011-03-18 21:42:19 +0000 | [diff] [blame] | 713 | MachineInstr *CopyMI = LIS.getInstructionFromIndex(DstVNI->def); |
| 714 | assert(CopyMI && CopyMI->isCopy() && "Bad copy value"); |
| 715 | unsigned LocNo = getLocationNo(CopyMI->getOperand(0)); |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 716 | DbgValueLocation NewLoc(LocNo, WasIndirect); |
| 717 | I.insert(Idx, Idx.getNextSlot(), NewLoc); |
| 718 | NewDefs.push_back(std::make_pair(Idx, NewLoc)); |
Jakob Stoklund Olesen | 816f5f4 | 2011-03-18 21:42:19 +0000 | [diff] [blame] | 719 | break; |
| 720 | } |
| 721 | } |
| 722 | } |
| 723 | |
Robert Lougher | 10f740d | 2017-08-03 11:54:02 +0000 | [diff] [blame] | 724 | void UserValue::computeIntervals(MachineRegisterInfo &MRI, |
| 725 | const TargetRegisterInfo &TRI, |
| 726 | LiveIntervals &LIS, LexicalScopes &LS) { |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 727 | SmallVector<std::pair<SlotIndex, DbgValueLocation>, 16> Defs; |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 728 | |
| 729 | // Collect all defs to be extended (Skipping undefs). |
| 730 | for (LocMap::const_iterator I = locInts.begin(); I.valid(); ++I) |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 731 | if (!I.value().isUndef()) |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 732 | Defs.push_back(std::make_pair(I.start(), I.value())); |
| 733 | |
Jakob Stoklund Olesen | 816f5f4 | 2011-03-18 21:42:19 +0000 | [diff] [blame] | 734 | // Extend all defs, and possibly add new ones along the way. |
| 735 | for (unsigned i = 0; i != Defs.size(); ++i) { |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 736 | SlotIndex Idx = Defs[i].first; |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 737 | DbgValueLocation Loc = Defs[i].second; |
| 738 | const MachineOperand &LocMO = locations[Loc.locNo()]; |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 739 | |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 740 | if (!LocMO.isReg()) { |
| 741 | extendDef(Idx, Loc, nullptr, nullptr, nullptr, LIS); |
Jakob Stoklund Olesen | 3244963 | 2012-06-22 17:15:32 +0000 | [diff] [blame] | 742 | continue; |
| 743 | } |
| 744 | |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 745 | // Register locations are constrained to where the register value is live. |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 746 | if (TargetRegisterInfo::isVirtualRegister(LocMO.getReg())) { |
Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 747 | LiveInterval *LI = nullptr; |
| 748 | const VNInfo *VNI = nullptr; |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 749 | if (LIS.hasInterval(LocMO.getReg())) { |
| 750 | LI = &LIS.getInterval(LocMO.getReg()); |
Jakob Stoklund Olesen | 48a1647 | 2012-06-22 18:51:35 +0000 | [diff] [blame] | 751 | VNI = LI->getVNInfoAt(Idx); |
| 752 | } |
Jakob Stoklund Olesen | 816f5f4 | 2011-03-18 21:42:19 +0000 | [diff] [blame] | 753 | SmallVector<SlotIndex, 16> Kills; |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 754 | extendDef(Idx, Loc, LI, VNI, &Kills, LIS); |
Bjorn Pettersson | 8483004 | 2018-08-25 10:02:03 +0000 | [diff] [blame^] | 755 | // FIXME: Handle sub-registers in addDefsFromCopies. The problem is that |
| 756 | // if the original location for example is %vreg0:sub_hi, and we find a |
| 757 | // full register copy in addDefsFromCopies (at the moment it only handles |
| 758 | // full register copies), then we must add the sub1 sub-register index to |
| 759 | // the new location. However, that is only possible if the new virtual |
| 760 | // register is of the same regclass (or if there is an equivalent |
| 761 | // sub-register in that regclass). For now, simply skip handling copies if |
| 762 | // a sub-register is involved. |
| 763 | if (LI && !LocMO.getSubReg()) |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 764 | addDefsFromCopies(LI, Loc.locNo(), Loc.wasIndirect(), Kills, Defs, MRI, |
| 765 | LIS); |
Jakob Stoklund Olesen | 3244963 | 2012-06-22 17:15:32 +0000 | [diff] [blame] | 766 | continue; |
| 767 | } |
| 768 | |
Bjorn Pettersson | 715a5ef | 2017-09-28 13:10:06 +0000 | [diff] [blame] | 769 | // For physregs, we only mark the start slot idx. DwarfDebug will see it |
| 770 | // as if the DBG_VALUE is valid up until the end of the basic block, or |
| 771 | // the next def of the physical register. So we do not need to extend the |
| 772 | // range. It might actually happen that the DBG_VALUE is the last use of |
| 773 | // the physical register (e.g. if this is an unused input argument to a |
| 774 | // function). |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 775 | } |
| 776 | |
Robert Lougher | 10f740d | 2017-08-03 11:54:02 +0000 | [diff] [blame] | 777 | // The computed intervals may extend beyond the range of the debug |
| 778 | // location's lexical scope. In this case, splitting of an interval |
| 779 | // can result in an interval outside of the scope being created, |
| 780 | // causing extra unnecessary DBG_VALUEs to be emitted. To prevent |
| 781 | // this, trim the intervals to the lexical scope. |
| 782 | |
| 783 | LexicalScope *Scope = LS.findLexicalScope(dl); |
| 784 | if (!Scope) |
| 785 | return; |
| 786 | |
| 787 | SlotIndex PrevEnd; |
| 788 | LocMap::iterator I = locInts.begin(); |
| 789 | |
| 790 | // Iterate over the lexical scope ranges. Each time round the loop |
| 791 | // we check the intervals for overlap with the end of the previous |
| 792 | // range and the start of the next. The first range is handled as |
| 793 | // a special case where there is no PrevEnd. |
| 794 | for (const InsnRange &Range : Scope->getRanges()) { |
| 795 | SlotIndex RStart = LIS.getInstructionIndex(*Range.first); |
| 796 | SlotIndex REnd = LIS.getInstructionIndex(*Range.second); |
| 797 | |
| 798 | // At the start of each iteration I has been advanced so that |
| 799 | // I.stop() >= PrevEnd. Check for overlap. |
| 800 | if (PrevEnd && I.start() < PrevEnd) { |
| 801 | SlotIndex IStop = I.stop(); |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 802 | DbgValueLocation Loc = I.value(); |
Robert Lougher | 10f740d | 2017-08-03 11:54:02 +0000 | [diff] [blame] | 803 | |
| 804 | // Stop overlaps previous end - trim the end of the interval to |
| 805 | // the scope range. |
| 806 | I.setStopUnchecked(PrevEnd); |
| 807 | ++I; |
| 808 | |
| 809 | // If the interval also overlaps the start of the "next" (i.e. |
| 810 | // current) range create a new interval for the remainder (which |
| 811 | // may be further trimmed). |
| 812 | if (RStart < IStop) |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 813 | I.insert(RStart, IStop, Loc); |
Robert Lougher | 10f740d | 2017-08-03 11:54:02 +0000 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | // Advance I so that I.stop() >= RStart, and check for overlap. |
| 817 | I.advanceTo(RStart); |
| 818 | if (!I.valid()) |
| 819 | return; |
| 820 | |
| 821 | if (I.start() < RStart) { |
| 822 | // Interval start overlaps range - trim to the scope range. |
| 823 | I.setStartUnchecked(RStart); |
| 824 | // Remember that this interval was trimmed. |
| 825 | trimmedDefs.insert(RStart); |
| 826 | } |
| 827 | |
| 828 | // The end of a lexical scope range is the last instruction in the |
| 829 | // range. To convert to an interval we need the index of the |
| 830 | // instruction after it. |
| 831 | REnd = REnd.getNextIndex(); |
| 832 | |
| 833 | // Advance I to first interval outside current range. |
| 834 | I.advanceTo(REnd); |
| 835 | if (!I.valid()) |
| 836 | return; |
| 837 | |
| 838 | PrevEnd = REnd; |
| 839 | } |
| 840 | |
| 841 | // Check for overlap with end of final range. |
| 842 | if (PrevEnd && I.start() < PrevEnd) |
| 843 | I.setStopUnchecked(PrevEnd); |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | void LDVImpl::computeIntervals() { |
Robert Lougher | 10f740d | 2017-08-03 11:54:02 +0000 | [diff] [blame] | 847 | LexicalScopes LS; |
| 848 | LS.initialize(*MF); |
| 849 | |
Jakob Stoklund Olesen | 816f5f4 | 2011-03-18 21:42:19 +0000 | [diff] [blame] | 850 | for (unsigned i = 0, e = userValues.size(); i != e; ++i) { |
Robert Lougher | 10f740d | 2017-08-03 11:54:02 +0000 | [diff] [blame] | 851 | userValues[i]->computeIntervals(MF->getRegInfo(), *TRI, *LIS, LS); |
Jakob Stoklund Olesen | 816f5f4 | 2011-03-18 21:42:19 +0000 | [diff] [blame] | 852 | userValues[i]->mapVirtRegs(this); |
| 853 | } |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | bool LDVImpl::runOnMachineFunction(MachineFunction &mf) { |
David Blaikie | 2f04011 | 2014-07-25 16:10:16 +0000 | [diff] [blame] | 857 | clear(); |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 858 | MF = &mf; |
| 859 | LIS = &pass.getAnalysis<LiveIntervals>(); |
Eric Christopher | fc6de42 | 2014-08-05 02:39:49 +0000 | [diff] [blame] | 860 | TRI = mf.getSubtarget().getRegisterInfo(); |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 861 | LLVM_DEBUG(dbgs() << "********** COMPUTING LIVE DEBUG VARIABLES: " |
| 862 | << mf.getName() << " **********\n"); |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 863 | |
| 864 | bool Changed = collectDebugValues(mf); |
| 865 | computeIntervals(); |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 866 | LLVM_DEBUG(print(dbgs())); |
Manman Ren | 7a4c8a7 | 2013-02-13 20:23:48 +0000 | [diff] [blame] | 867 | ModifiedMF = Changed; |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 868 | return Changed; |
| 869 | } |
| 870 | |
David Blaikie | 2f04011 | 2014-07-25 16:10:16 +0000 | [diff] [blame] | 871 | static void removeDebugValues(MachineFunction &mf) { |
| 872 | for (MachineBasicBlock &MBB : mf) { |
| 873 | for (auto MBBI = MBB.begin(), MBBE = MBB.end(); MBBI != MBBE; ) { |
| 874 | if (!MBBI->isDebugValue()) { |
| 875 | ++MBBI; |
| 876 | continue; |
| 877 | } |
| 878 | MBBI = MBB.erase(MBBI); |
| 879 | } |
| 880 | } |
| 881 | } |
| 882 | |
Jakob Stoklund Olesen | d4900a6 | 2010-11-30 02:17:10 +0000 | [diff] [blame] | 883 | bool LiveDebugVariables::runOnMachineFunction(MachineFunction &mf) { |
Devang Patel | acbee0b | 2011-01-07 22:33:41 +0000 | [diff] [blame] | 884 | if (!EnableLDV) |
| 885 | return false; |
Matthias Braun | f1caa28 | 2017-12-15 22:22:58 +0000 | [diff] [blame] | 886 | if (!mf.getFunction().getSubprogram()) { |
David Blaikie | 2f04011 | 2014-07-25 16:10:16 +0000 | [diff] [blame] | 887 | removeDebugValues(mf); |
| 888 | return false; |
| 889 | } |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 890 | if (!pImpl) |
| 891 | pImpl = new LDVImpl(this); |
Manman Ren | 7a4c8a7 | 2013-02-13 20:23:48 +0000 | [diff] [blame] | 892 | return static_cast<LDVImpl*>(pImpl)->runOnMachineFunction(mf); |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | void LiveDebugVariables::releaseMemory() { |
Manman Ren | 7a4c8a7 | 2013-02-13 20:23:48 +0000 | [diff] [blame] | 896 | if (pImpl) |
Jakob Stoklund Olesen | 4be0bd7 | 2010-12-02 00:37:37 +0000 | [diff] [blame] | 897 | static_cast<LDVImpl*>(pImpl)->clear(); |
| 898 | } |
| 899 | |
| 900 | LiveDebugVariables::~LiveDebugVariables() { |
| 901 | if (pImpl) |
| 902 | delete static_cast<LDVImpl*>(pImpl); |
Jakob Stoklund Olesen | d4900a6 | 2010-11-30 02:17:10 +0000 | [diff] [blame] | 903 | } |
Jakob Stoklund Olesen | 9ec2011 | 2010-12-02 18:15:44 +0000 | [diff] [blame] | 904 | |
Jakob Stoklund Olesen | f8da028 | 2011-05-06 18:00:02 +0000 | [diff] [blame] | 905 | //===----------------------------------------------------------------------===// |
| 906 | // Live Range Splitting |
| 907 | //===----------------------------------------------------------------------===// |
| 908 | |
| 909 | bool |
Mark Lacey | f9ea885 | 2013-08-14 23:50:04 +0000 | [diff] [blame] | 910 | UserValue::splitLocation(unsigned OldLocNo, ArrayRef<unsigned> NewRegs, |
| 911 | LiveIntervals& LIS) { |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 912 | LLVM_DEBUG({ |
Jakob Stoklund Olesen | f8da028 | 2011-05-06 18:00:02 +0000 | [diff] [blame] | 913 | dbgs() << "Splitting Loc" << OldLocNo << '\t'; |
Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 914 | print(dbgs(), nullptr); |
Jakob Stoklund Olesen | f8da028 | 2011-05-06 18:00:02 +0000 | [diff] [blame] | 915 | }); |
| 916 | bool DidChange = false; |
| 917 | LocMap::iterator LocMapI; |
| 918 | LocMapI.setMap(locInts); |
| 919 | for (unsigned i = 0; i != NewRegs.size(); ++i) { |
Mark Lacey | f9ea885 | 2013-08-14 23:50:04 +0000 | [diff] [blame] | 920 | LiveInterval *LI = &LIS.getInterval(NewRegs[i]); |
Jakob Stoklund Olesen | f8da028 | 2011-05-06 18:00:02 +0000 | [diff] [blame] | 921 | if (LI->empty()) |
| 922 | continue; |
| 923 | |
| 924 | // Don't allocate the new LocNo until it is needed. |
Reid Kleckner | eed0973 | 2017-09-15 22:08:50 +0000 | [diff] [blame] | 925 | unsigned NewLocNo = UndefLocNo; |
Jakob Stoklund Olesen | f8da028 | 2011-05-06 18:00:02 +0000 | [diff] [blame] | 926 | |
| 927 | // Iterate over the overlaps between locInts and LI. |
| 928 | LocMapI.find(LI->beginIndex()); |
| 929 | if (!LocMapI.valid()) |
| 930 | continue; |
| 931 | LiveInterval::iterator LII = LI->advanceTo(LI->begin(), LocMapI.start()); |
| 932 | LiveInterval::iterator LIE = LI->end(); |
| 933 | while (LocMapI.valid() && LII != LIE) { |
| 934 | // At this point, we know that LocMapI.stop() > LII->start. |
| 935 | LII = LI->advanceTo(LII, LocMapI.start()); |
| 936 | if (LII == LIE) |
| 937 | break; |
| 938 | |
| 939 | // Now LII->end > LocMapI.start(). Do we have an overlap? |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 940 | if (LocMapI.value().locNo() == OldLocNo && LII->start < LocMapI.stop()) { |
Jakob Stoklund Olesen | f8da028 | 2011-05-06 18:00:02 +0000 | [diff] [blame] | 941 | // Overlapping correct location. Allocate NewLocNo now. |
Reid Kleckner | eed0973 | 2017-09-15 22:08:50 +0000 | [diff] [blame] | 942 | if (NewLocNo == UndefLocNo) { |
Jakob Stoklund Olesen | f8da028 | 2011-05-06 18:00:02 +0000 | [diff] [blame] | 943 | MachineOperand MO = MachineOperand::CreateReg(LI->reg, false); |
| 944 | MO.setSubReg(locations[OldLocNo].getSubReg()); |
| 945 | NewLocNo = getLocationNo(MO); |
| 946 | DidChange = true; |
| 947 | } |
| 948 | |
| 949 | SlotIndex LStart = LocMapI.start(); |
| 950 | SlotIndex LStop = LocMapI.stop(); |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 951 | DbgValueLocation OldLoc = LocMapI.value(); |
Jakob Stoklund Olesen | f8da028 | 2011-05-06 18:00:02 +0000 | [diff] [blame] | 952 | |
| 953 | // Trim LocMapI down to the LII overlap. |
| 954 | if (LStart < LII->start) |
| 955 | LocMapI.setStartUnchecked(LII->start); |
| 956 | if (LStop > LII->end) |
| 957 | LocMapI.setStopUnchecked(LII->end); |
| 958 | |
| 959 | // Change the value in the overlap. This may trigger coalescing. |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 960 | LocMapI.setValue(OldLoc.changeLocNo(NewLocNo)); |
Jakob Stoklund Olesen | f8da028 | 2011-05-06 18:00:02 +0000 | [diff] [blame] | 961 | |
| 962 | // Re-insert any removed OldLocNo ranges. |
| 963 | if (LStart < LocMapI.start()) { |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 964 | LocMapI.insert(LStart, LocMapI.start(), OldLoc); |
Jakob Stoklund Olesen | f8da028 | 2011-05-06 18:00:02 +0000 | [diff] [blame] | 965 | ++LocMapI; |
| 966 | assert(LocMapI.valid() && "Unexpected coalescing"); |
| 967 | } |
| 968 | if (LStop > LocMapI.stop()) { |
| 969 | ++LocMapI; |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 970 | LocMapI.insert(LII->end, LStop, OldLoc); |
Jakob Stoklund Olesen | f8da028 | 2011-05-06 18:00:02 +0000 | [diff] [blame] | 971 | --LocMapI; |
| 972 | } |
| 973 | } |
| 974 | |
| 975 | // Advance to the next overlap. |
| 976 | if (LII->end < LocMapI.stop()) { |
| 977 | if (++LII == LIE) |
| 978 | break; |
| 979 | LocMapI.advanceTo(LII->start); |
| 980 | } else { |
| 981 | ++LocMapI; |
| 982 | if (!LocMapI.valid()) |
| 983 | break; |
| 984 | LII = LI->advanceTo(LII, LocMapI.start()); |
| 985 | } |
| 986 | } |
| 987 | } |
| 988 | |
| 989 | // Finally, remove any remaining OldLocNo intervals and OldLocNo itself. |
| 990 | locations.erase(locations.begin() + OldLocNo); |
| 991 | LocMapI.goToBegin(); |
| 992 | while (LocMapI.valid()) { |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 993 | DbgValueLocation v = LocMapI.value(); |
| 994 | if (v.locNo() == OldLocNo) { |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 995 | LLVM_DEBUG(dbgs() << "Erasing [" << LocMapI.start() << ';' |
| 996 | << LocMapI.stop() << ")\n"); |
Jakob Stoklund Olesen | f8da028 | 2011-05-06 18:00:02 +0000 | [diff] [blame] | 997 | LocMapI.erase(); |
| 998 | } else { |
Mikael Holmen | 57b33f6 | 2018-06-21 07:02:46 +0000 | [diff] [blame] | 999 | // Undef values always have location number UndefLocNo, so don't change |
| 1000 | // locNo in that case. See getLocationNo(). |
| 1001 | if (!v.isUndef() && v.locNo() > OldLocNo) |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 1002 | LocMapI.setValueUnchecked(v.changeLocNo(v.locNo() - 1)); |
Jakob Stoklund Olesen | f8da028 | 2011-05-06 18:00:02 +0000 | [diff] [blame] | 1003 | ++LocMapI; |
| 1004 | } |
| 1005 | } |
| 1006 | |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 1007 | LLVM_DEBUG({ |
| 1008 | dbgs() << "Split result: \t"; |
| 1009 | print(dbgs(), nullptr); |
| 1010 | }); |
Jakob Stoklund Olesen | f8da028 | 2011-05-06 18:00:02 +0000 | [diff] [blame] | 1011 | return DidChange; |
| 1012 | } |
| 1013 | |
| 1014 | bool |
Mark Lacey | f9ea885 | 2013-08-14 23:50:04 +0000 | [diff] [blame] | 1015 | UserValue::splitRegister(unsigned OldReg, ArrayRef<unsigned> NewRegs, |
| 1016 | LiveIntervals &LIS) { |
Jakob Stoklund Olesen | f8da028 | 2011-05-06 18:00:02 +0000 | [diff] [blame] | 1017 | bool DidChange = false; |
Jakob Stoklund Olesen | 57c8f58 | 2011-05-06 19:31:19 +0000 | [diff] [blame] | 1018 | // Split locations referring to OldReg. Iterate backwards so splitLocation can |
Eric Christopher | be153e6 | 2012-03-15 21:33:35 +0000 | [diff] [blame] | 1019 | // safely erase unused locations. |
Jakob Stoklund Olesen | 57c8f58 | 2011-05-06 19:31:19 +0000 | [diff] [blame] | 1020 | for (unsigned i = locations.size(); i ; --i) { |
| 1021 | unsigned LocNo = i-1; |
Jakob Stoklund Olesen | f8da028 | 2011-05-06 18:00:02 +0000 | [diff] [blame] | 1022 | const MachineOperand *Loc = &locations[LocNo]; |
| 1023 | if (!Loc->isReg() || Loc->getReg() != OldReg) |
| 1024 | continue; |
Mark Lacey | f9ea885 | 2013-08-14 23:50:04 +0000 | [diff] [blame] | 1025 | DidChange |= splitLocation(LocNo, NewRegs, LIS); |
Jakob Stoklund Olesen | f8da028 | 2011-05-06 18:00:02 +0000 | [diff] [blame] | 1026 | } |
| 1027 | return DidChange; |
| 1028 | } |
| 1029 | |
Mark Lacey | f9ea885 | 2013-08-14 23:50:04 +0000 | [diff] [blame] | 1030 | void LDVImpl::splitRegister(unsigned OldReg, ArrayRef<unsigned> NewRegs) { |
Jakob Stoklund Olesen | f8da028 | 2011-05-06 18:00:02 +0000 | [diff] [blame] | 1031 | bool DidChange = false; |
| 1032 | for (UserValue *UV = lookupVirtReg(OldReg); UV; UV = UV->getNext()) |
Mark Lacey | f9ea885 | 2013-08-14 23:50:04 +0000 | [diff] [blame] | 1033 | DidChange |= UV->splitRegister(OldReg, NewRegs, *LIS); |
Jakob Stoklund Olesen | f8da028 | 2011-05-06 18:00:02 +0000 | [diff] [blame] | 1034 | |
| 1035 | if (!DidChange) |
| 1036 | return; |
| 1037 | |
| 1038 | // Map all of the new virtual registers. |
| 1039 | UserValue *UV = lookupVirtReg(OldReg); |
| 1040 | for (unsigned i = 0; i != NewRegs.size(); ++i) |
Mark Lacey | f9ea885 | 2013-08-14 23:50:04 +0000 | [diff] [blame] | 1041 | mapVirtReg(NewRegs[i], UV); |
Jakob Stoklund Olesen | f8da028 | 2011-05-06 18:00:02 +0000 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | void LiveDebugVariables:: |
Mark Lacey | f9ea885 | 2013-08-14 23:50:04 +0000 | [diff] [blame] | 1045 | splitRegister(unsigned OldReg, ArrayRef<unsigned> NewRegs, LiveIntervals &LIS) { |
Jakob Stoklund Olesen | f8da028 | 2011-05-06 18:00:02 +0000 | [diff] [blame] | 1046 | if (pImpl) |
| 1047 | static_cast<LDVImpl*>(pImpl)->splitRegister(OldReg, NewRegs); |
| 1048 | } |
| 1049 | |
Reid Kleckner | 4e04028 | 2017-09-20 18:19:08 +0000 | [diff] [blame] | 1050 | void UserValue::rewriteLocations(VirtRegMap &VRM, const TargetRegisterInfo &TRI, |
| 1051 | BitVector &SpilledLocations) { |
Reid Kleckner | 92687d4 | 2017-09-20 17:32:54 +0000 | [diff] [blame] | 1052 | // Build a set of new locations with new numbers so we can coalesce our |
| 1053 | // IntervalMap if two vreg intervals collapse to the same physical location. |
| 1054 | // Use MapVector instead of SetVector because MapVector::insert returns the |
Reid Kleckner | 4e04028 | 2017-09-20 18:19:08 +0000 | [diff] [blame] | 1055 | // position of the previously or newly inserted element. The boolean value |
| 1056 | // tracks if the location was produced by a spill. |
| 1057 | // FIXME: This will be problematic if we ever support direct and indirect |
| 1058 | // frame index locations, i.e. expressing both variables in memory and |
| 1059 | // 'int x, *px = &x'. The "spilled" bit must become part of the location. |
Reid Kleckner | 92687d4 | 2017-09-20 17:32:54 +0000 | [diff] [blame] | 1060 | MapVector<MachineOperand, bool> NewLocations; |
| 1061 | SmallVector<unsigned, 4> LocNoMap(locations.size()); |
| 1062 | for (unsigned I = 0, E = locations.size(); I != E; ++I) { |
Reid Kleckner | 4e04028 | 2017-09-20 18:19:08 +0000 | [diff] [blame] | 1063 | bool Spilled = false; |
Reid Kleckner | 92687d4 | 2017-09-20 17:32:54 +0000 | [diff] [blame] | 1064 | MachineOperand Loc = locations[I]; |
Jakob Stoklund Olesen | afc2bc2 | 2010-12-03 21:47:10 +0000 | [diff] [blame] | 1065 | // Only virtual registers are rewritten. |
Reid Kleckner | 92687d4 | 2017-09-20 17:32:54 +0000 | [diff] [blame] | 1066 | if (Loc.isReg() && Loc.getReg() && |
| 1067 | TargetRegisterInfo::isVirtualRegister(Loc.getReg())) { |
| 1068 | unsigned VirtReg = Loc.getReg(); |
| 1069 | if (VRM.isAssignedReg(VirtReg) && |
| 1070 | TargetRegisterInfo::isPhysicalRegister(VRM.getPhys(VirtReg))) { |
| 1071 | // This can create a %noreg operand in rare cases when the sub-register |
| 1072 | // index is no longer available. That means the user value is in a |
| 1073 | // non-existent sub-register, and %noreg is exactly what we want. |
| 1074 | Loc.substPhysReg(VRM.getPhys(VirtReg), TRI); |
| 1075 | } else if (VRM.getStackSlot(VirtReg) != VirtRegMap::NO_STACK_SLOT) { |
| 1076 | // FIXME: Translate SubIdx to a stackslot offset. |
| 1077 | Loc = MachineOperand::CreateFI(VRM.getStackSlot(VirtReg)); |
Reid Kleckner | 4e04028 | 2017-09-20 18:19:08 +0000 | [diff] [blame] | 1078 | Spilled = true; |
Reid Kleckner | 92687d4 | 2017-09-20 17:32:54 +0000 | [diff] [blame] | 1079 | } else { |
| 1080 | Loc.setReg(0); |
| 1081 | Loc.setSubReg(0); |
| 1082 | } |
Jakob Stoklund Olesen | afc2bc2 | 2010-12-03 21:47:10 +0000 | [diff] [blame] | 1083 | } |
Reid Kleckner | 92687d4 | 2017-09-20 17:32:54 +0000 | [diff] [blame] | 1084 | |
| 1085 | // Insert this location if it doesn't already exist and record a mapping |
| 1086 | // from the old number to the new number. |
Reid Kleckner | 4e04028 | 2017-09-20 18:19:08 +0000 | [diff] [blame] | 1087 | auto InsertResult = NewLocations.insert({Loc, Spilled}); |
| 1088 | unsigned NewLocNo = std::distance(NewLocations.begin(), InsertResult.first); |
| 1089 | LocNoMap[I] = NewLocNo; |
Reid Kleckner | 92687d4 | 2017-09-20 17:32:54 +0000 | [diff] [blame] | 1090 | } |
| 1091 | |
Reid Kleckner | 4e04028 | 2017-09-20 18:19:08 +0000 | [diff] [blame] | 1092 | // Rewrite the locations and record which ones were spill slots. |
Reid Kleckner | 92687d4 | 2017-09-20 17:32:54 +0000 | [diff] [blame] | 1093 | locations.clear(); |
Reid Kleckner | 4e04028 | 2017-09-20 18:19:08 +0000 | [diff] [blame] | 1094 | SpilledLocations.clear(); |
| 1095 | SpilledLocations.resize(NewLocations.size()); |
| 1096 | for (auto &Pair : NewLocations) { |
Reid Kleckner | 92687d4 | 2017-09-20 17:32:54 +0000 | [diff] [blame] | 1097 | locations.push_back(Pair.first); |
Reid Kleckner | 4e04028 | 2017-09-20 18:19:08 +0000 | [diff] [blame] | 1098 | if (Pair.second) { |
| 1099 | unsigned NewLocNo = std::distance(&*NewLocations.begin(), &Pair); |
| 1100 | SpilledLocations.set(NewLocNo); |
| 1101 | } |
| 1102 | } |
Reid Kleckner | 92687d4 | 2017-09-20 17:32:54 +0000 | [diff] [blame] | 1103 | |
| 1104 | // Update the interval map, but only coalesce left, since intervals to the |
| 1105 | // right use the old location numbers. This should merge two contiguous |
| 1106 | // DBG_VALUE intervals with different vregs that were allocated to the same |
| 1107 | // physical register. |
| 1108 | for (LocMap::iterator I = locInts.begin(); I.valid(); ++I) { |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 1109 | DbgValueLocation Loc = I.value(); |
Mikael Holmen | 57b33f6 | 2018-06-21 07:02:46 +0000 | [diff] [blame] | 1110 | // Undef values don't exist in locations (and thus not in LocNoMap either) |
| 1111 | // so skip over them. See getLocationNo(). |
| 1112 | if (Loc.isUndef()) |
| 1113 | continue; |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 1114 | unsigned NewLocNo = LocNoMap[Loc.locNo()]; |
| 1115 | I.setValueUnchecked(Loc.changeLocNo(NewLocNo)); |
Reid Kleckner | 92687d4 | 2017-09-20 17:32:54 +0000 | [diff] [blame] | 1116 | I.setStart(I.start()); |
Jakob Stoklund Olesen | afc2bc2 | 2010-12-03 21:47:10 +0000 | [diff] [blame] | 1117 | } |
Jakob Stoklund Olesen | afc2bc2 | 2010-12-03 21:47:10 +0000 | [diff] [blame] | 1118 | } |
| 1119 | |
Karl-Johan Karlsson | 8d8d201 | 2017-10-05 08:37:31 +0000 | [diff] [blame] | 1120 | /// Find an iterator for inserting a DBG_VALUE instruction. |
Jakob Stoklund Olesen | afc2bc2 | 2010-12-03 21:47:10 +0000 | [diff] [blame] | 1121 | static MachineBasicBlock::iterator |
Devang Patel | 26ffa01 | 2011-02-04 01:43:25 +0000 | [diff] [blame] | 1122 | findInsertLocation(MachineBasicBlock *MBB, SlotIndex Idx, |
Jakob Stoklund Olesen | afc2bc2 | 2010-12-03 21:47:10 +0000 | [diff] [blame] | 1123 | LiveIntervals &LIS) { |
| 1124 | SlotIndex Start = LIS.getMBBStartIdx(MBB); |
| 1125 | Idx = Idx.getBaseIndex(); |
| 1126 | |
| 1127 | // Try to find an insert location by going backwards from Idx. |
| 1128 | MachineInstr *MI; |
| 1129 | while (!(MI = LIS.getInstructionFromIndex(Idx))) { |
| 1130 | // We've reached the beginning of MBB. |
| 1131 | if (Idx == Start) { |
Keith Walker | 830a8c1 | 2016-09-16 14:07:29 +0000 | [diff] [blame] | 1132 | MachineBasicBlock::iterator I = MBB->SkipPHIsLabelsAndDebug(MBB->begin()); |
Jakob Stoklund Olesen | afc2bc2 | 2010-12-03 21:47:10 +0000 | [diff] [blame] | 1133 | return I; |
| 1134 | } |
| 1135 | Idx = Idx.getPrevIndex(); |
| 1136 | } |
Devang Patel | 26ffa01 | 2011-02-04 01:43:25 +0000 | [diff] [blame] | 1137 | |
Jakob Stoklund Olesen | 088b30a | 2011-01-13 23:35:53 +0000 | [diff] [blame] | 1138 | // Don't insert anything after the first terminator, though. |
Evan Cheng | 7f8e563 | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 1139 | return MI->isTerminator() ? MBB->getFirstTerminator() : |
Benjamin Kramer | b6d0bd4 | 2014-03-02 12:27:27 +0000 | [diff] [blame] | 1140 | std::next(MachineBasicBlock::iterator(MI)); |
Jakob Stoklund Olesen | afc2bc2 | 2010-12-03 21:47:10 +0000 | [diff] [blame] | 1141 | } |
| 1142 | |
Karl-Johan Karlsson | 8d8d201 | 2017-10-05 08:37:31 +0000 | [diff] [blame] | 1143 | /// Find an iterator for inserting the next DBG_VALUE instruction |
| 1144 | /// (or end if no more insert locations found). |
| 1145 | static MachineBasicBlock::iterator |
| 1146 | findNextInsertLocation(MachineBasicBlock *MBB, |
| 1147 | MachineBasicBlock::iterator I, |
| 1148 | SlotIndex StopIdx, MachineOperand &LocMO, |
| 1149 | LiveIntervals &LIS, |
| 1150 | const TargetRegisterInfo &TRI) { |
| 1151 | if (!LocMO.isReg()) |
| 1152 | return MBB->instr_end(); |
| 1153 | unsigned Reg = LocMO.getReg(); |
| 1154 | |
| 1155 | // Find the next instruction in the MBB that define the register Reg. |
Stefan Maksimovic | 991af7a | 2018-02-09 14:03:26 +0000 | [diff] [blame] | 1156 | while (I != MBB->end() && !I->isTerminator()) { |
Karl-Johan Karlsson | 8d8d201 | 2017-10-05 08:37:31 +0000 | [diff] [blame] | 1157 | if (!LIS.isNotInMIMap(*I) && |
| 1158 | SlotIndex::isEarlierEqualInstr(StopIdx, LIS.getInstructionIndex(*I))) |
| 1159 | break; |
| 1160 | if (I->definesRegister(Reg, &TRI)) |
| 1161 | // The insert location is directly after the instruction/bundle. |
| 1162 | return std::next(I); |
| 1163 | ++I; |
| 1164 | } |
| 1165 | return MBB->end(); |
| 1166 | } |
| 1167 | |
| 1168 | void UserValue::insertDebugValue(MachineBasicBlock *MBB, SlotIndex StartIdx, |
| 1169 | SlotIndex StopIdx, |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 1170 | DbgValueLocation Loc, bool Spilled, |
Jakob Stoklund Olesen | afc2bc2 | 2010-12-03 21:47:10 +0000 | [diff] [blame] | 1171 | LiveIntervals &LIS, |
Karl-Johan Karlsson | 8d8d201 | 2017-10-05 08:37:31 +0000 | [diff] [blame] | 1172 | const TargetInstrInfo &TII, |
| 1173 | const TargetRegisterInfo &TRI) { |
| 1174 | SlotIndex MBBEndIdx = LIS.getMBBEndIdx(&*MBB); |
| 1175 | // Only search within the current MBB. |
| 1176 | StopIdx = (MBBEndIdx < StopIdx) ? MBBEndIdx : StopIdx; |
| 1177 | MachineBasicBlock::iterator I = findInsertLocation(MBB, StartIdx, LIS); |
Mikael Holmen | 57b33f6 | 2018-06-21 07:02:46 +0000 | [diff] [blame] | 1178 | // Undef values don't exist in locations so create new "noreg" register MOs |
| 1179 | // for them. See getLocationNo(). |
| 1180 | MachineOperand MO = !Loc.isUndef() ? |
| 1181 | locations[Loc.locNo()] : |
| 1182 | MachineOperand::CreateReg(/* Reg */ 0, /* isDef */ false, /* isImp */ false, |
| 1183 | /* isKill */ false, /* isDead */ false, |
| 1184 | /* isUndef */ false, /* isEarlyClobber */ false, |
| 1185 | /* SubReg */ 0, /* isDebug */ true); |
| 1186 | |
Devang Patel | eabc3cea | 2011-08-04 20:42:11 +0000 | [diff] [blame] | 1187 | ++NumInsertedDebugValues; |
Jakob Stoklund Olesen | afc2bc2 | 2010-12-03 21:47:10 +0000 | [diff] [blame] | 1188 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1189 | assert(cast<DILocalVariable>(Variable) |
Duncan P. N. Exon Smith | e686f15 | 2015-04-06 23:27:40 +0000 | [diff] [blame] | 1190 | ->isValidLocationForIntrinsic(getDebugLoc()) && |
Duncan P. N. Exon Smith | 3bef6a3 | 2015-04-03 19:20:26 +0000 | [diff] [blame] | 1191 | "Expected inlined-at fields to agree"); |
Reid Kleckner | 4e04028 | 2017-09-20 18:19:08 +0000 | [diff] [blame] | 1192 | |
| 1193 | // If the location was spilled, the new DBG_VALUE will be indirect. If the |
| 1194 | // original DBG_VALUE was indirect, we need to add DW_OP_deref to indicate |
| 1195 | // that the original virtual register was a pointer. |
Reid Kleckner | 4e04028 | 2017-09-20 18:19:08 +0000 | [diff] [blame] | 1196 | const DIExpression *Expr = Expression; |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 1197 | bool IsIndirect = Loc.wasIndirect(); |
| 1198 | if (Spilled) { |
| 1199 | if (IsIndirect) |
| 1200 | Expr = DIExpression::prepend(Expr, DIExpression::WithDeref); |
| 1201 | IsIndirect = true; |
| 1202 | } |
Reid Kleckner | 4e04028 | 2017-09-20 18:19:08 +0000 | [diff] [blame] | 1203 | |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 1204 | assert((!Spilled || MO.isFI()) && "a spilled location must be a frame index"); |
Reid Kleckner | 4e04028 | 2017-09-20 18:19:08 +0000 | [diff] [blame] | 1205 | |
Karl-Johan Karlsson | 8d8d201 | 2017-10-05 08:37:31 +0000 | [diff] [blame] | 1206 | do { |
Mikael Holmen | 42f7bc9 | 2018-06-21 10:03:34 +0000 | [diff] [blame] | 1207 | BuildMI(*MBB, I, getDebugLoc(), TII.get(TargetOpcode::DBG_VALUE), |
| 1208 | IsIndirect, MO, Variable, Expr); |
Karl-Johan Karlsson | 8d8d201 | 2017-10-05 08:37:31 +0000 | [diff] [blame] | 1209 | |
| 1210 | // Continue and insert DBG_VALUES after every redefinition of register |
| 1211 | // associated with the debug value within the range |
| 1212 | I = findNextInsertLocation(MBB, I, StopIdx, MO, LIS, TRI); |
| 1213 | } while (I != MBB->end()); |
Jakob Stoklund Olesen | afc2bc2 | 2010-12-03 21:47:10 +0000 | [diff] [blame] | 1214 | } |
| 1215 | |
Jakob Stoklund Olesen | afc2bc2 | 2010-12-03 21:47:10 +0000 | [diff] [blame] | 1216 | void UserValue::emitDebugValues(VirtRegMap *VRM, LiveIntervals &LIS, |
Reid Kleckner | 4e04028 | 2017-09-20 18:19:08 +0000 | [diff] [blame] | 1217 | const TargetInstrInfo &TII, |
Karl-Johan Karlsson | 8d8d201 | 2017-10-05 08:37:31 +0000 | [diff] [blame] | 1218 | const TargetRegisterInfo &TRI, |
Reid Kleckner | 4e04028 | 2017-09-20 18:19:08 +0000 | [diff] [blame] | 1219 | const BitVector &SpilledLocations) { |
Jakob Stoklund Olesen | afc2bc2 | 2010-12-03 21:47:10 +0000 | [diff] [blame] | 1220 | MachineFunction::iterator MFEnd = VRM->getMachineFunction().end(); |
| 1221 | |
| 1222 | for (LocMap::const_iterator I = locInts.begin(); I.valid();) { |
| 1223 | SlotIndex Start = I.start(); |
| 1224 | SlotIndex Stop = I.stop(); |
Reid Kleckner | 04e25e0 | 2017-10-03 17:59:02 +0000 | [diff] [blame] | 1225 | DbgValueLocation Loc = I.value(); |
| 1226 | bool Spilled = !Loc.isUndef() ? SpilledLocations.test(Loc.locNo()) : false; |
Robert Lougher | 10f740d | 2017-08-03 11:54:02 +0000 | [diff] [blame] | 1227 | |
| 1228 | // If the interval start was trimmed to the lexical scope insert the |
| 1229 | // DBG_VALUE at the previous index (otherwise it appears after the |
| 1230 | // first instruction in the range). |
| 1231 | if (trimmedDefs.count(Start)) |
| 1232 | Start = Start.getPrevIndex(); |
| 1233 | |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 1234 | LLVM_DEBUG(dbgs() << "\t[" << Start << ';' << Stop << "):" << Loc.locNo()); |
Duncan P. N. Exon Smith | 5ae5939 | 2015-10-09 19:13:58 +0000 | [diff] [blame] | 1235 | MachineFunction::iterator MBB = LIS.getMBBFromIndex(Start)->getIterator(); |
| 1236 | SlotIndex MBBEnd = LIS.getMBBEndIdx(&*MBB); |
Jakob Stoklund Olesen | afc2bc2 | 2010-12-03 21:47:10 +0000 | [diff] [blame] | 1237 | |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 1238 | LLVM_DEBUG(dbgs() << ' ' << printMBBReference(*MBB) << '-' << MBBEnd); |
Karl-Johan Karlsson | 8d8d201 | 2017-10-05 08:37:31 +0000 | [diff] [blame] | 1239 | insertDebugValue(&*MBB, Start, Stop, Loc, Spilled, LIS, TII, TRI); |
Jakob Stoklund Olesen | afc2bc2 | 2010-12-03 21:47:10 +0000 | [diff] [blame] | 1240 | // This interval may span multiple basic blocks. |
| 1241 | // Insert a DBG_VALUE into each one. |
Karl-Johan Karlsson | 8d8d201 | 2017-10-05 08:37:31 +0000 | [diff] [blame] | 1242 | while (Stop > MBBEnd) { |
Jakob Stoklund Olesen | afc2bc2 | 2010-12-03 21:47:10 +0000 | [diff] [blame] | 1243 | // Move to the next block. |
| 1244 | Start = MBBEnd; |
| 1245 | if (++MBB == MFEnd) |
| 1246 | break; |
Duncan P. N. Exon Smith | 5ae5939 | 2015-10-09 19:13:58 +0000 | [diff] [blame] | 1247 | MBBEnd = LIS.getMBBEndIdx(&*MBB); |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 1248 | LLVM_DEBUG(dbgs() << ' ' << printMBBReference(*MBB) << '-' << MBBEnd); |
Karl-Johan Karlsson | 8d8d201 | 2017-10-05 08:37:31 +0000 | [diff] [blame] | 1249 | insertDebugValue(&*MBB, Start, Stop, Loc, Spilled, LIS, TII, TRI); |
Jakob Stoklund Olesen | afc2bc2 | 2010-12-03 21:47:10 +0000 | [diff] [blame] | 1250 | } |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 1251 | LLVM_DEBUG(dbgs() << '\n'); |
Jakob Stoklund Olesen | afc2bc2 | 2010-12-03 21:47:10 +0000 | [diff] [blame] | 1252 | if (MBB == MFEnd) |
| 1253 | break; |
| 1254 | |
| 1255 | ++I; |
Jakob Stoklund Olesen | afc2bc2 | 2010-12-03 21:47:10 +0000 | [diff] [blame] | 1256 | } |
| 1257 | } |
| 1258 | |
| 1259 | void LDVImpl::emitDebugValues(VirtRegMap *VRM) { |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 1260 | LLVM_DEBUG(dbgs() << "********** EMITTING LIVE DEBUG VARIABLES **********\n"); |
David Blaikie | 2f04011 | 2014-07-25 16:10:16 +0000 | [diff] [blame] | 1261 | if (!MF) |
| 1262 | return; |
Eric Christopher | fc6de42 | 2014-08-05 02:39:49 +0000 | [diff] [blame] | 1263 | const TargetInstrInfo *TII = MF->getSubtarget().getInstrInfo(); |
Reid Kleckner | 4e04028 | 2017-09-20 18:19:08 +0000 | [diff] [blame] | 1264 | BitVector SpilledLocations; |
Jakob Stoklund Olesen | afc2bc2 | 2010-12-03 21:47:10 +0000 | [diff] [blame] | 1265 | for (unsigned i = 0, e = userValues.size(); i != e; ++i) { |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 1266 | LLVM_DEBUG(userValues[i]->print(dbgs(), TRI)); |
Reid Kleckner | 4e04028 | 2017-09-20 18:19:08 +0000 | [diff] [blame] | 1267 | userValues[i]->rewriteLocations(*VRM, *TRI, SpilledLocations); |
Karl-Johan Karlsson | 8d8d201 | 2017-10-05 08:37:31 +0000 | [diff] [blame] | 1268 | userValues[i]->emitDebugValues(VRM, *LIS, *TII, *TRI, SpilledLocations); |
Jakob Stoklund Olesen | afc2bc2 | 2010-12-03 21:47:10 +0000 | [diff] [blame] | 1269 | } |
Manman Ren | 7a4c8a7 | 2013-02-13 20:23:48 +0000 | [diff] [blame] | 1270 | EmitDone = true; |
Jakob Stoklund Olesen | afc2bc2 | 2010-12-03 21:47:10 +0000 | [diff] [blame] | 1271 | } |
| 1272 | |
| 1273 | void LiveDebugVariables::emitDebugValues(VirtRegMap *VRM) { |
Manman Ren | 7a4c8a7 | 2013-02-13 20:23:48 +0000 | [diff] [blame] | 1274 | if (pImpl) |
Jakob Stoklund Olesen | afc2bc2 | 2010-12-03 21:47:10 +0000 | [diff] [blame] | 1275 | static_cast<LDVImpl*>(pImpl)->emitDebugValues(VRM); |
| 1276 | } |
| 1277 | |
David Blaikie | 2f04011 | 2014-07-25 16:10:16 +0000 | [diff] [blame] | 1278 | bool LiveDebugVariables::doInitialization(Module &M) { |
David Blaikie | 2f04011 | 2014-07-25 16:10:16 +0000 | [diff] [blame] | 1279 | return Pass::doInitialization(M); |
| 1280 | } |
Jakob Stoklund Olesen | afc2bc2 | 2010-12-03 21:47:10 +0000 | [diff] [blame] | 1281 | |
Aaron Ballman | 615eb47 | 2017-10-15 14:32:27 +0000 | [diff] [blame] | 1282 | #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) |
Sam Clegg | 705f798 | 2017-06-21 22:19:17 +0000 | [diff] [blame] | 1283 | LLVM_DUMP_METHOD void LiveDebugVariables::dump() const { |
Jakob Stoklund Olesen | 9ec2011 | 2010-12-02 18:15:44 +0000 | [diff] [blame] | 1284 | if (pImpl) |
| 1285 | static_cast<LDVImpl*>(pImpl)->print(dbgs()); |
| 1286 | } |
| 1287 | #endif |