pub unsafe fn gen_slice(
        &mut self,
        builder: LLVMBuilderRef,
        vector: LLVMValueRef,
        index: LLVMValueRef,
        size: LLVMValueRef,
    ) -> WeldResult<LLVMValueRef> {
        use self::llvm_sys::LLVMIntPredicate::LLVMIntUGT;
        if self.slice.is_none() {
            let mut arg_tys = [self.vector_ty, self.i64_type(), self.i64_type()];
            let ret_ty = self.vector_ty;

            let name = format!("{}.slice", self.name);
            let (function, builder, _) = self.define_function(ret_ty, &mut arg_tys, name);

            let vector = LLVMGetParam(function, 0);
            let index = LLVMGetParam(function, 1);
            let size = LLVMGetParam(function, 2);

            // Compute the size of the array. We use the remaining size if the new size does not
            // accomodate the vector starting at the given index.
            let cur_size = LLVMBuildExtractValue(builder, vector, SIZE_INDEX, c_str!(""));
            let remaining = LLVMBuildSub(builder, cur_size, index, c_str!(""));
            let size_cmp = LLVMBuildICmp(builder, LLVMIntUGT, size, remaining, c_str!(""));
            let new_size = LLVMBuildSelect(builder, size_cmp, remaining, size, c_str!(""));

            let elements = LLVMBuildExtractValue(builder, vector, POINTER_INDEX, c_str!(""));
            let new_elements = LLVMBuildGEP(builder, elements, [index].as_mut_ptr(), 1, c_str!(""));

            let mut result = LLVMGetUndef(self.vector_ty);
            result = LLVMBuildInsertValue(builder, result, new_elements, POINTER_INDEX, c_str!(""));
            result = LLVMBuildInsertValue(builder, result, new_size, SIZE_INDEX, c_str!(""));
            LLVMBuildRet(builder, result);

            self.slice = Some(function);
            LLVMDisposeBuilder(builder);
        }

        let mut args = [vector, index, size];
        Ok(LLVMBuildCall(
            builder,
            self.slice.unwrap(),
            args.as_mut_ptr(),
            args.len() as u32,
            c_str!(""),
        ))
    }
Generate the `slice` method on vectors and calls it.

This method takes an index and size returns returns a view into the given vector. If index
is out of bounds, behavior is undefined. If `index + size` is greater than the length of
the vector, a slice up to the end of the vector starting at index is returned.
weld/src/codegen/llvm2/vector.rs