systemc-clang 2.0.0
Parsing SystemC constructs
Loading...
Searching...
No Matches
SplitCFGBlock.cpp
Go to the documentation of this file.
1#include "SplitCFGBlock.h"
2
3#include "llvm/Support/Debug.h"
4
5using namespace systemc_clang;
6
8 : block_{nullptr},
9 has_wait_{false},
10 is_conditional_{false},
11 is_loop_with_two_succ_{false},
12 terminator_has_break_{false},
13 terminator_has_wait_{false},
14 id_{0},
15 next_state_{0},
16 wait_arg_{32, 0, false} {}
17
32
36
38
40
42
43void SplitCFGBlock::setNextState(unsigned int state) { next_state_ = state; }
44
45const clang::CFGBlock* SplitCFGBlock::getCFGBlock() const { return block_; }
46
51
60
61bool SplitCFGBlock::hasWait() const { return has_wait_; }
62
63std::size_t SplitCFGBlock::getNumOfElements() const { return elements_.size(); }
64
66 elements_ = elements;
67}
68
69unsigned int SplitCFGBlock::getBlockID() const { return id_; }
70
71unsigned int SplitCFGBlock::getNextState() const { return next_state_; }
72
73llvm::APInt SplitCFGBlock::getWaitArg() const { return wait_arg_; }
74
75void SplitCFGBlock::identifyBreaks(clang::ASTContext& context) {
76 if (block_ && block_->getTerminator().isValid()) {
78 auto stmt{block_->getTerminator().getStmt()};
79 MatchFinder bm_reg{};
80 BreakMatcher bm{};
81 bm.registerMatchers(bm_reg);
82 bm_reg.match(*stmt, context);
83 terminator_has_wait_ = bm.hasWait();
84 terminator_has_break_ = bm.hasBreak();
85 }
86}
87
88void SplitCFGBlock::dump() const {
89 if (block_) {
90 llvm::dbgs() << "\nSB" << getBlockID() << " (B" << block_->getBlockID()
91 << ") ";
92 if (hasWait()) {
93 llvm::dbgs() << " (WAIT)";
94 llvm::dbgs() << " (Arg: " << wait_arg_ << ")"
95 << " (NextState: " << getNextState() << ")\n";
96 }
97 llvm::dbgs() << "\n";
98
99 unsigned int i{0};
100 for (auto const& element : elements_) {
101 llvm::dbgs() << " " << i << ": ";
102 element->dump();
103 ++i;
104 }
106 clang::LangOptions lang_opts;
107 if (!hasWait() && block_->getTerminator().isValid()) {
108 llvm::dbgs() << " T: ";
109 block_->printTerminator(llvm::dbgs(), lang_opts);
110 }
111
112 llvm::dbgs() << "\n\n";
113
114 llvm::dbgs() << " Preds (" << predecessors_.size() << "): ";
115 for (auto const& pre : predecessors_) {
116 llvm::dbgs() << "SB" << pre->getBlockID() << " ";
117 }
118
119 llvm::dbgs() << "\n Succs (" << successors_.size() << "): ";
120 for (auto const& succ : successors_) {
121 llvm::dbgs() << "SB" << succ->getBlockID() << " ";
122 }
123 llvm::dbgs() << "\n";
124 }
125}
126
128 if (block_) {
129 llvm::dbgs() << "\nSB" << getBlockID() << " (B" << block_->getBlockID()
130 << ") ";
131 if (hasWait()) {
132 llvm::dbgs() << llvm::buffer_ostream::Colors::RED << " (WAIT)";
133 llvm::dbgs() << llvm::buffer_ostream::Colors::BLUE
134 << " (Arg: " << wait_arg_ << ")"
135 << llvm::buffer_ostream::Colors::GREEN
136 << " (NextState: " << getNextState() << ")\n";
137 }
138 llvm::dbgs() << "\n" << llvm::buffer_ostream::Colors::RESET;
139
140 unsigned int i{0};
141 for (auto const& element : elements_) {
142 llvm::dbgs() << " " << i << ": ";
143 element->dump();
144 ++i;
145 }
146
147 llvm::dbgs() << "\n";
148
149 llvm::dbgs() << llvm::buffer_ostream::Colors::GREEN << " Preds ("
150 << llvm::buffer_ostream::Colors::RESET << predecessors_.size()
151 << llvm::buffer_ostream::Colors::GREEN << "): ";
152 for (auto const& pre : predecessors_) {
153 llvm::dbgs() << "SB" << pre->getBlockID() << " ";
154 }
155
156 llvm::dbgs() << llvm::buffer_ostream::Colors::MAGENTA << "\n Succs ("
157 << llvm::buffer_ostream::Colors::RESET << successors_.size()
158 << llvm::buffer_ostream::Colors::MAGENTA << "): ";
159 for (auto const& succ : successors_) {
160 llvm::dbgs() << "SB" << succ->getBlockID() << " ";
161 }
162 llvm::dbgs() << llvm::buffer_ostream::Colors::RESET;
163 llvm::dbgs() << "\n";
164 }
165}
void registerMatchers(MatchFinder &finder)
void identifyBreaks(clang::ASTContext &context)
Identify if the terminator of a CFGBlock has a break in it.
unsigned int getNextState() const
Returns the next state. Only pertinent for blocks that have waits in them.
llvm::APInt getWaitArg() const
Returns the integer value of the argument supplied to the wait().
llvm::SmallVector< unsigned int > wait_element_ids_
llvm::SmallVector< const SplitCFGBlock * > predecessors_
Predecessors and successors.
const VectorCFGElementPtrImpl & getElements() const
Returns the elements in this block.
void insertElements(VectorCFGElementPtr &elements)
The elements are added to this SplitCFGBlock.
bool hasTerminatorWait() const
Return whether the terminator for this block has a wait statement in it.
void setNextState(unsigned int state)
const clang::CFGBlock * getCFGBlock() const
Returns the pointer to the original CFGBlock from which the SplitCFGBlock was created.
const clang::CFGBlock * block_
A pointer to the original CFGBlock.
bool isLoopWithTwoSuccessors() const
Return whether the SplitCFGBlock is a loop CFGBlock with two succesors.
bool terminator_has_break_
The terminator has break.
unsigned int id_
The block id.
const VectorSplitCFGBlockPtrImpl & getPredecessors() const
Returns the predecessors for the block.
llvm::SmallVector< const clang::CFGElement * > VectorCFGElementPtr
bool isConditional() const
Return whether the SplitCFGBlock is an IF CFGBlock.
llvm::SmallVector< const SplitCFGBlock * > VectorSplitCFGBlockPtrImpl
llvm::SmallVectorImpl< const clang::CFGElement * > VectorCFGElementPtrImpl
unsigned int getBlockID() const
Returns the block ID for the SplitCFGBlock.
bool hasWait() const
Returns whether the SplitCFGBlock is a wait block or not.
const VectorSplitCFGBlockPtrImpl & getSuccessors() const
Returns the successors for the block.
bool terminator_has_wait_
The terminator has break.
unsigned int next_state_
The next state that the wait would transform to.
llvm::SmallVector< const SplitCFGBlock * > successors_
VectorCFGElementPtr elements_
CFG Elements.
llvm::APInt wait_arg_
The wait argument.
bool hasTerminatorBreak() const
Return whether the terminator for this block has a break statement in it.
std::size_t getNumOfElements() const
Returns the number of CFGElements in this block.