blob: 065a9e2b4987f47b52e6fea1ded01c4a031e3e87 [file] [log] [blame]
Eugene Zelenko5df3d892017-08-24 21:21:39 +00001//===- LiveDebugValues.cpp - Tracking Debug Value MIs ---------------------===//
Vikram TV859ad292015-12-16 11:09:48 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Vikram TV859ad292015-12-16 11:09:48 +00006//
7//===----------------------------------------------------------------------===//
8///
9/// This pass implements a data flow analysis that propagates debug location
Jeremy Morse67443c32019-08-21 09:22:31 +000010/// information by inserting additional DBG_VALUE insts into the machine
11/// instruction stream. Before running, each DBG_VALUE inst corresponds to a
12/// source assignment of a variable. Afterwards, a DBG_VALUE inst specifies a
13/// variable location for the current basic block (see SourceLevelDebugging.rst).
Vikram TV859ad292015-12-16 11:09:48 +000014///
15/// This is a separate pass from DbgValueHistoryCalculator to facilitate
16/// testing and improve modularity.
17///
Jeremy Morse67443c32019-08-21 09:22:31 +000018/// Each variable location is represented by a VarLoc object that identifies the
19/// source variable, its current machine-location, and the DBG_VALUE inst that
20/// specifies the location. Each VarLoc is indexed in the (function-scope)
21/// VarLocMap, giving each VarLoc a unique index. Rather than operate directly
22/// on machine locations, the dataflow analysis in this pass identifies
23/// locations by their index in the VarLocMap, meaning all the variable
24/// locations in a block can be described by a sparse vector of VarLocMap
25/// indexes.
26///
Vikram TV859ad292015-12-16 11:09:48 +000027//===----------------------------------------------------------------------===//
28
Eugene Zelenko5df3d892017-08-24 21:21:39 +000029#include "llvm/ADT/DenseMap.h"
Daniel Berlin72560592016-01-10 18:08:32 +000030#include "llvm/ADT/PostOrderIterator.h"
31#include "llvm/ADT/SmallPtrSet.h"
Jeremy Morsebf2b2f02019-06-13 12:51:57 +000032#include "llvm/ADT/SmallSet.h"
Eugene Zelenko5df3d892017-08-24 21:21:39 +000033#include "llvm/ADT/SmallVector.h"
Adrian Prantl6ee02c72016-05-25 22:21:12 +000034#include "llvm/ADT/SparseBitVector.h"
Mehdi Aminib550cb12016-04-18 09:17:29 +000035#include "llvm/ADT/Statistic.h"
Adrian Prantl6ee02c72016-05-25 22:21:12 +000036#include "llvm/ADT/UniqueVector.h"
Adrian Prantl7f5866c2016-09-28 17:51:14 +000037#include "llvm/CodeGen/LexicalScopes.h"
Eugene Zelenko5df3d892017-08-24 21:21:39 +000038#include "llvm/CodeGen/MachineBasicBlock.h"
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +000039#include "llvm/CodeGen/MachineFrameInfo.h"
Vikram TV859ad292015-12-16 11:09:48 +000040#include "llvm/CodeGen/MachineFunction.h"
41#include "llvm/CodeGen/MachineFunctionPass.h"
Eugene Zelenko5df3d892017-08-24 21:21:39 +000042#include "llvm/CodeGen/MachineInstr.h"
Vikram TV859ad292015-12-16 11:09:48 +000043#include "llvm/CodeGen/MachineInstrBuilder.h"
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +000044#include "llvm/CodeGen/MachineMemOperand.h"
Eugene Zelenko5df3d892017-08-24 21:21:39 +000045#include "llvm/CodeGen/MachineOperand.h"
46#include "llvm/CodeGen/PseudoSourceValue.h"
Wolfgang Pieb90d856c2019-02-04 20:42:45 +000047#include "llvm/CodeGen/RegisterScavenging.h"
David Blaikie3f833ed2017-11-08 01:01:31 +000048#include "llvm/CodeGen/TargetFrameLowering.h"
49#include "llvm/CodeGen/TargetInstrInfo.h"
David Blaikieb3bde2e2017-11-17 01:07:10 +000050#include "llvm/CodeGen/TargetLowering.h"
Djordje Todorovic12aca5d2019-07-09 08:36:34 +000051#include "llvm/CodeGen/TargetPassConfig.h"
David Blaikieb3bde2e2017-11-17 01:07:10 +000052#include "llvm/CodeGen/TargetRegisterInfo.h"
53#include "llvm/CodeGen/TargetSubtargetInfo.h"
Nico Weber432a3882018-04-30 14:59:11 +000054#include "llvm/Config/llvm-config.h"
Wolfgang Pieb90d856c2019-02-04 20:42:45 +000055#include "llvm/IR/DIBuilder.h"
Eugene Zelenko5df3d892017-08-24 21:21:39 +000056#include "llvm/IR/DebugInfoMetadata.h"
57#include "llvm/IR/DebugLoc.h"
58#include "llvm/IR/Function.h"
59#include "llvm/IR/Module.h"
60#include "llvm/MC/MCRegisterInfo.h"
61#include "llvm/Pass.h"
62#include "llvm/Support/Casting.h"
63#include "llvm/Support/Compiler.h"
Vikram TV859ad292015-12-16 11:09:48 +000064#include "llvm/Support/Debug.h"
65#include "llvm/Support/raw_ostream.h"
Eugene Zelenko5df3d892017-08-24 21:21:39 +000066#include <algorithm>
67#include <cassert>
68#include <cstdint>
69#include <functional>
Mehdi Aminib550cb12016-04-18 09:17:29 +000070#include <queue>
Jeremy Morsebf2b2f02019-06-13 12:51:57 +000071#include <tuple>
Eugene Zelenko5df3d892017-08-24 21:21:39 +000072#include <utility>
73#include <vector>
Vikram TV859ad292015-12-16 11:09:48 +000074
75using namespace llvm;
76
Matthias Braun1527baa2017-05-25 21:26:32 +000077#define DEBUG_TYPE "livedebugvalues"
Vikram TV859ad292015-12-16 11:09:48 +000078
79STATISTIC(NumInserted, "Number of DBG_VALUE instructions inserted");
Jeremy Morse0ae54982019-08-23 16:33:42 +000080STATISTIC(NumRemoved, "Number of DBG_VALUE instructions removed");
Vikram TV859ad292015-12-16 11:09:48 +000081
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000082// If @MI is a DBG_VALUE with debug value described by a defined
Adrian Prantl6ee02c72016-05-25 22:21:12 +000083// register, returns the number of this register. In the other case, returns 0.
Matt Arsenaulte3a676e2019-06-24 15:50:29 +000084static Register isDbgValueDescribedByReg(const MachineInstr &MI) {
Adrian Prantl6ee02c72016-05-25 22:21:12 +000085 assert(MI.isDebugValue() && "expected a DBG_VALUE");
86 assert(MI.getNumOperands() == 4 && "malformed DBG_VALUE");
87 // If location of variable is described using a register (directly
88 // or indirectly), this register is always a first operand.
Matt Arsenaulte3a676e2019-06-24 15:50:29 +000089 return MI.getOperand(0).isReg() ? MI.getOperand(0).getReg() : Register();
Adrian Prantl6ee02c72016-05-25 22:21:12 +000090}
91
David Stenberg4fec44c2019-11-13 10:36:13 +010092/// If \p Op is a stack or frame register return true, otherwise return false.
93/// This is used to avoid basing the debug entry values on the registers, since
94/// we do not support it at the moment.
95static bool isRegOtherThanSPAndFP(const MachineOperand &Op,
96 const MachineInstr &MI,
97 const TargetRegisterInfo *TRI) {
98 if (!Op.isReg())
99 return false;
100
101 const MachineFunction *MF = MI.getParent()->getParent();
102 const TargetLowering *TLI = MF->getSubtarget().getTargetLowering();
103 unsigned SP = TLI->getStackPointerRegisterToSaveRestore();
104 Register FP = TRI->getFrameRegister(*MF);
105 Register Reg = Op.getReg();
106
107 return Reg && Reg != SP && Reg != FP;
108}
109
Eugene Zelenko5df3d892017-08-24 21:21:39 +0000110namespace {
Vikram TV859ad292015-12-16 11:09:48 +0000111
David Stenberg5e646ff2019-11-13 10:37:53 +0100112using DefinedRegsSet = SmallSet<Register, 32>;
113
Eugene Zelenko5df3d892017-08-24 21:21:39 +0000114class LiveDebugValues : public MachineFunctionPass {
Vikram TV859ad292015-12-16 11:09:48 +0000115private:
116 const TargetRegisterInfo *TRI;
117 const TargetInstrInfo *TII;
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000118 const TargetFrameLowering *TFI;
Petar Jovanovicbe2e80a2018-07-13 08:24:26 +0000119 BitVector CalleeSavedRegs;
Adrian Prantl7f5866c2016-09-28 17:51:14 +0000120 LexicalScopes LS;
121
Wolfgang Pieb90d856c2019-02-04 20:42:45 +0000122 enum struct TransferKind { TransferCopy, TransferSpill, TransferRestore };
123
Adrian Prantl7f5866c2016-09-28 17:51:14 +0000124 /// Keeps track of lexical scopes associated with a user value's source
125 /// location.
126 class UserValueScopes {
127 DebugLoc DL;
128 LexicalScopes &LS;
129 SmallPtrSet<const MachineBasicBlock *, 4> LBlocks;
130
131 public:
132 UserValueScopes(DebugLoc D, LexicalScopes &L) : DL(std::move(D)), LS(L) {}
133
134 /// Return true if current scope dominates at least one machine
135 /// instruction in a given machine basic block.
136 bool dominates(MachineBasicBlock *MBB) {
137 if (LBlocks.empty())
138 LS.getMachineBasicBlocks(DL, LBlocks);
139 return LBlocks.count(MBB) != 0 || LS.dominates(DL, MBB);
140 }
141 };
Vikram TV859ad292015-12-16 11:09:48 +0000142
Jeremy Morsebf2b2f02019-06-13 12:51:57 +0000143 using FragmentInfo = DIExpression::FragmentInfo;
144 using OptFragmentInfo = Optional<DIExpression::FragmentInfo>;
Vikram TV859ad292015-12-16 11:09:48 +0000145
Jeremy Morsebf2b2f02019-06-13 12:51:57 +0000146 /// Storage for identifying a potentially inlined instance of a variable,
147 /// or a fragment thereof.
148 class DebugVariable {
149 const DILocalVariable *Variable;
150 OptFragmentInfo Fragment;
151 const DILocation *InlinedAt;
Vikram TV859ad292015-12-16 11:09:48 +0000152
Jeremy Morsebf2b2f02019-06-13 12:51:57 +0000153 /// Fragment that will overlap all other fragments. Used as default when
154 /// caller demands a fragment.
155 static const FragmentInfo DefaultFragment;
156
157 public:
158 DebugVariable(const DILocalVariable *Var, OptFragmentInfo &&FragmentInfo,
159 const DILocation *InlinedAt)
160 : Variable(Var), Fragment(FragmentInfo), InlinedAt(InlinedAt) {}
161
162 DebugVariable(const DILocalVariable *Var, OptFragmentInfo &FragmentInfo,
163 const DILocation *InlinedAt)
164 : Variable(Var), Fragment(FragmentInfo), InlinedAt(InlinedAt) {}
165
166 DebugVariable(const DILocalVariable *Var, const DIExpression *DIExpr,
167 const DILocation *InlinedAt)
168 : DebugVariable(Var, DIExpr->getFragmentInfo(), InlinedAt) {}
169
170 DebugVariable(const MachineInstr &MI)
171 : DebugVariable(MI.getDebugVariable(),
172 MI.getDebugExpression()->getFragmentInfo(),
173 MI.getDebugLoc()->getInlinedAt()) {}
174
175 const DILocalVariable *getVar() const { return Variable; }
176 const OptFragmentInfo &getFragment() const { return Fragment; }
177 const DILocation *getInlinedAt() const { return InlinedAt; }
178
179 const FragmentInfo getFragmentDefault() const {
180 return Fragment.getValueOr(DefaultFragment);
181 }
182
183 static bool isFragmentDefault(FragmentInfo &F) {
184 return F == DefaultFragment;
185 }
186
187 bool operator==(const DebugVariable &Other) const {
188 return std::tie(Variable, Fragment, InlinedAt) ==
189 std::tie(Other.Variable, Other.Fragment, Other.InlinedAt);
190 }
191
192 bool operator<(const DebugVariable &Other) const {
193 return std::tie(Variable, Fragment, InlinedAt) <
194 std::tie(Other.Variable, Other.Fragment, Other.InlinedAt);
Vikram TV859ad292015-12-16 11:09:48 +0000195 }
196 };
197
Jeremy Morsebf2b2f02019-06-13 12:51:57 +0000198 friend struct llvm::DenseMapInfo<DebugVariable>;
199
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000200 /// A pair of debug variable and value location.
Vikram TV859ad292015-12-16 11:09:48 +0000201 struct VarLoc {
Wolfgang Pieb90d856c2019-02-04 20:42:45 +0000202 // The location at which a spilled variable resides. It consists of a
203 // register and an offset.
204 struct SpillLoc {
205 unsigned SpillBase;
206 int SpillOffset;
207 bool operator==(const SpillLoc &Other) const {
208 return SpillBase == Other.SpillBase && SpillOffset == Other.SpillOffset;
209 }
210 };
211
Jeremy Morse337a7cb2019-09-04 11:09:05 +0000212 /// Identity of the variable at this location.
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000213 const DebugVariable Var;
Jeremy Morse337a7cb2019-09-04 11:09:05 +0000214
215 /// The expression applied to this location.
216 const DIExpression *Expr;
217
218 /// DBG_VALUE to clone var/expr information from if this location
219 /// is moved.
220 const MachineInstr &MI;
221
Adrian Prantl7f5866c2016-09-28 17:51:14 +0000222 mutable UserValueScopes UVS;
Wolfgang Pieb90d856c2019-02-04 20:42:45 +0000223 enum VarLocKind {
224 InvalidKind = 0,
225 RegisterKind,
Jeremy Morsebcff4172019-06-10 15:23:46 +0000226 SpillLocKind,
Djordje Todorovic12aca5d2019-07-09 08:36:34 +0000227 ImmediateKind,
228 EntryValueKind
Wolfgang Pieb90d856c2019-02-04 20:42:45 +0000229 } Kind = InvalidKind;
Vikram TV859ad292015-12-16 11:09:48 +0000230
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000231 /// The value location. Stored separately to avoid repeatedly
232 /// extracting it from MI.
233 union {
Adrian Prantl359846f2017-07-28 23:25:51 +0000234 uint64_t RegNo;
Wolfgang Pieb90d856c2019-02-04 20:42:45 +0000235 SpillLoc SpillLocation;
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000236 uint64_t Hash;
Jeremy Morsebcff4172019-06-10 15:23:46 +0000237 int64_t Immediate;
238 const ConstantFP *FPImm;
239 const ConstantInt *CImm;
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000240 } Loc;
241
Jeremy Morse61800a72019-10-04 10:53:47 +0000242 VarLoc(const MachineInstr &MI, LexicalScopes &LS)
Jeremy Morse337a7cb2019-09-04 11:09:05 +0000243 : Var(MI), Expr(MI.getDebugExpression()), MI(MI),
244 UVS(MI.getDebugLoc(), LS) {
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000245 static_assert((sizeof(Loc) == sizeof(uint64_t)),
246 "hash does not cover all members of Loc");
247 assert(MI.isDebugValue() && "not a DBG_VALUE");
248 assert(MI.getNumOperands() == 4 && "malformed DBG_VALUE");
Adrian Prantl00698732016-05-25 22:37:29 +0000249 if (int RegNo = isDbgValueDescribedByReg(MI)) {
Djordje Todorovic12aca5d2019-07-09 08:36:34 +0000250 Kind = MI.isDebugEntryValue() ? EntryValueKind : RegisterKind;
Adrian Prantl359846f2017-07-28 23:25:51 +0000251 Loc.RegNo = RegNo;
Jeremy Morsebcff4172019-06-10 15:23:46 +0000252 } else if (MI.getOperand(0).isImm()) {
253 Kind = ImmediateKind;
254 Loc.Immediate = MI.getOperand(0).getImm();
255 } else if (MI.getOperand(0).isFPImm()) {
256 Kind = ImmediateKind;
257 Loc.FPImm = MI.getOperand(0).getFPImm();
258 } else if (MI.getOperand(0).isCImm()) {
259 Kind = ImmediateKind;
260 Loc.CImm = MI.getOperand(0).getCImm();
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000261 }
Djordje Todorovic12aca5d2019-07-09 08:36:34 +0000262 assert((Kind != ImmediateKind || !MI.isDebugEntryValue()) &&
263 "entry values must be register locations");
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000264 }
265
Jeremy Morse61800a72019-10-04 10:53:47 +0000266 /// Take the variable and machine-location in DBG_VALUE MI, and build an
267 /// entry location using the given expression.
268 static VarLoc CreateEntryLoc(const MachineInstr &MI, LexicalScopes &LS,
269 const DIExpression *EntryExpr) {
270 VarLoc VL(MI, LS);
271 VL.Kind = EntryValueKind;
272 VL.Expr = EntryExpr;
273 return VL;
Wolfgang Pieb90d856c2019-02-04 20:42:45 +0000274 }
275
Jeremy Morse61800a72019-10-04 10:53:47 +0000276 /// Copy the register location in DBG_VALUE MI, updating the register to
277 /// be NewReg.
278 static VarLoc CreateCopyLoc(const MachineInstr &MI, LexicalScopes &LS,
279 unsigned NewReg) {
280 VarLoc VL(MI, LS);
281 assert(VL.Kind == RegisterKind);
282 VL.Loc.RegNo = NewReg;
283 return VL;
284 }
285
286 /// Take the variable described by DBG_VALUE MI, and create a VarLoc
287 /// locating it in the specified spill location.
288 static VarLoc CreateSpillLoc(const MachineInstr &MI, unsigned SpillBase,
289 int SpillOffset, LexicalScopes &LS) {
290 VarLoc VL(MI, LS);
291 assert(VL.Kind == RegisterKind);
292 VL.Kind = SpillLocKind;
293 VL.Loc.SpillLocation = {SpillBase, SpillOffset};
294 return VL;
295 }
296
297 /// Create a DBG_VALUE representing this VarLoc in the given function.
298 /// Copies variable-specific information such as DILocalVariable and
299 /// inlining information from the original DBG_VALUE instruction, which may
300 /// have been several transfers ago.
301 MachineInstr *BuildDbgValue(MachineFunction &MF) const {
302 const DebugLoc &DbgLoc = MI.getDebugLoc();
303 bool Indirect = MI.isIndirectDebugValue();
304 const auto &IID = MI.getDesc();
305 const DILocalVariable *Var = MI.getDebugVariable();
306 const DIExpression *DIExpr = MI.getDebugExpression();
307
308 switch (Kind) {
309 case EntryValueKind:
310 // An entry value is a register location -- but with an updated
311 // expression.
312 return BuildMI(MF, DbgLoc, IID, Indirect, Loc.RegNo, Var, Expr);
313 case RegisterKind:
314 // Register locations are like the source DBG_VALUE, but with the
315 // register number from this VarLoc.
316 return BuildMI(MF, DbgLoc, IID, Indirect, Loc.RegNo, Var, DIExpr);
317 case SpillLocKind: {
318 // Spills are indirect DBG_VALUEs, with a base register and offset.
319 // Use the original DBG_VALUEs expression to build the spilt location
320 // on top of. FIXME: spill locations created before this pass runs
321 // are not recognized, and not handled here.
322 auto *SpillExpr = DIExpression::prepend(
323 DIExpr, DIExpression::ApplyOffset, Loc.SpillLocation.SpillOffset);
324 unsigned Base = Loc.SpillLocation.SpillBase;
325 return BuildMI(MF, DbgLoc, IID, true, Base, Var, SpillExpr);
326 }
327 case ImmediateKind: {
328 MachineOperand MO = MI.getOperand(0);
329 return BuildMI(MF, DbgLoc, IID, Indirect, MO, Var, DIExpr);
330 }
331 case InvalidKind:
332 llvm_unreachable("Tried to produce DBG_VALUE for invalid VarLoc");
333 }
Simon Pilgrim84f5cd72019-10-04 12:45:27 +0000334 llvm_unreachable("Unrecognized LiveDebugValues.VarLoc.Kind enum");
Jeremy Morse61800a72019-10-04 10:53:47 +0000335 }
336
337 /// Is the Loc field a constant or constant object?
Jeremy Morsebcff4172019-06-10 15:23:46 +0000338 bool isConstant() const { return Kind == ImmediateKind; }
339
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000340 /// If this variable is described by a register, return it,
341 /// otherwise return 0.
342 unsigned isDescribedByReg() const {
343 if (Kind == RegisterKind)
Adrian Prantl359846f2017-07-28 23:25:51 +0000344 return Loc.RegNo;
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000345 return 0;
346 }
347
Adrian Prantl7f5866c2016-09-28 17:51:14 +0000348 /// Determine whether the lexical scope of this value's debug location
349 /// dominates MBB.
350 bool dominates(MachineBasicBlock &MBB) const { return UVS.dominates(&MBB); }
351
Aaron Ballman615eb472017-10-15 14:32:27 +0000352#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Jeremy Morse61800a72019-10-04 10:53:47 +0000353 // TRI can be null.
354 void dump(const TargetRegisterInfo *TRI, raw_ostream &Out = dbgs()) const {
355 dbgs() << "VarLoc(";
356 switch (Kind) {
357 case RegisterKind:
358 case EntryValueKind:
359 dbgs() << printReg(Loc.RegNo, TRI);
360 break;
361 case SpillLocKind:
362 dbgs() << printReg(Loc.SpillLocation.SpillBase, TRI);
363 dbgs() << "[" << Loc.SpillLocation.SpillOffset << "]";
364 break;
365 case ImmediateKind:
366 dbgs() << Loc.Immediate;
367 break;
368 case InvalidKind:
369 llvm_unreachable("Invalid VarLoc in dump method");
370 }
371
372 dbgs() << ", \"" << Var.getVar()->getName() << "\", " << *Expr << ", ";
373 if (Var.getInlinedAt())
374 dbgs() << "!" << Var.getInlinedAt()->getMetadataID() << ")\n";
375 else
376 dbgs() << "(null))\n";
377 }
Matthias Braun194ded52017-01-28 06:53:55 +0000378#endif
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000379
380 bool operator==(const VarLoc &Other) const {
Jeremy Morsebcff4172019-06-10 15:23:46 +0000381 return Kind == Other.Kind && Var == Other.Var &&
Jeremy Morse337a7cb2019-09-04 11:09:05 +0000382 Loc.Hash == Other.Loc.Hash && Expr == Other.Expr;
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000383 }
384
Adrian Prantl7509d542016-05-26 21:42:47 +0000385 /// This operator guarantees that VarLocs are sorted by Variable first.
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000386 bool operator<(const VarLoc &Other) const {
Jeremy Morse337a7cb2019-09-04 11:09:05 +0000387 return std::tie(Var, Kind, Loc.Hash, Expr) <
388 std::tie(Other.Var, Other.Kind, Other.Loc.Hash, Other.Expr);
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000389 }
Vikram TV859ad292015-12-16 11:09:48 +0000390 };
391
Djordje Todorovic12aca5d2019-07-09 08:36:34 +0000392 using DebugParamMap = SmallDenseMap<const DILocalVariable *, MachineInstr *>;
Eugene Zelenko5df3d892017-08-24 21:21:39 +0000393 using VarLocMap = UniqueVector<VarLoc>;
394 using VarLocSet = SparseBitVector<>;
395 using VarLocInMBB = SmallDenseMap<const MachineBasicBlock *, VarLocSet>;
Petar Jovanovicbe2e80a2018-07-13 08:24:26 +0000396 struct TransferDebugPair {
Jeremy Morse61800a72019-10-04 10:53:47 +0000397 MachineInstr *TransferInst; /// Instruction where this transfer occurs.
398 unsigned LocationID; /// Location number for the transfer dest.
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000399 };
Petar Jovanovicbe2e80a2018-07-13 08:24:26 +0000400 using TransferMap = SmallVector<TransferDebugPair, 4>;
Vikram TV859ad292015-12-16 11:09:48 +0000401
Jeremy Morsebf2b2f02019-06-13 12:51:57 +0000402 // Types for recording sets of variable fragments that overlap. For a given
403 // local variable, we record all other fragments of that variable that could
404 // overlap it, to reduce search time.
405 using FragmentOfVar =
406 std::pair<const DILocalVariable *, DIExpression::FragmentInfo>;
407 using OverlapMap =
408 DenseMap<FragmentOfVar, SmallVector<DIExpression::FragmentInfo, 1>>;
409
410 // Helper while building OverlapMap, a map of all fragments seen for a given
411 // DILocalVariable.
412 using VarToFragments =
413 DenseMap<const DILocalVariable *, SmallSet<FragmentInfo, 4>>;
414
Adrian Prantl7509d542016-05-26 21:42:47 +0000415 /// This holds the working set of currently open ranges. For fast
416 /// access, this is done both as a set of VarLocIDs, and a map of
417 /// DebugVariable to recent VarLocID. Note that a DBG_VALUE ends all
418 /// previous open ranges for the same variable.
419 class OpenRangesSet {
420 VarLocSet VarLocs;
Jeremy Morsebf2b2f02019-06-13 12:51:57 +0000421 SmallDenseMap<DebugVariable, unsigned, 8> Vars;
422 OverlapMap &OverlappingFragments;
Adrian Prantl7509d542016-05-26 21:42:47 +0000423
424 public:
Jeremy Morsebf2b2f02019-06-13 12:51:57 +0000425 OpenRangesSet(OverlapMap &_OLapMap) : OverlappingFragments(_OLapMap) {}
426
Adrian Prantl7509d542016-05-26 21:42:47 +0000427 const VarLocSet &getVarLocs() const { return VarLocs; }
428
429 /// Terminate all open ranges for Var by removing it from the set.
Jeremy Morsebf2b2f02019-06-13 12:51:57 +0000430 void erase(DebugVariable Var);
Adrian Prantl7509d542016-05-26 21:42:47 +0000431
432 /// Terminate all open ranges listed in \c KillSet by removing
433 /// them from the set.
434 void erase(const VarLocSet &KillSet, const VarLocMap &VarLocIDs) {
435 VarLocs.intersectWithComplement(KillSet);
436 for (unsigned ID : KillSet)
437 Vars.erase(VarLocIDs[ID].Var);
438 }
439
440 /// Insert a new range into the set.
Jeremy Morsebf2b2f02019-06-13 12:51:57 +0000441 void insert(unsigned VarLocID, DebugVariable Var) {
Adrian Prantl7509d542016-05-26 21:42:47 +0000442 VarLocs.set(VarLocID);
443 Vars.insert({Var, VarLocID});
444 }
445
Jeremy Morse67443c32019-08-21 09:22:31 +0000446 /// Insert a set of ranges.
447 void insertFromLocSet(const VarLocSet &ToLoad, const VarLocMap &Map) {
448 for (unsigned Id : ToLoad) {
449 const VarLoc &Var = Map[Id];
450 insert(Id, Var.Var);
451 }
452 }
453
Adrian Prantl7509d542016-05-26 21:42:47 +0000454 /// Empty the set.
455 void clear() {
456 VarLocs.clear();
457 Vars.clear();
458 }
459
460 /// Return whether the set is empty or not.
461 bool empty() const {
462 assert(Vars.empty() == VarLocs.empty() && "open ranges are inconsistent");
463 return VarLocs.empty();
464 }
465 };
466
Jeremy Morse5d9cd3b2019-09-06 10:08:22 +0000467 /// Tests whether this instruction is a spill to a stack location.
468 bool isSpillInstruction(const MachineInstr &MI, MachineFunction *MF);
469
470 /// Decide if @MI is a spill instruction and return true if it is. We use 2
471 /// criteria to make this decision:
472 /// - Is this instruction a store to a spill slot?
473 /// - Is there a register operand that is both used and killed?
474 /// TODO: Store optimization can fold spills into other stores (including
475 /// other spills). We do not handle this yet (more than one memory operand).
476 bool isLocationSpill(const MachineInstr &MI, MachineFunction *MF,
477 unsigned &Reg);
478
David Stenberg4fec44c2019-11-13 10:36:13 +0100479 /// Returns true if the given machine instruction is a debug value which we
480 /// can emit entry values for.
481 ///
482 /// Currently, we generate debug entry values only for parameters that are
483 /// unmodified throughout the function and located in a register.
David Stenberg5e646ff2019-11-13 10:37:53 +0100484 bool isEntryValueCandidate(const MachineInstr &MI,
485 const DefinedRegsSet &Regs) const;
David Stenberg4fec44c2019-11-13 10:36:13 +0100486
Wolfgang Pieb90d856c2019-02-04 20:42:45 +0000487 /// If a given instruction is identified as a spill, return the spill location
488 /// and set \p Reg to the spilled register.
489 Optional<VarLoc::SpillLoc> isRestoreInstruction(const MachineInstr &MI,
490 MachineFunction *MF,
491 unsigned &Reg);
492 /// Given a spill instruction, extract the register and offset used to
493 /// address the spill location in a target independent way.
494 VarLoc::SpillLoc extractSpillBaseRegAndOffset(const MachineInstr &MI);
Petar Jovanovicbe2e80a2018-07-13 08:24:26 +0000495 void insertTransferDebugPair(MachineInstr &MI, OpenRangesSet &OpenRanges,
496 TransferMap &Transfers, VarLocMap &VarLocIDs,
Wolfgang Pieb90d856c2019-02-04 20:42:45 +0000497 unsigned OldVarID, TransferKind Kind,
498 unsigned NewReg = 0);
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000499
Adrian Prantl7509d542016-05-26 21:42:47 +0000500 void transferDebugValue(const MachineInstr &MI, OpenRangesSet &OpenRanges,
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000501 VarLocMap &VarLocIDs);
Wolfgang Pieb90d856c2019-02-04 20:42:45 +0000502 void transferSpillOrRestoreInst(MachineInstr &MI, OpenRangesSet &OpenRanges,
503 VarLocMap &VarLocIDs, TransferMap &Transfers);
Djordje Todorovic12aca5d2019-07-09 08:36:34 +0000504 void emitEntryValues(MachineInstr &MI, OpenRangesSet &OpenRanges,
505 VarLocMap &VarLocIDs, TransferMap &Transfers,
506 DebugParamMap &DebugEntryVals,
507 SparseBitVector<> &KillSet);
Petar Jovanovicbe2e80a2018-07-13 08:24:26 +0000508 void transferRegisterCopy(MachineInstr &MI, OpenRangesSet &OpenRanges,
509 VarLocMap &VarLocIDs, TransferMap &Transfers);
Adrian Prantl7509d542016-05-26 21:42:47 +0000510 void transferRegisterDef(MachineInstr &MI, OpenRangesSet &OpenRanges,
Djordje Todorovic12aca5d2019-07-09 08:36:34 +0000511 VarLocMap &VarLocIDs, TransferMap &Transfers,
512 DebugParamMap &DebugEntryVals);
Jeremy Morse67443c32019-08-21 09:22:31 +0000513 bool transferTerminator(MachineBasicBlock *MBB, OpenRangesSet &OpenRanges,
514 VarLocInMBB &OutLocs, const VarLocMap &VarLocIDs);
Nikola Prica441ad622019-05-27 13:51:30 +0000515
Jeremy Morse67443c32019-08-21 09:22:31 +0000516 void process(MachineInstr &MI, OpenRangesSet &OpenRanges,
Djordje Todorovic8c99a542019-10-24 10:08:43 +0200517 VarLocMap &VarLocIDs, TransferMap &Transfers,
518 DebugParamMap &DebugEntryVals);
Vikram TV859ad292015-12-16 11:09:48 +0000519
Jeremy Morsebf2b2f02019-06-13 12:51:57 +0000520 void accumulateFragmentMap(MachineInstr &MI, VarToFragments &SeenFragments,
521 OverlapMap &OLapMap);
522
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000523 bool join(MachineBasicBlock &MBB, VarLocInMBB &OutLocs, VarLocInMBB &InLocs,
Keith Walker83ebef52016-09-27 16:46:07 +0000524 const VarLocMap &VarLocIDs,
Vedant Kumar8c466682018-10-05 21:44:15 +0000525 SmallPtrSet<const MachineBasicBlock *, 16> &Visited,
Jeremy Morse67443c32019-08-21 09:22:31 +0000526 SmallPtrSetImpl<const MachineBasicBlock *> &ArtificialBlocks,
527 VarLocInMBB &PendingInLocs);
528
529 /// Create DBG_VALUE insts for inlocs that have been propagated but
530 /// had their instruction creation deferred.
531 void flushPendingLocs(VarLocInMBB &PendingInLocs, VarLocMap &VarLocIDs);
Vikram TV859ad292015-12-16 11:09:48 +0000532
533 bool ExtendRanges(MachineFunction &MF);
534
535public:
536 static char ID;
537
538 /// Default construct and initialize the pass.
539 LiveDebugValues();
540
541 /// Tell the pass manager which passes we depend on and what
542 /// information we preserve.
543 void getAnalysisUsage(AnalysisUsage &AU) const override;
544
Derek Schuffad154c82016-03-28 17:05:30 +0000545 MachineFunctionProperties getRequiredProperties() const override {
546 return MachineFunctionProperties().set(
Matthias Braun1eb47362016-08-25 01:27:13 +0000547 MachineFunctionProperties::Property::NoVRegs);
Derek Schuffad154c82016-03-28 17:05:30 +0000548 }
549
Vikram TV859ad292015-12-16 11:09:48 +0000550 /// Print to ostream with a message.
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000551 void printVarLocInMBB(const MachineFunction &MF, const VarLocInMBB &V,
552 const VarLocMap &VarLocIDs, const char *msg,
Vikram TV859ad292015-12-16 11:09:48 +0000553 raw_ostream &Out) const;
554
555 /// Calculate the liveness information for the given machine function.
556 bool runOnMachineFunction(MachineFunction &MF) override;
557};
Adrian Prantl7f5866c2016-09-28 17:51:14 +0000558
Eugene Zelenko5df3d892017-08-24 21:21:39 +0000559} // end anonymous namespace
Vikram TV859ad292015-12-16 11:09:48 +0000560
Jeremy Morsebf2b2f02019-06-13 12:51:57 +0000561namespace llvm {
562
563template <> struct DenseMapInfo<LiveDebugValues::DebugVariable> {
564 using DV = LiveDebugValues::DebugVariable;
565 using OptFragmentInfo = LiveDebugValues::OptFragmentInfo;
566 using FragmentInfo = LiveDebugValues::FragmentInfo;
567
568 // Empty key: no key should be generated that has no DILocalVariable.
569 static inline DV getEmptyKey() {
570 return DV(nullptr, OptFragmentInfo(), nullptr);
571 }
572
573 // Difference in tombstone is that the Optional is meaningful
574 static inline DV getTombstoneKey() {
575 return DV(nullptr, OptFragmentInfo({0, 0}), nullptr);
576 }
577
578 static unsigned getHashValue(const DV &D) {
579 unsigned HV = 0;
580 const OptFragmentInfo &Fragment = D.getFragment();
581 if (Fragment)
582 HV = DenseMapInfo<FragmentInfo>::getHashValue(*Fragment);
583
584 return hash_combine(D.getVar(), HV, D.getInlinedAt());
585 }
586
587 static bool isEqual(const DV &A, const DV &B) { return A == B; }
588};
589
David Stenberg1278a192019-06-13 14:02:55 +0000590} // namespace llvm
Jeremy Morsebf2b2f02019-06-13 12:51:57 +0000591
Vikram TV859ad292015-12-16 11:09:48 +0000592//===----------------------------------------------------------------------===//
593// Implementation
594//===----------------------------------------------------------------------===//
595
Jeremy Morsebf2b2f02019-06-13 12:51:57 +0000596const DIExpression::FragmentInfo
597 LiveDebugValues::DebugVariable::DefaultFragment = {
598 std::numeric_limits<uint64_t>::max(),
599 std::numeric_limits<uint64_t>::min()};
600
Vikram TV859ad292015-12-16 11:09:48 +0000601char LiveDebugValues::ID = 0;
Eugene Zelenko5df3d892017-08-24 21:21:39 +0000602
Vikram TV859ad292015-12-16 11:09:48 +0000603char &llvm::LiveDebugValuesID = LiveDebugValues::ID;
Eugene Zelenko5df3d892017-08-24 21:21:39 +0000604
Matthias Braun1527baa2017-05-25 21:26:32 +0000605INITIALIZE_PASS(LiveDebugValues, DEBUG_TYPE, "Live DEBUG_VALUE analysis",
Vikram TV859ad292015-12-16 11:09:48 +0000606 false, false)
607
608/// Default construct and initialize the pass.
609LiveDebugValues::LiveDebugValues() : MachineFunctionPass(ID) {
610 initializeLiveDebugValuesPass(*PassRegistry::getPassRegistry());
611}
612
613/// Tell the pass manager which passes we depend on and what information we
614/// preserve.
615void LiveDebugValues::getAnalysisUsage(AnalysisUsage &AU) const {
Matt Arsenaultb1630a12016-06-08 05:18:01 +0000616 AU.setPreservesCFG();
Vikram TV859ad292015-12-16 11:09:48 +0000617 MachineFunctionPass::getAnalysisUsage(AU);
618}
619
Jeremy Morsebf2b2f02019-06-13 12:51:57 +0000620/// Erase a variable from the set of open ranges, and additionally erase any
621/// fragments that may overlap it.
622void LiveDebugValues::OpenRangesSet::erase(DebugVariable Var) {
623 // Erasure helper.
624 auto DoErase = [this](DebugVariable VarToErase) {
625 auto It = Vars.find(VarToErase);
626 if (It != Vars.end()) {
627 unsigned ID = It->second;
628 VarLocs.reset(ID);
629 Vars.erase(It);
630 }
631 };
632
633 // Erase the variable/fragment that ends here.
634 DoErase(Var);
635
636 // Extract the fragment. Interpret an empty fragment as one that covers all
637 // possible bits.
638 FragmentInfo ThisFragment = Var.getFragmentDefault();
639
640 // There may be fragments that overlap the designated fragment. Look them up
641 // in the pre-computed overlap map, and erase them too.
642 auto MapIt = OverlappingFragments.find({Var.getVar(), ThisFragment});
643 if (MapIt != OverlappingFragments.end()) {
644 for (auto Fragment : MapIt->second) {
645 LiveDebugValues::OptFragmentInfo FragmentHolder;
646 if (!DebugVariable::isFragmentDefault(Fragment))
647 FragmentHolder = LiveDebugValues::OptFragmentInfo(Fragment);
648 DoErase({Var.getVar(), FragmentHolder, Var.getInlinedAt()});
649 }
650 }
651}
652
Vikram TV859ad292015-12-16 11:09:48 +0000653//===----------------------------------------------------------------------===//
654// Debug Range Extension Implementation
655//===----------------------------------------------------------------------===//
656
Matthias Braun194ded52017-01-28 06:53:55 +0000657#ifndef NDEBUG
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000658void LiveDebugValues::printVarLocInMBB(const MachineFunction &MF,
659 const VarLocInMBB &V,
660 const VarLocMap &VarLocIDs,
661 const char *msg,
Vikram TV859ad292015-12-16 11:09:48 +0000662 raw_ostream &Out) const {
Keith Walkerf83a19f2016-09-20 16:04:31 +0000663 Out << '\n' << msg << '\n';
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000664 for (const MachineBasicBlock &BB : MF) {
Vedant Kumar9b558382018-10-05 21:44:00 +0000665 const VarLocSet &L = V.lookup(&BB);
666 if (L.empty())
667 continue;
668 Out << "MBB: " << BB.getNumber() << ":\n";
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000669 for (unsigned VLL : L) {
670 const VarLoc &VL = VarLocIDs[VLL];
Adrian Prantl7509d542016-05-26 21:42:47 +0000671 Out << " Var: " << VL.Var.getVar()->getName();
Vikram TV859ad292015-12-16 11:09:48 +0000672 Out << " MI: ";
Jeremy Morse61800a72019-10-04 10:53:47 +0000673 VL.dump(TRI, Out);
Vikram TV859ad292015-12-16 11:09:48 +0000674 }
675 }
676 Out << "\n";
677}
Matthias Braun194ded52017-01-28 06:53:55 +0000678#endif
Vikram TV859ad292015-12-16 11:09:48 +0000679
Wolfgang Pieb90d856c2019-02-04 20:42:45 +0000680LiveDebugValues::VarLoc::SpillLoc
681LiveDebugValues::extractSpillBaseRegAndOffset(const MachineInstr &MI) {
Fangrui Songf78650a2018-07-30 19:41:25 +0000682 assert(MI.hasOneMemOperand() &&
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000683 "Spill instruction does not have exactly one memory operand?");
684 auto MMOI = MI.memoperands_begin();
685 const PseudoSourceValue *PVal = (*MMOI)->getPseudoValue();
686 assert(PVal->kind() == PseudoSourceValue::FixedStack &&
687 "Inconsistent memory operand in spill instruction");
688 int FI = cast<FixedStackPseudoSourceValue>(PVal)->getFrameIndex();
689 const MachineBasicBlock *MBB = MI.getParent();
Wolfgang Pieb90d856c2019-02-04 20:42:45 +0000690 unsigned Reg;
691 int Offset = TFI->getFrameIndexReference(*MBB->getParent(), FI, Reg);
692 return {Reg, Offset};
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000693}
694
Vikram TV859ad292015-12-16 11:09:48 +0000695/// End all previous ranges related to @MI and start a new range from @MI
696/// if it is a DBG_VALUE instr.
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000697void LiveDebugValues::transferDebugValue(const MachineInstr &MI,
Adrian Prantl7509d542016-05-26 21:42:47 +0000698 OpenRangesSet &OpenRanges,
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000699 VarLocMap &VarLocIDs) {
Vikram TV859ad292015-12-16 11:09:48 +0000700 if (!MI.isDebugValue())
701 return;
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000702 const DILocalVariable *Var = MI.getDebugVariable();
Jeremy Morsebf2b2f02019-06-13 12:51:57 +0000703 const DIExpression *Expr = MI.getDebugExpression();
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000704 const DILocation *DebugLoc = MI.getDebugLoc();
705 const DILocation *InlinedAt = DebugLoc->getInlinedAt();
706 assert(Var->isValidLocationForIntrinsic(DebugLoc) &&
Vikram TV859ad292015-12-16 11:09:48 +0000707 "Expected inlined-at fields to agree");
Vikram TV859ad292015-12-16 11:09:48 +0000708
709 // End all previous ranges of Var.
Jeremy Morsebf2b2f02019-06-13 12:51:57 +0000710 DebugVariable V(Var, Expr, InlinedAt);
Adrian Prantl7509d542016-05-26 21:42:47 +0000711 OpenRanges.erase(V);
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000712
713 // Add the VarLoc to OpenRanges from this DBG_VALUE.
Jeremy Morsebcff4172019-06-10 15:23:46 +0000714 unsigned ID;
Djordje Todorovic774eabd2019-06-27 18:12:04 +0000715 if (isDbgValueDescribedByReg(MI) || MI.getOperand(0).isImm() ||
716 MI.getOperand(0).isFPImm() || MI.getOperand(0).isCImm()) {
Jeremy Morsebcff4172019-06-10 15:23:46 +0000717 // Use normal VarLoc constructor for registers and immediates.
Djordje Todorovic774eabd2019-06-27 18:12:04 +0000718 VarLoc VL(MI, LS);
Jeremy Morsebcff4172019-06-10 15:23:46 +0000719 ID = VarLocIDs.insert(VL);
Adrian Prantl7509d542016-05-26 21:42:47 +0000720 OpenRanges.insert(ID, VL.Var);
Jeremy Morsebcff4172019-06-10 15:23:46 +0000721 } else if (MI.hasOneMemOperand()) {
Jeremy Morse8b593482019-08-16 10:04:17 +0000722 llvm_unreachable("DBG_VALUE with mem operand encountered after regalloc?");
Jeremy Morsebcff4172019-06-10 15:23:46 +0000723 } else {
724 // This must be an undefined location. We should leave OpenRanges closed.
725 assert(MI.getOperand(0).isReg() && MI.getOperand(0).getReg() == 0 &&
726 "Unexpected non-undef DBG_VALUE encountered");
Adrian Prantl7509d542016-05-26 21:42:47 +0000727 }
Vikram TV859ad292015-12-16 11:09:48 +0000728}
729
Djordje Todorovic12aca5d2019-07-09 08:36:34 +0000730void LiveDebugValues::emitEntryValues(MachineInstr &MI,
731 OpenRangesSet &OpenRanges,
732 VarLocMap &VarLocIDs,
733 TransferMap &Transfers,
734 DebugParamMap &DebugEntryVals,
735 SparseBitVector<> &KillSet) {
Djordje Todorovic12aca5d2019-07-09 08:36:34 +0000736 for (unsigned ID : KillSet) {
737 if (!VarLocIDs[ID].Var.getVar()->isParameter())
738 continue;
739
740 const MachineInstr *CurrDebugInstr = &VarLocIDs[ID].MI;
741
742 // If parameter's DBG_VALUE is not in the map that means we can't
743 // generate parameter's entry value.
744 if (!DebugEntryVals.count(CurrDebugInstr->getDebugVariable()))
745 continue;
746
747 auto ParamDebugInstr = DebugEntryVals[CurrDebugInstr->getDebugVariable()];
748 DIExpression *NewExpr = DIExpression::prepend(
749 ParamDebugInstr->getDebugExpression(), DIExpression::EntryValue);
Djordje Todorovic12aca5d2019-07-09 08:36:34 +0000750
Jeremy Morse61800a72019-10-04 10:53:47 +0000751 VarLoc EntryLoc = VarLoc::CreateEntryLoc(*ParamDebugInstr, LS, NewExpr);
Djordje Todorovic12aca5d2019-07-09 08:36:34 +0000752
Jeremy Morse61800a72019-10-04 10:53:47 +0000753 unsigned EntryValLocID = VarLocIDs.insert(EntryLoc);
754 Transfers.push_back({&MI, EntryValLocID});
755 OpenRanges.insert(EntryValLocID, EntryLoc.Var);
Djordje Todorovic12aca5d2019-07-09 08:36:34 +0000756 }
757}
758
Petar Jovanovicbe2e80a2018-07-13 08:24:26 +0000759/// Create new TransferDebugPair and insert it in \p Transfers. The VarLoc
760/// with \p OldVarID should be deleted form \p OpenRanges and replaced with
761/// new VarLoc. If \p NewReg is different than default zero value then the
762/// new location will be register location created by the copy like instruction,
763/// otherwise it is variable's location on the stack.
764void LiveDebugValues::insertTransferDebugPair(
765 MachineInstr &MI, OpenRangesSet &OpenRanges, TransferMap &Transfers,
Wolfgang Pieb90d856c2019-02-04 20:42:45 +0000766 VarLocMap &VarLocIDs, unsigned OldVarID, TransferKind Kind,
767 unsigned NewReg) {
Petar Jovanovicaa28b6d2019-05-23 13:49:06 +0000768 const MachineInstr *DebugInstr = &VarLocIDs[OldVarID].MI;
Wolfgang Pieb90d856c2019-02-04 20:42:45 +0000769
Nikola Prica2d0106a2019-06-03 09:48:29 +0000770 auto ProcessVarLoc = [&MI, &OpenRanges, &Transfers, &DebugInstr,
Jeremy Morse61800a72019-10-04 10:53:47 +0000771 &VarLocIDs](VarLoc &VL) {
Wolfgang Pieb90d856c2019-02-04 20:42:45 +0000772 unsigned LocId = VarLocIDs.insert(VL);
Nikola Prica2d0106a2019-06-03 09:48:29 +0000773
774 // Close this variable's previous location range.
Jeremy Morsebf2b2f02019-06-13 12:51:57 +0000775 DebugVariable V(*DebugInstr);
Nikola Prica2d0106a2019-06-03 09:48:29 +0000776 OpenRanges.erase(V);
777
Jeremy Morse61800a72019-10-04 10:53:47 +0000778 // Record the new location as an open range, and a postponed transfer
779 // inserting a DBG_VALUE for this location.
Wolfgang Pieb90d856c2019-02-04 20:42:45 +0000780 OpenRanges.insert(LocId, VL.Var);
Jeremy Morse61800a72019-10-04 10:53:47 +0000781 TransferDebugPair MIP = {&MI, LocId};
Wolfgang Pieb90d856c2019-02-04 20:42:45 +0000782 Transfers.push_back(MIP);
783 };
784
785 // End all previous ranges of Var.
786 OpenRanges.erase(VarLocIDs[OldVarID].Var);
787 switch (Kind) {
788 case TransferKind::TransferCopy: {
789 assert(NewReg &&
790 "No register supplied when handling a copy of a debug value");
Petar Jovanovicbe2e80a2018-07-13 08:24:26 +0000791 // Create a DBG_VALUE instruction to describe the Var in its new
792 // register location.
Jeremy Morse61800a72019-10-04 10:53:47 +0000793 VarLoc VL = VarLoc::CreateCopyLoc(*DebugInstr, LS, NewReg);
794 ProcessVarLoc(VL);
795 LLVM_DEBUG({
796 dbgs() << "Creating VarLoc for register copy:";
797 VL.dump(TRI);
798 });
Wolfgang Pieb90d856c2019-02-04 20:42:45 +0000799 return;
800 }
801 case TransferKind::TransferSpill: {
Petar Jovanovicbe2e80a2018-07-13 08:24:26 +0000802 // Create a DBG_VALUE instruction to describe the Var in its spilled
803 // location.
Wolfgang Pieb90d856c2019-02-04 20:42:45 +0000804 VarLoc::SpillLoc SpillLocation = extractSpillBaseRegAndOffset(MI);
Jeremy Morse61800a72019-10-04 10:53:47 +0000805 VarLoc VL = VarLoc::CreateSpillLoc(*DebugInstr, SpillLocation.SpillBase,
806 SpillLocation.SpillOffset, LS);
807 ProcessVarLoc(VL);
808 LLVM_DEBUG({
809 dbgs() << "Creating VarLoc for spill:";
810 VL.dump(TRI);
811 });
Wolfgang Pieb90d856c2019-02-04 20:42:45 +0000812 return;
Petar Jovanovicbe2e80a2018-07-13 08:24:26 +0000813 }
Wolfgang Pieb90d856c2019-02-04 20:42:45 +0000814 case TransferKind::TransferRestore: {
815 assert(NewReg &&
816 "No register supplied when handling a restore of a debug value");
Jeremy Morse8b593482019-08-16 10:04:17 +0000817 // DebugInstr refers to the pre-spill location, therefore we can reuse
818 // its expression.
Jeremy Morse61800a72019-10-04 10:53:47 +0000819 VarLoc VL = VarLoc::CreateCopyLoc(*DebugInstr, LS, NewReg);
820 ProcessVarLoc(VL);
821 LLVM_DEBUG({
822 dbgs() << "Creating VarLoc for restore:";
823 VL.dump(TRI);
824 });
Wolfgang Pieb90d856c2019-02-04 20:42:45 +0000825 return;
826 }
827 }
828 llvm_unreachable("Invalid transfer kind");
Petar Jovanovicbe2e80a2018-07-13 08:24:26 +0000829}
830
Vikram TV859ad292015-12-16 11:09:48 +0000831/// A definition of a register may mark the end of a range.
Djordje Todorovic12aca5d2019-07-09 08:36:34 +0000832void LiveDebugValues::transferRegisterDef(
833 MachineInstr &MI, OpenRangesSet &OpenRanges, VarLocMap &VarLocIDs,
834 TransferMap &Transfers, DebugParamMap &DebugEntryVals) {
Justin Bognerfdf9bf42017-10-10 23:50:49 +0000835 MachineFunction *MF = MI.getMF();
Reid Klecknerf6f04f82016-03-25 17:54:46 +0000836 const TargetLowering *TLI = MF->getSubtarget().getTargetLowering();
837 unsigned SP = TLI->getStackPointerRegisterToSaveRestore();
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000838 SparseBitVector<> KillSet;
Vikram TV859ad292015-12-16 11:09:48 +0000839 for (const MachineOperand &MO : MI.operands()) {
Adrian Prantlea8880b2017-03-03 01:08:25 +0000840 // Determine whether the operand is a register def. Assume that call
841 // instructions never clobber SP, because some backends (e.g., AArch64)
842 // never list SP in the regmask.
Reid Klecknerf6f04f82016-03-25 17:54:46 +0000843 if (MO.isReg() && MO.isDef() && MO.getReg() &&
Daniel Sanders2bea69b2019-08-01 23:27:28 +0000844 Register::isPhysicalRegister(MO.getReg()) &&
Adrian Prantlea8880b2017-03-03 01:08:25 +0000845 !(MI.isCall() && MO.getReg() == SP)) {
Reid Klecknerf6f04f82016-03-25 17:54:46 +0000846 // Remove ranges of all aliased registers.
847 for (MCRegAliasIterator RAI(MO.getReg(), TRI, true); RAI.isValid(); ++RAI)
Adrian Prantl7509d542016-05-26 21:42:47 +0000848 for (unsigned ID : OpenRanges.getVarLocs())
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000849 if (VarLocIDs[ID].isDescribedByReg() == *RAI)
850 KillSet.set(ID);
Reid Klecknerf6f04f82016-03-25 17:54:46 +0000851 } else if (MO.isRegMask()) {
852 // Remove ranges of all clobbered registers. Register masks don't usually
853 // list SP as preserved. While the debug info may be off for an
854 // instruction or two around callee-cleanup calls, transferring the
855 // DEBUG_VALUE across the call is still a better user experience.
Adrian Prantl7509d542016-05-26 21:42:47 +0000856 for (unsigned ID : OpenRanges.getVarLocs()) {
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000857 unsigned Reg = VarLocIDs[ID].isDescribedByReg();
858 if (Reg && Reg != SP && MO.clobbersPhysReg(Reg))
859 KillSet.set(ID);
860 }
Reid Klecknerf6f04f82016-03-25 17:54:46 +0000861 }
Vikram TV859ad292015-12-16 11:09:48 +0000862 }
Adrian Prantl7509d542016-05-26 21:42:47 +0000863 OpenRanges.erase(KillSet, VarLocIDs);
Djordje Todorovic12aca5d2019-07-09 08:36:34 +0000864
865 if (auto *TPC = getAnalysisIfAvailable<TargetPassConfig>()) {
866 auto &TM = TPC->getTM<TargetMachine>();
867 if (TM.Options.EnableDebugEntryValues)
868 emitEntryValues(MI, OpenRanges, VarLocIDs, Transfers, DebugEntryVals,
869 KillSet);
870 }
Vikram TV859ad292015-12-16 11:09:48 +0000871}
872
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000873bool LiveDebugValues::isSpillInstruction(const MachineInstr &MI,
Jeremy Morse5d9cd3b2019-09-06 10:08:22 +0000874 MachineFunction *MF) {
Fangrui Songf78650a2018-07-30 19:41:25 +0000875 // TODO: Handle multiple stores folded into one.
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000876 if (!MI.hasOneMemOperand())
877 return false;
878
Wolfgang Pieb90d856c2019-02-04 20:42:45 +0000879 if (!MI.getSpillSize(TII) && !MI.getFoldedSpillSize(TII))
880 return false; // This is not a spill instruction, since no valid size was
881 // returned from either function.
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000882
Jeremy Morse5d9cd3b2019-09-06 10:08:22 +0000883 return true;
884}
885
886bool LiveDebugValues::isLocationSpill(const MachineInstr &MI,
887 MachineFunction *MF, unsigned &Reg) {
888 if (!isSpillInstruction(MI, MF))
889 return false;
890
Petar Jovanovic0b464e42018-01-16 14:46:05 +0000891 auto isKilledReg = [&](const MachineOperand MO, unsigned &Reg) {
892 if (!MO.isReg() || !MO.isUse()) {
893 Reg = 0;
894 return false;
895 }
896 Reg = MO.getReg();
897 return MO.isKill();
898 };
899
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000900 for (const MachineOperand &MO : MI.operands()) {
Petar Jovanovic0b464e42018-01-16 14:46:05 +0000901 // In a spill instruction generated by the InlineSpiller the spilled
902 // register has its kill flag set.
903 if (isKilledReg(MO, Reg))
904 return true;
905 if (Reg != 0) {
906 // Check whether next instruction kills the spilled register.
907 // FIXME: Current solution does not cover search for killed register in
908 // bundles and instructions further down the chain.
909 auto NextI = std::next(MI.getIterator());
910 // Skip next instruction that points to basic block end iterator.
911 if (MI.getParent()->end() == NextI)
912 continue;
913 unsigned RegNext;
914 for (const MachineOperand &MONext : NextI->operands()) {
915 // Return true if we came across the register from the
916 // previous spill instruction that is killed in NextI.
917 if (isKilledReg(MONext, RegNext) && RegNext == Reg)
918 return true;
919 }
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000920 }
921 }
Petar Jovanovic0b464e42018-01-16 14:46:05 +0000922 // Return false if we didn't find spilled register.
923 return false;
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000924}
925
Wolfgang Pieb90d856c2019-02-04 20:42:45 +0000926Optional<LiveDebugValues::VarLoc::SpillLoc>
927LiveDebugValues::isRestoreInstruction(const MachineInstr &MI,
928 MachineFunction *MF, unsigned &Reg) {
929 if (!MI.hasOneMemOperand())
930 return None;
931
932 // FIXME: Handle folded restore instructions with more than one memory
933 // operand.
934 if (MI.getRestoreSize(TII)) {
935 Reg = MI.getOperand(0).getReg();
936 return extractSpillBaseRegAndOffset(MI);
937 }
938 return None;
939}
940
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000941/// A spilled register may indicate that we have to end the current range of
942/// a variable and create a new one for the spill location.
Wolfgang Pieb90d856c2019-02-04 20:42:45 +0000943/// A restored register may indicate the reverse situation.
Petar Jovanovicbe2e80a2018-07-13 08:24:26 +0000944/// We don't want to insert any instructions in process(), so we just create
945/// the DBG_VALUE without inserting it and keep track of it in \p Transfers.
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000946/// It will be inserted into the BB when we're done iterating over the
947/// instructions.
Wolfgang Pieb90d856c2019-02-04 20:42:45 +0000948void LiveDebugValues::transferSpillOrRestoreInst(MachineInstr &MI,
949 OpenRangesSet &OpenRanges,
950 VarLocMap &VarLocIDs,
951 TransferMap &Transfers) {
Wolfgang Piebfacd0522019-01-30 20:37:14 +0000952 MachineFunction *MF = MI.getMF();
Wolfgang Pieb90d856c2019-02-04 20:42:45 +0000953 TransferKind TKind;
954 unsigned Reg;
955 Optional<VarLoc::SpillLoc> Loc;
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000956
Wolfgang Pieb90d856c2019-02-04 20:42:45 +0000957 LLVM_DEBUG(dbgs() << "Examining instruction: "; MI.dump(););
958
Jeremy Morse5d9cd3b2019-09-06 10:08:22 +0000959 // First, if there are any DBG_VALUEs pointing at a spill slot that is
960 // written to, then close the variable location. The value in memory
961 // will have changed.
962 VarLocSet KillSet;
963 if (isSpillInstruction(MI, MF)) {
964 Loc = extractSpillBaseRegAndOffset(MI);
965 for (unsigned ID : OpenRanges.getVarLocs()) {
966 const VarLoc &VL = VarLocIDs[ID];
967 if (VL.Kind == VarLoc::SpillLocKind && VL.Loc.SpillLocation == *Loc) {
968 // This location is overwritten by the current instruction -- terminate
969 // the open range, and insert an explicit DBG_VALUE $noreg.
970 //
971 // Doing this at a later stage would require re-interpreting all
972 // DBG_VALUes and DIExpressions to identify whether they point at
973 // memory, and then analysing all memory writes to see if they
974 // overwrite that memory, which is expensive.
975 //
976 // At this stage, we already know which DBG_VALUEs are for spills and
977 // where they are located; it's best to fix handle overwrites now.
978 KillSet.set(ID);
Jeremy Morse61800a72019-10-04 10:53:47 +0000979 VarLoc UndefVL = VarLoc::CreateCopyLoc(VL.MI, LS, 0);
980 unsigned UndefLocID = VarLocIDs.insert(UndefVL);
981 Transfers.push_back({&MI, UndefLocID});
Jeremy Morse5d9cd3b2019-09-06 10:08:22 +0000982 }
983 }
984 OpenRanges.erase(KillSet, VarLocIDs);
985 }
986
987 // Try to recognise spill and restore instructions that may create a new
988 // variable location.
989 if (isLocationSpill(MI, MF, Reg)) {
Wolfgang Pieb90d856c2019-02-04 20:42:45 +0000990 TKind = TransferKind::TransferSpill;
991 LLVM_DEBUG(dbgs() << "Recognized as spill: "; MI.dump(););
992 LLVM_DEBUG(dbgs() << "Register: " << Reg << " " << printReg(Reg, TRI)
993 << "\n");
994 } else {
995 if (!(Loc = isRestoreInstruction(MI, MF, Reg)))
996 return;
997 TKind = TransferKind::TransferRestore;
998 LLVM_DEBUG(dbgs() << "Recognized as restore: "; MI.dump(););
999 LLVM_DEBUG(dbgs() << "Register: " << Reg << " " << printReg(Reg, TRI)
1000 << "\n");
1001 }
1002 // Check if the register or spill location is the location of a debug value.
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +00001003 for (unsigned ID : OpenRanges.getVarLocs()) {
Wolfgang Pieb90d856c2019-02-04 20:42:45 +00001004 if (TKind == TransferKind::TransferSpill &&
Jeremy Morse8b593482019-08-16 10:04:17 +00001005 VarLocIDs[ID].isDescribedByReg() == Reg) {
Nicola Zaghend34e60c2018-05-14 12:53:11 +00001006 LLVM_DEBUG(dbgs() << "Spilling Register " << printReg(Reg, TRI) << '('
1007 << VarLocIDs[ID].Var.getVar()->getName() << ")\n");
Wolfgang Pieb90d856c2019-02-04 20:42:45 +00001008 } else if (TKind == TransferKind::TransferRestore &&
Jeremy Morseca0e4b32019-08-29 11:20:54 +00001009 VarLocIDs[ID].Kind == VarLoc::SpillLocKind &&
Wolfgang Pieb90d856c2019-02-04 20:42:45 +00001010 VarLocIDs[ID].Loc.SpillLocation == *Loc) {
1011 LLVM_DEBUG(dbgs() << "Restoring Register " << printReg(Reg, TRI) << '('
1012 << VarLocIDs[ID].Var.getVar()->getName() << ")\n");
1013 } else
1014 continue;
1015 insertTransferDebugPair(MI, OpenRanges, Transfers, VarLocIDs, ID, TKind,
1016 Reg);
1017 return;
Petar Jovanovicbe2e80a2018-07-13 08:24:26 +00001018 }
1019}
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +00001020
Petar Jovanovicbe2e80a2018-07-13 08:24:26 +00001021/// If \p MI is a register copy instruction, that copies a previously tracked
1022/// value from one register to another register that is callee saved, we
1023/// create new DBG_VALUE instruction described with copy destination register.
1024void LiveDebugValues::transferRegisterCopy(MachineInstr &MI,
1025 OpenRangesSet &OpenRanges,
1026 VarLocMap &VarLocIDs,
1027 TransferMap &Transfers) {
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +00001028
Djordje Todorovic8d2ccd12019-11-08 11:19:58 +01001029 auto DestSrc = TII->isCopyInstr(MI);
1030 if (!DestSrc)
1031 return;
1032
1033 const MachineOperand *DestRegOp = DestSrc->Destination;
1034 const MachineOperand *SrcRegOp = DestSrc->Source;
1035 if (!SrcRegOp->isKill() || !DestRegOp->isDef())
Petar Jovanovicbe2e80a2018-07-13 08:24:26 +00001036 return;
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +00001037
David Stenberg2a3dc6b2019-10-25 11:21:11 +02001038 auto isCalleeSavedReg = [&](unsigned Reg) {
Petar Jovanovicbe2e80a2018-07-13 08:24:26 +00001039 for (MCRegAliasIterator RAI(Reg, TRI, true); RAI.isValid(); ++RAI)
1040 if (CalleeSavedRegs.test(*RAI))
1041 return true;
1042 return false;
1043 };
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +00001044
Simon Pilgrim3842b942019-10-31 17:58:15 +00001045 Register SrcReg = SrcRegOp->getReg();
1046 Register DestReg = DestRegOp->getReg();
Petar Jovanovicbe2e80a2018-07-13 08:24:26 +00001047
1048 // We want to recognize instructions where destination register is callee
1049 // saved register. If register that could be clobbered by the call is
1050 // included, there would be a great chance that it is going to be clobbered
1051 // soon. It is more likely that previous register location, which is callee
1052 // saved, is going to stay unclobbered longer, even if it is killed.
David Stenberg2a3dc6b2019-10-25 11:21:11 +02001053 if (!isCalleeSavedReg(DestReg))
Petar Jovanovicbe2e80a2018-07-13 08:24:26 +00001054 return;
1055
1056 for (unsigned ID : OpenRanges.getVarLocs()) {
1057 if (VarLocIDs[ID].isDescribedByReg() == SrcReg) {
1058 insertTransferDebugPair(MI, OpenRanges, Transfers, VarLocIDs, ID,
Wolfgang Pieb90d856c2019-02-04 20:42:45 +00001059 TransferKind::TransferCopy, DestReg);
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +00001060 return;
1061 }
1062 }
1063}
1064
Vikram TV859ad292015-12-16 11:09:48 +00001065/// Terminate all open ranges at the end of the current basic block.
Jeremy Morse67443c32019-08-21 09:22:31 +00001066bool LiveDebugValues::transferTerminator(MachineBasicBlock *CurMBB,
1067 OpenRangesSet &OpenRanges,
1068 VarLocInMBB &OutLocs,
1069 const VarLocMap &VarLocIDs) {
Daniel Berlinca4d93a2016-01-10 03:25:42 +00001070 bool Changed = false;
Vikram TV859ad292015-12-16 11:09:48 +00001071
Nicola Zaghend34e60c2018-05-14 12:53:11 +00001072 LLVM_DEBUG(for (unsigned ID
1073 : OpenRanges.getVarLocs()) {
1074 // Copy OpenRanges to OutLocs, if not already present.
Vedant Kumar9b558382018-10-05 21:44:00 +00001075 dbgs() << "Add to OutLocs in MBB #" << CurMBB->getNumber() << ": ";
Jeremy Morse61800a72019-10-04 10:53:47 +00001076 VarLocIDs[ID].dump(TRI);
Nicola Zaghend34e60c2018-05-14 12:53:11 +00001077 });
Adrian Prantl6ee02c72016-05-25 22:21:12 +00001078 VarLocSet &VLS = OutLocs[CurMBB];
Jeremy Morse0ae54982019-08-23 16:33:42 +00001079 Changed = VLS != OpenRanges.getVarLocs();
Nikola Prica2d0106a2019-06-03 09:48:29 +00001080 // New OutLocs set may be different due to spill, restore or register
1081 // copy instruction processing.
1082 if (Changed)
1083 VLS = OpenRanges.getVarLocs();
Vikram TV859ad292015-12-16 11:09:48 +00001084 OpenRanges.clear();
Daniel Berlinca4d93a2016-01-10 03:25:42 +00001085 return Changed;
Vikram TV859ad292015-12-16 11:09:48 +00001086}
1087
Jeremy Morsebf2b2f02019-06-13 12:51:57 +00001088/// Accumulate a mapping between each DILocalVariable fragment and other
1089/// fragments of that DILocalVariable which overlap. This reduces work during
1090/// the data-flow stage from "Find any overlapping fragments" to "Check if the
1091/// known-to-overlap fragments are present".
1092/// \param MI A previously unprocessed DEBUG_VALUE instruction to analyze for
1093/// fragment usage.
1094/// \param SeenFragments Map from DILocalVariable to all fragments of that
1095/// Variable which are known to exist.
1096/// \param OverlappingFragments The overlap map being constructed, from one
1097/// Var/Fragment pair to a vector of fragments known to overlap.
1098void LiveDebugValues::accumulateFragmentMap(MachineInstr &MI,
1099 VarToFragments &SeenFragments,
1100 OverlapMap &OverlappingFragments) {
1101 DebugVariable MIVar(MI);
1102 FragmentInfo ThisFragment = MIVar.getFragmentDefault();
1103
1104 // If this is the first sighting of this variable, then we are guaranteed
1105 // there are currently no overlapping fragments either. Initialize the set
1106 // of seen fragments, record no overlaps for the current one, and return.
1107 auto SeenIt = SeenFragments.find(MIVar.getVar());
1108 if (SeenIt == SeenFragments.end()) {
1109 SmallSet<FragmentInfo, 4> OneFragment;
1110 OneFragment.insert(ThisFragment);
1111 SeenFragments.insert({MIVar.getVar(), OneFragment});
1112
1113 OverlappingFragments.insert({{MIVar.getVar(), ThisFragment}, {}});
1114 return;
1115 }
1116
1117 // If this particular Variable/Fragment pair already exists in the overlap
1118 // map, it has already been accounted for.
1119 auto IsInOLapMap =
1120 OverlappingFragments.insert({{MIVar.getVar(), ThisFragment}, {}});
1121 if (!IsInOLapMap.second)
1122 return;
1123
1124 auto &ThisFragmentsOverlaps = IsInOLapMap.first->second;
1125 auto &AllSeenFragments = SeenIt->second;
1126
1127 // Otherwise, examine all other seen fragments for this variable, with "this"
1128 // fragment being a previously unseen fragment. Record any pair of
1129 // overlapping fragments.
1130 for (auto &ASeenFragment : AllSeenFragments) {
1131 // Does this previously seen fragment overlap?
1132 if (DIExpression::fragmentsOverlap(ThisFragment, ASeenFragment)) {
1133 // Yes: Mark the current fragment as being overlapped.
1134 ThisFragmentsOverlaps.push_back(ASeenFragment);
1135 // Mark the previously seen fragment as being overlapped by the current
1136 // one.
1137 auto ASeenFragmentsOverlaps =
1138 OverlappingFragments.find({MIVar.getVar(), ASeenFragment});
1139 assert(ASeenFragmentsOverlaps != OverlappingFragments.end() &&
1140 "Previously seen var fragment has no vector of overlaps");
1141 ASeenFragmentsOverlaps->second.push_back(ThisFragment);
1142 }
1143 }
1144
1145 AllSeenFragments.insert(ThisFragment);
1146}
1147
Djordje Todorovic8c99a542019-10-24 10:08:43 +02001148/// This routine creates OpenRanges.
Jeremy Morse67443c32019-08-21 09:22:31 +00001149void LiveDebugValues::process(MachineInstr &MI, OpenRangesSet &OpenRanges,
Djordje Todorovic8c99a542019-10-24 10:08:43 +02001150 VarLocMap &VarLocIDs, TransferMap &Transfers,
1151 DebugParamMap &DebugEntryVals) {
Adrian Prantl6ee02c72016-05-25 22:21:12 +00001152 transferDebugValue(MI, OpenRanges, VarLocIDs);
Djordje Todorovic12aca5d2019-07-09 08:36:34 +00001153 transferRegisterDef(MI, OpenRanges, VarLocIDs, Transfers,
1154 DebugEntryVals);
Jeremy Morse313d2ce2019-08-29 10:53:29 +00001155 transferRegisterCopy(MI, OpenRanges, VarLocIDs, Transfers);
1156 transferSpillOrRestoreInst(MI, OpenRanges, VarLocIDs, Transfers);
Vikram TV859ad292015-12-16 11:09:48 +00001157}
1158
1159/// This routine joins the analysis results of all incoming edges in @MBB by
1160/// inserting a new DBG_VALUE instruction at the start of the @MBB - if the same
1161/// source variable in all the predecessors of @MBB reside in the same location.
Vedant Kumar8c466682018-10-05 21:44:15 +00001162bool LiveDebugValues::join(
1163 MachineBasicBlock &MBB, VarLocInMBB &OutLocs, VarLocInMBB &InLocs,
1164 const VarLocMap &VarLocIDs,
1165 SmallPtrSet<const MachineBasicBlock *, 16> &Visited,
Jeremy Morse67443c32019-08-21 09:22:31 +00001166 SmallPtrSetImpl<const MachineBasicBlock *> &ArtificialBlocks,
1167 VarLocInMBB &PendingInLocs) {
Vedant Kumar9b558382018-10-05 21:44:00 +00001168 LLVM_DEBUG(dbgs() << "join MBB: " << MBB.getNumber() << "\n");
Daniel Berlinca4d93a2016-01-10 03:25:42 +00001169 bool Changed = false;
Vikram TV859ad292015-12-16 11:09:48 +00001170
Adrian Prantl6ee02c72016-05-25 22:21:12 +00001171 VarLocSet InLocsT; // Temporary incoming locations.
Vikram TV859ad292015-12-16 11:09:48 +00001172
Adrian Prantl6ee02c72016-05-25 22:21:12 +00001173 // For all predecessors of this MBB, find the set of VarLocs that
1174 // can be joined.
Keith Walker83ebef52016-09-27 16:46:07 +00001175 int NumVisited = 0;
Vikram TV859ad292015-12-16 11:09:48 +00001176 for (auto p : MBB.predecessors()) {
Jeremy Morse313d2ce2019-08-29 10:53:29 +00001177 // Ignore backedges if we have not visited the predecessor yet. As the
1178 // predecessor hasn't yet had locations propagated into it, most locations
1179 // will not yet be valid, so treat them as all being uninitialized and
1180 // potentially valid. If a location guessed to be correct here is
1181 // invalidated later, we will remove it when we revisit this block.
Vedant Kumar9b558382018-10-05 21:44:00 +00001182 if (!Visited.count(p)) {
1183 LLVM_DEBUG(dbgs() << " ignoring unvisited pred MBB: " << p->getNumber()
1184 << "\n");
Keith Walker83ebef52016-09-27 16:46:07 +00001185 continue;
Vedant Kumar9b558382018-10-05 21:44:00 +00001186 }
Vikram TV859ad292015-12-16 11:09:48 +00001187 auto OL = OutLocs.find(p);
1188 // Join is null in case of empty OutLocs from any of the pred.
1189 if (OL == OutLocs.end())
Daniel Berlinca4d93a2016-01-10 03:25:42 +00001190 return false;
Vikram TV859ad292015-12-16 11:09:48 +00001191
Keith Walker83ebef52016-09-27 16:46:07 +00001192 // Just copy over the Out locs to incoming locs for the first visited
1193 // predecessor, and for all other predecessors join the Out locs.
1194 if (!NumVisited)
Vikram TV859ad292015-12-16 11:09:48 +00001195 InLocsT = OL->second;
Keith Walker83ebef52016-09-27 16:46:07 +00001196 else
1197 InLocsT &= OL->second;
Vedant Kumar9b558382018-10-05 21:44:00 +00001198
1199 LLVM_DEBUG({
1200 if (!InLocsT.empty()) {
1201 for (auto ID : InLocsT)
1202 dbgs() << " gathered candidate incoming var: "
1203 << VarLocIDs[ID].Var.getVar()->getName() << "\n";
1204 }
1205 });
1206
Keith Walker83ebef52016-09-27 16:46:07 +00001207 NumVisited++;
Vikram TV859ad292015-12-16 11:09:48 +00001208 }
1209
Adrian Prantl7f5866c2016-09-28 17:51:14 +00001210 // Filter out DBG_VALUES that are out of scope.
1211 VarLocSet KillSet;
Vedant Kumar8c466682018-10-05 21:44:15 +00001212 bool IsArtificial = ArtificialBlocks.count(&MBB);
1213 if (!IsArtificial) {
1214 for (auto ID : InLocsT) {
1215 if (!VarLocIDs[ID].dominates(MBB)) {
1216 KillSet.set(ID);
1217 LLVM_DEBUG({
1218 auto Name = VarLocIDs[ID].Var.getVar()->getName();
1219 dbgs() << " killing " << Name << ", it doesn't dominate MBB\n";
1220 });
1221 }
Vedant Kumar9b558382018-10-05 21:44:00 +00001222 }
1223 }
Adrian Prantl7f5866c2016-09-28 17:51:14 +00001224 InLocsT.intersectWithComplement(KillSet);
1225
Keith Walker83ebef52016-09-27 16:46:07 +00001226 // As we are processing blocks in reverse post-order we
1227 // should have processed at least one predecessor, unless it
1228 // is the entry block which has no predecessor.
1229 assert((NumVisited || MBB.pred_empty()) &&
1230 "Should have processed at least one predecessor");
Vikram TV859ad292015-12-16 11:09:48 +00001231
Adrian Prantl6ee02c72016-05-25 22:21:12 +00001232 VarLocSet &ILS = InLocs[&MBB];
Jeremy Morse67443c32019-08-21 09:22:31 +00001233 VarLocSet &Pending = PendingInLocs[&MBB];
Vikram TV859ad292015-12-16 11:09:48 +00001234
Jeremy Morse67443c32019-08-21 09:22:31 +00001235 // New locations will have DBG_VALUE insts inserted at the start of the
1236 // block, after location propagation has finished. Record the insertions
1237 // that we need to perform in the Pending set.
Adrian Prantl6ee02c72016-05-25 22:21:12 +00001238 VarLocSet Diff = InLocsT;
1239 Diff.intersectWithComplement(ILS);
1240 for (auto ID : Diff) {
Jeremy Morse67443c32019-08-21 09:22:31 +00001241 Pending.set(ID);
Adrian Prantl6ee02c72016-05-25 22:21:12 +00001242 ILS.set(ID);
1243 ++NumInserted;
1244 Changed = true;
Vikram TV859ad292015-12-16 11:09:48 +00001245 }
Jeremy Morse0ae54982019-08-23 16:33:42 +00001246
1247 // We may have lost locations by learning about a predecessor that either
1248 // loses or moves a variable. Find any locations in ILS that are not in the
1249 // new in-locations, and delete those.
1250 VarLocSet Removed = ILS;
1251 Removed.intersectWithComplement(InLocsT);
1252 for (auto ID : Removed) {
1253 Pending.reset(ID);
1254 ILS.reset(ID);
1255 ++NumRemoved;
1256 Changed = true;
1257 }
1258
Daniel Berlinca4d93a2016-01-10 03:25:42 +00001259 return Changed;
Vikram TV859ad292015-12-16 11:09:48 +00001260}
1261
Jeremy Morse67443c32019-08-21 09:22:31 +00001262void LiveDebugValues::flushPendingLocs(VarLocInMBB &PendingInLocs,
1263 VarLocMap &VarLocIDs) {
1264 // PendingInLocs records all locations propagated into blocks, which have
1265 // not had DBG_VALUE insts created. Go through and create those insts now.
1266 for (auto &Iter : PendingInLocs) {
1267 // Map is keyed on a constant pointer, unwrap it so we can insert insts.
1268 auto &MBB = const_cast<MachineBasicBlock &>(*Iter.first);
1269 VarLocSet &Pending = Iter.second;
1270
1271 for (unsigned ID : Pending) {
1272 // The ID location is live-in to MBB -- work out what kind of machine
1273 // location it is and create a DBG_VALUE.
1274 const VarLoc &DiffIt = VarLocIDs[ID];
Jeremy Morse61800a72019-10-04 10:53:47 +00001275 MachineInstr *MI = DiffIt.BuildDbgValue(*MBB.getParent());
1276 MBB.insert(MBB.instr_begin(), MI);
Jeremy Morse67443c32019-08-21 09:22:31 +00001277
Jeremy Morsec8c5f2a2019-09-04 10:18:03 +00001278 (void)MI;
Jeremy Morse67443c32019-08-21 09:22:31 +00001279 LLVM_DEBUG(dbgs() << "Inserted: "; MI->dump(););
1280 }
1281 }
1282}
1283
David Stenberg5e646ff2019-11-13 10:37:53 +01001284bool LiveDebugValues::isEntryValueCandidate(
1285 const MachineInstr &MI, const DefinedRegsSet &DefinedRegs) const {
David Stenberg4fec44c2019-11-13 10:36:13 +01001286 if (!MI.isDebugValue())
1287 return false;
1288
1289 // TODO: Add support for local variables that are expressed in terms of
1290 // parameters entry values.
1291 // TODO: Add support for modified arguments that can be expressed
1292 // by using its entry value.
1293 auto *DIVar = MI.getDebugVariable();
1294 if (!DIVar->isParameter() || !DIVar->isNotModified())
1295 return false;
1296
1297 // Do not consider parameters that belong to an inlined function.
1298 if (MI.getDebugLoc()->getInlinedAt())
1299 return false;
1300
1301 // Do not consider indirect debug values (TODO: explain why).
1302 if (MI.isIndirectDebugValue())
1303 return false;
1304
1305 // Only consider parameters that are described using registers. Parameters
1306 // that are passed on the stack are not yet supported, so ignore debug
1307 // values that are described by the frame or stack pointer.
1308 if (!isRegOtherThanSPAndFP(MI.getOperand(0), MI, TRI))
1309 return false;
1310
David Stenberg5e646ff2019-11-13 10:37:53 +01001311 // If a parameter's value has been propagated from the caller, then the
1312 // parameter's DBG_VALUE may be described using a register defined by some
1313 // instruction in the entry block, in which case we shouldn't create an
1314 // entry value.
1315 if (DefinedRegs.count(MI.getOperand(0).getReg()))
1316 return false;
1317
David Stenberg4fec44c2019-11-13 10:36:13 +01001318 // TODO: Add support for parameters that are described as fragments.
1319 if (MI.getDebugExpression()->isFragment())
1320 return false;
1321
1322 return true;
1323}
1324
David Stenberg5e646ff2019-11-13 10:37:53 +01001325/// Collect all register defines (including aliases) for the given instruction.
1326static void collectRegDefs(const MachineInstr &MI, DefinedRegsSet &Regs,
1327 const TargetRegisterInfo *TRI) {
1328 for (const MachineOperand &MO : MI.operands())
1329 if (MO.isReg() && MO.isDef() && MO.getReg())
1330 for (MCRegAliasIterator AI(MO.getReg(), TRI, true); AI.isValid(); ++AI)
1331 Regs.insert(*AI);
1332}
1333
Vikram TV859ad292015-12-16 11:09:48 +00001334/// Calculate the liveness information for the given machine function and
1335/// extend ranges across basic blocks.
1336bool LiveDebugValues::ExtendRanges(MachineFunction &MF) {
Nicola Zaghend34e60c2018-05-14 12:53:11 +00001337 LLVM_DEBUG(dbgs() << "\nDebug Range Extension\n");
Vikram TV859ad292015-12-16 11:09:48 +00001338
1339 bool Changed = false;
Daniel Berlinca4d93a2016-01-10 03:25:42 +00001340 bool OLChanged = false;
1341 bool MBBJoined = false;
Vikram TV859ad292015-12-16 11:09:48 +00001342
Jeremy Morsebf2b2f02019-06-13 12:51:57 +00001343 VarLocMap VarLocIDs; // Map VarLoc<>unique ID for use in bitvectors.
Djordje Todorovic8c99a542019-10-24 10:08:43 +02001344 OverlapMap OverlapFragments; // Map of overlapping variable fragments.
Jeremy Morsebf2b2f02019-06-13 12:51:57 +00001345 OpenRangesSet OpenRanges(OverlapFragments);
1346 // Ranges that are open until end of bb.
1347 VarLocInMBB OutLocs; // Ranges that exist beyond bb.
1348 VarLocInMBB InLocs; // Ranges that are incoming after joining.
Djordje Todorovic8c99a542019-10-24 10:08:43 +02001349 TransferMap Transfers; // DBG_VALUEs associated with transfers (such as
1350 // spills, copies and restores).
Jeremy Morse67443c32019-08-21 09:22:31 +00001351 VarLocInMBB PendingInLocs; // Ranges that are incoming after joining, but
1352 // that we have deferred creating DBG_VALUE insts
1353 // for immediately.
Jeremy Morsebf2b2f02019-06-13 12:51:57 +00001354
1355 VarToFragments SeenFragments;
Vikram TV859ad292015-12-16 11:09:48 +00001356
Vedant Kumar8c466682018-10-05 21:44:15 +00001357 // Blocks which are artificial, i.e. blocks which exclusively contain
1358 // instructions without locations, or with line 0 locations.
1359 SmallPtrSet<const MachineBasicBlock *, 16> ArtificialBlocks;
1360
Daniel Berlin72560592016-01-10 18:08:32 +00001361 DenseMap<unsigned int, MachineBasicBlock *> OrderToBB;
1362 DenseMap<MachineBasicBlock *, unsigned int> BBToOrder;
1363 std::priority_queue<unsigned int, std::vector<unsigned int>,
Adrian Prantl6ee02c72016-05-25 22:21:12 +00001364 std::greater<unsigned int>>
1365 Worklist;
Daniel Berlin72560592016-01-10 18:08:32 +00001366 std::priority_queue<unsigned int, std::vector<unsigned int>,
Adrian Prantl6ee02c72016-05-25 22:21:12 +00001367 std::greater<unsigned int>>
1368 Pending;
1369
Djordje Todorovic12aca5d2019-07-09 08:36:34 +00001370 // Working set of currently collected debug variables mapped to DBG_VALUEs
1371 // representing candidates for production of debug entry values.
1372 DebugParamMap DebugEntryVals;
1373
David Stenberg5e646ff2019-11-13 10:37:53 +01001374 // Set of register defines that are seen when traversing the entry block
1375 // looking for debug entry value candidates.
1376 DefinedRegsSet DefinedRegs;
1377
Djordje Todorovic12aca5d2019-07-09 08:36:34 +00001378 // Only in the case of entry MBB collect DBG_VALUEs representing
1379 // function parameters in order to generate debug entry values for them.
David Stenberg5e646ff2019-11-13 10:37:53 +01001380
David Stenberg4fec44c2019-11-13 10:36:13 +01001381 MachineBasicBlock &First_MBB = *(MF.begin());
David Stenberg5e646ff2019-11-13 10:37:53 +01001382 for (auto &MI : First_MBB) {
1383 collectRegDefs(MI, DefinedRegs, TRI);
1384 if (isEntryValueCandidate(MI, DefinedRegs) &&
David Stenberg4fec44c2019-11-13 10:36:13 +01001385 !DebugEntryVals.count(MI.getDebugVariable()))
Djordje Todorovic12aca5d2019-07-09 08:36:34 +00001386 DebugEntryVals[MI.getDebugVariable()] = &MI;
David Stenberg5e646ff2019-11-13 10:37:53 +01001387 }
Djordje Todorovic12aca5d2019-07-09 08:36:34 +00001388
Jeremy Morse313d2ce2019-08-29 10:53:29 +00001389 // Initialize per-block structures and scan for fragment overlaps.
Jeremy Morsebf2b2f02019-06-13 12:51:57 +00001390 for (auto &MBB : MF) {
Jeremy Morse67443c32019-08-21 09:22:31 +00001391 PendingInLocs[&MBB] = VarLocSet();
Jeremy Morse313d2ce2019-08-29 10:53:29 +00001392
1393 for (auto &MI : MBB) {
1394 if (MI.isDebugValue())
1395 accumulateFragmentMap(MI, SeenFragments, OverlapFragments);
1396 }
Jeremy Morsebf2b2f02019-06-13 12:51:57 +00001397 }
Adrian Prantl6ee02c72016-05-25 22:21:12 +00001398
Vedant Kumar8c466682018-10-05 21:44:15 +00001399 auto hasNonArtificialLocation = [](const MachineInstr &MI) -> bool {
1400 if (const DebugLoc &DL = MI.getDebugLoc())
1401 return DL.getLine() != 0;
1402 return false;
1403 };
1404 for (auto &MBB : MF)
1405 if (none_of(MBB.instrs(), hasNonArtificialLocation))
1406 ArtificialBlocks.insert(&MBB);
1407
Nicola Zaghend34e60c2018-05-14 12:53:11 +00001408 LLVM_DEBUG(printVarLocInMBB(MF, OutLocs, VarLocIDs,
1409 "OutLocs after initialization", dbgs()));
Vikram TV859ad292015-12-16 11:09:48 +00001410
Daniel Berlin72560592016-01-10 18:08:32 +00001411 ReversePostOrderTraversal<MachineFunction *> RPOT(&MF);
1412 unsigned int RPONumber = 0;
1413 for (auto RI = RPOT.begin(), RE = RPOT.end(); RI != RE; ++RI) {
1414 OrderToBB[RPONumber] = *RI;
1415 BBToOrder[*RI] = RPONumber;
1416 Worklist.push(RPONumber);
1417 ++RPONumber;
1418 }
Daniel Berlin72560592016-01-10 18:08:32 +00001419 // This is a standard "union of predecessor outs" dataflow problem.
Petar Jovanovicbe2e80a2018-07-13 08:24:26 +00001420 // To solve it, we perform join() and process() using the two worklist method
Daniel Berlin72560592016-01-10 18:08:32 +00001421 // until the ranges converge.
1422 // Ranges have converged when both worklists are empty.
Keith Walker83ebef52016-09-27 16:46:07 +00001423 SmallPtrSet<const MachineBasicBlock *, 16> Visited;
Daniel Berlin72560592016-01-10 18:08:32 +00001424 while (!Worklist.empty() || !Pending.empty()) {
1425 // We track what is on the pending worklist to avoid inserting the same
1426 // thing twice. We could avoid this with a custom priority queue, but this
1427 // is probably not worth it.
1428 SmallPtrSet<MachineBasicBlock *, 16> OnPending;
Nicola Zaghend34e60c2018-05-14 12:53:11 +00001429 LLVM_DEBUG(dbgs() << "Processing Worklist\n");
Daniel Berlin72560592016-01-10 18:08:32 +00001430 while (!Worklist.empty()) {
1431 MachineBasicBlock *MBB = OrderToBB[Worklist.top()];
1432 Worklist.pop();
Jeremy Morse67443c32019-08-21 09:22:31 +00001433 MBBJoined = join(*MBB, OutLocs, InLocs, VarLocIDs, Visited,
1434 ArtificialBlocks, PendingInLocs);
Jeremy Morse313d2ce2019-08-29 10:53:29 +00001435 MBBJoined |= Visited.insert(MBB).second;
Daniel Berlin72560592016-01-10 18:08:32 +00001436 if (MBBJoined) {
1437 MBBJoined = false;
1438 Changed = true;
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +00001439 // Now that we have started to extend ranges across BBs we need to
Djordje Todorovic8c99a542019-10-24 10:08:43 +02001440 // examine spill, copy and restore instructions to see whether they
1441 // operate with registers that correspond to user variables.
Jeremy Morse67443c32019-08-21 09:22:31 +00001442 // First load any pending inlocs.
1443 OpenRanges.insertFromLocSet(PendingInLocs[MBB], VarLocIDs);
Daniel Berlin72560592016-01-10 18:08:32 +00001444 for (auto &MI : *MBB)
Djordje Todorovic8c99a542019-10-24 10:08:43 +02001445 process(MI, OpenRanges, VarLocIDs, Transfers, DebugEntryVals);
Jeremy Morse67443c32019-08-21 09:22:31 +00001446 OLChanged |= transferTerminator(MBB, OpenRanges, OutLocs, VarLocIDs);
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +00001447
Nicola Zaghend34e60c2018-05-14 12:53:11 +00001448 LLVM_DEBUG(printVarLocInMBB(MF, OutLocs, VarLocIDs,
1449 "OutLocs after propagating", dbgs()));
1450 LLVM_DEBUG(printVarLocInMBB(MF, InLocs, VarLocIDs,
1451 "InLocs after propagating", dbgs()));
Vikram TV859ad292015-12-16 11:09:48 +00001452
Daniel Berlin72560592016-01-10 18:08:32 +00001453 if (OLChanged) {
1454 OLChanged = false;
1455 for (auto s : MBB->successors())
Benjamin Kramer4dea8f52016-06-17 18:59:41 +00001456 if (OnPending.insert(s).second) {
Daniel Berlin72560592016-01-10 18:08:32 +00001457 Pending.push(BBToOrder[s]);
1458 }
1459 }
Vikram TV859ad292015-12-16 11:09:48 +00001460 }
1461 }
Daniel Berlin72560592016-01-10 18:08:32 +00001462 Worklist.swap(Pending);
1463 // At this point, pending must be empty, since it was just the empty
1464 // worklist
1465 assert(Pending.empty() && "Pending should be empty");
Vikram TV859ad292015-12-16 11:09:48 +00001466 }
Daniel Berlin72560592016-01-10 18:08:32 +00001467
Jeremy Morse0ca48de22019-10-04 09:38:05 +00001468 // Add any DBG_VALUE instructions created by location transfers.
1469 for (auto &TR : Transfers) {
Jeremy Morse61800a72019-10-04 10:53:47 +00001470 MachineBasicBlock *MBB = TR.TransferInst->getParent();
1471 const VarLoc &VL = VarLocIDs[TR.LocationID];
1472 MachineInstr *MI = VL.BuildDbgValue(MF);
1473 MBB->insertAfterBundle(TR.TransferInst->getIterator(), MI);
Jeremy Morse0ca48de22019-10-04 09:38:05 +00001474 }
1475 Transfers.clear();
1476
Jeremy Morse67443c32019-08-21 09:22:31 +00001477 // Deferred inlocs will not have had any DBG_VALUE insts created; do
1478 // that now.
1479 flushPendingLocs(PendingInLocs, VarLocIDs);
1480
Nicola Zaghend34e60c2018-05-14 12:53:11 +00001481 LLVM_DEBUG(printVarLocInMBB(MF, OutLocs, VarLocIDs, "Final OutLocs", dbgs()));
1482 LLVM_DEBUG(printVarLocInMBB(MF, InLocs, VarLocIDs, "Final InLocs", dbgs()));
Vikram TV859ad292015-12-16 11:09:48 +00001483 return Changed;
1484}
1485
1486bool LiveDebugValues::runOnMachineFunction(MachineFunction &MF) {
Matthias Braunf1caa282017-12-15 22:22:58 +00001487 if (!MF.getFunction().getSubprogram())
Adrian Prantl7f5866c2016-09-28 17:51:14 +00001488 // LiveDebugValues will already have removed all DBG_VALUEs.
1489 return false;
1490
Wolfgang Piebe018bbd2017-07-19 19:36:40 +00001491 // Skip functions from NoDebug compilation units.
Matthias Braunf1caa282017-12-15 22:22:58 +00001492 if (MF.getFunction().getSubprogram()->getUnit()->getEmissionKind() ==
Wolfgang Piebe018bbd2017-07-19 19:36:40 +00001493 DICompileUnit::NoDebug)
1494 return false;
1495
Vikram TV859ad292015-12-16 11:09:48 +00001496 TRI = MF.getSubtarget().getRegisterInfo();
1497 TII = MF.getSubtarget().getInstrInfo();
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +00001498 TFI = MF.getSubtarget().getFrameLowering();
Sander de Smalend6a7da82019-10-29 12:49:34 +00001499 TFI->getCalleeSaves(MF, CalleeSavedRegs);
Adrian Prantl7f5866c2016-09-28 17:51:14 +00001500 LS.initialize(MF);
Vikram TV859ad292015-12-16 11:09:48 +00001501
Adrian Prantl7f5866c2016-09-28 17:51:14 +00001502 bool Changed = ExtendRanges(MF);
Vikram TV859ad292015-12-16 11:09:48 +00001503 return Changed;
1504}