source: icGREP/icgrep-devel/icgrep/pablo/optimizers/pablo_automultiplexing.hpp @ 4738

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

More work on the boolean reassociation pass.

File size: 3.1 KB
Line 
1#ifndef PABLO_AUTOMULTIPLEXING_HPP
2#define PABLO_AUTOMULTIPLEXING_HPP
3
4#include <pablo/codegenstate.h>
5#include <slab_allocator.h>
6#include <queue>
7#include <boost/graph/adjacency_list.hpp>
8#include <boost/graph/adjacency_matrix.hpp>
9#include <boost/container/flat_map.hpp>
10#include <boost/numeric/ublas/matrix.hpp>
11#include <random>
12#include <stdint.h>
13#include <llvm/ADT/DenseMap.h>
14
15struct DdManager; // forward declare of the CUDD manager
16struct DdNode;
17
18namespace pablo {
19
20class PabloBuilder;
21class PabloFunction;
22
23class AutoMultiplexing {
24
25    using CharacterizationMap = llvm::DenseMap<const PabloAST *, DdNode *>;
26    using ConstraintGraph = boost::adjacency_matrix<boost::directedS>;
27    using ConstraintVertex = ConstraintGraph::vertex_descriptor;
28    using RNG = std::mt19937;
29    using IntDistribution = std::uniform_int_distribution<RNG::result_type>;
30    using MultiplexSetGraph = boost::adjacency_list<boost::hash_setS, boost::vecS, boost::bidirectionalS>;
31    using SubsetGraph = boost::adjacency_list<boost::hash_setS, boost::vecS, boost::bidirectionalS>;
32    // the Advance pointer, input BDD and the BDD variable of the i-th Advance
33    using AdvanceMap = boost::container::flat_map<const Statement *, unsigned>;
34    using AdvanceVector = std::vector<std::tuple<Advance *, DdNode *, DdNode *>>;
35    using VertexVector = std::vector<ConstraintVertex>;
36    using RecentCharacterizations = std::vector<std::pair<const PabloAST *, DdNode *>>;
37public:
38    static bool optimize(PabloFunction & function);
39protected:
40    bool initialize(PabloFunction & function);
41    void characterize(PabloBlock &block);
42    DdNode * characterize(Statement * const stmt);
43    DdNode * characterize(Advance * adv, DdNode * input);
44    bool notTransitivelyDependant(const ConstraintVertex i, const ConstraintVertex j) const;
45    bool generateCandidateSets(RNG & rng);
46    void addCandidateSet(const VertexVector & S);
47    void selectMultiplexSets(RNG &);
48    void applySubsetConstraints();
49    void multiplexSelectedIndependentSets();
50    void topologicalSort(PabloBlock & entry) const;
51    inline AutoMultiplexing()
52    : mVariables(0)
53    , mConstraintGraph(0)
54    {
55    }
56private:
57
58    DdNode * Zero() const;
59    DdNode * One() const;
60    bool isZero(DdNode * const x) const;
61    DdNode * And(DdNode * const x, DdNode * const y);
62    DdNode * Or(DdNode * const x, DdNode * const y);
63    DdNode * Xor(DdNode * const x, DdNode * const y);
64    DdNode * Not(DdNode * x) const;
65    DdNode * Ite(DdNode * const x, DdNode * const y, DdNode * const z);
66    DdNode * NewVar();
67    void Ref(DdNode * const x);
68    void Deref(DdNode * const x);
69    bool NoSatisfyingAssignment(DdNode * const x);
70    void Shutdown();
71
72private:
73    DdManager *                 mManager;
74    unsigned                    mVariables;
75    CharacterizationMap         mCharacterizationMap;
76    ConstraintGraph             mConstraintGraph;
77    SubsetGraph                 mSubsetGraph;
78    AdvanceMap                  mAdvanceMap;
79    AdvanceVector               mAdvance;
80    MultiplexSetGraph           mMultiplexSetGraph;
81    RecentCharacterizations     mRecentCharacterizations;
82};
83
84}
85
86#endif // PABLO_AUTOMULTIPLEXING_HPP
Note: See TracBrowser for help on using the repository browser.