Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 1 | //===- llvm/CodeGen/AsmPrinter/DbgValueHistoryCalculator.cpp --------------===// |
Alexey Samsonov | 414b6fb | 2014-04-30 21:34:11 +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 | #include "DbgValueHistoryCalculator.h" |
Benjamin Kramer | 6bf8af5 | 2014-10-06 15:31:04 +0000 | [diff] [blame] | 11 | #include "llvm/ADT/BitVector.h" |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 12 | #include "llvm/ADT/STLExtras.h" |
Alexey Samsonov | dfcaf9c | 2014-05-20 18:34:54 +0000 | [diff] [blame] | 13 | #include "llvm/ADT/SmallVector.h" |
Alexey Samsonov | 414b6fb | 2014-04-30 21:34:11 +0000 | [diff] [blame] | 14 | #include "llvm/CodeGen/MachineBasicBlock.h" |
| 15 | #include "llvm/CodeGen/MachineFunction.h" |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 16 | #include "llvm/CodeGen/MachineInstr.h" |
| 17 | #include "llvm/CodeGen/MachineOperand.h" |
David Blaikie | b3bde2e | 2017-11-17 01:07:10 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/TargetLowering.h" |
| 19 | #include "llvm/CodeGen/TargetRegisterInfo.h" |
| 20 | #include "llvm/CodeGen/TargetSubtargetInfo.h" |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 21 | #include "llvm/IR/DebugInfoMetadata.h" |
| 22 | #include "llvm/IR/DebugLoc.h" |
| 23 | #include "llvm/MC/MCRegisterInfo.h" |
Alexey Samsonov | 414b6fb | 2014-04-30 21:34:11 +0000 | [diff] [blame] | 24 | #include "llvm/Support/Debug.h" |
Benjamin Kramer | 16132e6 | 2015-03-23 18:07:13 +0000 | [diff] [blame] | 25 | #include "llvm/Support/raw_ostream.h" |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 26 | #include <cassert> |
Alexey Samsonov | dfcaf9c | 2014-05-20 18:34:54 +0000 | [diff] [blame] | 27 | #include <map> |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 28 | #include <utility> |
| 29 | |
Benjamin Kramer | 6bf8af5 | 2014-10-06 15:31:04 +0000 | [diff] [blame] | 30 | using namespace llvm; |
Alexey Samsonov | 414b6fb | 2014-04-30 21:34:11 +0000 | [diff] [blame] | 31 | |
| 32 | #define DEBUG_TYPE "dwarfdebug" |
| 33 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 34 | // If @MI is a DBG_VALUE with debug value described by a |
Alexey Samsonov | dfcaf9c | 2014-05-20 18:34:54 +0000 | [diff] [blame] | 35 | // defined register, returns the number of this register. |
| 36 | // In the other case, returns 0. |
| 37 | static unsigned isDescribedByReg(const MachineInstr &MI) { |
| 38 | assert(MI.isDebugValue()); |
Adrian Prantl | 87b7eb9 | 2014-10-01 18:55:02 +0000 | [diff] [blame] | 39 | assert(MI.getNumOperands() == 4); |
Alexey Samsonov | dfcaf9c | 2014-05-20 18:34:54 +0000 | [diff] [blame] | 40 | // If location of variable is described using a register (directly or |
Dominic Chen | 6ba1965 | 2016-08-11 17:52:40 +0000 | [diff] [blame] | 41 | // indirectly), this register is always a first operand. |
Alexey Samsonov | dfcaf9c | 2014-05-20 18:34:54 +0000 | [diff] [blame] | 42 | return MI.getOperand(0).isReg() ? MI.getOperand(0).getReg() : 0; |
| 43 | } |
| 44 | |
Duncan P. N. Exon Smith | 62e0f45 | 2015-04-15 22:29:27 +0000 | [diff] [blame] | 45 | void DbgValueHistoryMap::startInstrRange(InlinedVariable Var, |
Alexey Samsonov | bb2990d | 2014-05-27 23:09:50 +0000 | [diff] [blame] | 46 | const MachineInstr &MI) { |
| 47 | // Instruction range should start with a DBG_VALUE instruction for the |
| 48 | // variable. |
Adrian Prantl | 87b7eb9 | 2014-10-01 18:55:02 +0000 | [diff] [blame] | 49 | assert(MI.isDebugValue() && "not a DBG_VALUE"); |
Alexey Samsonov | bb2990d | 2014-05-27 23:09:50 +0000 | [diff] [blame] | 50 | auto &Ranges = VarInstrRanges[Var]; |
| 51 | if (!Ranges.empty() && Ranges.back().second == nullptr && |
Duncan P. N. Exon Smith | fd8cc23 | 2016-02-27 20:01:33 +0000 | [diff] [blame] | 52 | Ranges.back().first->isIdenticalTo(MI)) { |
Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 53 | LLVM_DEBUG(dbgs() << "Coalescing identical DBG_VALUE entries:\n" |
| 54 | << "\t" << Ranges.back().first << "\t" << MI << "\n"); |
Alexey Samsonov | bb2990d | 2014-05-27 23:09:50 +0000 | [diff] [blame] | 55 | return; |
| 56 | } |
| 57 | Ranges.push_back(std::make_pair(&MI, nullptr)); |
| 58 | } |
| 59 | |
Duncan P. N. Exon Smith | 62e0f45 | 2015-04-15 22:29:27 +0000 | [diff] [blame] | 60 | void DbgValueHistoryMap::endInstrRange(InlinedVariable Var, |
Alexey Samsonov | bb2990d | 2014-05-27 23:09:50 +0000 | [diff] [blame] | 61 | const MachineInstr &MI) { |
| 62 | auto &Ranges = VarInstrRanges[Var]; |
| 63 | // Verify that the current instruction range is not yet closed. |
| 64 | assert(!Ranges.empty() && Ranges.back().second == nullptr); |
| 65 | // For now, instruction ranges are not allowed to cross basic block |
| 66 | // boundaries. |
| 67 | assert(Ranges.back().first->getParent() == MI.getParent()); |
| 68 | Ranges.back().second = &MI; |
| 69 | } |
| 70 | |
Duncan P. N. Exon Smith | 62e0f45 | 2015-04-15 22:29:27 +0000 | [diff] [blame] | 71 | unsigned DbgValueHistoryMap::getRegisterForVar(InlinedVariable Var) const { |
Alexey Samsonov | bb2990d | 2014-05-27 23:09:50 +0000 | [diff] [blame] | 72 | const auto &I = VarInstrRanges.find(Var); |
| 73 | if (I == VarInstrRanges.end()) |
| 74 | return 0; |
| 75 | const auto &Ranges = I->second; |
| 76 | if (Ranges.empty() || Ranges.back().second != nullptr) |
| 77 | return 0; |
| 78 | return isDescribedByReg(*Ranges.back().first); |
| 79 | } |
| 80 | |
| 81 | namespace { |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 82 | |
Alexey Samsonov | bb2990d | 2014-05-27 23:09:50 +0000 | [diff] [blame] | 83 | // Maps physreg numbers to the variables they describe. |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 84 | using InlinedVariable = DbgValueHistoryMap::InlinedVariable; |
| 85 | using RegDescribedVarsMap = std::map<unsigned, SmallVector<InlinedVariable, 1>>; |
| 86 | |
| 87 | } // end anonymous namespace |
Alexey Samsonov | bb2990d | 2014-05-27 23:09:50 +0000 | [diff] [blame] | 88 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 89 | // Claim that @Var is not described by @RegNo anymore. |
Duncan P. N. Exon Smith | 62e0f45 | 2015-04-15 22:29:27 +0000 | [diff] [blame] | 90 | static void dropRegDescribedVar(RegDescribedVarsMap &RegVars, unsigned RegNo, |
| 91 | InlinedVariable Var) { |
Alexey Samsonov | dfcaf9c | 2014-05-20 18:34:54 +0000 | [diff] [blame] | 92 | const auto &I = RegVars.find(RegNo); |
| 93 | assert(RegNo != 0U && I != RegVars.end()); |
| 94 | auto &VarSet = I->second; |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 95 | const auto &VarPos = llvm::find(VarSet, Var); |
Alexey Samsonov | dfcaf9c | 2014-05-20 18:34:54 +0000 | [diff] [blame] | 96 | assert(VarPos != VarSet.end()); |
| 97 | VarSet.erase(VarPos); |
| 98 | // Don't keep empty sets in a map to keep it as small as possible. |
| 99 | if (VarSet.empty()) |
| 100 | RegVars.erase(I); |
| 101 | } |
| 102 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 103 | // Claim that @Var is now described by @RegNo. |
Duncan P. N. Exon Smith | 62e0f45 | 2015-04-15 22:29:27 +0000 | [diff] [blame] | 104 | static void addRegDescribedVar(RegDescribedVarsMap &RegVars, unsigned RegNo, |
| 105 | InlinedVariable Var) { |
Alexey Samsonov | dfcaf9c | 2014-05-20 18:34:54 +0000 | [diff] [blame] | 106 | assert(RegNo != 0U); |
Alexey Samsonov | bb2990d | 2014-05-27 23:09:50 +0000 | [diff] [blame] | 107 | auto &VarSet = RegVars[RegNo]; |
David Majnemer | 0d955d0 | 2016-08-11 22:21:41 +0000 | [diff] [blame] | 108 | assert(!is_contained(VarSet, Var)); |
Alexey Samsonov | bb2990d | 2014-05-27 23:09:50 +0000 | [diff] [blame] | 109 | VarSet.push_back(Var); |
Alexey Samsonov | dfcaf9c | 2014-05-20 18:34:54 +0000 | [diff] [blame] | 110 | } |
| 111 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 112 | // Terminate the location range for variables described by register at |
Benjamin Kramer | 6bf8af5 | 2014-10-06 15:31:04 +0000 | [diff] [blame] | 113 | // @I by inserting @ClobberingInstr to their history. |
| 114 | static void clobberRegisterUses(RegDescribedVarsMap &RegVars, |
| 115 | RegDescribedVarsMap::iterator I, |
| 116 | DbgValueHistoryMap &HistMap, |
| 117 | const MachineInstr &ClobberingInstr) { |
| 118 | // Iterate over all variables described by this register and add this |
| 119 | // instruction to their history, clobbering it. |
| 120 | for (const auto &Var : I->second) |
| 121 | HistMap.endInstrRange(Var, ClobberingInstr); |
| 122 | RegVars.erase(I); |
| 123 | } |
| 124 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 125 | // Terminate the location range for variables described by register |
Alexey Samsonov | dfcaf9c | 2014-05-20 18:34:54 +0000 | [diff] [blame] | 126 | // @RegNo by inserting @ClobberingInstr to their history. |
| 127 | static void clobberRegisterUses(RegDescribedVarsMap &RegVars, unsigned RegNo, |
| 128 | DbgValueHistoryMap &HistMap, |
| 129 | const MachineInstr &ClobberingInstr) { |
| 130 | const auto &I = RegVars.find(RegNo); |
| 131 | if (I == RegVars.end()) |
| 132 | return; |
Benjamin Kramer | 6bf8af5 | 2014-10-06 15:31:04 +0000 | [diff] [blame] | 133 | clobberRegisterUses(RegVars, I, HistMap, ClobberingInstr); |
Alexey Samsonov | dfcaf9c | 2014-05-20 18:34:54 +0000 | [diff] [blame] | 134 | } |
| 135 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 136 | // Returns the first instruction in @MBB which corresponds to |
Alexey Samsonov | 8000e27 | 2014-06-09 21:53:47 +0000 | [diff] [blame] | 137 | // the function epilogue, or nullptr if @MBB doesn't contain an epilogue. |
| 138 | static const MachineInstr *getFirstEpilogueInst(const MachineBasicBlock &MBB) { |
| 139 | auto LastMI = MBB.getLastNonDebugInstr(); |
| 140 | if (LastMI == MBB.end() || !LastMI->isReturn()) |
| 141 | return nullptr; |
| 142 | // Assume that epilogue starts with instruction having the same debug location |
| 143 | // as the return instruction. |
| 144 | DebugLoc LastLoc = LastMI->getDebugLoc(); |
| 145 | auto Res = LastMI; |
Duncan P. N. Exon Smith | 1872096 | 2016-09-11 18:51:28 +0000 | [diff] [blame] | 146 | for (MachineBasicBlock::const_reverse_iterator I = LastMI.getReverse(), |
| 147 | E = MBB.rend(); |
Benjamin Kramer | 6bf8af5 | 2014-10-06 15:31:04 +0000 | [diff] [blame] | 148 | I != E; ++I) { |
Alexey Samsonov | 8000e27 | 2014-06-09 21:53:47 +0000 | [diff] [blame] | 149 | if (I->getDebugLoc() != LastLoc) |
Duncan P. N. Exon Smith | 5bff511 | 2016-07-08 19:31:47 +0000 | [diff] [blame] | 150 | return &*Res; |
Benjamin Kramer | 6bf8af5 | 2014-10-06 15:31:04 +0000 | [diff] [blame] | 151 | Res = &*I; |
Alexey Samsonov | 8000e27 | 2014-06-09 21:53:47 +0000 | [diff] [blame] | 152 | } |
| 153 | // If all instructions have the same debug location, assume whole MBB is |
| 154 | // an epilogue. |
Duncan P. N. Exon Smith | 5bff511 | 2016-07-08 19:31:47 +0000 | [diff] [blame] | 155 | return &*MBB.begin(); |
Alexey Samsonov | 8000e27 | 2014-06-09 21:53:47 +0000 | [diff] [blame] | 156 | } |
| 157 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 158 | // Collect registers that are modified in the function body (their |
Adrian Prantl | 364d131 | 2014-08-06 18:41:24 +0000 | [diff] [blame] | 159 | // contents is changed outside of the prologue and epilogue). |
Alexey Samsonov | 8000e27 | 2014-06-09 21:53:47 +0000 | [diff] [blame] | 160 | static void collectChangingRegs(const MachineFunction *MF, |
| 161 | const TargetRegisterInfo *TRI, |
Benjamin Kramer | 6bf8af5 | 2014-10-06 15:31:04 +0000 | [diff] [blame] | 162 | BitVector &Regs) { |
Alexey Samsonov | 8000e27 | 2014-06-09 21:53:47 +0000 | [diff] [blame] | 163 | for (const auto &MBB : *MF) { |
| 164 | auto FirstEpilogueInst = getFirstEpilogueInst(MBB); |
Adrian Prantl | e2d6375 | 2014-08-06 18:41:19 +0000 | [diff] [blame] | 165 | |
Alexey Samsonov | 8000e27 | 2014-06-09 21:53:47 +0000 | [diff] [blame] | 166 | for (const auto &MI : MBB) { |
Reid Kleckner | f6f04f8 | 2016-03-25 17:54:46 +0000 | [diff] [blame] | 167 | // Avoid looking at prologue or epilogue instructions. |
Adrian Prantl | e2d6375 | 2014-08-06 18:41:19 +0000 | [diff] [blame] | 168 | if (&MI == FirstEpilogueInst) |
| 169 | break; |
Reid Kleckner | f6f04f8 | 2016-03-25 17:54:46 +0000 | [diff] [blame] | 170 | if (MI.getFlag(MachineInstr::FrameSetup)) |
| 171 | continue; |
| 172 | |
| 173 | // Look for register defs and register masks. Register masks are |
| 174 | // typically on calls and they clobber everything not in the mask. |
| 175 | for (const MachineOperand &MO : MI.operands()) { |
Dominic Chen | 6ba1965 | 2016-08-11 17:52:40 +0000 | [diff] [blame] | 176 | // Skip virtual registers since they are handled by the parent. |
| 177 | if (MO.isReg() && MO.isDef() && MO.getReg() && |
| 178 | !TRI->isVirtualRegister(MO.getReg())) { |
Reid Kleckner | f6f04f8 | 2016-03-25 17:54:46 +0000 | [diff] [blame] | 179 | for (MCRegAliasIterator AI(MO.getReg(), TRI, true); AI.isValid(); |
| 180 | ++AI) |
| 181 | Regs.set(*AI); |
| 182 | } else if (MO.isRegMask()) { |
| 183 | Regs.setBitsNotInMask(MO.getRegMask()); |
| 184 | } |
| 185 | } |
Alexey Samsonov | 8000e27 | 2014-06-09 21:53:47 +0000 | [diff] [blame] | 186 | } |
| 187 | } |
Alexey Samsonov | dfcaf9c | 2014-05-20 18:34:54 +0000 | [diff] [blame] | 188 | } |
| 189 | |
Benjamin Kramer | 6bf8af5 | 2014-10-06 15:31:04 +0000 | [diff] [blame] | 190 | void llvm::calculateDbgValueHistory(const MachineFunction *MF, |
| 191 | const TargetRegisterInfo *TRI, |
| 192 | DbgValueHistoryMap &Result) { |
| 193 | BitVector ChangingRegs(TRI->getNumRegs()); |
Alexey Samsonov | 8000e27 | 2014-06-09 21:53:47 +0000 | [diff] [blame] | 194 | collectChangingRegs(MF, TRI, ChangingRegs); |
Alexey Samsonov | 414b6fb | 2014-04-30 21:34:11 +0000 | [diff] [blame] | 195 | |
Reid Kleckner | f6f04f8 | 2016-03-25 17:54:46 +0000 | [diff] [blame] | 196 | const TargetLowering *TLI = MF->getSubtarget().getTargetLowering(); |
| 197 | unsigned SP = TLI->getStackPointerRegisterToSaveRestore(); |
Alexey Samsonov | 8000e27 | 2014-06-09 21:53:47 +0000 | [diff] [blame] | 198 | RegDescribedVarsMap RegVars; |
Alexey Samsonov | dfcaf9c | 2014-05-20 18:34:54 +0000 | [diff] [blame] | 199 | for (const auto &MBB : *MF) { |
| 200 | for (const auto &MI : MBB) { |
Shiva Chen | 801bf7e | 2018-05-09 02:42:00 +0000 | [diff] [blame] | 201 | if (!MI.isDebugInstr()) { |
Alexey Samsonov | dfcaf9c | 2014-05-20 18:34:54 +0000 | [diff] [blame] | 202 | // Not a DBG_VALUE instruction. It may clobber registers which describe |
| 203 | // some variables. |
Reid Kleckner | f6f04f8 | 2016-03-25 17:54:46 +0000 | [diff] [blame] | 204 | for (const MachineOperand &MO : MI.operands()) { |
| 205 | if (MO.isReg() && MO.isDef() && MO.getReg()) { |
Adrian Prantl | d9cd4d5 | 2017-06-01 21:14:58 +0000 | [diff] [blame] | 206 | // Ignore call instructions that claim to clobber SP. The AArch64 |
| 207 | // backend does this for aggregate function arguments. |
| 208 | if (MI.isCall() && MO.getReg() == SP) |
| 209 | continue; |
Dominic Chen | 6ba1965 | 2016-08-11 17:52:40 +0000 | [diff] [blame] | 210 | // If this is a virtual register, only clobber it since it doesn't |
| 211 | // have aliases. |
| 212 | if (TRI->isVirtualRegister(MO.getReg())) |
| 213 | clobberRegisterUses(RegVars, MO.getReg(), Result, MI); |
Reid Kleckner | f6f04f8 | 2016-03-25 17:54:46 +0000 | [diff] [blame] | 214 | // If this is a register def operand, it may end a debug value |
| 215 | // range. |
Dominic Chen | 6ba1965 | 2016-08-11 17:52:40 +0000 | [diff] [blame] | 216 | else { |
| 217 | for (MCRegAliasIterator AI(MO.getReg(), TRI, true); AI.isValid(); |
| 218 | ++AI) |
| 219 | if (ChangingRegs.test(*AI)) |
| 220 | clobberRegisterUses(RegVars, *AI, Result, MI); |
| 221 | } |
Reid Kleckner | f6f04f8 | 2016-03-25 17:54:46 +0000 | [diff] [blame] | 222 | } else if (MO.isRegMask()) { |
| 223 | // If this is a register mask operand, clobber all debug values in |
| 224 | // non-CSRs. |
Francis Visoiu Mistrih | b52e036 | 2017-05-17 01:07:53 +0000 | [diff] [blame] | 225 | for (unsigned I : ChangingRegs.set_bits()) { |
Reid Kleckner | f6f04f8 | 2016-03-25 17:54:46 +0000 | [diff] [blame] | 226 | // Don't consider SP to be clobbered by register masks. |
| 227 | if (unsigned(I) != SP && TRI->isPhysicalRegister(I) && |
| 228 | MO.clobbersPhysReg(I)) { |
| 229 | clobberRegisterUses(RegVars, I, Result, MI); |
| 230 | } |
| 231 | } |
| 232 | } |
| 233 | } |
Alexey Samsonov | dfcaf9c | 2014-05-20 18:34:54 +0000 | [diff] [blame] | 234 | continue; |
Alexey Samsonov | 414b6fb | 2014-04-30 21:34:11 +0000 | [diff] [blame] | 235 | } |
Alexey Samsonov | 414b6fb | 2014-04-30 21:34:11 +0000 | [diff] [blame] | 236 | |
Shiva Chen | 801bf7e | 2018-05-09 02:42:00 +0000 | [diff] [blame] | 237 | // Skip DBG_LABEL instructions. |
| 238 | if (MI.isDebugLabel()) |
| 239 | continue; |
| 240 | |
Alexey Samsonov | f0e0cca | 2014-05-27 22:35:00 +0000 | [diff] [blame] | 241 | assert(MI.getNumOperands() > 1 && "Invalid DBG_VALUE instruction!"); |
Adrian Prantl | b141683 | 2014-08-01 22:11:58 +0000 | [diff] [blame] | 242 | // Use the base variable (without any DW_OP_piece expressions) |
| 243 | // as index into History. The full variables including the |
| 244 | // piece expressions are attached to the MI. |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 245 | const DILocalVariable *RawVar = MI.getDebugVariable(); |
Duncan P. N. Exon Smith | 62e0f45 | 2015-04-15 22:29:27 +0000 | [diff] [blame] | 246 | assert(RawVar->isValidLocationForIntrinsic(MI.getDebugLoc()) && |
Duncan P. N. Exon Smith | 3bef6a3 | 2015-04-03 19:20:26 +0000 | [diff] [blame] | 247 | "Expected inlined-at fields to agree"); |
Duncan P. N. Exon Smith | 78a9527 | 2015-04-16 22:12:59 +0000 | [diff] [blame] | 248 | InlinedVariable Var(RawVar, MI.getDebugLoc()->getInlinedAt()); |
Alexey Samsonov | 414b6fb | 2014-04-30 21:34:11 +0000 | [diff] [blame] | 249 | |
Alexey Samsonov | bb2990d | 2014-05-27 23:09:50 +0000 | [diff] [blame] | 250 | if (unsigned PrevReg = Result.getRegisterForVar(Var)) |
| 251 | dropRegDescribedVar(RegVars, PrevReg, Var); |
Alexey Samsonov | dfcaf9c | 2014-05-20 18:34:54 +0000 | [diff] [blame] | 252 | |
Alexey Samsonov | bb2990d | 2014-05-27 23:09:50 +0000 | [diff] [blame] | 253 | Result.startInstrRange(Var, MI); |
| 254 | |
| 255 | if (unsigned NewReg = isDescribedByReg(MI)) |
| 256 | addRegDescribedVar(RegVars, NewReg, Var); |
Alexey Samsonov | 414b6fb | 2014-04-30 21:34:11 +0000 | [diff] [blame] | 257 | } |
Alexey Samsonov | dfcaf9c | 2014-05-20 18:34:54 +0000 | [diff] [blame] | 258 | |
| 259 | // Make sure locations for register-described variables are valid only |
| 260 | // until the end of the basic block (unless it's the last basic block, in |
| 261 | // which case let their liveness run off to the end of the function). |
Benjamin Kramer | 6bf8af5 | 2014-10-06 15:31:04 +0000 | [diff] [blame] | 262 | if (!MBB.empty() && &MBB != &MF->back()) { |
| 263 | for (auto I = RegVars.begin(), E = RegVars.end(); I != E;) { |
| 264 | auto CurElem = I++; // CurElem can be erased below. |
Dominic Chen | 6ba1965 | 2016-08-11 17:52:40 +0000 | [diff] [blame] | 265 | if (TRI->isVirtualRegister(CurElem->first) || |
| 266 | ChangingRegs.test(CurElem->first)) |
Benjamin Kramer | 6bf8af5 | 2014-10-06 15:31:04 +0000 | [diff] [blame] | 267 | clobberRegisterUses(RegVars, CurElem, Result, MBB.back()); |
| 268 | } |
Alexey Samsonov | 8000e27 | 2014-06-09 21:53:47 +0000 | [diff] [blame] | 269 | } |
Alexey Samsonov | 414b6fb | 2014-04-30 21:34:11 +0000 | [diff] [blame] | 270 | } |
| 271 | } |
Vedant Kumar | 7224c08 | 2018-06-01 22:33:15 +0000 | [diff] [blame] | 272 | |
| 273 | #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) |
| 274 | LLVM_DUMP_METHOD void DbgValueHistoryMap::dump() const { |
| 275 | dbgs() << "DbgValueHistoryMap:\n"; |
| 276 | for (const auto &VarRangePair : *this) { |
| 277 | const InlinedVariable &Var = VarRangePair.first; |
| 278 | const InstrRanges &Ranges = VarRangePair.second; |
| 279 | |
| 280 | const DILocalVariable *LocalVar = Var.first; |
| 281 | const DILocation *Location = Var.second; |
| 282 | |
| 283 | dbgs() << " - " << LocalVar->getName() << " at "; |
| 284 | |
| 285 | if (Location) |
| 286 | dbgs() << Location->getFilename() << ":" << Location->getLine() << ":" |
| 287 | << Location->getColumn(); |
| 288 | else |
| 289 | dbgs() << "<unknown location>"; |
| 290 | |
| 291 | dbgs() << " --\n"; |
| 292 | |
| 293 | for (const InstrRange &Range : Ranges) { |
| 294 | dbgs() << " Begin: " << *Range.first; |
| 295 | if (Range.second) |
| 296 | dbgs() << " End : " << *Range.second; |
| 297 | dbgs() << "\n"; |
| 298 | } |
| 299 | } |
| 300 | } |
| 301 | #endif |