authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-03-18 13:13:35-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-03-18 13:14:26-07:00
log5cbb642525fa92e16dd3c9e978a9f8a34734de4c
tree7c479d76abcebda8ff536871095cffd6c9474e57
parent17c066e9257d539cc1779eaaa9ad2679ec6b8881

stage1: small mem usage improvement for IR

move a boolean field to be represented implicitly with the enum tag. Just borrowing one of the many strategies of stage2. This simple change took the peak mem usage from std lib tests on my machine from 8.21 GiB to 8.11 GiB.

3 files changed, 40 insertions(+), 20 deletions(-)

src/stage1/all_types.hpp+2-2
......@@ -2629,7 +2629,8 @@ enum IrInstSrcId {
26292629 IrInstSrcIdResolveResult,
26302630 IrInstSrcIdResetResult,
26312631 IrInstSrcIdSetAlignStack,
2632 IrInstSrcIdArgType,
2632 IrInstSrcIdArgTypeAllowVarFalse,
2633 IrInstSrcIdArgTypeAllowVarTrue,
26332634 IrInstSrcIdExport,
26342635 IrInstSrcIdExtern,
26352636 IrInstSrcIdErrorReturnTrace,
......@@ -4144,7 +4145,6 @@ struct IrInstSrcArgType {
41444145
41454146 IrInstSrc *fn_type;
41464147 IrInstSrc *arg_index;
4147 bool allow_var;
41484148};
41494149
41504150struct IrInstSrcExport {
src/stage1/ir.cpp+22-13
......@@ -514,7 +514,8 @@ static void destroy_instruction_src(IrInstSrc *inst) {
514514 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcResetResult *>(inst));
515515 case IrInstSrcIdSetAlignStack:
516516 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSetAlignStack *>(inst));
517 case IrInstSrcIdArgType:
517 case IrInstSrcIdArgTypeAllowVarFalse:
518 case IrInstSrcIdArgTypeAllowVarTrue:
518519 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcArgType *>(inst));
519520 case IrInstSrcIdExport:
520521 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcExport *>(inst));
......@@ -1546,10 +1547,6 @@ static constexpr IrInstSrcId ir_inst_id(IrInstSrcSetAlignStack *) {
15461547 return IrInstSrcIdSetAlignStack;
15471548}
15481549
1549static constexpr IrInstSrcId ir_inst_id(IrInstSrcArgType *) {
1550 return IrInstSrcIdArgType;
1551}
1552
15531550static constexpr IrInstSrcId ir_inst_id(IrInstSrcExport *) {
15541551 return IrInstSrcIdExport;
15551552}
......@@ -4590,10 +4587,17 @@ static IrInstSrc *ir_build_set_align_stack(IrBuilderSrc *irb, Scope *scope, AstN
45904587static IrInstSrc *ir_build_arg_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
45914588 IrInstSrc *fn_type, IrInstSrc *arg_index, bool allow_var)
45924589{
4593 IrInstSrcArgType *instruction = ir_build_instruction<IrInstSrcArgType>(irb, scope, source_node);
4590 IrInstSrcArgType *instruction = heap::c_allocator.create<IrInstSrcArgType>();
4591 instruction->base.id = allow_var ?
4592 IrInstSrcIdArgTypeAllowVarTrue : IrInstSrcIdArgTypeAllowVarFalse;
4593 instruction->base.base.scope = scope;
4594 instruction->base.base.source_node = source_node;
4595 instruction->base.base.debug_id = exec_next_debug_id(irb->exec);
4596 instruction->base.owner_bb = irb->current_basic_block;
4597 ir_instruction_append(irb->current_basic_block, &instruction->base);
4598
45944599 instruction->fn_type = fn_type;
45954600 instruction->arg_index = arg_index;
4596 instruction->allow_var = allow_var;
45974601
45984602 ir_ref_instruction(fn_type, irb->current_basic_block);
45994603 ir_ref_instruction(arg_index, irb->current_basic_block);
......@@ -30976,7 +30980,9 @@ static IrInstGen *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, IrInstS
3097630980 return ir_const_void(ira, &instruction->base.base);
3097730981}
3097830982
30979static IrInstGen *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstSrcArgType *instruction) {
30983static IrInstGen *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstSrcArgType *instruction,
30984 bool allow_var)
30985{
3098030986 IrInstGen *fn_type_inst = instruction->fn_type->child;
3098130987 ZigType *fn_type = ir_resolve_type(ira, fn_type_inst);
3098230988 if (type_is_invalid(fn_type))
......@@ -30998,7 +31004,7 @@ static IrInstGen *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstSrcArgTy
3099831004
3099931005 FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;
3100031006 if (arg_index >= fn_type_id->param_count) {
31001 if (instruction->allow_var) {
31007 if (allow_var) {
3100231008 // TODO remove this with var args
3100331009 return ir_const_type(ira, &instruction->base.base, ira->codegen->builtin_types.entry_anytype);
3100431010 }
......@@ -31013,7 +31019,7 @@ static IrInstGen *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstSrcArgTy
3101331019 // Args are only unresolved if our function is generic.
3101431020 ir_assert(fn_type->data.fn.is_generic, &instruction->base.base);
3101531021
31016 if (instruction->allow_var) {
31022 if (allow_var) {
3101731023 return ir_const_type(ira, &instruction->base.base, ira->codegen->builtin_types.entry_anytype);
3101831024 } else {
3101931025 ir_add_error(ira, &arg_index_inst->base,
......@@ -32383,8 +32389,10 @@ static IrInstGen *ir_analyze_instruction_base(IrAnalyze *ira, IrInstSrc *instruc
3238332389 return ir_analyze_instruction_reset_result(ira, (IrInstSrcResetResult *)instruction);
3238432390 case IrInstSrcIdSetAlignStack:
3238532391 return ir_analyze_instruction_set_align_stack(ira, (IrInstSrcSetAlignStack *)instruction);
32386 case IrInstSrcIdArgType:
32387 return ir_analyze_instruction_arg_type(ira, (IrInstSrcArgType *)instruction);
32392 case IrInstSrcIdArgTypeAllowVarFalse:
32393 return ir_analyze_instruction_arg_type(ira, (IrInstSrcArgType *)instruction, false);
32394 case IrInstSrcIdArgTypeAllowVarTrue:
32395 return ir_analyze_instruction_arg_type(ira, (IrInstSrcArgType *)instruction, true);
3238832396 case IrInstSrcIdExport:
3238932397 return ir_analyze_instruction_export(ira, (IrInstSrcExport *)instruction);
3239032398 case IrInstSrcIdExtern:
......@@ -32826,7 +32834,8 @@ bool ir_inst_src_has_side_effects(IrInstSrc *instruction) {
3282632834 case IrInstSrcIdAlignCast:
3282732835 case IrInstSrcIdImplicitCast:
3282832836 case IrInstSrcIdResolveResult:
32829 case IrInstSrcIdArgType:
32837 case IrInstSrcIdArgTypeAllowVarFalse:
32838 case IrInstSrcIdArgTypeAllowVarTrue:
3283032839 case IrInstSrcIdErrorReturnTrace:
3283132840 case IrInstSrcIdErrorUnion:
3283232841 case IrInstSrcIdFloatOp:
src/stage1/ir_print.cpp+16-5
......@@ -308,8 +308,10 @@ const char* ir_inst_src_type_str(IrInstSrcId id) {
308308 return "SrcResetResult";
309309 case IrInstSrcIdSetAlignStack:
310310 return "SrcSetAlignStack";
311 case IrInstSrcIdArgType:
312 return "SrcArgType";
311 case IrInstSrcIdArgTypeAllowVarFalse:
312 return "SrcArgTypeAllowVarFalse";
313 case IrInstSrcIdArgTypeAllowVarTrue:
314 return "SrcArgTypeAllowVarTrue";
313315 case IrInstSrcIdExport:
314316 return "SrcExport";
315317 case IrInstSrcIdExtern:
......@@ -2344,11 +2346,17 @@ static void ir_print_set_align_stack(IrPrintSrc *irp, IrInstSrcSetAlignStack *in
23442346 fprintf(irp->f, ")");
23452347}
23462348
2347static void ir_print_arg_type(IrPrintSrc *irp, IrInstSrcArgType *instruction) {
2349static void ir_print_arg_type(IrPrintSrc *irp, IrInstSrcArgType *instruction, bool allow_var) {
23482350 fprintf(irp->f, "@ArgType(");
23492351 ir_print_other_inst_src(irp, instruction->fn_type);
23502352 fprintf(irp->f, ",");
23512353 ir_print_other_inst_src(irp, instruction->arg_index);
2354 fprintf(irp->f, ",");
2355 if (allow_var) {
2356 fprintf(irp->f, "allow_var=true");
2357 } else {
2358 fprintf(irp->f, "allow_var=false");
2359 }
23522360 fprintf(irp->f, ")");
23532361}
23542362
......@@ -2942,8 +2950,11 @@ static void ir_print_inst_src(IrPrintSrc *irp, IrInstSrc *instruction, bool trai
29422950 case IrInstSrcIdSetAlignStack:
29432951 ir_print_set_align_stack(irp, (IrInstSrcSetAlignStack *)instruction);
29442952 break;
2945 case IrInstSrcIdArgType:
2946 ir_print_arg_type(irp, (IrInstSrcArgType *)instruction);
2953 case IrInstSrcIdArgTypeAllowVarFalse:
2954 ir_print_arg_type(irp, (IrInstSrcArgType *)instruction, false);
2955 break;
2956 case IrInstSrcIdArgTypeAllowVarTrue:
2957 ir_print_arg_type(irp, (IrInstSrcArgType *)instruction, true);
29472958 break;
29482959 case IrInstSrcIdExport:
29492960 ir_print_export(irp, (IrInstSrcExport *)instruction);