blob: ed0a62b99f245d344ee55ec2460b758ba55d2349 [file] [log] [blame]
Matthias Braunf8422972017-12-13 02:51:04 +00001//===- LiveIntervals.cpp - Live Interval Analysis -------------------------===//
Alkis Evlogimenos0e9ded72003-11-20 03:32:25 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Alkis Evlogimenos0e9ded72003-11-20 03:32:25 +00007//
8//===----------------------------------------------------------------------===//
9//
Matthias Braun9f21a8d2017-01-19 00:32:13 +000010/// \file This file implements the LiveInterval analysis pass which is used
11/// by the Linear Scan Register allocator. This pass linearizes the
12/// basic blocks of the function in DFS order and computes live intervals for
13/// each virtual and physical register.
Alkis Evlogimenos0e9ded72003-11-20 03:32:25 +000014//
15//===----------------------------------------------------------------------===//
16
Matthias Braunf8422972017-12-13 02:51:04 +000017#include "llvm/CodeGen/LiveIntervals.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000018#include "LiveRangeCalc.h"
Eugene Zelenko75480cc2017-05-24 23:10:29 +000019#include "llvm/ADT/ArrayRef.h"
20#include "llvm/ADT/DepthFirstIterator.h"
Eugene Zelenko75480cc2017-05-24 23:10:29 +000021#include "llvm/ADT/SmallPtrSet.h"
22#include "llvm/ADT/SmallVector.h"
Chandler Carruth6bda14b2017-06-06 11:49:48 +000023#include "llvm/ADT/iterator_range.h"
Dan Gohman09b04482008-07-25 00:02:30 +000024#include "llvm/Analysis/AliasAnalysis.h"
Eugene Zelenko75480cc2017-05-24 23:10:29 +000025#include "llvm/CodeGen/LiveInterval.h"
Alkis Evlogimenos0e9ded72003-11-20 03:32:25 +000026#include "llvm/CodeGen/LiveVariables.h"
Eugene Zelenko75480cc2017-05-24 23:10:29 +000027#include "llvm/CodeGen/MachineBasicBlock.h"
Michael Gottesman9f49d742013-12-14 00:53:32 +000028#include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
Jakob Stoklund Olesen12e03da2012-06-05 22:02:15 +000029#include "llvm/CodeGen/MachineDominators.h"
Eugene Zelenko75480cc2017-05-24 23:10:29 +000030#include "llvm/CodeGen/MachineFunction.h"
Alkis Evlogimenos0e9ded72003-11-20 03:32:25 +000031#include "llvm/CodeGen/MachineInstr.h"
Eugene Zelenko75480cc2017-05-24 23:10:29 +000032#include "llvm/CodeGen/MachineInstrBundle.h"
33#include "llvm/CodeGen/MachineOperand.h"
Chris Lattnera10fff52007-12-31 04:13:23 +000034#include "llvm/CodeGen/MachineRegisterInfo.h"
Alkis Evlogimenos0e9ded72003-11-20 03:32:25 +000035#include "llvm/CodeGen/Passes.h"
Eugene Zelenko75480cc2017-05-24 23:10:29 +000036#include "llvm/CodeGen/SlotIndexes.h"
David Blaikieb3bde2e2017-11-17 01:07:10 +000037#include "llvm/CodeGen/TargetRegisterInfo.h"
38#include "llvm/CodeGen/TargetSubtargetInfo.h"
Jakob Stoklund Olesen26c9d702012-11-28 19:13:06 +000039#include "llvm/CodeGen/VirtRegMap.h"
Nico Weber432a3882018-04-30 14:59:11 +000040#include "llvm/Config/llvm-config.h"
Eugene Zelenko75480cc2017-05-24 23:10:29 +000041#include "llvm/MC/LaneBitmask.h"
42#include "llvm/MC/MCRegisterInfo.h"
43#include "llvm/Pass.h"
Benjamin Kramere2a1d892013-06-17 19:00:36 +000044#include "llvm/Support/BlockFrequency.h"
Jakob Stoklund Olesen4021a7b2012-07-27 20:58:46 +000045#include "llvm/Support/CommandLine.h"
Eugene Zelenko75480cc2017-05-24 23:10:29 +000046#include "llvm/Support/Compiler.h"
Reid Spencer7c16caa2004-09-01 22:55:40 +000047#include "llvm/Support/Debug.h"
Eugene Zelenko75480cc2017-05-24 23:10:29 +000048#include "llvm/Support/MathExtras.h"
Torok Edwinccb29cd2009-07-11 13:10:19 +000049#include "llvm/Support/raw_ostream.h"
Alkis Evlogimenosa5c04ee2004-09-03 18:19:51 +000050#include <algorithm>
Eugene Zelenko75480cc2017-05-24 23:10:29 +000051#include <cassert>
52#include <cstdint>
53#include <iterator>
54#include <tuple>
55#include <utility>
56
Alkis Evlogimenos0e9ded72003-11-20 03:32:25 +000057using namespace llvm;
58
Chandler Carruth1b9dde02014-04-22 02:02:50 +000059#define DEBUG_TYPE "regalloc"
60
Devang Patel8c78a0b2007-05-03 01:11:54 +000061char LiveIntervals::ID = 0;
Jakob Stoklund Olesen1c465892012-08-03 22:12:54 +000062char &llvm::LiveIntervalsID = LiveIntervals::ID;
Owen Anderson8ac477f2010-10-12 19:48:12 +000063INITIALIZE_PASS_BEGIN(LiveIntervals, "liveintervals",
64 "Live Interval Analysis", false, false)
Chandler Carruth7b560d42015-09-09 17:55:00 +000065INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
Andrew Trickd3f8fe82012-02-10 04:10:36 +000066INITIALIZE_PASS_DEPENDENCY(MachineDominatorTree)
Owen Anderson8ac477f2010-10-12 19:48:12 +000067INITIALIZE_PASS_DEPENDENCY(SlotIndexes)
Owen Anderson8ac477f2010-10-12 19:48:12 +000068INITIALIZE_PASS_END(LiveIntervals, "liveintervals",
Owen Andersondf7a4f22010-10-07 22:25:06 +000069 "Live Interval Analysis", false, false)
Alkis Evlogimenos0e9ded72003-11-20 03:32:25 +000070
Andrew Trick8d02e912013-06-21 18:33:23 +000071#ifndef NDEBUG
72static cl::opt<bool> EnablePrecomputePhysRegs(
73 "precompute-phys-liveness", cl::Hidden,
74 cl::desc("Eagerly compute live intervals for all physreg units."));
75#else
76static bool EnablePrecomputePhysRegs = false;
77#endif // NDEBUG
78
Quentin Colombeta8cb36e2015-02-06 18:42:41 +000079namespace llvm {
Eugene Zelenko75480cc2017-05-24 23:10:29 +000080
Quentin Colombeta8cb36e2015-02-06 18:42:41 +000081cl::opt<bool> UseSegmentSetForPhysRegs(
82 "use-segment-set-for-physregs", cl::Hidden, cl::init(true),
83 cl::desc(
84 "Use segment set for the computation of the live ranges of physregs."));
Eugene Zelenko75480cc2017-05-24 23:10:29 +000085
86} // end namespace llvm
Quentin Colombeta8cb36e2015-02-06 18:42:41 +000087
Chris Lattnerbdf12102006-08-24 22:43:55 +000088void LiveIntervals::getAnalysisUsage(AnalysisUsage &AU) const {
Dan Gohman04023152009-07-31 23:37:33 +000089 AU.setPreservesCFG();
Chandler Carruth7b560d42015-09-09 17:55:00 +000090 AU.addRequired<AAResultsWrapperPass>();
91 AU.addPreserved<AAResultsWrapperPass>();
Evan Cheng16bfe5b2010-08-17 21:00:37 +000092 AU.addPreserved<LiveVariables>();
Andrew Trick5188c002012-02-13 20:44:42 +000093 AU.addPreservedID(MachineLoopInfoID);
Jakob Stoklund Olesen51c63e62012-06-20 23:31:34 +000094 AU.addRequiredTransitiveID(MachineDominatorsID);
Bill Wendling0c209432008-01-04 20:54:55 +000095 AU.addPreservedID(MachineDominatorsID);
Lang Hames05fb9632009-11-03 23:52:08 +000096 AU.addPreserved<SlotIndexes>();
97 AU.addRequiredTransitive<SlotIndexes>();
Alkis Evlogimenosa6983082004-08-04 09:46:26 +000098 MachineFunctionPass::getAnalysisUsage(AU);
Alkis Evlogimenos0e9ded72003-11-20 03:32:25 +000099}
100
Eugene Zelenko75480cc2017-05-24 23:10:29 +0000101LiveIntervals::LiveIntervals() : MachineFunctionPass(ID) {
Jakob Stoklund Olesen12e03da2012-06-05 22:02:15 +0000102 initializeLiveIntervalsPass(*PassRegistry::getPassRegistry());
103}
104
105LiveIntervals::~LiveIntervals() {
106 delete LRCalc;
107}
108
Chris Lattnerbdf12102006-08-24 22:43:55 +0000109void LiveIntervals::releaseMemory() {
Owen Anderson51f689a2008-08-13 21:49:13 +0000110 // Free the live intervals themselves.
Jakob Stoklund Olesenc61edda2012-06-22 20:37:52 +0000111 for (unsigned i = 0, e = VirtRegIntervals.size(); i != e; ++i)
112 delete VirtRegIntervals[TargetRegisterInfo::index2VirtReg(i)];
113 VirtRegIntervals.clear();
Jakob Stoklund Olesen3ff74d82012-02-08 17:33:45 +0000114 RegMaskSlots.clear();
115 RegMaskBits.clear();
Jakob Stoklund Olesen25c41952012-02-10 01:26:29 +0000116 RegMaskBlocks.clear();
Lang Hamesdab7b062009-07-09 03:57:02 +0000117
Matthias Braun9f21a8d2017-01-19 00:32:13 +0000118 for (LiveRange *LR : RegUnitRanges)
119 delete LR;
Matthias Braun34e1be92013-10-10 21:29:02 +0000120 RegUnitRanges.clear();
Jakob Stoklund Olesen12e03da2012-06-05 22:02:15 +0000121
Benjamin Kramera0000022010-06-26 11:30:59 +0000122 // Release VNInfo memory regions, VNInfo objects don't need to be dtor'd.
123 VNInfoAllocator.Reset();
Alkis Evlogimenos50d97e32004-01-31 19:59:32 +0000124}
125
Owen Anderson4f8e1ad2008-05-28 20:54:50 +0000126bool LiveIntervals::runOnMachineFunction(MachineFunction &fn) {
Jakob Stoklund Olesen11fb2482012-06-04 22:39:14 +0000127 MF = &fn;
128 MRI = &MF->getRegInfo();
Eric Christopherd3fa4402014-10-14 06:26:53 +0000129 TRI = MF->getSubtarget().getRegisterInfo();
130 TII = MF->getSubtarget().getInstrInfo();
Chandler Carruth7b560d42015-09-09 17:55:00 +0000131 AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
Jakob Stoklund Olesen11fb2482012-06-04 22:39:14 +0000132 Indexes = &getAnalysis<SlotIndexes>();
Jakob Stoklund Olesen51c63e62012-06-20 23:31:34 +0000133 DomTree = &getAnalysis<MachineDominatorTree>();
Matthias Braune3d3b882014-12-10 01:12:30 +0000134
Jakob Stoklund Olesen51c63e62012-06-20 23:31:34 +0000135 if (!LRCalc)
Jakob Stoklund Olesen12e03da2012-06-05 22:02:15 +0000136 LRCalc = new LiveRangeCalc();
Owen Anderson4f8e1ad2008-05-28 20:54:50 +0000137
Jakob Stoklund Olesen4021a7b2012-07-27 20:58:46 +0000138 // Allocate space for all virtual registers.
139 VirtRegIntervals.resize(MRI->getNumVirtRegs());
140
Jakob Stoklund Olesenfac770b2013-02-09 00:04:07 +0000141 computeVirtRegs();
142 computeRegMasks();
Jakob Stoklund Olesen51c63e62012-06-20 23:31:34 +0000143 computeLiveInRegUnits();
Jakob Stoklund Olesen12e03da2012-06-05 22:02:15 +0000144
Andrew Trick8d02e912013-06-21 18:33:23 +0000145 if (EnablePrecomputePhysRegs) {
146 // For stress testing, precompute live ranges of all physical register
147 // units, including reserved registers.
148 for (unsigned i = 0, e = TRI->getNumRegUnits(); i != e; ++i)
149 getRegUnit(i);
150 }
Chris Lattnerb0b707f2004-09-30 15:59:17 +0000151 DEBUG(dump());
Alkis Evlogimenosa6983082004-08-04 09:46:26 +0000152 return true;
Alkis Evlogimenos0e9ded72003-11-20 03:32:25 +0000153}
154
Chris Lattner13626022009-08-23 06:03:38 +0000155void LiveIntervals::print(raw_ostream &OS, const Module* ) const {
Chris Lattnera6f074f2009-08-23 03:41:05 +0000156 OS << "********** INTERVALS **********\n";
Jakob Stoklund Olesen20d25a72012-02-14 23:46:21 +0000157
Jakob Stoklund Olesen12e03da2012-06-05 22:02:15 +0000158 // Dump the regunits.
Matthias Braun9f21a8d2017-01-19 00:32:13 +0000159 for (unsigned Unit = 0, UnitE = RegUnitRanges.size(); Unit != UnitE; ++Unit)
160 if (LiveRange *LR = RegUnitRanges[Unit])
Francis Visoiu Mistrih9d419d32017-11-28 12:42:37 +0000161 OS << printRegUnit(Unit, TRI) << ' ' << *LR << '\n';
Jakob Stoklund Olesen12e03da2012-06-05 22:02:15 +0000162
Jakob Stoklund Olesen20d25a72012-02-14 23:46:21 +0000163 // Dump the virtregs.
Jakob Stoklund Olesenc61edda2012-06-22 20:37:52 +0000164 for (unsigned i = 0, e = MRI->getNumVirtRegs(); i != e; ++i) {
165 unsigned Reg = TargetRegisterInfo::index2VirtReg(i);
166 if (hasInterval(Reg))
Matthias Braunf6fe6bf2013-10-10 21:29:05 +0000167 OS << getInterval(Reg) << '\n';
Jakob Stoklund Olesenc61edda2012-06-22 20:37:52 +0000168 }
Chris Lattnerb0b707f2004-09-30 15:59:17 +0000169
Jakob Stoklund Olesen13d55622012-11-09 19:18:49 +0000170 OS << "RegMasks:";
Matthias Braun9f21a8d2017-01-19 00:32:13 +0000171 for (SlotIndex Idx : RegMaskSlots)
172 OS << ' ' << Idx;
Jakob Stoklund Olesen13d55622012-11-09 19:18:49 +0000173 OS << '\n';
174
Evan Cheng7f789592009-09-14 21:33:42 +0000175 printInstrs(OS);
176}
177
178void LiveIntervals::printInstrs(raw_ostream &OS) const {
Chris Lattnera6f074f2009-08-23 03:41:05 +0000179 OS << "********** MACHINEINSTRS **********\n";
Jakob Stoklund Olesen11fb2482012-06-04 22:39:14 +0000180 MF->print(OS, Indexes);
Chris Lattnerb0b707f2004-09-30 15:59:17 +0000181}
182
Aaron Ballman615eb472017-10-15 14:32:27 +0000183#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Matthias Braun8c209aa2017-01-28 02:02:38 +0000184LLVM_DUMP_METHOD void LiveIntervals::dumpInstrs() const {
David Greene1a51a212010-01-04 22:49:02 +0000185 printInstrs(dbgs());
Evan Cheng7f789592009-09-14 21:33:42 +0000186}
Manman Ren742534c2012-09-06 19:06:06 +0000187#endif
Evan Cheng7f789592009-09-14 21:33:42 +0000188
Owen Anderson51f689a2008-08-13 21:49:13 +0000189LiveInterval* LiveIntervals::createInterval(unsigned reg) {
Eugene Zelenko75480cc2017-05-24 23:10:29 +0000190 float Weight = TargetRegisterInfo::isPhysicalRegister(reg) ? huge_valf : 0.0F;
Owen Anderson51f689a2008-08-13 21:49:13 +0000191 return new LiveInterval(reg, Weight);
Alkis Evlogimenos237f2032004-04-09 18:07:57 +0000192}
Evan Chengbe51f282007-11-12 06:35:08 +0000193
Matthias Braun9f21a8d2017-01-19 00:32:13 +0000194/// Compute the live interval of a virtual register, based on defs and uses.
Matthias Braun2d5c32b2013-10-10 21:28:57 +0000195void LiveIntervals::computeVirtRegInterval(LiveInterval &LI) {
Jakob Stoklund Olesen4021a7b2012-07-27 20:58:46 +0000196 assert(LRCalc && "LRCalc not initialized.");
Matthias Braun2d5c32b2013-10-10 21:28:57 +0000197 assert(LI.empty() && "Should only compute empty intervals.");
Jakob Stoklund Olesen4021a7b2012-07-27 20:58:46 +0000198 LRCalc->reset(MF, getSlotIndexes(), DomTree, &getVNInfoAllocator());
Matthias Braune9631f12016-04-28 20:35:26 +0000199 LRCalc->calculate(LI, MRI->shouldTrackSubRegLiveness(LI.reg));
200 computeDeadValues(LI, nullptr);
Jakob Stoklund Olesen4021a7b2012-07-27 20:58:46 +0000201}
202
Jakob Stoklund Olesen7dfe7ab2012-07-27 21:56:39 +0000203void LiveIntervals::computeVirtRegs() {
204 for (unsigned i = 0, e = MRI->getNumVirtRegs(); i != e; ++i) {
205 unsigned Reg = TargetRegisterInfo::index2VirtReg(i);
206 if (MRI->reg_nodbg_empty(Reg))
207 continue;
Mark Lacey9d8103d2013-08-14 23:50:16 +0000208 createAndComputeVirtRegInterval(Reg);
Jakob Stoklund Olesen7dfe7ab2012-07-27 21:56:39 +0000209 }
210}
211
212void LiveIntervals::computeRegMasks() {
213 RegMaskBlocks.resize(MF->getNumBlockIDs());
214
215 // Find all instructions with regmask operands.
Matthias Braun9f21a8d2017-01-19 00:32:13 +0000216 for (const MachineBasicBlock &MBB : *MF) {
Reid Klecknere535c1f2015-11-06 02:01:02 +0000217 std::pair<unsigned, unsigned> &RMB = RegMaskBlocks[MBB.getNumber()];
Jakob Stoklund Olesen7dfe7ab2012-07-27 21:56:39 +0000218 RMB.first = RegMaskSlots.size();
Reid Klecknerb8fd1622015-11-06 17:06:38 +0000219
220 // Some block starts, such as EH funclets, create masks.
221 if (const uint32_t *Mask = MBB.getBeginClobberMask(TRI)) {
222 RegMaskSlots.push_back(Indexes->getMBBStartIdx(&MBB));
223 RegMaskBits.push_back(Mask);
224 }
225
Matthias Braun9f21a8d2017-01-19 00:32:13 +0000226 for (const MachineInstr &MI : MBB) {
Reid Klecknere535c1f2015-11-06 02:01:02 +0000227 for (const MachineOperand &MO : MI.operands()) {
Matthias Braune41e1462015-05-29 02:56:46 +0000228 if (!MO.isRegMask())
Jakob Stoklund Olesen7dfe7ab2012-07-27 21:56:39 +0000229 continue;
Duncan P. N. Exon Smith3ac9cc62016-02-27 06:40:41 +0000230 RegMaskSlots.push_back(Indexes->getInstructionIndex(MI).getRegSlot());
Reid Klecknere535c1f2015-11-06 02:01:02 +0000231 RegMaskBits.push_back(MO.getRegMask());
Jakob Stoklund Olesen7dfe7ab2012-07-27 21:56:39 +0000232 }
Reid Klecknere535c1f2015-11-06 02:01:02 +0000233 }
Reid Klecknerb8fd1622015-11-06 17:06:38 +0000234
Reid Kleckner70c9bc72016-02-26 16:53:19 +0000235 // Some block ends, such as funclet returns, create masks. Put the mask on
236 // the last instruction of the block, because MBB slot index intervals are
237 // half-open.
Reid Klecknerb8fd1622015-11-06 17:06:38 +0000238 if (const uint32_t *Mask = MBB.getEndClobberMask(TRI)) {
Reid Kleckner70c9bc72016-02-26 16:53:19 +0000239 assert(!MBB.empty() && "empty return block?");
240 RegMaskSlots.push_back(
Duncan P. N. Exon Smith3ac9cc62016-02-27 06:40:41 +0000241 Indexes->getInstructionIndex(MBB.back()).getRegSlot());
Reid Klecknerb8fd1622015-11-06 17:06:38 +0000242 RegMaskBits.push_back(Mask);
243 }
244
Jakob Stoklund Olesen7dfe7ab2012-07-27 21:56:39 +0000245 // Compute the number of register mask instructions in this block.
Dmitri Gribenkoca1e27b2012-09-10 21:26:47 +0000246 RMB.second = RegMaskSlots.size() - RMB.first;
Jakob Stoklund Olesen7dfe7ab2012-07-27 21:56:39 +0000247 }
248}
Jakob Stoklund Olesen4021a7b2012-07-27 20:58:46 +0000249
Jakob Stoklund Olesen12e03da2012-06-05 22:02:15 +0000250//===----------------------------------------------------------------------===//
251// Register Unit Liveness
252//===----------------------------------------------------------------------===//
253//
254// Fixed interference typically comes from ABI boundaries: Function arguments
255// and return values are passed in fixed registers, and so are exception
256// pointers entering landing pads. Certain instructions require values to be
257// present in specific registers. That is also represented through fixed
258// interference.
259//
260
Matthias Braun9f21a8d2017-01-19 00:32:13 +0000261/// Compute the live range of a register unit, based on the uses and defs of
262/// aliasing registers. The range should be empty, or contain only dead
263/// phi-defs from ABI blocks.
Matthias Braun34e1be92013-10-10 21:29:02 +0000264void LiveIntervals::computeRegUnitRange(LiveRange &LR, unsigned Unit) {
Jakob Stoklund Olesen12e03da2012-06-05 22:02:15 +0000265 assert(LRCalc && "LRCalc not initialized.");
266 LRCalc->reset(MF, getSlotIndexes(), DomTree, &getVNInfoAllocator());
267
268 // The physregs aliasing Unit are the roots and their super-registers.
269 // Create all values as dead defs before extending to uses. Note that roots
270 // may share super-registers. That's OK because createDeadDefs() is
271 // idempotent. It is very rare for a register unit to have multiple roots, so
272 // uniquing super-registers is probably not worthwhile.
Matthias Brauncebdb172017-09-01 18:36:26 +0000273 bool IsReserved = false;
Matthias Braun9f21a8d2017-01-19 00:32:13 +0000274 for (MCRegUnitRootIterator Root(Unit, TRI); Root.isValid(); ++Root) {
Matthias Brauncebdb172017-09-01 18:36:26 +0000275 bool IsRootReserved = true;
Matthias Braun9f21a8d2017-01-19 00:32:13 +0000276 for (MCSuperRegIterator Super(*Root, TRI, /*IncludeSelf=*/true);
277 Super.isValid(); ++Super) {
278 unsigned Reg = *Super;
279 if (!MRI->reg_empty(Reg))
280 LRCalc->createDeadDefs(LR, Reg);
Matthias Braunb901d332017-01-24 01:12:58 +0000281 // A register unit is considered reserved if all its roots and all their
282 // super registers are reserved.
283 if (!MRI->isReserved(Reg))
Matthias Brauncebdb172017-09-01 18:36:26 +0000284 IsRootReserved = false;
Matthias Braunc3a72c22014-12-15 21:36:35 +0000285 }
Matthias Brauncebdb172017-09-01 18:36:26 +0000286 IsReserved |= IsRootReserved;
Matthias Braunc3a72c22014-12-15 21:36:35 +0000287 }
Matthias Brauncebdb172017-09-01 18:36:26 +0000288 assert(IsReserved == MRI->isReservedRegUnit(Unit) &&
289 "reserved computation mismatch");
Matthias Braunc3a72c22014-12-15 21:36:35 +0000290
291 // Now extend LR to reach all uses.
292 // Ignore uses of reserved registers. We only track defs of those.
Matthias Braunb901d332017-01-24 01:12:58 +0000293 if (!IsReserved) {
294 for (MCRegUnitRootIterator Root(Unit, TRI); Root.isValid(); ++Root) {
295 for (MCSuperRegIterator Super(*Root, TRI, /*IncludeSelf=*/true);
296 Super.isValid(); ++Super) {
297 unsigned Reg = *Super;
298 if (!MRI->reg_empty(Reg))
299 LRCalc->extendToUses(LR, Reg);
300 }
Jakob Stoklund Olesen12e03da2012-06-05 22:02:15 +0000301 }
302 }
Quentin Colombeta8cb36e2015-02-06 18:42:41 +0000303
304 // Flush the segment set to the segment vector.
305 if (UseSegmentSetForPhysRegs)
306 LR.flushSegmentSet();
Jakob Stoklund Olesen12e03da2012-06-05 22:02:15 +0000307}
308
Matthias Braun9f21a8d2017-01-19 00:32:13 +0000309/// Precompute the live ranges of any register units that are live-in to an ABI
310/// block somewhere. Register values can appear without a corresponding def when
311/// entering the entry block or a landing pad.
Jakob Stoklund Olesen12e03da2012-06-05 22:02:15 +0000312void LiveIntervals::computeLiveInRegUnits() {
Matthias Braun34e1be92013-10-10 21:29:02 +0000313 RegUnitRanges.resize(TRI->getNumRegUnits());
Jakob Stoklund Olesen12e03da2012-06-05 22:02:15 +0000314 DEBUG(dbgs() << "Computing live-in reg-units in ABI blocks.\n");
315
Matthias Braun34e1be92013-10-10 21:29:02 +0000316 // Keep track of the live range sets allocated.
317 SmallVector<unsigned, 8> NewRanges;
Jakob Stoklund Olesen12e03da2012-06-05 22:02:15 +0000318
319 // Check all basic blocks for live-ins.
Matthias Braun9f21a8d2017-01-19 00:32:13 +0000320 for (const MachineBasicBlock &MBB : *MF) {
Jakob Stoklund Olesen12e03da2012-06-05 22:02:15 +0000321 // We only care about ABI blocks: Entry + landing pads.
Matthias Braun9f21a8d2017-01-19 00:32:13 +0000322 if ((&MBB != &MF->front() && !MBB.isEHPad()) || MBB.livein_empty())
Jakob Stoklund Olesen12e03da2012-06-05 22:02:15 +0000323 continue;
324
325 // Create phi-defs at Begin for all live-in registers.
Matthias Braun9f21a8d2017-01-19 00:32:13 +0000326 SlotIndex Begin = Indexes->getMBBStartIdx(&MBB);
Francis Visoiu Mistrih25528d62017-12-04 17:18:51 +0000327 DEBUG(dbgs() << Begin << "\t" << printMBBReference(MBB));
Matthias Braun9f21a8d2017-01-19 00:32:13 +0000328 for (const auto &LI : MBB.liveins()) {
Matthias Braund9da1622015-09-09 18:08:03 +0000329 for (MCRegUnitIterator Units(LI.PhysReg, TRI); Units.isValid(); ++Units) {
Jakob Stoklund Olesen12e03da2012-06-05 22:02:15 +0000330 unsigned Unit = *Units;
Matthias Braun34e1be92013-10-10 21:29:02 +0000331 LiveRange *LR = RegUnitRanges[Unit];
332 if (!LR) {
Quentin Colombeta8cb36e2015-02-06 18:42:41 +0000333 // Use segment set to speed-up initial computation of the live range.
334 LR = RegUnitRanges[Unit] = new LiveRange(UseSegmentSetForPhysRegs);
Matthias Braun34e1be92013-10-10 21:29:02 +0000335 NewRanges.push_back(Unit);
Jakob Stoklund Olesen12e03da2012-06-05 22:02:15 +0000336 }
Matthias Braun34e1be92013-10-10 21:29:02 +0000337 VNInfo *VNI = LR->createDeadDef(Begin, getVNInfoAllocator());
Matt Beaumont-Gay7ba769b2012-06-05 23:00:03 +0000338 (void)VNI;
Francis Visoiu Mistrih9d419d32017-11-28 12:42:37 +0000339 DEBUG(dbgs() << ' ' << printRegUnit(Unit, TRI) << '#' << VNI->id);
Jakob Stoklund Olesen12e03da2012-06-05 22:02:15 +0000340 }
341 }
342 DEBUG(dbgs() << '\n');
343 }
Matthias Braun34e1be92013-10-10 21:29:02 +0000344 DEBUG(dbgs() << "Created " << NewRanges.size() << " new intervals.\n");
Jakob Stoklund Olesen12e03da2012-06-05 22:02:15 +0000345
Matthias Braun34e1be92013-10-10 21:29:02 +0000346 // Compute the 'normal' part of the ranges.
Matthias Braun9f21a8d2017-01-19 00:32:13 +0000347 for (unsigned Unit : NewRanges)
Matthias Braun34e1be92013-10-10 21:29:02 +0000348 computeRegUnitRange(*RegUnitRanges[Unit], Unit);
Jakob Stoklund Olesen12e03da2012-06-05 22:02:15 +0000349}
350
Matthias Braun20e1f382014-12-10 01:12:18 +0000351static void createSegmentsForValues(LiveRange &LR,
Matthias Braun9f21a8d2017-01-19 00:32:13 +0000352 iterator_range<LiveInterval::vni_iterator> VNIs) {
353 for (VNInfo *VNI : VNIs) {
Matthias Braun20e1f382014-12-10 01:12:18 +0000354 if (VNI->isUnused())
355 continue;
356 SlotIndex Def = VNI->def;
357 LR.addSegment(LiveRange::Segment(Def, Def.getDeadSlot(), VNI));
358 }
359}
360
Eugene Zelenko75480cc2017-05-24 23:10:29 +0000361using ShrinkToUsesWorkList = SmallVector<std::pair<SlotIndex, VNInfo*>, 16>;
Matthias Braun20e1f382014-12-10 01:12:18 +0000362
363static void extendSegmentsToUses(LiveRange &LR, const SlotIndexes &Indexes,
364 ShrinkToUsesWorkList &WorkList,
365 const LiveRange &OldRange) {
366 // Keep track of the PHIs that are in use.
367 SmallPtrSet<VNInfo*, 8> UsedPHIs;
368 // Blocks that have already been added to WorkList as live-out.
Matthias Braun9f21a8d2017-01-19 00:32:13 +0000369 SmallPtrSet<const MachineBasicBlock*, 16> LiveOut;
Matthias Braun20e1f382014-12-10 01:12:18 +0000370
371 // Extend intervals to reach all uses in WorkList.
372 while (!WorkList.empty()) {
373 SlotIndex Idx = WorkList.back().first;
374 VNInfo *VNI = WorkList.back().second;
375 WorkList.pop_back();
376 const MachineBasicBlock *MBB = Indexes.getMBBFromIndex(Idx.getPrevSlot());
377 SlotIndex BlockStart = Indexes.getMBBStartIdx(MBB);
378
379 // Extend the live range for VNI to be live at Idx.
380 if (VNInfo *ExtVNI = LR.extendInBlock(BlockStart, Idx)) {
381 assert(ExtVNI == VNI && "Unexpected existing value number");
382 (void)ExtVNI;
383 // Is this a PHIDef we haven't seen before?
384 if (!VNI->isPHIDef() || VNI->def != BlockStart ||
385 !UsedPHIs.insert(VNI).second)
386 continue;
387 // The PHI is live, make sure the predecessors are live-out.
Matthias Braun9f21a8d2017-01-19 00:32:13 +0000388 for (const MachineBasicBlock *Pred : MBB->predecessors()) {
Matthias Braun20e1f382014-12-10 01:12:18 +0000389 if (!LiveOut.insert(Pred).second)
390 continue;
391 SlotIndex Stop = Indexes.getMBBEndIdx(Pred);
392 // A predecessor is not required to have a live-out value for a PHI.
393 if (VNInfo *PVNI = OldRange.getVNInfoBefore(Stop))
394 WorkList.push_back(std::make_pair(Stop, PVNI));
395 }
396 continue;
397 }
398
399 // VNI is live-in to MBB.
400 DEBUG(dbgs() << " live-in at " << BlockStart << '\n');
401 LR.addSegment(LiveRange::Segment(BlockStart, Idx, VNI));
402
403 // Make sure VNI is live-out from the predecessors.
Matthias Braun9f21a8d2017-01-19 00:32:13 +0000404 for (const MachineBasicBlock *Pred : MBB->predecessors()) {
Matthias Braun20e1f382014-12-10 01:12:18 +0000405 if (!LiveOut.insert(Pred).second)
406 continue;
407 SlotIndex Stop = Indexes.getMBBEndIdx(Pred);
408 assert(OldRange.getVNInfoBefore(Stop) == VNI &&
409 "Wrong value out of predecessor");
410 WorkList.push_back(std::make_pair(Stop, VNI));
411 }
412 }
413}
414
Jakob Stoklund Olesen86308402011-03-17 20:37:07 +0000415bool LiveIntervals::shrinkToUses(LiveInterval *li,
Jakob Stoklund Olesen71c380f2011-03-07 23:29:10 +0000416 SmallVectorImpl<MachineInstr*> *dead) {
Jakob Stoklund Olesen55fc1d02011-02-08 00:03:05 +0000417 DEBUG(dbgs() << "Shrink: " << *li << '\n');
418 assert(TargetRegisterInfo::isVirtualRegister(li->reg)
Lang Hamesc405ac42012-01-03 20:05:57 +0000419 && "Can only shrink virtual registers");
Jakob Stoklund Olesen55fc1d02011-02-08 00:03:05 +0000420
Matthias Braun20e1f382014-12-10 01:12:18 +0000421 // Shrink subregister live ranges.
Matthias Braun0d4cebd2015-07-16 18:55:35 +0000422 bool NeedsCleanup = false;
Matthias Braun09afa1e2014-12-11 00:59:06 +0000423 for (LiveInterval::SubRange &S : li->subranges()) {
424 shrinkToUses(S, li->reg);
Matthias Braun0d4cebd2015-07-16 18:55:35 +0000425 if (S.empty())
426 NeedsCleanup = true;
Matthias Braun20e1f382014-12-10 01:12:18 +0000427 }
Matthias Braun0d4cebd2015-07-16 18:55:35 +0000428 if (NeedsCleanup)
429 li->removeEmptySubRanges();
Matthias Braun20e1f382014-12-10 01:12:18 +0000430
431 // Find all the values used, including PHI kills.
432 ShrinkToUsesWorkList WorkList;
Jakob Stoklund Olesenb8b1d4c2011-09-15 15:24:16 +0000433
Jakob Stoklund Olesen55fc1d02011-02-08 00:03:05 +0000434 // Visit all instructions reading li->reg.
Matthias Braun9f21a8d2017-01-19 00:32:13 +0000435 unsigned Reg = li->reg;
436 for (MachineInstr &UseMI : MRI->reg_instructions(Reg)) {
437 if (UseMI.isDebugValue() || !UseMI.readsVirtualRegister(Reg))
Jakob Stoklund Olesen55fc1d02011-02-08 00:03:05 +0000438 continue;
Matthias Braun9f21a8d2017-01-19 00:32:13 +0000439 SlotIndex Idx = getInstructionIndex(UseMI).getRegSlot();
Matthias Braun88dd0ab2013-10-10 21:28:52 +0000440 LiveQueryResult LRQ = li->Query(Idx);
Jakob Stoklund Olesen02d83e32012-05-20 02:54:52 +0000441 VNInfo *VNI = LRQ.valueIn();
Jakob Stoklund Olesenfdc09942011-03-18 03:06:04 +0000442 if (!VNI) {
443 // This shouldn't happen: readsVirtualRegister returns true, but there is
444 // no live value. It is likely caused by a target getting <undef> flags
445 // wrong.
Matthias Braun9f21a8d2017-01-19 00:32:13 +0000446 DEBUG(dbgs() << Idx << '\t' << UseMI
Jakob Stoklund Olesenfdc09942011-03-18 03:06:04 +0000447 << "Warning: Instr claims to read non-existent value in "
Matthias Braun9f21a8d2017-01-19 00:32:13 +0000448 << *li << '\n');
Jakob Stoklund Olesenfdc09942011-03-18 03:06:04 +0000449 continue;
450 }
Jakob Stoklund Olesen7e6004a2011-11-14 18:45:38 +0000451 // Special case: An early-clobber tied operand reads and writes the
Jakob Stoklund Olesen02d83e32012-05-20 02:54:52 +0000452 // register one slot early.
453 if (VNInfo *DefVNI = LRQ.valueDefined())
454 Idx = DefVNI->def;
455
Jakob Stoklund Olesen55fc1d02011-02-08 00:03:05 +0000456 WorkList.push_back(std::make_pair(Idx, VNI));
457 }
458
Matthias Braund7df9352013-10-10 21:28:47 +0000459 // Create new live ranges with only minimal live segments per def.
460 LiveRange NewLR;
Matthias Braun20e1f382014-12-10 01:12:18 +0000461 createSegmentsForValues(NewLR, make_range(li->vni_begin(), li->vni_end()));
462 extendSegmentsToUses(NewLR, *Indexes, WorkList, *li);
Jakob Stoklund Olesen55fc1d02011-02-08 00:03:05 +0000463
Pete Cooper72235572014-06-03 22:42:10 +0000464 // Move the trimmed segments back.
465 li->segments.swap(NewLR.segments);
Matthias Braun15abf372014-12-18 19:58:52 +0000466
467 // Handle dead values.
468 bool CanSeparate = computeDeadValues(*li, dead);
Pete Cooper72235572014-06-03 22:42:10 +0000469 DEBUG(dbgs() << "Shrunk: " << *li << '\n');
470 return CanSeparate;
471}
472
Matthias Braun15abf372014-12-18 19:58:52 +0000473bool LiveIntervals::computeDeadValues(LiveInterval &LI,
Pete Cooper72235572014-06-03 22:42:10 +0000474 SmallVectorImpl<MachineInstr*> *dead) {
Matthias Braun73e42212015-09-22 22:37:44 +0000475 bool MayHaveSplitComponents = false;
Matthias Braun9f21a8d2017-01-19 00:32:13 +0000476 for (VNInfo *VNI : LI.valnos) {
Jakob Stoklund Olesen55fc1d02011-02-08 00:03:05 +0000477 if (VNI->isUnused())
478 continue;
Matthias Braunc1988f32015-01-21 22:55:13 +0000479 SlotIndex Def = VNI->def;
480 LiveRange::iterator I = LI.FindSegmentContaining(Def);
Matthias Braun15abf372014-12-18 19:58:52 +0000481 assert(I != LI.end() && "Missing segment for VNI");
Matthias Braunc1988f32015-01-21 22:55:13 +0000482
483 // Is the register live before? Otherwise we may have to add a read-undef
484 // flag for subregister defs.
Matthias Braun73e42212015-09-22 22:37:44 +0000485 unsigned VReg = LI.reg;
486 if (MRI->shouldTrackSubRegLiveness(VReg)) {
Matthias Braunc1988f32015-01-21 22:55:13 +0000487 if ((I == LI.begin() || std::prev(I)->end < Def) && !VNI->isPHIDef()) {
488 MachineInstr *MI = getInstructionFromIndex(Def);
Matthias Braun2c98d0f2015-11-11 00:41:58 +0000489 MI->setRegisterDefReadUndef(VReg);
Matthias Braunc1988f32015-01-21 22:55:13 +0000490 }
491 }
492
493 if (I->end != Def.getDeadSlot())
Jakob Stoklund Olesen55fc1d02011-02-08 00:03:05 +0000494 continue;
Jakob Stoklund Olesen81eb18d2011-03-02 00:33:01 +0000495 if (VNI->isPHIDef()) {
Jakob Stoklund Olesen55fc1d02011-02-08 00:03:05 +0000496 // This is a dead PHI. Remove it.
Jakob Stoklund Olesendaae19f2012-08-03 20:59:32 +0000497 VNI->markUnused();
Matthias Braun15abf372014-12-18 19:58:52 +0000498 LI.removeSegment(I);
Matthias Braunc1988f32015-01-21 22:55:13 +0000499 DEBUG(dbgs() << "Dead PHI at " << Def << " may separate interval\n");
Matthias Braun73e42212015-09-22 22:37:44 +0000500 MayHaveSplitComponents = true;
Matthias Braun15abf372014-12-18 19:58:52 +0000501 } else {
Jakob Stoklund Olesen55fc1d02011-02-08 00:03:05 +0000502 // This is a dead def. Make sure the instruction knows.
Matthias Braunc1988f32015-01-21 22:55:13 +0000503 MachineInstr *MI = getInstructionFromIndex(Def);
Jakob Stoklund Olesen55fc1d02011-02-08 00:03:05 +0000504 assert(MI && "No instruction defining live value");
Matthias Braune9631f12016-04-28 20:35:26 +0000505 MI->addRegisterDead(LI.reg, TRI);
Jakob Stoklund Olesen71c380f2011-03-07 23:29:10 +0000506 if (dead && MI->allDefsAreDead()) {
Matthias Braunc1988f32015-01-21 22:55:13 +0000507 DEBUG(dbgs() << "All defs dead: " << Def << '\t' << *MI);
Jakob Stoklund Olesen71c380f2011-03-07 23:29:10 +0000508 dead->push_back(MI);
509 }
Jakob Stoklund Olesen55fc1d02011-02-08 00:03:05 +0000510 }
511 }
Matthias Braun73e42212015-09-22 22:37:44 +0000512 return MayHaveSplitComponents;
Matthias Braun20e1f382014-12-10 01:12:18 +0000513}
514
Krzysztof Parzyszeka7ed0902016-08-24 13:37:55 +0000515void LiveIntervals::shrinkToUses(LiveInterval::SubRange &SR, unsigned Reg) {
Matthias Braun20e1f382014-12-10 01:12:18 +0000516 DEBUG(dbgs() << "Shrink: " << SR << '\n');
517 assert(TargetRegisterInfo::isVirtualRegister(Reg)
518 && "Can only shrink virtual registers");
519 // Find all the values used, including PHI kills.
520 ShrinkToUsesWorkList WorkList;
521
522 // Visit all instructions reading Reg.
523 SlotIndex LastIdx;
Krzysztof Parzyszek3bf4aec2016-09-02 19:48:55 +0000524 for (MachineOperand &MO : MRI->use_nodbg_operands(Reg)) {
525 // Skip "undef" uses.
526 if (!MO.readsReg())
Matthias Braun20e1f382014-12-10 01:12:18 +0000527 continue;
528 // Maybe the operand is for a subregister we don't care about.
529 unsigned SubReg = MO.getSubReg();
530 if (SubReg != 0) {
Matthias Braune6a24852015-09-25 21:51:14 +0000531 LaneBitmask LaneMask = TRI->getSubRegIndexLaneMask(SubReg);
Krzysztof Parzyszek91b5cf82016-12-15 14:36:06 +0000532 if ((LaneMask & SR.LaneMask).none())
Matthias Braun20e1f382014-12-10 01:12:18 +0000533 continue;
534 }
535 // We only need to visit each instruction once.
Krzysztof Parzyszek3bf4aec2016-09-02 19:48:55 +0000536 MachineInstr *UseMI = MO.getParent();
Duncan P. N. Exon Smith3ac9cc62016-02-27 06:40:41 +0000537 SlotIndex Idx = getInstructionIndex(*UseMI).getRegSlot();
Matthias Braun20e1f382014-12-10 01:12:18 +0000538 if (Idx == LastIdx)
539 continue;
540 LastIdx = Idx;
541
542 LiveQueryResult LRQ = SR.Query(Idx);
543 VNInfo *VNI = LRQ.valueIn();
544 // For Subranges it is possible that only undef values are left in that
545 // part of the subregister, so there is no real liverange at the use
546 if (!VNI)
547 continue;
548
549 // Special case: An early-clobber tied operand reads and writes the
550 // register one slot early.
551 if (VNInfo *DefVNI = LRQ.valueDefined())
552 Idx = DefVNI->def;
553
554 WorkList.push_back(std::make_pair(Idx, VNI));
555 }
556
557 // Create a new live ranges with only minimal live segments per def.
558 LiveRange NewLR;
559 createSegmentsForValues(NewLR, make_range(SR.vni_begin(), SR.vni_end()));
560 extendSegmentsToUses(NewLR, *Indexes, WorkList, SR);
561
Matthias Braun20e1f382014-12-10 01:12:18 +0000562 // Move the trimmed ranges back.
563 SR.segments.swap(NewLR.segments);
Matthias Braun15abf372014-12-18 19:58:52 +0000564
565 // Remove dead PHI value numbers
Matthias Braun9f21a8d2017-01-19 00:32:13 +0000566 for (VNInfo *VNI : SR.valnos) {
Matthias Braun15abf372014-12-18 19:58:52 +0000567 if (VNI->isUnused())
568 continue;
569 const LiveRange::Segment *Segment = SR.getSegmentContaining(VNI->def);
570 assert(Segment != nullptr && "Missing segment for VNI");
571 if (Segment->end != VNI->def.getDeadSlot())
572 continue;
573 if (VNI->isPHIDef()) {
574 // This is a dead PHI. Remove it.
Krzysztof Parzyszek98c0f482016-07-12 17:55:28 +0000575 DEBUG(dbgs() << "Dead PHI at " << VNI->def << " may separate interval\n");
Matthias Braun15abf372014-12-18 19:58:52 +0000576 VNI->markUnused();
577 SR.removeSegment(*Segment);
Matthias Braun15abf372014-12-18 19:58:52 +0000578 }
579 }
580
Matthias Braun20e1f382014-12-10 01:12:18 +0000581 DEBUG(dbgs() << "Shrunk: " << SR << '\n');
Jakob Stoklund Olesen55fc1d02011-02-08 00:03:05 +0000582}
583
Matthias Braun2d5c32b2013-10-10 21:28:57 +0000584void LiveIntervals::extendToIndices(LiveRange &LR,
Krzysztof Parzyszek4f863d72016-09-01 12:10:36 +0000585 ArrayRef<SlotIndex> Indices,
586 ArrayRef<SlotIndex> Undefs) {
Jakob Stoklund Olesen0bb3dd72012-09-17 23:03:25 +0000587 assert(LRCalc && "LRCalc not initialized.");
588 LRCalc->reset(MF, getSlotIndexes(), DomTree, &getVNInfoAllocator());
Matthias Braun9f21a8d2017-01-19 00:32:13 +0000589 for (SlotIndex Idx : Indices)
590 LRCalc->extend(LR, Idx, /*PhysReg=*/0, Undefs);
Jakob Stoklund Olesen0bb3dd72012-09-17 23:03:25 +0000591}
592
Matthias Braun8970d842014-12-10 01:12:36 +0000593void LiveIntervals::pruneValue(LiveRange &LR, SlotIndex Kill,
Jakob Stoklund Olesen0bb3dd72012-09-17 23:03:25 +0000594 SmallVectorImpl<SlotIndex> *EndPoints) {
Matthias Braun8970d842014-12-10 01:12:36 +0000595 LiveQueryResult LRQ = LR.Query(Kill);
596 VNInfo *VNI = LRQ.valueOutOrDead();
Jakob Stoklund Olesen0bb3dd72012-09-17 23:03:25 +0000597 if (!VNI)
598 return;
599
600 MachineBasicBlock *KillMBB = Indexes->getMBBFromIndex(Kill);
Matthias Braun8970d842014-12-10 01:12:36 +0000601 SlotIndex MBBEnd = Indexes->getMBBEndIdx(KillMBB);
Jakob Stoklund Olesen0bb3dd72012-09-17 23:03:25 +0000602
603 // If VNI isn't live out from KillMBB, the value is trivially pruned.
604 if (LRQ.endPoint() < MBBEnd) {
Matthias Braun8970d842014-12-10 01:12:36 +0000605 LR.removeSegment(Kill, LRQ.endPoint());
Jakob Stoklund Olesen0bb3dd72012-09-17 23:03:25 +0000606 if (EndPoints) EndPoints->push_back(LRQ.endPoint());
607 return;
608 }
609
610 // VNI is live out of KillMBB.
Matthias Braun8970d842014-12-10 01:12:36 +0000611 LR.removeSegment(Kill, MBBEnd);
Jakob Stoklund Olesen0bb3dd72012-09-17 23:03:25 +0000612 if (EndPoints) EndPoints->push_back(MBBEnd);
613
Jakob Stoklund Olesen2f6dfc72012-10-13 16:15:31 +0000614 // Find all blocks that are reachable from KillMBB without leaving VNI's live
615 // range. It is possible that KillMBB itself is reachable, so start a DFS
616 // from each successor.
Eugene Zelenko75480cc2017-05-24 23:10:29 +0000617 using VisitedTy = df_iterator_default_set<MachineBasicBlock*,9>;
Jakob Stoklund Olesen2f6dfc72012-10-13 16:15:31 +0000618 VisitedTy Visited;
Matthias Braun9f21a8d2017-01-19 00:32:13 +0000619 for (MachineBasicBlock *Succ : KillMBB->successors()) {
Jakob Stoklund Olesen2f6dfc72012-10-13 16:15:31 +0000620 for (df_ext_iterator<MachineBasicBlock*, VisitedTy>
Matthias Braun9f21a8d2017-01-19 00:32:13 +0000621 I = df_ext_begin(Succ, Visited), E = df_ext_end(Succ, Visited);
Jakob Stoklund Olesen2f6dfc72012-10-13 16:15:31 +0000622 I != E;) {
623 MachineBasicBlock *MBB = *I;
624
625 // Check if VNI is live in to MBB.
Matthias Braun8970d842014-12-10 01:12:36 +0000626 SlotIndex MBBStart, MBBEnd;
Benjamin Kramerd6f1f842014-03-02 13:30:33 +0000627 std::tie(MBBStart, MBBEnd) = Indexes->getMBBRange(MBB);
Matthias Braun8970d842014-12-10 01:12:36 +0000628 LiveQueryResult LRQ = LR.Query(MBBStart);
Jakob Stoklund Olesen2f6dfc72012-10-13 16:15:31 +0000629 if (LRQ.valueIn() != VNI) {
Matthias Braun13ddb7c2013-10-10 21:28:43 +0000630 // This block isn't part of the VNI segment. Prune the search.
Jakob Stoklund Olesen2f6dfc72012-10-13 16:15:31 +0000631 I.skipChildren();
632 continue;
633 }
634
635 // Prune the search if VNI is killed in MBB.
636 if (LRQ.endPoint() < MBBEnd) {
Matthias Braun8970d842014-12-10 01:12:36 +0000637 LR.removeSegment(MBBStart, LRQ.endPoint());
Jakob Stoklund Olesen2f6dfc72012-10-13 16:15:31 +0000638 if (EndPoints) EndPoints->push_back(LRQ.endPoint());
639 I.skipChildren();
640 continue;
641 }
642
643 // VNI is live through MBB.
Matthias Braun8970d842014-12-10 01:12:36 +0000644 LR.removeSegment(MBBStart, MBBEnd);
Jakob Stoklund Olesen2f6dfc72012-10-13 16:15:31 +0000645 if (EndPoints) EndPoints->push_back(MBBEnd);
Jakob Stoklund Olesen0bb3dd72012-09-17 23:03:25 +0000646 ++I;
Jakob Stoklund Olesen0bb3dd72012-09-17 23:03:25 +0000647 }
Jakob Stoklund Olesen0bb3dd72012-09-17 23:03:25 +0000648 }
649}
Jakob Stoklund Olesen55fc1d02011-02-08 00:03:05 +0000650
Evan Chengbe51f282007-11-12 06:35:08 +0000651//===----------------------------------------------------------------------===//
652// Register allocator hooks.
653//
654
Jakob Stoklund Olesenbb4bdd82012-09-06 18:15:18 +0000655void LiveIntervals::addKillFlags(const VirtRegMap *VRM) {
656 // Keep track of regunit ranges.
Matthias Braun7f8dece2014-12-20 01:54:48 +0000657 SmallVector<std::pair<const LiveRange*, LiveRange::const_iterator>, 8> RU;
Matthias Braun714c4942014-12-20 01:54:50 +0000658 // Keep track of subregister ranges.
659 SmallVector<std::pair<const LiveInterval::SubRange*,
660 LiveRange::const_iterator>, 4> SRs;
Jakob Stoklund Olesenbb4bdd82012-09-06 18:15:18 +0000661
Jakob Stoklund Olesen781e0b92012-06-20 23:23:59 +0000662 for (unsigned i = 0, e = MRI->getNumVirtRegs(); i != e; ++i) {
663 unsigned Reg = TargetRegisterInfo::index2VirtReg(i);
Jakob Stoklund Olesen11fb2482012-06-04 22:39:14 +0000664 if (MRI->reg_nodbg_empty(Reg))
Jakob Stoklund Olesenf2b16dc2011-02-08 21:13:03 +0000665 continue;
Matthias Braun7f8dece2014-12-20 01:54:48 +0000666 const LiveInterval &LI = getInterval(Reg);
667 if (LI.empty())
Jakob Stoklund Olesenbb4bdd82012-09-06 18:15:18 +0000668 continue;
669
670 // Find the regunit intervals for the assigned register. They may overlap
671 // the virtual register live range, cancelling any kills.
672 RU.clear();
Matthias Braun9f21a8d2017-01-19 00:32:13 +0000673 for (MCRegUnitIterator Unit(VRM->getPhys(Reg), TRI); Unit.isValid();
674 ++Unit) {
675 const LiveRange &RURange = getRegUnit(*Unit);
Matthias Braun7f8dece2014-12-20 01:54:48 +0000676 if (RURange.empty())
Jakob Stoklund Olesenbb4bdd82012-09-06 18:15:18 +0000677 continue;
Matthias Braun7f8dece2014-12-20 01:54:48 +0000678 RU.push_back(std::make_pair(&RURange, RURange.find(LI.begin()->end)));
Jakob Stoklund Olesenbb4bdd82012-09-06 18:15:18 +0000679 }
Jakob Stoklund Olesenf2b16dc2011-02-08 21:13:03 +0000680
Matthias Brauna25e13a2015-03-19 00:21:58 +0000681 if (MRI->subRegLivenessEnabled()) {
Matthias Braun714c4942014-12-20 01:54:50 +0000682 SRs.clear();
683 for (const LiveInterval::SubRange &SR : LI.subranges()) {
684 SRs.push_back(std::make_pair(&SR, SR.find(LI.begin()->end)));
685 }
686 }
687
Matthias Braun13ddb7c2013-10-10 21:28:43 +0000688 // Every instruction that kills Reg corresponds to a segment range end
689 // point.
Matthias Braun7f8dece2014-12-20 01:54:48 +0000690 for (LiveInterval::const_iterator RI = LI.begin(), RE = LI.end(); RI != RE;
Jakob Stoklund Olesenf2b16dc2011-02-08 21:13:03 +0000691 ++RI) {
Jakob Stoklund Olesen90b5e562011-11-13 20:45:27 +0000692 // A block index indicates an MBB edge.
693 if (RI->end.isBlock())
Jakob Stoklund Olesenf2b16dc2011-02-08 21:13:03 +0000694 continue;
695 MachineInstr *MI = getInstructionFromIndex(RI->end);
696 if (!MI)
697 continue;
Jakob Stoklund Olesenbb4bdd82012-09-06 18:15:18 +0000698
Matthias Braunc9d5c0f2013-10-04 16:52:58 +0000699 // Check if any of the regunits are live beyond the end of RI. That could
Jakob Stoklund Olesenbb4bdd82012-09-06 18:15:18 +0000700 // happen when a physreg is defined as a copy of a virtreg:
701 //
Francis Visoiu Mistrih93ef1452017-11-30 12:12:19 +0000702 // %eax = COPY %5
703 // FOO %5 <--- MI, cancel kill because %eax is live.
Francis Visoiu Mistriha8a83d12017-12-07 10:40:31 +0000704 // BAR killed %eax
Jakob Stoklund Olesenbb4bdd82012-09-06 18:15:18 +0000705 //
Francis Visoiu Mistrih93ef1452017-11-30 12:12:19 +0000706 // There should be no kill flag on FOO when %5 is rewritten as %eax.
Matthias Braun7f8dece2014-12-20 01:54:48 +0000707 for (auto &RUP : RU) {
708 const LiveRange &RURange = *RUP.first;
Matthias Braunf603c882014-12-24 02:11:43 +0000709 LiveRange::const_iterator &I = RUP.second;
Matthias Braun7f8dece2014-12-20 01:54:48 +0000710 if (I == RURange.end())
Jakob Stoklund Olesenbb4bdd82012-09-06 18:15:18 +0000711 continue;
Matthias Braun7f8dece2014-12-20 01:54:48 +0000712 I = RURange.advanceTo(I, RI->end);
713 if (I == RURange.end() || I->start >= RI->end)
Jakob Stoklund Olesenbb4bdd82012-09-06 18:15:18 +0000714 continue;
715 // I is overlapping RI.
Matthias Braun714c4942014-12-20 01:54:50 +0000716 goto CancelKill;
Jakob Stoklund Olesenbb4bdd82012-09-06 18:15:18 +0000717 }
Matthias Braund70caaf2014-12-10 01:13:04 +0000718
Matthias Brauna25e13a2015-03-19 00:21:58 +0000719 if (MRI->subRegLivenessEnabled()) {
Matthias Braun714c4942014-12-20 01:54:50 +0000720 // When reading a partial undefined value we must not add a kill flag.
721 // The regalloc might have used the undef lane for something else.
722 // Example:
Francis Visoiu Mistrih93ef1452017-11-30 12:12:19 +0000723 // %1 = ... ; R32: %1
724 // %2:high16 = ... ; R64: %2
Francis Visoiu Mistriha8a83d12017-12-07 10:40:31 +0000725 // = read killed %2 ; R64: %2
Francis Visoiu Mistrih93ef1452017-11-30 12:12:19 +0000726 // = read %1 ; R32: %1
727 // The <kill> flag is correct for %2, but the register allocator may
728 // assign R0L to %1, and R0 to %2 because the low 32bits of R0
729 // are actually never written by %2. After assignment the <kill>
Matthias Braun714c4942014-12-20 01:54:50 +0000730 // flag at the read instruction is invalid.
Matthias Braune6a24852015-09-25 21:51:14 +0000731 LaneBitmask DefinedLanesMask;
Matthias Braun714c4942014-12-20 01:54:50 +0000732 if (!SRs.empty()) {
733 // Compute a mask of lanes that are defined.
Krzysztof Parzyszek91b5cf82016-12-15 14:36:06 +0000734 DefinedLanesMask = LaneBitmask::getNone();
Matthias Braun714c4942014-12-20 01:54:50 +0000735 for (auto &SRP : SRs) {
736 const LiveInterval::SubRange &SR = *SRP.first;
Matthias Braunf603c882014-12-24 02:11:43 +0000737 LiveRange::const_iterator &I = SRP.second;
Matthias Braun714c4942014-12-20 01:54:50 +0000738 if (I == SR.end())
739 continue;
740 I = SR.advanceTo(I, RI->end);
741 if (I == SR.end() || I->start >= RI->end)
742 continue;
743 // I is overlapping RI
744 DefinedLanesMask |= SR.LaneMask;
Matthias Braund70caaf2014-12-10 01:13:04 +0000745 }
Matthias Braun714c4942014-12-20 01:54:50 +0000746 } else
Krzysztof Parzyszek91b5cf82016-12-15 14:36:06 +0000747 DefinedLanesMask = LaneBitmask::getAll();
Matthias Braun714c4942014-12-20 01:54:50 +0000748
749 bool IsFullWrite = false;
750 for (const MachineOperand &MO : MI->operands()) {
751 if (!MO.isReg() || MO.getReg() != Reg)
752 continue;
753 if (MO.isUse()) {
754 // Reading any undefined lanes?
Matthias Braune6a24852015-09-25 21:51:14 +0000755 LaneBitmask UseMask = TRI->getSubRegIndexLaneMask(MO.getSubReg());
Krzysztof Parzyszekea9f8ce2016-12-16 19:11:56 +0000756 if ((UseMask & ~DefinedLanesMask).any())
Matthias Braun714c4942014-12-20 01:54:50 +0000757 goto CancelKill;
758 } else if (MO.getSubReg() == 0) {
759 // Writing to the full register?
760 assert(MO.isDef());
761 IsFullWrite = true;
762 }
763 }
764
765 // If an instruction writes to a subregister, a new segment starts in
766 // the LiveInterval. But as this is only overriding part of the register
767 // adding kill-flags is not correct here after registers have been
768 // assigned.
769 if (!IsFullWrite) {
770 // Next segment has to be adjacent in the subregister write case.
771 LiveRange::const_iterator N = std::next(RI);
772 if (N != LI.end() && N->start == RI->end)
773 goto CancelKill;
Matthias Braund70caaf2014-12-10 01:13:04 +0000774 }
775 }
776
Matthias Braun714c4942014-12-20 01:54:50 +0000777 MI->addRegisterKilled(Reg, nullptr);
778 continue;
779CancelKill:
780 MI->clearRegisterKills(Reg, nullptr);
Jakob Stoklund Olesenf2b16dc2011-02-08 21:13:03 +0000781 }
782 }
783}
784
Jakob Stoklund Olesenaa06de22012-02-10 01:23:55 +0000785MachineBasicBlock*
786LiveIntervals::intervalIsInOneMBB(const LiveInterval &LI) const {
787 // A local live range must be fully contained inside the block, meaning it is
788 // defined and killed at instructions, not at block boundaries. It is not
Hiroshi Inouebcadfee2018-04-12 05:53:20 +0000789 // live in or out of any block.
Jakob Stoklund Olesenaa06de22012-02-10 01:23:55 +0000790 //
791 // It is technically possible to have a PHI-defined live range identical to a
792 // single block, but we are going to return false in that case.
Lang Hames05fb9632009-11-03 23:52:08 +0000793
Jakob Stoklund Olesenaa06de22012-02-10 01:23:55 +0000794 SlotIndex Start = LI.beginIndex();
795 if (Start.isBlock())
Craig Topperc0196b12014-04-14 00:51:57 +0000796 return nullptr;
Lang Hames05fb9632009-11-03 23:52:08 +0000797
Jakob Stoklund Olesenaa06de22012-02-10 01:23:55 +0000798 SlotIndex Stop = LI.endIndex();
799 if (Stop.isBlock())
Craig Topperc0196b12014-04-14 00:51:57 +0000800 return nullptr;
Lang Hames05fb9632009-11-03 23:52:08 +0000801
Jakob Stoklund Olesenaa06de22012-02-10 01:23:55 +0000802 // getMBBFromIndex doesn't need to search the MBB table when both indexes
803 // belong to proper instructions.
Jakob Stoklund Olesen11fb2482012-06-04 22:39:14 +0000804 MachineBasicBlock *MBB1 = Indexes->getMBBFromIndex(Start);
805 MachineBasicBlock *MBB2 = Indexes->getMBBFromIndex(Stop);
Craig Topperc0196b12014-04-14 00:51:57 +0000806 return MBB1 == MBB2 ? MBB1 : nullptr;
Evan Cheng8e223792007-11-17 00:40:40 +0000807}
808
Jakob Stoklund Olesen06d6a532012-08-03 20:10:24 +0000809bool
810LiveIntervals::hasPHIKill(const LiveInterval &LI, const VNInfo *VNI) const {
Matthias Braun96761952014-12-10 23:07:54 +0000811 for (const VNInfo *PHI : LI.valnos) {
Jakob Stoklund Olesen06d6a532012-08-03 20:10:24 +0000812 if (PHI->isUnused() || !PHI->isPHIDef())
813 continue;
814 const MachineBasicBlock *PHIMBB = getMBBFromIndex(PHI->def);
815 // Conservatively return true instead of scanning huge predecessor lists.
816 if (PHIMBB->pred_size() > 100)
817 return true;
Matthias Braun9f21a8d2017-01-19 00:32:13 +0000818 for (const MachineBasicBlock *Pred : PHIMBB->predecessors())
819 if (VNI == LI.getVNInfoBefore(Indexes->getMBBEndIdx(Pred)))
Jakob Stoklund Olesen06d6a532012-08-03 20:10:24 +0000820 return true;
821 }
822 return false;
823}
824
Duncan P. N. Exon Smithbe8f8c42016-02-27 20:14:29 +0000825float LiveIntervals::getSpillWeight(bool isDef, bool isUse,
826 const MachineBlockFrequencyInfo *MBFI,
827 const MachineInstr &MI) {
Marina Yatsinaf9371d82017-10-22 17:59:38 +0000828 return getSpillWeight(isDef, isUse, MBFI, MI.getParent());
829}
830
831float LiveIntervals::getSpillWeight(bool isDef, bool isUse,
832 const MachineBlockFrequencyInfo *MBFI,
833 const MachineBasicBlock *MBB) {
834 BlockFrequency Freq = MBFI->getBlockFreq(MBB);
Michael Gottesman5e985ee2013-12-14 02:37:38 +0000835 const float Scale = 1.0f / MBFI->getEntryFreq();
Michael Gottesman9f49d742013-12-14 00:53:32 +0000836 return (isDef + isUse) * (Freq.getFrequency() * Scale);
Jakob Stoklund Olesen115da882010-03-01 20:59:38 +0000837}
838
Matthias Braund7df9352013-10-10 21:28:47 +0000839LiveRange::Segment
Duncan P. N. Exon Smith3ac9cc62016-02-27 06:40:41 +0000840LiveIntervals::addSegmentToEndOfBlock(unsigned reg, MachineInstr &startInst) {
Mark Lacey9d8103d2013-08-14 23:50:16 +0000841 LiveInterval& Interval = createEmptyInterval(reg);
Duncan P. N. Exon Smith3ac9cc62016-02-27 06:40:41 +0000842 VNInfo *VN = Interval.getNextValue(
843 SlotIndex(getInstructionIndex(startInst).getRegSlot()),
844 getVNInfoAllocator());
845 LiveRange::Segment S(SlotIndex(getInstructionIndex(startInst).getRegSlot()),
846 getMBBEndIdx(startInst.getParent()), VN);
Matthias Braun13ddb7c2013-10-10 21:28:43 +0000847 Interval.addSegment(S);
Jakob Stoklund Olesen073cd802010-08-12 20:01:23 +0000848
Matthias Braun13ddb7c2013-10-10 21:28:43 +0000849 return S;
Owen Anderson35e2dfe2008-06-05 17:15:43 +0000850}
Jakob Stoklund Olesen3ff74d82012-02-08 17:33:45 +0000851
Jakob Stoklund Olesen3ff74d82012-02-08 17:33:45 +0000852//===----------------------------------------------------------------------===//
853// Register mask functions
854//===----------------------------------------------------------------------===//
855
856bool LiveIntervals::checkRegMaskInterference(LiveInterval &LI,
857 BitVector &UsableRegs) {
858 if (LI.empty())
859 return false;
Jakob Stoklund Olesen9ef50bd2012-02-10 01:31:31 +0000860 LiveInterval::iterator LiveI = LI.begin(), LiveE = LI.end();
861
862 // Use a smaller arrays for local live ranges.
863 ArrayRef<SlotIndex> Slots;
864 ArrayRef<const uint32_t*> Bits;
865 if (MachineBasicBlock *MBB = intervalIsInOneMBB(LI)) {
866 Slots = getRegMaskSlotsInBlock(MBB->getNumber());
867 Bits = getRegMaskBitsInBlock(MBB->getNumber());
868 } else {
869 Slots = getRegMaskSlots();
870 Bits = getRegMaskBits();
871 }
Jakob Stoklund Olesen3ff74d82012-02-08 17:33:45 +0000872
873 // We are going to enumerate all the register mask slots contained in LI.
874 // Start with a binary search of RegMaskSlots to find a starting point.
Jakob Stoklund Olesen3ff74d82012-02-08 17:33:45 +0000875 ArrayRef<SlotIndex>::iterator SlotI =
876 std::lower_bound(Slots.begin(), Slots.end(), LiveI->start);
877 ArrayRef<SlotIndex>::iterator SlotE = Slots.end();
878
879 // No slots in range, LI begins after the last call.
880 if (SlotI == SlotE)
881 return false;
882
883 bool Found = false;
Eugene Zelenko75480cc2017-05-24 23:10:29 +0000884 while (true) {
Jakob Stoklund Olesen3ff74d82012-02-08 17:33:45 +0000885 assert(*SlotI >= LiveI->start);
886 // Loop over all slots overlapping this segment.
887 while (*SlotI < LiveI->end) {
888 // *SlotI overlaps LI. Collect mask bits.
889 if (!Found) {
890 // This is the first overlap. Initialize UsableRegs to all ones.
891 UsableRegs.clear();
Jakob Stoklund Olesen11fb2482012-06-04 22:39:14 +0000892 UsableRegs.resize(TRI->getNumRegs(), true);
Jakob Stoklund Olesen3ff74d82012-02-08 17:33:45 +0000893 Found = true;
894 }
895 // Remove usable registers clobbered by this mask.
Jakob Stoklund Olesen9ef50bd2012-02-10 01:31:31 +0000896 UsableRegs.clearBitsNotInMask(Bits[SlotI-Slots.begin()]);
Jakob Stoklund Olesen3ff74d82012-02-08 17:33:45 +0000897 if (++SlotI == SlotE)
898 return Found;
899 }
900 // *SlotI is beyond the current LI segment.
901 LiveI = LI.advanceTo(LiveI, *SlotI);
902 if (LiveI == LiveE)
903 return Found;
904 // Advance SlotI until it overlaps.
905 while (*SlotI < LiveI->start)
906 if (++SlotI == SlotE)
907 return Found;
908 }
909}
Lang Hamesb9057d52012-02-17 18:44:18 +0000910
911//===----------------------------------------------------------------------===//
912// IntervalUpdate class.
913//===----------------------------------------------------------------------===//
914
Matthias Braun9f21a8d2017-01-19 00:32:13 +0000915/// Toolkit used by handleMove to trim or extend live intervals.
Lang Hamesb9057d52012-02-17 18:44:18 +0000916class LiveIntervals::HMEditor {
917private:
Lang Hames59761982012-02-17 23:43:40 +0000918 LiveIntervals& LIS;
919 const MachineRegisterInfo& MRI;
920 const TargetRegisterInfo& TRI;
Jakob Stoklund Olesen1a87a292012-10-12 21:31:57 +0000921 SlotIndex OldIdx;
Lang Hames59761982012-02-17 23:43:40 +0000922 SlotIndex NewIdx;
Matthias Braun34e1be92013-10-10 21:29:02 +0000923 SmallPtrSet<LiveRange*, 8> Updated;
Andrew Trickd9d4be02012-10-16 00:22:51 +0000924 bool UpdateFlags;
Lang Hames13b11522012-02-19 07:13:05 +0000925
Lang Hamesb9057d52012-02-17 18:44:18 +0000926public:
Lang Hames59761982012-02-17 23:43:40 +0000927 HMEditor(LiveIntervals& LIS, const MachineRegisterInfo& MRI,
Jakob Stoklund Olesen1a87a292012-10-12 21:31:57 +0000928 const TargetRegisterInfo& TRI,
Andrew Trickd9d4be02012-10-16 00:22:51 +0000929 SlotIndex OldIdx, SlotIndex NewIdx, bool UpdateFlags)
930 : LIS(LIS), MRI(MRI), TRI(TRI), OldIdx(OldIdx), NewIdx(NewIdx),
931 UpdateFlags(UpdateFlags) {}
932
933 // FIXME: UpdateFlags is a workaround that creates live intervals for all
934 // physregs, even those that aren't needed for regalloc, in order to update
935 // kill flags. This is wasteful. Eventually, LiveVariables will strip all kill
936 // flags, and postRA passes will use a live register utility instead.
Matthias Braun34e1be92013-10-10 21:29:02 +0000937 LiveRange *getRegUnitLI(unsigned Unit) {
Matthias Brauncebdb172017-09-01 18:36:26 +0000938 if (UpdateFlags && !MRI.isReservedRegUnit(Unit))
Andrew Trickd9d4be02012-10-16 00:22:51 +0000939 return &LIS.getRegUnit(Unit);
940 return LIS.getCachedRegUnit(Unit);
941 }
Lang Hamesb9057d52012-02-17 18:44:18 +0000942
Jakob Stoklund Olesen1a87a292012-10-12 21:31:57 +0000943 /// Update all live ranges touched by MI, assuming a move from OldIdx to
944 /// NewIdx.
945 void updateAllRanges(MachineInstr *MI) {
946 DEBUG(dbgs() << "handleMove " << OldIdx << " -> " << NewIdx << ": " << *MI);
947 bool hasRegMask = false;
Matthias Braune41e1462015-05-29 02:56:46 +0000948 for (MachineOperand &MO : MI->operands()) {
949 if (MO.isRegMask())
Jakob Stoklund Olesen1a87a292012-10-12 21:31:57 +0000950 hasRegMask = true;
Matthias Braune41e1462015-05-29 02:56:46 +0000951 if (!MO.isReg())
Lang Hamesd6e765c2012-02-21 22:29:38 +0000952 continue;
Matthias Braun71474e82016-05-06 21:47:41 +0000953 if (MO.isUse()) {
954 if (!MO.readsReg())
955 continue;
956 // Aggressively clear all kill flags.
957 // They are reinserted by VirtRegRewriter.
Matthias Braune41e1462015-05-29 02:56:46 +0000958 MO.setIsKill(false);
Matthias Braun71474e82016-05-06 21:47:41 +0000959 }
Jakob Stoklund Olesen1a87a292012-10-12 21:31:57 +0000960
Matthias Braune41e1462015-05-29 02:56:46 +0000961 unsigned Reg = MO.getReg();
Jakob Stoklund Olesen1a87a292012-10-12 21:31:57 +0000962 if (!Reg)
963 continue;
964 if (TargetRegisterInfo::isVirtualRegister(Reg)) {
Matthias Braun34e1be92013-10-10 21:29:02 +0000965 LiveInterval &LI = LIS.getInterval(Reg);
Matthias Braun7044d692014-12-10 01:12:20 +0000966 if (LI.hasSubRanges()) {
Matthias Braune41e1462015-05-29 02:56:46 +0000967 unsigned SubReg = MO.getSubReg();
Krzysztof Parzyszeka7ed0902016-08-24 13:37:55 +0000968 LaneBitmask LaneMask = SubReg ? TRI.getSubRegIndexLaneMask(SubReg)
969 : MRI.getMaxLaneMaskForVReg(Reg);
Matthias Braun09afa1e2014-12-11 00:59:06 +0000970 for (LiveInterval::SubRange &S : LI.subranges()) {
Krzysztof Parzyszek91b5cf82016-12-15 14:36:06 +0000971 if ((S.LaneMask & LaneMask).none())
Matthias Braun7044d692014-12-10 01:12:20 +0000972 continue;
Matthias Braun09afa1e2014-12-11 00:59:06 +0000973 updateRange(S, Reg, S.LaneMask);
Matthias Braun7044d692014-12-10 01:12:20 +0000974 }
975 }
Krzysztof Parzyszek91b5cf82016-12-15 14:36:06 +0000976 updateRange(LI, Reg, LaneBitmask::getNone());
Jakob Stoklund Olesen1a87a292012-10-12 21:31:57 +0000977 continue;
978 }
979
980 // For physregs, only update the regunits that actually have a
981 // precomputed live range.
982 for (MCRegUnitIterator Units(Reg, &TRI); Units.isValid(); ++Units)
Matthias Braun34e1be92013-10-10 21:29:02 +0000983 if (LiveRange *LR = getRegUnitLI(*Units))
Krzysztof Parzyszek91b5cf82016-12-15 14:36:06 +0000984 updateRange(*LR, *Units, LaneBitmask::getNone());
Lang Hamesd6e765c2012-02-21 22:29:38 +0000985 }
Jakob Stoklund Olesen1a87a292012-10-12 21:31:57 +0000986 if (hasRegMask)
987 updateRegMaskSlots();
Lang Hames13b11522012-02-19 07:13:05 +0000988 }
989
Lang Hames4645a722012-02-19 03:00:30 +0000990private:
Jakob Stoklund Olesen1a87a292012-10-12 21:31:57 +0000991 /// Update a single live range, assuming an instruction has been moved from
992 /// OldIdx to NewIdx.
Matthias Braune6a24852015-09-25 21:51:14 +0000993 void updateRange(LiveRange &LR, unsigned Reg, LaneBitmask LaneMask) {
David Blaikie70573dc2014-11-19 07:49:26 +0000994 if (!Updated.insert(&LR).second)
Jakob Stoklund Olesen1a87a292012-10-12 21:31:57 +0000995 return;
996 DEBUG({
997 dbgs() << " ";
Matthias Braun7044d692014-12-10 01:12:20 +0000998 if (TargetRegisterInfo::isVirtualRegister(Reg)) {
Francis Visoiu Mistrih9d419d32017-11-28 12:42:37 +0000999 dbgs() << printReg(Reg);
Krzysztof Parzyszekea9f8ce2016-12-16 19:11:56 +00001000 if (LaneMask.any())
Matthias Braunc804cdb2015-09-25 21:51:24 +00001001 dbgs() << " L" << PrintLaneMask(LaneMask);
Matthias Braun7044d692014-12-10 01:12:20 +00001002 } else {
Francis Visoiu Mistrih9d419d32017-11-28 12:42:37 +00001003 dbgs() << printRegUnit(Reg, &TRI);
Matthias Braun7044d692014-12-10 01:12:20 +00001004 }
Matthias Braun34e1be92013-10-10 21:29:02 +00001005 dbgs() << ":\t" << LR << '\n';
Jakob Stoklund Olesen1a87a292012-10-12 21:31:57 +00001006 });
1007 if (SlotIndex::isEarlierInstr(OldIdx, NewIdx))
Matthias Braun34e1be92013-10-10 21:29:02 +00001008 handleMoveDown(LR);
Jakob Stoklund Olesen1a87a292012-10-12 21:31:57 +00001009 else
Matthias Braun7044d692014-12-10 01:12:20 +00001010 handleMoveUp(LR, Reg, LaneMask);
Matthias Braun34e1be92013-10-10 21:29:02 +00001011 DEBUG(dbgs() << " -->\t" << LR << '\n');
1012 LR.verify();
Lang Hamesb9057d52012-02-17 18:44:18 +00001013 }
1014
Matthias Braun34e1be92013-10-10 21:29:02 +00001015 /// Update LR to reflect an instruction has been moved downwards from OldIdx
Matthias Braun242b8bb2016-01-26 00:43:50 +00001016 /// to NewIdx (OldIdx < NewIdx).
Matthias Braun34e1be92013-10-10 21:29:02 +00001017 void handleMoveDown(LiveRange &LR) {
Matthias Braun34e1be92013-10-10 21:29:02 +00001018 LiveRange::iterator E = LR.end();
Matthias Braun242b8bb2016-01-26 00:43:50 +00001019 // Segment going into OldIdx.
1020 LiveRange::iterator OldIdxIn = LR.find(OldIdx.getBaseIndex());
1021
1022 // No value live before or after OldIdx? Nothing to do.
1023 if (OldIdxIn == E || SlotIndex::isEarlierInstr(OldIdx, OldIdxIn->start))
Jakob Stoklund Olesen1a87a292012-10-12 21:31:57 +00001024 return;
Lang Hames13b11522012-02-19 07:13:05 +00001025
Matthias Braun242b8bb2016-01-26 00:43:50 +00001026 LiveRange::iterator OldIdxOut;
1027 // Do we have a value live-in to OldIdx?
1028 if (SlotIndex::isEarlierInstr(OldIdxIn->start, OldIdx)) {
Jakob Stoklund Olesen1a87a292012-10-12 21:31:57 +00001029 // If the live-in value already extends to NewIdx, there is nothing to do.
Matthias Braun242b8bb2016-01-26 00:43:50 +00001030 if (SlotIndex::isEarlierEqualInstr(NewIdx, OldIdxIn->end))
Jakob Stoklund Olesen1a87a292012-10-12 21:31:57 +00001031 return;
1032 // Aggressively remove all kill flags from the old kill point.
1033 // Kill flags shouldn't be used while live intervals exist, they will be
1034 // reinserted by VirtRegRewriter.
Matthias Braun242b8bb2016-01-26 00:43:50 +00001035 if (MachineInstr *KillMI = LIS.getInstructionFromIndex(OldIdxIn->end))
Duncan P. N. Exon Smithf9ab4162016-02-27 17:05:33 +00001036 for (MIBundleOperands MO(*KillMI); MO.isValid(); ++MO)
Jakob Stoklund Olesen1a87a292012-10-12 21:31:57 +00001037 if (MO->isReg() && MO->isUse())
1038 MO->setIsKill(false);
Matthias Braun4a6c7282016-02-15 19:25:36 +00001039
1040 // Is there a def before NewIdx which is not OldIdx?
1041 LiveRange::iterator Next = std::next(OldIdxIn);
1042 if (Next != E && !SlotIndex::isSameInstr(OldIdx, Next->start) &&
1043 SlotIndex::isEarlierInstr(Next->start, NewIdx)) {
1044 // If we are here then OldIdx was just a use but not a def. We only have
1045 // to ensure liveness extends to NewIdx.
1046 LiveRange::iterator NewIdxIn =
1047 LR.advanceTo(Next, NewIdx.getBaseIndex());
1048 // Extend the segment before NewIdx if necessary.
1049 if (NewIdxIn == E ||
1050 !SlotIndex::isEarlierInstr(NewIdxIn->start, NewIdx)) {
1051 LiveRange::iterator Prev = std::prev(NewIdxIn);
1052 Prev->end = NewIdx.getRegSlot();
1053 }
Matthias Braun3865b1d2016-07-26 03:57:45 +00001054 // Extend OldIdxIn.
1055 OldIdxIn->end = Next->start;
Matthias Braun4a6c7282016-02-15 19:25:36 +00001056 return;
1057 }
1058
Matthias Braun242b8bb2016-01-26 00:43:50 +00001059 // Adjust OldIdxIn->end to reach NewIdx. This may temporarily make LR
Matthias Braundb320772016-01-26 01:40:48 +00001060 // invalid by overlapping ranges.
Matthias Braun242b8bb2016-01-26 00:43:50 +00001061 bool isKill = SlotIndex::isSameInstr(OldIdx, OldIdxIn->end);
1062 OldIdxIn->end = NewIdx.getRegSlot(OldIdxIn->end.isEarlyClobber());
1063 // If this was not a kill, then there was no def and we're done.
Jakob Stoklund Olesen1a87a292012-10-12 21:31:57 +00001064 if (!isKill)
1065 return;
Matthias Braun242b8bb2016-01-26 00:43:50 +00001066
1067 // Did we have a Def at OldIdx?
Matthias Braun4a6c7282016-02-15 19:25:36 +00001068 OldIdxOut = Next;
Matthias Braun242b8bb2016-01-26 00:43:50 +00001069 if (OldIdxOut == E || !SlotIndex::isSameInstr(OldIdx, OldIdxOut->start))
1070 return;
1071 } else {
1072 OldIdxOut = OldIdxIn;
Lang Hames13b11522012-02-19 07:13:05 +00001073 }
1074
Matthias Braun242b8bb2016-01-26 00:43:50 +00001075 // If we are here then there is a Definition at OldIdx. OldIdxOut points
1076 // to the segment starting there.
1077 assert(OldIdxOut != E && SlotIndex::isSameInstr(OldIdx, OldIdxOut->start) &&
1078 "No def?");
1079 VNInfo *OldIdxVNI = OldIdxOut->valno;
1080 assert(OldIdxVNI->def == OldIdxOut->start && "Inconsistent def");
1081
1082 // If the defined value extends beyond NewIdx, just move the beginning
1083 // of the segment to NewIdx.
1084 SlotIndex NewIdxDef = NewIdx.getRegSlot(OldIdxOut->start.isEarlyClobber());
1085 if (SlotIndex::isEarlierInstr(NewIdxDef, OldIdxOut->end)) {
1086 OldIdxVNI->def = NewIdxDef;
1087 OldIdxOut->start = OldIdxVNI->def;
Jakob Stoklund Olesen1a87a292012-10-12 21:31:57 +00001088 return;
1089 }
Matthias Braun242b8bb2016-01-26 00:43:50 +00001090
1091 // If we are here then we have a Definition at OldIdx which ends before
Matthias Braun4a6c7282016-02-15 19:25:36 +00001092 // NewIdx.
1093
Matthias Braun242b8bb2016-01-26 00:43:50 +00001094 // Is there an existing Def at NewIdx?
1095 LiveRange::iterator AfterNewIdx
1096 = LR.advanceTo(OldIdxOut, NewIdx.getRegSlot());
Matthias Braun4a6c7282016-02-15 19:25:36 +00001097 bool OldIdxDefIsDead = OldIdxOut->end.isDead();
1098 if (!OldIdxDefIsDead &&
1099 SlotIndex::isEarlierInstr(OldIdxOut->end, NewIdxDef)) {
1100 // OldIdx is not a dead def, and NewIdxDef is inside a new interval.
1101 VNInfo *DefVNI;
1102 if (OldIdxOut != LR.begin() &&
1103 !SlotIndex::isEarlierInstr(std::prev(OldIdxOut)->end,
1104 OldIdxOut->start)) {
1105 // There is no gap between OldIdxOut and its predecessor anymore,
1106 // merge them.
1107 LiveRange::iterator IPrev = std::prev(OldIdxOut);
1108 DefVNI = OldIdxVNI;
1109 IPrev->end = OldIdxOut->end;
1110 } else {
1111 // The value is live in to OldIdx
1112 LiveRange::iterator INext = std::next(OldIdxOut);
1113 assert(INext != E && "Must have following segment");
1114 // We merge OldIdxOut and its successor. As we're dealing with subreg
1115 // reordering, there is always a successor to OldIdxOut in the same BB
1116 // We don't need INext->valno anymore and will reuse for the new segment
1117 // we create later.
Matthias Braunc9e759a2016-04-28 02:11:49 +00001118 DefVNI = OldIdxVNI;
Matthias Braun4a6c7282016-02-15 19:25:36 +00001119 INext->start = OldIdxOut->end;
Matthias Braun4a6c7282016-02-15 19:25:36 +00001120 INext->valno->def = INext->start;
1121 }
1122 // If NewIdx is behind the last segment, extend that and append a new one.
1123 if (AfterNewIdx == E) {
1124 // OldIdxOut is undef at this point, Slide (OldIdxOut;AfterNewIdx] up
1125 // one position.
1126 // |- ?/OldIdxOut -| |- X0 -| ... |- Xn -| end
1127 // => |- X0/OldIdxOut -| ... |- Xn -| |- undef/NewS -| end
1128 std::copy(std::next(OldIdxOut), E, OldIdxOut);
1129 // The last segment is undefined now, reuse it for a dead def.
1130 LiveRange::iterator NewSegment = std::prev(E);
1131 *NewSegment = LiveRange::Segment(NewIdxDef, NewIdxDef.getDeadSlot(),
1132 DefVNI);
1133 DefVNI->def = NewIdxDef;
1134
1135 LiveRange::iterator Prev = std::prev(NewSegment);
1136 Prev->end = NewIdxDef;
1137 } else {
1138 // OldIdxOut is undef at this point, Slide (OldIdxOut;AfterNewIdx] up
1139 // one position.
1140 // |- ?/OldIdxOut -| |- X0 -| ... |- Xn/AfterNewIdx -| |- Next -|
1141 // => |- X0/OldIdxOut -| ... |- Xn -| |- Xn/AfterNewIdx -| |- Next -|
1142 std::copy(std::next(OldIdxOut), std::next(AfterNewIdx), OldIdxOut);
1143 LiveRange::iterator Prev = std::prev(AfterNewIdx);
1144 // We have two cases:
1145 if (SlotIndex::isEarlierInstr(Prev->start, NewIdxDef)) {
1146 // Case 1: NewIdx is inside a liverange. Split this liverange at
1147 // NewIdxDef into the segment "Prev" followed by "NewSegment".
1148 LiveRange::iterator NewSegment = AfterNewIdx;
1149 *NewSegment = LiveRange::Segment(NewIdxDef, Prev->end, Prev->valno);
1150 Prev->valno->def = NewIdxDef;
1151
1152 *Prev = LiveRange::Segment(Prev->start, NewIdxDef, DefVNI);
1153 DefVNI->def = Prev->start;
1154 } else {
1155 // Case 2: NewIdx is in a lifetime hole. Keep AfterNewIdx as is and
1156 // turn Prev into a segment from NewIdx to AfterNewIdx->start.
1157 *Prev = LiveRange::Segment(NewIdxDef, AfterNewIdx->start, DefVNI);
1158 DefVNI->def = NewIdxDef;
1159 assert(DefVNI != AfterNewIdx->valno);
1160 }
1161 }
1162 return;
1163 }
1164
Matthias Braun242b8bb2016-01-26 00:43:50 +00001165 if (AfterNewIdx != E &&
1166 SlotIndex::isSameInstr(AfterNewIdx->start, NewIdxDef)) {
1167 // There is an existing def at NewIdx. The def at OldIdx is coalesced into
1168 // that value.
1169 assert(AfterNewIdx->valno != OldIdxVNI && "Multiple defs of value?");
1170 LR.removeValNo(OldIdxVNI);
1171 } else {
1172 // There was no existing def at NewIdx. We need to create a dead def
1173 // at NewIdx. Shift segments over the old OldIdxOut segment, this frees
1174 // a new segment at the place where we want to construct the dead def.
1175 // |- OldIdxOut -| |- X0 -| ... |- Xn -| |- AfterNewIdx -|
1176 // => |- X0/OldIdxOut -| ... |- Xn -| |- undef/NewS. -| |- AfterNewIdx -|
1177 assert(AfterNewIdx != OldIdxOut && "Inconsistent iterators");
1178 std::copy(std::next(OldIdxOut), AfterNewIdx, OldIdxOut);
1179 // We can reuse OldIdxVNI now.
1180 LiveRange::iterator NewSegment = std::prev(AfterNewIdx);
1181 VNInfo *NewSegmentVNI = OldIdxVNI;
1182 NewSegmentVNI->def = NewIdxDef;
1183 *NewSegment = LiveRange::Segment(NewIdxDef, NewIdxDef.getDeadSlot(),
1184 NewSegmentVNI);
Jakob Stoklund Olesen1a87a292012-10-12 21:31:57 +00001185 }
Jakob Stoklund Olesen1a87a292012-10-12 21:31:57 +00001186 }
1187
Matthias Braun34e1be92013-10-10 21:29:02 +00001188 /// Update LR to reflect an instruction has been moved upwards from OldIdx
Matthias Braun242b8bb2016-01-26 00:43:50 +00001189 /// to NewIdx (NewIdx < OldIdx).
Matthias Braune6a24852015-09-25 21:51:14 +00001190 void handleMoveUp(LiveRange &LR, unsigned Reg, LaneBitmask LaneMask) {
Matthias Braun34e1be92013-10-10 21:29:02 +00001191 LiveRange::iterator E = LR.end();
Matthias Braun242b8bb2016-01-26 00:43:50 +00001192 // Segment going into OldIdx.
1193 LiveRange::iterator OldIdxIn = LR.find(OldIdx.getBaseIndex());
1194
1195 // No value live before or after OldIdx? Nothing to do.
1196 if (OldIdxIn == E || SlotIndex::isEarlierInstr(OldIdx, OldIdxIn->start))
Jakob Stoklund Olesen1a87a292012-10-12 21:31:57 +00001197 return;
1198
Matthias Braun242b8bb2016-01-26 00:43:50 +00001199 LiveRange::iterator OldIdxOut;
1200 // Do we have a value live-in to OldIdx?
1201 if (SlotIndex::isEarlierInstr(OldIdxIn->start, OldIdx)) {
1202 // If the live-in value isn't killed here, then we have no Def at
1203 // OldIdx, moreover the value must be live at NewIdx so there is nothing
1204 // to do.
1205 bool isKill = SlotIndex::isSameInstr(OldIdx, OldIdxIn->end);
1206 if (!isKill)
Jakob Stoklund Olesen1a87a292012-10-12 21:31:57 +00001207 return;
Matthias Braun242b8bb2016-01-26 00:43:50 +00001208
1209 // At this point we have to move OldIdxIn->end back to the nearest
Matthias Braun4a6c7282016-02-15 19:25:36 +00001210 // previous use or (dead-)def but no further than NewIdx.
1211 SlotIndex DefBeforeOldIdx
1212 = std::max(OldIdxIn->start.getDeadSlot(),
1213 NewIdx.getRegSlot(OldIdxIn->end.isEarlyClobber()));
1214 OldIdxIn->end = findLastUseBefore(DefBeforeOldIdx, Reg, LaneMask);
Matthias Braun242b8bb2016-01-26 00:43:50 +00001215
Matthias Braun4a6c7282016-02-15 19:25:36 +00001216 // Did we have a Def at OldIdx? If not we are done now.
Matthias Braun242b8bb2016-01-26 00:43:50 +00001217 OldIdxOut = std::next(OldIdxIn);
Matthias Braun4a6c7282016-02-15 19:25:36 +00001218 if (OldIdxOut == E || !SlotIndex::isSameInstr(OldIdx, OldIdxOut->start))
Jakob Stoklund Olesen1a87a292012-10-12 21:31:57 +00001219 return;
Matthias Braun242b8bb2016-01-26 00:43:50 +00001220 } else {
1221 OldIdxOut = OldIdxIn;
Matthias Braun4a6c7282016-02-15 19:25:36 +00001222 OldIdxIn = OldIdxOut != LR.begin() ? std::prev(OldIdxOut) : E;
Matthias Braun242b8bb2016-01-26 00:43:50 +00001223 }
1224
1225 // If we are here then there is a Definition at OldIdx. OldIdxOut points
1226 // to the segment starting there.
1227 assert(OldIdxOut != E && SlotIndex::isSameInstr(OldIdx, OldIdxOut->start) &&
1228 "No def?");
1229 VNInfo *OldIdxVNI = OldIdxOut->valno;
1230 assert(OldIdxVNI->def == OldIdxOut->start && "Inconsistent def");
1231 bool OldIdxDefIsDead = OldIdxOut->end.isDead();
1232
1233 // Is there an existing def at NewIdx?
1234 SlotIndex NewIdxDef = NewIdx.getRegSlot(OldIdxOut->start.isEarlyClobber());
1235 LiveRange::iterator NewIdxOut = LR.find(NewIdx.getRegSlot());
1236 if (SlotIndex::isSameInstr(NewIdxOut->start, NewIdx)) {
1237 assert(NewIdxOut->valno != OldIdxVNI &&
1238 "Same value defined more than once?");
1239 // If OldIdx was a dead def remove it.
1240 if (!OldIdxDefIsDead) {
Matthias Braundb320772016-01-26 01:40:48 +00001241 // Remove segment starting at NewIdx and move begin of OldIdxOut to
1242 // NewIdx so it can take its place.
Matthias Braun242b8bb2016-01-26 00:43:50 +00001243 OldIdxVNI->def = NewIdxDef;
1244 OldIdxOut->start = NewIdxDef;
1245 LR.removeValNo(NewIdxOut->valno);
1246 } else {
Matthias Braundb320772016-01-26 01:40:48 +00001247 // Simply remove the dead def at OldIdx.
Matthias Braun242b8bb2016-01-26 00:43:50 +00001248 LR.removeValNo(OldIdxVNI);
1249 }
1250 } else {
1251 // Previously nothing was live after NewIdx, so all we have to do now is
1252 // move the begin of OldIdxOut to NewIdx.
1253 if (!OldIdxDefIsDead) {
Matthias Braun4a6c7282016-02-15 19:25:36 +00001254 // Do we have any intermediate Defs between OldIdx and NewIdx?
1255 if (OldIdxIn != E &&
1256 SlotIndex::isEarlierInstr(NewIdxDef, OldIdxIn->start)) {
1257 // OldIdx is not a dead def and NewIdx is before predecessor start.
1258 LiveRange::iterator NewIdxIn = NewIdxOut;
1259 assert(NewIdxIn == LR.find(NewIdx.getBaseIndex()));
1260 const SlotIndex SplitPos = NewIdxDef;
Stanislav Mekhanoshinb546174b2017-03-11 00:14:52 +00001261 OldIdxVNI = OldIdxIn->valno;
Matthias Braun4a6c7282016-02-15 19:25:36 +00001262
1263 // Merge the OldIdxIn and OldIdxOut segments into OldIdxOut.
Stanislav Mekhanoshinb546174b2017-03-11 00:14:52 +00001264 OldIdxOut->valno->def = OldIdxIn->start;
Matthias Braun4a6c7282016-02-15 19:25:36 +00001265 *OldIdxOut = LiveRange::Segment(OldIdxIn->start, OldIdxOut->end,
Stanislav Mekhanoshinb546174b2017-03-11 00:14:52 +00001266 OldIdxOut->valno);
Matthias Braun4a6c7282016-02-15 19:25:36 +00001267 // OldIdxIn and OldIdxVNI are now undef and can be overridden.
1268 // We Slide [NewIdxIn, OldIdxIn) down one position.
1269 // |- X0/NewIdxIn -| ... |- Xn-1 -||- Xn/OldIdxIn -||- OldIdxOut -|
1270 // => |- undef/NexIdxIn -| |- X0 -| ... |- Xn-1 -| |- Xn/OldIdxOut -|
1271 std::copy_backward(NewIdxIn, OldIdxIn, OldIdxOut);
1272 // NewIdxIn is now considered undef so we can reuse it for the moved
1273 // value.
1274 LiveRange::iterator NewSegment = NewIdxIn;
1275 LiveRange::iterator Next = std::next(NewSegment);
Matthias Braun4a6c7282016-02-15 19:25:36 +00001276 if (SlotIndex::isEarlierInstr(Next->start, NewIdx)) {
1277 // There is no gap between NewSegment and its predecessor.
1278 *NewSegment = LiveRange::Segment(Next->start, SplitPos,
Matthias Braunfc4c8a12016-05-24 21:54:01 +00001279 Next->valno);
1280 *Next = LiveRange::Segment(SplitPos, Next->end, OldIdxVNI);
Matthias Braun4a6c7282016-02-15 19:25:36 +00001281 Next->valno->def = SplitPos;
1282 } else {
1283 // There is a gap between NewSegment and its predecessor
1284 // Value becomes live in.
Matthias Braunfc4c8a12016-05-24 21:54:01 +00001285 *NewSegment = LiveRange::Segment(SplitPos, Next->start, OldIdxVNI);
Matthias Braun4a6c7282016-02-15 19:25:36 +00001286 NewSegment->valno->def = SplitPos;
1287 }
1288 } else {
1289 // Leave the end point of a live def.
1290 OldIdxOut->start = NewIdxDef;
1291 OldIdxVNI->def = NewIdxDef;
1292 if (OldIdxIn != E && SlotIndex::isEarlierInstr(NewIdx, OldIdxIn->end))
1293 OldIdxIn->end = NewIdx.getRegSlot();
1294 }
Tim Renouff40707a2018-02-26 14:42:13 +00001295 } else if (OldIdxIn != E
1296 && SlotIndex::isEarlierInstr(NewIdxOut->start, NewIdx)
1297 && SlotIndex::isEarlierInstr(NewIdx, NewIdxOut->end)) {
1298 // OldIdxVNI is a dead def that has been moved into the middle of
1299 // another value in LR. That can happen when LR is a whole register,
1300 // but the dead def is a write to a subreg that is dead at NewIdx.
1301 // The dead def may have been moved across other values
1302 // in LR, so move OldIdxOut up to NewIdxOut. Slide [NewIdxOut;OldIdxOut)
1303 // down one position.
1304 // |- X0/NewIdxOut -| ... |- Xn-1 -| |- Xn/OldIdxOut -| |- next - |
1305 // => |- X0/NewIdxOut -| |- X0 -| ... |- Xn-1 -| |- next -|
1306 std::copy_backward(NewIdxOut, OldIdxOut, std::next(OldIdxOut));
1307 // Modify the segment at NewIdxOut and the following segment to meet at
1308 // the point of the dead def, with the following segment getting
1309 // OldIdxVNI as its value number.
1310 *NewIdxOut = LiveRange::Segment(
1311 NewIdxOut->start, NewIdxDef.getRegSlot(), NewIdxOut->valno);
1312 *(NewIdxOut + 1) = LiveRange::Segment(
1313 NewIdxDef.getRegSlot(), (NewIdxOut + 1)->end, OldIdxVNI);
1314 OldIdxVNI->def = NewIdxDef;
1315 // Modify subsequent segments to be defined by the moved def OldIdxVNI.
1316 for (auto Idx = NewIdxOut + 2; Idx <= OldIdxOut; ++Idx)
1317 Idx->valno = OldIdxVNI;
1318 // Aggressively remove all dead flags from the former dead definition.
1319 // Kill/dead flags shouldn't be used while live intervals exist; they
1320 // will be reinserted by VirtRegRewriter.
1321 if (MachineInstr *KillMI = LIS.getInstructionFromIndex(NewIdx))
1322 for (MIBundleOperands MO(*KillMI); MO.isValid(); ++MO)
1323 if (MO->isReg() && !MO->isUse())
1324 MO->setIsDead(false);
Matthias Braun242b8bb2016-01-26 00:43:50 +00001325 } else {
1326 // OldIdxVNI is a dead def. It may have been moved across other values
1327 // in LR, so move OldIdxOut up to NewIdxOut. Slide [NewIdxOut;OldIdxOut)
1328 // down one position.
1329 // |- X0/NewIdxOut -| ... |- Xn-1 -| |- Xn/OldIdxOut -| |- next - |
1330 // => |- undef/NewIdxOut -| |- X0 -| ... |- Xn-1 -| |- next -|
1331 std::copy_backward(NewIdxOut, OldIdxOut, std::next(OldIdxOut));
1332 // OldIdxVNI can be reused now to build a new dead def segment.
1333 LiveRange::iterator NewSegment = NewIdxOut;
1334 VNInfo *NewSegmentVNI = OldIdxVNI;
1335 *NewSegment = LiveRange::Segment(NewIdxDef, NewIdxDef.getDeadSlot(),
1336 NewSegmentVNI);
1337 NewSegmentVNI->def = NewIdxDef;
Lang Hames13b11522012-02-19 07:13:05 +00001338 }
1339 }
Lang Hames13b11522012-02-19 07:13:05 +00001340 }
1341
Jakob Stoklund Olesen1a87a292012-10-12 21:31:57 +00001342 void updateRegMaskSlots() {
Lang Hames59761982012-02-17 23:43:40 +00001343 SmallVectorImpl<SlotIndex>::iterator RI =
1344 std::lower_bound(LIS.RegMaskSlots.begin(), LIS.RegMaskSlots.end(),
1345 OldIdx);
Jakob Stoklund Olesen13d55622012-11-09 19:18:49 +00001346 assert(RI != LIS.RegMaskSlots.end() && *RI == OldIdx.getRegSlot() &&
1347 "No RegMask at OldIdx.");
1348 *RI = NewIdx.getRegSlot();
1349 assert((RI == LIS.RegMaskSlots.begin() ||
Benjamin Kramerb6d0bd42014-03-02 12:27:27 +00001350 SlotIndex::isEarlierInstr(*std::prev(RI), *RI)) &&
1351 "Cannot move regmask instruction above another call");
1352 assert((std::next(RI) == LIS.RegMaskSlots.end() ||
1353 SlotIndex::isEarlierInstr(*RI, *std::next(RI))) &&
1354 "Cannot move regmask instruction below another call");
Lang Hamesa9afc6a2012-02-17 21:29:41 +00001355 }
Lang Hames4645a722012-02-19 03:00:30 +00001356
1357 // Return the last use of reg between NewIdx and OldIdx.
Matthias Braun4a6c7282016-02-15 19:25:36 +00001358 SlotIndex findLastUseBefore(SlotIndex Before, unsigned Reg,
1359 LaneBitmask LaneMask) {
Lang Hamesc3d9a3d2012-09-12 06:56:16 +00001360 if (TargetRegisterInfo::isVirtualRegister(Reg)) {
Matthias Braun4a6c7282016-02-15 19:25:36 +00001361 SlotIndex LastUse = Before;
Matthias Braun7044d692014-12-10 01:12:20 +00001362 for (MachineOperand &MO : MRI.use_nodbg_operands(Reg)) {
Matthias Braun959a8c92016-06-11 00:31:28 +00001363 if (MO.isUndef())
1364 continue;
Matthias Braun7044d692014-12-10 01:12:20 +00001365 unsigned SubReg = MO.getSubReg();
Krzysztof Parzyszekea9f8ce2016-12-16 19:11:56 +00001366 if (SubReg != 0 && LaneMask.any()
Krzysztof Parzyszek91b5cf82016-12-15 14:36:06 +00001367 && (TRI.getSubRegIndexLaneMask(SubReg) & LaneMask).none())
Matthias Braun7044d692014-12-10 01:12:20 +00001368 continue;
1369
Duncan P. N. Exon Smith3ac9cc62016-02-27 06:40:41 +00001370 const MachineInstr &MI = *MO.getParent();
Lang Hamesc3d9a3d2012-09-12 06:56:16 +00001371 SlotIndex InstSlot = LIS.getSlotIndexes()->getInstructionIndex(MI);
1372 if (InstSlot > LastUse && InstSlot < OldIdx)
Matthias Braun4a6c7282016-02-15 19:25:36 +00001373 LastUse = InstSlot.getRegSlot();
Lang Hamesc3d9a3d2012-09-12 06:56:16 +00001374 }
Jakob Stoklund Olesen8d1aaf22013-03-08 18:08:57 +00001375 return LastUse;
Lang Hames4645a722012-02-19 03:00:30 +00001376 }
Jakob Stoklund Olesen8d1aaf22013-03-08 18:08:57 +00001377
1378 // This is a regunit interval, so scanning the use list could be very
1379 // expensive. Scan upwards from OldIdx instead.
Matthias Braun4a6c7282016-02-15 19:25:36 +00001380 assert(Before < OldIdx && "Expected upwards move");
Jakob Stoklund Olesen8d1aaf22013-03-08 18:08:57 +00001381 SlotIndexes *Indexes = LIS.getSlotIndexes();
Matthias Braun4a6c7282016-02-15 19:25:36 +00001382 MachineBasicBlock *MBB = Indexes->getMBBFromIndex(Before);
Jakob Stoklund Olesen8d1aaf22013-03-08 18:08:57 +00001383
1384 // OldIdx may not correspond to an instruction any longer, so set MII to
1385 // point to the next instruction after OldIdx, or MBB->end().
1386 MachineBasicBlock::iterator MII = MBB->end();
1387 if (MachineInstr *MI = Indexes->getInstructionFromIndex(
1388 Indexes->getNextNonNullIndex(OldIdx)))
1389 if (MI->getParent() == MBB)
1390 MII = MI;
1391
1392 MachineBasicBlock::iterator Begin = MBB->begin();
1393 while (MII != Begin) {
Shiva Chen801bf7e2018-05-09 02:42:00 +00001394 if ((--MII)->isDebugInstr())
Jakob Stoklund Olesen8d1aaf22013-03-08 18:08:57 +00001395 continue;
Duncan P. N. Exon Smith3ac9cc62016-02-27 06:40:41 +00001396 SlotIndex Idx = Indexes->getInstructionIndex(*MII);
Jakob Stoklund Olesen8d1aaf22013-03-08 18:08:57 +00001397
Matthias Braun4a6c7282016-02-15 19:25:36 +00001398 // Stop searching when Before is reached.
1399 if (!SlotIndex::isEarlierInstr(Before, Idx))
1400 return Before;
Jakob Stoklund Olesen8d1aaf22013-03-08 18:08:57 +00001401
1402 // Check if MII uses Reg.
Duncan P. N. Exon Smithf9ab4162016-02-27 17:05:33 +00001403 for (MIBundleOperands MO(*MII); MO.isValid(); ++MO)
Matthias Braun959a8c92016-06-11 00:31:28 +00001404 if (MO->isReg() && !MO->isUndef() &&
Jakob Stoklund Olesen8d1aaf22013-03-08 18:08:57 +00001405 TargetRegisterInfo::isPhysicalRegister(MO->getReg()) &&
1406 TRI.hasRegUnit(MO->getReg(), Reg))
Matthias Braun4a6c7282016-02-15 19:25:36 +00001407 return Idx.getRegSlot();
Jakob Stoklund Olesen8d1aaf22013-03-08 18:08:57 +00001408 }
Matthias Braun4a6c7282016-02-15 19:25:36 +00001409 // Didn't reach Before. It must be the first instruction in the block.
1410 return Before;
Lang Hames4645a722012-02-19 03:00:30 +00001411 }
Lang Hamesb9057d52012-02-17 18:44:18 +00001412};
1413
Duncan P. N. Exon Smithbe8f8c42016-02-27 20:14:29 +00001414void LiveIntervals::handleMove(MachineInstr &MI, bool UpdateFlags) {
1415 assert(!MI.isBundled() && "Can't handle bundled instructions yet.");
1416 SlotIndex OldIndex = Indexes->getInstructionIndex(MI);
1417 Indexes->removeMachineInstrFromMaps(MI);
1418 SlotIndex NewIndex = Indexes->insertMachineInstrInMaps(MI);
1419 assert(getMBBStartIdx(MI.getParent()) <= OldIndex &&
1420 OldIndex < getMBBEndIdx(MI.getParent()) &&
Lang Hamesb9057d52012-02-17 18:44:18 +00001421 "Cannot handle moves across basic block boundaries.");
Lang Hamesb9057d52012-02-17 18:44:18 +00001422
Andrew Trickd9d4be02012-10-16 00:22:51 +00001423 HMEditor HME(*this, *MRI, *TRI, OldIndex, NewIndex, UpdateFlags);
Duncan P. N. Exon Smithbe8f8c42016-02-27 20:14:29 +00001424 HME.updateAllRanges(&MI);
Lang Hamesd6e765c2012-02-21 22:29:38 +00001425}
1426
Duncan P. N. Exon Smithbe8f8c42016-02-27 20:14:29 +00001427void LiveIntervals::handleMoveIntoBundle(MachineInstr &MI,
1428 MachineInstr &BundleStart,
Andrew Trickd9d4be02012-10-16 00:22:51 +00001429 bool UpdateFlags) {
Duncan P. N. Exon Smithbe8f8c42016-02-27 20:14:29 +00001430 SlotIndex OldIndex = Indexes->getInstructionIndex(MI);
1431 SlotIndex NewIndex = Indexes->getInstructionIndex(BundleStart);
Andrew Trickd9d4be02012-10-16 00:22:51 +00001432 HMEditor HME(*this, *MRI, *TRI, OldIndex, NewIndex, UpdateFlags);
Duncan P. N. Exon Smithbe8f8c42016-02-27 20:14:29 +00001433 HME.updateAllRanges(&MI);
Lang Hamesb9057d52012-02-17 18:44:18 +00001434}
Cameron Zwarichbfebb412013-02-17 00:10:44 +00001435
Matthias Braune5f861b2014-12-10 01:12:26 +00001436void LiveIntervals::repairOldRegInRange(const MachineBasicBlock::iterator Begin,
1437 const MachineBasicBlock::iterator End,
1438 const SlotIndex endIdx,
1439 LiveRange &LR, const unsigned Reg,
Matthias Braune6a24852015-09-25 21:51:14 +00001440 LaneBitmask LaneMask) {
Matthias Braune5f861b2014-12-10 01:12:26 +00001441 LiveInterval::iterator LII = LR.find(endIdx);
1442 SlotIndex lastUseIdx;
Nicolai Haehnle02d78412016-08-10 18:51:14 +00001443 if (LII == LR.begin()) {
1444 // This happens when the function is called for a subregister that only
1445 // occurs _after_ the range that is to be repaired.
1446 return;
1447 }
Matthias Braune5f861b2014-12-10 01:12:26 +00001448 if (LII != LR.end() && LII->start < endIdx)
1449 lastUseIdx = LII->end;
1450 else
1451 --LII;
1452
1453 for (MachineBasicBlock::iterator I = End; I != Begin;) {
1454 --I;
Duncan P. N. Exon Smithbe8f8c42016-02-27 20:14:29 +00001455 MachineInstr &MI = *I;
Shiva Chen801bf7e2018-05-09 02:42:00 +00001456 if (MI.isDebugInstr())
Matthias Braune5f861b2014-12-10 01:12:26 +00001457 continue;
1458
Duncan P. N. Exon Smithbe8f8c42016-02-27 20:14:29 +00001459 SlotIndex instrIdx = getInstructionIndex(MI);
Matthias Braune5f861b2014-12-10 01:12:26 +00001460 bool isStartValid = getInstructionFromIndex(LII->start);
1461 bool isEndValid = getInstructionFromIndex(LII->end);
1462
1463 // FIXME: This doesn't currently handle early-clobber or multiple removed
1464 // defs inside of the region to repair.
Duncan P. N. Exon Smithbe8f8c42016-02-27 20:14:29 +00001465 for (MachineInstr::mop_iterator OI = MI.operands_begin(),
1466 OE = MI.operands_end();
1467 OI != OE; ++OI) {
Matthias Braune5f861b2014-12-10 01:12:26 +00001468 const MachineOperand &MO = *OI;
1469 if (!MO.isReg() || MO.getReg() != Reg)
1470 continue;
1471
1472 unsigned SubReg = MO.getSubReg();
Matthias Braune6a24852015-09-25 21:51:14 +00001473 LaneBitmask Mask = TRI->getSubRegIndexLaneMask(SubReg);
Krzysztof Parzyszek91b5cf82016-12-15 14:36:06 +00001474 if ((Mask & LaneMask).none())
Matthias Braune5f861b2014-12-10 01:12:26 +00001475 continue;
1476
1477 if (MO.isDef()) {
1478 if (!isStartValid) {
1479 if (LII->end.isDead()) {
1480 SlotIndex prevStart;
1481 if (LII != LR.begin())
1482 prevStart = std::prev(LII)->start;
1483
1484 // FIXME: This could be more efficient if there was a
1485 // removeSegment method that returned an iterator.
1486 LR.removeSegment(*LII, true);
1487 if (prevStart.isValid())
1488 LII = LR.find(prevStart);
1489 else
1490 LII = LR.begin();
1491 } else {
1492 LII->start = instrIdx.getRegSlot();
1493 LII->valno->def = instrIdx.getRegSlot();
1494 if (MO.getSubReg() && !MO.isUndef())
1495 lastUseIdx = instrIdx.getRegSlot();
1496 else
1497 lastUseIdx = SlotIndex();
1498 continue;
1499 }
1500 }
1501
1502 if (!lastUseIdx.isValid()) {
1503 VNInfo *VNI = LR.getNextValue(instrIdx.getRegSlot(), VNInfoAllocator);
1504 LiveRange::Segment S(instrIdx.getRegSlot(),
1505 instrIdx.getDeadSlot(), VNI);
1506 LII = LR.addSegment(S);
1507 } else if (LII->start != instrIdx.getRegSlot()) {
1508 VNInfo *VNI = LR.getNextValue(instrIdx.getRegSlot(), VNInfoAllocator);
1509 LiveRange::Segment S(instrIdx.getRegSlot(), lastUseIdx, VNI);
1510 LII = LR.addSegment(S);
1511 }
1512
1513 if (MO.getSubReg() && !MO.isUndef())
1514 lastUseIdx = instrIdx.getRegSlot();
1515 else
1516 lastUseIdx = SlotIndex();
1517 } else if (MO.isUse()) {
1518 // FIXME: This should probably be handled outside of this branch,
1519 // either as part of the def case (for defs inside of the region) or
1520 // after the loop over the region.
1521 if (!isEndValid && !LII->end.isBlock())
1522 LII->end = instrIdx.getRegSlot();
1523 if (!lastUseIdx.isValid())
1524 lastUseIdx = instrIdx.getRegSlot();
1525 }
1526 }
1527 }
1528}
1529
Cameron Zwarichbfebb412013-02-17 00:10:44 +00001530void
1531LiveIntervals::repairIntervalsInRange(MachineBasicBlock *MBB,
Cameron Zwarich24955962013-02-17 11:09:00 +00001532 MachineBasicBlock::iterator Begin,
1533 MachineBasicBlock::iterator End,
Cameron Zwarich1286ef92013-02-17 03:48:23 +00001534 ArrayRef<unsigned> OrigRegs) {
Cameron Zwarichcaad7e12013-02-20 22:10:00 +00001535 // Find anchor points, which are at the beginning/end of blocks or at
1536 // instructions that already have indexes.
Duncan P. N. Exon Smith3ac9cc62016-02-27 06:40:41 +00001537 while (Begin != MBB->begin() && !Indexes->hasIndex(*Begin))
Cameron Zwarichcaad7e12013-02-20 22:10:00 +00001538 --Begin;
Duncan P. N. Exon Smith3ac9cc62016-02-27 06:40:41 +00001539 while (End != MBB->end() && !Indexes->hasIndex(*End))
Cameron Zwarichcaad7e12013-02-20 22:10:00 +00001540 ++End;
1541
Cameron Zwarich8e60d4d2013-02-20 06:46:48 +00001542 SlotIndex endIdx;
1543 if (End == MBB->end())
1544 endIdx = getMBBEndIdx(MBB).getPrevSlot();
Cameron Zwarich24955962013-02-17 11:09:00 +00001545 else
Duncan P. N. Exon Smith3ac9cc62016-02-27 06:40:41 +00001546 endIdx = getInstructionIndex(*End);
Cameron Zwarich24955962013-02-17 11:09:00 +00001547
Hal Finkel7b1b3da2016-05-21 16:03:50 +00001548 Indexes->repairIndexesInRange(MBB, Begin, End);
Cameron Zwarich29414822013-02-20 06:46:41 +00001549
Cameron Zwarich8e60d4d2013-02-20 06:46:48 +00001550 for (MachineBasicBlock::iterator I = End; I != Begin;) {
1551 --I;
Duncan P. N. Exon Smithbe8f8c42016-02-27 20:14:29 +00001552 MachineInstr &MI = *I;
Shiva Chen801bf7e2018-05-09 02:42:00 +00001553 if (MI.isDebugInstr())
Cameron Zwarich63acc732013-02-23 10:25:25 +00001554 continue;
Duncan P. N. Exon Smithbe8f8c42016-02-27 20:14:29 +00001555 for (MachineInstr::const_mop_iterator MOI = MI.operands_begin(),
1556 MOE = MI.operands_end();
1557 MOI != MOE; ++MOI) {
Cameron Zwarich8e60d4d2013-02-20 06:46:48 +00001558 if (MOI->isReg() &&
1559 TargetRegisterInfo::isVirtualRegister(MOI->getReg()) &&
1560 !hasInterval(MOI->getReg())) {
Mark Lacey9d8103d2013-08-14 23:50:16 +00001561 createAndComputeVirtRegInterval(MOI->getReg());
Cameron Zwarich8e60d4d2013-02-20 06:46:48 +00001562 }
1563 }
1564 }
1565
Matthias Braun9f21a8d2017-01-19 00:32:13 +00001566 for (unsigned Reg : OrigRegs) {
Cameron Zwarichbfebb412013-02-17 00:10:44 +00001567 if (!TargetRegisterInfo::isVirtualRegister(Reg))
1568 continue;
1569
1570 LiveInterval &LI = getInterval(Reg);
Cameron Zwarich8e7dc062013-02-20 22:09:57 +00001571 // FIXME: Should we support undefs that gain defs?
1572 if (!LI.hasAtLeastOneValue())
1573 continue;
1574
Matthias Braun9f21a8d2017-01-19 00:32:13 +00001575 for (LiveInterval::SubRange &S : LI.subranges())
Matthias Braun09afa1e2014-12-11 00:59:06 +00001576 repairOldRegInRange(Begin, End, endIdx, S, Reg, S.LaneMask);
Matthias Braun9f21a8d2017-01-19 00:32:13 +00001577
Matthias Braune5f861b2014-12-10 01:12:26 +00001578 repairOldRegInRange(Begin, End, endIdx, LI, Reg);
Cameron Zwarichbfebb412013-02-17 00:10:44 +00001579 }
1580}
Matthias Brauncfb8ad22015-01-21 18:50:21 +00001581
1582void LiveIntervals::removePhysRegDefAt(unsigned Reg, SlotIndex Pos) {
Matthias Braun9f21a8d2017-01-19 00:32:13 +00001583 for (MCRegUnitIterator Unit(Reg, TRI); Unit.isValid(); ++Unit) {
1584 if (LiveRange *LR = getCachedRegUnit(*Unit))
Matthias Brauncfb8ad22015-01-21 18:50:21 +00001585 if (VNInfo *VNI = LR->getVNInfoAt(Pos))
1586 LR->removeValNo(VNI);
1587 }
1588}
Matthias Braun311730a2015-01-21 19:02:30 +00001589
1590void LiveIntervals::removeVRegDefAt(LiveInterval &LI, SlotIndex Pos) {
Krzysztof Parzyszeka7ed0902016-08-24 13:37:55 +00001591 // LI may not have the main range computed yet, but its subranges may
1592 // be present.
Matthias Braun311730a2015-01-21 19:02:30 +00001593 VNInfo *VNI = LI.getVNInfoAt(Pos);
Krzysztof Parzyszeka7ed0902016-08-24 13:37:55 +00001594 if (VNI != nullptr) {
1595 assert(VNI->def.getBaseIndex() == Pos.getBaseIndex());
1596 LI.removeValNo(VNI);
1597 }
Matthias Braun311730a2015-01-21 19:02:30 +00001598
Krzysztof Parzyszeka7ed0902016-08-24 13:37:55 +00001599 // Also remove the value defined in subranges.
Matthias Braun311730a2015-01-21 19:02:30 +00001600 for (LiveInterval::SubRange &S : LI.subranges()) {
1601 if (VNInfo *SVNI = S.getVNInfoAt(Pos))
Krzysztof Parzyszeka7ed0902016-08-24 13:37:55 +00001602 if (SVNI->def.getBaseIndex() == Pos.getBaseIndex())
1603 S.removeValNo(SVNI);
Matthias Braun311730a2015-01-21 19:02:30 +00001604 }
1605 LI.removeEmptySubRanges();
1606}
Matthias Braund3dd1352015-09-22 03:44:41 +00001607
1608void LiveIntervals::splitSeparateComponents(LiveInterval &LI,
1609 SmallVectorImpl<LiveInterval*> &SplitLIs) {
1610 ConnectedVNInfoEqClasses ConEQ(*this);
Matthias Braunbf47f632016-01-08 01:16:35 +00001611 unsigned NumComp = ConEQ.Classify(LI);
Matthias Braund3dd1352015-09-22 03:44:41 +00001612 if (NumComp <= 1)
1613 return;
1614 DEBUG(dbgs() << " Split " << NumComp << " components: " << LI << '\n');
1615 unsigned Reg = LI.reg;
1616 const TargetRegisterClass *RegClass = MRI->getRegClass(Reg);
1617 for (unsigned I = 1; I < NumComp; ++I) {
1618 unsigned NewVReg = MRI->createVirtualRegister(RegClass);
1619 LiveInterval &NewLI = createEmptyInterval(NewVReg);
1620 SplitLIs.push_back(&NewLI);
1621 }
1622 ConEQ.Distribute(LI, SplitLIs.data(), *MRI);
1623}
Matthias Braun3907fde2016-01-20 00:23:21 +00001624
Matthias Braun71f95642016-05-20 23:14:56 +00001625void LiveIntervals::constructMainRangeFromSubranges(LiveInterval &LI) {
1626 assert(LRCalc && "LRCalc not initialized.");
1627 LRCalc->reset(MF, getSlotIndexes(), DomTree, &getVNInfoAllocator());
1628 LRCalc->constructMainRangeFromSubranges(LI);
1629}