Andrew Lenharth | d97591a | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 1 | //===-- AlphaISelDAGToDAG.cpp - Alpha pattern matching inst selector ------===// |
| 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 defines a pattern matching instruction selector for Alpha, |
| 11 | // converting from a legalized dag to a Alpha dag. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "Alpha.h" |
| 16 | #include "AlphaTargetMachine.h" |
| 17 | #include "AlphaISelLowering.h" |
| 18 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
| 19 | #include "llvm/CodeGen/MachineFunction.h" |
| 20 | #include "llvm/CodeGen/SSARegMap.h" |
| 21 | #include "llvm/CodeGen/SelectionDAG.h" |
| 22 | #include "llvm/CodeGen/SelectionDAGISel.h" |
| 23 | #include "llvm/Target/TargetOptions.h" |
| 24 | #include "llvm/ADT/Statistic.h" |
| 25 | #include "llvm/Constants.h" |
| 26 | #include "llvm/GlobalValue.h" |
| 27 | #include "llvm/Support/Debug.h" |
| 28 | #include "llvm/Support/MathExtras.h" |
Andrew Lenharth | 756fbeb | 2005-10-22 22:06:58 +0000 | [diff] [blame] | 29 | #include <algorithm> |
Andrew Lenharth | d97591a | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 30 | using namespace llvm; |
| 31 | |
| 32 | namespace { |
| 33 | |
| 34 | //===--------------------------------------------------------------------===// |
| 35 | /// AlphaDAGToDAGISel - Alpha specific code to select Alpha machine |
| 36 | /// instructions for SelectionDAG operations. |
| 37 | /// |
| 38 | class AlphaDAGToDAGISel : public SelectionDAGISel { |
| 39 | AlphaTargetLowering AlphaLowering; |
| 40 | |
Andrew Lenharth | 50b3784 | 2005-11-22 04:20:06 +0000 | [diff] [blame^] | 41 | static const int IMM_LOW = -32768; |
| 42 | static const int IMM_HIGH = 32767; |
| 43 | static const int IMM_MULT = 65536; |
| 44 | |
Andrew Lenharth | d97591a | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 45 | public: |
| 46 | AlphaDAGToDAGISel(TargetMachine &TM) |
| 47 | : SelectionDAGISel(AlphaLowering), AlphaLowering(TM) {} |
| 48 | |
| 49 | /// getI64Imm - Return a target constant with the specified value, of type |
| 50 | /// i64. |
Andrew Lenharth | 756fbeb | 2005-10-22 22:06:58 +0000 | [diff] [blame] | 51 | inline SDOperand getI64Imm(int64_t Imm) { |
Andrew Lenharth | d97591a | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 52 | return CurDAG->getTargetConstant(Imm, MVT::i64); |
| 53 | } |
| 54 | |
Andrew Lenharth | d97591a | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 55 | // Select - Convert the specified operand from a target-independent to a |
| 56 | // target-specific node if it hasn't already been changed. |
| 57 | SDOperand Select(SDOperand Op); |
| 58 | |
| 59 | /// InstructionSelectBasicBlock - This callback is invoked by |
| 60 | /// SelectionDAGISel when it has created a SelectionDAG for us to codegen. |
| 61 | virtual void InstructionSelectBasicBlock(SelectionDAG &DAG); |
| 62 | |
| 63 | virtual const char *getPassName() const { |
| 64 | return "Alpha DAG->DAG Pattern Instruction Selection"; |
| 65 | } |
| 66 | |
| 67 | // Include the pieces autogenerated from the target description. |
| 68 | #include "AlphaGenDAGISel.inc" |
| 69 | |
| 70 | private: |
Andrew Lenharth | 756fbeb | 2005-10-22 22:06:58 +0000 | [diff] [blame] | 71 | SDOperand getGlobalBaseReg(); |
| 72 | SDOperand SelectCALL(SDOperand Op); |
| 73 | |
Andrew Lenharth | d97591a | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 74 | }; |
| 75 | } |
| 76 | |
Andrew Lenharth | 756fbeb | 2005-10-22 22:06:58 +0000 | [diff] [blame] | 77 | /// getGlobalBaseReg - Output the instructions required to put the |
| 78 | /// GOT address into a register. |
| 79 | /// |
| 80 | SDOperand AlphaDAGToDAGISel::getGlobalBaseReg() { |
| 81 | return CurDAG->getRegister(AlphaLowering.getVRegGP(), MVT::i64); |
| 82 | } |
| 83 | |
Andrew Lenharth | d97591a | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 84 | /// InstructionSelectBasicBlock - This callback is invoked by |
| 85 | /// SelectionDAGISel when it has created a SelectionDAG for us to codegen. |
| 86 | void AlphaDAGToDAGISel::InstructionSelectBasicBlock(SelectionDAG &DAG) { |
| 87 | DEBUG(BB->dump()); |
| 88 | |
Andrew Lenharth | d97591a | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 89 | // Select target instructions for the DAG. |
| 90 | DAG.setRoot(Select(DAG.getRoot())); |
| 91 | CodeGenMap.clear(); |
| 92 | DAG.RemoveDeadNodes(); |
| 93 | |
| 94 | // Emit machine code to BB. |
| 95 | ScheduleAndEmitDAG(DAG); |
| 96 | } |
| 97 | |
| 98 | // Select - Convert the specified operand from a target-independent to a |
| 99 | // target-specific node if it hasn't already been changed. |
| 100 | SDOperand AlphaDAGToDAGISel::Select(SDOperand Op) { |
| 101 | SDNode *N = Op.Val; |
| 102 | if (N->getOpcode() >= ISD::BUILTIN_OP_END && |
| 103 | N->getOpcode() < AlphaISD::FIRST_NUMBER) |
| 104 | return Op; // Already selected. |
| 105 | |
| 106 | // If this has already been converted, use it. |
| 107 | std::map<SDOperand, SDOperand>::iterator CGMI = CodeGenMap.find(Op); |
| 108 | if (CGMI != CodeGenMap.end()) return CGMI->second; |
| 109 | |
| 110 | switch (N->getOpcode()) { |
| 111 | default: break; |
Andrew Lenharth | 756fbeb | 2005-10-22 22:06:58 +0000 | [diff] [blame] | 112 | case ISD::TAILCALL: |
| 113 | case ISD::CALL: return SelectCALL(Op); |
| 114 | |
Andrew Lenharth | 50b3784 | 2005-11-22 04:20:06 +0000 | [diff] [blame^] | 115 | case ISD::DYNAMIC_STACKALLOC: { |
| 116 | if (!isa<ConstantSDNode>(N->getOperand(2)) || |
| 117 | cast<ConstantSDNode>(N->getOperand(2))->getValue() != 0) { |
| 118 | std::cerr << "Cannot allocate stack object with greater alignment than" |
| 119 | << " the stack alignment yet!"; |
| 120 | abort(); |
| 121 | } |
Andrew Lenharth | d97591a | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 122 | |
Andrew Lenharth | 50b3784 | 2005-11-22 04:20:06 +0000 | [diff] [blame^] | 123 | SDOperand Chain = Select(N->getOperand(0)); |
| 124 | SDOperand Amt = Select(N->getOperand(1)); |
| 125 | SDOperand Reg = CurDAG->getRegister(Alpha::R30, MVT::i64); |
| 126 | SDOperand Val = CurDAG->getCopyFromReg(Chain, Alpha::R30, MVT::i64); |
| 127 | Chain = Val.getValue(1); |
| 128 | |
| 129 | // Subtract the amount (guaranteed to be a multiple of the stack alignment) |
| 130 | // from the stack pointer, giving us the result pointer. |
| 131 | SDOperand Result = CurDAG->getTargetNode(Alpha::SUBQ, MVT::i64, Val, Amt); |
| 132 | |
| 133 | // Copy this result back into R30. |
| 134 | Chain = CurDAG->getNode(ISD::CopyToReg, MVT::Other, Chain, Reg, Result); |
| 135 | |
| 136 | // Copy this result back out of R30 to make sure we're not using the stack |
| 137 | // space without decrementing the stack pointer. |
| 138 | Result = CurDAG->getCopyFromReg(Chain, Alpha::R30, MVT::i64); |
| 139 | |
| 140 | // Finally, replace the DYNAMIC_STACKALLOC with the copyfromreg. |
| 141 | CodeGenMap[Op.getValue(0)] = Result; |
| 142 | CodeGenMap[Op.getValue(1)] = Result.getValue(1); |
| 143 | return SDOperand(Result.Val, Op.ResNo); |
| 144 | } |
Andrew Lenharth | 8b7f14e | 2005-10-23 03:43:48 +0000 | [diff] [blame] | 145 | case ISD::BRCOND: { |
| 146 | SDOperand Chain = Select(N->getOperand(0)); |
| 147 | SDOperand CC = Select(N->getOperand(1)); |
Andrew Lenharth | 50b3784 | 2005-11-22 04:20:06 +0000 | [diff] [blame^] | 148 | MachineBasicBlock *Dest = |
| 149 | cast<BasicBlockSDNode>(N->getOperand(2))->getBasicBlock(); |
| 150 | CurDAG->SelectNodeTo(N, Alpha::BNE, MVT::Other, CC, CurDAG->getBasicBlock(Dest), Chain); |
Andrew Lenharth | 8b7f14e | 2005-10-23 03:43:48 +0000 | [diff] [blame] | 151 | return SDOperand(N, 0); |
| 152 | } |
| 153 | case ISD::LOAD: |
| 154 | case ISD::EXTLOAD: |
| 155 | case ISD::ZEXTLOAD: |
| 156 | case ISD::SEXTLOAD: { |
| 157 | SDOperand Chain = Select(N->getOperand(0)); |
| 158 | SDOperand Address = Select(N->getOperand(1)); |
| 159 | unsigned opcode = N->getOpcode(); |
| 160 | unsigned Opc = Alpha::WTF; |
| 161 | if (opcode == ISD::LOAD) |
| 162 | switch (N->getValueType(0)) { |
| 163 | default: N->dump(); assert(0 && "Bad load!"); |
| 164 | case MVT::i64: Opc = Alpha::LDQ; break; |
| 165 | case MVT::f64: Opc = Alpha::LDT; break; |
| 166 | case MVT::f32: Opc = Alpha::LDS; break; |
| 167 | } |
| 168 | else |
| 169 | switch (cast<VTSDNode>(N->getOperand(3))->getVT()) { |
| 170 | default: N->dump(); assert(0 && "Bad sign extend!"); |
| 171 | case MVT::i32: Opc = Alpha::LDL; |
| 172 | assert(opcode != ISD::ZEXTLOAD && "Not sext"); break; |
| 173 | case MVT::i16: Opc = Alpha::LDWU; |
| 174 | assert(opcode != ISD::SEXTLOAD && "Not zext"); break; |
| 175 | case MVT::i1: //FIXME: Treat i1 as i8 since there are problems otherwise |
| 176 | case MVT::i8: Opc = Alpha::LDBU; |
| 177 | assert(opcode != ISD::SEXTLOAD && "Not zext"); break; |
| 178 | } |
| 179 | |
| 180 | CurDAG->SelectNodeTo(N, Opc, N->getValueType(0), MVT::Other, |
| 181 | getI64Imm(0), Address, Chain); |
| 182 | return SDOperand(N, Op.ResNo); |
| 183 | } |
Andrew Lenharth | 50b3784 | 2005-11-22 04:20:06 +0000 | [diff] [blame^] | 184 | case ISD::STORE: |
| 185 | case ISD::TRUNCSTORE: { |
| 186 | SDOperand Chain = Select(N->getOperand(0)); |
| 187 | SDOperand Value = Select(N->getOperand(1)); |
| 188 | SDOperand Address = Select(N->getOperand(2)); |
| 189 | |
| 190 | unsigned Opc = Alpha::WTF; |
| 191 | |
| 192 | if (N->getOpcode() == ISD::STORE) { |
| 193 | switch (N->getOperand(1).getValueType()) { |
| 194 | case MVT::i64: Opc = Alpha::STQ; break; |
| 195 | case MVT::f64: Opc = Alpha::STT; break; |
| 196 | case MVT::f32: Opc = Alpha::STS; break; |
| 197 | default: assert(0 && "Bad store!"); |
| 198 | }; |
| 199 | } else { //TRUNCSTORE |
| 200 | switch (cast<VTSDNode>(N->getOperand(4))->getVT()) { |
| 201 | case MVT::i32: Opc = Alpha::STL; break; |
| 202 | case MVT::i16: Opc = Alpha::STW; break; |
| 203 | case MVT::i8: Opc = Alpha::STB; break; |
| 204 | default: assert(0 && "Bad truncstore!"); |
| 205 | }; |
| 206 | } |
| 207 | CurDAG->SelectNodeTo(N, Opc, MVT::Other, Value, getI64Imm(0), Address, |
| 208 | Chain); |
| 209 | return SDOperand(N, 0); |
| 210 | } |
Andrew Lenharth | 8b7f14e | 2005-10-23 03:43:48 +0000 | [diff] [blame] | 211 | |
Andrew Lenharth | 756fbeb | 2005-10-22 22:06:58 +0000 | [diff] [blame] | 212 | case ISD::BR: { |
| 213 | CurDAG->SelectNodeTo(N, Alpha::BR_DAG, MVT::Other, N->getOperand(1), |
| 214 | Select(N->getOperand(0))); |
| 215 | return SDOperand(N, 0); |
| 216 | } |
| 217 | |
Andrew Lenharth | d97591a | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 218 | case ISD::FrameIndex: { |
Andrew Lenharth | 50b3784 | 2005-11-22 04:20:06 +0000 | [diff] [blame^] | 219 | int FI = cast<FrameIndexSDNode>(N)->getIndex(); |
| 220 | CurDAG->SelectNodeTo(N, Alpha::LDA, MVT::i64, |
| 221 | CurDAG->getTargetFrameIndex(FI, MVT::i32), |
| 222 | getI64Imm(0)); |
| 223 | return SDOperand(N, 0); |
Andrew Lenharth | d97591a | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 224 | } |
| 225 | case ISD::ConstantPool: { |
Andrew Lenharth | 50b3784 | 2005-11-22 04:20:06 +0000 | [diff] [blame^] | 226 | Constant *C = cast<ConstantPoolSDNode>(N)->get(); |
| 227 | SDOperand Tmp, CPI = CurDAG->getTargetConstantPool(C, MVT::i64); |
| 228 | Tmp = CurDAG->getTargetNode(Alpha::LDAHr, MVT::i64, CPI, getGlobalBaseReg()); |
| 229 | CurDAG->SelectNodeTo(N, Alpha::LDAr, MVT::i64, CPI, Tmp); |
| 230 | return SDOperand(N, 0); |
Andrew Lenharth | d97591a | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 231 | } |
| 232 | case ISD::GlobalAddress: { |
Andrew Lenharth | 756fbeb | 2005-10-22 22:06:58 +0000 | [diff] [blame] | 233 | GlobalValue *GV = cast<GlobalAddressSDNode>(N)->getGlobal(); |
| 234 | SDOperand GA = CurDAG->getTargetGlobalAddress(GV, MVT::i64); |
| 235 | CurDAG->SelectNodeTo(N, Alpha::LDQl, MVT::i64, GA, getGlobalBaseReg()); |
| 236 | return SDOperand(N, 0); |
Andrew Lenharth | d97591a | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 237 | } |
Andrew Lenharth | 8b7f14e | 2005-10-23 03:43:48 +0000 | [diff] [blame] | 238 | case ISD::ExternalSymbol: |
| 239 | CurDAG->SelectNodeTo(N, Alpha::LDQl, MVT::i64, |
| 240 | CurDAG->getTargetExternalSymbol(cast<ExternalSymbolSDNode>(N)->getSymbol(), MVT::i64), |
| 241 | CurDAG->getRegister(AlphaLowering.getVRegGP(), MVT::i64)); |
| 242 | return SDOperand(N, 0); |
Andrew Lenharth | d97591a | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 243 | |
| 244 | case ISD::CALLSEQ_START: |
| 245 | case ISD::CALLSEQ_END: { |
| 246 | unsigned Amt = cast<ConstantSDNode>(N->getOperand(1))->getValue(); |
| 247 | unsigned Opc = N->getOpcode() == ISD::CALLSEQ_START ? |
| 248 | Alpha::ADJUSTSTACKDOWN : Alpha::ADJUSTSTACKUP; |
| 249 | CurDAG->SelectNodeTo(N, Opc, MVT::Other, |
| 250 | getI64Imm(Amt), Select(N->getOperand(0))); |
| 251 | return SDOperand(N, 0); |
| 252 | } |
| 253 | case ISD::RET: { |
| 254 | SDOperand Chain = Select(N->getOperand(0)); // Token chain. |
| 255 | |
| 256 | if (N->getNumOperands() == 2) { |
| 257 | SDOperand Val = Select(N->getOperand(1)); |
| 258 | if (N->getOperand(1).getValueType() == MVT::i64) { |
| 259 | Chain = CurDAG->getCopyToReg(Chain, Alpha::R0, Val); |
| 260 | } |
| 261 | } |
| 262 | //BuildMI(BB, Alpha::RET, 2, Alpha::R31).addReg(Alpha::R26).addImm(1); |
| 263 | |
| 264 | // FIXME: add restoring of the RA to R26 to the chain |
| 265 | // Finally, select this to a ret instruction. |
| 266 | CurDAG->SelectNodeTo(N, Alpha::RETDAG, MVT::Other, Chain); |
| 267 | return SDOperand(N, 0); |
| 268 | } |
Andrew Lenharth | 50b3784 | 2005-11-22 04:20:06 +0000 | [diff] [blame^] | 269 | case ISD::Constant: { |
| 270 | int64_t val = (int64_t)cast<ConstantSDNode>(N)->getValue(); |
| 271 | if (val > (int64_t)IMM_HIGH +(int64_t)IMM_HIGH* (int64_t)IMM_MULT || |
| 272 | val < (int64_t)IMM_LOW + (int64_t)IMM_LOW * (int64_t)IMM_MULT) { |
| 273 | MachineConstantPool *CP = BB->getParent()->getConstantPool(); |
| 274 | ConstantUInt *C = |
| 275 | ConstantUInt::get(Type::getPrimitiveType(Type::ULongTyID) , val); |
| 276 | SDOperand Tmp, CPI = CurDAG->getTargetConstantPool(C, MVT::i64); |
| 277 | Tmp = CurDAG->getTargetNode(Alpha::LDAHr, MVT::i64, CPI, getGlobalBaseReg()); |
| 278 | CurDAG->SelectNodeTo(N, Alpha::LDAr, MVT::i64, CPI, Tmp); |
| 279 | return SDOperand(N, 0); |
| 280 | } |
| 281 | } |
| 282 | case ISD::ConstantFP: |
| 283 | if (ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(N)) { |
| 284 | bool isDouble = N->getValueType(0) == MVT::f64; |
| 285 | MVT::ValueType T = isDouble ? MVT::f64 : MVT::f32; |
| 286 | if (CN->isExactlyValue(+0.0)) { |
| 287 | CurDAG->SelectNodeTo(N, isDouble ? Alpha::CPYST : Alpha::CPYSS, T, |
| 288 | CurDAG->getRegister(Alpha::F31, T), |
| 289 | CurDAG->getRegister(Alpha::F31, T)); |
| 290 | return SDOperand(N, 0); |
| 291 | } else if ( CN->isExactlyValue(-0.0)) { |
| 292 | CurDAG->SelectNodeTo(N, isDouble ? Alpha::CPYSNT : Alpha::CPYSNS, T, |
| 293 | CurDAG->getRegister(Alpha::F31, T), |
| 294 | CurDAG->getRegister(Alpha::F31, T)); |
| 295 | return SDOperand(N, 0); |
| 296 | } else { |
| 297 | abort(); |
| 298 | } |
| 299 | } |
Andrew Lenharth | d97591a | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | return SelectCode(Op); |
| 303 | } |
| 304 | |
Andrew Lenharth | 756fbeb | 2005-10-22 22:06:58 +0000 | [diff] [blame] | 305 | SDOperand AlphaDAGToDAGISel::SelectCALL(SDOperand Op) { |
Andrew Lenharth | 50b3784 | 2005-11-22 04:20:06 +0000 | [diff] [blame^] | 306 | //TODO: add flag stuff to prevent nondeturministic breakage! |
| 307 | |
Andrew Lenharth | 756fbeb | 2005-10-22 22:06:58 +0000 | [diff] [blame] | 308 | SDNode *N = Op.Val; |
| 309 | SDOperand Chain = Select(N->getOperand(0)); |
Andrew Lenharth | 756fbeb | 2005-10-22 22:06:58 +0000 | [diff] [blame] | 310 | SDOperand Addr = Select(N->getOperand(1)); |
| 311 | |
| 312 | // unsigned CallOpcode; |
| 313 | std::vector<SDOperand> CallOperands; |
| 314 | std::vector<MVT::ValueType> TypeOperands; |
| 315 | |
Andrew Lenharth | 756fbeb | 2005-10-22 22:06:58 +0000 | [diff] [blame] | 316 | //grab the arguments |
| 317 | for(int i = 2, e = N->getNumOperands(); i < e; ++i) { |
Andrew Lenharth | 756fbeb | 2005-10-22 22:06:58 +0000 | [diff] [blame] | 318 | TypeOperands.push_back(N->getOperand(i).getValueType()); |
Andrew Lenharth | 8b7f14e | 2005-10-23 03:43:48 +0000 | [diff] [blame] | 319 | CallOperands.push_back(Select(N->getOperand(i))); |
Andrew Lenharth | 756fbeb | 2005-10-22 22:06:58 +0000 | [diff] [blame] | 320 | } |
Andrew Lenharth | 8b7f14e | 2005-10-23 03:43:48 +0000 | [diff] [blame] | 321 | int count = N->getNumOperands() - 2; |
| 322 | |
Andrew Lenharth | 756fbeb | 2005-10-22 22:06:58 +0000 | [diff] [blame] | 323 | static const unsigned args_int[] = {Alpha::R16, Alpha::R17, Alpha::R18, |
| 324 | Alpha::R19, Alpha::R20, Alpha::R21}; |
| 325 | static const unsigned args_float[] = {Alpha::F16, Alpha::F17, Alpha::F18, |
| 326 | Alpha::F19, Alpha::F20, Alpha::F21}; |
| 327 | |
Andrew Lenharth | 8b7f14e | 2005-10-23 03:43:48 +0000 | [diff] [blame] | 328 | for (int i = 0; i < std::min(6, count); ++i) { |
Andrew Lenharth | 756fbeb | 2005-10-22 22:06:58 +0000 | [diff] [blame] | 329 | if (MVT::isInteger(TypeOperands[i])) { |
Andrew Lenharth | 8b7f14e | 2005-10-23 03:43:48 +0000 | [diff] [blame] | 330 | Chain = CurDAG->getCopyToReg(Chain, args_int[i], CallOperands[i]); |
Andrew Lenharth | 50b3784 | 2005-11-22 04:20:06 +0000 | [diff] [blame^] | 331 | } else if (TypeOperands[i] == MVT::f64 || TypeOperands[i] == MVT::f64) { |
| 332 | Chain = CurDAG->getCopyToReg(Chain, args_float[i], CallOperands[i]); |
| 333 | } else |
| 334 | assert(0 && "Unknown operand"); |
Andrew Lenharth | 756fbeb | 2005-10-22 22:06:58 +0000 | [diff] [blame] | 335 | } |
Andrew Lenharth | 50b3784 | 2005-11-22 04:20:06 +0000 | [diff] [blame^] | 336 | |
Andrew Lenharth | 756fbeb | 2005-10-22 22:06:58 +0000 | [diff] [blame] | 337 | assert(CallOperands.size() <= 6 && "Too big a call"); |
| 338 | |
Andrew Lenharth | 8b7f14e | 2005-10-23 03:43:48 +0000 | [diff] [blame] | 339 | Chain = CurDAG->getCopyToReg(Chain, Alpha::R27, Addr); |
Andrew Lenharth | 756fbeb | 2005-10-22 22:06:58 +0000 | [diff] [blame] | 340 | // Finally, once everything is in registers to pass to the call, emit the |
| 341 | // call itself. |
Andrew Lenharth | 8b7f14e | 2005-10-23 03:43:48 +0000 | [diff] [blame] | 342 | Chain = CurDAG->getTargetNode(Alpha::JSRDAG, MVT::Other, Chain ); |
Andrew Lenharth | 756fbeb | 2005-10-22 22:06:58 +0000 | [diff] [blame] | 343 | |
| 344 | std::vector<SDOperand> CallResults; |
| 345 | |
| 346 | switch (N->getValueType(0)) { |
| 347 | default: assert(0 && "Unexpected ret value!"); |
| 348 | case MVT::Other: break; |
| 349 | case MVT::i64: |
Andrew Lenharth | 8b7f14e | 2005-10-23 03:43:48 +0000 | [diff] [blame] | 350 | Chain = CurDAG->getCopyFromReg(Chain, Alpha::R0, MVT::i64).getValue(1); |
Andrew Lenharth | 756fbeb | 2005-10-22 22:06:58 +0000 | [diff] [blame] | 351 | CallResults.push_back(Chain.getValue(0)); |
| 352 | break; |
Andrew Lenharth | 50b3784 | 2005-11-22 04:20:06 +0000 | [diff] [blame^] | 353 | case MVT::f32: |
| 354 | Chain = CurDAG->getCopyFromReg(Chain, Alpha::F0, MVT::f32).getValue(1); |
| 355 | CallResults.push_back(Chain.getValue(0)); |
| 356 | break; |
| 357 | case MVT::f64: |
| 358 | Chain = CurDAG->getCopyFromReg(Chain, Alpha::F0, MVT::f64).getValue(1); |
| 359 | CallResults.push_back(Chain.getValue(0)); |
| 360 | break; |
Andrew Lenharth | 756fbeb | 2005-10-22 22:06:58 +0000 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | CallResults.push_back(Chain); |
| 364 | for (unsigned i = 0, e = CallResults.size(); i != e; ++i) |
| 365 | CodeGenMap[Op.getValue(i)] = CallResults[i]; |
| 366 | return CallResults[Op.ResNo]; |
| 367 | } |
| 368 | |
| 369 | |
Andrew Lenharth | d97591a | 2005-10-20 00:29:02 +0000 | [diff] [blame] | 370 | /// createAlphaISelDag - This pass converts a legalized DAG into a |
| 371 | /// Alpha-specific DAG, ready for instruction scheduling. |
| 372 | /// |
| 373 | FunctionPass *llvm::createAlphaISelDag(TargetMachine &TM) { |
| 374 | return new AlphaDAGToDAGISel(TM); |
| 375 | } |