refactor ir.cpp

Analysis functions no longer return `ZigType *`. Instead they
return `IrInstruction *`.
This commit is contained in:
Andrew Kelley 2018-10-04 14:32:55 -04:00
parent 31469daca3
commit 23b07ad8d2
No known key found for this signature in database
GPG Key ID: 4E7CD66038A4D47C
4 changed files with 1716 additions and 2124 deletions

View File

@ -1690,6 +1690,7 @@ struct CodeGen {
Buf cache_dir;
IrInstruction *invalid_instruction;
IrInstruction *unreach_instruction;
ConstExprValue const_void_val;
ConstExprValue panic_msg_vals[PanicMsgIdCount];
@ -2183,7 +2184,10 @@ struct IrInstruction {
// if ref_count is zero and the instruction has no side effects,
// the instruction can be omitted in codegen
size_t ref_count;
IrInstruction *other;
// When analyzing IR, instructions that point to this instruction in the "old ir"
// can find the instruction that corresponds to this value in the "new ir"
// with this child field.
IrInstruction *child;
IrBasicBlock *owner_bb;
// true if this instruction was generated by zig and not from user code
bool is_gen;

View File

@ -5512,10 +5512,19 @@ Error type_resolve(CodeGen *g, ZigType *ty, ResolveStatus status) {
}
bool ir_get_var_is_comptime(ZigVar *var) {
if (!var->is_comptime)
// The is_comptime field can be left null, which means not comptime.
if (var->is_comptime == nullptr)
return false;
if (var->is_comptime->other)
return var->is_comptime->other->value.data.x_bool;
// When the is_comptime field references an instruction that has to get analyzed, this
// is the value.
if (var->is_comptime->child != nullptr) {
assert(var->is_comptime->child->value.type->id == ZigTypeIdBool);
return var->is_comptime->child->value.data.x_bool;
}
// As an optimization, is_comptime values which are constant are allowed
// to be omitted from analysis. In this case, there is no child instruction
// and we simply look at the unanalyzed const parent instruction.
assert(var->is_comptime->value.type->id == ZigTypeIdBool);
return var->is_comptime->value.data.x_bool;
}

View File

@ -7279,10 +7279,15 @@ static void init(CodeGen *g) {
define_builtin_types(g);
g->invalid_instruction = allocate<IrInstruction>(1);
IrInstruction *sentinel_instructions = allocate<IrInstruction>(2);
g->invalid_instruction = &sentinel_instructions[0];
g->invalid_instruction->value.type = g->builtin_types.entry_invalid;
g->invalid_instruction->value.global_refs = allocate<ConstGlobalRefs>(1);
g->unreach_instruction = &sentinel_instructions[1];
g->unreach_instruction->value.type = g->builtin_types.entry_unreachable;
g->unreach_instruction->value.global_refs = allocate<ConstGlobalRefs>(1);
g->const_void_val.special = ConstValSpecialStatic;
g->const_void_val.type = g->builtin_types.entry_void;
g->const_void_val.global_refs = allocate<ConstGlobalRefs>(1);

3812
src/ir.cpp

File diff suppressed because it is too large Load Diff