Ignore:
Timestamp:
Aug 10, 2015, 3:30:31 PM (4 years ago)
Author:
nmedfort
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/generate_predefined_ucd_functions.cpp

    r4692 r4722  
    3838#include <llvm/Analysis/DependenceAnalysis.h>
    3939
     40#include <queue>
     41#include <unordered_map>
     42
    4043using namespace pablo;
    4144using namespace UCD;
     
    4952UCDSourcePath("dir", cl::desc("UCD source code directory"), cl::value_desc("directory"), cl::Required);
    5053
    51 static cl::opt<bool> PrintDependenceAnalysis("print-da", cl::init(false), cl::desc("print Dependence Analysis."));
     54static cl::opt<bool> PrintDependenceAnalysis("pablo-ldc", cl::init(false), cl::desc("print Pablo longest dependency chain metrics."));
    5255
    5356
    5457#ifdef ENABLE_MULTIPLEXING
    5558static cl::opt<bool> EnableMultiplexing("multiplexing", cl::init(false),
    56                                         cl::desc("combine Advances whose inputs are mutual exclusive into the fewest number of advances possible (expensive)."));
     59    cl::desc("combine Advances whose inputs are mutual exclusive into the fewest number of advances possible (expensive)."));
    5760
    5861static cl::opt<std::string>
    59 MultiplexingDistribution("multiplexing-dist", cl::desc("Generate a CSV containing the # of Advances found in each UCD function before and after applying multiplexing."), cl::value_desc("filename"));
     62MultiplexingDistribution("multiplexing-dist",
     63    cl::desc("Generate a CSV containing the # of Advances found in each UCD function before and after applying multiplexing."), cl::value_desc("filename"));
    6064
    6165static raw_fd_ostream * MultiplexingDistributionFile = nullptr;
     
    7882    }
    7983    return advances;
     84}
     85
     86/** ------------------------------------------------------------------------------------------------------------- *
     87 * @brief computePabloDependencyMetrics
     88 ** ------------------------------------------------------------------------------------------------------------- */
     89void computePabloDependencyChainMetrics(const PabloFunction & f) {
     90
     91    std::queue<const PabloAST *> Q;
     92    std::unordered_map<const PabloAST *, unsigned> V;
     93
     94    for (unsigned i = 0; i != f.getNumOfResults(); ++i) {
     95        V.insert(std::make_pair(f.getResult(i), 0));
     96        const PabloAST * expr = f.getResult(i)->getExpression();
     97        if (expr->getNumUses() == 1 && V.count(expr) == 0) {
     98            V.insert(std::make_pair(expr, 1));
     99            if (LLVM_LIKELY(isa<Statement>(expr))) {
     100                Q.push(cast<Statement>(expr));
     101            }
     102        }
     103    }
     104
     105    while (!Q.empty()) {
     106        const PabloAST * expr = Q.front(); Q.pop();
     107        unsigned lpl = 0; // longest path length
     108        for (const PabloAST * user : expr->users()) {
     109            lpl = std::max<unsigned>(lpl, V[user]);
     110        }
     111        V.insert(std::make_pair(expr, lpl + 1));
     112        if (const Statement * stmt = dyn_cast<Statement>(expr)) {
     113            for (unsigned i = 0; i != stmt->getNumOperands(); ++i) {
     114                assert (V.count(stmt->getOperand(i)) == 0);
     115                bool everyUserOfThisOperandWasProcessed = true;
     116                for (const PabloAST * user : stmt->getOperand(i)->users()) {
     117                    if (V.count(user) == 0) {
     118                        everyUserOfThisOperandWasProcessed = false;
     119                        break;
     120                    }
     121                }
     122                if (everyUserOfThisOperandWasProcessed) {
     123                    Q.push(stmt->getOperand(i));
     124                }
     125            }
     126        }
     127    }
     128
     129    unsigned lpl = 0;
     130    for (unsigned i = 0; i != f.getNumOfParameters(); ++i) {
     131        assert (V.count(f.getParameter(i)));
     132        lpl = std::max<unsigned>(lpl, V[f.getParameter(i)]);
     133    }
     134
     135
     136
     137}
     138
     139/** ------------------------------------------------------------------------------------------------------------- *
     140 * @brief computeLLVMDependencyMetrics
     141 ** ------------------------------------------------------------------------------------------------------------- */
     142void computeLLVMDependencyChainMetrics(const llvm::Function & f) {
     143
     144
     145
    80146}
    81147
     
    195261}
    196262
    197 
    198263/** ------------------------------------------------------------------------------------------------------------- *
    199264 * @brief generateUCDModule
Note: See TracChangeset for help on using the changeset viewer.