| ... | ... | @@ -549,6 +549,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionTypeId *) { |
| 549 | 549 | return IrInstructionIdTypeId; |
| 550 | 550 | } |
| 551 | 551 | |
| 552 | static constexpr IrInstructionId ir_instruction_id(IrInstructionSetEvalBranchQuota *) { |
| 553 | return IrInstructionIdSetEvalBranchQuota; |
| 554 | } |
| 555 | |
| 552 | 556 | template<typename T> |
| 553 | 557 | static T *ir_create_instruction(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 554 | 558 | T *special_instruction = allocate<T>(1); |
| ... | ... | @@ -2192,6 +2196,17 @@ static IrInstruction *ir_build_type_id(IrBuilder *irb, Scope *scope, AstNode *so |
| 2192 | 2196 | return &instruction->base; |
| 2193 | 2197 | } |
| 2194 | 2198 | |
| 2199 | static IrInstruction *ir_build_set_eval_branch_quota(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2200 | IrInstruction *new_quota) |
| 2201 | { |
| 2202 | IrInstructionSetEvalBranchQuota *instruction = ir_build_instruction<IrInstructionSetEvalBranchQuota>(irb, scope, source_node); |
| 2203 | instruction->new_quota = new_quota; |
| 2204 | |
| 2205 | ir_ref_instruction(new_quota, irb->current_basic_block); |
| 2206 | |
| 2207 | return &instruction->base; |
| 2208 | } |
| 2209 | |
| 2195 | 2210 | static IrInstruction *ir_instruction_br_get_dep(IrInstructionBr *instruction, size_t index) { |
| 2196 | 2211 | return nullptr; |
| 2197 | 2212 | } |
| ... | ... | @@ -2881,6 +2896,13 @@ static IrInstruction *ir_instruction_typeid_get_dep(IrInstructionTypeId *instruc |
| 2881 | 2896 | } |
| 2882 | 2897 | } |
| 2883 | 2898 | |
| 2899 | static IrInstruction *ir_instruction_setevalbranchquota_get_dep(IrInstructionSetEvalBranchQuota *instruction, size_t index) { |
| 2900 | switch (index) { |
| 2901 | case 0: return instruction->new_quota; |
| 2902 | default: return nullptr; |
| 2903 | } |
| 2904 | } |
| 2905 | |
| 2884 | 2906 | static IrInstruction *ir_instruction_get_dep(IrInstruction *instruction, size_t index) { |
| 2885 | 2907 | switch (instruction->id) { |
| 2886 | 2908 | case IrInstructionIdInvalid: |
| ... | ... | @@ -3075,6 +3097,8 @@ static IrInstruction *ir_instruction_get_dep(IrInstruction *instruction, size_t |
| 3075 | 3097 | return ir_instruction_offsetof_get_dep((IrInstructionOffsetOf *) instruction, index); |
| 3076 | 3098 | case IrInstructionIdTypeId: |
| 3077 | 3099 | return ir_instruction_typeid_get_dep((IrInstructionTypeId *) instruction, index); |
| 3100 | case IrInstructionIdSetEvalBranchQuota: |
| 3101 | return ir_instruction_setevalbranchquota_get_dep((IrInstructionSetEvalBranchQuota *) instruction, index); |
| 3078 | 3102 | } |
| 3079 | 3103 | zig_unreachable(); |
| 3080 | 3104 | } |
| ... | ... | @@ -4481,6 +4505,15 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4481 | 4505 | |
| 4482 | 4506 | return ir_build_bin_op(irb, scope, node, IrBinOpBitShiftRightExact, arg0_value, arg1_value, true); |
| 4483 | 4507 | } |
| 4508 | case BuiltinFnIdSetEvalBranchQuota: |
| 4509 | { |
| 4510 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 4511 | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 4512 | if (arg0_value == irb->codegen->invalid_instruction) |
| 4513 | return arg0_value; |
| 4514 | |
| 4515 | return ir_build_set_eval_branch_quota(irb, scope, node, arg0_value); |
| 4516 | } |
| 4484 | 4517 | } |
| 4485 | 4518 | zig_unreachable(); |
| 4486 | 4519 | } |
| ... | ... | @@ -12432,6 +12465,21 @@ static TypeTableEntry *ir_analyze_instruction_type_id(IrAnalyze *ira, |
| 12432 | 12465 | return result_type; |
| 12433 | 12466 | } |
| 12434 | 12467 | |
| 12468 | static TypeTableEntry *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira, |
| 12469 | IrInstructionSetEvalBranchQuota *instruction) |
| 12470 | { |
| 12471 | uint64_t new_quota; |
| 12472 | if (!ir_resolve_usize(ira, instruction->new_quota->other, &new_quota)) |
| 12473 | return ira->codegen->builtin_types.entry_invalid; |
| 12474 | |
| 12475 | if (new_quota > ira->new_irb.exec->backward_branch_quota) { |
| 12476 | ira->new_irb.exec->backward_branch_quota = new_quota; |
| 12477 | } |
| 12478 | |
| 12479 | ir_build_const_from(ira, &instruction->base); |
| 12480 | return ira->codegen->builtin_types.entry_void; |
| 12481 | } |
| 12482 | |
| 12435 | 12483 | static TypeTableEntry *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstructionTypeName *instruction) { |
| 12436 | 12484 | IrInstruction *type_value = instruction->type_value->other; |
| 12437 | 12485 | TypeTableEntry *type_entry = ir_resolve_type(ira, type_value); |
| ... | ... | @@ -14249,6 +14297,8 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi |
| 14249 | 14297 | return ir_analyze_instruction_offset_of(ira, (IrInstructionOffsetOf *)instruction); |
| 14250 | 14298 | case IrInstructionIdTypeId: |
| 14251 | 14299 | return ir_analyze_instruction_type_id(ira, (IrInstructionTypeId *)instruction); |
| 14300 | case IrInstructionIdSetEvalBranchQuota: |
| 14301 | return ir_analyze_instruction_set_eval_branch_quota(ira, (IrInstructionSetEvalBranchQuota *)instruction); |
| 14252 | 14302 | case IrInstructionIdMaybeWrap: |
| 14253 | 14303 | case IrInstructionIdErrWrapCode: |
| 14254 | 14304 | case IrInstructionIdErrWrapPayload: |
| ... | ... | @@ -14365,6 +14415,7 @@ bool ir_has_side_effects(IrInstruction *instruction) { |
| 14365 | 14415 | case IrInstructionIdSetGlobalSection: |
| 14366 | 14416 | case IrInstructionIdSetGlobalLinkage: |
| 14367 | 14417 | case IrInstructionIdPanic: |
| 14418 | case IrInstructionIdSetEvalBranchQuota: |
| 14368 | 14419 | return true; |
| 14369 | 14420 | case IrInstructionIdPhi: |
| 14370 | 14421 | case IrInstructionIdUnOp: |