| author | |
| committer | |
| log | 6c89f96df1484fc5017eb484f0f8270ab4be341f |
| tree | 8c5e0e68f2d6294690903fd4c0fefbc86975a461 |
| parent | 35d65cceb8aa4360accc0db30b2b1448159e7d26 |
| signature |
- merge const_void_val → intern.x_void
- move const_zero_byte → intern.zero_byte
- wrap intern access6 files changed, 65 insertions(+), 25 deletions(-)
src/all_types.hpp+9-4| ... | @@ -2021,12 +2021,19 @@ struct CodeGen { | ... | @@ -2021,12 +2021,19 @@ struct CodeGen { |
| 2021 | ZigType *entry_any_frame; | 2021 | ZigType *entry_any_frame; |
| 2022 | } builtin_types; | 2022 | } builtin_types; |
| 2023 | 2023 | ||
| 2024 | struct { | 2024 | struct Intern { |
| 2025 | ZigValue x_undefined; | 2025 | ZigValue x_undefined; |
| 2026 | ZigValue x_void; | 2026 | ZigValue x_void; |
| 2027 | ZigValue x_null; | 2027 | ZigValue x_null; |
| 2028 | ZigValue x_unreachable; | 2028 | ZigValue x_unreachable; |
| 2029 | } intern_values; | 2029 | ZigValue zero_byte; |
| 2030 | |||
| 2031 | ZigValue *for_undefined(); | ||
| 2032 | ZigValue *for_void(); | ||
| 2033 | ZigValue *for_null(); | ||
| 2034 | ZigValue *for_unreachable(); | ||
| 2035 | ZigValue *for_zero_byte(); | ||
| 2036 | } intern; | ||
| 2030 | 2037 | ||
| 2031 | ZigType *align_amt_type; | 2038 | ZigType *align_amt_type; |
| 2032 | ZigType *stack_trace_type; | 2039 | ZigType *stack_trace_type; |
| ... | @@ -2050,8 +2057,6 @@ struct CodeGen { | ... | @@ -2050,8 +2057,6 @@ struct CodeGen { |
| 2050 | IrInstruction *invalid_instruction; | 2057 | IrInstruction *invalid_instruction; |
| 2051 | IrInstruction *unreach_instruction; | 2058 | IrInstruction *unreach_instruction; |
| 2052 | 2059 | ||
| 2053 | ZigValue const_zero_byte; | ||
| 2054 | ZigValue const_void_val; | ||
| 2055 | ZigValue panic_msg_vals[PanicMsgIdCount]; | 2060 | ZigValue panic_msg_vals[PanicMsgIdCount]; |
| 2056 | 2061 | ||
| 2057 | // The function definitions this module includes. | 2062 | // The function definitions this module includes. |
src/analyze.cpp+1-1| ... | @@ -5647,7 +5647,7 @@ void init_const_str_lit(CodeGen *g, ZigValue *const_val, Buf *str) { | ... | @@ -5647,7 +5647,7 @@ void init_const_str_lit(CodeGen *g, ZigValue *const_val, Buf *str) { |
| 5647 | // first we build the underlying array | 5647 | // first we build the underlying array |
| 5648 | ZigValue *array_val = create_const_vals(1); | 5648 | ZigValue *array_val = create_const_vals(1); |
| 5649 | array_val->special = ConstValSpecialStatic; | 5649 | array_val->special = ConstValSpecialStatic; |
| 5650 | array_val->type = get_array_type(g, g->builtin_types.entry_u8, buf_len(str), &g->const_zero_byte); | 5650 | array_val->type = get_array_type(g, g->builtin_types.entry_u8, buf_len(str), g->intern.for_zero_byte()); |
| 5651 | array_val->data.x_array.special = ConstArraySpecialBuf; | 5651 | array_val->data.x_array.special = ConstArraySpecialBuf; |
| 5652 | array_val->data.x_array.data.s_buf = str; | 5652 | array_val->data.x_array.data.s_buf = str; |
| 5653 | 5653 |
src/codegen.cpp+46-13| ... | @@ -8010,29 +8010,36 @@ static void define_builtin_types(CodeGen *g) { | ... | @@ -8010,29 +8010,36 @@ static void define_builtin_types(CodeGen *g) { |
| 8010 | 8010 | ||
| 8011 | static void define_intern_values(CodeGen *g) { | 8011 | static void define_intern_values(CodeGen *g) { |
| 8012 | { | 8012 | { |
| 8013 | auto& value = g->intern_values.x_undefined; | 8013 | auto& value = g->intern.x_undefined; |
| 8014 | value.type = g->builtin_types.entry_undef; | 8014 | value.type = g->builtin_types.entry_undef; |
| 8015 | value.global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs.undefined"); | 8015 | value.global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs.undefined"); |
| 8016 | value.special = ConstValSpecialStatic; | 8016 | value.special = ConstValSpecialStatic; |
| 8017 | } | 8017 | } |
| 8018 | { | 8018 | { |
| 8019 | auto& value = g->intern_values.x_void; | 8019 | auto& value = g->intern.x_void; |
| 8020 | value.type = g->builtin_types.entry_void; | 8020 | value.type = g->builtin_types.entry_void; |
| 8021 | value.global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs.void"); | 8021 | value.global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs.void"); |
| 8022 | value.special = ConstValSpecialStatic; | 8022 | value.special = ConstValSpecialStatic; |
| 8023 | } | 8023 | } |
| 8024 | { | 8024 | { |
| 8025 | auto& value = g->intern_values.x_null; | 8025 | auto& value = g->intern.x_null; |
| 8026 | value.type = g->builtin_types.entry_null; | 8026 | value.type = g->builtin_types.entry_null; |
| 8027 | value.global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs.null"); | 8027 | value.global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs.null"); |
| 8028 | value.special = ConstValSpecialStatic; | 8028 | value.special = ConstValSpecialStatic; |
| 8029 | } | 8029 | } |
| 8030 | { | 8030 | { |
| 8031 | auto& value = g->intern_values.x_unreachable; | 8031 | auto& value = g->intern.x_unreachable; |
| 8032 | value.type = g->builtin_types.entry_unreachable; | 8032 | value.type = g->builtin_types.entry_unreachable; |
| 8033 | value.global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs.unreachable"); | 8033 | value.global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs.unreachable"); |
| 8034 | value.special = ConstValSpecialStatic; | 8034 | value.special = ConstValSpecialStatic; |
| 8035 | } | 8035 | } |
| 8036 | { | ||
| 8037 | auto& value = g->intern.zero_byte; | ||
| 8038 | value.type = g->builtin_types.entry_u8; | ||
| 8039 | value.global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs.zero_byte"); | ||
| 8040 | value.special = ConstValSpecialStatic; | ||
| 8041 | bigint_init_unsigned(&value.data.x_bigint, 0); | ||
| 8042 | } | ||
| 8036 | } | 8043 | } |
| 8037 | 8044 | ||
| 8038 | static BuiltinFnEntry *create_builtin_fn(CodeGen *g, BuiltinFnId id, const char *name, size_t count) { | 8045 | static BuiltinFnEntry *create_builtin_fn(CodeGen *g, BuiltinFnId id, const char *name, size_t count) { |
| ... | @@ -8669,15 +8676,6 @@ static void init(CodeGen *g) { | ... | @@ -8669,15 +8676,6 @@ static void init(CodeGen *g) { |
| 8669 | g->unreach_instruction->value->type = g->builtin_types.entry_unreachable; | 8676 | g->unreach_instruction->value->type = g->builtin_types.entry_unreachable; |
| 8670 | g->unreach_instruction->value->global_refs = allocate<ConstGlobalRefs>(1); | 8677 | g->unreach_instruction->value->global_refs = allocate<ConstGlobalRefs>(1); |
| 8671 | 8678 | ||
| 8672 | g->const_void_val.special = ConstValSpecialStatic; | ||
| 8673 | g->const_void_val.type = g->builtin_types.entry_void; | ||
| 8674 | g->const_void_val.global_refs = allocate<ConstGlobalRefs>(1); | ||
| 8675 | |||
| 8676 | g->const_zero_byte.special = ConstValSpecialStatic; | ||
| 8677 | g->const_zero_byte.type = g->builtin_types.entry_u8; | ||
| 8678 | g->const_zero_byte.global_refs = allocate<ConstGlobalRefs>(1); | ||
| 8679 | bigint_init_unsigned(&g->const_zero_byte.data.x_bigint, 0); | ||
| 8680 | |||
| 8681 | { | 8679 | { |
| 8682 | ConstGlobalRefs *global_refs = allocate<ConstGlobalRefs>(PanicMsgIdCount); | 8680 | ConstGlobalRefs *global_refs = allocate<ConstGlobalRefs>(PanicMsgIdCount); |
| 8683 | for (size_t i = 0; i < PanicMsgIdCount; i += 1) { | 8681 | for (size_t i = 0; i < PanicMsgIdCount; i += 1) { |
| ... | @@ -10564,3 +10562,38 @@ void codegen_switch_sub_prog_node(CodeGen *g, Stage2ProgressNode *node) { | ... | @@ -10564,3 +10562,38 @@ void codegen_switch_sub_prog_node(CodeGen *g, Stage2ProgressNode *node) { |
| 10564 | } | 10562 | } |
| 10565 | g->sub_progress_node = node; | 10563 | g->sub_progress_node = node; |
| 10566 | } | 10564 | } |
| 10565 | |||
| 10566 | ZigValue *CodeGen::Intern::for_undefined() { | ||
| 10567 | #ifdef ZIG_ENABLE_MEM_PROFILE | ||
| 10568 | memprof_intern_count.x_undefined += 1; | ||
| 10569 | #endif | ||
| 10570 | return &this->x_undefined; | ||
| 10571 | } | ||
| 10572 | |||
| 10573 | ZigValue *CodeGen::Intern::for_void() { | ||
| 10574 | #ifdef ZIG_ENABLE_MEM_PROFILE | ||
| 10575 | memprof_intern_count.x_void += 1; | ||
| 10576 | #endif | ||
| 10577 | return &this->x_void; | ||
| 10578 | } | ||
| 10579 | |||
| 10580 | ZigValue *CodeGen::Intern::for_null() { | ||
| 10581 | #ifdef ZIG_ENABLE_MEM_PROFILE | ||
| 10582 | memprof_intern_count.x_null += 1; | ||
| 10583 | #endif | ||
| 10584 | return &this->x_null; | ||
| 10585 | } | ||
| 10586 | |||
| 10587 | ZigValue *CodeGen::Intern::for_unreachable() { | ||
| 10588 | #ifdef ZIG_ENABLE_MEM_PROFILE | ||
| 10589 | memprof_intern_count.x_unreachable += 1; | ||
| 10590 | #endif | ||
| 10591 | return &this->x_unreachable; | ||
| 10592 | } | ||
| 10593 | |||
| 10594 | ZigValue *CodeGen::Intern::for_zero_byte() { | ||
| 10595 | #ifdef ZIG_ENABLE_MEM_PROFILE | ||
| 10596 | memprof_intern_count.zero_byte += 1; | ||
| 10597 | #endif | ||
| 10598 | return &this->zero_byte; | ||
| 10599 | } |
src/ir.cpp+7-7| ... | @@ -1235,7 +1235,7 @@ static IrInstruction *ir_build_const_void(IrBuilder *irb, Scope *scope, AstNode | ... | @@ -1235,7 +1235,7 @@ static IrInstruction *ir_build_const_void(IrBuilder *irb, Scope *scope, AstNode |
| 1235 | #endif | 1235 | #endif |
| 1236 | IrInstructionConst *const_instruction = ir_create_instruction_noval<IrInstructionConst>(irb, scope, source_node); | 1236 | IrInstructionConst *const_instruction = ir_create_instruction_noval<IrInstructionConst>(irb, scope, source_node); |
| 1237 | ir_instruction_append(irb->current_basic_block, &const_instruction->base); | 1237 | ir_instruction_append(irb->current_basic_block, &const_instruction->base); |
| 1238 | const_instruction->base.value = &irb->codegen->intern_values.x_void; | 1238 | const_instruction->base.value = irb->codegen->intern.for_void(); |
| 1239 | return &const_instruction->base; | 1239 | return &const_instruction->base; |
| 1240 | } | 1240 | } |
| 1241 | 1241 | ||
| ... | @@ -1245,7 +1245,7 @@ static IrInstruction *ir_build_const_undefined(IrBuilder *irb, Scope *scope, Ast | ... | @@ -1245,7 +1245,7 @@ static IrInstruction *ir_build_const_undefined(IrBuilder *irb, Scope *scope, Ast |
| 1245 | #endif | 1245 | #endif |
| 1246 | IrInstructionConst *const_instruction = ir_create_instruction_noval<IrInstructionConst>(irb, scope, source_node); | 1246 | IrInstructionConst *const_instruction = ir_create_instruction_noval<IrInstructionConst>(irb, scope, source_node); |
| 1247 | ir_instruction_append(irb->current_basic_block, &const_instruction->base); | 1247 | ir_instruction_append(irb->current_basic_block, &const_instruction->base); |
| 1248 | const_instruction->base.value = &irb->codegen->intern_values.x_undefined; | 1248 | const_instruction->base.value = irb->codegen->intern.for_undefined(); |
| 1249 | return &const_instruction->base; | 1249 | return &const_instruction->base; |
| 1250 | } | 1250 | } |
| 1251 | 1251 | ||
| ... | @@ -1279,7 +1279,7 @@ static IrInstruction *ir_build_const_null(IrBuilder *irb, Scope *scope, AstNode | ... | @@ -1279,7 +1279,7 @@ static IrInstruction *ir_build_const_null(IrBuilder *irb, Scope *scope, AstNode |
| 1279 | #endif | 1279 | #endif |
| 1280 | IrInstructionConst *const_instruction = ir_create_instruction_noval<IrInstructionConst>(irb, scope, source_node); | 1280 | IrInstructionConst *const_instruction = ir_create_instruction_noval<IrInstructionConst>(irb, scope, source_node); |
| 1281 | ir_instruction_append(irb->current_basic_block, &const_instruction->base); | 1281 | ir_instruction_append(irb->current_basic_block, &const_instruction->base); |
| 1282 | const_instruction->base.value = &irb->codegen->intern_values.x_null; | 1282 | const_instruction->base.value = irb->codegen->intern.for_null(); |
| 1283 | return &const_instruction->base; | 1283 | return &const_instruction->base; |
| 1284 | } | 1284 | } |
| 1285 | 1285 | ||
| ... | @@ -11464,7 +11464,7 @@ static IrInstruction *ir_const_unreachable(IrAnalyze *ira, IrInstruction *source | ... | @@ -11464,7 +11464,7 @@ static IrInstruction *ir_const_unreachable(IrAnalyze *ira, IrInstruction *source |
| 11464 | memprof_intern_count.x_unreachable += 1; | 11464 | memprof_intern_count.x_unreachable += 1; |
| 11465 | #endif | 11465 | #endif |
| 11466 | IrInstruction *result = ir_const_noval(ira, source_instruction); | 11466 | IrInstruction *result = ir_const_noval(ira, source_instruction); |
| 11467 | result->value = &ira->codegen->intern_values.x_unreachable; | 11467 | result->value = ira->codegen->intern.for_unreachable(); |
| 11468 | return result; | 11468 | return result; |
| 11469 | } | 11469 | } |
| 11470 | 11470 | ||
| ... | @@ -11473,7 +11473,7 @@ static IrInstruction *ir_const_void(IrAnalyze *ira, IrInstruction *source_instru | ... | @@ -11473,7 +11473,7 @@ static IrInstruction *ir_const_void(IrAnalyze *ira, IrInstruction *source_instru |
| 11473 | memprof_intern_count.x_void += 1; | 11473 | memprof_intern_count.x_void += 1; |
| 11474 | #endif | 11474 | #endif |
| 11475 | IrInstruction *result = ir_const_noval(ira, source_instruction); | 11475 | IrInstruction *result = ir_const_noval(ira, source_instruction); |
| 11476 | result->value = &ira->codegen->intern_values.x_void; | 11476 | result->value = ira->codegen->intern.for_void(); |
| 11477 | return result; | 11477 | return result; |
| 11478 | } | 11478 | } |
| 11479 | 11479 | ||
| ... | @@ -18493,7 +18493,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct | ... | @@ -18493,7 +18493,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 18493 | if (var) { | 18493 | if (var) { |
| 18494 | return ir_get_var_ptr(ira, &elem_ptr_instruction->base, var); | 18494 | return ir_get_var_ptr(ira, &elem_ptr_instruction->base, var); |
| 18495 | } else { | 18495 | } else { |
| 18496 | return ir_get_const_ptr(ira, &elem_ptr_instruction->base, &ira->codegen->const_void_val, | 18496 | return ir_get_const_ptr(ira, &elem_ptr_instruction->base, ira->codegen->intern.for_void(), |
| 18497 | ira->codegen->builtin_types.entry_void, ConstPtrMutComptimeConst, is_const, is_volatile, 0); | 18497 | ira->codegen->builtin_types.entry_void, ConstPtrMutComptimeConst, is_const, is_volatile, 0); |
| 18498 | } | 18498 | } |
| 18499 | } else if (array_type->id == ZigTypeIdVector) { | 18499 | } else if (array_type->id == ZigTypeIdVector) { |
| ... | @@ -21856,7 +21856,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr | ... | @@ -21856,7 +21856,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr |
| 21856 | case ZigTypeIdNull: | 21856 | case ZigTypeIdNull: |
| 21857 | case ZigTypeIdArgTuple: | 21857 | case ZigTypeIdArgTuple: |
| 21858 | case ZigTypeIdOpaque: | 21858 | case ZigTypeIdOpaque: |
| 21859 | result = &ira->codegen->const_void_val; | 21859 | result = ira->codegen->intern.for_void(); |
| 21860 | break; | 21860 | break; |
| 21861 | case ZigTypeIdInt: | 21861 | case ZigTypeIdInt: |
| 21862 | { | 21862 | { |
src/memory_profiling.cpp+1| ... | @@ -141,6 +141,7 @@ void memprof_dump_stats(FILE *file) { | ... | @@ -141,6 +141,7 @@ void memprof_dump_stats(FILE *file) { |
| 141 | fprintf(stderr, "void: interned %zu times\n", memprof_intern_count.x_void); | 141 | fprintf(stderr, "void: interned %zu times\n", memprof_intern_count.x_void); |
| 142 | fprintf(stderr, "null: interned %zu times\n", memprof_intern_count.x_null); | 142 | fprintf(stderr, "null: interned %zu times\n", memprof_intern_count.x_null); |
| 143 | fprintf(stderr, "unreachable: interned %zu times\n", memprof_intern_count.x_unreachable); | 143 | fprintf(stderr, "unreachable: interned %zu times\n", memprof_intern_count.x_unreachable); |
| 144 | fprintf(stderr, "zero_byte: interned %zu times\n", memprof_intern_count.zero_byte); | ||
| 144 | } | 145 | } |
| 145 | 146 | ||
| 146 | #endif | 147 | #endif |
src/memory_profiling.hpp+1| ... | @@ -18,6 +18,7 @@ struct MemprofInternCount { | ... | @@ -18,6 +18,7 @@ struct MemprofInternCount { |
| 18 | size_t x_void; | 18 | size_t x_void; |
| 19 | size_t x_null; | 19 | size_t x_null; |
| 20 | size_t x_unreachable; | 20 | size_t x_unreachable; |
| 21 | size_t zero_byte; | ||
| 21 | }; | 22 | }; |
| 22 | extern MemprofInternCount memprof_intern_count; | 23 | extern MemprofInternCount memprof_intern_count; |
| 23 | 24 |