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.

Location:
icGREP/icgrep-devel/icgrep/pablo/passes
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/pablo/passes/factorizedfg.cpp

    r5160 r5202  
    2929 * bicliques" by Alexe et. al. (2003).
    3030 ** ------------------------------------------------------------------------------------------------------------- */
    31 FactorizeDFG::BicliqueSet FactorizeDFG::enumerateFactoringSets(ObjectSet params, PabloBlock * const entryScope, const TypeId typeId) {
     31FactorizeDFG::BicliqueSet FactorizeDFG::enumerateFactoringSets(ObjectSet params, PabloBlock * const entryScope, TypeId typeId) {
    3232    using IntersectionSets = flat_set<ObjectSet>;
    3333
     
    125125        for (PabloAST * user : op->users()) {
    126126            if (user->getClassTypeId() == var->getClassTypeId()) {               
    127                 for (PabloBlock * scope = cast<Variadic>(user)->getParent(); scope; scope = scope->getPredecessor ()) {
     127                for (PabloBlock * scope = cast<Variadic>(user)->getParent(); scope; scope = scope->getPredecessor()) {
    128128                    if (LLVM_UNLIKELY(scope == var->getParent())) {
    129129                        tmp.push_back(user);
     
    196196 ** ------------------------------------------------------------------------------------------------------------- */
    197197template <class Type>
    198 inline bool intersects(const Type & A, const Type & B) {
     198inline bool intersects(Type & A, Type & B) {
    199199    auto first1 = A.begin(), last1 = A.end();
    200200    auto first2 = B.begin(), last2 = B.end();
     
    285285                    assert (nested);
    286286                    value = nested->getBranch();
    287                     nested = nested->getPredecessor ();
     287                    nested = nested->getPredecessor();
    288288                    if (nested == scope) {
    289289                        break;
     
    349349        // the scope tree until both scopes are at the same depth.
    350350        while (depth1 > depth2) {
    351             scope1 = scope1->getPredecessor ();
     351            scope1 = scope1->getPredecessor();
    352352            --depth1;
    353353        }
    354354        while (depth1 < depth2) {
    355             scope2 = scope2->getPredecessor ();
     355            scope2 = scope2->getPredecessor();
    356356            --depth2;
    357357        }
     
    360360        // must be the LCA of our original scopes.
    361361        while (scope1 != scope2) {
    362             scope1 = scope1->getPredecessor ();
    363             scope2 = scope2->getPredecessor ();
     362            scope1 = scope1->getPredecessor();
     363            scope2 = scope2->getPredecessor();
    364364        }
    365365        assert (scope1 && scope2);
     
    375375 * @brief factorize
    376376 ** ------------------------------------------------------------------------------------------------------------- */
    377 inline Variadic * FactorizeDFG::factorize(const TypeId typeId, PabloBlock * const scope, ObjectSet & operands, ObjectSet & users) const {
     377inline Variadic * FactorizeDFG::factorize(TypeId typeId, PabloBlock * const scope, ObjectSet & operands, ObjectSet & users) const {
    378378    Statement * const lastOperand = lastIn(scope, scope->back(), operands);
    379379    Statement * const firstUsage = firstIn(scope, lastOperand, users);
     
    400400 * @brief processFactoringSets
    401401 ** ------------------------------------------------------------------------------------------------------------- */
    402 inline bool FactorizeDFG::processFactoringSets(const TypeId typeId, PabloBlock * const scope, BicliqueSet && factoringSets) const {
     402inline bool FactorizeDFG::processFactoringSets(TypeId typeId, PabloBlock * const scope, BicliqueSet && factoringSets) const {
    403403    const auto S = independentFactoringSets(std::move(factoringSets), 0);
    404404    for (auto i : S) {
     
    411411// * @brief processFactoringSets
    412412// ** ------------------------------------------------------------------------------------------------------------- */
    413 //inline bool FactorizeDFG::processFactoringSets(const TypeId typeId, BicliqueSet && factoringSets, ObjectSet & factorings) const {
     413//inline bool FactorizeDFG::processFactoringSets(TypeId typeId, BicliqueSet && factoringSets, ObjectSet & factorings) const {
    414414//    const auto S = independentFactoringSets(std::move(factoringSets), 0);
    415415//    for (auto i : S) {
     
    443443// * @brief factor
    444444// ** ------------------------------------------------------------------------------------------------------------- */
    445 //void FactorizeDFG::factor(PabloFunction & function, const TypeId typeId) {
     445//void FactorizeDFG::factor(PabloFunction & function, TypeId typeId) {
    446446//    ObjectSet vars;
    447447//    for (unsigned i = 0; i != function.getNumOfParameters(); ++i) {
     
    608608                    }
    609609                    usage = scope->getBranch();
    610                     assert (scope != scope->getPredecessor ());
    611                     scope = scope->getPredecessor ();
     610                    assert (scope != scope->getPredecessor());
     611                    scope = scope->getPredecessor();
    612612                }
    613613            }
     
    836836                    }
    837837                    op = scope->getBranch();
    838                     scope = scope->getPredecessor ();
     838                    scope = scope->getPredecessor();
    839839                }
    840840            }
  • icGREP/icgrep-devel/icgrep/pablo/passes/factorizedfg.h

    r4927 r5202  
    3939    Statement * firstIn(PabloBlock * const scope, Statement * const initial, const ObjectSet & operands) const;
    4040    Statement * lastIn(PabloBlock * const scope, Statement * const initial, const ObjectSet & users) const;
    41     Variadic * factorize(const TypeId typeId, PabloBlock * const scope, ObjectSet & operands, ObjectSet & users) const;
     41    Variadic * factorize(TypeId typeId, PabloBlock * const scope, ObjectSet & operands, ObjectSet & users) const;
    4242    static BicliqueSet independentFactoringSets(BicliqueSet && factoringSets, const unsigned side);
    4343    static BicliqueSet enumerateFactoringSets(Variadic * const var);
    44     static BicliqueSet enumerateFactoringSets(ObjectSet params, PabloBlock * const entryScope, const TypeId typeId);
    45     bool processFactoringSets(const TypeId typeId, PabloBlock * const scope, BicliqueSet && factoringSets) const;
     44    static BicliqueSet enumerateFactoringSets(ObjectSet params, PabloBlock * const entryScope, TypeId typeId);
     45    bool processFactoringSets(TypeId typeId, PabloBlock * const scope, BicliqueSet && factoringSets) const;
    4646    PabloBlock * findInsertionScope(const ObjectSet & users) const;
    47     bool processFactoringSets(const TypeId typeId, BicliqueSet && factoringSets, ObjectSet & factorings) const;
     47    bool processFactoringSets(TypeId typeId, BicliqueSet && factoringSets, ObjectSet & factorings) const;
    4848    bool factor(PabloBlock * const block);
    49     void factor(PabloFunction & function, const TypeId typeId);
     49    void factor(PabloFunction & function, TypeId typeId);
    5050    void factor(PabloFunction & function);
    5151
  • icGREP/icgrep-devel/icgrep/pablo/passes/flattenassociativedfg.cpp

    r5160 r5202  
    6363    PabloAST * const negatedVar = negation->getOperand(0);
    6464    if (isa<And>(negatedVar) || isa<Or>(negatedVar)) {
    65         const TypeId typeId = isa<And>(negatedVar) ? TypeId::Or : TypeId::And;
     65        TypeId typeId = isa<And>(negatedVar) ? TypeId::Or : TypeId::And;
    6666        bool expandable = false;
    6767        for (PabloAST * user : negation->users()) {
     
    8989                        }
    9090                        br = scope->getBranch();
    91                         scope = scope->getPredecessor ();
     91                        scope = scope->getPredecessor();
    9292                    }
    9393                }
     
    313313 ** ------------------------------------------------------------------------------------------------------------- */
    314314template <class Type>
    315 inline bool intersects(const Type & A, const Type & B) {
     315inline bool intersects(Type & A, Type & B) {
    316316    auto first1 = A.begin(), last1 = A.end();
    317317    auto first2 = B.begin(), last2 = B.end();
     
    523523 ** ------------------------------------------------------------------------------------------------------------- */
    524524inline void analyzeScopeDependencies(Assign * const def, ScopeDependencyGraph & G, ScopeDependencyMap & M) {
    525     if (LLVM_LIKELY(isa<Variadic>(def->getExpression()))) {
    526         buildScopeDependencyGraph(cast<Variadic>(def->getExpression()), G, M);
     525    if (LLVM_LIKELY(isa<Variadic>(def->getValue()))) {
     526        buildScopeDependencyGraph(cast<Variadic>(def->getValue()), G, M);
    527527    }
    528528}
  • icGREP/icgrep-devel/icgrep/pablo/passes/flattenif.cpp

    r5032 r5202  
    11#include <pablo/passes/flattenif.hpp>
    22#include <pablo/codegenstate.h>
    3 #include <pablo/expression_map.hpp>
    4 #include <pablo/function.h>
    5 #include <pablo/printer_pablos.h>
    63#include <pablo/analysis/pabloverifier.hpp>
    7 #include <boost/container/flat_set.hpp>
    8 
    9 #include <pablo/printer_pablos.h>
    10 #include <iostream>
    114
    125namespace pablo {
    136   
    14 bool has_if(PabloBlock * const block){
     7void FlattenIf::flattenIf(PabloBlock * const block) {
    158    Statement * stmt = block->front();
    16     int if_flag = false;
    17     while(stmt){
    18         if (isa<If>(stmt)){
    19             if_flag = true;
    20             return if_flag;
    21         }
    22         stmt = stmt->getNextNode();
    23     }
    24     return if_flag;
    25 }
    26 
    27 void flattenIf_helper(PabloBlock * const block){
    28     Statement * stmt = block->front();
    29     /*std::string tmp;
    30      llvm::raw_string_ostream msg(tmp);
    31      msg << "stmt: ";
    32      PabloPrinter::print(stmt, msg);*/
    33     while(stmt){
    34         if (If * ifNode = dyn_cast<If>(stmt)){
    35             Statement * prior = stmt->getPrevNode();
    36             PabloBlock * body = ifNode->getBody();
    37             //Simplifier::flattenIf(body);
    38             Statement * body_stmt = body->front();
    39             Statement * next;
    40             while(body_stmt){
    41                 next = body_stmt->getNextNode();
    42                 if (isa<Assign>(body_stmt)) {
    43                     ifNode->removeDefined(cast<Assign>(body_stmt));
    44                 }
     9    while (stmt) {
     10        if (LLVM_UNLIKELY(isa<If>(stmt))) {
     11            Statement * prior = stmt;
     12            Statement * const initial = cast<If>(stmt)->getBody()->front();
     13            Statement * body_stmt = initial;
     14            while (body_stmt) {
     15                assert (body_stmt->getPrevNode() == nullptr);
     16                Statement * const next = body_stmt->getNextNode();
    4517                body_stmt->insertAfter(prior);
     18                assert (body_stmt->getPrevNode() == prior);
    4619                prior = body_stmt;
    4720                body_stmt = next;
    4821            }
    49             stmt = stmt->eraseFromParent();
    50            
     22            stmt = stmt->eraseFromParent(true);
     23            assert (stmt == initial);
     24        } else {
     25            stmt = stmt->getNextNode();
    5126        }
    52         stmt = stmt->getNextNode();
    53     }
    54 }
    55 
    56 void FlattenIf::flattenIf(PabloBlock * const block){
    57     bool flag = has_if(block);
    58     while(flag){
    59         flattenIf_helper(block);
    60         flag = has_if(block);
    6127    }
    6228}
  • icGREP/icgrep-devel/icgrep/pablo/passes/flattenif.hpp

    r5032 r5202  
    11#ifndef FLATTENIF_H
    22#define FLATTENIF_H
    3 #include <pablo/codegenstate.h>
    43
    54namespace pablo {
     
    76class PabloFunction;
    87class PabloBlock;
    9 class Statement;
    10 class PabloAST;
    118
    129class FlattenIf {
    13     friend class DistributivePass;
    14     friend class FactorizeDFG;
    1510public:
    1611    static void transform(PabloFunction & function);
Note: See TracChangeset for help on using the changeset viewer.