systemc-clang 2.0.0
Parsing SystemC constructs
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
systemc_clang::SplitCFG Class Reference

#include <SplitCFG.h>

Collaboration diagram for systemc_clang::SplitCFG:
Collaboration graph
[legend]

Public Types

using SplitCFGPathPair = std::pair<const SplitCFGBlock *, SupplementaryInfo>
 
using SplitCFGPath = llvm::SmallVector<SplitCFGPathPair>
 
using VectorSplitCFGBlock = llvm::SmallVector<const SplitCFGBlock *>
 
using VectorSplitCFGBlockImpl = llvm::SmallVector<const SplitCFGBlock *>
 
using VectorCFGElementPtrImpl
 
using VectorCFGElementPtr = llvm::SmallVector<const clang::CFGElement *>
 

Public Member Functions

 SplitCFG (clang::ASTContext &context)
 Constructor.
 
 SplitCFG (clang::ASTContext &context, const clang::CXXMethodDecl *cxx_decl)
 Overloaded constructor.
 
 SplitCFG (const SplitCFG &from)=delete
 Disallow a copy constructor for SCCFG.
 
SplitCFGoperator= (const SplitCFG &)=delete
 Disallow assignment operator.
 
virtual ~SplitCFG ()
 Destructor that erases all SplitCFGBlocks created.
 
const llvm::SmallVectorImpl< llvm::SmallVector< SplitCFGPathPair > > & getPathsFound ()
 Returns the paths that were found in the SCCFG.
 
void construct_sccfg (const clang::CXXMethodDecl *method)
 Construct the SCCFG.
 
void generate_paths ()
 Generates the paths between wait statements.
 
const std::unordered_map< const SplitCFGBlock *, SplitCFGPathInfo > & getPathInfo () const
 
const llvm::SmallVector< std::unordered_map< const SplitCFGBlock *, SplitCFGPathInfo > > & getAllPathInfo () const
 
void preparePathInfo ()
 
llvm::APInt getWaitArgument (const clang::CFGElement &element) const
 Returns the argument to a wait statement. Note that the only one supported are no arguments or integer arguments.
 
void dump () const
 Dump member functions.
 
void dumpToDot () const
 
void dumpWaitNextStates () const
 
void dumpPaths () const
 
void dumpCurrPath (SplitCFGPath &curr_path) const
 
void dumpPathInfo () const
 
void dumpAllPathInfo () const
 
std::map< SplitCFGBlock *, SplitCFGBlock * > getConfluenceBlocks () const
 Rework.
 
void identifyConfluenceBlocks ()
 Identify confluence blocks in the CFG.
 
std::set< SplitCFGBlock * > identifySkipBlocks ()
 
template<typename T >
void dumpSmallVector (llvm::SmallVectorImpl< T > &vlist)
 
const SplitCFGPath dfs_visit_wait (const SplitCFGBlock *BB, llvm::SmallPtrSet< const SplitCFGBlock *, 32 > &visited_blocks, llvm::SmallVectorImpl< const SplitCFGBlock * > &waits_to_visit, llvm::SmallPtrSetImpl< const SplitCFGBlock * > &visited_waits, llvm::SmallVector< SplitCFGPathPair > &curr_path)
 Modified DFS to create all paths within wait statements and from the root node.
 
void dfs_rework ()
 
bool isTernaryOperator (const SplitCFGBlock *block) const
 Checks if the block is contains a terminator that is a ternary operator.
 
bool isLoop (const SplitCFGBlock *block) const
 Checks if the block is a loop block.
 
bool isConditional (const SplitCFGBlock *block) const
 Checks if the block is a conditional. Note that this is different than ternary since the terminator is different.
 
bool getUnvisitedSuccessor (const SplitCFGBlock *curr_block, SplitCFGBlock::const_succ_iterator &I, llvm::SmallPtrSetImpl< const SplitCFGBlock * > &visited, const SplitCFGBlock *&block)
 
bool isLoopWithTwoSuccessors (const SplitCFGBlock *block) const
 
void addSuccessorToVisitOrPop (bool parent_has_wait, const SplitCFGBlock *BB, llvm::SmallVector< std::pair< const SplitCFGBlock *, SplitCFGBlock::const_succ_iterator >, 8 > &to_visit, bool found)
 
