-SDOperand AlphaDAGToDAGISel::Select(SDOperand Op) {
- SDNode *N = Op.Val;
- if (N->getOpcode() >= ISD::BUILTIN_OP_END &&
- N->getOpcode() < AlphaISD::FIRST_NUMBER)
- return Op; // Already selected.
-
- // If this has already been converted, use it.
- std::map<SDOperand, SDOperand>::iterator CGMI = CodeGenMap.find(Op);
- if (CGMI != CodeGenMap.end()) return CGMI->second;
-
- switch (N->getOpcode()) {
- default: break;
- case ISD::TAILCALL:
- case ISD::CALL: return SelectCALL(Op);
-
- case ISD::DYNAMIC_STACKALLOC: {
- if (!isa<ConstantSDNode>(N->getOperand(2)) ||
- cast<ConstantSDNode>(N->getOperand(2))->getValue() != 0) {
- std::cerr << "Cannot allocate stack object with greater alignment than"
- << " the stack alignment yet!";
- abort();
- }
-
- SDOperand Chain = Select(N->getOperand(0));
- SDOperand Amt = Select(N->getOperand(1));
- SDOperand Reg = CurDAG->getRegister(Alpha::R30, MVT::i64);
- SDOperand Val = CurDAG->getCopyFromReg(Chain, Alpha::R30, MVT::i64);
- Chain = Val.getValue(1);
-
- // Subtract the amount (guaranteed to be a multiple of the stack alignment)
- // from the stack pointer, giving us the result pointer.
- SDOperand Result = CurDAG->getTargetNode(Alpha::SUBQ, MVT::i64, Val, Amt);
-
- // Copy this result back into R30.
- Chain = CurDAG->getNode(ISD::CopyToReg, MVT::Other, Chain, Reg, Result);
-
- // Copy this result back out of R30 to make sure we're not using the stack
- // space without decrementing the stack pointer.
- Result = CurDAG->getCopyFromReg(Chain, Alpha::R30, MVT::i64);
-
- // Finally, replace the DYNAMIC_STACKALLOC with the copyfromreg.
- CodeGenMap[Op.getValue(0)] = Result;
- CodeGenMap[Op.getValue(1)] = Result.getValue(1);
- return SDOperand(Result.Val, Op.ResNo);
- }
- case ISD::BRCOND: {
- SDOperand Chain = Select(N->getOperand(0));
- SDOperand CC = Select(N->getOperand(1));
- MachineBasicBlock *Dest =
- cast<BasicBlockSDNode>(N->getOperand(2))->getBasicBlock();
- return CurDAG->SelectNodeTo(N, Alpha::BNE, MVT::Other, CC,
- CurDAG->getBasicBlock(Dest), Chain);
- }
- case ISD::LOAD:
- case ISD::EXTLOAD:
- case ISD::ZEXTLOAD:
- case ISD::SEXTLOAD: {
- SDOperand Chain = Select(N->getOperand(0));
- SDOperand Address = Select(N->getOperand(1));
- unsigned opcode = N->getOpcode();
- unsigned Opc = Alpha::WTF;
- if (opcode == ISD::LOAD)
- switch (N->getValueType(0)) {
- default: N->dump(); assert(0 && "Bad load!");
- case MVT::i64: Opc = Alpha::LDQ; break;
- case MVT::f64: Opc = Alpha::LDT; break;
- case MVT::f32: Opc = Alpha::LDS; break;
- }
- else
- switch (cast<VTSDNode>(N->getOperand(3))->getVT()) {
- default: N->dump(); assert(0 && "Bad sign extend!");
- case MVT::i32: Opc = Alpha::LDL;
- assert(opcode != ISD::ZEXTLOAD && "Not sext"); break;
- case MVT::i16: Opc = Alpha::LDWU;
- assert(opcode != ISD::SEXTLOAD && "Not zext"); break;
- case MVT::i1: //FIXME: Treat i1 as i8 since there are problems otherwise
- case MVT::i8: Opc = Alpha::LDBU;
- assert(opcode != ISD::SEXTLOAD && "Not zext"); break;
- }
-
- return CurDAG->SelectNodeTo(N, Opc, N->getValueType(0), MVT::Other,
- getI64Imm(0), Address,
- Chain).getValue(Op.ResNo);
- }
- case ISD::STORE:
- case ISD::TRUNCSTORE: {
- SDOperand Chain = Select(N->getOperand(0));
- SDOperand Value = Select(N->getOperand(1));
- SDOperand Address = Select(N->getOperand(2));
-
- unsigned Opc = Alpha::WTF;
-
- if (N->getOpcode() == ISD::STORE) {
- switch (N->getOperand(1).getValueType()) {
- case MVT::i64: Opc = Alpha::STQ; break;
- case MVT::f64: Opc = Alpha::STT; break;
- case MVT::f32: Opc = Alpha::STS; break;
- default: assert(0 && "Bad store!");
- };
- } else { //TRUNCSTORE
- switch (cast<VTSDNode>(N->getOperand(4))->getVT()) {
- case MVT::i32: Opc = Alpha::STL; break;
- case MVT::i16: Opc = Alpha::STW; break;
- case MVT::i8: Opc = Alpha::STB; break;
- default: assert(0 && "Bad truncstore!");
- };
- }
- return CurDAG->SelectNodeTo(N, Opc, MVT::Other, Value, getI64Imm(0),
- Address, Chain);