| Andrew Lenharth | aa38ce4 | 2005-09-02 18:46:02 +0000 | [diff] [blame] | 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" | 
| Andrew Lenharth | 167bc6e | 2006-01-23 20:59:50 +0000 | [diff] [blame] | 23 | #include "llvm/Module.h" | 
| Andrew Lenharth | aa38ce4 | 2005-09-02 18:46:02 +0000 | [diff] [blame] | 24 | #include "llvm/Support/CommandLine.h" | 
 | 25 | #include <iostream> | 
 | 26 |  | 
 | 27 | using namespace llvm; | 
 | 28 |  | 
 | 29 | namespace llvm { | 
| Andrew Lenharth | fabd5ba | 2006-01-23 21:56:07 +0000 | [diff] [blame] | 30 |   cl::opt<bool> EnableAlphaLSMark("enable-alpha-lsmark", | 
 | 31 |     cl::desc("Emit symbols to correlate Mem ops to LLVM Values"), | 
 | 32 |     cl::Hidden); | 
| Andrew Lenharth | aa38ce4 | 2005-09-02 18:46:02 +0000 | [diff] [blame] | 33 | } | 
 | 34 |  | 
 | 35 | /// AddLiveIn - This helper function adds the specified physical register to the | 
 | 36 | /// MachineFunction as a live in value.  It also creates a corresponding virtual | 
 | 37 | /// register for it. | 
 | 38 | static unsigned AddLiveIn(MachineFunction &MF, unsigned PReg, | 
 | 39 |                           TargetRegisterClass *RC) { | 
 | 40 |   assert(RC->contains(PReg) && "Not the correct regclass!"); | 
 | 41 |   unsigned VReg = MF.getSSARegMap()->createVirtualRegister(RC); | 
 | 42 |   MF.addLiveIn(PReg, VReg); | 
 | 43 |   return VReg; | 
 | 44 | } | 
 | 45 |  | 
 | 46 | AlphaTargetLowering::AlphaTargetLowering(TargetMachine &TM) : TargetLowering(TM) { | 
 | 47 |   // Set up the TargetLowering object. | 
 | 48 |   //I am having problems with shr n ubyte 1 | 
 | 49 |   setShiftAmountType(MVT::i64); | 
 | 50 |   setSetCCResultType(MVT::i64); | 
 | 51 |   setSetCCResultContents(ZeroOrOneSetCCResult); | 
 | 52 |    | 
 | 53 |   addRegisterClass(MVT::i64, Alpha::GPRCRegisterClass); | 
| Andrew Lenharth | 5cefc5e | 2005-11-09 19:17:08 +0000 | [diff] [blame] | 54 |   addRegisterClass(MVT::f64, Alpha::F8RCRegisterClass); | 
 | 55 |   addRegisterClass(MVT::f32, Alpha::F4RCRegisterClass); | 
| Andrew Lenharth | aa38ce4 | 2005-09-02 18:46:02 +0000 | [diff] [blame] | 56 |    | 
 | 57 |   setOperationAction(ISD::BRCONDTWOWAY, MVT::Other, Expand); | 
 | 58 |   setOperationAction(ISD::BRTWOWAY_CC,  MVT::Other, Expand); | 
 | 59 |    | 
 | 60 |   setOperationAction(ISD::EXTLOAD, MVT::i1,  Promote); | 
 | 61 |   setOperationAction(ISD::EXTLOAD, MVT::f32, Expand); | 
 | 62 |    | 
 | 63 |   setOperationAction(ISD::ZEXTLOAD, MVT::i1,  Promote); | 
 | 64 |   setOperationAction(ISD::ZEXTLOAD, MVT::i32, Expand); | 
 | 65 |    | 
 | 66 |   setOperationAction(ISD::SEXTLOAD, MVT::i1,  Promote); | 
 | 67 |   setOperationAction(ISD::SEXTLOAD, MVT::i8,  Expand); | 
 | 68 |   setOperationAction(ISD::SEXTLOAD, MVT::i16, Expand); | 
 | 69 |    | 
| Andrew Lenharth | f3fb71b | 2005-10-06 16:54:29 +0000 | [diff] [blame] | 70 |   setOperationAction(ISD::TRUNCSTORE, MVT::i1, Promote); | 
 | 71 |  | 
| Andrew Lenharth | 167bc6e | 2006-01-23 20:59:50 +0000 | [diff] [blame] | 72 |   if (EnableAlphaLSMark) { | 
 | 73 |     setOperationAction(ISD::LOAD, MVT::i64, Custom); | 
 | 74 |     setOperationAction(ISD::LOAD, MVT::f64, Custom); | 
 | 75 |     setOperationAction(ISD::LOAD, MVT::f32, Custom); | 
| Andrew Lenharth | 8707605 | 2006-01-23 21:23:26 +0000 | [diff] [blame] | 76 |  | 
 | 77 |     setOperationAction(ISD::ZEXTLOAD, MVT::i8,  Custom); | 
 | 78 |     setOperationAction(ISD::ZEXTLOAD, MVT::i16, Custom); | 
 | 79 |     setOperationAction(ISD::SEXTLOAD, MVT::i32, Custom); | 
 | 80 |  | 
 | 81 |     setOperationAction(ISD::EXTLOAD, MVT::i8,  Custom); | 
 | 82 |     setOperationAction(ISD::EXTLOAD, MVT::i16, Custom); | 
 | 83 |     setOperationAction(ISD::EXTLOAD, MVT::i32, Custom); | 
| Andrew Lenharth | 167bc6e | 2006-01-23 20:59:50 +0000 | [diff] [blame] | 84 |   } | 
 | 85 |  | 
| Chris Lattner | 3e2bafd | 2005-09-28 22:29:17 +0000 | [diff] [blame] | 86 |   setOperationAction(ISD::FREM, MVT::f32, Expand); | 
 | 87 |   setOperationAction(ISD::FREM, MVT::f64, Expand); | 
| Andrew Lenharth | aa38ce4 | 2005-09-02 18:46:02 +0000 | [diff] [blame] | 88 |    | 
 | 89 |   setOperationAction(ISD::UINT_TO_FP, MVT::i64, Expand); | 
| Andrew Lenharth | 7f0db91 | 2005-11-30 07:19:56 +0000 | [diff] [blame] | 90 |   setOperationAction(ISD::SINT_TO_FP, MVT::i64, Custom); | 
| Andrew Lenharth | cd80496 | 2005-11-30 16:10:29 +0000 | [diff] [blame] | 91 |   setOperationAction(ISD::FP_TO_UINT, MVT::i64, Expand); | 
 | 92 |   setOperationAction(ISD::FP_TO_SINT, MVT::i64, Custom); | 
 | 93 |  | 
| Andrew Lenharth | 120ab48 | 2005-09-29 22:54:56 +0000 | [diff] [blame] | 94 |   if (!TM.getSubtarget<AlphaSubtarget>().hasCT()) { | 
| Andrew Lenharth | aa38ce4 | 2005-09-02 18:46:02 +0000 | [diff] [blame] | 95 |     setOperationAction(ISD::CTPOP    , MVT::i64  , Expand); | 
 | 96 |     setOperationAction(ISD::CTTZ     , MVT::i64  , Expand); | 
 | 97 |     setOperationAction(ISD::CTLZ     , MVT::i64  , Expand); | 
 | 98 |   } | 
| Nate Begeman | d88fc03 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 99 |   setOperationAction(ISD::BSWAP    , MVT::i64, Expand); | 
| Nate Begeman | 35ef913 | 2006-01-11 21:21:00 +0000 | [diff] [blame] | 100 |   setOperationAction(ISD::ROTL     , MVT::i64, Expand); | 
 | 101 |   setOperationAction(ISD::ROTR     , MVT::i64, Expand); | 
| Andrew Lenharth | aa38ce4 | 2005-09-02 18:46:02 +0000 | [diff] [blame] | 102 |    | 
| Andrew Lenharth | 53d8970 | 2005-12-25 01:34:27 +0000 | [diff] [blame] | 103 |   setOperationAction(ISD::SREM     , MVT::i64, Custom); | 
 | 104 |   setOperationAction(ISD::UREM     , MVT::i64, Custom); | 
 | 105 |   setOperationAction(ISD::SDIV     , MVT::i64, Custom); | 
 | 106 |   setOperationAction(ISD::UDIV     , MVT::i64, Custom); | 
| Andrew Lenharth | aa38ce4 | 2005-09-02 18:46:02 +0000 | [diff] [blame] | 107 |    | 
 | 108 |   setOperationAction(ISD::MEMMOVE  , MVT::Other, Expand); | 
 | 109 |   setOperationAction(ISD::MEMSET   , MVT::Other, Expand); | 
 | 110 |   setOperationAction(ISD::MEMCPY   , MVT::Other, Expand); | 
 | 111 |    | 
 | 112 |   // We don't support sin/cos/sqrt | 
 | 113 |   setOperationAction(ISD::FSIN , MVT::f64, Expand); | 
 | 114 |   setOperationAction(ISD::FCOS , MVT::f64, Expand); | 
| Andrew Lenharth | aa38ce4 | 2005-09-02 18:46:02 +0000 | [diff] [blame] | 115 |   setOperationAction(ISD::FSIN , MVT::f32, Expand); | 
 | 116 |   setOperationAction(ISD::FCOS , MVT::f32, Expand); | 
| Andrew Lenharth | 3942447 | 2006-01-19 21:10:38 +0000 | [diff] [blame] | 117 |  | 
 | 118 |   setOperationAction(ISD::FSQRT, MVT::f64, Expand); | 
| Andrew Lenharth | aa38ce4 | 2005-09-02 18:46:02 +0000 | [diff] [blame] | 119 |   setOperationAction(ISD::FSQRT, MVT::f32, Expand); | 
 | 120 |  | 
| Andrew Lenharth | b2156f9 | 2005-11-30 17:11:20 +0000 | [diff] [blame] | 121 |   setOperationAction(ISD::SETCC, MVT::f32, Promote); | 
| Chris Lattner | f73bae1 | 2005-11-29 06:16:21 +0000 | [diff] [blame] | 122 |  | 
 | 123 |   // We don't have line number support yet. | 
 | 124 |   setOperationAction(ISD::LOCATION, MVT::Other, Expand); | 
| Jim Laskey | e0bce71 | 2006-01-05 01:47:43 +0000 | [diff] [blame] | 125 |   setOperationAction(ISD::DEBUG_LOC, MVT::Other, Expand); | 
 | 126 |   setOperationAction(ISD::DEBUG_LABEL, MVT::Other, Expand); | 
| Chris Lattner | b99329e | 2006-01-13 02:42:53 +0000 | [diff] [blame] | 127 |  | 
 | 128 |   // Not implemented yet. | 
 | 129 |   setOperationAction(ISD::STACKSAVE, MVT::Other, Expand);  | 
 | 130 |   setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand); | 
