For PR950:
[oota-llvm.git] / lib / Target / IA64 / IA64ISelLowering.cpp
index 3693d858908278c3489b5347196df69fc2e95890..6fddb37367569a54496854f4d91f38ac737ca8b7 100644 (file)
@@ -35,7 +35,17 @@ IA64TargetLowering::IA64TargetLowering(TargetMachine &TM)
       // register class for predicate registers
       addRegisterClass(MVT::i1, IA64::PRRegisterClass);
 
-      setOperationAction(ISD::BRIND            , MVT::i64,   Expand);
+      setLoadXAction(ISD::EXTLOAD          , MVT::i1   , Promote);
+
+      setLoadXAction(ISD::ZEXTLOAD         , MVT::i1   , Expand);
+
+      setLoadXAction(ISD::SEXTLOAD         , MVT::i1   , Expand);
+      setLoadXAction(ISD::SEXTLOAD         , MVT::i8   , Expand);
+      setLoadXAction(ISD::SEXTLOAD         , MVT::i16  , Expand);
+      setLoadXAction(ISD::SEXTLOAD         , MVT::i32  , Expand);
+
+      setOperationAction(ISD::BRIND            , MVT::Other, Expand);
+      setOperationAction(ISD::BR_JT            , MVT::Other, Expand);
       setOperationAction(ISD::BR_CC            , MVT::Other, Expand);
       setOperationAction(ISD::FP_ROUND_INREG   , MVT::f32  , Expand);
 
@@ -50,15 +60,6 @@ IA64TargetLowering::IA64TargetLowering(TargetMachine &TM)
       setSetCCResultType(MVT::i1);
       setShiftAmountType(MVT::i64);
 
-      setOperationAction(ISD::EXTLOAD          , MVT::i1   , Promote);
-
-      setOperationAction(ISD::ZEXTLOAD         , MVT::i1   , Expand);
-
-      setOperationAction(ISD::SEXTLOAD         , MVT::i1   , Expand);
-      setOperationAction(ISD::SEXTLOAD         , MVT::i8   , Expand);
-      setOperationAction(ISD::SEXTLOAD         , MVT::i16  , Expand);
-      setOperationAction(ISD::SEXTLOAD         , MVT::i32  , Expand);
-
       setOperationAction(ISD::FREM             , MVT::f32  , Expand);
       setOperationAction(ISD::FREM             , MVT::f64  , Expand);
 
@@ -109,6 +110,9 @@ IA64TargetLowering::IA64TargetLowering(TargetMachine &TM)
 
       setStackPointerRegisterToSaveRestore(IA64::r12);
 
+      setJumpBufSize(704); // on ia64-linux, jmp_bufs are 704 bytes..
+      setJumpBufAlignment(16); // ...and must be 16-byte aligned
+      
       computeRegisterProperties();
 
       setOperationAction(ISD::ConstantFP, MVT::f64, Expand);
@@ -126,19 +130,6 @@ const char *IA64TargetLowering::getTargetNodeName(unsigned Opcode) const {
 }
   
 
-/// isFloatingPointZero - Return true if this is 0.0 or -0.0.
-static bool isFloatingPointZero(SDOperand Op) {
-  if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(Op))
-    return CFP->isExactlyValue(-0.0) || CFP->isExactlyValue(0.0);
-  else if (Op.getOpcode() == ISD::EXTLOAD || Op.getOpcode() == ISD::LOAD) {
-    // Maybe this has already been legalized into the constant pool?
-    if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(Op.getOperand(1)))
-      if (ConstantFP *CFP = dyn_cast<ConstantFP>(CP->get()))
-        return CFP->isExactlyValue(-0.0) || CFP->isExactlyValue(0.0);
-  }
-  return false;
-}
-
 std::vector<SDOperand>
 IA64TargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) {
   std::vector<SDOperand> ArgValues;
@@ -148,6 +139,7 @@ IA64TargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) {
   //
   MachineFunction &MF = DAG.getMachineFunction();
   MachineFrameInfo *MFI = MF.getFrameInfo();
+  const TargetInstrInfo *TII = getTargetMachine().getInstrInfo();
   
   GP = MF.getSSARegMap()->createVirtualRegister(getRegClassFor(MVT::i64));
   SP = MF.getSSARegMap()->createVirtualRegister(getRegClassFor(MVT::i64));
@@ -223,7 +215,7 @@ IA64TargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) {
         //from this parameter
         SDOperand FIN = DAG.getFrameIndex(FI, MVT::i64);
         argt = newroot = DAG.getLoad(getValueType(I->getType()),
-                                     DAG.getEntryNode(), FIN, DAG.getSrcValue(NULL));
+                                     DAG.getEntryNode(), FIN, NULL, 0);
       }
       ++count;
       DAG.setRoot(newroot.getValue(1));
