diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-11-01 23:16:49 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-11-05 12:11:57 -0500 |
| commit | cbaa10fc3bcd2d5f8d48b9038e840ae508fe2822 (patch) | |
| tree | d5dbbb0d4edee73b54dbd03802ab6885d5699a99 /src/codegen.cpp | |
| parent | 70be308c4315c53d42889d568d5731ba227dcf88 (diff) | |
| download | zig-cbaa10fc3bcd2d5f8d48b9038e840ae508fe2822.tar.gz zig-cbaa10fc3bcd2d5f8d48b9038e840ae508fe2822.zip | |
implement storing vector elements via runtime index
Diffstat (limited to 'src/codegen.cpp')
| -rw-r--r-- | src/codegen.cpp | 15 |
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: |
