|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Transformation engine that lowers typed HIR into reusable CFGs. More...
#include <Compiler_CFG.H>
Classes | |
| struct | Loop_Targets |
| Internal state for loop lowering. More... | |
Public Member Functions | |
| Compiler_CFG_Lowering (Compiler_CFG_Context &ctx, const Compiler_Type_Context *type_ctx=nullptr) noexcept | |
| Builds a CFG lowerer over the specified context. | |
| const Compiler_Type_Context * | type_context () const noexcept |
| Returns the optional type context used by this lowerer. | |
| Compiler_CFG_Function * | lower_function (const Compiler_HIR_Function *function) |
| Lowers one HIR function into a CFG. | |
| Compiler_CFG_Module * | lower_module (const Compiler_HIR_Module *module) |
| Lowers one HIR module into function CFGs and optional top-level CFG. | |
Static Private Member Functions | |
| static void | merge_span (Source_Span &dst, const Source_Span &src) |
| Utility to merge a source span into a destination span. | |
Private Attributes | |
| Compiler_CFG_Context * | cfg_ = nullptr |
| CFG owner. | |
| const Compiler_Type_Context * | types_ = nullptr |
| Type metadata source. | |
| size_t | if_counter_ = 0 |
| ID generator for conditional blocks. | |
| size_t | while_counter_ = 0 |
| ID generator for loop blocks. | |
| size_t | dead_counter_ = 0 |
| ID generator for unreachable blocks. | |
Transformation engine that lowers typed HIR into reusable CFGs.
Decomposes structured control flow (if, while, blocks) into a graph of basic blocks connected by explicit terminators.
Definition at line 346 of file Compiler_CFG.H.
|
inlineexplicitnoexcept |
Builds a CFG lowerer over the specified context.
| ctx | Ownership context for the produced CFG nodes. |
| type_ctx | Optional type context used by textual dumps later. |
Definition at line 641 of file Compiler_CFG.H.
|
inlineprivate |
Adds a directed edge from one block to another.
Definition at line 391 of file Compiler_CFG.H.
References block(), Aleph::blossom_maximum_cardinality_matching(), and Aleph::Compiler_CFG_Detail::contains_block_id().
Referenced by set_branch().
|
inlineprivate |
Appends a linear statement to a block and updates its span.
Definition at line 405 of file Compiler_CFG.H.
References block(), Aleph::blossom_maximum_cardinality_matching(), merge_span(), and Aleph::Compiler_HIR_Node::span.
Referenced by lower_stmt().
|
inlineprivate |
Accesses a block by ID within a function.
Definition at line 362 of file Compiler_CFG.H.
References Aleph::Compiler_CFG_Function::blocks.
Referenced by add_edge(), append_linear_stmt(), create_block(), lower_statement_sequence(), set_branch(), and set_exit().
|
inlineprivate |
Creates a new basic block in the given function.
Definition at line 381 of file Compiler_CFG.H.
References block(), Aleph::Compiler_CFG_Function::blocks, Aleph::Compiler_CFG_Block::id, and Aleph::Compiler_CFG_Block::label.
Referenced by ensure_current_block(), lower_statement_sequence(), and lower_stmt().
|
inlineprivate |
Ensures a valid current block exists, creating a "dead" one if needed.
Definition at line 480 of file Compiler_CFG.H.
References Aleph::compiler_cfg_invalid_block_id(), create_block(), and dead_counter_.
Referenced by lower_stmt().
|
inline |
Lowers one HIR function into a CFG.
| function | Typed HIR function to lower. |
Definition at line 657 of file Compiler_CFG.H.
References ah_runtime_error_unless, Aleph::blossom_maximum_cardinality_matching(), Aleph::Compiler_HIR_Function::body, lower_statement_sequence(), Aleph::Compiler_HIR_Function::name, Aleph::Compiler_HIR_Node::span, Aleph::Compiler_HIR_Block_Stmt::statements, and Aleph::Compiler_HIR_Function::type_id.
Referenced by lower_module().
|
inline |
Lowers one HIR module into function CFGs and optional top-level CFG.
| module | Typed HIR module to lower. |
Definition at line 678 of file Compiler_CFG.H.
References ah_runtime_error_unless, Aleph::blossom_maximum_cardinality_matching(), cfg_, Aleph::Compiler_CFG_Module::functions, Aleph::Compiler_HIR_Module::functions, lower_function(), lower_statement_sequence(), Aleph::Compiler_CFG_Context::make(), Aleph::Compiler_HIR_Node::span, and Aleph::Compiler_HIR_Module::statements.
|
inlineprivate |
Lowers a sequence of statements into a new CFG function.
Definition at line 609 of file Compiler_CFG.H.
References Aleph::DynArray< T >::access(), Aleph::and, block(), Aleph::blossom_maximum_cardinality_matching(), cfg_, Aleph::compiler_cfg_invalid_block_id(), create_block(), Aleph::Compiler_CFG_Function::entry_block, Aleph::Compiler_CFG_Function::exit_block, lower_stmt(), Aleph::Compiler_CFG_Context::make(), Aleph::Compiler_CFG_Function::name, set_exit(), set_jump(), Aleph::DynArray< T >::size(), Aleph::Compiler_CFG_Function::source_function, Aleph::Compiler_CFG_Function::span, and Aleph::Compiler_CFG_Function::type_id.
Referenced by lower_function(), and lower_module().
|
inlineprivate |
Recursively lowers an HIR statement into the CFG.
Definition at line 489 of file Compiler_CFG.H.
References append_linear_stmt(), Aleph::Block, Aleph::blossom_maximum_cardinality_matching(), Aleph::Break, Aleph::compiler_cfg_invalid_block_id(), Aleph::Continue, create_block(), ensure_current_block(), Aleph::Eval, Aleph::If, if_counter_, Aleph::Invalid, Aleph::Compiler_CFG_Detail::is_linear_stmt(), Aleph::Compiler_HIR_Stmt::kind, Aleph::Let, lower_stmt(), Aleph::Return, set_branch(), set_jump(), set_return(), set_unreachable(), Aleph::Compiler_CFG_Function::span, Aleph::Compiler_HIR_Node::span, Aleph::While, and while_counter_.
Referenced by lower_statement_sequence(), and lower_stmt().
|
inlinestaticprivate |
Utility to merge a source span into a destination span.
Definition at line 368 of file Compiler_CFG.H.
References Aleph::blossom_maximum_cardinality_matching(), Aleph::compiler_hir_merge_spans(), and Aleph::Source_Span::is_valid().
Referenced by append_linear_stmt(), and set_branch().
|
inlineprivate |
Sets a Branch terminator on a block.
Definition at line 429 of file Compiler_CFG.H.
References add_edge(), ah_runtime_error_unless, block(), Aleph::blossom_maximum_cardinality_matching(), Aleph::Branch, merge_span(), and Aleph::Compiler_HIR_Node::span.
Referenced by lower_stmt().
|
inlineprivate |
Sets an Exit terminator (only for the canonical exit block).
Definition at line 461 of file Compiler_CFG.H.
References block(), Aleph::blossom_maximum_cardinality_matching(), and Aleph::Exit.
Referenced by lower_statement_sequence().
|
inlineprivate |
Sets a Jump terminator on a block.
Definition at line 415 of file Compiler_CFG.H.
Referenced by lower_statement_sequence(), and lower_stmt().
|
inlineprivate |
Sets a Return terminator on a block.
Definition at line 446 of file Compiler_CFG.H.
Referenced by lower_stmt().
|
inlineprivate |
Sets an Unreachable terminator on a block.
Definition at line 468 of file Compiler_CFG.H.
Referenced by lower_stmt().
|
inlinenoexcept |
Returns the optional type context used by this lowerer.
Definition at line 647 of file Compiler_CFG.H.
References types_.
|
private |
CFG owner.
Definition at line 355 of file Compiler_CFG.H.
Referenced by lower_module(), and lower_statement_sequence().
|
private |
ID generator for unreachable blocks.
Definition at line 359 of file Compiler_CFG.H.
Referenced by ensure_current_block().
|
private |
ID generator for conditional blocks.
Definition at line 357 of file Compiler_CFG.H.
Referenced by lower_stmt().
|
private |
|
private |
ID generator for loop blocks.
Definition at line 358 of file Compiler_CFG.H.
Referenced by lower_stmt().