systemc-clang 2.0.0
Parsing SystemC constructs
Loading...
Searching...
No Matches
SplitCFG.h
Go to the documentation of this file.
1#ifndef _SPLIT_CFG_H_
2#define _SPLIT_CFG_H_
3
4#include <unordered_map>
5
6#include "SplitCFGBlock.h"
7#include "llvm/ADT/SmallVector.h"
8#include "llvm/ADT/SmallPtrSet.h"
9#include <set>
10namespace systemc_clang {
11
12/* \class Additional information for paths traversed in SplitCFG
13 */
14
17 SupplementaryInfo(const SplitCFGBlock *block);
18
20
22
23 virtual ~SupplementaryInfo();
24
26 int getPathId() const;
27
29 int getFalseId() const;
30
32 const SplitCFGBlock *getSplitCFGBlock() const;
33
38};
39
44 public:
45 using SplitCFGBlockPtrVector = llvm::SmallVector<const SplitCFGBlock *>;
46 friend class SplitCFG;
47
48 public:
49 SplitCFGPathInfo(const SplitCFGBlock *block);
50
53
55
56 virtual ~SplitCFGPathInfo();
57
59 bool isTruePathValid() const { return (true_path_.size() > 0); }
60
62 bool isFalsePathValid() const { return ((false_path_.size() > 0)); }
63
66
69
70 // int getpathix() { return false_startix; }
71
73 std::string toStringFalsePath() const;
74
76 std::string toStringTruePath() const;
77
79 void dump() const;
80
81 private:
83 const clang::CFGBlock *cfg_block_;
87};
88
92class SplitCFG {
93 public:
94 using SplitCFGPathPair = std::pair<const SplitCFGBlock *, SupplementaryInfo>;
95 using SplitCFGPath = llvm::SmallVector<SplitCFGPathPair>;
96
97 // TODO: deprecated
98 using VectorSplitCFGBlock = llvm::SmallVector<const SplitCFGBlock *>;
99 using VectorSplitCFGBlockImpl = llvm::SmallVector<const SplitCFGBlock *>;
101 llvm::SmallVectorImpl<const clang::CFGElement *>;
102 using VectorCFGElementPtr = llvm::SmallVector<const clang::CFGElement *>;
103
104 private:
106 clang::ASTContext &context_;
107
109 std::unique_ptr<clang::CFG> cfg_;
110
112 std::unordered_map<const clang::CFGBlock *, SplitCFGBlock> split_blocks_;
113
115 llvm::SmallVector<SplitCFGPath> paths_;
116
118 std::unordered_map<unsigned int, SplitCFGBlock *> sccfg_;
119
120 llvm::SmallVector<std::pair<VectorCFGElementPtrImpl, bool>> split_elements;
121
123 std::unordered_map<const SplitCFGBlock *,
124 std::pair<const SplitCFGBlock *, unsigned int>>
126
130 std::unordered_map<const SplitCFGBlock *, SplitCFGPathInfo> path_info_;
131
132 llvm::SmallVector<std::unordered_map<const SplitCFGBlock *, SplitCFGPathInfo>>
134
136
137 unsigned int next_state_count_;
138
141
144 std::map<SplitCFGBlock*,SplitCFGBlock*> cop_;
145
148
149 private:
151 bool isElementWait(const clang::CFGElement &element) const;
152
155 void splitBlock(clang::CFGBlock *block);
156
158 void addSuccessors(SplitCFGBlock *to, const clang::CFGBlock *from);
159
161 void addPredecessors(SplitCFGBlock *to, const clang::CFGBlock *from);
162
164
168 void createUnsplitBlocks();
169
172 clang::CFGBlock *block,
173 const llvm::SmallVectorImpl<std::pair<VectorCFGElementPtr, bool>>
175
178 const llvm::SmallVector<std::pair<VectorCFGElementPtr, bool>>
179 &split_elements) const;
180
181 void dumpSCCFG() const;
182
183 public:
185 SplitCFG(clang::ASTContext &context);
187 SplitCFG(clang::ASTContext &context, const clang::CXXMethodDecl *cxx_decl);
188
190 SplitCFG(const SplitCFG &from) = delete;
191
193 SplitCFG &operator=(const SplitCFG &) = delete;
194
196 virtual ~SplitCFG();
197
199 // const llvm::SmallVectorImpl<VectorSplitCFGBlock> &
200
201 const llvm::SmallVectorImpl<llvm::SmallVector<SplitCFGPathPair>>
202 &getPathsFound();
203
205 void construct_sccfg(const clang::CXXMethodDecl *method);
206
208 void generate_paths();
209
210 const std::unordered_map<const SplitCFGBlock *, SplitCFGPathInfo>
211 &getPathInfo() const;
212
213 const llvm::SmallVector<std::unordered_map<const SplitCFGBlock *, SplitCFGPathInfo>>
214 &getAllPathInfo() const;
215
216 void preparePathInfo();
219 llvm::APInt getWaitArgument(const clang::CFGElement &element) const;
220
221
223 void dump() const;
224 void dumpToDot() const;
225 void dumpWaitNextStates() const;
226 void dumpPaths() const;
227 void dumpCurrPath(
228 // llvm::SmallVector<std::pair<const SplitCFGBlock *, SplitCFGPathInfo>>
229 SplitCFGPath &curr_path) const;
230
231 void dumpPathInfo() const;
232 void dumpAllPathInfo() const;
233
235 //
236 //
237
238 // Identify confluence blocks.
239 //
241 std::map<SplitCFGBlock*,SplitCFGBlock*> getConfluenceBlocks() const;
242
245 std::set<SplitCFGBlock*> identifySkipBlocks();
246
247
248 public:
249
250 template <typename T>
251 void dumpSmallVector(llvm::SmallVectorImpl<T> &vlist) {
252 for (const auto v : vlist) {
253 llvm::dbgs() << v.first->getBlockID() << " ";
254 }
255 }
256
264
265 const SplitCFGPath // llvm::SmallVector<std::pair<const SplitCFGBlock *,
266 // SplitCFGPathInfo>>
268 llvm::SmallPtrSet<const SplitCFGBlock *, 32> &visited_blocks,
269 llvm::SmallVectorImpl<const SplitCFGBlock *> &waits_to_visit,
270 llvm::SmallPtrSetImpl<const SplitCFGBlock *> &visited_waits,
271 llvm::SmallVector<SplitCFGPathPair> &curr_path);
272 void dfs_rework();
273
276 bool isTernaryOperator(const SplitCFGBlock *block) const;
277
279 bool isLoop(const SplitCFGBlock *block) const;
280
284 bool isConditional(const SplitCFGBlock *block) const;
285
288 llvm::SmallPtrSetImpl<const SplitCFGBlock *> &visited,
289 const SplitCFGBlock *&block);
290
291 bool isLoopWithTwoSuccessors(const SplitCFGBlock *block) const;
293 bool parent_has_wait, const SplitCFGBlock *BB,
294 llvm::SmallVector<
295 std::pair<const SplitCFGBlock *, SplitCFGBlock::const_succ_iterator>,
296 8> &to_visit,
297 bool found);
298
299 bool isTruePath(const SplitCFGBlock *parent_block,
300 const SplitCFGBlock *block) const;
301
303 void setDifference(
304 const llvm::SmallPtrSetImpl<const SplitCFGBlock *> &larger,
305 const llvm::SmallPtrSetImpl<const SplitCFGBlock *> &smaller,
306 llvm::SmallPtrSetImpl<const SplitCFGBlock *> &to);
307 void setTruePathInfo(const SplitCFGBlock *sblock,
308 // const llvm::SmallVector< std::pair<const SplitCFGBlock
309 // *, SplitCFGPathInfo>> &newly_visited,
310 const SplitCFGPath &newly_visited, int ix = -1);
311
312 void setFalsePathInfo(const SplitCFGBlock *sblock,
313 const SplitCFGPath &newly_visited);
314 // const llvm::SmallVector<
315 // std::pair<const SplitCFGBlock *, SplitCFGPathInfo>> &newly_visited);
316
317 void addPathToSpecialNode(const SplitCFGPath &from);
318
320 llvm::SmallPtrSetImpl<const SplitCFGBlock *> &to,
321 const llvm::SmallPtrSetImpl<const SplitCFGBlock *> &from);
322 void dumpVisitedBlocks(llvm::SmallPtrSetImpl<const SplitCFGBlock *> &visited);
323
325
327 public:
328 // void make_edge_pairs( const SplitCFGBlock* block );
329};
330
331}; // namespace systemc_clang
332
333#endif /* _SPLIT_CFG_H_ */
SuccessorIterator::const_iterator const_succ_iterator
SplitCFGBlockPtrVector true_path_
Definition SplitCFG.h:86
SplitCFGBlockPtrVector false_path_
Definition SplitCFG.h:85
llvm::SmallVector< const SplitCFGBlock * > SplitCFGBlockPtrVector
Definition SplitCFG.h:45
bool isFalsePathValid() const
Return if there is a valid FALSE path.
Definition SplitCFG.h:62
SplitCFGPathInfo(const SplitCFGBlock *block)
class SplitCFGPathInfo
Definition SplitCFG.cpp:55
const SplitCFGBlockPtrVector & getFalsePath() const
Return the list of blocks visited on the FALSE path.
Definition SplitCFG.h:68
const SplitCFGBlockPtrVector & getTruePath() const
Return the list of blocks visited on the TRUE path.
Definition SplitCFG.h:65
const clang::CFGBlock * cfg_block_
Definition SplitCFG.h:83
void dump() const
Dump the paths.
Definition SplitCFG.cpp:101
std::string toStringFalsePath() const
Converts the TRUE path into a string for testing.
Definition SplitCFG.cpp:75
bool isTruePathValid() const
Return if there is a valid TRUE path.
Definition SplitCFG.h:59
SplitCFGPathInfo & operator=(const SplitCFGPathInfo &from)
Definition SplitCFG.cpp:65
std::string toStringTruePath() const
Converts the FALSE path into a string for testing.
Definition SplitCFG.cpp:88
const SplitCFGBlock * split_block_
Definition SplitCFG.h:82
unsigned int next_state_count_
Definition SplitCFG.h:137
SplitCFGPath sub_path_to_special_node_
Definition SplitCFG.h:135
llvm::SmallVector< const SplitCFGBlock * > VectorSplitCFGBlockImpl
Definition SplitCFG.h:99
std::unordered_map< const SplitCFGBlock *, std::pair< const SplitCFGBlock *, unsigned int > > wait_next_state_
Predecessor SplitCFGBlock* => (Wait SplitCFGBlock*)
Definition SplitCFG.h:125
bool has_ternary_op_
Set to true if the CFG has a ternary operator (ConditionalOperator).
Definition SplitCFG.h:140
void addSuccessorToVisitOrPop(bool parent_has_wait, const SplitCFGBlock *BB, llvm::SmallVector< std::pair< const SplitCFGBlock *, SplitCFGBlock::const_succ_iterator >, 8 > &to_visit, bool found)
Definition SplitCFG.cpp:454
void setTruePathInfo(const SplitCFGBlock *sblock, const SplitCFGPath &newly_visited, int ix=-1)
Definition SplitCFG.cpp:385
void splitBlock(clang::CFGBlock *block)
Split a CFGBlock into respective SplitCFGBlock if the CFGBlock has wait statements in it.
Definition SplitCFG.cpp:642
bool isConditional(const SplitCFGBlock *block) const
Checks if the block is a conditional. Note that this is different than ternary since the terminator i...
Definition SplitCFG.cpp:487
void dumpWaitNextStates() const
Definition SplitCFG.cpp:848
void dump() const
Dump member functions.
SplitCFG(const SplitCFG &from)=delete
Disallow a copy constructor for SCCFG.
llvm::SmallVector< const SplitCFGBlock * > VectorSplitCFGBlock
Definition SplitCFG.h:98
void dumpSmallVector(llvm::SmallVectorImpl< T > &vlist)
Definition SplitCFG.h:251
bool isElementWait(const clang::CFGElement &element) const
Checks if a CFGBlock has a wait() call in it.
Definition SplitCFG.cpp:614
void updateVisitedBlocks(llvm::SmallPtrSetImpl< const SplitCFGBlock * > &to, const llvm::SmallPtrSetImpl< const SplitCFGBlock * > &from)
Definition SplitCFG.cpp:437
void dumpPathInfo() const
Definition SplitCFG.cpp:936
void generate_paths()
Generates the paths between wait statements.
Definition SplitCFG.cpp:836
clang::ASTContext & context_
The context necessary to access translation unit.
Definition SplitCFG.h:106
void identifyConfluenceBlocks()
Identify confluence blocks in the CFG.
bool getUnvisitedSuccessor(const SplitCFGBlock *curr_block, SplitCFGBlock::const_succ_iterator &I, llvm::SmallPtrSetImpl< const SplitCFGBlock * > &visited, const SplitCFGBlock *&block)
Definition SplitCFG.cpp:472
std::set< SplitCFGBlock * > identifySkipBlocks()
std::pair< const SplitCFGBlock *, SupplementaryInfo > SplitCFGPathPair
Definition SplitCFG.h:94
bool isTruePath(const SplitCFGBlock *parent_block, const SplitCFGBlock *block) const
Definition SplitCFG.cpp:419
void setFalsePathInfo(const SplitCFGBlock *sblock, const SplitCFGPath &newly_visited)
Definition SplitCFG.cpp:396
SplitCFG(clang::ASTContext &context)
Constructor.
bool isLoop(const SplitCFGBlock *block) const
Checks if the block is a loop block.
Definition SplitCFG.cpp:506
const llvm::SmallVectorImpl< llvm::SmallVector< SplitCFGPathPair > > & getPathsFound()
Returns the paths that were found in the SCCFG.
void dumpCurrPath(SplitCFGPath &curr_path) const
Definition SplitCFG.cpp:861
llvm::SmallVector< SplitCFGPathPair > SplitCFGPath
Definition SplitCFG.h:95
void addSuccessors(SplitCFGBlock *to, const clang::CFGBlock *from)
Add successors to the SplitCFGBlock.
Definition SplitCFG.cpp:788
std::unordered_map< const clang::CFGBlock *, SplitCFGBlock > split_blocks_
The split blocks in the CFG.
Definition SplitCFG.h:112
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 intege...
Definition SplitCFG.cpp:583
SplitCFGBlock * outter_top_
This is the pointer to the outtermost ternary operator.
Definition SplitCFG.h:147
llvm::SmallVector< SplitCFGPath > paths_
Paths of BBs generated.
Definition SplitCFG.h:115
bool isLoopWithTwoSuccessors(const SplitCFGBlock *block) const
Definition SplitCFG.cpp:445
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.
Definition SplitCFG.cpp:408
llvm::SmallVector< std::pair< VectorCFGElementPtrImpl, bool > > split_elements
Definition SplitCFG.h:120
const llvm::SmallVector< std::unordered_map< const SplitCFGBlock *, SplitCFGPathInfo > > & getAllPathInfo() const
void addPathToSpecialNode(const SplitCFGPath &from)
Definition SplitCFG.cpp:117
llvm::SmallVector< std::unordered_map< const SplitCFGBlock *, SplitCFGPathInfo > > all_path_info_
Definition SplitCFG.h:133
std::unordered_map< const SplitCFGBlock *, SplitCFGPathInfo > path_info_
Map a SplitCFGBlock* to its path information. Stores the path information for the blocks that are imp...
Definition SplitCFG.h:130
std::unordered_map< unsigned int, SplitCFGBlock * > sccfg_
The block id to block for SCCFG.
Definition SplitCFG.h:118
llvm::SmallVectorImpl< const clang::CFGElement * > VectorCFGElementPtrImpl
Definition SplitCFG.h:100
const std::unordered_map< const SplitCFGBlock *, SplitCFGPathInfo > & getPathInfo() const
void createWaitSplitCFGBlocks(clang::CFGBlock *block, const llvm::SmallVectorImpl< std::pair< VectorCFGElementPtr, bool > > &split_elements)
Creates the SplitCFGBlocks for CFGBlock with a wait.
Definition SplitCFG.cpp:705
bool isTernaryOperator(const SplitCFGBlock *block) const
Checks if the block is contains a terminator that is a ternary operator.
Definition SplitCFG.cpp:498
std::map< SplitCFGBlock *, SplitCFGBlock * > getConfluenceBlocks() const
Rework.
llvm::SmallVector< const clang::CFGElement * > VectorCFGElementPtr
Definition SplitCFG.h:102
void createUnsplitBlocks()
Creates SplitCFGBlocks for all CFGBlocks that do not have a wiat. splitBlock() creates the SplitCFGBl...
Definition SplitCFG.cpp:948
std::map< SplitCFGBlock *, SplitCFGBlock * > cop_
Definition SplitCFG.h:144
virtual ~SplitCFG()
Destructor that erases all SplitCFGBlocks created.
SplitCFG & operator=(const SplitCFG &)=delete
Disallow assignment operator.
void dumpVisitedBlocks(llvm::SmallPtrSetImpl< const SplitCFGBlock * > &visited)
Definition SplitCFG.cpp:428
void construct_sccfg(const clang::CXXMethodDecl *method)
Construct the SCCFG.
Definition SplitCFG.cpp:987
void dumpSplitElements(const llvm::SmallVector< std::pair< VectorCFGElementPtr, bool > > &split_elements) const
Dump all the CFGElements that were split.
Definition SplitCFG.cpp:816
void addPredecessors(SplitCFGBlock *to, const clang::CFGBlock *from)
Add predecessors to the SplitCFGBlock.
Definition SplitCFG.cpp:798
void dumpAllPathInfo() const
Definition SplitCFG.cpp:919
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.
Definition SplitCFG.cpp:127
std::unique_ptr< clang::CFG > cfg_
The saved CFG for a given method.
Definition SplitCFG.h:109
SupplementaryInfo(const SplitCFGBlock *block)
Construct object using SplitCFGBlock.
Definition SplitCFG.cpp:28
int getPathId() const
Returns the path identifier.
Definition SplitCFG.cpp:42
int getFalseId() const
Returns the path identifier for the false path.
Definition SplitCFG.cpp:44
SupplementaryInfo & operator=(const SupplementaryInfo &from)
Definition SplitCFG.cpp:35
const SplitCFGBlock * getSplitCFGBlock() const
Returns pointer to the SplitCFGBlock.
Definition SplitCFG.cpp:46
const SplitCFGBlock * split_block_
Member variables.
Definition SplitCFG.h:35