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

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

Minor improvements to the optimizers and AST manipulation.

File size: 2.8 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
15typedef int BDD;
16
17namespace pablo {
18
19class PabloBuilder;
20class PabloFunction;
21
22class AutoMultiplexing {
23
24    using CharacterizationMap = llvm::DenseMap<const PabloAST *, BDD>;
25    using ConstraintGraph = boost::adjacency_matrix<boost::directedS>;
26    using ConstraintVertex = ConstraintGraph::vertex_descriptor;
27    using RNG = std::mt19937;
28    using IntDistribution = std::uniform_int_distribution<RNG::result_type>;
29    using MultiplexSetGraph = boost::adjacency_list<boost::hash_setS, boost::vecS, boost::bidirectionalS>;
30    using SubsetGraph = boost::adjacency_list<boost::hash_setS, boost::vecS, boost::bidirectionalS>;
31    using AdvanceAttributes = std::vector<std::pair<Advance *, BDD>>; // the Advance pointer and its respective base BDD variable
32    using VertexVector = std::vector<ConstraintVertex>;
33    using ScopeMap = boost::container::flat_map<const PabloBlock *, Statement *>;
34
35public:
36    static bool optimize(PabloFunction & function, const unsigned limit = std::numeric_limits<unsigned>::max(), const unsigned maxSelections = 100, const bool independent = false);
37protected:
38    unsigned initialize(PabloFunction & function, const bool independent);
39    void characterize(PabloBlock * const block);
40    BDD characterize(Statement * const stmt);
41    BDD characterize(Advance * const adv, const BDD Ik);
42    bool independent(const ConstraintVertex i, const ConstraintVertex j) const;
43    bool generateCandidateSets(RNG & rng);
44    void addCandidateSet(const VertexVector & S, RNG & rng);
45    void selectMultiplexSets(RNG &);
46    void doTransitiveReductionOfSubsetGraph() ;
47    void applySubsetConstraints();
48    void multiplexSelectedIndependentSets(PabloFunction & function);
49    static void topologicalSort(PabloFunction & function);
50    BDD & get(const PabloAST * const expr);
51
52    inline AutoMultiplexing(const unsigned limit, const unsigned maxSelections)
53    : mLimit(limit)
54    , mMaxSelections(maxSelections)
55    , mVariables(0)
56    , mConstraintGraph(0)
57    {
58    }
59
60private:
61    const unsigned              mLimit;
62    const unsigned              mMaxSelections;
63    unsigned                    mVariables;
64    CharacterizationMap         mCharacterization;
65    ConstraintGraph             mConstraintGraph;
66    SubsetGraph                 mSubsetGraph;
67    AdvanceAttributes           mAdvanceAttributes;
68    MultiplexSetGraph           mMultiplexSetGraph;
69    ScopeMap                    mResolvedScopes;
70};
71
72}
73
74#endif // PABLO_AUTOMULTIPLEXING_HPP
Note: See TracBrowser for help on using the repository browser.