Ignore:
Timestamp:
Feb 12, 2016, 4:44:35 PM (3 years ago)
Author:
nmedfort
Message:

Bug fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/pablo/optimizers/distributivepass.cpp

    r4922 r4927  
    377377inline void DistributivePass::distribute(Variadic * const var) {
    378378
    379     std::vector<Variadic *> Q;
     379
    380380
    381381    assert (isa<And>(var) || isa<Or>(var));
    382 
    383     Q.push_back(var);
    384382
    385383    Graph G;
    386384    VertexSet A;
    387385
     386    std::vector<Variadic *> Q = {var};
     387
    388388    while (Q.size() > 0) {
    389 
    390         Variadic * expr = CanonicalizeDFG::canonicalize(Q.back());
    391         Q.pop_back();
     389        Variadic * expr = CanonicalizeDFG::canonicalize(Q.back()); Q.pop_back();
    392390        PabloAST * const replacement = Simplifier::fold(expr, expr->getParent());
    393391        if (LLVM_UNLIKELY(replacement != nullptr)) {
     
    427425                const VertexSet & sinks = std::get<2>(set);
    428426                assert (sinks.size() > 0);
    429 
    430                 // Test whether we can apply the identity law to distributed set. I.e., (P ∧ Q) √ (P ∧ ¬Q) ⇔ (P √ Q) ∧ (P √ ¬Q) ⇔ P
    431 
    432427
    433428                for (const Vertex u : intermediary) {
     
    465460                Q.push_back(innerOp);
    466461                Q.push_back(outerOp);
     462
     463                unmodified = false;
    467464            }
    468465
     
    471468        }
    472469    }
     470
    473471}
    474472
     
    477475 ** ------------------------------------------------------------------------------------------------------------- */
    478476void DistributivePass::distribute(PabloBlock * const block) {
    479     for (Statement * stmt : *block) {
     477    Statement * stmt = block->front();
     478    while (stmt) {
     479        Statement * next = stmt->getNextNode();
    480480        if (isa<If>(stmt) || isa<While>(stmt)) {
    481481            distribute(isa<If>(stmt) ? cast<If>(stmt)->getBody() : cast<While>(stmt)->getBody());
     
    483483            distribute(cast<Variadic>(stmt));
    484484        }
     485        stmt = next;
    485486    }
    486487}
     
    489490 * @brief optimize
    490491 ** ------------------------------------------------------------------------------------------------------------- */
    491 void DistributivePass::optimize(PabloFunction & function) {
    492     DistributivePass::distribute(function.getEntryBlock());
    493     #ifndef NDEBUG
    494     PabloVerifier::verify(function, "post-distribution");
    495     #endif
    496     Simplifier::optimize(function);
    497 }
    498 
    499 
    500 }
     492bool DistributivePass::optimize(PabloFunction & function) {
     493    DistributivePass dp;
     494    unsigned rounds = 0;
     495    for (;;) {
     496        dp.unmodified = true;
     497        dp.distribute(function.getEntryBlock());
     498        if (dp.unmodified) {
     499            break;
     500        }
     501        ++rounds;
     502        #ifndef NDEBUG
     503        PabloVerifier::verify(function, "post-distribution");
     504        #endif
     505        Simplifier::optimize(function);
     506    }
     507    return rounds > 0;
     508}
     509
     510
     511}
Note: See TracChangeset for help on using the changeset viewer.