Eugene Zelenko | 5df3d89 | 2017-08-24 21:21:39 +0000 | [diff] [blame] | 1 | //===- LiveDebugValues.cpp - Tracking Debug Value MIs ---------------------===// |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 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 | |
Eugene Zelenko | 5df3d89 | 2017-08-24 21:21:39 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/DenseMap.h" |
Daniel Berlin | 7256059 | 2016-01-10 18:08:32 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/PostOrderIterator.h" |
| 23 | #include "llvm/ADT/SmallPtrSet.h" |
Eugene Zelenko | 5df3d89 | 2017-08-24 21:21:39 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/SmallVector.h" |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/SparseBitVector.h" |
Mehdi Amini | b550cb1 | 2016-04-18 09:17:29 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/Statistic.h" |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 27 | #include "llvm/ADT/UniqueVector.h" |
Adrian Prantl | 7f5866c | 2016-09-28 17:51:14 +0000 | [diff] [blame] | 28 | #include "llvm/CodeGen/LexicalScopes.h" |
Eugene Zelenko | 5df3d89 | 2017-08-24 21:21:39 +0000 | [diff] [blame] | 29 | #include "llvm/CodeGen/MachineBasicBlock.h" |
Wolfgang Pieb | 399dcfa | 2017-02-14 19:08:45 +0000 | [diff] [blame] | 30 | #include "llvm/CodeGen/MachineFrameInfo.h" |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 31 | #include "llvm/CodeGen/MachineFunction.h" |
| 32 | #include "llvm/CodeGen/MachineFunctionPass.h" |
Eugene Zelenko | 5df3d89 | 2017-08-24 21:21:39 +0000 | [diff] [blame] | 33 | #include "llvm/CodeGen/MachineInstr.h" |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 34 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Wolfgang Pieb | 399dcfa | 2017-02-14 19:08:45 +0000 | [diff] [blame] | 35 | #include "llvm/CodeGen/MachineMemOperand.h" |
Eugene Zelenko | 5df3d89 | 2017-08-24 21:21:39 +0000 | [diff] [blame] | 36 | #include "llvm/CodeGen/MachineOperand.h" |
| 37 | #include "llvm/CodeGen/PseudoSourceValue.h" |
David Blaikie | 3f833ed | 2017-11-08 01:01:31 +0000 | [diff] [blame] | 38 | #include "llvm/CodeGen/TargetFrameLowering.h" |
| 39 | #include "llvm/CodeGen/TargetInstrInfo.h" |
David Blaikie | b3bde2e | 2017-11-17 01:07:10 +0000 | [diff] [blame] | 40 | #include "llvm/CodeGen/TargetLowering.h" |
| 41 | #include "llvm/CodeGen/TargetRegisterInfo.h" |
| 42 | #include "llvm/CodeGen/TargetSubtargetInfo.h" |
Petar Jovanovic | be2e80a | 2018-07-13 08:24:26 +0000 | [diff] [blame] | 43 | #include "llvm/CodeGen/RegisterScavenging.h" |
Nico Weber | 432a388 | 2018-04-30 14:59:11 +0000 | [diff] [blame] | 44 | #include "llvm/Config/llvm-config.h" |
Eugene Zelenko | 5df3d89 | 2017-08-24 21:21:39 +0000 | [diff] [blame] | 45 | #include "llvm/IR/DebugInfoMetadata.h" |
| 46 | #include "llvm/IR/DebugLoc.h" |
| 47 | #include "llvm/IR/Function.h" |
| 48 | #include "llvm/IR/Module.h" |
| 49 | #include "llvm/MC/MCRegisterInfo.h" |
| 50 | #include "llvm/Pass.h" |
| 51 | #include "llvm/Support/Casting.h" |
| 52 | #include "llvm/Support/Compiler.h" |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 53 | #include "llvm/Support/Debug.h" |
| 54 | #include "llvm/Support/raw_ostream.h" |
Eugene Zelenko | 5df3d89 | 2017-08-24 21:21:39 +0000 | [diff] [blame] | 55 | #include <algorithm> |
| 56 | #include <cassert> |
| 57 | #include <cstdint> |
| 58 | #include <functional> |
Mehdi Amini | b550cb1 | 2016-04-18 09:17:29 +0000 | [diff] [blame] | 59 | #include <queue> |
Eugene Zelenko | 5df3d89 | 2017-08-24 21:21:39 +0000 | [diff] [blame] | 60 | #include <utility> |
| 61 | #include <vector> |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 62 | |
| 63 | using namespace llvm; |
| 64 | |
Matthias Braun | 1527baa | 2017-05-25 21:26:32 +0000 | [diff] [blame] | 65 | #define DEBUG_TYPE "livedebugvalues" |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 66 | |
| 67 | STATISTIC(NumInserted, "Number of DBG_VALUE instructions inserted"); |
| 68 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 69 | // If @MI is a DBG_VALUE with debug value described by a defined |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 70 | // 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] | 71 | static unsigned isDbgValueDescribedByReg(const MachineInstr &MI) { |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 72 | assert(MI.isDebugValue() && "expected a DBG_VALUE"); |
| 73 | assert(MI.getNumOperands() == 4 && "malformed DBG_VALUE"); |
| 74 | // If location of variable is described using a register (directly |
| 75 | // or indirectly), this register is always a first operand. |
| 76 | return MI.getOperand(0).isReg() ? MI.getOperand(0).getReg() : 0; |
| 77 | } |
| 78 | |
Eugene Zelenko | 5df3d89 | 2017-08-24 21:21:39 +0000 | [diff] [blame] | 79 | namespace { |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 80 | |
Eugene Zelenko | 5df3d89 | 2017-08-24 21:21:39 +0000 | [diff] [blame] | 81 | class LiveDebugValues : public MachineFunctionPass { |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 82 | private: |
| 83 | const TargetRegisterInfo *TRI; |
| 84 | const TargetInstrInfo *TII; |
Wolfgang Pieb | 399dcfa | 2017-02-14 19:08:45 +0000 | [diff] [blame] | 85 | const TargetFrameLowering *TFI; |
Petar Jovanovic | be2e80a | 2018-07-13 08:24:26 +0000 | [diff] [blame] | 86 | BitVector CalleeSavedRegs; |
Adrian Prantl | 7f5866c | 2016-09-28 17:51:14 +0000 | [diff] [blame] | 87 | LexicalScopes LS; |
| 88 | |
| 89 | /// Keeps track of lexical scopes associated with a user value's source |
| 90 | /// location. |
| 91 | class UserValueScopes { |
| 92 | DebugLoc DL; |
| 93 | LexicalScopes &LS; |
| 94 | SmallPtrSet<const MachineBasicBlock *, 4> LBlocks; |
| 95 | |
| 96 | public: |
| 97 | UserValueScopes(DebugLoc D, LexicalScopes &L) : DL(std::move(D)), LS(L) {} |
| 98 | |
| 99 | /// Return true if current scope dominates at least one machine |
| 100 | /// instruction in a given machine basic block. |
| 101 | bool dominates(MachineBasicBlock *MBB) { |
| 102 | if (LBlocks.empty()) |
| 103 | LS.getMachineBasicBlocks(DL, LBlocks); |
| 104 | return LBlocks.count(MBB) != 0 || LS.dominates(DL, MBB); |
| 105 | } |
| 106 | }; |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 107 | |
Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 108 | /// Based on std::pair so it can be used as an index into a DenseMap. |
Eugene Zelenko | 5df3d89 | 2017-08-24 21:21:39 +0000 | [diff] [blame] | 109 | using DebugVariableBase = |
| 110 | std::pair<const DILocalVariable *, const DILocation *>; |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 111 | /// A potentially inlined instance of a variable. |
Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 112 | struct DebugVariable : public DebugVariableBase { |
| 113 | DebugVariable(const DILocalVariable *Var, const DILocation *InlinedAt) |
| 114 | : DebugVariableBase(Var, InlinedAt) {} |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 115 | |
Eugene Zelenko | 5df3d89 | 2017-08-24 21:21:39 +0000 | [diff] [blame] | 116 | const DILocalVariable *getVar() const { return this->first; } |
| 117 | const DILocation *getInlinedAt() const { return this->second; } |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 118 | |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 119 | bool operator<(const DebugVariable &DV) const { |
Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 120 | if (getVar() == DV.getVar()) |
| 121 | return getInlinedAt() < DV.getInlinedAt(); |
| 122 | return getVar() < DV.getVar(); |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 123 | } |
| 124 | }; |
| 125 | |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 126 | /// A pair of debug variable and value location. |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 127 | struct VarLoc { |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 128 | const DebugVariable Var; |
| 129 | const MachineInstr &MI; ///< Only used for cloning a new DBG_VALUE. |
Adrian Prantl | 7f5866c | 2016-09-28 17:51:14 +0000 | [diff] [blame] | 130 | mutable UserValueScopes UVS; |
Eugene Zelenko | 5df3d89 | 2017-08-24 21:21:39 +0000 | [diff] [blame] | 131 | enum { InvalidKind = 0, RegisterKind } Kind = InvalidKind; |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 132 | |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 133 | /// The value location. Stored separately to avoid repeatedly |
| 134 | /// extracting it from MI. |
| 135 | union { |
Adrian Prantl | 359846f | 2017-07-28 23:25:51 +0000 | [diff] [blame] | 136 | uint64_t RegNo; |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 137 | uint64_t Hash; |
| 138 | } Loc; |
| 139 | |
Adrian Prantl | 7f5866c | 2016-09-28 17:51:14 +0000 | [diff] [blame] | 140 | VarLoc(const MachineInstr &MI, LexicalScopes &LS) |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 141 | : Var(MI.getDebugVariable(), MI.getDebugLoc()->getInlinedAt()), MI(MI), |
Eugene Zelenko | 5df3d89 | 2017-08-24 21:21:39 +0000 | [diff] [blame] | 142 | UVS(MI.getDebugLoc(), LS) { |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 143 | static_assert((sizeof(Loc) == sizeof(uint64_t)), |
| 144 | "hash does not cover all members of Loc"); |
| 145 | assert(MI.isDebugValue() && "not a DBG_VALUE"); |
| 146 | assert(MI.getNumOperands() == 4 && "malformed DBG_VALUE"); |
Adrian Prantl | 0069873 | 2016-05-25 22:37:29 +0000 | [diff] [blame] | 147 | if (int RegNo = isDbgValueDescribedByReg(MI)) { |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 148 | Kind = RegisterKind; |
Adrian Prantl | 359846f | 2017-07-28 23:25:51 +0000 | [diff] [blame] | 149 | Loc.RegNo = RegNo; |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 150 | } |
| 151 | } |
| 152 | |
| 153 | /// If this variable is described by a register, return it, |
| 154 | /// otherwise return 0. |
| 155 | unsigned isDescribedByReg() const { |
| 156 | if (Kind == RegisterKind) |
Adrian Prantl | 359846f | 2017-07-28 23:25:51 +0000 | [diff] [blame] | 157 | return Loc.RegNo; |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 158 | return 0; |
| 159 | } |
| 160 | |
Adrian Prantl | 7f5866c | 2016-09-28 17:51:14 +0000 | [diff] [blame] | 161 | /// Determine whether the lexical scope of this value's debug location |
| 162 | /// dominates MBB. |
| 163 | bool dominates(MachineBasicBlock &MBB) const { return UVS.dominates(&MBB); } |
| 164 | |
Aaron Ballman | 615eb47 | 2017-10-15 14:32:27 +0000 | [diff] [blame] | 165 | #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) |
Matthias Braun | 194ded5 | 2017-01-28 06:53:55 +0000 | [diff] [blame] | 166 | LLVM_DUMP_METHOD void dump() const { MI.dump(); } |
| 167 | #endif |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 168 | |
| 169 | bool operator==(const VarLoc &Other) const { |
| 170 | return Var == Other.Var && Loc.Hash == Other.Loc.Hash; |
| 171 | } |
| 172 | |
Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 173 | /// This operator guarantees that VarLocs are sorted by Variable first. |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 174 | bool operator<(const VarLoc &Other) const { |
| 175 | if (Var == Other.Var) |
| 176 | return Loc.Hash < Other.Loc.Hash; |
| 177 | return Var < Other.Var; |
| 178 | } |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 179 | }; |
| 180 | |
Eugene Zelenko | 5df3d89 | 2017-08-24 21:21:39 +0000 | [diff] [blame] | 181 | using VarLocMap = UniqueVector<VarLoc>; |
| 182 | using VarLocSet = SparseBitVector<>; |
| 183 | using VarLocInMBB = SmallDenseMap<const MachineBasicBlock *, VarLocSet>; |
Petar Jovanovic | be2e80a | 2018-07-13 08:24:26 +0000 | [diff] [blame] | 184 | struct TransferDebugPair { |
| 185 | MachineInstr *TransferInst; |
Wolfgang Pieb | 399dcfa | 2017-02-14 19:08:45 +0000 | [diff] [blame] | 186 | MachineInstr *DebugInst; |
| 187 | }; |
Petar Jovanovic | be2e80a | 2018-07-13 08:24:26 +0000 | [diff] [blame] | 188 | using TransferMap = SmallVector<TransferDebugPair, 4>; |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 189 | |
Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 190 | /// This holds the working set of currently open ranges. For fast |
| 191 | /// access, this is done both as a set of VarLocIDs, and a map of |
| 192 | /// DebugVariable to recent VarLocID. Note that a DBG_VALUE ends all |
| 193 | /// previous open ranges for the same variable. |
| 194 | class OpenRangesSet { |
| 195 | VarLocSet VarLocs; |
| 196 | SmallDenseMap<DebugVariableBase, unsigned, 8> Vars; |
| 197 | |
| 198 | public: |
| 199 | const VarLocSet &getVarLocs() const { return VarLocs; } |
| 200 | |
| 201 | /// Terminate all open ranges for Var by removing it from the set. |
| 202 | void erase(DebugVariable Var) { |
| 203 | auto It = Vars.find(Var); |
| 204 | if (It != Vars.end()) { |
| 205 | unsigned ID = It->second; |
| 206 | VarLocs.reset(ID); |
| 207 | Vars.erase(It); |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | /// Terminate all open ranges listed in \c KillSet by removing |
| 212 | /// them from the set. |
| 213 | void erase(const VarLocSet &KillSet, const VarLocMap &VarLocIDs) { |
| 214 | VarLocs.intersectWithComplement(KillSet); |
| 215 | for (unsigned ID : KillSet) |
| 216 | Vars.erase(VarLocIDs[ID].Var); |
| 217 | } |
| 218 | |
| 219 | /// Insert a new range into the set. |
| 220 | void insert(unsigned VarLocID, DebugVariableBase Var) { |
| 221 | VarLocs.set(VarLocID); |
| 222 | Vars.insert({Var, VarLocID}); |
| 223 | } |
| 224 | |
| 225 | /// Empty the set. |
| 226 | void clear() { |
| 227 | VarLocs.clear(); |
| 228 | Vars.clear(); |
| 229 | } |
| 230 | |
| 231 | /// Return whether the set is empty or not. |
| 232 | bool empty() const { |
| 233 | assert(Vars.empty() == VarLocs.empty() && "open ranges are inconsistent"); |
| 234 | return VarLocs.empty(); |
| 235 | } |
| 236 | }; |
| 237 | |
Wolfgang Pieb | 399dcfa | 2017-02-14 19:08:45 +0000 | [diff] [blame] | 238 | bool isSpillInstruction(const MachineInstr &MI, MachineFunction *MF, |
| 239 | unsigned &Reg); |
| 240 | int extractSpillBaseRegAndOffset(const MachineInstr &MI, unsigned &Reg); |
Petar Jovanovic | be2e80a | 2018-07-13 08:24:26 +0000 | [diff] [blame] | 241 | void insertTransferDebugPair(MachineInstr &MI, OpenRangesSet &OpenRanges, |
| 242 | TransferMap &Transfers, VarLocMap &VarLocIDs, |
| 243 | unsigned OldVarID, unsigned NewReg = 0); |
Wolfgang Pieb | 399dcfa | 2017-02-14 19:08:45 +0000 | [diff] [blame] | 244 | |
Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 245 | void transferDebugValue(const MachineInstr &MI, OpenRangesSet &OpenRanges, |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 246 | VarLocMap &VarLocIDs); |
Wolfgang Pieb | 399dcfa | 2017-02-14 19:08:45 +0000 | [diff] [blame] | 247 | void transferSpillInst(MachineInstr &MI, OpenRangesSet &OpenRanges, |
Petar Jovanovic | be2e80a | 2018-07-13 08:24:26 +0000 | [diff] [blame] | 248 | VarLocMap &VarLocIDs, TransferMap &Transfers); |
| 249 | void transferRegisterCopy(MachineInstr &MI, OpenRangesSet &OpenRanges, |
| 250 | VarLocMap &VarLocIDs, TransferMap &Transfers); |
Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 251 | void transferRegisterDef(MachineInstr &MI, OpenRangesSet &OpenRanges, |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 252 | const VarLocMap &VarLocIDs); |
Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 253 | bool transferTerminatorInst(MachineInstr &MI, OpenRangesSet &OpenRanges, |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 254 | VarLocInMBB &OutLocs, const VarLocMap &VarLocIDs); |
Petar Jovanovic | be2e80a | 2018-07-13 08:24:26 +0000 | [diff] [blame] | 255 | bool process(MachineInstr &MI, OpenRangesSet &OpenRanges, |
| 256 | VarLocInMBB &OutLocs, VarLocMap &VarLocIDs, |
| 257 | TransferMap &Transfers, bool transferChanges); |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 258 | |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 259 | bool join(MachineBasicBlock &MBB, VarLocInMBB &OutLocs, VarLocInMBB &InLocs, |
Keith Walker | 83ebef5 | 2016-09-27 16:46:07 +0000 | [diff] [blame] | 260 | const VarLocMap &VarLocIDs, |
| 261 | SmallPtrSet<const MachineBasicBlock *, 16> &Visited); |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 262 | |
| 263 | bool ExtendRanges(MachineFunction &MF); |
| 264 | |
| 265 | public: |
| 266 | static char ID; |
| 267 | |
| 268 | /// Default construct and initialize the pass. |
| 269 | LiveDebugValues(); |
| 270 | |
| 271 | /// Tell the pass manager which passes we depend on and what |
| 272 | /// information we preserve. |
| 273 | void getAnalysisUsage(AnalysisUsage &AU) const override; |
| 274 | |
Derek Schuff | ad154c8 | 2016-03-28 17:05:30 +0000 | [diff] [blame] | 275 | MachineFunctionProperties getRequiredProperties() const override { |
| 276 | return MachineFunctionProperties().set( |
Matthias Braun | 1eb4736 | 2016-08-25 01:27:13 +0000 | [diff] [blame] | 277 | MachineFunctionProperties::Property::NoVRegs); |
Derek Schuff | ad154c8 | 2016-03-28 17:05:30 +0000 | [diff] [blame] | 278 | } |
| 279 | |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 280 | /// Print to ostream with a message. |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 281 | void printVarLocInMBB(const MachineFunction &MF, const VarLocInMBB &V, |
| 282 | const VarLocMap &VarLocIDs, const char *msg, |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 283 | raw_ostream &Out) const; |
| 284 | |
| 285 | /// Calculate the liveness information for the given machine function. |
| 286 | bool runOnMachineFunction(MachineFunction &MF) override; |
| 287 | }; |
Adrian Prantl | 7f5866c | 2016-09-28 17:51:14 +0000 | [diff] [blame] | 288 | |
Eugene Zelenko | 5df3d89 | 2017-08-24 21:21:39 +0000 | [diff] [blame] | 289 | } // end anonymous namespace |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 290 | |
| 291 | //===----------------------------------------------------------------------===// |
| 292 | // Implementation |
| 293 | //===----------------------------------------------------------------------===// |
| 294 | |
| 295 | char LiveDebugValues::ID = 0; |
Eugene Zelenko | 5df3d89 | 2017-08-24 21:21:39 +0000 | [diff] [blame] | 296 | |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 297 | char &llvm::LiveDebugValuesID = LiveDebugValues::ID; |
Eugene Zelenko | 5df3d89 | 2017-08-24 21:21:39 +0000 | [diff] [blame] | 298 | |
Matthias Braun | 1527baa | 2017-05-25 21:26:32 +0000 | [diff] [blame] | 299 | INITIALIZE_PASS(LiveDebugValues, DEBUG_TYPE, "Live DEBUG_VALUE analysis", |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 300 | false, false) |
| 301 | |
| 302 | /// Default construct and initialize the pass. |
| 303 | LiveDebugValues::LiveDebugValues() : MachineFunctionPass(ID) { |
| 304 | initializeLiveDebugValuesPass(*PassRegistry::getPassRegistry()); |
| 305 | } |
| 306 | |
| 307 | /// Tell the pass manager which passes we depend on and what information we |
| 308 | /// preserve. |
| 309 | void LiveDebugValues::getAnalysisUsage(AnalysisUsage &AU) const { |
Matt Arsenault | b1630a1 | 2016-06-08 05:18:01 +0000 | [diff] [blame] | 310 | AU.setPreservesCFG(); |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 311 | MachineFunctionPass::getAnalysisUsage(AU); |
| 312 | } |
| 313 | |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 314 | //===----------------------------------------------------------------------===// |
| 315 | // Debug Range Extension Implementation |
| 316 | //===----------------------------------------------------------------------===// |
| 317 | |
Matthias Braun | 194ded5 | 2017-01-28 06:53:55 +0000 | [diff] [blame] | 318 | #ifndef NDEBUG |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 319 | void LiveDebugValues::printVarLocInMBB(const MachineFunction &MF, |
| 320 | const VarLocInMBB &V, |
| 321 | const VarLocMap &VarLocIDs, |
| 322 | const char *msg, |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 323 | raw_ostream &Out) const { |
Keith Walker | f83a19f | 2016-09-20 16:04:31 +0000 | [diff] [blame] | 324 | Out << '\n' << msg << '\n'; |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 325 | for (const MachineBasicBlock &BB : MF) { |
| 326 | const auto &L = V.lookup(&BB); |
| 327 | Out << "MBB: " << BB.getName() << ":\n"; |
| 328 | for (unsigned VLL : L) { |
| 329 | const VarLoc &VL = VarLocIDs[VLL]; |
Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 330 | Out << " Var: " << VL.Var.getVar()->getName(); |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 331 | Out << " MI: "; |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 332 | VL.dump(); |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 333 | } |
| 334 | } |
| 335 | Out << "\n"; |
| 336 | } |
Matthias Braun | 194ded5 | 2017-01-28 06:53:55 +0000 | [diff] [blame] | 337 | #endif |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 338 | |
Wolfgang Pieb | 399dcfa | 2017-02-14 19:08:45 +0000 | [diff] [blame] | 339 | /// Given a spill instruction, extract the register and offset used to |
| 340 | /// address the spill location in a target independent way. |
| 341 | int LiveDebugValues::extractSpillBaseRegAndOffset(const MachineInstr &MI, |
| 342 | unsigned &Reg) { |
Fangrui Song | f78650a | 2018-07-30 19:41:25 +0000 | [diff] [blame^] | 343 | assert(MI.hasOneMemOperand() && |
Wolfgang Pieb | 399dcfa | 2017-02-14 19:08:45 +0000 | [diff] [blame] | 344 | "Spill instruction does not have exactly one memory operand?"); |
| 345 | auto MMOI = MI.memoperands_begin(); |
| 346 | const PseudoSourceValue *PVal = (*MMOI)->getPseudoValue(); |
| 347 | assert(PVal->kind() == PseudoSourceValue::FixedStack && |
| 348 | "Inconsistent memory operand in spill instruction"); |
| 349 | int FI = cast<FixedStackPseudoSourceValue>(PVal)->getFrameIndex(); |
| 350 | const MachineBasicBlock *MBB = MI.getParent(); |
| 351 | return TFI->getFrameIndexReference(*MBB->getParent(), FI, Reg); |
| 352 | } |
| 353 | |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 354 | /// End all previous ranges related to @MI and start a new range from @MI |
| 355 | /// if it is a DBG_VALUE instr. |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 356 | void LiveDebugValues::transferDebugValue(const MachineInstr &MI, |
Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 357 | OpenRangesSet &OpenRanges, |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 358 | VarLocMap &VarLocIDs) { |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 359 | if (!MI.isDebugValue()) |
| 360 | return; |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 361 | const DILocalVariable *Var = MI.getDebugVariable(); |
| 362 | const DILocation *DebugLoc = MI.getDebugLoc(); |
| 363 | const DILocation *InlinedAt = DebugLoc->getInlinedAt(); |
| 364 | assert(Var->isValidLocationForIntrinsic(DebugLoc) && |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 365 | "Expected inlined-at fields to agree"); |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 366 | |
| 367 | // End all previous ranges of Var. |
Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 368 | DebugVariable V(Var, InlinedAt); |
| 369 | OpenRanges.erase(V); |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 370 | |
| 371 | // Add the VarLoc to OpenRanges from this DBG_VALUE. |
| 372 | // TODO: Currently handles DBG_VALUE which has only reg as location. |
Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 373 | if (isDbgValueDescribedByReg(MI)) { |
Adrian Prantl | 7f5866c | 2016-09-28 17:51:14 +0000 | [diff] [blame] | 374 | VarLoc VL(MI, LS); |
Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 375 | unsigned ID = VarLocIDs.insert(VL); |
| 376 | OpenRanges.insert(ID, VL.Var); |
| 377 | } |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 378 | } |
| 379 | |
Petar Jovanovic | be2e80a | 2018-07-13 08:24:26 +0000 | [diff] [blame] | 380 | /// Create new TransferDebugPair and insert it in \p Transfers. The VarLoc |
| 381 | /// with \p OldVarID should be deleted form \p OpenRanges and replaced with |
| 382 | /// new VarLoc. If \p NewReg is different than default zero value then the |
| 383 | /// new location will be register location created by the copy like instruction, |
| 384 | /// otherwise it is variable's location on the stack. |
| 385 | void LiveDebugValues::insertTransferDebugPair( |
| 386 | MachineInstr &MI, OpenRangesSet &OpenRanges, TransferMap &Transfers, |
| 387 | VarLocMap &VarLocIDs, unsigned OldVarID, unsigned NewReg) { |
| 388 | const MachineInstr *DMI = &VarLocIDs[OldVarID].MI; |
| 389 | MachineFunction *MF = MI.getParent()->getParent(); |
| 390 | MachineInstr *NewDMI; |
| 391 | if (NewReg) { |
| 392 | // Create a DBG_VALUE instruction to describe the Var in its new |
| 393 | // register location. |
| 394 | NewDMI = BuildMI(*MF, DMI->getDebugLoc(), DMI->getDesc(), |
| 395 | DMI->isIndirectDebugValue(), NewReg, |
| 396 | DMI->getDebugVariable(), DMI->getDebugExpression()); |
| 397 | if (DMI->isIndirectDebugValue()) |
| 398 | NewDMI->getOperand(1).setImm(DMI->getOperand(1).getImm()); |
| 399 | LLVM_DEBUG(dbgs() << "Creating DBG_VALUE inst for register copy: "; |
| 400 | NewDMI->print(dbgs(), false, false, false, TII)); |
| 401 | } else { |
| 402 | // Create a DBG_VALUE instruction to describe the Var in its spilled |
| 403 | // location. |
| 404 | unsigned SpillBase; |
| 405 | int SpillOffset = extractSpillBaseRegAndOffset(MI, SpillBase); |
| 406 | auto *SpillExpr = DIExpression::prepend(DMI->getDebugExpression(), |
| 407 | DIExpression::NoDeref, SpillOffset); |
| 408 | NewDMI = BuildMI(*MF, DMI->getDebugLoc(), DMI->getDesc(), true, SpillBase, |
| 409 | DMI->getDebugVariable(), SpillExpr); |
| 410 | LLVM_DEBUG(dbgs() << "Creating DBG_VALUE inst for spill: "; |
| 411 | NewDMI->print(dbgs(), false, false, false, TII)); |
| 412 | } |
| 413 | |
| 414 | // The newly created DBG_VALUE instruction NewDMI must be inserted after |
| 415 | // MI. Keep track of the pairing. |
| 416 | TransferDebugPair MIP = {&MI, NewDMI}; |
| 417 | Transfers.push_back(MIP); |
| 418 | |
| 419 | // End all previous ranges of Var. |
| 420 | OpenRanges.erase(VarLocIDs[OldVarID].Var); |
| 421 | |
| 422 | // Add the VarLoc to OpenRanges. |
| 423 | VarLoc VL(*NewDMI, LS); |
| 424 | unsigned LocID = VarLocIDs.insert(VL); |
| 425 | OpenRanges.insert(LocID, VL.Var); |
| 426 | } |
| 427 | |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 428 | /// A definition of a register may mark the end of a range. |
| 429 | void LiveDebugValues::transferRegisterDef(MachineInstr &MI, |
Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 430 | OpenRangesSet &OpenRanges, |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 431 | const VarLocMap &VarLocIDs) { |
Justin Bogner | fdf9bf4 | 2017-10-10 23:50:49 +0000 | [diff] [blame] | 432 | MachineFunction *MF = MI.getMF(); |
Reid Kleckner | f6f04f8 | 2016-03-25 17:54:46 +0000 | [diff] [blame] | 433 | const TargetLowering *TLI = MF->getSubtarget().getTargetLowering(); |
| 434 | unsigned SP = TLI->getStackPointerRegisterToSaveRestore(); |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 435 | SparseBitVector<> KillSet; |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 436 | for (const MachineOperand &MO : MI.operands()) { |
Adrian Prantl | ea8880b | 2017-03-03 01:08:25 +0000 | [diff] [blame] | 437 | // Determine whether the operand is a register def. Assume that call |
| 438 | // instructions never clobber SP, because some backends (e.g., AArch64) |
| 439 | // never list SP in the regmask. |
Reid Kleckner | f6f04f8 | 2016-03-25 17:54:46 +0000 | [diff] [blame] | 440 | if (MO.isReg() && MO.isDef() && MO.getReg() && |
Adrian Prantl | ea8880b | 2017-03-03 01:08:25 +0000 | [diff] [blame] | 441 | TRI->isPhysicalRegister(MO.getReg()) && |
| 442 | !(MI.isCall() && MO.getReg() == SP)) { |
Reid Kleckner | f6f04f8 | 2016-03-25 17:54:46 +0000 | [diff] [blame] | 443 | // Remove ranges of all aliased registers. |
| 444 | for (MCRegAliasIterator RAI(MO.getReg(), TRI, true); RAI.isValid(); ++RAI) |
Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 445 | for (unsigned ID : OpenRanges.getVarLocs()) |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 446 | if (VarLocIDs[ID].isDescribedByReg() == *RAI) |
| 447 | KillSet.set(ID); |
Reid Kleckner | f6f04f8 | 2016-03-25 17:54:46 +0000 | [diff] [blame] | 448 | } else if (MO.isRegMask()) { |
| 449 | // Remove ranges of all clobbered registers. Register masks don't usually |
| 450 | // list SP as preserved. While the debug info may be off for an |
| 451 | // instruction or two around callee-cleanup calls, transferring the |
| 452 | // DEBUG_VALUE across the call is still a better user experience. |
Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 453 | for (unsigned ID : OpenRanges.getVarLocs()) { |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 454 | unsigned Reg = VarLocIDs[ID].isDescribedByReg(); |
| 455 | if (Reg && Reg != SP && MO.clobbersPhysReg(Reg)) |
| 456 | KillSet.set(ID); |
| 457 | } |
Reid Kleckner | f6f04f8 | 2016-03-25 17:54:46 +0000 | [diff] [blame] | 458 | } |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 459 | } |
Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 460 | OpenRanges.erase(KillSet, VarLocIDs); |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 461 | } |
| 462 | |
Wolfgang Pieb | 399dcfa | 2017-02-14 19:08:45 +0000 | [diff] [blame] | 463 | /// Decide if @MI is a spill instruction and return true if it is. We use 2 |
| 464 | /// criteria to make this decision: |
| 465 | /// - Is this instruction a store to a spill slot? |
| 466 | /// - Is there a register operand that is both used and killed? |
| 467 | /// TODO: Store optimization can fold spills into other stores (including |
| 468 | /// other spills). We do not handle this yet (more than one memory operand). |
| 469 | bool LiveDebugValues::isSpillInstruction(const MachineInstr &MI, |
| 470 | MachineFunction *MF, unsigned &Reg) { |
| 471 | const MachineFrameInfo &FrameInfo = MF->getFrameInfo(); |
| 472 | int FI; |
| 473 | const MachineMemOperand *MMO; |
| 474 | |
Fangrui Song | f78650a | 2018-07-30 19:41:25 +0000 | [diff] [blame^] | 475 | // TODO: Handle multiple stores folded into one. |
Wolfgang Pieb | 399dcfa | 2017-02-14 19:08:45 +0000 | [diff] [blame] | 476 | if (!MI.hasOneMemOperand()) |
| 477 | return false; |
| 478 | |
| 479 | // To identify a spill instruction, use the same criteria as in AsmPrinter. |
| 480 | if (!((TII->isStoreToStackSlotPostFE(MI, FI) || |
| 481 | TII->hasStoreToStackSlot(MI, MMO, FI)) && |
| 482 | FrameInfo.isSpillSlotObjectIndex(FI))) |
| 483 | return false; |
| 484 | |
Petar Jovanovic | 0b464e4 | 2018-01-16 14:46:05 +0000 | [diff] [blame] | 485 | auto isKilledReg = [&](const MachineOperand MO, unsigned &Reg) { |
| 486 | if (!MO.isReg() || !MO.isUse()) { |
| 487 | Reg = 0; |
| 488 | return false; |
| 489 | } |
| 490 | Reg = MO.getReg(); |
| 491 | return MO.isKill(); |
| 492 | }; |
| 493 | |
Wolfgang Pieb | 399dcfa | 2017-02-14 19:08:45 +0000 | [diff] [blame] | 494 | for (const MachineOperand &MO : MI.operands()) { |
Petar Jovanovic | 0b464e4 | 2018-01-16 14:46:05 +0000 | [diff] [blame] | 495 | // In a spill instruction generated by the InlineSpiller the spilled |
| 496 | // register has its kill flag set. |
| 497 | if (isKilledReg(MO, Reg)) |
| 498 | return true; |
| 499 | if (Reg != 0) { |
| 500 | // Check whether next instruction kills the spilled register. |
| 501 | // FIXME: Current solution does not cover search for killed register in |
| 502 | // bundles and instructions further down the chain. |
| 503 | auto NextI = std::next(MI.getIterator()); |
| 504 | // Skip next instruction that points to basic block end iterator. |
| 505 | if (MI.getParent()->end() == NextI) |
| 506 | continue; |
| 507 | unsigned RegNext; |
| 508 | for (const MachineOperand &MONext : NextI->operands()) { |
| 509 | // Return true if we came across the register from the |
| 510 | // previous spill instruction that is killed in NextI. |
| 511 | if (isKilledReg(MONext, RegNext) && RegNext == Reg) |
| 512 | return true; |
| 513 | } |
Wolfgang Pieb | 399dcfa | 2017-02-14 19:08:45 +0000 | [diff] [blame] | 514 | } |
| 515 | } |
Petar Jovanovic | 0b464e4 | 2018-01-16 14:46:05 +0000 | [diff] [blame] | 516 | // Return false if we didn't find spilled register. |
| 517 | return false; |
Wolfgang Pieb | 399dcfa | 2017-02-14 19:08:45 +0000 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | /// A spilled register may indicate that we have to end the current range of |
| 521 | /// a variable and create a new one for the spill location. |
Petar Jovanovic | be2e80a | 2018-07-13 08:24:26 +0000 | [diff] [blame] | 522 | /// We don't want to insert any instructions in process(), so we just create |
| 523 | /// the DBG_VALUE without inserting it and keep track of it in \p Transfers. |
Wolfgang Pieb | 399dcfa | 2017-02-14 19:08:45 +0000 | [diff] [blame] | 524 | /// It will be inserted into the BB when we're done iterating over the |
| 525 | /// instructions. |
| 526 | void LiveDebugValues::transferSpillInst(MachineInstr &MI, |
| 527 | OpenRangesSet &OpenRanges, |
| 528 | VarLocMap &VarLocIDs, |
Petar Jovanovic | be2e80a | 2018-07-13 08:24:26 +0000 | [diff] [blame] | 529 | TransferMap &Transfers) { |
Wolfgang Pieb | 399dcfa | 2017-02-14 19:08:45 +0000 | [diff] [blame] | 530 | unsigned Reg; |
Justin Bogner | fdf9bf4 | 2017-10-10 23:50:49 +0000 | [diff] [blame] | 531 | MachineFunction *MF = MI.getMF(); |
Wolfgang Pieb | 399dcfa | 2017-02-14 19:08:45 +0000 | [diff] [blame] | 532 | if (!isSpillInstruction(MI, MF, Reg)) |
| 533 | return; |
| 534 | |
| 535 | // Check if the register is the location of a debug value. |
| 536 | for (unsigned ID : OpenRanges.getVarLocs()) { |
| 537 | if (VarLocIDs[ID].isDescribedByReg() == Reg) { |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 538 | LLVM_DEBUG(dbgs() << "Spilling Register " << printReg(Reg, TRI) << '(' |
| 539 | << VarLocIDs[ID].Var.getVar()->getName() << ")\n"); |
Petar Jovanovic | be2e80a | 2018-07-13 08:24:26 +0000 | [diff] [blame] | 540 | insertTransferDebugPair(MI, OpenRanges, Transfers, VarLocIDs, ID); |
| 541 | return; |
| 542 | } |
| 543 | } |
| 544 | } |
Wolfgang Pieb | 399dcfa | 2017-02-14 19:08:45 +0000 | [diff] [blame] | 545 | |
Petar Jovanovic | be2e80a | 2018-07-13 08:24:26 +0000 | [diff] [blame] | 546 | /// If \p MI is a register copy instruction, that copies a previously tracked |
| 547 | /// value from one register to another register that is callee saved, we |
| 548 | /// create new DBG_VALUE instruction described with copy destination register. |
| 549 | void LiveDebugValues::transferRegisterCopy(MachineInstr &MI, |
| 550 | OpenRangesSet &OpenRanges, |
| 551 | VarLocMap &VarLocIDs, |
| 552 | TransferMap &Transfers) { |
| 553 | const MachineOperand *SrcRegOp, *DestRegOp; |
Wolfgang Pieb | 399dcfa | 2017-02-14 19:08:45 +0000 | [diff] [blame] | 554 | |
Petar Jovanovic | be2e80a | 2018-07-13 08:24:26 +0000 | [diff] [blame] | 555 | if (!TII->isCopyInstr(MI, SrcRegOp, DestRegOp) || !SrcRegOp->isKill() || |
| 556 | !DestRegOp->isDef()) |
| 557 | return; |
Wolfgang Pieb | 399dcfa | 2017-02-14 19:08:45 +0000 | [diff] [blame] | 558 | |
Petar Jovanovic | be2e80a | 2018-07-13 08:24:26 +0000 | [diff] [blame] | 559 | auto isCalleSavedReg = [&](unsigned Reg) { |
| 560 | for (MCRegAliasIterator RAI(Reg, TRI, true); RAI.isValid(); ++RAI) |
| 561 | if (CalleeSavedRegs.test(*RAI)) |
| 562 | return true; |
| 563 | return false; |
| 564 | }; |
Wolfgang Pieb | 399dcfa | 2017-02-14 19:08:45 +0000 | [diff] [blame] | 565 | |
Petar Jovanovic | be2e80a | 2018-07-13 08:24:26 +0000 | [diff] [blame] | 566 | unsigned SrcReg = SrcRegOp->getReg(); |
| 567 | unsigned DestReg = DestRegOp->getReg(); |
| 568 | |
| 569 | // We want to recognize instructions where destination register is callee |
| 570 | // saved register. If register that could be clobbered by the call is |
| 571 | // included, there would be a great chance that it is going to be clobbered |
| 572 | // soon. It is more likely that previous register location, which is callee |
| 573 | // saved, is going to stay unclobbered longer, even if it is killed. |
| 574 | if (!isCalleSavedReg(DestReg)) |
| 575 | return; |
| 576 | |
| 577 | for (unsigned ID : OpenRanges.getVarLocs()) { |
| 578 | if (VarLocIDs[ID].isDescribedByReg() == SrcReg) { |
| 579 | insertTransferDebugPair(MI, OpenRanges, Transfers, VarLocIDs, ID, |
| 580 | DestReg); |
Wolfgang Pieb | 399dcfa | 2017-02-14 19:08:45 +0000 | [diff] [blame] | 581 | return; |
| 582 | } |
| 583 | } |
| 584 | } |
| 585 | |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 586 | /// Terminate all open ranges at the end of the current basic block. |
Daniel Berlin | ca4d93a | 2016-01-10 03:25:42 +0000 | [diff] [blame] | 587 | bool LiveDebugValues::transferTerminatorInst(MachineInstr &MI, |
Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 588 | OpenRangesSet &OpenRanges, |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 589 | VarLocInMBB &OutLocs, |
| 590 | const VarLocMap &VarLocIDs) { |
Daniel Berlin | ca4d93a | 2016-01-10 03:25:42 +0000 | [diff] [blame] | 591 | bool Changed = false; |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 592 | const MachineBasicBlock *CurMBB = MI.getParent(); |
Petar Jovanovic | e9500ba | 2018-01-08 18:21:15 +0000 | [diff] [blame] | 593 | if (!(MI.isTerminator() || (&MI == &CurMBB->back()))) |
Daniel Berlin | ca4d93a | 2016-01-10 03:25:42 +0000 | [diff] [blame] | 594 | return false; |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 595 | |
| 596 | if (OpenRanges.empty()) |
Daniel Berlin | ca4d93a | 2016-01-10 03:25:42 +0000 | [diff] [blame] | 597 | return false; |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 598 | |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 599 | LLVM_DEBUG(for (unsigned ID |
| 600 | : OpenRanges.getVarLocs()) { |
| 601 | // Copy OpenRanges to OutLocs, if not already present. |
| 602 | dbgs() << "Add to OutLocs: "; |
| 603 | VarLocIDs[ID].dump(); |
| 604 | }); |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 605 | VarLocSet &VLS = OutLocs[CurMBB]; |
Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 606 | Changed = VLS |= OpenRanges.getVarLocs(); |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 607 | OpenRanges.clear(); |
Daniel Berlin | ca4d93a | 2016-01-10 03:25:42 +0000 | [diff] [blame] | 608 | return Changed; |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | /// This routine creates OpenRanges and OutLocs. |
Petar Jovanovic | be2e80a | 2018-07-13 08:24:26 +0000 | [diff] [blame] | 612 | bool LiveDebugValues::process(MachineInstr &MI, OpenRangesSet &OpenRanges, |
| 613 | VarLocInMBB &OutLocs, VarLocMap &VarLocIDs, |
| 614 | TransferMap &Transfers, bool transferChanges) { |
Daniel Berlin | ca4d93a | 2016-01-10 03:25:42 +0000 | [diff] [blame] | 615 | bool Changed = false; |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 616 | transferDebugValue(MI, OpenRanges, VarLocIDs); |
| 617 | transferRegisterDef(MI, OpenRanges, VarLocIDs); |
Petar Jovanovic | be2e80a | 2018-07-13 08:24:26 +0000 | [diff] [blame] | 618 | if (transferChanges) { |
| 619 | transferRegisterCopy(MI, OpenRanges, VarLocIDs, Transfers); |
| 620 | transferSpillInst(MI, OpenRanges, VarLocIDs, Transfers); |
| 621 | } |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 622 | Changed = transferTerminatorInst(MI, OpenRanges, OutLocs, VarLocIDs); |
Daniel Berlin | ca4d93a | 2016-01-10 03:25:42 +0000 | [diff] [blame] | 623 | return Changed; |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | /// This routine joins the analysis results of all incoming edges in @MBB by |
| 627 | /// inserting a new DBG_VALUE instruction at the start of the @MBB - if the same |
| 628 | /// 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] | 629 | bool LiveDebugValues::join(MachineBasicBlock &MBB, VarLocInMBB &OutLocs, |
Keith Walker | 83ebef5 | 2016-09-27 16:46:07 +0000 | [diff] [blame] | 630 | VarLocInMBB &InLocs, const VarLocMap &VarLocIDs, |
| 631 | SmallPtrSet<const MachineBasicBlock *, 16> &Visited) { |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 632 | LLVM_DEBUG(dbgs() << "join MBB: " << MBB.getName() << "\n"); |
Daniel Berlin | ca4d93a | 2016-01-10 03:25:42 +0000 | [diff] [blame] | 633 | bool Changed = false; |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 634 | |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 635 | VarLocSet InLocsT; // Temporary incoming locations. |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 636 | |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 637 | // For all predecessors of this MBB, find the set of VarLocs that |
| 638 | // can be joined. |
Keith Walker | 83ebef5 | 2016-09-27 16:46:07 +0000 | [diff] [blame] | 639 | int NumVisited = 0; |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 640 | for (auto p : MBB.predecessors()) { |
Keith Walker | 83ebef5 | 2016-09-27 16:46:07 +0000 | [diff] [blame] | 641 | // Ignore unvisited predecessor blocks. As we are processing |
| 642 | // the blocks in reverse post-order any unvisited block can |
| 643 | // be considered to not remove any incoming values. |
| 644 | if (!Visited.count(p)) |
| 645 | continue; |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 646 | auto OL = OutLocs.find(p); |
| 647 | // Join is null in case of empty OutLocs from any of the pred. |
| 648 | if (OL == OutLocs.end()) |
Daniel Berlin | ca4d93a | 2016-01-10 03:25:42 +0000 | [diff] [blame] | 649 | return false; |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 650 | |
Keith Walker | 83ebef5 | 2016-09-27 16:46:07 +0000 | [diff] [blame] | 651 | // Just copy over the Out locs to incoming locs for the first visited |
| 652 | // predecessor, and for all other predecessors join the Out locs. |
| 653 | if (!NumVisited) |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 654 | InLocsT = OL->second; |
Keith Walker | 83ebef5 | 2016-09-27 16:46:07 +0000 | [diff] [blame] | 655 | else |
| 656 | InLocsT &= OL->second; |
| 657 | NumVisited++; |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 658 | } |
| 659 | |
Adrian Prantl | 7f5866c | 2016-09-28 17:51:14 +0000 | [diff] [blame] | 660 | // Filter out DBG_VALUES that are out of scope. |
| 661 | VarLocSet KillSet; |
| 662 | for (auto ID : InLocsT) |
| 663 | if (!VarLocIDs[ID].dominates(MBB)) |
| 664 | KillSet.set(ID); |
| 665 | InLocsT.intersectWithComplement(KillSet); |
| 666 | |
Keith Walker | 83ebef5 | 2016-09-27 16:46:07 +0000 | [diff] [blame] | 667 | // As we are processing blocks in reverse post-order we |
| 668 | // should have processed at least one predecessor, unless it |
| 669 | // is the entry block which has no predecessor. |
| 670 | assert((NumVisited || MBB.pred_empty()) && |
| 671 | "Should have processed at least one predecessor"); |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 672 | if (InLocsT.empty()) |
Daniel Berlin | ca4d93a | 2016-01-10 03:25:42 +0000 | [diff] [blame] | 673 | return false; |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 674 | |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 675 | VarLocSet &ILS = InLocs[&MBB]; |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 676 | |
| 677 | // Insert DBG_VALUE instructions, if not already inserted. |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 678 | VarLocSet Diff = InLocsT; |
| 679 | Diff.intersectWithComplement(ILS); |
| 680 | for (auto ID : Diff) { |
| 681 | // This VarLoc is not found in InLocs i.e. it is not yet inserted. So, a |
| 682 | // new range is started for the var from the mbb's beginning by inserting |
Petar Jovanovic | be2e80a | 2018-07-13 08:24:26 +0000 | [diff] [blame] | 683 | // a new DBG_VALUE. process() will end this range however appropriate. |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 684 | const VarLoc &DiffIt = VarLocIDs[ID]; |
| 685 | const MachineInstr *DMI = &DiffIt.MI; |
| 686 | MachineInstr *MI = |
| 687 | BuildMI(MBB, MBB.instr_begin(), DMI->getDebugLoc(), DMI->getDesc(), |
Adrian Prantl | 8b9bb53 | 2017-07-28 23:00:45 +0000 | [diff] [blame] | 688 | DMI->isIndirectDebugValue(), DMI->getOperand(0).getReg(), |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 689 | DMI->getDebugVariable(), DMI->getDebugExpression()); |
| 690 | if (DMI->isIndirectDebugValue()) |
| 691 | MI->getOperand(1).setImm(DMI->getOperand(1).getImm()); |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 692 | LLVM_DEBUG(dbgs() << "Inserted: "; MI->dump();); |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 693 | ILS.set(ID); |
| 694 | ++NumInserted; |
| 695 | Changed = true; |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 696 | } |
Daniel Berlin | ca4d93a | 2016-01-10 03:25:42 +0000 | [diff] [blame] | 697 | return Changed; |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | /// Calculate the liveness information for the given machine function and |
| 701 | /// extend ranges across basic blocks. |
| 702 | bool LiveDebugValues::ExtendRanges(MachineFunction &MF) { |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 703 | LLVM_DEBUG(dbgs() << "\nDebug Range Extension\n"); |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 704 | |
| 705 | bool Changed = false; |
Daniel Berlin | ca4d93a | 2016-01-10 03:25:42 +0000 | [diff] [blame] | 706 | bool OLChanged = false; |
| 707 | bool MBBJoined = false; |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 708 | |
Wolfgang Pieb | 399dcfa | 2017-02-14 19:08:45 +0000 | [diff] [blame] | 709 | VarLocMap VarLocIDs; // Map VarLoc<>unique ID for use in bitvectors. |
Adrian Prantl | 7509d54 | 2016-05-26 21:42:47 +0000 | [diff] [blame] | 710 | OpenRangesSet OpenRanges; // Ranges that are open until end of bb. |
Wolfgang Pieb | 399dcfa | 2017-02-14 19:08:45 +0000 | [diff] [blame] | 711 | VarLocInMBB OutLocs; // Ranges that exist beyond bb. |
| 712 | VarLocInMBB InLocs; // Ranges that are incoming after joining. |
Petar Jovanovic | be2e80a | 2018-07-13 08:24:26 +0000 | [diff] [blame] | 713 | TransferMap Transfers; // DBG_VALUEs associated with spills. |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 714 | |
Daniel Berlin | 7256059 | 2016-01-10 18:08:32 +0000 | [diff] [blame] | 715 | DenseMap<unsigned int, MachineBasicBlock *> OrderToBB; |
| 716 | DenseMap<MachineBasicBlock *, unsigned int> BBToOrder; |
| 717 | std::priority_queue<unsigned int, std::vector<unsigned int>, |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 718 | std::greater<unsigned int>> |
| 719 | Worklist; |
Daniel Berlin | 7256059 | 2016-01-10 18:08:32 +0000 | [diff] [blame] | 720 | std::priority_queue<unsigned int, std::vector<unsigned int>, |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 721 | std::greater<unsigned int>> |
| 722 | Pending; |
| 723 | |
Petar Jovanovic | be2e80a | 2018-07-13 08:24:26 +0000 | [diff] [blame] | 724 | enum : bool { dontTransferChanges = false, transferChanges = true }; |
| 725 | |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 726 | // Initialize every mbb with OutLocs. |
Wolfgang Pieb | 399dcfa | 2017-02-14 19:08:45 +0000 | [diff] [blame] | 727 | // We are not looking at any spill instructions during the initial pass |
| 728 | // over the BBs. The LiveDebugVariables pass has already created DBG_VALUE |
| 729 | // instructions for spills of registers that are known to be user variables |
| 730 | // within the BB in which the spill occurs. |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 731 | for (auto &MBB : MF) |
| 732 | for (auto &MI : MBB) |
Petar Jovanovic | be2e80a | 2018-07-13 08:24:26 +0000 | [diff] [blame] | 733 | process(MI, OpenRanges, OutLocs, VarLocIDs, Transfers, |
| 734 | dontTransferChanges); |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 735 | |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 736 | LLVM_DEBUG(printVarLocInMBB(MF, OutLocs, VarLocIDs, |
| 737 | "OutLocs after initialization", dbgs())); |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 738 | |
Daniel Berlin | 7256059 | 2016-01-10 18:08:32 +0000 | [diff] [blame] | 739 | ReversePostOrderTraversal<MachineFunction *> RPOT(&MF); |
| 740 | unsigned int RPONumber = 0; |
| 741 | for (auto RI = RPOT.begin(), RE = RPOT.end(); RI != RE; ++RI) { |
| 742 | OrderToBB[RPONumber] = *RI; |
| 743 | BBToOrder[*RI] = RPONumber; |
| 744 | Worklist.push(RPONumber); |
| 745 | ++RPONumber; |
| 746 | } |
Daniel Berlin | 7256059 | 2016-01-10 18:08:32 +0000 | [diff] [blame] | 747 | // This is a standard "union of predecessor outs" dataflow problem. |
Petar Jovanovic | be2e80a | 2018-07-13 08:24:26 +0000 | [diff] [blame] | 748 | // To solve it, we perform join() and process() using the two worklist method |
Daniel Berlin | 7256059 | 2016-01-10 18:08:32 +0000 | [diff] [blame] | 749 | // until the ranges converge. |
| 750 | // Ranges have converged when both worklists are empty. |
Keith Walker | 83ebef5 | 2016-09-27 16:46:07 +0000 | [diff] [blame] | 751 | SmallPtrSet<const MachineBasicBlock *, 16> Visited; |
Daniel Berlin | 7256059 | 2016-01-10 18:08:32 +0000 | [diff] [blame] | 752 | while (!Worklist.empty() || !Pending.empty()) { |
| 753 | // We track what is on the pending worklist to avoid inserting the same |
| 754 | // thing twice. We could avoid this with a custom priority queue, but this |
| 755 | // is probably not worth it. |
| 756 | SmallPtrSet<MachineBasicBlock *, 16> OnPending; |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 757 | LLVM_DEBUG(dbgs() << "Processing Worklist\n"); |
Daniel Berlin | 7256059 | 2016-01-10 18:08:32 +0000 | [diff] [blame] | 758 | while (!Worklist.empty()) { |
| 759 | MachineBasicBlock *MBB = OrderToBB[Worklist.top()]; |
| 760 | Worklist.pop(); |
Keith Walker | 83ebef5 | 2016-09-27 16:46:07 +0000 | [diff] [blame] | 761 | MBBJoined = join(*MBB, OutLocs, InLocs, VarLocIDs, Visited); |
| 762 | Visited.insert(MBB); |
Daniel Berlin | 7256059 | 2016-01-10 18:08:32 +0000 | [diff] [blame] | 763 | if (MBBJoined) { |
| 764 | MBBJoined = false; |
| 765 | Changed = true; |
Wolfgang Pieb | 399dcfa | 2017-02-14 19:08:45 +0000 | [diff] [blame] | 766 | // Now that we have started to extend ranges across BBs we need to |
| 767 | // examine spill instructions to see whether they spill registers that |
| 768 | // correspond to user variables. |
Daniel Berlin | 7256059 | 2016-01-10 18:08:32 +0000 | [diff] [blame] | 769 | for (auto &MI : *MBB) |
Petar Jovanovic | be2e80a | 2018-07-13 08:24:26 +0000 | [diff] [blame] | 770 | OLChanged |= process(MI, OpenRanges, OutLocs, VarLocIDs, Transfers, |
| 771 | transferChanges); |
Wolfgang Pieb | 399dcfa | 2017-02-14 19:08:45 +0000 | [diff] [blame] | 772 | |
| 773 | // Add any DBG_VALUE instructions necessitated by spills. |
Petar Jovanovic | be2e80a | 2018-07-13 08:24:26 +0000 | [diff] [blame] | 774 | for (auto &TR : Transfers) |
| 775 | MBB->insertAfter(MachineBasicBlock::iterator(*TR.TransferInst), |
| 776 | TR.DebugInst); |
| 777 | Transfers.clear(); |
Adrian Prantl | 6ee02c7 | 2016-05-25 22:21:12 +0000 | [diff] [blame] | 778 | |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 779 | LLVM_DEBUG(printVarLocInMBB(MF, OutLocs, VarLocIDs, |
| 780 | "OutLocs after propagating", dbgs())); |
| 781 | LLVM_DEBUG(printVarLocInMBB(MF, InLocs, VarLocIDs, |
| 782 | "InLocs after propagating", dbgs())); |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 783 | |
Daniel Berlin | 7256059 | 2016-01-10 18:08:32 +0000 | [diff] [blame] | 784 | if (OLChanged) { |
| 785 | OLChanged = false; |
| 786 | for (auto s : MBB->successors()) |
Benjamin Kramer | 4dea8f5 | 2016-06-17 18:59:41 +0000 | [diff] [blame] | 787 | if (OnPending.insert(s).second) { |
Daniel Berlin | 7256059 | 2016-01-10 18:08:32 +0000 | [diff] [blame] | 788 | Pending.push(BBToOrder[s]); |
| 789 | } |
| 790 | } |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 791 | } |
| 792 | } |
Daniel Berlin | 7256059 | 2016-01-10 18:08:32 +0000 | [diff] [blame] | 793 | Worklist.swap(Pending); |
| 794 | // At this point, pending must be empty, since it was just the empty |
| 795 | // worklist |
| 796 | assert(Pending.empty() && "Pending should be empty"); |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 797 | } |
Daniel Berlin | 7256059 | 2016-01-10 18:08:32 +0000 | [diff] [blame] | 798 | |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 799 | LLVM_DEBUG(printVarLocInMBB(MF, OutLocs, VarLocIDs, "Final OutLocs", dbgs())); |
| 800 | LLVM_DEBUG(printVarLocInMBB(MF, InLocs, VarLocIDs, "Final InLocs", dbgs())); |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 801 | return Changed; |
| 802 | } |
| 803 | |
| 804 | bool LiveDebugValues::runOnMachineFunction(MachineFunction &MF) { |
Matthias Braun | f1caa28 | 2017-12-15 22:22:58 +0000 | [diff] [blame] | 805 | if (!MF.getFunction().getSubprogram()) |
Adrian Prantl | 7f5866c | 2016-09-28 17:51:14 +0000 | [diff] [blame] | 806 | // LiveDebugValues will already have removed all DBG_VALUEs. |
| 807 | return false; |
| 808 | |
Wolfgang Pieb | e018bbd | 2017-07-19 19:36:40 +0000 | [diff] [blame] | 809 | // Skip functions from NoDebug compilation units. |
Matthias Braun | f1caa28 | 2017-12-15 22:22:58 +0000 | [diff] [blame] | 810 | if (MF.getFunction().getSubprogram()->getUnit()->getEmissionKind() == |
Wolfgang Pieb | e018bbd | 2017-07-19 19:36:40 +0000 | [diff] [blame] | 811 | DICompileUnit::NoDebug) |
| 812 | return false; |
| 813 | |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 814 | TRI = MF.getSubtarget().getRegisterInfo(); |
| 815 | TII = MF.getSubtarget().getInstrInfo(); |
Wolfgang Pieb | 399dcfa | 2017-02-14 19:08:45 +0000 | [diff] [blame] | 816 | TFI = MF.getSubtarget().getFrameLowering(); |
Petar Jovanovic | be2e80a | 2018-07-13 08:24:26 +0000 | [diff] [blame] | 817 | TFI->determineCalleeSaves(MF, CalleeSavedRegs, |
| 818 | make_unique<RegScavenger>().get()); |
Adrian Prantl | 7f5866c | 2016-09-28 17:51:14 +0000 | [diff] [blame] | 819 | LS.initialize(MF); |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 820 | |
Adrian Prantl | 7f5866c | 2016-09-28 17:51:14 +0000 | [diff] [blame] | 821 | bool Changed = ExtendRanges(MF); |
Vikram TV | 859ad29 | 2015-12-16 11:09:48 +0000 | [diff] [blame] | 822 | return Changed; |
| 823 | } |