| Andrew Lenharth | 739027e | 2006-01-16 21:22:38 +0000 | [diff] [blame] | 131 |   setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i64, Expand); | 
 | 132 |  | 
| Andrew Lenharth | 53d8970 | 2005-12-25 01:34:27 +0000 | [diff] [blame] | 133 |   // We want to legalize GlobalAddress and ConstantPool and | 
 | 134 |   // ExternalSymbols nodes into the appropriate instructions to | 
 | 135 |   // materialize the address. | 
 | 136 |   setOperationAction(ISD::GlobalAddress,  MVT::i64, Custom); | 
 | 137 |   setOperationAction(ISD::ConstantPool,   MVT::i64, Custom); | 
 | 138 |   setOperationAction(ISD::ExternalSymbol, MVT::i64, Custom); | 
| Andrew Lenharth | 4e62951 | 2005-12-24 05:36:33 +0000 | [diff] [blame] | 139 |  | 
| Andrew Lenharth | 739027e | 2006-01-16 21:22:38 +0000 | [diff] [blame] | 140 |   setStackPointerRegisterToSaveRestore(Alpha::R30); | 
 | 141 |  | 
| Andrew Lenharth | aa38ce4 | 2005-09-02 18:46:02 +0000 | [diff] [blame] | 142 |   addLegalFPImmediate(+0.0); //F31 | 
 | 143 |   addLegalFPImmediate(-0.0); //-F31 | 
| Andrew Lenharth | 7f0db91 | 2005-11-30 07:19:56 +0000 | [diff] [blame] | 144 |  | 
 | 145 |   computeRegisterProperties(); | 
 | 146 |  | 
 | 147 |   useITOF = TM.getSubtarget<AlphaSubtarget>().hasF2I(); | 
| Andrew Lenharth | aa38ce4 | 2005-09-02 18:46:02 +0000 | [diff] [blame] | 148 | } | 
 | 149 |  | 