bool isTruePath (const SplitCFGBlock *parent_block, const SplitCFGBlock *block) const
 
void setDifference (const llvm::SmallPtrSetImpl< const SplitCFGBlock * > &larger, const llvm::SmallPtrSetImpl< const SplitCFGBlock * > &smaller, llvm::SmallPtrSetImpl< const SplitCFGBlock * > &to)
 Compute the set difference between two SmallPtrSets.
 
void setTruePathInfo (const SplitCFGBlock *sblock, const SplitCFGPath &newly_visited, int ix=-1)
 
void setFalsePathInfo (const SplitCFGBlock *sblock, const SplitCFGPath &newly_visited)
 
void addPathToSpecialNode (const SplitCFGPath &from)
 
void updateVisitedBlocks (llvm::SmallPtrSetImpl< const SplitCFGBlock * > &to, const llvm::SmallPtrSetImpl< const SplitCFGBlock * > &from)
 
void dumpVisitedBlocks (llvm::SmallPtrSetImpl< const SplitCFGBlock * > &visited)
 

Public Attributes

SplitCFGBlockoutter_top
 
bool popping_
 

Private Member Functions

bool isElementWait (const clang::CFGElement &element) const
 Checks if a CFGBlock has a wait() call in it.
 
void splitBlock (clang::CFGBlock *block)
 Split a CFGBlock into respective SplitCFGBlock if the CFGBlock has wait statements in it.
 
void addSuccessors (SplitCFGBlock *to, const clang::CFGBlock *from)
 Add successors to the SplitCFGBlock.
 
void addPredecessors (SplitCFGBlock *to, const clang::CFGBlock *from)
 Add predecessors to the SplitCFGBlock.
 
void addNextStatesToBlocks ()
 
void createUnsplitBlocks ()
 Creates SplitCFGBlocks for all CFGBlocks that do not have a wiat. splitBlock() creates the SplitCFGBlocks used for splitting CFGBLocks that have wait statements.
 
void createWaitSplitCFGBlocks (clang::CFGBlock *block, const llvm::SmallVectorImpl< std::pair< VectorCFGElementPtr, bool > > &split_elements)
 Creates the SplitCFGBlocks for CFGBlock with a wait.
 
void dumpSplitElements (const llvm::SmallVector< std::pair< VectorCFGElementPtr, bool > > &split_elements) const
 Dump all the CFGElements that were split.
 
void dumpSCCFG () const
 

Private Attributes

clang::ASTContext & context_
 The context necessary to access translation unit.
 
std::unique_ptr< clang::CFG > cfg_
 The saved CFG for a given method.
 
std::unordered_map< const clang::CFGBlock *, SplitCFGBlocksplit_blocks_
 The split blocks in the CFG.
 
llvm::SmallVector< SplitCFGPathpaths_
 Paths of BBs generated.
 
std::unordered_map< unsigned int, SplitCFGBlock * > sccfg_
 The block id to block for SCCFG.
 
llvm::SmallVector< std::pair< VectorCFGElementPtrImpl, bool > > split_elements
 
std::unordered_map< const SplitCFGBlock *, std::pair< const SplitCFGBlock *, unsigned int > > wait_next_state_
 Predecessor SplitCFGBlock* => (Wait SplitCFGBlock*)
 
std::unordered_map< const SplitCFGBlock *, SplitCFGPathInfopath_info_
 Map a SplitCFGBlock* to its path information. Stores the path information for the blocks that are important. The important blocks are (1) conditionals, and (2) loop blocks with two outgoing edges.
 
llvm::SmallVector< std::unordered_map< const SplitCFGBlock *, SplitCFGPathInfo > > all_path_info_
 
SplitCFGPath sub_path_to_special_node_
 
unsigned int next_state_count_
 
bool has_ternary_op_
 Set to true if the CFG has a ternary operator (ConditionalOperator).
 
std::map< SplitCFGBlock *, SplitCFGBlock * > cop_
 

Detailed Description

===========================================

SplitCFG

Definition at line 92 of file SplitCFG.h.

Member Typedef Documentation

◆ SplitCFGPath

Definition at line 95 of file SplitCFG.h.

◆ SplitCFGPathPair

