From 8e0c6fa5b693e90498045e582a5f66f6a78d67d0 Mon Sep 17 00:00:00 2001 From: Seo Sanghyeon Date: Thu, 2 May 2013 16:59:26 +0900 Subject: [PATCH] Port IRBuilder::CreateVectorSplat --- src/librustc/middle/trans/build.rs | 20 ++++++++++++++------ src/librustc/middle/trans/common.rs | 6 ++++++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/librustc/middle/trans/build.rs b/src/librustc/middle/trans/build.rs index c3dc4f1e8eb..29fd90edce8 100644 --- a/src/librustc/middle/trans/build.rs +++ b/src/librustc/middle/trans/build.rs @@ -963,20 +963,28 @@ pub fn ExtractElement(cx: block, VecVal: ValueRef, Index: ValueRef) -> } pub fn InsertElement(cx: block, VecVal: ValueRef, EltVal: ValueRef, - Index: ValueRef) { + Index: ValueRef) -> ValueRef { unsafe { - if cx.unreachable { return; } + if cx.unreachable { return llvm::LLVMGetUndef(T_nil()); } count_insn(cx, "insertelement"); - llvm::LLVMBuildInsertElement(B(cx), VecVal, EltVal, Index, noname()); + llvm::LLVMBuildInsertElement(B(cx), VecVal, EltVal, Index, noname()) } } pub fn ShuffleVector(cx: block, V1: ValueRef, V2: ValueRef, - Mask: ValueRef) { + Mask: ValueRef) -> ValueRef { unsafe { - if cx.unreachable { return; } + if cx.unreachable { return llvm::LLVMGetUndef(T_nil()); } count_insn(cx, "shufflevector"); - llvm::LLVMBuildShuffleVector(B(cx), V1, V2, Mask, noname()); + llvm::LLVMBuildShuffleVector(B(cx), V1, V2, Mask, noname()) + } +} + +pub fn VectorSplat(cx: block, NumElts: uint, EltVal: ValueRef) -> ValueRef { + unsafe { + let Undef = llvm::LLVMGetUndef(T_vector(val_ty(EltVal), NumElts)); + let VecVal = InsertElement(cx, Undef, EltVal, C_i32(0)); + ShuffleVector(cx, VecVal, Undef, C_null(T_vector(T_i32(), NumElts))) } } diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs index 442b5d25c8b..b004ba9d41f 100644 --- a/src/librustc/middle/trans/common.rs +++ b/src/librustc/middle/trans/common.rs @@ -984,6 +984,12 @@ pub fn T_array(t: TypeRef, n: uint) -> TypeRef { } } +pub fn T_vector(t: TypeRef, n: uint) -> TypeRef { + unsafe { + return llvm::LLVMVectorType(t, n as c_uint); + } +} + // Interior vector. pub fn T_vec2(targ_cfg: @session::config, t: TypeRef) -> TypeRef { return T_struct(~[T_int(targ_cfg), // fill