[cfe-commits] r45062 - in /cfe/trunk/CodeGen: CGBuiltin.cpp CGExprScalar.cpp CodeGenFunction.h
Chris Lattner
clattner at apple.com
Mon Dec 17 14:29:15 PST 2007
On Dec 15, 2007, at 1:23 PM, Anders Carlsson wrote:
> URL: http://llvm.org/viewvc/llvm-project?rev=45062&view=rev
> Log:
> We now support all MMX intrinsics. SSE intrinsics are next.
Hi Anders,
> +++ cfe/trunk/CodeGen/CGExprScalar.cpp Sat Dec 15 15:23:30 2007
> @@ -1099,3 +1099,37 @@
> return Builder.CreateShuffleVector(V1, V2, Mask, Name);
> }
>
> +llvm::Value *CodeGenFunction::EmitVector(llvm::Value * const *Vals,
> + unsigned NumVals)
> +{
> + bool AllConstElements = true;
> +
> + for (unsigned i = 0; i < NumVals; i++) {
> + if (!isa<llvm::Constant>(Vals[i])) {
> + AllConstElements = false;
> + break;
> + }
> + }
> +
> + assert(!(NumVals & NumVals - 1) &&
> + "Number of elements must be power of two!");
Please don't abort on non-power-2 vectors. Nothing in this code
depends on it, and we'd like to support them in time.
> +
> + if (AllConstElements) {
> + llvm::SmallVector<llvm::Constant*, 16> Constants;
> +
> + for (unsigned i = 0, e = NumVals; i != e; ++i)
> + Constants.push_back(cast<llvm::Constant>(Vals[i]));
> +
> + return llvm::ConstantVector::get(&Constants[0], Constants.size
> ());
> + }
I don't think you need any of this code, doesn't the folding builder
do this already? (looks) ah, the issue is that the folding builder
doesn't fold insertelement instructions. Can you add this to the
LLVMFoldingBuilder instead of this code?
> +
> + llvm::Value *Vec
> + = llvm::UndefValue::get(llvm::VectorType::get(Vals[0]->getType
> (), NumVals));
> +
> + for (unsigned i = 0, e = NumVals ; i != e; ++i) {
> + llvm::Value *Idx = llvm::ConstantInt::get(llvm::Type::Int32Ty,
> i);
> + Vec = Builder.CreateInsertElement(Vec, Vals[i], Idx, "tmp");
> + }
> +
> + return Vec;
This looks great :)
-Chris
More information about the cfe-commits
mailing list