Ignore:
Timestamp:
Sep 7, 2017, 4:56:56 PM (22 months ago)
Author:
nmedfort
Message:

Partial check-in for avoidance of compiling Pablo/LLVM code to determine the Kernel struct type when using a cached object. Inactive RE alternation minimization check in.

Location:
icGREP/icgrep-devel/icgrep/re
Files:
3 added
7 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/re/re_memoizer.hpp

    r5267 r5630  
    1 #ifndef RE_NAMEDICTIONARY_H
    2 #define RE_NAMEDICTIONARY_H
     1#ifndef RE_MEMOIZER_H
     2#define RE_MEMOIZER_H
    33
    44#include <re/re_name.h>
     
    88
    99struct MemoizerComparator {
    10     inline bool operator() (const RE * lh, const RE * rh) const{
    11         if (LLVM_LIKELY(llvm::isa<Name>(lh) && llvm::isa<Name>(rh))) {
    12             return *llvm::cast<Name>(lh) < *llvm::cast<Name>(rh);
    13         } else if (llvm::isa<Name>(lh)) {
    14             return *llvm::cast<Name>(lh) < *llvm::cast<CC>(rh);
    15         }
    16         return *llvm::cast<Name>(rh) > *llvm::cast<CC>(lh);
    17     }
     10    bool operator() (const RE * lh, const RE * rh) const;
    1811};
    1912
    2013struct Memoizer : public std::set<RE *, MemoizerComparator> {
    2114
    22     inline Name * memoize(CC * cc) {
     15    RE * memoize(RE * const re) {
     16        return *(insert(re).first);
     17    }
     18
     19    Name * memoize(Name * const name) {
     20        return llvm::cast<Name>(memoize(llvm::cast<RE>(name)));
     21    }
     22
     23    Name * memoize(CC * const cc) {
    2324        auto f = find(cc);
    2425        if (f != end()) {
    2526            return llvm::cast<Name>(*f);
    2627        } else {
    27             Name * name = makeName(cc);
    28             insert(name);
    29             return name;
     28            return memoize(makeName(cc));
    3029        }
    31     }
    32 
    33     inline Name * memoize(Name * name) {
    34         return llvm::cast<Name>(*insert(name).first);
    3530    }
    3631};
     
    3833}
    3934
    40 #endif // RE_NAMEDICTIONARY_H
     35#endif // RE_MEMOIZER_H
  • icGREP/icgrep-devel/icgrep/re/re_name.h

    r5558 r5630  
    127127        return *llvm::cast<CC>(mDefinition) < other;
    128128    }
    129     return false;
     129    return RE::ClassTypeId::Name < RE::ClassTypeId::CC;
    130130}
    131131
     
    134134        return other < *llvm::cast<CC>(mDefinition);
    135135    }
    136     return true;
     136    return RE::ClassTypeId::CC < RE::ClassTypeId::Name;
    137137}
    138138
  • icGREP/icgrep-devel/icgrep/re/re_parser.cpp

    r5620 r5630  
    149149    RE * re = nullptr;
    150150    if (fModeFlagSet & IGNORE_SPACE_MODE_FLAG) {
    151         while (*mCursor == ' ') mCursor++;
     151        while (mCursor.more() && *mCursor == ' ') {
     152            ++mCursor;
     153        }
    152154    }
    153155    if (mCursor.more()) {
     
    190192                    re = makeSeq({re, makeZeroWidth("GCB")});
    191193                }
    192                 return re;
     194                break;
    193195            case '.': // the 'any' metacharacter
    194196                mCursor++;
     
    202204                    fGraphemeBoundaryPending = true;
    203205                }
    204                 return re;
    205         }
    206     }
    207     return nullptr;
     206        }
     207    }
     208    return re;
    208209}
    209210
  • icGREP/icgrep-devel/icgrep/re/re_re.h

    r5267 r5630  
    2626        , Intersect
    2727        , Name
    28         , Permute
     28        // , Permute
    2929        , Rep
    3030        , Seq
    3131        , Start
    32         , SymDiff
    33         , Union
     32        // , SymDiff
     33        // , Union
    3434    };
    3535    inline ClassTypeId getClassTypeId() const {
     
    5252class Vector : public RE, public std::vector<RE*, RE::VectorAllocator> {
    5353public:
     54    static inline bool classof(const RE * re) {
     55        const auto typeId = re->getClassTypeId();
     56        return typeId == ClassTypeId::Alt || typeId == ClassTypeId::Seq;
     57    }
     58    static inline bool classof(const void *) {
     59        return false;
     60    }
    5461    virtual ~Vector() {}
    5562protected:
  • icGREP/icgrep-devel/icgrep/re/re_reverse.cpp

    r5493 r5630  
    5656    } else if (Name * n = dyn_cast<Name>(re)) {
    5757        switch (n->getType()) {
    58             case Name::Type::Byte:  return makeName(cast<CC>(n->getDefinition()));
    59             case Name::Type::Unicode:  return makeName(cast<CC>(n->getDefinition()));
     58            case Name::Type::Byte:
     59            case Name::Type::Unicode:
     60                return makeName(cast<CC>(n->getDefinition()));
    6061            case Name::Type::UnicodeProperty:
    6162                return makeName(n->getNamespace(), n->getName(), Name::Type::UnicodeProperty);
  • icGREP/icgrep-devel/icgrep/re/re_simplifier.cpp

    r5493 r5630  
    11#include "re_simplifier.h"
    22#include <re/re_name.h>
    3 #include <re/re_any.h>
    4 #include <re/re_start.h>
    5 #include <re/re_end.h>
    63#include <re/re_alt.h>
    7 #include <re/re_cc.h>
    84#include <re/re_seq.h>
    95#include <re/re_rep.h>
     
    117#include <re/re_intersect.h>
    128#include <re/re_assertion.h>
    13 #include <re/re_analysis.h>
    14 #include <algorithm>
    15 #include <memory>
    16 #include <queue>
     9#include <re/re_memoizer.hpp>
     10#include <boost/container/flat_set.hpp>
    1711
    1812using namespace llvm;
     
    2014namespace re {
    2115
     16struct PassContainer {
     17    RE * simplify(RE * re) {
     18        if (Alt * alt = dyn_cast<Alt>(re)) {
     19            boost::container::flat_set<RE *> list;
     20            list.reserve(alt->size());
     21            for (RE * item : *alt) {
     22                item = simplify(item);
     23                if (LLVM_UNLIKELY(isa<Vector>(item) && cast<Vector>(item)->empty())) {
     24                    continue;
     25                }
     26                list.insert(item);
     27            }
     28            re = makeAlt(list.begin(), list.end());
     29        } else if (Seq * seq = dyn_cast<Seq>(re)) {
     30            std::vector<RE *> list;
     31            list.reserve(seq->size());
     32            for (RE * item : *seq) {
     33                item = simplify(item);
     34                if (LLVM_UNLIKELY(isa<Vector>(item) && cast<Vector>(item)->empty())) {
     35                    continue;
     36                }
     37                list.push_back(item);
     38            }
     39            re = makeSeq(list.begin(), list.end());
     40        } else if (Assertion * a = dyn_cast<Assertion>(re)) {
     41            re = makeAssertion(simplify(a->getAsserted()), a->getKind(), a->getSense());
     42        } else if (Rep * rep = dyn_cast<Rep>(re)) {
     43            RE * expr = simplify(rep->getRE());
     44            re = makeRep(expr, rep->getLB(), rep->getUB());
     45        } else if (Diff * diff = dyn_cast<Diff>(re)) {
     46            re = makeDiff(simplify(diff->getLH()), simplify(diff->getRH()));
     47        } else if (Intersect * e = dyn_cast<Intersect>(re)) {
     48            re = makeIntersect(simplify(e->getLH()), simplify(e->getRH()));
     49        }
     50        return mMemoizer.memoize(re);
     51    }
     52private:
     53    Memoizer mMemoizer;
     54};
     55
    2256RE * RE_Simplifier::simplify(RE * re) {
    23     if (Alt * alt = dyn_cast<Alt>(re)) {
    24         std::vector<RE *> list;
    25         list.reserve(alt->size());
    26         for (RE * re : *alt) {
    27             list.push_back(simplify(re));
    28         }
    29         re = makeAlt(list.begin(), list.end());
    30     } else if (Seq * seq = dyn_cast<Seq>(re)) {
    31         std::vector<RE *> list;
    32         list.reserve(seq->size());
    33         for (RE * re : *seq) {
    34             list.push_back(simplify(re));
    35         }
    36         re = makeSeq(list.begin(), list.end());
    37     } else if (Assertion * a = dyn_cast<Assertion>(re)) {
    38         re = makeAssertion(simplify(a->getAsserted()), a->getKind(), a->getSense());
    39     } else if (Rep * rep = dyn_cast<Rep>(re)) {
    40         RE * expr = simplify(rep->getRE());
    41         re = makeRep(expr, rep->getLB(), rep->getUB());
    42     } else if (Diff * diff = dyn_cast<Diff>(re)) {
    43         re = makeDiff(simplify(diff->getLH()), simplify(diff->getRH()));
    44     } else if (Intersect * e = dyn_cast<Intersect>(re)) {
    45         re = makeIntersect(simplify(e->getLH()), simplify(e->getRH()));
    46     }
    47     return re;
     57    PassContainer pc;
     58    return pc.simplify(re);
    4859}
    4960
  • icGREP/icgrep-devel/icgrep/re/re_toolchain.cpp

    r5620 r5630  
    1212#include <re/re_star_normal.h>         // for RE_Star_Normal
    1313#include <re/re_simplifier.h>          // for RE_Simplifier
     14#include <re/re_minimizer.h>
    1415#include <re/re_local.h>
    1516#include <re/printer_re.h>
     
    6364
    6465    //Optimization passes to simplify the AST.
    65     re_ast = re::RE_Nullable::removeNullablePrefix(re_ast);
     66    re_ast = RE_Nullable::removeNullablePrefix(re_ast);
    6667    if (PrintOptions.isSet(ShowAllREs) || PrintOptions.isSet(ShowStrippedREs)) {
    6768        std::cerr << "RemoveNullablePrefix:" << std::endl << Printer_RE::PrintRE(re_ast) << std::endl;
    6869    }
    69     re_ast = re::RE_Nullable::removeNullableSuffix(re_ast);
     70    re_ast = RE_Nullable::removeNullableSuffix(re_ast);
    7071    if (PrintOptions.isSet(ShowAllREs) || PrintOptions.isSet(ShowStrippedREs)) {
    7172        std::cerr << "RemoveNullableSuffix:" << std::endl << Printer_RE::PrintRE(re_ast) << std::endl;
    7273    }
    73     re_ast = re::RE_Nullable::removeNullableAssertion(re_ast);
     74    re_ast = RE_Nullable::removeNullableAssertion(re_ast);
    7475    if (PrintOptions.isSet(ShowAllREs) || PrintOptions.isSet(ShowStrippedREs)) {
    7576        std::cerr << "RemoveNullableAssertion:" << std::endl << Printer_RE::PrintRE(re_ast) << std::endl;
    7677    }
    77     //re_ast = re::RE_Nullable::removeNullableAfterAssertion(re_ast);
     78    //re_ast = RE_Nullable::removeNullableAfterAssertion(re_ast);
    7879    //if (PrintOptions.isSet(ShowAllREs) || PrintOptions.isSet(ShowStrippedREs)) {
    7980    //    std::cerr << "RemoveNullableAfterAssertion" << std::endl << Printer_RE::PrintRE(re_ast) << std::endl;
    8081    //}
    8182   
    82     re_ast = re::RE_Simplifier::simplify(re_ast);
     83    // re_ast = RE_Minimizer::minimize(re_ast);
     84
     85    re_ast = RE_Simplifier::simplify(re_ast);
     86
    8387    if (PrintOptions.isSet(ShowAllREs) || PrintOptions.isSet(ShowSimplifiedREs)) {
    8488        //Print to the terminal the AST that was generated by the simplifier.
     
    8690    }
    8791
    88     re_ast = re::RE_Star_Normal::star_normal(re_ast);
     92    re_ast = RE_Star_Normal::star_normal(re_ast);
     93
    8994    if (PrintOptions.isSet(ShowAllREs) || PrintOptions.isSet(ShowSimplifiedREs)) {
    9095        //Print to the terminal the AST that was transformed to the star normal form.
    9196        std::cerr << "Star_Normal_Form:" << std::endl << Printer_RE::PrintRE(re_ast) << std::endl;
    9297    }   
     98
    9399    return re_ast;
    94100}
     
    98104    bool local = RE_Local::isLocalLanguage(re_ast) && isTypeForLocal(re_ast);
    99105    cc::CC_Compiler cc_compiler(kernel, basis);
    100     re::RE_Compiler re_compiler(kernel, cc_compiler, local);
     106    RE_Compiler re_compiler(kernel, cc_compiler, local);
    101107    re_compiler.compileUnicodeNames(re_ast);
    102108    re_compiler.compile(re_ast);
Note: See TracChangeset for help on using the changeset viewer.