Ignore:
Timestamp:
Jun 20, 2015, 3:52:41 PM (4 years ago)
Author:
nmedfort
Message:

Temporary check-in

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/pablo/optimizers/pablo_automultiplexing.hpp

    r4610 r4611  
    1313#include <random>
    1414#include <stdint.h>
     15#include <llvm/ADT/DenseMap.h>
    1516
    1617struct DdManager; // forward declare of the CUDD manager
     
    2122class AutoMultiplexing {
    2223
    23     using CharacterizationMap = boost::container::flat_map<const PabloAST *, DdNode *>;
     24    using CharacterizationMap = llvm::DenseMap<const PabloAST *, DdNode *>;
    2425    using ConstraintGraph = boost::adjacency_matrix<boost::directedS>;
    2526    using ConstraintVertex = ConstraintGraph::vertex_descriptor;
     
    2930    using IndependentSetGraph = boost::adjacency_matrix<boost::undirectedS, std::pair<int, int>>;
    3031    using SubsetGraph = boost::adjacency_list<boost::hash_setS, boost::vecS, boost::bidirectionalS>;
    31     using Advances = std::vector<Advance *>;
     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 *>>;
    3235    using IndependentSet = std::vector<ConstraintVertex>;
     36
     37    struct SubsitutionMap {
     38        SubsitutionMap(SubsitutionMap * parent = nullptr) : mParent(parent) {}
     39        PabloAST * test(const DdNode * node, PabloAST * stmt) {
     40            PabloAST * replacement = find(node);
     41            if (LLVM_LIKELY(replacement == nullptr)) {
     42                mMap.insert(std::make_pair(node, stmt));
     43            }
     44            return replacement;
     45        }
     46        PabloAST * find(const DdNode * node) const {
     47            auto f = mMap.find(node);
     48            if (LLVM_LIKELY(f == mMap.end())) {
     49                PabloAST * replacement = nullptr;
     50                if (mParent == nullptr) {
     51                    replacement = mParent->find(node);
     52                }
     53                return replacement;
     54            }
     55            return f->second;
     56        }
     57        void insert(const DdNode * node, PabloAST * stmt) {
     58            mMap.insert(std::make_pair(node, stmt));
     59        }
     60    private:
     61        const SubsitutionMap * const mParent;
     62        llvm::DenseMap<const DdNode *, PabloAST *> mMap;
     63    };
    3364
    3465public:
    3566    static bool optimize(const std::vector<Var *> & input, PabloBlock & entry);
    3667protected:
    37     void initialize(const std::vector<Var *> & vars, const PabloBlock & entry);
    38     void characterize(PabloBlock & entry);
     68    void initialize(const std::vector<Var *> & vars, PabloBlock & entry);
     69    void characterize(PabloBlock & block);
     70    DdNode * characterize(Statement * const stmt, const bool throwUncharacterizedOperandError);
     71    DdNode * characterize(Advance * adv, DdNode * input);
     72    void reevaluate(Next * next, DdNode * value);
     73    void minimize(PabloBlock & entry);
     74    void minimize(PabloBlock & block, SubsitutionMap & parent);
     75
    3976    bool notTransitivelyDependant(const ConstraintVertex i, const ConstraintVertex j) const;
    4077    bool generateMultiplexSets(RNG & rng, unsigned k = 1);
     
    68105    ConstraintGraph         mConstraintGraph;
    69106    SubsetGraph             mSubsetGraph;
    70     Advances                mAdvance;   
     107    AdvanceMap              mAdvanceMap;
     108    AdvanceVector           mAdvance;
    71109    MultiplexSetGraph       mMultiplexSetGraph;
    72110};
Note: See TracChangeset for help on using the changeset viewer.