48 function.
name =
"simplify";
55 slot.kind = Compiler_IR_Slot_Kind::Local;
61 entry.
label =
"entry";
64 c1.
kind = Compiler_IR_Instruction_Kind::Constant;
70 store1.
kind = Compiler_IR_Instruction_Kind::Store;
76 cond.
kind = Compiler_IR_Instruction_Kind::Constant;
90 exit.terminator.kind = Compiler_IR_Terminator_Kind::Exit;
91 exit.predecessors.append(3);
98 c2.
kind = Compiler_IR_Instruction_Kind::Constant;
104 store2.
kind = Compiler_IR_Instruction_Kind::Store;
106 store2.operands.append(3);
109 then_block.terminator.kind = Compiler_IR_Terminator_Kind::Jump;
123 join_block.terminator.kind = Compiler_IR_Terminator_Kind::Return;
134 c3.
kind = Compiler_IR_Instruction_Kind::Constant;
140 store3.
kind = Compiler_IR_Instruction_Kind::Store;
142 store3.operands.append(4);
145 else_block.terminator.kind = Compiler_IR_Terminator_Kind::Jump;
149 function.
blocks.append(entry);
167 std::cout <<
"OptimizedSummary\n";
168 std::cout <<
" Blocks: " <<
optimized.function.blocks.size() <<
'\n';
169 std::cout <<
" RemovedBlocks: " <<
optimized.removed_blocks <<
'\n';
170 std::cout <<
" RemovedInstructions: " <<
optimized.removed_instructions <<
'\n';
171 std::cout <<
" FoldedBranches: " <<
optimized.folded_branches <<
'\n';
172 for (
size_t i = 0; i <
optimized.function.blocks.size(); ++i)
174 const auto & block =
optimized.function.blocks.access(i);
175 std::cout <<
" Block " << i <<
" [" << block.
label <<
"] -> "
181 std::cout <<
"\nWarnings:\n";
184 for (
size_t i = 0; i <
dce_report.warnings.size(); ++i)
185 std::cout <<
"- " <<
dce_report.warnings.access(i) <<
'\n';
Reusable dataflow analyses and dead-code elimination over Compiler_IR_Model.H.
T & append()
Allocate a new entry to the end of array.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Main namespace for Aleph-w library functions.
const char * compiler_ir_terminator_kind_name(const Compiler_IR_Terminator_Kind kind) noexcept
Stable debug name for one terminator kind.
Compiler_Dataflow_Validation_Report validate_dead_code_elimination(const Compiler_Dead_Code_Elimination_Result &result, const Compiler_IR_Module *module=nullptr)
Validates the result of dead-code elimination.
Compiler_Dataflow_Function_Analysis analyze_dataflow_function(const Compiler_IR_Function &function)
Computes reachability, liveness, definite assignment, and constant propagation for one IR function.
void exit(const char *file, int line, const char *format,...)
Print a message and exit the program.
and
Check uniqueness with explicit hash + equality functors.
Compiler_Dead_Code_Elimination_Result eliminate_dead_code(const Compiler_IR_Function &function)
Eliminates unreachable blocks, dead pure instructions, dead local stores, and folds constant-conditio...
Compiler_Dataflow_Validation_Report validate_dataflow_analysis(const Compiler_IR_Function &function, const Compiler_Dataflow_Function_Analysis &analysis)
Validates structural invariants of a dataflow result against its source function.
std::string compiler_dump_dataflow_analysis(const Compiler_IR_Function *function, const Compiler_Dataflow_Function_Analysis &analysis, const Compiler_Type_Context *types=nullptr)
Produces a deterministic, human-readable dump of a dataflow result.
One basic block of IR instructions.
std::string label
Deterministic debug label.
Compiler_IR_Terminator terminator
Explicit block terminator.
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.
bool bool_value
Decoded boolean payload for bool constants.
Compiler_IR_Instruction_Kind kind
Instruction category.
Compiler_IR_Value_Id result_id
Produced value id, or 0 for void instructions.
One storage slot used by the IR.
size_t id
Stable slot id within its storage space.
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.
std::string label
Deterministic debug label.
Compiler_SSA_Terminator terminator
Explicit block terminator.
Compiler_IR_Terminator_Kind kind
Terminator category.