* Both Method & GlobalVariable now subclass GlobalValue
[oota-llvm.git] / lib / Target / SparcV9 / SparcV9RegInfo.cpp
1 #include "llvm/Target/Sparc.h"
2 #include "SparcInternals.h"
3 #include "llvm/Method.h"
4 #include "llvm/iTerminators.h"
5 #include "llvm/iOther.h"
6 #include "llvm/CodeGen/InstrScheduling.h"
7 #include "llvm/CodeGen/InstrSelection.h"
8
9 #include "llvm/Analysis/LiveVar/MethodLiveVarInfo.h"
10 #include "llvm/CodeGen/PhyRegAlloc.h"
11
12
13
14
15 //---------------------------------------------------------------------------
16 // UltraSparcRegInfo
17 //---------------------------------------------------------------------------
18
19
20
21 //---------------------------------------------------------------------------
22 // This method sets the hidden operand for return address in RETURN and 
23 // JMPL machine instructions.
24 //---------------------------------------------------------------------------
25
26 bool UltraSparcRegInfo::handleSpecialMInstr(const MachineInstr * MInst, 
27                                             LiveRangeInfo& LRI,
28                                             vector<RegClass *>RCList) const {
29   
30   unsigned OpCode = MInst->getOpCode();
31
32
33   // if the instruction is a RETURN instruction, suggest %i7
34
35   if( (UltraSparcInfo->getInstrInfo()).isReturn( OpCode ) ) {
36
37     const Value *RetAddrVal = getValue4ReturnAddr(MInst);
38     
39     if( (getRegClassIDOfValue( RetAddrVal) == IntRegClassID) ) {
40       if( DEBUG_RA) {
41         cout <<  "\n$?$Return Address Value is not of Integer Type. Type =";
42         cout << (RetAddrVal->getType())->getPrimitiveID() << endl;
43       }
44     }
45
46   
47     LiveRange * RetAddrLR = new LiveRange();  
48     RetAddrLR->add(RetAddrVal);
49     RetAddrLR->setRegClass( RCList[IntRegClassID] );
50     LRI.addLRToMap( RetAddrVal, RetAddrLR);
51     
52     RetAddrLR->setSuggestedColor(SparcIntRegOrder::i7);
53
54     return true;
55   }
56
57   // else if the instruction is a JMPL instruction, color it with %o7
58   // this can be permenently colored since the LR is very short (one instr)
59   // TODO: Directly change the machine register instead of creating a LR
60
61   else if( (UltraSparcInfo->getInstrInfo()).isCall(MInst->getOpCode() ) ) {
62
63     const Value *RetAddrVal = getValue4ReturnAddr(MInst);
64     
65     if( (getRegClassIDOfValue( RetAddrVal) == IntRegClassID) ) {
66       if( DEBUG_RA) {
67         cout <<  "\n$?$Return Address Value is not of Integer Type. Type =";
68         cout << (RetAddrVal->getType())->getPrimitiveID() << endl;
69       }
70     }
71
72     LiveRange * RetAddrLR = new LiveRange();      
73     RetAddrLR->add(RetAddrVal);
74     RetAddrLR->setRegClass( RCList[IntRegClassID] );
75     LRI.addLRToMap( RetAddrVal, RetAddrLR);
76
77     RetAddrLR->setColor(SparcIntRegOrder::o7);
78
79     return true;                    
80     
81   }
82   
83   else return false;   // not a special machine instruction
84
85 }
86
87
88 //---------------------------------------------------------------------------
89 // This gets the hidden value in a return register which is used to
90 // pass the return address.
91 //---------------------------------------------------------------------------
92
93 Value *  
94 UltraSparcRegInfo::getValue4ReturnAddr( const MachineInstr * MInst ) const {
95   
96   if( (UltraSparcInfo->getInstrInfo()).isReturn(MInst->getOpCode()) ) {
97     
98     assert( (MInst->getNumOperands() == 2) && "RETURN must have 2 operands");
99     const MachineOperand & MO  = MInst->getOperand(0);
100     return MO.getVRegValue();
101    
102   }
103   else if(  (UltraSparcInfo->getInstrInfo()).isCall(MInst->getOpCode()) ) {
104          
105     assert( (MInst->getNumOperands() == 3) && "JMPL must have 3 operands");
106     const MachineOperand & MO  = MInst->getOperand(2);
107     return MO.getVRegValue();
108   }
109
110   else
111     assert(0 && "Machine Instr is not a CALL/RET");
112 }
113
114        
115
116 //---------------------------------------------------------------------------
117 //  This method will suggest colors to incoming args to a method. 
118 //  If the arg is passed on stack due to the lack of regs, NOTHING will be
119 //  done - it will be colored (or spilled) as a normal value.
120 //---------------------------------------------------------------------------
121
122 void UltraSparcRegInfo::suggestRegs4MethodArgs(const Method *const Meth, 
123                                                LiveRangeInfo& LRI) const 
124 {
125
126                                                  // get the argument list
127   const Method::ArgumentListType& ArgList = Meth->getArgumentList();           
128                                                  // get an iterator to arg list
129   Method::ArgumentListType::const_iterator ArgIt = ArgList.begin(); 
130
131   // for each argument
132   for( unsigned argNo=0; ArgIt != ArgList.end() ; ++ArgIt, ++argNo) {    
133
134     // get the LR of arg
135     LiveRange *const LR = LRI.getLiveRangeForValue((const Value *) *ArgIt); 
136     assert( LR && "No live range found for method arg");
137
138     unsigned RegType = getRegType( LR );
139
140
141     // if the arg is in int class - allocate a reg for an int arg
142     if( RegType == IntRegType ) {
143
144       if( argNo < NumOfIntArgRegs) {
145         LR->setSuggestedColor( SparcIntRegOrder::i0 + argNo );
146
147       }
148   
149       else {
150         // Do NOTHING as this will be colored as a normal value.
151         if (DEBUG_RA) cout << " Int Regr not suggested for method arg\n";
152       }
153      
154     }
155     else if( RegType==FPSingleRegType && (argNo*2+1) < NumOfFloatArgRegs) 
156       LR->setSuggestedColor( SparcFloatRegOrder::f0 + (argNo * 2 + 1) );
157     
158  
159     else if( RegType == FPDoubleRegType && (argNo*2) < NumOfFloatArgRegs) 
160       LR->setSuggestedColor( SparcFloatRegOrder::f0 + (argNo * 2) ); 
161     
162
163   }
164   
165 }
166
167 //---------------------------------------------------------------------------
168 // 
169 //---------------------------------------------------------------------------
170
171 void UltraSparcRegInfo::colorMethodArgs(const Method *const Meth, 
172                                         LiveRangeInfo& LRI,
173                                         AddedInstrns *const FirstAI) const {
174
175                                                  // get the argument list
176   const Method::ArgumentListType& ArgList = Meth->getArgumentList();           
177                                                  // get an iterator to arg list
178   Method::ArgumentListType::const_iterator ArgIt = ArgList.begin(); 
179
180   MachineInstr *AdMI;
181
182
183   // for each argument
184   for( unsigned argNo=0; ArgIt != ArgList.end() ; ++ArgIt, ++argNo) {    
185
186     // get the LR of arg
187     LiveRange *const LR = LRI.getLiveRangeForValue((const Value *) *ArgIt); 
188     assert( LR && "No live range found for method arg");
189
190
191     // if the LR received the suggested color, NOTHING to be done
192     if( LR->hasSuggestedColor() && LR->hasColor() )
193       if( LR->getSuggestedColor() == LR->getColor() )
194         continue;
195
196     // We are here because the LR did not have a suggested 
197     // color or did not receive the suggested color. Now handle
198     // individual cases.
199
200
201     unsigned RegType = getRegType( LR );
202     unsigned RegClassID = (LR->getRegClass())->getID();
203
204
205     // find whether this argument is coming in a register (if not, on stack)
206
207     bool isArgInReg = false;
208     unsigned UniArgReg = InvalidRegNum;
209
210     if( (RegType== IntRegType && argNo <  NumOfIntArgRegs)) {
211       isArgInReg = true;
212       UniArgReg = getUnifiedRegNum( RegClassID, SparcIntRegOrder::o0 + argNo );
213     }
214     else if(RegType == FPSingleRegType && argNo < NumOfFloatArgRegs)  { 
215       isArgInReg = true;
216       UniArgReg = getUnifiedRegNum( RegClassID, 
217                                     SparcFloatRegOrder::f0 + argNo*2 + 1 ) ;
218     }
219     else if(RegType == FPDoubleRegType && argNo < NumOfFloatArgRegs)  { 
220       isArgInReg = true;
221       UniArgReg = getUnifiedRegNum(RegClassID, SparcFloatRegOrder::f0+argNo*2);
222     }
223
224     
225     if( LR->hasColor() ) {
226
227       // We are here because the LR did not have a suggested 
228       // color or did not receive the suggested color but LR got a register.
229       // Now we have to copy %ix reg (or stack pos of arg) 
230       // to the register it was colored with.
231
232       unsigned UniLRReg = getUnifiedRegNum(  RegClassID, LR->getColor() );
233        
234       // if the arg is coming in a register and goes into a register
235       if( isArgInReg ) 
236         AdMI = cpReg2RegMI(UniArgReg, UniLRReg, RegType );
237
238       else 
239         assert(0 && "TODO: Color an Incoming arg on stack");
240
241       // Now add the instruction
242       FirstAI->InstrnsBefore.push_back( AdMI );
243
244     }
245
246     else {                                // LR is not colored (i.e., spilled)
247       
248       assert(0 && "TODO: Color a spilled arg ");
249       
250     }
251
252
253   }  // for each incoming argument
254
255 }
256
257
258
259
260 //---------------------------------------------------------------------------
261 // This method is called before graph coloring to suggest colors to the
262 // outgoing call args and the return value of the call.
263 //---------------------------------------------------------------------------
264 void UltraSparcRegInfo::suggestRegs4CallArgs(const CallInst *const CallI, 
265                                              LiveRangeInfo& LRI,
266                                              vector<RegClass *> RCList) const {
267
268
269   assert( (CallI->getOpcode() == Instruction::Call) && "Not a call instr");
270
271   // First color the return value of the call instruction. The return value
272   // will be in %o0 if the value is an integer type, or in %f0 if the 
273   // value is a float type.
274
275   // the return value cannot have a LR in machine instruction since it is
276   // only defined by the call instruction
277
278   assert( (! LRI.getLiveRangeForValue( CallI ) ) && 
279           "LR for ret Value of call already definded!");
280
281   // if type is not void,  create a new live range and set its 
282   // register class and add to LRI
283
284   if( ! ((CallI->getType())->getPrimitiveID() == Type::VoidTyID) ) {
285   
286     // create a new LR for the return value
287
288     LiveRange * RetValLR = new LiveRange();  
289     RetValLR->add( CallI );
290     unsigned RegClassID = getRegClassIDOfValue( CallI );
291     RetValLR->setRegClass( RCList[RegClassID] );
292     LRI.addLRToMap( CallI, RetValLR);
293
294     // now suggest a register depending on the register class of ret arg
295
296     if( RegClassID == IntRegClassID ) 
297       RetValLR->setSuggestedColor(SparcIntRegOrder::o0);
298     else if (RegClassID == FloatRegClassID ) 
299       RetValLR->setSuggestedColor(SparcFloatRegOrder::f0 );
300     else assert( 0 && "Unknown reg class for return value of call\n");
301
302   }
303
304
305   // Now suggest colors for arguments (operands) of the call instruction.
306   // Colors are suggested only if the arg number is smaller than the
307   // the number of registers allocated for argument passing.
308
309   Instruction::op_const_iterator OpIt = CallI->op_begin();
310   ++OpIt;   // first operand is the called method - skip it
311   
312   // go thru all the operands of LLVM instruction
313   for(unsigned argNo=0; OpIt != CallI->op_end(); ++OpIt, ++argNo ) {
314     
315     // get the LR of call operand (parameter)
316     LiveRange *const LR = LRI.getLiveRangeForValue((const Value *) *OpIt); 
317
318     if( !LR ) {              // possible because arg can be a const
319       if( DEBUG_RA) {
320         cout << " Warning: In call instr, no LR for arg:  " ;
321         printValue(*OpIt); cout << endl;
322       }
323       continue;
324     }
325     
326     unsigned RegType = getRegType( LR );
327
328     // if the arg is in int class - allocate a reg for an int arg
329     if( RegType == IntRegType ) {
330
331       if( argNo < NumOfIntArgRegs) 
332         LR->setSuggestedColor( SparcIntRegOrder::o0 + argNo );
333
334       else if (DEBUG_RA) 
335         // Do NOTHING as this will be colored as a normal value.
336         cout << " Regr not suggested for int call arg" << endl;
337       
338     }
339     else if( RegType == FPSingleRegType &&  (argNo*2 +1)< NumOfFloatArgRegs) 
340       LR->setSuggestedColor( SparcFloatRegOrder::f0 + (argNo * 2 + 1) );
341     
342  
343     else if( RegType == FPDoubleRegType && (argNo*2) < NumOfFloatArgRegs) 
344       LR->setSuggestedColor( SparcFloatRegOrder::f0 + (argNo * 2) ); 
345     
346
347   } // for all call arguments
348
349 }
350
351
352 //---------------------------------------------------------------------------
353 // After graph coloring, we have call this method to see whehter the return
354 // value and the call args received the correct colors. If not, we have
355 // to instert copy instructions.
356 //---------------------------------------------------------------------------
357
358
359 void UltraSparcRegInfo::colorCallArgs(const CallInst *const CallI,
360                                       LiveRangeInfo& LRI,
361                                       AddedInstrns *const CallAI) const {
362
363
364   // First color the return value of the call.
365   // If there is a LR for the return value, it means this
366   // method returns a value
367   
368   MachineInstr *AdMI;
369   LiveRange * RetValLR = LRI.getLiveRangeForValue( CallI );
370
371   if( RetValLR ) {
372
373     bool recvSugColor = false;
374
375     if( RetValLR->hasSuggestedColor() && RetValLR->hasColor() )
376       if( RetValLR->getSuggestedColor() == RetValLR->getColor())
377         recvSugColor = true;
378
379     // if we didn't receive the suggested color for some reason, 
380     // put copy instruction
381
382     if( !recvSugColor ) {
383
384       if( RetValLR->hasColor() ) {
385
386         unsigned RegType = getRegType( RetValLR );
387         unsigned RegClassID = (RetValLR->getRegClass())->getID();
388
389         unsigned UniRetLRReg=getUnifiedRegNum(RegClassID,RetValLR->getColor());
390         unsigned UniRetReg = InvalidRegNum;
391
392         // find where we receive the return value depending on
393         // register class
394             
395         if(RegClassID == IntRegClassID)
396           UniRetReg = getUnifiedRegNum( RegClassID, SparcIntRegOrder::o0);
397         else if(RegClassID == FloatRegClassID)
398           UniRetReg = getUnifiedRegNum( RegClassID, SparcFloatRegOrder::f0);
399
400
401         AdMI = cpReg2RegMI(UniRetLRReg, UniRetReg, RegType );   
402         CallAI->InstrnsAfter.push_back( AdMI );
403       
404         
405       } // if LR has color
406       else {
407         
408         assert(0 && "LR of return value is splilled");
409       }
410       
411
412     } // the LR didn't receive the suggested color  
413     
414   } // if there is a LR - i.e., return value is not void
415   
416
417
418   // Now color all the operands of the call instruction
419
420   Instruction::op_const_iterator OpIt = CallI->op_begin();
421   ++OpIt;   // first operand is the called method - skip it
422
423   // go thru all the operands of LLVM instruction
424   for(unsigned argNo=0; OpIt != CallI->op_end(); ++OpIt, ++argNo ) {
425     
426     // get the LR of call operand (parameter)
427     LiveRange *const LR = LRI.getLiveRangeForValue((const Value *) *OpIt); 
428
429     Value *ArgVal = (Value *) *OpIt;
430
431     unsigned RegType = getRegType( ArgVal );
432     unsigned RegClassID =  getRegClassIDOfValue( ArgVal );
433     
434     // find whether this argument is coming in a register (if not, on stack)
435
436     bool isArgInReg = false;
437     unsigned UniArgReg = InvalidRegNum;
438
439     if( (RegType== IntRegType && argNo <  NumOfIntArgRegs)) {
440       isArgInReg = true;
441       UniArgReg = getUnifiedRegNum(RegClassID, SparcIntRegOrder::o0 + argNo );
442     }
443     else if(RegType == FPSingleRegType && argNo < NumOfFloatArgRegs)  { 
444       isArgInReg = true;
445       UniArgReg = getUnifiedRegNum(RegClassID, 
446                                    SparcFloatRegOrder::f0 + (argNo*2 + 1) );
447     }
448     else if(RegType == FPDoubleRegType && argNo < NumOfFloatArgRegs)  { 
449       isArgInReg = true;
450       UniArgReg = getUnifiedRegNum(RegClassID, SparcFloatRegOrder::f0+argNo*2);
451     }
452
453
454    
455     if( !LR ) {              // possible because arg can be a const
456
457       if( DEBUG_RA) {
458         cout << " Warning: In call instr, no LR for arg:  " ;
459         printValue(*OpIt); cout << endl;
460       }
461
462       //AdMI = cpValue2RegMI( ArgVal, UniArgReg, RegType);
463       //(CallAI->InstrnsBefore).push_back( AdMI );
464       //cout << " *Constant moved to an output register\n";
465
466       continue;
467     }
468     
469
470     // if the LR received the suggested color, NOTHING to do
471
472     if( LR->hasSuggestedColor() && LR->hasColor() )
473       if( LR->getSuggestedColor() == LR->getColor() )
474         continue;
475         
476
477
478
479     
480     if( LR->hasColor() ) {
481
482       // We are here because though the LR is allocated a register, it
483       // was not allocated the suggested register. So, we have to copy %ix reg 
484       // (or stack pos of arg) to the register it was colored with
485
486
487       unsigned UniLRReg = getUnifiedRegNum( RegClassID,  LR->getColor() );
488
489       if( isArgInReg ) 
490         AdMI = cpReg2RegMI(UniLRReg, UniArgReg, RegType );
491
492       else 
493         assert(0 && "TODO: Push an outgoing arg on stack");
494
495       // Now add the instruction
496       CallAI->InstrnsBefore.push_back( AdMI );
497
498     }
499
500     else {                                // LR is not colored (i.e., spilled)
501       
502       assert(0 && "TODO: Copy a spilled call arg to an output reg ");
503       
504     }
505
506   }  // for each parameter in call instruction
507
508 }
509
510 //---------------------------------------------------------------------------
511 // This method is called for an LLVM return instruction to identify which
512 // values will be returned from this method and to suggest colors.
513 //---------------------------------------------------------------------------
514 void UltraSparcRegInfo::suggestReg4RetValue(const ReturnInst *const RetI, 
515                                              LiveRangeInfo& LRI) const {
516
517
518
519   assert( (RetI->getOpcode() == Instruction::Ret) && "Not a ret instr");
520
521   // get the return value of this return instruction
522
523   const Value *RetVal =  (RetI)->getReturnValue();
524
525   // if the method returns a value
526   if( RetVal ) {
527
528     MachineInstr *AdMI;
529     LiveRange *const LR = LRI.getLiveRangeForValue( RetVal ); 
530   
531
532     if ( LR ) {     
533
534       unsigned RegClassID = (LR->getRegClass())->getID();
535       
536       if( RegClassID == IntRegClassID ) 
537         LR->setSuggestedColor(SparcIntRegOrder::i0);
538       
539       else if ( RegClassID == FloatRegClassID ) 
540         LR->setSuggestedColor(SparcFloatRegOrder::f0);
541       
542     }
543     else {
544       if( DEBUG_RA )
545       cout << "Warning: No LR for return value" << endl;
546       // possible since this can be returning a constant
547     }
548
549
550
551   }
552
553
554
555 }
556
557 //---------------------------------------------------------------------------
558
559 //---------------------------------------------------------------------------
560 void UltraSparcRegInfo::colorRetValue(const  ReturnInst *const RetI, 
561                                       LiveRangeInfo& LRI,
562                                       AddedInstrns *const RetAI) const {
563
564
565   // get the return value of this return instruction
566   Value *RetVal =  (Value *) (RetI)->getReturnValue();
567
568   // if the method returns a value
569   if( RetVal ) {
570
571     MachineInstr *AdMI;
572     LiveRange *const LR = LRI.getLiveRangeForValue( RetVal ); 
573
574     unsigned RegClassID =  getRegClassIDOfValue(RetVal);
575     unsigned RegType = getRegType( RetVal );
576     unsigned UniRetReg = InvalidRegNum;
577     
578     if(RegClassID == IntRegClassID)
579       UniRetReg = getUnifiedRegNum( RegClassID, SparcIntRegOrder::i0 );
580     else if(RegClassID == FloatRegClassID)
581       UniRetReg = getUnifiedRegNum( RegClassID, SparcFloatRegOrder::f0);
582      
583     if ( LR ) {      
584
585       // if the LR received the suggested color, NOTHING to do
586
587       if( LR->hasSuggestedColor() && LR->hasColor() )
588         if( LR->getSuggestedColor() == LR->getColor() )
589           return;
590
591       if( LR->hasColor() ) {
592
593         // We are here because the LR was allocted a regiter, but NOT
594         // the correct register.
595
596         // copy the LR of retun value to i0 or f0
597
598         unsigned UniLRReg =getUnifiedRegNum( RegClassID, LR->getColor());
599
600         if(RegClassID == IntRegClassID)
601           UniRetReg = getUnifiedRegNum( RegClassID, SparcIntRegOrder::i0);
602         else if(RegClassID == FloatRegClassID)
603           UniRetReg = getUnifiedRegNum( RegClassID, SparcFloatRegOrder::f0);
604
605         AdMI = cpReg2RegMI( UniLRReg, UniRetReg, RegType); 
606
607       }
608       else 
609         assert(0 && "TODO: Copy the return value from stack\n");
610     
611     } else { 
612
613       // if NO LR we have to add an explicit copy to move the value to 
614       // the return register.
615
616       //AdMI = cpValue2RegMI( RetVal, UniRetReg, RegType);
617       //(RetAI->InstrnsBefore).push_back( AdMI );
618  
619       // assert( 0 && "Returned constant must be moved to the ret reg\n");
620     }
621
622
623   } // if there is a return value
624
625 }
626
627
628 //---------------------------------------------------------------------------
629 // Copy from a register to register. Register number must be the unified
630 // register number
631 //---------------------------------------------------------------------------
632
633
634 MachineInstr * UltraSparcRegInfo::cpReg2RegMI(const unsigned SrcReg, 
635                                               const unsigned DestReg,
636                                               const int RegType) const {
637
638   assert( (SrcReg != InvalidRegNum) && (DestReg != InvalidRegNum) &&
639           "Invalid Register");
640   
641   MachineInstr * MI = NULL;
642
643   switch( RegType ) {
644     
645   case IntRegType:
646     MI = new MachineInstr(ADD, 3);
647     MI->SetMachineOperand(0, SrcReg, false);
648     MI->SetMachineOperand(1, SparcIntRegOrder::g0, false);
649     MI->SetMachineOperand(2, DestReg, true);
650     break;
651
652   case FPSingleRegType:
653     MI = new MachineInstr(FMOVS, 2);
654     MI->SetMachineOperand(0, SrcReg, false);
655     MI->SetMachineOperand(1, DestReg, true);
656     break;
657
658   case FPDoubleRegType:
659     MI = new MachineInstr(FMOVD, 2);
660     MI->SetMachineOperand(0, SrcReg, false);    
661     MI->SetMachineOperand(1, DestReg, true);
662     break;
663
664   default:
665     assert(0 && "Unknow RegType");
666   }
667
668   return MI;
669 }
670
671
672
673
674 //---------------------------------------------------------------------------
675 // Only  constant/label values are accepted.
676 // ***This code is temporary ***
677 //---------------------------------------------------------------------------
678
679
680 MachineInstr * UltraSparcRegInfo::cpValue2RegMI(Value * Val, 
681                                                 const unsigned DestReg,
682                                                 const int RegType) const {
683
684   assert( (DestReg != InvalidRegNum) && "Invalid Register");
685
686   /*
687   unsigned MReg;
688   int64_t Imm;
689
690   MachineOperand::MachineOperandType MOTypeInt = 
691     ChooseRegOrImmed(Val, ADD,  *UltraSparcInfo, true, MReg, Imm);
692   */
693
694   MachineOperand::MachineOperandType MOType;
695
696   switch( Val->getValueType() ) {
697
698   case Value::ConstantVal: 
699   case Value::GlobalVariableVal:
700     MOType = MachineOperand:: MO_UnextendedImmed;  // TODO**** correct???
701     break;
702
703   case Value::BasicBlockVal:
704   case Value::MethodVal:
705     MOType = MachineOperand::MO_PCRelativeDisp;
706     break;
707
708   default:
709     cout << "Value Type: " << Val->getValueType() << endl;
710     assert(0 && "Unknown val type - Only constants/globals/labels are valid");
711   }
712
713
714
715   MachineInstr * MI = NULL;
716
717   switch( RegType ) {
718     
719   case IntRegType:
720     MI = new MachineInstr(ADD);
721     MI->SetMachineOperand(0, MOType, Val, false);
722     MI->SetMachineOperand(1, SparcIntRegOrder::g0, false);
723     MI->SetMachineOperand(2, DestReg, true);
724     break;
725
726   case FPSingleRegType:
727     assert(0 && "FP const move not yet implemented");
728     MI = new MachineInstr(FMOVS);
729     MI->SetMachineOperand(0, MachineOperand::MO_SignExtendedImmed, Val, false);
730     MI->SetMachineOperand(1, DestReg, true);
731     break;
732
733   case FPDoubleRegType:    
734     assert(0 && "FP const move not yet implemented");
735     MI = new MachineInstr(FMOVD);
736     MI->SetMachineOperand(0, MachineOperand::MO_SignExtendedImmed, Val, false);
737     MI->SetMachineOperand(1, DestReg, true);
738     break;
739
740   default:
741     assert(0 && "Unknow RegType");
742   }
743
744   return MI;
745 }
746
747
748
749
750
751
752
753 //---------------------------------------------------------------------------
754 // Print the register assigned to a LR
755 //---------------------------------------------------------------------------
756
757 void UltraSparcRegInfo::printReg(const LiveRange *const LR) {
758
759   unsigned RegClassID = (LR->getRegClass())->getID();
760
761   cout << " *Node " << (LR->getUserIGNode())->getIndex();
762
763   if( ! LR->hasColor() ) {
764     cout << " - could not find a color" << endl;
765     return;
766   }
767   
768   // if a color is found
769
770   cout << " colored with color "<< LR->getColor();
771
772   if( RegClassID == IntRegClassID ) {
773
774     cout<< " [" << SparcIntRegOrder::getRegName(LR->getColor()) ;
775     cout << "]" << endl;
776   }
777   else if ( RegClassID == FloatRegClassID) {
778     cout << "[" << SparcFloatRegOrder::getRegName(LR->getColor());
779     if( LR->getTypeID() == Type::DoubleTyID )
780       cout << "+" << SparcFloatRegOrder::getRegName(LR->getColor()+1);
781     cout << "]" << endl;
782   }
783
784
785 }
786
787
788
789
790