Ignore:
Timestamp:
Nov 6, 2016, 8:37:11 PM (3 years ago)
Author:
nmedfort
Message:

Initial work on adding types to PabloAST and mutable Var objects.

File:
1 edited

Legend:

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

    r5160 r5202  
    3939        }
    4040    }
    41     reschedule(block);
    4241}
    4342
    4443/** ------------------------------------------------------------------------------------------------------------- *
    45  * @brief isSafeToMove
    46  ** ------------------------------------------------------------------------------------------------------------- */
    47 inline static bool isSafeToMove(Statement * stmt) {
    48     return !isa<Assign>(stmt) && !isa<Next>(stmt);
    49 }
    50 
    51 /** ------------------------------------------------------------------------------------------------------------- *
    52  * @brief calculateDepthToCurrentBlock
     44 * @brief depthTo
    5345 ** ------------------------------------------------------------------------------------------------------------- */
    5446inline static unsigned depthTo(const PabloBlock * scope, const PabloBlock * const root) {
     
    5749        ++depth;
    5850        assert (scope);
    59         scope = scope->getPredecessor ();
     51        scope = scope->getPredecessor();
    6052    }
    6153    return depth;
     
    6658 ** ------------------------------------------------------------------------------------------------------------- */
    6759template <class ScopeSet>
    68 inline bool findScopeUsages(Statement * stmt, ScopeSet & scopeSet, const PabloBlock * const block, const PabloBlock * const blocker) {
    69     for (PabloAST * use : stmt->users()) {
     60inline bool findScopeUsages(PabloAST * expr, ScopeSet & scopeSet, const PabloBlock * const block, const PabloBlock * const blocker) {
     61    for (PabloAST * use : expr->users()) {
    7062        assert (isa<Statement>(use));
    7163        PabloBlock * const parent = cast<Statement>(use)->getParent();
     
    8779    // find the least common ancestor of the scope blocks. If it is not the current scope,
    8880    // then we can sink the instruction.
    89     if (isa<If>(stmt)) {
    90         for (Assign * def : cast<If>(stmt)->getDefined()) {
    91             if (!findScopeUsages(def, scopeSet, block, cast<If>(stmt)->getBody())) {
     81    assert (scopeSet.empty());
     82    if (isa<Branch>(stmt)) {
     83        for (Var * def : cast<Branch>(stmt)->getEscaped()) {
     84            if (!findScopeUsages(def, scopeSet, block, cast<Branch>(stmt)->getBody())) {
    9285                return false;
    9386            }
    9487        }
    95     } else if (isa<While>(stmt)) {
    96         for (Next * var : cast<While>(stmt)->getVariants()) {
    97             if (escapes(var) && !findScopeUsages(var, scopeSet, block, cast<While>(stmt)->getBody())) {
    98                 return false;
    99             }
    100         }
    101     } else if (isSafeToMove(stmt)) {
     88    } else if (!isa<Assign>(stmt)) {
    10289        return findScopeUsages(stmt, scopeSet, block, nullptr);
    10390    }
     
    126113                // the scope tree until both scopes are at the same depth.
    127114                while (depth1 > depth2) {
    128                     scope1 = scope1->getPredecessor ();
     115                    scope1 = scope1->getPredecessor();
    129116                    --depth1;
    130117                }
    131118                while (depth1 < depth2) {
    132                     scope2 = scope2->getPredecessor ();
     119                    scope2 = scope2->getPredecessor();
    133120                    --depth2;
    134121                }
     
    138125                while (scope1 != scope2) {
    139126                    assert (scope1 && scope2);
    140                     scope1 = scope1->getPredecessor ();
    141                     scope2 = scope2->getPredecessor ();
     127                    scope1 = scope1->getPredecessor();
     128                    scope2 = scope2->getPredecessor();
    142129                }
    143130                assert (scope1);
     
    149136            }
    150137            assert (scopes.size() == 1);
    151             assert (isa<If>(stmt) ? (cast<If>(stmt)->getBody() != scopes.front()) : true);
    152             assert (isa<While>(stmt) ? (cast<While>(stmt)->getBody() != scopes.front()) : true);
     138            assert (isa<Branch>(stmt) ? (cast<Branch>(stmt)->getBody() != scopes.front()) : true);
    153139            stmt->insertBefore(scopes.front()->front());
    154140        }
     
    163149void CodeMotionPass::hoistLoopInvariants(While * loop) {
    164150    flat_set<const PabloAST *> loopVariants;
    165     for (Next * variant : loop->getVariants()) {
     151    for (Var * variant : loop->getEscaped()) {
    166152        loopVariants.insert(variant);
    167         loopVariants.insert(variant->getInitial());
    168153    }
    169154    Statement * outerNode = loop->getPrevNode();
    170155    Statement * stmt = loop->getBody()->front();
    171156    while (stmt) {
    172         if (isa<If>(stmt)) {
    173             for (Assign * def : cast<If>(stmt)->getDefined()) {
    174                 loopVariants.insert(def);
    175             }
    176         } else if (isa<While>(stmt)) {
    177             for (Next * var : cast<While>(stmt)->getVariants()) {
     157        if (isa<Branch>(stmt)) {
     158            for (Var * var : cast<Branch>(stmt)->getEscaped()) {
    178159                loopVariants.insert(var);
    179160            }
     
    199180}
    200181
    201 /** ------------------------------------------------------------------------------------------------------------- *
    202  * @brief reschedule
    203  ** ------------------------------------------------------------------------------------------------------------- */
    204 void CodeMotionPass::reschedule(PabloBlock * const block) {
    205 
    206 //    using Graph = adjacency_list<hash_setS, vecS, bidirectionalS, Statement *>;
    207 //    using Vertex = Graph::vertex_descriptor;
    208 //    using Map = flat_map<Statement *, Vertex>;
    209 
    210 //    const unsigned size = std::distance(block->begin(), block->end());
    211 
    212 //    Graph G(size);
    213 //    Map M;
    214 
    215 //    M.reserve(size);
    216 
    217 //    unsigned i = 0;
    218 //    for (Statement * stmt : *block) {
    219 //        G[i] = stmt;
    220 //        M.emplace(stmt, i);
    221 //        ++i;
    222 //    }
    223 
    224 //    i = 0;
    225 //    for (Statement * stmt : *block) {
    226 //        for (PabloAST * user : stmt->users()) {
    227 //            if (isa<Statement>(user)) {
    228 //                Statement * use = cast<Statement>(user);
    229 //                PabloBlock * parent = use->getParent();
    230 //                while (parent) {
    231 //                    if (parent == block) {
    232 //                        break;
    233 //                    }
    234 //                    use = parent->getBranch();
    235 //                    parent = parent->getParent();
    236 //                }
    237 //                auto f = M.find(use);
    238 //                assert (f != M.end());
    239 //                add_edge(i, f->second, G);
    240 //            }
    241 //        }
    242 //        ++i;
    243 //    }
    244 
    245 //    circular_buffer<Vertex> ordering(size);
    246 //    std::vector<unsigned> cumulativeDependencies;
    247 //    topological_sort(G, std::back_inserter(ordering));
    248    
    249 
    250 
    251182}
    252 
    253 }
Note: See TracChangeset for help on using the changeset viewer.