blob: 369493ff94e54a591dbe40aeb128408618cc1aab [file] [log] [blame]
Chris Lattnera3b8b5c2004-07-23 17:56:30 +00001//===-- LiveIntervalAnalysis.cpp - Live Interval Analysis -----------------===//
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// 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 uses the
13// LiveVariables pass to conservatively compute live intervals for
14// each virtual and physical register.
15//
16//===----------------------------------------------------------------------===//
17
18#define DEBUG_TYPE "liveintervals"
Chris Lattner3c3fe462005-09-21 04:19:09 +000019#include "llvm/CodeGen/LiveIntervalAnalysis.h"
Misha Brukman08a6c762004-09-03 18:25:53 +000020#include "VirtRegMap.h"
Chris Lattner015959e2004-05-01 21:24:39 +000021#include "llvm/Value.h"
Alkis Evlogimenos6b4edba2003-12-21 20:19:10 +000022#include "llvm/Analysis/LoopInfo.h"
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +000023#include "llvm/CodeGen/LiveVariables.h"
24#include "llvm/CodeGen/MachineFrameInfo.h"
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +000025#include "llvm/CodeGen/MachineInstr.h"
26#include "llvm/CodeGen/Passes.h"
27#include "llvm/CodeGen/SSARegMap.h"
28#include "llvm/Target/MRegisterInfo.h"
29#include "llvm/Target/TargetInstrInfo.h"
30#include "llvm/Target/TargetMachine.h"
Reid Spencer551ccae2004-09-01 22:55:40 +000031#include "llvm/Support/CommandLine.h"
32#include "llvm/Support/Debug.h"
Evan Cheng20b0abc2007-04-17 20:32:26 +000033#include "llvm/ADT/SmallSet.h"
Reid Spencer551ccae2004-09-01 22:55:40 +000034#include "llvm/ADT/Statistic.h"
35#include "llvm/ADT/STLExtras.h"
Alkis Evlogimenos20aa4742004-09-03 18:19:51 +000036#include <algorithm>
Jeff Cohen97af7512006-12-02 02:22:01 +000037#include <cmath>
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +000038using namespace llvm;
39
Chris Lattnercd3245a2006-12-19 22:41:21 +000040STATISTIC(numIntervals, "Number of original intervals");
41STATISTIC(numIntervalsAfter, "Number of intervals after coalescing");
Chris Lattnercd3245a2006-12-19 22:41:21 +000042STATISTIC(numFolded , "Number of loads/stores folded into instructions");
43
Devang Patel19974732007-05-03 01:11:54 +000044char LiveIntervals::ID = 0;
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +000045namespace {
Chris Lattner5d8925c2006-08-27 22:30:17 +000046 RegisterPass<LiveIntervals> X("liveintervals", "Live Interval Analysis");
Chris Lattnerd74ea2b2006-05-24 17:04:05 +000047}
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +000048
Chris Lattnerf7da2c72006-08-24 22:43:55 +000049void LiveIntervals::getAnalysisUsage(AnalysisUsage &AU) const {
David Greene25133302007-06-08 17:18:56 +000050 AU.addPreserved<LiveVariables>();
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +000051 AU.addRequired<LiveVariables>();
52 AU.addPreservedID(PHIEliminationID);
53 AU.addRequiredID(PHIEliminationID);
54 AU.addRequiredID(TwoAddressInstructionPassID);
55 AU.addRequired<LoopInfo>();
56 MachineFunctionPass::getAnalysisUsage(AU);
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +000057}
58
Chris Lattnerf7da2c72006-08-24 22:43:55 +000059void LiveIntervals::releaseMemory() {
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +000060 mi2iMap_.clear();
61 i2miMap_.clear();
62 r2iMap_.clear();
Alkis Evlogimenos08cec002004-01-31 19:59:32 +000063}
64
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +000065/// runOnMachineFunction - Register allocate the whole function
66///
67bool LiveIntervals::runOnMachineFunction(MachineFunction &fn) {
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +000068 mf_ = &fn;
69 tm_ = &fn.getTarget();
70 mri_ = tm_->getRegisterInfo();
Chris Lattnerf768bba2005-03-09 23:05:19 +000071 tii_ = tm_->getInstrInfo();
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +000072 lv_ = &getAnalysis<LiveVariables>();
Evan Cheng20b0abc2007-04-17 20:32:26 +000073 allocatableRegs_ = mri_->getAllocatableSet(fn);
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +000074
Chris Lattner428b92e2006-09-15 03:57:23 +000075 // Number MachineInstrs and MachineBasicBlocks.
76 // Initialize MBB indexes to a sentinal.
77 MBB2IdxMap.resize(mf_->getNumBlockIDs(), ~0U);
78
79 unsigned MIIndex = 0;
80 for (MachineFunction::iterator MBB = mf_->begin(), E = mf_->end();
81 MBB != E; ++MBB) {
82 // Set the MBB2IdxMap entry for this MBB.
83 MBB2IdxMap[MBB->getNumber()] = MIIndex;
Evan Cheng0c9f92e2007-02-13 01:30:55 +000084
Chris Lattner428b92e2006-09-15 03:57:23 +000085 for (MachineBasicBlock::iterator I = MBB->begin(), E = MBB->end();
86 I != E; ++I) {
87 bool inserted = mi2iMap_.insert(std::make_pair(I, MIIndex)).second;
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +000088 assert(inserted && "multiple MachineInstr -> index mappings");
Chris Lattner428b92e2006-09-15 03:57:23 +000089 i2miMap_.push_back(I);
90 MIIndex += InstrSlots::NUM;
Alkis Evlogimenos843b1602004-02-15 10:24:21 +000091 }
Chris Lattner428b92e2006-09-15 03:57:23 +000092 }
Alkis Evlogimenosd6e40a62004-01-14 10:44:29 +000093
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +000094 computeIntervals();
Alkis Evlogimenos843b1602004-02-15 10:24:21 +000095
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +000096 numIntervals += getNumIntervals();
97
Bill Wendlingbdc679d2006-11-29 00:39:47 +000098 DOUT << "********** INTERVALS **********\n";
99 for (iterator I = begin(), E = end(); I != E; ++I) {
100 I->second.print(DOUT, mri_);
101 DOUT << "\n";
102 }
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000103
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000104 numIntervalsAfter += getNumIntervals();
Chris Lattner70ca3582004-09-30 15:59:17 +0000105 DEBUG(dump());
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000106 return true;
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +0000107}
108
Chris Lattner70ca3582004-09-30 15:59:17 +0000109/// print - Implement the dump method.
Reid Spencerce9653c2004-12-07 04:03:45 +0000110void LiveIntervals::print(std::ostream &O, const Module* ) const {
Chris Lattner70ca3582004-09-30 15:59:17 +0000111 O << "********** INTERVALS **********\n";
Chris Lattner8e7a7092005-07-27 23:03:38 +0000112 for (const_iterator I = begin(), E = end(); I != E; ++I) {
Bill Wendlingbdc679d2006-11-29 00:39:47 +0000113 I->second.print(DOUT, mri_);
114 DOUT << "\n";
Chris Lattner8e7a7092005-07-27 23:03:38 +0000115 }
Chris Lattner70ca3582004-09-30 15:59:17 +0000116
117 O << "********** MACHINEINSTRS **********\n";
118 for (MachineFunction::iterator mbbi = mf_->begin(), mbbe = mf_->end();
119 mbbi != mbbe; ++mbbi) {
120 O << ((Value*)mbbi->getBasicBlock())->getName() << ":\n";
121 for (MachineBasicBlock::iterator mii = mbbi->begin(),
122 mie = mbbi->end(); mii != mie; ++mii) {
Chris Lattner477e4552004-09-30 16:10:45 +0000123 O << getInstructionIndex(mii) << '\t' << *mii;
Chris Lattner70ca3582004-09-30 15:59:17 +0000124 }
125 }
126}
127
David Greene25133302007-06-08 17:18:56 +0000128// Not called?
Bill Wendling01352aa2006-11-16 02:41:50 +0000129/// CreateNewLiveInterval - Create a new live interval with the given live
130/// ranges. The new live interval will have an infinite spill weight.
131LiveInterval&
132LiveIntervals::CreateNewLiveInterval(const LiveInterval *LI,
133 const std::vector<LiveRange> &LRs) {
134 const TargetRegisterClass *RC = mf_->getSSARegMap()->getRegClass(LI->reg);
135
136 // Create a new virtual register for the spill interval.
137 unsigned NewVReg = mf_->getSSARegMap()->createVirtualRegister(RC);
138
139 // Replace the old virtual registers in the machine operands with the shiny
140 // new one.
141 for (std::vector<LiveRange>::const_iterator
142 I = LRs.begin(), E = LRs.end(); I != E; ++I) {
143 unsigned Index = getBaseIndex(I->start);
144 unsigned End = getBaseIndex(I->end - 1) + InstrSlots::NUM;
145
146 for (; Index != End; Index += InstrSlots::NUM) {
147 // Skip deleted instructions
148 while (Index != End && !getInstructionFromIndex(Index))
149 Index += InstrSlots::NUM;
150
151 if (Index == End) break;
152
153 MachineInstr *MI = getInstructionFromIndex(Index);
154
Bill Wendlingbeeb77f2006-11-16 07:35:18 +0000155 for (unsigned J = 0, e = MI->getNumOperands(); J != e; ++J) {
Bill Wendling01352aa2006-11-16 02:41:50 +0000156 MachineOperand &MOp = MI->getOperand(J);
David Greene25133302007-06-08 17:18:56 +0000157 if (MOp.isRegister() && MOp.getReg() == LI->reg)
Bill Wendling01352aa2006-11-16 02:41:50 +0000158 MOp.setReg(NewVReg);
159 }
160 }
161 }
162
163 LiveInterval &NewLI = getOrCreateInterval(NewVReg);
164
165 // The spill weight is now infinity as it cannot be spilled again
166 NewLI.weight = float(HUGE_VAL);
167
168 for (std::vector<LiveRange>::const_iterator
169 I = LRs.begin(), E = LRs.end(); I != E; ++I) {
Bill Wendlingbdc679d2006-11-29 00:39:47 +0000170 DOUT << " Adding live range " << *I << " to new interval\n";
Bill Wendling01352aa2006-11-16 02:41:50 +0000171 NewLI.addRange(*I);
172 }
173
Bill Wendlingbdc679d2006-11-29 00:39:47 +0000174 DOUT << "Created new live interval " << NewLI << "\n";
Bill Wendling01352aa2006-11-16 02:41:50 +0000175 return NewLI;
176}
177
Chris Lattner70ca3582004-09-30 15:59:17 +0000178std::vector<LiveInterval*> LiveIntervals::
179addIntervalsForSpills(const LiveInterval &li, VirtRegMap &vrm, int slot) {
Alkis Evlogimenosd8d26b32004-08-27 18:59:22 +0000180 // since this is called after the analysis is done we don't know if
181 // LiveVariables is available
182 lv_ = getAnalysisToUpdate<LiveVariables>();
183
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000184 std::vector<LiveInterval*> added;
Alkis Evlogimenos26f5a692004-05-30 07:24:39 +0000185
Jim Laskey7902c752006-11-07 12:25:45 +0000186 assert(li.weight != HUGE_VALF &&
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000187 "attempt to spill already spilled interval!");
Alkis Evlogimenos843b1602004-02-15 10:24:21 +0000188
Bill Wendlingbdc679d2006-11-29 00:39:47 +0000189 DOUT << "\t\t\t\tadding intervals for spills for interval: ";
190 li.print(DOUT, mri_);
191 DOUT << '\n';
Alkis Evlogimenos39a0d5c2004-02-20 06:15:40 +0000192
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000193 const TargetRegisterClass* rc = mf_->getSSARegMap()->getRegClass(li.reg);
Alkis Evlogimenos26f5a692004-05-30 07:24:39 +0000194
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000195 for (LiveInterval::Ranges::const_iterator
196 i = li.ranges.begin(), e = li.ranges.end(); i != e; ++i) {
197 unsigned index = getBaseIndex(i->start);
198 unsigned end = getBaseIndex(i->end-1) + InstrSlots::NUM;
199 for (; index != end; index += InstrSlots::NUM) {
200 // skip deleted instructions
201 while (index != end && !getInstructionFromIndex(index))
202 index += InstrSlots::NUM;
203 if (index == end) break;
Chris Lattner8640f4e2004-07-19 15:16:53 +0000204
Chris Lattner3b9db832006-01-03 07:41:37 +0000205 MachineInstr *MI = getInstructionFromIndex(index);
Alkis Evlogimenos39a0d5c2004-02-20 06:15:40 +0000206
Chris Lattner29268692006-09-05 02:12:02 +0000207 RestartInstruction:
Chris Lattner3b9db832006-01-03 07:41:37 +0000208 for (unsigned i = 0; i != MI->getNumOperands(); ++i) {
209 MachineOperand& mop = MI->getOperand(i);
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000210 if (mop.isRegister() && mop.getReg() == li.reg) {
Evan Cheng2638e1a2007-03-20 08:13:50 +0000211 MachineInstr *fmi = li.remat ? NULL
212 : mri_->foldMemoryOperand(MI, i, slot);
213 if (fmi) {
Chris Lattnerb11443d2005-09-09 19:17:47 +0000214 // Attempt to fold the memory reference into the instruction. If we
215 // can do this, we don't need to insert spill code.
Alkis Evlogimenosd8d26b32004-08-27 18:59:22 +0000216 if (lv_)
Chris Lattner3b9db832006-01-03 07:41:37 +0000217 lv_->instructionChanged(MI, fmi);
Evan Cheng200370f2006-04-30 08:41:47 +0000218 MachineBasicBlock &MBB = *MI->getParent();
Chris Lattner35f27052006-05-01 21:16:03 +0000219 vrm.virtFolded(li.reg, MI, i, fmi);
Chris Lattner3b9db832006-01-03 07:41:37 +0000220 mi2iMap_.erase(MI);
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000221 i2miMap_[index/InstrSlots::NUM] = fmi;
222 mi2iMap_[fmi] = index;
Chris Lattner3b9db832006-01-03 07:41:37 +0000223 MI = MBB.insert(MBB.erase(MI), fmi);
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000224 ++numFolded;
Chris Lattner477e4552004-09-30 16:10:45 +0000225 // Folding the load/store can completely change the instruction in
226 // unpredictable ways, rescan it from the beginning.
Chris Lattner29268692006-09-05 02:12:02 +0000227 goto RestartInstruction;
Chris Lattner477e4552004-09-30 16:10:45 +0000228 } else {
Chris Lattner29268692006-09-05 02:12:02 +0000229 // Create a new virtual register for the spill interval.
230 unsigned NewVReg = mf_->getSSARegMap()->createVirtualRegister(rc);
231
232 // Scan all of the operands of this instruction rewriting operands
233 // to use NewVReg instead of li.reg as appropriate. We do this for
234 // two reasons:
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000235 //
Chris Lattner29268692006-09-05 02:12:02 +0000236 // 1. If the instr reads the same spilled vreg multiple times, we
237 // want to reuse the NewVReg.
238 // 2. If the instr is a two-addr instruction, we are required to
239 // keep the src/dst regs pinned.
240 //
241 // Keep track of whether we replace a use and/or def so that we can
242 // create the spill interval with the appropriate range.
243 mop.setReg(NewVReg);
244
245 bool HasUse = mop.isUse();
246 bool HasDef = mop.isDef();
247 for (unsigned j = i+1, e = MI->getNumOperands(); j != e; ++j) {
248 if (MI->getOperand(j).isReg() &&
249 MI->getOperand(j).getReg() == li.reg) {
250 MI->getOperand(j).setReg(NewVReg);
251 HasUse |= MI->getOperand(j).isUse();
252 HasDef |= MI->getOperand(j).isDef();
253 }
254 }
Alkis Evlogimenos26f5a692004-05-30 07:24:39 +0000255
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000256 // create a new register for this spill
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000257 vrm.grow();
Evan Cheng2638e1a2007-03-20 08:13:50 +0000258 if (li.remat)
259 vrm.setVirtIsReMaterialized(NewVReg, li.remat);
Chris Lattner29268692006-09-05 02:12:02 +0000260 vrm.assignVirt2StackSlot(NewVReg, slot);
261 LiveInterval &nI = getOrCreateInterval(NewVReg);
Evan Cheng2638e1a2007-03-20 08:13:50 +0000262 nI.remat = li.remat;
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000263 assert(nI.empty());
Chris Lattner70ca3582004-09-30 15:59:17 +0000264
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000265 // the spill weight is now infinity as it
266 // cannot be spilled again
Jim Laskey7902c752006-11-07 12:25:45 +0000267 nI.weight = HUGE_VALF;
Chris Lattner29268692006-09-05 02:12:02 +0000268
269 if (HasUse) {
270 LiveRange LR(getLoadIndex(index), getUseIndex(index),
271 nI.getNextValue(~0U, 0));
Bill Wendlingbdc679d2006-11-29 00:39:47 +0000272 DOUT << " +" << LR;
Chris Lattner29268692006-09-05 02:12:02 +0000273 nI.addRange(LR);
274 }
275 if (HasDef) {
276 LiveRange LR(getDefIndex(index), getStoreIndex(index),
277 nI.getNextValue(~0U, 0));
Bill Wendlingbdc679d2006-11-29 00:39:47 +0000278 DOUT << " +" << LR;
Chris Lattner29268692006-09-05 02:12:02 +0000279 nI.addRange(LR);
280 }
281
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000282 added.push_back(&nI);
Chris Lattner70ca3582004-09-30 15:59:17 +0000283
Alkis Evlogimenosd8d26b32004-08-27 18:59:22 +0000284 // update live variables if it is available
285 if (lv_)
Chris Lattner29268692006-09-05 02:12:02 +0000286 lv_->addVirtualRegisterKilled(NewVReg, MI);
Chris Lattnerb11443d2005-09-09 19:17:47 +0000287
Bill Wendlingbdc679d2006-11-29 00:39:47 +0000288 DOUT << "\t\t\t\tadded new interval: ";
289 nI.print(DOUT, mri_);
290 DOUT << '\n';
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000291 }
Alkis Evlogimenos843b1602004-02-15 10:24:21 +0000292 }
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000293 }
Alkis Evlogimenos843b1602004-02-15 10:24:21 +0000294 }
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000295 }
Alkis Evlogimenos26f5a692004-05-30 07:24:39 +0000296
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000297 return added;
Alkis Evlogimenos843b1602004-02-15 10:24:21 +0000298}
299
Chris Lattnerbe4f88a2006-08-22 18:19:46 +0000300void LiveIntervals::printRegName(unsigned reg) const {
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000301 if (MRegisterInfo::isPhysicalRegister(reg))
Bill Wendlinge8156192006-12-07 01:30:32 +0000302 cerr << mri_->getName(reg);
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000303 else
Bill Wendlinge8156192006-12-07 01:30:32 +0000304 cerr << "%reg" << reg;
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +0000305}
306
Evan Chengbf105c82006-11-03 03:04:46 +0000307/// isReDefinedByTwoAddr - Returns true if the Reg re-definition is due to
308/// two addr elimination.
309static bool isReDefinedByTwoAddr(MachineInstr *MI, unsigned Reg,
310 const TargetInstrInfo *TII) {
311 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
312 MachineOperand &MO1 = MI->getOperand(i);
313 if (MO1.isRegister() && MO1.isDef() && MO1.getReg() == Reg) {
314 for (unsigned j = i+1; j < e; ++j) {
315 MachineOperand &MO2 = MI->getOperand(j);
316 if (MO2.isRegister() && MO2.isUse() && MO2.getReg() == Reg &&
Evan Cheng51cdcd12006-12-07 01:21:59 +0000317 MI->getInstrDescriptor()->
318 getOperandConstraint(j, TOI::TIED_TO) == (int)i)
Evan Chengbf105c82006-11-03 03:04:46 +0000319 return true;
320 }
321 }
322 }
323 return false;
324}
325
Chris Lattnerbe4f88a2006-08-22 18:19:46 +0000326void LiveIntervals::handleVirtualRegisterDef(MachineBasicBlock *mbb,
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +0000327 MachineBasicBlock::iterator mi,
Chris Lattner6b128bd2006-09-03 08:07:11 +0000328 unsigned MIIdx,
Chris Lattnerbe4f88a2006-08-22 18:19:46 +0000329 LiveInterval &interval) {
Bill Wendlingbdc679d2006-11-29 00:39:47 +0000330 DOUT << "\t\tregister: "; DEBUG(printRegName(interval.reg));
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000331 LiveVariables::VarInfo& vi = lv_->getVarInfo(interval.reg);
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +0000332
Alkis Evlogimenos70651572004-08-04 09:46:56 +0000333 // Virtual registers may be defined multiple times (due to phi
334 // elimination and 2-addr elimination). Much of what we do only has to be
335 // done once for the vreg. We use an empty interval to detect the first
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000336 // time we see a vreg.
337 if (interval.empty()) {
Evan Cheng91935142007-04-04 07:40:01 +0000338 // Remember if the definition can be rematerialized. All load's from fixed
Dan Gohman82a87a02007-06-19 01:48:05 +0000339 // stack slots are re-materializable. The target may permit other
340 // instructions to be re-materialized as well.
Evan Cheng91935142007-04-04 07:40:01 +0000341 int FrameIdx = 0;
342 if (vi.DefInst &&
Dan Gohman82a87a02007-06-19 01:48:05 +0000343 (tii_->isTriviallyReMaterializable(vi.DefInst) ||
Evan Cheng91935142007-04-04 07:40:01 +0000344 (tii_->isLoadFromStackSlot(vi.DefInst, FrameIdx) &&
Dan Gohman82a87a02007-06-19 01:48:05 +0000345 mf_->getFrameInfo()->isFixedObjectIndex(FrameIdx))))
Evan Cheng2638e1a2007-03-20 08:13:50 +0000346 interval.remat = vi.DefInst;
347
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000348 // Get the Idx of the defining instructions.
Chris Lattner6b128bd2006-09-03 08:07:11 +0000349 unsigned defIndex = getDefIndex(MIIdx);
Chris Lattner6097d132004-07-19 02:15:56 +0000350
Chris Lattner91725b72006-08-31 05:54:43 +0000351 unsigned ValNum;
352 unsigned SrcReg, DstReg;
353 if (!tii_->isMoveInstr(*mi, SrcReg, DstReg))
354 ValNum = interval.getNextValue(~0U, 0);
355 else
356 ValNum = interval.getNextValue(defIndex, SrcReg);
357
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000358 assert(ValNum == 0 && "First value in interval is not 0?");
359 ValNum = 0; // Clue in the optimizer.
Chris Lattner7ac2d312004-07-24 02:59:07 +0000360
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000361 // Loop over all of the blocks that the vreg is defined in. There are
362 // two cases we have to handle here. The most common case is a vreg
363 // whose lifetime is contained within a basic block. In this case there
364 // will be a single kill, in MBB, which comes after the definition.
365 if (vi.Kills.size() == 1 && vi.Kills[0]->getParent() == mbb) {
366 // FIXME: what about dead vars?
367 unsigned killIdx;
368 if (vi.Kills[0] != mi)
369 killIdx = getUseIndex(getInstructionIndex(vi.Kills[0]))+1;
370 else
371 killIdx = defIndex+1;
Chris Lattner6097d132004-07-19 02:15:56 +0000372
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000373 // If the kill happens after the definition, we have an intra-block
374 // live range.
375 if (killIdx > defIndex) {
Evan Cheng61de82d2007-02-15 05:59:24 +0000376 assert(vi.AliveBlocks.none() &&
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000377 "Shouldn't be alive across any blocks!");
378 LiveRange LR(defIndex, killIdx, ValNum);
379 interval.addRange(LR);
Bill Wendlingbdc679d2006-11-29 00:39:47 +0000380 DOUT << " +" << LR << "\n";
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000381 return;
382 }
Alkis Evlogimenosdd2cc652003-12-18 08:48:48 +0000383 }
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +0000384
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000385 // The other case we handle is when a virtual register lives to the end
386 // of the defining block, potentially live across some blocks, then is
387 // live into some number of blocks, but gets killed. Start by adding a
388 // range that goes from this definition to the end of the defining block.
Alkis Evlogimenosd19e2902004-08-31 17:39:15 +0000389 LiveRange NewLR(defIndex,
390 getInstructionIndex(&mbb->back()) + InstrSlots::NUM,
391 ValNum);
Bill Wendlingbdc679d2006-11-29 00:39:47 +0000392 DOUT << " +" << NewLR;
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000393 interval.addRange(NewLR);
394
395 // Iterate over all of the blocks that the variable is completely
396 // live in, adding [insrtIndex(begin), instrIndex(end)+4) to the
397 // live interval.
398 for (unsigned i = 0, e = vi.AliveBlocks.size(); i != e; ++i) {
399 if (vi.AliveBlocks[i]) {
Chris Lattner428b92e2006-09-15 03:57:23 +0000400 MachineBasicBlock *MBB = mf_->getBlockNumbered(i);
401 if (!MBB->empty()) {
402 LiveRange LR(getMBBStartIdx(i),
403 getInstructionIndex(&MBB->back()) + InstrSlots::NUM,
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000404 ValNum);
405 interval.addRange(LR);
Bill Wendlingbdc679d2006-11-29 00:39:47 +0000406 DOUT << " +" << LR;
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000407 }
408 }
409 }
410
411 // Finally, this virtual register is live from the start of any killing
412 // block to the 'use' slot of the killing instruction.
413 for (unsigned i = 0, e = vi.Kills.size(); i != e; ++i) {
414 MachineInstr *Kill = vi.Kills[i];
Chris Lattner428b92e2006-09-15 03:57:23 +0000415 LiveRange LR(getMBBStartIdx(Kill->getParent()),
Alkis Evlogimenosd19e2902004-08-31 17:39:15 +0000416 getUseIndex(getInstructionIndex(Kill))+1,
417 ValNum);
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000418 interval.addRange(LR);
Bill Wendlingbdc679d2006-11-29 00:39:47 +0000419 DOUT << " +" << LR;
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000420 }
421
422 } else {
Evan Cheng91935142007-04-04 07:40:01 +0000423 // Can no longer safely assume definition is rematerializable.
Evan Cheng2638e1a2007-03-20 08:13:50 +0000424 interval.remat = NULL;
425
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000426 // If this is the second time we see a virtual register definition, it
427 // must be due to phi elimination or two addr elimination. If this is
Evan Chengbf105c82006-11-03 03:04:46 +0000428 // the result of two address elimination, then the vreg is one of the
429 // def-and-use register operand.
430 if (isReDefinedByTwoAddr(mi, interval.reg, tii_)) {
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000431 // If this is a two-address definition, then we have already processed
432 // the live range. The only problem is that we didn't realize there
433 // are actually two values in the live interval. Because of this we
434 // need to take the LiveRegion that defines this register and split it
435 // into two values.
436 unsigned DefIndex = getDefIndex(getInstructionIndex(vi.DefInst));
Chris Lattner6b128bd2006-09-03 08:07:11 +0000437 unsigned RedefIndex = getDefIndex(MIIdx);
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000438
439 // Delete the initial value, which should be short and continuous,
Chris Lattnerbe4f88a2006-08-22 18:19:46 +0000440 // because the 2-addr copy must be in the same MBB as the redef.
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000441 interval.removeRange(DefIndex, RedefIndex);
Alkis Evlogimenos70651572004-08-04 09:46:56 +0000442
Chris Lattnerbe4f88a2006-08-22 18:19:46 +0000443 // Two-address vregs should always only be redefined once. This means
444 // that at this point, there should be exactly one value number in it.
445 assert(interval.containsOneValue() && "Unexpected 2-addr liveint!");
446
Chris Lattner91725b72006-08-31 05:54:43 +0000447 // The new value number (#1) is defined by the instruction we claimed
448 // defined value #0.
449 unsigned ValNo = interval.getNextValue(0, 0);
450 interval.setValueNumberInfo(1, interval.getValNumInfo(0));
Chris Lattnerbe4f88a2006-08-22 18:19:46 +0000451
Chris Lattner91725b72006-08-31 05:54:43 +0000452 // Value#0 is now defined by the 2-addr instruction.
453 interval.setValueNumberInfo(0, std::make_pair(~0U, 0U));
Chris Lattnerbe4f88a2006-08-22 18:19:46 +0000454
455 // Add the new live interval which replaces the range for the input copy.
456 LiveRange LR(DefIndex, RedefIndex, ValNo);
Bill Wendlingbdc679d2006-11-29 00:39:47 +0000457 DOUT << " replace range with " << LR;
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000458 interval.addRange(LR);
459
460 // If this redefinition is dead, we need to add a dummy unit live
461 // range covering the def slot.
Chris Lattnerab4b66d2005-08-23 22:51:41 +0000462 if (lv_->RegisterDefIsDead(mi, interval.reg))
463 interval.addRange(LiveRange(RedefIndex, RedefIndex+1, 0));
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000464
Evan Cheng56fdd7a2007-03-15 21:19:28 +0000465 DOUT << " RESULT: ";
Bill Wendlingbdc679d2006-11-29 00:39:47 +0000466 interval.print(DOUT, mri_);
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000467
468 } else {
469 // Otherwise, this must be because of phi elimination. If this is the
470 // first redefinition of the vreg that we have seen, go back and change
471 // the live range in the PHI block to be a different value number.
472 if (interval.containsOneValue()) {
473 assert(vi.Kills.size() == 1 &&
474 "PHI elimination vreg should have one kill, the PHI itself!");
475
476 // Remove the old range that we now know has an incorrect number.
477 MachineInstr *Killer = vi.Kills[0];
Chris Lattner428b92e2006-09-15 03:57:23 +0000478 unsigned Start = getMBBStartIdx(Killer->getParent());
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000479 unsigned End = getUseIndex(getInstructionIndex(Killer))+1;
Evan Cheng56fdd7a2007-03-15 21:19:28 +0000480 DOUT << " Removing [" << Start << "," << End << "] from: ";
Bill Wendlingbdc679d2006-11-29 00:39:47 +0000481 interval.print(DOUT, mri_); DOUT << "\n";
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000482 interval.removeRange(Start, End);
Evan Cheng56fdd7a2007-03-15 21:19:28 +0000483 DOUT << " RESULT: "; interval.print(DOUT, mri_);
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000484
Chris Lattnerbe4f88a2006-08-22 18:19:46 +0000485 // Replace the interval with one of a NEW value number. Note that this
486 // value number isn't actually defined by an instruction, weird huh? :)
Chris Lattner91725b72006-08-31 05:54:43 +0000487 LiveRange LR(Start, End, interval.getNextValue(~0U, 0));
Bill Wendlingbdc679d2006-11-29 00:39:47 +0000488 DOUT << " replace range with " << LR;
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000489 interval.addRange(LR);
Evan Cheng56fdd7a2007-03-15 21:19:28 +0000490 DOUT << " RESULT: "; interval.print(DOUT, mri_);
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000491 }
492
493 // In the case of PHI elimination, each variable definition is only
494 // live until the end of the block. We've already taken care of the
495 // rest of the live range.
Chris Lattner6b128bd2006-09-03 08:07:11 +0000496 unsigned defIndex = getDefIndex(MIIdx);
Chris Lattner91725b72006-08-31 05:54:43 +0000497
498 unsigned ValNum;
499 unsigned SrcReg, DstReg;
500 if (!tii_->isMoveInstr(*mi, SrcReg, DstReg))
501 ValNum = interval.getNextValue(~0U, 0);
502 else
503 ValNum = interval.getNextValue(defIndex, SrcReg);
504
Alkis Evlogimenos70651572004-08-04 09:46:56 +0000505 LiveRange LR(defIndex,
Chris Lattner91725b72006-08-31 05:54:43 +0000506 getInstructionIndex(&mbb->back()) + InstrSlots::NUM, ValNum);
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000507 interval.addRange(LR);
Bill Wendlingbdc679d2006-11-29 00:39:47 +0000508 DOUT << " +" << LR;
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000509 }
510 }
511
Bill Wendlingbdc679d2006-11-29 00:39:47 +0000512 DOUT << '\n';
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +0000513}
514
Chris Lattnerf35fef72004-07-23 21:24:19 +0000515void LiveIntervals::handlePhysicalRegisterDef(MachineBasicBlock *MBB,
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +0000516 MachineBasicBlock::iterator mi,
Chris Lattner6b128bd2006-09-03 08:07:11 +0000517 unsigned MIIdx,
Chris Lattner91725b72006-08-31 05:54:43 +0000518 LiveInterval &interval,
519 unsigned SrcReg) {
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000520 // A physical register cannot be live across basic block, so its
521 // lifetime must end somewhere in its defining basic block.
Bill Wendlingbdc679d2006-11-29 00:39:47 +0000522 DOUT << "\t\tregister: "; DEBUG(printRegName(interval.reg));
Alkis Evlogimenos02ba13c2004-01-31 23:13:30 +0000523
Chris Lattner6b128bd2006-09-03 08:07:11 +0000524 unsigned baseIndex = MIIdx;
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000525 unsigned start = getDefIndex(baseIndex);
526 unsigned end = start;
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +0000527
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000528 // If it is not used after definition, it is considered dead at
529 // the instruction defining it. Hence its interval is:
530 // [defSlot(def), defSlot(def)+1)
Chris Lattnerab4b66d2005-08-23 22:51:41 +0000531 if (lv_->RegisterDefIsDead(mi, interval.reg)) {
Bill Wendlingbdc679d2006-11-29 00:39:47 +0000532 DOUT << " dead";
Chris Lattnerab4b66d2005-08-23 22:51:41 +0000533 end = getDefIndex(start) + 1;
534 goto exit;
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000535 }
536
537 // If it is not dead on definition, it must be killed by a
538 // subsequent instruction. Hence its interval is:
539 // [defSlot(def), useSlot(kill)+1)
Chris Lattner5ab6f5f2005-09-02 00:20:32 +0000540 while (++mi != MBB->end()) {
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000541 baseIndex += InstrSlots::NUM;
Chris Lattnerab4b66d2005-08-23 22:51:41 +0000542 if (lv_->KillsRegister(mi, interval.reg)) {
Bill Wendlingbdc679d2006-11-29 00:39:47 +0000543 DOUT << " killed";
Chris Lattnerab4b66d2005-08-23 22:51:41 +0000544 end = getUseIndex(baseIndex) + 1;
545 goto exit;
Evan Cheng9a1956a2006-11-15 20:54:11 +0000546 } else if (lv_->ModifiesRegister(mi, interval.reg)) {
547 // Another instruction redefines the register before it is ever read.
548 // Then the register is essentially dead at the instruction that defines
549 // it. Hence its interval is:
550 // [defSlot(def), defSlot(def)+1)
Bill Wendlingbdc679d2006-11-29 00:39:47 +0000551 DOUT << " dead";
Evan Cheng9a1956a2006-11-15 20:54:11 +0000552 end = getDefIndex(start) + 1;
553 goto exit;
Alkis Evlogimenosaf254732004-01-13 22:26:14 +0000554 }
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000555 }
Chris Lattner5ab6f5f2005-09-02 00:20:32 +0000556
557 // The only case we should have a dead physreg here without a killing or
558 // instruction where we know it's dead is if it is live-in to the function
559 // and never used.
Chris Lattner91725b72006-08-31 05:54:43 +0000560 assert(!SrcReg && "physreg was not killed in defining block!");
Chris Lattner5ab6f5f2005-09-02 00:20:32 +0000561 end = getDefIndex(start) + 1; // It's dead.
Alkis Evlogimenos02ba13c2004-01-31 23:13:30 +0000562
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +0000563exit:
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000564 assert(start < end && "did not find end of interval?");
Chris Lattnerf768bba2005-03-09 23:05:19 +0000565
Evan Cheng24a3cc42007-04-25 07:30:23 +0000566 // Already exists? Extend old live interval.
567 LiveInterval::iterator OldLR = interval.FindLiveRangeContaining(start);
568 unsigned Id = (OldLR != interval.end())
569 ? OldLR->ValId
570 : interval.getNextValue(SrcReg != 0 ? start : ~0U, SrcReg);
571 LiveRange LR(start, end, Id);
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000572 interval.addRange(LR);
Bill Wendlingbdc679d2006-11-29 00:39:47 +0000573 DOUT << " +" << LR << '\n';
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +0000574}
575
Chris Lattnerf35fef72004-07-23 21:24:19 +0000576void LiveIntervals::handleRegisterDef(MachineBasicBlock *MBB,
577 MachineBasicBlock::iterator MI,
Chris Lattner6b128bd2006-09-03 08:07:11 +0000578 unsigned MIIdx,
Chris Lattnerf35fef72004-07-23 21:24:19 +0000579 unsigned reg) {
580 if (MRegisterInfo::isVirtualRegister(reg))
Chris Lattner6b128bd2006-09-03 08:07:11 +0000581 handleVirtualRegisterDef(MBB, MI, MIIdx, getOrCreateInterval(reg));
Alkis Evlogimenos53278012004-08-26 22:22:38 +0000582 else if (allocatableRegs_[reg]) {
Chris Lattner91725b72006-08-31 05:54:43 +0000583 unsigned SrcReg, DstReg;
584 if (!tii_->isMoveInstr(*MI, SrcReg, DstReg))
585 SrcReg = 0;
Chris Lattner6b128bd2006-09-03 08:07:11 +0000586 handlePhysicalRegisterDef(MBB, MI, MIIdx, getOrCreateInterval(reg), SrcReg);
Evan Cheng24a3cc42007-04-25 07:30:23 +0000587 // Def of a register also defines its sub-registers.
588 for (const unsigned* AS = mri_->getSubRegisters(reg); *AS; ++AS)
589 // Avoid processing some defs more than once.
590 if (!MI->findRegisterDefOperand(*AS))
591 handlePhysicalRegisterDef(MBB, MI, MIIdx, getOrCreateInterval(*AS), 0);
Chris Lattnerf35fef72004-07-23 21:24:19 +0000592 }
Alkis Evlogimenos4d46e1e2004-01-31 14:37:41 +0000593}
594
Evan Chengb371f452007-02-19 21:49:54 +0000595void LiveIntervals::handleLiveInRegister(MachineBasicBlock *MBB,
Jim Laskey9b25b8c2007-02-21 22:41:17 +0000596 unsigned MIIdx,
Evan Cheng24a3cc42007-04-25 07:30:23 +0000597 LiveInterval &interval, bool isAlias) {
Evan Chengb371f452007-02-19 21:49:54 +0000598 DOUT << "\t\tlivein register: "; DEBUG(printRegName(interval.reg));
599
600 // Look for kills, if it reaches a def before it's killed, then it shouldn't
601 // be considered a livein.
602 MachineBasicBlock::iterator mi = MBB->begin();
Jim Laskey9b25b8c2007-02-21 22:41:17 +0000603 unsigned baseIndex = MIIdx;
604 unsigned start = baseIndex;
Evan Chengb371f452007-02-19 21:49:54 +0000605 unsigned end = start;
606 while (mi != MBB->end()) {
607 if (lv_->KillsRegister(mi, interval.reg)) {
608 DOUT << " killed";
609 end = getUseIndex(baseIndex) + 1;
610 goto exit;
611 } else if (lv_->ModifiesRegister(mi, interval.reg)) {
612 // Another instruction redefines the register before it is ever read.
613 // Then the register is essentially dead at the instruction that defines
614 // it. Hence its interval is:
615 // [defSlot(def), defSlot(def)+1)
616 DOUT << " dead";
617 end = getDefIndex(start) + 1;
618 goto exit;
619 }
620
621 baseIndex += InstrSlots::NUM;
622 ++mi;
623 }
624
625exit:
Evan Cheng75611fb2007-06-27 01:16:36 +0000626 // Live-in register might not be used at all.
627 if (end == MIIdx) {
Evan Cheng292da942007-06-27 18:47:28 +0000628 if (isAlias) {
629 DOUT << " dead";
Evan Cheng75611fb2007-06-27 01:16:36 +0000630 end = getDefIndex(MIIdx) + 1;
Evan Cheng292da942007-06-27 18:47:28 +0000631 } else {
632 DOUT << " live through";
633 end = baseIndex;
634 }
Evan Cheng24a3cc42007-04-25 07:30:23 +0000635 }
636
Evan Chengb371f452007-02-19 21:49:54 +0000637 LiveRange LR(start, end, interval.getNextValue(~0U, 0));
Evan Chengb371f452007-02-19 21:49:54 +0000638 DOUT << " +" << LR << '\n';
Jim Laskey9b25b8c2007-02-21 22:41:17 +0000639 interval.addRange(LR);
Evan Chengb371f452007-02-19 21:49:54 +0000640}
641
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +0000642/// computeIntervals - computes the live intervals for virtual
Alkis Evlogimenos4d46e1e2004-01-31 14:37:41 +0000643/// registers. for some ordering of the machine instructions [1,N] a
Alkis Evlogimenos08cec002004-01-31 19:59:32 +0000644/// live interval is an interval [i, j) where 1 <= i <= j < N for
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +0000645/// which a variable is live
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000646void LiveIntervals::computeIntervals() {
Bill Wendlingbdc679d2006-11-29 00:39:47 +0000647 DOUT << "********** COMPUTING LIVE INTERVALS **********\n"
648 << "********** Function: "
649 << ((Value*)mf_->getFunction())->getName() << '\n';
Chris Lattner6b128bd2006-09-03 08:07:11 +0000650 // Track the index of the current machine instr.
651 unsigned MIIndex = 0;
Chris Lattner428b92e2006-09-15 03:57:23 +0000652 for (MachineFunction::iterator MBBI = mf_->begin(), E = mf_->end();
653 MBBI != E; ++MBBI) {
654 MachineBasicBlock *MBB = MBBI;
Bill Wendlingbdc679d2006-11-29 00:39:47 +0000655 DOUT << ((Value*)MBB->getBasicBlock())->getName() << ":\n";
Alkis Evlogimenos6b4edba2003-12-21 20:19:10 +0000656
Chris Lattner428b92e2006-09-15 03:57:23 +0000657 MachineBasicBlock::iterator MI = MBB->begin(), miEnd = MBB->end();
Evan Cheng0c9f92e2007-02-13 01:30:55 +0000658
659 if (MBB->livein_begin() != MBB->livein_end()) {
Evan Chengb371f452007-02-19 21:49:54 +0000660 // Create intervals for live-ins to this BB first.
661 for (MachineBasicBlock::const_livein_iterator LI = MBB->livein_begin(),
Evan Cheng0c9f92e2007-02-13 01:30:55 +0000662 LE = MBB->livein_end(); LI != LE; ++LI) {
Jim Laskey9b25b8c2007-02-21 22:41:17 +0000663 handleLiveInRegister(MBB, MIIndex, getOrCreateInterval(*LI));
Evan Cheng24a3cc42007-04-25 07:30:23 +0000664 // Multiple live-ins can alias the same register.
665 for (const unsigned* AS = mri_->getSubRegisters(*LI); *AS; ++AS)
666 if (!hasInterval(*AS))
Evan Cheng292da942007-06-27 18:47:28 +0000667 handleLiveInRegister(MBB, MIIndex, getOrCreateInterval(*AS),
668 true);
Evan Cheng0c9f92e2007-02-13 01:30:55 +0000669 }
Chris Lattnerdffb2e82006-09-04 18:27:40 +0000670 }
671
Chris Lattner428b92e2006-09-15 03:57:23 +0000672 for (; MI != miEnd; ++MI) {
Bill Wendlingbdc679d2006-11-29 00:39:47 +0000673 DOUT << MIIndex << "\t" << *MI;
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +0000674
Evan Cheng438f7bc2006-11-10 08:43:01 +0000675 // Handle defs.
Chris Lattner428b92e2006-09-15 03:57:23 +0000676 for (int i = MI->getNumOperands() - 1; i >= 0; --i) {
677 MachineOperand &MO = MI->getOperand(i);
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000678 // handle register defs - build intervals
Chris Lattner428b92e2006-09-15 03:57:23 +0000679 if (MO.isRegister() && MO.getReg() && MO.isDef())
680 handleRegisterDef(MBB, MI, MIIndex, MO.getReg());
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000681 }
Chris Lattner6b128bd2006-09-03 08:07:11 +0000682
683 MIIndex += InstrSlots::NUM;
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +0000684 }
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000685 }
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +0000686}
Alkis Evlogimenosb27ef242003-12-05 10:38:28 +0000687
Alkis Evlogimenosa1613db2004-07-24 11:44:15 +0000688LiveInterval LiveIntervals::createInterval(unsigned reg) {
Misha Brukmanedf128a2005-04-21 22:36:52 +0000689 float Weight = MRegisterInfo::isPhysicalRegister(reg) ?
Jim Laskey7902c752006-11-07 12:25:45 +0000690 HUGE_VALF : 0.0F;
Alkis Evlogimenosa1613db2004-07-24 11:44:15 +0000691 return LiveInterval(reg, Weight);
Alkis Evlogimenos9a8b4902004-04-09 18:07:57 +0000692}