Definition at line 94 of file SplitCFG.h.

◆ VectorCFGElementPtr

using systemc_clang::SplitCFG::VectorCFGElementPtr = llvm::SmallVector<const clang::CFGElement *>

Definition at line 102 of file SplitCFG.h.

◆ VectorCFGElementPtrImpl

Initial value:
llvm::SmallVectorImpl<const clang::CFGElement *>

Definition at line 100 of file SplitCFG.h.

◆ VectorSplitCFGBlock

using systemc_clang::SplitCFG::VectorSplitCFGBlock = llvm::SmallVector<const SplitCFGBlock *>

Definition at line 98 of file SplitCFG.h.

◆ VectorSplitCFGBlockImpl

Definition at line 99 of file SplitCFG.h.

Constructor & Destructor Documentation

◆ SplitCFG() [1/3]

SplitCFG::SplitCFG ( clang::ASTContext & context)

Constructor.

Definition at line 1154 of file SplitCFG.cpp.

◆ SplitCFG() [2/3]

SplitCFG::SplitCFG ( clang::ASTContext & context,
const clang::CXXMethodDecl * cxx_decl )

Overloaded constructor.

Definition at line 1162 of file SplitCFG.cpp.

◆ SplitCFG() [3/3]

systemc_clang::SplitCFG::SplitCFG ( const SplitCFG & from)
delete

Disallow a copy constructor for SCCFG.

◆ ~SplitCFG()

SplitCFG::~SplitCFG ( )
virtual

Destructor that erases all SplitCFGBlocks created.

Definition at line 1029 of file SplitCFG.cpp.

Member Function Documentation

◆ addNextStatesToBlocks()

void SplitCFG::addNextStatesToBlocks ( )
private

Definition at line 838 of file SplitCFG.cpp.

◆ addPathToSpecialNode()

void SplitCFG::addPathToSpecialNode ( const SplitCFGPath & from)

Definition at line 117 of file SplitCFG.cpp.

◆ addPredecessors()

void SplitCFG::addPredecessors ( SplitCFGBlock * to,
const clang::CFGBlock * from )
private

Add predecessors to the SplitCFGBlock.

Definition at line 798 of file SplitCFG.cpp.

◆ addSuccessors()

void SplitCFG::addSuccessors ( SplitCFGBlock * to,
const clang::CFGBlock * from )
private

Add successors to the SplitCFGBlock.

Definition at line 788 of file SplitCFG.cpp.

◆ addSuccessorToVisitOrPop()

void SplitCFG::addSuccessorToVisitOrPop ( bool parent_has_wait,
const SplitCFGBlock * BB,
llvm::SmallVector< std::pair< const SplitCFGBlock *, SplitCFGBlock::const_succ_iterator >, 8 > & to_visit,
bool found )

Definition at line 454 of file SplitCFG.cpp.

◆ construct_sccfg()

void SplitCFG::construct_sccfg ( const clang::CXXMethodDecl * method)

Construct the SCCFG.

Definition at line 987 of file SplitCFG.cpp.

◆ createUnsplitBlocks()

void SplitCFG::createUnsplitBlocks ( )
private

Creates SplitCFGBlocks for all CFGBlocks that do not have a wiat. splitBlock() creates the SplitCFGBlocks used for splitting CFGBLocks that have wait statements.

Set if the block is an IF conditional

Set if the block is a loop with two successors

Definition at line 948 of file SplitCFG.cpp.

◆ createWaitSplitCFGBlocks()

void SplitCFG::createWaitSplitCFGBlocks ( clang::CFGBlock * block,
const llvm::SmallVectorImpl< std::pair< VectorCFGElementPtr, bool > > & split_elements )
private

Creates the SplitCFGBlocks for CFGBlock with a wait.

Go through all the split_elements and create blocks.

check if the block has already been created.

First one

Succesors

Last one

Predecessors

Get the first element of the SmallVector, which will be a wait()

Propogate in the SplitCFGBlock whether the block has a terminator that has a break statement.

Definition at line 705 of file SplitCFG.cpp.

◆ dfs_rework()

void SplitCFG::dfs_rework ( )

G = cfg_

Record the current path.

Definition at line 520 of file SplitCFG.cpp.

◆ dfs_visit_wait()

const SplitCFG::SplitCFGPath SplitCFG::dfs_visit_wait ( const SplitCFGBlock * BB,
llvm::SmallPtrSet< const SplitCFGBlock *, 32 > & visited_blocks,
llvm::SmallVectorImpl< const SplitCFGBlock * > & waits_to_visit,
llvm::SmallPtrSetImpl< const SplitCFGBlock * > & visited_waits,
llvm::SmallVector< SplitCFGPathPair > & curr_path )

Modified DFS to create all paths within wait statements and from the root node.

REWORK the Cthread Path generation.

Parameters
basic_blockThe current basic block to process.
waits_in_stackThe SplitCFGBlock that come after the wait statements. These need to be processed.
visited_waitsThese are the SplitCFGBlocks that have waits and those that have been visited.

<

Empty CFG block

If the block contains a wait. It is a wait block.

If we are traversing down then we are not popping back up.

Handle the case when the block has a wait in it. There should only be a single statement, which is the wait.

Check if the found succesor is the TRUE or FALSE for the conditional. The first successor is the true, and the second is the false.

This only updates the visited blocks for the subgraph within the loop. We do not want to update the global visited_blocks yet.

Haven't looked at new successor yet. Find the new visited blocks.

There are two parts to updating the visited blocks.

  1. You do not update the visited blocks when iterating over a subgraph. This is because for each successor, we want to traverse the nodes without having visited them when traversing another successor.
  2. However, when the subgraph has been fully visited, we need to update the visited_blocks with all the blocks visited so that we let the DFS know to not revist them. The below is doing (2).

Update the visited blocks when there is no more successor to visit in the subgraph. This means, the loop will be exiting.

Definition at line 127 of file SplitCFG.cpp.

◆ dump()

void SplitCFG::dump ( ) const

Dump member functions.

Definition at line 1037 of file SplitCFG.cpp.

◆ dumpAllPathInfo()

void SplitCFG::dumpAllPathInfo ( ) const

Definition at line 919 of file SplitCFG.cpp.

◆ dumpCurrPath()

void SplitCFG::dumpCurrPath ( SplitCFGPath & curr_path) const

Definition at line 861 of file SplitCFG.cpp.

◆ dumpPathInfo()

void SplitCFG::dumpPathInfo ( ) const

Definition at line 936 of file SplitCFG.cpp.

◆ dumpPaths()

void SplitCFG::dumpPaths ( ) const

Definition at line 879 of file SplitCFG.cpp.

◆ dumpSCCFG()

void SplitCFG::dumpSCCFG ( ) const
private

Definition at line 808 of file SplitCFG.cpp.

◆ dumpSmallVector()

template<typename T >
void systemc_clang::SplitCFG::dumpSmallVector ( llvm::SmallVectorImpl< T > & vlist)
inline

Definition at line 247 of file SplitCFG.h.

◆ dumpSplitElements()

void SplitCFG::dumpSplitElements ( const llvm::SmallVector< std::pair< VectorCFGElementPtr, bool > > & split_elements) const
private

Dump all the CFGElements that were split.

Definition at line 816 of file SplitCFG.cpp.

◆ dumpToDot()

void SplitCFG::dumpToDot ( ) const

Create names for each node and its pattern.

Generate the string with CFGElements

Generate the connections

Definition at line 1048 of file SplitCFG.cpp.

◆ dumpVisitedBlocks()

void SplitCFG::dumpVisitedBlocks ( llvm::SmallPtrSetImpl< const SplitCFGBlock * > & visited)

Definition at line 428 of file SplitCFG.cpp.

◆ dumpWaitNextStates()

void SplitCFG::dumpWaitNextStates ( ) const

Definition at line 848 of file SplitCFG.cpp.

◆ generate_paths()

void SplitCFG::generate_paths ( )

Generates the paths between wait statements.

Definition at line 836 of file SplitCFG.cpp.

◆ getAllPathInfo()

const llvm::SmallVector< std::unordered_map< const SplitCFGBlock *, SplitCFGPathInfo > > & SplitCFG::getAllPathInfo ( ) const

Definition at line 1145 of file SplitCFG.cpp.

◆ getConfluenceBlocks()

std::map< SplitCFGBlock *, SplitCFGBlock * > SplitCFG::getConfluenceBlocks ( ) const

