blob: 9ed7450d5cb633a3356b4681cf2faeab63899349 [file] [log] [blame]
Eugene Zelenko4f81cdd2017-09-29 21:55:49 +00001//===- AggressiveAntiDepBreaker.cpp - Anti-dep breaker --------------------===//
David Goodwinde11f362009-10-26 19:32:42 +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 file implements the AggressiveAntiDepBreaker class, which
11// implements register anti-dependence breaking during post-RA
12// scheduling. It attempts to break all anti-dependencies within a
13// block.
14//
15//===----------------------------------------------------------------------===//
16
David Goodwinde11f362009-10-26 19:32:42 +000017#include "AggressiveAntiDepBreaker.h"
Eugene Zelenko4f81cdd2017-09-29 21:55:49 +000018#include "llvm/ADT/ArrayRef.h"
19#include "llvm/ADT/BitVector.h"
20#include "llvm/ADT/SmallSet.h"
21#include "llvm/ADT/iterator_range.h"
David Goodwinde11f362009-10-26 19:32:42 +000022#include "llvm/CodeGen/MachineBasicBlock.h"
23#include "llvm/CodeGen/MachineFrameInfo.h"
Eugene Zelenko4f81cdd2017-09-29 21:55:49 +000024#include "llvm/CodeGen/MachineFunction.h"
David Goodwinde11f362009-10-26 19:32:42 +000025#include "llvm/CodeGen/MachineInstr.h"
Eugene Zelenko4f81cdd2017-09-29 21:55:49 +000026#include "llvm/CodeGen/MachineOperand.h"
27#include "llvm/CodeGen/MachineRegisterInfo.h"
28#include "llvm/CodeGen/MachineValueType.h"
Andrew Trick05ff4662012-06-06 20:29:31 +000029#include "llvm/CodeGen/RegisterClassInfo.h"
Eugene Zelenko4f81cdd2017-09-29 21:55:49 +000030#include "llvm/CodeGen/ScheduleDAG.h"
David Blaikie3f833ed2017-11-08 01:01:31 +000031#include "llvm/CodeGen/TargetInstrInfo.h"
David Blaikieb3bde2e2017-11-17 01:07:10 +000032#include "llvm/CodeGen/TargetRegisterInfo.h"
33#include "llvm/CodeGen/TargetSubtargetInfo.h"
Eugene Zelenko4f81cdd2017-09-29 21:55:49 +000034#include "llvm/MC/MCInstrDesc.h"
35#include "llvm/MC/MCRegisterInfo.h"
David Goodwine056d102009-10-26 22:31:16 +000036#include "llvm/Support/CommandLine.h"
David Goodwinde11f362009-10-26 19:32:42 +000037#include "llvm/Support/Debug.h"
David Goodwinde11f362009-10-26 19:32:42 +000038#include "llvm/Support/raw_ostream.h"
Eugene Zelenko4f81cdd2017-09-29 21:55:49 +000039#include <cassert>
40#include <map>
41#include <set>
42#include <utility>
43#include <vector>
44
David Goodwinde11f362009-10-26 19:32:42 +000045using namespace llvm;
46
Chandler Carruth1b9dde02014-04-22 02:02:50 +000047#define DEBUG_TYPE "post-RA-sched"
48
David Goodwindd1c6192009-11-19 23:12:37 +000049// If DebugDiv > 0 then only break antidep with (ID % DebugDiv) == DebugMod
50static cl::opt<int>
51DebugDiv("agg-antidep-debugdiv",
Bob Wilson67dd3a42010-04-09 21:38:26 +000052 cl::desc("Debug control for aggressive anti-dep breaker"),
53 cl::init(0), cl::Hidden);
Eugene Zelenko4f81cdd2017-09-29 21:55:49 +000054
David Goodwindd1c6192009-11-19 23:12:37 +000055static cl::opt<int>
56DebugMod("agg-antidep-debugmod",
Bob Wilson67dd3a42010-04-09 21:38:26 +000057 cl::desc("Debug control for aggressive anti-dep breaker"),
58 cl::init(0), cl::Hidden);
David Goodwindd1c6192009-11-19 23:12:37 +000059
David Goodwina45fe672009-12-09 17:18:22 +000060AggressiveAntiDepState::AggressiveAntiDepState(const unsigned TargetRegs,
Eugene Zelenko4f81cdd2017-09-29 21:55:49 +000061 MachineBasicBlock *BB)
62 : NumTargetRegs(TargetRegs), GroupNodes(TargetRegs, 0),
63 GroupNodeIndices(TargetRegs, 0), KillIndices(TargetRegs, 0),
64 DefIndices(TargetRegs, 0) {
David Goodwina45fe672009-12-09 17:18:22 +000065 const unsigned BBSize = BB->size();
66 for (unsigned i = 0; i < NumTargetRegs; ++i) {
67 // Initialize all registers to be in their own group. Initially we
68 // assign the register to the same-indexed GroupNode.
69 GroupNodeIndices[i] = i;
70 // Initialize the indices to indicate that no registers are live.
71 KillIndices[i] = ~0u;
72 DefIndices[i] = BBSize;
73 }
David Goodwinde11f362009-10-26 19:32:42 +000074}
75
Bill Wendling5a8d15c2010-07-15 19:41:20 +000076unsigned AggressiveAntiDepState::GetGroup(unsigned Reg) {
David Goodwinde11f362009-10-26 19:32:42 +000077 unsigned Node = GroupNodeIndices[Reg];
78 while (GroupNodes[Node] != Node)
79 Node = GroupNodes[Node];
80
81 return Node;
82}
83
David Goodwinb9fe5d52009-11-13 19:52:48 +000084void AggressiveAntiDepState::GetGroupRegs(
85 unsigned Group,
86 std::vector<unsigned> &Regs,
87 std::multimap<unsigned, AggressiveAntiDepState::RegisterReference> *RegRefs)
David Goodwinde11f362009-10-26 19:32:42 +000088{
David Goodwina45fe672009-12-09 17:18:22 +000089 for (unsigned Reg = 0; Reg != NumTargetRegs; ++Reg) {
David Goodwinb9fe5d52009-11-13 19:52:48 +000090 if ((GetGroup(Reg) == Group) && (RegRefs->count(Reg) > 0))
David Goodwinde11f362009-10-26 19:32:42 +000091 Regs.push_back(Reg);
92 }
93}
94
Eugene Zelenko4f81cdd2017-09-29 21:55:49 +000095unsigned AggressiveAntiDepState::UnionGroups(unsigned Reg1, unsigned Reg2) {
David Goodwinde11f362009-10-26 19:32:42 +000096 assert(GroupNodes[0] == 0 && "GroupNode 0 not parent!");
97 assert(GroupNodeIndices[0] == 0 && "Reg 0 not in Group 0!");
Jim Grosbacheb431da2010-01-06 16:48:02 +000098
David Goodwinde11f362009-10-26 19:32:42 +000099 // find group for each register
100 unsigned Group1 = GetGroup(Reg1);
101 unsigned Group2 = GetGroup(Reg2);
Jim Grosbacheb431da2010-01-06 16:48:02 +0000102
David Goodwinde11f362009-10-26 19:32:42 +0000103 // if either group is 0, then that must become the parent
104 unsigned Parent = (Group1 == 0) ? Group1 : Group2;
105 unsigned Other = (Parent == Group1) ? Group2 : Group1;
106 GroupNodes.at(Other) = Parent;
107 return Parent;
108}
Jim Grosbacheb431da2010-01-06 16:48:02 +0000109
Eugene Zelenko4f81cdd2017-09-29 21:55:49 +0000110unsigned AggressiveAntiDepState::LeaveGroup(unsigned Reg) {
David Goodwinde11f362009-10-26 19:32:42 +0000111 // Create a new GroupNode for Reg. Reg's existing GroupNode must
112 // stay as is because there could be other GroupNodes referring to
113 // it.
114 unsigned idx = GroupNodes.size();
115 GroupNodes.push_back(idx);
116 GroupNodeIndices[Reg] = idx;
117 return idx;
118}
119
Eugene Zelenko4f81cdd2017-09-29 21:55:49 +0000120bool AggressiveAntiDepState::IsLive(unsigned Reg) {
David Goodwinde11f362009-10-26 19:32:42 +0000121 // KillIndex must be defined and DefIndex not defined for a register
122 // to be live.
123 return((KillIndices[Reg] != ~0u) && (DefIndices[Reg] == ~0u));
124}
125
Eric Christopherd9134482014-08-04 21:25:23 +0000126AggressiveAntiDepBreaker::AggressiveAntiDepBreaker(
127 MachineFunction &MFi, const RegisterClassInfo &RCI,
128 TargetSubtargetInfo::RegClassVector &CriticalPathRCs)
129 : AntiDepBreaker(), MF(MFi), MRI(MF.getRegInfo()),
Eric Christopherfc6de422014-08-05 02:39:49 +0000130 TII(MF.getSubtarget().getInstrInfo()),
Eugene Zelenko4f81cdd2017-09-29 21:55:49 +0000131 TRI(MF.getSubtarget().getRegisterInfo()), RegClassInfo(RCI) {
David Goodwinb9fe5d52009-11-13 19:52:48 +0000132 /* Collect a bitset of all registers that are only broken if they
133 are on the critical path. */
134 for (unsigned i = 0, e = CriticalPathRCs.size(); i < e; ++i) {
135 BitVector CPSet = TRI->getAllocatableSet(MF, CriticalPathRCs[i]);
136 if (CriticalPathSet.none())
137 CriticalPathSet = CPSet;
138 else
139 CriticalPathSet |= CPSet;
140 }
Jim Grosbacheb431da2010-01-06 16:48:02 +0000141
David Greene75a2efb2009-12-24 00:14:25 +0000142 DEBUG(dbgs() << "AntiDep Critical-Path Registers:");
Francis Visoiu Mistrihb52e0362017-05-17 01:07:53 +0000143 DEBUG(for (unsigned r : CriticalPathSet.set_bits())
Francis Visoiu Mistrihc71cced2017-11-30 16:12:24 +0000144 dbgs() << " " << printReg(r, TRI));
David Greene75a2efb2009-12-24 00:14:25 +0000145 DEBUG(dbgs() << '\n');
David Goodwine056d102009-10-26 22:31:16 +0000146}
147
148AggressiveAntiDepBreaker::~AggressiveAntiDepBreaker() {
149 delete State;
David Goodwine056d102009-10-26 22:31:16 +0000150}
151
152void AggressiveAntiDepBreaker::StartBlock(MachineBasicBlock *BB) {
Craig Topperc0196b12014-04-14 00:51:57 +0000153 assert(!State);
David Goodwina45fe672009-12-09 17:18:22 +0000154 State = new AggressiveAntiDepState(TRI->getNumRegs(), BB);
David Goodwine056d102009-10-26 22:31:16 +0000155
Matthias Braunc2d4bef2015-09-25 21:25:19 +0000156 bool IsReturnBlock = BB->isReturnBlock();
Bill Wendling030b0282010-07-15 18:43:09 +0000157 std::vector<unsigned> &KillIndices = State->GetKillIndices();
158 std::vector<unsigned> &DefIndices = State->GetDefIndices();
David Goodwine056d102009-10-26 22:31:16 +0000159
Jakob Stoklund Olesenc3386792013-02-05 18:21:52 +0000160 // Examine the live-in regs of all successors.
Evan Chengf128bdc2010-06-16 07:35:02 +0000161 for (MachineBasicBlock::succ_iterator SI = BB->succ_begin(),
162 SE = BB->succ_end(); SI != SE; ++SI)
Matthias Braund9da1622015-09-09 18:08:03 +0000163 for (const auto &LI : (*SI)->liveins()) {
164 for (MCRegAliasIterator AI(LI.PhysReg, TRI, true); AI.isValid(); ++AI) {
Jakob Stoklund Olesen54038d72012-06-01 23:28:30 +0000165 unsigned Reg = *AI;
Jakob Stoklund Olesenbe1c8d32010-12-14 23:23:15 +0000166 State->UnionGroups(Reg, 0);
167 KillIndices[Reg] = BB->size();
168 DefIndices[Reg] = ~0u;
Evan Chengf128bdc2010-06-16 07:35:02 +0000169 }
170 }
171
David Goodwine056d102009-10-26 22:31:16 +0000172 // Mark live-out callee-saved registers. In a return block this is
173 // all callee-saved registers. In non-return this is any
174 // callee-saved register that is not saved in the prolog.
Matthias Braun941a7052016-07-28 18:40:00 +0000175 const MachineFrameInfo &MFI = MF.getFrameInfo();
176 BitVector Pristine = MFI.getPristineRegs(MF);
Oren Ben Simhonfe34c5e2017-03-14 09:09:26 +0000177 for (const MCPhysReg *I = MF.getRegInfo().getCalleeSavedRegs(); *I;
178 ++I) {
David Goodwine056d102009-10-26 22:31:16 +0000179 unsigned Reg = *I;
Tim Shen0bd0aa82017-05-30 22:26:52 +0000180 if (!IsReturnBlock && !Pristine.test(Reg))
Eric Christopherb9c56d12017-03-30 22:34:20 +0000181 continue;
Jakob Stoklund Olesen54038d72012-06-01 23:28:30 +0000182 for (MCRegAliasIterator AI(Reg, TRI, true); AI.isValid(); ++AI) {
183 unsigned AliasReg = *AI;
David Goodwine056d102009-10-26 22:31:16 +0000184 State->UnionGroups(AliasReg, 0);
185 KillIndices[AliasReg] = BB->size();
186 DefIndices[AliasReg] = ~0u;
187 }
188 }
189}
190
191void AggressiveAntiDepBreaker::FinishBlock() {
192 delete State;
Craig Topperc0196b12014-04-14 00:51:57 +0000193 State = nullptr;
David Goodwine056d102009-10-26 22:31:16 +0000194}
195
Duncan P. N. Exon Smith5e6e8c72016-02-27 19:33:37 +0000196void AggressiveAntiDepBreaker::Observe(MachineInstr &MI, unsigned Count,
Bob Wilson67dd3a42010-04-09 21:38:26 +0000197 unsigned InsertPosIndex) {
David Goodwine056d102009-10-26 22:31:16 +0000198 assert(Count < InsertPosIndex && "Instruction index out of expected range!");
199
David Goodwinfaa76602009-10-29 23:30:59 +0000200 std::set<unsigned> PassthruRegs;
201 GetPassthruRegs(MI, PassthruRegs);
202 PrescanInstruction(MI, Count, PassthruRegs);
203 ScanInstruction(MI, Count);
204
David Greene75a2efb2009-12-24 00:14:25 +0000205 DEBUG(dbgs() << "Observe: ");
Duncan P. N. Exon Smith5e6e8c72016-02-27 19:33:37 +0000206 DEBUG(MI.dump());
David Greene75a2efb2009-12-24 00:14:25 +0000207 DEBUG(dbgs() << "\tRegs:");
David Goodwine056d102009-10-26 22:31:16 +0000208
Bill Wendling030b0282010-07-15 18:43:09 +0000209 std::vector<unsigned> &DefIndices = State->GetDefIndices();
David Goodwina45fe672009-12-09 17:18:22 +0000210 for (unsigned Reg = 0; Reg != TRI->getNumRegs(); ++Reg) {
David Goodwine056d102009-10-26 22:31:16 +0000211 // If Reg is current live, then mark that it can't be renamed as
212 // we don't know the extent of its live-range anymore (now that it
213 // has been scheduled). If it is not live but was defined in the
214 // previous schedule region, then set its def index to the most
215 // conservative location (i.e. the beginning of the previous
216 // schedule region).
217 if (State->IsLive(Reg)) {
218 DEBUG(if (State->GetGroup(Reg) != 0)
Francis Visoiu Mistrihc71cced2017-11-30 16:12:24 +0000219 dbgs() << " " << printReg(Reg, TRI) << "=g" <<
David Goodwine056d102009-10-26 22:31:16 +0000220 State->GetGroup(Reg) << "->g0(region live-out)");
221 State->UnionGroups(Reg, 0);
Jim Grosbacheb431da2010-01-06 16:48:02 +0000222 } else if ((DefIndices[Reg] < InsertPosIndex)
223 && (DefIndices[Reg] >= Count)) {
David Goodwine056d102009-10-26 22:31:16 +0000224 DefIndices[Reg] = Count;
225 }
226 }
David Greene75a2efb2009-12-24 00:14:25 +0000227 DEBUG(dbgs() << '\n');
David Goodwine056d102009-10-26 22:31:16 +0000228}
229
Duncan P. N. Exon Smith5e6e8c72016-02-27 19:33:37 +0000230bool AggressiveAntiDepBreaker::IsImplicitDefUse(MachineInstr &MI,
231 MachineOperand &MO) {
David Goodwinde11f362009-10-26 19:32:42 +0000232 if (!MO.isReg() || !MO.isImplicit())
233 return false;
234
235 unsigned Reg = MO.getReg();
236 if (Reg == 0)
237 return false;
238
Chad Rosier47eba052015-10-09 19:48:48 +0000239 MachineOperand *Op = nullptr;
240 if (MO.isDef())
Duncan P. N. Exon Smith5e6e8c72016-02-27 19:33:37 +0000241 Op = MI.findRegisterUseOperand(Reg, true);
Chad Rosier47eba052015-10-09 19:48:48 +0000242 else
Duncan P. N. Exon Smith5e6e8c72016-02-27 19:33:37 +0000243 Op = MI.findRegisterDefOperand(Reg);
Chad Rosier47eba052015-10-09 19:48:48 +0000244
Craig Topperc0196b12014-04-14 00:51:57 +0000245 return(Op && Op->isImplicit());
David Goodwinde11f362009-10-26 19:32:42 +0000246}
247
Duncan P. N. Exon Smith5e6e8c72016-02-27 19:33:37 +0000248void AggressiveAntiDepBreaker::GetPassthruRegs(
249 MachineInstr &MI, std::set<unsigned> &PassthruRegs) {
250 for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) {
251 MachineOperand &MO = MI.getOperand(i);
David Goodwinde11f362009-10-26 19:32:42 +0000252 if (!MO.isReg()) continue;
Duncan P. N. Exon Smith5e6e8c72016-02-27 19:33:37 +0000253 if ((MO.isDef() && MI.isRegTiedToUseOperand(i)) ||
David Goodwinde11f362009-10-26 19:32:42 +0000254 IsImplicitDefUse(MI, MO)) {
255 const unsigned Reg = MO.getReg();
Chad Rosierabdb1d62013-05-22 23:17:36 +0000256 for (MCSubRegIterator SubRegs(Reg, TRI, /*IncludeSelf=*/true);
257 SubRegs.isValid(); ++SubRegs)
Jakob Stoklund Olesen54038d72012-06-01 23:28:30 +0000258 PassthruRegs.insert(*SubRegs);
David Goodwinde11f362009-10-26 19:32:42 +0000259 }
260 }
261}
262
David Goodwin80a03cc2009-11-20 19:32:48 +0000263/// AntiDepEdges - Return in Edges the anti- and output- dependencies
264/// in SU that we want to consider for breaking.
Eugene Zelenko4f81cdd2017-09-29 21:55:49 +0000265static void AntiDepEdges(const SUnit *SU, std::vector<const SDep *> &Edges) {
David Goodwin80a03cc2009-11-20 19:32:48 +0000266 SmallSet<unsigned, 4> RegSet;
Dan Gohman35bc4d42010-04-19 23:11:58 +0000267 for (SUnit::const_pred_iterator P = SU->Preds.begin(), PE = SU->Preds.end();
David Goodwinde11f362009-10-26 19:32:42 +0000268 P != PE; ++P) {
David Goodwinda83f7d2009-11-12 19:08:21 +0000269 if ((P->getKind() == SDep::Anti) || (P->getKind() == SDep::Output)) {
David Blaikie70573dc2014-11-19 07:49:26 +0000270 if (RegSet.insert(P->getReg()).second)
David Goodwinde11f362009-10-26 19:32:42 +0000271 Edges.push_back(&*P);
David Goodwinde11f362009-10-26 19:32:42 +0000272 }
273 }
274}
275
David Goodwinb9fe5d52009-11-13 19:52:48 +0000276/// CriticalPathStep - Return the next SUnit after SU on the bottom-up
277/// critical path.
Dan Gohman35bc4d42010-04-19 23:11:58 +0000278static const SUnit *CriticalPathStep(const SUnit *SU) {
Craig Topperc0196b12014-04-14 00:51:57 +0000279 const SDep *Next = nullptr;
David Goodwinb9fe5d52009-11-13 19:52:48 +0000280 unsigned NextDepth = 0;
281 // Find the predecessor edge with the greatest depth.
Craig Topperc0196b12014-04-14 00:51:57 +0000282 if (SU) {
Dan Gohman35bc4d42010-04-19 23:11:58 +0000283 for (SUnit::const_pred_iterator P = SU->Preds.begin(), PE = SU->Preds.end();
David Goodwinb9fe5d52009-11-13 19:52:48 +0000284 P != PE; ++P) {
Dan Gohman35bc4d42010-04-19 23:11:58 +0000285 const SUnit *PredSU = P->getSUnit();
David Goodwinb9fe5d52009-11-13 19:52:48 +0000286 unsigned PredLatency = P->getLatency();
287 unsigned PredTotalLatency = PredSU->getDepth() + PredLatency;
288 // In the case of a latency tie, prefer an anti-dependency edge over
289 // other types of edges.
290 if (NextDepth < PredTotalLatency ||
291 (NextDepth == PredTotalLatency && P->getKind() == SDep::Anti)) {
292 NextDepth = PredTotalLatency;
293 Next = &*P;
294 }
295 }
296 }
297
Craig Topperc0196b12014-04-14 00:51:57 +0000298 return (Next) ? Next->getSUnit() : nullptr;
David Goodwinb9fe5d52009-11-13 19:52:48 +0000299}
300
David Goodwin9f1b2d42009-10-29 19:17:04 +0000301void AggressiveAntiDepBreaker::HandleLastUse(unsigned Reg, unsigned KillIdx,
Jim Grosbacheb431da2010-01-06 16:48:02 +0000302 const char *tag,
303 const char *header,
David Goodwindd1c6192009-11-19 23:12:37 +0000304 const char *footer) {
Bill Wendling030b0282010-07-15 18:43:09 +0000305 std::vector<unsigned> &KillIndices = State->GetKillIndices();
306 std::vector<unsigned> &DefIndices = State->GetDefIndices();
Jim Grosbacheb431da2010-01-06 16:48:02 +0000307 std::multimap<unsigned, AggressiveAntiDepState::RegisterReference>&
David Goodwin9f1b2d42009-10-29 19:17:04 +0000308 RegRefs = State->GetRegRefs();
309
Hal Finkel34c94d52015-01-28 14:44:14 +0000310 // FIXME: We must leave subregisters of live super registers as live, so that
311 // we don't clear out the register tracking information for subregisters of
312 // super registers we're still tracking (and with which we're unioning
313 // subregister definitions).
314 for (MCRegAliasIterator AI(Reg, TRI, true); AI.isValid(); ++AI)
315 if (TRI->isSuperRegister(Reg, *AI) && State->IsLive(*AI)) {
316 DEBUG(if (!header && footer) dbgs() << footer);
317 return;
318 }
319
David Goodwin9f1b2d42009-10-29 19:17:04 +0000320 if (!State->IsLive(Reg)) {
321 KillIndices[Reg] = KillIdx;
322 DefIndices[Reg] = ~0u;
323 RegRefs.erase(Reg);
324 State->LeaveGroup(Reg);
Craig Topperc0196b12014-04-14 00:51:57 +0000325 DEBUG(if (header) {
Francis Visoiu Mistrihc71cced2017-11-30 16:12:24 +0000326 dbgs() << header << printReg(Reg, TRI); header = nullptr; });
David Greene75a2efb2009-12-24 00:14:25 +0000327 DEBUG(dbgs() << "->g" << State->GetGroup(Reg) << tag);
Chuang-Yu Cheng35c61812016-04-01 02:05:29 +0000328 // Repeat for subregisters. Note that we only do this if the superregister
329 // was not live because otherwise, regardless whether we have an explicit
330 // use of the subregister, the subregister's contents are needed for the
331 // uses of the superregister.
332 for (MCSubRegIterator SubRegs(Reg, TRI); SubRegs.isValid(); ++SubRegs) {
333 unsigned SubregReg = *SubRegs;
334 if (!State->IsLive(SubregReg)) {
335 KillIndices[SubregReg] = KillIdx;
336 DefIndices[SubregReg] = ~0u;
337 RegRefs.erase(SubregReg);
338 State->LeaveGroup(SubregReg);
339 DEBUG(if (header) {
Francis Visoiu Mistrihc71cced2017-11-30 16:12:24 +0000340 dbgs() << header << printReg(Reg, TRI); header = nullptr; });
341 DEBUG(dbgs() << " " << printReg(SubregReg, TRI) << "->g" <<
Chuang-Yu Cheng35c61812016-04-01 02:05:29 +0000342 State->GetGroup(SubregReg) << tag);
343 }
David Goodwin9f1b2d42009-10-29 19:17:04 +0000344 }
345 }
David Goodwindd1c6192009-11-19 23:12:37 +0000346
Craig Topperc0196b12014-04-14 00:51:57 +0000347 DEBUG(if (!header && footer) dbgs() << footer);
David Goodwin9f1b2d42009-10-29 19:17:04 +0000348}
349
Duncan P. N. Exon Smith5e6e8c72016-02-27 19:33:37 +0000350void AggressiveAntiDepBreaker::PrescanInstruction(
351 MachineInstr &MI, unsigned Count, std::set<unsigned> &PassthruRegs) {
Bill Wendling030b0282010-07-15 18:43:09 +0000352 std::vector<unsigned> &DefIndices = State->GetDefIndices();
Jim Grosbacheb431da2010-01-06 16:48:02 +0000353 std::multimap<unsigned, AggressiveAntiDepState::RegisterReference>&
David Goodwine056d102009-10-26 22:31:16 +0000354 RegRefs = State->GetRegRefs();
355
David Goodwin9f1b2d42009-10-29 19:17:04 +0000356 // Handle dead defs by simulating a last-use of the register just
Chris Lattner0ab5e2c2011-04-15 05:18:47 +0000357 // after the def. A dead def can occur because the def is truly
David Goodwin9f1b2d42009-10-29 19:17:04 +0000358 // dead, or because only a subregister is live at the def. If we
359 // don't do this the dead def will be incorrectly merged into the
360 // previous def.
Duncan P. N. Exon Smith5e6e8c72016-02-27 19:33:37 +0000361 for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) {
362 MachineOperand &MO = MI.getOperand(i);
David Goodwinde11f362009-10-26 19:32:42 +0000363 if (!MO.isReg() || !MO.isDef()) continue;
364 unsigned Reg = MO.getReg();
365 if (Reg == 0) continue;
Jim Grosbacheb431da2010-01-06 16:48:02 +0000366
David Goodwindd1c6192009-11-19 23:12:37 +0000367 HandleLastUse(Reg, Count + 1, "", "\tDead Def: ", "\n");
David Goodwinde11f362009-10-26 19:32:42 +0000368 }
369
David Greene75a2efb2009-12-24 00:14:25 +0000370 DEBUG(dbgs() << "\tDef Groups:");
Duncan P. N. Exon Smith5e6e8c72016-02-27 19:33:37 +0000371 for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) {
372 MachineOperand &MO = MI.getOperand(i);
David Goodwinde11f362009-10-26 19:32:42 +0000373 if (!MO.isReg() || !MO.isDef()) continue;
374 unsigned Reg = MO.getReg();
375 if (Reg == 0) continue;
376
Francis Visoiu Mistrihc71cced2017-11-30 16:12:24 +0000377 DEBUG(dbgs() << " " << printReg(Reg, TRI) << "=g" << State->GetGroup(Reg));
David Goodwinde11f362009-10-26 19:32:42 +0000378
David Goodwin9f1b2d42009-10-29 19:17:04 +0000379 // If MI's defs have a special allocation requirement, don't allow
David Goodwinde11f362009-10-26 19:32:42 +0000380 // any def registers to be changed. Also assume all registers
Kyle Buttcf6a8bf2015-12-02 18:58:51 +0000381 // defined in a call must not be changed (ABI). Inline assembly may
382 // reference either system calls or the register directly. Skip it until we
383 // can tell user specified registers from compiler-specified.
Duncan P. N. Exon Smith5e6e8c72016-02-27 19:33:37 +0000384 if (MI.isCall() || MI.hasExtraDefRegAllocReq() || TII->isPredicated(MI) ||
385 MI.isInlineAsm()) {
David Greene75a2efb2009-12-24 00:14:25 +0000386 DEBUG(if (State->GetGroup(Reg) != 0) dbgs() << "->g0(alloc-req)");
David Goodwine056d102009-10-26 22:31:16 +0000387 State->UnionGroups(Reg, 0);
David Goodwinde11f362009-10-26 19:32:42 +0000388 }
389
390 // Any aliased that are live at this point are completely or
David Goodwin9f1b2d42009-10-29 19:17:04 +0000391 // partially defined here, so group those aliases with Reg.
Jakob Stoklund Olesen54038d72012-06-01 23:28:30 +0000392 for (MCRegAliasIterator AI(Reg, TRI, false); AI.isValid(); ++AI) {
393 unsigned AliasReg = *AI;
David Goodwine056d102009-10-26 22:31:16 +0000394 if (State->IsLive(AliasReg)) {
395 State->UnionGroups(Reg, AliasReg);
Francis Visoiu Mistrihc71cced2017-11-30 16:12:24 +0000396 DEBUG(dbgs() << "->g" << State->GetGroup(Reg) << "(via "
397 << printReg(AliasReg, TRI) << ")");
David Goodwinde11f362009-10-26 19:32:42 +0000398 }
399 }
Jim Grosbacheb431da2010-01-06 16:48:02 +0000400
David Goodwinde11f362009-10-26 19:32:42 +0000401 // Note register reference...
Craig Topperc0196b12014-04-14 00:51:57 +0000402 const TargetRegisterClass *RC = nullptr;
Duncan P. N. Exon Smith5e6e8c72016-02-27 19:33:37 +0000403 if (i < MI.getDesc().getNumOperands())
404 RC = TII->getRegClass(MI.getDesc(), i, TRI, MF);
David Goodwine056d102009-10-26 22:31:16 +0000405 AggressiveAntiDepState::RegisterReference RR = { &MO, RC };
David Goodwinde11f362009-10-26 19:32:42 +0000406 RegRefs.insert(std::make_pair(Reg, RR));
407 }
408
David Greene75a2efb2009-12-24 00:14:25 +0000409 DEBUG(dbgs() << '\n');
David Goodwin9f1b2d42009-10-29 19:17:04 +0000410
411 // Scan the register defs for this instruction and update
412 // live-ranges.
Duncan P. N. Exon Smith5e6e8c72016-02-27 19:33:37 +0000413 for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) {
414 MachineOperand &MO = MI.getOperand(i);
David Goodwin9f1b2d42009-10-29 19:17:04 +0000415 if (!MO.isReg() || !MO.isDef()) continue;
416 unsigned Reg = MO.getReg();
417 if (Reg == 0) continue;
David Goodwindd1c6192009-11-19 23:12:37 +0000418 // Ignore KILLs and passthru registers for liveness...
Duncan P. N. Exon Smith5e6e8c72016-02-27 19:33:37 +0000419 if (MI.isKill() || (PassthruRegs.count(Reg) != 0))
David Goodwindd1c6192009-11-19 23:12:37 +0000420 continue;
David Goodwin9f1b2d42009-10-29 19:17:04 +0000421
David Goodwindd1c6192009-11-19 23:12:37 +0000422 // Update def for Reg and aliases.
Hal Finkel121caf62014-02-26 20:20:30 +0000423 for (MCRegAliasIterator AI(Reg, TRI, true); AI.isValid(); ++AI) {
424 // We need to be careful here not to define already-live super registers.
425 // If the super register is already live, then this definition is not
426 // a definition of the whole super register (just a partial insertion
427 // into it). Earlier subregister definitions (which we've not yet visited
428 // because we're iterating bottom-up) need to be linked to the same group
429 // as this definition.
430 if (TRI->isSuperRegister(Reg, *AI) && State->IsLive(*AI))
431 continue;
432
Jakob Stoklund Olesen54038d72012-06-01 23:28:30 +0000433 DefIndices[*AI] = Count;
Hal Finkel121caf62014-02-26 20:20:30 +0000434 }
David Goodwin9f1b2d42009-10-29 19:17:04 +0000435 }
David Goodwinde11f362009-10-26 19:32:42 +0000436}
437
Duncan P. N. Exon Smith5e6e8c72016-02-27 19:33:37 +0000438void AggressiveAntiDepBreaker::ScanInstruction(MachineInstr &MI,
Bob Wilson67dd3a42010-04-09 21:38:26 +0000439 unsigned Count) {
David Greene75a2efb2009-12-24 00:14:25 +0000440 DEBUG(dbgs() << "\tUse Groups:");
Jim Grosbacheb431da2010-01-06 16:48:02 +0000441 std::multimap<unsigned, AggressiveAntiDepState::RegisterReference>&
David Goodwine056d102009-10-26 22:31:16 +0000442 RegRefs = State->GetRegRefs();
David Goodwinde11f362009-10-26 19:32:42 +0000443
Evan Chengf128bdc2010-06-16 07:35:02 +0000444 // If MI's uses have special allocation requirement, don't allow
445 // any use registers to be changed. Also assume all registers
446 // used in a call must not be changed (ABI).
Kyle Buttcf6a8bf2015-12-02 18:58:51 +0000447 // Inline Assembly register uses also cannot be safely changed.
Evan Chengf128bdc2010-06-16 07:35:02 +0000448 // FIXME: The issue with predicated instruction is more complex. We are being
449 // conservatively here because the kill markers cannot be trusted after
450 // if-conversion:
Francis Visoiu Mistrih7d9bef82018-01-09 17:31:07 +0000451 // %r6 = LDR %sp, %reg0, 92, 14, %reg0; mem:LD4[FixedStack14]
Evan Chengf128bdc2010-06-16 07:35:02 +0000452 // ...
Francis Visoiu Mistrih7d9bef82018-01-09 17:31:07 +0000453 // STR %r0, killed %r6, %reg0, 0, 0, %cpsr; mem:ST4[%395]
454 // %r6 = LDR %sp, %reg0, 100, 0, %cpsr; mem:LD4[FixedStack12]
455 // STR %r0, killed %r6, %reg0, 0, 14, %reg0; mem:ST4[%396](align=8)
Evan Chengf128bdc2010-06-16 07:35:02 +0000456 //
457 // The first R6 kill is not really a kill since it's killed by a predicated
458 // instruction which may not be executed. The second R6 def may or may not
459 // re-define R6 so it's not safe to change it since the last R6 use cannot be
460 // changed.
Duncan P. N. Exon Smith5e6e8c72016-02-27 19:33:37 +0000461 bool Special = MI.isCall() || MI.hasExtraSrcRegAllocReq() ||
462 TII->isPredicated(MI) || MI.isInlineAsm();
Evan Chengf128bdc2010-06-16 07:35:02 +0000463
David Goodwinde11f362009-10-26 19:32:42 +0000464 // Scan the register uses for this instruction and update
465 // live-ranges, groups and RegRefs.
Duncan P. N. Exon Smith5e6e8c72016-02-27 19:33:37 +0000466 for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) {
467 MachineOperand &MO = MI.getOperand(i);
David Goodwinde11f362009-10-26 19:32:42 +0000468 if (!MO.isReg() || !MO.isUse()) continue;
469 unsigned Reg = MO.getReg();
470 if (Reg == 0) continue;
Jim Grosbacheb431da2010-01-06 16:48:02 +0000471
Francis Visoiu Mistrihc71cced2017-11-30 16:12:24 +0000472 DEBUG(dbgs() << " " << printReg(Reg, TRI) << "=g" << State->GetGroup(Reg));
David Goodwinde11f362009-10-26 19:32:42 +0000473
474 // It wasn't previously live but now it is, this is a kill. Forget
475 // the previous live-range information and start a new live-range
476 // for the register.
David Goodwin9f1b2d42009-10-29 19:17:04 +0000477 HandleLastUse(Reg, Count, "(last-use)");
David Goodwinde11f362009-10-26 19:32:42 +0000478
Evan Chengf128bdc2010-06-16 07:35:02 +0000479 if (Special) {
David Greene75a2efb2009-12-24 00:14:25 +0000480 DEBUG(if (State->GetGroup(Reg) != 0) dbgs() << "->g0(alloc-req)");
David Goodwine056d102009-10-26 22:31:16 +0000481 State->UnionGroups(Reg, 0);
David Goodwinde11f362009-10-26 19:32:42 +0000482 }
483
484 // Note register reference...
Craig Topperc0196b12014-04-14 00:51:57 +0000485 const TargetRegisterClass *RC = nullptr;
Duncan P. N. Exon Smith5e6e8c72016-02-27 19:33:37 +0000486 if (i < MI.getDesc().getNumOperands())
487 RC = TII->getRegClass(MI.getDesc(), i, TRI, MF);
David Goodwine056d102009-10-26 22:31:16 +0000488 AggressiveAntiDepState::RegisterReference RR = { &MO, RC };
David Goodwinde11f362009-10-26 19:32:42 +0000489 RegRefs.insert(std::make_pair(Reg, RR));
490 }
Jim Grosbacheb431da2010-01-06 16:48:02 +0000491
David Greene75a2efb2009-12-24 00:14:25 +0000492 DEBUG(dbgs() << '\n');
David Goodwinde11f362009-10-26 19:32:42 +0000493
494 // Form a group of all defs and uses of a KILL instruction to ensure
495 // that all registers are renamed as a group.
Duncan P. N. Exon Smith5e6e8c72016-02-27 19:33:37 +0000496 if (MI.isKill()) {
David Greene75a2efb2009-12-24 00:14:25 +0000497 DEBUG(dbgs() << "\tKill Group:");
David Goodwinde11f362009-10-26 19:32:42 +0000498
499 unsigned FirstReg = 0;
Duncan P. N. Exon Smith5e6e8c72016-02-27 19:33:37 +0000500 for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) {
501 MachineOperand &MO = MI.getOperand(i);
David Goodwinde11f362009-10-26 19:32:42 +0000502 if (!MO.isReg()) continue;
503 unsigned Reg = MO.getReg();
504 if (Reg == 0) continue;
Jim Grosbacheb431da2010-01-06 16:48:02 +0000505
David Goodwinde11f362009-10-26 19:32:42 +0000506 if (FirstReg != 0) {
Francis Visoiu Mistrihc71cced2017-11-30 16:12:24 +0000507 DEBUG(dbgs() << "=" << printReg(Reg, TRI));
David Goodwine056d102009-10-26 22:31:16 +0000508 State->UnionGroups(FirstReg, Reg);
David Goodwinde11f362009-10-26 19:32:42 +0000509 } else {
Francis Visoiu Mistrihc71cced2017-11-30 16:12:24 +0000510 DEBUG(dbgs() << " " << printReg(Reg, TRI));
David Goodwinde11f362009-10-26 19:32:42 +0000511 FirstReg = Reg;
512 }
513 }
Jim Grosbacheb431da2010-01-06 16:48:02 +0000514
David Greene75a2efb2009-12-24 00:14:25 +0000515 DEBUG(dbgs() << "->g" << State->GetGroup(FirstReg) << '\n');
David Goodwinde11f362009-10-26 19:32:42 +0000516 }
517}
518
519BitVector AggressiveAntiDepBreaker::GetRenameRegisters(unsigned Reg) {
520 BitVector BV(TRI->getNumRegs(), false);
521 bool first = true;
522
523 // Check all references that need rewriting for Reg. For each, use
524 // the corresponding register class to narrow the set of registers
525 // that are appropriate for renaming.
Benjamin Kramerc9436ad2015-07-18 20:05:10 +0000526 for (const auto &Q : make_range(State->GetRegRefs().equal_range(Reg))) {
527 const TargetRegisterClass *RC = Q.second.RC;
Craig Topperc0196b12014-04-14 00:51:57 +0000528 if (!RC) continue;
David Goodwinde11f362009-10-26 19:32:42 +0000529
530 BitVector RCBV = TRI->getAllocatableSet(MF, RC);
531 if (first) {
532 BV |= RCBV;
533 first = false;
534 } else {
535 BV &= RCBV;
536 }
537
Craig Toppercf0444b2014-11-17 05:50:14 +0000538 DEBUG(dbgs() << " " << TRI->getRegClassName(RC));
David Goodwinde11f362009-10-26 19:32:42 +0000539 }
Jim Grosbacheb431da2010-01-06 16:48:02 +0000540
David Goodwinde11f362009-10-26 19:32:42 +0000541 return BV;
Jim Grosbacheb431da2010-01-06 16:48:02 +0000542}
David Goodwinde11f362009-10-26 19:32:42 +0000543
544bool AggressiveAntiDepBreaker::FindSuitableFreeRegisters(
David Goodwin7d8878a2009-11-05 01:19:35 +0000545 unsigned AntiDepGroupIndex,
546 RenameOrderType& RenameOrder,
547 std::map<unsigned, unsigned> &RenameMap) {
Bill Wendling030b0282010-07-15 18:43:09 +0000548 std::vector<unsigned> &KillIndices = State->GetKillIndices();
549 std::vector<unsigned> &DefIndices = State->GetDefIndices();
Jim Grosbacheb431da2010-01-06 16:48:02 +0000550 std::multimap<unsigned, AggressiveAntiDepState::RegisterReference>&
David Goodwine056d102009-10-26 22:31:16 +0000551 RegRefs = State->GetRegRefs();
552
David Goodwinb9fe5d52009-11-13 19:52:48 +0000553 // Collect all referenced registers in the same group as
554 // AntiDepReg. These all need to be renamed together if we are to
555 // break the anti-dependence.
David Goodwinde11f362009-10-26 19:32:42 +0000556 std::vector<unsigned> Regs;
David Goodwinb9fe5d52009-11-13 19:52:48 +0000557 State->GetGroupRegs(AntiDepGroupIndex, Regs, &RegRefs);
Eugene Zelenko4f81cdd2017-09-29 21:55:49 +0000558 assert(!Regs.empty() && "Empty register group!");
559 if (Regs.empty())
David Goodwinde11f362009-10-26 19:32:42 +0000560 return false;
561
562 // Find the "superest" register in the group. At the same time,
563 // collect the BitVector of registers that can be used to rename
564 // each register.
Jim Grosbacheb431da2010-01-06 16:48:02 +0000565 DEBUG(dbgs() << "\tRename Candidates for Group g" << AntiDepGroupIndex
566 << ":\n");
David Goodwinde11f362009-10-26 19:32:42 +0000567 std::map<unsigned, BitVector> RenameRegisterMap;
568 unsigned SuperReg = 0;
569 for (unsigned i = 0, e = Regs.size(); i != e; ++i) {
570 unsigned Reg = Regs[i];
571 if ((SuperReg == 0) || TRI->isSuperRegister(SuperReg, Reg))
572 SuperReg = Reg;
573
574 // If Reg has any references, then collect possible rename regs
575 if (RegRefs.count(Reg) > 0) {
Francis Visoiu Mistrihc71cced2017-11-30 16:12:24 +0000576 DEBUG(dbgs() << "\t\t" << printReg(Reg, TRI) << ":");
Jim Grosbacheb431da2010-01-06 16:48:02 +0000577
Benjamin Kramer7f75e942016-02-13 16:39:39 +0000578 BitVector &BV = RenameRegisterMap[Reg];
579 assert(BV.empty());
580 BV = GetRenameRegisters(Reg);
David Goodwinde11f362009-10-26 19:32:42 +0000581
Benjamin Kramer7f75e942016-02-13 16:39:39 +0000582 DEBUG({
583 dbgs() << " ::";
Francis Visoiu Mistrihb52e0362017-05-17 01:07:53 +0000584 for (unsigned r : BV.set_bits())
Francis Visoiu Mistrihc71cced2017-11-30 16:12:24 +0000585 dbgs() << " " << printReg(r, TRI);
Benjamin Kramer7f75e942016-02-13 16:39:39 +0000586 dbgs() << "\n";
587 });
David Goodwinde11f362009-10-26 19:32:42 +0000588 }
589 }
590
591 // All group registers should be a subreg of SuperReg.
592 for (unsigned i = 0, e = Regs.size(); i != e; ++i) {
593 unsigned Reg = Regs[i];
594 if (Reg == SuperReg) continue;
595 bool IsSub = TRI->isSubRegister(SuperReg, Reg);
Will Schmidt44ff8f02014-07-31 19:50:53 +0000596 // FIXME: remove this once PR18663 has been properly fixed. For now,
597 // return a conservative answer:
598 // assert(IsSub && "Expecting group subregister");
David Goodwinde11f362009-10-26 19:32:42 +0000599 if (!IsSub)
600 return false;
601 }
602
David Goodwin5305dc02009-11-20 23:33:54 +0000603#ifndef NDEBUG
604 // If DebugDiv > 0 then only rename (renamecnt % DebugDiv) == DebugMod
605 if (DebugDiv > 0) {
606 static int renamecnt = 0;
607 if (renamecnt++ % DebugDiv != DebugMod)
608 return false;
Jim Grosbacheb431da2010-01-06 16:48:02 +0000609
Francis Visoiu Mistrihc71cced2017-11-30 16:12:24 +0000610 dbgs() << "*** Performing rename " << printReg(SuperReg, TRI)
611 << " for debug ***\n";
David Goodwin5305dc02009-11-20 23:33:54 +0000612 }
613#endif
614
David Goodwin7d8878a2009-11-05 01:19:35 +0000615 // Check each possible rename register for SuperReg in round-robin
616 // order. If that register is available, and the corresponding
617 // registers are available for the other group subregisters, then we
618 // can use those registers to rename.
Rafael Espindola871c7242010-07-12 02:55:34 +0000619
620 // FIXME: Using getMinimalPhysRegClass is very conservative. We should
621 // check every use of the register and find the largest register class
622 // that can be used in all of them.
Jim Grosbacheb431da2010-01-06 16:48:02 +0000623 const TargetRegisterClass *SuperRC =
Rafael Espindola871c7242010-07-12 02:55:34 +0000624 TRI->getMinimalPhysRegClass(SuperReg, MVT::Other);
Jim Grosbacheb431da2010-01-06 16:48:02 +0000625
Jakob Stoklund Olesenbdb55e02012-11-29 03:34:17 +0000626 ArrayRef<MCPhysReg> Order = RegClassInfo.getOrder(SuperRC);
Jakob Stoklund Olesen4f5f84c2011-06-16 21:56:21 +0000627 if (Order.empty()) {
David Greene75a2efb2009-12-24 00:14:25 +0000628 DEBUG(dbgs() << "\tEmpty Super Regclass!!\n");
David Goodwin7d8878a2009-11-05 01:19:35 +0000629 return false;
630 }
631
David Greene75a2efb2009-12-24 00:14:25 +0000632 DEBUG(dbgs() << "\tFind Registers:");
David Goodwindd1c6192009-11-19 23:12:37 +0000633
Benjamin Kramer2c99e412014-10-10 15:32:50 +0000634 RenameOrder.insert(RenameOrderType::value_type(SuperRC, Order.size()));
David Goodwin7d8878a2009-11-05 01:19:35 +0000635
Jakob Stoklund Olesen4f5f84c2011-06-16 21:56:21 +0000636 unsigned OrigR = RenameOrder[SuperRC];
637 unsigned EndR = ((OrigR == Order.size()) ? 0 : OrigR);
638 unsigned R = OrigR;
David Goodwin7d8878a2009-11-05 01:19:35 +0000639 do {
Jakob Stoklund Olesen4f5f84c2011-06-16 21:56:21 +0000640 if (R == 0) R = Order.size();
David Goodwin7d8878a2009-11-05 01:19:35 +0000641 --R;
Jakob Stoklund Olesen4f5f84c2011-06-16 21:56:21 +0000642 const unsigned NewSuperReg = Order[R];
Jim Grosbach944aece2010-09-02 17:12:55 +0000643 // Don't consider non-allocatable registers
Jakob Stoklund Olesenf67bf3e2012-10-15 22:41:03 +0000644 if (!MRI.isAllocatable(NewSuperReg)) continue;
David Goodwinde11f362009-10-26 19:32:42 +0000645 // Don't replace a register with itself.
David Goodwin5305dc02009-11-20 23:33:54 +0000646 if (NewSuperReg == SuperReg) continue;
Jim Grosbacheb431da2010-01-06 16:48:02 +0000647
Francis Visoiu Mistrihc71cced2017-11-30 16:12:24 +0000648 DEBUG(dbgs() << " [" << printReg(NewSuperReg, TRI) << ':');
David Goodwin5305dc02009-11-20 23:33:54 +0000649 RenameMap.clear();
650
651 // For each referenced group register (which must be a SuperReg or
652 // a subregister of SuperReg), find the corresponding subregister
653 // of NewSuperReg and make sure it is free to be renamed.
654 for (unsigned i = 0, e = Regs.size(); i != e; ++i) {
655 unsigned Reg = Regs[i];
656 unsigned NewReg = 0;
657 if (Reg == SuperReg) {
658 NewReg = NewSuperReg;
659 } else {
660 unsigned NewSubRegIdx = TRI->getSubRegIndex(SuperReg, Reg);
661 if (NewSubRegIdx != 0)
662 NewReg = TRI->getSubReg(NewSuperReg, NewSubRegIdx);
David Goodwinde11f362009-10-26 19:32:42 +0000663 }
David Goodwin5305dc02009-11-20 23:33:54 +0000664
Francis Visoiu Mistrihc71cced2017-11-30 16:12:24 +0000665 DEBUG(dbgs() << " " << printReg(NewReg, TRI));
Jim Grosbacheb431da2010-01-06 16:48:02 +0000666
David Goodwin5305dc02009-11-20 23:33:54 +0000667 // Check if Reg can be renamed to NewReg.
Benjamin Kramer7f75e942016-02-13 16:39:39 +0000668 if (!RenameRegisterMap[Reg].test(NewReg)) {
David Greene75a2efb2009-12-24 00:14:25 +0000669 DEBUG(dbgs() << "(no rename)");
David Goodwin5305dc02009-11-20 23:33:54 +0000670 goto next_super_reg;
671 }
672
673 // If NewReg is dead and NewReg's most recent def is not before
674 // Regs's kill, it's safe to replace Reg with NewReg. We
675 // must also check all aliases of NewReg, because we can't define a
676 // register when any sub or super is already live.
677 if (State->IsLive(NewReg) || (KillIndices[Reg] > DefIndices[NewReg])) {
David Greene75a2efb2009-12-24 00:14:25 +0000678 DEBUG(dbgs() << "(live)");
David Goodwin5305dc02009-11-20 23:33:54 +0000679 goto next_super_reg;
680 } else {
681 bool found = false;
Jakob Stoklund Olesen54038d72012-06-01 23:28:30 +0000682 for (MCRegAliasIterator AI(NewReg, TRI, false); AI.isValid(); ++AI) {
683 unsigned AliasReg = *AI;
Jim Grosbacheb431da2010-01-06 16:48:02 +0000684 if (State->IsLive(AliasReg) ||
685 (KillIndices[Reg] > DefIndices[AliasReg])) {
Francis Visoiu Mistrihc71cced2017-11-30 16:12:24 +0000686 DEBUG(dbgs() << "(alias " << printReg(AliasReg, TRI) << " live)");
David Goodwin5305dc02009-11-20 23:33:54 +0000687 found = true;
688 break;
689 }
690 }
691 if (found)
692 goto next_super_reg;
693 }
Jim Grosbacheb431da2010-01-06 16:48:02 +0000694
Hal Finkelc8cf2b82014-12-09 01:00:59 +0000695 // We cannot rename 'Reg' to 'NewReg' if one of the uses of 'Reg' also
696 // defines 'NewReg' via an early-clobber operand.
Benjamin Kramerc9436ad2015-07-18 20:05:10 +0000697 for (const auto &Q : make_range(RegRefs.equal_range(Reg))) {
698 MachineInstr *UseMI = Q.second.Operand->getParent();
Hal Finkelc8cf2b82014-12-09 01:00:59 +0000699 int Idx = UseMI->findRegisterDefOperandIdx(NewReg, false, true, TRI);
700 if (Idx == -1)
701 continue;
702
703 if (UseMI->getOperand(Idx).isEarlyClobber()) {
704 DEBUG(dbgs() << "(ec)");
705 goto next_super_reg;
706 }
707 }
708
Hal Finkele0a28e52015-08-31 07:51:36 +0000709 // Also, we cannot rename 'Reg' to 'NewReg' if the instruction defining
710 // 'Reg' is an early-clobber define and that instruction also uses
711 // 'NewReg'.
712 for (const auto &Q : make_range(RegRefs.equal_range(Reg))) {
713 if (!Q.second.Operand->isDef() || !Q.second.Operand->isEarlyClobber())
714 continue;
715
716 MachineInstr *DefMI = Q.second.Operand->getParent();
717 if (DefMI->readsRegister(NewReg, TRI)) {
718 DEBUG(dbgs() << "(ec)");
719 goto next_super_reg;
720 }
721 }
722
David Goodwin5305dc02009-11-20 23:33:54 +0000723 // Record that 'Reg' can be renamed to 'NewReg'.
724 RenameMap.insert(std::pair<unsigned, unsigned>(Reg, NewReg));
David Goodwinde11f362009-10-26 19:32:42 +0000725 }
Jim Grosbacheb431da2010-01-06 16:48:02 +0000726
David Goodwin5305dc02009-11-20 23:33:54 +0000727 // If we fall-out here, then every register in the group can be
728 // renamed, as recorded in RenameMap.
729 RenameOrder.erase(SuperRC);
730 RenameOrder.insert(RenameOrderType::value_type(SuperRC, R));
David Greene75a2efb2009-12-24 00:14:25 +0000731 DEBUG(dbgs() << "]\n");
David Goodwin5305dc02009-11-20 23:33:54 +0000732 return true;
733
734 next_super_reg:
David Greene75a2efb2009-12-24 00:14:25 +0000735 DEBUG(dbgs() << ']');
David Goodwin7d8878a2009-11-05 01:19:35 +0000736 } while (R != EndR);
David Goodwinde11f362009-10-26 19:32:42 +0000737
David Greene75a2efb2009-12-24 00:14:25 +0000738 DEBUG(dbgs() << '\n');
David Goodwinde11f362009-10-26 19:32:42 +0000739
740 // No registers are free and available!
741 return false;
742}
743
744/// BreakAntiDependencies - Identifiy anti-dependencies within the
745/// ScheduleDAG and break them by renaming registers.
David Goodwine056d102009-10-26 22:31:16 +0000746unsigned AggressiveAntiDepBreaker::BreakAntiDependencies(
Eugene Zelenko4f81cdd2017-09-29 21:55:49 +0000747 const std::vector<SUnit> &SUnits,
Dan Gohman35bc4d42010-04-19 23:11:58 +0000748 MachineBasicBlock::iterator Begin,
749 MachineBasicBlock::iterator End,
Devang Patelf02a3762011-06-02 21:26:52 +0000750 unsigned InsertPosIndex,
751 DbgValueVector &DbgValues) {
Bill Wendling030b0282010-07-15 18:43:09 +0000752 std::vector<unsigned> &KillIndices = State->GetKillIndices();
753 std::vector<unsigned> &DefIndices = State->GetDefIndices();
Jim Grosbacheb431da2010-01-06 16:48:02 +0000754 std::multimap<unsigned, AggressiveAntiDepState::RegisterReference>&
David Goodwine056d102009-10-26 22:31:16 +0000755 RegRefs = State->GetRegRefs();
756
David Goodwinde11f362009-10-26 19:32:42 +0000757 // The code below assumes that there is at least one instruction,
758 // so just duck out immediately if the block is empty.
David Goodwin8501dbbe2009-11-03 20:57:50 +0000759 if (SUnits.empty()) return 0;
Jim Grosbacheb431da2010-01-06 16:48:02 +0000760
David Goodwin7d8878a2009-11-05 01:19:35 +0000761 // For each regclass the next register to use for renaming.
762 RenameOrderType RenameOrder;
David Goodwinde11f362009-10-26 19:32:42 +0000763
764 // ...need a map from MI to SUnit.
Dan Gohman35bc4d42010-04-19 23:11:58 +0000765 std::map<MachineInstr *, const SUnit *> MISUnitMap;
David Goodwinde11f362009-10-26 19:32:42 +0000766 for (unsigned i = 0, e = SUnits.size(); i != e; ++i) {
Dan Gohman35bc4d42010-04-19 23:11:58 +0000767 const SUnit *SU = &SUnits[i];
768 MISUnitMap.insert(std::pair<MachineInstr *, const SUnit *>(SU->getInstr(),
769 SU));
David Goodwinde11f362009-10-26 19:32:42 +0000770 }
771
David Goodwinb9fe5d52009-11-13 19:52:48 +0000772 // Track progress along the critical path through the SUnit graph as
773 // we walk the instructions. This is needed for regclasses that only
774 // break critical-path anti-dependencies.
Craig Topperc0196b12014-04-14 00:51:57 +0000775 const SUnit *CriticalPathSU = nullptr;
776 MachineInstr *CriticalPathMI = nullptr;
David Goodwinb9fe5d52009-11-13 19:52:48 +0000777 if (CriticalPathSet.any()) {
778 for (unsigned i = 0, e = SUnits.size(); i != e; ++i) {
Dan Gohman35bc4d42010-04-19 23:11:58 +0000779 const SUnit *SU = &SUnits[i];
Jim Grosbacheb431da2010-01-06 16:48:02 +0000780 if (!CriticalPathSU ||
781 ((SU->getDepth() + SU->Latency) >
David Goodwinb9fe5d52009-11-13 19:52:48 +0000782 (CriticalPathSU->getDepth() + CriticalPathSU->Latency))) {
783 CriticalPathSU = SU;
784 }
785 }
Jim Grosbacheb431da2010-01-06 16:48:02 +0000786
David Goodwinb9fe5d52009-11-13 19:52:48 +0000787 CriticalPathMI = CriticalPathSU->getInstr();
788 }
789
Jim Grosbacheb431da2010-01-06 16:48:02 +0000790#ifndef NDEBUG
David Greene75a2efb2009-12-24 00:14:25 +0000791 DEBUG(dbgs() << "\n===== Aggressive anti-dependency breaking\n");
792 DEBUG(dbgs() << "Available regs:");
David Goodwin80a03cc2009-11-20 19:32:48 +0000793 for (unsigned Reg = 0; Reg < TRI->getNumRegs(); ++Reg) {
794 if (!State->IsLive(Reg))
Francis Visoiu Mistrihc71cced2017-11-30 16:12:24 +0000795 DEBUG(dbgs() << " " << printReg(Reg, TRI));
David Goodwinde11f362009-10-26 19:32:42 +0000796 }
David Greene75a2efb2009-12-24 00:14:25 +0000797 DEBUG(dbgs() << '\n');
David Goodwinde11f362009-10-26 19:32:42 +0000798#endif
799
Krzysztof Parzyszek143f6842016-05-26 18:22:53 +0000800 BitVector RegAliases(TRI->getNumRegs());
801
David Goodwinde11f362009-10-26 19:32:42 +0000802 // Attempt to break anti-dependence edges. Walk the instructions
803 // from the bottom up, tracking information about liveness as we go
804 // to help determine which registers are available.
805 unsigned Broken = 0;
806 unsigned Count = InsertPosIndex - 1;
807 for (MachineBasicBlock::iterator I = End, E = Begin;
808 I != E; --Count) {
Duncan P. N. Exon Smith5e6e8c72016-02-27 19:33:37 +0000809 MachineInstr &MI = *--I;
David Goodwinde11f362009-10-26 19:32:42 +0000810
Duncan P. N. Exon Smith5e6e8c72016-02-27 19:33:37 +0000811 if (MI.isDebugValue())
Hal Finkel8606e3c2012-01-16 22:53:41 +0000812 continue;
813
David Greene75a2efb2009-12-24 00:14:25 +0000814 DEBUG(dbgs() << "Anti: ");
Duncan P. N. Exon Smith5e6e8c72016-02-27 19:33:37 +0000815 DEBUG(MI.dump());
David Goodwinde11f362009-10-26 19:32:42 +0000816
817 std::set<unsigned> PassthruRegs;
818 GetPassthruRegs(MI, PassthruRegs);
819
820 // Process the defs in MI...
821 PrescanInstruction(MI, Count, PassthruRegs);
Jim Grosbacheb431da2010-01-06 16:48:02 +0000822
David Goodwin80a03cc2009-11-20 19:32:48 +0000823 // The dependence edges that represent anti- and output-
David Goodwinb9fe5d52009-11-13 19:52:48 +0000824 // dependencies that are candidates for breaking.
Dan Gohman35bc4d42010-04-19 23:11:58 +0000825 std::vector<const SDep *> Edges;
Duncan P. N. Exon Smith5e6e8c72016-02-27 19:33:37 +0000826 const SUnit *PathSU = MISUnitMap[&MI];
David Goodwin80a03cc2009-11-20 19:32:48 +0000827 AntiDepEdges(PathSU, Edges);
David Goodwinb9fe5d52009-11-13 19:52:48 +0000828
829 // If MI is not on the critical path, then we don't rename
830 // registers in the CriticalPathSet.
Craig Topperc0196b12014-04-14 00:51:57 +0000831 BitVector *ExcludeRegs = nullptr;
Duncan P. N. Exon Smith5e6e8c72016-02-27 19:33:37 +0000832 if (&MI == CriticalPathMI) {
David Goodwinb9fe5d52009-11-13 19:52:48 +0000833 CriticalPathSU = CriticalPathStep(CriticalPathSU);
Craig Topperc0196b12014-04-14 00:51:57 +0000834 CriticalPathMI = (CriticalPathSU) ? CriticalPathSU->getInstr() : nullptr;
Hal Finkel6f1ff8e2013-09-12 04:22:31 +0000835 } else if (CriticalPathSet.any()) {
David Goodwinb9fe5d52009-11-13 19:52:48 +0000836 ExcludeRegs = &CriticalPathSet;
837 }
838
David Goodwinde11f362009-10-26 19:32:42 +0000839 // Ignore KILL instructions (they form a group in ScanInstruction
840 // but don't cause any anti-dependence breaking themselves)
Duncan P. N. Exon Smith5e6e8c72016-02-27 19:33:37 +0000841 if (!MI.isKill()) {
David Goodwinde11f362009-10-26 19:32:42 +0000842 // Attempt to break each anti-dependency...
843 for (unsigned i = 0, e = Edges.size(); i != e; ++i) {
Dan Gohman35bc4d42010-04-19 23:11:58 +0000844 const SDep *Edge = Edges[i];
David Goodwinde11f362009-10-26 19:32:42 +0000845 SUnit *NextSU = Edge->getSUnit();
Jim Grosbacheb431da2010-01-06 16:48:02 +0000846
David Goodwinda83f7d2009-11-12 19:08:21 +0000847 if ((Edge->getKind() != SDep::Anti) &&
848 (Edge->getKind() != SDep::Output)) continue;
Jim Grosbacheb431da2010-01-06 16:48:02 +0000849
David Goodwinde11f362009-10-26 19:32:42 +0000850 unsigned AntiDepReg = Edge->getReg();
Francis Visoiu Mistrihc71cced2017-11-30 16:12:24 +0000851 DEBUG(dbgs() << "\tAntidep reg: " << printReg(AntiDepReg, TRI));
David Goodwinde11f362009-10-26 19:32:42 +0000852 assert(AntiDepReg != 0 && "Anti-dependence on reg0?");
Jim Grosbacheb431da2010-01-06 16:48:02 +0000853
Jakob Stoklund Olesenf67bf3e2012-10-15 22:41:03 +0000854 if (!MRI.isAllocatable(AntiDepReg)) {
David Goodwinde11f362009-10-26 19:32:42 +0000855 // Don't break anti-dependencies on non-allocatable registers.
David Greene75a2efb2009-12-24 00:14:25 +0000856 DEBUG(dbgs() << " (non-allocatable)\n");
David Goodwinde11f362009-10-26 19:32:42 +0000857 continue;
Craig Topperc0196b12014-04-14 00:51:57 +0000858 } else if (ExcludeRegs && ExcludeRegs->test(AntiDepReg)) {
David Goodwinb9fe5d52009-11-13 19:52:48 +0000859 // Don't break anti-dependencies for critical path registers
860 // if not on the critical path
David Greene75a2efb2009-12-24 00:14:25 +0000861 DEBUG(dbgs() << " (not critical-path)\n");
David Goodwinb9fe5d52009-11-13 19:52:48 +0000862 continue;
David Goodwinde11f362009-10-26 19:32:42 +0000863 } else if (PassthruRegs.count(AntiDepReg) != 0) {
864 // If the anti-dep register liveness "passes-thru", then
865 // don't try to change it. It will be changed along with
866 // the use if required to break an earlier antidep.
David Greene75a2efb2009-12-24 00:14:25 +0000867 DEBUG(dbgs() << " (passthru)\n");
David Goodwinde11f362009-10-26 19:32:42 +0000868 continue;
869 } else {
870 // No anti-dep breaking for implicit deps
Duncan P. N. Exon Smith5e6e8c72016-02-27 19:33:37 +0000871 MachineOperand *AntiDepOp = MI.findRegisterDefOperand(AntiDepReg);
Craig Topperc0196b12014-04-14 00:51:57 +0000872 assert(AntiDepOp && "Can't find index for defined register operand");
873 if (!AntiDepOp || AntiDepOp->isImplicit()) {
David Greene75a2efb2009-12-24 00:14:25 +0000874 DEBUG(dbgs() << " (implicit)\n");
David Goodwinde11f362009-10-26 19:32:42 +0000875 continue;
876 }
Jim Grosbacheb431da2010-01-06 16:48:02 +0000877
David Goodwinde11f362009-10-26 19:32:42 +0000878 // If the SUnit has other dependencies on the SUnit that
879 // it anti-depends on, don't bother breaking the
880 // anti-dependency since those edges would prevent such
881 // units from being scheduled past each other
882 // regardless.
David Goodwin80a03cc2009-11-20 19:32:48 +0000883 //
884 // Also, if there are dependencies on other SUnits with the
885 // same register as the anti-dependency, don't attempt to
886 // break it.
Dan Gohman35bc4d42010-04-19 23:11:58 +0000887 for (SUnit::const_pred_iterator P = PathSU->Preds.begin(),
David Goodwinde11f362009-10-26 19:32:42 +0000888 PE = PathSU->Preds.end(); P != PE; ++P) {
David Goodwin80a03cc2009-11-20 19:32:48 +0000889 if (P->getSUnit() == NextSU ?
890 (P->getKind() != SDep::Anti || P->getReg() != AntiDepReg) :
891 (P->getKind() == SDep::Data && P->getReg() == AntiDepReg)) {
892 AntiDepReg = 0;
893 break;
894 }
895 }
Dan Gohman35bc4d42010-04-19 23:11:58 +0000896 for (SUnit::const_pred_iterator P = PathSU->Preds.begin(),
David Goodwin80a03cc2009-11-20 19:32:48 +0000897 PE = PathSU->Preds.end(); P != PE; ++P) {
898 if ((P->getSUnit() == NextSU) && (P->getKind() != SDep::Anti) &&
899 (P->getKind() != SDep::Output)) {
David Greene75a2efb2009-12-24 00:14:25 +0000900 DEBUG(dbgs() << " (real dependency)\n");
David Goodwinde11f362009-10-26 19:32:42 +0000901 AntiDepReg = 0;
902 break;
Jim Grosbacheb431da2010-01-06 16:48:02 +0000903 } else if ((P->getSUnit() != NextSU) &&
904 (P->getKind() == SDep::Data) &&
David Goodwin80a03cc2009-11-20 19:32:48 +0000905 (P->getReg() == AntiDepReg)) {
David Greene75a2efb2009-12-24 00:14:25 +0000906 DEBUG(dbgs() << " (other dependency)\n");
David Goodwin80a03cc2009-11-20 19:32:48 +0000907 AntiDepReg = 0;
908 break;
David Goodwinde11f362009-10-26 19:32:42 +0000909 }
910 }
Jim Grosbacheb431da2010-01-06 16:48:02 +0000911
David Goodwinde11f362009-10-26 19:32:42 +0000912 if (AntiDepReg == 0) continue;
Krzysztof Parzyszek143f6842016-05-26 18:22:53 +0000913
914 // If the definition of the anti-dependency register does not start
915 // a new live range, bail out. This can happen if the anti-dep
916 // register is a sub-register of another register whose live range
917 // spans over PathSU. In such case, PathSU defines only a part of
918 // the larger register.
919 RegAliases.reset();
920 for (MCRegAliasIterator AI(AntiDepReg, TRI, true); AI.isValid(); ++AI)
921 RegAliases.set(*AI);
922 for (SDep S : PathSU->Succs) {
923 SDep::Kind K = S.getKind();
924 if (K != SDep::Data && K != SDep::Output && K != SDep::Anti)
925 continue;
926 unsigned R = S.getReg();
927 if (!RegAliases[R])
928 continue;
929 if (R == AntiDepReg || TRI->isSubRegister(AntiDepReg, R))
930 continue;
931 AntiDepReg = 0;
932 break;
933 }
934
935 if (AntiDepReg == 0) continue;
David Goodwinde11f362009-10-26 19:32:42 +0000936 }
Jim Grosbacheb431da2010-01-06 16:48:02 +0000937
David Goodwinde11f362009-10-26 19:32:42 +0000938 assert(AntiDepReg != 0);
939 if (AntiDepReg == 0) continue;
Jim Grosbacheb431da2010-01-06 16:48:02 +0000940
David Goodwinde11f362009-10-26 19:32:42 +0000941 // Determine AntiDepReg's register group.
David Goodwine056d102009-10-26 22:31:16 +0000942 const unsigned GroupIndex = State->GetGroup(AntiDepReg);
David Goodwinde11f362009-10-26 19:32:42 +0000943 if (GroupIndex == 0) {
David Greene75a2efb2009-12-24 00:14:25 +0000944 DEBUG(dbgs() << " (zero group)\n");
David Goodwinde11f362009-10-26 19:32:42 +0000945 continue;
946 }
Jim Grosbacheb431da2010-01-06 16:48:02 +0000947
David Greene75a2efb2009-12-24 00:14:25 +0000948 DEBUG(dbgs() << '\n');
Jim Grosbacheb431da2010-01-06 16:48:02 +0000949
David Goodwinde11f362009-10-26 19:32:42 +0000950 // Look for a suitable register to use to break the anti-dependence.
951 std::map<unsigned, unsigned> RenameMap;
David Goodwin7d8878a2009-11-05 01:19:35 +0000952 if (FindSuitableFreeRegisters(GroupIndex, RenameOrder, RenameMap)) {
David Greene75a2efb2009-12-24 00:14:25 +0000953 DEBUG(dbgs() << "\tBreaking anti-dependence edge on "
Francis Visoiu Mistrihc71cced2017-11-30 16:12:24 +0000954 << printReg(AntiDepReg, TRI) << ":");
Jim Grosbacheb431da2010-01-06 16:48:02 +0000955
David Goodwinde11f362009-10-26 19:32:42 +0000956 // Handle each group register...
957 for (std::map<unsigned, unsigned>::iterator
958 S = RenameMap.begin(), E = RenameMap.end(); S != E; ++S) {
959 unsigned CurrReg = S->first;
960 unsigned NewReg = S->second;
Jim Grosbacheb431da2010-01-06 16:48:02 +0000961
Francis Visoiu Mistrihc71cced2017-11-30 16:12:24 +0000962 DEBUG(dbgs() << " " << printReg(CurrReg, TRI) << "->"
963 << printReg(NewReg, TRI) << "("
964 << RegRefs.count(CurrReg) << " refs)");
Jim Grosbacheb431da2010-01-06 16:48:02 +0000965
David Goodwinde11f362009-10-26 19:32:42 +0000966 // Update the references to the old register CurrReg to
967 // refer to the new register NewReg.
Benjamin Kramerc9436ad2015-07-18 20:05:10 +0000968 for (const auto &Q : make_range(RegRefs.equal_range(CurrReg))) {
969 Q.second.Operand->setReg(NewReg);
Jim Grosbach12ac8f02010-06-01 23:48:44 +0000970 // If the SU for the instruction being updated has debug
971 // information related to the anti-dependency register, make
972 // sure to update that as well.
Benjamin Kramerc9436ad2015-07-18 20:05:10 +0000973 const SUnit *SU = MISUnitMap[Q.second.Operand->getParent()];
Jim Grosbach84854832010-06-02 15:29:36 +0000974 if (!SU) continue;
Andrew Ng10ebfe02017-04-25 15:39:57 +0000975 UpdateDbgValues(DbgValues, Q.second.Operand->getParent(),
976 AntiDepReg, NewReg);
David Goodwinde11f362009-10-26 19:32:42 +0000977 }
Jim Grosbacheb431da2010-01-06 16:48:02 +0000978
David Goodwinde11f362009-10-26 19:32:42 +0000979 // We just went back in time and modified history; the
980 // liveness information for CurrReg is now inconsistent. Set
981 // the state as if it were dead.
David Goodwine056d102009-10-26 22:31:16 +0000982 State->UnionGroups(NewReg, 0);
David Goodwinde11f362009-10-26 19:32:42 +0000983 RegRefs.erase(NewReg);
984 DefIndices[NewReg] = DefIndices[CurrReg];
985 KillIndices[NewReg] = KillIndices[CurrReg];
Jim Grosbacheb431da2010-01-06 16:48:02 +0000986
David Goodwine056d102009-10-26 22:31:16 +0000987 State->UnionGroups(CurrReg, 0);
David Goodwinde11f362009-10-26 19:32:42 +0000988 RegRefs.erase(CurrReg);
989 DefIndices[CurrReg] = KillIndices[CurrReg];
990 KillIndices[CurrReg] = ~0u;
991 assert(((KillIndices[CurrReg] == ~0u) !=
992 (DefIndices[CurrReg] == ~0u)) &&
993 "Kill and Def maps aren't consistent for AntiDepReg!");
994 }
Jim Grosbacheb431da2010-01-06 16:48:02 +0000995
David Goodwinde11f362009-10-26 19:32:42 +0000996 ++Broken;
David Greene75a2efb2009-12-24 00:14:25 +0000997 DEBUG(dbgs() << '\n');
David Goodwinde11f362009-10-26 19:32:42 +0000998 }
999 }
1000 }
1001
1002 ScanInstruction(MI, Count);
1003 }
Jim Grosbacheb431da2010-01-06 16:48:02 +00001004
David Goodwinde11f362009-10-26 19:32:42 +00001005 return Broken;
1006}