Changeset 5775


Ignore:
Timestamp:
Dec 11, 2017, 7:24:31 AM (18 months ago)
Author:
cameron
Message:

makeAlt should combine CCs as advertised, but should not recursively flatten

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/re/re_alt.h

    r5736 r5775  
    99
    1010#include "re_re.h"
     11#include "re_cc.h"
    1112#include <llvm/Support/Casting.h>
    1213
     
    3233
    3334    }
    34 private:
    35     template<typename iterator>
    36     void flatten(iterator begin, iterator end) {
    37         for (auto i = begin; i != end; ++i) {
    38             if (LLVM_UNLIKELY(llvm::isa<Alt>(*i))) {
    39                 flatten<Alt::iterator>(llvm::cast<Alt>(*i)->begin(), llvm::cast<Alt>(*i)->end());
    40             } else {
    41                 push_back(*i);
    42             }
    43         }
    44     }
    4535};
    4636
     
    6151template<typename iterator>
    6252RE * makeAlt(iterator begin, iterator end) {
    63     if (LLVM_UNLIKELY(std::distance(begin, end) == 0)) {
    64         return makeAlt();
    65     } else {
    66         Alt * alt = makeAlt();
    67         alt->flatten(begin, end);
    68         if (alt->size() == 1) {
    69             return alt->front();
     53    Alt * newAlt = makeAlt();
     54    CC * unionCC = makeCC();
     55    for (auto i = begin; i != end; ++i) {
     56        if (const CC * cc = llvm::dyn_cast<CC>(*i)) {
     57            unionCC = makeCC(unionCC, cc);
     58        } else if (const Alt * alt = llvm::dyn_cast<Alt>(*i)) {
     59            // We have an Alt to embed within the alt.  We extract the individual
     60            // elements to include within the new alt.   Note that recursive flattening
     61            // is not required, if the elements themselves were created with makeAlt.
     62            for (RE * a : *alt) {
     63                if (CC * cc = llvm::dyn_cast<CC>(a)) {
     64                    unionCC = makeCC(unionCC, cc);
     65                }
     66                else newAlt->push_back(a);
     67            }
    7068        }
    71         return alt;
     69        else {
     70            newAlt->push_back(*i);
     71        }
    7272    }
     73    if (!unionCC->empty()) newAlt->push_back(unionCC);
     74    return newAlt;
    7375}
    7476
Note: See TracChangeset for help on using the changeset viewer.