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