authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-27 18:40:47-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-28 12:58:40-07:00
logb11ac9c5bfb4048eb4aa561f8b3b058a76787f7e
tree53ac787d868ca852bbbf854b829dfd3e4296cd8c
parente072ace436e3bfda18cde71492380f863e51cc61

stage1: move some mutable state from Stage1Zir to IrAnalyze

This is progress towards making Stage1Zir immutable, so that we can avoid generating it for every comptime function call. Also rename IrExecutableGen to Stage1Air.

9 files changed, 157 insertions(+), 178 deletions(-)

src/stage1/all_types.hpp+5-14
......@@ -51,7 +51,7 @@ struct ResultLocPeerParent;
5151struct ResultLocBitCast;
5252struct ResultLocCast;
5353struct ResultLocReturn;
54struct IrExecutableGen;
54struct Stage1Air;
5555
5656enum FileExt {
5757 FileExtUnknown,
......@@ -116,19 +116,14 @@ struct Stage1Zir {
116116 ZigFn *name_fn;
117117 size_t mem_slot_count;
118118 size_t next_debug_id;
119 size_t *backward_branch_count;
120 size_t *backward_branch_quota;
121119 ZigFn *fn_entry;
122120 Buf *c_import_buf;
123121 AstNode *source_node;
124 IrExecutableGen *parent_exec;
125 IrAnalyze *analysis;
126122 Scope *begin_scope;
127123 ErrorMsg *first_err_trace_msg;
128124 ZigList<Tld *> tld_list;
129125
130126 bool is_inline;
131 bool is_generic_instantiation;
132127 bool need_err_code_spill;
133128
134129 // This is a function for use in the debugger to print
......@@ -136,25 +131,22 @@ struct Stage1Zir {
136131 void src();
137132};
138133
139struct IrExecutableGen {
134struct Stage1Air {
140135 ZigList<IrBasicBlockGen *> basic_block_list;
141136 Buf *name;
142137 ZigFn *name_fn;
143138 size_t mem_slot_count;
144139 size_t next_debug_id;
145 size_t *backward_branch_count;
146 size_t *backward_branch_quota;
147140 ZigFn *fn_entry;
148141 Buf *c_import_buf;
149142 AstNode *source_node;
150 IrExecutableGen *parent_exec;
143 Stage1Air *parent_exec;
151144 Stage1Zir *source_exec;
152145 Scope *begin_scope;
153146 ErrorMsg *first_err_trace_msg;
154147 ZigList<Tld *> tld_list;
155148
156149 bool is_inline;
157 bool is_generic_instantiation;
158150 bool need_err_code_spill;
159151
160152 // This is a function for use in the debugger to print
......@@ -1652,9 +1644,8 @@ struct ZigFn {
16521644 // zig source code, not according to zig ir
16531645 ZigType *src_implicit_return_type;
16541646 Stage1Zir *ir_executable;
1655 IrExecutableGen analyzed_executable;
1656 size_t prealloc_bbc;
1657 size_t prealloc_backward_branch_quota;
1647 Stage1Air analyzed_executable;
1648 size_t branch_quota;
16581649 AstNode **param_source_nodes;
16591650 Buf **param_names;
16601651 IrInstGen *err_code_spill;
src/stage1/analyze.cpp+7-11
......@@ -3655,10 +3655,6 @@ static ZigFn *create_fn_raw(CodeGen *g, bool is_noinline) {
36553655 ZigFn *fn_entry = heap::c_allocator.create<ZigFn>();
36563656 fn_entry->ir_executable = heap::c_allocator.create<Stage1Zir>();
36573657
3658 fn_entry->prealloc_backward_branch_quota = default_backward_branch_quota;
3659
3660 fn_entry->analyzed_executable.backward_branch_count = &fn_entry->prealloc_bbc;
3661 fn_entry->analyzed_executable.backward_branch_quota = &fn_entry->prealloc_backward_branch_quota;
36623658 fn_entry->analyzed_executable.fn_entry = fn_entry;
36633659 fn_entry->ir_executable->fn_entry = fn_entry;
36643660 fn_entry->is_noinline = is_noinline;
......@@ -5134,8 +5130,11 @@ static void analyze_fn_ir(CodeGen *g, ZigFn *fn, AstNode *return_type_node) {
51345130 if (fn->analyzed_executable.source_node == nullptr) {
51355131 fn->analyzed_executable.source_node = fn->body_node;
51365132 }
5137 ZigType *block_return_type = ir_analyze(g, fn->ir_executable,
5138 &fn->analyzed_executable, fn_type_id->return_type, return_type_node, nullptr);
5133 size_t backward_branch_count = 0;
5134 size_t backward_branch_quota = max(fn->branch_quota, default_backward_branch_quota);
5135 ZigType *block_return_type = ir_analyze(g, fn->ir_executable, &fn->analyzed_executable,
5136 &backward_branch_count, &backward_branch_quota,
5137 fn_type_id->return_type, return_type_node, nullptr);
51395138 fn->src_implicit_return_type = block_return_type;
51405139
51415140 if (type_is_invalid(block_return_type) || fn->analyzed_executable.first_err_trace_msg != nullptr) {
......@@ -9866,13 +9865,10 @@ void Stage1Zir::src() {
98669865 if (this->source_node != nullptr) {
98679866 this->source_node->src();
98689867 }
9869 if (this->parent_exec != nullptr) {
9870 this->parent_exec->src();
9871 }
98729868}
98739869
9874void IrExecutableGen::src() {
9875 IrExecutableGen *it;
9870void Stage1Air::src() {
9871 Stage1Air *it;
98769872 for (it = this; it != nullptr && it->source_node != nullptr; it = it->parent_exec) {
98779873 it->source_node->src();
98789874 }
src/stage1/astgen.cpp+1-11
......@@ -41,19 +41,9 @@ static void ir_assert_impl(bool ok, IrInst *source_instruction, char const *file
4141 src_assert_impl(ok, source_instruction->source_node, file, line);
4242}
4343
44static void ir_add_call_stack_errors(CodeGen *codegen, Stage1Zir *exec, ErrorMsg *err_msg, int limit) {
45 if (!exec || !exec->source_node || limit < 0) return;
46 add_error_note(codegen, err_msg, exec->source_node, buf_sprintf("called from here"));
47
48 ir_add_call_stack_errors_gen(codegen, exec->parent_exec, err_msg, limit - 1);
49}
50
5144static ErrorMsg *exec_add_error_node(CodeGen *codegen, Stage1Zir *exec, AstNode *source_node, Buf *msg) {
5245 ErrorMsg *err_msg = add_node_error(codegen, source_node, msg);
5346 invalidate_exec(exec, err_msg);
54 if (exec->parent_exec) {
55 ir_add_call_stack_errors(codegen, exec, err_msg, 10);
56 }
5747 return err_msg;
5848}
5949
......@@ -8118,7 +8108,7 @@ AstNode *ast_field_to_symbol_node(AstNode *err_set_field_node) {
81188108 }
81198109}
81208110
8121void ir_add_call_stack_errors_gen(CodeGen *codegen, IrExecutableGen *exec, ErrorMsg *err_msg, int limit) {
8111void ir_add_call_stack_errors_gen(CodeGen *codegen, Stage1Air *exec, ErrorMsg *err_msg, int limit) {
81228112 if (!exec || !exec->source_node || limit < 0) return;
81238113 add_error_note(codegen, err_msg, exec->source_node, buf_sprintf("called from here"));
81248114
src/stage1/astgen.hpp+1-1
......@@ -24,7 +24,7 @@ ResultLoc *no_result_loc(void);
2424void invalidate_exec(Stage1Zir *exec, ErrorMsg *msg);
2525
2626AstNode *ast_field_to_symbol_node(AstNode *err_set_field_node);
27void ir_add_call_stack_errors_gen(CodeGen *codegen, IrExecutableGen *exec, ErrorMsg *err_msg,
27void ir_add_call_stack_errors_gen(CodeGen *codegen, Stage1Air *exec, ErrorMsg *err_msg,
2828 int limit);
2929
3030void destroy_instruction_src(IrInstSrc *inst);
src/stage1/codegen.cpp+91-91
......@@ -2443,7 +2443,7 @@ static LLVMValueRef get_merge_err_ret_traces_fn_val(CodeGen *g) {
24432443 return fn_val;
24442444
24452445}
2446static LLVMValueRef ir_render_save_err_ret_addr(CodeGen *g, IrExecutableGen *executable,
2446static LLVMValueRef ir_render_save_err_ret_addr(CodeGen *g, Stage1Air *executable,
24472447 IrInstGenSaveErrRetAddr *save_err_ret_addr_instruction)
24482448{
24492449 assert(g->have_err_ret_tracing);
......@@ -2636,7 +2636,7 @@ static void gen_async_return(CodeGen *g, IrInstGenReturn *instruction) {
26362636 LLVMBuildRetVoid(g->builder);
26372637}
26382638
2639static LLVMValueRef ir_render_return(CodeGen *g, IrExecutableGen *executable, IrInstGenReturn *instruction) {
2639static LLVMValueRef ir_render_return(CodeGen *g, Stage1Air *executable, IrInstGenReturn *instruction) {
26402640 if (fn_is_async(g->cur_fn)) {
26412641 gen_async_return(g, instruction);
26422642 return nullptr;
......@@ -3061,7 +3061,7 @@ static void gen_shift_rhs_check(CodeGen *g, ZigType *lhs_type, ZigType *rhs_type
30613061 }
30623062}
30633063
3064static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutableGen *executable,
3064static LLVMValueRef ir_render_bin_op(CodeGen *g, Stage1Air *executable,
30653065 IrInstGenBinOp *bin_op_instruction)
30663066{
30673067 IrBinOp op_id = bin_op_instruction->op_id;
......@@ -3283,7 +3283,7 @@ static void add_error_range_check(CodeGen *g, ZigType *err_set_type, ZigType *in
32833283 }
32843284}
32853285
3286static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutableGen *executable,
3286static LLVMValueRef ir_render_cast(CodeGen *g, Stage1Air *executable,
32873287 IrInstGenCast *cast_instruction)
32883288{
32893289 Error err;
......@@ -3367,7 +3367,7 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutableGen *executable,
33673367 zig_unreachable();
33683368}
33693369
3370static LLVMValueRef ir_render_ptr_of_array_to_slice(CodeGen *g, IrExecutableGen *executable,
3370static LLVMValueRef ir_render_ptr_of_array_to_slice(CodeGen *g, Stage1Air *executable,
33713371 IrInstGenPtrOfArrayToSlice *instruction)
33723372{
33733373 ZigType *actual_type = instruction->operand->value->type;
......@@ -3404,7 +3404,7 @@ static LLVMValueRef ir_render_ptr_of_array_to_slice(CodeGen *g, IrExecutableGen
34043404 return result_loc;
34053405}
34063406
3407static LLVMValueRef ir_render_ptr_cast(CodeGen *g, IrExecutableGen *executable,
3407static LLVMValueRef ir_render_ptr_cast(CodeGen *g, Stage1Air *executable,
34083408 IrInstGenPtrCast *instruction)
34093409{
34103410 ZigType *wanted_type = instruction->base.value->type;
......@@ -3430,7 +3430,7 @@ static LLVMValueRef ir_render_ptr_cast(CodeGen *g, IrExecutableGen *executable,
34303430 return result_ptr;
34313431}
34323432
3433static LLVMValueRef ir_render_bit_cast(CodeGen *g, IrExecutableGen *executable,
3433static LLVMValueRef ir_render_bit_cast(CodeGen *g, Stage1Air *executable,
34343434 IrInstGenBitCast *instruction)
34353435{
34363436 ZigType *wanted_type = instruction->base.value->type;
......@@ -3458,7 +3458,7 @@ static LLVMValueRef ir_render_bit_cast(CodeGen *g, IrExecutableGen *executable,
34583458 }
34593459}
34603460
3461static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, IrExecutableGen *executable,
3461static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, Stage1Air *executable,
34623462 IrInstGenWidenOrShorten *instruction)
34633463{
34643464 ZigType *actual_type = instruction->target->value->type;
......@@ -3475,7 +3475,7 @@ static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, IrExecutableGen *exec
34753475 instruction->base.value->type, target_val);
34763476}
34773477
3478static LLVMValueRef ir_render_int_to_ptr(CodeGen *g, IrExecutableGen *executable, IrInstGenIntToPtr *instruction) {
3478static LLVMValueRef ir_render_int_to_ptr(CodeGen *g, Stage1Air *executable, IrInstGenIntToPtr *instruction) {
34793479 ZigType *wanted_type = instruction->base.value->type;
34803480 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
34813481 const uint32_t align_bytes = get_ptr_align(g, wanted_type);
......@@ -3513,13 +3513,13 @@ static LLVMValueRef ir_render_int_to_ptr(CodeGen *g, IrExecutableGen *executable
35133513 return LLVMBuildIntToPtr(g->builder, target_val, get_llvm_type(g, wanted_type), "");
35143514}
35153515
3516static LLVMValueRef ir_render_ptr_to_int(CodeGen *g, IrExecutableGen *executable, IrInstGenPtrToInt *instruction) {
3516static LLVMValueRef ir_render_ptr_to_int(CodeGen *g, Stage1Air *executable, IrInstGenPtrToInt *instruction) {
35173517 ZigType *wanted_type = instruction->base.value->type;
35183518 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
35193519 return LLVMBuildPtrToInt(g->builder, target_val, get_llvm_type(g, wanted_type), "");
35203520}
35213521
3522static LLVMValueRef ir_render_int_to_enum(CodeGen *g, IrExecutableGen *executable, IrInstGenIntToEnum *instruction) {
3522static LLVMValueRef ir_render_int_to_enum(CodeGen *g, Stage1Air *executable, IrInstGenIntToEnum *instruction) {
35233523 ZigType *wanted_type = instruction->base.value->type;
35243524 assert(wanted_type->id == ZigTypeIdEnum);
35253525 ZigType *tag_int_type = wanted_type->data.enumeration.tag_int_type;
......@@ -3559,7 +3559,7 @@ static LLVMValueRef ir_render_int_to_enum(CodeGen *g, IrExecutableGen *executabl
35593559 return tag_int_value;
35603560}
35613561
3562static LLVMValueRef ir_render_int_to_err(CodeGen *g, IrExecutableGen *executable, IrInstGenIntToErr *instruction) {
3562static LLVMValueRef ir_render_int_to_err(CodeGen *g, Stage1Air *executable, IrInstGenIntToErr *instruction) {
35633563 ZigType *wanted_type = instruction->base.value->type;
35643564 assert(wanted_type->id == ZigTypeIdErrorSet);
35653565
......@@ -3576,7 +3576,7 @@ static LLVMValueRef ir_render_int_to_err(CodeGen *g, IrExecutableGen *executable
35763576 return gen_widen_or_shorten(g, false, actual_type, g->err_tag_type, target_val);
35773577}
35783578
3579static LLVMValueRef ir_render_err_to_int(CodeGen *g, IrExecutableGen *executable, IrInstGenErrToInt *instruction) {
3579static LLVMValueRef ir_render_err_to_int(CodeGen *g, Stage1Air *executable, IrInstGenErrToInt *instruction) {
35803580 ZigType *wanted_type = instruction->base.value->type;
35813581 assert(wanted_type->id == ZigTypeIdInt);
35823582 assert(!wanted_type->data.integral.is_signed);
......@@ -3602,7 +3602,7 @@ static LLVMValueRef ir_render_err_to_int(CodeGen *g, IrExecutableGen *executable
36023602 }
36033603}
36043604
3605static LLVMValueRef ir_render_unreachable(CodeGen *g, IrExecutableGen *executable,
3605static LLVMValueRef ir_render_unreachable(CodeGen *g, Stage1Air *executable,
36063606 IrInstGenUnreachable *unreachable_instruction)
36073607{
36083608 if (ir_want_runtime_safety(g, &unreachable_instruction->base)) {
......@@ -3613,7 +3613,7 @@ static LLVMValueRef ir_render_unreachable(CodeGen *g, IrExecutableGen *executabl
36133613 return nullptr;
36143614}
36153615
3616static LLVMValueRef ir_render_cond_br(CodeGen *g, IrExecutableGen *executable,
3616static LLVMValueRef ir_render_cond_br(CodeGen *g, Stage1Air *executable,
36173617 IrInstGenCondBr *cond_br_instruction)
36183618{
36193619 LLVMBuildCondBr(g->builder,
......@@ -3623,12 +3623,12 @@ static LLVMValueRef ir_render_cond_br(CodeGen *g, IrExecutableGen *executable,
36233623 return nullptr;
36243624}
36253625
3626static LLVMValueRef ir_render_br(CodeGen *g, IrExecutableGen *executable, IrInstGenBr *br_instruction) {
3626static LLVMValueRef ir_render_br(CodeGen *g, Stage1Air *executable, IrInstGenBr *br_instruction) {
36273627 LLVMBuildBr(g->builder, br_instruction->dest_block->llvm_block);
36283628 return nullptr;
36293629}
36303630
3631static LLVMValueRef ir_render_binary_not(CodeGen *g, IrExecutableGen *executable,
3631static LLVMValueRef ir_render_binary_not(CodeGen *g, Stage1Air *executable,
36323632 IrInstGenBinaryNot *inst)
36333633{
36343634 LLVMValueRef operand = ir_llvm_value(g, inst->operand);
......@@ -3660,13 +3660,13 @@ static LLVMValueRef ir_gen_negation(CodeGen *g, IrInstGen *inst, IrInstGen *oper
36603660 }
36613661}
36623662
3663static LLVMValueRef ir_render_negation(CodeGen *g, IrExecutableGen *executable,
3663static LLVMValueRef ir_render_negation(CodeGen *g, Stage1Air *executable,
36643664 IrInstGenNegation *inst)
36653665{
36663666 return ir_gen_negation(g, &inst->base, inst->operand, inst->wrapping);
36673667}
36683668
3669static LLVMValueRef ir_render_bool_not(CodeGen *g, IrExecutableGen *executable, IrInstGenBoolNot *instruction) {
3669static LLVMValueRef ir_render_bool_not(CodeGen *g, Stage1Air *executable, IrInstGenBoolNot *instruction) {
36703670 LLVMValueRef value = ir_llvm_value(g, instruction->value);
36713671 LLVMValueRef zero = LLVMConstNull(LLVMTypeOf(value));
36723672 return LLVMBuildICmp(g->builder, LLVMIntEQ, value, zero, "");
......@@ -3680,14 +3680,14 @@ static void render_decl_var(CodeGen *g, ZigVar *var) {
36803680 gen_var_debug_decl(g, var);
36813681}
36823682
3683static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutableGen *executable, IrInstGenDeclVar *instruction) {
3683static LLVMValueRef ir_render_decl_var(CodeGen *g, Stage1Air *executable, IrInstGenDeclVar *instruction) {
36843684 instruction->var->ptr_instruction = instruction->var_ptr;
36853685 instruction->var->did_the_decl_codegen = true;
36863686 render_decl_var(g, instruction->var);
36873687 return nullptr;
36883688}
36893689
3690static LLVMValueRef ir_render_load_ptr(CodeGen *g, IrExecutableGen *executable,
3690static LLVMValueRef ir_render_load_ptr(CodeGen *g, Stage1Air *executable,
36913691 IrInstGenLoadPtr *instruction)
36923692{
36933693 ZigType *child_type = instruction->base.value->type;
......@@ -3889,7 +3889,7 @@ static void gen_undef_init(CodeGen *g, ZigType *ptr_type, ZigType *value_type, L
38893889 gen_assign_raw(g, ptr, ptr_type, zero);
38903890}
38913891
3892static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutableGen *executable, IrInstGenStorePtr *instruction) {
3892static LLVMValueRef ir_render_store_ptr(CodeGen *g, Stage1Air *executable, IrInstGenStorePtr *instruction) {
38933893 Error err;
38943894
38953895 ZigType *ptr_type = instruction->ptr->value->type;
......@@ -3921,7 +3921,7 @@ static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutableGen *executable,
39213921 return nullptr;
39223922}
39233923
3924static LLVMValueRef ir_render_vector_store_elem(CodeGen *g, IrExecutableGen *executable,
3924static LLVMValueRef ir_render_vector_store_elem(CodeGen *g, Stage1Air *executable,
39253925 IrInstGenVectorStoreElem *instruction)
39263926{
39273927 LLVMValueRef vector_ptr = ir_llvm_value(g, instruction->vector_ptr);
......@@ -3934,7 +3934,7 @@ static LLVMValueRef ir_render_vector_store_elem(CodeGen *g, IrExecutableGen *exe
39343934 return nullptr;
39353935}
39363936
3937static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutableGen *executable, IrInstGenVarPtr *instruction) {
3937static LLVMValueRef ir_render_var_ptr(CodeGen *g, Stage1Air *executable, IrInstGenVarPtr *instruction) {
39383938 Error err;
39393939
39403940 ZigType *ptr_type = instruction->base.value->type;
......@@ -3961,7 +3961,7 @@ static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutableGen *executable, I
39613961 get_llvm_type(g, ptr_type), "");
39623962}
39633963
3964static LLVMValueRef ir_render_return_ptr(CodeGen *g, IrExecutableGen *executable,
3964static LLVMValueRef ir_render_return_ptr(CodeGen *g, Stage1Air *executable,
39653965 IrInstGenReturnPtr *instruction)
39663966{
39673967 if (!type_has_bits(g, instruction->base.value->type))
......@@ -3970,7 +3970,7 @@ static LLVMValueRef ir_render_return_ptr(CodeGen *g, IrExecutableGen *executable
39703970 return g->cur_ret_ptr;
39713971}
39723972
3973static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutableGen *executable, IrInstGenElemPtr *instruction) {
3973static LLVMValueRef ir_render_elem_ptr(CodeGen *g, Stage1Air *executable, IrInstGenElemPtr *instruction) {
39743974 LLVMValueRef array_ptr_ptr = ir_llvm_value(g, instruction->array_ptr);
39753975 ZigType *array_ptr_type = instruction->array_ptr->value->type;
39763976 assert(array_ptr_type->id == ZigTypeIdPointer);
......@@ -4222,7 +4222,7 @@ static void gen_init_stack_trace(CodeGen *g, LLVMValueRef trace_field_ptr, LLVMV
42224222 LLVMBuildStore(g->builder, LLVMConstInt(usize_type_ref, stack_trace_ptr_count, false), addrs_len_ptr);
42234223}
42244224
4225static LLVMValueRef ir_render_call(CodeGen *g, IrExecutableGen *executable, IrInstGenCall *instruction) {
4225static LLVMValueRef ir_render_call(CodeGen *g, Stage1Air *executable, IrInstGenCall *instruction) {
42264226 Error err;
42274227
42284228 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;
......@@ -4642,7 +4642,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutableGen *executable, IrIn
46424642 }
46434643}
46444644
4645static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutableGen *executable,
4645static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, Stage1Air *executable,
46464646 IrInstGenStructFieldPtr *instruction)
46474647{
46484648 Error err;
......@@ -4693,7 +4693,7 @@ static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutableGen *exec
46934693 return field_ptr_val;
46944694}
46954695
4696static LLVMValueRef ir_render_union_field_ptr(CodeGen *g, IrExecutableGen *executable,
4696static LLVMValueRef ir_render_union_field_ptr(CodeGen *g, Stage1Air *executable,
46974697 IrInstGenUnionFieldPtr *instruction)
46984698{
46994699 if (instruction->base.value->special != ConstValSpecialRuntime)
......@@ -4793,7 +4793,7 @@ static size_t find_asm_index(CodeGen *g, AstNode *node, AsmToken *tok, Buf *src_
47934793 return SIZE_MAX;
47944794}
47954795
4796static LLVMValueRef ir_render_asm_gen(CodeGen *g, IrExecutableGen *executable, IrInstGenAsm *instruction) {
4796static LLVMValueRef ir_render_asm_gen(CodeGen *g, Stage1Air *executable, IrInstGenAsm *instruction) {
47974797 AstNode *asm_node = instruction->base.base.source_node;
47984798 assert(asm_node->type == NodeTypeAsmExpr);
47994799 AstNodeAsmExpr *asm_expr = &asm_node->data.asm_expr;
......@@ -4970,13 +4970,13 @@ static LLVMValueRef gen_non_null_bit(CodeGen *g, ZigType *maybe_type, LLVMValueR
49704970 return gen_load_untyped(g, maybe_field_ptr, 0, false, "");
49714971}
49724972
4973static LLVMValueRef ir_render_test_non_null(CodeGen *g, IrExecutableGen *executable,
4973static LLVMValueRef ir_render_test_non_null(CodeGen *g, Stage1Air *executable,
49744974 IrInstGenTestNonNull *instruction)
49754975{
49764976 return gen_non_null_bit(g, instruction->value->value->type, ir_llvm_value(g, instruction->value));
49774977}
49784978
4979static LLVMValueRef ir_render_optional_unwrap_ptr(CodeGen *g, IrExecutableGen *executable,
4979static LLVMValueRef ir_render_optional_unwrap_ptr(CodeGen *g, Stage1Air *executable,
49804980 IrInstGenOptionalUnwrapPtr *instruction)
49814981{
49824982 if (instruction->base.value->special != ConstValSpecialRuntime)
......@@ -5083,7 +5083,7 @@ static LLVMValueRef get_int_builtin_fn(CodeGen *g, ZigType *expr_type, BuiltinFn
50835083 return fn_val;
50845084}
50855085
5086static LLVMValueRef ir_render_clz(CodeGen *g, IrExecutableGen *executable, IrInstGenClz *instruction) {
5086static LLVMValueRef ir_render_clz(CodeGen *g, Stage1Air *executable, IrInstGenClz *instruction) {
50875087 ZigType *int_type = instruction->op->value->type;
50885088 LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdClz);
50895089 LLVMValueRef operand = ir_llvm_value(g, instruction->op);
......@@ -5095,7 +5095,7 @@ static LLVMValueRef ir_render_clz(CodeGen *g, IrExecutableGen *executable, IrIns
50955095 return gen_widen_or_shorten(g, false, int_type, instruction->base.value->type, wrong_size_int);
50965096}
50975097
5098static LLVMValueRef ir_render_ctz(CodeGen *g, IrExecutableGen *executable, IrInstGenCtz *instruction) {
5098static LLVMValueRef ir_render_ctz(CodeGen *g, Stage1Air *executable, IrInstGenCtz *instruction) {
50995099 ZigType *int_type = instruction->op->value->type;
51005100 LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdCtz);
51015101 LLVMValueRef operand = ir_llvm_value(g, instruction->op);
......@@ -5107,7 +5107,7 @@ static LLVMValueRef ir_render_ctz(CodeGen *g, IrExecutableGen *executable, IrIns
51075107 return gen_widen_or_shorten(g, false, int_type, instruction->base.value->type, wrong_size_int);
51085108}
51095109
5110static LLVMValueRef ir_render_shuffle_vector(CodeGen *g, IrExecutableGen *executable, IrInstGenShuffleVector *instruction) {
5110static LLVMValueRef ir_render_shuffle_vector(CodeGen *g, Stage1Air *executable, IrInstGenShuffleVector *instruction) {
51115111 uint64_t len_a = instruction->a->value->type->data.vector.len;
51125112 uint64_t len_mask = instruction->mask->value->type->data.vector.len;
51135113
......@@ -5137,7 +5137,7 @@ static LLVMValueRef ir_render_shuffle_vector(CodeGen *g, IrExecutableGen *execut
51375137 llvm_mask_value, "");
51385138}
51395139
5140static LLVMValueRef ir_render_splat(CodeGen *g, IrExecutableGen *executable, IrInstGenSplat *instruction) {
5140static LLVMValueRef ir_render_splat(CodeGen *g, Stage1Air *executable, IrInstGenSplat *instruction) {
51415141 ZigType *result_type = instruction->base.value->type;
51425142 ir_assert(result_type->id == ZigTypeIdVector, &instruction->base);
51435143 uint32_t len = result_type->data.vector.len;
......@@ -5149,7 +5149,7 @@ static LLVMValueRef ir_render_splat(CodeGen *g, IrExecutableGen *executable, IrI
51495149 return LLVMBuildShuffleVector(g->builder, op_vector, undef_vector, LLVMConstNull(mask_llvm_type), "");
51505150}
51515151
5152static LLVMValueRef ir_render_pop_count(CodeGen *g, IrExecutableGen *executable, IrInstGenPopCount *instruction) {
5152static LLVMValueRef ir_render_pop_count(CodeGen *g, Stage1Air *executable, IrInstGenPopCount *instruction) {
51535153 ZigType *int_type = instruction->op->value->type;
51545154 LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdPopCount);
51555155 LLVMValueRef operand = ir_llvm_value(g, instruction->op);
......@@ -5157,7 +5157,7 @@ static LLVMValueRef ir_render_pop_count(CodeGen *g, IrExecutableGen *executable,
51575157 return gen_widen_or_shorten(g, false, int_type, instruction->base.value->type, wrong_size_int);
51585158}
51595159
5160static LLVMValueRef ir_render_switch_br(CodeGen *g, IrExecutableGen *executable, IrInstGenSwitchBr *instruction) {
5160static LLVMValueRef ir_render_switch_br(CodeGen *g, Stage1Air *executable, IrInstGenSwitchBr *instruction) {
51615161 ZigType *target_type = instruction->target_value->value->type;
51625162 LLVMBasicBlockRef else_block = instruction->else_block->llvm_block;
51635163
......@@ -5185,7 +5185,7 @@ static LLVMValueRef ir_render_switch_br(CodeGen *g, IrExecutableGen *executable,
51855185 return nullptr;
51865186}
51875187
5188static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutableGen *executable, IrInstGenPhi *instruction) {
5188static LLVMValueRef ir_render_phi(CodeGen *g, Stage1Air *executable, IrInstGenPhi *instruction) {
51895189 if (!type_has_bits(g, instruction->base.value->type))
51905190 return nullptr;
51915191
......@@ -5209,7 +5209,7 @@ static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutableGen *executable, IrIns
52095209 return phi;
52105210}
52115211
5212static LLVMValueRef ir_render_ref(CodeGen *g, IrExecutableGen *executable, IrInstGenRef *instruction) {
5212static LLVMValueRef ir_render_ref(CodeGen *g, Stage1Air *executable, IrInstGenRef *instruction) {
52135213 if (!type_has_bits(g, instruction->base.value->type)) {
52145214 return nullptr;
52155215 }
......@@ -5229,7 +5229,7 @@ static LLVMValueRef ir_render_ref(CodeGen *g, IrExecutableGen *executable, IrIns
52295229 }
52305230}
52315231
5232static LLVMValueRef ir_render_err_name(CodeGen *g, IrExecutableGen *executable, IrInstGenErrName *instruction) {
5232static LLVMValueRef ir_render_err_name(CodeGen *g, Stage1Air *executable, IrInstGenErrName *instruction) {
52335233 assert(g->generate_error_name_table);
52345234 assert(g->errors_by_index.length > 0);
52355235
......@@ -5356,7 +5356,7 @@ static LLVMValueRef get_enum_tag_name_function(CodeGen *g, ZigType *enum_type) {
53565356 return fn_val;
53575357}
53585358
5359static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, IrExecutableGen *executable,
5359static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, Stage1Air *executable,
53605360 IrInstGenTagName *instruction)
53615361{
53625362 ZigType *enum_type = instruction->target->value->type;
......@@ -5369,7 +5369,7 @@ static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, IrExecutableGen *executa
53695369 get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, "");
53705370}
53715371
5372static LLVMValueRef ir_render_field_parent_ptr(CodeGen *g, IrExecutableGen *executable,
5372static LLVMValueRef ir_render_field_parent_ptr(CodeGen *g, Stage1Air *executable,
53735373 IrInstGenFieldParentPtr *instruction)
53745374{
53755375 ZigType *container_ptr_type = instruction->base.value->type;
......@@ -5396,7 +5396,7 @@ static LLVMValueRef ir_render_field_parent_ptr(CodeGen *g, IrExecutableGen *exec
53965396 }
53975397}
53985398
5399static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutableGen *executable, IrInstGenAlignCast *instruction) {
5399static LLVMValueRef ir_render_align_cast(CodeGen *g, Stage1Air *executable, IrInstGenAlignCast *instruction) {
54005400 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
54015401 assert(target_val);
54025402
......@@ -5459,7 +5459,7 @@ static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutableGen *executable
54595459 return target_val;
54605460}
54615461
5462static LLVMValueRef ir_render_error_return_trace(CodeGen *g, IrExecutableGen *executable,
5462static LLVMValueRef ir_render_error_return_trace(CodeGen *g, Stage1Air *executable,
54635463 IrInstGenErrorReturnTrace *instruction)
54645464{
54655465 bool is_llvm_alloca;
......@@ -5530,7 +5530,7 @@ static LLVMTypeRef get_atomic_abi_type(CodeGen *g, IrInstGen *instruction) {
55305530 }
55315531}
55325532
5533static LLVMValueRef ir_render_cmpxchg(CodeGen *g, IrExecutableGen *executable, IrInstGenCmpxchg *instruction) {
5533static LLVMValueRef ir_render_cmpxchg(CodeGen *g, Stage1Air *executable, IrInstGenCmpxchg *instruction) {
55345534 LLVMValueRef ptr_val = ir_llvm_value(g, instruction->ptr);
55355535 LLVMValueRef cmp_val = ir_llvm_value(g, instruction->cmp_value);
55365536 LLVMValueRef new_val = ir_llvm_value(g, instruction->new_value);
......@@ -5592,7 +5592,7 @@ static LLVMValueRef ir_render_cmpxchg(CodeGen *g, IrExecutableGen *executable, I
55925592 return result_loc;
55935593}
55945594
5595static LLVMValueRef ir_render_reduce(CodeGen *g, IrExecutableGen *executable, IrInstGenReduce *instruction) {
5595static LLVMValueRef ir_render_reduce(CodeGen *g, Stage1Air *executable, IrInstGenReduce *instruction) {
55965596 LLVMValueRef value = ir_llvm_value(g, instruction->value);
55975597
55985598 ZigType *value_type = instruction->value->value->type;
......@@ -5656,13 +5656,13 @@ static LLVMValueRef ir_render_reduce(CodeGen *g, IrExecutableGen *executable, Ir
56565656 return result_val;
56575657}
56585658
5659static LLVMValueRef ir_render_fence(CodeGen *g, IrExecutableGen *executable, IrInstGenFence *instruction) {
5659static LLVMValueRef ir_render_fence(CodeGen *g, Stage1Air *executable, IrInstGenFence *instruction) {
56605660 LLVMAtomicOrdering atomic_order = to_LLVMAtomicOrdering(instruction->order);
56615661 LLVMBuildFence(g->builder, atomic_order, false, "");
56625662 return nullptr;
56635663}
56645664
5665static LLVMValueRef ir_render_truncate(CodeGen *g, IrExecutableGen *executable, IrInstGenTruncate *instruction) {
5665static LLVMValueRef ir_render_truncate(CodeGen *g, Stage1Air *executable, IrInstGenTruncate *instruction) {
56665666 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
56675667 ZigType *dest_type = instruction->base.value->type;
56685668 ZigType *src_type = instruction->target->value->type;
......@@ -5677,7 +5677,7 @@ static LLVMValueRef ir_render_truncate(CodeGen *g, IrExecutableGen *executable,
56775677 }
56785678}
56795679
5680static LLVMValueRef ir_render_memset(CodeGen *g, IrExecutableGen *executable, IrInstGenMemset *instruction) {
5680static LLVMValueRef ir_render_memset(CodeGen *g, Stage1Air *executable, IrInstGenMemset *instruction) {
56815681 LLVMValueRef dest_ptr = ir_llvm_value(g, instruction->dest_ptr);
56825682 LLVMValueRef len_val = ir_llvm_value(g, instruction->count);
56835683
......@@ -5707,7 +5707,7 @@ static LLVMValueRef ir_render_memset(CodeGen *g, IrExecutableGen *executable, Ir
57075707 return nullptr;
57085708}
57095709
5710static LLVMValueRef ir_render_memcpy(CodeGen *g, IrExecutableGen *executable, IrInstGenMemcpy *instruction) {
5710static LLVMValueRef ir_render_memcpy(CodeGen *g, Stage1Air *executable, IrInstGenMemcpy *instruction) {
57115711 LLVMValueRef dest_ptr = ir_llvm_value(g, instruction->dest_ptr);
57125712 LLVMValueRef src_ptr = ir_llvm_value(g, instruction->src_ptr);
57135713 LLVMValueRef len_val = ir_llvm_value(g, instruction->count);
......@@ -5729,14 +5729,14 @@ static LLVMValueRef ir_render_memcpy(CodeGen *g, IrExecutableGen *executable, Ir
57295729 return nullptr;
57305730}
57315731
5732static LLVMValueRef ir_render_wasm_memory_size(CodeGen *g, IrExecutableGen *executable, IrInstGenWasmMemorySize *instruction) {
5732static LLVMValueRef ir_render_wasm_memory_size(CodeGen *g, Stage1Air *executable, IrInstGenWasmMemorySize *instruction) {
57335733 // TODO adjust for wasm64
57345734 LLVMValueRef param = ir_llvm_value(g, instruction->index);
57355735 LLVMValueRef val = LLVMBuildCall(g->builder, gen_wasm_memory_size(g), &param, 1, "");
57365736 return val;
57375737}
57385738
5739static LLVMValueRef ir_render_wasm_memory_grow(CodeGen *g, IrExecutableGen *executable, IrInstGenWasmMemoryGrow *instruction) {
5739static LLVMValueRef ir_render_wasm_memory_grow(CodeGen *g, Stage1Air *executable, IrInstGenWasmMemoryGrow *instruction) {
57405740 // TODO adjust for wasm64
57415741 LLVMValueRef params[] = {
57425742 ir_llvm_value(g, instruction->index),
......@@ -5746,7 +5746,7 @@ static LLVMValueRef ir_render_wasm_memory_grow(CodeGen *g, IrExecutableGen *exec
57465746 return val;
57475747}
57485748
5749static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutableGen *executable, IrInstGenSlice *instruction) {
5749static LLVMValueRef ir_render_slice(CodeGen *g, Stage1Air *executable, IrInstGenSlice *instruction) {
57505750 Error err;
57515751
57525752 LLVMValueRef array_ptr_ptr = ir_llvm_value(g, instruction->ptr);
......@@ -5983,12 +5983,12 @@ static LLVMValueRef get_trap_fn_val(CodeGen *g) {
59835983}
59845984
59855985
5986static LLVMValueRef ir_render_breakpoint(CodeGen *g, IrExecutableGen *executable, IrInstGenBreakpoint *instruction) {
5986static LLVMValueRef ir_render_breakpoint(CodeGen *g, Stage1Air *executable, IrInstGenBreakpoint *instruction) {
59875987 LLVMBuildCall(g->builder, get_trap_fn_val(g), nullptr, 0, "");
59885988 return nullptr;
59895989}
59905990
5991static LLVMValueRef ir_render_return_address(CodeGen *g, IrExecutableGen *executable,
5991static LLVMValueRef ir_render_return_address(CodeGen *g, Stage1Air *executable,
59925992 IrInstGenReturnAddress *instruction)
59935993{
59945994 if (target_is_wasm(g->zig_target) && g->zig_target->os != OsEmscripten) {
......@@ -6016,7 +6016,7 @@ static LLVMValueRef get_frame_address_fn_val(CodeGen *g) {
60166016 return g->frame_address_fn_val;
60176017}
60186018
6019static LLVMValueRef ir_render_frame_address(CodeGen *g, IrExecutableGen *executable,
6019static LLVMValueRef ir_render_frame_address(CodeGen *g, Stage1Air *executable,
60206020 IrInstGenFrameAddress *instruction)
60216021{
60226022 LLVMValueRef zero = LLVMConstNull(g->builtin_types.entry_i32->llvm_type);
......@@ -6024,7 +6024,7 @@ static LLVMValueRef ir_render_frame_address(CodeGen *g, IrExecutableGen *executa
60246024 return LLVMBuildPtrToInt(g->builder, ptr_val, g->builtin_types.entry_usize->llvm_type, "");
60256025}
60266026
6027static LLVMValueRef ir_render_handle(CodeGen *g, IrExecutableGen *executable, IrInstGenFrameHandle *instruction) {
6027static LLVMValueRef ir_render_handle(CodeGen *g, Stage1Air *executable, IrInstGenFrameHandle *instruction) {
60286028 return g->cur_frame_ptr;
60296029}
60306030
......@@ -6053,7 +6053,7 @@ static LLVMValueRef render_shl_with_overflow(CodeGen *g, IrInstGenOverflowOp *in
60536053 return overflow_bit;
60546054}
60556055
6056static LLVMValueRef ir_render_overflow_op(CodeGen *g, IrExecutableGen *executable, IrInstGenOverflowOp *instruction) {
6056static LLVMValueRef ir_render_overflow_op(CodeGen *g, Stage1Air *executable, IrInstGenOverflowOp *instruction) {
60576057 AddSubMul add_sub_mul;
60586058 switch (instruction->op) {
60596059 case IrOverflowOpAdd:
......@@ -6091,7 +6091,7 @@ static LLVMValueRef ir_render_overflow_op(CodeGen *g, IrExecutableGen *executabl
60916091 return overflow_bit;
60926092}
60936093
6094static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutableGen *executable, IrInstGenTestErr *instruction) {
6094static LLVMValueRef ir_render_test_err(CodeGen *g, Stage1Air *executable, IrInstGenTestErr *instruction) {
60956095 ZigType *err_union_type = instruction->err_union->value->type;
60966096 ZigType *payload_type = err_union_type->data.error_union.payload_type;
60976097 LLVMValueRef err_union_handle = ir_llvm_value(g, instruction->err_union);
......@@ -6108,7 +6108,7 @@ static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutableGen *executable,
61086108 return LLVMBuildICmp(g->builder, LLVMIntNE, err_val, zero, "");
61096109}
61106110
6111static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutableGen *executable,
6111static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, Stage1Air *executable,
61126112 IrInstGenUnwrapErrCode *instruction)
61136113{
61146114 if (instruction->base.value->special != ConstValSpecialRuntime)
......@@ -6128,7 +6128,7 @@ static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutableGen *execu
61286128 }
61296129}
61306130
6131static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutableGen *executable,
6131static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, Stage1Air *executable,
61326132 IrInstGenUnwrapErrPayload *instruction)
61336133{
61346134 Error err;
......@@ -6197,7 +6197,7 @@ static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutableGen *ex
61976197 }
61986198}
61996199
6200static LLVMValueRef ir_render_optional_wrap(CodeGen *g, IrExecutableGen *executable, IrInstGenOptionalWrap *instruction) {
6200static LLVMValueRef ir_render_optional_wrap(CodeGen *g, Stage1Air *executable, IrInstGenOptionalWrap *instruction) {
62016201 ZigType *wanted_type = instruction->base.value->type;
62026202
62036203 assert(wanted_type->id == ZigTypeIdOptional);
......@@ -6233,7 +6233,7 @@ static LLVMValueRef ir_render_optional_wrap(CodeGen *g, IrExecutableGen *executa
62336233 return result_loc;
62346234}
62356235
6236static LLVMValueRef ir_render_err_wrap_code(CodeGen *g, IrExecutableGen *executable, IrInstGenErrWrapCode *instruction) {
6236static LLVMValueRef ir_render_err_wrap_code(CodeGen *g, Stage1Air *executable, IrInstGenErrWrapCode *instruction) {
62376237 ZigType *wanted_type = instruction->base.value->type;
62386238
62396239 assert(wanted_type->id == ZigTypeIdErrorUnion);
......@@ -6253,7 +6253,7 @@ static LLVMValueRef ir_render_err_wrap_code(CodeGen *g, IrExecutableGen *executa
62536253 return result_loc;
62546254}
62556255
6256static LLVMValueRef ir_render_err_wrap_payload(CodeGen *g, IrExecutableGen *executable, IrInstGenErrWrapPayload *instruction) {
6256static LLVMValueRef ir_render_err_wrap_payload(CodeGen *g, Stage1Air *executable, IrInstGenErrWrapPayload *instruction) {
62576257 ZigType *wanted_type = instruction->base.value->type;
62586258
62596259 assert(wanted_type->id == ZigTypeIdErrorUnion);
......@@ -6284,7 +6284,7 @@ static LLVMValueRef ir_render_err_wrap_payload(CodeGen *g, IrExecutableGen *exec
62846284 return result_loc;
62856285}
62866286
6287static LLVMValueRef ir_render_union_tag(CodeGen *g, IrExecutableGen *executable, IrInstGenUnionTag *instruction) {
6287static LLVMValueRef ir_render_union_tag(CodeGen *g, Stage1Air *executable, IrInstGenUnionTag *instruction) {
62886288 ZigType *union_type = instruction->value->value->type;
62896289
62906290 ZigType *tag_type = union_type->data.unionation.tag_type;
......@@ -6302,14 +6302,14 @@ static LLVMValueRef ir_render_union_tag(CodeGen *g, IrExecutableGen *executable,
63026302 return get_handle_value(g, tag_field_ptr, tag_type, ptr_type);
63036303}
63046304
6305static LLVMValueRef ir_render_panic(CodeGen *g, IrExecutableGen *executable, IrInstGenPanic *instruction) {
6305static LLVMValueRef ir_render_panic(CodeGen *g, Stage1Air *executable, IrInstGenPanic *instruction) {
63066306 bool is_llvm_alloca;
63076307 LLVMValueRef err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.base.scope, &is_llvm_alloca);
63086308 gen_panic(g, ir_llvm_value(g, instruction->msg), err_ret_trace_val, is_llvm_alloca);
63096309 return nullptr;
63106310}
63116311
6312static LLVMValueRef ir_render_atomic_rmw(CodeGen *g, IrExecutableGen *executable,
6312static LLVMValueRef ir_render_atomic_rmw(CodeGen *g, Stage1Air *executable,
63136313 IrInstGenAtomicRmw *instruction)
63146314{
63156315 bool is_signed;
......@@ -6354,7 +6354,7 @@ static LLVMValueRef ir_render_atomic_rmw(CodeGen *g, IrExecutableGen *executable
63546354 return LLVMBuildIntToPtr(g->builder, uncasted_result, get_llvm_type(g, operand_type), "");
63556355}
63566356
6357static LLVMValueRef ir_render_atomic_load(CodeGen *g, IrExecutableGen *executable,
6357static LLVMValueRef ir_render_atomic_load(CodeGen *g, Stage1Air *executable,
63586358 IrInstGenAtomicLoad *instruction)
63596359{
63606360 LLVMAtomicOrdering ordering = to_LLVMAtomicOrdering(instruction->ordering);
......@@ -6375,7 +6375,7 @@ static LLVMValueRef ir_render_atomic_load(CodeGen *g, IrExecutableGen *executabl
63756375 return load_inst;
63766376}
63776377
6378static LLVMValueRef ir_render_atomic_store(CodeGen *g, IrExecutableGen *executable,
6378static LLVMValueRef ir_render_atomic_store(CodeGen *g, Stage1Air *executable,
63796379 IrInstGenAtomicStore *instruction)
63806380{
63816381 LLVMAtomicOrdering ordering = to_LLVMAtomicOrdering(instruction->ordering);
......@@ -6398,13 +6398,13 @@ static LLVMValueRef ir_render_atomic_store(CodeGen *g, IrExecutableGen *executab
63986398 return nullptr;
63996399}
64006400
6401static LLVMValueRef ir_render_float_op(CodeGen *g, IrExecutableGen *executable, IrInstGenFloatOp *instruction) {
6401static LLVMValueRef ir_render_float_op(CodeGen *g, Stage1Air *executable, IrInstGenFloatOp *instruction) {
64026402 LLVMValueRef operand = ir_llvm_value(g, instruction->operand);
64036403 LLVMValueRef fn_val = get_float_fn(g, instruction->base.value->type, ZigLLVMFnIdFloatOp, instruction->fn_id);
64046404 return LLVMBuildCall(g->builder, fn_val, &operand, 1, "");
64056405}
64066406
6407static LLVMValueRef ir_render_mul_add(CodeGen *g, IrExecutableGen *executable, IrInstGenMulAdd *instruction) {
6407static LLVMValueRef ir_render_mul_add(CodeGen *g, Stage1Air *executable, IrInstGenMulAdd *instruction) {
64086408 LLVMValueRef op1 = ir_llvm_value(g, instruction->op1);
64096409 LLVMValueRef op2 = ir_llvm_value(g, instruction->op2);
64106410 LLVMValueRef op3 = ir_llvm_value(g, instruction->op3);
......@@ -6419,7 +6419,7 @@ static LLVMValueRef ir_render_mul_add(CodeGen *g, IrExecutableGen *executable, I
64196419 return LLVMBuildCall(g->builder, fn_val, args, 3, "");
64206420}
64216421
6422static LLVMValueRef ir_render_bswap(CodeGen *g, IrExecutableGen *executable, IrInstGenBswap *instruction) {
6422static LLVMValueRef ir_render_bswap(CodeGen *g, Stage1Air *executable, IrInstGenBswap *instruction) {
64236423 LLVMValueRef op = ir_llvm_value(g, instruction->op);
64246424 ZigType *expr_type = instruction->base.value->type;
64256425 bool is_vector = expr_type->id == ZigTypeIdVector;
......@@ -6453,7 +6453,7 @@ static LLVMValueRef ir_render_bswap(CodeGen *g, IrExecutableGen *executable, IrI
64536453 return LLVMBuildTrunc(g->builder, shifted, get_llvm_type(g, expr_type), "");
64546454}
64556455
6456static LLVMValueRef ir_render_extern(CodeGen *g, IrExecutableGen *executable,
6456static LLVMValueRef ir_render_extern(CodeGen *g, Stage1Air *executable,
64576457 IrInstGenExtern *instruction)
64586458{
64596459 ZigType *expr_type = instruction->base.value->type;
......@@ -6477,7 +6477,7 @@ static LLVMValueRef ir_render_extern(CodeGen *g, IrExecutableGen *executable,
64776477 return LLVMBuildBitCast(g->builder, global_value, get_llvm_type(g, expr_type), "");
64786478}
64796479
6480static LLVMValueRef ir_render_bit_reverse(CodeGen *g, IrExecutableGen *executable, IrInstGenBitReverse *instruction) {
6480static LLVMValueRef ir_render_bit_reverse(CodeGen *g, Stage1Air *executable, IrInstGenBitReverse *instruction) {
64816481 LLVMValueRef op = ir_llvm_value(g, instruction->op);
64826482 ZigType *int_type = instruction->base.value->type;
64836483 assert(int_type->id == ZigTypeIdInt);
......@@ -6485,7 +6485,7 @@ static LLVMValueRef ir_render_bit_reverse(CodeGen *g, IrExecutableGen *executabl
64856485 return LLVMBuildCall(g->builder, fn_val, &op, 1, "");
64866486}
64876487
6488static LLVMValueRef ir_render_vector_to_array(CodeGen *g, IrExecutableGen *executable,
6488static LLVMValueRef ir_render_vector_to_array(CodeGen *g, Stage1Air *executable,
64896489 IrInstGenVectorToArray *instruction)
64906490{
64916491 ZigType *array_type = instruction->base.value->type;
......@@ -6519,7 +6519,7 @@ static LLVMValueRef ir_render_vector_to_array(CodeGen *g, IrExecutableGen *execu
65196519 return result_loc;
65206520}
65216521
6522static LLVMValueRef ir_render_array_to_vector(CodeGen *g, IrExecutableGen *executable,
6522static LLVMValueRef ir_render_array_to_vector(CodeGen *g, Stage1Air *executable,
65236523 IrInstGenArrayToVector *instruction)
65246524{
65256525 ZigType *vector_type = instruction->base.value->type;
......@@ -6556,7 +6556,7 @@ static LLVMValueRef ir_render_array_to_vector(CodeGen *g, IrExecutableGen *execu
65566556 }
65576557}
65586558
6559static LLVMValueRef ir_render_assert_zero(CodeGen *g, IrExecutableGen *executable,
6559static LLVMValueRef ir_render_assert_zero(CodeGen *g, Stage1Air *executable,
65606560 IrInstGenAssertZero *instruction)
65616561{
65626562 LLVMValueRef target = ir_llvm_value(g, instruction->target);
......@@ -6567,7 +6567,7 @@ static LLVMValueRef ir_render_assert_zero(CodeGen *g, IrExecutableGen *executabl
65676567 return nullptr;
65686568}
65696569
6570static LLVMValueRef ir_render_assert_non_null(CodeGen *g, IrExecutableGen *executable,
6570static LLVMValueRef ir_render_assert_non_null(CodeGen *g, Stage1Air *executable,
65716571 IrInstGenAssertNonNull *instruction)
65726572{
65736573 LLVMValueRef target = ir_llvm_value(g, instruction->target);
......@@ -6592,7 +6592,7 @@ static LLVMValueRef ir_render_assert_non_null(CodeGen *g, IrExecutableGen *execu
65926592 return nullptr;
65936593}
65946594
6595static LLVMValueRef ir_render_suspend_begin(CodeGen *g, IrExecutableGen *executable,
6595static LLVMValueRef ir_render_suspend_begin(CodeGen *g, Stage1Air *executable,
65966596 IrInstGenSuspendBegin *instruction)
65976597{
65986598 if (fn_is_async(g->cur_fn)) {
......@@ -6601,7 +6601,7 @@ static LLVMValueRef ir_render_suspend_begin(CodeGen *g, IrExecutableGen *executa
66016601 return nullptr;
66026602}
66036603
6604static LLVMValueRef ir_render_suspend_finish(CodeGen *g, IrExecutableGen *executable,
6604static LLVMValueRef ir_render_suspend_finish(CodeGen *g, Stage1Air *executable,
66056605 IrInstGenSuspendFinish *instruction)
66066606{
66076607 LLVMBuildRetVoid(g->builder);
......@@ -6653,7 +6653,7 @@ static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstGen *source_instr,
66536653 }
66546654}
66556655
6656static LLVMValueRef ir_render_await(CodeGen *g, IrExecutableGen *executable, IrInstGenAwait *instruction) {
6656static LLVMValueRef ir_render_await(CodeGen *g, Stage1Air *executable, IrInstGenAwait *instruction) {
66576657 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;
66586658 LLVMValueRef zero = LLVMConstNull(usize_type_ref);
66596659 LLVMValueRef target_frame_ptr = ir_llvm_value(g, instruction->frame);
......@@ -6740,7 +6740,7 @@ static LLVMValueRef ir_render_await(CodeGen *g, IrExecutableGen *executable, IrI
67406740 return nullptr;
67416741}
67426742
6743static LLVMValueRef ir_render_resume(CodeGen *g, IrExecutableGen *executable, IrInstGenResume *instruction) {
6743static LLVMValueRef ir_render_resume(CodeGen *g, Stage1Air *executable, IrInstGenResume *instruction) {
67446744 LLVMValueRef frame = ir_llvm_value(g, instruction->frame);
67456745 ZigType *frame_type = instruction->frame->value->type;
67466746 assert(frame_type->id == ZigTypeIdAnyFrame);
......@@ -6749,14 +6749,14 @@ static LLVMValueRef ir_render_resume(CodeGen *g, IrExecutableGen *executable, Ir
67496749 return nullptr;
67506750}
67516751
6752static LLVMValueRef ir_render_frame_size(CodeGen *g, IrExecutableGen *executable,
6752static LLVMValueRef ir_render_frame_size(CodeGen *g, Stage1Air *executable,
67536753 IrInstGenFrameSize *instruction)
67546754{
67556755 LLVMValueRef fn_val = ir_llvm_value(g, instruction->fn);
67566756 return gen_frame_size(g, fn_val);
67576757}
67586758
6759static LLVMValueRef ir_render_spill_begin(CodeGen *g, IrExecutableGen *executable,
6759static LLVMValueRef ir_render_spill_begin(CodeGen *g, Stage1Air *executable,
67606760 IrInstGenSpillBegin *instruction)
67616761{
67626762 if (!fn_is_async(g->cur_fn))
......@@ -6776,7 +6776,7 @@ static LLVMValueRef ir_render_spill_begin(CodeGen *g, IrExecutableGen *executabl
67766776 zig_unreachable();
67776777}
67786778
6779static LLVMValueRef ir_render_spill_end(CodeGen *g, IrExecutableGen *executable, IrInstGenSpillEnd *instruction) {
6779static LLVMValueRef ir_render_spill_end(CodeGen *g, Stage1Air *executable, IrInstGenSpillEnd *instruction) {
67806780 if (!fn_is_async(g->cur_fn))
67816781 return ir_llvm_value(g, instruction->begin->operand);
67826782
......@@ -6792,7 +6792,7 @@ static LLVMValueRef ir_render_spill_end(CodeGen *g, IrExecutableGen *executable,
67926792 zig_unreachable();
67936793}
67946794
6795static LLVMValueRef ir_render_vector_extract_elem(CodeGen *g, IrExecutableGen *executable,
6795static LLVMValueRef ir_render_vector_extract_elem(CodeGen *g, Stage1Air *executable,
67966796 IrInstGenVectorExtractElem *instruction)
67976797{
67986798 LLVMValueRef vector = ir_llvm_value(g, instruction->vector);
......@@ -6811,7 +6811,7 @@ static void set_debug_location(CodeGen *g, IrInstGen *instruction) {
68116811 node_column_onebased(source_node), get_di_scope(g, scope));
68126812}
68136813
6814static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutableGen *executable, IrInstGen *instruction) {
6814static LLVMValueRef ir_render_instruction(CodeGen *g, Stage1Air *executable, IrInstGen *instruction) {
68156815 switch (instruction->id) {
68166816 case IrInstGenIdInvalid:
68176817 case IrInstGenIdConst:
......@@ -6999,7 +6999,7 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutableGen *executabl
69996999static void ir_render(CodeGen *g, ZigFn *fn_entry) {
70007000 assert(fn_entry);
70017001
7002 IrExecutableGen *executable = &fn_entry->analyzed_executable;
7002 Stage1Air *executable = &fn_entry->analyzed_executable;
70037003 assert(executable->basic_block_list.length > 0);
70047004
70057005 for (size_t block_i = 0; block_i < executable->basic_block_list.length; block_i += 1) {
......@@ -7997,7 +7997,7 @@ static void generate_error_name_table(CodeGen *g) {
79977997}
79987998
79997999static void build_all_basic_blocks(CodeGen *g, ZigFn *fn) {
8000 IrExecutableGen *executable = &fn->analyzed_executable;
8000 Stage1Air *executable = &fn->analyzed_executable;
80018001 assert(executable->basic_block_list.length > 0);
80028002 LLVMValueRef fn_val = fn_llvm_value(g, fn);
80038003 LLVMBasicBlockRef first_bb = nullptr;
......@@ -8380,7 +8380,7 @@ static void do_code_gen(CodeGen *g) {
83808380 node_line_onebased(source_node), node_column_onebased(source_node),
83818381 get_di_scope(g, fn_table_entry->child_scope));
83828382 }
8383 IrExecutableGen *executable = &fn_table_entry->analyzed_executable;
8383 Stage1Air *executable = &fn_table_entry->analyzed_executable;
83848384 LLVMBasicBlockRef bad_resume_block = LLVMAppendBasicBlock(g->cur_fn_val, "BadResume");
83858385 LLVMPositionBuilderAtEnd(g->builder, bad_resume_block);
83868386 gen_assertion_scope(g, PanicMsgIdBadResume, fn_table_entry->child_scope);
src/stage1/ir.cpp+46-45
......@@ -24,7 +24,7 @@
2424
2525struct IrBuilderGen {
2626 CodeGen *codegen;
27 IrExecutableGen *exec;
27 Stage1Air *exec;
2828 IrBasicBlockGen *current_basic_block;
2929
3030 // track for immediate post-analysis destruction
......@@ -46,6 +46,9 @@ struct IrAnalyze {
4646 size_t ref_count;
4747 size_t break_debug_id; // for debugging purposes
4848 IrInstGen *return_ptr;
49 Stage1Air *parent_exec;
50 size_t *backward_branch_count;
51 size_t *backward_branch_quota;
4952
5053 // For the purpose of using in a debugger
5154 void dump();
......@@ -672,7 +675,7 @@ static void ir_inst_gen_append(IrBasicBlockGen *basic_block, IrInstGen *instruct
672675 basic_block->instruction_list.append(instruction);
673676}
674677
675static size_t exec_next_debug_id_gen(IrExecutableGen *exec) {
678static size_t exec_next_debug_id_gen(Stage1Air *exec) {
676679 size_t result = exec->next_debug_id;
677680 exec->next_debug_id += 1;
678681 return result;
......@@ -716,7 +719,7 @@ ZigType *ir_analyze_type_expr(IrAnalyze *ira, Scope *scope, AstNode *node) {
716719 create_result_ptr(ira->codegen, ira->codegen->builtin_types.entry_type, &result, &result_ptr);
717720
718721 if ((err = ir_eval_const_value(ira->codegen, scope, node, result_ptr,
719 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota,
722 ira->backward_branch_count, ira->backward_branch_quota,
720723 nullptr, nullptr, node, nullptr, ira->new_irb.exec, nullptr, UndefBad)))
721724 {
722725 return ira->codegen->builtin_types.entry_invalid;
......@@ -2512,7 +2515,7 @@ static ZigType *make_err_set_with_one_item(CodeGen *g, Scope *parent_scope, AstN
25122515 return err_set_type;
25132516}
25142517
2515static void invalidate_exec_gen(IrExecutableGen *exec, ErrorMsg *msg) {
2518static void invalidate_exec_gen(Stage1Air *exec, ErrorMsg *msg) {
25162519 if (exec->first_err_trace_msg != nullptr)
25172520 return;
25182521
......@@ -2527,7 +2530,7 @@ static void invalidate_exec_gen(IrExecutableGen *exec, ErrorMsg *msg) {
25272530}
25282531
25292532
2530static ErrorMsg *exec_add_error_node_gen(CodeGen *codegen, IrExecutableGen *exec, AstNode *source_node, Buf *msg) {
2533static ErrorMsg *exec_add_error_node_gen(CodeGen *codegen, Stage1Air *exec, AstNode *source_node, Buf *msg) {
25312534 ErrorMsg *err_msg = add_node_error(codegen, source_node, msg);
25322535 invalidate_exec_gen(exec, err_msg);
25332536 if (exec->parent_exec) {
......@@ -2601,7 +2604,7 @@ ZigValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ZigValue *const_va
26012604 return val;
26022605}
26032606
2604static Error ir_exec_scan_for_side_effects(CodeGen *codegen, IrExecutableGen *exec) {
2607static Error ir_exec_scan_for_side_effects(CodeGen *codegen, Stage1Air *exec) {
26052608 IrBasicBlockGen *bb = exec->basic_block_list.at(0);
26062609 for (size_t i = 0; i < bb->instruction_list.length; i += 1) {
26072610 IrInstGen *instruction = bb->instruction_list.at(i);
......@@ -5425,8 +5428,8 @@ static IrInstGen *ir_unreach_error(IrAnalyze *ira) {
54255428}
54265429
54275430static bool ir_emit_backward_branch(IrAnalyze *ira, IrInst* source_instruction) {
5428 size_t *bbc = ira->new_irb.exec->backward_branch_count;
5429 size_t *quota = ira->new_irb.exec->backward_branch_quota;
5431 size_t *bbc = ira->backward_branch_count;
5432 size_t *quota = ira->backward_branch_quota;
54305433
54315434 // If we're already over quota, we've already given an error message for this.
54325435 if (*bbc > *quota) {
......@@ -5532,7 +5535,7 @@ static IrInstGen *ir_get_const_ptr(IrAnalyze *ira, IrInst *instruction,
55325535 return const_instr;
55335536}
55345537
5535static Error ir_resolve_const_val(CodeGen *codegen, IrExecutableGen *exec, AstNode *source_node,
5538static Error ir_resolve_const_val(CodeGen *codegen, Stage1Air *exec, AstNode *source_node,
55365539 ZigValue *val, UndefAllowed undef_allowed)
55375540{
55385541 Error err;
......@@ -5579,7 +5582,7 @@ static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstGen *value, UndefAllowed
55795582Error ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
55805583 ZigValue *return_ptr, size_t *backward_branch_count, size_t *backward_branch_quota,
55815584 ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name,
5582 IrExecutableGen *parent_exec, AstNode *expected_type_source_node, UndefAllowed undef_allowed)
5585 Stage1Air *parent_exec, AstNode *expected_type_source_node, UndefAllowed undef_allowed)
55835586{
55845587 Error err;
55855588
......@@ -5590,7 +5593,6 @@ Error ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
55905593
55915594 Stage1Zir *ir_executable = heap::c_allocator.create<Stage1Zir>();
55925595 ir_executable->source_node = source_node;
5593 ir_executable->parent_exec = parent_exec;
55945596 ir_executable->name = exec_name;
55955597 ir_executable->is_inline = true;
55965598 ir_executable->fn_entry = fn_entry;
......@@ -5610,7 +5612,7 @@ Error ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
56105612 ir_print_src(codegen, stderr, ir_executable, 2);
56115613 fprintf(stderr, "}\n");
56125614 }
5613 IrExecutableGen *analyzed_executable = heap::c_allocator.create<IrExecutableGen>();
5615 Stage1Air *analyzed_executable = heap::c_allocator.create<Stage1Air>();
56145616 analyzed_executable->source_node = source_node;
56155617 analyzed_executable->parent_exec = parent_exec;
56165618 analyzed_executable->source_exec = ir_executable;
......@@ -5618,10 +5620,9 @@ Error ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
56185620 analyzed_executable->is_inline = true;
56195621 analyzed_executable->fn_entry = fn_entry;
56205622 analyzed_executable->c_import_buf = c_import_buf;
5621 analyzed_executable->backward_branch_count = backward_branch_count;
5622 analyzed_executable->backward_branch_quota = backward_branch_quota;
56235623 analyzed_executable->begin_scope = scope;
56245624 ZigType *result_type = ir_analyze(codegen, ir_executable, analyzed_executable,
5625 backward_branch_count, backward_branch_quota,
56255626 return_ptr->type->data.pointer.child_type, expected_type_source_node, return_ptr);
56265627 if (type_is_invalid(result_type)) {
56275628 return ErrorSemanticAnalyzeFail;
......@@ -5663,7 +5664,7 @@ static ErrorTableEntry *ir_resolve_error(IrAnalyze *ira, IrInstGen *err_value) {
56635664 return const_val->data.x_err_set;
56645665}
56655666
5666static ZigType *ir_resolve_const_type(CodeGen *codegen, IrExecutableGen *exec, AstNode *source_node,
5667static ZigType *ir_resolve_const_type(CodeGen *codegen, Stage1Air *exec, AstNode *source_node,
56675668 ZigValue *val)
56685669{
56695670 Error err;
......@@ -8071,7 +8072,7 @@ static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrIns
80718072 return ir_build_load_ptr_gen(ira, source_instruction, ptr, child_type, result_loc_inst);
80728073}
80738074
8074static bool ir_resolve_const_align(CodeGen *codegen, IrExecutableGen *exec, AstNode *source_node,
8075static bool ir_resolve_const_align(CodeGen *codegen, Stage1Air *exec, AstNode *source_node,
80758076 ZigValue *const_val, uint32_t *out)
80768077{
80778078 Error err;
......@@ -12752,7 +12753,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1275212753 create_result_ptr(ira->codegen, return_type, &result, &result_ptr);
1275312754
1275412755 if ((err = ir_eval_const_value(ira->codegen, exec_scope, body_node, result_ptr,
12755 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota,
12756 ira->backward_branch_count, ira->backward_branch_quota,
1275612757 fn_entry, nullptr, source_instr->source_node, nullptr, ira->new_irb.exec, return_type_node,
1275712758 UndefOk)))
1275812759 {
......@@ -12869,7 +12870,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1286912870 create_result_ptr(ira->codegen, get_align_amt_type(ira->codegen), &align_result, &result_ptr);
1287012871 if ((err = ir_eval_const_value(ira->codegen, impl_fn->child_scope,
1287112872 fn_proto_node->data.fn_proto.align_expr, result_ptr,
12872 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota,
12873 ira->backward_branch_count, ira->backward_branch_quota,
1287312874 nullptr, nullptr, fn_proto_node->data.fn_proto.align_expr, nullptr, ira->new_irb.exec,
1287412875 nullptr, UndefBad)))
1287512876 {
......@@ -12934,11 +12935,9 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1293412935 return ira->codegen->invalid_inst_gen;
1293512936
1293612937 impl_fn->ir_executable->source_node = source_instr->source_node;
12937 impl_fn->ir_executable->parent_exec = ira->new_irb.exec;
1293812938 impl_fn->analyzed_executable.source_node = source_instr->source_node;
1293912939 impl_fn->analyzed_executable.parent_exec = ira->new_irb.exec;
12940 impl_fn->analyzed_executable.backward_branch_quota = ira->new_irb.exec->backward_branch_quota;
12941 impl_fn->analyzed_executable.is_generic_instantiation = true;
12940 impl_fn->branch_quota = *ira->backward_branch_quota;
1294212941
1294312942 ira->codegen->fn_defs.append(impl_fn);
1294412943 }
......@@ -18980,8 +18979,8 @@ static IrInstGen *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira,
1898018979 if (!ir_resolve_unsigned(ira, instruction->new_quota->child, ira->codegen->builtin_types.entry_u32, &new_quota))
1898118980 return ira->codegen->invalid_inst_gen;
1898218981
18983 if (new_quota > *ira->new_irb.exec->backward_branch_quota) {
18984 *ira->new_irb.exec->backward_branch_quota = new_quota;
18982 if (new_quota > *ira->backward_branch_quota) {
18983 *ira->backward_branch_quota = new_quota;
1898518984 }
1898618985
1898718986 return ir_const_void(ira, &instruction->base.base);
......@@ -19015,7 +19014,7 @@ static IrInstGen *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstSrcCImpo
1901519014 ZigValue *result_ptr;
1901619015 create_result_ptr(ira->codegen, void_type, &cimport_result, &result_ptr);
1901719016 if ((err = ir_eval_const_value(ira->codegen, &cimport_scope->base, block_node, result_ptr,
19018 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr,
19017 ira->backward_branch_count, ira->backward_branch_quota, nullptr,
1901919018 &cimport_scope->buf, block_node, nullptr, nullptr, nullptr, UndefBad)))
1902019019 {
1902119020 return ira->codegen->invalid_inst_gen;
......@@ -24467,25 +24466,27 @@ static IrInstGen *ir_analyze_instruction_base(IrAnalyze *ira, IrInstSrc *instruc
2446724466}
2446824467
2446924468// This function attempts to evaluate IR code while doing type checking and other analysis.
24470// It emits to a new IrExecutableGen which is partially evaluated IR code.
24471ZigType *ir_analyze(CodeGen *codegen, Stage1Zir *old_exec, IrExecutableGen *new_exec,
24469// It emits to a new Stage1Air which is partially evaluated IR code.
24470ZigType *ir_analyze(CodeGen *codegen, Stage1Zir *stage1_zir, Stage1Air *stage1_air,
24471 size_t *backward_branch_count, size_t *backward_branch_quota,
2447224472 ZigType *expected_type, AstNode *expected_type_source_node, ZigValue *result_ptr)
2447324473{
24474 assert(old_exec->first_err_trace_msg == nullptr);
24474 assert(stage1_zir->first_err_trace_msg == nullptr);
2447524475 assert(expected_type == nullptr || !type_is_invalid(expected_type));
2447624476
2447724477 IrAnalyze *ira = heap::c_allocator.create<IrAnalyze>();
24478 ira->backward_branch_count = backward_branch_count;
24479 ira->backward_branch_quota = backward_branch_quota;
2447824480 ira->ref_count = 1;
24479 old_exec->analysis = ira;
2448024481 ira->codegen = codegen;
2448124482
2448224483 ira->explicit_return_type = expected_type;
2448324484 ira->explicit_return_type_source_node = expected_type_source_node;
2448424485
24485 ira->zir = old_exec;
24486 ira->zir = stage1_zir;
2448624487
2448724488 ira->new_irb.codegen = codegen;
24488 ira->new_irb.exec = new_exec;
24489 ira->new_irb.exec = stage1_air;
2448924490
2449024491 IrBasicBlockSrc *old_entry_bb = ira->zir->basic_block_list.at(0);
2449124492 IrBasicBlockGen *new_entry_bb = ir_get_new_bb(ira, old_entry_bb, nullptr);
......@@ -24497,13 +24498,13 @@ ZigType *ir_analyze(CodeGen *codegen, Stage1Zir *old_exec, IrExecutableGen *new_
2449724498 if (result_ptr != nullptr) {
2449824499 assert(result_ptr->type->id == ZigTypeIdPointer);
2449924500 IrInstGenConst *const_inst = ir_create_inst_noval<IrInstGenConst>(
24500 &ira->new_irb, new_exec->begin_scope, new_exec->source_node);
24501 &ira->new_irb, stage1_air->begin_scope, stage1_air->source_node);
2450124502 const_inst->base.value = result_ptr;
2450224503 ira->return_ptr = &const_inst->base;
2450324504 } else {
24504 assert(new_exec->begin_scope != nullptr);
24505 assert(new_exec->source_node != nullptr);
24506 ira->return_ptr = ir_build_return_ptr(ira, new_exec->begin_scope, new_exec->source_node,
24505 assert(stage1_air->begin_scope != nullptr);
24506 assert(stage1_air->source_node != nullptr);
24507 ira->return_ptr = ir_build_return_ptr(ira, stage1_air->begin_scope, stage1_air->source_node,
2450724508 get_pointer_to_type(codegen, expected_type, false));
2450824509 }
2450924510
......@@ -24531,16 +24532,16 @@ ZigType *ir_analyze(CodeGen *codegen, Stage1Zir *old_exec, IrExecutableGen *new_
2453124532 fprintf(stderr, "-> (invalid)");
2453224533 }
2453324534
24534 if (new_exec->first_err_trace_msg != nullptr) {
24535 ira->codegen->trace_err = new_exec->first_err_trace_msg;
24535 if (stage1_air->first_err_trace_msg != nullptr) {
24536 ira->codegen->trace_err = stage1_air->first_err_trace_msg;
2453624537 } else {
24537 new_exec->first_err_trace_msg = ira->codegen->trace_err;
24538 stage1_air->first_err_trace_msg = ira->codegen->trace_err;
2453824539 }
24539 if (new_exec->first_err_trace_msg != nullptr &&
24540 if (stage1_air->first_err_trace_msg != nullptr &&
2454024541 !old_instruction->base.source_node->already_traced_this_node)
2454124542 {
2454224543 old_instruction->base.source_node->already_traced_this_node = true;
24543 new_exec->first_err_trace_msg = add_error_note(ira->codegen, new_exec->first_err_trace_msg,
24544 stage1_air->first_err_trace_msg = add_error_note(ira->codegen, stage1_air->first_err_trace_msg,
2454424545 old_instruction->base.source_node, buf_create_from_str("referenced here"));
2454524546 }
2454624547 return ira->codegen->builtin_types.entry_invalid;
......@@ -24566,14 +24567,14 @@ ZigType *ir_analyze(CodeGen *codegen, Stage1Zir *old_exec, IrExecutableGen *new_
2456624567 }
2456724568
2456824569 ZigType *res_type;
24569 if (new_exec->first_err_trace_msg != nullptr) {
24570 codegen->trace_err = new_exec->first_err_trace_msg;
24571 if (codegen->trace_err != nullptr && new_exec->source_node != nullptr &&
24572 !new_exec->source_node->already_traced_this_node)
24570 if (stage1_air->first_err_trace_msg != nullptr) {
24571 codegen->trace_err = stage1_air->first_err_trace_msg;
24572 if (codegen->trace_err != nullptr && stage1_air->source_node != nullptr &&
24573 !stage1_air->source_node->already_traced_this_node)
2457324574 {
24574 new_exec->source_node->already_traced_this_node = true;
24575 stage1_air->source_node->already_traced_this_node = true;
2457524576 codegen->trace_err = add_error_note(codegen, codegen->trace_err,
24576 new_exec->source_node, buf_create_from_str("referenced here"));
24577 stage1_air->source_node, buf_create_from_str("referenced here"));
2457724578 }
2457824579 res_type = ira->codegen->builtin_types.entry_invalid;
2457924580 } else if (ira->src_implicit_return_type_list.length == 0) {
src/stage1/ir.hpp+4-3
......@@ -16,12 +16,13 @@ IrInstGen *ir_create_alloca(CodeGen *g, Scope *scope, AstNode *source_node, ZigF
1616Error ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
1717 ZigValue *return_ptr, size_t *backward_branch_count, size_t *backward_branch_quota,
1818 ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name,
19 IrExecutableGen *parent_exec, AstNode *expected_type_source_node, UndefAllowed undef);
19 Stage1Air *parent_exec, AstNode *expected_type_source_node, UndefAllowed undef);
2020
2121Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ZigValue *val);
2222
23ZigType *ir_analyze(CodeGen *g, Stage1Zir *old_executable, IrExecutableGen *new_executable,
24 ZigType *expected_type, AstNode *expected_type_source_node, ZigValue *return_ptr);
23ZigType *ir_analyze(CodeGen *codegen, Stage1Zir *stage1_zir, Stage1Air *stage1_air,
24 size_t *backward_branch_count, size_t *backward_branch_quota,
25 ZigType *expected_type, AstNode *expected_type_source_node, ZigValue *result_ptr);
2526
2627bool ir_inst_gen_has_side_effects(IrInstGen *inst);
2728bool ir_inst_src_has_side_effects(IrInstSrc *inst);
src/stage1/ir_print.cpp+1-1
......@@ -3408,7 +3408,7 @@ void ir_print_src(CodeGen *codegen, FILE *f, Stage1Zir *executable, int indent_s
34083408 }
34093409}
34103410
3411void ir_print_gen(CodeGen *codegen, FILE *f, IrExecutableGen *executable, int indent_size) {
3411void ir_print_gen(CodeGen *codegen, FILE *f, Stage1Air *executable, int indent_size) {
34123412 IrPrintGen ir_print = {};
34133413 IrPrintGen *irp = &ir_print;
34143414 irp->codegen = codegen;
src/stage1/ir_print.hpp+1-1
......@@ -13,7 +13,7 @@
1313#include <stdio.h>
1414
1515void ir_print_src(CodeGen *codegen, FILE *f, Stage1Zir *executable, int indent_size);
16void ir_print_gen(CodeGen *codegen, FILE *f, IrExecutableGen *executable, int indent_size);
16void ir_print_gen(CodeGen *codegen, FILE *f, Stage1Air *executable, int indent_size);
1717void ir_print_inst_src(CodeGen *codegen, FILE *f, IrInstSrc *inst, int indent_size);
1818void ir_print_inst_gen(CodeGen *codegen, FILE *f, IrInstGen *inst, int indent_size);
1919void ir_print_basic_block_src(CodeGen *codegen, FILE *f, IrBasicBlockSrc *bb, int indent_size);