Nearly CC
An educational compiler skeleton
Classes | Public Types | Public Member Functions | List of all members
ControlFlowGraph Class Reference

ControlFlowGraph: graph of basic blocks connected by control edges. More...

#include "cfg.h"

Public Types

typedef std::vector< std::shared_ptr< InstructionSequence > > BlockList
 Data type for a vector of basic blocks.
 
typedef std::vector< Edge * > EdgeList
 Data type for a vector of edges.
 
typedef std::map< std::shared_ptr< InstructionSequence >, EdgeListEdgeMap
 Data type for a map of basic blocks to an EdgeList.
 

Public Member Functions

unsigned get_num_blocks () const
 Get total number of basic blocks (including entry and exit). More...
 
std::shared_ptr< InstructionSequenceget_entry_block () const
 Get pointer to the dedicated empty entry block. More...
 
std::shared_ptr< InstructionSequenceget_exit_block () const
 Get pointer to the dedicated empty exit block. More...
 
std::shared_ptr< InstructionSequenceget_block (unsigned id) const
 Get block with specified id. More...
 
BlockList::const_iterator bb_begin () const
 Get a begin iterator for the list of all basic blocks in the ControlFlowGraph. More...
 
BlockList::const_iterator bb_end () const
 Get an end iterator for the list of all basic blocks in the ControlFlowGraph. More...
 
std::shared_ptr< InstructionSequencecreate_basic_block (BasicBlockKind kind, int code_order, const std::string &label="")
 Create a new InstructionSequence. More...
 
void adopt_basic_block (std::shared_ptr< InstructionSequence > &bb)
 Adopt a new basic block. More...
 
Edgecreate_edge (std::shared_ptr< InstructionSequence > source, std::shared_ptr< InstructionSequence > target, EdgeKind kind)
 Create Edge of given kind from source basic block to target basic block. More...
 
Edgelookup_edge (std::shared_ptr< InstructionSequence > source, std::shared_ptr< InstructionSequence > target) const
 Look up edge from specified source block to target block. More...
 
const EdgeListget_outgoing_edges (std::shared_ptr< InstructionSequence > bb) const
 Get vector of all outgoing edges from given block. More...
 
const EdgeListget_incoming_edges (std::shared_ptr< InstructionSequence > bb) const
 Get vector of all incoming edges to given block. More...
 
std::shared_ptr< InstructionSequencecreate_instruction_sequence () const
 Return a "flat" InstructionSequence created from this ControlFlowGraph. More...
 

Detailed Description

ControlFlowGraph: graph of basic blocks connected by control edges.

There are dedicated empty entry and exit blocks. An InstructionSequence can be converted to a ControlFlowGraph by a ControlFlowGraphBuilder object.

Member Function Documentation

◆ adopt_basic_block()

void ControlFlowGraph::adopt_basic_block ( std::shared_ptr< InstructionSequence > &  bb)

Adopt a new basic block.

(Used by ControlFlowGraphTransform to add transformed blocks to the transformed ControlFlowGraph.)

Parameters
bbthe basic block to adopt

◆ bb_begin()

BlockList::const_iterator ControlFlowGraph::bb_begin ( ) const
inline

Get a begin iterator for the list of all basic blocks in the ControlFlowGraph.

Returns
begin iterator to list of basic blocks

◆ bb_end()

BlockList::const_iterator ControlFlowGraph::bb_end ( ) const
inline

Get an end iterator for the list of all basic blocks in the ControlFlowGraph.

Returns
end iterator to list of basic blocks

◆ create_basic_block()

std::shared_ptr< InstructionSequence > ControlFlowGraph::create_basic_block ( BasicBlockKind  kind,
int  code_order,
const std::string &  label = "" 
)

Create a new InstructionSequence.

Use BASICBLOCK_INTERIOR for all blocks except for entry and exit. The label parameter should be a non-empty string if the InstructionSequence is reached via one or more branch instructions (which should have this label as their Operand.)

Parameters
kindthe BasicBlockKind for the block to be created
code_orderrelative order of this basic block in the original InstructionSequence (so that when the ControlFlowGraph is converted back to an InstructionSequence, the instructions are in the "correct" order)
labellabel of the first instruction (if this basic block is reached by any branch edges)
Returns
a shared pointer to the new basic block

◆ create_edge()

Edge * ControlFlowGraph::create_edge ( std::shared_ptr< InstructionSequence source,
std::shared_ptr< InstructionSequence target,
EdgeKind  kind 
)

Create Edge of given kind from source basic block to target basic block.

Note that Edge objects are owned by the ControlFlowGraph.

Parameters
sourcethe source basic block
targetthe target basic block
theEdgeKind of the Edge to create
Returns
the created Edge

◆ create_instruction_sequence()

std::shared_ptr< InstructionSequence > ControlFlowGraph::create_instruction_sequence ( ) const

Return a "flat" InstructionSequence created from this ControlFlowGraph.

This is useful for optimization passes which create a transformed ControlFlowGraph.

Returns
an InstructionSequence containing all instructions in all

◆ get_block()

std::shared_ptr<InstructionSequence> ControlFlowGraph::get_block ( unsigned  id) const
inline

Get block with specified id.

Parameters
idthe id value of a basic block
Returns
the basic block with the specified id

◆ get_entry_block()

std::shared_ptr< InstructionSequence > ControlFlowGraph::get_entry_block ( ) const

Get pointer to the dedicated empty entry block.

Returns
the entry block

◆ get_exit_block()

std::shared_ptr< InstructionSequence > ControlFlowGraph::get_exit_block ( ) const

Get pointer to the dedicated empty exit block.

Returns
the exit block

◆ get_incoming_edges()

const ControlFlowGraph::EdgeList & ControlFlowGraph::get_incoming_edges ( std::shared_ptr< InstructionSequence bb) const

Get vector of all incoming edges to given block.

Parameters
bbthe basic block
Returns
EdgeList of all incoming edges to the basic block

◆ get_num_blocks()

unsigned ControlFlowGraph::get_num_blocks ( ) const
inline

Get total number of basic blocks (including entry and exit).

Returns
total number of basic blocks

◆ get_outgoing_edges()

const ControlFlowGraph::EdgeList & ControlFlowGraph::get_outgoing_edges ( std::shared_ptr< InstructionSequence bb) const

Get vector of all outgoing edges from given block.

Parameters
bbthe basic block
Returns
EdgeList of all outgoing edges from the basic block

◆ lookup_edge()

Edge * ControlFlowGraph::lookup_edge ( std::shared_ptr< InstructionSequence source,
std::shared_ptr< InstructionSequence target 
) const

Look up edge from specified source block to target block.

Returns a null pointer if no such block exists

Parameters
sourcethe source basic block
targetthe target basic block
Returns
the Edge connecting the source block to the target block, or a null pointer if there is no such control edge

The documentation for this class was generated from the following files: