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