systemc-clang 2.0.0
Parsing SystemC constructs
|
#include <SplitCFG.h>
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. | |
SplitCFG & | operator= (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 | |
SplitCFGBlock * | outter_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 *, SplitCFGBlock > | split_blocks_ |
The split blocks in the CFG. | |
llvm::SmallVector< SplitCFGPath > | paths_ |
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 *, SplitCFGPathInfo > | path_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_ |
using systemc_clang::SplitCFG::SplitCFGPath = llvm::SmallVector<SplitCFGPathPair> |
Definition at line 95 of file SplitCFG.h.
using systemc_clang::SplitCFG::SplitCFGPathPair = std::pair<const SplitCFGBlock *, SupplementaryInfo> |
Definition at line 94 of file SplitCFG.h.
using systemc_clang::SplitCFG::VectorCFGElementPtr = llvm::SmallVector<const clang::CFGElement *> |
Definition at line 102 of file SplitCFG.h.
Definition at line 100 of file SplitCFG.h.
using systemc_clang::SplitCFG::VectorSplitCFGBlock = llvm::SmallVector<const SplitCFGBlock *> |
Definition at line 98 of file SplitCFG.h.
using systemc_clang::SplitCFG::VectorSplitCFGBlockImpl = llvm::SmallVector<const SplitCFGBlock *> |
Definition at line 99 of file SplitCFG.h.
SplitCFG::SplitCFG | ( | clang::ASTContext & | context | ) |
Constructor.
Definition at line 1154 of file SplitCFG.cpp.
SplitCFG::SplitCFG | ( | clang::ASTContext & | context, |
const clang::CXXMethodDecl * | cxx_decl ) |
Overloaded constructor.
Definition at line 1162 of file SplitCFG.cpp.
|
delete |
Disallow a copy constructor for SCCFG.
|
virtual |
Destructor that erases all SplitCFGBlocks created.
Definition at line 1029 of file SplitCFG.cpp.
|
private |
Definition at line 838 of file SplitCFG.cpp.
void SplitCFG::addPathToSpecialNode | ( | const SplitCFGPath & | from | ) |
Definition at line 117 of file SplitCFG.cpp.
|
private |
Add predecessors to the SplitCFGBlock.
Definition at line 798 of file SplitCFG.cpp.
|
private |
Add successors to the SplitCFGBlock.
Definition at line 788 of file SplitCFG.cpp.
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.
void SplitCFG::construct_sccfg | ( | const clang::CXXMethodDecl * | method | ) |
Construct the SCCFG.
Definition at line 987 of file SplitCFG.cpp.
|
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.
|
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.
void SplitCFG::dfs_rework | ( | ) |
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.
basic_block | The current basic block to process. |
waits_in_stack | The SplitCFGBlock that come after the wait statements. These need to be processed. |
visited_waits | These 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.
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.
void SplitCFG::dump | ( | ) | const |
Dump member functions.
Definition at line 1037 of file SplitCFG.cpp.
void SplitCFG::dumpAllPathInfo | ( | ) | const |
Definition at line 919 of file SplitCFG.cpp.
void SplitCFG::dumpCurrPath | ( | SplitCFGPath & | curr_path | ) | const |
Definition at line 861 of file SplitCFG.cpp.
void SplitCFG::dumpPathInfo | ( | ) | const |
Definition at line 936 of file SplitCFG.cpp.
void SplitCFG::dumpPaths | ( | ) | const |
Definition at line 879 of file SplitCFG.cpp.
|
private |
Definition at line 808 of file SplitCFG.cpp.
|
inline |
Definition at line 247 of file SplitCFG.h.
|
private |
Dump all the CFGElements that were split.
Definition at line 816 of file SplitCFG.cpp.
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.
void SplitCFG::dumpVisitedBlocks | ( | llvm::SmallPtrSetImpl< const SplitCFGBlock * > & | visited | ) |
Definition at line 428 of file SplitCFG.cpp.
void SplitCFG::dumpWaitNextStates | ( | ) | const |
Definition at line 848 of file SplitCFG.cpp.
void SplitCFG::generate_paths | ( | ) |
Generates the paths between wait statements.
Definition at line 836 of file SplitCFG.cpp.
const llvm::SmallVector< std::unordered_map< const SplitCFGBlock *, SplitCFGPathInfo > > & SplitCFG::getAllPathInfo | ( | ) | const |
Definition at line 1145 of file SplitCFG.cpp.
std::map< SplitCFGBlock *, SplitCFGBlock * > SplitCFG::getConfluenceBlocks | ( | ) | const |
const std::unordered_map< const SplitCFGBlock *, SplitCFGPathInfo > & SplitCFG::getPathInfo | ( | ) | const |
Definition at line 1139 of file SplitCFG.cpp.
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.
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.
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.
===========================================
Definition at line 583 of file SplitCFG.cpp.
void SplitCFG::identifyConfluenceBlocks | ( | ) |
Identify confluence blocks in the CFG.
Definition at line 1216 of file SplitCFG.cpp.
std::set< SplitCFGBlock * > SplitCFG::identifySkipBlocks | ( | ) |
Definition at line 1177 of file SplitCFG.cpp.
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.
|
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.
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.
bool SplitCFG::isLoopWithTwoSuccessors | ( | const SplitCFGBlock * | block | ) | const |
Definition at line 445 of file SplitCFG.cpp.
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.
bool SplitCFG::isTruePath | ( | const SplitCFGBlock * | parent_block, |
const SplitCFGBlock * | block ) const |
Definition at line 419 of file SplitCFG.cpp.
Disallow assignment operator.
void SplitCFG::preparePathInfo | ( | ) |
Definition at line 1020 of file SplitCFG.cpp.
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.
void SplitCFG::setFalsePathInfo | ( | const SplitCFGBlock * | sblock, |
const SplitCFGPath & | newly_visited ) |
Definition at line 396 of file SplitCFG.cpp.
void SplitCFG::setTruePathInfo | ( | const SplitCFGBlock * | sblock, |
const SplitCFGPath & | newly_visited, | ||
int | ix = -1 ) |
Definition at line 385 of file SplitCFG.cpp.
|
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.
void SplitCFG::updateVisitedBlocks | ( | llvm::SmallPtrSetImpl< const SplitCFGBlock * > & | to, |
const llvm::SmallPtrSetImpl< const SplitCFGBlock * > & | from ) |
Definition at line 437 of file SplitCFG.cpp.
|
private |
Definition at line 133 of file SplitCFG.h.
|
private |
The saved CFG for a given method.
Definition at line 109 of file SplitCFG.h.
|
private |
The context necessary to access translation unit.
Definition at line 106 of file SplitCFG.h.
|
private |
Map to store the confluence blocks. Ternary op block => Confluence block
Definition at line 144 of file SplitCFG.h.
|
private |
Set to true if the CFG has a ternary operator (ConditionalOperator).
Definition at line 140 of file SplitCFG.h.
|
private |
Definition at line 137 of file SplitCFG.h.
SplitCFGBlock* systemc_clang::SplitCFG::outter_top |
Definition at line 244 of file SplitCFG.h.
|
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.
|
private |
Paths of BBs generated.
Definition at line 115 of file SplitCFG.h.
bool systemc_clang::SplitCFG::popping_ |
Definition at line 320 of file SplitCFG.h.
|
private |
The block id to block for SCCFG.
Definition at line 118 of file SplitCFG.h.
|
private |
The split blocks in the CFG.
Definition at line 112 of file SplitCFG.h.
|
private |
Definition at line 120 of file SplitCFG.h.
|
private |
Definition at line 135 of file SplitCFG.h.
|
private |
Predecessor SplitCFGBlock* => (Wait SplitCFGBlock*)
Definition at line 125 of file SplitCFG.h.