authorgravatar for michael.dusan@gmail.comMichael Dusan <michael.dusan@gmail.com> 2019-11-25 17:18:56-05:00
committergravatar for michael.dusan@gmail.comMichael Dusan <michael.dusan@gmail.com> 2019-11-25 17:18:56-05:00
log6c89f96df1484fc5017eb484f0f8270ab4be341f
tree8c5e0e68f2d6294690903fd4c0fefbc86975a461
parent35d65cceb8aa4360accc0db30b2b1448159e7d26
signaturelock-open Commit is signed but in an unrecognized format.

stage1: consolodate interning

- merge const_void_val → intern.x_void - move const_zero_byte → intern.zero_byte - wrap intern access

6 files changed, 65 insertions(+), 25 deletions(-)

src/all_types.hpp+9-4
......@@ -2021,12 +2021,19 @@ struct CodeGen {
20212021 ZigType *entry_any_frame;
20222022 } builtin_types;
20232023
2024 struct {
2024 struct Intern {
20252025 ZigValue x_undefined;
20262026 ZigValue x_void;
20272027 ZigValue x_null;
20282028 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;
20302037
20312038 ZigType *align_amt_type;
20322039 ZigType *stack_trace_type;
......@@ -2050,8 +2057,6 @@ struct CodeGen {
20502057 IrInstruction *invalid_instruction;
20512058 IrInstruction *unreach_instruction;
20522059
2053 ZigValue const_zero_byte;
2054 ZigValue const_void_val;
20552060 ZigValue panic_msg_vals[PanicMsgIdCount];
20562061
20572062 // 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) {
56475647 // first we build the underlying array
56485648 ZigValue *array_val = create_const_vals(1);
56495649 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());
56515651 array_val->data.x_array.special = ConstArraySpecialBuf;
56525652 array_val->data.x_array.data.s_buf = str;
56535653
src/codegen.cpp+46-13
......@@ -8010,29 +8010,36 @@ static void define_builtin_types(CodeGen *g) {
80108010
80118011static void define_intern_values(CodeGen *g) {
80128012 {
8013 auto& value = g->intern_values.x_undefined;
8013 auto& value = g->intern.x_undefined;
80148014 value.type = g->builtin_types.entry_undef;
80158015 value.global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs.undefined");
80168016 value.special = ConstValSpecialStatic;
80178017 }
80188018 {
8019 auto& value = g->intern_values.x_void;
8019 auto& value = g->intern.x_void;
80208020 value.type = g->builtin_types.entry_void;
80218021 value.global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs.void");
80228022 value.special = ConstValSpecialStatic;
80238023 }
80248024 {
8025 auto& value = g->intern_values.x_null;
8025 auto& value = g->intern.x_null;
80268026 value.type = g->builtin_types.entry_null;
80278027 value.global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs.null");
80288028 value.special = ConstValSpecialStatic;
80298029 }
80308030 {
8031 auto& value = g->intern_values.x_unreachable;
8031 auto& value = g->intern.x_unreachable;
80328032 value.type = g->builtin_types.entry_unreachable;
80338033 value.global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs.unreachable");
80348034 value.special = ConstValSpecialStatic;
80358035 }
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 }
80368043}
80378044
80388045static BuiltinFnEntry *create_builtin_fn(CodeGen *g, BuiltinFnId id, const char *name, size_t count) {
......@@ -8669,15 +8676,6 @@ static void init(CodeGen *g) {
86698676 g->unreach_instruction->value->type = g->builtin_types.entry_unreachable;
86708677 g->unreach_instruction->value->global_refs = allocate<ConstGlobalRefs>(1);
86718678
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
86818679 {
86828680 ConstGlobalRefs *global_refs = allocate<ConstGlobalRefs>(PanicMsgIdCount);
86838681 for (size_t i = 0; i < PanicMsgIdCount; i += 1) {
......@@ -10564,3 +10562,38 @@ void codegen_switch_sub_prog_node(CodeGen *g, Stage2ProgressNode *node) {
1056410562 }
1056510563 g->sub_progress_node = node;
1056610564}
10565
10566ZigValue *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
10573ZigValue *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
10580ZigValue *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
10587ZigValue *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
10594ZigValue *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
12351235#endif
12361236 IrInstructionConst *const_instruction = ir_create_instruction_noval<IrInstructionConst>(irb, scope, source_node);
12371237 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();
12391239 return &const_instruction->base;
12401240}
12411241
......@@ -1245,7 +1245,7 @@ static IrInstruction *ir_build_const_undefined(IrBuilder *irb, Scope *scope, Ast
12451245#endif
12461246 IrInstructionConst *const_instruction = ir_create_instruction_noval<IrInstructionConst>(irb, scope, source_node);
12471247 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();
12491249 return &const_instruction->base;
12501250}
12511251
......@@ -1279,7 +1279,7 @@ static IrInstruction *ir_build_const_null(IrBuilder *irb, Scope *scope, AstNode
12791279#endif
12801280 IrInstructionConst *const_instruction = ir_create_instruction_noval<IrInstructionConst>(irb, scope, source_node);
12811281 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();
12831283 return &const_instruction->base;
12841284}
12851285
......@@ -11464,7 +11464,7 @@ static IrInstruction *ir_const_unreachable(IrAnalyze *ira, IrInstruction *source
1146411464 memprof_intern_count.x_unreachable += 1;
1146511465#endif
1146611466 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();
1146811468 return result;
1146911469}
1147011470
......@@ -11473,7 +11473,7 @@ static IrInstruction *ir_const_void(IrAnalyze *ira, IrInstruction *source_instru
1147311473 memprof_intern_count.x_void += 1;
1147411474#endif
1147511475 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();
1147711477 return result;
1147811478}
1147911479
......@@ -18493,7 +18493,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1849318493 if (var) {
1849418494 return ir_get_var_ptr(ira, &elem_ptr_instruction->base, var);
1849518495 } 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(),
1849718497 ira->codegen->builtin_types.entry_void, ConstPtrMutComptimeConst, is_const, is_volatile, 0);
1849818498 }
1849918499 } else if (array_type->id == ZigTypeIdVector) {
......@@ -21856,7 +21856,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2185621856 case ZigTypeIdNull:
2185721857 case ZigTypeIdArgTuple:
2185821858 case ZigTypeIdOpaque:
21859 result = &ira->codegen->const_void_val;
21859 result = ira->codegen->intern.for_void();
2186021860 break;
2186121861 case ZigTypeIdInt:
2186221862 {
src/memory_profiling.cpp+1
......@@ -141,6 +141,7 @@ void memprof_dump_stats(FILE *file) {
141141 fprintf(stderr, "void: interned %zu times\n", memprof_intern_count.x_void);
142142 fprintf(stderr, "null: interned %zu times\n", memprof_intern_count.x_null);
143143 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);
144145}
145146
146147#endif
src/memory_profiling.hpp+1
......@@ -18,6 +18,7 @@ struct MemprofInternCount {
1818 size_t x_void;
1919 size_t x_null;
2020 size_t x_unreachable;
21 size_t zero_byte;
2122};
2223extern MemprofInternCount memprof_intern_count;
2324