@@ -248,6 +248,100 @@ void PhyRegAlloc::addInterferencesForArgs()
248
248
}
249
249
250
250
251
+ #if 0
252
+ //----------------------------------------------------------------------------
253
+
254
+ //----------------------------------------------------------------------------
255
+
256
+
257
+ void PhyRegAlloc::insertCallerSavingCode(const MachineInstr *MInst,
258
+ const BasicBlock *BB )
259
+ {
260
+ assert( (TM.getInstrInfo()).isCall( MInst->getOpCode() ) );
261
+
262
+ int StackOff = 10; // ****TODO : Change
263
+ set<unsigned> PushedRegSet();
264
+
265
+ // Now find the LR of the return value of the call
266
+ // The last *implicit operand* is the return value of a call
267
+ // Insert it to to he PushedRegSet since we must not save that register
268
+ // and restore it after the call.
269
+ // We do this because, we look at the LV set *after* the instruction
270
+ // to determine, which LRs must be saved across calls. The return value
271
+ // of the call is live in this set - but we must not save/restore it.
272
+
273
+ unsigned NumOfImpRefs = MInst->getNumImplicitRefs();
274
+ if( NumOfImpRefs > 0 ) {
275
+
276
+ if( MInst->implicitRefIsDefined(NumOfImpRefs-1) ) {
277
+
278
+ const Value *RetVal = CallMI->getImplicitRef(NumOfImpRefs-1);
279
+ LiveRange *RetValLR = LRI.getLiveRangeForValue( RetVal );
280
+ assert( RetValLR && "No LR for RetValue of call");
281
+
282
+ PushedRegSet.insert(
283
+ MRI.getUnifiedRegNum((RetValLR->getRegClass())->getID(),
284
+ RetValLR->getColor() ) );
285
+ }
286
+
287
+ }
288
+
289
+
290
+ LiveVarSet *LVSetAft = LVI->getLiveVarSetAfterMInst(MInst, BB);
291
+
292
+ LiveVarSet::const_iterator LIt = LVSetAft->begin();
293
+
294
+ // for each live var in live variable set after machine inst
295
+ for( ; LIt != LVSetAft->end(); ++LIt) {
296
+
297
+ // get the live range corresponding to live var
298
+ LiveRange *const LR = LRI.getLiveRangeForValue(*LIt );
299
+
300
+ // LROfVar can be null if it is a const since a const
301
+ // doesn't have a dominating def - see Assumptions above
302
+ if( LR ) {
303
+
304
+ if( LR->hasColor() ) {
305
+
306
+ unsigned RCID = (LR->getRegClass())->getID();
307
+ unsigned Color = LR->getColor();
308
+
309
+ if ( MRI.isRegVolatile(RCID, Color) ) {
310
+
311
+ // if the value is in both LV sets (i.e., live before and after
312
+ // the call machine instruction)
313
+
314
+ unsigned Reg = MRI.getUnifiedRegNum(RCID, Color);
315
+
316
+ if( PuhsedRegSet.find(Reg) == PhusedRegSet.end() ) {
317
+
318
+ // if we haven't already pushed that register
319
+
320
+ MachineInstr *AdI =
321
+ MRI.saveRegOnStackMI(Reg, MRI.getFPReg(), StackOff );
322
+
323
+ ((AddedInstrMap[MInst])->InstrnsBefore).push_front(AdI);
324
+ ((AddedInstrMap[MInst])->InstrnsAfter).push_back(AdI);
325
+
326
+
327
+ PushedRegSet.insert( Reg );
328
+ StackOff += 4; // ****TODO: Correct ??????
329
+ cout << "Inserted caller saving instr");
330
+
331
+ } // if not already pushed
332
+
333
+ } // if LR has a volatile color
334
+
335
+ } // if LR has color
336
+
337
+ } // if there is a LR for Var
338
+
339
+ } // for each value in the LV set after instruction
340
+
341
+ }
342
+
343
+ #endif
344
+
251
345
// ----------------------------------------------------------------------------
252
346
// This method is called after register allocation is complete to set the
253
347
// allocated reisters in the machine code. This code will add register numbers
@@ -275,12 +369,12 @@ void PhyRegAlloc::updateMachineCode()
275
369
// ***TODO: Add InstrnsAfter as well
276
370
if ( AddedInstrMap[ MInst ] ) {
277
371
278
- vector <MachineInstr *> &IBef =
372
+ deque <MachineInstr *> &IBef =
279
373
(AddedInstrMap[MInst])->InstrnsBefore ;
280
374
281
375
if ( ! IBef.empty () ) {
282
376
283
- vector <MachineInstr *>::iterator AdIt;
377
+ deque <MachineInstr *>::iterator AdIt;
284
378
285
379
for ( AdIt = IBef.begin (); AdIt != IBef.end () ; ++AdIt ) {
286
380
@@ -331,7 +425,8 @@ void PhyRegAlloc::updateMachineCode()
331
425
cout << TargetInstrDescriptors[MInst->getOpCode ()].opCodeString ;
332
426
}
333
427
334
- Op.setRegForValue ( 1000 ); // mark register as invalid
428
+ if ( Op.getAllocatedRegNum () == -1 )
429
+ Op.setRegForValue ( 1000 ); // mark register as invalid
335
430
336
431
#if 0
337
432
if( ((Val->getType())->isLabelType()) ||
@@ -475,31 +570,22 @@ void PhyRegAlloc::colorCallRetArgs()
475
570
476
571
for ( ; It != CallRetInstList.end (); ++It ) {
477
572
478
- const Instruction *const CallRetI = *It;
479
- unsigned OpCode = (CallRetI)-> getOpcode ();
573
+ const MachineInstr *const CRMI = *It;
574
+ unsigned OpCode = CRMI-> getOpCode ();
480
575
481
- const MachineInstr *CRMI = *((CallRetI->getMachineInstrVec ()).begin ());
482
-
483
-
484
- assert ( (TM.getInstrInfo ().isReturn (CRMI->getOpCode ()) ||
485
- TM.getInstrInfo ().isCall (CRMI->getOpCode ()) )
486
- && " First Machine Instruction is not a Call/Retrunr" );
487
-
488
576
// get the added instructions for this Call/Ret instruciton
489
577
AddedInstrns *AI = AddedInstrMap[ CRMI ];
490
578
if ( !AI ) {
491
579
AI = new AddedInstrns ();
492
580
AddedInstrMap[ CRMI ] = AI;
493
581
}
494
582
495
- if ( (OpCode == Instruction::Call ) )
496
- MRI.colorCallArgs ( (CallInst *) CallRetI , LRI, AI );
583
+ if ( (TM. getInstrInfo ()). isCall ( OpCode ) )
584
+ MRI.colorCallArgs ( CRMI , LRI, AI );
497
585
498
-
499
- else if (OpCode == Instruction::Ret )
500
- MRI.colorRetValue ( (ReturnInst *) CallRetI, LRI, AI );
586
+ else if ( (TM.getInstrInfo ()).isReturn (OpCode) )
587
+ MRI.colorRetValue ( CRMI, LRI, AI );
501
588
502
-
503
589
else assert ( 0 && " Non Call/Ret instrn in CallRetInstrList\n " );
504
590
505
591
}
0 commit comments