| author | |
| committer | |
| log | f6d4e2565e7c0eea7e50e50dd808246d65d9f200 |
| tree | b935932394c4de92002444029530c68b9d2e6137 |
| parent | a0427d29e4d3c47f470d88a4afdd0e87d3373325 |
| signature | Commit is signed but in an unrecognized format. |
4 files changed, 59 insertions(+), 26 deletions(-)
src/all_types.hpp+8-1| ... | @@ -2234,6 +2234,7 @@ enum IrInstructionId { | ... | @@ -2234,6 +2234,7 @@ enum IrInstructionId { |
| 2234 | IrInstructionIdCDefine, | 2234 | IrInstructionIdCDefine, |
| 2235 | IrInstructionIdCUndef, | 2235 | IrInstructionIdCUndef, |
| 2236 | IrInstructionIdRef, | 2236 | IrInstructionIdRef, |
| 2237 | IrInstructionIdRefGen, | ||
| 2237 | IrInstructionIdCompileErr, | 2238 | IrInstructionIdCompileErr, |
| 2238 | IrInstructionIdCompileLog, | 2239 | IrInstructionIdCompileLog, |
| 2239 | IrInstructionIdErrName, | 2240 | IrInstructionIdErrName, |
| ... | @@ -2812,11 +2813,17 @@ struct IrInstructionRef { | ... | @@ -2812,11 +2813,17 @@ struct IrInstructionRef { |
| 2812 | IrInstruction base; | 2813 | IrInstruction base; |
| 2813 | 2814 | ||
| 2814 | IrInstruction *value; | 2815 | IrInstruction *value; |
| 2815 | LLVMValueRef tmp_ptr; | ||
| 2816 | bool is_const; | 2816 | bool is_const; |
| 2817 | bool is_volatile; | 2817 | bool is_volatile; |
| 2818 | }; | 2818 | }; |
| 2819 | 2819 | ||
| 2820 | struct IrInstructionRefGen { | ||
| 2821 | IrInstruction base; | ||
| 2822 | |||
| 2823 | IrInstruction *operand; | ||
| 2824 | IrInstruction *result_loc; | ||
| 2825 | }; | ||
| 2826 | |||
| 2820 | struct IrInstructionCompileErr { | 2827 | struct IrInstructionCompileErr { |
| 2821 | IrInstruction base; | 2828 | IrInstruction base; |
| 2822 | 2829 |
src/codegen.cpp+9-13| ... | @@ -4212,17 +4212,17 @@ static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutable *executable, IrInstru | ... | @@ -4212,17 +4212,17 @@ static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutable *executable, IrInstru |
| 4212 | return phi; | 4212 | return phi; |
| 4213 | } | 4213 | } |
| 4214 | 4214 | ||
| 4215 | static LLVMValueRef ir_render_ref(CodeGen *g, IrExecutable *executable, IrInstructionRef *instruction) { | 4215 | static LLVMValueRef ir_render_ref(CodeGen *g, IrExecutable *executable, IrInstructionRefGen *instruction) { |
| 4216 | if (!type_has_bits(instruction->base.value.type)) { | 4216 | if (!type_has_bits(instruction->base.value.type)) { |
| 4217 | return nullptr; | 4217 | return nullptr; |
| 4218 | } | 4218 | } |
| 4219 | LLVMValueRef value = ir_llvm_value(g, instruction->value); | 4219 | LLVMValueRef value = ir_llvm_value(g, instruction->operand); |
| 4220 | if (handle_is_ptr(instruction->value->value.type)) { | 4220 | if (handle_is_ptr(instruction->operand->value.type)) { |
| 4221 | return value; | 4221 | return value; |
| 4222 | } else { | 4222 | } else { |
| 4223 | assert(instruction->tmp_ptr); | 4223 | LLVMValueRef result_loc = ir_llvm_value(g, instruction->result_loc); |
| 4224 | gen_store_untyped(g, value, instruction->tmp_ptr, 0, false); | 4224 | gen_store_untyped(g, value, result_loc, 0, false); |
| 4225 | return instruction->tmp_ptr; | 4225 | return result_loc; |
| 4226 | } | 4226 | } |
| 4227 | } | 4227 | } |
| 4228 | 4228 | ||
| ... | @@ -5530,6 +5530,7 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable, | ... | @@ -5530,6 +5530,7 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable, |
| 5530 | case IrInstructionIdResolveResult: | 5530 | case IrInstructionIdResolveResult: |
| 5531 | case IrInstructionIdContainerInitList: | 5531 | case IrInstructionIdContainerInitList: |
| 5532 | case IrInstructionIdSliceSrc: | 5532 | case IrInstructionIdSliceSrc: |
| 5533 | case IrInstructionIdRef: | ||
| 5533 | zig_unreachable(); | 5534 | zig_unreachable(); |
| 5534 | 5535 | ||
| 5535 | case IrInstructionIdDeclVarGen: | 5536 | case IrInstructionIdDeclVarGen: |
| ... | @@ -5584,8 +5585,8 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable, | ... | @@ -5584,8 +5585,8 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable, |
| 5584 | return ir_render_bit_reverse(g, executable, (IrInstructionBitReverse *)instruction); | 5585 | return ir_render_bit_reverse(g, executable, (IrInstructionBitReverse *)instruction); |
| 5585 | case IrInstructionIdPhi: | 5586 | case IrInstructionIdPhi: |
| 5586 | return ir_render_phi(g, executable, (IrInstructionPhi *)instruction); | 5587 | return ir_render_phi(g, executable, (IrInstructionPhi *)instruction); |
| 5587 | case IrInstructionIdRef: | 5588 | case IrInstructionIdRefGen: |
| 5588 | return ir_render_ref(g, executable, (IrInstructionRef *)instruction); | 5589 | return ir_render_ref(g, executable, (IrInstructionRefGen *)instruction); |
| 5589 | case IrInstructionIdErrName: | 5590 | case IrInstructionIdErrName: |
| 5590 | return ir_render_err_name(g, executable, (IrInstructionErrName *)instruction); | 5591 | return ir_render_err_name(g, executable, (IrInstructionErrName *)instruction); |
| 5591 | case IrInstructionIdCmpxchgGen: | 5592 | case IrInstructionIdCmpxchgGen: |
| ... | @@ -6833,11 +6834,6 @@ static void do_code_gen(CodeGen *g) { | ... | @@ -6833,11 +6834,6 @@ static void do_code_gen(CodeGen *g) { |
| 6833 | if (instruction->id == IrInstructionIdCast) { | 6834 | if (instruction->id == IrInstructionIdCast) { |
| 6834 | IrInstructionCast *cast_instruction = (IrInstructionCast *)instruction; | 6835 | IrInstructionCast *cast_instruction = (IrInstructionCast *)instruction; |
| 6835 | slot = &cast_instruction->tmp_ptr; | 6836 | slot = &cast_instruction->tmp_ptr; |
| 6836 | } else if (instruction->id == IrInstructionIdRef) { | ||
| 6837 | IrInstructionRef *ref_instruction = (IrInstructionRef *)instruction; | ||
| 6838 | slot = &ref_instruction->tmp_ptr; | ||
| 6839 | assert(instruction->value.type->id == ZigTypeIdPointer); | ||
| 6840 | slot_type = instruction->value.type->data.pointer.child_type; | ||
| 6841 | } else { | 6837 | } else { |
| 6842 | zig_unreachable(); | 6838 | zig_unreachable(); |
| 6843 | } | 6839 | } |
src/ir.cpp+32-12| ... | @@ -617,6 +617,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionRef *) { | ... | @@ -617,6 +617,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionRef *) { |
| 617 | return IrInstructionIdRef; | 617 | return IrInstructionIdRef; |
| 618 | } | 618 | } |
| 619 | 619 | ||
| 620 | static constexpr IrInstructionId ir_instruction_id(IrInstructionRefGen *) { | ||
| 621 | return IrInstructionIdRefGen; | ||
| 622 | } | ||
| 623 | |||
| 620 | static constexpr IrInstructionId ir_instruction_id(IrInstructionCompileErr *) { | 624 | static constexpr IrInstructionId ir_instruction_id(IrInstructionCompileErr *) { |
| 621 | return IrInstructionIdCompileErr; | 625 | return IrInstructionIdCompileErr; |
| 622 | } | 626 | } |
| ... | @@ -1961,6 +1965,21 @@ static IrInstruction *ir_build_ref(IrBuilder *irb, Scope *scope, AstNode *source | ... | @@ -1961,6 +1965,21 @@ static IrInstruction *ir_build_ref(IrBuilder *irb, Scope *scope, AstNode *source |
| 1961 | return &instruction->base; | 1965 | return &instruction->base; |
| 1962 | } | 1966 | } |
| 1963 | 1967 | ||
| 1968 | static IrInstruction *ir_build_ref_gen(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *result_type, | ||
| 1969 | IrInstruction *operand, IrInstruction *result_loc) | ||
| 1970 | { | ||
| 1971 | IrInstructionRefGen *instruction = ir_build_instruction<IrInstructionRefGen>(&ira->new_irb, | ||
| 1972 | source_instruction->scope, source_instruction->source_node); | ||
| 1973 | instruction->base.value.type = result_type; | ||
| 1974 | instruction->operand = operand; | ||
| 1975 | instruction->result_loc = result_loc; | ||
| 1976 | |||
| 1977 | ir_ref_instruction(operand, ira->new_irb.current_basic_block); | ||
| 1978 | if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block); | ||
| 1979 | |||
| 1980 | return &instruction->base; | ||
| 1981 | } | ||
| 1982 | |||
| 1964 | static IrInstruction *ir_build_compile_err(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *msg) { | 1983 | static IrInstruction *ir_build_compile_err(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *msg) { |
| 1965 | IrInstructionCompileErr *instruction = ir_build_instruction<IrInstructionCompileErr>(irb, scope, source_node); | 1984 | IrInstructionCompileErr *instruction = ir_build_instruction<IrInstructionCompileErr>(irb, scope, source_node); |
| 1966 | instruction->msg = msg; | 1985 | instruction->msg = msg; |
| ... | @@ -2636,11 +2655,8 @@ static IrInstruction *ir_build_type_name(IrBuilder *irb, Scope *scope, AstNode * | ... | @@ -2636,11 +2655,8 @@ static IrInstruction *ir_build_type_name(IrBuilder *irb, Scope *scope, AstNode * |
| 2636 | return &instruction->base; | 2655 | return &instruction->base; |
| 2637 | } | 2656 | } |
| 2638 | 2657 | ||
| 2639 | static IrInstruction *ir_build_decl_ref(IrBuilder *irb, Scope *scope, AstNode *source_node, | 2658 | static IrInstruction *ir_build_decl_ref(IrBuilder *irb, Scope *scope, AstNode *source_node, Tld *tld, LVal lval) { |
| 2640 | Tld *tld, LVal lval) | 2659 | IrInstructionDeclRef *instruction = ir_build_instruction<IrInstructionDeclRef>(irb, scope, source_node); |
| 2641 | { | ||
| 2642 | IrInstructionDeclRef *instruction = ir_build_instruction<IrInstructionDeclRef>( | ||
| 2643 | irb, scope, source_node); | ||
| 2644 | instruction->tld = tld; | 2660 | instruction->tld = tld; |
| 2645 | instruction->lval = lval; | 2661 | instruction->lval = lval; |
| 2646 | 2662 | ||
| ... | @@ -11335,15 +11351,16 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi | ... | @@ -11335,15 +11351,16 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi |
| 11335 | 11351 | ||
| 11336 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value->value.type, | 11352 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value->value.type, |
| 11337 | is_const, is_volatile, PtrLenSingle, 0, 0, 0, false); | 11353 | is_const, is_volatile, PtrLenSingle, 0, 0, 0, false); |
| 11338 | IrInstruction *new_instruction = ir_build_ref(&ira->new_irb, source_instruction->scope, | 11354 | |
| 11339 | source_instruction->source_node, value, is_const, is_volatile); | 11355 | IrInstruction *result_loc; |
| 11340 | new_instruction->value.type = ptr_type; | ||
| 11341 | new_instruction->value.data.rh_ptr = RuntimeHintPtrStack; | ||
| 11342 | if (type_has_bits(ptr_type) && !handle_is_ptr(value->value.type)) { | 11356 | if (type_has_bits(ptr_type) && !handle_is_ptr(value->value.type)) { |
| 11343 | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); | 11357 | result_loc = ir_resolve_result(ira, source_instruction, no_result_loc(), value->value.type, nullptr); |
| 11344 | assert(fn_entry); | 11358 | } else { |
| 11345 | fn_entry->alloca_list.append(new_instruction); | 11359 | result_loc = nullptr; |
| 11346 | } | 11360 | } |
| 11361 | |||
| 11362 | IrInstruction *new_instruction = ir_build_ref_gen(ira, source_instruction, ptr_type, value, result_loc); | ||
| 11363 | new_instruction->value.data.rh_ptr = RuntimeHintPtrStack; | ||
| 11347 | return new_instruction; | 11364 | return new_instruction; |
| 11348 | } | 11365 | } |
| 11349 | 11366 | ||
| ... | @@ -24119,6 +24136,7 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction | ... | @@ -24119,6 +24136,7 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction |
| 24119 | case IrInstructionIdReturnPtr: | 24136 | case IrInstructionIdReturnPtr: |
| 24120 | case IrInstructionIdAllocaGen: | 24137 | case IrInstructionIdAllocaGen: |
| 24121 | case IrInstructionIdSliceGen: | 24138 | case IrInstructionIdSliceGen: |
| 24139 | case IrInstructionIdRefGen: | ||
| 24122 | zig_unreachable(); | 24140 | zig_unreachable(); |
| 24123 | 24141 | ||
| 24124 | case IrInstructionIdReturn: | 24142 | case IrInstructionIdReturn: |
| ... | @@ -24653,6 +24671,8 @@ bool ir_has_side_effects(IrInstruction *instruction) { | ... | @@ -24653,6 +24671,8 @@ bool ir_has_side_effects(IrInstruction *instruction) { |
| 24653 | return reinterpret_cast<IrInstructionErrWrapCode *>(instruction)->result_loc != nullptr; | 24671 | return reinterpret_cast<IrInstructionErrWrapCode *>(instruction)->result_loc != nullptr; |
| 24654 | case IrInstructionIdLoadPtrGen: | 24672 | case IrInstructionIdLoadPtrGen: |
| 24655 | return reinterpret_cast<IrInstructionLoadPtrGen *>(instruction)->result_loc != nullptr; | 24673 | return reinterpret_cast<IrInstructionLoadPtrGen *>(instruction)->result_loc != nullptr; |
| 24674 | case IrInstructionIdRefGen: | ||
| 24675 | return reinterpret_cast<IrInstructionRefGen *>(instruction)->result_loc != nullptr; | ||
| 24656 | } | 24676 | } |
| 24657 | zig_unreachable(); | 24677 | zig_unreachable(); |
| 24658 | } | 24678 | } |
src/ir_print.cpp+10| ... | @@ -668,6 +668,13 @@ static void ir_print_ref(IrPrint *irp, IrInstructionRef *instruction) { | ... | @@ -668,6 +668,13 @@ static void ir_print_ref(IrPrint *irp, IrInstructionRef *instruction) { |
| 668 | ir_print_other_instruction(irp, instruction->value); | 668 | ir_print_other_instruction(irp, instruction->value); |
| 669 | } | 669 | } |
| 670 | 670 | ||
| 671 | static void ir_print_ref_gen(IrPrint *irp, IrInstructionRefGen *instruction) { | ||
| 672 | fprintf(irp->f, "@ref("); | ||
| 673 | ir_print_other_instruction(irp, instruction->operand); | ||
| 674 | fprintf(irp->f, ")result="); | ||
| 675 | ir_print_other_instruction(irp, instruction->result_loc); | ||
| 676 | } | ||
| 677 | |||
| 671 | static void ir_print_compile_err(IrPrint *irp, IrInstructionCompileErr *instruction) { | 678 | static void ir_print_compile_err(IrPrint *irp, IrInstructionCompileErr *instruction) { |
| 672 | fprintf(irp->f, "@compileError("); | 679 | fprintf(irp->f, "@compileError("); |
| 673 | ir_print_other_instruction(irp, instruction->msg); | 680 | ir_print_other_instruction(irp, instruction->msg); |
| ... | @@ -1711,6 +1718,9 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) { | ... | @@ -1711,6 +1718,9 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) { |
| 1711 | case IrInstructionIdRef: | 1718 | case IrInstructionIdRef: |
| 1712 | ir_print_ref(irp, (IrInstructionRef *)instruction); | 1719 | ir_print_ref(irp, (IrInstructionRef *)instruction); |
| 1713 | break; | 1720 | break; |
| 1721 | case IrInstructionIdRefGen: | ||
| 1722 | ir_print_ref_gen(irp, (IrInstructionRefGen *)instruction); | ||
| 1723 | break; | ||
| 1714 | case IrInstructionIdCompileErr: | 1724 | case IrInstructionIdCompileErr: |
| 1715 | ir_print_compile_err(irp, (IrInstructionCompileErr *)instruction); | 1725 | ir_print_compile_err(irp, (IrInstructionCompileErr *)instruction); |
| 1716 | break; | 1726 | break; |