Ignore:
Timestamp:
Sep 23, 2015, 12:54:17 AM (4 years ago)
Author:
nmedfort
Message:

Misc changes + potential SIGBUS fix for issue reported by Hongpu.

Location:
icGREP/icgrep-devel/icgrep/pablo/optimizers
Files:
4 edited

Legend:

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

    r4778 r4788  
    8282}
    8383
     84inline PabloAST *& getValue(VertexData & data) {
     85    return std::get<1>(data);
     86}
     87
     88inline PabloAST * getValue(const VertexData & data) {
     89    return std::get<1>(data);
     90}
     91
    8492inline bool isAssociative(const VertexData & data) {
    8593    switch (getType(data)) {
     
    104112
    105113inline bool isNegated(const VertexData & data) {
    106     return getType(data) == TypeId::Not && (std::get<1>(data) != nullptr);
     114    return getType(data) == TypeId::Not && (getValue(data) != nullptr);
    107115}
    108116
     
    339347    flat_set<PabloAST *> sources;
    340348    for (const auto e : make_iterator_range(in_edges(u, G))) {
    341         PabloAST * expr = std::get<1>(G[source(e, G)]);
     349        PabloAST * expr = getValue(G[source(e, G)]);
    342350        assert ("G contains a null input variable!" && (expr != nullptr));
    343351        sources.insert(expr);
     
    346354    // Sort the queue in order of how the inputs were written
    347355    std::sort(Q.begin(), Q.end(), [&writtenAt](const PabloAST * const e1, const PabloAST * const e2) -> bool {
    348         const auto f1 = writtenAt.find(e1);
    349         const unsigned v1 = (f1 == writtenAt.end()) ? 0 : f1->second;
    350         const auto f2 = writtenAt.find(e2);
    351         const unsigned v2 = (f2 == writtenAt.end()) ? 0 : f2->second;
    352         return v1 < v2;
     356        const auto f1 = writtenAt.find(e1); assert (f1 != writtenAt.end());
     357        const auto f2 = writtenAt.find(e2); assert (f2 != writtenAt.end());
     358        return f1->second < f2->second;
    353359    });
    354360
    355361    const TypeId typeId = getType(G[u]);
    356362    while (Q.size() > 1) {
    357         PabloAST * e1 = Q.front(); Q.pop_front();
     363        PabloAST * e1 = Q.front(); Q.pop_front();       
    358364        PabloAST * e2 = Q.front(); Q.pop_front();
    359365        PabloAST * expr = nullptr;
    360         // Note: this switch ought to compile to an array of function pointers to the appropriate method.
    361366        switch (typeId) {
    362367            case TypeId::And:
     
    372377    PabloAST * const result = Q.front();
    373378    assert (result);
    374     std::get<1>(G[u]) = result;
     379    getValue(G[u]) = result;
    375380    return result;
    376381}
     
    391396void BooleanReassociationPass::rewriteAST(PabloBlock & block, Graph & G) {
    392397
     398//    // Clear out the current AST
     399//    std::vector<Statement *> currentAST;
     400//    for (Statement * stmt = block.front(); stmt; stmt = stmt->removeFromParent()) {
     401//        currentAST.push_back(stmt);
     402//    }
     403    // Rewrite the AST in accordance to G
    393404    circular_buffer<Vertex> Q(num_vertices(G));
    394405    topological_sort(G, std::back_inserter(Q));
     406
    395407    block.setInsertPoint(nullptr);
    396 
    397     unsigned index = 0;
     408    unsigned statementCount = 0;
    398409    WrittenAt writtenAt;
    399410    while (!Q.empty()) {
    400         const Vertex u = Q.back(); Q.pop_back();
     411        const Vertex u = Q.back();
     412        Q.pop_back();
     413        // Supress any isolated vertices; the AST must be a single connected component.
     414        if (in_degree(u, G) == 0 && out_degree(u, G) == 0) {
     415            continue;
     416        }
     417        unsigned statementIndex = 0;
     418        PabloAST * expr = getValue(G[u]);
    401419        if (LLVM_LIKELY(isMutable(G[u], block))) {
    402420            Statement * stmt = nullptr;
     
    405423                if (LLVM_LIKELY(inCurrentBlock(replacement, block))) {
    406424                    stmt = cast<Statement>(replacement);
    407                 } else { // optimization reduced this to a Constant, Var or an outer-scope statement
     425                } else { // optimization reduced this to a Constant, Var or a prior-scope statement
    408426                    getType(G[u]) = TypeId::Var;
    409427                    continue;
    410428                }
    411429            } else { // update any potential mappings
    412                 stmt = cast<Statement>(std::get<1>(G[u]));
     430                stmt = cast<Statement>(getValue(G[u]));
    413431            }
    414432            assert (stmt);
    415             assert (inCurrentBlock(stmt, block));           
    416433            for (auto e : make_iterator_range(out_edges(u, G))) {
    417434                if (G[e] && G[e] != stmt) {
    418                     PabloAST * expr = std::get<1>(G[target(e, G)]);
     435                    PabloAST * expr = getValue(G[target(e, G)]);
    419436                    if (expr) { // processing a yet-to-be created value
    420437                        cast<Statement>(expr)->replaceUsesOfWith(G[e], stmt);
     
    426443                continue;
    427444            }
    428             writtenAt.emplace(stmt, ++index);
    429445            block.insert(stmt);
    430         }
    431     }
     446            statementIndex = ++statementCount;
     447            expr = stmt;
     448        }
     449        writtenAt.emplace(expr, statementIndex);
     450    }
     451//    // Erase any AST node that weren't placed back into the AST
     452//    for (Statement * stmt : currentAST) {
     453//        if (stmt->getParent() == nullptr) {
     454//            stmt->eraseFromParent(true);
     455//        }
     456//    }
    432457}
    433458
     
    745770    VertexSet sinks;
    746771    for (const Vertex u : make_iterator_range(vertices(H))) {
    747         if (out_degree(u, H) == 0) {
     772        if (out_degree(u, H) == 0 && in_degree(u, G) != 0) {
    748773            sinks.push_back(u);
    749774        }
     
    892917            for (const Vertex t : sinks) {
    893918                const auto v = mapping[H[t]];
    894                 add_edge(std::get<1>(G[v]), y, v, G);
     919                add_edge(getValue(G[v]), y, v, G);
    895920            }
    896921
  • icGREP/icgrep-devel/icgrep/pablo/optimizers/pablo_automultiplexing.cpp

    r4775 r4788  
    301301
    302302    // Map the predefined 0/1 entries
    303     mCharacterizationMap[function.getEntryBlock().createZeroes()] = Zero();
    304     mCharacterizationMap[function.getEntryBlock().createOnes()] = One();
     303    mCharacterizationMap[PabloBlock::createZeroes()] = Zero();
     304    mCharacterizationMap[PabloBlock::createOnes()] = One();
    305305
    306306    // Order the variables so the input Vars are pushed to the end; they ought to
  • icGREP/icgrep-devel/icgrep/pablo/optimizers/pablo_bddminimization.cpp

    r4775 r4788  
    8383    Cudd_MakeTreeNode(mManager, 0, function.getNumOfParameters(), MTR_DEFAULT);
    8484    // Map the predefined 0/1 entries
    85     mCharacterizationMap[function.getEntryBlock().createZeroes()] = Zero();
    86     mCharacterizationMap[function.getEntryBlock().createOnes()] = One();   
     85    mCharacterizationMap[PabloBlock::createZeroes()] = Zero();
     86    mCharacterizationMap[PabloBlock::createOnes()] = One();
    8787    // Order the variables so the input Vars are pushed to the end; they ought to
    8888    // be the most complex to resolve.   
  • icGREP/icgrep-devel/icgrep/pablo/optimizers/pablo_simplifier.cpp

    r4775 r4788  
    107107            if (LLVM_UNLIKELY(isa<Zeroes>(ifNode->getCondition()))) {
    108108                for (Assign * defVar : ifNode->getDefined()) {
    109                     defVar->replaceWith(block.createZeroes(), false, true);
     109                    defVar->replaceWith(PabloBlock::createZeroes(), false, true);
    110110                }
    111111                stmt = stmt->eraseFromParent(true);
Note: See TracChangeset for help on using the changeset viewer.