systemc-clang 2.0.0
Parsing SystemC constructs
Loading...
Searching...
No Matches
HDLThread.h
Go to the documentation of this file.
1#ifndef _HDLTHREAD_H
2#define _HDLTHREAD_H
3
4// clang-format off
5
6#include "SystemCClang.h"
7#include "clang/Analysis/CFG.h"
8#include "llvm/Support/raw_ostream.h"
9#include "llvm/Support/Debug.h"
10#include "llvm/ADT/StringRef.h"
11#include "hNode.h"
12#include "HDLBody.h"
13#include "SplitCFG.h"
14#include <unordered_set>
15
16// clang-format on
17
18using namespace clang;
19using namespace systemc_clang;
20using namespace hnode;
21using namespace llvm;
22
23namespace systemc_hdl {
24
25 class HDLThread {
26 public:
27 HDLThread(EntryFunctionContainer *efc, hNodep &h_top, hNodep &h_portsigvarlist,
28 clang::DiagnosticsEngine &diag_engine, const ASTContext &ast_context,
29 hdecl_name_map_t &mod_vname_map, hfunc_name_map_t &allmethods, overridden_method_map_t &overridden_method_map, hNodep h_resetvarinfo);
30 virtual ~HDLThread();
31
32 hfunc_name_map_t methodecls; // methods called in this SC_METHOD or function
33
34 clang::DiagnosticsEngine &diag_e;
35
36 private:
37
39 // additional information about conditional expression a?b:c
40 // subgraphs. we generate hcode for the confluence block terminator
41 // of the outmost cond expr only, and skip split graph nodes that
42 // have a path from outermost cond expr block to confluence block.
43 // path vector is incorrect for intervening nodes of nested cond exprs.
44
45 std::map<SplitCFGBlock*,SplitCFGBlock*> condexp_confluence_block_map;
46 std::set<SplitCFGBlock*> condexp_skip_block_set;
47
48 hNodep h_ret; // value returned by each subexpression
50 hNodep h_top_; // reference to calling hnode pointer
51 hNodep hthreadblocksp; // collect the case alternatives here
52 hNodep hlocalvarsp; // collect the local vars here
53
56 hdecl_name_map_t &mod_vname_map_; // reference to module level names
57
59
67 string waitnextstate_string; // holds the state# to set when ctr=0
68 string savewaitnextstate_string; // signal to hold the waitnextstate
71
72 const string nextstring{"_next_"};
73 const string shadowstring{"_main_"};
74 const string statestringsymbol{"#"};
75
76 inline string NameNext(string &s) {return nextstring+s;} // convention for variable name holding next value of var s
77
78 // inline string
79 std::unordered_map<std::string, int> SGVisited; // Split Graph Blocks visited
80 //std::unordered_map<unsigned int, int> CFGVisited; // CFG Blocks visited
81 std::unordered_set<int> pathnodevisited; // index of visited node in path
82
83 inline void updatepnvisited(int i) {
84 if (pathnodevisited.find(i) == pathnodevisited.end()) { //haven't visited
85 pathnodevisited.insert(i);
86 }
87 }
88
89 inline bool isBreak(const Stmt* S) {
90 return dyn_cast<BreakStmt> (S) != NULL;
91 }
92
93 // pre-pass over BB to mark subexpressions
94 void FindStatements(const CFGBlock &B, std::vector<const Stmt *> &SS);
95 void FindStatements(const SplitCFGBlock *B, std::vector<const Stmt *> &SS);
96 void MarkStatements(const Stmt *S, llvm::SmallDenseMap<const Stmt*, bool> &Map);
97 void CheckVardecls(hNodep &hp, string &cfgblockid);
98 void ProcessDeclStmt(const DeclStmt *declstmt, hNodep htmp);
99
100 int GetFalseLength(const SplitCFG::SplitCFGPath &pt, int cond_node_ix, int state_num);
101
103 int startix, int num_ele,
104 int state_num, hNodep h_switchcase);
105
107 int thisix,
108 int state_num, hNodep h_switchcase);
109 void GenerateStateUpdate(hNodep hstatemethod, hNodep hlocalvarsp);
110 void GenerateStateVar(string sname);
111 void GenerateWaitCntUpdate(hNodep h_switchcase);
112 hNodep GenerateBinop(string opname, string lhs, string rhs, bool rhs_is_literal=true);
113 bool IsWaitStmt(hNodep hp);
114 bool isContinueorBreak(const Stmt *S);
115 void ProcessHWait(hNodep htmp, int nxtstate); // rewrite the hWait into next state update
116
118
119 const clang::ASTContext& ast_context_;
120
121 // these functions are no longer used
122 void ProcessBB(const CFGBlock &BI);
123 void AddThreadMethod(const CFGBlock &BI);
124
125 };
126
127}
128
129#endif
llvm::SmallVector< SplitCFGPathPair > SplitCFGPath
Definition SplitCFG.h:95
void ProcessSplitGraphGroup(const SplitCFG::SplitCFGPath pt, int startix, int num_ele, int state_num, hNodep h_switchcase)
void GenerateStateVar(string sname)
int GetFalseLength(const SplitCFG::SplitCFGPath &pt, int cond_node_ix, int state_num)
void GenerateStateUpdate(hNodep hstatemethod, hNodep hlocalvarsp)
string savewaitnextstate_string
Definition HDLThread.h:68
bool isContinueorBreak(const Stmt *S)
clang::DiagnosticsEngine & diag_e
Definition HDLThread.h:34
void CheckVardecls(hNodep &hp, string &cfgblockid)
const string nextstring
Definition HDLThread.h:72
const clang::ASTContext & ast_context_
Definition HDLThread.h:119
hdecl_name_map_t & mod_vname_map_
Definition HDLThread.h:56
const string statestringsymbol
Definition HDLThread.h:74
std::map< SplitCFGBlock *, SplitCFGBlock * > condexp_confluence_block_map
Definition HDLThread.h:45
hfunc_name_map_t allmethodecls_
Definition HDLThread.h:61
void ProcessHWait(hNodep htmp, int nxtstate)
const string shadowstring
Definition HDLThread.h:73
void ProcessSplitGraphBlock(const SplitCFG::SplitCFGPath &pt, int thisix, int state_num, hNodep h_switchcase)
hfunc_name_map_t methodecls
Definition HDLThread.h:32
void updatepnvisited(int i)
Definition HDLThread.h:83
bool isBreak(const Stmt *S)
Definition HDLThread.h:89
void AddThreadMethod(const CFGBlock &BI)
std::unordered_map< std::string, int > SGVisited
Definition HDLThread.h:79
overridden_method_map_t & overridden_method_map_
Definition HDLThread.h:62
std::set< SplitCFGBlock * > condexp_skip_block_set
Definition HDLThread.h:46
std::unordered_set< int > pathnodevisited
Definition HDLThread.h:81
void MarkStatements(const Stmt *S, llvm::SmallDenseMap< const Stmt *, bool > &Map)
hNodep GenerateBinop(string opname, string lhs, string rhs, bool rhs_is_literal=true)
void ProcessBB(const CFGBlock &BI)
string NameNext(string &s)
Definition HDLThread.h:76
void GenerateWaitCntUpdate(hNodep h_switchcase)
bool IsWaitStmt(hNodep hp)
HDLThread(EntryFunctionContainer *efc, hNodep &h_top, hNodep &h_portsigvarlist, clang::DiagnosticsEngine &diag_engine, const ASTContext &ast_context, hdecl_name_map_t &mod_vname_map, hfunc_name_map_t &allmethods, overridden_method_map_t &overridden_method_map, hNodep h_resetvarinfo)
Definition HDLThread.cpp:24
void FindStatements(const CFGBlock &B, std::vector< const Stmt * > &SS)
EntryFunctionContainer * efc_
Definition HDLThread.h:49
hdecl_name_map_t thread_vname_map
Definition HDLThread.h:54
void ProcessDeclStmt(const DeclStmt *declstmt, hNodep htmp)
Clang forward declarations.
Definition FindArgument.h:6
Definition hNode.h:24
std::unordered_map< const CXXMethodDecl *, const CXXMethodDecl * > overridden_method_map_t
Definition hNode.h:628