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

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

Progress on multi-target UCD compiler.

File size: 2.0 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    using WrittenAt = boost::container::flat_map<const PabloAST *, unsigned>;
18    using ScopeMap = boost::container::flat_map<const PabloBlock *, Statement *>;
19
20    static bool optimize(PabloFunction & function);
21protected:
22    inline BooleanReassociationPass() {}
23    void resolveScopes(PabloFunction & function);
24    void resolveScopes(PabloBlock &block);
25    void processScopes(PabloFunction & function);
26    void processScopes(PabloFunction & function, PabloBlock & block);
27    void processScope(PabloFunction &, PabloBlock & block);
28    void summarizeAST(PabloBlock & block, Graph & G, Map & M) const;
29    static void findAndPropogateAnyConstants(const Vertex u, Graph & G, Map & M);
30    static void summarizeGraph(const PabloBlock & block, Graph & G, std::vector<Vertex> & mapping, Map &M);
31    void resolveUsages(const Vertex u, PabloAST * expr, PabloBlock & block, Graph & G, Map & M, const Statement * const ignoreIfThis = nullptr) const;
32    void redistributeAST(const PabloBlock & block, Graph & G, Map & M) const;
33    void rewriteAST(PabloBlock & block, Graph & G);
34    static PabloAST * createTree(PabloBlock & block, const Vertex u, Graph & G, const WrittenAt & writtenAt);
35    static Vertex getSummaryVertex(PabloAST * expr, Graph & G, Map & M, const PabloBlock & block);
36    static Vertex addSummaryVertex(const PabloAST::ClassTypeId typeId, Graph & G);
37private:
38    ScopeMap mResolvedScopes;
39};
40
41}
42
43#endif // BOOLEANREASSOCIATIONPASS_H
Note: See TracBrowser for help on using the repository browser.