Changeset 4234


Ignore:
Timestamp:
Oct 14, 2014, 1:17:26 PM (5 years ago)
Author:
nmedfort
Message:

Restored Assign and Var objects that were removed in r4212. Ought to fix performance of Tom_near_river (and others).

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

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/cc/cc_compiler.cpp

    r4220 r4234  
    5555        if (Seq * seq = dyn_cast<Seq>(i->second)) {
    5656            if (seq->getType() == Seq::Type::Byte) {
    57                 PabloE * marker = nullptr;
     57                Assign * assignment = nullptr;
    5858                auto j = seq->begin();
    5959                while (true) {
     
    6161                    assert (name);
    6262                    CharClass * cc = mCG.createCharClass(name->getName());
    63                     PabloE * sym = marker ? mCG.createAnd(marker, cc) : cc;
     63                    PabloE * sym = assignment ? mCG.createAnd(mCG.createVar(assignment->getName()), cc) : cc;
    6464                    if (++j != seq->end()) {
    65                         marker = mCG.createAdvance(sym);
     65                        assignment = mCG.createAssign(mCG.ssa("marker"), mCG.createAdvance(sym));
    6666                        continue;
    6767                    }
     
    9595inline void CC_Compiler::process(const CC * cc) {
    9696    if (mComputedSet.insert(cc->getName()).second) {
    97         //Add the new mapping to the list of pablo statements:
     97        // Add the new mapping to the list of pablo statements:
    9898        mCG.createAssign(cc->getName(), charset_expr(cc));
    9999    }
     
    148148}
    149149
    150 PabloE* CC_Compiler::char_test_expr(const CodePointType ch)
     150PabloE * CC_Compiler::char_test_expr(const CodePointType ch)
    151151{
    152152    return bit_pattern_expr(ch, mEncoding.getMask());
    153153}
    154154
    155 PabloE* CC_Compiler::make_range(const CodePointType n1, const CodePointType n2)
     155PabloE * CC_Compiler::make_range(const CodePointType n1, const CodePointType n2)
    156156{
    157157    CodePointType diff_count = 0;
     
    231231}
    232232
    233 PabloE* CC_Compiler::charset_expr(const CC * cc) {
     233inline PabloE * CC_Compiler::charset_expr(const CC * cc) {
    234234    if (cc->empty()) {
    235235        return mCG.createAll(0);
  • icGREP/icgrep-devel/icgrep/cc/cc_compiler.h

    r4220 r4234  
    1212#include <pablo/pe_pabloe.h>
    1313#include <re/re_cc.h>
     14#include <unordered_map>
    1415#include <string>
    1516#include <set>
     
    4243    void process(const re::CC *cc);
    4344
    44     pablo::PabloBlock &         mCG;
    45     std::vector<pablo::Var *>   mBasisBit;
    46     const Encoding              mEncoding;
    47     const std::string           mGenSymPattern;
    48     const std::string           mBasisPattern;
    49     ComputedSet                 mComputedSet;
     45    pablo::PabloBlock &                                 mCG;
     46    std::vector<pablo::Var *>                           mBasisBit;
     47    const Encoding                                      mEncoding;
     48    const std::string                                   mGenSymPattern;
     49    const std::string                                   mBasisPattern;
     50    ComputedSet                                         mComputedSet;
    5051};
    5152
  • icGREP/icgrep-devel/icgrep/compiler.cpp

    r4227 r4234  
    5050    {
    5151        std::cerr << "REGEX PARSING FAILURE: " << failure.what() << std::endl;
     52        std::cerr << input_string << std::endl;
    5253        exit(1);
    5354    }
  • icGREP/icgrep-devel/icgrep/llvm_gen.cpp

    r4227 r4234  
    66
    77#include "llvm_gen.h"
    8 //Pablo Expressions
    98#include <pablo/codegenstate.h>
    109#include <stdexcept>
     10
     11// #define DUMP_GENERATED_IR
     12// #define DUMP_OPTIMIZED_IR
    1113
    1214using namespace pablo;
     
    7779, mCarryQueueSize(0)
    7880, mConst_int64_neg1(nullptr)
    79 , mConst_Aggregate_Xi64_0(nullptr)
    80 , mConst_Aggregate_Xi64_neg1(nullptr)
     81, mZeroInitializer(nullptr)
     82, mAllOneInitializer(nullptr)
    8183, mFuncTy_0(nullptr)
    8284, mFunc_process_block(nullptr)
     
    169171
    170172    //Generate the IR instructions for the function.
    171     SetReturnMarker(compileStatements(cg_state.expressions()), 0);
    172     SetReturnMarker(GetMarker(m_name_map.find("LineFeed")->second), 1);
     173    SetReturnMarker(compileStatements(cg_state.expressions()), 0); // matches
     174    SetReturnMarker(GetMarker(m_name_map.find("LineFeed")->second), 1); // line feeds
    173175
    174176    assert (mCarryQueueIdx == mCarryQueueSize);
     
    235237    //Constant definitions.
    236238    mConst_int64_neg1 = ConstantInt::get(mMod->getContext(), APInt(64, -1));
    237     mConst_Aggregate_Xi64_0 = ConstantAggregateZero::get(mXi64Vect);
     239    mZeroInitializer = ConstantAggregateZero::get(mXi64Vect);
    238240
    239241    std::vector<Constant*> const_packed_27_elems;
     
    241243        const_packed_27_elems.push_back(mConst_int64_neg1);
    242244    }
    243     mConst_Aggregate_Xi64_neg1 = ConstantVector::get(const_packed_27_elems);
     245    mAllOneInitializer = ConstantVector::get(const_packed_27_elems);
    244246
    245247
     
    492494    if (itr == mMarkerMap.end()) {
    493495        Value* ptr = b.CreateAlloca(mXi64Vect);
    494         b.CreateStore(mConst_Aggregate_Xi64_0, ptr);
     496        b.CreateStore(mZeroInitializer, ptr);
    495497        itr = mMarkerMap.insert(make_pair(name, ptr)).first;
    496498    }
     
    587589
    588590        BasicBlock*  whileCondBlock = BasicBlock::Create(mMod->getContext(), "while.cond", mFunc_process_block, 0);
    589         BasicBlock*  whileBodyBlock = BasicBlock::Create(mMod->getContext(), "while.body",mFunc_process_block, 0);
    590         BasicBlock*  whileEndBlock = BasicBlock::Create(mMod->getContext(), "while.end",mFunc_process_block, 0);
     591        BasicBlock*  whileBodyBlock = BasicBlock::Create(mMod->getContext(), "while.body", mFunc_process_block, 0);
     592        BasicBlock*  whileEndBlock = BasicBlock::Create(mMod->getContext(), "while.end", mFunc_process_block, 0);
    591593
    592594        IRBuilder<> b(mBasicBlock);
     
    609611        Value * ptr_while_carry_q = b_wb1.CreateAlloca(mXi64Vect, b_wb1.getInt64(mCarryQueueSize - idx));
    610612        for (int i = 0; i < (mCarryQueueSize - idx); i++) {
    611             genCarryOutStore(mConst_Aggregate_Xi64_0, ptr_while_carry_q, i);
     613            genCarryOutStore(mZeroInitializer, ptr_while_carry_q, i);
    612614        }
    613615
     
    643645    {
    644646        Value* ptr_all = b.CreateAlloca(mXi64Vect);
    645         b.CreateStore((all->getValue() == 0 ? mConst_Aggregate_Xi64_0 : mConst_Aggregate_Xi64_neg1), ptr_all);
     647        b.CreateStore((all->getValue() == 0 ? mZeroInitializer : mAllOneInitializer), ptr_all);
    646648        retVal = b.CreateLoad(ptr_all);
    647649    }
     
    685687    {
    686688        Value* expr_value = compileExpression(pablo_not->getExpr());
    687         retVal = b.CreateXor(expr_value, mConst_Aggregate_Xi64_neg1, "not");
     689        retVal = b.CreateXor(expr_value, mAllOneInitializer, "not");
    688690    }
    689691    else if (const CharClass * cc = dyn_cast<CharClass>(expr))
     
    820822Value* PabloCompiler::genNot(Value* e, const Twine &namehint) {
    821823    IRBuilder<> b(mBasicBlock);
    822     return b.CreateXor(e, mConst_Aggregate_Xi64_neg1, namehint);
     824    return b.CreateXor(e, mAllOneInitializer, namehint);
    823825}
    824826
  • icGREP/icgrep-devel/icgrep/llvm_gen.h

    r4227 r4234  
    143143
    144144    ConstantInt*                        mConst_int64_neg1;
    145     ConstantAggregateZero*              mConst_Aggregate_Xi64_0;
    146     Constant*                           mConst_Aggregate_Xi64_neg1;
     145    ConstantAggregateZero*              mZeroInitializer;
     146    Constant*                           mAllOneInitializer;
    147147
    148148    FunctionType*                       mFuncTy_0;
  • icGREP/icgrep-devel/icgrep/pablo/codegenstate.cpp

    r4220 r4234  
    4545
    4646Assign * PabloBlock::createAssign(const std::string name, PabloE * expr) {
     47//    auto key = std::make_tuple(PabloE::ClassTypeId::Assign, expr);
     48//    Assign * assign = cast<Assign>(mUnary.find(key));
     49//    if (assign == nullptr) {
     50//        assign = new Assign(mSymbolGenerator[name], expr);
     51//        mUnary.insert(std::move(key), assign);
     52//    }
     53//    else {
     54//        assign = new Assign(mSymbolGenerator[name], createVar(assign));
     55//    }
    4756    Assign * assign = mBinary.findOrMake<Assign>(PabloE::ClassTypeId::Assign, mSymbolGenerator[name], expr);
    4857    mStatements.push_back(assign);
  • icGREP/icgrep-devel/icgrep/pablo/codegenstate.h

    r4227 r4234  
    124124            }
    125125            Type * expr = new Type(args...);
    126             mMap.insert(std::make_pair(std::move(key), expr));
     126            insert(std::move(key), expr);
    127127            return expr;
    128128        }
     
    137137            Functor mf(mCodeGenState);
    138138            PabloE * expr = mf(args...);           
    139             mMap.insert(std::make_pair(std::move(key), expr));
     139            insert(std::move(key), expr);
    140140            return expr;
    141141        }
    142142
    143     private:
     143        inline void insert(Key && key, PabloE * expr) {
     144            mMap.insert(std::make_pair(std::move(key), expr));
     145        }
    144146
    145147        inline PabloE * find(const Key & key) const {
  • icGREP/icgrep-devel/icgrep/re/re_compiler.cpp

    r4220 r4234  
    6767        //#define USE_IF_FOR_NONFINAL
    6868        #ifdef USE_IF_FOR_NONFINAL
    69         cg.createAssign(gs_nonfinal, make_all(0));
     69        cg.createAssign(gs_nonfinal, cg.createAll(0));
    7070        #endif
    7171        PabloE * u8scope32 = cg.createAdvance(u8pfx3);
     
    7373        PabloE * u8scope43 = cg.createAdvance(u8scope42);
    7474        #ifdef USE_IF_FOR_NONFINAL
    75         CodeGenState it(cg);
     75        PabloBlock it(cg);
    7676        it.createAssign(gs_nonfinal, it.createOr(it.createOr(u8pfx, u8scope32), it.createOr(u8scope42, u8scope43)));
    7777        cg.createIf(u8pfx, std::move(it));
    78         #else
     78        #else       
    7979        cg.createAssign(gs_nonfinal, cg.createOr(cg.createOr(u8pfx, u8scope32), cg.createOr(u8scope42, u8scope43)));
    8080        #endif
    8181    }
    8282
    83     PabloE * start_marker = cg.createAll(1);
     83    Assign * start_marker = cg.createAssign("start", cg.createAll(1));
    8484    PabloE * result = process(re, start_marker, cg);
    8585
     
    9090
    9191
    92 PabloE * RE_Compiler::process(RE * re, PabloE * target, PabloBlock & cg) {
     92Assign * RE_Compiler::process(RE * re, Assign * target, PabloBlock & cg) {
    9393    if (Name * name = dyn_cast<Name>(re)) {
    9494        target = process(name, target, cg);
     
    104104    }
    105105    else if (isa<Start>(re)) {
    106         target = cg.createAnd(cg.createVarIfAssign(target), cg.createNot(cg.createAdvance(cg.createNot(cg.createCharClass(m_name_map.find("LineFeed")->second)))));
     106        PabloE * sol = cg.createNot(cg.createAdvance(cg.createNot(cg.createCharClass(m_name_map.find("LineFeed")->second))));
     107        target = cg.createAssign(cg.ssa("sol"), cg.createAnd(cg.createVarIfAssign(target), sol));
    107108    }
    108109    else if (isa<End>(re)) {
    109         target = cg.createAnd(cg.createVarIfAssign(target), cg.createCharClass(m_name_map.find("LineFeed")->second));
    110     }
    111 
    112     return target;
    113 }
    114 
    115 inline PabloE * RE_Compiler::process(Name * name, PabloE * target, PabloBlock & cg) {
    116     PabloE * markerExpr = cg.createVarIfAssign(target);
     110        PabloE * eol = cg.createCharClass(m_name_map.find("LineFeed")->second);
     111        target = cg.createAssign(cg.ssa("eol"), cg.createAnd(cg.createVarIfAssign(target), eol));
     112    }
     113
     114    return target;
     115}
     116
     117inline Assign * RE_Compiler::process(Name * name, Assign * target, PabloBlock & cg) {
     118    PabloE * marker = cg.createVar(target);
    117119    if (name->getType() != Name::Type::FixedLength) {
    118120        // Move the markers forward through any nonfinal UTF-8 bytes to the final position of each character.
    119         markerExpr = cg.createAnd(markerExpr, cg.createCharClass(m_name_map.find("initial")->second));
    120         markerExpr = cg.createScanThru(markerExpr, cg.createCharClass(m_name_map.find("nonfinal")->second));
     121        marker = cg.createAnd(marker, cg.createCharClass(m_name_map.find("initial")->second));
     122        marker = cg.createScanThru(marker, cg.createCharClass(m_name_map.find("nonfinal")->second));
    121123    }
    122124    PabloE * cc = nullptr;
     
    131133                                cg.createCharClass(m_name_map.find("nonfinal")->second)));
    132134    }
    133     return cg.createAssign(cg.ssa("marker"), cg.createAdvance(cg.createAnd(cc, markerExpr)));
    134 }
    135 
    136 inline PabloE * RE_Compiler::process(Seq * seq, PabloE * target, PabloBlock & cg) {
     135    return cg.createAssign(cg.ssa("marker"), cg.createAdvance(cg.createAnd(cc, marker)));
     136}
     137
     138inline Assign * RE_Compiler::process(Seq * seq, Assign *target, PabloBlock & cg) {
    137139    for (RE * re : *seq) {
    138140        target = process(re, target, cg);
     
    141143}
    142144
    143 inline PabloE * RE_Compiler::process(Alt * alt, PabloE * target, PabloBlock & cg) {
     145inline Assign * RE_Compiler::process(Alt * alt, Assign * target, PabloBlock & cg) {
    144146    if (alt->empty()) {
    145         target = cg.createAll(0); // always fail (note: I'm not sure this ever occurs. How do I create a 0-element alternation?)
     147        target = cg.createAssign(cg.ssa("fail"), cg.createAll(0)); // always fail (note: I'm not sure this ever occurs. How do I create a 0-element alternation?)
    146148    }
    147149    else {
    148150        auto i = alt->begin();
    149         PabloE * const base = target;
    150         target = cg.createVarIfAssign(process(*i, target, cg));
     151        Assign * const base = target;
     152        target = process(*i, base, cg);
    151153        while (++i != alt->end()) {
    152             PabloE * other = cg.createVarIfAssign(process(*i, base, cg));
    153             target = cg.createOr(target, other);
     154            Assign * other = process(*i, base, cg);
     155            target = cg.createAssign(cg.ssa("alt"), cg.createOr(cg.createVar(target), cg.createVar(other)));
    154156        }
    155157    }   
     
    157159}
    158160
    159 inline PabloE * RE_Compiler::process(Rep * rep, PabloE * target, PabloBlock & cg) {
     161inline Assign * RE_Compiler::process(Rep * rep, Assign * target, PabloBlock & cg) {
    160162    if (rep->getUB() == Rep::UNBOUNDED_REP) {
    161163        target = processUnboundedRep(rep->getRE(), rep->getLB(), target, cg);
     
    167169}
    168170
    169 inline PabloE * RE_Compiler::processUnboundedRep(RE * repeated, int lb, PabloE * target, PabloBlock & cg) {
     171inline Assign * RE_Compiler::processUnboundedRep(RE * repeated, int lb, Assign * target, PabloBlock & cg) {
    170172    while (lb-- != 0) {
    171173        target = process(repeated, target, cg);
    172174    }
    173 
    174     target = cg.createVarIfAssign(target);
    175175
    176176    if (isa<Name>(repeated)) {
     
    189189        }
    190190
     191        PabloE * unbounded = cg.createVar(target);
    191192        if (rep_name->getType() == Name::Type::FixedLength) {
    192             target = cg.createMatchStar(target, ccExpr);
     193            unbounded = cg.createMatchStar(unbounded, ccExpr);
    193194        }
    194195        else { // Name::Unicode and Name::UnicodeCategory
    195             target = cg.createAnd(cg.createMatchStar(target, cg.createOr(cg.createCharClass(m_name_map.find("nonfinal")->second), ccExpr)), cg.createCharClass(m_name_map.find("initial")->second));
    196         }
     196            unbounded = cg.createAnd(cg.createMatchStar(unbounded, cg.createOr(cg.createCharClass(m_name_map.find("nonfinal")->second), ccExpr)), cg.createCharClass(m_name_map.find("initial")->second));
     197        }
     198        target = cg.createAssign(cg.ssa("marker"), unbounded);
    197199    }
    198200    else {
     
    211213}
    212214
    213 inline PabloE * RE_Compiler::processBoundedRep(RE * repeated, int lb, int ub, PabloE * target, PabloBlock & cg) {
     215inline Assign * RE_Compiler::processBoundedRep(RE * repeated, int lb, int ub, Assign * target, PabloBlock & cg) {
    214216    ub -= lb;
    215217    while(lb-- != 0) {
     
    217219    }
    218220    while (ub-- != 0) {
    219         PabloE * alt = process(repeated, target, cg);
    220         target = cg.createOr(cg.createVarIfAssign(target), cg.createVarIfAssign(alt));
     221        Assign * alt = process(repeated, target, cg);
     222        target = cg.createAssign(cg.ssa("alt"), cg.createOr(cg.createVar(target), cg.createVar(alt)));
    221223    }
    222224    return target;
  • icGREP/icgrep-devel/icgrep/re/re_compiler.h

    r4220 r4234  
    88#define RE_TO_PABLO_COMPILER_H
    99
    10 #include <pablo/codegenstate.h>
    1110#include <re/re_re.h>
    1211
     
    1413#include <list>
    1514#include <map>
     15
     16namespace pablo {
     17
     18class PabloBlock;
     19class Assign;
     20class Var;
     21
     22}
    1623
    1724namespace re {
     
    2936    void compile(RE * re, pablo::PabloBlock & cg);
    3037
    31     pablo::PabloE * process(RE * re, pablo::PabloE * target, pablo::PabloBlock & cg_state);
    32     pablo::PabloE * process(Alt * alt, pablo::PabloE * target, pablo::PabloBlock & cg_state);
    33     pablo::PabloE * process(Seq * seq, pablo::PabloE * target, pablo::PabloBlock & cg_state);
    34     pablo::PabloE * process(Rep * rep, pablo::PabloE * target, pablo::PabloBlock & cg_state);
    35     pablo::PabloE * processUnboundedRep(RE * repeated, int lb, pablo::PabloE * target, pablo::PabloBlock & cg_state);
    36     pablo::PabloE * processBoundedRep(RE * repeated, int lb, int ub, pablo::PabloE * target, pablo::PabloBlock & cg_state);
    37     pablo::PabloE * process(Name * name, pablo::PabloE * target, pablo::PabloBlock & cg_state);
     38    pablo::Assign * process(RE * re, pablo::Assign *target, pablo::PabloBlock & cg_state);
     39    pablo::Assign * process(Name * name, pablo::Assign * target, pablo::PabloBlock & cg_state);
     40    pablo::Assign * process(Seq * seq, pablo::Assign * target, pablo::PabloBlock & cg_state);
     41    pablo::Assign * process(Alt * alt, pablo::Assign * target, pablo::PabloBlock & cg_state);
     42    pablo::Assign * process(Rep * rep, pablo::Assign *target, pablo::PabloBlock & cg_state);
     43    pablo::Assign * processUnboundedRep(RE * repeated, int lb, pablo::Assign * target, pablo::PabloBlock & cg_state);
     44    pablo::Assign * processBoundedRep(RE * repeated, int lb, int ub, pablo::Assign * target, pablo::PabloBlock & cg_state);
     45
    3846
    3947    static bool hasUnicode(const RE *re);
    4048
    41     pablo::PabloBlock &                      mCG;
    42     std::map<std::string, std::string>  m_name_map;
     49    pablo::PabloBlock &                             mCG;
     50    std::map<std::string, std::string>              m_name_map;
    4351};
    4452
  • icGREP/icgrep-devel/icgrep/re/re_parser.cpp

    r4229 r4234  
    354354            case '.': case '?': case '[': case '\\':
    355355            case ']': case '{': case '|': case '}':
     356            case '-':
    356357                if (_allow_escapes_within_charset) {
    357358                    literal = *_cursor++;
Note: See TracChangeset for help on using the changeset viewer.