blob: 0554908584ee1a9017be2cd127935630267cd545 [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"
Nico Weber432a3882018-04-30 14:59:11 +000043#include "llvm/Config/llvm-config.h"
Eugene Zelenko5df3d892017-08-24 21:21:39 +000044#include "llvm/IR/DebugInfoMetadata.h"
45#include "llvm/IR/DebugLoc.h"
46#include "llvm/IR/Function.h"
47#include "llvm/IR/Module.h"
48#include "llvm/MC/MCRegisterInfo.h"
49#include "llvm/Pass.h"
50#include "llvm/Support/Casting.h"
51#include "llvm/Support/Compiler.h"
Vikram TV859ad292015-12-16 11:09:48 +000052#include "llvm/Support/Debug.h"
53#include "llvm/Support/raw_ostream.h"
Eugene Zelenko5df3d892017-08-24 21:21:39 +000054#include <algorithm>
55#include <cassert>
56#include <cstdint>
57#include <functional>
Mehdi Aminib550cb12016-04-18 09:17:29 +000058#include <queue>
Eugene Zelenko5df3d892017-08-24 21:21:39 +000059#include <utility>
60#include <vector>
Vikram TV859ad292015-12-16 11:09:48 +000061
62using namespace llvm;
63
Matthias Braun1527baa2017-05-25 21:26:32 +000064#define DEBUG_TYPE "livedebugvalues"
Vikram TV859ad292015-12-16 11:09:48 +000065
66STATISTIC(NumInserted, "Number of DBG_VALUE instructions inserted");
67
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000068// If @MI is a DBG_VALUE with debug value described by a defined
Adrian Prantl6ee02c72016-05-25 22:21:12 +000069// register, returns the number of this register. In the other case, returns 0.
Adrian Prantl00698732016-05-25 22:37:29 +000070static unsigned isDbgValueDescribedByReg(const MachineInstr &MI) {
Adrian Prantl6ee02c72016-05-25 22:21:12 +000071 assert(MI.isDebugValue() && "expected a DBG_VALUE");
72 assert(MI.getNumOperands() == 4 && "malformed DBG_VALUE");
73 // If location of variable is described using a register (directly
74 // or indirectly), this register is always a first operand.
75 return MI.getOperand(0).isReg() ? MI.getOperand(0).getReg() : 0;
76}
77
Eugene Zelenko5df3d892017-08-24 21:21:39 +000078namespace {
Vikram TV859ad292015-12-16 11:09:48 +000079
Eugene Zelenko5df3d892017-08-24 21:21:39 +000080class LiveDebugValues : public MachineFunctionPass {
Vikram TV859ad292015-12-16 11:09:48 +000081private:
82 const TargetRegisterInfo *TRI;
83 const TargetInstrInfo *TII;
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +000084 const TargetFrameLowering *TFI;
Adrian Prantl7f5866c2016-09-28 17:51:14 +000085 LexicalScopes LS;
86
87 /// Keeps track of lexical scopes associated with a user value's source
88 /// location.
89 class UserValueScopes {
90 DebugLoc DL;
91 LexicalScopes &LS;
92 SmallPtrSet<const MachineBasicBlock *, 4> LBlocks;
93
94 public:
95 UserValueScopes(DebugLoc D, LexicalScopes &L) : DL(std::move(D)), LS(L) {}
96
97 /// Return true if current scope dominates at least one machine
98 /// instruction in a given machine basic block.
99 bool dominates(MachineBasicBlock *MBB) {
100 if (LBlocks.empty())
101 LS.getMachineBasicBlocks(DL, LBlocks);
102 return LBlocks.count(MBB) != 0 || LS.dominates(DL, MBB);
103 }
104 };
Vikram TV859ad292015-12-16 11:09:48 +0000105
Adrian Prantl7509d542016-05-26 21:42:47 +0000106 /// Based on std::pair so it can be used as an index into a DenseMap.
Eugene Zelenko5df3d892017-08-24 21:21:39 +0000107 using DebugVariableBase =
108 std::pair<const DILocalVariable *, const DILocation *>;
Vikram TV859ad292015-12-16 11:09:48 +0000109 /// A potentially inlined instance of a variable.
Adrian Prantl7509d542016-05-26 21:42:47 +0000110 struct DebugVariable : public DebugVariableBase {
111 DebugVariable(const DILocalVariable *Var, const DILocation *InlinedAt)
112 : DebugVariableBase(Var, InlinedAt) {}
Vikram TV859ad292015-12-16 11:09:48 +0000113
Eugene Zelenko5df3d892017-08-24 21:21:39 +0000114 const DILocalVariable *getVar() const { return this->first; }
115 const DILocation *getInlinedAt() const { return this->second; }
Vikram TV859ad292015-12-16 11:09:48 +0000116
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000117 bool operator<(const DebugVariable &DV) const {
Adrian Prantl7509d542016-05-26 21:42:47 +0000118 if (getVar() == DV.getVar())
119 return getInlinedAt() < DV.getInlinedAt();
120 return getVar() < DV.getVar();
Vikram TV859ad292015-12-16 11:09:48 +0000121 }
122 };
123
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000124 /// A pair of debug variable and value location.
Vikram TV859ad292015-12-16 11:09:48 +0000125 struct VarLoc {
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000126 const DebugVariable Var;
127 const MachineInstr &MI; ///< Only used for cloning a new DBG_VALUE.
Adrian Prantl7f5866c2016-09-28 17:51:14 +0000128 mutable UserValueScopes UVS;
Eugene Zelenko5df3d892017-08-24 21:21:39 +0000129 enum { InvalidKind = 0, RegisterKind } Kind = InvalidKind;
Vikram TV859ad292015-12-16 11:09:48 +0000130
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000131 /// The value location. Stored separately to avoid repeatedly
132 /// extracting it from MI.
133 union {
Adrian Prantl359846f2017-07-28 23:25:51 +0000134 uint64_t RegNo;
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000135 uint64_t Hash;
136 } Loc;
137
Adrian Prantl7f5866c2016-09-28 17:51:14 +0000138 VarLoc(const MachineInstr &MI, LexicalScopes &LS)
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000139 : Var(MI.getDebugVariable(), MI.getDebugLoc()->getInlinedAt()), MI(MI),
Eugene Zelenko5df3d892017-08-24 21:21:39 +0000140 UVS(MI.getDebugLoc(), LS) {
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000141 static_assert((sizeof(Loc) == sizeof(uint64_t)),
142 "hash does not cover all members of Loc");
143 assert(MI.isDebugValue() && "not a DBG_VALUE");
144 assert(MI.getNumOperands() == 4 && "malformed DBG_VALUE");
Adrian Prantl00698732016-05-25 22:37:29 +0000145 if (int RegNo = isDbgValueDescribedByReg(MI)) {
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000146 Kind = RegisterKind;
Adrian Prantl359846f2017-07-28 23:25:51 +0000147 Loc.RegNo = RegNo;
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000148 }
149 }
150
151 /// If this variable is described by a register, return it,
152 /// otherwise return 0.
153 unsigned isDescribedByReg() const {
154 if (Kind == RegisterKind)
Adrian Prantl359846f2017-07-28 23:25:51 +0000155 return Loc.RegNo;
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000156 return 0;
157 }
158
Adrian Prantl7f5866c2016-09-28 17:51:14 +0000159 /// Determine whether the lexical scope of this value's debug location
160 /// dominates MBB.
161 bool dominates(MachineBasicBlock &MBB) const { return UVS.dominates(&MBB); }
162
Aaron Ballman615eb472017-10-15 14:32:27 +0000163#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Matthias Braun194ded52017-01-28 06:53:55 +0000164 LLVM_DUMP_METHOD void dump() const { MI.dump(); }
165#endif
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000166
167 bool operator==(const VarLoc &Other) const {
168 return Var == Other.Var && Loc.Hash == Other.Loc.Hash;
169 }
170
Adrian Prantl7509d542016-05-26 21:42:47 +0000171 /// This operator guarantees that VarLocs are sorted by Variable first.
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000172 bool operator<(const VarLoc &Other) const {
173 if (Var == Other.Var)
174 return Loc.Hash < Other.Loc.Hash;
175 return Var < Other.Var;
176 }
Vikram TV859ad292015-12-16 11:09:48 +0000177 };
178
Eugene Zelenko5df3d892017-08-24 21:21:39 +0000179 using VarLocMap = UniqueVector<VarLoc>;
180 using VarLocSet = SparseBitVector<>;
181 using VarLocInMBB = SmallDenseMap<const MachineBasicBlock *, VarLocSet>;
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000182 struct SpillDebugPair {
183 MachineInstr *SpillInst;
184 MachineInstr *DebugInst;
185 };
Eugene Zelenko5df3d892017-08-24 21:21:39 +0000186 using SpillMap = SmallVector<SpillDebugPair, 4>;
Vikram TV859ad292015-12-16 11:09:48 +0000187
Adrian Prantl7509d542016-05-26 21:42:47 +0000188 /// This holds the working set of currently open ranges. For fast
189 /// access, this is done both as a set of VarLocIDs, and a map of
190 /// DebugVariable to recent VarLocID. Note that a DBG_VALUE ends all
191 /// previous open ranges for the same variable.
192 class OpenRangesSet {
193 VarLocSet VarLocs;
194 SmallDenseMap<DebugVariableBase, unsigned, 8> Vars;
195
196 public:
197 const VarLocSet &getVarLocs() const { return VarLocs; }
198
199 /// Terminate all open ranges for Var by removing it from the set.
200 void erase(DebugVariable Var) {
201 auto It = Vars.find(Var);
202 if (It != Vars.end()) {
203 unsigned ID = It->second;
204 VarLocs.reset(ID);
205 Vars.erase(It);
206 }
207 }
208
209 /// Terminate all open ranges listed in \c KillSet by removing
210 /// them from the set.
211 void erase(const VarLocSet &KillSet, const VarLocMap &VarLocIDs) {
212 VarLocs.intersectWithComplement(KillSet);
213 for (unsigned ID : KillSet)
214 Vars.erase(VarLocIDs[ID].Var);
215 }
216
217 /// Insert a new range into the set.
218 void insert(unsigned VarLocID, DebugVariableBase Var) {
219 VarLocs.set(VarLocID);
220 Vars.insert({Var, VarLocID});
221 }
222
223 /// Empty the set.
224 void clear() {
225 VarLocs.clear();
226 Vars.clear();
227 }
228
229 /// Return whether the set is empty or not.
230 bool empty() const {
231 assert(Vars.empty() == VarLocs.empty() && "open ranges are inconsistent");
232 return VarLocs.empty();
233 }
234 };
235
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000236 bool isSpillInstruction(const MachineInstr &MI, MachineFunction *MF,
237 unsigned &Reg);
238 int extractSpillBaseRegAndOffset(const MachineInstr &MI, unsigned &Reg);
239
Adrian Prantl7509d542016-05-26 21:42:47 +0000240 void transferDebugValue(const MachineInstr &MI, OpenRangesSet &OpenRanges,
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000241 VarLocMap &VarLocIDs);
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000242 void transferSpillInst(MachineInstr &MI, OpenRangesSet &OpenRanges,
243 VarLocMap &VarLocIDs, SpillMap &Spills);
Adrian Prantl7509d542016-05-26 21:42:47 +0000244 void transferRegisterDef(MachineInstr &MI, OpenRangesSet &OpenRanges,
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000245 const VarLocMap &VarLocIDs);
Adrian Prantl7509d542016-05-26 21:42:47 +0000246 bool transferTerminatorInst(MachineInstr &MI, OpenRangesSet &OpenRanges,
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000247 VarLocInMBB &OutLocs, const VarLocMap &VarLocIDs);
Adrian Prantl7509d542016-05-26 21:42:47 +0000248 bool transfer(MachineInstr &MI, OpenRangesSet &OpenRanges,
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000249 VarLocInMBB &OutLocs, VarLocMap &VarLocIDs, SpillMap &Spills,
250 bool transferSpills);
Vikram TV859ad292015-12-16 11:09:48 +0000251
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000252 bool join(MachineBasicBlock &MBB, VarLocInMBB &OutLocs, VarLocInMBB &InLocs,
Keith Walker83ebef52016-09-27 16:46:07 +0000253 const VarLocMap &VarLocIDs,
254 SmallPtrSet<const MachineBasicBlock *, 16> &Visited);
Vikram TV859ad292015-12-16 11:09:48 +0000255
256 bool ExtendRanges(MachineFunction &MF);
257
258public:
259 static char ID;
260
261 /// Default construct and initialize the pass.
262 LiveDebugValues();
263
264 /// Tell the pass manager which passes we depend on and what
265 /// information we preserve.
266 void getAnalysisUsage(AnalysisUsage &AU) const override;
267
Derek Schuffad154c82016-03-28 17:05:30 +0000268 MachineFunctionProperties getRequiredProperties() const override {
269 return MachineFunctionProperties().set(
Matthias Braun1eb47362016-08-25 01:27:13 +0000270 MachineFunctionProperties::Property::NoVRegs);
Derek Schuffad154c82016-03-28 17:05:30 +0000271 }
272
Vikram TV859ad292015-12-16 11:09:48 +0000273 /// Print to ostream with a message.
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000274 void printVarLocInMBB(const MachineFunction &MF, const VarLocInMBB &V,
275 const VarLocMap &VarLocIDs, const char *msg,
Vikram TV859ad292015-12-16 11:09:48 +0000276 raw_ostream &Out) const;
277
278 /// Calculate the liveness information for the given machine function.
279 bool runOnMachineFunction(MachineFunction &MF) override;
280};
Adrian Prantl7f5866c2016-09-28 17:51:14 +0000281
Eugene Zelenko5df3d892017-08-24 21:21:39 +0000282} // end anonymous namespace
Vikram TV859ad292015-12-16 11:09:48 +0000283
284//===----------------------------------------------------------------------===//
285// Implementation
286//===----------------------------------------------------------------------===//
287
288char LiveDebugValues::ID = 0;
Eugene Zelenko5df3d892017-08-24 21:21:39 +0000289
Vikram TV859ad292015-12-16 11:09:48 +0000290char &llvm::LiveDebugValuesID = LiveDebugValues::ID;
Eugene Zelenko5df3d892017-08-24 21:21:39 +0000291
Matthias Braun1527baa2017-05-25 21:26:32 +0000292INITIALIZE_PASS(LiveDebugValues, DEBUG_TYPE, "Live DEBUG_VALUE analysis",
Vikram TV859ad292015-12-16 11:09:48 +0000293 false, false)
294
295/// Default construct and initialize the pass.
296LiveDebugValues::LiveDebugValues() : MachineFunctionPass(ID) {
297 initializeLiveDebugValuesPass(*PassRegistry::getPassRegistry());
298}
299
300/// Tell the pass manager which passes we depend on and what information we
301/// preserve.
302void LiveDebugValues::getAnalysisUsage(AnalysisUsage &AU) const {
Matt Arsenaultb1630a12016-06-08 05:18:01 +0000303 AU.setPreservesCFG();
Vikram TV859ad292015-12-16 11:09:48 +0000304 MachineFunctionPass::getAnalysisUsage(AU);
305}
306
Vikram TV859ad292015-12-16 11:09:48 +0000307//===----------------------------------------------------------------------===//
308// Debug Range Extension Implementation
309//===----------------------------------------------------------------------===//
310
Matthias Braun194ded52017-01-28 06:53:55 +0000311#ifndef NDEBUG
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000312void LiveDebugValues::printVarLocInMBB(const MachineFunction &MF,
313 const VarLocInMBB &V,
314 const VarLocMap &VarLocIDs,
315 const char *msg,
Vikram TV859ad292015-12-16 11:09:48 +0000316 raw_ostream &Out) const {
Keith Walkerf83a19f2016-09-20 16:04:31 +0000317 Out << '\n' << msg << '\n';
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000318 for (const MachineBasicBlock &BB : MF) {
319 const auto &L = V.lookup(&BB);
320 Out << "MBB: " << BB.getName() << ":\n";
321 for (unsigned VLL : L) {
322 const VarLoc &VL = VarLocIDs[VLL];
Adrian Prantl7509d542016-05-26 21:42:47 +0000323 Out << " Var: " << VL.Var.getVar()->getName();
Vikram TV859ad292015-12-16 11:09:48 +0000324 Out << " MI: ";
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000325 VL.dump();
Vikram TV859ad292015-12-16 11:09:48 +0000326 }
327 }
328 Out << "\n";
329}
Matthias Braun194ded52017-01-28 06:53:55 +0000330#endif
Vikram TV859ad292015-12-16 11:09:48 +0000331
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000332/// Given a spill instruction, extract the register and offset used to
333/// address the spill location in a target independent way.
334int LiveDebugValues::extractSpillBaseRegAndOffset(const MachineInstr &MI,
335 unsigned &Reg) {
336 assert(MI.hasOneMemOperand() &&
337 "Spill instruction does not have exactly one memory operand?");
338 auto MMOI = MI.memoperands_begin();
339 const PseudoSourceValue *PVal = (*MMOI)->getPseudoValue();
340 assert(PVal->kind() == PseudoSourceValue::FixedStack &&
341 "Inconsistent memory operand in spill instruction");
342 int FI = cast<FixedStackPseudoSourceValue>(PVal)->getFrameIndex();
343 const MachineBasicBlock *MBB = MI.getParent();
344 return TFI->getFrameIndexReference(*MBB->getParent(), FI, Reg);
345}
346
Vikram TV859ad292015-12-16 11:09:48 +0000347/// End all previous ranges related to @MI and start a new range from @MI
348/// if it is a DBG_VALUE instr.
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000349void LiveDebugValues::transferDebugValue(const MachineInstr &MI,
Adrian Prantl7509d542016-05-26 21:42:47 +0000350 OpenRangesSet &OpenRanges,
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000351 VarLocMap &VarLocIDs) {
Vikram TV859ad292015-12-16 11:09:48 +0000352 if (!MI.isDebugValue())
353 return;
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000354 const DILocalVariable *Var = MI.getDebugVariable();
355 const DILocation *DebugLoc = MI.getDebugLoc();
356 const DILocation *InlinedAt = DebugLoc->getInlinedAt();
357 assert(Var->isValidLocationForIntrinsic(DebugLoc) &&
Vikram TV859ad292015-12-16 11:09:48 +0000358 "Expected inlined-at fields to agree");
Vikram TV859ad292015-12-16 11:09:48 +0000359
360 // End all previous ranges of Var.
Adrian Prantl7509d542016-05-26 21:42:47 +0000361 DebugVariable V(Var, InlinedAt);
362 OpenRanges.erase(V);
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000363
364 // Add the VarLoc to OpenRanges from this DBG_VALUE.
365 // TODO: Currently handles DBG_VALUE which has only reg as location.
Adrian Prantl7509d542016-05-26 21:42:47 +0000366 if (isDbgValueDescribedByReg(MI)) {
Adrian Prantl7f5866c2016-09-28 17:51:14 +0000367 VarLoc VL(MI, LS);
Adrian Prantl7509d542016-05-26 21:42:47 +0000368 unsigned ID = VarLocIDs.insert(VL);
369 OpenRanges.insert(ID, VL.Var);
370 }
Vikram TV859ad292015-12-16 11:09:48 +0000371}
372
373/// A definition of a register may mark the end of a range.
374void LiveDebugValues::transferRegisterDef(MachineInstr &MI,
Adrian Prantl7509d542016-05-26 21:42:47 +0000375 OpenRangesSet &OpenRanges,
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000376 const VarLocMap &VarLocIDs) {
Justin Bognerfdf9bf42017-10-10 23:50:49 +0000377 MachineFunction *MF = MI.getMF();
Reid Klecknerf6f04f82016-03-25 17:54:46 +0000378 const TargetLowering *TLI = MF->getSubtarget().getTargetLowering();
379 unsigned SP = TLI->getStackPointerRegisterToSaveRestore();
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000380 SparseBitVector<> KillSet;
Vikram TV859ad292015-12-16 11:09:48 +0000381 for (const MachineOperand &MO : MI.operands()) {
Adrian Prantlea8880b2017-03-03 01:08:25 +0000382 // Determine whether the operand is a register def. Assume that call
383 // instructions never clobber SP, because some backends (e.g., AArch64)
384 // never list SP in the regmask.
Reid Klecknerf6f04f82016-03-25 17:54:46 +0000385 if (MO.isReg() && MO.isDef() && MO.getReg() &&
Adrian Prantlea8880b2017-03-03 01:08:25 +0000386 TRI->isPhysicalRegister(MO.getReg()) &&
387 !(MI.isCall() && MO.getReg() == SP)) {
Reid Klecknerf6f04f82016-03-25 17:54:46 +0000388 // Remove ranges of all aliased registers.
389 for (MCRegAliasIterator RAI(MO.getReg(), TRI, true); RAI.isValid(); ++RAI)
Adrian Prantl7509d542016-05-26 21:42:47 +0000390 for (unsigned ID : OpenRanges.getVarLocs())
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000391 if (VarLocIDs[ID].isDescribedByReg() == *RAI)
392 KillSet.set(ID);
Reid Klecknerf6f04f82016-03-25 17:54:46 +0000393 } else if (MO.isRegMask()) {
394 // Remove ranges of all clobbered registers. Register masks don't usually
395 // list SP as preserved. While the debug info may be off for an
396 // instruction or two around callee-cleanup calls, transferring the
397 // DEBUG_VALUE across the call is still a better user experience.
Adrian Prantl7509d542016-05-26 21:42:47 +0000398 for (unsigned ID : OpenRanges.getVarLocs()) {
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000399 unsigned Reg = VarLocIDs[ID].isDescribedByReg();
400 if (Reg && Reg != SP && MO.clobbersPhysReg(Reg))
401 KillSet.set(ID);
402 }
Reid Klecknerf6f04f82016-03-25 17:54:46 +0000403 }
Vikram TV859ad292015-12-16 11:09:48 +0000404 }
Adrian Prantl7509d542016-05-26 21:42:47 +0000405 OpenRanges.erase(KillSet, VarLocIDs);
Vikram TV859ad292015-12-16 11:09:48 +0000406}
407
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000408/// Decide if @MI is a spill instruction and return true if it is. We use 2
409/// criteria to make this decision:
410/// - Is this instruction a store to a spill slot?
411/// - Is there a register operand that is both used and killed?
412/// TODO: Store optimization can fold spills into other stores (including
413/// other spills). We do not handle this yet (more than one memory operand).
414bool LiveDebugValues::isSpillInstruction(const MachineInstr &MI,
415 MachineFunction *MF, unsigned &Reg) {
416 const MachineFrameInfo &FrameInfo = MF->getFrameInfo();
417 int FI;
418 const MachineMemOperand *MMO;
419
420 // TODO: Handle multiple stores folded into one.
421 if (!MI.hasOneMemOperand())
422 return false;
423
424 // To identify a spill instruction, use the same criteria as in AsmPrinter.
425 if (!((TII->isStoreToStackSlotPostFE(MI, FI) ||
426 TII->hasStoreToStackSlot(MI, MMO, FI)) &&
427 FrameInfo.isSpillSlotObjectIndex(FI)))
428 return false;
429
Petar Jovanovic0b464e42018-01-16 14:46:05 +0000430 auto isKilledReg = [&](const MachineOperand MO, unsigned &Reg) {
431 if (!MO.isReg() || !MO.isUse()) {
432 Reg = 0;
433 return false;
434 }
435 Reg = MO.getReg();
436 return MO.isKill();
437 };
438
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000439 for (const MachineOperand &MO : MI.operands()) {
Petar Jovanovic0b464e42018-01-16 14:46:05 +0000440 // In a spill instruction generated by the InlineSpiller the spilled
441 // register has its kill flag set.
442 if (isKilledReg(MO, Reg))
443 return true;
444 if (Reg != 0) {
445 // Check whether next instruction kills the spilled register.
446 // FIXME: Current solution does not cover search for killed register in
447 // bundles and instructions further down the chain.
448 auto NextI = std::next(MI.getIterator());
449 // Skip next instruction that points to basic block end iterator.
450 if (MI.getParent()->end() == NextI)
451 continue;
452 unsigned RegNext;
453 for (const MachineOperand &MONext : NextI->operands()) {
454 // Return true if we came across the register from the
455 // previous spill instruction that is killed in NextI.
456 if (isKilledReg(MONext, RegNext) && RegNext == Reg)
457 return true;
458 }
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000459 }
460 }
Petar Jovanovic0b464e42018-01-16 14:46:05 +0000461 // Return false if we didn't find spilled register.
462 return false;
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000463}
464
465/// A spilled register may indicate that we have to end the current range of
466/// a variable and create a new one for the spill location.
467/// We don't want to insert any instructions in transfer(), so we just create
468/// the DBG_VALUE witout inserting it and keep track of it in @Spills.
469/// It will be inserted into the BB when we're done iterating over the
470/// instructions.
471void LiveDebugValues::transferSpillInst(MachineInstr &MI,
472 OpenRangesSet &OpenRanges,
473 VarLocMap &VarLocIDs,
474 SpillMap &Spills) {
475 unsigned Reg;
Justin Bognerfdf9bf42017-10-10 23:50:49 +0000476 MachineFunction *MF = MI.getMF();
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000477 if (!isSpillInstruction(MI, MF, Reg))
478 return;
479
480 // Check if the register is the location of a debug value.
481 for (unsigned ID : OpenRanges.getVarLocs()) {
482 if (VarLocIDs[ID].isDescribedByReg() == Reg) {
Francis Visoiu Mistrih9d419d32017-11-28 12:42:37 +0000483 DEBUG(dbgs() << "Spilling Register " << printReg(Reg, TRI) << '('
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000484 << VarLocIDs[ID].Var.getVar()->getName() << ")\n");
485
486 // Create a DBG_VALUE instruction to describe the Var in its spilled
487 // location, but don't insert it yet to avoid invalidating the
488 // iterator in our caller.
489 unsigned SpillBase;
490 int SpillOffset = extractSpillBaseRegAndOffset(MI, SpillBase);
491 const MachineInstr *DMI = &VarLocIDs[ID].MI;
Adrian Prantl83ca4fc2017-08-02 00:16:56 +0000492 auto *SpillExpr = DIExpression::prepend(
493 DMI->getDebugExpression(), DIExpression::NoDeref, SpillOffset);
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000494 MachineInstr *SpDMI =
Adrian Prantl8b9bb532017-07-28 23:00:45 +0000495 BuildMI(*MF, DMI->getDebugLoc(), DMI->getDesc(), true, SpillBase,
Adrian Prantl83ca4fc2017-08-02 00:16:56 +0000496 DMI->getDebugVariable(), SpillExpr);
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000497 DEBUG(dbgs() << "Creating DBG_VALUE inst for spill: ";
498 SpDMI->print(dbgs(), false, TII));
499
500 // The newly created DBG_VALUE instruction SpDMI must be inserted after
501 // MI. Keep track of the pairing.
502 SpillDebugPair MIP = {&MI, SpDMI};
503 Spills.push_back(MIP);
504
505 // End all previous ranges of Var.
506 OpenRanges.erase(VarLocIDs[ID].Var);
507
508 // Add the VarLoc to OpenRanges.
509 VarLoc VL(*SpDMI, LS);
510 unsigned SpillLocID = VarLocIDs.insert(VL);
511 OpenRanges.insert(SpillLocID, VL.Var);
512 return;
513 }
514 }
515}
516
Vikram TV859ad292015-12-16 11:09:48 +0000517/// Terminate all open ranges at the end of the current basic block.
Daniel Berlinca4d93a2016-01-10 03:25:42 +0000518bool LiveDebugValues::transferTerminatorInst(MachineInstr &MI,
Adrian Prantl7509d542016-05-26 21:42:47 +0000519 OpenRangesSet &OpenRanges,
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000520 VarLocInMBB &OutLocs,
521 const VarLocMap &VarLocIDs) {
Daniel Berlinca4d93a2016-01-10 03:25:42 +0000522 bool Changed = false;
Vikram TV859ad292015-12-16 11:09:48 +0000523 const MachineBasicBlock *CurMBB = MI.getParent();
Petar Jovanovice9500ba2018-01-08 18:21:15 +0000524 if (!(MI.isTerminator() || (&MI == &CurMBB->back())))
Daniel Berlinca4d93a2016-01-10 03:25:42 +0000525 return false;
Vikram TV859ad292015-12-16 11:09:48 +0000526
527 if (OpenRanges.empty())
Daniel Berlinca4d93a2016-01-10 03:25:42 +0000528 return false;
Vikram TV859ad292015-12-16 11:09:48 +0000529
Adrian Prantl7509d542016-05-26 21:42:47 +0000530 DEBUG(for (unsigned ID : OpenRanges.getVarLocs()) {
531 // Copy OpenRanges to OutLocs, if not already present.
532 dbgs() << "Add to OutLocs: "; VarLocIDs[ID].dump();
533 });
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000534 VarLocSet &VLS = OutLocs[CurMBB];
Adrian Prantl7509d542016-05-26 21:42:47 +0000535 Changed = VLS |= OpenRanges.getVarLocs();
Vikram TV859ad292015-12-16 11:09:48 +0000536 OpenRanges.clear();
Daniel Berlinca4d93a2016-01-10 03:25:42 +0000537 return Changed;
Vikram TV859ad292015-12-16 11:09:48 +0000538}
539
540/// This routine creates OpenRanges and OutLocs.
Adrian Prantl7509d542016-05-26 21:42:47 +0000541bool LiveDebugValues::transfer(MachineInstr &MI, OpenRangesSet &OpenRanges,
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000542 VarLocInMBB &OutLocs, VarLocMap &VarLocIDs,
543 SpillMap &Spills, bool transferSpills) {
Daniel Berlinca4d93a2016-01-10 03:25:42 +0000544 bool Changed = false;
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000545 transferDebugValue(MI, OpenRanges, VarLocIDs);
546 transferRegisterDef(MI, OpenRanges, VarLocIDs);
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000547 if (transferSpills)
548 transferSpillInst(MI, OpenRanges, VarLocIDs, Spills);
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000549 Changed = transferTerminatorInst(MI, OpenRanges, OutLocs, VarLocIDs);
Daniel Berlinca4d93a2016-01-10 03:25:42 +0000550 return Changed;
Vikram TV859ad292015-12-16 11:09:48 +0000551}
552
553/// This routine joins the analysis results of all incoming edges in @MBB by
554/// inserting a new DBG_VALUE instruction at the start of the @MBB - if the same
555/// source variable in all the predecessors of @MBB reside in the same location.
Daniel Berlinca4d93a2016-01-10 03:25:42 +0000556bool LiveDebugValues::join(MachineBasicBlock &MBB, VarLocInMBB &OutLocs,
Keith Walker83ebef52016-09-27 16:46:07 +0000557 VarLocInMBB &InLocs, const VarLocMap &VarLocIDs,
558 SmallPtrSet<const MachineBasicBlock *, 16> &Visited) {
Vikram TV859ad292015-12-16 11:09:48 +0000559 DEBUG(dbgs() << "join MBB: " << MBB.getName() << "\n");
Daniel Berlinca4d93a2016-01-10 03:25:42 +0000560 bool Changed = false;
Vikram TV859ad292015-12-16 11:09:48 +0000561
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000562 VarLocSet InLocsT; // Temporary incoming locations.
Vikram TV859ad292015-12-16 11:09:48 +0000563
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000564 // For all predecessors of this MBB, find the set of VarLocs that
565 // can be joined.
Keith Walker83ebef52016-09-27 16:46:07 +0000566 int NumVisited = 0;
Vikram TV859ad292015-12-16 11:09:48 +0000567 for (auto p : MBB.predecessors()) {
Keith Walker83ebef52016-09-27 16:46:07 +0000568 // Ignore unvisited predecessor blocks. As we are processing
569 // the blocks in reverse post-order any unvisited block can
570 // be considered to not remove any incoming values.
571 if (!Visited.count(p))
572 continue;
Vikram TV859ad292015-12-16 11:09:48 +0000573 auto OL = OutLocs.find(p);
574 // Join is null in case of empty OutLocs from any of the pred.
575 if (OL == OutLocs.end())
Daniel Berlinca4d93a2016-01-10 03:25:42 +0000576 return false;
Vikram TV859ad292015-12-16 11:09:48 +0000577
Keith Walker83ebef52016-09-27 16:46:07 +0000578 // Just copy over the Out locs to incoming locs for the first visited
579 // predecessor, and for all other predecessors join the Out locs.
580 if (!NumVisited)
Vikram TV859ad292015-12-16 11:09:48 +0000581 InLocsT = OL->second;
Keith Walker83ebef52016-09-27 16:46:07 +0000582 else
583 InLocsT &= OL->second;
584 NumVisited++;
Vikram TV859ad292015-12-16 11:09:48 +0000585 }
586
Adrian Prantl7f5866c2016-09-28 17:51:14 +0000587 // Filter out DBG_VALUES that are out of scope.
588 VarLocSet KillSet;
589 for (auto ID : InLocsT)
590 if (!VarLocIDs[ID].dominates(MBB))
591 KillSet.set(ID);
592 InLocsT.intersectWithComplement(KillSet);
593
Keith Walker83ebef52016-09-27 16:46:07 +0000594 // As we are processing blocks in reverse post-order we
595 // should have processed at least one predecessor, unless it
596 // is the entry block which has no predecessor.
597 assert((NumVisited || MBB.pred_empty()) &&
598 "Should have processed at least one predecessor");
Vikram TV859ad292015-12-16 11:09:48 +0000599 if (InLocsT.empty())
Daniel Berlinca4d93a2016-01-10 03:25:42 +0000600 return false;
Vikram TV859ad292015-12-16 11:09:48 +0000601
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000602 VarLocSet &ILS = InLocs[&MBB];
Vikram TV859ad292015-12-16 11:09:48 +0000603
604 // Insert DBG_VALUE instructions, if not already inserted.
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000605 VarLocSet Diff = InLocsT;
606 Diff.intersectWithComplement(ILS);
607 for (auto ID : Diff) {
608 // This VarLoc is not found in InLocs i.e. it is not yet inserted. So, a
609 // new range is started for the var from the mbb's beginning by inserting
610 // a new DBG_VALUE. transfer() will end this range however appropriate.
611 const VarLoc &DiffIt = VarLocIDs[ID];
612 const MachineInstr *DMI = &DiffIt.MI;
613 MachineInstr *MI =
614 BuildMI(MBB, MBB.instr_begin(), DMI->getDebugLoc(), DMI->getDesc(),
Adrian Prantl8b9bb532017-07-28 23:00:45 +0000615 DMI->isIndirectDebugValue(), DMI->getOperand(0).getReg(),
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000616 DMI->getDebugVariable(), DMI->getDebugExpression());
617 if (DMI->isIndirectDebugValue())
618 MI->getOperand(1).setImm(DMI->getOperand(1).getImm());
619 DEBUG(dbgs() << "Inserted: "; MI->dump(););
620 ILS.set(ID);
621 ++NumInserted;
622 Changed = true;
Vikram TV859ad292015-12-16 11:09:48 +0000623 }
Daniel Berlinca4d93a2016-01-10 03:25:42 +0000624 return Changed;
Vikram TV859ad292015-12-16 11:09:48 +0000625}
626
627/// Calculate the liveness information for the given machine function and
628/// extend ranges across basic blocks.
629bool LiveDebugValues::ExtendRanges(MachineFunction &MF) {
Vikram TV859ad292015-12-16 11:09:48 +0000630 DEBUG(dbgs() << "\nDebug Range Extension\n");
631
632 bool Changed = false;
Daniel Berlinca4d93a2016-01-10 03:25:42 +0000633 bool OLChanged = false;
634 bool MBBJoined = false;
Vikram TV859ad292015-12-16 11:09:48 +0000635
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000636 VarLocMap VarLocIDs; // Map VarLoc<>unique ID for use in bitvectors.
Adrian Prantl7509d542016-05-26 21:42:47 +0000637 OpenRangesSet OpenRanges; // Ranges that are open until end of bb.
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000638 VarLocInMBB OutLocs; // Ranges that exist beyond bb.
639 VarLocInMBB InLocs; // Ranges that are incoming after joining.
640 SpillMap Spills; // DBG_VALUEs associated with spills.
Vikram TV859ad292015-12-16 11:09:48 +0000641
Daniel Berlin72560592016-01-10 18:08:32 +0000642 DenseMap<unsigned int, MachineBasicBlock *> OrderToBB;
643 DenseMap<MachineBasicBlock *, unsigned int> BBToOrder;
644 std::priority_queue<unsigned int, std::vector<unsigned int>,
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000645 std::greater<unsigned int>>
646 Worklist;
Daniel Berlin72560592016-01-10 18:08:32 +0000647 std::priority_queue<unsigned int, std::vector<unsigned int>,
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000648 std::greater<unsigned int>>
649 Pending;
650
Vikram TV859ad292015-12-16 11:09:48 +0000651 // Initialize every mbb with OutLocs.
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000652 // We are not looking at any spill instructions during the initial pass
653 // over the BBs. The LiveDebugVariables pass has already created DBG_VALUE
654 // instructions for spills of registers that are known to be user variables
655 // within the BB in which the spill occurs.
Vikram TV859ad292015-12-16 11:09:48 +0000656 for (auto &MBB : MF)
657 for (auto &MI : MBB)
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000658 transfer(MI, OpenRanges, OutLocs, VarLocIDs, Spills,
659 /*transferSpills=*/false);
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000660
661 DEBUG(printVarLocInMBB(MF, OutLocs, VarLocIDs, "OutLocs after initialization",
662 dbgs()));
Vikram TV859ad292015-12-16 11:09:48 +0000663
Daniel Berlin72560592016-01-10 18:08:32 +0000664 ReversePostOrderTraversal<MachineFunction *> RPOT(&MF);
665 unsigned int RPONumber = 0;
666 for (auto RI = RPOT.begin(), RE = RPOT.end(); RI != RE; ++RI) {
667 OrderToBB[RPONumber] = *RI;
668 BBToOrder[*RI] = RPONumber;
669 Worklist.push(RPONumber);
670 ++RPONumber;
671 }
Daniel Berlin72560592016-01-10 18:08:32 +0000672 // This is a standard "union of predecessor outs" dataflow problem.
673 // To solve it, we perform join() and transfer() using the two worklist method
674 // until the ranges converge.
675 // Ranges have converged when both worklists are empty.
Keith Walker83ebef52016-09-27 16:46:07 +0000676 SmallPtrSet<const MachineBasicBlock *, 16> Visited;
Daniel Berlin72560592016-01-10 18:08:32 +0000677 while (!Worklist.empty() || !Pending.empty()) {
678 // We track what is on the pending worklist to avoid inserting the same
679 // thing twice. We could avoid this with a custom priority queue, but this
680 // is probably not worth it.
681 SmallPtrSet<MachineBasicBlock *, 16> OnPending;
Keith Walkerf83a19f2016-09-20 16:04:31 +0000682 DEBUG(dbgs() << "Processing Worklist\n");
Daniel Berlin72560592016-01-10 18:08:32 +0000683 while (!Worklist.empty()) {
684 MachineBasicBlock *MBB = OrderToBB[Worklist.top()];
685 Worklist.pop();
Keith Walker83ebef52016-09-27 16:46:07 +0000686 MBBJoined = join(*MBB, OutLocs, InLocs, VarLocIDs, Visited);
687 Visited.insert(MBB);
Daniel Berlin72560592016-01-10 18:08:32 +0000688 if (MBBJoined) {
689 MBBJoined = false;
690 Changed = true;
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000691 // Now that we have started to extend ranges across BBs we need to
692 // examine spill instructions to see whether they spill registers that
693 // correspond to user variables.
Daniel Berlin72560592016-01-10 18:08:32 +0000694 for (auto &MI : *MBB)
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000695 OLChanged |= transfer(MI, OpenRanges, OutLocs, VarLocIDs, Spills,
696 /*transferSpills=*/true);
697
698 // Add any DBG_VALUE instructions necessitated by spills.
699 for (auto &SP : Spills)
700 MBB->insertAfter(MachineBasicBlock::iterator(*SP.SpillInst),
701 SP.DebugInst);
702 Spills.clear();
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000703
704 DEBUG(printVarLocInMBB(MF, OutLocs, VarLocIDs,
705 "OutLocs after propagating", dbgs()));
706 DEBUG(printVarLocInMBB(MF, InLocs, VarLocIDs,
707 "InLocs after propagating", dbgs()));
Vikram TV859ad292015-12-16 11:09:48 +0000708
Daniel Berlin72560592016-01-10 18:08:32 +0000709 if (OLChanged) {
710 OLChanged = false;
711 for (auto s : MBB->successors())
Benjamin Kramer4dea8f52016-06-17 18:59:41 +0000712 if (OnPending.insert(s).second) {
Daniel Berlin72560592016-01-10 18:08:32 +0000713 Pending.push(BBToOrder[s]);
714 }
715 }
Vikram TV859ad292015-12-16 11:09:48 +0000716 }
717 }
Daniel Berlin72560592016-01-10 18:08:32 +0000718 Worklist.swap(Pending);
719 // At this point, pending must be empty, since it was just the empty
720 // worklist
721 assert(Pending.empty() && "Pending should be empty");
Vikram TV859ad292015-12-16 11:09:48 +0000722 }
Daniel Berlin72560592016-01-10 18:08:32 +0000723
Adrian Prantl6ee02c72016-05-25 22:21:12 +0000724 DEBUG(printVarLocInMBB(MF, OutLocs, VarLocIDs, "Final OutLocs", dbgs()));
725 DEBUG(printVarLocInMBB(MF, InLocs, VarLocIDs, "Final InLocs", dbgs()));
Vikram TV859ad292015-12-16 11:09:48 +0000726 return Changed;
727}
728
729bool LiveDebugValues::runOnMachineFunction(MachineFunction &MF) {
Matthias Braunf1caa282017-12-15 22:22:58 +0000730 if (!MF.getFunction().getSubprogram())
Adrian Prantl7f5866c2016-09-28 17:51:14 +0000731 // LiveDebugValues will already have removed all DBG_VALUEs.
732 return false;
733
Wolfgang Piebe018bbd2017-07-19 19:36:40 +0000734 // Skip functions from NoDebug compilation units.
Matthias Braunf1caa282017-12-15 22:22:58 +0000735 if (MF.getFunction().getSubprogram()->getUnit()->getEmissionKind() ==
Wolfgang Piebe018bbd2017-07-19 19:36:40 +0000736 DICompileUnit::NoDebug)
737 return false;
738
Vikram TV859ad292015-12-16 11:09:48 +0000739 TRI = MF.getSubtarget().getRegisterInfo();
740 TII = MF.getSubtarget().getInstrInfo();
Wolfgang Pieb399dcfa2017-02-14 19:08:45 +0000741 TFI = MF.getSubtarget().getFrameLowering();
Adrian Prantl7f5866c2016-09-28 17:51:14 +0000742 LS.initialize(MF);
Vikram TV859ad292015-12-16 11:09:48 +0000743
Adrian Prantl7f5866c2016-09-28 17:51:14 +0000744 bool Changed = ExtendRanges(MF);
Vikram TV859ad292015-12-16 11:09:48 +0000745 return Changed;
746}