Ignore:
Timestamp:
May 6, 2017, 4:05:05 PM (2 years ago)
Author:
nmedfort
Message:

Continued refactoring work.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r5431 r5435  
    4444}
    4545
    46 void PabloCompiler::compile() {
    47     iBuilder = mKernel->getBuilder();
    48     assert ("PabloCompiler does not have a IDISA builder" && iBuilder);
    49     mCarryManager->initializeCodeGen();     
     46void PabloCompiler::initializeKernelData(IDISA::IDISA_Builder * const builder) {
     47    assert ("PabloCompiler does not have a IDISA builder" && builder);
     48    examineBlock(builder, mKernel->getEntryBlock());
     49    mCarryManager->initializeCarryData(builder, mKernel);
     50}
     51
     52void PabloCompiler::compile(IDISA::IDISA_Builder * const builder) {
     53    assert ("PabloCompiler does not have a IDISA builder" && builder);
     54    mCarryManager->initializeCodeGen(builder);
    5055    PabloBlock * const entryBlock = mKernel->getEntryBlock(); assert (entryBlock);
    51     mMarker.emplace(entryBlock->createZeroes(), iBuilder->allZeroes());
    52     mMarker.emplace(entryBlock->createOnes(), iBuilder->allOnes());
    53     compileBlock(entryBlock);
    54     mCarryManager->finalizeCodeGen();
    55 }
    56 
    57 void PabloCompiler::initializeKernelData() {
    58     iBuilder = mKernel->getBuilder();
    59     assert ("PabloCompiler does not have a IDISA builder" && iBuilder);
    60     examineBlock(mKernel->getEntryBlock());
    61     mCarryManager->initializeCarryData();
    62 }
    63 
    64 void PabloCompiler::examineBlock(const PabloBlock * const block) {
     56    mMarker.emplace(entryBlock->createZeroes(), builder->allZeroes());
     57    mMarker.emplace(entryBlock->createOnes(), builder->allOnes());
     58    compileBlock(builder, entryBlock);
     59    mCarryManager->finalizeCodeGen(builder);
     60}
     61
     62void PabloCompiler::examineBlock(IDISA::IDISA_Builder * const builder, const PabloBlock * const block) {
    6563    for (const Statement * stmt : *block) {
    6664        if (LLVM_UNLIKELY(isa<Lookahead>(stmt))) {
     
    7169            }
    7270        } else if (LLVM_UNLIKELY(isa<Branch>(stmt))) {
    73             examineBlock(cast<Branch>(stmt)->getBody());
     71            examineBlock(builder, cast<Branch>(stmt)->getBody());
    7472        } else if (LLVM_UNLIKELY(isa<Count>(stmt))) {
    75             mAccumulator.insert(std::make_pair(stmt, iBuilder->getInt32(mKernel->addUnnamedScalar(stmt->getType()))));
     73            mAccumulator.insert(std::make_pair(stmt, builder->getInt32(mKernel->addUnnamedScalar(stmt->getType()))));
    7674        }
    7775    }   
    7876}
    7977
    80 inline void PabloCompiler::compileBlock(const PabloBlock * const block) {
     78inline void PabloCompiler::compileBlock(IDISA::IDISA_Builder * const builder, const PabloBlock * const block) {
    8179    for (const Statement * statement : *block) {
    82         compileStatement(statement);
    83     }
    84 }
    85 
    86 void PabloCompiler::compileIf(const If * const ifStatement) {
     80        compileStatement(builder, statement);
     81    }
     82}
     83
     84void PabloCompiler::compileIf(IDISA::IDISA_Builder * const builder, const If * const ifStatement) {
    8785    //
    8886    //  The If-ElseZero stmt:
     
    103101    //
    104102
    105     BasicBlock * const ifEntryBlock = iBuilder->GetInsertBlock();
     103    BasicBlock * const ifEntryBlock = builder->GetInsertBlock();
    106104    BasicBlock * const ifBodyBlock = mKernel->CreateBasicBlock("if.body");
    107105    BasicBlock * const ifEndBlock = mKernel->CreateBasicBlock("if.end");
     
    115113                marker = mKernel->getScalarFieldPtr(var->getName());
    116114            } else if (var->isReadOnly()) {
    117                 marker = mKernel->getInputStreamBlockPtr(var->getName(), iBuilder->getInt32(0));
     115                marker = mKernel->getInputStreamBlockPtr(var->getName(), builder->getInt32(0));
    118116            } else if (var->isReadNone()) {
    119                 marker = mKernel->getOutputStreamBlockPtr(var->getName(), iBuilder->getInt32(0));
     117                marker = mKernel->getOutputStreamBlockPtr(var->getName(), builder->getInt32(0));
    120118            }
    121119            mMarker[var] = marker;
     
    136134    const PabloBlock * ifBody = ifStatement->getBody();
    137135   
    138     mCarryManager->enterIfScope(ifBody);
    139 
    140     Value * condition = compileExpression(ifStatement->getCondition());
    141     if (condition->getType() == iBuilder->getBitBlockType()) {
    142         condition = iBuilder->bitblock_any(mCarryManager->generateSummaryTest(condition));
     136    mCarryManager->enterIfScope(builder, ifBody);
     137
     138    Value * condition = compileExpression(builder, ifStatement->getCondition());
     139    if (condition->getType() == builder->getBitBlockType()) {
     140        condition = builder->bitblock_any(mCarryManager->generateSummaryTest(builder, condition));
    143141    }
    144142   
    145     iBuilder->CreateCondBr(condition, ifBodyBlock, ifEndBlock);
     143    builder->CreateCondBr(condition, ifBodyBlock, ifEndBlock);
    146144   
    147145    // Entry processing is complete, now handle the body of the if.
    148     iBuilder->SetInsertPoint(ifBodyBlock);
    149 
    150     mCarryManager->enterIfBody(ifEntryBlock);
    151 
    152     compileBlock(ifBody);
    153 
    154     mCarryManager->leaveIfBody(iBuilder->GetInsertBlock());
    155 
    156     BasicBlock * ifExitBlock = iBuilder->GetInsertBlock();
    157 
    158     iBuilder->CreateBr(ifEndBlock);
     146    builder->SetInsertPoint(ifBodyBlock);
     147
     148    mCarryManager->enterIfBody(builder, ifEntryBlock);
     149
     150    compileBlock(builder, ifBody);
     151
     152    mCarryManager->leaveIfBody(builder, builder->GetInsertBlock());
     153
     154    BasicBlock * ifExitBlock = builder->GetInsertBlock();
     155
     156    builder->CreateBr(ifEndBlock);
    159157
    160158    ifEndBlock->moveAfter(ifExitBlock);
    161159
    162160    //End Block
    163     iBuilder->SetInsertPoint(ifEndBlock);
    164 
    165     mCarryManager->leaveIfScope(ifEntryBlock, ifExitBlock);
     161    builder->SetInsertPoint(ifEndBlock);
     162
     163    mCarryManager->leaveIfScope(builder, ifEntryBlock, ifExitBlock);
    166164
    167165    for (const auto i : incoming) {
     
    198196        }
    199197
    200         PHINode * phi = iBuilder->CreatePHI(incoming->getType(), 2, var->getName());
     198        PHINode * phi = builder->CreatePHI(incoming->getType(), 2, var->getName());
    201199        phi->addIncoming(incoming, ifEntryBlock);
    202200        phi->addIncoming(outgoing, ifExitBlock);
     
    205203}
    206204
    207 void PabloCompiler::compileWhile(const While * const whileStatement) {
     205void PabloCompiler::compileWhile(IDISA::IDISA_Builder * const builder, const While * const whileStatement) {
    208206
    209207    const PabloBlock * const whileBody = whileStatement->getBody();
    210208
    211     BasicBlock * whileEntryBlock = iBuilder->GetInsertBlock();
     209    BasicBlock * whileEntryBlock = builder->GetInsertBlock();
    212210
    213211    const auto escaped = whileStatement->getEscaped();
     
    226224                marker = mKernel->getScalarFieldPtr(var->getName());
    227225            } else if (var->isReadOnly()) {
    228                 marker = mKernel->getInputStreamBlockPtr(var->getName(), iBuilder->getInt32(0));
     226                marker = mKernel->getInputStreamBlockPtr(var->getName(), builder->getInt32(0));
    229227            } else if (var->isReadNone()) {
    230                 marker = mKernel->getOutputStreamBlockPtr(var->getName(), iBuilder->getInt32(0));
     228                marker = mKernel->getOutputStreamBlockPtr(var->getName(), builder->getInt32(0));
    231229            }
    232230            mMarker[var] = marker;
     
    234232    }
    235233
    236     mCarryManager->enterLoopScope(whileBody);
     234    mCarryManager->enterLoopScope(builder, whileBody);
    237235
    238236    BasicBlock * whileBodyBlock = mKernel->CreateBasicBlock("while.body");
    239237
    240     iBuilder->CreateBr(whileBodyBlock);
    241 
    242     iBuilder->SetInsertPoint(whileBodyBlock);
     238    builder->CreateBr(whileBodyBlock);
     239
     240    builder->SetInsertPoint(whileBodyBlock);
    243241
    244242    //
     
    266264        }
    267265        Value * entryValue = f->second;
    268         PHINode * phi = iBuilder->CreatePHI(entryValue->getType(), 2, var->getName());
     266        PHINode * phi = builder->CreatePHI(entryValue->getType(), 2, var->getName());
    269267        phi->addIncoming(entryValue, whileEntryBlock);
    270268        f->second = phi;
     
    279277#endif
    280278
    281     mCarryManager->enterLoopBody(whileEntryBlock);
    282 
    283     compileBlock(whileBody);
     279    mCarryManager->enterLoopBody(builder, whileEntryBlock);
     280
     281    compileBlock(builder, whileBody);
    284282
    285283    // After the whileBody has been compiled, we may be in a different basic block.
    286284
    287     mCarryManager->leaveLoopBody(iBuilder->GetInsertBlock());
     285    mCarryManager->leaveLoopBody(builder, builder->GetInsertBlock());
    288286
    289287
     
    296294#endif
    297295
    298     BasicBlock * const whileExitBlock = iBuilder->GetInsertBlock();
     296    BasicBlock * const whileExitBlock = builder->GetInsertBlock();
    299297
    300298    // and for any variant nodes in the loop body
     
    334332
    335333    // Terminate the while loop body with a conditional branch back.
    336     Value * condition = compileExpression(whileStatement->getCondition());
    337     if (condition->getType() == iBuilder->getBitBlockType()) {
    338         condition = iBuilder->bitblock_any(mCarryManager->generateSummaryTest(condition));
    339     }
    340 
    341     iBuilder->CreateCondBr(condition, whileBodyBlock, whileEndBlock);
    342 
    343     iBuilder->SetInsertPoint(whileEndBlock);
    344 
    345     mCarryManager->leaveLoopScope(whileEntryBlock, whileExitBlock);
    346 
    347 }
    348 
    349 void PabloCompiler::compileStatement(const Statement * const stmt) {
     334    Value * condition = compileExpression(builder, whileStatement->getCondition());
     335    if (condition->getType() == builder->getBitBlockType()) {
     336        condition = builder->bitblock_any(mCarryManager->generateSummaryTest(builder, condition));
     337    }
     338
     339    builder->CreateCondBr(condition, whileBodyBlock, whileEndBlock);
     340
     341    builder->SetInsertPoint(whileEndBlock);
     342
     343    mCarryManager->leaveLoopScope(builder, whileEntryBlock, whileExitBlock);
     344
     345}
     346
     347void PabloCompiler::compileStatement(IDISA::IDISA_Builder * const builder, const Statement * const stmt) {
    350348
    351349    if (LLVM_UNLIKELY(isa<If>(stmt))) {
    352         compileIf(cast<If>(stmt));
     350        compileIf(builder, cast<If>(stmt));
    353351    } else if (LLVM_UNLIKELY(isa<While>(stmt))) {
    354         compileWhile(cast<While>(stmt));
     352        compileWhile(builder, cast<While>(stmt));
    355353    } else {
    356354        const PabloAST * expr = stmt;
    357355        Value * value = nullptr;
    358356        if (LLVM_UNLIKELY(isa<Assign>(stmt))) {
    359             value = compileExpression(cast<Assign>(stmt)->getValue());
     357            value = compileExpression(builder, cast<Assign>(stmt)->getValue());
    360358            expr = cast<Assign>(stmt)->getVariable();
    361359            Value * ptr = nullptr;
     
    377375                        ptr = mKernel->getScalarFieldPtr(var->getName());
    378376                    } else {
    379                         ptr = mKernel->getOutputStreamBlockPtr(var->getName(), iBuilder->getInt32(0));
     377                        ptr = mKernel->getOutputStreamBlockPtr(var->getName(), builder->getInt32(0));
    380378                    }
    381379                }
     
    398396            }
    399397            if (ptr) {
    400                 iBuilder->CreateAlignedStore(value, ptr, getAlignment(value));
     398                builder->CreateAlignedStore(value, ptr, getAlignment(value));
    401399                value = ptr;
    402400            }
    403401        } else if (const Extract * extract = dyn_cast<Extract>(stmt)) {
    404             Value * index = compileExpression(extract->getIndex());
     402            Value * index = compileExpression(builder, extract->getIndex());
    405403            Var * const array = dyn_cast<Var>(extract->getArray());
    406404            if (LLVM_LIKELY(array && array->isKernelParameter())) {
     
    419417                }
    420418            } else {
    421                 Value * ptr = compileExpression(extract->getArray(), false);
    422                 value = iBuilder->CreateGEP(ptr, {ConstantInt::getNullValue(index->getType()), index}, "extract");
     419                Value * ptr = compileExpression(builder, extract->getArray(), false);
     420                value = builder->CreateGEP(ptr, {ConstantInt::getNullValue(index->getType()), index}, "extract");
    423421            }
    424422        } else if (isa<And>(stmt)) {
    425             value = compileExpression(stmt->getOperand(0));
     423            value = compileExpression(builder, stmt->getOperand(0));
    426424            for (unsigned i = 1; i < stmt->getNumOperands(); ++i) {
    427                 value = iBuilder->simd_and(value, compileExpression(stmt->getOperand(1)));
     425                value = builder->simd_and(value, compileExpression(builder, stmt->getOperand(1)));
    428426            }
    429427        } else if (isa<Or>(stmt)) {
    430             value = compileExpression(stmt->getOperand(0));
     428            value = compileExpression(builder, stmt->getOperand(0));
    431429            for (unsigned i = 1; i < stmt->getNumOperands(); ++i) {
    432                 value = iBuilder->simd_or(value, compileExpression(stmt->getOperand(1)));
     430                value = builder->simd_or(value, compileExpression(builder, stmt->getOperand(1)));
    433431            }
    434432        } else if (isa<Xor>(stmt)) {
    435             value = compileExpression(stmt->getOperand(0));
     433            value = compileExpression(builder, stmt->getOperand(0));
    436434            for (unsigned i = 1; i < stmt->getNumOperands(); ++i) {
    437                 value = iBuilder->simd_xor(value, compileExpression(stmt->getOperand(1)));
     435                value = builder->simd_xor(value, compileExpression(builder, stmt->getOperand(1)));
    438436            }
    439437        } else if (const Sel * sel = dyn_cast<Sel>(stmt)) {
    440             Value* ifMask = compileExpression(sel->getCondition());
    441             Value* ifTrue = iBuilder->simd_and(ifMask, compileExpression(sel->getTrueExpr()));
    442             Value* ifFalse = iBuilder->simd_and(iBuilder->simd_not(ifMask), compileExpression(sel->getFalseExpr()));
    443             value = iBuilder->simd_or(ifTrue, ifFalse);
     438            Value* ifMask = compileExpression(builder, sel->getCondition());
     439            Value* ifTrue = builder->simd_and(ifMask, compileExpression(builder, sel->getTrueExpr()));
     440            Value* ifFalse = builder->simd_and(builder->simd_not(ifMask), compileExpression(builder, sel->getFalseExpr()));
     441            value = builder->simd_or(ifTrue, ifFalse);
    444442        } else if (isa<Not>(stmt)) {
    445             value = iBuilder->simd_not(compileExpression(stmt->getOperand(0)));
     443            value = builder->simd_not(compileExpression(builder, stmt->getOperand(0)));
    446444        } else if (isa<Advance>(stmt)) {
    447445            const Advance * const adv = cast<Advance>(stmt);
    448446            // If our expr is an Extract op on a mutable Var then we need to pass the index value to the carry
    449447            // manager so that it properly selects the correct carry bit.
    450             value = mCarryManager->advanceCarryInCarryOut(adv, compileExpression(adv->getExpression()));
     448            value = mCarryManager->advanceCarryInCarryOut(builder, adv, compileExpression(builder, adv->getExpression()));
    451449        } else if (const MatchStar * mstar = dyn_cast<MatchStar>(stmt)) {
    452             Value * const marker = compileExpression(mstar->getMarker());
    453             Value * const cc = compileExpression(mstar->getCharClass());
    454             Value * const marker_and_cc = iBuilder->simd_and(marker, cc);
    455             Value * const sum = mCarryManager->addCarryInCarryOut(mstar, marker_and_cc, cc);
    456             value = iBuilder->simd_or(iBuilder->simd_xor(sum, cc), marker);
     450            Value * const marker = compileExpression(builder, mstar->getMarker());
     451            Value * const cc = compileExpression(builder, mstar->getCharClass());
     452            Value * const marker_and_cc = builder->simd_and(marker, cc);
     453            Value * const sum = mCarryManager->addCarryInCarryOut(builder, mstar, marker_and_cc, cc);
     454            value = builder->simd_or(builder->simd_xor(sum, cc), marker);
    457455        } else if (const ScanThru * sthru = dyn_cast<ScanThru>(stmt)) {
    458             Value * const from = compileExpression(sthru->getScanFrom());
    459             Value * const thru = compileExpression(sthru->getScanThru());
    460             Value * const sum = mCarryManager->addCarryInCarryOut(sthru, from, thru);
    461             value = iBuilder->simd_and(sum, iBuilder->simd_not(thru));
     456            Value * const from = compileExpression(builder, sthru->getScanFrom());
     457            Value * const thru = compileExpression(builder, sthru->getScanThru());
     458            Value * const sum = mCarryManager->addCarryInCarryOut(builder, sthru, from, thru);
     459            value = builder->simd_and(sum, builder->simd_not(thru));
    462460        } else if (const ScanTo * sthru = dyn_cast<ScanTo>(stmt)) {
    463             Value * const marker_expr = compileExpression(sthru->getScanFrom());
    464             Value * const to = iBuilder->simd_xor(compileExpression(sthru->getScanTo()), mKernel->getScalarField("EOFmask"));
    465             Value * const sum = mCarryManager->addCarryInCarryOut(sthru, marker_expr, iBuilder->simd_not(to));
    466             value = iBuilder->simd_and(sum, to);
     461            Value * const marker_expr = compileExpression(builder, sthru->getScanFrom());
     462            Value * const to = builder->simd_xor(compileExpression(builder, sthru->getScanTo()), mKernel->getScalarField("EOFmask"));
     463            Value * const sum = mCarryManager->addCarryInCarryOut(builder, sthru, marker_expr, builder->simd_not(to));
     464            value = builder->simd_and(sum, to);
    467465        } else if (const AdvanceThenScanThru * sthru = dyn_cast<AdvanceThenScanThru>(stmt)) {
    468             Value * const from = compileExpression(sthru->getScanFrom());
    469             Value * const thru = compileExpression(sthru->getScanThru());
    470             Value * const sum = mCarryManager->addCarryInCarryOut(sthru, from, iBuilder->simd_or(from, thru));
    471             value = iBuilder->simd_and(sum, iBuilder->simd_not(thru));
     466            Value * const from = compileExpression(builder, sthru->getScanFrom());
     467            Value * const thru = compileExpression(builder, sthru->getScanThru());
     468            Value * const sum = mCarryManager->addCarryInCarryOut(builder, sthru, from, builder->simd_or(from, thru));
     469            value = builder->simd_and(sum, builder->simd_not(thru));
    472470        } else if (const AdvanceThenScanTo * sthru = dyn_cast<AdvanceThenScanTo>(stmt)) {
    473             Value * const from = compileExpression(sthru->getScanFrom());
    474             Value * const to = iBuilder->simd_xor(compileExpression(sthru->getScanTo()), mKernel->getScalarField("EOFmask"));
    475             Value * const sum = mCarryManager->addCarryInCarryOut(sthru, from, iBuilder->simd_or(from, iBuilder->simd_not(to)));
    476             value = iBuilder->simd_and(sum, to);
     471            Value * const from = compileExpression(builder, sthru->getScanFrom());
     472            Value * const to = builder->simd_xor(compileExpression(builder, sthru->getScanTo()), mKernel->getScalarField("EOFmask"));
     473            Value * const sum = mCarryManager->addCarryInCarryOut(builder, sthru, from, builder->simd_or(from, builder->simd_not(to)));
     474            value = builder->simd_and(sum, to);
    477475        } else if (const InFile * e = dyn_cast<InFile>(stmt)) {
    478476            Value * EOFmask = mKernel->getScalarField("EOFmask");
    479             value = iBuilder->simd_and(compileExpression(e->getExpr()), iBuilder->simd_not(EOFmask));
     477            value = builder->simd_and(compileExpression(builder, e->getExpr()), builder->simd_not(EOFmask));
    480478        } else if (const AtEOF * e = dyn_cast<AtEOF>(stmt)) {
    481479            Value * EOFbit = mKernel->getScalarField("EOFbit");
    482             value = iBuilder->simd_and(compileExpression(e->getExpr()), EOFbit);
     480            value = builder->simd_and(compileExpression(builder, e->getExpr()), EOFbit);
    483481        } else if (const Count * c = dyn_cast<Count>(stmt)) {
    484482            Value * EOFbit = mKernel->getScalarField("EOFbit");
    485483            Value * EOFmask = mKernel->getScalarField("EOFmask");
    486             Value * const to_count = iBuilder->simd_and(iBuilder->simd_or(iBuilder->simd_not(EOFmask), EOFbit), compileExpression(c->getExpr()));
    487             const unsigned counterSize = iBuilder->getSizeTy()->getBitWidth();
     484        Value * const to_count = builder->simd_and(builder->simd_or(builder->simd_not(EOFmask), EOFbit), compileExpression(builder, c->getExpr()));
     485            const unsigned counterSize = builder->getSizeTy()->getBitWidth();
    488486            const auto f = mAccumulator.find(c);
    489487            if (LLVM_UNLIKELY(f == mAccumulator.end())) {
     
    492490            Value * ptr = mKernel->getScalarFieldPtr(f->second);
    493491            const auto alignment = getPointerElementAlignment(ptr);
    494             Value * count = iBuilder->CreateAlignedLoad(ptr, alignment, c->getName() + "_accumulator");
    495             Value * const partial = iBuilder->simd_popcount(counterSize, to_count);
     492            Value * count = builder->CreateAlignedLoad(ptr, alignment, c->getName() + "_accumulator");
     493            Value * const partial = builder->simd_popcount(counterSize, to_count);
    496494            if (LLVM_UNLIKELY(counterSize <= 1)) {
    497495                value = partial;
    498496            } else {
    499                 value = iBuilder->mvmd_extract(counterSize, partial, 0);
    500                 const auto fields = (iBuilder->getBitBlockWidth() / counterSize);
     497                value = builder->mvmd_extract(counterSize, partial, 0);
     498                const auto fields = (builder->getBitBlockWidth() / counterSize);
    501499                for (unsigned i = 1; i < fields; ++i) {
    502                     Value * temp = iBuilder->mvmd_extract(counterSize, partial, i);
    503                     value = iBuilder->CreateAdd(value, temp);
    504                 }
    505             }
    506             value = iBuilder->CreateAdd(value, count);
    507             iBuilder->CreateAlignedStore(value, ptr, alignment);
     500                    Value * temp = builder->mvmd_extract(counterSize, partial, i);
     501                    value = builder->CreateAdd(value, temp);
     502                }
     503            }
     504            value = builder->CreateAdd(value, count);
     505            builder->CreateAlignedStore(value, ptr, alignment);
    508506        } else if (const Lookahead * l = dyn_cast<Lookahead>(stmt)) {
    509507            Var * var = nullptr;
    510508            PabloAST * stream = l->getExpr();
    511             Value * index = iBuilder->getInt32(0);
     509            Value * index = builder->getInt32(0);
    512510            if (LLVM_UNLIKELY(isa<Extract>(stream))) {
    513511                var = dyn_cast<Var>(cast<Extract>(stream)->getArray());
    514                 index = compileExpression(cast<Extract>(stream)->getIndex());
     512                index = compileExpression(builder, cast<Extract>(stream)->getIndex());
    515513                if (!var->isKernelParameter() || var->isReadNone()) {
    516514                    std::string tmp;
     
    535533                }
    536534            }
    537             const auto bit_shift = (l->getAmount() % iBuilder->getBitBlockWidth());
    538             const auto block_shift = (l->getAmount() / iBuilder->getBitBlockWidth());
    539 
    540             Value * ptr = mKernel->getAdjustedInputStreamBlockPtr(iBuilder->getSize(block_shift), var->getName(), index);
    541             Value * lookAhead = iBuilder->CreateBlockAlignedLoad(ptr);
     535            const auto bit_shift = (l->getAmount() % builder->getBitBlockWidth());
     536            const auto block_shift = (l->getAmount() / builder->getBitBlockWidth());
     537
     538            Value * ptr = mKernel->getAdjustedInputStreamBlockPtr(builder->getSize(block_shift), var->getName(), index);
     539            Value * lookAhead = builder->CreateBlockAlignedLoad(ptr);
    542540            if (bit_shift == 0) {  // Simple case with no intra-block shifting.
    543541                value = lookAhead;
    544542            } else { // Need to form shift result from two adjacent blocks.
    545                 Value * ptr = mKernel->getAdjustedInputStreamBlockPtr(iBuilder->getSize(block_shift + 1), var->getName(), index);
    546                 Value * lookAhead1 = iBuilder->CreateBlockAlignedLoad(ptr);
     543                Value * ptr = mKernel->getAdjustedInputStreamBlockPtr(builder->getSize(block_shift + 1), var->getName(), index);
     544                Value * lookAhead1 = builder->CreateBlockAlignedLoad(ptr);
    547545                if (LLVM_UNLIKELY((bit_shift % 8) == 0)) { // Use a single whole-byte shift, if possible.
    548                     value = iBuilder->mvmd_dslli(8, lookAhead1, lookAhead, (bit_shift / 8));
     546                    value = builder->mvmd_dslli(8, lookAhead1, lookAhead, (bit_shift / 8));
    549547                } else {
    550                     Type  * const streamType = iBuilder->getIntNTy(iBuilder->getBitBlockWidth());
    551                     Value * b1 = iBuilder->CreateBitCast(lookAhead1, streamType);
    552                     Value * b0 = iBuilder->CreateBitCast(lookAhead, streamType);
    553                     Value * result = iBuilder->CreateOr(iBuilder->CreateShl(b1, iBuilder->getBitBlockWidth() - bit_shift), iBuilder->CreateLShr(b0, bit_shift));
    554                     value = iBuilder->CreateBitCast(result, iBuilder->getBitBlockType());
     548                    Type  * const streamType = builder->getIntNTy(builder->getBitBlockWidth());
     549                    Value * b1 = builder->CreateBitCast(lookAhead1, streamType);
     550                    Value * b0 = builder->CreateBitCast(lookAhead, streamType);
     551                    Value * result = builder->CreateOr(builder->CreateShl(b1, builder->getBitBlockWidth() - bit_shift), builder->CreateLShr(b0, bit_shift));
     552                    value = builder->CreateBitCast(result, builder->getBitBlockType());
    555553                }
    556554            }
     
    569567            const String & name = isa<Var>(expr) ? cast<Var>(expr)->getName() : cast<Statement>(expr)->getName();
    570568            if (value->getType()->isPointerTy()) {
    571                 value = iBuilder->CreateLoad(value);
     569                value = builder->CreateLoad(value);
    572570            }
    573571            if (value->getType()->isVectorTy()) {
    574                 iBuilder->CallPrintRegister(name.str(), value);
     572                builder->CallPrintRegister(name.str(), value);
    575573            } else if (value->getType()->isIntegerTy()) {
    576                 iBuilder->CallPrintInt(name.str(), value);
    577             }
    578         }
    579     }
    580 }
    581 
    582 Value * PabloCompiler::compileExpression(const PabloAST * expr, const bool ensureLoaded) const {
     574                builder->CallPrintInt(name.str(), value);
     575            }
     576        }
     577    }
     578}
     579
     580Value * PabloCompiler::compileExpression(IDISA::IDISA_Builder * const builder, const PabloAST * expr, const bool ensureLoaded) const {
    583581    if (LLVM_UNLIKELY(isa<Ones>(expr))) {
    584         return iBuilder->allOnes();
     582        return builder->allOnes();
    585583    } else if (LLVM_UNLIKELY(isa<Zeroes>(expr))) {
    586         return iBuilder->allZeroes();
     584        return builder->allZeroes();
    587585    } else if (LLVM_UNLIKELY(isa<Integer>(expr))) {
    588586        return ConstantInt::get(cast<Integer>(expr)->getType(), cast<Integer>(expr)->value());
    589587    } else if (LLVM_UNLIKELY(isa<Operator>(expr))) {
    590588        const Operator * op = cast<Operator>(expr);
    591         Value * lh = compileExpression(op->getLH());
    592         Value * rh = compileExpression(op->getRH());
     589        Value * lh = compileExpression(builder, op->getLH());
     590        Value * rh = compileExpression(builder, op->getRH());
    593591        if (LLVM_UNLIKELY(lh->getType() != rh->getType())) {
    594592            std::string tmp;
     
    605603        switch (op->getClassTypeId()) {
    606604            case TypeId::Add:
    607                 return iBuilder->CreateAdd(lh, rh);
     605                return builder->CreateAdd(lh, rh);
    608606            case TypeId::Subtract:
    609                 return iBuilder->CreateSub(lh, rh);
     607                return builder->CreateSub(lh, rh);
    610608            case TypeId::LessThan:
    611                 return iBuilder->CreateICmpSLT(lh, rh);
     609                return builder->CreateICmpSLT(lh, rh);
    612610            case TypeId::LessThanEquals:
    613                 return iBuilder->CreateICmpSLE(lh, rh);
     611                return builder->CreateICmpSLE(lh, rh);
    614612            case TypeId::Equals:
    615                 return iBuilder->CreateICmpEQ(lh, rh);
     613                return builder->CreateICmpEQ(lh, rh);
    616614            case TypeId::GreaterThanEquals:
    617                 return iBuilder->CreateICmpSGE(lh, rh);
     615                return builder->CreateICmpSGE(lh, rh);
    618616            case TypeId::GreaterThan:
    619                 return iBuilder->CreateICmpSGT(lh, rh);
     617                return builder->CreateICmpSGT(lh, rh);
    620618            case TypeId::NotEquals:
    621                 return iBuilder->CreateICmpNE(lh, rh);
     619                return builder->CreateICmpNE(lh, rh);
    622620            default: break;
    623621        }
     
    640638    Value * value = f->second;
    641639    if (LLVM_UNLIKELY(isa<GetElementPtrInst>(value) && ensureLoaded)) {
    642         value = iBuilder->CreateAlignedLoad(value, getPointerElementAlignment(value));
     640        value = builder->CreateAlignedLoad(value, getPointerElementAlignment(value));
    643641    }
    644642    return value;
     
    646644
    647645PabloCompiler::PabloCompiler(PabloKernel * const kernel)
    648 : iBuilder(nullptr)
    649 , mKernel(kernel)
    650 , mCarryManager(new CarryManager(kernel)) {
     646: mKernel(kernel)
     647, mCarryManager(new CarryManager) {
    651648    assert ("PabloKernel cannot be null!" && kernel);
    652649}
Note: See TracChangeset for help on using the changeset viewer.