From 8ca05e0c302e15d6365afd2a0ea5fe15c9e85758 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 29 Jan 2006 06:34:16 +0000 Subject: [PATCH] Allow custom expansion of ConstantVec nodes. PPC will use this in the future. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25774 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/SelectionDAG/LegalizeDAG.cpp | 57 +++++++++++++++--------- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp index 89d764cc6cd..fb5329a5c0c 100644 --- a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp +++ b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp @@ -530,30 +530,43 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) { } break; } - case ISD::ConstantVec: { - // We assume that vector constants are not legal, and will be immediately - // spilled to the constant pool. - // - // FIXME: Allow custom lowering to TargetConstantVec's. - // - // Create a ConstantPacked, and put it in the constant pool. - std::vector CV; - MVT::ValueType VT = Node->getValueType(0); - for (unsigned I = 0, E = Node->getNumOperands(); I < E; ++I) { - SDOperand OpN = Node->getOperand(I); - const Type* OpNTy = MVT::getTypeForValueType(OpN.getValueType()); - if (MVT::isFloatingPoint(VT)) - CV.push_back(ConstantFP::get(OpNTy, - cast(OpN)->getValue())); - else - CV.push_back(ConstantUInt::get(OpNTy, - cast(OpN)->getValue())); + case ISD::ConstantVec: + switch (TLI.getOperationAction(ISD::ConstantVec, Node->getValueType(0))) { + default: assert(0 && "This action is not supported yet!"); + case TargetLowering::Custom: + Tmp3 = TLI.LowerOperation(Result, DAG); + if (Tmp3.Val) { + Result = Tmp3; + break; + } + // FALLTHROUGH + case TargetLowering::Expand: + // We assume that vector constants are not legal, and will be immediately + // spilled to the constant pool. + // + // Create a ConstantPacked, and put it in the constant pool. + MVT::ValueType VT = Node->getValueType(0); + const Type *OpNTy = + MVT::getTypeForValueType(Node->getOperand(0).getValueType()); + std::vector CV; + if (MVT::isFloatingPoint(VT)) { + for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) { + double V = cast(Node->getOperand(i))->getValue(); + CV.push_back(ConstantFP::get(OpNTy, V)); + } + } else { + for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) { + uint64_t V = cast(Node->getOperand(i))->getValue(); + CV.push_back(ConstantUInt::get(OpNTy, V)); + } + } + Constant *CP = ConstantPacked::get(CV); + SDOperand CPIdx = DAG.getConstantPool(CP, TLI.getPointerTy()); + Result = DAG.getLoad(VT, DAG.getEntryNode(), CPIdx, + DAG.getSrcValue(NULL)); + break; } - Constant *CP = ConstantPacked::get(CV); - SDOperand CPIdx = DAG.getConstantPool(CP, TLI.getPointerTy()); - Result = DAG.getLoad(VT, DAG.getEntryNode(), CPIdx, DAG.getSrcValue(NULL)); break; - } case ISD::TokenFactor: if (Node->getNumOperands() == 2) { Tmp1 = LegalizeOp(Node->getOperand(0));