Chisel
LocalReduction.h
Go to the documentation of this file.
1 #ifndef LOCAL_REDUCTION_H
2 #define LOCAL_REDUCTION_H
3 
4 #include <queue>
5 #include <vector>
6 
7 #include "clang/AST/RecursiveASTVisitor.h"
8 
9 #include "Reduction.h"
10 
12 
17 class LocalReduction : public Reduction {
19 
20 public:
21  LocalReduction() : CollectionVisitor(NULL) {}
22  ~LocalReduction() { delete CollectionVisitor; }
23 
24 private:
25  void Initialize(clang::ASTContext &Ctx);
26  bool HandleTopLevelDecl(clang::DeclGroupRef D);
27  void HandleTranslationUnit(clang::ASTContext &Ctx);
28 
29  std::set<clang::Stmt *> toSet(std::vector<clang::Stmt *> &Vec);
30  std::set<clang::Stmt *> setDifference(std::set<clang::Stmt *> &A,
31  std::set<clang::Stmt *> &B);
32  static DDElement CastElement(clang::Stmt *S);
33 
34  bool callOracle();
35  bool test(DDElementVector &ToBeRemoved);
36  bool isInvalidChunk(DDElementVector &Chunk);
37  void filterElements(std::vector<clang::Stmt *> &Vec);
38 
39  void doHierarchicalDeltaDebugging(clang::Stmt *S);
40  void reduceSwitch(clang::SwitchStmt *SS);
41  void reduceIf(clang::IfStmt *IS);
42  void reduceWhile(clang::WhileStmt *WS);
43  void reduceDoWhile(clang::DoStmt *DS);
44  void reduceFor(clang::ForStmt *FS);
45  void reduceCompound(clang::CompoundStmt *CS);
46  void reduceLabel(clang::LabelStmt *LS);
47  int countReturnStmts(std::set<clang::Stmt *> &Elements);
48  bool noReturn(std::set<clang::Stmt *> &FunctionStmts,
49  std::set<clang::Stmt *> &AllRemovedStmts);
50  bool danglingLabel(std::set<clang::Stmt *> &Remaining);
51  bool brokenDependency(std::set<clang::Stmt *> &Remaining);
52 
53  std::vector<clang::DeclRefExpr *> getDeclRefExprs(clang::Expr *E);
54  std::vector<clang::Stmt *> getBodyStatements(clang::CompoundStmt *CS);
55 
56  void addDefUse(clang::DeclRefExpr *DRE, std::set<clang::Decl *> &DU);
57 
58  std::set<clang::Stmt *> RemovedElements;
59  std::vector<clang::FunctionDecl *> Functions;
60  std::queue<clang::Stmt *> Queue;
61 
62  LocalElementCollectionVisitor *CollectionVisitor;
63  clang::FunctionDecl *CurrentFunction;
64 };
65 
67  : public clang::RecursiveASTVisitor<LocalElementCollectionVisitor> {
68 public:
70 
71  bool VisitFunctionDecl(clang::FunctionDecl *FD);
72 
73 private:
74  LocalReduction *Consumer;
75 };
76 
77 #endif // LOCAL_REDUCTION_H
clang::Expr Expr
Definition: LocalReduction.cpp:31
Represents a general reduction step.
Definition: Reduction.h:14
clang::DeclGroupRef DeclGroupRef
Definition: LocalReduction.cpp:16
clang::DoStmt DoStmt
Definition: LocalReduction.cpp:35
LocalElementCollectionVisitor(LocalReduction *R)
Definition: LocalReduction.h:69
Represents a local reduction phase.
Definition: LocalReduction.h:17
clang::Stmt Stmt
Definition: LocalReduction.cpp:25
std::vector< DDElement > DDElementVector
Definition: ProbabilisticModel.h:12
clang::IfStmt IfStmt
Definition: LocalReduction.cpp:20
clang::LabelStmt LabelStmt
Definition: LocalReduction.cpp:21
LocalReduction()
Definition: LocalReduction.h:21
Definition: LocalReduction.h:66
clang::SwitchStmt SwitchStmt
Definition: LocalReduction.cpp:34
clang::CompoundStmt CompoundStmt
Definition: LocalReduction.cpp:15
clang::FunctionDecl FunctionDecl
Definition: LocalReduction.cpp:18
clang::DeclRefExpr DeclRefExpr
Definition: LocalReduction.cpp:32
clang::ForStmt ForStmt
Definition: LocalReduction.cpp:33
~LocalReduction()
Definition: LocalReduction.h:22
llvm::PointerUnion< clang::Decl *, clang::Stmt * > DDElement
Definition: ProbabilisticModel.h:11
clang::WhileStmt WhileStmt
Definition: LocalReduction.cpp:27