diff options
Diffstat (limited to 'include/llvm/IRBuilder.h')
-rw-r--r-- | include/llvm/IRBuilder.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/include/llvm/IRBuilder.h b/include/llvm/IRBuilder.h index 75aa8e7..c4c2fb9 100644 --- a/include/llvm/IRBuilder.h +++ b/include/llvm/IRBuilder.h @@ -1367,6 +1367,22 @@ public: ConstantExpr::getSizeOf(ArgType->getElementType()), Name); } + + /// CreateVectorSplat - Return a vector value that contains \arg V broadcasted + /// to \p NumElts elements. + Value *CreateVectorSplat(unsigned NumElts, Value *V, const Twine &Name = "") { + assert(NumElts > 0 && "Cannot splat to an empty vector!"); + + // First insert it into an undef vector so we can shuffle it. + Type *I32Ty = getInt32Ty(); + Value *Undef = UndefValue::get(VectorType::get(V->getType(), NumElts)); + V = CreateInsertElement(Undef, V, ConstantInt::get(I32Ty, 0), + Name + ".splatinsert"); + + // Shuffle the value across the desired number of elements. + Value *Zeros = ConstantAggregateZero::get(VectorType::get(I32Ty, NumElts)); + return CreateShuffleVector(V, Undef, Zeros, Name + ".splat"); + } }; } |