blob: d18703803d3111f9a114c3047ca92c4baeb61f08 [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//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9///
10/// This pass implements a data flow analysis that propagates debug location
11/// information by inserting additional DBG_VALUE instructions into the machine
12/// instruction stream. The pass internally builds debug location liveness
13/// ranges to determine the points where additional DBG_VALUEs need to be
14/// inserted.
15///
16/// This is a separate pass from DbgValueHistoryCalculator to facilitate
17/// testing and improve modularity.
18///
19//===----------------------------------------------------------------------===//
20
Eugene Zelenko5df3d892017-08-24 21:21:39 +000021#include "llvm/ADT/DenseMap.h"
Daniel Berlin72560592016-01-10 18:08:32 +000022#include "llvm/ADT/PostOrderIterator.h"
23#include "llvm/ADT/SmallPtrSet.h"
Eugene Zelenko5df3d892017-08-24 21:21:39 +000024#include "llvm/ADT/SmallVector.h"
Adrian Prantl6ee02c72016-05-25 22:21:12 +000025#include "llvm/ADT/SparseBitVector.h"
Mehdi Aminib550cb12016-04-18 09:17:29 +000026#include "llvm/ADT/Statistic.h"
Adrian Prantl6ee02c72016-05-25 22:21:12 +000027#include "llvm/ADT/UniqueVector.h"
Adrian Prantl7f5866c2016-09-28 17:51:14 +000028#include "llvm/CodeGen/LexicalScopes.h"
Eugene Zelenko5df3d892017-08-24 21:21:39 +000029#include "llvm/CodeGen/MachineBasicBlock.h"
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +000030#include "llvm/CodeGen/MachineFrameInfo.h"
Vikram TV859ad292015-12-16 11:09:48 +000031#include "llvm/CodeGen/MachineFunction.h"
32#include "llvm/CodeGen/MachineFunctionPass.h"
Eugene Zelenko5df3d892017-08-24 21:21:39 +000033#include "llvm/CodeGen/MachineInstr.h"
Vikram TV859ad292015-12-16 11:09:48 +000034#include "llvm/CodeGen/MachineInstrBuilder.h"
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +000035#include "llvm/CodeGen/MachineMemOperand.h"
Eugene Zelenko5df3d892017-08-24 21:21:39 +000036#include "llvm/CodeGen/MachineOperand.h"
37#include "llvm/CodeGen/PseudoSourceValue.h"
David Blaikie3f833ed2017-11-08 01:01:31 +000038#include "llvm/CodeGen/TargetFrameLowering.h"
39#include "llvm/CodeGen/TargetInstrInfo.h"
David Blaikieb3bde2e2017-11-17 01:07:10 +000040#include "llvm/CodeGen/TargetLowering.h"
41#include "llvm/CodeGen/TargetRegisterInfo.h"
42#include "llvm/CodeGen/TargetSubtargetInfo.h"
Eugene Zelenko5df3d892017-08-24 21:21:39 +000043#include "llvm/IR/DebugInfoMetadata.h"
44#include "llvm/IR/DebugLoc.h"
45#include "llvm/IR/Function.h"
46#include "llvm/IR/Module.h"
47#include "llvm/MC/MCRegisterInfo.h"
48#include "llvm/Pass.h"
49#include "llvm/Support/Casting.h"
50#include "llvm/Support/Compiler.h"
Vikram TV859ad292015-12-16 11:09:48 +000051#include "llvm/Support/Debug.h"
52#include "llvm/Support/raw_ostream.h"
Eugene Zelenko5df3d892017-08-24 21:21:39 +000053#include <algorithm>
54#include <cassert>
55#include <cstdint>
56#include <functional>
Mehdi Aminib550cb12016-04-18 09:17:29 +000057#include <queue>
Eugene Zelenko5df3d892017-08-24 21:21:39 +000058#include <utility>
59#include <vector>
Vikram TV859ad292015-12-16 11:09:48 +000060
61using namespace llvm;
62
Matthias Braun1527baa2017-05-25 21:26:32 +000063#define DEBUG_TYPE "livedebugvalues"
Vikram TV859ad292015-12-16 11:09:48 +000064
65STATISTIC(NumInserted, "Number of DBG_VALUE instructions inserted");
66
Adrian Prantl6ee02c72016-05-25 22:21:12 +000067// \brief If @MI is a DBG_VALUE with debug value described by a defined
68// register, returns the number of this register. In the other case, returns 0.
Adrian Prantl00698732016-05-25 22:37:29 +000069static unsigned isDbgValueDescribedByReg(const MachineInstr &MI) {
Adrian Prantl6ee02c72016-05-25 22:21:12 +000070 assert(MI.isDebugValue() && "expected a DBG_VALUE");
71 assert(MI.getNumOperands() == 4 && "malformed DBG_VALUE");
72 // If location of variable is described using a register (directly
73 // or indirectly), this register is always a first operand.
74 return MI.getOperand(0).isReg() ? MI.getOperand(0).getReg() : 0;
75}
76
Eugene Zelenko5df3d892017-08-24 21:21:39 +000077namespace {
Vikram TV859ad292015-12-16 11:09:48 +000078
Eugene Zelenko5df3d892017-08-24 21:21:39 +000079class LiveDebugValues : public MachineFunctionPass {
Vikram TV859ad292015-12-16 11:09:48 +000080private:
81 const TargetRegisterInfo *TRI;
82 const TargetInstrInfo *TII;
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +000083 const TargetFrameLowering *TFI;
Adrian Prantl7f5866c2016-09-28 17:51:14 +000084 LexicalScopes LS;
85
86 /// Keeps track of lexical scopes associated with a user value's source
87 /// location.
88 class UserValueScopes {
89 DebugLoc DL;
90 LexicalScopes &LS;
91 SmallPtrSet<const MachineBasicBlock *, 4> LBlocks;
92
93 public:
94 UserValueScopes(DebugLoc D, LexicalScopes &L) : DL(std::move(D)), LS(L) {}
95
96 /// Return true if current scope dominates at least one machine
97 /// instruction in a given machine basic block.
98 bool dominates(MachineBasicBlock *MBB) {
99 if (LBlocks.empty())
100 LS.getMachineBasicBlocks(DL, LBlocks);
101 return LBlocks.count(MBB) != 0 || LS.dominates(DL, MBB);
102 }
103 };
Vikram TV859ad292015-12-16 11:09:48 +0000104
Adrian Prantl7509d542016-05-26 21:42:47 +0000105 /// Based on std::pair so it can be used as an index into a DenseMap.
Eugene Zelenko5df3d892017-08-24 21:21:39 +0000106 using DebugVariableBase =
107 std::pair<const DILocalVariable *, const DILocation *>;
Vikram TV859ad292015-12-16 11:09:48 +0000108 /// A potentially inlined instance of a variable.
Adrian Prantl7509d542016-05-26 21:42:47 +0000109 struct DebugVariable : public DebugVariableBase {
110 DebugVariable(const DILocalVariable *Var, const DILocation *InlinedAt)
111 : DebugVariableBase(Var, InlinedAt) {}
Vikram TV859ad292015-12-16 11:09:48 +0000112
Eugene Zelenko5df3d892017-08-24 21:21:39 +0000113 const DILocalVariable *getVar() const { return this->first; }
114 const DILocation *getInlinedAt() const { return this->second; }
Vikram TV859ad292015-12-16 11:09:48 +0000115
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000116 bool operator<(const DebugVariable &DV) const {
Adrian Prantl7509d542016-05-26 21:42:47 +0000117 if (getVar() == DV.getVar())
118 return getInlinedAt() < DV.getInlinedAt();
119 return getVar() < DV.getVar();
Vikram TV859ad292015-12-16 11:09:48 +0000120 }
121 };
122
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000123 /// A pair of debug variable and value location.
Vikram TV859ad292015-12-16 11:09:48 +0000124 struct VarLoc {
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000125 const DebugVariable Var;
126 const MachineInstr &MI; ///< Only used for cloning a new DBG_VALUE.
Adrian Prantl7f5866c2016-09-28 17:51:14 +0000127 mutable UserValueScopes UVS;
Eugene Zelenko5df3d892017-08-24 21:21:39 +0000128 enum { InvalidKind = 0, RegisterKind } Kind = InvalidKind;
Vikram TV859ad292015-12-16 11:09:48 +0000129
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000130 /// The value location. Stored separately to avoid repeatedly
131 /// extracting it from MI.
132 union {
Adrian Prantl359846f2017-07-28 23:25:51 +0000133 uint64_t RegNo;
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000134 uint64_t Hash;
135 } Loc;
136
Adrian Prantl7f5866c2016-09-28 17:51:14 +0000137 VarLoc(const MachineInstr &MI, LexicalScopes &LS)
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000138 : Var(MI.getDebugVariable(), MI.getDebugLoc()->getInlinedAt()), MI(MI),
Eugene Zelenko5df3d892017-08-24 21:21:39 +0000139 UVS(MI.getDebugLoc(), LS) {
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000140 static_assert((sizeof(Loc) == sizeof(uint64_t)),
141 "hash does not cover all members of Loc");
142 assert(MI.isDebugValue() && "not a DBG_VALUE");
143 assert(MI.getNumOperands() == 4 && "malformed DBG_VALUE");
Adrian Prantl00698732016-05-25 22:37:29 +0000144 if (int RegNo = isDbgValueDescribedByReg(MI)) {
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000145 Kind = RegisterKind;
Adrian Prantl359846f2017-07-28 23:25:51 +0000146 Loc.RegNo = RegNo;
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000147 }
148 }
149
150 /// If this variable is described by a register, return it,
151 /// otherwise return 0.
152 unsigned isDescribedByReg() const {
153 if (Kind == RegisterKind)
Adrian Prantl359846f2017-07-28 23:25:51 +0000154 return Loc.RegNo;
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000155 return 0;
156 }
157
Adrian Prantl7f5866c2016-09-28 17:51:14 +0000158 /// Determine whether the lexical scope of this value's debug location
159 /// dominates MBB.
160 bool dominates(MachineBasicBlock &MBB) const { return UVS.dominates(&MBB); }
161
Aaron Ballman615eb472017-10-15 14:32:27 +0000162#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Matthias Braun194ded52017-01-28 06:53:55 +0000163 LLVM_DUMP_METHOD void dump() const { MI.dump(); }
164#endif
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000165
166 bool operator==(const VarLoc &Other) const {
167 return Var == Other.Var && Loc.Hash == Other.Loc.Hash;
168 }
169
Adrian Prantl7509d542016-05-26 21:42:47 +0000170 /// This operator guarantees that VarLocs are sorted by Variable first.
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000171 bool operator<(const VarLoc &Other) const {
172 if (Var == Other.Var)
173 return Loc.Hash < Other.Loc.Hash;
174 return Var < Other.Var;
175 }
Vikram TV859ad292015-12-16 11:09:48 +0000176 };
177
Eugene Zelenko5df3d892017-08-24 21:21:39 +0000178 using VarLocMap = UniqueVector<VarLoc>;
179 using VarLocSet = SparseBitVector<>;
180 using VarLocInMBB = SmallDenseMap<const MachineBasicBlock *, VarLocSet>;
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000181 struct SpillDebugPair {
182 MachineInstr *SpillInst;
183 MachineInstr *DebugInst;
184 };
Eugene Zelenko5df3d892017-08-24 21:21:39 +0000185 using SpillMap = SmallVector<SpillDebugPair, 4>;
Vikram TV859ad292015-12-16 11:09:48 +0000186
Adrian Prantl7509d542016-05-26 21:42:47 +0000187 /// This holds the working set of currently open ranges. For fast
188 /// access, this is done both as a set of VarLocIDs, and a map of
189 /// DebugVariable to recent VarLocID. Note that a DBG_VALUE ends all
190 /// previous open ranges for the same variable.
191 class OpenRangesSet {
192 VarLocSet VarLocs;
193 SmallDenseMap<DebugVariableBase, unsigned, 8> Vars;
194
195 public:
196 const VarLocSet &getVarLocs() const { return VarLocs; }
197
198 /// Terminate all open ranges for Var by removing it from the set.
199 void erase(DebugVariable Var) {
200 auto It = Vars.find(Var);
201 if (It != Vars.end()) {
202 unsigned ID = It->second;
203 VarLocs.reset(ID);
204 Vars.erase(It);
205 }
206 }
207
208 /// Terminate all open ranges listed in \c KillSet by removing
209 /// them from the set.
210 void erase(const VarLocSet &KillSet, const VarLocMap &VarLocIDs) {
211 VarLocs.intersectWithComplement(KillSet);
212 for (unsigned ID : KillSet)
213 Vars.erase(VarLocIDs[ID].Var);
214 }
215
216 /// Insert a new range into the set.
217 void insert(unsigned VarLocID, DebugVariableBase Var) {
218 VarLocs.set(VarLocID);
219 Vars.insert({Var, VarLocID});
220 }
221
222 /// Empty the set.
223 void clear() {
224 VarLocs.clear();
225 Vars.clear();
226 }
227
228 /// Return whether the set is empty or not.
229 bool empty() const {
230 assert(Vars.empty() == VarLocs.empty() && "open ranges are inconsistent");
231 return VarLocs.empty();
232 }
233 };
234
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000235 bool isSpillInstruction(const MachineInstr &MI, MachineFunction *MF,
236 unsigned &Reg);
237 int extractSpillBaseRegAndOffset(const MachineInstr &MI, unsigned &Reg);
238
Adrian Prantl7509d542016-05-26 21:42:47 +0000239 void transferDebugValue(const MachineInstr &MI, OpenRangesSet &OpenRanges,
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000240 VarLocMap &VarLocIDs);
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000241 void transferSpillInst(MachineInstr &MI, OpenRangesSet &OpenRanges,
242 VarLocMap &VarLocIDs, SpillMap &Spills);
Adrian Prantl7509d542016-05-26 21:42:47 +0000243 void transferRegisterDef(MachineInstr &MI, OpenRangesSet &OpenRanges,
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000244 const VarLocMap &VarLocIDs);
Adrian Prantl7509d542016-05-26 21:42:47 +0000245 bool transferTerminatorInst(MachineInstr &MI, OpenRangesSet &OpenRanges,
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000246 VarLocInMBB &OutLocs, const VarLocMap &VarLocIDs);
Adrian Prantl7509d542016-05-26 21:42:47 +0000247 bool transfer(MachineInstr &MI, OpenRangesSet &OpenRanges,
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000248 VarLocInMBB &OutLocs, VarLocMap &VarLocIDs, SpillMap &Spills,
249 bool transferSpills);
Vikram TV859ad292015-12-16 11:09:48 +0000250
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000251 bool join(MachineBasicBlock &MBB, VarLocInMBB &OutLocs, VarLocInMBB &InLocs,
Keith Walker83ebef52016-09-27 16:46:07 +0000252 const VarLocMap &VarLocIDs,
253 SmallPtrSet<const MachineBasicBlock *, 16> &Visited);
Vikram TV859ad292015-12-16 11:09:48 +0000254
255 bool ExtendRanges(MachineFunction &MF);
256
257public:
258 static char ID;
259
260 /// Default construct and initialize the pass.
261 LiveDebugValues();
262
263 /// Tell the pass manager which passes we depend on and what
264 /// information we preserve.
265 void getAnalysisUsage(AnalysisUsage &AU) const override;
266
Derek Schuffad154c82016-03-28 17:05:30 +0000267 MachineFunctionProperties getRequiredProperties() const override {
268 return MachineFunctionProperties().set(
Matthias Braun1eb47362016-08-25 01:27:13 +0000269 MachineFunctionProperties::Property::NoVRegs);
Derek Schuffad154c82016-03-28 17:05:30 +0000270 }
271
Vikram TV859ad292015-12-16 11:09:48 +0000272 /// Print to ostream with a message.
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000273 void printVarLocInMBB(const MachineFunction &MF, const VarLocInMBB &V,
274 const VarLocMap &VarLocIDs, const char *msg,
Vikram TV859ad292015-12-16 11:09:48 +0000275 raw_ostream &Out) const;
276
277 /// Calculate the liveness information for the given machine function.
278 bool runOnMachineFunction(MachineFunction &MF) override;
279};
Adrian Prantl7f5866c2016-09-28 17:51:14 +0000280
Eugene Zelenko5df3d892017-08-24 21:21:39 +0000281} // end anonymous namespace
Vikram TV859ad292015-12-16 11:09:48 +0000282
283//===----------------------------------------------------------------------===//
284// Implementation
285//===----------------------------------------------------------------------===//
286
287char LiveDebugValues::ID = 0;
Eugene Zelenko5df3d892017-08-24 21:21:39 +0000288
Vikram TV859ad292015-12-16 11:09:48 +0000289char &llvm::LiveDebugValuesID = LiveDebugValues::ID;
Eugene Zelenko5df3d892017-08-24 21:21:39 +0000290
Matthias Braun1527baa2017-05-25 21:26:32 +0000291INITIALIZE_PASS(LiveDebugValues, DEBUG_TYPE, "Live DEBUG_VALUE analysis",
Vikram TV859ad292015-12-16 11:09:48 +0000292 false, false)
293
294/// Default construct and initialize the pass.
295LiveDebugValues::LiveDebugValues() : MachineFunctionPass(ID) {
296 initializeLiveDebugValuesPass(*PassRegistry::getPassRegistry());
297}
298
299/// Tell the pass manager which passes we depend on and what information we
300/// preserve.
301void LiveDebugValues::getAnalysisUsage(AnalysisUsage &AU) const {
Matt Arsenaultb1630a12016-06-08 05:18:01 +0000302 AU.setPreservesCFG();
Vikram TV859ad292015-12-16 11:09:48 +0000303 MachineFunctionPass::getAnalysisUsage(AU);
304}
305
Vikram TV859ad292015-12-16 11:09:48 +0000306//===----------------------------------------------------------------------===//
307// Debug Range Extension Implementation
308//===----------------------------------------------------------------------===//
309
Matthias Braun194ded52017-01-28 06:53:55 +0000310#ifndef NDEBUG
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000311void LiveDebugValues::printVarLocInMBB(const MachineFunction &MF,
312 const VarLocInMBB &V,
313 const VarLocMap &VarLocIDs,
314 const char *msg,
Vikram TV859ad292015-12-16 11:09:48 +0000315 raw_ostream &Out) const {
Keith Walkerf83a19f2016-09-20 16:04:31 +0000316 Out << '\n' << msg << '\n';
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000317 for (const MachineBasicBlock &BB : MF) {
318 const auto &L = V.lookup(&BB);
319 Out << "MBB: " << BB.getName() << ":\n";
320 for (unsigned VLL : L) {
321 const VarLoc &VL = VarLocIDs[VLL];
Adrian Prantl7509d542016-05-26 21:42:47 +0000322 Out << " Var: " << VL.Var.getVar()->getName();
Vikram TV859ad292015-12-16 11:09:48 +0000323 Out << " MI: ";
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000324 VL.dump();
Vikram TV859ad292015-12-16 11:09:48 +0000325 }
326 }
327 Out << "\n";
328}
Matthias Braun194ded52017-01-28 06:53:55 +0000329#endif
Vikram TV859ad292015-12-16 11:09:48 +0000330
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000331/// Given a spill instruction, extract the register and offset used to
332/// address the spill location in a target independent way.
333int LiveDebugValues::extractSpillBaseRegAndOffset(const MachineInstr &MI,
334 unsigned &Reg) {
335 assert(MI.hasOneMemOperand() &&
336 "Spill instruction does not have exactly one memory operand?");
337 auto MMOI = MI.memoperands_begin();
338 const PseudoSourceValue *PVal = (*MMOI)->getPseudoValue();
339 assert(PVal->kind() == PseudoSourceValue::FixedStack &&
340 "Inconsistent memory operand in spill instruction");
341 int FI = cast<FixedStackPseudoSourceValue>(PVal)->getFrameIndex();
342 const MachineBasicBlock *MBB = MI.getParent();
343 return TFI->getFrameIndexReference(*MBB->getParent(), FI, Reg);
344}
345
Vikram TV859ad292015-12-16 11:09:48 +0000346/// End all previous ranges related to @MI and start a new range from @MI
347/// if it is a DBG_VALUE instr.
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000348void LiveDebugValues::transferDebugValue(const MachineInstr &MI,
Adrian Prantl7509d542016-05-26 21:42:47 +0000349 OpenRangesSet &OpenRanges,
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000350 VarLocMap &VarLocIDs) {
Vikram TV859ad292015-12-16 11:09:48 +0000351 if (!MI.isDebugValue())
352 return;
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000353 const DILocalVariable *Var = MI.getDebugVariable();
354 const DILocation *DebugLoc = MI.getDebugLoc();
355 const DILocation *InlinedAt = DebugLoc->getInlinedAt();
356 assert(Var->isValidLocationForIntrinsic(DebugLoc) &&
Vikram TV859ad292015-12-16 11:09:48 +0000357 "Expected inlined-at fields to agree");
Vikram TV859ad292015-12-16 11:09:48 +0000358
359 // End all previous ranges of Var.
Adrian Prantl7509d542016-05-26 21:42:47 +0000360 DebugVariable V(Var, InlinedAt);
361 OpenRanges.erase(V);
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000362
363 // Add the VarLoc to OpenRanges from this DBG_VALUE.
364 // TODO: Currently handles DBG_VALUE which has only reg as location.
Adrian Prantl7509d542016-05-26 21:42:47 +0000365 if (isDbgValueDescribedByReg(MI)) {
Adrian Prantl7f5866c2016-09-28 17:51:14 +0000366 VarLoc VL(MI, LS);
Adrian Prantl7509d542016-05-26 21:42:47 +0000367 unsigned ID = VarLocIDs.insert(VL);
368 OpenRanges.insert(ID, VL.Var);
369 }
Vikram TV859ad292015-12-16 11:09:48 +0000370}
371
372/// A definition of a register may mark the end of a range.
373void LiveDebugValues::transferRegisterDef(MachineInstr &MI,
Adrian Prantl7509d542016-05-26 21:42:47 +0000374 OpenRangesSet &OpenRanges,
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000375 const VarLocMap &VarLocIDs) {
Justin Bognerfdf9bf42017-10-10 23:50:49 +0000376 MachineFunction *MF = MI.getMF();
Reid Klecknerf6f04f82016-03-25 17:54:46 +0000377 const TargetLowering *TLI = MF->getSubtarget().getTargetLowering();
378 unsigned SP = TLI->getStackPointerRegisterToSaveRestore();
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000379 SparseBitVector<> KillSet;
Vikram TV859ad292015-12-16 11:09:48 +0000380 for (const MachineOperand &MO : MI.operands()) {
Adrian Prantlea8880b2017-03-03 01:08:25 +0000381 // Determine whether the operand is a register def. Assume that call
382 // instructions never clobber SP, because some backends (e.g., AArch64)
383 // never list SP in the regmask.
Reid Klecknerf6f04f82016-03-25 17:54:46 +0000384 if (MO.isReg() && MO.isDef() && MO.getReg() &&
Adrian Prantlea8880b2017-03-03 01:08:25 +0000385 TRI->isPhysicalRegister(MO.getReg()) &&
386 !(MI.isCall() && MO.getReg() == SP)) {
Reid Klecknerf6f04f82016-03-25 17:54:46 +0000387 // Remove ranges of all aliased registers.
388 for (MCRegAliasIterator RAI(MO.getReg(), TRI, true); RAI.isValid(); ++RAI)
Adrian Prantl7509d542016-05-26 21:42:47 +0000389 for (unsigned ID : OpenRanges.getVarLocs())
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000390 if (VarLocIDs[ID].isDescribedByReg() == *RAI)
391 KillSet.set(ID);
Reid Klecknerf6f04f82016-03-25 17:54:46 +0000392 } else if (MO.isRegMask()) {
393 // Remove ranges of all clobbered registers. Register masks don't usually
394 // list SP as preserved. While the debug info may be off for an
395 // instruction or two around callee-cleanup calls, transferring the
396 // DEBUG_VALUE across the call is still a better user experience.
Adrian Prantl7509d542016-05-26 21:42:47 +0000397 for (unsigned ID : OpenRanges.getVarLocs()) {
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000398 unsigned Reg = VarLocIDs[ID].isDescribedByReg();
399 if (Reg && Reg != SP && MO.clobbersPhysReg(Reg))
400 KillSet.set(ID);
401 }
Reid Klecknerf6f04f82016-03-25 17:54:46 +0000402 }
Vikram TV859ad292015-12-16 11:09:48 +0000403 }
Adrian Prantl7509d542016-05-26 21:42:47 +0000404 OpenRanges.erase(KillSet, VarLocIDs);
Vikram TV859ad292015-12-16 11:09:48 +0000405}
406
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000407/// Decide if @MI is a spill instruction and return true if it is. We use 2
408/// criteria to make this decision:
409/// - Is this instruction a store to a spill slot?
410/// - Is there a register operand that is both used and killed?
411/// TODO: Store optimization can fold spills into other stores (including
412/// other spills). We do not handle this yet (more than one memory operand).
413bool LiveDebugValues::isSpillInstruction(const MachineInstr &MI,
414 MachineFunction *MF, unsigned &Reg) {
415 const MachineFrameInfo &FrameInfo = MF->getFrameInfo();
416 int FI;
417 const MachineMemOperand *MMO;
418
419 // TODO: Handle multiple stores folded into one.
420 if (!MI.hasOneMemOperand())
421 return false;
422
423 // To identify a spill instruction, use the same criteria as in AsmPrinter.
424 if (!((TII->isStoreToStackSlotPostFE(MI, FI) ||
425 TII->hasStoreToStackSlot(MI, MMO, FI)) &&
426 FrameInfo.isSpillSlotObjectIndex(FI)))
427 return false;
428
Petar Jovanovic0b464e42018-01-16 14:46:05 +0000429 auto isKilledReg = [&](const MachineOperand MO, unsigned &Reg) {
430 if (!MO.isReg() || !MO.isUse()) {
431 Reg = 0;
432 return false;
433 }
434 Reg = MO.getReg();
435 return MO.isKill();
436 };
437
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000438 for (const MachineOperand &MO : MI.operands()) {
Petar Jovanovic0b464e42018-01-16 14:46:05 +0000439 // In a spill instruction generated by the InlineSpiller the spilled
440 // register has its kill flag set.
441 if (isKilledReg(MO, Reg))
442 return true;
443 if (Reg != 0) {
444 // Check whether next instruction kills the spilled register.
445 // FIXME: Current solution does not cover search for killed register in
446 // bundles and instructions further down the chain.
447 auto NextI = std::next(MI.getIterator());
448 // Skip next instruction that points to basic block end iterator.
449 if (MI.getParent()->end() == NextI)
450 continue;
451 unsigned RegNext;
452 for (const MachineOperand &MONext : NextI->operands()) {
453 // Return true if we came across the register from the
454 // previous spill instruction that is killed in NextI.
455 if (isKilledReg(MONext, RegNext) && RegNext == Reg)
456 return true;
457 }
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000458 }
459 }
Petar Jovanovic0b464e42018-01-16 14:46:05 +0000460 // Return false if we didn't find spilled register.
461 return false;
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000462}
463
464/// A spilled register may indicate that we have to end the current range of
465/// a variable and create a new one for the spill location.
466/// We don't want to insert any instructions in transfer(), so we just create
467/// the DBG_VALUE witout inserting it and keep track of it in @Spills.
468/// It will be inserted into the BB when we're done iterating over the
469/// instructions.
470void LiveDebugValues::transferSpillInst(MachineInstr &MI,
471 OpenRangesSet &OpenRanges,
472 VarLocMap &VarLocIDs,
473 SpillMap &Spills) {
474 unsigned Reg;
Justin Bognerfdf9bf42017-10-10 23:50:49 +0000475 MachineFunction *MF = MI.getMF();
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000476 if (!isSpillInstruction(MI, MF, Reg))
477 return;
478
479 // Check if the register is the location of a debug value.
480 for (unsigned ID : OpenRanges.getVarLocs()) {
481 if (VarLocIDs[ID].isDescribedByReg() == Reg) {
Francis Visoiu Mistrih9d419d32017-11-28 12:42:37 +0000482 DEBUG(dbgs() << "Spilling Register " << printReg(Reg, TRI) << '('
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000483 << VarLocIDs[ID].Var.getVar()->getName() << ")\n");
484
485 // Create a DBG_VALUE instruction to describe the Var in its spilled
486 // location, but don't insert it yet to avoid invalidating the
487 // iterator in our caller.
488 unsigned SpillBase;
489 int SpillOffset = extractSpillBaseRegAndOffset(MI, SpillBase);
490 const MachineInstr *DMI = &VarLocIDs[ID].MI;
Adrian Prantl83ca4fc2017-08-02 00:16:56 +0000491 auto *SpillExpr = DIExpression::prepend(
492 DMI->getDebugExpression(), DIExpression::NoDeref, SpillOffset);
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000493 MachineInstr *SpDMI =
Adrian Prantl8b9bb532017-07-28 23:00:45 +0000494 BuildMI(*MF, DMI->getDebugLoc(), DMI->getDesc(), true, SpillBase,
Adrian Prantl83ca4fc2017-08-02 00:16:56 +0000495 DMI->getDebugVariable(), SpillExpr);
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000496 DEBUG(dbgs() << "Creating DBG_VALUE inst for spill: ";
497 SpDMI->print(dbgs(), false, TII));
498
499 // The newly created DBG_VALUE instruction SpDMI must be inserted after
500 // MI. Keep track of the pairing.
501 SpillDebugPair MIP = {&MI, SpDMI};
502 Spills.push_back(MIP);
503
504 // End all previous ranges of Var.
505 OpenRanges.erase(VarLocIDs[ID].Var);
506
507 // Add the VarLoc to OpenRanges.
508 VarLoc VL(*SpDMI, LS);
509 unsigned SpillLocID = VarLocIDs.insert(VL);
510 OpenRanges.insert(SpillLocID, VL.Var);
511 return;
512 }
513 }
514}
515
Vikram TV859ad292015-12-16 11:09:48 +0000516/// Terminate all open ranges at the end of the current basic block.
Daniel Berlinca4d93a2016-01-10 03:25:42 +0000517bool LiveDebugValues::transferTerminatorInst(MachineInstr &MI,
Adrian Prantl7509d542016-05-26 21:42:47 +0000518 OpenRangesSet &OpenRanges,
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000519 VarLocInMBB &OutLocs,
520 const VarLocMap &VarLocIDs) {
Daniel Berlinca4d93a2016-01-10 03:25:42 +0000521 bool Changed = false;
Vikram TV859ad292015-12-16 11:09:48 +0000522 const MachineBasicBlock *CurMBB = MI.getParent();
Petar Jovanovice9500ba2018-01-08 18:21:15 +0000523 if (!(MI.isTerminator() || (&MI == &CurMBB->back())))
Daniel Berlinca4d93a2016-01-10 03:25:42 +0000524 return false;
Vikram TV859ad292015-12-16 11:09:48 +0000525
526 if (OpenRanges.empty())
Daniel Berlinca4d93a2016-01-10 03:25:42 +0000527 return false;
Vikram TV859ad292015-12-16 11:09:48 +0000528
Adrian Prantl7509d542016-05-26 21:42:47 +0000529 DEBUG(for (unsigned ID : OpenRanges.getVarLocs()) {
530 // Copy OpenRanges to OutLocs, if not already present.
531 dbgs() << "Add to OutLocs: "; VarLocIDs[ID].dump();
532 });
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000533 VarLocSet &VLS = OutLocs[CurMBB];
Adrian Prantl7509d542016-05-26 21:42:47 +0000534 Changed = VLS |= OpenRanges.getVarLocs();
Vikram TV859ad292015-12-16 11:09:48 +0000535 OpenRanges.clear();
Daniel Berlinca4d93a2016-01-10 03:25:42 +0000536 return Changed;
Vikram TV859ad292015-12-16 11:09:48 +0000537}
538
539/// This routine creates OpenRanges and OutLocs.
Adrian Prantl7509d542016-05-26 21:42:47 +0000540bool LiveDebugValues::transfer(MachineInstr &MI, OpenRangesSet &OpenRanges,
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000541 VarLocInMBB &OutLocs, VarLocMap &VarLocIDs,
542 SpillMap &Spills, bool transferSpills) {
Daniel Berlinca4d93a2016-01-10 03:25:42 +0000543 bool Changed = false;
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000544 transferDebugValue(MI, OpenRanges, VarLocIDs);
545 transferRegisterDef(MI, OpenRanges, VarLocIDs);
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000546 if (transferSpills)
547 transferSpillInst(MI, OpenRanges, VarLocIDs, Spills);
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000548 Changed = transferTerminatorInst(MI, OpenRanges, OutLocs, VarLocIDs);
Daniel Berlinca4d93a2016-01-10 03:25:42 +0000549 return Changed;
Vikram TV859ad292015-12-16 11:09:48 +0000550}
551
552/// This routine joins the analysis results of all incoming edges in @MBB by
553/// inserting a new DBG_VALUE instruction at the start of the @MBB - if the same
554/// source variable in all the predecessors of @MBB reside in the same location.
Daniel Berlinca4d93a2016-01-10 03:25:42 +0000555bool LiveDebugValues::join(MachineBasicBlock &MBB, VarLocInMBB &OutLocs,
Keith Walker83ebef52016-09-27 16:46:07 +0000556 VarLocInMBB &InLocs, const VarLocMap &VarLocIDs,
557 SmallPtrSet<const MachineBasicBlock *, 16> &Visited) {
Vikram TV859ad292015-12-16 11:09:48 +0000558 DEBUG(dbgs() << "join MBB: " << MBB.getName() << "\n");
Daniel Berlinca4d93a2016-01-10 03:25:42 +0000559 bool Changed = false;
Vikram TV859ad292015-12-16 11:09:48 +0000560
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000561 VarLocSet InLocsT; // Temporary incoming locations.
Vikram TV859ad292015-12-16 11:09:48 +0000562
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000563 // For all predecessors of this MBB, find the set of VarLocs that
564 // can be joined.
Keith Walker83ebef52016-09-27 16:46:07 +0000565 int NumVisited = 0;
Vikram TV859ad292015-12-16 11:09:48 +0000566 for (auto p : MBB.predecessors()) {
Keith Walker83ebef52016-09-27 16:46:07 +0000567 // Ignore unvisited predecessor blocks. As we are processing
568 // the blocks in reverse post-order any unvisited block can
569 // be considered to not remove any incoming values.
570 if (!Visited.count(p))
571 continue;
Vikram TV859ad292015-12-16 11:09:48 +0000572 auto OL = OutLocs.find(p);
573 // Join is null in case of empty OutLocs from any of the pred.
574 if (OL == OutLocs.end())
Daniel Berlinca4d93a2016-01-10 03:25:42 +0000575 return false;
Vikram TV859ad292015-12-16 11:09:48 +0000576
Keith Walker83ebef52016-09-27 16:46:07 +0000577 // Just copy over the Out locs to incoming locs for the first visited
578 // predecessor, and for all other predecessors join the Out locs.
579 if (!NumVisited)
Vikram TV859ad292015-12-16 11:09:48 +0000580 InLocsT = OL->second;
Keith Walker83ebef52016-09-27 16:46:07 +0000581 else
582 InLocsT &= OL->second;
583 NumVisited++;
Vikram TV859ad292015-12-16 11:09:48 +0000584 }
585
Adrian Prantl7f5866c2016-09-28 17:51:14 +0000586 // Filter out DBG_VALUES that are out of scope.
587 VarLocSet KillSet;
588 for (auto ID : InLocsT)
589 if (!VarLocIDs[ID].dominates(MBB))
590 KillSet.set(ID);
591 InLocsT.intersectWithComplement(KillSet);
592
Keith Walker83ebef52016-09-27 16:46:07 +0000593 // As we are processing blocks in reverse post-order we
594 // should have processed at least one predecessor, unless it
595 // is the entry block which has no predecessor.
596 assert((NumVisited || MBB.pred_empty()) &&
597 "Should have processed at least one predecessor");
Vikram TV859ad292015-12-16 11:09:48 +0000598 if (InLocsT.empty())
Daniel Berlinca4d93a2016-01-10 03:25:42 +0000599 return false;
Vikram TV859ad292015-12-16 11:09:48 +0000600
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000601 VarLocSet &ILS = InLocs[&MBB];
Vikram TV859ad292015-12-16 11:09:48 +0000602
603 // Insert DBG_VALUE instructions, if not already inserted.
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000604 VarLocSet Diff = InLocsT;
605 Diff.intersectWithComplement(ILS);
606 for (auto ID : Diff) {
607 // This VarLoc is not found in InLocs i.e. it is not yet inserted. So, a
608 // new range is started for the var from the mbb's beginning by inserting
609 // a new DBG_VALUE. transfer() will end this range however appropriate.
610 const VarLoc &DiffIt = VarLocIDs[ID];
611 const MachineInstr *DMI = &DiffIt.MI;
612 MachineInstr *MI =
613 BuildMI(MBB, MBB.instr_begin(), DMI->getDebugLoc(), DMI->getDesc(),
Adrian Prantl8b9bb532017-07-28 23:00:45 +0000614 DMI->isIndirectDebugValue(), DMI->getOperand(0).getReg(),
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000615 DMI->getDebugVariable(), DMI->getDebugExpression());
616 if (DMI->isIndirectDebugValue())
617 MI->getOperand(1).setImm(DMI->getOperand(1).getImm());
618 DEBUG(dbgs() << "Inserted: "; MI->dump(););
619 ILS.set(ID);
620 ++NumInserted;
621 Changed = true;
Vikram TV859ad292015-12-16 11:09:48 +0000622 }
Daniel Berlinca4d93a2016-01-10 03:25:42 +0000623 return Changed;
Vikram TV859ad292015-12-16 11:09:48 +0000624}
625
626/// Calculate the liveness information for the given machine function and
627/// extend ranges across basic blocks.
628bool LiveDebugValues::ExtendRanges(MachineFunction &MF) {
Vikram TV859ad292015-12-16 11:09:48 +0000629 DEBUG(dbgs() << "\nDebug Range Extension\n");
630
631 bool Changed = false;
Daniel Berlinca4d93a2016-01-10 03:25:42 +0000632 bool OLChanged = false;
633 bool MBBJoined = false;
Vikram TV859ad292015-12-16 11:09:48 +0000634
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000635 VarLocMap VarLocIDs; // Map VarLoc<>unique ID for use in bitvectors.
Adrian Prantl7509d542016-05-26 21:42:47 +0000636 OpenRangesSet OpenRanges; // Ranges that are open until end of bb.
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000637 VarLocInMBB OutLocs; // Ranges that exist beyond bb.
638 VarLocInMBB InLocs; // Ranges that are incoming after joining.
639 SpillMap Spills; // DBG_VALUEs associated with spills.
Vikram TV859ad292015-12-16 11:09:48 +0000640
Daniel Berlin72560592016-01-10 18:08:32 +0000641 DenseMap<unsigned int, MachineBasicBlock *> OrderToBB;
642 DenseMap<MachineBasicBlock *, unsigned int> BBToOrder;
643 std::priority_queue<unsigned int, std::vector<unsigned int>,
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000644 std::greater<unsigned int>>
645 Worklist;
Daniel Berlin72560592016-01-10 18:08:32 +0000646 std::priority_queue<unsigned int, std::vector<unsigned int>,
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000647 std::greater<unsigned int>>
648 Pending;
649
Vikram TV859ad292015-12-16 11:09:48 +0000650 // Initialize every mbb with OutLocs.
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000651 // We are not looking at any spill instructions during the initial pass
652 // over the BBs. The LiveDebugVariables pass has already created DBG_VALUE
653 // instructions for spills of registers that are known to be user variables
654 // within the BB in which the spill occurs.
Vikram TV859ad292015-12-16 11:09:48 +0000655 for (auto &MBB : MF)
656 for (auto &MI : MBB)
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000657 transfer(MI, OpenRanges, OutLocs, VarLocIDs, Spills,
658 /*transferSpills=*/false);
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000659
660 DEBUG(printVarLocInMBB(MF, OutLocs, VarLocIDs, "OutLocs after initialization",
661 dbgs()));
Vikram TV859ad292015-12-16 11:09:48 +0000662
Daniel Berlin72560592016-01-10 18:08:32 +0000663 ReversePostOrderTraversal<MachineFunction *> RPOT(&MF);
664 unsigned int RPONumber = 0;
665 for (auto RI = RPOT.begin(), RE = RPOT.end(); RI != RE; ++RI) {
666 OrderToBB[RPONumber] = *RI;
667 BBToOrder[*RI] = RPONumber;
668 Worklist.push(RPONumber);
669 ++RPONumber;
670 }
Daniel Berlin72560592016-01-10 18:08:32 +0000671 // This is a standard "union of predecessor outs" dataflow problem.
672 // To solve it, we perform join() and transfer() using the two worklist method
673 // until the ranges converge.
674 // Ranges have converged when both worklists are empty.
Keith Walker83ebef52016-09-27 16:46:07 +0000675 SmallPtrSet<const MachineBasicBlock *, 16> Visited;
Daniel Berlin72560592016-01-10 18:08:32 +0000676 while (!Worklist.empty() || !Pending.empty()) {
677 // We track what is on the pending worklist to avoid inserting the same
678 // thing twice. We could avoid this with a custom priority queue, but this
679 // is probably not worth it.
680 SmallPtrSet<MachineBasicBlock *, 16> OnPending;
Keith Walkerf83a19f2016-09-20 16:04:31 +0000681 DEBUG(dbgs() << "Processing Worklist\n");
Daniel Berlin72560592016-01-10 18:08:32 +0000682 while (!Worklist.empty()) {
683 MachineBasicBlock *MBB = OrderToBB[Worklist.top()];
684 Worklist.pop();
Keith Walker83ebef52016-09-27 16:46:07 +0000685 MBBJoined = join(*MBB, OutLocs, InLocs, VarLocIDs, Visited);
686 Visited.insert(MBB);
Daniel Berlin72560592016-01-10 18:08:32 +0000687 if (MBBJoined) {
688 MBBJoined = false;
689 Changed = true;
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000690 // Now that we have started to extend ranges across BBs we need to
691 // examine spill instructions to see whether they spill registers that
692 // correspond to user variables.
Daniel Berlin72560592016-01-10 18:08:32 +0000693 for (auto &MI : *MBB)
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000694 OLChanged |= transfer(MI, OpenRanges, OutLocs, VarLocIDs, Spills,
695 /*transferSpills=*/true);
696
697 // Add any DBG_VALUE instructions necessitated by spills.
698 for (auto &SP : Spills)
699 MBB->insertAfter(MachineBasicBlock::iterator(*SP.SpillInst),
700 SP.DebugInst);
701 Spills.clear();
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000702
703 DEBUG(printVarLocInMBB(MF, OutLocs, VarLocIDs,
704 "OutLocs after propagating", dbgs()));
705 DEBUG(printVarLocInMBB(MF, InLocs, VarLocIDs,
706 "InLocs after propagating", dbgs()));
Vikram TV859ad292015-12-16 11:09:48 +0000707
Daniel Berlin72560592016-01-10 18:08:32 +0000708 if (OLChanged) {
709 OLChanged = false;
710 for (auto s : MBB->successors())
Benjamin Kramer4dea8f52016-06-17 18:59:41 +0000711 if (OnPending.insert(s).second) {
Daniel Berlin72560592016-01-10 18:08:32 +0000712 Pending.push(BBToOrder[s]);
713 }
714 }
Vikram TV859ad292015-12-16 11:09:48 +0000715 }
716 }
Daniel Berlin72560592016-01-10 18:08:32 +0000717 Worklist.swap(Pending);
718 // At this point, pending must be empty, since it was just the empty
719 // worklist
720 assert(Pending.empty() && "Pending should be empty");
Vikram TV859ad292015-12-16 11:09:48 +0000721 }
Daniel Berlin72560592016-01-10 18:08:32 +0000722
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000723 DEBUG(printVarLocInMBB(MF, OutLocs, VarLocIDs, "Final OutLocs", dbgs()));
724 DEBUG(printVarLocInMBB(MF, InLocs, VarLocIDs, "Final InLocs", dbgs()));
Vikram TV859ad292015-12-16 11:09:48 +0000725 return Changed;
726}
727
728bool LiveDebugValues::runOnMachineFunction(MachineFunction &MF) {
Matthias Braunf1caa282017-12-15 22:22:58 +0000729 if (!MF.getFunction().getSubprogram())
Adrian Prantl7f5866c2016-09-28 17:51:14 +0000730 // LiveDebugValues will already have removed all DBG_VALUEs.
731 return false;
732
Wolfgang Piebe018bbd2017-07-19 19:36:40 +0000733 // Skip functions from NoDebug compilation units.
Matthias Braunf1caa282017-12-15 22:22:58 +0000734 if (MF.getFunction().getSubprogram()->getUnit()->getEmissionKind() ==
Wolfgang Piebe018bbd2017-07-19 19:36:40 +0000735 DICompileUnit::NoDebug)
736 return false;
737
Vikram TV859ad292015-12-16 11:09:48 +0000738 TRI = MF.getSubtarget().getRegisterInfo();
739 TII = MF.getSubtarget().getInstrInfo();
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000740 TFI = MF.getSubtarget().getFrameLowering();
Adrian Prantl7f5866c2016-09-28 17:51:14 +0000741 LS.initialize(MF);
Vikram TV859ad292015-12-16 11:09:48 +0000742
Adrian Prantl7f5866c2016-09-28 17:51:14 +0000743 bool Changed = ExtendRanges(MF);
Vikram TV859ad292015-12-16 11:09:48 +0000744 return Changed;
745}