| Andrew Lenharth | 84a0605 | 2006-01-16 19:53:25 +0000 | [diff] [blame] | 150 | const char *AlphaTargetLowering::getTargetNodeName(unsigned Opcode) const { | 
 | 151 |   switch (Opcode) { | 
 | 152 |   default: return 0; | 
 | 153 |   case AlphaISD::ITOFT_: return "Alpha::ITOFT_"; | 
 | 154 |   case AlphaISD::FTOIT_: return "Alpha::FTOIT_"; | 
 | 155 |   case AlphaISD::CVTQT_: return "Alpha::CVTQT_"; | 
 | 156 |   case AlphaISD::CVTQS_: return "Alpha::CVTQS_"; | 
 | 157 |   case AlphaISD::CVTTQ_: return "Alpha::CVTTQ_"; | 
 | 158 |   case AlphaISD::GPRelHi: return "Alpha::GPRelHi"; | 
 | 159 |   case AlphaISD::GPRelLo: return "Alpha::GPRelLo"; | 
 | 160 |   case AlphaISD::RelLit: return "Alpha::RelLit"; | 
 | 161 |   case AlphaISD::GlobalBaseReg: return "Alpha::GlobalBaseReg"; | 
 | 162 |   case AlphaISD::DivCall: return "Alpha::DivCall"; | 
| Andrew Lenharth | 167bc6e | 2006-01-23 20:59:50 +0000 | [diff] [blame] | 163 |   case AlphaISD::LDQ_: return "Alpha::LDQ_"; | 
 | 164 |   case AlphaISD::LDT_: return "Alpha::LDT_"; | 
 | 165 |   case AlphaISD::LDS_: return "Alpha::LDS_"; | 
 | 166 |   case AlphaISD::LDL_: return "Alpha::LDL_"; | 
 | 167 |   case AlphaISD::LDWU_: return "Alpha::LDWU_"; | 
 | 168 |   case AlphaISD::LDBU_:  return "Alpha::LDBU_"; | 
| Andrew Lenharth | 66e4958 | 2006-01-23 21:51:33 +0000 | [diff] [blame] | 169 |   case AlphaISD::STQ_: return "Alpha::STQ_"; | 
 | 170 |   case AlphaISD::STT_: return "Alpha::STT_"; | 
 | 171 |   case AlphaISD::STS_: return "Alpha::STS_"; | 
 | 172 |   case AlphaISD::STL_: return "Alpha::STL_"; | 
 | 173 |   case AlphaISD::STW_: return "Alpha::STW_"; | 
 | 174 |   case AlphaISD::STB_:  return "Alpha::STB_"; | 
| Andrew Lenharth | 84a0605 | 2006-01-16 19:53:25 +0000 | [diff] [blame] | 175 |   } | 
 | 176 | } | 
