Changeset 5042 for icGREP/icgrep-devel


Ignore:
Timestamp:
May 19, 2016, 8:50:15 PM (3 years ago)
Author:
cameron
Message:

Add pablo.atEOF; clean out bit4/6 hack for unterminated final lines in icgrep.

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

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/kernels/pipeline.cpp

    r5038 r5042  
    102102    BasicBlock * finalPartialBlock = BasicBlock::Create(mMod->getContext(), "partial", main, 0);
    103103    BasicBlock * finalEmptyBlock = BasicBlock::Create(mMod->getContext(), "empty", main, 0);
    104     BasicBlock * endBlock = BasicBlock::Create(mMod->getContext(), "end", main, 0);
    105     BasicBlock * unterminatedBlock = BasicBlock::Create(mMod->getContext(), "unterminated", main, 0);
    106104    BasicBlock * exitBlock = BasicBlock::Create(mMod->getContext(), "exit", main, 0);
    107105
     
    189187
    190188    iBuilder->SetInsertPoint(finalBlock);
    191     Value * const b4 = s2pInstance->getOutputStream(4);
    192     Value * const b6 = s2pInstance->getOutputStream(6);
    193189    Value * emptyBlockCond = iBuilder->CreateICmpEQ(remainingBytes, ConstantInt::get(int64ty, 0));
    194190    iBuilder->CreateCondBr(emptyBlockCond, finalEmptyBlock, finalPartialBlock);
     
    197193    iBuilder->SetInsertPoint(finalPartialBlock);
    198194    s2pInstance->CreateDoBlockCall();
    199     iBuilder->CreateBr(endBlock);
     195    iBuilder->CreateBr(exitBlock);
    200196
    201197    iBuilder->SetInsertPoint(finalEmptyBlock);
    202198    s2pInstance->clearOutputStreamSet();
    203     iBuilder->CreateBr(endBlock);
    204 
    205     iBuilder->SetInsertPoint(endBlock);
    206     Value * isFinalLineUnterminated = iBuilder->CreateICmpEQ(finalLineUnterminated, ConstantInt::getNullValue(finalLineUnterminated->getType()));
    207     iBuilder->CreateCondBr(isFinalLineUnterminated, exitBlock, unterminatedBlock);
    208    
    209     iBuilder->SetInsertPoint(unterminatedBlock);
     199    iBuilder->CreateBr(exitBlock);
     200
     201    iBuilder->SetInsertPoint(exitBlock);
    210202
    211203    Value * remaining = iBuilder->CreateZExt(remainingBytes, iBuilder->getIntNTy(mBlockSize));
    212     Value * EOF_pos = iBuilder->CreateShl(ConstantInt::get(iBuilder->getIntNTy(mBlockSize), 1), remaining);
    213     EOF_pos = iBuilder->CreateBitCast(EOF_pos, mBitBlockType);
    214     Value * EOF_mask = iBuilder->CreateShl(Constant::getAllOnesValue(iBuilder->getIntNTy(mBlockSize)), remaining);
    215         icGrepInstance->setInternalState("EOFmask", iBuilder->CreateBitCast(EOF_mask, mBitBlockType));
    216 
    217 
    218     Value * b4val = iBuilder->CreateBlockAlignedLoad(b4);
    219     b4val = iBuilder->CreateOr(b4val, EOF_pos);
    220     iBuilder->CreateBlockAlignedStore(b4val, b4);
    221 
    222     Value * b6val = iBuilder->CreateBlockAlignedLoad(b6);
    223     b6val = iBuilder->CreateOr(b6val, EOF_pos);
    224     iBuilder->CreateBlockAlignedStore(b6val, b6);
    225 
    226     iBuilder->CreateBr(exitBlock);
    227 
    228     iBuilder->SetInsertPoint(exitBlock);
     204    Value * EOFmark = iBuilder->CreateShl(ConstantInt::get(iBuilder->getIntNTy(mBlockSize), 1), remaining);
     205        icGrepInstance->setInternalState("EOFmark", iBuilder->CreateBitCast(EOFmark, mBitBlockType));
    229206
    230207    icGrepInstance->CreateDoBlockCall();
  • icGREP/icgrep-devel/icgrep/pablo/builder.cpp

    r5023 r5042  
    171171    return result;
    172172}
    173    
     173
     174PabloAST * PabloBuilder::createAtEOF(PabloAST * expr) {
     175    MAKE_UNARY(createAtEOF, PabloAST::ClassTypeId::AtEOF, expr);
     176    return result;
     177}
     178
     179PabloAST * PabloBuilder::createAtEOF(PabloAST * expr, const std::string prefix) {
     180    MAKE_UNARY(createAtEOF, PabloAST::ClassTypeId::AtEOF, expr, prefix);
     181    return result;
     182}
     183
    174184PabloAST * PabloBuilder::createMatchStar(PabloAST * marker, PabloAST * charclass) {
    175     MAKE_BINARY(createMatchStar, PabloAST::ClassTypeId::MatchStar, marker, charclass);
    176     return result;
     185MAKE_BINARY(createMatchStar, PabloAST::ClassTypeId::MatchStar, marker, charclass);
     186return result;
    177187}
    178188
  • icGREP/icgrep-devel/icgrep/pablo/builder.hpp

    r5037 r5042  
    145145    PabloAST * createInFile(PabloAST * expr, const std::string prefix);
    146146   
     147    PabloAST * createAtEOF(PabloAST * expr);
     148   
     149    PabloAST * createAtEOF(PabloAST * expr, const std::string prefix);
     150   
    147151    /// CreateIf Wrappers
    148152
  • icGREP/icgrep-devel/icgrep/pablo/codegenstate.cpp

    r5023 r5042  
    156156PabloAST * PabloBlock::createInFile(PabloAST * expr) {
    157157    assert (expr);
    158     return insertAtInsertionPoint(new InFile(expr, makeName("count_")));
     158    return insertAtInsertionPoint(new InFile(expr, makeName("inFile_")));
    159159}
    160160
     
    165165
    166166
    167 /// BINARY CREATE FUNCTIONS
     167PabloAST * PabloBlock::createAtEOF(PabloAST * expr) {
     168    assert (expr);
     169    return insertAtInsertionPoint(new AtEOF(expr, makeName("atEOF_")));
     170}
     171
     172PabloAST * PabloBlock::createAtEOF(PabloAST * expr, const std::string prefix) {
     173    assert (expr);
     174    return insertAtInsertionPoint(new AtEOF(expr, makeName(prefix, false)));
     175}
     176   
     177   
     178    /// BINARY CREATE FUNCTIONS
    168179
    169180Next * PabloBlock::createNext(Assign * assign, PabloAST * expr) {
  • icGREP/icgrep-devel/icgrep/pablo/codegenstate.h

    r5023 r5042  
    187187    PabloAST * createInFile(PabloAST * expr, const std::string prefix);
    188188   
     189    PabloAST * createAtEOF(PabloAST * expr);
     190   
     191    PabloAST * createAtEOF(PabloAST * expr, const std::string prefix);
     192   
    189193    If * createIf(PabloAST * condition, const std::initializer_list<Assign *> definedVars, PabloBlock * body);
    190194
  • icGREP/icgrep-devel/icgrep/pablo/pabloAST.cpp

    r5037 r5042  
    3535        } else if (isa<InFile>(expr1)) {
    3636            return equals(cast<InFile>(expr1)->getOperand(0), cast<InFile>(expr2)->getOperand(0));
     37        } else if (isa<AtEOF>(expr1)) {
     38            return equals(cast<AtEOF>(expr1)->getOperand(0), cast<AtEOF>(expr2)->getOperand(0));
    3739        } else if (isa<Variadic>(expr1)) {
    3840            const Variadic * const var1 = cast<Variadic>(expr1);
  • icGREP/icgrep-devel/icgrep/pablo/pabloAST.h

    r5037 r5042  
    6969        , MatchStar
    7070        , InFile
     71        , AtEOF
    7172        // Statistics operations
    7273        , Count
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r5039 r5042  
    112112    mCarryManager->initialize(function, mKernelBuilder);
    113113   
    114     mKernelBuilder->addInternalState(mBitBlockType, "EOFmask");
     114    mKernelBuilder->addInternalState(mBitBlockType, "EOFmark");
    115115   
    116116    mFunction = mKernelBuilder->prepareFunction({mInputStreamOffset.begin(), mInputStreamOffset.end()});
     
    396396        expr = iBuilder->simd_and(sum, iBuilder->simd_not(cc_expr));
    397397    } else if (const InFile * e = dyn_cast<InFile>(stmt)) {
    398         // Currently InFile(x) => x;  a no-op
    399         Value * EOFmask = iBuilder->CreateLoad(mKernelBuilder->getInternalState("EOFmask"));
    400         expr = iBuilder->simd_and(compileExpression(e->getExpr()), iBuilder->simd_not(EOFmask));
     398        Value * EOFmark = iBuilder->CreateLoad(mKernelBuilder->getInternalState("EOFmark"));
     399        Value * infileMask = iBuilder->simd_add(iBuilder->getBitBlockWidth(), EOFmark, iBuilder->allOnes());
     400        expr = iBuilder->simd_and(compileExpression(e->getExpr()), infileMask);
     401    } else if (const AtEOF * e = dyn_cast<AtEOF>(stmt)) {
     402        Value * EOFmark = iBuilder->CreateLoad(mKernelBuilder->getInternalState("EOFmark"));
     403        expr = iBuilder->simd_and(compileExpression(e->getExpr()), EOFmark);
    401404    } else if (const Count * c = dyn_cast<Count>(stmt)) {
    402405        Value * const to_count = compileExpression(c->getExpr());
  • icGREP/icgrep-devel/icgrep/pablo/pe_infile.h

    r5024 r5042  
    3030};
    3131
     32class AtEOF : public Statement {
     33    friend class PabloBlock;
     34public:
     35    static inline bool classof(const PabloAST * e) {
     36        return e->getClassTypeId() == ClassTypeId::AtEOF;
     37    }
     38    static inline bool classof(const void *) {
     39        return false;
     40    }
     41    virtual ~AtEOF(){
     42    }
     43    PabloAST * getExpr() const {
     44        return getOperand(0);
     45    }
     46protected:
     47    AtEOF(PabloAST * expr, String * name) : Statement(ClassTypeId::AtEOF, {expr}, name) { }
     48};
     49   
    3250}
    3351
  • icGREP/icgrep-devel/icgrep/re/re_compiler.cpp

    r5037 r5042  
    4646
    4747    Assign * LF = mPB.createAssign("LF", mCCCompiler.compileCC(makeCC(0x0A)));
    48     mLineFeed = LF;
    4948    PabloAST * CR = mCCCompiler.compileCC(makeCC(0x0D));
    5049    PabloAST * LF_VT_FF_CR = mCCCompiler.compileCC(makeCC(0x0A, 0x0D));
     
    121120    mInitial = mPB.createOr(u8single, valid_pfx, "initial");
    122121    mFinal = mPB.createNot(mPB.createOr(mNonFinal, u8invalid), "final");
    123     mUnicodeLineBreak = mPB.createAnd(LB_chars, mPB.createNot(mCRLF));  // count the CR, but not CRLF
    124     PabloAST * const lb = UNICODE_LINE_BREAK ? mUnicodeLineBreak : mLineFeed;
     122    PabloAST * UnicodeLineBreak = mPB.createAnd(LB_chars, mPB.createNot(mCRLF));  // count the CR, but not CRLF
     123    PabloAST * lb = UNICODE_LINE_BREAK ? UnicodeLineBreak : LF;
     124    PabloAST * unterminatedLineAtEOF = mPB.createAtEOF(mPB.createAdvance(mPB.createNot(LB_chars), 1));
     125    mLineBreak = mPB.createOr(lb, unterminatedLineAtEOF);
    125126    mAny = mPB.createNot(lb, "any");
    126     mFunction.setResult(1, mPB.createAssign("lf", mPB.createAnd(lb, mPB.createNot(mCRLF))));
     127    mFunction.setResult(1, mPB.createAssign("lf", mLineBreak));
    127128}
    128129
     
    362363        match_follow = mPB.createNot(match_follow);
    363364    }
    364     mFunction.setResult(0, mPB.createAssign("matches", mPB.createAnd(match_follow, UNICODE_LINE_BREAK ? mUnicodeLineBreak : mLineFeed)));
     365    mFunction.setResult(0, mPB.createAssign("matches", mPB.createAnd(match_follow, mLineBreak)));
    365366}
    366367
     
    398399inline MarkerType RE_Compiler::compileAny(const MarkerType m, PabloBuilder & pb) {
    399400    PabloAST * nextFinalByte = markerVar(AdvanceMarker(m, MarkerPosition::FinalPostPositionByte, pb));
    400     PabloAST * lb = mLineFeed;
     401    PabloAST * lb = mLineBreak;
    401402    if (UNICODE_LINE_BREAK) {
    402         lb = pb.createOr(mUnicodeLineBreak, mCRLF);
     403        lb = pb.createOr(mLineBreak, mCRLF);
    403404    }
    404405    return makeMarker(MarkerPosition::FinalMatchByte, pb.createAnd(nextFinalByte, pb.createNot(lb), "dot"));
     
    698699    MarkerType m = AdvanceMarker(marker, MarkerPosition::InitialPostPositionByte, pb);
    699700    if (UNICODE_LINE_BREAK) {
    700         PabloAST * line_end = mPB.createOr(mUnicodeLineBreak, mCRLF);
     701        PabloAST * line_end = mPB.createOr(mLineBreak, mCRLF);
    701702        PabloAST * sol = pb.createNot(pb.createOr(pb.createAdvance(pb.createNot(line_end), 1), mCRLF));
    702703        return makeMarker(MarkerPosition::InitialPostPositionByte, pb.createAnd(markerVar(m), sol, "sol"));
    703704    } else {
    704         PabloAST * sol = pb.createNot(pb.createAdvance(pb.createNot(mLineFeed), 1));
     705        PabloAST * sol = pb.createNot(pb.createAdvance(pb.createNot(mLineBreak), 1));
    705706        return makeMarker(MarkerPosition::FinalPostPositionByte, pb.createAnd(markerVar(m), sol, "sol"));
    706707    }
     
    710711    if (UNICODE_LINE_BREAK) {
    711712        PabloAST * nextPos = markerVar(AdvanceMarker(marker, MarkerPosition::FinalPostPositionByte, pb));
    712         return makeMarker(MarkerPosition::FinalPostPositionByte, pb.createAnd(nextPos, mUnicodeLineBreak, "eol"));
     713        return makeMarker(MarkerPosition::FinalPostPositionByte, pb.createAnd(nextPos, mLineBreak, "eol"));
    713714    } else {
    714715        PabloAST * nextPos = markerVar(AdvanceMarker(marker, MarkerPosition::InitialPostPositionByte, pb));  // For LF match
    715         return makeMarker(MarkerPosition::FinalPostPositionByte, pb.createAnd(nextPos, mLineFeed, "eol"));
     716        return makeMarker(MarkerPosition::FinalPostPositionByte, pb.createAnd(nextPos, mLineBreak, "eol"));
    716717    }
    717718}
     
    765766RE_Compiler::RE_Compiler(pablo::PabloFunction & function, cc::CC_Compiler & ccCompiler)
    766767: mCCCompiler(ccCompiler)
    767 , mLineFeed(nullptr)
     768, mLineBreak(nullptr)
    768769, mCRLF(nullptr)
    769 , mUnicodeLineBreak(nullptr)
    770770, mAny(nullptr)
    771771, mGraphemeBoundaryRule(nullptr)
  • icGREP/icgrep-devel/icgrep/re/re_compiler.h

    r5030 r5042  
    9494
    9595    cc::CC_Compiler &                               mCCCompiler;
    96     pablo::Assign *                                 mLineFeed;
     96    pablo::PabloAST *                                 mLineBreak;
    9797    pablo::PabloAST *                               mCRLF;
    98     pablo::PabloAST *                               mUnicodeLineBreak;
    9998    pablo::PabloAST *                               mAny;
    10099    pablo::PabloAST *                               mGraphemeBoundaryRule;
  • icGREP/icgrep-devel/icgrep/wc.cpp

    r5036 r5042  
    287287   
    288288    iBuilder->SetInsertPoint(finalBlock);
    289     Value * EOF_mask = iBuilder->CreateShl(Constant::getAllOnesValue(iBuilder->getIntNTy(mBlockSize)), remainingBytes);
    290         wcInstance->setInternalState("EOFmask", iBuilder->CreateBitCast(EOF_mask, mBitBlockType));
     289    Value * EOFmark = iBuilder->CreateShl(ConstantInt::get(iBuilder->getIntNTy(mBlockSize), 1), remainingBytes);
     290        wcInstance->setInternalState("EOFmark", iBuilder->CreateBitCast(EOFmark, mBitBlockType));
    291291   
    292292    Value * emptyBlockCond = iBuilder->CreateICmpEQ(remainingBytes, ConstantInt::get(int64ty, 0));
Note: See TracChangeset for help on using the changeset viewer.