Public Member Functions | Private Member Functions | Private Attributes

OA::CFG::ManagerCFGStandard Class Reference

#include <ManagerCFG.hpp>

Collaboration diagram for OA::CFG::ManagerCFGStandard:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 ManagerCFGStandard (OA_ptr< CFGIRInterface > _ir, bool _build_stmt_level_cfg=false)
virtual ~ManagerCFGStandard ()
virtual OA_ptr< CFGperformAnalysis (ProcHandle)

Private Member Functions

IRStmtType build_block (OA_ptr< Node > prev_node, OA_ptr< IRRegionStmtIterator > si, std::list< CFG::NodeLabel > &exit_nodes, OA_ptr< std::list< CFG::NodeLabel > > break_nodes, OA_ptr< std::list< CFG::NodeLabel > > return_nodes, OA_ptr< std::list< CFG::NodeLabel > > continue_nodes)
IRStmtType build_stmt (OA_ptr< Node > prev_node, OA::StmtHandle, std::list< CFG::NodeLabel > &exit_nodes, OA_ptr< std::list< CFG::NodeLabel > > break_nodes, OA_ptr< std::list< CFG::NodeLabel > > return_nodes, OA_ptr< std::list< CFG::NodeLabel > > continue_nodes)
IRStmtType build_CFG_loop (OA_ptr< Node > prev_node, OA::StmtHandle th, std::list< CFG::NodeLabel > &exit_nodes, OA_ptr< std::list< CFG::NodeLabel > > return_nodes)
IRStmtType build_CFG_twoway_branch (OA_ptr< Node > prev_node, OA::StmtHandle th, std::list< CFG::NodeLabel > &exit_nodes, OA_ptr< std::list< CFG::NodeLabel > > break_nodes, OA_ptr< std::list< CFG::NodeLabel > > return_nodes, OA_ptr< std::list< CFG::NodeLabel > > continue_nodes)
IRStmtType build_CFG_multiway_branch (OA_ptr< Node > prev_node, StmtHandle th, std::list< CFG::NodeLabel > &exit_nodes, OA_ptr< std::list< CFG::NodeLabel > > break_nodes, OA_ptr< std::list< CFG::NodeLabel > > return_nodes, OA_ptr< std::list< CFG::NodeLabel > > continue_nodes)
IRStmtType build_CFG_multiway_branch_with_fallthrough (OA_ptr< Node > prev_node, StmtHandle th, std::list< CFG::NodeLabel > &exit_nodes, OA_ptr< std::list< CFG::NodeLabel > > return_nodes, OA_ptr< std::list< CFG::NodeLabel > > continue_nodes)
IRStmtType build_CFG_end_tested_loop (OA_ptr< Node > prev_node, StmtHandle th, std::list< CFG::NodeLabel > &exit_nodes, OA_ptr< std::list< CFG::NodeLabel > > return_nodes)
IRStmtType build_CFG_unconditional_jump (OA_ptr< Node > prev_node, StmtHandle stmt)
IRStmtType build_CFG_ustruct_twoway_branch (OA_ptr< Node > prev_node, StmtHandle stmt, std::list< CFG::NodeLabel > &exit_nodes)
IRStmtType build_CFG_unconditional_jump_i (OA_ptr< Node > prev_node, StmtHandle stmt)
IRStmtType build_CFG_ustruct_multiway_branch (OA_ptr< Node > prev_node, StmtHandle stmt)
void HandleDelayedBranches ()
void createBasicCFG ()

Private Attributes

OA_ptr< CFGIRInterfacemIR
OA_ptr< CFGmCFG
std::map< OA_ptr< Node >
, OA_ptr< Node > > 
mFallThrough
const bool mBuildStmtLevelCFG

Detailed Description

The AnnotationManager for a CFGStandard Annotation. Knows how to build a CFG, read one in from a file, and write one out to a file.

Definition at line 50 of file ManagerCFG.hpp.


Constructor & Destructor Documentation

OA::CFG::ManagerCFGStandard::ManagerCFGStandard ( OA_ptr< CFGIRInterface _ir,
bool  _build_stmt_level_cfg = false 
)

Definition at line 43 of file ManagerCFG.cpp.

References OA::CFG::debug, mFallThrough, and OA_DEBUG_CTRL_MACRO.

virtual OA::CFG::ManagerCFGStandard::~ManagerCFGStandard (  )  [inline, virtual]

Definition at line 53 of file ManagerCFG.hpp.


Member Function Documentation