Rework.

Returns the confluence map.

Definition at line 1173 of file SplitCFG.cpp.

◆ getPathInfo()

const std::unordered_map< const SplitCFGBlock *, SplitCFGPathInfo > & SplitCFG::getPathInfo ( ) const

Definition at line 1139 of file SplitCFG.cpp.

◆ getPathsFound()

const llvm::SmallVectorImpl< llvm::SmallVector< SplitCFG::SplitCFGPathPair > > & SplitCFG::getPathsFound ( )

Returns the paths that were found in the SCCFG.

Definition at line 1150 of file SplitCFG.cpp.

◆ getUnvisitedSuccessor()

bool SplitCFG::getUnvisitedSuccessor ( const SplitCFGBlock * curr_block,
SplitCFGBlock::const_succ_iterator & I,
llvm::SmallPtrSetImpl< const SplitCFGBlock * > & visited,
const SplitCFGBlock *& block )

Definition at line 472 of file SplitCFG.cpp.

◆ getWaitArgument()

llvm::APInt SplitCFG::getWaitArgument ( const clang::CFGElement & element) const

Returns the argument to a wait statement. Note that the only one supported are no arguments or integer arguments.

===========================================

SplitCFG

Definition at line 583 of file SplitCFG.cpp.

◆ identifyConfluenceBlocks()

void SplitCFG::identifyConfluenceBlocks ( )

Identify confluence blocks in the CFG.

Definition at line 1216 of file SplitCFG.cpp.

◆ identifySkipBlocks()

std::set< SplitCFGBlock * > SplitCFG::identifySkipBlocks ( )

Definition at line 1177 of file SplitCFG.cpp.

◆ isConditional()

bool SplitCFG::isConditional ( const SplitCFGBlock * block) const

Checks if the block is a conditional. Note that this is different than ternary since the terminator is different.

Loop block has a terminator. The terminator is a clang::Stmt

Definition at line 487 of file SplitCFG.cpp.

◆ isElementWait()

bool SplitCFG::isElementWait ( const clang::CFGElement & element) const
private

Checks if a CFGBlock has a wait() call in it.

Use cast to CallExpr instead of CXXMemberCallExpr.

Check that there is only 1 or 0 arguments

Definition at line 614 of file SplitCFG.cpp.

◆ isLoop()

bool SplitCFG::isLoop ( const SplitCFGBlock * block) const

Checks if the block is a loop block.

Loop block has a terminator. The terminator is a clang::Stmt

Definition at line 506 of file SplitCFG.cpp.

◆ isLoopWithTwoSuccessors()

bool SplitCFG::isLoopWithTwoSuccessors ( const SplitCFGBlock * block) const

Definition at line 445 of file SplitCFG.cpp.

◆ isTernaryOperator()

bool SplitCFG::isTernaryOperator ( const SplitCFGBlock * block) const

Checks if the block is contains a terminator that is a ternary operator.

Definition at line 498 of file SplitCFG.cpp.

◆ isTruePath()

bool SplitCFG::isTruePath ( const SplitCFGBlock * parent_block,
const SplitCFGBlock * block ) const

Definition at line 419 of file SplitCFG.cpp.

◆ operator=()

SplitCFG & systemc_clang::SplitCFG::operator= ( const SplitCFG & )
delete

Disallow assignment operator.

◆ preparePathInfo()

void SplitCFG::preparePathInfo ( )

Definition at line 1020 of file SplitCFG.cpp.

◆ setDifference()

void SplitCFG::setDifference ( const llvm::SmallPtrSetImpl< const SplitCFGBlock * > & larger,
const llvm::SmallPtrSetImpl< const SplitCFGBlock * > & smaller,
llvm::SmallPtrSetImpl< const SplitCFGBlock * > & to )

Compute the set difference between two SmallPtrSets.

Definition at line 408 of file SplitCFG.cpp.

◆ setFalsePathInfo()

void SplitCFG::setFalsePathInfo ( const SplitCFGBlock * sblock,
const SplitCFGPath & newly_visited )

Definition at line 396 of file SplitCFG.cpp.

◆ setTruePathInfo()

void SplitCFG::setTruePathInfo ( const SplitCFGBlock * sblock,
const SplitCFGPath & newly_visited,
int ix = -1 )

