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
signaturelock-open 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
44look at all the ir_gen_node ir_gen_node_extra calls and make sure result locations are properly propagated
55 return ir_gen_comptime(irb, scope, node, lval);
66
7migrate all the alloca_list to alloca_gen_list
8
97comptime expressions
10
src/all_types.hpp-2
......@@ -1369,7 +1369,6 @@ struct ZigFn {
13691369 AstNode *fn_no_inline_set_node;
13701370 AstNode *fn_static_eval_set_node;
13711371
1372 ZigList<IrInstruction *> alloca_list;
13731372 ZigList<IrInstructionAllocaGen *> alloca_gen_list;
13741373 ZigList<ZigVar *> variable_list;
13751374
......@@ -2635,7 +2634,6 @@ struct IrInstructionCast {
26352634 IrInstruction *value;
26362635 ZigType *dest_type;
26372636 CastOp cast_op;
2638 LLVMValueRef tmp_ptr;
26392637};
26402638
26412639struct IrInstructionResizeSlice {
src/codegen.cpp-14
......@@ -6826,20 +6826,6 @@ static void do_code_gen(CodeGen *g) {
68266826 get_ptr_align(g, ptr_type));
68276827 }
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
68436829 ZigType *import = get_scope_import(&fn_table_entry->fndef_scope->base);
68446830
68456831 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_
181181static ConstExprValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAllowed undef_allowed);
182182static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_global_refs);
183183static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align);
184static void ir_add_alloca(IrAnalyze *ira, IrInstruction *instruction, ZigType *type_entry);
185184static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,
186185 ZigType *ptr_type);
187186static 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
1049710496 }
1049810497}
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
1050910499static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_global_refs) {
1051010500 ConstGlobalRefs *global_refs = dest->global_refs;
1051110501 assert(!same_global_refs || src->global_refs != nullptr);
......@@ -10631,7 +10621,7 @@ static IrInstruction *ir_const(IrAnalyze *ira, IrInstruction *old_instruction, Z
1063110621}
1063210622
1063310623static 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)
1063510625{
1063610626 if (instr_is_comptime(value) || !type_has_bits(wanted_type)) {
1063710627 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
......@@ -10644,9 +10634,6 @@ static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_inst
1064410634 } else {
1064510635 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node, wanted_type, value, cast_op);
1064610636 result->value.type = wanted_type;
10647 if (need_alloca) {
10648 ir_add_alloca(ira, result, wanted_type);
10649 }
1065010637 return result;
1065110638 }
1065210639}
......@@ -12121,7 +12108,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1212112108 if (const_cast_result.id == ConstCastResultIdInvalid)
1212212109 return ira->codegen->invalid_instruction;
1212312110 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);
1212512112 }
1212612113
1212712114 // cast from T to ?T
......@@ -20752,7 +20739,7 @@ static IrInstruction *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstru
2075220739 } else {
2075320740 op = CastOpNumLitToConcrete;
2075420741 }
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);
2075620743 } else {
2075720744 return ira->codegen->invalid_instruction;
2075820745 }
......@@ -20975,7 +20962,7 @@ static IrInstruction *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInst
2097520962 return ira->codegen->invalid_instruction;
2097620963 }
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);
2097920966}
2098020967
2098120968static 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
2099720984 return ira->codegen->invalid_instruction;
2099820985 }
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);
2100120988}
2100220989
2100320990static 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
2104921036 }
2105021037
2105121038 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);
2105321040}
2105421041
2105521042static IrInstruction *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstructionIntType *instruction) {