15#ifndef _SPLIT_CFG_BLOCK_H_
16#define _SPLIT_CFG_BLOCK_H_
18#include "clang/Analysis/CFG.h"
20#include "clang/ASTMatchers/ASTMatchers.h"
21#include "clang/ASTMatchers/ASTMatchFinder.h"
25#define DEBUG_TYPE "SplitCFGMatcher"
27using namespace clang::ast_matchers;
43 auto bstmt = findAll(breakStmt().bind(
"break_stmt"));
44 auto wait_stmt = findAll(cxxMemberCallExpr(callee(cxxMethodDecl(hasName(
"wait")))).bind(
"wait_stmt"));
47 finder.addMatcher(bstmt,
this);
48 finder.addMatcher(wait_stmt,
this);
51 virtual void run(
const MatchFinder::MatchResult &result) {
52 auto bk_stmt =
const_cast<clang::Stmt *
>(
53 result.Nodes.getNodeAs<clang::Stmt>(
"break_stmt"));
54 auto wait_stmt =
const_cast<clang::CXXMemberCallExpr *
>(
55 result.Nodes.getNodeAs<clang::CXXMemberCallExpr>(
"wait_stmt"));
58 LLVM_DEBUG(llvm::dbgs() <<
"## BreakStmt \n");
62 LLVM_DEBUG(llvm::dbgs() <<
"## Wait\n");
69 LLVM_DEBUG(llvm::dbgs() <<
"## BREAK FOUND\n");
83 llvm::SmallVectorImpl<const clang::CFGElement *>;
135 VectorSuccessors::const_iterator
begin() {
return succs_.begin(); }
136 VectorSuccessors::const_iterator
end() {
return succs_.end(); }
virtual void run(const MatchFinder::MatchResult &result)
void registerMatchers(MatchFinder &finder)
const_succ_iterator_range const_succs()
SuccessorIterator::const_iterator const_succ_iterator
void identifyBreaks(clang::ASTContext &context)
Identify if the terminator of a CFGBlock has a break in it.
SuccessorIterator::const_iterator succ_begin() const
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.
llvm::iterator_range< succ_iterator > succ_iterator_range
bool isLoopWithTwoSuccessors() const
Return whether the SplitCFGBlock is a loop CFGBlock with two succesors.
llvm::iterator_range< const_succ_iterator > const_succ_iterator_range
bool terminator_has_break_
The terminator has break.
bool is_loop_with_two_succ_
unsigned int id_
The block id.
const VectorSplitCFGBlockPtrImpl & getPredecessors() const
Returns the predecessors for the block.
llvm::SmallVector< const clang::CFGElement * > VectorCFGElementPtr
SplitCFGBlock()
Constructor.
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.
SuccessorIterator::const_iterator succ_end() const
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_
llvm::SmallVector< const SplitCFGBlock * > VectorSplitCFGBlockPtr
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.
VectorSuccessors::const_iterator begin()
std::forward_iterator_tag iterator_category
llvm::SmallVector< const SplitCFGBlock * > VectorSuccessors
std::ptrdiff_t difference_type
const VectorSuccessors & succs_
SuccessorIterator(const llvm::SmallVector< const SplitCFGBlock * > &succ)
VectorSuccessors::const_iterator end()
VectorSuccessors::const_iterator const_iterator