| Andrew Lenharth | aa38ce4 | 2005-09-02 18:46:02 +0000 | [diff] [blame] | 177 |  | 
 | 178 | //http://www.cs.arizona.edu/computer.help/policy/DIGITAL_unix/AA-PY8AC-TET1_html/callCH3.html#BLOCK21 | 
 | 179 |  | 
 | 180 | //For now, just use variable size stack frame format | 
 | 181 |  | 
 | 182 | //In a standard call, the first six items are passed in registers $16 | 
 | 183 | //- $21 and/or registers $f16 - $f21. (See Section 4.1.2 for details | 
 | 184 | //of argument-to-register correspondence.) The remaining items are | 
 | 185 | //collected in a memory argument list that is a naturally aligned | 
 | 186 | //array of quadwords. In a standard call, this list, if present, must | 
 | 187 | //be passed at 0(SP). | 
 | 188 | //7 ... n         0(SP) ... (n-7)*8(SP) | 
 | 189 |  | 
 | 190 | // //#define FP    $15 | 
 | 191 | // //#define RA    $26 | 
 | 192 | // //#define PV    $27 | 
 | 193 | // //#define GP    $29 | 
 | 194 | // //#define SP    $30 | 
 | 195 |  | 
 | 196 | std::vector<SDOperand> | 
 | 197 | AlphaTargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) | 
 | 198 | { | 
 | 199 |   MachineFunction &MF = DAG.getMachineFunction(); | 
 | 200 |   MachineFrameInfo *MFI = MF.getFrameInfo(); | 
 | 201 |   MachineBasicBlock& BB = MF.front(); | 
 | 202 |   std::vector<SDOperand> ArgValues; | 
 | 203 |  | 
| Andrew Lenharth | f71df33 | 2005-09-04 06:12:19 +0000 | [diff] [blame] | 204 |   unsigned args_int[] = { | 
| Andrew Lenharth | aa38ce4 | 2005-09-02 18:46:02 +0000 | [diff] [blame] | 205 |     Alpha::R16, Alpha::R17, Alpha::R18, Alpha::R19, Alpha::R20, Alpha::R21}; | 
| Andrew Lenharth | f71df33 | 2005-09-04 06:12:19 +0000 | [diff] [blame] | 206 |   unsigned args_float[] = { | 
| Andrew Lenharth | aa38ce4 | 2005-09-02 18:46:02 +0000 | [diff] [blame] | 207 |     Alpha::F16, Alpha::F17, Alpha::F18, Alpha::F19, Alpha::F20, Alpha::F21}; | 
| Andrew Lenharth | aa38ce4 | 2005-09-02 18:46:02 +0000 | [diff] [blame] | 208 |  | 
 | 209 |   int count = 0; | 
 | 210 |  | 
 | 211 |   GP = AddLiveIn(MF, Alpha::R29, getRegClassFor(MVT::i64)); | 
 | 212 |   RA = AddLiveIn(MF, Alpha::R26, getRegClassFor(MVT::i64)); | 
 | 213 |  | 
 | 214 |   for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I) | 
 | 215 |   { | 
 | 216 |     SDOperand argt; | 
 | 217 |     if (count  < 6) { | 
 | 218 |       unsigned Vreg; | 
 | 219 |       MVT::ValueType VT = getValueType(I->getType()); | 
 | 220 |       switch (VT) { | 
 | 221 |       default: | 
 | 222 |         std::cerr << "Unknown Type " << VT << "\n"; | 
 | 223 |         abort(); | 
 | 224 |       case MVT::f64: | 
 | 225 |       case MVT::f32: | 
| Andrew Lenharth | f71df33 | 2005-09-04 06:12:19 +0000 | [diff] [blame] | 226 |         args_float[count] = AddLiveIn(MF, args_float[count], getRegClassFor(VT)); | 
| Andrew Lenharth | aa38ce4 | 2005-09-02 18:46:02 +0000 | [diff] [blame] | 227 |         argt = DAG.getCopyFromReg(DAG.getRoot(), args_float[count], VT); | 
 | 228 |         DAG.setRoot(argt.getValue(1)); | 
 | 229 |         break; | 
 | 230 |       case MVT::i1: | 
 | 231 |       case MVT::i8: | 
 | 232 |       case MVT::i16: | 
 | 233 |       case MVT::i32: | 
 | 234 |       case MVT::i64: | 
| Andrew Lenharth | f71df33 | 2005-09-04 06:12:19 +0000 | [diff] [blame] | 235 |         args_int[count] = AddLiveIn(MF, args_int[count], getRegClassFor(MVT::i64)); | 
| Andrew Lenharth | aa38ce4 | 2005-09-02 18:46:02 +0000 | [diff] [blame] | 236 |         argt = DAG.getCopyFromReg(DAG.getRoot(), args_int[count], MVT::i64); | 
 | 237 |         DAG.setRoot(argt.getValue(1)); | 
 | 238 |         if (VT != MVT::i64) { | 
 | 239 |           unsigned AssertOp =  | 
 | 240 |             I->getType()->isSigned() ? ISD::AssertSext : ISD::AssertZext; | 
 | 241 |           argt = DAG.getNode(AssertOp, MVT::i64, argt,  | 
 | 242 |                              DAG.getValueType(VT)); | 
 | 243 |           argt = DAG.getNode(ISD::TRUNCATE, VT, argt); | 
 | 244 |         } | 
 | 245 |         break; | 
 | 246 |       } | 
 | 247 |     } else { //more args | 
 | 248 |       // Create the frame index object for this incoming parameter... | 
 | 249 |       int FI = MFI->CreateFixedObject(8, 8 * (count - 6)); | 
 | 250 |  | 
 | 251 |       // Create the SelectionDAG nodes corresponding to a load | 
 | 252 |       //from this parameter | 
 | 253 |       SDOperand FIN = DAG.getFrameIndex(FI, MVT::i64); | 
 | 254 |       argt = DAG.getLoad(getValueType(I->getType()), | 
 | 255 |                          DAG.getEntryNode(), FIN, DAG.getSrcValue(NULL)); | 
 | 256 |     } | 
 | 257 |     ++count; | 
 | 258 |     ArgValues.push_back(argt); | 
 | 259 |   } | 
 | 260 |  | 
 | 261 |   // If the functions takes variable number of arguments, copy all regs to stack | 
 | 262 |   if (F.isVarArg()) { | 
 | 263 |     VarArgsOffset = count * 8; | 
 | 264 |     std::vector<SDOperand> LS; | 
 | 265 |     for (int i = 0; i < 6; ++i) { | 
| Chris Lattner | f2cded7 | 2005-09-13 19:03:13 +0000 | [diff] [blame] | 266 |       if (MRegisterInfo::isPhysicalRegister(args_int[i])) | 
| Andrew Lenharth | f71df33 | 2005-09-04 06:12:19 +0000 | [diff] [blame] | 267 |         args_int[i] = AddLiveIn(MF, args_int[i], getRegClassFor(MVT::i64)); | 
| Andrew Lenharth | aa38ce4 | 2005-09-02 18:46:02 +0000 | [diff] [blame] | 268 |       SDOperand argt = DAG.getCopyFromReg(DAG.getRoot(), args_int[i], MVT::i64); | 
 | 269 |       int FI = MFI->CreateFixedObject(8, -8 * (6 - i)); | 
 | 270 |       if (i == 0) VarArgsBase = FI; | 
 | 271 |       SDOperand SDFI = DAG.getFrameIndex(FI, MVT::i64); | 
 | 272 |       LS.push_back(DAG.getNode(ISD::STORE, MVT::Other, DAG.getRoot(), argt, | 
 | 273 |                                SDFI, DAG.getSrcValue(NULL))); | 
 | 274 |  | 
| Chris Lattner | f2cded7 | 2005-09-13 19:03:13 +0000 | [diff] [blame] | 275 |       if (MRegisterInfo::isPhysicalRegister(args_float[i])) | 
| Andrew Lenharth | f71df33 | 2005-09-04 06:12:19 +0000 | [diff] [blame] | 276 |         args_float[i] = AddLiveIn(MF, args_float[i], getRegClassFor(MVT::f64)); | 
| Andrew Lenharth | aa38ce4 | 2005-09-02 18:46:02 +0000 | [diff] [blame] | 277 |       argt = DAG.getCopyFromReg(DAG.getRoot(), args_float[i], MVT::f64); | 
 | 278 |       FI = MFI->CreateFixedObject(8, - 8 * (12 - i)); | 
 | 279 |       SDFI = DAG.getFrameIndex(FI, MVT::i64); | 
 | 280 |       LS.push_back(DAG.getNode(ISD::STORE, MVT::Other, DAG.getRoot(), argt, | 
 | 281 |                                SDFI, DAG.getSrcValue(NULL))); | 
 | 282 |     } | 
 | 283 |  | 
 | 284 |     //Set up a token factor with all the stack traffic | 
 | 285 |     DAG.setRoot(DAG.getNode(ISD::TokenFactor, MVT::Other, LS)); | 
 | 286 |   } | 
 | 287 |  | 
 | 288 |   // Finally, inform the code generator which regs we return values in. | 
 | 289 |   switch (getValueType(F.getReturnType())) { | 
 | 290 |   default: assert(0 && "Unknown type!"); | 
 | 291 |   case MVT::isVoid: break; | 
 | 292 |   case MVT::i1: | 
 | 293 |   case MVT::i8: | 
 | 294 |   case MVT::i16: | 
 | 295 |   case MVT::i32: | 
 | 296 |   case MVT::i64: | 
 | 297 |     MF.addLiveOut(Alpha::R0); | 
 | 298 |     break; | 
 | 299 |   case MVT::f32: | 
 | 300 |   case MVT::f64: | 
 | 301 |     MF.addLiveOut(Alpha::F0); | 
 | 302 |     break; | 
 | 303 |   } | 
 | 304 |  | 
 | 305 |   //return the arguments | 
 | 306 |   return ArgValues; | 
 | 307 | } | 
 | 308 |  | 
 | 309 | std::pair<SDOperand, SDOperand> | 
 | 310 | AlphaTargetLowering::LowerCallTo(SDOperand Chain, | 
 | 311 |                                  const Type *RetTy, bool isVarArg, | 
 | 312 |                                  unsigned CallingConv, bool isTailCall, | 
 | 313 |                                  SDOperand Callee, ArgListTy &Args, | 
 | 314 |                                  SelectionDAG &DAG) { | 
 | 315 |   int NumBytes = 0; | 
 | 316 |   if (Args.size() > 6) | 
 | 317 |     NumBytes = (Args.size() - 6) * 8; | 
 | 318 |  | 
 | 319 |   Chain = DAG.getNode(ISD::CALLSEQ_START, MVT::Other, Chain, | 
 | 320 |                       DAG.getConstant(NumBytes, getPointerTy())); | 
 | 321 |   std::vector<SDOperand> args_to_use; | 
 | 322 |   for (unsigned i = 0, e = Args.size(); i != e; ++i) | 
 | 323 |   { | 
 | 324 |     switch (getValueType(Args[i].second)) { | 
 | 325 |     default: assert(0 && "Unexpected ValueType for argument!"); | 
 | 326 |     case MVT::i1: | 
 | 327 |     case MVT::i8: | 
 | 328 |     case MVT::i16: | 
 | 329 |     case MVT::i32: | 
 | 330 |       // Promote the integer to 64 bits.  If the input type is signed use a | 
 | 331 |       // sign extend, otherwise use a zero extend. | 
 | 332 |       if (Args[i].second->isSigned()) | 
 | 333 |         Args[i].first = DAG.getNode(ISD::SIGN_EXTEND, MVT::i64, Args[i].first); | 
 | 334 |       else | 
 | 335 |         Args[i].first = DAG.getNode(ISD::ZERO_EXTEND, MVT::i64, Args[i].first); | 
 | 336 |       break; | 
 | 337 |     case MVT::i64: | 
 | 338 |     case MVT::f64: | 
 | 339 |     case MVT::f32: | 
 | 340 |       break; | 
 | 341 |     } | 
 | 342 |     args_to_use.push_back(Args[i].first); | 
 | 343 |   } | 
 | 344 |  | 
 | 345 |   std::vector<MVT::ValueType> RetVals; | 
 | 346 |   MVT::ValueType RetTyVT = getValueType(RetTy); | 
| Andrew Lenharth | 46a776e | 2005-09-06 17:00:23 +0000 | [diff] [blame] | 347 |   MVT::ValueType ActualRetTyVT = RetTyVT; | 
 | 348 |   if (RetTyVT >= MVT::i1 && RetTyVT <= MVT::i32) | 
 | 349 |     ActualRetTyVT = MVT::i64; | 
 | 350 |  | 
| Andrew Lenharth | aa38ce4 | 2005-09-02 18:46:02 +0000 | [diff] [blame] | 351 |   if (RetTyVT != MVT::isVoid) | 
| Andrew Lenharth | 46a776e | 2005-09-06 17:00:23 +0000 | [diff] [blame] | 352 |     RetVals.push_back(ActualRetTyVT); | 
| Andrew Lenharth | aa38ce4 | 2005-09-02 18:46:02 +0000 | [diff] [blame] | 353 |   RetVals.push_back(MVT::Other); | 
 | 354 |  | 
 | 355 |   SDOperand TheCall = SDOperand(DAG.getCall(RetVals, | 
 | 356 |                                             Chain, Callee, args_to_use), 0); | 
 | 357 |   Chain = TheCall.getValue(RetTyVT != MVT::isVoid); | 
 | 358 |   Chain = DAG.getNode(ISD::CALLSEQ_END, MVT::Other, Chain, | 
 | 359 |                       DAG.getConstant(NumBytes, getPointerTy())); | 
| Andrew Lenharth | 46a776e | 2005-09-06 17:00:23 +0000 | [diff] [blame] | 360 |   SDOperand RetVal = TheCall; | 
 | 361 |  | 
 | 362 |   if (RetTyVT != ActualRetTyVT) { | 
 | 363 |     RetVal = DAG.getNode(RetTy->isSigned() ? ISD::AssertSext : ISD::AssertZext, | 
 | 364 |                          MVT::i64, RetVal, DAG.getValueType(RetTyVT)); | 
 | 365 |     RetVal = DAG.getNode(ISD::TRUNCATE, RetTyVT, RetVal); | 
 | 366 |   } | 
 | 367 |  | 
 | 368 |   return std::make_pair(RetVal, Chain); | 
| Andrew Lenharth | aa38ce4 | 2005-09-02 18:46:02 +0000 | [diff] [blame] | 369 | } | 
 | 370 |  | 
