48 function.
name =
"choose";
54 flag.
kind = Compiler_IR_Slot_Kind::Parameter;
60 value.kind = Compiler_IR_Slot_Kind::Local;
66 entry.
label =
"entry";
69 zero.
kind = Compiler_IR_Instruction_Kind::Constant;
75 init_store.
kind = Compiler_IR_Instruction_Kind::Store;
81 load_flag.
kind = Compiler_IR_Instruction_Kind::Load;
94 exit.terminator.kind = Compiler_IR_Terminator_Kind::Exit;
95 exit.predecessors.append(3);
99 then_block.
label =
"if.then.0";
102 one.
kind = Compiler_IR_Instruction_Kind::Constant;
108 then_store.
kind = Compiler_IR_Instruction_Kind::Store;
119 join_block.
label =
"if.end.0";
122 load_value.
kind = Compiler_IR_Instruction_Kind::Load;
135 else_block.
label =
"if.else.0";
138 two.
kind = Compiler_IR_Instruction_Kind::Constant;
144 else_store.
kind = Compiler_IR_Instruction_Kind::Store;
153 function.
blocks.append(entry);
155 function.
blocks.append(then_block);
156 function.
blocks.append(join_block);
157 function.
blocks.append(else_block);
160 for (
size_t i = 0; i < function.
blocks.size(); ++i)
181 auto function = make_demo_function();
182 module.functions.append(&function);
188 if (not report.warnings.is_empty())
190 std::cout <<
"\nWarnings:\n";
191 for (
size_t i = 0; i < report.warnings.size(); ++i)
192 std::cout <<
"- " << report.warnings.access(i) <<
'\n';
195 return report.valid ? 0 : 1;
Static single assignment form over Compiler_IR.H.
size_t size_t int32_t value
Arena-backed ownership context for SSA functions and modules.
Lowers non-SSA IR to SSA form for all reachable blocks.
Compiler_SSA_Module * lower_module(const Compiler_IR_Module *module) const
Lowers one IR module to SSA form.
T & append()
Allocate a new entry to the end of array.
Compiler_SSA_Block & block(Compiler_SSA_Function &function, const Compiler_SSA_Block_Id id)
Main namespace for Aleph-w library functions.
Compiler_SSA_Validation_Report validate_ssa_module(const Compiler_SSA_Module &module)
Validates all functions in one SSA module.
void exit(const char *file, int line, const char *format,...)
Print a message and exit the program.
std::string compiler_dump_ssa_module(const Compiler_SSA_Module *module, const Compiler_Type_Context *types=nullptr)
Dumps all SSA functions in one module deterministically.
One basic block of IR instructions.
std::string label
Deterministic debug label.
Compiler_IR_Terminator terminator
Explicit block terminator.
DynArray< Compiler_IR_Block_Id > predecessors
Predecessor block ids.
DynArray< Compiler_IR_Instruction > instructions
Linear instruction list.
Compiler_IR_Block_Id id
Stable block id.
Lowered IR for one function or top-level body.
Compiler_IR_Value_Id next_value_id
Next value id to allocate while lowering.
DynArray< Compiler_IR_Block > blocks
Basic blocks in deterministic id order.
std::string name
Debug or source-level name.
Compiler_IR_Block_Id exit_block
Canonical exit block.
Compiler_IR_Block_Id entry_block
Canonical entry block.
DynArray< Compiler_IR_Slot > local_slots
Parameter/local slots in stable order.
One instruction producing an optional explicit result value.
std::string text
Constant spelling or debug payload.
Compiler_IR_Instruction_Kind kind
Instruction category.
Compiler_IR_Value_Id result_id
Produced value id, or 0 for void instructions.
DynArray< Compiler_IR_Value_Id > operands
Input values in deterministic order.
Compiler_IR_Local_Slot_Id local_slot_id
Referenced local/parameter slot, when relevant.
Lowered IR module with shared global slots and functions.
One storage slot used by the IR.
std::string name
Debug name of the slot.
size_t id
Stable slot id within its storage space.
Compiler_IR_Slot_Kind kind
Slot storage category.
Compiler_IR_Terminator_Kind kind
Terminator category.
DynArray< Compiler_IR_Block_Id > successors
Successor blocks in deterministic order.
Compiler_IR_Value_Id condition_value
Branch condition value, if any.
Compiler_IR_Value_Id return_value
Return value, if any.
DynArray< Compiler_SSA_Instruction > instructions
Linear SSA instruction list.