Default scheduling preference is SchedulingForLatency.
[oota-llvm.git] / lib / Target / PowerPC / PPCISelLowering.cpp
1 //===-- PPCISelLowering.cpp - PPC DAG Lowering Implementation -------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by Chris Lattner and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the PPCISelLowering class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "PPCISelLowering.h"
15 #include "PPCTargetMachine.h"
16 #include "llvm/CodeGen/MachineFrameInfo.h"
17 #include "llvm/CodeGen/MachineFunction.h"
18 #include "llvm/CodeGen/MachineInstrBuilder.h"
19 #include "llvm/CodeGen/SelectionDAG.h"
20 #include "llvm/CodeGen/SSARegMap.h"
21 #include "llvm/Constants.h"
22 #include "llvm/Function.h"
23 using namespace llvm;
24
25 PPCTargetLowering::PPCTargetLowering(TargetMachine &TM)
26   : TargetLowering(TM) {
27     
28   // Fold away setcc operations if possible.
29   setSetCCIsExpensive();
30   setPow2DivIsCheap();
31   
32   // Use _setjmp/_longjmp instead of setjmp/longjmp.
33   setUseUnderscoreSetJmpLongJmp(true);
34     
35   // Set up the register classes.
36   addRegisterClass(MVT::i32, PPC::GPRCRegisterClass);
37   addRegisterClass(MVT::f32, PPC::F4RCRegisterClass);
38   addRegisterClass(MVT::f64, PPC::F8RCRegisterClass);
39   
40   // PowerPC has no intrinsics for these particular operations
41   setOperationAction(ISD::MEMMOVE, MVT::Other, Expand);
42   setOperationAction(ISD::MEMSET, MVT::Other, Expand);
43   setOperationAction(ISD::MEMCPY, MVT::Other, Expand);
44   
45   // PowerPC has an i16 but no i8 (or i1) SEXTLOAD
46   setOperationAction(ISD::SEXTLOAD, MVT::i1, Expand);
47   setOperationAction(ISD::SEXTLOAD, MVT::i8, Expand);
48   
49   // PowerPC has no SREM/UREM instructions
50   setOperationAction(ISD::SREM, MVT::i32, Expand);
51   setOperationAction(ISD::UREM, MVT::i32, Expand);
52   
53   // We don't support sin/cos/sqrt/fmod
54   setOperationAction(ISD::FSIN , MVT::f64, Expand);
55   setOperationAction(ISD::FCOS , MVT::f64, Expand);
56   setOperationAction(ISD::FREM , MVT::f64, Expand);
57   setOperationAction(ISD::FSIN , MVT::f32, Expand);
58   setOperationAction(ISD::FCOS , MVT::f32, Expand);
59   setOperationAction(ISD::FREM , MVT::f32, Expand);
60   
61   // If we're enabling GP optimizations, use hardware square root
62   if (!TM.getSubtarget<PPCSubtarget>().hasFSQRT()) {
63     setOperationAction(ISD::FSQRT, MVT::f64, Expand);
64     setOperationAction(ISD::FSQRT, MVT::f32, Expand);
65   }
66   
67   // PowerPC does not have BSWAP, CTPOP or CTTZ
68   setOperationAction(ISD::BSWAP, MVT::i32  , Expand);
69   setOperationAction(ISD::CTPOP, MVT::i32  , Expand);
70   setOperationAction(ISD::CTTZ , MVT::i32  , Expand);
71   
72   // PowerPC does not have ROTR
73   setOperationAction(ISD::ROTR, MVT::i32   , Expand);
74   
75   // PowerPC does not have Select
76   setOperationAction(ISD::SELECT, MVT::i32, Expand);
77   setOperationAction(ISD::SELECT, MVT::f32, Expand);
78   setOperationAction(ISD::SELECT, MVT::f64, Expand);
79   
80   // PowerPC wants to turn select_cc of FP into fsel when possible.
81   setOperationAction(ISD::SELECT_CC, MVT::f32, Custom);
82   setOperationAction(ISD::SELECT_CC, MVT::f64, Custom);
83   
84   // PowerPC does not have BRCOND* which requires SetCC
85   setOperationAction(ISD::BRCOND,       MVT::Other, Expand);
86   setOperationAction(ISD::BRCONDTWOWAY, MVT::Other, Expand);
87   
88   // PowerPC turns FP_TO_SINT into FCTIWZ and some load/stores.
89   setOperationAction(ISD::FP_TO_SINT, MVT::i32, Custom);
90
91   // PowerPC does not have [U|S]INT_TO_FP
92   setOperationAction(ISD::SINT_TO_FP, MVT::i32, Expand);
93   setOperationAction(ISD::UINT_TO_FP, MVT::i32, Expand);
94
95   setOperationAction(ISD::BIT_CONVERT, MVT::f32, Expand);
96   setOperationAction(ISD::BIT_CONVERT, MVT::i32, Expand);
97
98   // PowerPC does not have truncstore for i1.
99   setOperationAction(ISD::TRUNCSTORE, MVT::i1, Promote);
100
101   // Support label based line numbers.
102   setOperationAction(ISD::LOCATION, MVT::Other, Expand);
103   setOperationAction(ISD::DEBUG_LOC, MVT::Other, Expand);
104   // FIXME - use subtarget debug flags
105   if (!TM.getSubtarget<PPCSubtarget>().isDarwin())
106     setOperationAction(ISD::DEBUG_LABEL, MVT::Other, Expand);
107   
108   // We want to legalize GlobalAddress and ConstantPool nodes into the 
109   // appropriate instructions to materialize the address.
110   setOperationAction(ISD::GlobalAddress, MVT::i32, Custom);
111   setOperationAction(ISD::ConstantPool,  MVT::i32, Custom);
112
113   // Use the default implementation.
114   setOperationAction(ISD::STACKSAVE         , MVT::Other, Expand); 
115   setOperationAction(ISD::STACKRESTORE      , MVT::Other, Expand);
116   setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32  , Expand);
117   
118   if (TM.getSubtarget<PPCSubtarget>().is64Bit()) {
119     // They also have instructions for converting between i64 and fp.
120     setOperationAction(ISD::FP_TO_SINT, MVT::i64, Custom);
121     setOperationAction(ISD::SINT_TO_FP, MVT::i64, Custom);
122     // To take advantage of the above i64 FP_TO_SINT, promote i32 FP_TO_UINT
123     setOperationAction(ISD::FP_TO_UINT, MVT::i32, Promote);
124   } else {
125     // PowerPC does not have FP_TO_UINT on 32-bit implementations.
126     setOperationAction(ISD::FP_TO_UINT, MVT::i32, Expand);
127   }
128
129   if (TM.getSubtarget<PPCSubtarget>().has64BitRegs()) {
130     // 64 bit PowerPC implementations can support i64 types directly
131     addRegisterClass(MVT::i64, PPC::G8RCRegisterClass);
132     // BUILD_PAIR can't be handled natively, and should be expanded to shl/or
133     setOperationAction(ISD::BUILD_PAIR, MVT::i64, Expand);
134   } else {
135     // 32 bit PowerPC wants to expand i64 shifts itself.
136     setOperationAction(ISD::SHL, MVT::i64, Custom);
137     setOperationAction(ISD::SRL, MVT::i64, Custom);
138     setOperationAction(ISD::SRA, MVT::i64, Custom);
139   }
140   
141   if (TM.getSubtarget<PPCSubtarget>().hasAltivec()) {
142     addRegisterClass(MVT::v4f32, PPC::VRRCRegisterClass);
143     addRegisterClass(MVT::v4i32, PPC::VRRCRegisterClass);
144   }
145   
146   setSetCCResultContents(ZeroOrOneSetCCResult);
147   setSchedulingPreference(SchedulingForLatency);
148   setStackPointerRegisterToSaveRestore(PPC::R1);
149   
150   computeRegisterProperties();
151 }
152
153 const char *PPCTargetLowering::getTargetNodeName(unsigned Opcode) const {
154   switch (Opcode) {
155   default: return 0;
156   case PPCISD::FSEL:          return "PPCISD::FSEL";
157   case PPCISD::FCFID:         return "PPCISD::FCFID";
158   case PPCISD::FCTIDZ:        return "PPCISD::FCTIDZ";
159   case PPCISD::FCTIWZ:        return "PPCISD::FCTIWZ";
160   case PPCISD::VMADDFP:       return "PPCISD::VMADDFP";
161   case PPCISD::VNMSUBFP:      return "PPCISD::VNMSUBFP";
162   case PPCISD::Hi:            return "PPCISD::Hi";
163   case PPCISD::Lo:            return "PPCISD::Lo";
164   case PPCISD::GlobalBaseReg: return "PPCISD::GlobalBaseReg";
165   case PPCISD::SRL:           return "PPCISD::SRL";
166   case PPCISD::SRA:           return "PPCISD::SRA";
167   case PPCISD::SHL:           return "PPCISD::SHL";
168   case PPCISD::RET_FLAG:      return "PPCISD::RET_FLAG";
169   }
170 }
171
172 /// isFloatingPointZero - Return true if this is 0.0 or -0.0.
173 static bool isFloatingPointZero(SDOperand Op) {
174   if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(Op))
175     return CFP->isExactlyValue(-0.0) || CFP->isExactlyValue(0.0);
176   else if (Op.getOpcode() == ISD::EXTLOAD || Op.getOpcode() == ISD::LOAD) {
177     // Maybe this has already been legalized into the constant pool?
178     if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(Op.getOperand(1)))
179       if (ConstantFP *CFP = dyn_cast<ConstantFP>(CP->get()))
180         return CFP->isExactlyValue(-0.0) || CFP->isExactlyValue(0.0);
181   }
182   return false;
183 }
184
185 /// LowerOperation - Provide custom lowering hooks for some operations.
186 ///
187 SDOperand PPCTargetLowering::LowerOperation(SDOperand Op, SelectionDAG &DAG) {
188   switch (Op.getOpcode()) {
189   default: assert(0 && "Wasn't expecting to be able to lower this!"); 
190   case ISD::FP_TO_SINT: {
191     assert(MVT::isFloatingPoint(Op.getOperand(0).getValueType()));
192     SDOperand Src = Op.getOperand(0);
193     if (Src.getValueType() == MVT::f32)
194       Src = DAG.getNode(ISD::FP_EXTEND, MVT::f64, Src);
195     
196     SDOperand Tmp;
197     switch (Op.getValueType()) {
198     default: assert(0 && "Unhandled FP_TO_SINT type in custom expander!");
199     case MVT::i32:
200       Tmp = DAG.getNode(PPCISD::FCTIWZ, MVT::f64, Src);
201       break;
202     case MVT::i64:
203       Tmp = DAG.getNode(PPCISD::FCTIDZ, MVT::f64, Src);
204       break;
205     }
206    
207     // Convert the FP value to an int value through memory.
208     SDOperand Bits = DAG.getNode(ISD::BIT_CONVERT, MVT::i64, Tmp);
209     if (Op.getValueType() == MVT::i32)
210       Bits = DAG.getNode(ISD::TRUNCATE, MVT::i32, Bits);
211     return Bits;
212   }
213   case ISD::SINT_TO_FP: {
214     assert(MVT::i64 == Op.getOperand(0).getValueType() && 
215            "Unhandled SINT_TO_FP type in custom expander!");
216     SDOperand Bits = DAG.getNode(ISD::BIT_CONVERT, MVT::f64, Op.getOperand(0));
217     SDOperand FP = DAG.getNode(PPCISD::FCFID, MVT::f64, Bits);
218     if (MVT::f32 == Op.getValueType())
219       FP = DAG.getNode(ISD::FP_ROUND, MVT::f32, FP);
220     return FP;
221   }
222   case ISD::SELECT_CC: {
223     // Turn FP only select_cc's into fsel instructions.
224     if (!MVT::isFloatingPoint(Op.getOperand(0).getValueType()) ||
225         !MVT::isFloatingPoint(Op.getOperand(2).getValueType()))
226       break;
227     
228     ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(4))->get();
229     
230     // Cannot handle SETEQ/SETNE.
231     if (CC == ISD::SETEQ || CC == ISD::SETNE) break;
232     
233     MVT::ValueType ResVT = Op.getValueType();
234     MVT::ValueType CmpVT = Op.getOperand(0).getValueType();
235     SDOperand LHS = Op.getOperand(0), RHS = Op.getOperand(1);
236     SDOperand TV  = Op.getOperand(2), FV  = Op.getOperand(3);
237
238     // If the RHS of the comparison is a 0.0, we don't need to do the
239     // subtraction at all.
240     if (isFloatingPointZero(RHS))
241       switch (CC) {
242       default: break;       // SETUO etc aren't handled by fsel.
243       case ISD::SETULT:
244       case ISD::SETLT:
245         std::swap(TV, FV);  // fsel is natively setge, swap operands for setlt
246       case ISD::SETUGE:
247       case ISD::SETGE:
248         if (LHS.getValueType() == MVT::f32)   // Comparison is always 64-bits
249           LHS = DAG.getNode(ISD::FP_EXTEND, MVT::f64, LHS);
250         return DAG.getNode(PPCISD::FSEL, ResVT, LHS, TV, FV);
251       case ISD::SETUGT:
252       case ISD::SETGT:
253         std::swap(TV, FV);  // fsel is natively setge, swap operands for setlt
254       case ISD::SETULE:
255       case ISD::SETLE:
256         if (LHS.getValueType() == MVT::f32)   // Comparison is always 64-bits
257           LHS = DAG.getNode(ISD::FP_EXTEND, MVT::f64, LHS);
258         return DAG.getNode(PPCISD::FSEL, ResVT,
259                            DAG.getNode(ISD::FNEG, MVT::f64, LHS), TV, FV);
260       }
261     
262     SDOperand Cmp;
263     switch (CC) {
264     default: break;       // SETUO etc aren't handled by fsel.
265     case ISD::SETULT:
266     case ISD::SETLT:
267       Cmp = DAG.getNode(ISD::FSUB, CmpVT, LHS, RHS);
268       if (Cmp.getValueType() == MVT::f32)   // Comparison is always 64-bits
269         Cmp = DAG.getNode(ISD::FP_EXTEND, MVT::f64, Cmp);
270       return DAG.getNode(PPCISD::FSEL, ResVT, Cmp, FV, TV);
271     case ISD::SETUGE:
272     case ISD::SETGE:
273       Cmp = DAG.getNode(ISD::FSUB, CmpVT, LHS, RHS);
274       if (Cmp.getValueType() == MVT::f32)   // Comparison is always 64-bits
275         Cmp = DAG.getNode(ISD::FP_EXTEND, MVT::f64, Cmp);
276       return DAG.getNode(PPCISD::FSEL, ResVT, Cmp, TV, FV);
277     case ISD::SETUGT:
278     case ISD::SETGT:
279       Cmp = DAG.getNode(ISD::FSUB, CmpVT, RHS, LHS);
280       if (Cmp.getValueType() == MVT::f32)   // Comparison is always 64-bits
281         Cmp = DAG.getNode(ISD::FP_EXTEND, MVT::f64, Cmp);
282       return DAG.getNode(PPCISD::FSEL, ResVT, Cmp, FV, TV);
283     case ISD::SETULE:
284     case ISD::SETLE:
285       Cmp = DAG.getNode(ISD::FSUB, CmpVT, RHS, LHS);
286       if (Cmp.getValueType() == MVT::f32)   // Comparison is always 64-bits
287         Cmp = DAG.getNode(ISD::FP_EXTEND, MVT::f64, Cmp);
288       return DAG.getNode(PPCISD::FSEL, ResVT, Cmp, TV, FV);
289     }
290     break;
291   }
292   case ISD::SHL: {
293     assert(Op.getValueType() == MVT::i64 &&
294            Op.getOperand(1).getValueType() == MVT::i32 && "Unexpected SHL!");
295     // The generic code does a fine job expanding shift by a constant.
296     if (isa<ConstantSDNode>(Op.getOperand(1))) break;
297     
298     // Otherwise, expand into a bunch of logical ops.  Note that these ops
299     // depend on the PPC behavior for oversized shift amounts.
300     SDOperand Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32, Op.getOperand(0),
301                                DAG.getConstant(0, MVT::i32));
302     SDOperand Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32, Op.getOperand(0),
303                                DAG.getConstant(1, MVT::i32));
304     SDOperand Amt = Op.getOperand(1);
305     
306     SDOperand Tmp1 = DAG.getNode(ISD::SUB, MVT::i32,
307                                  DAG.getConstant(32, MVT::i32), Amt);
308     SDOperand Tmp2 = DAG.getNode(PPCISD::SHL, MVT::i32, Hi, Amt);
309     SDOperand Tmp3 = DAG.getNode(PPCISD::SRL, MVT::i32, Lo, Tmp1);
310     SDOperand Tmp4 = DAG.getNode(ISD::OR , MVT::i32, Tmp2, Tmp3);
311     SDOperand Tmp5 = DAG.getNode(ISD::ADD, MVT::i32, Amt,
312                                  DAG.getConstant(-32U, MVT::i32));
313     SDOperand Tmp6 = DAG.getNode(PPCISD::SHL, MVT::i32, Lo, Tmp5);
314     SDOperand OutHi = DAG.getNode(ISD::OR, MVT::i32, Tmp4, Tmp6);
315     SDOperand OutLo = DAG.getNode(PPCISD::SHL, MVT::i32, Lo, Amt);
316     return DAG.getNode(ISD::BUILD_PAIR, MVT::i64, OutLo, OutHi);
317   }
318   case ISD::SRL: {
319     assert(Op.getValueType() == MVT::i64 &&
320            Op.getOperand(1).getValueType() == MVT::i32 && "Unexpected SHL!");
321     // The generic code does a fine job expanding shift by a constant.
322     if (isa<ConstantSDNode>(Op.getOperand(1))) break;
323     
324     // Otherwise, expand into a bunch of logical ops.  Note that these ops
325     // depend on the PPC behavior for oversized shift amounts.
326     SDOperand Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32, Op.getOperand(0),
327                                DAG.getConstant(0, MVT::i32));
328     SDOperand Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32, Op.getOperand(0),
329                                DAG.getConstant(1, MVT::i32));
330     SDOperand Amt = Op.getOperand(1);
331     
332     SDOperand Tmp1 = DAG.getNode(ISD::SUB, MVT::i32,
333                                  DAG.getConstant(32, MVT::i32), Amt);
334     SDOperand Tmp2 = DAG.getNode(PPCISD::SRL, MVT::i32, Lo, Amt);
335     SDOperand Tmp3 = DAG.getNode(PPCISD::SHL, MVT::i32, Hi, Tmp1);
336     SDOperand Tmp4 = DAG.getNode(ISD::OR , MVT::i32, Tmp2, Tmp3);
337     SDOperand Tmp5 = DAG.getNode(ISD::ADD, MVT::i32, Amt,
338                                  DAG.getConstant(-32U, MVT::i32));
339     SDOperand Tmp6 = DAG.getNode(PPCISD::SRL, MVT::i32, Hi, Tmp5);
340     SDOperand OutLo = DAG.getNode(ISD::OR, MVT::i32, Tmp4, Tmp6);
341     SDOperand OutHi = DAG.getNode(PPCISD::SRL, MVT::i32, Hi, Amt);
342     return DAG.getNode(ISD::BUILD_PAIR, MVT::i64, OutLo, OutHi);
343   }    
344   case ISD::SRA: {
345     assert(Op.getValueType() == MVT::i64 &&
346            Op.getOperand(1).getValueType() == MVT::i32 && "Unexpected SRA!");
347     // The generic code does a fine job expanding shift by a constant.
348     if (isa<ConstantSDNode>(Op.getOperand(1))) break;
349       
350     // Otherwise, expand into a bunch of logical ops, followed by a select_cc.
351     SDOperand Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32, Op.getOperand(0),
352                                DAG.getConstant(0, MVT::i32));
353     SDOperand Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32, Op.getOperand(0),
354                                DAG.getConstant(1, MVT::i32));
355     SDOperand Amt = Op.getOperand(1);
356     
357     SDOperand Tmp1 = DAG.getNode(ISD::SUB, MVT::i32,
358                                  DAG.getConstant(32, MVT::i32), Amt);
359     SDOperand Tmp2 = DAG.getNode(PPCISD::SRL, MVT::i32, Lo, Amt);
360     SDOperand Tmp3 = DAG.getNode(PPCISD::SHL, MVT::i32, Hi, Tmp1);
361     SDOperand Tmp4 = DAG.getNode(ISD::OR , MVT::i32, Tmp2, Tmp3);
362     SDOperand Tmp5 = DAG.getNode(ISD::ADD, MVT::i32, Amt,
363                                  DAG.getConstant(-32U, MVT::i32));
364     SDOperand Tmp6 = DAG.getNode(PPCISD::SRA, MVT::i32, Hi, Tmp5);
365     SDOperand OutHi = DAG.getNode(PPCISD::SRA, MVT::i32, Hi, Amt);
366     SDOperand OutLo = DAG.getSelectCC(Tmp5, DAG.getConstant(0, MVT::i32),
367                                       Tmp4, Tmp6, ISD::SETLE);
368     return DAG.getNode(ISD::BUILD_PAIR, MVT::i64, OutLo, OutHi);
369   }
370   case ISD::ConstantPool: {
371     Constant *C = cast<ConstantPoolSDNode>(Op)->get();
372     SDOperand CPI = DAG.getTargetConstantPool(C, MVT::i32);
373     SDOperand Zero = DAG.getConstant(0, MVT::i32);
374     
375     if (PPCGenerateStaticCode) {
376       // Generate non-pic code that has direct accesses to the constant pool.
377       // The address of the global is just (hi(&g)+lo(&g)).
378       SDOperand Hi = DAG.getNode(PPCISD::Hi, MVT::i32, CPI, Zero);
379       SDOperand Lo = DAG.getNode(PPCISD::Lo, MVT::i32, CPI, Zero);
380       return DAG.getNode(ISD::ADD, MVT::i32, Hi, Lo);
381     }
382     
383     // Only lower ConstantPool on Darwin.
384     if (!getTargetMachine().getSubtarget<PPCSubtarget>().isDarwin()) break;
385     SDOperand Hi = DAG.getNode(PPCISD::Hi, MVT::i32, CPI, Zero);
386     if (PICEnabled) {
387       // With PIC, the first instruction is actually "GR+hi(&G)".
388       Hi = DAG.getNode(ISD::ADD, MVT::i32,
389                        DAG.getNode(PPCISD::GlobalBaseReg, MVT::i32), Hi);
390     }
391
392     SDOperand Lo = DAG.getNode(PPCISD::Lo, MVT::i32, CPI, Zero);
393     Lo = DAG.getNode(ISD::ADD, MVT::i32, Hi, Lo);
394     return Lo;
395   }
396   case ISD::GlobalAddress: {
397     GlobalAddressSDNode *GSDN = cast<GlobalAddressSDNode>(Op);
398     GlobalValue *GV = GSDN->getGlobal();
399     SDOperand GA = DAG.getTargetGlobalAddress(GV, MVT::i32, GSDN->getOffset());
400     SDOperand Zero = DAG.getConstant(0, MVT::i32);
401
402     if (PPCGenerateStaticCode) {
403       // Generate non-pic code that has direct accesses to globals.
404       // The address of the global is just (hi(&g)+lo(&g)).
405       SDOperand Hi = DAG.getNode(PPCISD::Hi, MVT::i32, GA, Zero);
406       SDOperand Lo = DAG.getNode(PPCISD::Lo, MVT::i32, GA, Zero);
407       return DAG.getNode(ISD::ADD, MVT::i32, Hi, Lo);
408     }
409     
410     // Only lower GlobalAddress on Darwin.
411     if (!getTargetMachine().getSubtarget<PPCSubtarget>().isDarwin()) break;
412     
413     SDOperand Hi = DAG.getNode(PPCISD::Hi, MVT::i32, GA, Zero);
414     if (PICEnabled) {
415       // With PIC, the first instruction is actually "GR+hi(&G)".
416       Hi = DAG.getNode(ISD::ADD, MVT::i32,
417                        DAG.getNode(PPCISD::GlobalBaseReg, MVT::i32), Hi);
418     }
419     
420     SDOperand Lo = DAG.getNode(PPCISD::Lo, MVT::i32, GA, Zero);
421     Lo = DAG.getNode(ISD::ADD, MVT::i32, Hi, Lo);
422                                    
423     if (!GV->hasWeakLinkage() && !GV->hasLinkOnceLinkage() && !GV->isExternal())
424       return Lo;
425
426     // If the global is weak or external, we have to go through the lazy
427     // resolution stub.
428     return DAG.getLoad(MVT::i32, DAG.getEntryNode(), Lo, DAG.getSrcValue(0));
429   }
430   }
431   return SDOperand();
432 }
433
434 std::vector<SDOperand>
435 PPCTargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) {
436   //
437   // add beautiful description of PPC stack frame format, or at least some docs
438   //
439   MachineFunction &MF = DAG.getMachineFunction();
440   MachineFrameInfo *MFI = MF.getFrameInfo();
441   MachineBasicBlock& BB = MF.front();
442   SSARegMap *RegMap = MF.getSSARegMap();
443   std::vector<SDOperand> ArgValues;
444   
445   unsigned ArgOffset = 24;
446   unsigned GPR_remaining = 8;
447   unsigned FPR_remaining = 13;
448   unsigned GPR_idx = 0, FPR_idx = 0;
449   static const unsigned GPR[] = {
450     PPC::R3, PPC::R4, PPC::R5, PPC::R6,
451     PPC::R7, PPC::R8, PPC::R9, PPC::R10,
452   };
453   static const unsigned FPR[] = {
454     PPC::F1, PPC::F2, PPC::F3, PPC::F4, PPC::F5, PPC::F6, PPC::F7,
455     PPC::F8, PPC::F9, PPC::F10, PPC::F11, PPC::F12, PPC::F13
456   };
457   
458   // Add DAG nodes to load the arguments...  On entry to a function on PPC,
459   // the arguments start at offset 24, although they are likely to be passed
460   // in registers.
461   for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I) {
462     SDOperand newroot, argt;
463     unsigned ObjSize;
464     bool needsLoad = false;
465     bool ArgLive = !I->use_empty();
466     MVT::ValueType ObjectVT = getValueType(I->getType());
467     
468     switch (ObjectVT) {
469     default: assert(0 && "Unhandled argument type!");
470     case MVT::i1:
471     case MVT::i8:
472     case MVT::i16:
473     case MVT::i32:
474       ObjSize = 4;
475       if (!ArgLive) break;
476       if (GPR_remaining > 0) {
477         unsigned VReg = RegMap->createVirtualRegister(&PPC::GPRCRegClass);
478         MF.addLiveIn(GPR[GPR_idx], VReg);
479         argt = newroot = DAG.getCopyFromReg(DAG.getRoot(), VReg, MVT::i32);
480         if (ObjectVT != MVT::i32) {
481           unsigned AssertOp = I->getType()->isSigned() ? ISD::AssertSext 
482                                                        : ISD::AssertZext;
483           argt = DAG.getNode(AssertOp, MVT::i32, argt, 
484                              DAG.getValueType(ObjectVT));
485           argt = DAG.getNode(ISD::TRUNCATE, ObjectVT, argt);
486         }
487       } else {
488         needsLoad = true;
489       }
490       break;
491     case MVT::i64:
492       ObjSize = 8;
493       if (!ArgLive) break;
494       if (GPR_remaining > 0) {
495         SDOperand argHi, argLo;
496         unsigned VReg = RegMap->createVirtualRegister(&PPC::GPRCRegClass);
497         MF.addLiveIn(GPR[GPR_idx], VReg);
498         argHi = DAG.getCopyFromReg(DAG.getRoot(), VReg, MVT::i32);
499         // If we have two or more remaining argument registers, then both halves
500         // of the i64 can be sourced from there.  Otherwise, the lower half will
501         // have to come off the stack.  This can happen when an i64 is preceded
502         // by 28 bytes of arguments.
503         if (GPR_remaining > 1) {
504           unsigned VReg = RegMap->createVirtualRegister(&PPC::GPRCRegClass);
505           MF.addLiveIn(GPR[GPR_idx+1], VReg);
506           argLo = DAG.getCopyFromReg(argHi, VReg, MVT::i32);
507         } else {
508           int FI = MFI->CreateFixedObject(4, ArgOffset+4);
509           SDOperand FIN = DAG.getFrameIndex(FI, MVT::i32);
510           argLo = DAG.getLoad(MVT::i32, DAG.getEntryNode(), FIN,
511                               DAG.getSrcValue(NULL));
512         }
513         // Build the outgoing arg thingy
514         argt = DAG.getNode(ISD::BUILD_PAIR, MVT::i64, argLo, argHi);
515         newroot = argLo;
516       } else {
517         needsLoad = true;
518       }
519       break;
520     case MVT::f32:
521     case MVT::f64:
522       ObjSize = (ObjectVT == MVT::f64) ? 8 : 4;
523       if (!ArgLive) {
524         if (FPR_remaining > 0) {
525           --FPR_remaining;
526           ++FPR_idx;
527         }        
528         break;
529       }
530       if (FPR_remaining > 0) {
531         unsigned VReg;
532         if (ObjectVT == MVT::f32)
533           VReg = RegMap->createVirtualRegister(&PPC::F4RCRegClass);
534         else
535           VReg = RegMap->createVirtualRegister(&PPC::F8RCRegClass);
536         MF.addLiveIn(FPR[FPR_idx], VReg);
537         argt = newroot = DAG.getCopyFromReg(DAG.getRoot(), VReg, ObjectVT);
538         --FPR_remaining;
539         ++FPR_idx;
540       } else {
541         needsLoad = true;
542       }
543       break;
544     }
545     
546     // We need to load the argument to a virtual register if we determined above
547     // that we ran out of physical registers of the appropriate type
548     if (needsLoad) {
549       unsigned SubregOffset = 0;
550       if (ObjectVT == MVT::i8 || ObjectVT == MVT::i1) SubregOffset = 3;
551       if (ObjectVT == MVT::i16) SubregOffset = 2;
552       int FI = MFI->CreateFixedObject(ObjSize, ArgOffset);
553       SDOperand FIN = DAG.getFrameIndex(FI, MVT::i32);
554       FIN = DAG.getNode(ISD::ADD, MVT::i32, FIN,
555                         DAG.getConstant(SubregOffset, MVT::i32));
556       argt = newroot = DAG.getLoad(ObjectVT, DAG.getEntryNode(), FIN,
557                                    DAG.getSrcValue(NULL));
558     }
559     
560     // Every 4 bytes of argument space consumes one of the GPRs available for
561     // argument passing.
562     if (GPR_remaining > 0) {
563       unsigned delta = (GPR_remaining > 1 && ObjSize == 8) ? 2 : 1;
564       GPR_remaining -= delta;
565       GPR_idx += delta;
566     }
567     ArgOffset += ObjSize;
568     if (newroot.Val)
569       DAG.setRoot(newroot.getValue(1));
570     
571     ArgValues.push_back(argt);
572   }
573   
574   // If the function takes variable number of arguments, make a frame index for
575   // the start of the first vararg value... for expansion of llvm.va_start.
576   if (F.isVarArg()) {
577     VarArgsFrameIndex = MFI->CreateFixedObject(4, ArgOffset);
578     SDOperand FIN = DAG.getFrameIndex(VarArgsFrameIndex, MVT::i32);
579     // If this function is vararg, store any remaining integer argument regs
580     // to their spots on the stack so that they may be loaded by deferencing the
581     // result of va_next.
582     std::vector<SDOperand> MemOps;
583     for (; GPR_remaining > 0; --GPR_remaining, ++GPR_idx) {
584       unsigned VReg = RegMap->createVirtualRegister(&PPC::GPRCRegClass);
585       MF.addLiveIn(GPR[GPR_idx], VReg);
586       SDOperand Val = DAG.getCopyFromReg(DAG.getRoot(), VReg, MVT::i32);
587       SDOperand Store = DAG.getNode(ISD::STORE, MVT::Other, Val.getValue(1),
588                                     Val, FIN, DAG.getSrcValue(NULL));
589       MemOps.push_back(Store);
590       // Increment the address by four for the next argument to store
591       SDOperand PtrOff = DAG.getConstant(4, getPointerTy());
592       FIN = DAG.getNode(ISD::ADD, MVT::i32, FIN, PtrOff);
593     }
594     if (!MemOps.empty()) {
595       MemOps.push_back(DAG.getRoot());
596       DAG.setRoot(DAG.getNode(ISD::TokenFactor, MVT::Other, MemOps));
597     }
598   }
599   
600   // Finally, inform the code generator which regs we return values in.
601   switch (getValueType(F.getReturnType())) {
602     default: assert(0 && "Unknown type!");
603     case MVT::isVoid: break;
604     case MVT::i1:
605     case MVT::i8:
606     case MVT::i16:
607     case MVT::i32:
608       MF.addLiveOut(PPC::R3);
609       break;
610     case MVT::i64:
611       MF.addLiveOut(PPC::R3);
612       MF.addLiveOut(PPC::R4);
613       break;
614     case MVT::f32:
615     case MVT::f64:
616       MF.addLiveOut(PPC::F1);
617       break;
618   }
619   
620   return ArgValues;
621 }
622
623 std::pair<SDOperand, SDOperand>
624 PPCTargetLowering::LowerCallTo(SDOperand Chain,
625                                const Type *RetTy, bool isVarArg,
626                                unsigned CallingConv, bool isTailCall,
627                                SDOperand Callee, ArgListTy &Args,
628                                SelectionDAG &DAG) {
629   // args_to_use will accumulate outgoing args for the ISD::CALL case in
630   // SelectExpr to use to put the arguments in the appropriate registers.
631   std::vector<SDOperand> args_to_use;
632   
633   // Count how many bytes are to be pushed on the stack, including the linkage
634   // area, and parameter passing area.
635   unsigned NumBytes = 24;
636   
637   if (Args.empty()) {
638     Chain = DAG.getNode(ISD::CALLSEQ_START, MVT::Other, Chain,
639                         DAG.getConstant(NumBytes, getPointerTy()));
640   } else {
641     for (unsigned i = 0, e = Args.size(); i != e; ++i) {
642       switch (getValueType(Args[i].second)) {
643       default: assert(0 && "Unknown value type!");
644       case MVT::i1:
645       case MVT::i8:
646       case MVT::i16:
647       case MVT::i32:
648       case MVT::f32:
649         NumBytes += 4;
650         break;
651       case MVT::i64:
652       case MVT::f64:
653         NumBytes += 8;
654         break;
655       }
656     }
657         
658     // Just to be safe, we'll always reserve the full 24 bytes of linkage area
659     // plus 32 bytes of argument space in case any called code gets funky on us.
660     // (Required by ABI to support var arg)
661     if (NumBytes < 56) NumBytes = 56;
662     
663     // Adjust the stack pointer for the new arguments...
664     // These operations are automatically eliminated by the prolog/epilog pass
665     Chain = DAG.getNode(ISD::CALLSEQ_START, MVT::Other, Chain,
666                         DAG.getConstant(NumBytes, getPointerTy()));
667     
668     // Set up a copy of the stack pointer for use loading and storing any
669     // arguments that may not fit in the registers available for argument
670     // passing.
671     SDOperand StackPtr = DAG.getRegister(PPC::R1, MVT::i32);
672     
673     // Figure out which arguments are going to go in registers, and which in
674     // memory.  Also, if this is a vararg function, floating point operations
675     // must be stored to our stack, and loaded into integer regs as well, if
676     // any integer regs are available for argument passing.
677     unsigned ArgOffset = 24;
678     unsigned GPR_remaining = 8;
679     unsigned FPR_remaining = 13;
680     
681     std::vector<SDOperand> MemOps;
682     for (unsigned i = 0, e = Args.size(); i != e; ++i) {
683       // PtrOff will be used to store the current argument to the stack if a
684       // register cannot be found for it.
685       SDOperand PtrOff = DAG.getConstant(ArgOffset, getPointerTy());
686       PtrOff = DAG.getNode(ISD::ADD, MVT::i32, StackPtr, PtrOff);
687       MVT::ValueType ArgVT = getValueType(Args[i].second);
688       
689       switch (ArgVT) {
690       default: assert(0 && "Unexpected ValueType for argument!");
691       case MVT::i1:
692       case MVT::i8:
693       case MVT::i16:
694         // Promote the integer to 32 bits.  If the input type is signed use a
695         // sign extend, otherwise use a zero extend.
696         if (Args[i].second->isSigned())
697           Args[i].first =DAG.getNode(ISD::SIGN_EXTEND, MVT::i32, Args[i].first);
698         else
699           Args[i].first =DAG.getNode(ISD::ZERO_EXTEND, MVT::i32, Args[i].first);
700         // FALL THROUGH
701       case MVT::i32:
702         if (GPR_remaining > 0) {
703           args_to_use.push_back(Args[i].first);
704           --GPR_remaining;
705         } else {
706           MemOps.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain,
707                                        Args[i].first, PtrOff,
708                                        DAG.getSrcValue(NULL)));
709         }
710         ArgOffset += 4;
711         break;
712       case MVT::i64:
713         // If we have one free GPR left, we can place the upper half of the i64
714         // in it, and store the other half to the stack.  If we have two or more
715         // free GPRs, then we can pass both halves of the i64 in registers.
716         if (GPR_remaining > 0) {
717           SDOperand Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32,
718                                      Args[i].first, DAG.getConstant(1, MVT::i32));
719           SDOperand Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32,
720                                      Args[i].first, DAG.getConstant(0, MVT::i32));
721           args_to_use.push_back(Hi);
722           --GPR_remaining;
723           if (GPR_remaining > 0) {
724             args_to_use.push_back(Lo);
725             --GPR_remaining;
726           } else {
727             SDOperand ConstFour = DAG.getConstant(4, getPointerTy());
728             PtrOff = DAG.getNode(ISD::ADD, MVT::i32, PtrOff, ConstFour);
729             MemOps.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain,
730                                          Lo, PtrOff, DAG.getSrcValue(NULL)));
731           }
732         } else {
733           MemOps.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain,
734                                        Args[i].first, PtrOff,
735                                        DAG.getSrcValue(NULL)));
736         }
737         ArgOffset += 8;
738         break;
739       case MVT::f32:
740       case MVT::f64:
741         if (FPR_remaining > 0) {
742           args_to_use.push_back(Args[i].first);
743           --FPR_remaining;
744           if (isVarArg) {
745             SDOperand Store = DAG.getNode(ISD::STORE, MVT::Other, Chain,
746                                           Args[i].first, PtrOff,
747                                           DAG.getSrcValue(NULL));
748             MemOps.push_back(Store);
749             // Float varargs are always shadowed in available integer registers
750             if (GPR_remaining > 0) {
751               SDOperand Load = DAG.getLoad(MVT::i32, Store, PtrOff,
752                                            DAG.getSrcValue(NULL));
753               MemOps.push_back(Load.getValue(1));
754               args_to_use.push_back(Load);
755               --GPR_remaining;
756             }
757             if (GPR_remaining > 0 && MVT::f64 == ArgVT) {
758               SDOperand ConstFour = DAG.getConstant(4, getPointerTy());
759               PtrOff = DAG.getNode(ISD::ADD, MVT::i32, PtrOff, ConstFour);
760               SDOperand Load = DAG.getLoad(MVT::i32, Store, PtrOff,
761                                            DAG.getSrcValue(NULL));
762               MemOps.push_back(Load.getValue(1));
763               args_to_use.push_back(Load);
764               --GPR_remaining;
765             }
766           } else {
767             // If we have any FPRs remaining, we may also have GPRs remaining.
768             // Args passed in FPRs consume either 1 (f32) or 2 (f64) available
769             // GPRs.
770             if (GPR_remaining > 0) {
771               args_to_use.push_back(DAG.getNode(ISD::UNDEF, MVT::i32));
772               --GPR_remaining;
773             }
774             if (GPR_remaining > 0 && MVT::f64 == ArgVT) {
775               args_to_use.push_back(DAG.getNode(ISD::UNDEF, MVT::i32));
776               --GPR_remaining;
777             }
778           }
779         } else {
780           MemOps.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain,
781                                        Args[i].first, PtrOff,
782                                        DAG.getSrcValue(NULL)));
783         }
784         ArgOffset += (ArgVT == MVT::f32) ? 4 : 8;
785         break;
786       }
787     }
788     if (!MemOps.empty())
789       Chain = DAG.getNode(ISD::TokenFactor, MVT::Other, MemOps);
790   }
791   
792   std::vector<MVT::ValueType> RetVals;
793   MVT::ValueType RetTyVT = getValueType(RetTy);
794   MVT::ValueType ActualRetTyVT = RetTyVT;
795   if (RetTyVT >= MVT::i1 && RetTyVT <= MVT::i16)
796     ActualRetTyVT = MVT::i32;   // Promote result to i32.
797     
798   if (RetTyVT != MVT::isVoid)
799     RetVals.push_back(ActualRetTyVT);
800   RetVals.push_back(MVT::Other);
801   
802   // If the callee is a GlobalAddress node (quite common, every direct call is)
803   // turn it into a TargetGlobalAddress node so that legalize doesn't hack it.
804   if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee))
805     Callee = DAG.getTargetGlobalAddress(G->getGlobal(), MVT::i32);
806   
807   SDOperand TheCall = SDOperand(DAG.getCall(RetVals,
808                                             Chain, Callee, args_to_use), 0);
809   Chain = TheCall.getValue(RetTyVT != MVT::isVoid);
810   Chain = DAG.getNode(ISD::CALLSEQ_END, MVT::Other, Chain,
811                       DAG.getConstant(NumBytes, getPointerTy()));
812   SDOperand RetVal = TheCall;
813   
814   // If the result is a small value, add a note so that we keep track of the
815   // information about whether it is sign or zero extended.
816   if (RetTyVT != ActualRetTyVT) {
817     RetVal = DAG.getNode(RetTy->isSigned() ? ISD::AssertSext : ISD::AssertZext,
818                          MVT::i32, RetVal, DAG.getValueType(RetTyVT));
819     RetVal = DAG.getNode(ISD::TRUNCATE, RetTyVT, RetVal);
820   }
821   
822   return std::make_pair(RetVal, Chain);
823 }
824
825 SDOperand PPCTargetLowering::LowerReturnTo(SDOperand Chain, SDOperand Op,
826                                            SelectionDAG &DAG) {
827   SDOperand Copy;
828   switch (Op.getValueType()) {
829     default: assert(0 && "Unknown type to return!");
830     case MVT::i32:
831       Copy = DAG.getCopyToReg(Chain, PPC::R3, Op, SDOperand());
832       break;
833     case MVT::f32:
834     case MVT::f64:
835       Copy = DAG.getCopyToReg(Chain, PPC::F1, Op, SDOperand());
836       break;
837     case MVT::i64:
838       SDOperand Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32, Op, 
839                                  DAG.getConstant(1, MVT::i32));
840       SDOperand Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32, Op,
841                                  DAG.getConstant(0, MVT::i32));
842       Copy = DAG.getCopyToReg(Chain, PPC::R3, Hi, SDOperand());
843       Copy = DAG.getCopyToReg(Copy, PPC::R4, Lo, Copy.getValue(1));
844       break;
845   }
846   return DAG.getNode(PPCISD::RET_FLAG, MVT::Other, Copy, Copy.getValue(1));
847 }
848
849 SDOperand PPCTargetLowering::LowerVAStart(SDOperand Chain, SDOperand VAListP,
850                                           Value *VAListV, SelectionDAG &DAG) {
851   // vastart just stores the address of the VarArgsFrameIndex slot into the
852   // memory location argument.
853   SDOperand FR = DAG.getFrameIndex(VarArgsFrameIndex, MVT::i32);
854   return DAG.getNode(ISD::STORE, MVT::Other, Chain, FR, VAListP,
855                      DAG.getSrcValue(VAListV));
856 }
857
858 std::pair<SDOperand,SDOperand>
859 PPCTargetLowering::LowerVAArg(SDOperand Chain,
860                               SDOperand VAListP, Value *VAListV,
861                               const Type *ArgTy, SelectionDAG &DAG) {
862   MVT::ValueType ArgVT = getValueType(ArgTy);
863   
864   SDOperand VAList =
865     DAG.getLoad(MVT::i32, Chain, VAListP, DAG.getSrcValue(VAListV));
866   SDOperand Result = DAG.getLoad(ArgVT, Chain, VAList, DAG.getSrcValue(NULL));
867   unsigned Amt;
868   if (ArgVT == MVT::i32 || ArgVT == MVT::f32)
869     Amt = 4;
870   else {
871     assert((ArgVT == MVT::i64 || ArgVT == MVT::f64) &&
872            "Other types should have been promoted for varargs!");
873     Amt = 8;
874   }
875   VAList = DAG.getNode(ISD::ADD, VAList.getValueType(), VAList,
876                        DAG.getConstant(Amt, VAList.getValueType()));
877   Chain = DAG.getNode(ISD::STORE, MVT::Other, Chain,
878                       VAList, VAListP, DAG.getSrcValue(VAListV));
879   return std::make_pair(Result, Chain);
880 }
881
882
883 std::pair<SDOperand, SDOperand> PPCTargetLowering::
884 LowerFrameReturnAddress(bool isFrameAddress, SDOperand Chain, unsigned Depth,
885                         SelectionDAG &DAG) {
886   assert(0 && "LowerFrameReturnAddress unimplemented");
887   abort();
888 }
889
890 MachineBasicBlock *
891 PPCTargetLowering::InsertAtEndOfBasicBlock(MachineInstr *MI,
892                                            MachineBasicBlock *BB) {
893   assert((MI->getOpcode() == PPC::SELECT_CC_Int ||
894           MI->getOpcode() == PPC::SELECT_CC_F4 ||
895           MI->getOpcode() == PPC::SELECT_CC_F8) &&
896          "Unexpected instr type to insert");
897   
898   // To "insert" a SELECT_CC instruction, we actually have to insert the diamond
899   // control-flow pattern.  The incoming instruction knows the destination vreg
900   // to set, the condition code register to branch on, the true/false values to
901   // select between, and a branch opcode to use.
902   const BasicBlock *LLVM_BB = BB->getBasicBlock();
903   ilist<MachineBasicBlock>::iterator It = BB;
904   ++It;
905   
906   //  thisMBB:
907   //  ...
908   //   TrueVal = ...
909   //   cmpTY ccX, r1, r2
910   //   bCC copy1MBB
911   //   fallthrough --> copy0MBB
912   MachineBasicBlock *thisMBB = BB;
913   MachineBasicBlock *copy0MBB = new MachineBasicBlock(LLVM_BB);
914   MachineBasicBlock *sinkMBB = new MachineBasicBlock(LLVM_BB);
915   BuildMI(BB, MI->getOperand(4).getImmedValue(), 2)
916     .addReg(MI->getOperand(1).getReg()).addMBB(sinkMBB);
917   MachineFunction *F = BB->getParent();
918   F->getBasicBlockList().insert(It, copy0MBB);
919   F->getBasicBlockList().insert(It, sinkMBB);
920   // Update machine-CFG edges
921   BB->addSuccessor(copy0MBB);
922   BB->addSuccessor(sinkMBB);
923   
924   //  copy0MBB:
925   //   %FalseValue = ...
926   //   # fallthrough to sinkMBB
927   BB = copy0MBB;
928   
929   // Update machine-CFG edges
930   BB->addSuccessor(sinkMBB);
931   
932   //  sinkMBB:
933   //   %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ]
934   //  ...
935   BB = sinkMBB;
936   BuildMI(BB, PPC::PHI, 4, MI->getOperand(0).getReg())
937     .addReg(MI->getOperand(3).getReg()).addMBB(copy0MBB)
938     .addReg(MI->getOperand(2).getReg()).addMBB(thisMBB);
939
940   delete MI;   // The pseudo instruction is gone now.
941   return BB;
942 }
943