Eugene Zelenko | 4f81cdd | 2017-09-29 21:55:49 +0000 | [diff] [blame] | 1 | //===- AggressiveAntiDepBreaker.cpp - Anti-dep breaker --------------------===// |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // 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 Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 17 | #include "AggressiveAntiDepBreaker.h" |
Eugene Zelenko | 4f81cdd | 2017-09-29 21:55:49 +0000 | [diff] [blame] | 18 | #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 Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 22 | #include "llvm/CodeGen/MachineBasicBlock.h" |
| 23 | #include "llvm/CodeGen/MachineFrameInfo.h" |
Eugene Zelenko | 4f81cdd | 2017-09-29 21:55:49 +0000 | [diff] [blame] | 24 | #include "llvm/CodeGen/MachineFunction.h" |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 25 | #include "llvm/CodeGen/MachineInstr.h" |
Eugene Zelenko | 4f81cdd | 2017-09-29 21:55:49 +0000 | [diff] [blame] | 26 | #include "llvm/CodeGen/MachineOperand.h" |
| 27 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
| 28 | #include "llvm/CodeGen/MachineValueType.h" |
Andrew Trick | 05ff466 | 2012-06-06 20:29:31 +0000 | [diff] [blame] | 29 | #include "llvm/CodeGen/RegisterClassInfo.h" |
Eugene Zelenko | 4f81cdd | 2017-09-29 21:55:49 +0000 | [diff] [blame] | 30 | #include "llvm/CodeGen/ScheduleDAG.h" |
| 31 | #include "llvm/MC/MCInstrDesc.h" |
| 32 | #include "llvm/MC/MCRegisterInfo.h" |
David Goodwin | e056d10 | 2009-10-26 22:31:16 +0000 | [diff] [blame] | 33 | #include "llvm/Support/CommandLine.h" |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 34 | #include "llvm/Support/Debug.h" |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 35 | #include "llvm/Support/raw_ostream.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 36 | #include "llvm/Target/TargetInstrInfo.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 37 | #include "llvm/Target/TargetRegisterInfo.h" |
Eugene Zelenko | 4f81cdd | 2017-09-29 21:55:49 +0000 | [diff] [blame] | 38 | #include "llvm/Target/TargetSubtargetInfo.h" |
| 39 | #include <cassert> |
| 40 | #include <map> |
| 41 | #include <set> |
| 42 | #include <utility> |
| 43 | #include <vector> |
| 44 | |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 45 | using namespace llvm; |
| 46 | |
Chandler Carruth | 1b9dde0 | 2014-04-22 02:02:50 +0000 | [diff] [blame] | 47 | #define DEBUG_TYPE "post-RA-sched" |
| 48 | |
David Goodwin | dd1c619 | 2009-11-19 23:12:37 +0000 | [diff] [blame] | 49 | // If DebugDiv > 0 then only break antidep with (ID % DebugDiv) == DebugMod |
| 50 | static cl::opt<int> |
| 51 | DebugDiv("agg-antidep-debugdiv", |
Bob Wilson | 67dd3a4 | 2010-04-09 21:38:26 +0000 | [diff] [blame] | 52 | cl::desc("Debug control for aggressive anti-dep breaker"), |
| 53 | cl::init(0), cl::Hidden); |
Eugene Zelenko | 4f81cdd | 2017-09-29 21:55:49 +0000 | [diff] [blame] | 54 | |
David Goodwin | dd1c619 | 2009-11-19 23:12:37 +0000 | [diff] [blame] | 55 | static cl::opt<int> |
| 56 | DebugMod("agg-antidep-debugmod", |
Bob Wilson | 67dd3a4 | 2010-04-09 21:38:26 +0000 | [diff] [blame] | 57 | cl::desc("Debug control for aggressive anti-dep breaker"), |
| 58 | cl::init(0), cl::Hidden); |
David Goodwin | dd1c619 | 2009-11-19 23:12:37 +0000 | [diff] [blame] | 59 | |
David Goodwin | a45fe67 | 2009-12-09 17:18:22 +0000 | [diff] [blame] | 60 | AggressiveAntiDepState::AggressiveAntiDepState(const unsigned TargetRegs, |
Eugene Zelenko | 4f81cdd | 2017-09-29 21:55:49 +0000 | [diff] [blame] | 61 | MachineBasicBlock *BB) |
| 62 | : NumTargetRegs(TargetRegs), GroupNodes(TargetRegs, 0), |
| 63 | GroupNodeIndices(TargetRegs, 0), KillIndices(TargetRegs, 0), |
| 64 | DefIndices(TargetRegs, 0) { |
David Goodwin | a45fe67 | 2009-12-09 17:18:22 +0000 | [diff] [blame] | 65 | 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 Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Bill Wendling | 5a8d15c | 2010-07-15 19:41:20 +0000 | [diff] [blame] | 76 | unsigned AggressiveAntiDepState::GetGroup(unsigned Reg) { |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 77 | unsigned Node = GroupNodeIndices[Reg]; |
| 78 | while (GroupNodes[Node] != Node) |
| 79 | Node = GroupNodes[Node]; |
| 80 | |
| 81 | return Node; |
| 82 | } |
| 83 | |
David Goodwin | b9fe5d5 | 2009-11-13 19:52:48 +0000 | [diff] [blame] | 84 | void AggressiveAntiDepState::GetGroupRegs( |
| 85 | unsigned Group, |
| 86 | std::vector<unsigned> &Regs, |
| 87 | std::multimap<unsigned, AggressiveAntiDepState::RegisterReference> *RegRefs) |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 88 | { |
David Goodwin | a45fe67 | 2009-12-09 17:18:22 +0000 | [diff] [blame] | 89 | for (unsigned Reg = 0; Reg != NumTargetRegs; ++Reg) { |
David Goodwin | b9fe5d5 | 2009-11-13 19:52:48 +0000 | [diff] [blame] | 90 | if ((GetGroup(Reg) == Group) && (RegRefs->count(Reg) > 0)) |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 91 | Regs.push_back(Reg); |
| 92 | } |
| 93 | } |
| 94 | |
Eugene Zelenko | 4f81cdd | 2017-09-29 21:55:49 +0000 | [diff] [blame] | 95 | unsigned AggressiveAntiDepState::UnionGroups(unsigned Reg1, unsigned Reg2) { |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 96 | assert(GroupNodes[0] == 0 && "GroupNode 0 not parent!"); |
| 97 | assert(GroupNodeIndices[0] == 0 && "Reg 0 not in Group 0!"); |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 98 | |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 99 | // find group for each register |
| 100 | unsigned Group1 = GetGroup(Reg1); |
| 101 | unsigned Group2 = GetGroup(Reg2); |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 102 | |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 103 | // 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 Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 109 | |
Eugene Zelenko | 4f81cdd | 2017-09-29 21:55:49 +0000 | [diff] [blame] | 110 | unsigned AggressiveAntiDepState::LeaveGroup(unsigned Reg) { |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 111 | // 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 Zelenko | 4f81cdd | 2017-09-29 21:55:49 +0000 | [diff] [blame] | 120 | bool AggressiveAntiDepState::IsLive(unsigned Reg) { |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 121 | // 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 Christopher | d913448 | 2014-08-04 21:25:23 +0000 | [diff] [blame] | 126 | AggressiveAntiDepBreaker::AggressiveAntiDepBreaker( |
| 127 | MachineFunction &MFi, const RegisterClassInfo &RCI, |
| 128 | TargetSubtargetInfo::RegClassVector &CriticalPathRCs) |
| 129 | : AntiDepBreaker(), MF(MFi), MRI(MF.getRegInfo()), |
Eric Christopher | fc6de42 | 2014-08-05 02:39:49 +0000 | [diff] [blame] | 130 | TII(MF.getSubtarget().getInstrInfo()), |
Eugene Zelenko | 4f81cdd | 2017-09-29 21:55:49 +0000 | [diff] [blame] | 131 | TRI(MF.getSubtarget().getRegisterInfo()), RegClassInfo(RCI) { |
David Goodwin | b9fe5d5 | 2009-11-13 19:52:48 +0000 | [diff] [blame] | 132 | /* 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 Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 141 | |
David Greene | 75a2efb | 2009-12-24 00:14:25 +0000 | [diff] [blame] | 142 | DEBUG(dbgs() << "AntiDep Critical-Path Registers:"); |
Francis Visoiu Mistrih | b52e036 | 2017-05-17 01:07:53 +0000 | [diff] [blame] | 143 | DEBUG(for (unsigned r : CriticalPathSet.set_bits()) |
David Greene | 75a2efb | 2009-12-24 00:14:25 +0000 | [diff] [blame] | 144 | dbgs() << " " << TRI->getName(r)); |
| 145 | DEBUG(dbgs() << '\n'); |
David Goodwin | e056d10 | 2009-10-26 22:31:16 +0000 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | AggressiveAntiDepBreaker::~AggressiveAntiDepBreaker() { |
| 149 | delete State; |
David Goodwin | e056d10 | 2009-10-26 22:31:16 +0000 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | void AggressiveAntiDepBreaker::StartBlock(MachineBasicBlock *BB) { |
Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 153 | assert(!State); |
David Goodwin | a45fe67 | 2009-12-09 17:18:22 +0000 | [diff] [blame] | 154 | State = new AggressiveAntiDepState(TRI->getNumRegs(), BB); |
David Goodwin | e056d10 | 2009-10-26 22:31:16 +0000 | [diff] [blame] | 155 | |
Matthias Braun | c2d4bef | 2015-09-25 21:25:19 +0000 | [diff] [blame] | 156 | bool IsReturnBlock = BB->isReturnBlock(); |
Bill Wendling | 030b028 | 2010-07-15 18:43:09 +0000 | [diff] [blame] | 157 | std::vector<unsigned> &KillIndices = State->GetKillIndices(); |
| 158 | std::vector<unsigned> &DefIndices = State->GetDefIndices(); |
David Goodwin | e056d10 | 2009-10-26 22:31:16 +0000 | [diff] [blame] | 159 | |
Jakob Stoklund Olesen | c338679 | 2013-02-05 18:21:52 +0000 | [diff] [blame] | 160 | // Examine the live-in regs of all successors. |
Evan Cheng | f128bdc | 2010-06-16 07:35:02 +0000 | [diff] [blame] | 161 | for (MachineBasicBlock::succ_iterator SI = BB->succ_begin(), |
| 162 | SE = BB->succ_end(); SI != SE; ++SI) |
Matthias Braun | d9da162 | 2015-09-09 18:08:03 +0000 | [diff] [blame] | 163 | for (const auto &LI : (*SI)->liveins()) { |
| 164 | for (MCRegAliasIterator AI(LI.PhysReg, TRI, true); AI.isValid(); ++AI) { |
Jakob Stoklund Olesen | 54038d7 | 2012-06-01 23:28:30 +0000 | [diff] [blame] | 165 | unsigned Reg = *AI; |
Jakob Stoklund Olesen | be1c8d3 | 2010-12-14 23:23:15 +0000 | [diff] [blame] | 166 | State->UnionGroups(Reg, 0); |
| 167 | KillIndices[Reg] = BB->size(); |
| 168 | DefIndices[Reg] = ~0u; |
Evan Cheng | f128bdc | 2010-06-16 07:35:02 +0000 | [diff] [blame] | 169 | } |
| 170 | } |
| 171 | |
David Goodwin | e056d10 | 2009-10-26 22:31:16 +0000 | [diff] [blame] | 172 | // 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 Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 175 | const MachineFrameInfo &MFI = MF.getFrameInfo(); |
| 176 | BitVector Pristine = MFI.getPristineRegs(MF); |
Oren Ben Simhon | fe34c5e | 2017-03-14 09:09:26 +0000 | [diff] [blame] | 177 | for (const MCPhysReg *I = MF.getRegInfo().getCalleeSavedRegs(); *I; |
| 178 | ++I) { |
David Goodwin | e056d10 | 2009-10-26 22:31:16 +0000 | [diff] [blame] | 179 | unsigned Reg = *I; |
Tim Shen | 0bd0aa8 | 2017-05-30 22:26:52 +0000 | [diff] [blame] | 180 | if (!IsReturnBlock && !Pristine.test(Reg)) |
Eric Christopher | b9c56d1 | 2017-03-30 22:34:20 +0000 | [diff] [blame] | 181 | continue; |
Jakob Stoklund Olesen | 54038d7 | 2012-06-01 23:28:30 +0000 | [diff] [blame] | 182 | for (MCRegAliasIterator AI(Reg, TRI, true); AI.isValid(); ++AI) { |
| 183 | unsigned AliasReg = *AI; |
David Goodwin | e056d10 | 2009-10-26 22:31:16 +0000 | [diff] [blame] | 184 | State->UnionGroups(AliasReg, 0); |
| 185 | KillIndices[AliasReg] = BB->size(); |
| 186 | DefIndices[AliasReg] = ~0u; |
| 187 | } |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | void AggressiveAntiDepBreaker::FinishBlock() { |
| 192 | delete State; |
Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 193 | State = nullptr; |
David Goodwin | e056d10 | 2009-10-26 22:31:16 +0000 | [diff] [blame] | 194 | } |
| 195 | |
Duncan P. N. Exon Smith | 5e6e8c7 | 2016-02-27 19:33:37 +0000 | [diff] [blame] | 196 | void AggressiveAntiDepBreaker::Observe(MachineInstr &MI, unsigned Count, |
Bob Wilson | 67dd3a4 | 2010-04-09 21:38:26 +0000 | [diff] [blame] | 197 | unsigned InsertPosIndex) { |
David Goodwin | e056d10 | 2009-10-26 22:31:16 +0000 | [diff] [blame] | 198 | assert(Count < InsertPosIndex && "Instruction index out of expected range!"); |
| 199 | |
David Goodwin | faa7660 | 2009-10-29 23:30:59 +0000 | [diff] [blame] | 200 | std::set<unsigned> PassthruRegs; |
| 201 | GetPassthruRegs(MI, PassthruRegs); |
| 202 | PrescanInstruction(MI, Count, PassthruRegs); |
| 203 | ScanInstruction(MI, Count); |
| 204 | |
David Greene | 75a2efb | 2009-12-24 00:14:25 +0000 | [diff] [blame] | 205 | DEBUG(dbgs() << "Observe: "); |
Duncan P. N. Exon Smith | 5e6e8c7 | 2016-02-27 19:33:37 +0000 | [diff] [blame] | 206 | DEBUG(MI.dump()); |
David Greene | 75a2efb | 2009-12-24 00:14:25 +0000 | [diff] [blame] | 207 | DEBUG(dbgs() << "\tRegs:"); |
David Goodwin | e056d10 | 2009-10-26 22:31:16 +0000 | [diff] [blame] | 208 | |
Bill Wendling | 030b028 | 2010-07-15 18:43:09 +0000 | [diff] [blame] | 209 | std::vector<unsigned> &DefIndices = State->GetDefIndices(); |
David Goodwin | a45fe67 | 2009-12-09 17:18:22 +0000 | [diff] [blame] | 210 | for (unsigned Reg = 0; Reg != TRI->getNumRegs(); ++Reg) { |
David Goodwin | e056d10 | 2009-10-26 22:31:16 +0000 | [diff] [blame] | 211 | // 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) |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 219 | dbgs() << " " << TRI->getName(Reg) << "=g" << |
David Goodwin | e056d10 | 2009-10-26 22:31:16 +0000 | [diff] [blame] | 220 | State->GetGroup(Reg) << "->g0(region live-out)"); |
| 221 | State->UnionGroups(Reg, 0); |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 222 | } else if ((DefIndices[Reg] < InsertPosIndex) |
| 223 | && (DefIndices[Reg] >= Count)) { |
David Goodwin | e056d10 | 2009-10-26 22:31:16 +0000 | [diff] [blame] | 224 | DefIndices[Reg] = Count; |
| 225 | } |
| 226 | } |
David Greene | 75a2efb | 2009-12-24 00:14:25 +0000 | [diff] [blame] | 227 | DEBUG(dbgs() << '\n'); |
David Goodwin | e056d10 | 2009-10-26 22:31:16 +0000 | [diff] [blame] | 228 | } |
| 229 | |
Duncan P. N. Exon Smith | 5e6e8c7 | 2016-02-27 19:33:37 +0000 | [diff] [blame] | 230 | bool AggressiveAntiDepBreaker::IsImplicitDefUse(MachineInstr &MI, |
| 231 | MachineOperand &MO) { |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 232 | if (!MO.isReg() || !MO.isImplicit()) |
| 233 | return false; |
| 234 | |
| 235 | unsigned Reg = MO.getReg(); |
| 236 | if (Reg == 0) |
| 237 | return false; |
| 238 | |
Chad Rosier | 47eba05 | 2015-10-09 19:48:48 +0000 | [diff] [blame] | 239 | MachineOperand *Op = nullptr; |
| 240 | if (MO.isDef()) |
Duncan P. N. Exon Smith | 5e6e8c7 | 2016-02-27 19:33:37 +0000 | [diff] [blame] | 241 | Op = MI.findRegisterUseOperand(Reg, true); |
Chad Rosier | 47eba05 | 2015-10-09 19:48:48 +0000 | [diff] [blame] | 242 | else |
Duncan P. N. Exon Smith | 5e6e8c7 | 2016-02-27 19:33:37 +0000 | [diff] [blame] | 243 | Op = MI.findRegisterDefOperand(Reg); |
Chad Rosier | 47eba05 | 2015-10-09 19:48:48 +0000 | [diff] [blame] | 244 | |
Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 245 | return(Op && Op->isImplicit()); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 246 | } |
| 247 | |
Duncan P. N. Exon Smith | 5e6e8c7 | 2016-02-27 19:33:37 +0000 | [diff] [blame] | 248 | void 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 Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 252 | if (!MO.isReg()) continue; |
Duncan P. N. Exon Smith | 5e6e8c7 | 2016-02-27 19:33:37 +0000 | [diff] [blame] | 253 | if ((MO.isDef() && MI.isRegTiedToUseOperand(i)) || |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 254 | IsImplicitDefUse(MI, MO)) { |
| 255 | const unsigned Reg = MO.getReg(); |
Chad Rosier | abdb1d6 | 2013-05-22 23:17:36 +0000 | [diff] [blame] | 256 | for (MCSubRegIterator SubRegs(Reg, TRI, /*IncludeSelf=*/true); |
| 257 | SubRegs.isValid(); ++SubRegs) |
Jakob Stoklund Olesen | 54038d7 | 2012-06-01 23:28:30 +0000 | [diff] [blame] | 258 | PassthruRegs.insert(*SubRegs); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 259 | } |
| 260 | } |
| 261 | } |
| 262 | |
David Goodwin | 80a03cc | 2009-11-20 19:32:48 +0000 | [diff] [blame] | 263 | /// AntiDepEdges - Return in Edges the anti- and output- dependencies |
| 264 | /// in SU that we want to consider for breaking. |
Eugene Zelenko | 4f81cdd | 2017-09-29 21:55:49 +0000 | [diff] [blame] | 265 | static void AntiDepEdges(const SUnit *SU, std::vector<const SDep *> &Edges) { |
David Goodwin | 80a03cc | 2009-11-20 19:32:48 +0000 | [diff] [blame] | 266 | SmallSet<unsigned, 4> RegSet; |
Dan Gohman | 35bc4d4 | 2010-04-19 23:11:58 +0000 | [diff] [blame] | 267 | for (SUnit::const_pred_iterator P = SU->Preds.begin(), PE = SU->Preds.end(); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 268 | P != PE; ++P) { |
David Goodwin | da83f7d | 2009-11-12 19:08:21 +0000 | [diff] [blame] | 269 | if ((P->getKind() == SDep::Anti) || (P->getKind() == SDep::Output)) { |
David Blaikie | 70573dc | 2014-11-19 07:49:26 +0000 | [diff] [blame] | 270 | if (RegSet.insert(P->getReg()).second) |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 271 | Edges.push_back(&*P); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 272 | } |
| 273 | } |
| 274 | } |
| 275 | |
David Goodwin | b9fe5d5 | 2009-11-13 19:52:48 +0000 | [diff] [blame] | 276 | /// CriticalPathStep - Return the next SUnit after SU on the bottom-up |
| 277 | /// critical path. |
Dan Gohman | 35bc4d4 | 2010-04-19 23:11:58 +0000 | [diff] [blame] | 278 | static const SUnit *CriticalPathStep(const SUnit *SU) { |
Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 279 | const SDep *Next = nullptr; |
David Goodwin | b9fe5d5 | 2009-11-13 19:52:48 +0000 | [diff] [blame] | 280 | unsigned NextDepth = 0; |
| 281 | // Find the predecessor edge with the greatest depth. |
Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 282 | if (SU) { |
Dan Gohman | 35bc4d4 | 2010-04-19 23:11:58 +0000 | [diff] [blame] | 283 | for (SUnit::const_pred_iterator P = SU->Preds.begin(), PE = SU->Preds.end(); |
David Goodwin | b9fe5d5 | 2009-11-13 19:52:48 +0000 | [diff] [blame] | 284 | P != PE; ++P) { |
Dan Gohman | 35bc4d4 | 2010-04-19 23:11:58 +0000 | [diff] [blame] | 285 | const SUnit *PredSU = P->getSUnit(); |
David Goodwin | b9fe5d5 | 2009-11-13 19:52:48 +0000 | [diff] [blame] | 286 | 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 Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 298 | return (Next) ? Next->getSUnit() : nullptr; |
David Goodwin | b9fe5d5 | 2009-11-13 19:52:48 +0000 | [diff] [blame] | 299 | } |
| 300 | |
David Goodwin | 9f1b2d4 | 2009-10-29 19:17:04 +0000 | [diff] [blame] | 301 | void AggressiveAntiDepBreaker::HandleLastUse(unsigned Reg, unsigned KillIdx, |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 302 | const char *tag, |
| 303 | const char *header, |
David Goodwin | dd1c619 | 2009-11-19 23:12:37 +0000 | [diff] [blame] | 304 | const char *footer) { |
Bill Wendling | 030b028 | 2010-07-15 18:43:09 +0000 | [diff] [blame] | 305 | std::vector<unsigned> &KillIndices = State->GetKillIndices(); |
| 306 | std::vector<unsigned> &DefIndices = State->GetDefIndices(); |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 307 | std::multimap<unsigned, AggressiveAntiDepState::RegisterReference>& |
David Goodwin | 9f1b2d4 | 2009-10-29 19:17:04 +0000 | [diff] [blame] | 308 | RegRefs = State->GetRegRefs(); |
| 309 | |
Hal Finkel | 34c94d5 | 2015-01-28 14:44:14 +0000 | [diff] [blame] | 310 | // 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 Goodwin | 9f1b2d4 | 2009-10-29 19:17:04 +0000 | [diff] [blame] | 320 | if (!State->IsLive(Reg)) { |
| 321 | KillIndices[Reg] = KillIdx; |
| 322 | DefIndices[Reg] = ~0u; |
| 323 | RegRefs.erase(Reg); |
| 324 | State->LeaveGroup(Reg); |
Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 325 | DEBUG(if (header) { |
| 326 | dbgs() << header << TRI->getName(Reg); header = nullptr; }); |
David Greene | 75a2efb | 2009-12-24 00:14:25 +0000 | [diff] [blame] | 327 | DEBUG(dbgs() << "->g" << State->GetGroup(Reg) << tag); |
Chuang-Yu Cheng | 35c6181 | 2016-04-01 02:05:29 +0000 | [diff] [blame] | 328 | // 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) { |
| 340 | dbgs() << header << TRI->getName(Reg); header = nullptr; }); |
| 341 | DEBUG(dbgs() << " " << TRI->getName(SubregReg) << "->g" << |
| 342 | State->GetGroup(SubregReg) << tag); |
| 343 | } |
David Goodwin | 9f1b2d4 | 2009-10-29 19:17:04 +0000 | [diff] [blame] | 344 | } |
| 345 | } |
David Goodwin | dd1c619 | 2009-11-19 23:12:37 +0000 | [diff] [blame] | 346 | |
Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 347 | DEBUG(if (!header && footer) dbgs() << footer); |
David Goodwin | 9f1b2d4 | 2009-10-29 19:17:04 +0000 | [diff] [blame] | 348 | } |
| 349 | |
Duncan P. N. Exon Smith | 5e6e8c7 | 2016-02-27 19:33:37 +0000 | [diff] [blame] | 350 | void AggressiveAntiDepBreaker::PrescanInstruction( |
| 351 | MachineInstr &MI, unsigned Count, std::set<unsigned> &PassthruRegs) { |
Bill Wendling | 030b028 | 2010-07-15 18:43:09 +0000 | [diff] [blame] | 352 | std::vector<unsigned> &DefIndices = State->GetDefIndices(); |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 353 | std::multimap<unsigned, AggressiveAntiDepState::RegisterReference>& |
David Goodwin | e056d10 | 2009-10-26 22:31:16 +0000 | [diff] [blame] | 354 | RegRefs = State->GetRegRefs(); |
| 355 | |
David Goodwin | 9f1b2d4 | 2009-10-29 19:17:04 +0000 | [diff] [blame] | 356 | // Handle dead defs by simulating a last-use of the register just |
Chris Lattner | 0ab5e2c | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 357 | // after the def. A dead def can occur because the def is truly |
David Goodwin | 9f1b2d4 | 2009-10-29 19:17:04 +0000 | [diff] [blame] | 358 | // 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 Smith | 5e6e8c7 | 2016-02-27 19:33:37 +0000 | [diff] [blame] | 361 | for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) { |
| 362 | MachineOperand &MO = MI.getOperand(i); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 363 | if (!MO.isReg() || !MO.isDef()) continue; |
| 364 | unsigned Reg = MO.getReg(); |
| 365 | if (Reg == 0) continue; |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 366 | |
David Goodwin | dd1c619 | 2009-11-19 23:12:37 +0000 | [diff] [blame] | 367 | HandleLastUse(Reg, Count + 1, "", "\tDead Def: ", "\n"); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 368 | } |
| 369 | |
David Greene | 75a2efb | 2009-12-24 00:14:25 +0000 | [diff] [blame] | 370 | DEBUG(dbgs() << "\tDef Groups:"); |
Duncan P. N. Exon Smith | 5e6e8c7 | 2016-02-27 19:33:37 +0000 | [diff] [blame] | 371 | for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) { |
| 372 | MachineOperand &MO = MI.getOperand(i); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 373 | if (!MO.isReg() || !MO.isDef()) continue; |
| 374 | unsigned Reg = MO.getReg(); |
| 375 | if (Reg == 0) continue; |
| 376 | |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 377 | DEBUG(dbgs() << " " << TRI->getName(Reg) << "=g" << State->GetGroup(Reg)); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 378 | |
David Goodwin | 9f1b2d4 | 2009-10-29 19:17:04 +0000 | [diff] [blame] | 379 | // If MI's defs have a special allocation requirement, don't allow |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 380 | // any def registers to be changed. Also assume all registers |
Kyle Butt | cf6a8bf | 2015-12-02 18:58:51 +0000 | [diff] [blame] | 381 | // 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 Smith | 5e6e8c7 | 2016-02-27 19:33:37 +0000 | [diff] [blame] | 384 | if (MI.isCall() || MI.hasExtraDefRegAllocReq() || TII->isPredicated(MI) || |
| 385 | MI.isInlineAsm()) { |
David Greene | 75a2efb | 2009-12-24 00:14:25 +0000 | [diff] [blame] | 386 | DEBUG(if (State->GetGroup(Reg) != 0) dbgs() << "->g0(alloc-req)"); |
David Goodwin | e056d10 | 2009-10-26 22:31:16 +0000 | [diff] [blame] | 387 | State->UnionGroups(Reg, 0); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | // Any aliased that are live at this point are completely or |
David Goodwin | 9f1b2d4 | 2009-10-29 19:17:04 +0000 | [diff] [blame] | 391 | // partially defined here, so group those aliases with Reg. |
Jakob Stoklund Olesen | 54038d7 | 2012-06-01 23:28:30 +0000 | [diff] [blame] | 392 | for (MCRegAliasIterator AI(Reg, TRI, false); AI.isValid(); ++AI) { |
| 393 | unsigned AliasReg = *AI; |
David Goodwin | e056d10 | 2009-10-26 22:31:16 +0000 | [diff] [blame] | 394 | if (State->IsLive(AliasReg)) { |
| 395 | State->UnionGroups(Reg, AliasReg); |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 396 | DEBUG(dbgs() << "->g" << State->GetGroup(Reg) << "(via " << |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 397 | TRI->getName(AliasReg) << ")"); |
| 398 | } |
| 399 | } |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 400 | |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 401 | // Note register reference... |
Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 402 | const TargetRegisterClass *RC = nullptr; |
Duncan P. N. Exon Smith | 5e6e8c7 | 2016-02-27 19:33:37 +0000 | [diff] [blame] | 403 | if (i < MI.getDesc().getNumOperands()) |
| 404 | RC = TII->getRegClass(MI.getDesc(), i, TRI, MF); |
David Goodwin | e056d10 | 2009-10-26 22:31:16 +0000 | [diff] [blame] | 405 | AggressiveAntiDepState::RegisterReference RR = { &MO, RC }; |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 406 | RegRefs.insert(std::make_pair(Reg, RR)); |
| 407 | } |
| 408 | |
David Greene | 75a2efb | 2009-12-24 00:14:25 +0000 | [diff] [blame] | 409 | DEBUG(dbgs() << '\n'); |
David Goodwin | 9f1b2d4 | 2009-10-29 19:17:04 +0000 | [diff] [blame] | 410 | |
| 411 | // Scan the register defs for this instruction and update |
| 412 | // live-ranges. |
Duncan P. N. Exon Smith | 5e6e8c7 | 2016-02-27 19:33:37 +0000 | [diff] [blame] | 413 | for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) { |
| 414 | MachineOperand &MO = MI.getOperand(i); |
David Goodwin | 9f1b2d4 | 2009-10-29 19:17:04 +0000 | [diff] [blame] | 415 | if (!MO.isReg() || !MO.isDef()) continue; |
| 416 | unsigned Reg = MO.getReg(); |
| 417 | if (Reg == 0) continue; |
David Goodwin | dd1c619 | 2009-11-19 23:12:37 +0000 | [diff] [blame] | 418 | // Ignore KILLs and passthru registers for liveness... |
Duncan P. N. Exon Smith | 5e6e8c7 | 2016-02-27 19:33:37 +0000 | [diff] [blame] | 419 | if (MI.isKill() || (PassthruRegs.count(Reg) != 0)) |
David Goodwin | dd1c619 | 2009-11-19 23:12:37 +0000 | [diff] [blame] | 420 | continue; |
David Goodwin | 9f1b2d4 | 2009-10-29 19:17:04 +0000 | [diff] [blame] | 421 | |
David Goodwin | dd1c619 | 2009-11-19 23:12:37 +0000 | [diff] [blame] | 422 | // Update def for Reg and aliases. |
Hal Finkel | 121caf6 | 2014-02-26 20:20:30 +0000 | [diff] [blame] | 423 | 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 Olesen | 54038d7 | 2012-06-01 23:28:30 +0000 | [diff] [blame] | 433 | DefIndices[*AI] = Count; |
Hal Finkel | 121caf6 | 2014-02-26 20:20:30 +0000 | [diff] [blame] | 434 | } |
David Goodwin | 9f1b2d4 | 2009-10-29 19:17:04 +0000 | [diff] [blame] | 435 | } |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 436 | } |
| 437 | |
Duncan P. N. Exon Smith | 5e6e8c7 | 2016-02-27 19:33:37 +0000 | [diff] [blame] | 438 | void AggressiveAntiDepBreaker::ScanInstruction(MachineInstr &MI, |
Bob Wilson | 67dd3a4 | 2010-04-09 21:38:26 +0000 | [diff] [blame] | 439 | unsigned Count) { |
David Greene | 75a2efb | 2009-12-24 00:14:25 +0000 | [diff] [blame] | 440 | DEBUG(dbgs() << "\tUse Groups:"); |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 441 | std::multimap<unsigned, AggressiveAntiDepState::RegisterReference>& |
David Goodwin | e056d10 | 2009-10-26 22:31:16 +0000 | [diff] [blame] | 442 | RegRefs = State->GetRegRefs(); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 443 | |
Evan Cheng | f128bdc | 2010-06-16 07:35:02 +0000 | [diff] [blame] | 444 | // 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 Butt | cf6a8bf | 2015-12-02 18:58:51 +0000 | [diff] [blame] | 447 | // Inline Assembly register uses also cannot be safely changed. |
Evan Cheng | f128bdc | 2010-06-16 07:35:02 +0000 | [diff] [blame] | 448 | // 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: |
| 451 | // %R6<def> = LDR %SP, %reg0, 92, pred:14, pred:%reg0; mem:LD4[FixedStack14] |
| 452 | // ... |
| 453 | // STR %R0, %R6<kill>, %reg0, 0, pred:0, pred:%CPSR; mem:ST4[%395] |
| 454 | // %R6<def> = LDR %SP, %reg0, 100, pred:0, pred:%CPSR; mem:LD4[FixedStack12] |
| 455 | // STR %R0, %R6<kill>, %reg0, 0, pred:14, pred:%reg0; mem:ST4[%396](align=8) |
| 456 | // |
| 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 Smith | 5e6e8c7 | 2016-02-27 19:33:37 +0000 | [diff] [blame] | 461 | bool Special = MI.isCall() || MI.hasExtraSrcRegAllocReq() || |
| 462 | TII->isPredicated(MI) || MI.isInlineAsm(); |
Evan Cheng | f128bdc | 2010-06-16 07:35:02 +0000 | [diff] [blame] | 463 | |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 464 | // Scan the register uses for this instruction and update |
| 465 | // live-ranges, groups and RegRefs. |
Duncan P. N. Exon Smith | 5e6e8c7 | 2016-02-27 19:33:37 +0000 | [diff] [blame] | 466 | for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) { |
| 467 | MachineOperand &MO = MI.getOperand(i); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 468 | if (!MO.isReg() || !MO.isUse()) continue; |
| 469 | unsigned Reg = MO.getReg(); |
| 470 | if (Reg == 0) continue; |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 471 | |
| 472 | DEBUG(dbgs() << " " << TRI->getName(Reg) << "=g" << |
| 473 | State->GetGroup(Reg)); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 474 | |
| 475 | // It wasn't previously live but now it is, this is a kill. Forget |
| 476 | // the previous live-range information and start a new live-range |
| 477 | // for the register. |
David Goodwin | 9f1b2d4 | 2009-10-29 19:17:04 +0000 | [diff] [blame] | 478 | HandleLastUse(Reg, Count, "(last-use)"); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 479 | |
Evan Cheng | f128bdc | 2010-06-16 07:35:02 +0000 | [diff] [blame] | 480 | if (Special) { |
David Greene | 75a2efb | 2009-12-24 00:14:25 +0000 | [diff] [blame] | 481 | DEBUG(if (State->GetGroup(Reg) != 0) dbgs() << "->g0(alloc-req)"); |
David Goodwin | e056d10 | 2009-10-26 22:31:16 +0000 | [diff] [blame] | 482 | State->UnionGroups(Reg, 0); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | // Note register reference... |
Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 486 | const TargetRegisterClass *RC = nullptr; |
Duncan P. N. Exon Smith | 5e6e8c7 | 2016-02-27 19:33:37 +0000 | [diff] [blame] | 487 | if (i < MI.getDesc().getNumOperands()) |
| 488 | RC = TII->getRegClass(MI.getDesc(), i, TRI, MF); |
David Goodwin | e056d10 | 2009-10-26 22:31:16 +0000 | [diff] [blame] | 489 | AggressiveAntiDepState::RegisterReference RR = { &MO, RC }; |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 490 | RegRefs.insert(std::make_pair(Reg, RR)); |
| 491 | } |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 492 | |
David Greene | 75a2efb | 2009-12-24 00:14:25 +0000 | [diff] [blame] | 493 | DEBUG(dbgs() << '\n'); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 494 | |
| 495 | // Form a group of all defs and uses of a KILL instruction to ensure |
| 496 | // that all registers are renamed as a group. |
Duncan P. N. Exon Smith | 5e6e8c7 | 2016-02-27 19:33:37 +0000 | [diff] [blame] | 497 | if (MI.isKill()) { |
David Greene | 75a2efb | 2009-12-24 00:14:25 +0000 | [diff] [blame] | 498 | DEBUG(dbgs() << "\tKill Group:"); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 499 | |
| 500 | unsigned FirstReg = 0; |
Duncan P. N. Exon Smith | 5e6e8c7 | 2016-02-27 19:33:37 +0000 | [diff] [blame] | 501 | for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) { |
| 502 | MachineOperand &MO = MI.getOperand(i); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 503 | if (!MO.isReg()) continue; |
| 504 | unsigned Reg = MO.getReg(); |
| 505 | if (Reg == 0) continue; |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 506 | |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 507 | if (FirstReg != 0) { |
David Greene | 75a2efb | 2009-12-24 00:14:25 +0000 | [diff] [blame] | 508 | DEBUG(dbgs() << "=" << TRI->getName(Reg)); |
David Goodwin | e056d10 | 2009-10-26 22:31:16 +0000 | [diff] [blame] | 509 | State->UnionGroups(FirstReg, Reg); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 510 | } else { |
David Greene | 75a2efb | 2009-12-24 00:14:25 +0000 | [diff] [blame] | 511 | DEBUG(dbgs() << " " << TRI->getName(Reg)); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 512 | FirstReg = Reg; |
| 513 | } |
| 514 | } |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 515 | |
David Greene | 75a2efb | 2009-12-24 00:14:25 +0000 | [diff] [blame] | 516 | DEBUG(dbgs() << "->g" << State->GetGroup(FirstReg) << '\n'); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 517 | } |
| 518 | } |
| 519 | |
| 520 | BitVector AggressiveAntiDepBreaker::GetRenameRegisters(unsigned Reg) { |
| 521 | BitVector BV(TRI->getNumRegs(), false); |
| 522 | bool first = true; |
| 523 | |
| 524 | // Check all references that need rewriting for Reg. For each, use |
| 525 | // the corresponding register class to narrow the set of registers |
| 526 | // that are appropriate for renaming. |
Benjamin Kramer | c9436ad | 2015-07-18 20:05:10 +0000 | [diff] [blame] | 527 | for (const auto &Q : make_range(State->GetRegRefs().equal_range(Reg))) { |
| 528 | const TargetRegisterClass *RC = Q.second.RC; |
Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 529 | if (!RC) continue; |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 530 | |
| 531 | BitVector RCBV = TRI->getAllocatableSet(MF, RC); |
| 532 | if (first) { |
| 533 | BV |= RCBV; |
| 534 | first = false; |
| 535 | } else { |
| 536 | BV &= RCBV; |
| 537 | } |
| 538 | |
Craig Topper | cf0444b | 2014-11-17 05:50:14 +0000 | [diff] [blame] | 539 | DEBUG(dbgs() << " " << TRI->getRegClassName(RC)); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 540 | } |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 541 | |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 542 | return BV; |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 543 | } |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 544 | |
| 545 | bool AggressiveAntiDepBreaker::FindSuitableFreeRegisters( |
David Goodwin | 7d8878a | 2009-11-05 01:19:35 +0000 | [diff] [blame] | 546 | unsigned AntiDepGroupIndex, |
| 547 | RenameOrderType& RenameOrder, |
| 548 | std::map<unsigned, unsigned> &RenameMap) { |
Bill Wendling | 030b028 | 2010-07-15 18:43:09 +0000 | [diff] [blame] | 549 | std::vector<unsigned> &KillIndices = State->GetKillIndices(); |
| 550 | std::vector<unsigned> &DefIndices = State->GetDefIndices(); |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 551 | std::multimap<unsigned, AggressiveAntiDepState::RegisterReference>& |
David Goodwin | e056d10 | 2009-10-26 22:31:16 +0000 | [diff] [blame] | 552 | RegRefs = State->GetRegRefs(); |
| 553 | |
David Goodwin | b9fe5d5 | 2009-11-13 19:52:48 +0000 | [diff] [blame] | 554 | // Collect all referenced registers in the same group as |
| 555 | // AntiDepReg. These all need to be renamed together if we are to |
| 556 | // break the anti-dependence. |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 557 | std::vector<unsigned> Regs; |
David Goodwin | b9fe5d5 | 2009-11-13 19:52:48 +0000 | [diff] [blame] | 558 | State->GetGroupRegs(AntiDepGroupIndex, Regs, &RegRefs); |
Eugene Zelenko | 4f81cdd | 2017-09-29 21:55:49 +0000 | [diff] [blame] | 559 | assert(!Regs.empty() && "Empty register group!"); |
| 560 | if (Regs.empty()) |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 561 | return false; |
| 562 | |
| 563 | // Find the "superest" register in the group. At the same time, |
| 564 | // collect the BitVector of registers that can be used to rename |
| 565 | // each register. |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 566 | DEBUG(dbgs() << "\tRename Candidates for Group g" << AntiDepGroupIndex |
| 567 | << ":\n"); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 568 | std::map<unsigned, BitVector> RenameRegisterMap; |
| 569 | unsigned SuperReg = 0; |
| 570 | for (unsigned i = 0, e = Regs.size(); i != e; ++i) { |
| 571 | unsigned Reg = Regs[i]; |
| 572 | if ((SuperReg == 0) || TRI->isSuperRegister(SuperReg, Reg)) |
| 573 | SuperReg = Reg; |
| 574 | |
| 575 | // If Reg has any references, then collect possible rename regs |
| 576 | if (RegRefs.count(Reg) > 0) { |
David Greene | 75a2efb | 2009-12-24 00:14:25 +0000 | [diff] [blame] | 577 | DEBUG(dbgs() << "\t\t" << TRI->getName(Reg) << ":"); |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 578 | |
Benjamin Kramer | 7f75e94 | 2016-02-13 16:39:39 +0000 | [diff] [blame] | 579 | BitVector &BV = RenameRegisterMap[Reg]; |
| 580 | assert(BV.empty()); |
| 581 | BV = GetRenameRegisters(Reg); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 582 | |
Benjamin Kramer | 7f75e94 | 2016-02-13 16:39:39 +0000 | [diff] [blame] | 583 | DEBUG({ |
| 584 | dbgs() << " ::"; |
Francis Visoiu Mistrih | b52e036 | 2017-05-17 01:07:53 +0000 | [diff] [blame] | 585 | for (unsigned r : BV.set_bits()) |
Benjamin Kramer | 7f75e94 | 2016-02-13 16:39:39 +0000 | [diff] [blame] | 586 | dbgs() << " " << TRI->getName(r); |
| 587 | dbgs() << "\n"; |
| 588 | }); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 589 | } |
| 590 | } |
| 591 | |
| 592 | // All group registers should be a subreg of SuperReg. |
| 593 | for (unsigned i = 0, e = Regs.size(); i != e; ++i) { |
| 594 | unsigned Reg = Regs[i]; |
| 595 | if (Reg == SuperReg) continue; |
| 596 | bool IsSub = TRI->isSubRegister(SuperReg, Reg); |
Will Schmidt | 44ff8f0 | 2014-07-31 19:50:53 +0000 | [diff] [blame] | 597 | // FIXME: remove this once PR18663 has been properly fixed. For now, |
| 598 | // return a conservative answer: |
| 599 | // assert(IsSub && "Expecting group subregister"); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 600 | if (!IsSub) |
| 601 | return false; |
| 602 | } |
| 603 | |
David Goodwin | 5305dc0 | 2009-11-20 23:33:54 +0000 | [diff] [blame] | 604 | #ifndef NDEBUG |
| 605 | // If DebugDiv > 0 then only rename (renamecnt % DebugDiv) == DebugMod |
| 606 | if (DebugDiv > 0) { |
| 607 | static int renamecnt = 0; |
| 608 | if (renamecnt++ % DebugDiv != DebugMod) |
| 609 | return false; |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 610 | |
David Greene | 75a2efb | 2009-12-24 00:14:25 +0000 | [diff] [blame] | 611 | dbgs() << "*** Performing rename " << TRI->getName(SuperReg) << |
David Goodwin | 5305dc0 | 2009-11-20 23:33:54 +0000 | [diff] [blame] | 612 | " for debug ***\n"; |
| 613 | } |
| 614 | #endif |
| 615 | |
David Goodwin | 7d8878a | 2009-11-05 01:19:35 +0000 | [diff] [blame] | 616 | // Check each possible rename register for SuperReg in round-robin |
| 617 | // order. If that register is available, and the corresponding |
| 618 | // registers are available for the other group subregisters, then we |
| 619 | // can use those registers to rename. |
Rafael Espindola | 871c724 | 2010-07-12 02:55:34 +0000 | [diff] [blame] | 620 | |
| 621 | // FIXME: Using getMinimalPhysRegClass is very conservative. We should |
| 622 | // check every use of the register and find the largest register class |
| 623 | // that can be used in all of them. |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 624 | const TargetRegisterClass *SuperRC = |
Rafael Espindola | 871c724 | 2010-07-12 02:55:34 +0000 | [diff] [blame] | 625 | TRI->getMinimalPhysRegClass(SuperReg, MVT::Other); |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 626 | |
Jakob Stoklund Olesen | bdb55e0 | 2012-11-29 03:34:17 +0000 | [diff] [blame] | 627 | ArrayRef<MCPhysReg> Order = RegClassInfo.getOrder(SuperRC); |
Jakob Stoklund Olesen | 4f5f84c | 2011-06-16 21:56:21 +0000 | [diff] [blame] | 628 | if (Order.empty()) { |
David Greene | 75a2efb | 2009-12-24 00:14:25 +0000 | [diff] [blame] | 629 | DEBUG(dbgs() << "\tEmpty Super Regclass!!\n"); |
David Goodwin | 7d8878a | 2009-11-05 01:19:35 +0000 | [diff] [blame] | 630 | return false; |
| 631 | } |
| 632 | |
David Greene | 75a2efb | 2009-12-24 00:14:25 +0000 | [diff] [blame] | 633 | DEBUG(dbgs() << "\tFind Registers:"); |
David Goodwin | dd1c619 | 2009-11-19 23:12:37 +0000 | [diff] [blame] | 634 | |
Benjamin Kramer | 2c99e41 | 2014-10-10 15:32:50 +0000 | [diff] [blame] | 635 | RenameOrder.insert(RenameOrderType::value_type(SuperRC, Order.size())); |
David Goodwin | 7d8878a | 2009-11-05 01:19:35 +0000 | [diff] [blame] | 636 | |
Jakob Stoklund Olesen | 4f5f84c | 2011-06-16 21:56:21 +0000 | [diff] [blame] | 637 | unsigned OrigR = RenameOrder[SuperRC]; |
| 638 | unsigned EndR = ((OrigR == Order.size()) ? 0 : OrigR); |
| 639 | unsigned R = OrigR; |
David Goodwin | 7d8878a | 2009-11-05 01:19:35 +0000 | [diff] [blame] | 640 | do { |
Jakob Stoklund Olesen | 4f5f84c | 2011-06-16 21:56:21 +0000 | [diff] [blame] | 641 | if (R == 0) R = Order.size(); |
David Goodwin | 7d8878a | 2009-11-05 01:19:35 +0000 | [diff] [blame] | 642 | --R; |
Jakob Stoklund Olesen | 4f5f84c | 2011-06-16 21:56:21 +0000 | [diff] [blame] | 643 | const unsigned NewSuperReg = Order[R]; |
Jim Grosbach | 944aece | 2010-09-02 17:12:55 +0000 | [diff] [blame] | 644 | // Don't consider non-allocatable registers |
Jakob Stoklund Olesen | f67bf3e | 2012-10-15 22:41:03 +0000 | [diff] [blame] | 645 | if (!MRI.isAllocatable(NewSuperReg)) continue; |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 646 | // Don't replace a register with itself. |
David Goodwin | 5305dc0 | 2009-11-20 23:33:54 +0000 | [diff] [blame] | 647 | if (NewSuperReg == SuperReg) continue; |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 648 | |
David Greene | 75a2efb | 2009-12-24 00:14:25 +0000 | [diff] [blame] | 649 | DEBUG(dbgs() << " [" << TRI->getName(NewSuperReg) << ':'); |
David Goodwin | 5305dc0 | 2009-11-20 23:33:54 +0000 | [diff] [blame] | 650 | RenameMap.clear(); |
| 651 | |
| 652 | // For each referenced group register (which must be a SuperReg or |
| 653 | // a subregister of SuperReg), find the corresponding subregister |
| 654 | // of NewSuperReg and make sure it is free to be renamed. |
| 655 | for (unsigned i = 0, e = Regs.size(); i != e; ++i) { |
| 656 | unsigned Reg = Regs[i]; |
| 657 | unsigned NewReg = 0; |
| 658 | if (Reg == SuperReg) { |
| 659 | NewReg = NewSuperReg; |
| 660 | } else { |
| 661 | unsigned NewSubRegIdx = TRI->getSubRegIndex(SuperReg, Reg); |
| 662 | if (NewSubRegIdx != 0) |
| 663 | NewReg = TRI->getSubReg(NewSuperReg, NewSubRegIdx); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 664 | } |
David Goodwin | 5305dc0 | 2009-11-20 23:33:54 +0000 | [diff] [blame] | 665 | |
David Greene | 75a2efb | 2009-12-24 00:14:25 +0000 | [diff] [blame] | 666 | DEBUG(dbgs() << " " << TRI->getName(NewReg)); |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 667 | |
David Goodwin | 5305dc0 | 2009-11-20 23:33:54 +0000 | [diff] [blame] | 668 | // Check if Reg can be renamed to NewReg. |
Benjamin Kramer | 7f75e94 | 2016-02-13 16:39:39 +0000 | [diff] [blame] | 669 | if (!RenameRegisterMap[Reg].test(NewReg)) { |
David Greene | 75a2efb | 2009-12-24 00:14:25 +0000 | [diff] [blame] | 670 | DEBUG(dbgs() << "(no rename)"); |
David Goodwin | 5305dc0 | 2009-11-20 23:33:54 +0000 | [diff] [blame] | 671 | goto next_super_reg; |
| 672 | } |
| 673 | |
| 674 | // If NewReg is dead and NewReg's most recent def is not before |
| 675 | // Regs's kill, it's safe to replace Reg with NewReg. We |
| 676 | // must also check all aliases of NewReg, because we can't define a |
| 677 | // register when any sub or super is already live. |
| 678 | if (State->IsLive(NewReg) || (KillIndices[Reg] > DefIndices[NewReg])) { |
David Greene | 75a2efb | 2009-12-24 00:14:25 +0000 | [diff] [blame] | 679 | DEBUG(dbgs() << "(live)"); |
David Goodwin | 5305dc0 | 2009-11-20 23:33:54 +0000 | [diff] [blame] | 680 | goto next_super_reg; |
| 681 | } else { |
| 682 | bool found = false; |
Jakob Stoklund Olesen | 54038d7 | 2012-06-01 23:28:30 +0000 | [diff] [blame] | 683 | for (MCRegAliasIterator AI(NewReg, TRI, false); AI.isValid(); ++AI) { |
| 684 | unsigned AliasReg = *AI; |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 685 | if (State->IsLive(AliasReg) || |
| 686 | (KillIndices[Reg] > DefIndices[AliasReg])) { |
David Greene | 75a2efb | 2009-12-24 00:14:25 +0000 | [diff] [blame] | 687 | DEBUG(dbgs() << "(alias " << TRI->getName(AliasReg) << " live)"); |
David Goodwin | 5305dc0 | 2009-11-20 23:33:54 +0000 | [diff] [blame] | 688 | found = true; |
| 689 | break; |
| 690 | } |
| 691 | } |
| 692 | if (found) |
| 693 | goto next_super_reg; |
| 694 | } |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 695 | |
Hal Finkel | c8cf2b8 | 2014-12-09 01:00:59 +0000 | [diff] [blame] | 696 | // We cannot rename 'Reg' to 'NewReg' if one of the uses of 'Reg' also |
| 697 | // defines 'NewReg' via an early-clobber operand. |
Benjamin Kramer | c9436ad | 2015-07-18 20:05:10 +0000 | [diff] [blame] | 698 | for (const auto &Q : make_range(RegRefs.equal_range(Reg))) { |
| 699 | MachineInstr *UseMI = Q.second.Operand->getParent(); |
Hal Finkel | c8cf2b8 | 2014-12-09 01:00:59 +0000 | [diff] [blame] | 700 | int Idx = UseMI->findRegisterDefOperandIdx(NewReg, false, true, TRI); |
| 701 | if (Idx == -1) |
| 702 | continue; |
| 703 | |
| 704 | if (UseMI->getOperand(Idx).isEarlyClobber()) { |
| 705 | DEBUG(dbgs() << "(ec)"); |
| 706 | goto next_super_reg; |
| 707 | } |
| 708 | } |
| 709 | |
Hal Finkel | e0a28e5 | 2015-08-31 07:51:36 +0000 | [diff] [blame] | 710 | // Also, we cannot rename 'Reg' to 'NewReg' if the instruction defining |
| 711 | // 'Reg' is an early-clobber define and that instruction also uses |
| 712 | // 'NewReg'. |
| 713 | for (const auto &Q : make_range(RegRefs.equal_range(Reg))) { |
| 714 | if (!Q.second.Operand->isDef() || !Q.second.Operand->isEarlyClobber()) |
| 715 | continue; |
| 716 | |
| 717 | MachineInstr *DefMI = Q.second.Operand->getParent(); |
| 718 | if (DefMI->readsRegister(NewReg, TRI)) { |
| 719 | DEBUG(dbgs() << "(ec)"); |
| 720 | goto next_super_reg; |
| 721 | } |
| 722 | } |
| 723 | |
David Goodwin | 5305dc0 | 2009-11-20 23:33:54 +0000 | [diff] [blame] | 724 | // Record that 'Reg' can be renamed to 'NewReg'. |
| 725 | RenameMap.insert(std::pair<unsigned, unsigned>(Reg, NewReg)); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 726 | } |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 727 | |
David Goodwin | 5305dc0 | 2009-11-20 23:33:54 +0000 | [diff] [blame] | 728 | // If we fall-out here, then every register in the group can be |
| 729 | // renamed, as recorded in RenameMap. |
| 730 | RenameOrder.erase(SuperRC); |
| 731 | RenameOrder.insert(RenameOrderType::value_type(SuperRC, R)); |
David Greene | 75a2efb | 2009-12-24 00:14:25 +0000 | [diff] [blame] | 732 | DEBUG(dbgs() << "]\n"); |
David Goodwin | 5305dc0 | 2009-11-20 23:33:54 +0000 | [diff] [blame] | 733 | return true; |
| 734 | |
| 735 | next_super_reg: |
David Greene | 75a2efb | 2009-12-24 00:14:25 +0000 | [diff] [blame] | 736 | DEBUG(dbgs() << ']'); |
David Goodwin | 7d8878a | 2009-11-05 01:19:35 +0000 | [diff] [blame] | 737 | } while (R != EndR); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 738 | |
David Greene | 75a2efb | 2009-12-24 00:14:25 +0000 | [diff] [blame] | 739 | DEBUG(dbgs() << '\n'); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 740 | |
| 741 | // No registers are free and available! |
| 742 | return false; |
| 743 | } |
| 744 | |
| 745 | /// BreakAntiDependencies - Identifiy anti-dependencies within the |
| 746 | /// ScheduleDAG and break them by renaming registers. |
David Goodwin | e056d10 | 2009-10-26 22:31:16 +0000 | [diff] [blame] | 747 | unsigned AggressiveAntiDepBreaker::BreakAntiDependencies( |
Eugene Zelenko | 4f81cdd | 2017-09-29 21:55:49 +0000 | [diff] [blame] | 748 | const std::vector<SUnit> &SUnits, |
Dan Gohman | 35bc4d4 | 2010-04-19 23:11:58 +0000 | [diff] [blame] | 749 | MachineBasicBlock::iterator Begin, |
| 750 | MachineBasicBlock::iterator End, |
Devang Patel | f02a376 | 2011-06-02 21:26:52 +0000 | [diff] [blame] | 751 | unsigned InsertPosIndex, |
| 752 | DbgValueVector &DbgValues) { |
Bill Wendling | 030b028 | 2010-07-15 18:43:09 +0000 | [diff] [blame] | 753 | std::vector<unsigned> &KillIndices = State->GetKillIndices(); |
| 754 | std::vector<unsigned> &DefIndices = State->GetDefIndices(); |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 755 | std::multimap<unsigned, AggressiveAntiDepState::RegisterReference>& |
David Goodwin | e056d10 | 2009-10-26 22:31:16 +0000 | [diff] [blame] | 756 | RegRefs = State->GetRegRefs(); |
| 757 | |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 758 | // The code below assumes that there is at least one instruction, |
| 759 | // so just duck out immediately if the block is empty. |
David Goodwin | 8501dbbe | 2009-11-03 20:57:50 +0000 | [diff] [blame] | 760 | if (SUnits.empty()) return 0; |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 761 | |
David Goodwin | 7d8878a | 2009-11-05 01:19:35 +0000 | [diff] [blame] | 762 | // For each regclass the next register to use for renaming. |
| 763 | RenameOrderType RenameOrder; |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 764 | |
| 765 | // ...need a map from MI to SUnit. |
Dan Gohman | 35bc4d4 | 2010-04-19 23:11:58 +0000 | [diff] [blame] | 766 | std::map<MachineInstr *, const SUnit *> MISUnitMap; |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 767 | for (unsigned i = 0, e = SUnits.size(); i != e; ++i) { |
Dan Gohman | 35bc4d4 | 2010-04-19 23:11:58 +0000 | [diff] [blame] | 768 | const SUnit *SU = &SUnits[i]; |
| 769 | MISUnitMap.insert(std::pair<MachineInstr *, const SUnit *>(SU->getInstr(), |
| 770 | SU)); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 771 | } |
| 772 | |
David Goodwin | b9fe5d5 | 2009-11-13 19:52:48 +0000 | [diff] [blame] | 773 | // Track progress along the critical path through the SUnit graph as |
| 774 | // we walk the instructions. This is needed for regclasses that only |
| 775 | // break critical-path anti-dependencies. |
Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 776 | const SUnit *CriticalPathSU = nullptr; |
| 777 | MachineInstr *CriticalPathMI = nullptr; |
David Goodwin | b9fe5d5 | 2009-11-13 19:52:48 +0000 | [diff] [blame] | 778 | if (CriticalPathSet.any()) { |
| 779 | for (unsigned i = 0, e = SUnits.size(); i != e; ++i) { |
Dan Gohman | 35bc4d4 | 2010-04-19 23:11:58 +0000 | [diff] [blame] | 780 | const SUnit *SU = &SUnits[i]; |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 781 | if (!CriticalPathSU || |
| 782 | ((SU->getDepth() + SU->Latency) > |
David Goodwin | b9fe5d5 | 2009-11-13 19:52:48 +0000 | [diff] [blame] | 783 | (CriticalPathSU->getDepth() + CriticalPathSU->Latency))) { |
| 784 | CriticalPathSU = SU; |
| 785 | } |
| 786 | } |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 787 | |
David Goodwin | b9fe5d5 | 2009-11-13 19:52:48 +0000 | [diff] [blame] | 788 | CriticalPathMI = CriticalPathSU->getInstr(); |
| 789 | } |
| 790 | |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 791 | #ifndef NDEBUG |
David Greene | 75a2efb | 2009-12-24 00:14:25 +0000 | [diff] [blame] | 792 | DEBUG(dbgs() << "\n===== Aggressive anti-dependency breaking\n"); |
| 793 | DEBUG(dbgs() << "Available regs:"); |
David Goodwin | 80a03cc | 2009-11-20 19:32:48 +0000 | [diff] [blame] | 794 | for (unsigned Reg = 0; Reg < TRI->getNumRegs(); ++Reg) { |
| 795 | if (!State->IsLive(Reg)) |
David Greene | 75a2efb | 2009-12-24 00:14:25 +0000 | [diff] [blame] | 796 | DEBUG(dbgs() << " " << TRI->getName(Reg)); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 797 | } |
David Greene | 75a2efb | 2009-12-24 00:14:25 +0000 | [diff] [blame] | 798 | DEBUG(dbgs() << '\n'); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 799 | #endif |
| 800 | |
Krzysztof Parzyszek | 143f684 | 2016-05-26 18:22:53 +0000 | [diff] [blame] | 801 | BitVector RegAliases(TRI->getNumRegs()); |
| 802 | |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 803 | // Attempt to break anti-dependence edges. Walk the instructions |
| 804 | // from the bottom up, tracking information about liveness as we go |
| 805 | // to help determine which registers are available. |
| 806 | unsigned Broken = 0; |
| 807 | unsigned Count = InsertPosIndex - 1; |
| 808 | for (MachineBasicBlock::iterator I = End, E = Begin; |
| 809 | I != E; --Count) { |
Duncan P. N. Exon Smith | 5e6e8c7 | 2016-02-27 19:33:37 +0000 | [diff] [blame] | 810 | MachineInstr &MI = *--I; |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 811 | |
Duncan P. N. Exon Smith | 5e6e8c7 | 2016-02-27 19:33:37 +0000 | [diff] [blame] | 812 | if (MI.isDebugValue()) |
Hal Finkel | 8606e3c | 2012-01-16 22:53:41 +0000 | [diff] [blame] | 813 | continue; |
| 814 | |
David Greene | 75a2efb | 2009-12-24 00:14:25 +0000 | [diff] [blame] | 815 | DEBUG(dbgs() << "Anti: "); |
Duncan P. N. Exon Smith | 5e6e8c7 | 2016-02-27 19:33:37 +0000 | [diff] [blame] | 816 | DEBUG(MI.dump()); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 817 | |
| 818 | std::set<unsigned> PassthruRegs; |
| 819 | GetPassthruRegs(MI, PassthruRegs); |
| 820 | |
| 821 | // Process the defs in MI... |
| 822 | PrescanInstruction(MI, Count, PassthruRegs); |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 823 | |
David Goodwin | 80a03cc | 2009-11-20 19:32:48 +0000 | [diff] [blame] | 824 | // The dependence edges that represent anti- and output- |
David Goodwin | b9fe5d5 | 2009-11-13 19:52:48 +0000 | [diff] [blame] | 825 | // dependencies that are candidates for breaking. |
Dan Gohman | 35bc4d4 | 2010-04-19 23:11:58 +0000 | [diff] [blame] | 826 | std::vector<const SDep *> Edges; |
Duncan P. N. Exon Smith | 5e6e8c7 | 2016-02-27 19:33:37 +0000 | [diff] [blame] | 827 | const SUnit *PathSU = MISUnitMap[&MI]; |
David Goodwin | 80a03cc | 2009-11-20 19:32:48 +0000 | [diff] [blame] | 828 | AntiDepEdges(PathSU, Edges); |
David Goodwin | b9fe5d5 | 2009-11-13 19:52:48 +0000 | [diff] [blame] | 829 | |
| 830 | // If MI is not on the critical path, then we don't rename |
| 831 | // registers in the CriticalPathSet. |
Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 832 | BitVector *ExcludeRegs = nullptr; |
Duncan P. N. Exon Smith | 5e6e8c7 | 2016-02-27 19:33:37 +0000 | [diff] [blame] | 833 | if (&MI == CriticalPathMI) { |
David Goodwin | b9fe5d5 | 2009-11-13 19:52:48 +0000 | [diff] [blame] | 834 | CriticalPathSU = CriticalPathStep(CriticalPathSU); |
Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 835 | CriticalPathMI = (CriticalPathSU) ? CriticalPathSU->getInstr() : nullptr; |
Hal Finkel | 6f1ff8e | 2013-09-12 04:22:31 +0000 | [diff] [blame] | 836 | } else if (CriticalPathSet.any()) { |
David Goodwin | b9fe5d5 | 2009-11-13 19:52:48 +0000 | [diff] [blame] | 837 | ExcludeRegs = &CriticalPathSet; |
| 838 | } |
| 839 | |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 840 | // Ignore KILL instructions (they form a group in ScanInstruction |
| 841 | // but don't cause any anti-dependence breaking themselves) |
Duncan P. N. Exon Smith | 5e6e8c7 | 2016-02-27 19:33:37 +0000 | [diff] [blame] | 842 | if (!MI.isKill()) { |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 843 | // Attempt to break each anti-dependency... |
| 844 | for (unsigned i = 0, e = Edges.size(); i != e; ++i) { |
Dan Gohman | 35bc4d4 | 2010-04-19 23:11:58 +0000 | [diff] [blame] | 845 | const SDep *Edge = Edges[i]; |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 846 | SUnit *NextSU = Edge->getSUnit(); |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 847 | |
David Goodwin | da83f7d | 2009-11-12 19:08:21 +0000 | [diff] [blame] | 848 | if ((Edge->getKind() != SDep::Anti) && |
| 849 | (Edge->getKind() != SDep::Output)) continue; |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 850 | |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 851 | unsigned AntiDepReg = Edge->getReg(); |
David Greene | 75a2efb | 2009-12-24 00:14:25 +0000 | [diff] [blame] | 852 | DEBUG(dbgs() << "\tAntidep reg: " << TRI->getName(AntiDepReg)); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 853 | assert(AntiDepReg != 0 && "Anti-dependence on reg0?"); |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 854 | |
Jakob Stoklund Olesen | f67bf3e | 2012-10-15 22:41:03 +0000 | [diff] [blame] | 855 | if (!MRI.isAllocatable(AntiDepReg)) { |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 856 | // Don't break anti-dependencies on non-allocatable registers. |
David Greene | 75a2efb | 2009-12-24 00:14:25 +0000 | [diff] [blame] | 857 | DEBUG(dbgs() << " (non-allocatable)\n"); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 858 | continue; |
Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 859 | } else if (ExcludeRegs && ExcludeRegs->test(AntiDepReg)) { |
David Goodwin | b9fe5d5 | 2009-11-13 19:52:48 +0000 | [diff] [blame] | 860 | // Don't break anti-dependencies for critical path registers |
| 861 | // if not on the critical path |
David Greene | 75a2efb | 2009-12-24 00:14:25 +0000 | [diff] [blame] | 862 | DEBUG(dbgs() << " (not critical-path)\n"); |
David Goodwin | b9fe5d5 | 2009-11-13 19:52:48 +0000 | [diff] [blame] | 863 | continue; |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 864 | } else if (PassthruRegs.count(AntiDepReg) != 0) { |
| 865 | // If the anti-dep register liveness "passes-thru", then |
| 866 | // don't try to change it. It will be changed along with |
| 867 | // the use if required to break an earlier antidep. |
David Greene | 75a2efb | 2009-12-24 00:14:25 +0000 | [diff] [blame] | 868 | DEBUG(dbgs() << " (passthru)\n"); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 869 | continue; |
| 870 | } else { |
| 871 | // No anti-dep breaking for implicit deps |
Duncan P. N. Exon Smith | 5e6e8c7 | 2016-02-27 19:33:37 +0000 | [diff] [blame] | 872 | MachineOperand *AntiDepOp = MI.findRegisterDefOperand(AntiDepReg); |
Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 873 | assert(AntiDepOp && "Can't find index for defined register operand"); |
| 874 | if (!AntiDepOp || AntiDepOp->isImplicit()) { |
David Greene | 75a2efb | 2009-12-24 00:14:25 +0000 | [diff] [blame] | 875 | DEBUG(dbgs() << " (implicit)\n"); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 876 | continue; |
| 877 | } |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 878 | |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 879 | // If the SUnit has other dependencies on the SUnit that |
| 880 | // it anti-depends on, don't bother breaking the |
| 881 | // anti-dependency since those edges would prevent such |
| 882 | // units from being scheduled past each other |
| 883 | // regardless. |
David Goodwin | 80a03cc | 2009-11-20 19:32:48 +0000 | [diff] [blame] | 884 | // |
| 885 | // Also, if there are dependencies on other SUnits with the |
| 886 | // same register as the anti-dependency, don't attempt to |
| 887 | // break it. |
Dan Gohman | 35bc4d4 | 2010-04-19 23:11:58 +0000 | [diff] [blame] | 888 | for (SUnit::const_pred_iterator P = PathSU->Preds.begin(), |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 889 | PE = PathSU->Preds.end(); P != PE; ++P) { |
David Goodwin | 80a03cc | 2009-11-20 19:32:48 +0000 | [diff] [blame] | 890 | if (P->getSUnit() == NextSU ? |
| 891 | (P->getKind() != SDep::Anti || P->getReg() != AntiDepReg) : |
| 892 | (P->getKind() == SDep::Data && P->getReg() == AntiDepReg)) { |
| 893 | AntiDepReg = 0; |
| 894 | break; |
| 895 | } |
| 896 | } |
Dan Gohman | 35bc4d4 | 2010-04-19 23:11:58 +0000 | [diff] [blame] | 897 | for (SUnit::const_pred_iterator P = PathSU->Preds.begin(), |
David Goodwin | 80a03cc | 2009-11-20 19:32:48 +0000 | [diff] [blame] | 898 | PE = PathSU->Preds.end(); P != PE; ++P) { |
| 899 | if ((P->getSUnit() == NextSU) && (P->getKind() != SDep::Anti) && |
| 900 | (P->getKind() != SDep::Output)) { |
David Greene | 75a2efb | 2009-12-24 00:14:25 +0000 | [diff] [blame] | 901 | DEBUG(dbgs() << " (real dependency)\n"); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 902 | AntiDepReg = 0; |
| 903 | break; |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 904 | } else if ((P->getSUnit() != NextSU) && |
| 905 | (P->getKind() == SDep::Data) && |
David Goodwin | 80a03cc | 2009-11-20 19:32:48 +0000 | [diff] [blame] | 906 | (P->getReg() == AntiDepReg)) { |
David Greene | 75a2efb | 2009-12-24 00:14:25 +0000 | [diff] [blame] | 907 | DEBUG(dbgs() << " (other dependency)\n"); |
David Goodwin | 80a03cc | 2009-11-20 19:32:48 +0000 | [diff] [blame] | 908 | AntiDepReg = 0; |
| 909 | break; |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 910 | } |
| 911 | } |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 912 | |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 913 | if (AntiDepReg == 0) continue; |
Krzysztof Parzyszek | 143f684 | 2016-05-26 18:22:53 +0000 | [diff] [blame] | 914 | |
| 915 | // If the definition of the anti-dependency register does not start |
| 916 | // a new live range, bail out. This can happen if the anti-dep |
| 917 | // register is a sub-register of another register whose live range |
| 918 | // spans over PathSU. In such case, PathSU defines only a part of |
| 919 | // the larger register. |
| 920 | RegAliases.reset(); |
| 921 | for (MCRegAliasIterator AI(AntiDepReg, TRI, true); AI.isValid(); ++AI) |
| 922 | RegAliases.set(*AI); |
| 923 | for (SDep S : PathSU->Succs) { |
| 924 | SDep::Kind K = S.getKind(); |
| 925 | if (K != SDep::Data && K != SDep::Output && K != SDep::Anti) |
| 926 | continue; |
| 927 | unsigned R = S.getReg(); |
| 928 | if (!RegAliases[R]) |
| 929 | continue; |
| 930 | if (R == AntiDepReg || TRI->isSubRegister(AntiDepReg, R)) |
| 931 | continue; |
| 932 | AntiDepReg = 0; |
| 933 | break; |
| 934 | } |
| 935 | |
| 936 | if (AntiDepReg == 0) continue; |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 937 | } |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 938 | |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 939 | assert(AntiDepReg != 0); |
| 940 | if (AntiDepReg == 0) continue; |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 941 | |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 942 | // Determine AntiDepReg's register group. |
David Goodwin | e056d10 | 2009-10-26 22:31:16 +0000 | [diff] [blame] | 943 | const unsigned GroupIndex = State->GetGroup(AntiDepReg); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 944 | if (GroupIndex == 0) { |
David Greene | 75a2efb | 2009-12-24 00:14:25 +0000 | [diff] [blame] | 945 | DEBUG(dbgs() << " (zero group)\n"); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 946 | continue; |
| 947 | } |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 948 | |
David Greene | 75a2efb | 2009-12-24 00:14:25 +0000 | [diff] [blame] | 949 | DEBUG(dbgs() << '\n'); |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 950 | |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 951 | // Look for a suitable register to use to break the anti-dependence. |
| 952 | std::map<unsigned, unsigned> RenameMap; |
David Goodwin | 7d8878a | 2009-11-05 01:19:35 +0000 | [diff] [blame] | 953 | if (FindSuitableFreeRegisters(GroupIndex, RenameOrder, RenameMap)) { |
David Greene | 75a2efb | 2009-12-24 00:14:25 +0000 | [diff] [blame] | 954 | DEBUG(dbgs() << "\tBreaking anti-dependence edge on " |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 955 | << TRI->getName(AntiDepReg) << ":"); |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 956 | |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 957 | // Handle each group register... |
| 958 | for (std::map<unsigned, unsigned>::iterator |
| 959 | S = RenameMap.begin(), E = RenameMap.end(); S != E; ++S) { |
| 960 | unsigned CurrReg = S->first; |
| 961 | unsigned NewReg = S->second; |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 962 | |
| 963 | DEBUG(dbgs() << " " << TRI->getName(CurrReg) << "->" << |
| 964 | TRI->getName(NewReg) << "(" << |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 965 | RegRefs.count(CurrReg) << " refs)"); |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 966 | |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 967 | // Update the references to the old register CurrReg to |
| 968 | // refer to the new register NewReg. |
Benjamin Kramer | c9436ad | 2015-07-18 20:05:10 +0000 | [diff] [blame] | 969 | for (const auto &Q : make_range(RegRefs.equal_range(CurrReg))) { |
| 970 | Q.second.Operand->setReg(NewReg); |
Jim Grosbach | 12ac8f0 | 2010-06-01 23:48:44 +0000 | [diff] [blame] | 971 | // If the SU for the instruction being updated has debug |
| 972 | // information related to the anti-dependency register, make |
| 973 | // sure to update that as well. |
Benjamin Kramer | c9436ad | 2015-07-18 20:05:10 +0000 | [diff] [blame] | 974 | const SUnit *SU = MISUnitMap[Q.second.Operand->getParent()]; |
Jim Grosbach | 8485483 | 2010-06-02 15:29:36 +0000 | [diff] [blame] | 975 | if (!SU) continue; |
Andrew Ng | 10ebfe0 | 2017-04-25 15:39:57 +0000 | [diff] [blame] | 976 | UpdateDbgValues(DbgValues, Q.second.Operand->getParent(), |
| 977 | AntiDepReg, NewReg); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 978 | } |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 979 | |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 980 | // We just went back in time and modified history; the |
| 981 | // liveness information for CurrReg is now inconsistent. Set |
| 982 | // the state as if it were dead. |
David Goodwin | e056d10 | 2009-10-26 22:31:16 +0000 | [diff] [blame] | 983 | State->UnionGroups(NewReg, 0); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 984 | RegRefs.erase(NewReg); |
| 985 | DefIndices[NewReg] = DefIndices[CurrReg]; |
| 986 | KillIndices[NewReg] = KillIndices[CurrReg]; |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 987 | |
David Goodwin | e056d10 | 2009-10-26 22:31:16 +0000 | [diff] [blame] | 988 | State->UnionGroups(CurrReg, 0); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 989 | RegRefs.erase(CurrReg); |
| 990 | DefIndices[CurrReg] = KillIndices[CurrReg]; |
| 991 | KillIndices[CurrReg] = ~0u; |
| 992 | assert(((KillIndices[CurrReg] == ~0u) != |
| 993 | (DefIndices[CurrReg] == ~0u)) && |
| 994 | "Kill and Def maps aren't consistent for AntiDepReg!"); |
| 995 | } |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 996 | |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 997 | ++Broken; |
David Greene | 75a2efb | 2009-12-24 00:14:25 +0000 | [diff] [blame] | 998 | DEBUG(dbgs() << '\n'); |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 999 | } |
| 1000 | } |
| 1001 | } |
| 1002 | |
| 1003 | ScanInstruction(MI, Count); |
| 1004 | } |
Jim Grosbach | eb431da | 2010-01-06 16:48:02 +0000 | [diff] [blame] | 1005 | |
David Goodwin | de11f36 | 2009-10-26 19:32:42 +0000 | [diff] [blame] | 1006 | return Broken; |
| 1007 | } |