blob: dc1c8690ee6977bab9e5a70e455b4613683739c0 [file] [log] [blame]
Vikram S. Adve12af1642001-11-08 04:48:50 +00001// $Id$
2//***************************************************************************
3// File:
4// PhyRegAlloc.cpp
5//
6// Purpose:
7// Register allocation for LLVM.
8//
9// History:
10// 9/10/01 - Ruchira Sasanka - created.
11//**************************************************************************/
Ruchira Sasanka8e604792001-09-14 21:18:34 +000012
Vikram S. Adve12af1642001-11-08 04:48:50 +000013#include "llvm/CodeGen/PhyRegAlloc.h"
14#include "llvm/CodeGen/MachineInstr.h"
15#include "llvm/Target/TargetMachine.h"
16#include "llvm/Target/MachineFrameInfo.h"
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +000017#include <math.h>
Vikram S. Adve12af1642001-11-08 04:48:50 +000018
19
20// ***TODO: There are several places we add instructions. Validate the order
21// of adding these instructions.
Ruchira Sasanka174bded2001-10-28 18:12:02 +000022
23
24
Chris Lattner045e7c82001-09-19 16:26:23 +000025cl::Enum<RegAllocDebugLevel_t> DEBUG_RA("dregalloc", cl::NoFlags,
26 "enable register allocation debugging information",
27 clEnumValN(RA_DEBUG_None , "n", "disable debug output"),
28 clEnumValN(RA_DEBUG_Normal , "y", "enable debug output"),
29 clEnumValN(RA_DEBUG_Verbose, "v", "enable extra debug output"), 0);
Ruchira Sasanka6b0a8b52001-09-15 21:11:11 +000030
31
32//----------------------------------------------------------------------------
33// Constructor: Init local composite objects and create register classes.
34//----------------------------------------------------------------------------
Vikram S. Adve12af1642001-11-08 04:48:50 +000035PhyRegAlloc::PhyRegAlloc(Method *M,
Ruchira Sasanka8e604792001-09-14 21:18:34 +000036 const TargetMachine& tm,
37 MethodLiveVarInfo *const Lvi)
38 : RegClassList(),
Vikram S. Adve12af1642001-11-08 04:48:50 +000039 TM(tm),
40 Meth(M),
41 mcInfo(MachineCodeForMethod::get(M)),
42 LVI(Lvi), LRI(M, tm, RegClassList),
Ruchira Sasanka8e604792001-09-14 21:18:34 +000043 MRI( tm.getRegInfo() ),
44 NumOfRegClasses(MRI.getNumOfRegClasses()),
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +000045 AddedInstrMap(), LoopDepthCalc(M), ResColList() {
Ruchira Sasanka8e604792001-09-14 21:18:34 +000046
47 // create each RegisterClass and put in RegClassList
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +000048 //
Ruchira Sasanka8e604792001-09-14 21:18:34 +000049 for( unsigned int rc=0; rc < NumOfRegClasses; rc++)
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +000050 RegClassList.push_back( new RegClass(M, MRI.getMachineRegClass(rc),
51 &ResColList) );
Ruchira Sasanka8e604792001-09-14 21:18:34 +000052}
53
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +000054
55//----------------------------------------------------------------------------
56// Destructor: Deletes register classes
57//----------------------------------------------------------------------------
58PhyRegAlloc::~PhyRegAlloc() {
59
60 for( unsigned int rc=0; rc < NumOfRegClasses; rc++) {
61 RegClass *RC = RegClassList[rc];
62 delete RC;
63 }
64}
65
Ruchira Sasanka6b0a8b52001-09-15 21:11:11 +000066//----------------------------------------------------------------------------
67// This method initally creates interference graphs (one in each reg class)
68// and IGNodeList (one in each IG). The actual nodes will be pushed later.
69//----------------------------------------------------------------------------
Ruchira Sasanka8e604792001-09-14 21:18:34 +000070void PhyRegAlloc::createIGNodeListsAndIGs()
71{
Ruchira Sasankac4d4b762001-10-16 01:23:19 +000072 if(DEBUG_RA ) cout << "Creating LR lists ..." << endl;
Ruchira Sasanka8e604792001-09-14 21:18:34 +000073
74 // hash map iterator
75 LiveRangeMapType::const_iterator HMI = (LRI.getLiveRangeMap())->begin();
76
77 // hash map end
78 LiveRangeMapType::const_iterator HMIEnd = (LRI.getLiveRangeMap())->end();
79
80 for( ; HMI != HMIEnd ; ++HMI ) {
Ruchira Sasankaa5ab9642001-09-30 23:11:59 +000081
82 if( (*HMI).first ) {
Ruchira Sasanka8e604792001-09-14 21:18:34 +000083
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +000084 LiveRange *L = (*HMI).second; // get the LiveRange
Ruchira Sasanka8e604792001-09-14 21:18:34 +000085
Ruchira Sasankaa5ab9642001-09-30 23:11:59 +000086 if( !L) {
87 if( DEBUG_RA) {
Ruchira Sasankac4d4b762001-10-16 01:23:19 +000088 cout << "\n*?!?Warning: Null liver range found for: ";
89 printValue( (*HMI).first) ; cout << endl;
Ruchira Sasankaa5ab9642001-09-30 23:11:59 +000090 }
91 continue;
92 }
Ruchira Sasanka8e604792001-09-14 21:18:34 +000093 // if the Value * is not null, and LR
94 // is not yet written to the IGNodeList
95 if( !(L->getUserIGNode()) ) {
96
97 RegClass *const RC = // RegClass of first value in the LR
98 //RegClassList [MRI.getRegClassIDOfValue(*(L->begin()))];
99 RegClassList[ L->getRegClass()->getID() ];
100
101 RC-> addLRToIG( L ); // add this LR to an IG
102 }
103 }
104 }
105
106 // init RegClassList
107 for( unsigned int rc=0; rc < NumOfRegClasses ; rc++)
108 RegClassList[ rc ]->createInterferenceGraph();
109
110 if( DEBUG_RA)
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000111 cout << "LRLists Created!" << endl;
Ruchira Sasanka8e604792001-09-14 21:18:34 +0000112}
113
114
115
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000116
Ruchira Sasanka6b0a8b52001-09-15 21:11:11 +0000117//----------------------------------------------------------------------------
118// This method will add all interferences at for a given instruction.
Ruchira Sasanka8e604792001-09-14 21:18:34 +0000119// Interence occurs only if the LR of Def (Inst or Arg) is of the same reg
120// class as that of live var. The live var passed to this function is the
121// LVset AFTER the instruction
Ruchira Sasanka6b0a8b52001-09-15 21:11:11 +0000122//----------------------------------------------------------------------------
Ruchira Sasanka8e604792001-09-14 21:18:34 +0000123void PhyRegAlloc::addInterference(const Value *const Def,
124 const LiveVarSet *const LVSet,
125 const bool isCallInst) {
126
127 LiveVarSet::const_iterator LIt = LVSet->begin();
128
129 // get the live range of instruction
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000130 //
Ruchira Sasanka8e604792001-09-14 21:18:34 +0000131 const LiveRange *const LROfDef = LRI.getLiveRangeForValue( Def );
132
133 IGNode *const IGNodeOfDef = LROfDef->getUserIGNode();
134 assert( IGNodeOfDef );
135
136 RegClass *const RCOfDef = LROfDef->getRegClass();
137
138 // for each live var in live variable set
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000139 //
Ruchira Sasanka8e604792001-09-14 21:18:34 +0000140 for( ; LIt != LVSet->end(); ++LIt) {
141
142 if( DEBUG_RA > 1) {
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000143 cout << "< Def="; printValue(Def);
144 cout << ", Lvar="; printValue( *LIt); cout << "> ";
Ruchira Sasanka8e604792001-09-14 21:18:34 +0000145 }
146
147 // get the live range corresponding to live var
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000148 //
Ruchira Sasanka8e604792001-09-14 21:18:34 +0000149 LiveRange *const LROfVar = LRI.getLiveRangeForValue(*LIt );
150
151 // LROfVar can be null if it is a const since a const
152 // doesn't have a dominating def - see Assumptions above
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000153 //
Ruchira Sasanka8e604792001-09-14 21:18:34 +0000154 if( LROfVar) {
155
156 if(LROfDef == LROfVar) // do not set interf for same LR
157 continue;
158
159 // if 2 reg classes are the same set interference
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000160 //
Ruchira Sasanka8e604792001-09-14 21:18:34 +0000161 if( RCOfDef == LROfVar->getRegClass() ){
162 RCOfDef->setInterference( LROfDef, LROfVar);
163
164 }
165
Ruchira Sasanka0931a012001-09-15 19:06:58 +0000166 else if(DEBUG_RA > 1) {
Ruchira Sasanka8e604792001-09-14 21:18:34 +0000167 // we will not have LRs for values not explicitly allocated in the
168 // instruction stream (e.g., constants)
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000169 cout << " warning: no live range for " ;
170 printValue( *LIt); cout << endl; }
Ruchira Sasanka8e604792001-09-14 21:18:34 +0000171
Ruchira Sasanka958faf32001-10-19 17:21:03 +0000172 }
Ruchira Sasanka8e604792001-09-14 21:18:34 +0000173
Ruchira Sasanka958faf32001-10-19 17:21:03 +0000174 }
175
Ruchira Sasanka8e604792001-09-14 21:18:34 +0000176}
177
Ruchira Sasanka958faf32001-10-19 17:21:03 +0000178
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000179
180
Ruchira Sasanka958faf32001-10-19 17:21:03 +0000181//----------------------------------------------------------------------------
182// For a call instruction, this method sets the CallInterference flag in
183// the LR of each variable live int the Live Variable Set live after the
184// call instruction (except the return value of the call instruction - since
185// the return value does not interfere with that call itself).
186//----------------------------------------------------------------------------
187
188void PhyRegAlloc::setCallInterferences(const MachineInstr *MInst,
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000189 const LiveVarSet *const LVSetAft ) {
190
Ruchira Sasanka958faf32001-10-19 17:21:03 +0000191 // Now find the LR of the return value of the call
Ruchira Sasanka958faf32001-10-19 17:21:03 +0000192 // We do this because, we look at the LV set *after* the instruction
193 // to determine, which LRs must be saved across calls. The return value
194 // of the call is live in this set - but it does not interfere with call
195 // (i.e., we can allocate a volatile register to the return value)
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000196 //
Ruchira Sasanka958faf32001-10-19 17:21:03 +0000197 LiveRange *RetValLR = NULL;
Ruchira Sasankab3b6f532001-10-21 16:43:41 +0000198 const Value *RetVal = MRI.getCallInstRetVal( MInst );
Ruchira Sasanka958faf32001-10-19 17:21:03 +0000199
Ruchira Sasankab3b6f532001-10-21 16:43:41 +0000200 if( RetVal ) {
201 RetValLR = LRI.getLiveRangeForValue( RetVal );
202 assert( RetValLR && "No LR for RetValue of call");
Ruchira Sasanka958faf32001-10-19 17:21:03 +0000203 }
204
Ruchira Sasanka958faf32001-10-19 17:21:03 +0000205 if( DEBUG_RA)
206 cout << "\n For call inst: " << *MInst;
207
208 LiveVarSet::const_iterator LIt = LVSetAft->begin();
209
210 // for each live var in live variable set after machine inst
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000211 //
Ruchira Sasanka958faf32001-10-19 17:21:03 +0000212 for( ; LIt != LVSetAft->end(); ++LIt) {
213
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000214 // get the live range corresponding to live var
215 //
Ruchira Sasanka958faf32001-10-19 17:21:03 +0000216 LiveRange *const LR = LRI.getLiveRangeForValue(*LIt );
217
218 if( LR && DEBUG_RA) {
219 cout << "\n\tLR Aft Call: ";
220 LR->printSet();
221 }
222
223
224 // LR can be null if it is a const since a const
225 // doesn't have a dominating def - see Assumptions above
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000226 //
Ruchira Sasanka958faf32001-10-19 17:21:03 +0000227 if( LR && (LR != RetValLR) ) {
228 LR->setCallInterference();
229 if( DEBUG_RA) {
230 cout << "\n ++Added call interf for LR: " ;
231 LR->printSet();
232 }
233 }
234
235 }
236
237}
238
239
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000240
241
Ruchira Sasanka6b0a8b52001-09-15 21:11:11 +0000242//----------------------------------------------------------------------------
243// This method will walk thru code and create interferences in the IG of
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000244// each RegClass. Also, this method calculates the spill cost of each
245// Live Range (it is done in this method to save another pass over the code).
Ruchira Sasanka6b0a8b52001-09-15 21:11:11 +0000246//----------------------------------------------------------------------------
Ruchira Sasanka8e604792001-09-14 21:18:34 +0000247void PhyRegAlloc::buildInterferenceGraphs()
248{
249
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000250 if(DEBUG_RA) cout << "Creating interference graphs ..." << endl;
Ruchira Sasanka8e604792001-09-14 21:18:34 +0000251
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000252 unsigned BBLoopDepthCost;
Ruchira Sasanka8e604792001-09-14 21:18:34 +0000253 Method::const_iterator BBI = Meth->begin(); // random iterator for BBs
254
255 for( ; BBI != Meth->end(); ++BBI) { // traverse BBs in random order
256
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000257 // find the 10^(loop_depth) of this BB
258 //
259 BBLoopDepthCost = (unsigned) pow( 10.0, LoopDepthCalc.getLoopDepth(*BBI));
260
Ruchira Sasanka8e604792001-09-14 21:18:34 +0000261 // get the iterator for machine instructions
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000262 //
Ruchira Sasanka8e604792001-09-14 21:18:34 +0000263 const MachineCodeForBasicBlock& MIVec = (*BBI)->getMachineInstrVec();
264 MachineCodeForBasicBlock::const_iterator
265 MInstIterator = MIVec.begin();
266
267 // iterate over all the machine instructions in BB
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000268 //
Ruchira Sasanka8e604792001-09-14 21:18:34 +0000269 for( ; MInstIterator != MIVec.end(); ++MInstIterator) {
Ruchira Sasankaa5ab9642001-09-30 23:11:59 +0000270
Ruchira Sasankaef1b0cb2001-11-03 17:13:27 +0000271 const MachineInstr * MInst = *MInstIterator;
Ruchira Sasanka8e604792001-09-14 21:18:34 +0000272
273 // get the LV set after the instruction
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000274 //
Ruchira Sasanka8e604792001-09-14 21:18:34 +0000275 const LiveVarSet *const LVSetAI =
276 LVI->getLiveVarSetAfterMInst(MInst, *BBI);
277
278 const bool isCallInst = TM.getInstrInfo().isCall(MInst->getOpCode());
279
Ruchira Sasanka958faf32001-10-19 17:21:03 +0000280 if( isCallInst ) {
Ruchira Sasanka958faf32001-10-19 17:21:03 +0000281 // set the isCallInterference flag of each live range wich extends
282 // accross this call instruction. This information is used by graph
283 // coloring algo to avoid allocating volatile colors to live ranges
284 // that span across calls (since they have to be saved/restored)
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000285 //
Ruchira Sasanka958faf32001-10-19 17:21:03 +0000286 setCallInterferences( MInst, LVSetAI);
287 }
288
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000289
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000290 // iterate over all MI operands to find defs
291 //
Chris Lattner7a176752001-12-04 00:03:30 +0000292 for( MachineInstr::val_const_op_iterator OpI(MInst);!OpI.done(); ++OpI) {
Ruchira Sasanka22ccb1b2001-11-14 15:33:58 +0000293
294 if( OpI.isDef() ) {
Ruchira Sasanka8e604792001-09-14 21:18:34 +0000295 // create a new LR iff this operand is a def
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000296 //
Ruchira Sasanka8e604792001-09-14 21:18:34 +0000297 addInterference(*OpI, LVSetAI, isCallInst );
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000298 }
299
300 // Calculate the spill cost of each live range
301 //
302 LiveRange *LR = LRI.getLiveRangeForValue( *OpI );
303 if( LR )
304 LR->addSpillCost(BBLoopDepthCost);
305 }
Ruchira Sasanka8e604792001-09-14 21:18:34 +0000306
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000307
Ruchira Sasanka22ccb1b2001-11-14 15:33:58 +0000308 // if there are multiple defs in this instruction e.g. in SETX
309 //
310 if( (TM.getInstrInfo()).isPseudoInstr( MInst->getOpCode()) )
311 addInterf4PseudoInstr(MInst);
312
313
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000314 // Also add interference for any implicit definitions in a machine
315 // instr (currently, only calls have this).
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000316 //
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000317 unsigned NumOfImpRefs = MInst->getNumImplicitRefs();
318 if( NumOfImpRefs > 0 ) {
319 for(unsigned z=0; z < NumOfImpRefs; z++)
320 if( MInst->implicitRefIsDefined(z) )
321 addInterference( MInst->getImplicitRef(z), LVSetAI, isCallInst );
322 }
323
Ruchira Sasankaef1b0cb2001-11-03 17:13:27 +0000324
Ruchira Sasanka8e604792001-09-14 21:18:34 +0000325 } // for all machine instructions in BB
Ruchira Sasanka8e604792001-09-14 21:18:34 +0000326
327 } // for all BBs in method
328
329
330 // add interferences for method arguments. Since there are no explict
331 // defs in method for args, we have to add them manually
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000332 //
333 addInterferencesForArgs();
Ruchira Sasanka8e604792001-09-14 21:18:34 +0000334
335 if( DEBUG_RA)
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000336 cout << "Interference graphs calculted!" << endl;
Ruchira Sasanka8e604792001-09-14 21:18:34 +0000337
338}
339
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000340
341
Ruchira Sasanka22ccb1b2001-11-14 15:33:58 +0000342//--------------------------------------------------------------------------
343// Pseudo instructions will be exapnded to multiple instructions by the
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000344// assembler. Consequently, all the opernds must get distinct registers.
345// Therefore, we mark all operands of a pseudo instruction as they interfere
346// with one another.
Ruchira Sasanka22ccb1b2001-11-14 15:33:58 +0000347//--------------------------------------------------------------------------
Ruchira Sasanka22ccb1b2001-11-14 15:33:58 +0000348void PhyRegAlloc::addInterf4PseudoInstr(const MachineInstr *MInst) {
349
Ruchira Sasankaf6dfca12001-11-15 15:00:53 +0000350 bool setInterf = false;
351
Ruchira Sasanka22ccb1b2001-11-14 15:33:58 +0000352 // iterate over MI operands to find defs
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000353 //
Chris Lattner7a176752001-12-04 00:03:30 +0000354 for( MachineInstr::val_const_op_iterator It1(MInst);!It1.done(); ++It1) {
Ruchira Sasanka22ccb1b2001-11-14 15:33:58 +0000355
356 const LiveRange *const LROfOp1 = LRI.getLiveRangeForValue( *It1 );
357
Ruchira Sasankaf6dfca12001-11-15 15:00:53 +0000358 if( !LROfOp1 && It1.isDef() )
359 assert( 0 && "No LR for Def in PSEUDO insruction");
360
Chris Lattner7a176752001-12-04 00:03:30 +0000361 MachineInstr::val_const_op_iterator It2 = It1;
Ruchira Sasanka22ccb1b2001-11-14 15:33:58 +0000362 ++It2;
363
364 for( ; !It2.done(); ++It2) {
365
366 const LiveRange *const LROfOp2 = LRI.getLiveRangeForValue( *It2 );
367
368 if( LROfOp2) {
369
370 RegClass *const RCOfOp1 = LROfOp1->getRegClass();
371 RegClass *const RCOfOp2 = LROfOp2->getRegClass();
372
373 if( RCOfOp1 == RCOfOp2 ){
374 RCOfOp1->setInterference( LROfOp1, LROfOp2 );
Ruchira Sasankaf6dfca12001-11-15 15:00:53 +0000375 setInterf = true;
Ruchira Sasanka22ccb1b2001-11-14 15:33:58 +0000376 }
377
378 } // if Op2 has a LR
379
380 } // for all other defs in machine instr
381
382 } // for all operands in an instruction
383
Ruchira Sasankaf6dfca12001-11-15 15:00:53 +0000384 if( !setInterf && (MInst->getNumOperands() > 2) ) {
385 cerr << "\nInterf not set for any operand in pseudo instr:\n";
386 cerr << *MInst;
387 assert(0 && "Interf not set for pseudo instr with > 2 operands" );
388
389 }
390
Ruchira Sasanka22ccb1b2001-11-14 15:33:58 +0000391}
392
393
Ruchira Sasanka8e604792001-09-14 21:18:34 +0000394
Ruchira Sasanka6b0a8b52001-09-15 21:11:11 +0000395//----------------------------------------------------------------------------
396// This method will add interferences for incoming arguments to a method.
397//----------------------------------------------------------------------------
Ruchira Sasanka8e604792001-09-14 21:18:34 +0000398void PhyRegAlloc::addInterferencesForArgs()
399{
400 // get the InSet of root BB
401 const LiveVarSet *const InSet = LVI->getInSetOfBB( Meth->front() );
402
403 // get the argument list
404 const Method::ArgumentListType& ArgList = Meth->getArgumentList();
405
406 // get an iterator to arg list
407 Method::ArgumentListType::const_iterator ArgIt = ArgList.begin();
408
409
410 for( ; ArgIt != ArgList.end() ; ++ArgIt) { // for each argument
411 addInterference( *ArgIt, InSet, false ); // add interferences between
412 // args and LVars at start
413 if( DEBUG_RA > 1) {
Ruchira Sasanka97b8b442001-10-18 22:36:26 +0000414 cout << " - %% adding interference for argument ";
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000415 printValue( (const Value *) *ArgIt); cout << endl;
Ruchira Sasanka8e604792001-09-14 21:18:34 +0000416 }
417 }
418}
419
420
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000421
422
Ruchira Sasanka6b0a8b52001-09-15 21:11:11 +0000423//----------------------------------------------------------------------------
424// This method is called after register allocation is complete to set the
425// allocated reisters in the machine code. This code will add register numbers
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000426// to MachineOperands that contain a Value. Also it calls target specific
427// methods to produce caller saving instructions. At the end, it adds all
428// additional instructions produced by the register allocator to the
429// instruction stream.
Ruchira Sasanka6b0a8b52001-09-15 21:11:11 +0000430//----------------------------------------------------------------------------
Ruchira Sasanka8e604792001-09-14 21:18:34 +0000431void PhyRegAlloc::updateMachineCode()
432{
433
434 Method::const_iterator BBI = Meth->begin(); // random iterator for BBs
435
436 for( ; BBI != Meth->end(); ++BBI) { // traverse BBs in random order
437
Ruchira Sasanka0931a012001-09-15 19:06:58 +0000438 // get the iterator for machine instructions
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000439 //
Ruchira Sasanka0931a012001-09-15 19:06:58 +0000440 MachineCodeForBasicBlock& MIVec = (*BBI)->getMachineInstrVec();
441 MachineCodeForBasicBlock::iterator MInstIterator = MIVec.begin();
442
443 // iterate over all the machine instructions in BB
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000444 //
Ruchira Sasanka0931a012001-09-15 19:06:58 +0000445 for( ; MInstIterator != MIVec.end(); ++MInstIterator) {
446
Ruchira Sasankaa5ab9642001-09-30 23:11:59 +0000447 MachineInstr *MInst = *MInstIterator;
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000448
449 unsigned Opcode = MInst->getOpCode();
450
Ruchira Sasanka65480b72001-11-10 21:21:36 +0000451 // do not process Phis
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000452 if( (TM.getInstrInfo()).isPhi( Opcode ) )
Ruchira Sasanka65480b72001-11-10 21:21:36 +0000453 continue;
454
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000455 // Now insert speical instructions (if necessary) for call/return
456 // instructions.
457 //
458 if( (TM.getInstrInfo()).isCall( Opcode) ||
459 (TM.getInstrInfo()).isReturn( Opcode) ) {
460
461 AddedInstrns *AI = AddedInstrMap[ MInst];
462 if ( !AI ) {
463 AI = new AddedInstrns();
464 AddedInstrMap[ MInst ] = AI;
465 }
466
467 // Tmp stack poistions are needed by some calls that have spilled args
468 // So reset it before we call each such method
469 // TODO: mcInfo.popAllTempValues(TM);
470
471 if( (TM.getInstrInfo()).isCall( Opcode ) )
472 MRI.colorCallArgs( MInst, LRI, AI, *this, *BBI );
473
474 else if ( (TM.getInstrInfo()).isReturn(Opcode) )
475 MRI.colorRetValue( MInst, LRI, AI );
476
477 }
478
479
480 /* -- Using above code instead of this
Ruchira Sasanka65480b72001-11-10 21:21:36 +0000481
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000482 // if this machine instr is call, insert caller saving code
Ruchira Sasankaa5ab9642001-09-30 23:11:59 +0000483
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000484 if( (TM.getInstrInfo()).isCall( MInst->getOpCode()) )
Ruchira Sasanka174bded2001-10-28 18:12:02 +0000485 MRI.insertCallerSavingCode(MInst, *BBI, *this );
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000486
487 */
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000488
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000489
Ruchira Sasanka174bded2001-10-28 18:12:02 +0000490 // reset the stack offset for temporary variables since we may
491 // need that to spill
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000492 // mcInfo.popAllTempValues(TM);
Ruchira Sasankaf90870f2001-11-15 22:02:06 +0000493 // TODO ** : do later
Vikram S. Adve12af1642001-11-08 04:48:50 +0000494
Chris Lattner7a176752001-12-04 00:03:30 +0000495 //for(MachineInstr::val_const_op_iterator OpI(MInst);!OpI.done();++OpI) {
Ruchira Sasanka0931a012001-09-15 19:06:58 +0000496
Ruchira Sasankaf221a2e2001-11-13 23:09:30 +0000497
498 // Now replace set the registers for operands in the machine instruction
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000499 //
Ruchira Sasanka0931a012001-09-15 19:06:58 +0000500 for(unsigned OpNum=0; OpNum < MInst->getNumOperands(); ++OpNum) {
501
502 MachineOperand& Op = MInst->getOperand(OpNum);
503
504 if( Op.getOperandType() == MachineOperand::MO_VirtualRegister ||
505 Op.getOperandType() == MachineOperand::MO_CCRegister) {
506
507 const Value *const Val = Op.getVRegValue();
508
509 // delete this condition checking later (must assert if Val is null)
Chris Lattner045e7c82001-09-19 16:26:23 +0000510 if( !Val) {
511 if (DEBUG_RA)
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000512 cout << "Warning: NULL Value found for operand" << endl;
Ruchira Sasanka0931a012001-09-15 19:06:58 +0000513 continue;
514 }
515 assert( Val && "Value is NULL");
516
Ruchira Sasanka174bded2001-10-28 18:12:02 +0000517 LiveRange *const LR = LRI.getLiveRangeForValue(Val);
Ruchira Sasanka0931a012001-09-15 19:06:58 +0000518
519 if ( !LR ) {
Ruchira Sasankae727f852001-09-18 22:43:57 +0000520
521 // nothing to worry if it's a const or a label
522
Chris Lattner4c3aaa42001-09-19 16:09:04 +0000523 if (DEBUG_RA) {
Ruchira Sasanka1b732fd2001-10-16 16:34:44 +0000524 cout << "*NO LR for operand : " << Op ;
525 cout << " [reg:" << Op.getAllocatedRegNum() << "]";
526 cout << " in inst:\t" << *MInst << endl;
Chris Lattner4c3aaa42001-09-19 16:09:04 +0000527 }
Ruchira Sasankae727f852001-09-18 22:43:57 +0000528
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000529 // if register is not allocated, mark register as invalid
Ruchira Sasankaa90e7702001-10-15 16:26:38 +0000530 if( Op.getAllocatedRegNum() == -1)
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000531 Op.setRegForValue( MRI.getInvalidRegNum());
Ruchira Sasankae727f852001-09-18 22:43:57 +0000532
Ruchira Sasankaa5ab9642001-09-30 23:11:59 +0000533
Ruchira Sasanka0931a012001-09-15 19:06:58 +0000534 continue;
535 }
536
537 unsigned RCID = (LR->getRegClass())->getID();
538
Ruchira Sasanka174bded2001-10-28 18:12:02 +0000539 if( LR->hasColor() ) {
540 Op.setRegForValue( MRI.getUnifiedRegNum(RCID, LR->getColor()) );
541 }
542 else {
Ruchira Sasanka0931a012001-09-15 19:06:58 +0000543
Ruchira Sasanka174bded2001-10-28 18:12:02 +0000544 // LR did NOT receive a color (register). Now, insert spill code
545 // for spilled opeands in this machine instruction
Ruchira Sasanka0931a012001-09-15 19:06:58 +0000546
Ruchira Sasanka5a61d852001-11-08 16:43:25 +0000547 //assert(0 && "LR must be spilled");
548 insertCode4SpilledLR(LR, MInst, *BBI, OpNum );
Ruchira Sasanka174bded2001-10-28 18:12:02 +0000549
550 }
Ruchira Sasankae727f852001-09-18 22:43:57 +0000551 }
552
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000553 } // for each operand
554
555
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000556 // Now add instructions that the register allocator inserts before/after
557 // this machine instructions (done only for calls/rets/incoming args)
558 // We do this here, to ensure that spill for an instruction is inserted
559 // closest as possible to an instruction (see above insertCode4Spill...)
560 //
Ruchira Sasankaf221a2e2001-11-13 23:09:30 +0000561 // If there are instructions to be added, *before* this machine
562 // instruction, add them now.
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000563 //
Ruchira Sasankaf221a2e2001-11-13 23:09:30 +0000564 if( AddedInstrMap[ MInst ] ) {
565
566 deque<MachineInstr *> &IBef = (AddedInstrMap[MInst])->InstrnsBefore;
567
568 if( ! IBef.empty() ) {
569
570 deque<MachineInstr *>::iterator AdIt;
571
572 for( AdIt = IBef.begin(); AdIt != IBef.end() ; ++AdIt ) {
573
574 if( DEBUG_RA) {
575 cerr << "For inst " << *MInst;
576 cerr << " PREPENDed instr: " << **AdIt << endl;
577 }
578
579 MInstIterator = MIVec.insert( MInstIterator, *AdIt );
580 ++MInstIterator;
581 }
582
583 }
584
585 }
586
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000587 // If there are instructions to be added *after* this machine
588 // instruction, add them now
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000589 //
Ruchira Sasanka251d8db2001-10-23 21:38:00 +0000590 if( AddedInstrMap[ MInst ] &&
591 ! (AddedInstrMap[ MInst ]->InstrnsAfter).empty() ) {
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000592
Ruchira Sasanka251d8db2001-10-23 21:38:00 +0000593 // if there are delay slots for this instruction, the instructions
594 // added after it must really go after the delayed instruction(s)
595 // So, we move the InstrAfter of the current instruction to the
596 // corresponding delayed instruction
597
598 unsigned delay;
599 if((delay=TM.getInstrInfo().getNumDelaySlots(MInst->getOpCode())) >0){
600 move2DelayedInstr(MInst, *(MInstIterator+delay) );
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000601
Ruchira Sasanka251d8db2001-10-23 21:38:00 +0000602 if(DEBUG_RA) cout<< "\nMoved an added instr after the delay slot";
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000603 }
Ruchira Sasanka251d8db2001-10-23 21:38:00 +0000604
605 else {
606
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000607
Ruchira Sasanka251d8db2001-10-23 21:38:00 +0000608 // Here we can add the "instructions after" to the current
609 // instruction since there are no delay slots for this instruction
610
611 deque<MachineInstr *> &IAft = (AddedInstrMap[MInst])->InstrnsAfter;
612
613 if( ! IAft.empty() ) {
614
615 deque<MachineInstr *>::iterator AdIt;
616
617 ++MInstIterator; // advance to the next instruction
618
619 for( AdIt = IAft.begin(); AdIt != IAft.end() ; ++AdIt ) {
620
Ruchira Sasankaf221a2e2001-11-13 23:09:30 +0000621 if(DEBUG_RA) {
622 cerr << "For inst " << *MInst;
Ruchira Sasankaad140092001-11-09 23:49:42 +0000623 cerr << " APPENDed instr: " << **AdIt << endl;
Ruchira Sasankaf221a2e2001-11-13 23:09:30 +0000624 }
625
Ruchira Sasanka251d8db2001-10-23 21:38:00 +0000626 MInstIterator = MIVec.insert( MInstIterator, *AdIt );
627 ++MInstIterator;
628 }
629
630 // MInsterator already points to the next instr. Since the
631 // for loop also increments it, decrement it to point to the
632 // instruction added last
633 --MInstIterator;
634
635 }
636
637 } // if not delay
638
Ruchira Sasanka0931a012001-09-15 19:06:58 +0000639 }
Ruchira Sasanka251d8db2001-10-23 21:38:00 +0000640
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000641 } // for each machine instruction
Ruchira Sasanka0931a012001-09-15 19:06:58 +0000642 }
643}
644
645
Ruchira Sasanka5a61d852001-11-08 16:43:25 +0000646
647//----------------------------------------------------------------------------
648// This method inserts spill code for AN operand whose LR was spilled.
649// This method may be called several times for a single machine instruction
650// if it contains many spilled operands. Each time it is called, it finds
651// a register which is not live at that instruction and also which is not
652// used by other spilled operands of the same instruction. Then it uses
653// this register temporarily to accomodate the spilled value.
654//----------------------------------------------------------------------------
655void PhyRegAlloc::insertCode4SpilledLR(const LiveRange *LR,
656 MachineInstr *MInst,
657 const BasicBlock *BB,
658 const unsigned OpNum) {
659
Ruchira Sasankaba9d5db2001-11-15 20:23:19 +0000660 assert(! TM.getInstrInfo().isCall(MInst->getOpCode()) &&
661 (! TM.getInstrInfo().isReturn(MInst->getOpCode())) &&
662 "Arg of a call/ret must be handled elsewhere");
663
Ruchira Sasanka5a61d852001-11-08 16:43:25 +0000664 MachineOperand& Op = MInst->getOperand(OpNum);
665 bool isDef = MInst->operandIsDefined(OpNum);
666 unsigned RegType = MRI.getRegType( LR );
667 int SpillOff = LR->getSpillOffFromFP();
668 RegClass *RC = LR->getRegClass();
669 const LiveVarSet *LVSetBef = LVI->getLiveVarSetBeforeMInst(MInst, BB);
Vikram S. Adve00521d72001-11-12 23:26:35 +0000670
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000671
Ruchira Sasanka5a61d852001-11-08 16:43:25 +0000672 int TmpOff =
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000673 mcInfo.pushTempValue(TM, MRI.getSpilledRegSize(RegType) );
Ruchira Sasanka5a61d852001-11-08 16:43:25 +0000674
Ruchira Sasanka226f1f02001-11-08 19:11:30 +0000675 MachineInstr *MIBef=NULL, *AdIMid=NULL, *MIAft=NULL;
Ruchira Sasankaba9d5db2001-11-15 20:23:19 +0000676
677 int TmpRegU = getUsableUniRegAtMI(RC, RegType, MInst,LVSetBef, MIBef, MIAft);
678
Ruchira Sasanka226f1f02001-11-08 19:11:30 +0000679 // get the added instructions for this instruciton
680 AddedInstrns *AI = AddedInstrMap[ MInst ];
681 if ( !AI ) {
682 AI = new AddedInstrns();
683 AddedInstrMap[ MInst ] = AI;
684 }
685
Ruchira Sasankaba9d5db2001-11-15 20:23:19 +0000686
Ruchira Sasanka5a61d852001-11-08 16:43:25 +0000687 if( !isDef ) {
688
689 // for a USE, we have to load the value of LR from stack to a TmpReg
690 // and use the TmpReg as one operand of instruction
691
692 // actual loading instruction
Ruchira Sasankaba9d5db2001-11-15 20:23:19 +0000693 AdIMid = MRI.cpMem2RegMI(MRI.getFramePointer(), SpillOff, TmpRegU,RegType);
Ruchira Sasanka5a61d852001-11-08 16:43:25 +0000694
695 if( MIBef )
Ruchira Sasanka226f1f02001-11-08 19:11:30 +0000696 (AI->InstrnsBefore).push_back(MIBef);
Ruchira Sasanka5a61d852001-11-08 16:43:25 +0000697
Ruchira Sasanka226f1f02001-11-08 19:11:30 +0000698 (AI->InstrnsBefore).push_back(AdIMid);
Ruchira Sasanka5a61d852001-11-08 16:43:25 +0000699
700 if( MIAft)
Ruchira Sasanka226f1f02001-11-08 19:11:30 +0000701 (AI->InstrnsAfter).push_front(MIAft);
702
Ruchira Sasanka5a61d852001-11-08 16:43:25 +0000703
704 }
705 else { // if this is a Def
706
707 // for a DEF, we have to store the value produced by this instruction
708 // on the stack position allocated for this LR
709
710 // actual storing instruction
Ruchira Sasankaba9d5db2001-11-15 20:23:19 +0000711 AdIMid = MRI.cpReg2MemMI(TmpRegU, MRI.getFramePointer(), SpillOff,RegType);
Ruchira Sasanka5a61d852001-11-08 16:43:25 +0000712
713 if( MIBef )
Ruchira Sasanka226f1f02001-11-08 19:11:30 +0000714 (AI->InstrnsBefore).push_back(MIBef);
Ruchira Sasanka5a61d852001-11-08 16:43:25 +0000715
Ruchira Sasankaf221a2e2001-11-13 23:09:30 +0000716 (AI->InstrnsAfter).push_front(AdIMid);
Ruchira Sasanka5a61d852001-11-08 16:43:25 +0000717
718 if( MIAft)
Ruchira Sasanka226f1f02001-11-08 19:11:30 +0000719 (AI->InstrnsAfter).push_front(MIAft);
Ruchira Sasanka5a61d852001-11-08 16:43:25 +0000720
721 } // if !DEF
722
723 cerr << "\nFor Inst " << *MInst;
Ruchira Sasanka65480b72001-11-10 21:21:36 +0000724 cerr << " - SPILLED LR: "; LR->printSet();
Ruchira Sasanka5a61d852001-11-08 16:43:25 +0000725 cerr << "\n - Added Instructions:";
726 if( MIBef ) cerr << *MIBef;
727 cerr << *AdIMid;
728 if( MIAft ) cerr << *MIAft;
729
Ruchira Sasankaba9d5db2001-11-15 20:23:19 +0000730 Op.setRegForValue( TmpRegU ); // set the opearnd
Ruchira Sasanka5a61d852001-11-08 16:43:25 +0000731
732
733}
734
735
736
737
738
739
Ruchira Sasanka174bded2001-10-28 18:12:02 +0000740//----------------------------------------------------------------------------
741// We can use the following method to get a temporary register to be used
742// BEFORE any given machine instruction. If there is a register available,
743// this method will simply return that register and set MIBef = MIAft = NULL.
744// Otherwise, it will return a register and MIAft and MIBef will contain
745// two instructions used to free up this returned register.
Ruchira Sasanka80b1a1a2001-11-03 20:41:22 +0000746// Returned register number is the UNIFIED register number
Ruchira Sasanka174bded2001-10-28 18:12:02 +0000747//----------------------------------------------------------------------------
748
Ruchira Sasankaba9d5db2001-11-15 20:23:19 +0000749int PhyRegAlloc::getUsableUniRegAtMI(RegClass *RC,
Ruchira Sasanka174bded2001-10-28 18:12:02 +0000750 const int RegType,
751 const MachineInstr *MInst,
752 const LiveVarSet *LVSetBef,
753 MachineInstr *MIBef,
754 MachineInstr *MIAft) {
755
Ruchira Sasankaba9d5db2001-11-15 20:23:19 +0000756 int RegU = getUnusedUniRegAtMI(RC, MInst, LVSetBef);
Ruchira Sasanka174bded2001-10-28 18:12:02 +0000757
Ruchira Sasankaba9d5db2001-11-15 20:23:19 +0000758
759 if( RegU != -1) {
Ruchira Sasankaf6dfca12001-11-15 15:00:53 +0000760 // we found an unused register, so we can simply use it
Ruchira Sasanka174bded2001-10-28 18:12:02 +0000761 MIBef = MIAft = NULL;
762 }
763 else {
Ruchira Sasanka80b1a1a2001-11-03 20:41:22 +0000764 // we couldn't find an unused register. Generate code to free up a reg by
Ruchira Sasanka174bded2001-10-28 18:12:02 +0000765 // saving it on stack and restoring after the instruction
766
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +0000767 int TmpOff = mcInfo.pushTempValue(TM, MRI.getSpilledRegSize(RegType) );
Vikram S. Adve12af1642001-11-08 04:48:50 +0000768
Ruchira Sasankaba9d5db2001-11-15 20:23:19 +0000769 RegU = getUniRegNotUsedByThisInst(RC, MInst);
770 MIBef = MRI.cpReg2MemMI(RegU, MRI.getFramePointer(), TmpOff, RegType );
771 MIAft = MRI.cpMem2RegMI(MRI.getFramePointer(), TmpOff, RegU, RegType );
Ruchira Sasanka174bded2001-10-28 18:12:02 +0000772 }
773
Ruchira Sasankaba9d5db2001-11-15 20:23:19 +0000774 return RegU;
Ruchira Sasanka174bded2001-10-28 18:12:02 +0000775}
776
777//----------------------------------------------------------------------------
778// This method is called to get a new unused register that can be used to
779// accomodate a spilled value.
780// This method may be called several times for a single machine instruction
781// if it contains many spilled operands. Each time it is called, it finds
782// a register which is not live at that instruction and also which is not
783// used by other spilled operands of the same instruction.
Ruchira Sasanka80b1a1a2001-11-03 20:41:22 +0000784// Return register number is relative to the register class. NOT
785// unified number
Ruchira Sasanka174bded2001-10-28 18:12:02 +0000786//----------------------------------------------------------------------------
Ruchira Sasankaba9d5db2001-11-15 20:23:19 +0000787int PhyRegAlloc::getUnusedUniRegAtMI(RegClass *RC,
Ruchira Sasanka174bded2001-10-28 18:12:02 +0000788 const MachineInstr *MInst,
789 const LiveVarSet *LVSetBef) {
790
791 unsigned NumAvailRegs = RC->getNumOfAvailRegs();
792
793 bool *IsColorUsedArr = RC->getIsColorUsedArr();
794
Ruchira Sasankaba9d5db2001-11-15 20:23:19 +0000795 for(unsigned i=0; i < NumAvailRegs; i++) // Reset array
Ruchira Sasanka174bded2001-10-28 18:12:02 +0000796 IsColorUsedArr[i] = false;
797
798 LiveVarSet::const_iterator LIt = LVSetBef->begin();
799
800 // for each live var in live variable set after machine inst
801 for( ; LIt != LVSetBef->end(); ++LIt) {
802
803 // get the live range corresponding to live var
804 LiveRange *const LRofLV = LRI.getLiveRangeForValue(*LIt );
805
806 // LR can be null if it is a const since a const
807 // doesn't have a dominating def - see Assumptions above
808 if( LRofLV )
809 if( LRofLV->hasColor() )
810 IsColorUsedArr[ LRofLV->getColor() ] = true;
811 }
812
813 // It is possible that one operand of this MInst was already spilled
814 // and it received some register temporarily. If that's the case,
815 // it is recorded in machine operand. We must skip such registers.
816
Ruchira Sasankaba9d5db2001-11-15 20:23:19 +0000817 setRelRegsUsedByThisInst(RC, MInst);
Ruchira Sasanka174bded2001-10-28 18:12:02 +0000818
819 unsigned c; // find first unused color
820 for( c=0; c < NumAvailRegs; c++)
821 if( ! IsColorUsedArr[ c ] ) break;
822
823 if(c < NumAvailRegs)
Ruchira Sasankaba9d5db2001-11-15 20:23:19 +0000824 return MRI.getUnifiedRegNum(RC->getID(), c);
Ruchira Sasanka174bded2001-10-28 18:12:02 +0000825 else
826 return -1;
827
828
829}
830
831
Ruchira Sasankaba9d5db2001-11-15 20:23:19 +0000832//----------------------------------------------------------------------------
833// Get any other register in a register class, other than what is used
834// by operands of a machine instruction. Returns the unified reg number.
835//----------------------------------------------------------------------------
836int PhyRegAlloc::getUniRegNotUsedByThisInst(RegClass *RC,
837 const MachineInstr *MInst) {
838
839 bool *IsColorUsedArr = RC->getIsColorUsedArr();
840 unsigned NumAvailRegs = RC->getNumOfAvailRegs();
841
842
843 for(unsigned i=0; i < NumAvailRegs ; i++) // Reset array
844 IsColorUsedArr[i] = false;
845
846 setRelRegsUsedByThisInst(RC, MInst);
847
848 unsigned c; // find first unused color
849 for( c=0; c < RC->getNumOfAvailRegs(); c++)
850 if( ! IsColorUsedArr[ c ] ) break;
851
852 if(c < NumAvailRegs)
853 return MRI.getUnifiedRegNum(RC->getID(), c);
854 else
855 assert( 0 && "FATAL: No free register could be found in reg class!!");
856
857}
858
859
860
861
Ruchira Sasanka174bded2001-10-28 18:12:02 +0000862
863//----------------------------------------------------------------------------
864// This method modifies the IsColorUsedArr of the register class passed to it.
865// It sets the bits corresponding to the registers used by this machine
Ruchira Sasankaf6dfca12001-11-15 15:00:53 +0000866// instructions. Both explicit and implicit operands are set.
Ruchira Sasanka174bded2001-10-28 18:12:02 +0000867//----------------------------------------------------------------------------
Ruchira Sasankaba9d5db2001-11-15 20:23:19 +0000868void PhyRegAlloc::setRelRegsUsedByThisInst(RegClass *RC,
Ruchira Sasanka174bded2001-10-28 18:12:02 +0000869 const MachineInstr *MInst ) {
870
871 bool *IsColorUsedArr = RC->getIsColorUsedArr();
872
873 for(unsigned OpNum=0; OpNum < MInst->getNumOperands(); ++OpNum) {
874
875 const MachineOperand& Op = MInst->getOperand(OpNum);
876
877 if( Op.getOperandType() == MachineOperand::MO_VirtualRegister ||
Ruchira Sasankaf6dfca12001-11-15 15:00:53 +0000878 Op.getOperandType() == MachineOperand::MO_CCRegister ) {
Ruchira Sasanka174bded2001-10-28 18:12:02 +0000879
880 const Value *const Val = Op.getVRegValue();
881
Ruchira Sasankaba9d5db2001-11-15 20:23:19 +0000882 if( Val )
883 if( MRI.getRegClassIDOfValue(Val) == RC->getID() ) {
Ruchira Sasanka174bded2001-10-28 18:12:02 +0000884 int Reg;
Ruchira Sasankaf6dfca12001-11-15 15:00:53 +0000885 if( (Reg=Op.getAllocatedRegNum()) != -1) {
Ruchira Sasanka174bded2001-10-28 18:12:02 +0000886 IsColorUsedArr[ Reg ] = true;
Ruchira Sasankaf6dfca12001-11-15 15:00:53 +0000887 }
888 else {
889 // it is possilbe that this operand still is not marked with
890 // a register but it has a LR and that received a color
891
892 LiveRange *LROfVal = LRI.getLiveRangeForValue(Val);
893 if( LROfVal)
894 if( LROfVal->hasColor() )
895 IsColorUsedArr[ LROfVal->getColor() ] = true;
896 }
Ruchira Sasanka174bded2001-10-28 18:12:02 +0000897
Ruchira Sasankaf6dfca12001-11-15 15:00:53 +0000898 } // if reg classes are the same
899 }
900 else if (Op.getOperandType() == MachineOperand::MO_MachineRegister) {
901 IsColorUsedArr[ Op.getMachineRegNum() ] = true;
Ruchira Sasanka174bded2001-10-28 18:12:02 +0000902 }
903 }
904
905 // If there are implicit references, mark them as well
906
907 for(unsigned z=0; z < MInst->getNumImplicitRefs(); z++) {
908
909 LiveRange *const LRofImpRef =
910 LRI.getLiveRangeForValue( MInst->getImplicitRef(z) );
911
912 if( LRofImpRef )
913 if( LRofImpRef->hasColor() )
914 IsColorUsedArr[ LRofImpRef->getColor() ] = true;
915 }
916
917
918
919}
920
921
922
Ruchira Sasanka174bded2001-10-28 18:12:02 +0000923
924
925
926
927
928//----------------------------------------------------------------------------
Ruchira Sasanka251d8db2001-10-23 21:38:00 +0000929// If there are delay slots for an instruction, the instructions
930// added after it must really go after the delayed instruction(s).
931// So, we move the InstrAfter of that instruction to the
932// corresponding delayed instruction using the following method.
Ruchira Sasanka0931a012001-09-15 19:06:58 +0000933
Ruchira Sasanka251d8db2001-10-23 21:38:00 +0000934//----------------------------------------------------------------------------
935void PhyRegAlloc:: move2DelayedInstr(const MachineInstr *OrigMI,
936 const MachineInstr *DelayedMI) {
937
938
939 // "added after" instructions of the original instr
940 deque<MachineInstr *> &OrigAft = (AddedInstrMap[OrigMI])->InstrnsAfter;
941
942 // "added instructions" of the delayed instr
943 AddedInstrns *DelayAdI = AddedInstrMap[DelayedMI];
944
945 if(! DelayAdI ) { // create a new "added after" if necessary
946 DelayAdI = new AddedInstrns();
947 AddedInstrMap[DelayedMI] = DelayAdI;
948 }
949
950 // "added after" instructions of the delayed instr
951 deque<MachineInstr *> &DelayedAft = DelayAdI->InstrnsAfter;
952
953 // go thru all the "added after instructions" of the original instruction
954 // and append them to the "addded after instructions" of the delayed
955 // instructions
956
957 deque<MachineInstr *>::iterator OrigAdIt;
958
959 for( OrigAdIt = OrigAft.begin(); OrigAdIt != OrigAft.end() ; ++OrigAdIt ) {
960 DelayedAft.push_back( *OrigAdIt );
961 }
962
963 // empty the "added after instructions" of the original instruction
964 OrigAft.clear();
965
966}
Ruchira Sasanka0931a012001-09-15 19:06:58 +0000967
Ruchira Sasanka6b0a8b52001-09-15 21:11:11 +0000968//----------------------------------------------------------------------------
969// This method prints the code with registers after register allocation is
970// complete.
971//----------------------------------------------------------------------------
972void PhyRegAlloc::printMachineCode()
973{
974
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000975 cout << endl << ";************** Method ";
976 cout << Meth->getName() << " *****************" << endl;
Ruchira Sasanka6b0a8b52001-09-15 21:11:11 +0000977
978 Method::const_iterator BBI = Meth->begin(); // random iterator for BBs
979
980 for( ; BBI != Meth->end(); ++BBI) { // traverse BBs in random order
981
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000982 cout << endl ; printLabel( *BBI); cout << ": ";
Ruchira Sasanka6b0a8b52001-09-15 21:11:11 +0000983
984 // get the iterator for machine instructions
985 MachineCodeForBasicBlock& MIVec = (*BBI)->getMachineInstrVec();
986 MachineCodeForBasicBlock::iterator MInstIterator = MIVec.begin();
987
988 // iterate over all the machine instructions in BB
989 for( ; MInstIterator != MIVec.end(); ++MInstIterator) {
990
991 MachineInstr *const MInst = *MInstIterator;
992
993
Ruchira Sasankac4d4b762001-10-16 01:23:19 +0000994 cout << endl << "\t";
995 cout << TargetInstrDescriptors[MInst->getOpCode()].opCodeString;
Ruchira Sasanka6b0a8b52001-09-15 21:11:11 +0000996
997
Chris Lattner7a176752001-12-04 00:03:30 +0000998 //for(MachineInstr::val_const_op_iterator OpI(MInst);!OpI.done();++OpI) {
Ruchira Sasanka6b0a8b52001-09-15 21:11:11 +0000999
1000 for(unsigned OpNum=0; OpNum < MInst->getNumOperands(); ++OpNum) {
1001
1002 MachineOperand& Op = MInst->getOperand(OpNum);
1003
1004 if( Op.getOperandType() == MachineOperand::MO_VirtualRegister ||
Ruchira Sasanka97b8b442001-10-18 22:36:26 +00001005 Op.getOperandType() == MachineOperand::MO_CCRegister /*||
1006 Op.getOperandType() == MachineOperand::MO_PCRelativeDisp*/ ) {
Ruchira Sasanka6b0a8b52001-09-15 21:11:11 +00001007
Ruchira Sasanka6b0a8b52001-09-15 21:11:11 +00001008 const Value *const Val = Op.getVRegValue () ;
Ruchira Sasankae727f852001-09-18 22:43:57 +00001009 // ****this code is temporary till NULL Values are fixed
1010 if( ! Val ) {
Ruchira Sasankac4d4b762001-10-16 01:23:19 +00001011 cout << "\t<*NULL*>";
Ruchira Sasanka6b0a8b52001-09-15 21:11:11 +00001012 continue;
1013 }
Ruchira Sasankae727f852001-09-18 22:43:57 +00001014
1015 // if a label or a constant
Ruchira Sasankaa5ab9642001-09-30 23:11:59 +00001016 if( (Val->getValueType() == Value::BasicBlockVal) ) {
Ruchira Sasankae727f852001-09-18 22:43:57 +00001017
Ruchira Sasankac4d4b762001-10-16 01:23:19 +00001018 cout << "\t"; printLabel( Op.getVRegValue () );
Ruchira Sasankae727f852001-09-18 22:43:57 +00001019 }
1020 else {
1021 // else it must be a register value
1022 const int RegNum = Op.getAllocatedRegNum();
1023
Ruchira Sasanka0e62aa62001-10-19 21:39:31 +00001024 cout << "\t" << "%" << MRI.getUnifiedRegName( RegNum );
Ruchira Sasankaba9d5db2001-11-15 20:23:19 +00001025 if (Val->hasName() )
1026 cout << "(" << Val->getName() << ")";
1027 else
1028 cout << "(" << Val << ")";
1029
1030 if( Op.opIsDef() )
1031 cout << "*";
1032
1033 const LiveRange *LROfVal = LRI.getLiveRangeForValue(Val);
1034 if( LROfVal )
1035 if( LROfVal->hasSpillOffset() )
1036 cout << "$";
Ruchira Sasankae727f852001-09-18 22:43:57 +00001037 }
1038
1039 }
1040 else if(Op.getOperandType() == MachineOperand::MO_MachineRegister) {
Ruchira Sasankac4d4b762001-10-16 01:23:19 +00001041 cout << "\t" << "%" << MRI.getUnifiedRegName(Op.getMachineRegNum());
Ruchira Sasanka6b0a8b52001-09-15 21:11:11 +00001042 }
1043
1044 else
Ruchira Sasankac4d4b762001-10-16 01:23:19 +00001045 cout << "\t" << Op; // use dump field
Ruchira Sasanka6b0a8b52001-09-15 21:11:11 +00001046 }
1047
Ruchira Sasankac4d4b762001-10-16 01:23:19 +00001048
Ruchira Sasanka6b0a8b52001-09-15 21:11:11 +00001049
Ruchira Sasankac4d4b762001-10-16 01:23:19 +00001050 unsigned NumOfImpRefs = MInst->getNumImplicitRefs();
1051 if( NumOfImpRefs > 0 ) {
1052
1053 cout << "\tImplicit:";
Ruchira Sasanka6b0a8b52001-09-15 21:11:11 +00001054
Ruchira Sasankac4d4b762001-10-16 01:23:19 +00001055 for(unsigned z=0; z < NumOfImpRefs; z++) {
1056 printValue( MInst->getImplicitRef(z) );
1057 cout << "\t";
1058 }
1059
1060 }
Ruchira Sasanka6b0a8b52001-09-15 21:11:11 +00001061
Ruchira Sasankac4d4b762001-10-16 01:23:19 +00001062 } // for all machine instructions
1063
1064
1065 cout << endl;
1066
1067 } // for all BBs
1068
1069 cout << endl;
Ruchira Sasanka6b0a8b52001-09-15 21:11:11 +00001070}
1071
Ruchira Sasankae727f852001-09-18 22:43:57 +00001072
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +00001073#if 0
1074
Ruchira Sasankaa5ab9642001-09-30 23:11:59 +00001075//----------------------------------------------------------------------------
1076//
1077//----------------------------------------------------------------------------
1078
1079void PhyRegAlloc::colorCallRetArgs()
1080{
1081
1082 CallRetInstrListType &CallRetInstList = LRI.getCallRetInstrList();
1083 CallRetInstrListType::const_iterator It = CallRetInstList.begin();
1084
1085 for( ; It != CallRetInstList.end(); ++It ) {
1086
Ruchira Sasankaa90e7702001-10-15 16:26:38 +00001087 const MachineInstr *const CRMI = *It;
1088 unsigned OpCode = CRMI->getOpCode();
Ruchira Sasankaa5ab9642001-09-30 23:11:59 +00001089
Ruchira Sasankaa5ab9642001-09-30 23:11:59 +00001090 // get the added instructions for this Call/Ret instruciton
1091 AddedInstrns *AI = AddedInstrMap[ CRMI ];
1092 if ( !AI ) {
1093 AI = new AddedInstrns();
1094 AddedInstrMap[ CRMI ] = AI;
1095 }
1096
Ruchira Sasanka174bded2001-10-28 18:12:02 +00001097 // Tmp stack poistions are needed by some calls that have spilled args
1098 // So reset it before we call each such method
Ruchira Sasankaf90870f2001-11-15 22:02:06 +00001099 //mcInfo.popAllTempValues(TM);
1100
1101
Vikram S. Adve12af1642001-11-08 04:48:50 +00001102
Ruchira Sasankaa90e7702001-10-15 16:26:38 +00001103 if( (TM.getInstrInfo()).isCall( OpCode ) )
Ruchira Sasanka174bded2001-10-28 18:12:02 +00001104 MRI.colorCallArgs( CRMI, LRI, AI, *this );
Ruchira Sasankaa5ab9642001-09-30 23:11:59 +00001105
Ruchira Sasankaa90e7702001-10-15 16:26:38 +00001106 else if ( (TM.getInstrInfo()).isReturn(OpCode) )
1107 MRI.colorRetValue( CRMI, LRI, AI );
Ruchira Sasankaa5ab9642001-09-30 23:11:59 +00001108
Ruchira Sasankaa5ab9642001-09-30 23:11:59 +00001109 else assert( 0 && "Non Call/Ret instrn in CallRetInstrList\n" );
1110
1111 }
1112
1113}
1114
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +00001115#endif
Ruchira Sasanka0e62aa62001-10-19 21:39:31 +00001116
Ruchira Sasankaa5ab9642001-09-30 23:11:59 +00001117//----------------------------------------------------------------------------
1118
1119//----------------------------------------------------------------------------
1120void PhyRegAlloc::colorIncomingArgs()
1121{
1122 const BasicBlock *const FirstBB = Meth->front();
1123 const MachineInstr *FirstMI = *((FirstBB->getMachineInstrVec()).begin());
1124 assert( FirstMI && "No machine instruction in entry BB");
1125
1126 AddedInstrns *AI = AddedInstrMap[ FirstMI ];
1127 if ( !AI ) {
1128 AI = new AddedInstrns();
1129 AddedInstrMap[ FirstMI ] = AI;
1130 }
1131
1132 MRI.colorMethodArgs(Meth, LRI, AI );
1133}
1134
Ruchira Sasankae727f852001-09-18 22:43:57 +00001135
1136//----------------------------------------------------------------------------
1137// Used to generate a label for a basic block
1138//----------------------------------------------------------------------------
Ruchira Sasanka6b0a8b52001-09-15 21:11:11 +00001139void PhyRegAlloc::printLabel(const Value *const Val)
1140{
1141 if( Val->hasName() )
Ruchira Sasankac4d4b762001-10-16 01:23:19 +00001142 cout << Val->getName();
Ruchira Sasanka6b0a8b52001-09-15 21:11:11 +00001143 else
Ruchira Sasankac4d4b762001-10-16 01:23:19 +00001144 cout << "Label" << Val;
Ruchira Sasanka6b0a8b52001-09-15 21:11:11 +00001145}
1146
1147
Ruchira Sasankae727f852001-09-18 22:43:57 +00001148//----------------------------------------------------------------------------
Ruchira Sasanka0e62aa62001-10-19 21:39:31 +00001149// This method calls setSugColorUsable method of each live range. This
1150// will determine whether the suggested color of LR is really usable.
1151// A suggested color is not usable when the suggested color is volatile
1152// AND when there are call interferences
1153//----------------------------------------------------------------------------
1154
1155void PhyRegAlloc::markUnusableSugColors()
1156{
Ruchira Sasanka174bded2001-10-28 18:12:02 +00001157 if(DEBUG_RA ) cout << "\nmarking unusable suggested colors ..." << endl;
Ruchira Sasanka0e62aa62001-10-19 21:39:31 +00001158
1159 // hash map iterator
1160 LiveRangeMapType::const_iterator HMI = (LRI.getLiveRangeMap())->begin();
1161 LiveRangeMapType::const_iterator HMIEnd = (LRI.getLiveRangeMap())->end();
1162
1163 for( ; HMI != HMIEnd ; ++HMI ) {
1164
1165 if( (*HMI).first ) {
1166
1167 LiveRange *L = (*HMI).second; // get the LiveRange
1168
1169 if(L) {
1170 if( L->hasSuggestedColor() ) {
1171
1172 int RCID = (L->getRegClass())->getID();
1173 if( MRI.isRegVolatile( RCID, L->getSuggestedColor()) &&
1174 L->isCallInterference() )
1175 L->setSuggestedColorUsable( false );
1176 else
1177 L->setSuggestedColorUsable( true );
1178 }
1179 } // if L->hasSuggestedColor()
1180 }
1181 } // for all LR's in hash map
1182}
1183
1184
1185
Ruchira Sasanka174bded2001-10-28 18:12:02 +00001186//----------------------------------------------------------------------------
1187// The following method will set the stack offsets of the live ranges that
1188// are decided to be spillled. This must be called just after coloring the
1189// LRs using the graph coloring algo. For each live range that is spilled,
1190// this method allocate a new spill position on the stack.
1191//----------------------------------------------------------------------------
Ruchira Sasanka0e62aa62001-10-19 21:39:31 +00001192
Ruchira Sasanka174bded2001-10-28 18:12:02 +00001193void PhyRegAlloc::allocateStackSpace4SpilledLRs()
1194{
1195 if(DEBUG_RA ) cout << "\nsetting LR stack offsets ..." << endl;
Ruchira Sasanka0e62aa62001-10-19 21:39:31 +00001196
Ruchira Sasanka174bded2001-10-28 18:12:02 +00001197 // hash map iterator
1198 LiveRangeMapType::const_iterator HMI = (LRI.getLiveRangeMap())->begin();
1199 LiveRangeMapType::const_iterator HMIEnd = (LRI.getLiveRangeMap())->end();
1200
1201 for( ; HMI != HMIEnd ; ++HMI ) {
Ruchira Sasanka174bded2001-10-28 18:12:02 +00001202 if( (*HMI).first ) {
1203 LiveRange *L = (*HMI).second; // get the LiveRange
1204 if(L)
1205 if( ! L->hasColor() )
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +00001206
1207 // NOTE: ** allocating the size of long Type **
1208 L->setSpillOffFromFP(mcInfo.allocateSpilledValue(TM,
1209 Type::LongTy));
1210
Ruchira Sasanka174bded2001-10-28 18:12:02 +00001211 }
1212 } // for all LR's in hash map
Ruchira Sasanka174bded2001-10-28 18:12:02 +00001213}
Ruchira Sasanka0e62aa62001-10-19 21:39:31 +00001214
1215
1216
Ruchira Sasanka0e62aa62001-10-19 21:39:31 +00001217//----------------------------------------------------------------------------
Ruchira Sasankae727f852001-09-18 22:43:57 +00001218// The entry pont to Register Allocation
1219//----------------------------------------------------------------------------
Ruchira Sasanka6b0a8b52001-09-15 21:11:11 +00001220
1221void PhyRegAlloc::allocateRegisters()
1222{
Ruchira Sasankaa5ab9642001-09-30 23:11:59 +00001223
1224 // make sure that we put all register classes into the RegClassList
1225 // before we call constructLiveRanges (now done in the constructor of
1226 // PhyRegAlloc class).
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +00001227 //
1228 LRI.constructLiveRanges(); // create LR info
Ruchira Sasanka6b0a8b52001-09-15 21:11:11 +00001229
Ruchira Sasankaa5ab9642001-09-30 23:11:59 +00001230 if( DEBUG_RA )
Ruchira Sasanka6b0a8b52001-09-15 21:11:11 +00001231 LRI.printLiveRanges();
Ruchira Sasankaa5ab9642001-09-30 23:11:59 +00001232
Ruchira Sasanka6b0a8b52001-09-15 21:11:11 +00001233 createIGNodeListsAndIGs(); // create IGNode list and IGs
1234
1235 buildInterferenceGraphs(); // build IGs in all reg classes
Ruchira Sasanka6b0a8b52001-09-15 21:11:11 +00001236
Ruchira Sasankaa5ab9642001-09-30 23:11:59 +00001237
1238 if( DEBUG_RA ) {
Ruchira Sasanka6b0a8b52001-09-15 21:11:11 +00001239 // print all LRs in all reg classes
1240 for( unsigned int rc=0; rc < NumOfRegClasses ; rc++)
1241 RegClassList[ rc ]->printIGNodeList();
Ruchira Sasankaa5ab9642001-09-30 23:11:59 +00001242
Ruchira Sasanka6b0a8b52001-09-15 21:11:11 +00001243 // print IGs in all register classes
1244 for( unsigned int rc=0; rc < NumOfRegClasses ; rc++)
1245 RegClassList[ rc ]->printIG();
1246 }
Ruchira Sasankaa5ab9642001-09-30 23:11:59 +00001247
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +00001248
Ruchira Sasanka6b0a8b52001-09-15 21:11:11 +00001249 LRI.coalesceLRs(); // coalesce all live ranges
Ruchira Sasankaa5ab9642001-09-30 23:11:59 +00001250
Ruchira Sasankaef1b0cb2001-11-03 17:13:27 +00001251
Ruchira Sasanka6b0a8b52001-09-15 21:11:11 +00001252 if( DEBUG_RA) {
1253 // print all LRs in all reg classes
1254 for( unsigned int rc=0; rc < NumOfRegClasses ; rc++)
1255 RegClassList[ rc ]->printIGNodeList();
Ruchira Sasankaa5ab9642001-09-30 23:11:59 +00001256
Ruchira Sasanka6b0a8b52001-09-15 21:11:11 +00001257 // print IGs in all register classes
1258 for( unsigned int rc=0; rc < NumOfRegClasses ; rc++)
1259 RegClassList[ rc ]->printIG();
1260 }
1261
Ruchira Sasanka0e62aa62001-10-19 21:39:31 +00001262
1263 // mark un-usable suggested color before graph coloring algorithm.
1264 // When this is done, the graph coloring algo will not reserve
1265 // suggested color unnecessarily - they can be used by another LR
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +00001266 //
Ruchira Sasanka0e62aa62001-10-19 21:39:31 +00001267 markUnusableSugColors();
1268
1269 // color all register classes using the graph coloring algo
Ruchira Sasanka6b0a8b52001-09-15 21:11:11 +00001270 for( unsigned int rc=0; rc < NumOfRegClasses ; rc++)
1271 RegClassList[ rc ]->colorAllRegs();
1272
Ruchira Sasanka174bded2001-10-28 18:12:02 +00001273 // Atter grpah coloring, if some LRs did not receive a color (i.e, spilled)
1274 // a poistion for such spilled LRs
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +00001275 //
Ruchira Sasanka174bded2001-10-28 18:12:02 +00001276 allocateStackSpace4SpilledLRs();
Ruchira Sasankaa5ab9642001-09-30 23:11:59 +00001277
Ruchira Sasankaf90870f2001-11-15 22:02:06 +00001278 mcInfo.popAllTempValues(TM); // TODO **Check
1279
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +00001280 // color incoming args - if the correct color was not received
1281 // insert code to copy to the correct register
1282 //
Ruchira Sasankaa5ab9642001-09-30 23:11:59 +00001283 colorIncomingArgs();
Ruchira Sasankaa5ab9642001-09-30 23:11:59 +00001284
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +00001285
1286 // Now update the machine code with register names and add any
1287 // additional code inserted by the register allocator to the instruction
1288 // stream
1289 //
Ruchira Sasanka6b0a8b52001-09-15 21:11:11 +00001290 updateMachineCode();
Ruchira Sasanka4f3eb222002-01-07 19:19:18 +00001291
1292
Chris Lattner045e7c82001-09-19 16:26:23 +00001293 if (DEBUG_RA) {
Vikram S. Adve12af1642001-11-08 04:48:50 +00001294 MachineCodeForMethod::get(Meth).dump();
Chris Lattner045e7c82001-09-19 16:26:23 +00001295 printMachineCode(); // only for DEBUGGING
1296 }
Ruchira Sasankaf221a2e2001-11-13 23:09:30 +00001297
Ruchira Sasanka6b0a8b52001-09-15 21:11:11 +00001298}
1299
Ruchira Sasankae727f852001-09-18 22:43:57 +00001300
1301