Ignore:
Timestamp:
Oct 17, 2015, 4:25:05 PM (4 years ago)
Author:
nmedfort
Message:

Update for grapheme cluster mode and boundaries.

Location:
icGREP/icgrep-devel/icgrep/pablo
Files:
3 edited

Legend:

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

    r4835 r4841  
    2222#endif
    2323
     24/** ------------------------------------------------------------------------------------------------------------- *
     25 * @brief optimize
     26 ** ------------------------------------------------------------------------------------------------------------- */
    2427bool Simplifier::optimize(PabloFunction & function) {
    2528    eliminateRedundantCode(function.getEntryBlock());
     
    3235}
    3336
     37/** ------------------------------------------------------------------------------------------------------------- *
     38 * @brief canTriviallyFold
     39 ** ------------------------------------------------------------------------------------------------------------- */
    3440inline static PabloAST * canTriviallyFold(Statement * stmt, PabloBlock & block) {
    3541    for (unsigned i = 0; i != stmt->getNumOperands(); ++i) {
     
    8187}
    8288
     89/** ------------------------------------------------------------------------------------------------------------- *
     90 * @brief isSuperfluous
     91 ** ------------------------------------------------------------------------------------------------------------- */
    8392inline bool Simplifier::isSuperfluous(const Assign * const assign) {
    8493    for (const PabloAST * inst : assign->users()) {
     
    105114}
    106115
     116/** ------------------------------------------------------------------------------------------------------------- *
     117 * @brief demoteDefinedVar
     118 ** ------------------------------------------------------------------------------------------------------------- */
    107119inline bool demoteDefinedVar(const If * ifNode, const Assign * def) {
    108120    // If this value isn't used outside of this scope then there is no reason to allow it to escape it.
     
    121133}
    122134
     135/** ------------------------------------------------------------------------------------------------------------- *
     136 * @brief replaceReachableUsersOfWith
     137 ** ------------------------------------------------------------------------------------------------------------- */
    123138inline void replaceReachableUsersOfWith(Statement * stmt, PabloAST * expr) {
    124139    const PabloBlock * const root = stmt->getParent();
     
    146161}
    147162
     163/** ------------------------------------------------------------------------------------------------------------- *
     164 * @brief discardNestedIfBlock
     165 *
     166 * If this inner block is composed of only Boolean logic and Assign statements and there are fewer than 3
     167 * statements, just add the statements in the inner block to the current block.
     168 ** ------------------------------------------------------------------------------------------------------------- */
     169inline bool discardNestedIfBlock(const PabloBlock & pb) {
     170    unsigned computations = 0;
     171    for (const Statement * stmt : pb) {
     172        switch (stmt->getClassTypeId()) {
     173            case PabloAST::ClassTypeId::And:
     174            case PabloAST::ClassTypeId::Or:
     175            case PabloAST::ClassTypeId::Xor:
     176                if (++computations > 3) {
     177                    return false;
     178                }
     179            case PabloAST::ClassTypeId::Not:
     180            case PabloAST::ClassTypeId::Assign:
     181                break;
     182            default:
     183                return false;
     184        }
     185    }
     186    return true;
     187}
     188
     189/** ------------------------------------------------------------------------------------------------------------- *
     190 * @brief removeIdenticalEscapedValues
     191 ** ------------------------------------------------------------------------------------------------------------- */
    148192template <class ValueList>
    149193inline void removeIdenticalEscapedValues(ValueList & list) {
     
    161205}
    162206
     207/** ------------------------------------------------------------------------------------------------------------- *
     208 * @brief eliminateRedundantCode
     209 ** ------------------------------------------------------------------------------------------------------------- */
    163210void Simplifier::eliminateRedundantCode(PabloBlock & block, ExpressionTable * predecessor) {
    164211    ExpressionTable encountered(predecessor);
     
    211258                continue;
    212259            }
     260
    213261            // Otherwise check if we any Assign reports the same value as another. If so, replace all uses of the
    214262            // second with the first. This will simplify future analysis.
    215263            removeIdenticalEscapedValues(ifNode->getDefined());
     264
     265            // Finally after we've eliminated everything we can from the If body, check whether testing the If
     266            // condition will meet or exceed the cost of executing the body.
     267            if (LLVM_UNLIKELY(discardNestedIfBlock(ifNode->getBody()))) {
     268                Statement * nested = ifNode->getBody().front();
     269                while (nested) {
     270                    Statement * next = nested->removeFromParent();
     271                    nested->insertAfter(stmt);
     272                    stmt = nested;
     273                    nested = next;
     274                }
     275                ifNode->getDefined().clear();
     276                stmt = ifNode->eraseFromParent(true);
     277                continue;
     278            }
    216279
    217280        } else if (While * whileNode = dyn_cast<While>(stmt)) {
     
    244307}
    245308
    246 
     309/** ------------------------------------------------------------------------------------------------------------- *
     310 * @brief deadCodeElimination
     311 ** ------------------------------------------------------------------------------------------------------------- */
    247312void Simplifier::deadCodeElimination(PabloBlock & block) {
    248313    Statement * stmt = block.front();
     
    260325}
    261326
     327/** ------------------------------------------------------------------------------------------------------------- *
     328 * @brief eliminateRedundantEquations
     329 ** ------------------------------------------------------------------------------------------------------------- */
    262330void Simplifier::eliminateRedundantEquations(PabloBlock & block) {
    263331    Statement * stmt = block.front();
  • icGREP/icgrep-devel/icgrep/pablo/pabloAST.h

    r4775 r4841  
    213213        return mName;
    214214    }
     215    inline void setName(const String * const name) {
     216        mName = name;
     217    }
    215218    inline Statement * getNextNode() const {
    216219        return mNext;
     
    239242            }
    240243        }
    241     }
    242     inline void setName(const String * const name) {
    243         mName = name;
    244     }   
     244    } 
    245245#ifndef NDEBUG
    246246    bool noRecursiveOperand(const PabloAST * const operand);
  • icGREP/icgrep-devel/icgrep/pablo/ps_if.h

    r4764 r4841  
    4444        return mDefined;
    4545    }
    46     void addDefined(Assign * def);
    47 protected:
    4846    inline DefinedVars & getDefined() {
    4947        return mDefined;
    5048    }
     49    void addDefined(Assign * def);
     50protected:
    5151    If(PabloAST * expr, const std::initializer_list<Assign *> definedVars, PabloBlock & body);
    52 
    5352    If(PabloAST * expr, const std::vector<Assign *> & definedVars, PabloBlock & body);
    5453private:
Note: See TracChangeset for help on using the changeset viewer.