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

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

Incorporated a few common case boolean optimizations in the Simplifier.

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