blob: a63ab8fabb04c840a99fb7f776424aa7598ef6d1 [file] [log] [blame]
Eugene Zelenkoe4fc6ee2017-07-26 23:20:35 +00001//===- HexagonBlockRanges.cpp ---------------------------------------------===//
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +000010#include "HexagonBlockRanges.h"
11#include "HexagonInstrInfo.h"
12#include "HexagonSubtarget.h"
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +000013#include "llvm/ADT/BitVector.h"
Eugene Zelenko82085922016-12-13 22:13:50 +000014#include "llvm/ADT/STLExtras.h"
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +000015#include "llvm/CodeGen/MachineBasicBlock.h"
Eugene Zelenko82085922016-12-13 22:13:50 +000016#include "llvm/CodeGen/MachineFunction.h"
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +000017#include "llvm/CodeGen/MachineInstr.h"
Eugene Zelenko3b873362017-09-28 22:27:31 +000018#include "llvm/CodeGen/MachineOperand.h"
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +000019#include "llvm/CodeGen/MachineRegisterInfo.h"
David Blaikieb3bde2e2017-11-17 01:07:10 +000020#include "llvm/CodeGen/TargetRegisterInfo.h"
Eugene Zelenko82085922016-12-13 22:13:50 +000021#include "llvm/MC/MCRegisterInfo.h"
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +000022#include "llvm/Support/Debug.h"
23#include "llvm/Support/raw_ostream.h"
Eugene Zelenko82085922016-12-13 22:13:50 +000024#include <algorithm>
25#include <cassert>
Eugene Zelenkoe4fc6ee2017-07-26 23:20:35 +000026#include <cstdint>
Eugene Zelenko82085922016-12-13 22:13:50 +000027#include <iterator>
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +000028#include <map>
Eugene Zelenkoe4fc6ee2017-07-26 23:20:35 +000029#include <utility>
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +000030
31using namespace llvm;
32
Eugene Zelenko3b873362017-09-28 22:27:31 +000033#define DEBUG_TYPE "hbr"
34
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +000035bool HexagonBlockRanges::IndexRange::overlaps(const IndexRange &A) const {
36 // If A contains start(), or "this" contains A.start(), then overlap.
37 IndexType S = start(), E = end(), AS = A.start(), AE = A.end();
38 if (AS == S)
39 return true;
40 bool SbAE = (S < AE) || (S == AE && A.TiedEnd); // S-before-AE.
41 bool ASbE = (AS < E) || (AS == E && TiedEnd); // AS-before-E.
42 if ((AS < S && SbAE) || (S < AS && ASbE))
43 return true;
44 // Otherwise no overlap.
45 return false;
46}
47
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +000048bool HexagonBlockRanges::IndexRange::contains(const IndexRange &A) const {
49 if (start() <= A.start()) {
50 // Treat "None" in the range end as equal to the range start.
51 IndexType E = (end() != IndexType::None) ? end() : start();
52 IndexType AE = (A.end() != IndexType::None) ? A.end() : A.start();
53 if (AE <= E)
54 return true;
55 }
56 return false;
57}
58
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +000059void HexagonBlockRanges::IndexRange::merge(const IndexRange &A) {
60 // Allow merging adjacent ranges.
61 assert(end() == A.start() || overlaps(A));
62 IndexType AS = A.start(), AE = A.end();
63 if (AS < start() || start() == IndexType::None)
64 setStart(AS);
65 if (end() < AE || end() == IndexType::None) {
66 setEnd(AE);
67 TiedEnd = A.TiedEnd;
68 } else {
69 if (end() == AE)
70 TiedEnd |= A.TiedEnd;
71 }
72 if (A.Fixed)
73 Fixed = true;
74}
75
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +000076void HexagonBlockRanges::RangeList::include(const RangeList &RL) {
77 for (auto &R : RL)
David Majnemer42531262016-08-12 03:55:06 +000078 if (!is_contained(*this, R))
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +000079 push_back(R);
80}
81
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +000082// Merge all overlapping ranges in the list, so that all that remains
83// is a list of disjoint ranges.
84void HexagonBlockRanges::RangeList::unionize(bool MergeAdjacent) {
85 if (empty())
86 return;
87
88 std::sort(begin(), end());
89 iterator Iter = begin();
90
91 while (Iter != end()-1) {
92 iterator Next = std::next(Iter);
93 // If MergeAdjacent is true, merge ranges A and B, where A.end == B.start.
94 // This allows merging dead ranges, but is not valid for live ranges.
95 bool Merge = MergeAdjacent && (Iter->end() == Next->start());
96 if (Merge || Iter->overlaps(*Next)) {
97 Iter->merge(*Next);
98 erase(Next);
99 continue;
100 }
101 ++Iter;
102 }
103}
104
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +0000105// Compute a range A-B and add it to the list.
106void HexagonBlockRanges::RangeList::addsub(const IndexRange &A,
107 const IndexRange &B) {
108 // Exclusion of non-overlapping ranges makes some checks simpler
109 // later in this function.
110 if (!A.overlaps(B)) {
111 // A - B = A.
112 add(A);
113 return;
114 }
115
116 IndexType AS = A.start(), AE = A.end();
117 IndexType BS = B.start(), BE = B.end();
118
119 // If AE is None, then A is included in B, since A and B overlap.
120 // The result of subtraction if empty, so just return.
121 if (AE == IndexType::None)
122 return;
123
124 if (AS < BS) {
125 // A starts before B.
126 // AE cannot be None since A and B overlap.
127 assert(AE != IndexType::None);
128 // Add the part of A that extends on the "less" side of B.
129 add(AS, BS, A.Fixed, false);
130 }
131
132 if (BE < AE) {
133 // BE cannot be Exit here.
134 if (BE == IndexType::None)
135 add(BS, AE, A.Fixed, false);
136 else
137 add(BE, AE, A.Fixed, false);
138 }
139}
140
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +0000141// Subtract a given range from each element in the list.
142void HexagonBlockRanges::RangeList::subtract(const IndexRange &Range) {
143 // Cannot assume that the list is unionized (i.e. contains only non-
144 // overlapping ranges.
145 RangeList T;
146 for (iterator Next, I = begin(); I != end(); I = Next) {
147 IndexRange &Rg = *I;
148 if (Rg.overlaps(Range)) {
149 T.addsub(Rg, Range);
150 Next = this->erase(I);
151 } else {
152 Next = std::next(I);
153 }
154 }
155 include(T);
156}
157
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +0000158HexagonBlockRanges::InstrIndexMap::InstrIndexMap(MachineBasicBlock &B)
159 : Block(B) {
160 IndexType Idx = IndexType::First;
161 First = Idx;
162 for (auto &In : B) {
163 if (In.isDebugValue())
164 continue;
165 assert(getIndex(&In) == IndexType::None && "Instruction already in map");
166 Map.insert(std::make_pair(Idx, &In));
167 ++Idx;
168 }
169 Last = B.empty() ? IndexType::None : unsigned(Idx)-1;
170}
171
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +0000172MachineInstr *HexagonBlockRanges::InstrIndexMap::getInstr(IndexType Idx) const {
173 auto F = Map.find(Idx);
Eugene Zelenko82085922016-12-13 22:13:50 +0000174 return (F != Map.end()) ? F->second : nullptr;
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +0000175}
176
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +0000177HexagonBlockRanges::IndexType HexagonBlockRanges::InstrIndexMap::getIndex(
178 MachineInstr *MI) const {
179 for (auto &I : Map)
180 if (I.second == MI)
181 return I.first;
182 return IndexType::None;
183}
184
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +0000185HexagonBlockRanges::IndexType HexagonBlockRanges::InstrIndexMap::getPrevIndex(
186 IndexType Idx) const {
187 assert (Idx != IndexType::None);
188 if (Idx == IndexType::Entry)
189 return IndexType::None;
190 if (Idx == IndexType::Exit)
191 return Last;
192 if (Idx == First)
193 return IndexType::Entry;
194 return unsigned(Idx)-1;
195}
196
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +0000197HexagonBlockRanges::IndexType HexagonBlockRanges::InstrIndexMap::getNextIndex(
198 IndexType Idx) const {
199 assert (Idx != IndexType::None);
200 if (Idx == IndexType::Entry)
201 return IndexType::First;
202 if (Idx == IndexType::Exit || Idx == Last)
203 return IndexType::None;
204 return unsigned(Idx)+1;
205}
206
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +0000207void HexagonBlockRanges::InstrIndexMap::replaceInstr(MachineInstr *OldMI,
208 MachineInstr *NewMI) {
209 for (auto &I : Map) {
210 if (I.second != OldMI)
211 continue;
212 if (NewMI != nullptr)
213 I.second = NewMI;
214 else
215 Map.erase(I.first);
216 break;
217 }
218}
219
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +0000220HexagonBlockRanges::HexagonBlockRanges(MachineFunction &mf)
221 : MF(mf), HST(mf.getSubtarget<HexagonSubtarget>()),
222 TII(*HST.getInstrInfo()), TRI(*HST.getRegisterInfo()),
223 Reserved(TRI.getReservedRegs(mf)) {
224 // Consider all non-allocatable registers as reserved.
Krzysztof Parzyszekee9aa3f2017-01-25 19:29:04 +0000225 for (const TargetRegisterClass *RC : TRI.regclasses()) {
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +0000226 if (RC->isAllocatable())
227 continue;
228 for (unsigned R : *RC)
229 Reserved[R] = true;
230 }
231}
232
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +0000233HexagonBlockRanges::RegisterSet HexagonBlockRanges::getLiveIns(
Krzysztof Parzyszek5bb417b2016-10-18 19:47:20 +0000234 const MachineBasicBlock &B, const MachineRegisterInfo &MRI,
235 const TargetRegisterInfo &TRI) {
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +0000236 RegisterSet LiveIns;
Krzysztof Parzyszek5bb417b2016-10-18 19:47:20 +0000237 RegisterSet Tmp;
Krzysztof Parzyszekf928e242017-04-14 16:21:55 +0000238
Krzysztof Parzyszek5bb417b2016-10-18 19:47:20 +0000239 for (auto I : B.liveins()) {
Krzysztof Parzyszekf928e242017-04-14 16:21:55 +0000240 MCSubRegIndexIterator S(I.PhysReg, &TRI);
241 if (I.LaneMask.all() || (I.LaneMask.any() && !S.isValid())) {
242 Tmp.insert({I.PhysReg, 0});
Krzysztof Parzyszek5bb417b2016-10-18 19:47:20 +0000243 continue;
244 }
Krzysztof Parzyszekf928e242017-04-14 16:21:55 +0000245 for (; S.isValid(); ++S) {
246 unsigned SI = S.getSubRegIndex();
247 if ((I.LaneMask & TRI.getSubRegIndexLaneMask(SI)).any())
Krzysztof Parzyszek5bb417b2016-10-18 19:47:20 +0000248 Tmp.insert({S.getSubReg(), 0});
249 }
250 }
251
252 for (auto R : Tmp) {
253 if (!Reserved[R.Reg])
254 LiveIns.insert(R);
255 for (auto S : expandToSubRegs(R, MRI, TRI))
256 if (!Reserved[S.Reg])
257 LiveIns.insert(S);
258 }
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +0000259 return LiveIns;
260}
261
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +0000262HexagonBlockRanges::RegisterSet HexagonBlockRanges::expandToSubRegs(
263 RegisterRef R, const MachineRegisterInfo &MRI,
264 const TargetRegisterInfo &TRI) {
265 RegisterSet SRs;
266
267 if (R.Sub != 0) {
268 SRs.insert(R);
269 return SRs;
270 }
271
272 if (TargetRegisterInfo::isPhysicalRegister(R.Reg)) {
273 MCSubRegIterator I(R.Reg, &TRI);
274 if (!I.isValid())
275 SRs.insert({R.Reg, 0});
276 for (; I.isValid(); ++I)
277 SRs.insert({*I, 0});
278 } else {
279 assert(TargetRegisterInfo::isVirtualRegister(R.Reg));
280 auto &RC = *MRI.getRegClass(R.Reg);
281 unsigned PReg = *RC.begin();
282 MCSubRegIndexIterator I(PReg, &TRI);
283 if (!I.isValid())
284 SRs.insert({R.Reg, 0});
285 for (; I.isValid(); ++I)
286 SRs.insert({R.Reg, I.getSubRegIndex()});
287 }
288 return SRs;
289}
290
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +0000291void HexagonBlockRanges::computeInitialLiveRanges(InstrIndexMap &IndexMap,
292 RegToRangeMap &LiveMap) {
293 std::map<RegisterRef,IndexType> LastDef, LastUse;
294 RegisterSet LiveOnEntry;
295 MachineBasicBlock &B = IndexMap.getBlock();
296 MachineRegisterInfo &MRI = B.getParent()->getRegInfo();
297
Krzysztof Parzyszek5bb417b2016-10-18 19:47:20 +0000298 for (auto R : getLiveIns(B, MRI, TRI))
299 LiveOnEntry.insert(R);
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +0000300
301 for (auto R : LiveOnEntry)
302 LastDef[R] = IndexType::Entry;
303
304 auto closeRange = [&LastUse,&LastDef,&LiveMap] (RegisterRef R) -> void {
305 auto LD = LastDef[R], LU = LastUse[R];
306 if (LD == IndexType::None)
307 LD = IndexType::Entry;
308 if (LU == IndexType::None)
309 LU = IndexType::Exit;
310 LiveMap[R].add(LD, LU, false, false);
311 LastUse[R] = LastDef[R] = IndexType::None;
312 };
313
Krzysztof Parzyszek1aaf41a2017-02-17 22:14:51 +0000314 RegisterSet Defs, Clobbers;
315
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +0000316 for (auto &In : B) {
317 if (In.isDebugValue())
318 continue;
319 IndexType Index = IndexMap.getIndex(&In);
320 // Process uses first.
321 for (auto &Op : In.operands()) {
322 if (!Op.isReg() || !Op.isUse() || Op.isUndef())
323 continue;
324 RegisterRef R = { Op.getReg(), Op.getSubReg() };
325 if (TargetRegisterInfo::isPhysicalRegister(R.Reg) && Reserved[R.Reg])
326 continue;
327 bool IsKill = Op.isKill();
328 for (auto S : expandToSubRegs(R, MRI, TRI)) {
329 LastUse[S] = Index;
330 if (IsKill)
331 closeRange(S);
332 }
333 }
Krzysztof Parzyszek1aaf41a2017-02-17 22:14:51 +0000334 // Process defs and clobbers.
335 Defs.clear();
336 Clobbers.clear();
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +0000337 for (auto &Op : In.operands()) {
338 if (!Op.isReg() || !Op.isDef() || Op.isUndef())
339 continue;
340 RegisterRef R = { Op.getReg(), Op.getSubReg() };
Rafael Espindola6eab4042017-02-17 02:08:58 +0000341 for (auto S : expandToSubRegs(R, MRI, TRI)) {
Krzysztof Parzyszek1aaf41a2017-02-17 22:14:51 +0000342 if (TargetRegisterInfo::isPhysicalRegister(S.Reg) && Reserved[S.Reg])
343 continue;
344 if (Op.isDead())
345 Clobbers.insert(S);
346 else
347 Defs.insert(S);
Krzysztof Parzyszekfb9503c2017-02-16 20:25:23 +0000348 }
349 }
Krzysztof Parzyszek1aaf41a2017-02-17 22:14:51 +0000350
351 for (auto &Op : In.operands()) {
352 if (!Op.isRegMask())
353 continue;
354 const uint32_t *BM = Op.getRegMask();
355 for (unsigned PR = 1, N = TRI.getNumRegs(); PR != N; ++PR) {
356 // Skip registers that have subregisters. A register is preserved
357 // iff its bit is set in the regmask, so if R1:0 was preserved, both
358 // R1 and R0 would also be present.
359 if (MCSubRegIterator(PR, &TRI, false).isValid())
360 continue;
361 if (Reserved[PR])
362 continue;
363 if (BM[PR/32] & (1u << (PR%32)))
364 continue;
365 RegisterRef R = { PR, 0 };
366 if (!Defs.count(R))
367 Clobbers.insert(R);
368 }
369 }
Krzysztof Parzyszeke9be3552017-02-27 18:03:35 +0000370 // Defs and clobbers can overlap, e.g.
371 // %D0<def,dead> = COPY %vreg5, %R0<imp-def>, %R1<imp-def>
Krzysztof Parzyszek1aaf41a2017-02-17 22:14:51 +0000372 for (RegisterRef R : Defs)
Krzysztof Parzyszeke9be3552017-02-27 18:03:35 +0000373 Clobbers.erase(R);
374
Krzysztof Parzyszek1aaf41a2017-02-17 22:14:51 +0000375 // Update maps for defs.
376 for (RegisterRef S : Defs) {
377 // Defs should already be expanded into subregs.
378 assert(!TargetRegisterInfo::isPhysicalRegister(S.Reg) ||
379 !MCSubRegIterator(S.Reg, &TRI, false).isValid());
380 if (LastDef[S] != IndexType::None || LastUse[S] != IndexType::None)
381 closeRange(S);
382 LastDef[S] = Index;
383 }
384 // Update maps for clobbers.
385 for (RegisterRef S : Clobbers) {
386 // Clobbers should already be expanded into subregs.
387 assert(!TargetRegisterInfo::isPhysicalRegister(S.Reg) ||
388 !MCSubRegIterator(S.Reg, &TRI, false).isValid());
389 if (LastDef[S] != IndexType::None || LastUse[S] != IndexType::None)
390 closeRange(S);
391 // Create a single-instruction range.
392 LastDef[S] = LastUse[S] = Index;
393 closeRange(S);
394 }
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +0000395 }
396
397 // Collect live-on-exit.
398 RegisterSet LiveOnExit;
399 for (auto *SB : B.successors())
Krzysztof Parzyszek5bb417b2016-10-18 19:47:20 +0000400 for (auto R : getLiveIns(*SB, MRI, TRI))
401 LiveOnExit.insert(R);
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +0000402
403 for (auto R : LiveOnExit)
404 LastUse[R] = IndexType::Exit;
405
406 // Process remaining registers.
407 RegisterSet Left;
408 for (auto &I : LastUse)
409 if (I.second != IndexType::None)
410 Left.insert(I.first);
411 for (auto &I : LastDef)
412 if (I.second != IndexType::None)
413 Left.insert(I.first);
414 for (auto R : Left)
415 closeRange(R);
416
417 // Finalize the live ranges.
418 for (auto &P : LiveMap)
419 P.second.unionize();
420}
421
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +0000422HexagonBlockRanges::RegToRangeMap HexagonBlockRanges::computeLiveMap(
423 InstrIndexMap &IndexMap) {
424 RegToRangeMap LiveMap;
Reid Kleckner40d72302016-10-20 00:22:23 +0000425 DEBUG(dbgs() << __func__ << ": index map\n" << IndexMap << '\n');
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +0000426 computeInitialLiveRanges(IndexMap, LiveMap);
Reid Kleckner40d72302016-10-20 00:22:23 +0000427 DEBUG(dbgs() << __func__ << ": live map\n"
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +0000428 << PrintRangeMap(LiveMap, TRI) << '\n');
429 return LiveMap;
430}
431
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +0000432HexagonBlockRanges::RegToRangeMap HexagonBlockRanges::computeDeadMap(
433 InstrIndexMap &IndexMap, RegToRangeMap &LiveMap) {
434 RegToRangeMap DeadMap;
435
436 auto addDeadRanges = [&IndexMap,&LiveMap,&DeadMap] (RegisterRef R) -> void {
437 auto F = LiveMap.find(R);
438 if (F == LiveMap.end() || F->second.empty()) {
439 DeadMap[R].add(IndexType::Entry, IndexType::Exit, false, false);
440 return;
441 }
442
443 RangeList &RL = F->second;
444 RangeList::iterator A = RL.begin(), Z = RL.end()-1;
445
446 // Try to create the initial range.
447 if (A->start() != IndexType::Entry) {
448 IndexType DE = IndexMap.getPrevIndex(A->start());
449 if (DE != IndexType::Entry)
450 DeadMap[R].add(IndexType::Entry, DE, false, false);
451 }
452
453 while (A != Z) {
454 // Creating a dead range that follows A. Pay attention to empty
455 // ranges (i.e. those ending with "None").
456 IndexType AE = (A->end() == IndexType::None) ? A->start() : A->end();
457 IndexType DS = IndexMap.getNextIndex(AE);
458 ++A;
459 IndexType DE = IndexMap.getPrevIndex(A->start());
460 if (DS < DE)
461 DeadMap[R].add(DS, DE, false, false);
462 }
463
464 // Try to create the final range.
465 if (Z->end() != IndexType::Exit) {
466 IndexType ZE = (Z->end() == IndexType::None) ? Z->start() : Z->end();
467 IndexType DS = IndexMap.getNextIndex(ZE);
468 if (DS < IndexType::Exit)
469 DeadMap[R].add(DS, IndexType::Exit, false, false);
470 }
471 };
472
473 MachineFunction &MF = *IndexMap.getBlock().getParent();
474 auto &MRI = MF.getRegInfo();
475 unsigned NumRegs = TRI.getNumRegs();
476 BitVector Visited(NumRegs);
477 for (unsigned R = 1; R < NumRegs; ++R) {
478 for (auto S : expandToSubRegs({R,0}, MRI, TRI)) {
479 if (Reserved[S.Reg] || Visited[S.Reg])
480 continue;
481 addDeadRanges(S);
482 Visited[S.Reg] = true;
483 }
484 }
485 for (auto &P : LiveMap)
486 if (TargetRegisterInfo::isVirtualRegister(P.first.Reg))
487 addDeadRanges(P.first);
488
Reid Kleckner40d72302016-10-20 00:22:23 +0000489 DEBUG(dbgs() << __func__ << ": dead map\n"
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +0000490 << PrintRangeMap(DeadMap, TRI) << '\n');
491 return DeadMap;
492}
493
Benjamin Kramer922efd72016-05-27 10:06:40 +0000494raw_ostream &llvm::operator<<(raw_ostream &OS,
495 HexagonBlockRanges::IndexType Idx) {
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +0000496 if (Idx == HexagonBlockRanges::IndexType::None)
497 return OS << '-';
498 if (Idx == HexagonBlockRanges::IndexType::Entry)
499 return OS << 'n';
500 if (Idx == HexagonBlockRanges::IndexType::Exit)
501 return OS << 'x';
502 return OS << unsigned(Idx)-HexagonBlockRanges::IndexType::First+1;
503}
504
505// A mapping to translate between instructions and their indices.
Benjamin Kramer922efd72016-05-27 10:06:40 +0000506raw_ostream &llvm::operator<<(raw_ostream &OS,
507 const HexagonBlockRanges::IndexRange &IR) {
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +0000508 OS << '[' << IR.start() << ':' << IR.end() << (IR.TiedEnd ? '}' : ']');
509 if (IR.Fixed)
510 OS << '!';
511 return OS;
512}
513
Benjamin Kramer922efd72016-05-27 10:06:40 +0000514raw_ostream &llvm::operator<<(raw_ostream &OS,
515 const HexagonBlockRanges::RangeList &RL) {
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +0000516 for (auto &R : RL)
517 OS << R << " ";
518 return OS;
519}
520
Benjamin Kramer922efd72016-05-27 10:06:40 +0000521raw_ostream &llvm::operator<<(raw_ostream &OS,
522 const HexagonBlockRanges::InstrIndexMap &M) {
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +0000523 for (auto &In : M.Block) {
524 HexagonBlockRanges::IndexType Idx = M.getIndex(&In);
525 OS << Idx << (Idx == M.Last ? ". " : " ") << In;
526 }
527 return OS;
528}
529
Benjamin Kramer922efd72016-05-27 10:06:40 +0000530raw_ostream &llvm::operator<<(raw_ostream &OS,
531 const HexagonBlockRanges::PrintRangeMap &P) {
Krzysztof Parzyszek7793ddb2016-02-12 22:53:35 +0000532 for (auto &I : P.Map) {
533 const HexagonBlockRanges::RangeList &RL = I.second;
534 OS << PrintReg(I.first.Reg, &P.TRI, I.first.Sub) << " -> " << RL << "\n";
535 }
536 return OS;
537}