IRStmtType OA::CFG::ManagerCFGStandard::build_block ( OA_ptr< Node prev_node,
OA_ptr< IRRegionStmtIterator si,
std::list< CFG::NodeLabel > &  exit_nodes,
OA_ptr< std::list< CFG::NodeLabel > >  break_nodes,
OA_ptr< std::list< CFG::NodeLabel > >  return_nodes,
OA_ptr< std::list< CFG::NodeLabel > >  continue_nodes 
) [private]
IRStmtType OA::CFG::ManagerCFGStandard::build_CFG_end_tested_loop ( OA_ptr< Node prev_node,
StmtHandle  th,
std::list< CFG::NodeLabel > &  exit_nodes,
OA_ptr< std::list< CFG::NodeLabel > >  return_nodes 
) [private]

The general structure of an end-tested loop (e.g., do-while in C) CFG is as below:

              |
              |   ______
              |  /      \
              V V        |
             body        |
              |          |
              |          |
              V          |
          condition      |
              |/
              |
              |
              |
              V
    

The statement representing the do-while loop will be used to represent the condition block in the CFG.

Definition at line 844 of file ManagerCFG.cpp.

IRStmtType OA::CFG::ManagerCFGStandard::build_CFG_loop ( OA_ptr< Node prev_node,
OA::StmtHandle  th,
std::list< CFG::NodeLabel > &  exit_nodes,
OA_ptr< std::list< CFG::NodeLabel > >  return_nodes 
) [private]
IRStmtType OA::CFG::ManagerCFGStandard::build_CFG_multiway_branch ( OA_ptr< Node prev_node,
StmtHandle  th,
std::list< CFG::NodeLabel > &  exit_nodes,
OA_ptr< std::list< CFG::NodeLabel > >  break_nodes,
OA_ptr< std::list< CFG::NodeLabel > >  return_nodes,
OA_ptr< std::list< CFG::NodeLabel > >  continue_nodes 
) [private]

A multi-way branch consists of a multiway condition expression that branches off into a number of cases, and an optional catchall (default) body. The structure of a multi-way branch is as follows:

                |
                |
                V
         ___condition______
        /  /  |  \ ...    \
       /  /   |   \    \    \
      V  V    V    V    V    V
     B1  B2   B3  B4    Bk  catchall
      |  |    |    |    |    |
      |____|____|____|___/
                |
                |
                V
    

Definition at line 606 of file ManagerCFG.cpp.

IRStmtType OA::CFG::ManagerCFGStandard::build_CFG_multiway_branch_with_fallthrough ( OA_ptr< Node prev_node,
StmtHandle  th,
std::list< CFG::NodeLabel > &  exit_nodes,
OA_ptr< std::list< CFG::NodeLabel > >  return_nodes,
OA_ptr< std::list< CFG::NodeLabel > >  continue_nodes 
) [private]

This is similar to build_CFG_multiway_branch, but it handles switch statements that have fall-through semantics for each case (that is, there are no implied breaks). Each case can fall-through to the following case if an explicit control flow statement (e.g., break in C) is not present. Also, unlike build_CFG_multiway_branch, the catchall/default case is not necessarily the last. The functions are different enough that is seems cleaner to keep them separate.

FIXME: The default case is still assumed to be last. All of the underlying infrastructure of mint assumes this and has to be fixed. MMS 12/03: this function no longer assumes that the default case is last, not sure what other code might still make this assumption

Definition at line 695 of file ManagerCFG.cpp.

IRStmtType OA::CFG::ManagerCFGStandard::build_CFG_twoway_branch ( OA_ptr< Node prev_node,
OA::StmtHandle  th,
std::list< CFG::NodeLabel > &  exit_nodes,
OA_ptr< std::list< CFG::NodeLabel > >  break_nodes,
OA_ptr< std::list< CFG::NodeLabel > >  return_nodes,
OA_ptr< std::list< CFG::NodeLabel > >  continue_nodes 
) [private]

A two-way branch consists of a condition along with a true branch and a false branch. Note that "elseif" statements should be translated to this form while parsing, since, they are semantically equivalent to a chain of nested "else if" statements. Indeed, "elseif" is just a short form for "else if". The general structure of the CFG for a two-way branch is as follows:

        |
        V
    condition
      |      \
      V       V
   true_body false_body
      |          |
       /
           |
           V
    

Definition at line 491 of file ManagerCFG.cpp.

IRStmtType OA::CFG::ManagerCFGStandard::build_CFG_unconditional_jump ( OA_ptr< Node prev_node,
StmtHandle  stmt 
) [private]