Definition at line 385 of file SplitCFG.cpp.

◆ splitBlock()

void SplitCFG::splitBlock ( clang::CFGBlock * block)
private

Split a CFGBlock into respective SplitCFGBlock if the CFGBlock has wait statements in it.

0 elements so simply just add them and return.

refs() returns an iterator, which actually stores an ElementRefImpl<> interface. In order to get the correct pointer to CFGElement, we need to explicitly call operator->(). Odd!

If the element is a wait() then split it.

There is only one statement and it's a wait().

Add the wait as a separate entry in the list.

Definition at line 642 of file SplitCFG.cpp.

◆ updateVisitedBlocks()

void SplitCFG::updateVisitedBlocks ( llvm::SmallPtrSetImpl< const SplitCFGBlock * > & to,
const llvm::SmallPtrSetImpl< const SplitCFGBlock * > & from )

Definition at line 437 of file SplitCFG.cpp.

Member Data Documentation

◆ all_path_info_

llvm::SmallVector<std::unordered_map<const SplitCFGBlock *, SplitCFGPathInfo> > systemc_clang::SplitCFG::all_path_info_
private

Definition at line 133 of file SplitCFG.h.

◆ cfg_

std::unique_ptr<clang::CFG> systemc_clang::SplitCFG::cfg_
private

The saved CFG for a given method.

Definition at line 109 of file SplitCFG.h.

◆ context_

clang::ASTContext& systemc_clang::SplitCFG::context_
private

The context necessary to access translation unit.

Definition at line 106 of file SplitCFG.h.

◆ cop_

std::map<SplitCFGBlock*,SplitCFGBlock*> systemc_clang::SplitCFG::cop_
private

Map to store the confluence blocks. Ternary op block => Confluence block

Definition at line 144 of file SplitCFG.h.

◆ has_ternary_op_

bool systemc_clang::SplitCFG::has_ternary_op_
private

Set to true if the CFG has a ternary operator (ConditionalOperator).

Definition at line 140 of file SplitCFG.h.

◆ next_state_count_

unsigned int systemc_clang::SplitCFG::next_state_count_
private

Definition at line 137 of file SplitCFG.h.

◆ outter_top

SplitCFGBlock* systemc_clang::SplitCFG::outter_top

Definition at line 244 of file SplitCFG.h.

◆ path_info_

std::unordered_map<const SplitCFGBlock *, SplitCFGPathInfo> systemc_clang::SplitCFG::path_info_
private

Map a SplitCFGBlock* to its path information. Stores the path information for the blocks that are important. The important blocks are (1) conditionals, and (2) loop blocks with two outgoing edges.

Definition at line 130 of file SplitCFG.h.

◆ paths_

llvm::SmallVector<SplitCFGPath> systemc_clang::SplitCFG::paths_
private

Paths of BBs generated.

Definition at line 115 of file SplitCFG.h.

◆ popping_

bool systemc_clang::SplitCFG::popping_

Definition at line 320 of file SplitCFG.h.

◆ sccfg_

std::unordered_map<unsigned int, SplitCFGBlock *> systemc_clang::SplitCFG::sccfg_
private

The block id to block for SCCFG.

Definition at line 118 of file SplitCFG.h.

◆ split_blocks_

std::unordered_map<const clang::CFGBlock *, SplitCFGBlock> systemc_clang::SplitCFG::split_blocks_
private

The split blocks in the CFG.

Definition at line 112 of file SplitCFG.h.

◆ split_elements

llvm::SmallVector<std::pair<VectorCFGElementPtrImpl, bool> > systemc_clang::SplitCFG::split_elements
private

Definition at line 120 of file SplitCFG.h.

◆ sub_path_to_special_node_

SplitCFGPath systemc_clang::SplitCFG::sub_path_to_special_node_
private

Definition at line 135 of file SplitCFG.h.

◆ wait_next_state_

std::unordered_map<const SplitCFGBlock *, std::pair<const SplitCFGBlock *, unsigned int> > systemc_clang::SplitCFG::wait_next_state_
private

Predecessor SplitCFGBlock* => (Wait SplitCFGBlock*)

Definition at line 125 of file SplitCFG.h.


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