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

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

Minor revisions.

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