| Andrew Lenharth | aa38ce4 | 2005-09-02 18:46:02 +0000 | [diff] [blame] | 371 | void AlphaTargetLowering::restoreGP(MachineBasicBlock* BB) | 
 | 372 | { | 
 | 373 |   BuildMI(BB, Alpha::BIS, 2, Alpha::R29).addReg(GP).addReg(GP); | 
 | 374 | } | 
 | 375 | void AlphaTargetLowering::restoreRA(MachineBasicBlock* BB) | 
 | 376 | { | 
 | 377 |   BuildMI(BB, Alpha::BIS, 2, Alpha::R26).addReg(RA).addReg(RA); | 
 | 378 | } | 
 | 379 |  | 
 | 380 |  | 
| Andrew Lenharth | 167bc6e | 2006-01-23 20:59:50 +0000 | [diff] [blame] | 381 |  | 
 | 382 | static void getValueInfo(const Value* v, int& type, int& fun, int& offset) | 
 | 383 | { | 
 | 384 |   fun = type = offset = 0; | 
 | 385 |   if (v == NULL) { | 
 | 386 |     type = 0; | 
 | 387 |   } else if (const GlobalValue* GV = dyn_cast<GlobalValue>(v)) { | 
 | 388 |     type = 1; | 
 | 389 |     const Module* M = GV->getParent(); | 
 | 390 |     for(Module::const_global_iterator ii = M->global_begin(); &*ii != GV; ++ii) | 
 | 391 |       ++offset; | 
 | 392 |   } else if (const Argument* Arg = dyn_cast<Argument>(v)) { | 
 | 393 |     type = 2; | 
 | 394 |     const Function* F = Arg->getParent(); | 
 | 395 |     const Module* M = F->getParent(); | 
 | 396 |     for(Module::const_iterator ii = M->begin(); &*ii != F; ++ii) | 
 | 397 |       ++fun; | 
 | 398 |     for(Function::const_arg_iterator ii = F->arg_begin(); &*ii != Arg; ++ii) | 
 | 399 |       ++offset; | 
 | 400 |   } else if (const Instruction* I = dyn_cast<Instruction>(v)) { | 
 | 401 |     assert(dyn_cast<PointerType>(I->getType())); | 
 | 402 |     type = 3; | 
 | 403 |     const BasicBlock* bb = I->getParent(); | 
 | 404 |     const Function* F = bb->getParent(); | 
 | 405 |     const Module* M = F->getParent(); | 
 | 406 |     for(Module::const_iterator ii = M->begin(); &*ii != F; ++ii) | 
 | 407 |       ++fun; | 
 | 408 |     for(Function::const_iterator ii = F->begin(); &*ii != bb; ++ii) | 
 | 409 |       offset += ii->size(); | 
 | 410 |     for(BasicBlock::const_iterator ii = bb->begin(); &*ii != I; ++ii) | 
 | 411 |       ++offset; | 
 | 412 |   } else if (const Constant* C = dyn_cast<Constant>(v)) { | 
 | 413 |     //Don't know how to look these up yet | 
 | 414 |     type = 0; | 
 | 415 |   } else { | 
 | 416 |     assert(0 && "Error in value marking"); | 
 | 417 |   } | 
 | 418 |   //type = 4: register spilling | 
 | 419 |   //type = 5: global address loading or constant loading | 
 | 420 | } | 
 | 421 |  | 
 | 422 | static int getUID() | 
 | 423 | { | 
 | 424 |   static int id = 0; | 
 | 425 |   return ++id; | 
 | 426 | } | 
 | 427 |  | 
