authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-10 23:54:28-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-10 23:54:28-04:00
logd504318f2e0f3054c772abbd34f938f2cefa6ccc
tree444f83aa8bb12f3d635b32f0c0031ba4c17fcf5d
parentf6d4e2565e7c0eea7e50e50dd808246d65d9f200
signature Commit is signed but in an unrecognized format.

remove the final legacy stack allocation


4 files changed, 6 insertions(+), 38 deletions(-)

BRANCH_TODO-3
...@@ -4,7 +4,4 @@ Scratch pad for stuff to do before merging master...@@ -4,7 +4,4 @@ Scratch pad for stuff to do before merging master
4look at all the ir_gen_node ir_gen_node_extra calls and make sure result locations are properly propagated4look at all the ir_gen_node ir_gen_node_extra calls and make sure result locations are properly propagated
5 return ir_gen_comptime(irb, scope, node, lval);5 return ir_gen_comptime(irb, scope, node, lval);
66
7migrate all the alloca_list to alloca_gen_list
8
9comptime expressions7comptime expressions
10
src/all_types.hpp-2
...@@ -1369,7 +1369,6 @@ struct ZigFn {...@@ -1369,7 +1369,6 @@ struct ZigFn {
1369 AstNode *fn_no_inline_set_node;1369 AstNode *fn_no_inline_set_node;
1370 AstNode *fn_static_eval_set_node;1370 AstNode *fn_static_eval_set_node;
13711371
1372 ZigList<IrInstruction *> alloca_list;
1373 ZigList<IrInstructionAllocaGen *> alloca_gen_list;1372 ZigList<IrInstructionAllocaGen *> alloca_gen_list;
1374 ZigList<ZigVar *> variable_list;1373 ZigList<ZigVar *> variable_list;
13751374
...@@ -2635,7 +2634,6 @@ struct IrInstructionCast {...@@ -2635,7 +2634,6 @@ struct IrInstructionCast {
2635 IrInstruction *value;2634 IrInstruction *value;
2636 ZigType *dest_type;2635 ZigType *dest_type;
2637 CastOp cast_op;2636 CastOp cast_op;
2638 LLVMValueRef tmp_ptr;
2639};2637};
26402638
2641struct IrInstructionResizeSlice {2639struct IrInstructionResizeSlice {
src/codegen.cpp-14
...@@ -6826,20 +6826,6 @@ static void do_code_gen(CodeGen *g) {...@@ -6826,20 +6826,6 @@ static void do_code_gen(CodeGen *g) {
6826 get_ptr_align(g, ptr_type));6826 get_ptr_align(g, ptr_type));
6827 }6827 }
68286828
6829 for (size_t alloca_i = 0; alloca_i < fn_table_entry->alloca_list.length; alloca_i += 1) {
6830 IrInstruction *instruction = fn_table_entry->alloca_list.at(alloca_i);
6831 LLVMValueRef *slot;
6832 ZigType *slot_type = instruction->value.type;
6833 uint32_t alignment_bytes = 0;
6834 if (instruction->id == IrInstructionIdCast) {
6835 IrInstructionCast *cast_instruction = (IrInstructionCast *)instruction;
6836 slot = &cast_instruction->tmp_ptr;
6837 } else {
6838 zig_unreachable();
6839 }
6840 *slot = build_alloca(g, slot_type, "", alignment_bytes);
6841 }
6842
6843 ZigType *import = get_scope_import(&fn_table_entry->fndef_scope->base);6829 ZigType *import = get_scope_import(&fn_table_entry->fndef_scope->base);
68446830
6845 unsigned gen_i_init = want_first_arg_sret(g, fn_type_id) ? 1 : 0;6831 unsigned gen_i_init = want_first_arg_sret(g, fn_type_id) ? 1 : 0;
src/ir.cpp+6-19
...@@ -181,7 +181,6 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_...@@ -181,7 +181,6 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_
181static ConstExprValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAllowed undef_allowed);181static ConstExprValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAllowed undef_allowed);
182static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_global_refs);182static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_global_refs);
183static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align);183static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align);
184static void ir_add_alloca(IrAnalyze *ira, IrInstruction *instruction, ZigType *type_entry);
185static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,184static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,
186 ZigType *ptr_type);185 ZigType *ptr_type);
187static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,186static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,
...@@ -10497,15 +10496,6 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -10497,15 +10496,6 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
10497 }10496 }
10498}10497}
1049910498
10500static void ir_add_alloca(IrAnalyze *ira, IrInstruction *instruction, ZigType *type_entry) {
10501 if (type_has_bits(type_entry) && handle_is_ptr(type_entry)) {
10502 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
10503 if (fn_entry != nullptr) {
10504 fn_entry->alloca_list.append(instruction);
10505 }
10506 }
10507}
10508
10509static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_global_refs) {10499static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_global_refs) {
10510 ConstGlobalRefs *global_refs = dest->global_refs;10500 ConstGlobalRefs *global_refs = dest->global_refs;
10511 assert(!same_global_refs || src->global_refs != nullptr);10501 assert(!same_global_refs || src->global_refs != nullptr);
...@@ -10631,7 +10621,7 @@ static IrInstruction *ir_const(IrAnalyze *ira, IrInstruction *old_instruction, Z...@@ -10631,7 +10621,7 @@ static IrInstruction *ir_const(IrAnalyze *ira, IrInstruction *old_instruction, Z
10631}10621}
1063210622
10633static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,10623static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,
10634 ZigType *wanted_type, CastOp cast_op, bool need_alloca)10624 ZigType *wanted_type, CastOp cast_op)
10635{10625{
10636 if (instr_is_comptime(value) || !type_has_bits(wanted_type)) {10626 if (instr_is_comptime(value) || !type_has_bits(wanted_type)) {
10637 IrInstruction *result = ir_const(ira, source_instr, wanted_type);10627 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
...@@ -10644,9 +10634,6 @@ static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10644,9 +10634,6 @@ static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_inst
10644 } else {10634 } else {
10645 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node, wanted_type, value, cast_op);10635 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node, wanted_type, value, cast_op);
10646 result->value.type = wanted_type;10636 result->value.type = wanted_type;
10647 if (need_alloca) {
10648 ir_add_alloca(ira, result, wanted_type);
10649 }
10650 return result;10637 return result;
10651 }10638 }
10652}10639}
...@@ -12121,7 +12108,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -12121,7 +12108,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
12121 if (const_cast_result.id == ConstCastResultIdInvalid)12108 if (const_cast_result.id == ConstCastResultIdInvalid)
12122 return ira->codegen->invalid_instruction;12109 return ira->codegen->invalid_instruction;
12123 if (const_cast_result.id == ConstCastResultIdOk) {12110 if (const_cast_result.id == ConstCastResultIdOk) {
12124 return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpNoop, false);12111 return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpNoop);
12125 }12112 }
1212612113
12127 // cast from T to ?T12114 // cast from T to ?T
...@@ -20752,7 +20739,7 @@ static IrInstruction *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstru...@@ -20752,7 +20739,7 @@ static IrInstruction *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstru
20752 } else {20739 } else {
20753 op = CastOpNumLitToConcrete;20740 op = CastOpNumLitToConcrete;
20754 }20741 }
20755 return ir_resolve_cast(ira, &instruction->base, target, dest_type, op, false);20742 return ir_resolve_cast(ira, &instruction->base, target, dest_type, op);
20756 } else {20743 } else {
20757 return ira->codegen->invalid_instruction;20744 return ira->codegen->invalid_instruction;
20758 }20745 }
...@@ -20975,7 +20962,7 @@ static IrInstruction *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInst...@@ -20975,7 +20962,7 @@ static IrInstruction *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInst
20975 return ira->codegen->invalid_instruction;20962 return ira->codegen->invalid_instruction;
20976 }20963 }
2097720964
20978 return ir_resolve_cast(ira, &instruction->base, target, dest_type, CastOpIntToFloat, false);20965 return ir_resolve_cast(ira, &instruction->base, target, dest_type, CastOpIntToFloat);
20979}20966}
2098020967
20981static IrInstruction *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstructionFloatToInt *instruction) {20968static IrInstruction *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstructionFloatToInt *instruction) {
...@@ -20997,7 +20984,7 @@ static IrInstruction *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInst...@@ -20997,7 +20984,7 @@ static IrInstruction *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInst
20997 return ira->codegen->invalid_instruction;20984 return ira->codegen->invalid_instruction;
20998 }20985 }
2099920986
21000 return ir_resolve_cast(ira, &instruction->base, target, dest_type, CastOpFloatToInt, false);20987 return ir_resolve_cast(ira, &instruction->base, target, dest_type, CastOpFloatToInt);
21001}20988}
2100220989
21003static IrInstruction *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstructionErrToInt *instruction) {20990static IrInstruction *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstructionErrToInt *instruction) {
...@@ -21049,7 +21036,7 @@ static IrInstruction *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstr...@@ -21049,7 +21036,7 @@ static IrInstruction *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstr
21049 }21036 }
2105021037
21051 ZigType *u1_type = get_int_type(ira->codegen, false, 1);21038 ZigType *u1_type = get_int_type(ira->codegen, false, 1);
21052 return ir_resolve_cast(ira, &instruction->base, target, u1_type, CastOpBoolToInt, false);21039 return ir_resolve_cast(ira, &instruction->base, target, u1_type, CastOpBoolToInt);
21053}21040}
2105421041
21055static IrInstruction *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstructionIntType *instruction) {21042static IrInstruction *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstructionIntType *instruction) {