Definition at line 901 of file ManagerCFG.cpp.

IRStmtType OA::CFG::ManagerCFGStandard::build_CFG_unconditional_jump_i ( OA_ptr< Node prev_node,
StmtHandle  stmt 
) [private]

Handle unconditional indirect jumps.

Create:

      goto statement
       |   ...   |
       |         |
       V         V
    potential   potential
    target 0    target n
    

Currently, any label in the program unit is considered to be a potential target of the indirect branch. This could be very conservative for some constructs, such as Fortran computed gotos (since we could more intelligently examine only those labels that are used in the Fortran ASSIGN statement -- i.e., labels that have their address taken and stored). It may be worthwhile to revisit this if unacceptably large graphs result from a combination of many labels and many indirect branches.

Definition at line 975 of file ManagerCFG.cpp.

IRStmtType OA::CFG::ManagerCFGStandard::build_CFG_ustruct_multiway_branch ( OA_ptr< Node prev_node,
StmtHandle  stmt 
) [private]

Handle unstructured multiway branches.

An unstructured multiway is essentially any non-structured branch with multiple targets. An optional default/catchall target is also allowed. Examples of this construct include Fortran's computed goto statement or a simple jump/dispatch table in a low-level intermediate representation. A vanilla jump table will not have a default target, but a Fortran computed goto (for example) may if it isn't known that one of the targets is always taken.

                |
                |
                V
         ____branch________
        /  /  |  \ ...    \
       /  /   |   \    \    \
      V  V    V    V    V    V
     B1  B2   B3  B4    Bk  catchall (optional)
    

Each edge will have an associated condition. For case-like statements, this is the case value for the particular target. For jump/dispatch tables or computed gotos, which have no conditions, the index of the target is used (i.e., 0..number_of_targets).

Definition at line 1018 of file ManagerCFG.cpp.

IRStmtType OA::CFG::ManagerCFGStandard::build_CFG_ustruct_twoway_branch ( OA_ptr< Node prev_node,
StmtHandle  stmt,
std::list< CFG::NodeLabel > &  exit_nodes 
) [private]

Handle unstructured twoway branches. The structure of a branch-on-true is as follows:

        |
        V
    condition_t
      |        \ (true edge)
      V          \
    fall-through   \
     block          V
                  true block
    

A similar subgraph is created for branch-on-false, except that the fall-through is on true and the branching edge is a false edge.

??? Use FALSE_EDGE?

Definition at line 934 of file ManagerCFG.cpp.

IRStmtType OA::CFG::ManagerCFGStandard::build_stmt ( OA_ptr< Node prev_node,
OA::StmtHandle  stmt,
std::list< CFG::NodeLabel > &  exit_nodes,
OA_ptr< std::list< CFG::NodeLabel > >  break_nodes,
OA_ptr< std::list< CFG::NodeLabel > >  return_nodes,
OA_ptr< std::list< CFG::NodeLabel > >  continue_nodes 
) [private]

Build a CFG for the IR rooted at the given node. The CFG builder depends upon the IR providing a minimal interface. In particular, the CFG needs for the IR nodes to be able to categorize themselves as simple statements, statement lists, loops, two-way branches, and multi-way branches.

The routine uses the given node prev_node as the entry node and updates the exit_nodes for the CFG that it builds. Notice that for every CFG component built by this call, there is exactly one entry node, but there may be multiple exit nodes.

Definition at line 218 of file ManagerCFG.cpp.

Referenced by build_block().

void OA::CFG::ManagerCFGStandard::createBasicCFG (  )  [private]
void OA::CFG::ManagerCFGStandard::HandleDelayedBranches (  )  [private]

Definition at line 1057 of file ManagerCFG.cpp.

References createBasicCFG().

Here is the call graph for this function:

OA_ptr< CFG > OA::CFG::ManagerCFGStandard::performAnalysis ( ProcHandle  proc  )  [virtual]

Definition at line 54 of file ManagerCFG.cpp.


Member Data Documentation

Definition at line 172 of file ManagerCFG.hpp.

Referenced by build_block().

Definition at line 161 of file ManagerCFG.hpp.

Referenced by build_block(), build_CFG_loop(), and createBasicCFG().

Definition at line 167 of file ManagerCFG.hpp.

Referenced by createBasicCFG(), and ManagerCFGStandard().

Definition at line 160 of file ManagerCFG.hpp.

Referenced by build_block(), build_CFG_loop(), and createBasicCFG().


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