Marina Yatsina | be6cfa9 | 2018-01-22 10:06:50 +0000 | [diff] [blame] | 1 | //===- ExecutionDomainFix.cpp - Fix execution domain issues ----*- C++ -*--===// |
Jakob Stoklund Olesen | 352aa50 | 2010-03-25 17:25:00 +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 | //===----------------------------------------------------------------------===// |
Jakob Stoklund Olesen | 352aa50 | 2010-03-25 17:25:00 +0000 | [diff] [blame] | 9 | |
Marina Yatsina | d6bf9cd | 2018-01-22 10:06:33 +0000 | [diff] [blame] | 10 | #include "llvm/CodeGen/ExecutionDomainFix.h" |
Jakob Stoklund Olesen | 352aa50 | 2010-03-25 17:25:00 +0000 | [diff] [blame] | 11 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
David Blaikie | 4831923 | 2017-11-08 01:01:31 +0000 | [diff] [blame] | 12 | #include "llvm/CodeGen/TargetInstrInfo.h" |
Eric Christopher | 9f85dcc | 2014-08-04 21:25:23 +0000 | [diff] [blame] | 13 | |
Jakob Stoklund Olesen | 352aa50 | 2010-03-25 17:25:00 +0000 | [diff] [blame] | 14 | using namespace llvm; |
| 15 | |
Matthias Braun | 76900dd | 2017-03-18 05:05:40 +0000 | [diff] [blame] | 16 | #define DEBUG_TYPE "execution-deps-fix" |
Chandler Carruth | 8677f2f | 2014-04-22 02:02:50 +0000 | [diff] [blame] | 17 | |
Matthias Braun | cd56c19 | 2014-12-17 19:13:47 +0000 | [diff] [blame] | 18 | iterator_range<SmallVectorImpl<int>::const_iterator> |
Marina Yatsina | ef27918 | 2018-01-22 10:05:23 +0000 | [diff] [blame] | 19 | ExecutionDomainFix::regIndices(unsigned Reg) const { |
Jakob Stoklund Olesen | df4b35e | 2011-09-27 23:50:46 +0000 | [diff] [blame] | 20 | assert(Reg < AliasMap.size() && "Invalid register"); |
Matthias Braun | cd56c19 | 2014-12-17 19:13:47 +0000 | [diff] [blame] | 21 | const auto &Entry = AliasMap[Reg]; |
| 22 | return make_range(Entry.begin(), Entry.end()); |
Jakob Stoklund Olesen | e4b94b4 | 2010-03-29 23:24:21 +0000 | [diff] [blame] | 23 | } |
| 24 | |
Marina Yatsina | ef27918 | 2018-01-22 10:05:23 +0000 | [diff] [blame] | 25 | DomainValue *ExecutionDomainFix::alloc(int domain) { |
Marina Yatsina | 95ade18 | 2018-01-22 10:06:18 +0000 | [diff] [blame] | 26 | DomainValue *dv = Avail.empty() ? new (Allocator.Allocate()) DomainValue |
| 27 | : Avail.pop_back_val(); |
Jakob Stoklund Olesen | bbef815 | 2010-04-04 18:00:21 +0000 | [diff] [blame] | 28 | if (domain >= 0) |
Jakob Stoklund Olesen | e0103f0 | 2010-04-04 21:27:26 +0000 | [diff] [blame] | 29 | dv->addDomain(domain); |
Jakob Stoklund Olesen | 737e9a2 | 2011-11-08 23:26:00 +0000 | [diff] [blame] | 30 | assert(dv->Refs == 0 && "Reference count wasn't cleared"); |
Jakob Stoklund Olesen | dbc372f | 2011-11-09 00:06:18 +0000 | [diff] [blame] | 31 | assert(!dv->Next && "Chained DomainValue shouldn't have been recycled"); |
Jakob Stoklund Olesen | bbef815 | 2010-04-04 18:00:21 +0000 | [diff] [blame] | 32 | return dv; |
| 33 | } |
| 34 | |
Marina Yatsina | ef27918 | 2018-01-22 10:05:23 +0000 | [diff] [blame] | 35 | void ExecutionDomainFix::release(DomainValue *DV) { |
Jakob Stoklund Olesen | dbc372f | 2011-11-09 00:06:18 +0000 | [diff] [blame] | 36 | while (DV) { |
| 37 | assert(DV->Refs && "Bad DomainValue"); |
| 38 | if (--DV->Refs) |
| 39 | return; |
Jakob Stoklund Olesen | 35e9324 | 2011-11-08 21:57:44 +0000 | [diff] [blame] | 40 | |
Jakob Stoklund Olesen | dbc372f | 2011-11-09 00:06:18 +0000 | [diff] [blame] | 41 | // There are no more DV references. Collapse any contained instructions. |
| 42 | if (DV->AvailableDomains && !DV->isCollapsed()) |
| 43 | collapse(DV, DV->getFirstDomain()); |
Jakob Stoklund Olesen | 35e9324 | 2011-11-08 21:57:44 +0000 | [diff] [blame] | 44 | |
Jakob Stoklund Olesen | dbc372f | 2011-11-09 00:06:18 +0000 | [diff] [blame] | 45 | DomainValue *Next = DV->Next; |
| 46 | DV->clear(); |
| 47 | Avail.push_back(DV); |
| 48 | // Also release the next DomainValue in the chain. |
| 49 | DV = Next; |
| 50 | } |
| 51 | } |
| 52 | |
Marina Yatsina | ef27918 | 2018-01-22 10:05:23 +0000 | [diff] [blame] | 53 | DomainValue *ExecutionDomainFix::resolve(DomainValue *&DVRef) { |
Jakob Stoklund Olesen | dbc372f | 2011-11-09 00:06:18 +0000 | [diff] [blame] | 54 | DomainValue *DV = DVRef; |
| 55 | if (!DV || !DV->Next) |
| 56 | return DV; |
| 57 | |
| 58 | // DV has a chain. Find the end. |
Marina Yatsina | 95ade18 | 2018-01-22 10:06:18 +0000 | [diff] [blame] | 59 | do |
| 60 | DV = DV->Next; |
Jakob Stoklund Olesen | dbc372f | 2011-11-09 00:06:18 +0000 | [diff] [blame] | 61 | while (DV->Next); |
| 62 | |
| 63 | // Update DVRef to point to DV. |
| 64 | retain(DV); |
| 65 | release(DVRef); |
| 66 | DVRef = DV; |
| 67 | return DV; |
Jakob Stoklund Olesen | bbef815 | 2010-04-04 18:00:21 +0000 | [diff] [blame] | 68 | } |
| 69 | |
Marina Yatsina | ef27918 | 2018-01-22 10:05:23 +0000 | [diff] [blame] | 70 | void ExecutionDomainFix::setLiveReg(int rx, DomainValue *dv) { |
Jakob Stoklund Olesen | 1a5d2a8 | 2010-03-30 20:04:01 +0000 | [diff] [blame] | 71 | assert(unsigned(rx) < NumRegs && "Invalid index"); |
Marina Yatsina | 982e880 | 2018-01-22 10:05:53 +0000 | [diff] [blame] | 72 | assert(!LiveRegs.empty() && "Must enter basic block first."); |
Jakob Stoklund Olesen | 1a5d2a8 | 2010-03-30 20:04:01 +0000 | [diff] [blame] | 73 | |
Marina Yatsina | 8957ed6 | 2018-01-22 10:06:01 +0000 | [diff] [blame] | 74 | if (LiveRegs[rx] == dv) |
Jakob Stoklund Olesen | e4b94b4 | 2010-03-29 23:24:21 +0000 | [diff] [blame] | 75 | return; |
Marina Yatsina | 8957ed6 | 2018-01-22 10:06:01 +0000 | [diff] [blame] | 76 | if (LiveRegs[rx]) |
| 77 | release(LiveRegs[rx]); |
| 78 | LiveRegs[rx] = retain(dv); |
Jakob Stoklund Olesen | e4b94b4 | 2010-03-29 23:24:21 +0000 | [diff] [blame] | 79 | } |
| 80 | |
Marina Yatsina | ef27918 | 2018-01-22 10:05:23 +0000 | [diff] [blame] | 81 | void ExecutionDomainFix::kill(int rx) { |
Jakob Stoklund Olesen | 1a5d2a8 | 2010-03-30 20:04:01 +0000 | [diff] [blame] | 82 | assert(unsigned(rx) < NumRegs && "Invalid index"); |
Marina Yatsina | 982e880 | 2018-01-22 10:05:53 +0000 | [diff] [blame] | 83 | assert(!LiveRegs.empty() && "Must enter basic block first."); |
Marina Yatsina | 8957ed6 | 2018-01-22 10:06:01 +0000 | [diff] [blame] | 84 | if (!LiveRegs[rx]) |
Jakob Stoklund Olesen | 2947f73 | 2011-11-15 01:15:25 +0000 | [diff] [blame] | 85 | return; |
Jakob Stoklund Olesen | e4b94b4 | 2010-03-29 23:24:21 +0000 | [diff] [blame] | 86 | |
Marina Yatsina | 8957ed6 | 2018-01-22 10:06:01 +0000 | [diff] [blame] | 87 | release(LiveRegs[rx]); |
| 88 | LiveRegs[rx] = nullptr; |
Jakob Stoklund Olesen | e4b94b4 | 2010-03-29 23:24:21 +0000 | [diff] [blame] | 89 | } |
| 90 | |
Marina Yatsina | ef27918 | 2018-01-22 10:05:23 +0000 | [diff] [blame] | 91 | void ExecutionDomainFix::force(int rx, unsigned domain) { |
Jakob Stoklund Olesen | 1a5d2a8 | 2010-03-30 20:04:01 +0000 | [diff] [blame] | 92 | assert(unsigned(rx) < NumRegs && "Invalid index"); |
Marina Yatsina | 982e880 | 2018-01-22 10:05:53 +0000 | [diff] [blame] | 93 | assert(!LiveRegs.empty() && "Must enter basic block first."); |
Marina Yatsina | 8957ed6 | 2018-01-22 10:06:01 +0000 | [diff] [blame] | 94 | if (DomainValue *dv = LiveRegs[rx]) { |
Jakob Stoklund Olesen | e0103f0 | 2010-04-04 21:27:26 +0000 | [diff] [blame] | 95 | if (dv->isCollapsed()) |
| 96 | dv->addDomain(domain); |
Jakob Stoklund Olesen | 8ba1c6a | 2010-04-06 19:48:56 +0000 | [diff] [blame] | 97 | else if (dv->hasDomain(domain)) |
Jakob Stoklund Olesen | 6bcb9a7 | 2011-11-08 21:57:47 +0000 | [diff] [blame] | 98 | collapse(dv, domain); |
Jakob Stoklund Olesen | 8ba1c6a | 2010-04-06 19:48:56 +0000 | [diff] [blame] | 99 | else { |
Jakob Stoklund Olesen | 56ab875 | 2011-09-28 00:01:56 +0000 | [diff] [blame] | 100 | // This is an incompatible open DomainValue. Collapse it to whatever and |
| 101 | // force the new value into domain. This costs a domain crossing. |
Jakob Stoklund Olesen | 6bcb9a7 | 2011-11-08 21:57:47 +0000 | [diff] [blame] | 102 | collapse(dv, dv->getFirstDomain()); |
Marina Yatsina | 8957ed6 | 2018-01-22 10:06:01 +0000 | [diff] [blame] | 103 | assert(LiveRegs[rx] && "Not live after collapse?"); |
| 104 | LiveRegs[rx]->addDomain(domain); |
Jakob Stoklund Olesen | 8ba1c6a | 2010-04-06 19:48:56 +0000 | [diff] [blame] | 105 | } |
Jakob Stoklund Olesen | e4b94b4 | 2010-03-29 23:24:21 +0000 | [diff] [blame] | 106 | } else { |
Jakob Stoklund Olesen | 1a5d2a8 | 2010-03-30 20:04:01 +0000 | [diff] [blame] | 107 | // Set up basic collapsed DomainValue. |
Jakob Stoklund Olesen | 6bcb9a7 | 2011-11-08 21:57:47 +0000 | [diff] [blame] | 108 | setLiveReg(rx, alloc(domain)); |
Jakob Stoklund Olesen | e4b94b4 | 2010-03-29 23:24:21 +0000 | [diff] [blame] | 109 | } |
| 110 | } |
| 111 | |
Marina Yatsina | ef27918 | 2018-01-22 10:05:23 +0000 | [diff] [blame] | 112 | void ExecutionDomainFix::collapse(DomainValue *dv, unsigned domain) { |
Jakob Stoklund Olesen | e0103f0 | 2010-04-04 21:27:26 +0000 | [diff] [blame] | 113 | assert(dv->hasDomain(domain) && "Cannot collapse"); |
Jakob Stoklund Olesen | e4b94b4 | 2010-03-29 23:24:21 +0000 | [diff] [blame] | 114 | |
| 115 | // Collapse all the instructions. |
Jakob Stoklund Olesen | e0103f0 | 2010-04-04 21:27:26 +0000 | [diff] [blame] | 116 | while (!dv->Instrs.empty()) |
Duncan P. N. Exon Smith | 567409d | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 117 | TII->setExecutionDomain(*dv->Instrs.pop_back_val(), domain); |
Jakob Stoklund Olesen | e0103f0 | 2010-04-04 21:27:26 +0000 | [diff] [blame] | 118 | dv->setSingleDomain(domain); |
Jakob Stoklund Olesen | e4b94b4 | 2010-03-29 23:24:21 +0000 | [diff] [blame] | 119 | |
| 120 | // If there are multiple users, give them new, unique DomainValues. |
Marina Yatsina | 982e880 | 2018-01-22 10:05:53 +0000 | [diff] [blame] | 121 | if (!LiveRegs.empty() && dv->Refs > 1) |
Jakob Stoklund Olesen | 1a5d2a8 | 2010-03-30 20:04:01 +0000 | [diff] [blame] | 122 | for (unsigned rx = 0; rx != NumRegs; ++rx) |
Marina Yatsina | 8957ed6 | 2018-01-22 10:06:01 +0000 | [diff] [blame] | 123 | if (LiveRegs[rx] == dv) |
Jakob Stoklund Olesen | 6bcb9a7 | 2011-11-08 21:57:47 +0000 | [diff] [blame] | 124 | setLiveReg(rx, alloc(domain)); |
Jakob Stoklund Olesen | e4b94b4 | 2010-03-29 23:24:21 +0000 | [diff] [blame] | 125 | } |
| 126 | |
Marina Yatsina | ef27918 | 2018-01-22 10:05:23 +0000 | [diff] [blame] | 127 | bool ExecutionDomainFix::merge(DomainValue *A, DomainValue *B) { |
Jakob Stoklund Olesen | e0103f0 | 2010-04-04 21:27:26 +0000 | [diff] [blame] | 128 | assert(!A->isCollapsed() && "Cannot merge into collapsed"); |
| 129 | assert(!B->isCollapsed() && "Cannot merge from collapsed"); |
Jakob Stoklund Olesen | 85ffee2 | 2010-03-31 20:05:12 +0000 | [diff] [blame] | 130 | if (A == B) |
Jakob Stoklund Olesen | 5f282b5 | 2010-03-31 17:13:16 +0000 | [diff] [blame] | 131 | return true; |
Jakob Stoklund Olesen | e0103f0 | 2010-04-04 21:27:26 +0000 | [diff] [blame] | 132 | // Restrict to the domains that A and B have in common. |
| 133 | unsigned common = A->getCommonDomains(B->AvailableDomains); |
| 134 | if (!common) |
Jakob Stoklund Olesen | e4b94b4 | 2010-03-29 23:24:21 +0000 | [diff] [blame] | 135 | return false; |
Jakob Stoklund Olesen | e0103f0 | 2010-04-04 21:27:26 +0000 | [diff] [blame] | 136 | A->AvailableDomains = common; |
Jakob Stoklund Olesen | e4b94b4 | 2010-03-29 23:24:21 +0000 | [diff] [blame] | 137 | A->Instrs.append(B->Instrs.begin(), B->Instrs.end()); |
Jakob Stoklund Olesen | e1b3e11 | 2011-11-08 20:57:04 +0000 | [diff] [blame] | 138 | |
| 139 | // Clear the old DomainValue so we won't try to swizzle instructions twice. |
Jakob Stoklund Olesen | 737e9a2 | 2011-11-08 23:26:00 +0000 | [diff] [blame] | 140 | B->clear(); |
Jakob Stoklund Olesen | dbc372f | 2011-11-09 00:06:18 +0000 | [diff] [blame] | 141 | // All uses of B are referred to A. |
| 142 | B->Next = retain(A); |
Jakob Stoklund Olesen | e1b3e11 | 2011-11-08 20:57:04 +0000 | [diff] [blame] | 143 | |
Michael Ilseman | 9ecdca9 | 2014-12-15 18:48:43 +0000 | [diff] [blame] | 144 | for (unsigned rx = 0; rx != NumRegs; ++rx) { |
Marina Yatsina | 982e880 | 2018-01-22 10:05:53 +0000 | [diff] [blame] | 145 | assert(!LiveRegs.empty() && "no space allocated for live registers"); |
Marina Yatsina | 8957ed6 | 2018-01-22 10:06:01 +0000 | [diff] [blame] | 146 | if (LiveRegs[rx] == B) |
Jakob Stoklund Olesen | 6bcb9a7 | 2011-11-08 21:57:47 +0000 | [diff] [blame] | 147 | setLiveReg(rx, A); |
Michael Ilseman | 9ecdca9 | 2014-12-15 18:48:43 +0000 | [diff] [blame] | 148 | } |
Jakob Stoklund Olesen | e4b94b4 | 2010-03-29 23:24:21 +0000 | [diff] [blame] | 149 | return true; |
| 150 | } |
| 151 | |
Marina Yatsina | ef27918 | 2018-01-22 10:05:23 +0000 | [diff] [blame] | 152 | void ExecutionDomainFix::enterBasicBlock( |
| 153 | const LoopTraversal::TraversedMBBInfo &TraversedMBB) { |
| 154 | |
| 155 | MachineBasicBlock *MBB = TraversedMBB.MBB; |
| 156 | |
| 157 | // Set up LiveRegs to represent registers entering MBB. |
Marina Yatsina | 8957ed6 | 2018-01-22 10:06:01 +0000 | [diff] [blame] | 158 | // Set default domain values to 'no domain' (nullptr) |
Marina Yatsina | 982e880 | 2018-01-22 10:05:53 +0000 | [diff] [blame] | 159 | if (LiveRegs.empty()) |
Marina Yatsina | 8957ed6 | 2018-01-22 10:06:01 +0000 | [diff] [blame] | 160 | LiveRegs.assign(NumRegs, nullptr); |
Marina Yatsina | ef27918 | 2018-01-22 10:05:23 +0000 | [diff] [blame] | 161 | |
| 162 | // This is the entry block. |
| 163 | if (MBB->pred_empty()) { |
Nicola Zaghen | 0818e78 | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 164 | LLVM_DEBUG(dbgs() << printMBBReference(*MBB) << ": entry\n"); |
Marina Yatsina | ef27918 | 2018-01-22 10:05:23 +0000 | [diff] [blame] | 165 | return; |
| 166 | } |
| 167 | |
| 168 | // Try to coalesce live-out registers from predecessors. |
Marina Yatsina | 95ade18 | 2018-01-22 10:06:18 +0000 | [diff] [blame] | 169 | for (MachineBasicBlock *pred : MBB->predecessors()) { |
Marina Yatsina | 66bd7d7 | 2018-01-22 13:24:10 +0000 | [diff] [blame] | 170 | assert(unsigned(pred->getNumber()) < MBBOutRegsInfos.size() && |
Marina Yatsina | 95ade18 | 2018-01-22 10:06:18 +0000 | [diff] [blame] | 171 | "Should have pre-allocated MBBInfos for all MBBs"); |
| 172 | LiveRegsDVInfo &Incoming = MBBOutRegsInfos[pred->getNumber()]; |
Keno Fischer | 2a3b42c | 2017-01-30 23:37:03 +0000 | [diff] [blame] | 173 | // Incoming is null if this is a backedge from a BB |
| 174 | // we haven't processed yet |
Marina Yatsina | 982e880 | 2018-01-22 10:05:53 +0000 | [diff] [blame] | 175 | if (Incoming.empty()) |
Jakob Stoklund Olesen | 2947f73 | 2011-11-15 01:15:25 +0000 | [diff] [blame] | 176 | continue; |
Jakob Stoklund Olesen | 2947f73 | 2011-11-15 01:15:25 +0000 | [diff] [blame] | 177 | |
| 178 | for (unsigned rx = 0; rx != NumRegs; ++rx) { |
Marina Yatsina | 8957ed6 | 2018-01-22 10:06:01 +0000 | [diff] [blame] | 179 | DomainValue *pdv = resolve(Incoming[rx]); |
Jakob Stoklund Olesen | 2947f73 | 2011-11-15 01:15:25 +0000 | [diff] [blame] | 180 | if (!pdv) |
Jakob Stoklund Olesen | f4c4768 | 2011-11-09 01:06:56 +0000 | [diff] [blame] | 181 | continue; |
Marina Yatsina | 8957ed6 | 2018-01-22 10:06:01 +0000 | [diff] [blame] | 182 | if (!LiveRegs[rx]) { |
Jakob Stoklund Olesen | 6bcb9a7 | 2011-11-08 21:57:47 +0000 | [diff] [blame] | 183 | setLiveReg(rx, pdv); |
Chris Lattner | 563d83f | 2010-03-31 20:32:51 +0000 | [diff] [blame] | 184 | continue; |
Jakob Stoklund Olesen | 1a5d2a8 | 2010-03-30 20:04:01 +0000 | [diff] [blame] | 185 | } |
Chris Lattner | 563d83f | 2010-03-31 20:32:51 +0000 | [diff] [blame] | 186 | |
| 187 | // We have a live DomainValue from more than one predecessor. |
Marina Yatsina | 8957ed6 | 2018-01-22 10:06:01 +0000 | [diff] [blame] | 188 | if (LiveRegs[rx]->isCollapsed()) { |
Eric Christopher | 68c7a1c | 2014-05-20 17:11:11 +0000 | [diff] [blame] | 189 | // We are already collapsed, but predecessor is not. Force it. |
Marina Yatsina | 8957ed6 | 2018-01-22 10:06:01 +0000 | [diff] [blame] | 190 | unsigned Domain = LiveRegs[rx]->getFirstDomain(); |
Jakob Stoklund Olesen | 2947f73 | 2011-11-15 01:15:25 +0000 | [diff] [blame] | 191 | if (!pdv->isCollapsed() && pdv->hasDomain(Domain)) |
| 192 | collapse(pdv, Domain); |
Chris Lattner | 563d83f | 2010-03-31 20:32:51 +0000 | [diff] [blame] | 193 | continue; |
| 194 | } |
Jakob Stoklund Olesen | bbef815 | 2010-04-04 18:00:21 +0000 | [diff] [blame] | 195 | |
Chris Lattner | 563d83f | 2010-03-31 20:32:51 +0000 | [diff] [blame] | 196 | // Currently open, merge in predecessor. |
Jakob Stoklund Olesen | e0103f0 | 2010-04-04 21:27:26 +0000 | [diff] [blame] | 197 | if (!pdv->isCollapsed()) |
Marina Yatsina | 8957ed6 | 2018-01-22 10:06:01 +0000 | [diff] [blame] | 198 | merge(LiveRegs[rx], pdv); |
Chris Lattner | 563d83f | 2010-03-31 20:32:51 +0000 | [diff] [blame] | 199 | else |
Jakob Stoklund Olesen | 6bcb9a7 | 2011-11-08 21:57:47 +0000 | [diff] [blame] | 200 | force(rx, pdv->getFirstDomain()); |
Jakob Stoklund Olesen | 1a5d2a8 | 2010-03-30 20:04:01 +0000 | [diff] [blame] | 201 | } |
| 202 | } |
Nicola Zaghen | 0818e78 | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 203 | LLVM_DEBUG(dbgs() << printMBBReference(*MBB) |
| 204 | << (!TraversedMBB.IsDone ? ": incomplete\n" |
| 205 | : ": all preds known\n")); |
Jakob Stoklund Olesen | e4b94b4 | 2010-03-29 23:24:21 +0000 | [diff] [blame] | 206 | } |
| 207 | |
Marina Yatsina | ef27918 | 2018-01-22 10:05:23 +0000 | [diff] [blame] | 208 | void ExecutionDomainFix::leaveBasicBlock( |
| 209 | const LoopTraversal::TraversedMBBInfo &TraversedMBB) { |
Marina Yatsina | 982e880 | 2018-01-22 10:05:53 +0000 | [diff] [blame] | 210 | assert(!LiveRegs.empty() && "Must enter basic block first."); |
Marina Yatsina | 66bd7d7 | 2018-01-22 13:24:10 +0000 | [diff] [blame] | 211 | unsigned MBBNumber = TraversedMBB.MBB->getNumber(); |
Marina Yatsina | 95ade18 | 2018-01-22 10:06:18 +0000 | [diff] [blame] | 212 | assert(MBBNumber < MBBOutRegsInfos.size() && |
| 213 | "Unexpected basic block number."); |
Marina Yatsina | ef27918 | 2018-01-22 10:05:23 +0000 | [diff] [blame] | 214 | // Save register clearances at end of MBB - used by enterBasicBlock(). |
Marina Yatsina | 8957ed6 | 2018-01-22 10:06:01 +0000 | [diff] [blame] | 215 | for (DomainValue *OldLiveReg : MBBOutRegsInfos[MBBNumber]) { |
| 216 | release(OldLiveReg); |
Jakob Stoklund Olesen | f4c4768 | 2011-11-09 01:06:56 +0000 | [diff] [blame] | 217 | } |
Marina Yatsina | 8957ed6 | 2018-01-22 10:06:01 +0000 | [diff] [blame] | 218 | MBBOutRegsInfos[MBBNumber] = LiveRegs; |
Marina Yatsina | 982e880 | 2018-01-22 10:05:53 +0000 | [diff] [blame] | 219 | LiveRegs.clear(); |
Jakob Stoklund Olesen | 25265d0 | 2011-11-07 21:40:27 +0000 | [diff] [blame] | 220 | } |
| 221 | |
Marina Yatsina | ef27918 | 2018-01-22 10:05:23 +0000 | [diff] [blame] | 222 | bool ExecutionDomainFix::visitInstr(MachineInstr *MI) { |
Jakob Stoklund Olesen | 2947f73 | 2011-11-15 01:15:25 +0000 | [diff] [blame] | 223 | // Update instructions with explicit execution domains. |
Duncan P. N. Exon Smith | 567409d | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 224 | std::pair<uint16_t, uint16_t> DomP = TII->getExecutionDomain(*MI); |
Jakob Stoklund Olesen | 2947f73 | 2011-11-15 01:15:25 +0000 | [diff] [blame] | 225 | if (DomP.first) { |
| 226 | if (DomP.second) |
| 227 | visitSoftInstr(MI, DomP.second); |
Jakob Stoklund Olesen | 25265d0 | 2011-11-07 21:40:27 +0000 | [diff] [blame] | 228 | else |
Jakob Stoklund Olesen | 2947f73 | 2011-11-15 01:15:25 +0000 | [diff] [blame] | 229 | visitHardInstr(MI, DomP.first); |
| 230 | } |
| 231 | |
Keno Fischer | 2a3b42c | 2017-01-30 23:37:03 +0000 | [diff] [blame] | 232 | return !DomP.first; |
Jakob Stoklund Olesen | 2947f73 | 2011-11-15 01:15:25 +0000 | [diff] [blame] | 233 | } |
| 234 | |
Marina Yatsina | ef27918 | 2018-01-22 10:05:23 +0000 | [diff] [blame] | 235 | void ExecutionDomainFix::processDefs(MachineInstr *MI, bool Kill) { |
Shiva Chen | 24abe71 | 2018-05-09 02:42:00 +0000 | [diff] [blame] | 236 | assert(!MI->isDebugInstr() && "Won't process debug values"); |
Jakob Stoklund Olesen | 2947f73 | 2011-11-15 01:15:25 +0000 | [diff] [blame] | 237 | const MCInstrDesc &MCID = MI->getDesc(); |
| 238 | for (unsigned i = 0, |
Marina Yatsina | 95ade18 | 2018-01-22 10:06:18 +0000 | [diff] [blame] | 239 | e = MI->isVariadic() ? MI->getNumOperands() : MCID.getNumDefs(); |
| 240 | i != e; ++i) { |
Jakob Stoklund Olesen | 2947f73 | 2011-11-15 01:15:25 +0000 | [diff] [blame] | 241 | MachineOperand &MO = MI->getOperand(i); |
| 242 | if (!MO.isReg()) |
| 243 | continue; |
Jakob Stoklund Olesen | 2947f73 | 2011-11-15 01:15:25 +0000 | [diff] [blame] | 244 | if (MO.isUse()) |
| 245 | continue; |
Matthias Braun | ae6bbac | 2015-03-06 18:56:20 +0000 | [diff] [blame] | 246 | for (int rx : regIndices(MO.getReg())) { |
Matthias Braun | cd56c19 | 2014-12-17 19:13:47 +0000 | [diff] [blame] | 247 | // This instruction explicitly defines rx. |
Nicola Zaghen | 0818e78 | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 248 | LLVM_DEBUG(dbgs() << printReg(RC->getRegister(rx), TRI) << ":\t" << *MI); |
Andrew Trick | a6a9ac5 | 2013-10-14 22:19:03 +0000 | [diff] [blame] | 249 | |
Matthias Braun | cd56c19 | 2014-12-17 19:13:47 +0000 | [diff] [blame] | 250 | // Kill off domains redefined by generic instructions. |
| 251 | if (Kill) |
| 252 | kill(rx); |
| 253 | } |
Jakob Stoklund Olesen | 2947f73 | 2011-11-15 01:15:25 +0000 | [diff] [blame] | 254 | } |
Marina Yatsina | ef27918 | 2018-01-22 10:05:23 +0000 | [diff] [blame] | 255 | } |
| 256 | |
Marina Yatsina | ef27918 | 2018-01-22 10:05:23 +0000 | [diff] [blame] | 257 | void ExecutionDomainFix::visitHardInstr(MachineInstr *mi, unsigned domain) { |
Jakob Stoklund Olesen | e4b94b4 | 2010-03-29 23:24:21 +0000 | [diff] [blame] | 258 | // Collapse all uses. |
| 259 | for (unsigned i = mi->getDesc().getNumDefs(), |
Marina Yatsina | 95ade18 | 2018-01-22 10:06:18 +0000 | [diff] [blame] | 260 | e = mi->getDesc().getNumOperands(); |
| 261 | i != e; ++i) { |
Jakob Stoklund Olesen | e4b94b4 | 2010-03-29 23:24:21 +0000 | [diff] [blame] | 262 | MachineOperand &mo = mi->getOperand(i); |
Marina Yatsina | 95ade18 | 2018-01-22 10:06:18 +0000 | [diff] [blame] | 263 | if (!mo.isReg()) |
| 264 | continue; |
Matthias Braun | ae6bbac | 2015-03-06 18:56:20 +0000 | [diff] [blame] | 265 | for (int rx : regIndices(mo.getReg())) { |
Matthias Braun | cd56c19 | 2014-12-17 19:13:47 +0000 | [diff] [blame] | 266 | force(rx, domain); |
| 267 | } |
Jakob Stoklund Olesen | e4b94b4 | 2010-03-29 23:24:21 +0000 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | // Kill all defs and force them. |
| 271 | for (unsigned i = 0, e = mi->getDesc().getNumDefs(); i != e; ++i) { |
| 272 | MachineOperand &mo = mi->getOperand(i); |
Marina Yatsina | 95ade18 | 2018-01-22 10:06:18 +0000 | [diff] [blame] | 273 | if (!mo.isReg()) |
| 274 | continue; |
Matthias Braun | ae6bbac | 2015-03-06 18:56:20 +0000 | [diff] [blame] | 275 | for (int rx : regIndices(mo.getReg())) { |
Matthias Braun | cd56c19 | 2014-12-17 19:13:47 +0000 | [diff] [blame] | 276 | kill(rx); |
| 277 | force(rx, domain); |
| 278 | } |
Jakob Stoklund Olesen | e4b94b4 | 2010-03-29 23:24:21 +0000 | [diff] [blame] | 279 | } |
| 280 | } |
| 281 | |
Marina Yatsina | ef27918 | 2018-01-22 10:05:23 +0000 | [diff] [blame] | 282 | void ExecutionDomainFix::visitSoftInstr(MachineInstr *mi, unsigned mask) { |
Jakob Stoklund Olesen | e0103f0 | 2010-04-04 21:27:26 +0000 | [diff] [blame] | 283 | // Bitmask of available domains for this instruction after taking collapsed |
| 284 | // operands into account. |
| 285 | unsigned available = mask; |
| 286 | |
Jakob Stoklund Olesen | e4b94b4 | 2010-03-29 23:24:21 +0000 | [diff] [blame] | 287 | // Scan the explicit use operands for incoming domains. |
Jakob Stoklund Olesen | e4b94b4 | 2010-03-29 23:24:21 +0000 | [diff] [blame] | 288 | SmallVector<int, 4> used; |
Marina Yatsina | 982e880 | 2018-01-22 10:05:53 +0000 | [diff] [blame] | 289 | if (!LiveRegs.empty()) |
Jakob Stoklund Olesen | 1a5d2a8 | 2010-03-30 20:04:01 +0000 | [diff] [blame] | 290 | for (unsigned i = mi->getDesc().getNumDefs(), |
Marina Yatsina | 95ade18 | 2018-01-22 10:06:18 +0000 | [diff] [blame] | 291 | e = mi->getDesc().getNumOperands(); |
| 292 | i != e; ++i) { |
Chris Lattner | 563d83f | 2010-03-31 20:32:51 +0000 | [diff] [blame] | 293 | MachineOperand &mo = mi->getOperand(i); |
Marina Yatsina | 95ade18 | 2018-01-22 10:06:18 +0000 | [diff] [blame] | 294 | if (!mo.isReg()) |
| 295 | continue; |
Matthias Braun | ae6bbac | 2015-03-06 18:56:20 +0000 | [diff] [blame] | 296 | for (int rx : regIndices(mo.getReg())) { |
Marina Yatsina | 8957ed6 | 2018-01-22 10:06:01 +0000 | [diff] [blame] | 297 | DomainValue *dv = LiveRegs[rx]; |
Matthias Braun | cd56c19 | 2014-12-17 19:13:47 +0000 | [diff] [blame] | 298 | if (dv == nullptr) |
| 299 | continue; |
Jakob Stoklund Olesen | e0103f0 | 2010-04-04 21:27:26 +0000 | [diff] [blame] | 300 | // Bitmask of domains that dv and available have in common. |
| 301 | unsigned common = dv->getCommonDomains(available); |
Chris Lattner | 563d83f | 2010-03-31 20:32:51 +0000 | [diff] [blame] | 302 | // Is it possible to use this collapsed register for free? |
Jakob Stoklund Olesen | e0103f0 | 2010-04-04 21:27:26 +0000 | [diff] [blame] | 303 | if (dv->isCollapsed()) { |
| 304 | // Restrict available domains to the ones in common with the operand. |
Andrew Trick | a6a9ac5 | 2013-10-14 22:19:03 +0000 | [diff] [blame] | 305 | // If there are no common domains, we must pay the cross-domain |
Jakob Stoklund Olesen | e0103f0 | 2010-04-04 21:27:26 +0000 | [diff] [blame] | 306 | // penalty for this operand. |
Marina Yatsina | 95ade18 | 2018-01-22 10:06:18 +0000 | [diff] [blame] | 307 | if (common) |
| 308 | available = common; |
Jakob Stoklund Olesen | e0103f0 | 2010-04-04 21:27:26 +0000 | [diff] [blame] | 309 | } else if (common) |
| 310 | // Open DomainValue is compatible, save it for merging. |
Chris Lattner | 563d83f | 2010-03-31 20:32:51 +0000 | [diff] [blame] | 311 | used.push_back(rx); |
| 312 | else |
Jakob Stoklund Olesen | e0103f0 | 2010-04-04 21:27:26 +0000 | [diff] [blame] | 313 | // Open DomainValue is not compatible with instruction. It is useless |
| 314 | // now. |
Jakob Stoklund Olesen | 6bcb9a7 | 2011-11-08 21:57:47 +0000 | [diff] [blame] | 315 | kill(rx); |
Chris Lattner | 563d83f | 2010-03-31 20:32:51 +0000 | [diff] [blame] | 316 | } |
Jakob Stoklund Olesen | e4b94b4 | 2010-03-29 23:24:21 +0000 | [diff] [blame] | 317 | } |
Jakob Stoklund Olesen | e4b94b4 | 2010-03-29 23:24:21 +0000 | [diff] [blame] | 318 | |
| 319 | // If the collapsed operands force a single domain, propagate the collapse. |
Jakob Stoklund Olesen | e0103f0 | 2010-04-04 21:27:26 +0000 | [diff] [blame] | 320 | if (isPowerOf2_32(available)) { |
Michael J. Spencer | c6af243 | 2013-05-24 22:23:49 +0000 | [diff] [blame] | 321 | unsigned domain = countTrailingZeros(available); |
Duncan P. N. Exon Smith | 567409d | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 322 | TII->setExecutionDomain(*mi, domain); |
Jakob Stoklund Olesen | e4b94b4 | 2010-03-29 23:24:21 +0000 | [diff] [blame] | 323 | visitHardInstr(mi, domain); |
| 324 | return; |
| 325 | } |
| 326 | |
Jakob Stoklund Olesen | e0103f0 | 2010-04-04 21:27:26 +0000 | [diff] [blame] | 327 | // Kill off any remaining uses that don't match available, and build a list of |
| 328 | // incoming DomainValues that we want to merge. |
Marina Yatsina | 8957ed6 | 2018-01-22 10:06:01 +0000 | [diff] [blame] | 329 | SmallVector<int, 4> Regs; |
Craig Topper | 7329851 | 2017-02-24 06:38:24 +0000 | [diff] [blame] | 330 | for (int rx : used) { |
Marina Yatsina | 982e880 | 2018-01-22 10:05:53 +0000 | [diff] [blame] | 331 | assert(!LiveRegs.empty() && "no space allocated for live registers"); |
Marina Yatsina | 8957ed6 | 2018-01-22 10:06:01 +0000 | [diff] [blame] | 332 | DomainValue *&LR = LiveRegs[rx]; |
Jakob Stoklund Olesen | 1a5d2a8 | 2010-03-30 20:04:01 +0000 | [diff] [blame] | 333 | // This useless DomainValue could have been missed above. |
Marina Yatsina | 8957ed6 | 2018-01-22 10:06:01 +0000 | [diff] [blame] | 334 | if (!LR->getCommonDomains(available)) { |
Jakob Stoklund Olesen | 2947f73 | 2011-11-15 01:15:25 +0000 | [diff] [blame] | 335 | kill(rx); |
Jakob Stoklund Olesen | e4b94b4 | 2010-03-29 23:24:21 +0000 | [diff] [blame] | 336 | continue; |
| 337 | } |
Jakob Stoklund Olesen | 2947f73 | 2011-11-15 01:15:25 +0000 | [diff] [blame] | 338 | // Sorted insertion. |
Marina Yatsina | 8957ed6 | 2018-01-22 10:06:01 +0000 | [diff] [blame] | 339 | // Enables giving priority to the latest domains during merging. |
Marina Yatsina | 95ade18 | 2018-01-22 10:06:18 +0000 | [diff] [blame] | 340 | auto I = std::upper_bound( |
| 341 | Regs.begin(), Regs.end(), rx, [&](int LHS, const int RHS) { |
| 342 | return RDA->getReachingDef(mi, RC->getRegister(LHS)) < |
| 343 | RDA->getReachingDef(mi, RC->getRegister(RHS)); |
| 344 | }); |
Marina Yatsina | 8957ed6 | 2018-01-22 10:06:01 +0000 | [diff] [blame] | 345 | Regs.insert(I, rx); |
Jakob Stoklund Olesen | e4b94b4 | 2010-03-29 23:24:21 +0000 | [diff] [blame] | 346 | } |
| 347 | |
Jakob Stoklund Olesen | e0103f0 | 2010-04-04 21:27:26 +0000 | [diff] [blame] | 348 | // doms are now sorted in order of appearance. Try to merge them all, giving |
| 349 | // priority to the latest ones. |
Craig Topper | 4ba8443 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 350 | DomainValue *dv = nullptr; |
Jakob Stoklund Olesen | 2947f73 | 2011-11-15 01:15:25 +0000 | [diff] [blame] | 351 | while (!Regs.empty()) { |
Chris Lattner | 563d83f | 2010-03-31 20:32:51 +0000 | [diff] [blame] | 352 | if (!dv) { |
Marina Yatsina | 8957ed6 | 2018-01-22 10:06:01 +0000 | [diff] [blame] | 353 | dv = LiveRegs[Regs.pop_back_val()]; |
Jakob Stoklund Olesen | 7f5e43f | 2011-11-23 04:03:08 +0000 | [diff] [blame] | 354 | // Force the first dv to match the current instruction. |
| 355 | dv->AvailableDomains = dv->getCommonDomains(available); |
| 356 | assert(dv->AvailableDomains && "Domain should have been filtered"); |
Chris Lattner | 563d83f | 2010-03-31 20:32:51 +0000 | [diff] [blame] | 357 | continue; |
| 358 | } |
Jakob Stoklund Olesen | bbef815 | 2010-04-04 18:00:21 +0000 | [diff] [blame] | 359 | |
Marina Yatsina | 8957ed6 | 2018-01-22 10:06:01 +0000 | [diff] [blame] | 360 | DomainValue *Latest = LiveRegs[Regs.pop_back_val()]; |
Jakob Stoklund Olesen | 2947f73 | 2011-11-15 01:15:25 +0000 | [diff] [blame] | 361 | // Skip already merged values. |
| 362 | if (Latest == dv || Latest->Next) |
| 363 | continue; |
| 364 | if (merge(dv, Latest)) |
| 365 | continue; |
Jakob Stoklund Olesen | bbef815 | 2010-04-04 18:00:21 +0000 | [diff] [blame] | 366 | |
Jakob Stoklund Olesen | e0103f0 | 2010-04-04 21:27:26 +0000 | [diff] [blame] | 367 | // If latest didn't merge, it is useless now. Kill all registers using it. |
Michael Ilseman | 9ecdca9 | 2014-12-15 18:48:43 +0000 | [diff] [blame] | 368 | for (int i : used) { |
Marina Yatsina | 982e880 | 2018-01-22 10:05:53 +0000 | [diff] [blame] | 369 | assert(!LiveRegs.empty() && "no space allocated for live registers"); |
Marina Yatsina | 8957ed6 | 2018-01-22 10:06:01 +0000 | [diff] [blame] | 370 | if (LiveRegs[i] == Latest) |
Michael Ilseman | 9ecdca9 | 2014-12-15 18:48:43 +0000 | [diff] [blame] | 371 | kill(i); |
| 372 | } |
Jakob Stoklund Olesen | e4b94b4 | 2010-03-29 23:24:21 +0000 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | // dv is the DomainValue we are going to use for this instruction. |
Jakob Stoklund Olesen | 7f5e43f | 2011-11-23 04:03:08 +0000 | [diff] [blame] | 376 | if (!dv) { |
Jakob Stoklund Olesen | 6bcb9a7 | 2011-11-08 21:57:47 +0000 | [diff] [blame] | 377 | dv = alloc(); |
Jakob Stoklund Olesen | 7f5e43f | 2011-11-23 04:03:08 +0000 | [diff] [blame] | 378 | dv->AvailableDomains = available; |
| 379 | } |
Jakob Stoklund Olesen | e4b94b4 | 2010-03-29 23:24:21 +0000 | [diff] [blame] | 380 | dv->Instrs.push_back(mi); |
| 381 | |
Silviu Baranga | 541a858 | 2012-10-03 08:29:36 +0000 | [diff] [blame] | 382 | // Finally set all defs and non-collapsed uses to dv. We must iterate through |
| 383 | // all the operators, including imp-def ones. |
Marina Yatsina | f2a8b01 | 2018-01-22 10:05:37 +0000 | [diff] [blame] | 384 | for (MachineOperand &mo : mi->operands()) { |
Marina Yatsina | 95ade18 | 2018-01-22 10:06:18 +0000 | [diff] [blame] | 385 | if (!mo.isReg()) |
| 386 | continue; |
Matthias Braun | ae6bbac | 2015-03-06 18:56:20 +0000 | [diff] [blame] | 387 | for (int rx : regIndices(mo.getReg())) { |
Marina Yatsina | 8957ed6 | 2018-01-22 10:06:01 +0000 | [diff] [blame] | 388 | if (!LiveRegs[rx] || (mo.isDef() && LiveRegs[rx] != dv)) { |
Matthias Braun | cd56c19 | 2014-12-17 19:13:47 +0000 | [diff] [blame] | 389 | kill(rx); |
| 390 | setLiveReg(rx, dv); |
| 391 | } |
Jakob Stoklund Olesen | e4b94b4 | 2010-03-29 23:24:21 +0000 | [diff] [blame] | 392 | } |
| 393 | } |
| 394 | } |
| 395 | |
Marina Yatsina | ef27918 | 2018-01-22 10:05:23 +0000 | [diff] [blame] | 396 | void ExecutionDomainFix::processBasicBlock( |
| 397 | const LoopTraversal::TraversedMBBInfo &TraversedMBB) { |
| 398 | enterBasicBlock(TraversedMBB); |
Keno Fischer | 2a3b42c | 2017-01-30 23:37:03 +0000 | [diff] [blame] | 399 | // If this block is not done, it makes little sense to make any decisions |
| 400 | // based on clearance information. We need to make a second pass anyway, |
| 401 | // and by then we'll have better information, so we can avoid doing the work |
| 402 | // to try and break dependencies now. |
Marina Yatsina | ef27918 | 2018-01-22 10:05:23 +0000 | [diff] [blame] | 403 | for (MachineInstr &MI : *TraversedMBB.MBB) { |
Shiva Chen | 24abe71 | 2018-05-09 02:42:00 +0000 | [diff] [blame] | 404 | if (!MI.isDebugInstr()) { |
Keno Fischer | 2a3b42c | 2017-01-30 23:37:03 +0000 | [diff] [blame] | 405 | bool Kill = false; |
Marina Yatsina | ef27918 | 2018-01-22 10:05:23 +0000 | [diff] [blame] | 406 | if (TraversedMBB.PrimaryPass) |
Keno Fischer | 2a3b42c | 2017-01-30 23:37:03 +0000 | [diff] [blame] | 407 | Kill = visitInstr(&MI); |
Marina Yatsina | ef27918 | 2018-01-22 10:05:23 +0000 | [diff] [blame] | 408 | processDefs(&MI, Kill); |
Keno Fischer | 2a3b42c | 2017-01-30 23:37:03 +0000 | [diff] [blame] | 409 | } |
| 410 | } |
Marina Yatsina | ef27918 | 2018-01-22 10:05:23 +0000 | [diff] [blame] | 411 | leaveBasicBlock(TraversedMBB); |
Keno Fischer | 2a3b42c | 2017-01-30 23:37:03 +0000 | [diff] [blame] | 412 | } |
| 413 | |
Marina Yatsina | ef27918 | 2018-01-22 10:05:23 +0000 | [diff] [blame] | 414 | bool ExecutionDomainFix::runOnMachineFunction(MachineFunction &mf) { |
| 415 | if (skipFunction(mf.getFunction())) |
| 416 | return false; |
| 417 | MF = &mf; |
| 418 | TII = MF->getSubtarget().getInstrInfo(); |
| 419 | TRI = MF->getSubtarget().getRegisterInfo(); |
Marina Yatsina | 982e880 | 2018-01-22 10:05:53 +0000 | [diff] [blame] | 420 | LiveRegs.clear(); |
Marina Yatsina | ef27918 | 2018-01-22 10:05:23 +0000 | [diff] [blame] | 421 | assert(NumRegs == RC->getNumRegs() && "Bad regclass"); |
| 422 | |
Nicola Zaghen | 0818e78 | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 423 | LLVM_DEBUG(dbgs() << "********** FIX EXECUTION DOMAIN: " |
| 424 | << TRI->getRegClassName(RC) << " **********\n"); |
Marina Yatsina | ef27918 | 2018-01-22 10:05:23 +0000 | [diff] [blame] | 425 | |
| 426 | // If no relevant registers are used in the function, we can skip it |
| 427 | // completely. |
| 428 | bool anyregs = false; |
| 429 | const MachineRegisterInfo &MRI = mf.getRegInfo(); |
| 430 | for (unsigned Reg : *RC) { |
| 431 | if (MRI.isPhysRegUsed(Reg)) { |
| 432 | anyregs = true; |
| 433 | break; |
| 434 | } |
| 435 | } |
Marina Yatsina | 95ade18 | 2018-01-22 10:06:18 +0000 | [diff] [blame] | 436 | if (!anyregs) |
| 437 | return false; |
Marina Yatsina | ef27918 | 2018-01-22 10:05:23 +0000 | [diff] [blame] | 438 | |
Marina Yatsina | f2a8b01 | 2018-01-22 10:05:37 +0000 | [diff] [blame] | 439 | RDA = &getAnalysis<ReachingDefAnalysis>(); |
| 440 | |
Marina Yatsina | ef27918 | 2018-01-22 10:05:23 +0000 | [diff] [blame] | 441 | // Initialize the AliasMap on the first use. |
| 442 | if (AliasMap.empty()) { |
| 443 | // Given a PhysReg, AliasMap[PhysReg] returns a list of indices into RC and |
| 444 | // therefore the LiveRegs array. |
| 445 | AliasMap.resize(TRI->getNumRegs()); |
| 446 | for (unsigned i = 0, e = RC->getNumRegs(); i != e; ++i) |
Marina Yatsina | 95ade18 | 2018-01-22 10:06:18 +0000 | [diff] [blame] | 447 | for (MCRegAliasIterator AI(RC->getRegister(i), TRI, true); AI.isValid(); |
| 448 | ++AI) |
Marina Yatsina | ef27918 | 2018-01-22 10:05:23 +0000 | [diff] [blame] | 449 | AliasMap[*AI].push_back(i); |
| 450 | } |
| 451 | |
| 452 | // Initialize the MBBOutRegsInfos |
Marina Yatsina | 982e880 | 2018-01-22 10:05:53 +0000 | [diff] [blame] | 453 | MBBOutRegsInfos.resize(mf.getNumBlockIDs()); |
Marina Yatsina | ef27918 | 2018-01-22 10:05:23 +0000 | [diff] [blame] | 454 | |
| 455 | // Traverse the basic blocks. |
| 456 | LoopTraversal Traversal; |
Marina Yatsina | f2a8b01 | 2018-01-22 10:05:37 +0000 | [diff] [blame] | 457 | LoopTraversal::TraversalOrder TraversedMBBOrder = Traversal.traverse(mf); |
| 458 | for (LoopTraversal::TraversedMBBInfo TraversedMBB : TraversedMBBOrder) { |
Marina Yatsina | ef27918 | 2018-01-22 10:05:23 +0000 | [diff] [blame] | 459 | processBasicBlock(TraversedMBB); |
| 460 | } |
| 461 | |
Marina Yatsina | 95ade18 | 2018-01-22 10:06:18 +0000 | [diff] [blame] | 462 | for (LiveRegsDVInfo OutLiveRegs : MBBOutRegsInfos) { |
Marina Yatsina | 8957ed6 | 2018-01-22 10:06:01 +0000 | [diff] [blame] | 463 | for (DomainValue *OutLiveReg : OutLiveRegs) { |
| 464 | if (OutLiveReg) |
| 465 | release(OutLiveReg); |
Marina Yatsina | 982e880 | 2018-01-22 10:05:53 +0000 | [diff] [blame] | 466 | } |
Jakob Stoklund Olesen | b26c772 | 2011-11-07 23:08:21 +0000 | [diff] [blame] | 467 | } |
Marina Yatsina | ef27918 | 2018-01-22 10:05:23 +0000 | [diff] [blame] | 468 | MBBOutRegsInfos.clear(); |
Jakob Stoklund Olesen | bbef815 | 2010-04-04 18:00:21 +0000 | [diff] [blame] | 469 | Avail.clear(); |
| 470 | Allocator.DestroyAll(); |
Jakob Stoklund Olesen | e4b94b4 | 2010-03-29 23:24:21 +0000 | [diff] [blame] | 471 | |
Jakob Stoklund Olesen | 352aa50 | 2010-03-25 17:25:00 +0000 | [diff] [blame] | 472 | return false; |
| 473 | } |