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

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

Misc. changes and start of dependency chain analysis in ucd generator.

File size: 3.7 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    using MuxedVariables = std::vector<std::vector<PabloAST *>>;
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();
52    void simplifyAST(const PabloFunction & function);
53    PabloAST * simplifyAST(DdNode * const f, const std::vector<PabloAST *> & variables, PabloBuilder & builder);
54    PabloAST * makeCoverAST(DdNode * const f, const std::vector<PabloAST *> & variables, PabloBuilder & builder);
55    void topologicalSort(PabloBlock & entry) const;
56    inline AutoMultiplexing()
57    : mVariables(0)
58    , mConstraintGraph(0)
59    {
60    }
61private:
62
63    DdNode * Zero() const;
64    DdNode * One() const;
65    bool isZero(DdNode * const x) const;
66    DdNode * And(DdNode * const x, DdNode * const y);
67    DdNode * Or(DdNode * const x, DdNode * const y);
68    DdNode * Xor(DdNode * const x, DdNode * const y);
69    DdNode * Not(DdNode * x) const;
70    DdNode * Ite(DdNode * const x, DdNode * const y, DdNode * const z);
71    DdNode * NewVar();
72    void Ref(DdNode * const x);
73    void Deref(DdNode * const x);
74    bool NoSatisfyingAssignment(DdNode * const x);
75    void Shutdown();
76
77private:
78    DdManager *                 mManager;
79    unsigned                    mVariables;
80    CharacterizationMap         mCharacterizationMap;
81    ConstraintGraph             mConstraintGraph;
82    SubsetGraph                 mSubsetGraph;
83    AdvanceMap                  mAdvanceMap;
84    AdvanceVector               mAdvance;
85    MultiplexSetGraph           mMultiplexSetGraph;
86    RecentCharacterizations     mRecentCharacterizations;
87    MuxedVariables              mMuxedVariables;
88    unsigned                    mSimplifyDepth;
89};
90
91}
92
93#endif // PABLO_AUTOMULTIPLEXING_HPP
Note: See TracBrowser for help on using the repository browser.