@@ -234,7 +226,7 @@ IA64TargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) {
   // Create a vreg to hold the output of (what will become)
   // the "alloc" instruction
   VirtGPR = MF.getSSARegMap()->createVirtualRegister(getRegClassFor(MVT::i64));
-  BuildMI(&BB, IA64::PSEUDO_ALLOC, 0, VirtGPR);
+  BuildMI(&BB, TII->get(IA64::PSEUDO_ALLOC), VirtGPR);
   // we create a PSEUDO_ALLOC (pseudo)instruction for now
 /*
   BuildMI(&BB, IA64::IDEF, 0, IA64::r1);
@@ -264,14 +256,14 @@ IA64TargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) {
   // here we actually do the moving of args, and store them to the stack
   // too if this is a varargs function:
   for (int i = 0; i < count && i < 8; ++i) {
-    BuildMI(&BB, argOpc[i], 1, argVreg[i]).addReg(argPreg[i]);
+    BuildMI(&BB, TII->get(argOpc[i]), argVreg[i]).addReg(argPreg[i]);
     if(F.isVarArg()) {
       // if this is a varargs function, we copy the input registers to the stack
       int FI = MFI->CreateFixedObject(8, tempOffset);
       tempOffset+=8;   //XXX: is it safe to use r22 like this?
-      BuildMI(&BB, IA64::MOV, 1, IA64::r22).addFrameIndex(FI);
+      BuildMI(&BB, TII->get(IA64::MOV), IA64::r22).addFrameIndex(FI);
       // FIXME: we should use st8.spill here, one day
-      BuildMI(&BB, IA64::ST8, 1, IA64::r22).addReg(argPreg[i]);
+      BuildMI(&BB, TII->get(IA64::ST8), IA64::r22).addReg(argPreg[i]);
     }
   }
 
@@ -298,10 +290,10 @@ IA64TargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) {
 
 std::pair<SDOperand, SDOperand>
 IA64TargetLowering::LowerCallTo(SDOperand Chain,
-                                const Type *RetTy, bool isVarArg,
-                                unsigned CallingConv, bool isTailCall,
-                                SDOperand Callee, ArgListTy &Args,
-                                SelectionDAG &DAG) {
+                                const Type *RetTy, bool RetTyIsSigned, 
+                                bool isVarArg, unsigned CallingConv, 
+                                bool isTailCall, SDOperand Callee, 
+                                ArgListTy &Args, SelectionDAG &DAG) {
 
   MachineFunction &MF = DAG.getMachineFunction();
 
@@ -323,12 +315,13 @@ IA64TargetLowering::LowerCallTo(SDOperand Chain,
     std::max(outRegsUsed, MF.getInfo<IA64FunctionInfo>()->outRegsUsed);
 
   // keep stack frame 16-byte aligned
-  //assert(NumBytes==((NumBytes+15) & ~15) && "stack frame not 16-byte aligned!");
+  // assert(NumBytes==((NumBytes+15) & ~15) && 
+  //        "stack frame not 16-byte aligned!");
   NumBytes = (NumBytes+15) & ~15;
   
   Chain = DAG.getCALLSEQ_START(Chain,DAG.getConstant(NumBytes, getPointerTy()));
 
-  SDOperand StackPtr, NullSV;
+  SDOperand StackPtr;
   std::vector<SDOperand> Stores;
   std::vector<SDOperand> Converts;
   std::vector<SDOperand> RegValuesToPass;
@@ -336,7 +329,7 @@ IA64TargetLowering::LowerCallTo(SDOperand Chain,
   
   for (unsigned i = 0, e = Args.size(); i != e; ++i)
     {
-      SDOperand Val = Args[i].first;
+      SDOperand Val = Args[i].Node;
       MVT::ValueType ObjectVT = Val.getValueType();
       SDOperand ValToStore(0, 0), ValToConvert(0, 0);
       unsigned ObjSize=8;
@@ -345,14 +338,15 @@ IA64TargetLowering::LowerCallTo(SDOperand Chain,
       case MVT::i1:
       case MVT::i8:
       case MVT::i16:
-      case MVT::i32:
+      case MVT::i32: {
         //promote to 64-bits, sign/zero extending based on type
         //of the argument
-        if(Args[i].second->isSigned())
-          Val = DAG.getNode(ISD::SIGN_EXTEND, MVT::i64, Val);
-        else
-          Val = DAG.getNode(ISD::ZERO_EXTEND, MVT::i64, Val);
+        ISD::NodeType ExtendKind = ISD::ZERO_EXTEND;
+        if (Args[i].isSigned)
+          ExtendKind = ISD::SIGN_EXTEND;
+        Val = DAG.getNode(ExtendKind, MVT::i64, Val);
         // XXX: fall through
+      }
       case MVT::i64:
         //ObjSize = 8;
         if(RegValuesToPass.size() >= 8) {
@@ -380,12 +374,10 @@ IA64TargetLowering::LowerCallTo(SDOperand Chain,
       if(ValToStore.Val) {
         if(!StackPtr.Val) {
           StackPtr = DAG.getRegister(IA64::r12, MVT::i64);
-          NullSV = DAG.getSrcValue(NULL);
         }
         SDOperand PtrOff = DAG.getConstant(ArgOffset, getPointerTy());
         PtrOff = DAG.getNode(ISD::ADD, MVT::i64, StackPtr, PtrOff);
-        Stores.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain,
-                                     ValToStore, PtrOff, NullSV));
+        Stores.push_back(DAG.getStore(Chain, ValToStore, PtrOff, NULL, 0));
         ArgOffset += ObjSize;
       }
 
@@ -432,7 +424,8 @@ IA64TargetLowering::LowerCallTo(SDOperand Chain,
   unsigned seenConverts = 0;
   for (unsigned i = 0, e = RegValuesToPass.size(); i != e; ++i) {
     if(MVT::isFloatingPoint(RegValuesToPass[i].getValueType())) {
-      Chain = DAG.getCopyToReg(Chain, IntArgRegs[i], Converts[seenConverts++], InFlag);
+      Chain = DAG.getCopyToReg(Chain, IntArgRegs[i], Converts[seenConverts++], 
+                               InFlag);
       InFlag = Chain.getValue(1);
     }
   }
@@ -442,8 +435,7 @@ IA64TargetLowering::LowerCallTo(SDOperand Chain,
   for (unsigned i = 0, e = RegValuesToPass.size(); i != e; ++i) {
     Chain = DAG.getCopyToReg(Chain,
       MVT::isInteger(RegValuesToPass[i].getValueType()) ?
-                                          IntArgRegs[i] : FPArgRegs[usedFPArgs++],
-      RegValuesToPass[i], InFlag);
+        IntArgRegs[i] : FPArgRegs[usedFPArgs++], RegValuesToPass[i], InFlag);
     InFlag = Chain.getValue(1);
   }
 
@@ -493,7 +485,7 @@ IA64TargetLowering::LowerCallTo(SDOperand Chain,
     case MVT::i1: { // bools are just like other integers (returned in r8)
       // we *could* fall through to the truncate below, but this saves a
       // few redundant predicate ops
-      SDOperand boolInR8 = DAG.getCopyFromReg(Chain, IA64::r8, MVT::i64, InFlag);
+      SDOperand boolInR8 = DAG.getCopyFromReg(Chain, IA64::r8, MVT::i64,InFlag);
       InFlag = boolInR8.getValue(2);
       Chain = boolInR8.getValue(1);
       SDOperand zeroReg = DAG.getCopyFromReg(Chain, IA64::r0, MVT::i64, InFlag);
@@ -581,24 +573,26 @@ LowerOperation(SDOperand Op, SelectionDAG &DAG) {
   }
   case ISD::VAARG: {
     MVT::ValueType VT = getPointerTy();
+    SrcValueSDNode *SV = cast<SrcValueSDNode>(Op.getOperand(2));
     SDOperand VAList = DAG.getLoad(VT, Op.getOperand(0), Op.getOperand(1), 
-                                   Op.getOperand(2));
+                                   SV->getValue(), SV->getOffset());
     // Increment the pointer, VAList, to the next vaarg
     SDOperand VAIncr = DAG.getNode(ISD::ADD, VT, VAList, 
                                    DAG.getConstant(MVT::getSizeInBits(VT)/8, 
                                                    VT));
     // Store the incremented VAList to the legalized pointer
-    VAIncr = DAG.getNode(ISD::STORE, MVT::Other, VAList.getValue(1), VAIncr,
-                         Op.getOperand(1), Op.getOperand(2));
+    VAIncr = DAG.getStore(VAList.getValue(1), VAIncr,
+                          Op.getOperand(1), SV->getValue(), SV->getOffset());
     // Load the actual argument out of the pointer VAList
-    return DAG.getLoad(Op.getValueType(), VAIncr, VAList, DAG.getSrcValue(0));
+    return DAG.getLoad(Op.getValueType(), VAIncr, VAList, NULL, 0);
   }
   case ISD::VASTART: {
     // vastart just stores the address of the VarArgsFrameIndex slot into the
     // memory location argument.
     SDOperand FR = DAG.getFrameIndex(VarArgsFrameIndex, MVT::i64);
-    return DAG.getNode(ISD::STORE, MVT::Other, Op.getOperand(0), FR, 
-                       Op.getOperand(1), Op.getOperand(2));
+    SrcValueSDNode *SV = cast<SrcValueSDNode>(Op.getOperand(2));
+    return DAG.getStore(Op.getOperand(0), FR, 
+                        Op.getOperand(1), SV->getValue(), SV->getOffset());
   }
   }
 }