From b77ba73a29f25807caf07fbad8b423b5a38a88bd Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 16 May 2006 23:39:44 +0000 Subject: [PATCH] Add support for calls that pass and return legal vectors. llvm-svn: 28340 --- .../CodeGen/SelectionDAG/SelectionDAGISel.cpp | 63 ++++++++++++++++++- 1 file changed, 60 insertions(+), 3 deletions(-) diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp index 105eb9ba1261..bddaa904aa4f 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp @@ -2470,6 +2470,7 @@ TargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) { Ops.push_back(N); } else { assert(0 && "Don't support illegal by-val vector arguments yet!"); + abort(); } } break; @@ -2537,7 +2538,26 @@ TargetLowering::LowerCallTo(SDOperand Chain, const Type *RetTy, bool isVarArg, assert(0 && "Cannot expand i64 -> i16 yet!"); } } else { - assert(0 && "Doesn't handle vectors yet!"); + // Otherwise, this is a vector type. We only support legal vectors + // right now. + const PackedType *PTy = cast(Args[i].second); + unsigned NumElems = PTy->getNumElements(); + const Type *EltTy = PTy->getElementType(); + + // Figure out if there is a Packed type corresponding to this Vector + // type. If so, convert to the packed type. + MVT::ValueType TVT = MVT::getVectorType(getValueType(EltTy), NumElems); + if (TVT != MVT::Other && isTypeLegal(TVT)) { + // Handle copies from generic vectors to registers. + MVT::ValueType PTyElementVT, PTyLegalElementVT; + unsigned NE = getPackedTypeBreakdown(PTy, PTyElementVT, + PTyLegalElementVT); + // Insert a VBIT_CONVERT of the MVT::Vector type to the packed type. + Ops.push_back(DAG.getNode(ISD::VBIT_CONVERT, TVT, Op)); + } else { + assert(0 && "Don't support illegal by-val vector call args yet!"); + abort(); + } } break; } @@ -2566,7 +2586,21 @@ TargetLowering::LowerCallTo(SDOperand Chain, const Type *RetTy, bool isVarArg, for (unsigned i = 0; i != NumVals; ++i) RetTys.push_back(NVT); } else { - assert(0 && "Doesn't handle vectors yet!"); + // Otherwise, this is a vector type. We only support legal vectors + // right now. + const PackedType *PTy = cast(RetTy); + unsigned NumElems = PTy->getNumElements(); + const Type *EltTy = PTy->getElementType(); + + // Figure out if there is a Packed type corresponding to this Vector + // type. If so, convert to the packed type. + MVT::ValueType TVT = MVT::getVectorType(getValueType(EltTy), NumElems); + if (TVT != MVT::Other && isTypeLegal(TVT)) { + RetTys.push_back(TVT); + } else { + assert(0 && "Don't support illegal by-val vector call results yet!"); + abort(); + } } } } @@ -2587,7 +2621,30 @@ TargetLowering::LowerCallTo(SDOperand Chain, const Type *RetTy, bool isVarArg, // If this value was promoted, truncate it down. if (ResVal.getValueType() != VT) { - if (MVT::isInteger(VT)) { + if (VT == MVT::Vector) { + // Insert a VBITCONVERT to convert from the packed result type to the + // MVT::Vector type. + unsigned NumElems = cast(RetTy)->getNumElements(); + const Type *EltTy = cast(RetTy)->getElementType(); + + // Figure out if there is a Packed type corresponding to this Vector + // type. If so, convert to the packed type. + MVT::ValueType TVT = MVT::getVectorType(getValueType(EltTy), NumElems); + if (TVT != MVT::Other && isTypeLegal(TVT)) { + // Handle copies from generic vectors to registers. + MVT::ValueType PTyElementVT, PTyLegalElementVT; + unsigned NE = getPackedTypeBreakdown(cast(RetTy), + PTyElementVT, + PTyLegalElementVT); + // Insert a VBIT_CONVERT of the FORMAL_ARGUMENTS to a + // "N x PTyElementVT" MVT::Vector type. + ResVal = DAG.getNode(ISD::VBIT_CONVERT, MVT::Vector, ResVal, + DAG.getConstant(NE, MVT::i32), + DAG.getValueType(PTyElementVT)); + } else { + abort(); + } + } else if (MVT::isInteger(VT)) { unsigned AssertOp = RetTy->isSigned() ? ISD::AssertSext : ISD::AssertZext; ResVal = DAG.getNode(AssertOp, ResVal.getValueType(), ResVal,