-
Notifications
You must be signed in to change notification settings - Fork 219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add control flow graph (CFG) #1117
Comments
For the record we already have a CFG implemented in the BasicBlock structure, where blocks have left and right successors. |
Cranelift's public cfg interface is as follows: pub fn new() -> Self // What's the use case for an empty cfg?
pub fn clear(&mut self) // unneeded?
pub fn with_function(func: &Function) -> Self
pub fn compute(&mut self, func: &Function) // unneeded?
pub fn recompute_block(&mut self, func: &Function, block: Block)
pub fn pred_iter(&self, block: Block) -> PredIter // convenient?
pub fn succ_iter(&self, block: Block) -> SuccIter // convenient?
pub fn is_valid(&self) -> bool // unneeded? Successors are block references and predecessors are pairs of a block reference plus the instruction that led there. Keeping the instruction reference sounds like it could be useful to track (e.g. I see it being checked when block merging).
Since we know that our blocks will never have more than two predecessors I wonder if there's a more convenient representation to us. Before we had Note that cranelift's cfg encapsulates the building/traversal logic via an imported Essentially their cfg is tightly coupled to the data entities contained within it. The data required to compute the cfg is passed as a // Do we already have a struct for representing functions and their contents?
pub fn with_function(func: &Function) -> Self
pub fn recompute_block(&mut self, func: &Function, block_id: BlockId)
pub fn pred_iter(&self, block_id: BlockId) -> PredIter
pub fn succ_iter(&self, block_id: BlockId) -> SuccIter However, if we want better decoupling and for cfg building to be driven externally this might be better: pub fn new() -> Self
pub fn add_edge(from: BlockId, from_inst: InstId, to: BlockId)
pub fn clear_successors(block_id: BlockId) |
|
Problem
A CFG is a data structure that shows the flow of control in a program. The nodes of a CFG can be instructions, however since the control flow analysis of instructions that do not affect control flow is uninteresting, we group instructions into basic blocks.
The nodes of the CFG will be basic blocks. The CFG is useful for certain optimizations like loop analysis.
Proposed solution
Implement CFG data structure in a modular way with tests and comments.
Alternatives considered
No response
Additional context
No response
Submission Checklist
The text was updated successfully, but these errors were encountered: