authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-10 23:51:43-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-10 23:51:43-04:00
logf6d4e2565e7c0eea7e50e50dd808246d65d9f200
treeb935932394c4de92002444029530c68b9d2e6137
parenta0427d29e4d3c47f470d88a4afdd0e87d3373325
signaturelock-open Commit is signed but in an unrecognized format.

use result loc for ref instruction


4 files changed, 59 insertions(+), 26 deletions(-)

src/all_types.hpp+8-1
......@@ -2234,6 +2234,7 @@ enum IrInstructionId {
22342234 IrInstructionIdCDefine,
22352235 IrInstructionIdCUndef,
22362236 IrInstructionIdRef,
2237 IrInstructionIdRefGen,
22372238 IrInstructionIdCompileErr,
22382239 IrInstructionIdCompileLog,
22392240 IrInstructionIdErrName,
......@@ -2812,11 +2813,17 @@ struct IrInstructionRef {
28122813 IrInstruction base;
28132814
28142815 IrInstruction *value;
2815 LLVMValueRef tmp_ptr;
28162816 bool is_const;
28172817 bool is_volatile;
28182818};
28192819
2820struct IrInstructionRefGen {
2821 IrInstruction base;
2822
2823 IrInstruction *operand;
2824 IrInstruction *result_loc;
2825};
2826
28202827struct IrInstructionCompileErr {
28212828 IrInstruction base;
28222829
src/codegen.cpp+9-13
......@@ -4212,17 +4212,17 @@ static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutable *executable, IrInstru
42124212 return phi;
42134213}
42144214
4215static LLVMValueRef ir_render_ref(CodeGen *g, IrExecutable *executable, IrInstructionRef *instruction) {
4215static LLVMValueRef ir_render_ref(CodeGen *g, IrExecutable *executable, IrInstructionRefGen *instruction) {
42164216 if (!type_has_bits(instruction->base.value.type)) {
42174217 return nullptr;
42184218 }
4219 LLVMValueRef value = ir_llvm_value(g, instruction->value);
4220 if (handle_is_ptr(instruction->value->value.type)) {
4219 LLVMValueRef value = ir_llvm_value(g, instruction->operand);
4220 if (handle_is_ptr(instruction->operand->value.type)) {
42214221 return value;
42224222 } else {
4223 assert(instruction->tmp_ptr);
4224 gen_store_untyped(g, value, instruction->tmp_ptr, 0, false);
4225 return instruction->tmp_ptr;
4223 LLVMValueRef result_loc = ir_llvm_value(g, instruction->result_loc);
4224 gen_store_untyped(g, value, result_loc, 0, false);
4225 return result_loc;
42264226 }
42274227}
42284228
......@@ -5530,6 +5530,7 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
55305530 case IrInstructionIdResolveResult:
55315531 case IrInstructionIdContainerInitList:
55325532 case IrInstructionIdSliceSrc:
5533 case IrInstructionIdRef:
55335534 zig_unreachable();
55345535
55355536 case IrInstructionIdDeclVarGen:
......@@ -5584,8 +5585,8 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
55845585 return ir_render_bit_reverse(g, executable, (IrInstructionBitReverse *)instruction);
55855586 case IrInstructionIdPhi:
55865587 return ir_render_phi(g, executable, (IrInstructionPhi *)instruction);
5587 case IrInstructionIdRef:
5588 return ir_render_ref(g, executable, (IrInstructionRef *)instruction);
5588 case IrInstructionIdRefGen:
5589 return ir_render_ref(g, executable, (IrInstructionRefGen *)instruction);
55895590 case IrInstructionIdErrName:
55905591 return ir_render_err_name(g, executable, (IrInstructionErrName *)instruction);
55915592 case IrInstructionIdCmpxchgGen:
......@@ -6833,11 +6834,6 @@ static void do_code_gen(CodeGen *g) {
68336834 if (instruction->id == IrInstructionIdCast) {
68346835 IrInstructionCast *cast_instruction = (IrInstructionCast *)instruction;
68356836 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;
68416837 } else {
68426838 zig_unreachable();
68436839 }
src/ir.cpp+32-12
......@@ -617,6 +617,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionRef *) {
617617 return IrInstructionIdRef;
618618}
619619
620static constexpr IrInstructionId ir_instruction_id(IrInstructionRefGen *) {
621 return IrInstructionIdRefGen;
622}
623
620624static constexpr IrInstructionId ir_instruction_id(IrInstructionCompileErr *) {
621625 return IrInstructionIdCompileErr;
622626}
......@@ -1961,6 +1965,21 @@ static IrInstruction *ir_build_ref(IrBuilder *irb, Scope *scope, AstNode *source
19611965 return &instruction->base;
19621966}
19631967
1968static 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
19641983static IrInstruction *ir_build_compile_err(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *msg) {
19651984 IrInstructionCompileErr *instruction = ir_build_instruction<IrInstructionCompileErr>(irb, scope, source_node);
19661985 instruction->msg = msg;
......@@ -2636,11 +2655,8 @@ static IrInstruction *ir_build_type_name(IrBuilder *irb, Scope *scope, AstNode *
26362655 return &instruction->base;
26372656}
26382657
2639static IrInstruction *ir_build_decl_ref(IrBuilder *irb, Scope *scope, AstNode *source_node,
2640 Tld *tld, LVal lval)
2641{
2642 IrInstructionDeclRef *instruction = ir_build_instruction<IrInstructionDeclRef>(
2643 irb, scope, source_node);
2658static IrInstruction *ir_build_decl_ref(IrBuilder *irb, Scope *scope, AstNode *source_node, Tld *tld, LVal lval) {
2659 IrInstructionDeclRef *instruction = ir_build_instruction<IrInstructionDeclRef>(irb, scope, source_node);
26442660 instruction->tld = tld;
26452661 instruction->lval = lval;
26462662
......@@ -11335,15 +11351,16 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi
1133511351
1133611352 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value->value.type,
1133711353 is_const, is_volatile, PtrLenSingle, 0, 0, 0, false);
11338 IrInstruction *new_instruction = ir_build_ref(&ira->new_irb, source_instruction->scope,
11339 source_instruction->source_node, value, is_const, is_volatile);
11340 new_instruction->value.type = ptr_type;
11341 new_instruction->value.data.rh_ptr = RuntimeHintPtrStack;
11354
11355 IrInstruction *result_loc;
1134211356 if (type_has_bits(ptr_type) && !handle_is_ptr(value->value.type)) {
11343 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
11344 assert(fn_entry);
11345 fn_entry->alloca_list.append(new_instruction);
11357 result_loc = ir_resolve_result(ira, source_instruction, no_result_loc(), value->value.type, nullptr);
11358 } else {
11359 result_loc = nullptr;
1134611360 }
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;
1134711364 return new_instruction;
1134811365}
1134911366
......@@ -24119,6 +24136,7 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction
2411924136 case IrInstructionIdReturnPtr:
2412024137 case IrInstructionIdAllocaGen:
2412124138 case IrInstructionIdSliceGen:
24139 case IrInstructionIdRefGen:
2412224140 zig_unreachable();
2412324141
2412424142 case IrInstructionIdReturn:
......@@ -24653,6 +24671,8 @@ bool ir_has_side_effects(IrInstruction *instruction) {
2465324671 return reinterpret_cast<IrInstructionErrWrapCode *>(instruction)->result_loc != nullptr;
2465424672 case IrInstructionIdLoadPtrGen:
2465524673 return reinterpret_cast<IrInstructionLoadPtrGen *>(instruction)->result_loc != nullptr;
24674 case IrInstructionIdRefGen:
24675 return reinterpret_cast<IrInstructionRefGen *>(instruction)->result_loc != nullptr;
2465624676 }
2465724677 zig_unreachable();
2465824678}
src/ir_print.cpp+10
......@@ -668,6 +668,13 @@ static void ir_print_ref(IrPrint *irp, IrInstructionRef *instruction) {
668668 ir_print_other_instruction(irp, instruction->value);
669669}
670670
671static 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
671678static void ir_print_compile_err(IrPrint *irp, IrInstructionCompileErr *instruction) {
672679 fprintf(irp->f, "@compileError(");
673680 ir_print_other_instruction(irp, instruction->msg);
......@@ -1711,6 +1718,9 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
17111718 case IrInstructionIdRef:
17121719 ir_print_ref(irp, (IrInstructionRef *)instruction);
17131720 break;
1721 case IrInstructionIdRefGen:
1722 ir_print_ref_gen(irp, (IrInstructionRefGen *)instruction);
1723 break;
17141724 case IrInstructionIdCompileErr:
17151725 ir_print_compile_err(irp, (IrInstructionCompileErr *)instruction);
17161726 break;