| Andrew Lenharth | 7f0db91 | 2005-11-30 07:19:56 +0000 | [diff] [blame] | 428 | /// LowerOperation - Provide custom lowering hooks for some operations. | 
 | 429 | /// | 
 | 430 | SDOperand AlphaTargetLowering::LowerOperation(SDOperand Op, SelectionDAG &DAG) { | 
 | 431 |   switch (Op.getOpcode()) { | 
 | 432 |   default: assert(0 && "Wasn't expecting to be able to lower this!");  | 
 | 433 |   case ISD::SINT_TO_FP: { | 
 | 434 |     assert(MVT::i64 == Op.getOperand(0).getValueType() &&  | 
 | 435 |            "Unhandled SINT_TO_FP type in custom expander!"); | 
 | 436 |     SDOperand LD; | 
 | 437 |     bool isDouble = MVT::f64 == Op.getValueType(); | 
 | 438 |     if (useITOF) { | 
 | 439 |       LD = DAG.getNode(AlphaISD::ITOFT_, MVT::f64, Op.getOperand(0)); | 
 | 440 |     } else { | 
 | 441 |       int FrameIdx = | 
 | 442 |         DAG.getMachineFunction().getFrameInfo()->CreateStackObject(8, 8); | 
 | 443 |       SDOperand FI = DAG.getFrameIndex(FrameIdx, MVT::i64); | 
 | 444 |       SDOperand ST = DAG.getNode(ISD::STORE, MVT::Other, DAG.getEntryNode(), | 
 | 445 |                                  Op.getOperand(0), FI, DAG.getSrcValue(0)); | 
 | 446 |       LD = DAG.getLoad(MVT::f64, ST, FI, DAG.getSrcValue(0)); | 
 | 447 |       } | 
 | 448 |     SDOperand FP = DAG.getNode(isDouble?AlphaISD::CVTQT_:AlphaISD::CVTQS_, | 
 | 449 |                                isDouble?MVT::f64:MVT::f32, LD); | 
 | 450 |     return FP; | 
 | 451 |   } | 
| Andrew Lenharth | cd80496 | 2005-11-30 16:10:29 +0000 | [diff] [blame] | 452 |   case ISD::FP_TO_SINT: { | 
 | 453 |     bool isDouble = MVT::f64 == Op.getOperand(0).getValueType(); | 
 | 454 |     SDOperand src = Op.getOperand(0); | 
 | 455 |  | 
 | 456 |     if (!isDouble) //Promote | 
 | 457 |       src = DAG.getNode(ISD::FP_EXTEND, MVT::f64, src); | 
 | 458 |      | 
 | 459 |     src = DAG.getNode(AlphaISD::CVTTQ_, MVT::f64, src); | 
 | 460 |  | 
 | 461 |     if (useITOF) { | 
 | 462 |       return DAG.getNode(AlphaISD::FTOIT_, MVT::i64, src); | 
 | 463 |     } else { | 
 | 464 |       int FrameIdx = | 
 | 465 |         DAG.getMachineFunction().getFrameInfo()->CreateStackObject(8, 8); | 
 | 466 |       SDOperand FI = DAG.getFrameIndex(FrameIdx, MVT::i64); | 
 | 467 |       SDOperand ST = DAG.getNode(ISD::STORE, MVT::Other, DAG.getEntryNode(), | 
 | 468 |                                  src, FI, DAG.getSrcValue(0)); | 
 | 469 |       return DAG.getLoad(MVT::i64, ST, FI, DAG.getSrcValue(0)); | 
 | 470 |       } | 
| Andrew Lenharth | 7f0db91 | 2005-11-30 07:19:56 +0000 | [diff] [blame] | 471 |   } | 
| Andrew Lenharth | 4e62951 | 2005-12-24 05:36:33 +0000 | [diff] [blame] | 472 |   case ISD::ConstantPool: { | 
 | 473 |     Constant *C = cast<ConstantPoolSDNode>(Op)->get(); | 
 | 474 |     SDOperand CPI = DAG.getTargetConstantPool(C, MVT::i64); | 
 | 475 |      | 
 | 476 |     SDOperand Hi = DAG.getNode(AlphaISD::GPRelHi,  MVT::i64, CPI, | 
 | 477 | 			       DAG.getNode(AlphaISD::GlobalBaseReg, MVT::i64)); | 
 | 478 |     SDOperand Lo = DAG.getNode(AlphaISD::GPRelLo, MVT::i64, CPI, Hi); | 
 | 479 |     return Lo; | 
 | 480 |   } | 
 | 481 |   case ISD::GlobalAddress: { | 
 | 482 |     GlobalAddressSDNode *GSDN = cast<GlobalAddressSDNode>(Op); | 
 | 483 |     GlobalValue *GV = GSDN->getGlobal(); | 
 | 484 |     SDOperand GA = DAG.getTargetGlobalAddress(GV, MVT::i64, GSDN->getOffset()); | 
 | 485 |  | 
 | 486 |     if (!GV->hasWeakLinkage() && !GV->isExternal()) { | 
 | 487 |       SDOperand Hi = DAG.getNode(AlphaISD::GPRelHi,  MVT::i64, GA, | 
 | 488 | 				 DAG.getNode(AlphaISD::GlobalBaseReg, MVT::i64)); | 
 | 489 |       SDOperand Lo = DAG.getNode(AlphaISD::GPRelLo, MVT::i64, GA, Hi); | 
 | 490 |       return Lo; | 
 | 491 |     } else | 
| Andrew Lenharth | c687b48 | 2005-12-24 08:29:32 +0000 | [diff] [blame] | 492 |       return DAG.getNode(AlphaISD::RelLit, MVT::i64, GA, DAG.getNode(AlphaISD::GlobalBaseReg, MVT::i64)); | 
| Andrew Lenharth | 4e62951 | 2005-12-24 05:36:33 +0000 | [diff] [blame] | 493 |   } | 
| Andrew Lenharth | 53d8970 | 2005-12-25 01:34:27 +0000 | [diff] [blame] | 494 |   case ISD::ExternalSymbol: { | 
 | 495 |     return DAG.getNode(AlphaISD::RelLit, MVT::i64,  | 
 | 496 | 		       DAG.getTargetExternalSymbol(cast<ExternalSymbolSDNode>(Op)->getSymbol(), MVT::i64), | 
 | 497 | 		       DAG.getNode(AlphaISD::GlobalBaseReg, MVT::i64)); | 
 | 498 |   } | 
 | 499 |  | 
 | 500 |   case ISD::SDIV: | 
 | 501 |   case ISD::UDIV: | 
 | 502 |   case ISD::UREM: | 
 | 503 |   case ISD::SREM: | 
 | 504 |     if (MVT::isInteger(Op.getValueType())) { | 
 | 505 |       const char* opstr = 0; | 
 | 506 |       switch(Op.getOpcode()) { | 
 | 507 |       case ISD::UREM: opstr = "__remqu"; break; | 
 | 508 |       case ISD::SREM: opstr = "__remq";  break; | 
 | 509 |       case ISD::UDIV: opstr = "__divqu"; break; | 
 | 510 |       case ISD::SDIV: opstr = "__divq";  break; | 
 | 511 |       } | 
 | 512 |       SDOperand Tmp1 = Op.getOperand(0), | 
 | 513 |         Tmp2 = Op.getOperand(1), | 
 | 514 |         Addr = DAG.getExternalSymbol(opstr, MVT::i64); | 
 | 515 |       return DAG.getNode(AlphaISD::DivCall, MVT::i64, Addr, Tmp1, Tmp2); | 
 | 516 |     } | 
 | 517 |     break; | 
| Andrew Lenharth | cd80496 | 2005-11-30 16:10:29 +0000 | [diff] [blame] | 518 |  | 
| Andrew Lenharth | 167bc6e | 2006-01-23 20:59:50 +0000 | [diff] [blame] | 519 |   case ISD::LOAD: | 
 | 520 |   case ISD::SEXTLOAD: | 
 | 521 |   case ISD::ZEXTLOAD: | 
| Andrew Lenharth | 8707605 | 2006-01-23 21:23:26 +0000 | [diff] [blame] | 522 |   case ISD::EXTLOAD: | 
| Andrew Lenharth | 167bc6e | 2006-01-23 20:59:50 +0000 | [diff] [blame] | 523 |     { | 
 | 524 |       SDOperand Chain   = Op.getOperand(0); | 
 | 525 |       SDOperand Address = Op.getOperand(1); | 
 | 526 |  | 
 | 527 |       unsigned Opc; | 
 | 528 |       unsigned opcode = Op.getOpcode(); | 
 | 529 |  | 
 | 530 |       if (opcode == ISD::LOAD) | 
 | 531 |         switch (Op.Val->getValueType(0)) { | 
 | 532 |         default: Op.Val->dump(); assert(0 && "Bad load!"); | 
 | 533 |         case MVT::i64: Opc = AlphaISD::LDQ_; break; | 
 | 534 |         case MVT::f64: Opc = AlphaISD::LDT_; break; | 
 | 535 |         case MVT::f32: Opc = AlphaISD::LDS_; break; | 
 | 536 |         } | 
 | 537 |       else | 
 | 538 |         switch (cast<VTSDNode>(Op.getOperand(3))->getVT()) { | 
 | 539 |         default: Op.Val->dump(); assert(0 && "Bad sign extend!"); | 
 | 540 |         case MVT::i32: Opc = AlphaISD::LDL_; | 
 | 541 |           assert(opcode != ISD::ZEXTLOAD && "Not sext"); break; | 
 | 542 |         case MVT::i16: Opc = AlphaISD::LDWU_; | 
 | 543 |           assert(opcode != ISD::SEXTLOAD && "Not zext"); break; | 
 | 544 |         case MVT::i1: //FIXME: Treat i1 as i8 since there are problems otherwise | 
 | 545 |         case MVT::i8: Opc = AlphaISD::LDBU_; | 
 | 546 |           assert(opcode != ISD::SEXTLOAD && "Not zext"); break; | 
 | 547 |         } | 
 | 548 |  | 
 | 549 |       int i, j, k; | 
 | 550 |       getValueInfo(dyn_cast<SrcValueSDNode>(Op.getOperand(2))->getValue(), i, j, k); | 
 | 551 |  | 
 | 552 |       SDOperand Zero = DAG.getConstant(0, MVT::i64); | 
 | 553 |       std::vector<MVT::ValueType> VTS; | 
 | 554 |       VTS.push_back(Op.Val->getValueType(0)); | 
 | 555 |       VTS.push_back(MVT::Other); | 
 | 556 |       std::vector<SDOperand> ARGS; | 
| Andrew Lenharth | 8707605 | 2006-01-23 21:23:26 +0000 | [diff] [blame] | 557 |       ARGS.push_back(Chain); | 
| Andrew Lenharth | 167bc6e | 2006-01-23 20:59:50 +0000 | [diff] [blame] | 558 |       ARGS.push_back(Zero); | 
 | 559 |       ARGS.push_back(Address); | 
 | 560 |       ARGS.push_back(DAG.getConstant(i, MVT::i64)); | 
 | 561 |       ARGS.push_back(DAG.getConstant(j, MVT::i64)); | 
 | 562 |       ARGS.push_back(DAG.getConstant(k, MVT::i64)); | 
 | 563 |       ARGS.push_back(DAG.getConstant(getUID(), MVT::i64)); | 
| Andrew Lenharth | 167bc6e | 2006-01-23 20:59:50 +0000 | [diff] [blame] | 564 |       return DAG.getNode(Opc, VTS, ARGS); | 
 | 565 |     } | 
 | 566 |  | 
| Andrew Lenharth | 66e4958 | 2006-01-23 21:51:33 +0000 | [diff] [blame] | 567 |   case ISD::TRUNCSTORE: | 
 | 568 |   case ISD::STORE: | 
 | 569 |     { | 
 | 570 |       SDOperand Chain   = Op.getOperand(0); | 
 | 571 |       SDOperand Value = Op.getOperand(1); | 
 | 572 |       SDOperand Address = Op.getOperand(2); | 
 | 573 |  | 
 | 574 |       unsigned Opc; | 
 | 575 |       unsigned opcode = Op.getOpcode(); | 
 | 576 |  | 
 | 577 |       if (opcode == ISD::STORE) { | 
 | 578 |         switch(Value.getValueType()) { | 
 | 579 |         default: assert(0 && "unknown Type in store"); | 
 | 580 |         case MVT::i64: Opc = AlphaISD::STQ_; break; | 
 | 581 |         case MVT::f64: Opc = AlphaISD::STT_; break; | 
 | 582 |         case MVT::f32: Opc = AlphaISD::STS_; break; | 
 | 583 |         } | 
 | 584 |       } else { //ISD::TRUNCSTORE | 
 | 585 |         switch(cast<VTSDNode>(Op.getOperand(4))->getVT()) { | 
 | 586 |         default: assert(0 && "unknown Type in store"); | 
 | 587 |         case MVT::i8: Opc = AlphaISD::STB_; break; | 
 | 588 |         case MVT::i16: Opc = AlphaISD::STW_; break; | 
 | 589 |         case MVT::i32: Opc = AlphaISD::STL_; break; | 
 | 590 |         } | 
 | 591 |       } | 
 | 592 |  | 
 | 593 |       int i, j, k; | 
 | 594 |       getValueInfo(cast<SrcValueSDNode>(Op.getOperand(3))->getValue(), i, j, k); | 
 | 595 |  | 
 | 596 |       SDOperand Zero = DAG.getConstant(0, MVT::i64); | 
 | 597 |       std::vector<MVT::ValueType> VTS; | 
 | 598 |       VTS.push_back(MVT::Other); | 
 | 599 |       std::vector<SDOperand> ARGS; | 
 | 600 |       ARGS.push_back(Chain); | 
 | 601 |       ARGS.push_back(Value); | 
 | 602 |       ARGS.push_back(Zero); | 
 | 603 |       ARGS.push_back(Address); | 
 | 604 |       ARGS.push_back(DAG.getConstant(i, MVT::i64)); | 
 | 605 |       ARGS.push_back(DAG.getConstant(j, MVT::i64)); | 
 | 606 |       ARGS.push_back(DAG.getConstant(k, MVT::i64)); | 
 | 607 |       ARGS.push_back(DAG.getConstant(getUID(), MVT::i64)); | 
 | 608 |       return DAG.getNode(Opc, VTS, ARGS); | 
 | 609 |     } | 
| Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 610 |   case ISD::VAARG: { | 
 | 611 |     SDOperand Chain = Op.getOperand(0); | 
 | 612 |     SDOperand VAListP = Op.getOperand(1); | 
 | 613 |     SDOperand VAListS = Op.getOperand(2); | 
 | 614 |      | 
 | 615 |     SDOperand Base = DAG.getLoad(MVT::i64, Chain, VAListP, VAListS); | 
 | 616 |     SDOperand Tmp = DAG.getNode(ISD::ADD, MVT::i64, VAListP, | 
 | 617 |                                 DAG.getConstant(8, MVT::i64)); | 
 | 618 |     SDOperand Offset = DAG.getExtLoad(ISD::SEXTLOAD, MVT::i64, Base.getValue(1), | 
 | 619 |                                       Tmp, DAG.getSrcValue(0), MVT::i32); | 
 | 620 |     SDOperand DataPtr = DAG.getNode(ISD::ADD, MVT::i64, Base, Offset); | 
 | 621 |     if (MVT::isFloatingPoint(Op.getValueType())) | 
 | 622 |     { | 
 | 623 |       //if fp && Offset < 6*8, then subtract 6*8 from DataPtr | 
 | 624 |       SDOperand FPDataPtr = DAG.getNode(ISD::SUB, MVT::i64, DataPtr, | 
 | 625 |                                         DAG.getConstant(8*6, MVT::i64)); | 
 | 626 |       SDOperand CC = DAG.getSetCC(MVT::i64, Offset, | 
 | 627 |                                   DAG.getConstant(8*6, MVT::i64), ISD::SETLT); | 
 | 628 |       DataPtr = DAG.getNode(ISD::SELECT, MVT::i64, CC, FPDataPtr, DataPtr); | 
 | 629 |     } | 
| Andrew Lenharth | 66e4958 | 2006-01-23 21:51:33 +0000 | [diff] [blame] | 630 |  | 
| Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 631 |     SDOperand NewOffset = DAG.getNode(ISD::ADD, MVT::i64, Offset, | 
 | 632 |                                       DAG.getConstant(8, MVT::i64)); | 
 | 633 |     SDOperand Update = DAG.getNode(ISD::TRUNCSTORE, MVT::Other, | 
 | 634 |                                    Offset.getValue(1), NewOffset, | 
 | 635 |                                    Tmp, DAG.getSrcValue(0), | 
 | 636 |                                    DAG.getValueType(MVT::i32)); | 
 | 637 |      | 
 | 638 |     SDOperand Result; | 
 | 639 |     if (Op.getValueType() == MVT::i32) | 
 | 640 |       Result = DAG.getExtLoad(ISD::SEXTLOAD, MVT::i64, Update, DataPtr, | 
 | 641 |                               DAG.getSrcValue(0), MVT::i32); | 
 | 642 |     else | 
 | 643 |       Result = DAG.getLoad(Op.getValueType(), Update, DataPtr,  | 
 | 644 |                            DAG.getSrcValue(0)); | 
 | 645 |     return Result; | 
 | 646 |   } | 
 | 647 |   case ISD::VACOPY: { | 
 | 648 |     SDOperand Chain = Op.getOperand(0); | 
 | 649 |     SDOperand DestP = Op.getOperand(1); | 
 | 650 |     SDOperand SrcP = Op.getOperand(2); | 
 | 651 |     SDOperand DestS = Op.getOperand(3); | 
 | 652 |     SDOperand SrcS = Op.getOperand(4); | 
 | 653 |      | 
 | 654 |     SDOperand Val = DAG.getLoad(getPointerTy(), Chain, SrcP, SrcS); | 
 | 655 |     SDOperand Result = DAG.getNode(ISD::STORE, MVT::Other, Val.getValue(1), Val, | 
 | 656 |                                    DestP, DestS); | 
 | 657 |     SDOperand NP = DAG.getNode(ISD::ADD, MVT::i64, SrcP,  | 
 | 658 |                                DAG.getConstant(8, MVT::i64)); | 
 | 659 |     Val = DAG.getExtLoad(ISD::SEXTLOAD, MVT::i64, Result, NP, | 
 | 660 |                          DAG.getSrcValue(0), MVT::i32); | 
 | 661 |     SDOperand NPD = DAG.getNode(ISD::ADD, MVT::i64, DestP, | 
 | 662 |                                 DAG.getConstant(8, MVT::i64)); | 
 | 663 |     return DAG.getNode(ISD::TRUNCSTORE, MVT::Other, Val.getValue(1), | 
 | 664 |                        Val, NPD, DAG.getSrcValue(0),DAG.getValueType(MVT::i32)); | 
 | 665 |   } | 
 | 666 |   case ISD::VASTART: { | 
 | 667 |     SDOperand Chain = Op.getOperand(0); | 
 | 668 |     SDOperand VAListP = Op.getOperand(1); | 
 | 669 |     SDOperand VAListS = Op.getOperand(2); | 
 | 670 |      | 
 | 671 |     // vastart stores the address of the VarArgsBase and VarArgsOffset | 
 | 672 |     SDOperand FR  = DAG.getFrameIndex(VarArgsBase, MVT::i64); | 
 | 673 |     SDOperand S1  = DAG.getNode(ISD::STORE, MVT::Other, Chain, FR, VAListP, | 
 | 674 |                                 VAListS); | 
 | 675 |     SDOperand SA2 = DAG.getNode(ISD::ADD, MVT::i64, VAListP, | 
 | 676 |                                 DAG.getConstant(8, MVT::i64)); | 
 | 677 |     return DAG.getNode(ISD::TRUNCSTORE, MVT::Other, S1, | 
 | 678 |                        DAG.getConstant(VarArgsOffset, MVT::i64), SA2, | 
 | 679 |                        DAG.getSrcValue(0), DAG.getValueType(MVT::i32)); | 
 | 680 |   } | 
| Andrew Lenharth | cd80496 | 2005-11-30 16:10:29 +0000 | [diff] [blame] | 681 |   } | 
 | 682 |  | 
| Andrew Lenharth | 7f0db91 | 2005-11-30 07:19:56 +0000 | [diff] [blame] | 683 |   return SDOperand(); | 
 | 684 | } |