Changeset 5817


Ignore:
Timestamp:
Dec 31, 2017, 7:46:49 PM (11 months ago)
Author:
cameron
Message:

Toolchain restructuring; creating a total order for memoizer lessThan

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

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/grep_engine.cpp

    r5816 r5817  
    130130//#define USE_MULTIPLEX_CC
    131131#ifdef USE_MULTIPLEX_CC
    132         REs[i] = multiplexing_prepasses(REs[i]);
     132        REs[i] = regular_expression_passes(REs[i]);
    133133        const std::vector<const re::CC *> UnicodeSets = re::collectUnicodeSets(REs[i]);
    134134        if (UnicodeSets.size() <= 1) {
  • icGREP/icgrep-devel/icgrep/re/re_memoizer.cpp

    r5765 r5817  
    2727        if (compare(*i, *j)) {
    2828            return true;
     29        } else if (compare(*j, *i)) {
     30            return false;
    2931        }
    3032    }
    3133    return false;
     34}
     35
     36inline bool lessThan(const Name * const lh, const Name * const rh) {
     37    if (lh->getType() != rh->getType()) {
     38        return lh->getType() < rh->getType();
     39    } else if (lh->hasNamespace() != rh->hasNamespace()) {
     40        return lh->hasNamespace();
     41    } else if (lh->hasNamespace() && (lh->getNamespace() != rh->getNamespace())) {
     42        return lh->getNamespace() < rh->getNamespace();
     43    } else if (lh->getName() != rh->getName()) {
     44        return lh->getName() < rh->getName();
     45    } else if (lh->getDefinition() == nullptr) {
     46        return rh->getDefinition() != nullptr;
     47    } else if (rh->getDefinition() == nullptr) {
     48        return false;
     49    } else {
     50        return compare(lh->getDefinition(), rh->getDefinition());
     51    }
    3252}
    3353
     
    4161    return compare(lh->getAsserted(), rh->getAsserted());
    4262}
    43 
     63   
    4464inline bool lessThan(const Rep * const lh, const Rep * const rh) {
    4565    if (lh->getLB() != rh->getLB()) {
     
    5373
    5474inline bool lessThan(const Diff * const lh, const Diff * const rh) {
    55     return compare(lh->getLH(), rh->getLH()) || compare(lh->getRH(), rh->getRH());
     75    if (compare(lh->getLH(), rh->getLH())) {
     76        return true;
     77    } else if (compare(rh->getLH(), lh->getLH())) {
     78        return false;
     79    } else if (compare(lh->getRH(), rh->getRH())) {
     80        return true;
     81    } else {
     82        return !compare(rh->getRH(), lh->getRH());
     83    }
    5684}
    5785
    5886inline bool lessThan(const Range * const lh, const Range * const rh) {
    59     return compare(lh->getLo(), rh->getLo()) || compare(lh->getHi(), rh->getHi());
     87    if (compare(lh->getLo(), rh->getLo())) {
     88        return true;
     89    } else if (compare(rh->getLo(), lh->getLo())) {
     90        return false;
     91    } else if (compare(lh->getHi(), rh->getHi())) {
     92        return true;
     93    } else {
     94        return !compare(rh->getHi(), lh->getHi());
     95    }
    6096}
    6197
    6298static bool lessThan(const Intersect * const lh, const Intersect * const rh) {
    63     return compare(lh->getLH(), rh->getLH()) || compare(lh->getRH(), rh->getRH());
     99    if (compare(lh->getLH(), rh->getLH())) {
     100        return true;
     101    } else if (compare(rh->getLH(), lh->getLH())) {
     102        return false;
     103    } else if (compare(lh->getRH(), rh->getRH())) {
     104        return true;
     105    } else {
     106        return !compare(rh->getRH(), lh->getRH());
     107    }
    64108}
    65109
     
    80124    const auto typeR = rh->getClassTypeId();
    81125    if (LLVM_LIKELY(typeL != typeR)) {
    82         if ((typeL == Type::CC || typeR == Type::CC) && (typeL == Type::Name || typeR == Type::Name)) {
    83             if (typeL == Type::Name) {
    84                 return *cast<Name>(lh) < *cast<CC>(rh);
    85             } else {
    86                 return *cast<Name>(rh) > *cast<CC>(lh);
    87             }
    88         }
    89126        return typeL < typeR;
    90127    }
     
    100137            return *cast<CC>(lh) < *cast<CC>(rh);
    101138        case Type::Name:
    102             return *cast<Name>(lh) < *cast<Name>(rh);
     139            return lessThan(cast<Name>(lh), cast<Name>(rh));
    103140        case Type::Group:
    104141            return lessThan(cast<Group>(lh), cast<Group>(rh));
  • icGREP/icgrep-devel/icgrep/re/re_toolchain.cpp

    r5816 r5817  
    6262
    6363RE * resolveModesAndExternalSymbols(RE * r) {
     64    if (PrintOptions.isSet(ShowAllREs) || PrintOptions.isSet(ShowREs)) {
     65        errs() << "Parser:\n" << Printer_RE::PrintRE(r) << '\n';
     66    }
    6467    r = resolveGraphemeMode(r, false /* not in grapheme mode at top level*/);
    6568    if (PrintOptions.isSet(ShowAllREs)) {
     
    8588}
    8689
    87 RE * multiplexing_prepasses(RE * r) {
     90RE * regular_expression_passes(RE * r) {
    8891    std::vector<re::CC *> charclasses;
    89     if (PrintOptions.isSet(ShowAllREs) || PrintOptions.isSet(ShowREs)) {
    90         errs() << "Parser:\n" << Printer_RE::PrintRE(r) << '\n';
    91     }
    9292    //Optimization passes to simplify the AST.
    9393    r = RE_Nullable::removeNullablePrefix(r);
     
    116116    return r;
    117117}
    118 
    119 RE * regular_expression_passes(RE * r)  {
    120 
    121     if (PrintOptions.isSet(ShowAllREs) || PrintOptions.isSet(ShowREs)) {
    122         errs() << "Parser:\n" << Printer_RE::PrintRE(r) << '\n';
    123     }
    124 
    125     //Optimization passes to simplify the AST.
    126     r = RE_Nullable::removeNullablePrefix(r);
    127     if (PrintOptions.isSet(ShowAllREs) || PrintOptions.isSet(ShowStrippedREs)) {
    128         errs() << "RemoveNullablePrefix:\n" << Printer_RE::PrintRE(r) << '\n';
    129     }
    130     r = RE_Nullable::removeNullableSuffix(r);
    131     if (PrintOptions.isSet(ShowAllREs) || PrintOptions.isSet(ShowStrippedREs)) {
    132         errs() << "RemoveNullableSuffix:\n" << Printer_RE::PrintRE(r) << '\n';
    133     }
    134     r = RE_Simplifier::simplify(r);
    135 
    136     if (PrintOptions.isSet(ShowAllREs) || PrintOptions.isSet(ShowSimplifiedREs)) {
    137         //Print to the terminal the AST that was generated by the simplifier.
    138         errs() << "Simplifier:\n" << Printer_RE::PrintRE(r) << '\n';
    139     }
    140    
    141 //    r = RE_Minimizer::minimize(r);
    142 
    143 //    if (PrintOptions.isSet(ShowAllREs) || PrintOptions.isSet(ShowSimplifiedREs)) {
    144 //        //Print to the terminal the AST that was generated by the simplifier.
    145 //        errs() << "Minimizer:\n" << Printer_RE::PrintRE(r) << '\n';
    146 //    }
    147 
    148     r = RE_Star_Normal::star_normal(r);
    149 
    150     if (PrintOptions.isSet(ShowAllREs) || PrintOptions.isSet(ShowSimplifiedREs)) {
    151         //Print to the terminal the AST that was transformed to the star normal form.
    152         errs() << "Star_Normal_Form:\n" << Printer_RE::PrintRE(r) << '\n';
    153     }
    154 
    155     return r;
    156118}
    157    
    158 PabloAST * re2pablo_compiler(PabloKernel * kernel, RE * re_ast) {
    159     Var * const basis = kernel->getInputStreamVar("basis");
    160     cc::CC_Compiler cc_compiler(kernel, basis);
    161     RE_Compiler re_compiler(kernel, cc_compiler);
    162     return re_compiler.compile(re_ast);
    163 }
    164 
    165 }
  • icGREP/icgrep-devel/icgrep/re/re_toolchain.h

    r5803 r5817  
    3535
    3636RE * regular_expression_passes(RE * r);
    37 
    38 RE * multiplexing_prepasses(RE * r);
    39 
    40 pablo::PabloAST * re2pablo_compiler(pablo::PabloKernel * kernel, RE * re_ast);
    4137   
    4238}
Note: See TracChangeset for help on using the changeset viewer.