expand unsupported stacksave/stackrestore nodes
[oota-llvm.git] / lib / Target / Alpha / AlphaISelLowering.cpp
1 //===-- AlphaISelLowering.cpp - Alpha DAG Lowering Implementation ---------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by Andrew Lenharth 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 AlphaISelLowering class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "AlphaISelLowering.h"
15 #include "AlphaTargetMachine.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 #include "llvm/Support/CommandLine.h"
24 #include <iostream>
25
26 using namespace llvm;
27
28 namespace llvm {
29   extern cl::opt<bool> EnableAlphaIDIV;
30   extern cl::opt<bool> EnableAlphaCount;
31   extern cl::opt<bool> EnableAlphaLSMark;
32 }
33
34 /// AddLiveIn - This helper function adds the specified physical register to the
35 /// MachineFunction as a live in value.  It also creates a corresponding virtual
36 /// register for it.
37 static unsigned AddLiveIn(MachineFunction &MF, unsigned PReg,
38                           TargetRegisterClass *RC) {
39   assert(RC->contains(PReg) && "Not the correct regclass!");
40   unsigned VReg = MF.getSSARegMap()->createVirtualRegister(RC);
41   MF.addLiveIn(PReg, VReg);
42   return VReg;
43 }
44
45 AlphaTargetLowering::AlphaTargetLowering(TargetMachine &TM) : TargetLowering(TM) {
46   // Set up the TargetLowering object.
47   //I am having problems with shr n ubyte 1
48   setShiftAmountType(MVT::i64);
49   setSetCCResultType(MVT::i64);
50   setSetCCResultContents(ZeroOrOneSetCCResult);
51   
52   addRegisterClass(MVT::i64, Alpha::GPRCRegisterClass);
53   addRegisterClass(MVT::f64, Alpha::F8RCRegisterClass);
54   addRegisterClass(MVT::f32, Alpha::F4RCRegisterClass);
55   
56   setOperationAction(ISD::BRCONDTWOWAY, MVT::Other, Expand);
57   setOperationAction(ISD::BRTWOWAY_CC,  MVT::Other, Expand);
58   
59   setOperationAction(ISD::EXTLOAD, MVT::i1,  Promote);
60   setOperationAction(ISD::EXTLOAD, MVT::f32, Expand);
61   
62   setOperationAction(ISD::ZEXTLOAD, MVT::i1,  Promote);
63   setOperationAction(ISD::ZEXTLOAD, MVT::i32, Expand);
64   
65   setOperationAction(ISD::SEXTLOAD, MVT::i1,  Promote);
66   setOperationAction(ISD::SEXTLOAD, MVT::i8,  Expand);
67   setOperationAction(ISD::SEXTLOAD, MVT::i16, Expand);
68   
69   setOperationAction(ISD::TRUNCSTORE, MVT::i1, Promote);
70
71   setOperationAction(ISD::FREM, MVT::f32, Expand);
72   setOperationAction(ISD::FREM, MVT::f64, Expand);
73   
74   setOperationAction(ISD::UINT_TO_FP, MVT::i64, Expand);
75   setOperationAction(ISD::SINT_TO_FP, MVT::i64, Custom);
76   setOperationAction(ISD::FP_TO_UINT, MVT::i64, Expand);
77   setOperationAction(ISD::FP_TO_SINT, MVT::i64, Custom);
78
79   if (!TM.getSubtarget<AlphaSubtarget>().hasCT()) {
80     setOperationAction(ISD::CTPOP    , MVT::i64  , Expand);
81     setOperationAction(ISD::CTTZ     , MVT::i64  , Expand);
82     setOperationAction(ISD::CTLZ     , MVT::i64  , Expand);
83   }
84   setOperationAction(ISD::ROTL     , MVT::i64, Expand);
85   setOperationAction(ISD::ROTR     , MVT::i64, Expand);
86   
87   setOperationAction(ISD::SREM     , MVT::i64, Custom);
88   setOperationAction(ISD::UREM     , MVT::i64, Custom);
89   setOperationAction(ISD::SDIV     , MVT::i64, Custom);
90   setOperationAction(ISD::UDIV     , MVT::i64, Custom);
91   
92   setOperationAction(ISD::MEMMOVE  , MVT::Other, Expand);
93   setOperationAction(ISD::MEMSET   , MVT::Other, Expand);
94   setOperationAction(ISD::MEMCPY   , MVT::Other, Expand);
95   
96   // We don't support sin/cos/sqrt
97   setOperationAction(ISD::FSIN , MVT::f64, Expand);
98   setOperationAction(ISD::FCOS , MVT::f64, Expand);
99   setOperationAction(ISD::FSQRT, MVT::f64, Expand);
100   setOperationAction(ISD::FSIN , MVT::f32, Expand);
101   setOperationAction(ISD::FCOS , MVT::f32, Expand);
102   setOperationAction(ISD::FSQRT, MVT::f32, Expand);
103
104   setOperationAction(ISD::SETCC, MVT::f32, Promote);
105
106   // We don't have line number support yet.
107   setOperationAction(ISD::LOCATION, MVT::Other, Expand);
108   setOperationAction(ISD::DEBUG_LOC, MVT::Other, Expand);
109   setOperationAction(ISD::DEBUG_LABEL, MVT::Other, Expand);
110
111   // Not implemented yet.
112   setOperationAction(ISD::STACKSAVE, MVT::Other, Expand); 
113   setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand);
114   
115   // We want to legalize GlobalAddress and ConstantPool and
116   // ExternalSymbols nodes into the appropriate instructions to
117   // materialize the address.
118   setOperationAction(ISD::GlobalAddress,  MVT::i64, Custom);
119   setOperationAction(ISD::ConstantPool,   MVT::i64, Custom);
120   setOperationAction(ISD::ExternalSymbol, MVT::i64, Custom);
121
122   addLegalFPImmediate(+0.0); //F31
123   addLegalFPImmediate(-0.0); //-F31
124
125   computeRegisterProperties();
126
127   useITOF = TM.getSubtarget<AlphaSubtarget>().hasF2I();
128 }
129
130
131 //http://www.cs.arizona.edu/computer.help/policy/DIGITAL_unix/AA-PY8AC-TET1_html/callCH3.html#BLOCK21
132
133 //For now, just use variable size stack frame format
134
135 //In a standard call, the first six items are passed in registers $16
136 //- $21 and/or registers $f16 - $f21. (See Section 4.1.2 for details
137 //of argument-to-register correspondence.) The remaining items are
138 //collected in a memory argument list that is a naturally aligned
139 //array of quadwords. In a standard call, this list, if present, must
140 //be passed at 0(SP).
141 //7 ... n         0(SP) ... (n-7)*8(SP)
142
143 // //#define FP    $15
144 // //#define RA    $26
145 // //#define PV    $27
146 // //#define GP    $29
147 // //#define SP    $30
148
149 std::vector<SDOperand>
150 AlphaTargetLowering::LowerArguments(Function &F, SelectionDAG &DAG)
151 {
152   MachineFunction &MF = DAG.getMachineFunction();
153   MachineFrameInfo *MFI = MF.getFrameInfo();
154   MachineBasicBlock& BB = MF.front();
155   std::vector<SDOperand> ArgValues;
156
157   unsigned args_int[] = {
158     Alpha::R16, Alpha::R17, Alpha::R18, Alpha::R19, Alpha::R20, Alpha::R21};
159   unsigned args_float[] = {
160     Alpha::F16, Alpha::F17, Alpha::F18, Alpha::F19, Alpha::F20, Alpha::F21};
161
162   int count = 0;
163
164   GP = AddLiveIn(MF, Alpha::R29, getRegClassFor(MVT::i64));
165   RA = AddLiveIn(MF, Alpha::R26, getRegClassFor(MVT::i64));
166
167   for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I)
168   {
169     SDOperand argt;
170     if (count  < 6) {
171       unsigned Vreg;
172       MVT::ValueType VT = getValueType(I->getType());
173       switch (VT) {
174       default:
175         std::cerr << "Unknown Type " << VT << "\n";
176         abort();
177       case MVT::f64:
178       case MVT::f32:
179         args_float[count] = AddLiveIn(MF, args_float[count], getRegClassFor(VT));
180         argt = DAG.getCopyFromReg(DAG.getRoot(), args_float[count], VT);
181         DAG.setRoot(argt.getValue(1));
182         break;
183       case MVT::i1:
184       case MVT::i8:
185       case MVT::i16:
186       case MVT::i32:
187       case MVT::i64:
188         args_int[count] = AddLiveIn(MF, args_int[count], getRegClassFor(MVT::i64));
189         argt = DAG.getCopyFromReg(DAG.getRoot(), args_int[count], MVT::i64);
190         DAG.setRoot(argt.getValue(1));
191         if (VT != MVT::i64) {
192           unsigned AssertOp = 
193             I->getType()->isSigned() ? ISD::AssertSext : ISD::AssertZext;
194           argt = DAG.getNode(AssertOp, MVT::i64, argt, 
195                              DAG.getValueType(VT));
196           argt = DAG.getNode(ISD::TRUNCATE, VT, argt);
197         }
198         break;
199       }
200     } else { //more args
201       // Create the frame index object for this incoming parameter...
202       int FI = MFI->CreateFixedObject(8, 8 * (count - 6));
203
204       // Create the SelectionDAG nodes corresponding to a load
205       //from this parameter
206       SDOperand FIN = DAG.getFrameIndex(FI, MVT::i64);
207       argt = DAG.getLoad(getValueType(I->getType()),
208                          DAG.getEntryNode(), FIN, DAG.getSrcValue(NULL));
209     }
210     ++count;
211     ArgValues.push_back(argt);
212   }
213
214   // If the functions takes variable number of arguments, copy all regs to stack
215   if (F.isVarArg()) {
216     VarArgsOffset = count * 8;
217     std::vector<SDOperand> LS;
218     for (int i = 0; i < 6; ++i) {
219       if (MRegisterInfo::isPhysicalRegister(args_int[i]))
220         args_int[i] = AddLiveIn(MF, args_int[i], getRegClassFor(MVT::i64));
221       SDOperand argt = DAG.getCopyFromReg(DAG.getRoot(), args_int[i], MVT::i64);
222       int FI = MFI->CreateFixedObject(8, -8 * (6 - i));
223       if (i == 0) VarArgsBase = FI;
224       SDOperand SDFI = DAG.getFrameIndex(FI, MVT::i64);
225       LS.push_back(DAG.getNode(ISD::STORE, MVT::Other, DAG.getRoot(), argt,
226                                SDFI, DAG.getSrcValue(NULL)));
227
228       if (MRegisterInfo::isPhysicalRegister(args_float[i]))
229         args_float[i] = AddLiveIn(MF, args_float[i], getRegClassFor(MVT::f64));
230       argt = DAG.getCopyFromReg(DAG.getRoot(), args_float[i], MVT::f64);
231       FI = MFI->CreateFixedObject(8, - 8 * (12 - i));
232       SDFI = DAG.getFrameIndex(FI, MVT::i64);
233       LS.push_back(DAG.getNode(ISD::STORE, MVT::Other, DAG.getRoot(), argt,
234                                SDFI, DAG.getSrcValue(NULL)));
235     }
236
237     //Set up a token factor with all the stack traffic
238     DAG.setRoot(DAG.getNode(ISD::TokenFactor, MVT::Other, LS));
239   }
240
241   // Finally, inform the code generator which regs we return values in.
242   switch (getValueType(F.getReturnType())) {
243   default: assert(0 && "Unknown type!");
244   case MVT::isVoid: break;
245   case MVT::i1:
246   case MVT::i8:
247   case MVT::i16:
248   case MVT::i32:
249   case MVT::i64:
250     MF.addLiveOut(Alpha::R0);
251     break;
252   case MVT::f32:
253   case MVT::f64:
254     MF.addLiveOut(Alpha::F0);
255     break;
256   }
257
258   //return the arguments
259   return ArgValues;
260 }
261
262 std::pair<SDOperand, SDOperand>
263 AlphaTargetLowering::LowerCallTo(SDOperand Chain,
264                                  const Type *RetTy, bool isVarArg,
265                                  unsigned CallingConv, bool isTailCall,
266                                  SDOperand Callee, ArgListTy &Args,
267                                  SelectionDAG &DAG) {
268   int NumBytes = 0;
269   if (Args.size() > 6)
270     NumBytes = (Args.size() - 6) * 8;
271
272   Chain = DAG.getNode(ISD::CALLSEQ_START, MVT::Other, Chain,
273                       DAG.getConstant(NumBytes, getPointerTy()));
274   std::vector<SDOperand> args_to_use;
275   for (unsigned i = 0, e = Args.size(); i != e; ++i)
276   {
277     switch (getValueType(Args[i].second)) {
278     default: assert(0 && "Unexpected ValueType for argument!");
279     case MVT::i1:
280     case MVT::i8:
281     case MVT::i16:
282     case MVT::i32:
283       // Promote the integer to 64 bits.  If the input type is signed use a
284       // sign extend, otherwise use a zero extend.
285       if (Args[i].second->isSigned())
286         Args[i].first = DAG.getNode(ISD::SIGN_EXTEND, MVT::i64, Args[i].first);
287       else
288         Args[i].first = DAG.getNode(ISD::ZERO_EXTEND, MVT::i64, Args[i].first);
289       break;
290     case MVT::i64:
291     case MVT::f64:
292     case MVT::f32:
293       break;
294     }
295     args_to_use.push_back(Args[i].first);
296   }
297
298   std::vector<MVT::ValueType> RetVals;
299   MVT::ValueType RetTyVT = getValueType(RetTy);
300   MVT::ValueType ActualRetTyVT = RetTyVT;
301   if (RetTyVT >= MVT::i1 && RetTyVT <= MVT::i32)
302     ActualRetTyVT = MVT::i64;
303
304   if (RetTyVT != MVT::isVoid)
305     RetVals.push_back(ActualRetTyVT);
306   RetVals.push_back(MVT::Other);
307
308   SDOperand TheCall = SDOperand(DAG.getCall(RetVals,
309                                             Chain, Callee, args_to_use), 0);
310   Chain = TheCall.getValue(RetTyVT != MVT::isVoid);
311   Chain = DAG.getNode(ISD::CALLSEQ_END, MVT::Other, Chain,
312                       DAG.getConstant(NumBytes, getPointerTy()));
313   SDOperand RetVal = TheCall;
314
315   if (RetTyVT != ActualRetTyVT) {
316     RetVal = DAG.getNode(RetTy->isSigned() ? ISD::AssertSext : ISD::AssertZext,
317                          MVT::i64, RetVal, DAG.getValueType(RetTyVT));
318     RetVal = DAG.getNode(ISD::TRUNCATE, RetTyVT, RetVal);
319   }
320
321   return std::make_pair(RetVal, Chain);
322 }
323
324 SDOperand AlphaTargetLowering::LowerVAStart(SDOperand Chain, SDOperand VAListP,
325                                             Value *VAListV, SelectionDAG &DAG) {
326   // vastart stores the address of the VarArgsBase and VarArgsOffset
327   SDOperand FR  = DAG.getFrameIndex(VarArgsBase, MVT::i64);
328   SDOperand S1  = DAG.getNode(ISD::STORE, MVT::Other, Chain, FR, VAListP,
329                               DAG.getSrcValue(VAListV));
330   SDOperand SA2 = DAG.getNode(ISD::ADD, MVT::i64, VAListP,
331                               DAG.getConstant(8, MVT::i64));
332   return DAG.getNode(ISD::TRUNCSTORE, MVT::Other, S1,
333                      DAG.getConstant(VarArgsOffset, MVT::i64), SA2,
334                      DAG.getSrcValue(VAListV, 8), DAG.getValueType(MVT::i32));
335 }
336
337 std::pair<SDOperand,SDOperand> AlphaTargetLowering::
338 LowerVAArg(SDOperand Chain, SDOperand VAListP, Value *VAListV,
339            const Type *ArgTy, SelectionDAG &DAG) {
340   SDOperand Base = DAG.getLoad(MVT::i64, Chain, VAListP,
341                                DAG.getSrcValue(VAListV));
342   SDOperand Tmp = DAG.getNode(ISD::ADD, MVT::i64, VAListP,
343                               DAG.getConstant(8, MVT::i64));
344   SDOperand Offset = DAG.getExtLoad(ISD::SEXTLOAD, MVT::i64, Base.getValue(1),
345                                     Tmp, DAG.getSrcValue(VAListV, 8), MVT::i32);
346   SDOperand DataPtr = DAG.getNode(ISD::ADD, MVT::i64, Base, Offset);
347   if (ArgTy->isFloatingPoint())
348   {
349     //if fp && Offset < 6*8, then subtract 6*8 from DataPtr
350       SDOperand FPDataPtr = DAG.getNode(ISD::SUB, MVT::i64, DataPtr,
351                                         DAG.getConstant(8*6, MVT::i64));
352       SDOperand CC = DAG.getSetCC(MVT::i64, Offset,
353                                   DAG.getConstant(8*6, MVT::i64), ISD::SETLT);
354       DataPtr = DAG.getNode(ISD::SELECT, MVT::i64, CC, FPDataPtr, DataPtr);
355   }
356
357   SDOperand Result;
358   if (ArgTy == Type::IntTy)
359     Result = DAG.getExtLoad(ISD::SEXTLOAD, MVT::i64, Offset.getValue(1),
360                             DataPtr, DAG.getSrcValue(NULL), MVT::i32);
361   else if (ArgTy == Type::UIntTy)
362     Result = DAG.getExtLoad(ISD::ZEXTLOAD, MVT::i64, Offset.getValue(1),
363                             DataPtr, DAG.getSrcValue(NULL), MVT::i32);
364   else
365     Result = DAG.getLoad(getValueType(ArgTy), Offset.getValue(1), DataPtr,
366                          DAG.getSrcValue(NULL));
367
368   SDOperand NewOffset = DAG.getNode(ISD::ADD, MVT::i64, Offset,
369                                     DAG.getConstant(8, MVT::i64));
370   SDOperand Update = DAG.getNode(ISD::TRUNCSTORE, MVT::Other,
371                                  Result.getValue(1), NewOffset,
372                                  Tmp, DAG.getSrcValue(VAListV, 8),
373                                  DAG.getValueType(MVT::i32));
374   Result = DAG.getNode(ISD::TRUNCATE, getValueType(ArgTy), Result);
375
376   return std::make_pair(Result, Update);
377 }
378
379
380 SDOperand AlphaTargetLowering::
381 LowerVACopy(SDOperand Chain, SDOperand SrcP, Value *SrcV, SDOperand DestP,
382             Value *DestV, SelectionDAG &DAG) {
383   SDOperand Val = DAG.getLoad(getPointerTy(), Chain, SrcP,
384                               DAG.getSrcValue(SrcV));
385   SDOperand Result = DAG.getNode(ISD::STORE, MVT::Other, Val.getValue(1),
386                                  Val, DestP, DAG.getSrcValue(DestV));
387   SDOperand NP = DAG.getNode(ISD::ADD, MVT::i64, SrcP,
388                              DAG.getConstant(8, MVT::i64));
389   Val = DAG.getExtLoad(ISD::SEXTLOAD, MVT::i64, Result, NP,
390                        DAG.getSrcValue(SrcV, 8), MVT::i32);
391   SDOperand NPD = DAG.getNode(ISD::ADD, MVT::i64, DestP,
392                              DAG.getConstant(8, MVT::i64));
393   return DAG.getNode(ISD::TRUNCSTORE, MVT::Other, Val.getValue(1),
394                      Val, NPD, DAG.getSrcValue(DestV, 8),
395                      DAG.getValueType(MVT::i32));
396 }
397
398 void AlphaTargetLowering::restoreGP(MachineBasicBlock* BB)
399 {
400   BuildMI(BB, Alpha::BIS, 2, Alpha::R29).addReg(GP).addReg(GP);
401 }
402 void AlphaTargetLowering::restoreRA(MachineBasicBlock* BB)
403 {
404   BuildMI(BB, Alpha::BIS, 2, Alpha::R26).addReg(RA).addReg(RA);
405 }
406
407
408 /// LowerOperation - Provide custom lowering hooks for some operations.
409 ///
410 SDOperand AlphaTargetLowering::LowerOperation(SDOperand Op, SelectionDAG &DAG) {
411   switch (Op.getOpcode()) {
412   default: assert(0 && "Wasn't expecting to be able to lower this!"); 
413   case ISD::SINT_TO_FP: {
414     assert(MVT::i64 == Op.getOperand(0).getValueType() && 
415            "Unhandled SINT_TO_FP type in custom expander!");
416     SDOperand LD;
417     bool isDouble = MVT::f64 == Op.getValueType();
418     if (useITOF) {
419       LD = DAG.getNode(AlphaISD::ITOFT_, MVT::f64, Op.getOperand(0));
420     } else {
421       int FrameIdx =
422         DAG.getMachineFunction().getFrameInfo()->CreateStackObject(8, 8);
423       SDOperand FI = DAG.getFrameIndex(FrameIdx, MVT::i64);
424       SDOperand ST = DAG.getNode(ISD::STORE, MVT::Other, DAG.getEntryNode(),
425                                  Op.getOperand(0), FI, DAG.getSrcValue(0));
426       LD = DAG.getLoad(MVT::f64, ST, FI, DAG.getSrcValue(0));
427       }
428     SDOperand FP = DAG.getNode(isDouble?AlphaISD::CVTQT_:AlphaISD::CVTQS_,
429                                isDouble?MVT::f64:MVT::f32, LD);
430     return FP;
431   }
432   case ISD::FP_TO_SINT: {
433     bool isDouble = MVT::f64 == Op.getOperand(0).getValueType();
434     SDOperand src = Op.getOperand(0);
435
436     if (!isDouble) //Promote
437       src = DAG.getNode(ISD::FP_EXTEND, MVT::f64, src);
438     
439     src = DAG.getNode(AlphaISD::CVTTQ_, MVT::f64, src);
440
441     if (useITOF) {
442       return DAG.getNode(AlphaISD::FTOIT_, MVT::i64, src);
443     } else {
444       int FrameIdx =
445         DAG.getMachineFunction().getFrameInfo()->CreateStackObject(8, 8);
446       SDOperand FI = DAG.getFrameIndex(FrameIdx, MVT::i64);
447       SDOperand ST = DAG.getNode(ISD::STORE, MVT::Other, DAG.getEntryNode(),
448                                  src, FI, DAG.getSrcValue(0));
449       return DAG.getLoad(MVT::i64, ST, FI, DAG.getSrcValue(0));
450       }
451   }
452   case ISD::ConstantPool: {
453     Constant *C = cast<ConstantPoolSDNode>(Op)->get();
454     SDOperand CPI = DAG.getTargetConstantPool(C, MVT::i64);
455     
456     SDOperand Hi = DAG.getNode(AlphaISD::GPRelHi,  MVT::i64, CPI,
457                                DAG.getNode(AlphaISD::GlobalBaseReg, MVT::i64));
458     SDOperand Lo = DAG.getNode(AlphaISD::GPRelLo, MVT::i64, CPI, Hi);
459     return Lo;
460   }
461   case ISD::GlobalAddress: {
462     GlobalAddressSDNode *GSDN = cast<GlobalAddressSDNode>(Op);
463     GlobalValue *GV = GSDN->getGlobal();
464     SDOperand GA = DAG.getTargetGlobalAddress(GV, MVT::i64, GSDN->getOffset());
465
466     if (!GV->hasWeakLinkage() && !GV->isExternal()) {
467       SDOperand Hi = DAG.getNode(AlphaISD::GPRelHi,  MVT::i64, GA,
468                                  DAG.getNode(AlphaISD::GlobalBaseReg, MVT::i64));
469       SDOperand Lo = DAG.getNode(AlphaISD::GPRelLo, MVT::i64, GA, Hi);
470       return Lo;
471     } else
472       return DAG.getNode(AlphaISD::RelLit, MVT::i64, GA, DAG.getNode(AlphaISD::GlobalBaseReg, MVT::i64));
473   }
474   case ISD::ExternalSymbol: {
475     return DAG.getNode(AlphaISD::RelLit, MVT::i64, 
476                        DAG.getTargetExternalSymbol(cast<ExternalSymbolSDNode>(Op)->getSymbol(), MVT::i64),
477                        DAG.getNode(AlphaISD::GlobalBaseReg, MVT::i64));
478   }
479
480   case ISD::SDIV:
481   case ISD::UDIV:
482   case ISD::UREM:
483   case ISD::SREM:
484     if (MVT::isInteger(Op.getValueType())) {
485       const char* opstr = 0;
486       switch(Op.getOpcode()) {
487       case ISD::UREM: opstr = "__remqu"; break;
488       case ISD::SREM: opstr = "__remq";  break;
489       case ISD::UDIV: opstr = "__divqu"; break;
490       case ISD::SDIV: opstr = "__divq";  break;
491       }
492       SDOperand Tmp1 = Op.getOperand(0),
493         Tmp2 = Op.getOperand(1),
494         Addr = DAG.getExternalSymbol(opstr, MVT::i64);
495       return DAG.getNode(AlphaISD::DivCall, MVT::i64, Addr, Tmp1, Tmp2);
496     }
497     break;
498
499   }
500
501   return SDOperand();
502 }