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

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

Made pablo compiler reenterant through alternate compile method that takes a Module parameter.

File size: 3.2 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 Trie = boost::adjacency_list<boost::hash_setS, boost::vecS, boost::directedS, ConstraintVertex, boost::no_property>;
32    using SubsetGraph = boost::adjacency_list<boost::hash_setS, boost::vecS, boost::bidirectionalS>;
33    // the Advance pointer, input BDD and the BDD variable of the i-th Advance
34    using AdvanceMap = boost::container::flat_map<const Statement *, unsigned>;
35    using AdvanceVector = std::vector<std::tuple<Advance *, DdNode *, DdNode *>>;
36    using VertexVector = std::vector<ConstraintVertex>;
37    using RecentCharacterizations = std::vector<std::pair<const PabloAST *, DdNode *>>;
38
39public:
40    static bool optimize(PabloFunction & function);
41protected:
42    bool initialize(PabloFunction & function);
43    void characterize(PabloBlock &block);
44    DdNode * characterize(Statement * const stmt);
45    DdNode * characterize(Advance * adv, DdNode * input);
46    bool notTransitivelyDependant(const ConstraintVertex i, const ConstraintVertex j) const;
47    bool generateCandidateSets(RNG & rng);
48    void addCandidateSet(const VertexVector & S);
49    void selectMultiplexSets(RNG &);
50    void applySubsetConstraints();
51    void multiplexSelectedIndependentSets() const;
52    void topologicalSort(PabloBlock & entry) const;
53    inline AutoMultiplexing()
54    : mVariables(0)
55    , mConstraintGraph(0)
56    {
57    }
58private:
59
60    DdNode * Zero() const;
61    DdNode * One() const;
62    bool isZero(DdNode * const x) const;
63    DdNode * And(DdNode * const x, DdNode * const y);
64    DdNode * Or(DdNode * const x, DdNode * const y);
65    DdNode * Xor(DdNode * const x, DdNode * const y);
66    DdNode * Not(DdNode * x) const;
67    DdNode * Ite(DdNode * const x, DdNode * const y, DdNode * const z);
68    DdNode * NewVar();
69    void Ref(DdNode * const x);
70    void Deref(DdNode * const x);
71    bool NoSatisfyingAssignment(DdNode * const x);
72    void Shutdown();
73
74private:
75    DdManager *                 mManager;
76    unsigned                    mVariables;
77    CharacterizationMap         mCharacterizationMap;
78    ConstraintGraph             mConstraintGraph;
79    SubsetGraph                 mSubsetGraph;
80    AdvanceMap                  mAdvanceMap;
81    AdvanceVector               mAdvance;
82    MultiplexSetGraph           mMultiplexSetGraph;
83    RecentCharacterizations     mRecentCharacterizations;
84};
85
86}
87
88#endif // PABLO_AUTOMULTIPLEXING_HPP
Note: See TracBrowser for help on using the repository browser.