source: icGREP/icgrep-devel/icgrep/pablo/passes/factorizedfg.h @ 5828

Last change on this file since 5828 was 5202, checked in by nmedfort, 3 years ago

Initial work on adding types to PabloAST and mutable Var objects.

File size: 2.7 KB
Line 
1#ifndef FACTORIZEDFG_H
2#define FACTORIZEDFG_H
3
4
5#include <boost/container/flat_set.hpp>
6#include <boost/container/flat_map.hpp>
7#include <pablo/pabloAST.h>
8#include <vector>
9#include <deque>
10
11namespace pablo {
12
13class PabloFunction;
14class PabloBlock;
15class Variadic;
16class Statement;
17class PabloAST;
18
19class FactorizeDFG {
20
21    using ScopeDepth = boost::container::flat_map<const PabloBlock *, unsigned>;
22    using ObjectSet = std::vector<PabloAST *>;
23    using ScopeUsers = std::pair<PabloBlock *, ObjectSet>;
24    using Biclique = std::pair<ObjectSet, ObjectSet>; // [{Operands}, {Users}]
25    using BicliqueSet = std::vector<Biclique>;
26    using CheckSet = boost::container::flat_set<PabloAST *>;
27    using LiveSet = std::deque<PabloAST *>;
28    using TypeId = PabloAST::ClassTypeId;
29public:
30    static void transform(PabloFunction & function);
31protected:   
32    void initialize(PabloFunction &function);
33    void initialize(PabloBlock * const block, const unsigned depth);
34
35    unsigned scopeDepthOf(const PabloBlock * const block) const;
36    unsigned scopeDepthOf(const PabloAST * const expr) const;
37
38    CheckSet makeCheckSet(PabloBlock * const scope, const ObjectSet & values) const;
39    Statement * firstIn(PabloBlock * const scope, Statement * const initial, const ObjectSet & operands) const;
40    Statement * lastIn(PabloBlock * const scope, Statement * const initial, const ObjectSet & users) const;
41    Variadic * factorize(TypeId typeId, PabloBlock * const scope, ObjectSet & operands, ObjectSet & users) const;
42    static BicliqueSet independentFactoringSets(BicliqueSet && factoringSets, const unsigned side);
43    static BicliqueSet enumerateFactoringSets(Variadic * const var);
44    static BicliqueSet enumerateFactoringSets(ObjectSet params, PabloBlock * const entryScope, TypeId typeId);
45    bool processFactoringSets(TypeId typeId, PabloBlock * const scope, BicliqueSet && factoringSets) const;
46    PabloBlock * findInsertionScope(const ObjectSet & users) const;
47    bool processFactoringSets(TypeId typeId, BicliqueSet && factoringSets, ObjectSet & factorings) const;
48    bool factor(PabloBlock * const block);
49    void factor(PabloFunction & function, TypeId typeId);
50    void factor(PabloFunction & function);
51
52//    void rematerialize(PabloBlock * const block, LiveSet & priorSet);
53//    void rematerialize(PabloFunction & function);
54
55    void elevate(PabloFunction & function) const;
56    void elevate(PabloBlock * const block) const;
57    void elevate(Variadic * const var, PabloBlock * block) const;
58
59    void lower(PabloFunction & function) const;
60    void lower(PabloBlock * const block) const;
61    PabloAST * lower(Variadic * const var, PabloBlock * block) const;
62
63    FactorizeDFG() = default;
64
65private:
66    ScopeDepth              mScopeDepth;
67};
68
69}
70
71#endif // FACTORIZEDFG_H
Note: See TracBrowser for help on using the repository browser.