diff options
| author | Chris Lattner <sabre@nondot.org> | 2006-03-19 04:18:56 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2006-03-19 04:18:56 +0000 |
| commit | 5d3ff12c8f7ebea202c9c17e699c3679ff748e36 (patch) | |
| tree | 5168f50e437e8d2611bf902fd423fbe636a2b640 /llvm/lib/CodeGen | |
| parent | 5336a59e4baa3061271423df33ca41c2d6ad5221 (diff) | |
| download | bcm5719-llvm-5d3ff12c8f7ebea202c9c17e699c3679ff748e36.tar.gz bcm5719-llvm-5d3ff12c8f7ebea202c9c17e699c3679ff748e36.zip | |
Implement expand of BUILD_VECTOR containing variable elements.
This implements CodeGen/Generic/vector.ll:test_variable_buildvector
llvm-svn: 26852
Diffstat (limited to 'llvm/lib/CodeGen')
| -rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp index 52c43af8111..a0c10a09f72 100644 --- a/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp @@ -779,8 +779,38 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) { // Otherwise, this isn't a constant entry. Allocate a sufficiently // aligned object on the stack, store each element into it, then load // the result as a vector. - assert(0 && "Cannot lower variable BUILD_VECTOR yet!"); - abort(); + MVT::ValueType VT = Node->getValueType(0); + // Create the stack frame object. + MachineFrameInfo *FrameInfo = DAG.getMachineFunction().getFrameInfo(); + unsigned ByteSize = MVT::getSizeInBits(VT)/8; + int FrameIdx = FrameInfo->CreateStackObject(ByteSize, ByteSize); + SDOperand FIPtr = DAG.getFrameIndex(FrameIdx, TLI.getPointerTy()); + + // Emit a store of each element to the stack slot. + std::vector<SDOperand> Stores; + bool isLittleEndian = TLI.isLittleEndian(); + unsigned TypeByteSize = + MVT::getSizeInBits(Node->getOperand(0).getValueType())/8; + unsigned VectorSize = MVT::getSizeInBits(VT)/8; + // Store (in the right endianness) the elements to memory. + for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) { + unsigned Offset; + if (isLittleEndian) + Offset = TypeByteSize*i; + else + Offset = TypeByteSize*(e-i-1); + + SDOperand Idx = DAG.getConstant(Offset, FIPtr.getValueType()); + Idx = DAG.getNode(ISD::ADD, FIPtr.getValueType(), FIPtr, Idx); + + Stores.push_back(DAG.getNode(ISD::STORE, MVT::Other, DAG.getEntryNode(), + Node->getOperand(i), Idx, + DAG.getSrcValue(NULL))); + } + SDOperand StoreChain = DAG.getNode(ISD::TokenFactor, MVT::Other, Stores); + + // Result is a load from the stack slot. + Result = DAG.getLoad(VT, StoreChain, FIPtr, DAG.getSrcValue(0)); break; } } |

