source: icGREP/icgrep-devel/icgrep/pablo/optimizers/booleanreassociationpass.h @ 4896

Last change on this file since 4896 was 4871, checked in by nmedfort, 4 years ago

Minor improvements to the optimizers and AST manipulation.

File size: 1.7 KB
Line 
1#ifndef BOOLEANREASSOCIATIONPASS_H
2#define BOOLEANREASSOCIATIONPASS_H
3
4#include <pablo/codegenstate.h>
5#include <boost/container/flat_map.hpp>
6#include <boost/graph/adjacency_list.hpp>
7
8namespace pablo {
9
10class BooleanReassociationPass {
11public:
12    using VertexData = std::pair<PabloAST::ClassTypeId, PabloAST *>;
13    using Graph = boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, VertexData, PabloAST *>;
14    using Vertex = Graph::vertex_descriptor;
15    using Map = std::unordered_map<const PabloAST *, Vertex>;
16    using ScopeMap = boost::container::flat_map<const PabloBlock *, Statement *>;
17    static bool optimize(PabloFunction & function);
18protected:
19    inline BooleanReassociationPass() {}
20    void processScopes(PabloFunction & function);
21    PabloBlock * processScopes(PabloFunction & f, PabloBlock * const block);
22    PabloBlock * processScope(PabloFunction & f, PabloBlock * const block);
23    void summarizeAST(PabloBlock * const block, Graph & G) const;
24    static void summarizeGraph(Graph & G, std::vector<Vertex> & mapping);
25    void resolveNestedUsages(const Vertex u, PabloAST * expr, PabloBlock * const block, Graph & G, Map & M, const Statement * const ignoreIfThis = nullptr) const;
26    void redistributeAST(Graph & G) const;
27    PabloBlock * rewriteAST(PabloFunction & f, PabloBlock * const block, Graph & G);
28    static PabloAST * createTree(const PabloBlock * const block, PabloBlock * const newScope, const Vertex u, Graph & G);
29    static Vertex getSummaryVertex(PabloAST * expr, Graph & G, Map & M, const PabloBlock * const block);
30    static Vertex addSummaryVertex(const PabloAST::ClassTypeId typeId, Graph & G);
31private:
32    ScopeMap mResolvedScopes;
33};
34
35}
36
37#endif // BOOLEANREASSOCIATIONPASS_H
Note: See TracBrowser for help on using the repository browser.