blob: 8a54051673b3d569710a02719b9fb034592d7beb [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 Lattnera3b8b5c2004-07-23 17:56:30 +000019#include "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"
33#include "llvm/ADT/Statistic.h"
34#include "llvm/ADT/STLExtras.h"
Alkis Evlogimenos20aa4742004-09-03 18:19:51 +000035#include <algorithm>
Misha Brukman08a6c762004-09-03 18:25:53 +000036#include <cmath>
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +000037using namespace llvm;
38
39namespace {
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +000040 RegisterAnalysis<LiveIntervals> X("liveintervals", "Live Interval Analysis");
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +000041
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +000042 Statistic<> numIntervals
43 ("liveintervals", "Number of original intervals");
Alkis Evlogimenos007726c2004-02-20 20:53:26 +000044
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +000045 Statistic<> numIntervalsAfter
46 ("liveintervals", "Number of intervals after coalescing");
Alkis Evlogimenos007726c2004-02-20 20:53:26 +000047
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +000048 Statistic<> numJoins
49 ("liveintervals", "Number of interval joins performed");
Alkis Evlogimenos007726c2004-02-20 20:53:26 +000050
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +000051 Statistic<> numPeep
52 ("liveintervals", "Number of identity moves eliminated after coalescing");
Alkis Evlogimenos007726c2004-02-20 20:53:26 +000053
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +000054 Statistic<> numFolded
55 ("liveintervals", "Number of loads/stores folded into instructions");
Alkis Evlogimenos007726c2004-02-20 20:53:26 +000056
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +000057 cl::opt<bool>
58 EnableJoining("join-liveintervals",
59 cl::desc("Join compatible live intervals"),
60 cl::init(true));
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +000061};
62
63void LiveIntervals::getAnalysisUsage(AnalysisUsage &AU) const
64{
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +000065 AU.addPreserved<LiveVariables>();
66 AU.addRequired<LiveVariables>();
67 AU.addPreservedID(PHIEliminationID);
68 AU.addRequiredID(PHIEliminationID);
69 AU.addRequiredID(TwoAddressInstructionPassID);
70 AU.addRequired<LoopInfo>();
71 MachineFunctionPass::getAnalysisUsage(AU);
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +000072}
73
Alkis Evlogimenos08cec002004-01-31 19:59:32 +000074void LiveIntervals::releaseMemory()
75{
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +000076 mi2iMap_.clear();
77 i2miMap_.clear();
78 r2iMap_.clear();
79 r2rMap_.clear();
Alkis Evlogimenos08cec002004-01-31 19:59:32 +000080}
81
82
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +000083/// runOnMachineFunction - Register allocate the whole function
84///
85bool LiveIntervals::runOnMachineFunction(MachineFunction &fn) {
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +000086 mf_ = &fn;
87 tm_ = &fn.getTarget();
88 mri_ = tm_->getRegisterInfo();
Chris Lattnerf768bba2005-03-09 23:05:19 +000089 tii_ = tm_->getInstrInfo();
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +000090 lv_ = &getAnalysis<LiveVariables>();
Alkis Evlogimenos53278012004-08-26 22:22:38 +000091 allocatableRegs_ = mri_->getAllocatableSet(fn);
Alkis Evlogimenos2c4f7b52004-09-09 19:24:38 +000092 r2rMap_.grow(mf_->getSSARegMap()->getLastVirtReg());
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +000093
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +000094 // number MachineInstrs
95 unsigned miIndex = 0;
96 for (MachineFunction::iterator mbb = mf_->begin(), mbbEnd = mf_->end();
97 mbb != mbbEnd; ++mbb)
98 for (MachineBasicBlock::iterator mi = mbb->begin(), miEnd = mbb->end();
99 mi != miEnd; ++mi) {
100 bool inserted = mi2iMap_.insert(std::make_pair(mi, miIndex)).second;
101 assert(inserted && "multiple MachineInstr -> index mappings");
102 i2miMap_.push_back(mi);
103 miIndex += InstrSlots::NUM;
Alkis Evlogimenos843b1602004-02-15 10:24:21 +0000104 }
Alkis Evlogimenosd6e40a62004-01-14 10:44:29 +0000105
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000106 computeIntervals();
Alkis Evlogimenos843b1602004-02-15 10:24:21 +0000107
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000108 numIntervals += getNumIntervals();
109
110#if 1
111 DEBUG(std::cerr << "********** INTERVALS **********\n");
112 DEBUG(for (iterator I = begin(), E = end(); I != E; ++I)
113 std::cerr << I->second << "\n");
114#endif
115
116 // join intervals if requested
117 if (EnableJoining) joinIntervals();
118
119 numIntervalsAfter += getNumIntervals();
120
121 // perform a final pass over the instructions and compute spill
122 // weights, coalesce virtual registers and remove identity moves
123 const LoopInfo& loopInfo = getAnalysis<LoopInfo>();
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000124
125 for (MachineFunction::iterator mbbi = mf_->begin(), mbbe = mf_->end();
126 mbbi != mbbe; ++mbbi) {
127 MachineBasicBlock* mbb = mbbi;
128 unsigned loopDepth = loopInfo.getLoopDepth(mbb->getBasicBlock());
129
130 for (MachineBasicBlock::iterator mii = mbb->begin(), mie = mbb->end();
131 mii != mie; ) {
132 // if the move will be an identity move delete it
133 unsigned srcReg, dstReg, RegRep;
Chris Lattnerf768bba2005-03-09 23:05:19 +0000134 if (tii_->isMoveInstr(*mii, srcReg, dstReg) &&
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000135 (RegRep = rep(srcReg)) == rep(dstReg)) {
136 // remove from def list
137 LiveInterval &interval = getOrCreateInterval(RegRep);
138 // remove index -> MachineInstr and
139 // MachineInstr -> index mappings
140 Mi2IndexMap::iterator mi2i = mi2iMap_.find(mii);
141 if (mi2i != mi2iMap_.end()) {
142 i2miMap_[mi2i->second/InstrSlots::NUM] = 0;
143 mi2iMap_.erase(mi2i);
144 }
145 mii = mbbi->erase(mii);
146 ++numPeep;
147 }
148 else {
149 for (unsigned i = 0; i < mii->getNumOperands(); ++i) {
150 const MachineOperand& mop = mii->getOperand(i);
151 if (mop.isRegister() && mop.getReg() &&
152 MRegisterInfo::isVirtualRegister(mop.getReg())) {
153 // replace register with representative register
154 unsigned reg = rep(mop.getReg());
155 mii->SetMachineOperandReg(i, reg);
156
157 LiveInterval &RegInt = getInterval(reg);
158 RegInt.weight +=
Chris Lattner7a36ae82004-10-25 18:40:47 +0000159 (mop.isUse() + mop.isDef()) * pow(10.0F, (int)loopDepth);
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000160 }
161 }
162 ++mii;
163 }
164 }
165 }
166
Chris Lattner70ca3582004-09-30 15:59:17 +0000167 DEBUG(dump());
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000168 return true;
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +0000169}
170
Chris Lattner70ca3582004-09-30 15:59:17 +0000171/// print - Implement the dump method.
Reid Spencerce9653c2004-12-07 04:03:45 +0000172void LiveIntervals::print(std::ostream &O, const Module* ) const {
Chris Lattner70ca3582004-09-30 15:59:17 +0000173 O << "********** INTERVALS **********\n";
174 for (const_iterator I = begin(), E = end(); I != E; ++I)
Chris Lattneref054362004-10-01 19:01:39 +0000175 O << " " << I->second << "\n";
Chris Lattner70ca3582004-09-30 15:59:17 +0000176
177 O << "********** MACHINEINSTRS **********\n";
178 for (MachineFunction::iterator mbbi = mf_->begin(), mbbe = mf_->end();
179 mbbi != mbbe; ++mbbi) {
180 O << ((Value*)mbbi->getBasicBlock())->getName() << ":\n";
181 for (MachineBasicBlock::iterator mii = mbbi->begin(),
182 mie = mbbi->end(); mii != mie; ++mii) {
Chris Lattner477e4552004-09-30 16:10:45 +0000183 O << getInstructionIndex(mii) << '\t' << *mii;
Chris Lattner70ca3582004-09-30 15:59:17 +0000184 }
185 }
186}
187
Chris Lattner70ca3582004-09-30 15:59:17 +0000188std::vector<LiveInterval*> LiveIntervals::
189addIntervalsForSpills(const LiveInterval &li, VirtRegMap &vrm, int slot) {
Alkis Evlogimenosd8d26b32004-08-27 18:59:22 +0000190 // since this is called after the analysis is done we don't know if
191 // LiveVariables is available
192 lv_ = getAnalysisToUpdate<LiveVariables>();
193
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000194 std::vector<LiveInterval*> added;
Alkis Evlogimenos26f5a692004-05-30 07:24:39 +0000195
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000196 assert(li.weight != HUGE_VAL &&
197 "attempt to spill already spilled interval!");
Alkis Evlogimenos843b1602004-02-15 10:24:21 +0000198
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000199 DEBUG(std::cerr << "\t\t\t\tadding intervals for spills for interval: "
200 << li << '\n');
Alkis Evlogimenos39a0d5c2004-02-20 06:15:40 +0000201
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000202 const TargetRegisterClass* rc = mf_->getSSARegMap()->getRegClass(li.reg);
Alkis Evlogimenos26f5a692004-05-30 07:24:39 +0000203
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000204 for (LiveInterval::Ranges::const_iterator
205 i = li.ranges.begin(), e = li.ranges.end(); i != e; ++i) {
206 unsigned index = getBaseIndex(i->start);
207 unsigned end = getBaseIndex(i->end-1) + InstrSlots::NUM;
208 for (; index != end; index += InstrSlots::NUM) {
209 // skip deleted instructions
210 while (index != end && !getInstructionFromIndex(index))
211 index += InstrSlots::NUM;
212 if (index == end) break;
Chris Lattner8640f4e2004-07-19 15:16:53 +0000213
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000214 MachineBasicBlock::iterator mi = getInstructionFromIndex(index);
Alkis Evlogimenos39a0d5c2004-02-20 06:15:40 +0000215
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000216 for_operand:
217 for (unsigned i = 0; i != mi->getNumOperands(); ++i) {
218 MachineOperand& mop = mi->getOperand(i);
219 if (mop.isRegister() && mop.getReg() == li.reg) {
Chris Lattner477e4552004-09-30 16:10:45 +0000220 // First thing, attempt to fold the memory reference into the
221 // instruction. If we can do this, we don't need to insert spill
222 // code.
Alkis Evlogimenosd8d26b32004-08-27 18:59:22 +0000223 if (MachineInstr* fmi = mri_->foldMemoryOperand(mi, i, slot)) {
224 if (lv_)
225 lv_->instructionChanged(mi, fmi);
Chris Lattnerbec6a9e2004-10-01 23:15:36 +0000226 vrm.virtFolded(li.reg, mi, i, fmi);
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000227 mi2iMap_.erase(mi);
228 i2miMap_[index/InstrSlots::NUM] = fmi;
229 mi2iMap_[fmi] = index;
Chris Lattner477e4552004-09-30 16:10:45 +0000230 MachineBasicBlock &MBB = *mi->getParent();
231 mi = MBB.insert(MBB.erase(mi), fmi);
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000232 ++numFolded;
Chris Lattner477e4552004-09-30 16:10:45 +0000233
234 // Folding the load/store can completely change the instruction in
235 // unpredictable ways, rescan it from the beginning.
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000236 goto for_operand;
Chris Lattner477e4552004-09-30 16:10:45 +0000237 } else {
Chris Lattner70ca3582004-09-30 15:59:17 +0000238 // This is tricky. We need to add information in the interval about
239 // the spill code so we have to use our extra load/store slots.
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000240 //
Chris Lattner70ca3582004-09-30 15:59:17 +0000241 // If we have a use we are going to have a load so we start the
242 // interval from the load slot onwards. Otherwise we start from the
243 // def slot.
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000244 unsigned start = (mop.isUse() ?
245 getLoadIndex(index) :
246 getDefIndex(index));
Chris Lattner70ca3582004-09-30 15:59:17 +0000247 // If we have a def we are going to have a store right after it so
248 // we end the interval after the use of the next
249 // instruction. Otherwise we end after the use of this instruction.
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000250 unsigned end = 1 + (mop.isDef() ?
251 getStoreIndex(index) :
252 getUseIndex(index));
Alkis Evlogimenos26f5a692004-05-30 07:24:39 +0000253
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000254 // create a new register for this spill
Alkis Evlogimenosd8d26b32004-08-27 18:59:22 +0000255 unsigned nReg = mf_->getSSARegMap()->createVirtualRegister(rc);
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000256 mi->SetMachineOperandReg(i, nReg);
257 vrm.grow();
258 vrm.assignVirt2StackSlot(nReg, slot);
259 LiveInterval& nI = getOrCreateInterval(nReg);
260 assert(nI.empty());
Chris Lattner70ca3582004-09-30 15:59:17 +0000261
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000262 // the spill weight is now infinity as it
263 // cannot be spilled again
Chris Lattner28696be2005-01-08 19:55:00 +0000264 nI.weight = float(HUGE_VAL);
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000265 LiveRange LR(start, end, nI.getNextValue());
266 DEBUG(std::cerr << " +" << LR);
267 nI.addRange(LR);
268 added.push_back(&nI);
Chris Lattner70ca3582004-09-30 15:59:17 +0000269
Alkis Evlogimenosd8d26b32004-08-27 18:59:22 +0000270 // update live variables if it is available
271 if (lv_)
272 lv_->addVirtualRegisterKilled(nReg, mi);
273 DEBUG(std::cerr << "\t\t\t\tadded new interval: " << nI << '\n');
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000274 }
Alkis Evlogimenos843b1602004-02-15 10:24:21 +0000275 }
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000276 }
Alkis Evlogimenos843b1602004-02-15 10:24:21 +0000277 }
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000278 }
Alkis Evlogimenos26f5a692004-05-30 07:24:39 +0000279
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000280 return added;
Alkis Evlogimenos843b1602004-02-15 10:24:21 +0000281}
282
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +0000283void LiveIntervals::printRegName(unsigned reg) const
284{
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000285 if (MRegisterInfo::isPhysicalRegister(reg))
286 std::cerr << mri_->getName(reg);
287 else
288 std::cerr << "%reg" << reg;
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +0000289}
290
291void LiveIntervals::handleVirtualRegisterDef(MachineBasicBlock* mbb,
292 MachineBasicBlock::iterator mi,
Chris Lattner418da552004-06-21 13:10:56 +0000293 LiveInterval& interval)
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +0000294{
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000295 DEBUG(std::cerr << "\t\tregister: "; printRegName(interval.reg));
296 LiveVariables::VarInfo& vi = lv_->getVarInfo(interval.reg);
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +0000297
Alkis Evlogimenos70651572004-08-04 09:46:56 +0000298 // Virtual registers may be defined multiple times (due to phi
299 // elimination and 2-addr elimination). Much of what we do only has to be
300 // done once for the vreg. We use an empty interval to detect the first
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000301 // time we see a vreg.
302 if (interval.empty()) {
303 // Get the Idx of the defining instructions.
304 unsigned defIndex = getDefIndex(getInstructionIndex(mi));
Chris Lattner6097d132004-07-19 02:15:56 +0000305
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000306 unsigned ValNum = interval.getNextValue();
307 assert(ValNum == 0 && "First value in interval is not 0?");
308 ValNum = 0; // Clue in the optimizer.
Chris Lattner7ac2d312004-07-24 02:59:07 +0000309
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000310 // Loop over all of the blocks that the vreg is defined in. There are
311 // two cases we have to handle here. The most common case is a vreg
312 // whose lifetime is contained within a basic block. In this case there
313 // will be a single kill, in MBB, which comes after the definition.
314 if (vi.Kills.size() == 1 && vi.Kills[0]->getParent() == mbb) {
315 // FIXME: what about dead vars?
316 unsigned killIdx;
317 if (vi.Kills[0] != mi)
318 killIdx = getUseIndex(getInstructionIndex(vi.Kills[0]))+1;
319 else
320 killIdx = defIndex+1;
Chris Lattner6097d132004-07-19 02:15:56 +0000321
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000322 // If the kill happens after the definition, we have an intra-block
323 // live range.
324 if (killIdx > defIndex) {
Alkis Evlogimenos70651572004-08-04 09:46:56 +0000325 assert(vi.AliveBlocks.empty() &&
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000326 "Shouldn't be alive across any blocks!");
327 LiveRange LR(defIndex, killIdx, ValNum);
328 interval.addRange(LR);
329 DEBUG(std::cerr << " +" << LR << "\n");
330 return;
331 }
Alkis Evlogimenosdd2cc652003-12-18 08:48:48 +0000332 }
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +0000333
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000334 // The other case we handle is when a virtual register lives to the end
335 // of the defining block, potentially live across some blocks, then is
336 // live into some number of blocks, but gets killed. Start by adding a
337 // range that goes from this definition to the end of the defining block.
Alkis Evlogimenosd19e2902004-08-31 17:39:15 +0000338 LiveRange NewLR(defIndex,
339 getInstructionIndex(&mbb->back()) + InstrSlots::NUM,
340 ValNum);
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000341 DEBUG(std::cerr << " +" << NewLR);
342 interval.addRange(NewLR);
343
344 // Iterate over all of the blocks that the variable is completely
345 // live in, adding [insrtIndex(begin), instrIndex(end)+4) to the
346 // live interval.
347 for (unsigned i = 0, e = vi.AliveBlocks.size(); i != e; ++i) {
348 if (vi.AliveBlocks[i]) {
349 MachineBasicBlock* mbb = mf_->getBlockNumbered(i);
350 if (!mbb->empty()) {
351 LiveRange LR(getInstructionIndex(&mbb->front()),
Alkis Evlogimenosd19e2902004-08-31 17:39:15 +0000352 getInstructionIndex(&mbb->back()) + InstrSlots::NUM,
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000353 ValNum);
354 interval.addRange(LR);
355 DEBUG(std::cerr << " +" << LR);
356 }
357 }
358 }
359
360 // Finally, this virtual register is live from the start of any killing
361 // block to the 'use' slot of the killing instruction.
362 for (unsigned i = 0, e = vi.Kills.size(); i != e; ++i) {
363 MachineInstr *Kill = vi.Kills[i];
364 LiveRange LR(getInstructionIndex(Kill->getParent()->begin()),
Alkis Evlogimenosd19e2902004-08-31 17:39:15 +0000365 getUseIndex(getInstructionIndex(Kill))+1,
366 ValNum);
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000367 interval.addRange(LR);
368 DEBUG(std::cerr << " +" << LR);
369 }
370
371 } else {
372 // If this is the second time we see a virtual register definition, it
373 // must be due to phi elimination or two addr elimination. If this is
374 // the result of two address elimination, then the vreg is the first
375 // operand, and is a def-and-use.
Alkis Evlogimenos70651572004-08-04 09:46:56 +0000376 if (mi->getOperand(0).isRegister() &&
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000377 mi->getOperand(0).getReg() == interval.reg &&
378 mi->getOperand(0).isDef() && mi->getOperand(0).isUse()) {
379 // If this is a two-address definition, then we have already processed
380 // the live range. The only problem is that we didn't realize there
381 // are actually two values in the live interval. Because of this we
382 // need to take the LiveRegion that defines this register and split it
383 // into two values.
384 unsigned DefIndex = getDefIndex(getInstructionIndex(vi.DefInst));
385 unsigned RedefIndex = getDefIndex(getInstructionIndex(mi));
386
387 // Delete the initial value, which should be short and continuous,
388 // becuase the 2-addr copy must be in the same MBB as the redef.
389 interval.removeRange(DefIndex, RedefIndex);
Alkis Evlogimenos70651572004-08-04 09:46:56 +0000390
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000391 LiveRange LR(DefIndex, RedefIndex, interval.getNextValue());
392 DEBUG(std::cerr << " replace range with " << LR);
393 interval.addRange(LR);
394
395 // If this redefinition is dead, we need to add a dummy unit live
396 // range covering the def slot.
397 for (LiveVariables::killed_iterator KI = lv_->dead_begin(mi),
398 E = lv_->dead_end(mi); KI != E; ++KI)
399 if (KI->second == interval.reg) {
400 interval.addRange(LiveRange(RedefIndex, RedefIndex+1, 0));
401 break;
402 }
403
404 DEBUG(std::cerr << "RESULT: " << interval);
405
406 } else {
407 // Otherwise, this must be because of phi elimination. If this is the
408 // first redefinition of the vreg that we have seen, go back and change
409 // the live range in the PHI block to be a different value number.
410 if (interval.containsOneValue()) {
411 assert(vi.Kills.size() == 1 &&
412 "PHI elimination vreg should have one kill, the PHI itself!");
413
414 // Remove the old range that we now know has an incorrect number.
415 MachineInstr *Killer = vi.Kills[0];
416 unsigned Start = getInstructionIndex(Killer->getParent()->begin());
417 unsigned End = getUseIndex(getInstructionIndex(Killer))+1;
418 DEBUG(std::cerr << "Removing [" << Start << "," << End << "] from: "
419 << interval << "\n");
420 interval.removeRange(Start, End);
421 DEBUG(std::cerr << "RESULT: " << interval);
422
423 // Replace the interval with one of a NEW value number.
424 LiveRange LR(Start, End, interval.getNextValue());
425 DEBUG(std::cerr << " replace range with " << LR);
426 interval.addRange(LR);
427 DEBUG(std::cerr << "RESULT: " << interval);
428 }
429
430 // In the case of PHI elimination, each variable definition is only
431 // live until the end of the block. We've already taken care of the
432 // rest of the live range.
433 unsigned defIndex = getDefIndex(getInstructionIndex(mi));
Alkis Evlogimenos70651572004-08-04 09:46:56 +0000434 LiveRange LR(defIndex,
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000435 getInstructionIndex(&mbb->back()) + InstrSlots::NUM,
436 interval.getNextValue());
437 interval.addRange(LR);
438 DEBUG(std::cerr << " +" << LR);
439 }
440 }
441
442 DEBUG(std::cerr << '\n');
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +0000443}
444
Chris Lattnerf35fef72004-07-23 21:24:19 +0000445void LiveIntervals::handlePhysicalRegisterDef(MachineBasicBlock *MBB,
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +0000446 MachineBasicBlock::iterator mi,
Chris Lattnerf768bba2005-03-09 23:05:19 +0000447 LiveInterval& interval,
448 unsigned SrcReg, unsigned DestReg)
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +0000449{
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000450 // A physical register cannot be live across basic block, so its
451 // lifetime must end somewhere in its defining basic block.
452 DEBUG(std::cerr << "\t\tregister: "; printRegName(interval.reg));
453 typedef LiveVariables::killed_iterator KillIter;
Alkis Evlogimenos02ba13c2004-01-31 23:13:30 +0000454
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000455 unsigned baseIndex = getInstructionIndex(mi);
456 unsigned start = getDefIndex(baseIndex);
457 unsigned end = start;
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +0000458
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000459 // If it is not used after definition, it is considered dead at
460 // the instruction defining it. Hence its interval is:
461 // [defSlot(def), defSlot(def)+1)
462 for (KillIter ki = lv_->dead_begin(mi), ke = lv_->dead_end(mi);
463 ki != ke; ++ki) {
464 if (interval.reg == ki->second) {
465 DEBUG(std::cerr << " dead");
466 end = getDefIndex(start) + 1;
467 goto exit;
468 }
469 }
470
471 // If it is not dead on definition, it must be killed by a
472 // subsequent instruction. Hence its interval is:
473 // [defSlot(def), useSlot(kill)+1)
474 while (true) {
475 ++mi;
476 assert(mi != MBB->end() && "physreg was not killed in defining block!");
477 baseIndex += InstrSlots::NUM;
478 for (KillIter ki = lv_->killed_begin(mi), ke = lv_->killed_end(mi);
Alkis Evlogimenosaf254732004-01-13 22:26:14 +0000479 ki != ke; ++ki) {
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000480 if (interval.reg == ki->second) {
481 DEBUG(std::cerr << " killed");
482 end = getUseIndex(baseIndex) + 1;
483 goto exit;
484 }
Alkis Evlogimenosaf254732004-01-13 22:26:14 +0000485 }
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000486 }
Alkis Evlogimenos02ba13c2004-01-31 23:13:30 +0000487
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +0000488exit:
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000489 assert(start < end && "did not find end of interval?");
Chris Lattnerf768bba2005-03-09 23:05:19 +0000490
491 // Finally, if this is defining a new range for the physical register, and if
492 // that physreg is just a copy from a vreg, and if THAT vreg was a copy from
493 // the physreg, then the new fragment has the same value as the one copied
494 // into the vreg.
495 if (interval.reg == DestReg && !interval.empty() &&
Chris Lattnere97568c2005-03-10 20:59:51 +0000496 MRegisterInfo::isVirtualRegister(SrcReg)) {
Chris Lattnerf768bba2005-03-09 23:05:19 +0000497
498 // Get the live interval for the vreg, see if it is defined by a copy.
499 LiveInterval &SrcInterval = getOrCreateInterval(SrcReg);
500
501 if (SrcInterval.containsOneValue()) {
502 assert(!SrcInterval.empty() && "Can't contain a value and be empty!");
503
504 // Get the first index of the first range. Though the interval may have
505 // multiple liveranges in it, we only check the first.
506 unsigned StartIdx = SrcInterval.begin()->start;
507 MachineInstr *SrcDefMI = getInstructionFromIndex(StartIdx);
508
509 // Check to see if the vreg was defined by a copy instruction, and that
510 // the source was this physreg.
511 unsigned VRegSrcSrc, VRegSrcDest;
512 if (tii_->isMoveInstr(*SrcDefMI, VRegSrcSrc, VRegSrcDest) &&
513 SrcReg == VRegSrcDest && VRegSrcSrc == DestReg) {
514 // Okay, now we know that the vreg was defined by a copy from this
515 // physreg. Find the value number being copied and use it as the value
516 // for this range.
517 const LiveRange *DefRange = interval.getLiveRangeContaining(StartIdx-1);
518 if (DefRange) {
519 LiveRange LR(start, end, DefRange->ValId);
520 interval.addRange(LR);
521 DEBUG(std::cerr << " +" << LR << '\n');
522 return;
523 }
524 }
525 }
526 }
527
528
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000529 LiveRange LR(start, end, interval.getNextValue());
530 interval.addRange(LR);
531 DEBUG(std::cerr << " +" << LR << '\n');
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +0000532}
533
Chris Lattnerf35fef72004-07-23 21:24:19 +0000534void LiveIntervals::handleRegisterDef(MachineBasicBlock *MBB,
535 MachineBasicBlock::iterator MI,
536 unsigned reg) {
537 if (MRegisterInfo::isVirtualRegister(reg))
538 handleVirtualRegisterDef(MBB, MI, getOrCreateInterval(reg));
Alkis Evlogimenos53278012004-08-26 22:22:38 +0000539 else if (allocatableRegs_[reg]) {
Chris Lattnerf768bba2005-03-09 23:05:19 +0000540 unsigned SrcReg = 0, DestReg = 0;
541 bool IsMove = tii_->isMoveInstr(*MI, SrcReg, DestReg);
542
543 handlePhysicalRegisterDef(MBB, MI, getOrCreateInterval(reg),
544 SrcReg, DestReg);
Chris Lattnerf35fef72004-07-23 21:24:19 +0000545 for (const unsigned* AS = mri_->getAliasSet(reg); *AS; ++AS)
Chris Lattnerf768bba2005-03-09 23:05:19 +0000546 handlePhysicalRegisterDef(MBB, MI, getOrCreateInterval(*AS),
547 SrcReg, DestReg);
Chris Lattnerf35fef72004-07-23 21:24:19 +0000548 }
Alkis Evlogimenos4d46e1e2004-01-31 14:37:41 +0000549}
550
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +0000551/// computeIntervals - computes the live intervals for virtual
Alkis Evlogimenos4d46e1e2004-01-31 14:37:41 +0000552/// registers. for some ordering of the machine instructions [1,N] a
Alkis Evlogimenos08cec002004-01-31 19:59:32 +0000553/// live interval is an interval [i, j) where 1 <= i <= j < N for
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +0000554/// which a variable is live
555void LiveIntervals::computeIntervals()
556{
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000557 DEBUG(std::cerr << "********** COMPUTING LIVE INTERVALS **********\n");
558 DEBUG(std::cerr << "********** Function: "
559 << ((Value*)mf_->getFunction())->getName() << '\n');
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +0000560
Alkis Evlogimenos70651572004-08-04 09:46:56 +0000561 for (MachineFunction::iterator I = mf_->begin(), E = mf_->end();
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000562 I != E; ++I) {
563 MachineBasicBlock* mbb = I;
564 DEBUG(std::cerr << ((Value*)mbb->getBasicBlock())->getName() << ":\n");
Alkis Evlogimenos6b4edba2003-12-21 20:19:10 +0000565
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000566 for (MachineBasicBlock::iterator mi = mbb->begin(), miEnd = mbb->end();
567 mi != miEnd; ++mi) {
568 const TargetInstrDescriptor& tid =
569 tm_->getInstrInfo()->get(mi->getOpcode());
Chris Lattner477e4552004-09-30 16:10:45 +0000570 DEBUG(std::cerr << getInstructionIndex(mi) << "\t" << *mi);
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +0000571
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000572 // handle implicit defs
573 for (const unsigned* id = tid.ImplicitDefs; *id; ++id)
574 handleRegisterDef(mbb, mi, *id);
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +0000575
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000576 // handle explicit defs
577 for (int i = mi->getNumOperands() - 1; i >= 0; --i) {
578 MachineOperand& mop = mi->getOperand(i);
579 // handle register defs - build intervals
580 if (mop.isRegister() && mop.getReg() && mop.isDef())
581 handleRegisterDef(mbb, mi, mop.getReg());
582 }
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +0000583 }
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000584 }
Alkis Evlogimenosff0cbe12003-11-20 03:32:25 +0000585}
Alkis Evlogimenosb27ef242003-12-05 10:38:28 +0000586
Chris Lattner1c5c0442004-07-19 14:08:10 +0000587void LiveIntervals::joinIntervalsInMachineBB(MachineBasicBlock *MBB) {
Chris Lattner7ac2d312004-07-24 02:59:07 +0000588 DEBUG(std::cerr << ((Value*)MBB->getBasicBlock())->getName() << ":\n");
Alkis Evlogimenose88280a2004-01-22 23:08:45 +0000589
Chris Lattner7ac2d312004-07-24 02:59:07 +0000590 for (MachineBasicBlock::iterator mi = MBB->begin(), mie = MBB->end();
591 mi != mie; ++mi) {
592 DEBUG(std::cerr << getInstructionIndex(mi) << '\t' << *mi);
Alkis Evlogimenose88280a2004-01-22 23:08:45 +0000593
Chris Lattner7ac2d312004-07-24 02:59:07 +0000594 // we only join virtual registers with allocatable
595 // physical registers since we do not have liveness information
596 // on not allocatable physical registers
597 unsigned regA, regB;
Chris Lattnerf768bba2005-03-09 23:05:19 +0000598 if (tii_->isMoveInstr(*mi, regA, regB) &&
Alkis Evlogimenos53278012004-08-26 22:22:38 +0000599 (MRegisterInfo::isVirtualRegister(regA) || allocatableRegs_[regA]) &&
600 (MRegisterInfo::isVirtualRegister(regB) || allocatableRegs_[regB])) {
Alkis Evlogimenos70651572004-08-04 09:46:56 +0000601
Chris Lattner7ac2d312004-07-24 02:59:07 +0000602 // Get representative registers.
603 regA = rep(regA);
604 regB = rep(regB);
Alkis Evlogimenos70651572004-08-04 09:46:56 +0000605
Chris Lattner7ac2d312004-07-24 02:59:07 +0000606 // If they are already joined we continue.
607 if (regA == regB)
608 continue;
Alkis Evlogimenos70651572004-08-04 09:46:56 +0000609
Chris Lattner7ac2d312004-07-24 02:59:07 +0000610 // If they are both physical registers, we cannot join them.
Alkis Evlogimenos70651572004-08-04 09:46:56 +0000611 if (MRegisterInfo::isPhysicalRegister(regA) &&
Chris Lattner7ac2d312004-07-24 02:59:07 +0000612 MRegisterInfo::isPhysicalRegister(regB))
613 continue;
Alkis Evlogimenose88280a2004-01-22 23:08:45 +0000614
Chris Lattner7ac2d312004-07-24 02:59:07 +0000615 // If they are not of the same register class, we cannot join them.
616 if (differingRegisterClasses(regA, regB))
617 continue;
Alkis Evlogimenose88280a2004-01-22 23:08:45 +0000618
Chris Lattner7ac2d312004-07-24 02:59:07 +0000619 LiveInterval &IntA = getInterval(regA);
620 LiveInterval &IntB = getInterval(regB);
621 assert(IntA.reg == regA && IntB.reg == regB &&
622 "Register mapping is horribly broken!");
Chris Lattner060913c2004-07-24 04:32:22 +0000623
624 DEBUG(std::cerr << "\t\tInspecting " << IntA << " and " << IntB << ": ");
625
Chris Lattner4df98e52004-07-24 03:32:06 +0000626 // If two intervals contain a single value and are joined by a copy, it
627 // does not matter if the intervals overlap, they can always be joined.
Chris Lattner7ac2d312004-07-24 02:59:07 +0000628 bool TriviallyJoinable =
629 IntA.containsOneValue() && IntB.containsOneValue();
Alkis Evlogimenose88280a2004-01-22 23:08:45 +0000630
Chris Lattner7ac2d312004-07-24 02:59:07 +0000631 unsigned MIDefIdx = getDefIndex(getInstructionIndex(mi));
Chris Lattnerc25b55a2004-07-25 07:47:25 +0000632 if ((TriviallyJoinable || IntB.joinable(IntA, MIDefIdx)) &&
Chris Lattner7ac2d312004-07-24 02:59:07 +0000633 !overlapsAliases(&IntA, &IntB)) {
634 IntB.join(IntA, MIDefIdx);
Chris Lattner1c5c0442004-07-19 14:08:10 +0000635
Chris Lattner7ac2d312004-07-24 02:59:07 +0000636 if (!MRegisterInfo::isPhysicalRegister(regA)) {
Chris Lattner4df98e52004-07-24 03:32:06 +0000637 r2iMap_.erase(regA);
Chris Lattner7ac2d312004-07-24 02:59:07 +0000638 r2rMap_[regA] = regB;
639 } else {
640 // Otherwise merge the data structures the other way so we don't lose
641 // the physreg information.
642 r2rMap_[regB] = regA;
643 IntB.reg = regA;
Alkis Evlogimenosa1613db2004-07-24 11:44:15 +0000644 IntA.swap(IntB);
Chris Lattner4df98e52004-07-24 03:32:06 +0000645 r2iMap_.erase(regB);
Alkis Evlogimenose88280a2004-01-22 23:08:45 +0000646 }
Chris Lattner7ac2d312004-07-24 02:59:07 +0000647 DEBUG(std::cerr << "Joined. Result = " << IntB << "\n");
648 ++numJoins;
649 } else {
650 DEBUG(std::cerr << "Interference!\n");
651 }
Alkis Evlogimenose88280a2004-01-22 23:08:45 +0000652 }
Chris Lattner7ac2d312004-07-24 02:59:07 +0000653 }
Alkis Evlogimenose88280a2004-01-22 23:08:45 +0000654}
655
Chris Lattnercc0d1562004-07-19 14:40:29 +0000656namespace {
657 // DepthMBBCompare - Comparison predicate that sort first based on the loop
658 // depth of the basic block (the unsigned), and then on the MBB number.
659 struct DepthMBBCompare {
660 typedef std::pair<unsigned, MachineBasicBlock*> DepthMBBPair;
661 bool operator()(const DepthMBBPair &LHS, const DepthMBBPair &RHS) const {
662 if (LHS.first > RHS.first) return true; // Deeper loops first
Alkis Evlogimenos70651572004-08-04 09:46:56 +0000663 return LHS.first == RHS.first &&
Alkis Evlogimenos1a8ea012004-08-04 09:46:26 +0000664 LHS.second->getNumber() < RHS.second->getNumber();
Chris Lattnercc0d1562004-07-19 14:40:29 +0000665 }
666 };
667}
Chris Lattner1c5c0442004-07-19 14:08:10 +0000668
Chris Lattnercc0d1562004-07-19 14:40:29 +0000669void LiveIntervals::joinIntervals() {
670 DEBUG(std::cerr << "********** JOINING INTERVALS ***********\n");
671
672 const LoopInfo &LI = getAnalysis<LoopInfo>();
673 if (LI.begin() == LI.end()) {
674 // If there are no loops in the function, join intervals in function order.
Chris Lattner1c5c0442004-07-19 14:08:10 +0000675 for (MachineFunction::iterator I = mf_->begin(), E = mf_->end();
676 I != E; ++I)
677 joinIntervalsInMachineBB(I);
Chris Lattnercc0d1562004-07-19 14:40:29 +0000678 } else {
679 // Otherwise, join intervals in inner loops before other intervals.
680 // Unfortunately we can't just iterate over loop hierarchy here because
681 // there may be more MBB's than BB's. Collect MBB's for sorting.
682 std::vector<std::pair<unsigned, MachineBasicBlock*> > MBBs;
683 for (MachineFunction::iterator I = mf_->begin(), E = mf_->end();
684 I != E; ++I)
685 MBBs.push_back(std::make_pair(LI.getLoopDepth(I->getBasicBlock()), I));
686
687 // Sort by loop depth.
688 std::sort(MBBs.begin(), MBBs.end(), DepthMBBCompare());
689
Alkis Evlogimenos70651572004-08-04 09:46:56 +0000690 // Finally, join intervals in loop nest order.
Chris Lattnercc0d1562004-07-19 14:40:29 +0000691 for (unsigned i = 0, e = MBBs.size(); i != e; ++i)
692 joinIntervalsInMachineBB(MBBs[i].second);
693 }
Chris Lattnerc83e40d2004-07-25 03:24:11 +0000694
695 DEBUG(std::cerr << "*** Register mapping ***\n");
Alkis Evlogimenos5d0d1e32004-09-08 03:01:50 +0000696 DEBUG(for (int i = 0, e = r2rMap_.size(); i != e; ++i)
697 if (r2rMap_[i])
698 std::cerr << " reg " << i << " -> reg " << r2rMap_[i] << "\n");
Chris Lattner1c5c0442004-07-19 14:08:10 +0000699}
700
Chris Lattner7ac2d312004-07-24 02:59:07 +0000701/// Return true if the two specified registers belong to different register
702/// classes. The registers may be either phys or virt regs.
703bool LiveIntervals::differingRegisterClasses(unsigned RegA,
704 unsigned RegB) const {
Alkis Evlogimenos79b0c3f2004-01-23 13:37:51 +0000705
Chris Lattner7ac2d312004-07-24 02:59:07 +0000706 // Get the register classes for the first reg.
Chris Lattnerad3c74f2004-10-26 05:29:18 +0000707 if (MRegisterInfo::isPhysicalRegister(RegA)) {
708 assert(MRegisterInfo::isVirtualRegister(RegB) &&
709 "Shouldn't consider two physregs!");
710 return !mf_->getSSARegMap()->getRegClass(RegB)->contains(RegA);
711 }
Chris Lattner7ac2d312004-07-24 02:59:07 +0000712
713 // Compare against the regclass for the second reg.
Chris Lattnerad3c74f2004-10-26 05:29:18 +0000714 const TargetRegisterClass *RegClass = mf_->getSSARegMap()->getRegClass(RegA);
Chris Lattner7ac2d312004-07-24 02:59:07 +0000715 if (MRegisterInfo::isVirtualRegister(RegB))
716 return RegClass != mf_->getSSARegMap()->getRegClass(RegB);
717 else
Chris Lattnerd0d0a1a2004-08-24 17:48:29 +0000718 return !RegClass->contains(RegB);
Chris Lattner7ac2d312004-07-24 02:59:07 +0000719}
720
721bool LiveIntervals::overlapsAliases(const LiveInterval *LHS,
722 const LiveInterval *RHS) const {
723 if (!MRegisterInfo::isPhysicalRegister(LHS->reg)) {
724 if (!MRegisterInfo::isPhysicalRegister(RHS->reg))
725 return false; // vreg-vreg merge has no aliases!
726 std::swap(LHS, RHS);
727 }
728
729 assert(MRegisterInfo::isPhysicalRegister(LHS->reg) &&
730 MRegisterInfo::isVirtualRegister(RHS->reg) &&
731 "first interval must describe a physical register");
732
Chris Lattner4df98e52004-07-24 03:32:06 +0000733 for (const unsigned *AS = mri_->getAliasSet(LHS->reg); *AS; ++AS)
734 if (RHS->overlaps(getInterval(*AS)))
735 return true;
Alkis Evlogimenos79b0c3f2004-01-23 13:37:51 +0000736
Chris Lattner4df98e52004-07-24 03:32:06 +0000737 return false;
Alkis Evlogimenos79b0c3f2004-01-23 13:37:51 +0000738}
739
Alkis Evlogimenosa1613db2004-07-24 11:44:15 +0000740LiveInterval LiveIntervals::createInterval(unsigned reg) {
Chris Lattner28696be2005-01-08 19:55:00 +0000741 float Weight = MRegisterInfo::isPhysicalRegister(reg) ?
742 (float)HUGE_VAL :0.0F;
Alkis Evlogimenosa1613db2004-07-24 11:44:15 +0000743 return LiveInterval(reg, Weight);
Alkis Evlogimenos9a8b4902004-04-09 18:07:57 +0000744}