Commit d504318f2e

Andrew Kelley <andrew@ziglang.org>
2019-06-11 05:54:28
remove the final legacy stack allocation
1 parent f6d4e25
src/all_types.hpp
@@ -1369,7 +1369,6 @@ struct ZigFn {
     AstNode *fn_no_inline_set_node;
     AstNode *fn_static_eval_set_node;
 
-    ZigList<IrInstruction *> alloca_list;
     ZigList<IrInstructionAllocaGen *> alloca_gen_list;
     ZigList<ZigVar *> variable_list;
 
@@ -2635,7 +2634,6 @@ struct IrInstructionCast {
     IrInstruction *value;
     ZigType *dest_type;
     CastOp cast_op;
-    LLVMValueRef tmp_ptr;
 };
 
 struct IrInstructionResizeSlice {
src/codegen.cpp
@@ -6826,20 +6826,6 @@ static void do_code_gen(CodeGen *g) {
                     get_ptr_align(g, ptr_type));
         }
 
-        for (size_t alloca_i = 0; alloca_i < fn_table_entry->alloca_list.length; alloca_i += 1) {
-            IrInstruction *instruction = fn_table_entry->alloca_list.at(alloca_i);
-            LLVMValueRef *slot;
-            ZigType *slot_type = instruction->value.type;
-            uint32_t alignment_bytes = 0;
-            if (instruction->id == IrInstructionIdCast) {
-                IrInstructionCast *cast_instruction = (IrInstructionCast *)instruction;
-                slot = &cast_instruction->tmp_ptr;
-            } else {
-                zig_unreachable();
-            }
-            *slot = build_alloca(g, slot_type, "", alignment_bytes);
-        }
-
         ZigType *import = get_scope_import(&fn_table_entry->fndef_scope->base);
 
         unsigned gen_i_init = want_first_arg_sret(g, fn_type_id) ? 1 : 0;
src/ir.cpp
@@ -181,7 +181,6 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_
 static ConstExprValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAllowed undef_allowed);
 static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_global_refs);
 static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align);
-static void ir_add_alloca(IrAnalyze *ira, IrInstruction *instruction, ZigType *type_entry);
 static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,
         ZigType *ptr_type);
 static 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
     }
 }
 
-static void ir_add_alloca(IrAnalyze *ira, IrInstruction *instruction, ZigType *type_entry) {
-    if (type_has_bits(type_entry) && handle_is_ptr(type_entry)) {
-        ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
-        if (fn_entry != nullptr) {
-            fn_entry->alloca_list.append(instruction);
-        }
-    }
-}
-
 static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_global_refs) {
     ConstGlobalRefs *global_refs = dest->global_refs;
     assert(!same_global_refs || src->global_refs != nullptr);
@@ -10631,7 +10621,7 @@ static IrInstruction *ir_const(IrAnalyze *ira, IrInstruction *old_instruction, Z
 }
 
 static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,
-        ZigType *wanted_type, CastOp cast_op, bool need_alloca)
+        ZigType *wanted_type, CastOp cast_op)
 {
     if (instr_is_comptime(value) || !type_has_bits(wanted_type)) {
         IrInstruction *result = ir_const(ira, source_instr, wanted_type);
@@ -10644,9 +10634,6 @@ static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_inst
     } else {
         IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node, wanted_type, value, cast_op);
         result->value.type = wanted_type;
-        if (need_alloca) {
-            ir_add_alloca(ira, result, wanted_type);
-        }
         return result;
     }
 }
@@ -12121,7 +12108,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
     if (const_cast_result.id == ConstCastResultIdInvalid)
         return ira->codegen->invalid_instruction;
     if (const_cast_result.id == ConstCastResultIdOk) {
-        return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpNoop, false);
+        return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpNoop);
     }
 
     // cast from T to ?T
@@ -20752,7 +20739,7 @@ static IrInstruction *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstru
             } else {
                 op = CastOpNumLitToConcrete;
             }
-            return ir_resolve_cast(ira, &instruction->base, target, dest_type, op, false);
+            return ir_resolve_cast(ira, &instruction->base, target, dest_type, op);
         } else {
             return ira->codegen->invalid_instruction;
         }
@@ -20975,7 +20962,7 @@ static IrInstruction *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInst
         return ira->codegen->invalid_instruction;
     }
 
-    return ir_resolve_cast(ira, &instruction->base, target, dest_type, CastOpIntToFloat, false);
+    return ir_resolve_cast(ira, &instruction->base, target, dest_type, CastOpIntToFloat);
 }
 
 static 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
         return ira->codegen->invalid_instruction;
     }
 
-    return ir_resolve_cast(ira, &instruction->base, target, dest_type, CastOpFloatToInt, false);
+    return ir_resolve_cast(ira, &instruction->base, target, dest_type, CastOpFloatToInt);
 }
 
 static 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
     }
 
     ZigType *u1_type = get_int_type(ira->codegen, false, 1);
-    return ir_resolve_cast(ira, &instruction->base, target, u1_type, CastOpBoolToInt, false);
+    return ir_resolve_cast(ira, &instruction->base, target, u1_type, CastOpBoolToInt);
 }
 
 static IrInstruction *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstructionIntType *instruction) {
BRANCH_TODO
@@ -4,7 +4,4 @@ Scratch pad for stuff to do before merging master
 look at all the ir_gen_node ir_gen_node_extra calls and make sure result locations are properly propagated
             return ir_gen_comptime(irb, scope, node, lval);
 
-migrate all the alloca_list to alloca_gen_list
-
 comptime expressions
-