aboutsummaryrefslogtreecommitdiff
path: root/src/codegen.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-11-01 23:16:49 -0400
committerAndrew Kelley <andrew@ziglang.org>2019-11-05 12:11:57 -0500
commitcbaa10fc3bcd2d5f8d48b9038e840ae508fe2822 (patch)
treed5dbbb0d4edee73b54dbd03802ab6885d5699a99 /src/codegen.cpp
parent70be308c4315c53d42889d568d5731ba227dcf88 (diff)
downloadzig-cbaa10fc3bcd2d5f8d48b9038e840ae508fe2822.tar.gz
zig-cbaa10fc3bcd2d5f8d48b9038e840ae508fe2822.zip
implement storing vector elements via runtime index
Diffstat (limited to 'src/codegen.cpp')
-rw-r--r--src/codegen.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp
index 0c67a9954a..154c21893a 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -3644,6 +3644,19 @@ static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, Ir
return nullptr;
}
+static LLVMValueRef ir_render_vector_store_elem(CodeGen *g, IrExecutable *executable,
+ IrInstructionVectorStoreElem *instruction)
+{
+ LLVMValueRef vector_ptr = ir_llvm_value(g, instruction->vector_ptr);
+ LLVMValueRef index = ir_llvm_value(g, instruction->index);
+ LLVMValueRef value = ir_llvm_value(g, instruction->value);
+
+ LLVMValueRef loaded_vector = gen_load(g, vector_ptr, instruction->vector_ptr->value.type, "");
+ LLVMValueRef modified_vector = LLVMBuildInsertElement(g->builder, loaded_vector, value, index, "");
+ gen_store(g, modified_vector, vector_ptr, instruction->vector_ptr->value.type);
+ return nullptr;
+}
+
static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutable *executable, IrInstructionVarPtr *instruction) {
if (instruction->base.value.special != ConstValSpecialRuntime)
return ir_llvm_value(g, &instruction->base);
@@ -6130,6 +6143,8 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
return ir_render_load_ptr(g, executable, (IrInstructionLoadPtrGen *)instruction);
case IrInstructionIdStorePtr:
return ir_render_store_ptr(g, executable, (IrInstructionStorePtr *)instruction);
+ case IrInstructionIdVectorStoreElem:
+ return ir_render_vector_store_elem(g, executable, (IrInstructionVectorStoreElem *)instruction);
case IrInstructionIdVarPtr:
return ir_render_var_ptr(g, executable, (IrInstructionVarPtr *)instruction);
case IrInstructionIdReturnPtr: