Ignore:
Timestamp:
Feb 2, 2016, 4:02:08 PM (3 years ago)
Author:
nmedfort
Message:

Slight optimization for Simplifier; major change to CarryManager? to build summary variables whenever a carry operation is performed.

File:
1 edited

Legend:

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

    r4922 r4925  
    117117   
    118118    mCarryManager->initialize(mMod, mainScope);
    119    
     119
    120120    compileBlock(mainScope);
    121    
    122     mCarryManager->ensureCarriesStoredLocal();
    123     mCarryManager->leaveScope();
    124    
    125121   
    126122    mCarryManager->generateBlockNoIncrement();
     
    146142    const timestamp_t pablo_compilation_end = read_cycle_counter();
    147143    std::cerr << "PABLO COMPILATION TIME: " << (pablo_compilation_end - pablo_compilation_start) << std::endl;
    148     #endif
    149 
    150     #ifndef NDEBUG
    151     raw_os_ostream err(std::cerr);
    152     verifyModule(*mMod, &err);
    153144    #endif
    154145
     
    169160        }
    170161    }
     162
     163    #ifndef NDEBUG
     164    raw_os_ostream err(std::cerr);
     165    verifyModule(*mMod, &err);
     166    #endif
    171167
    172168    return mFunction;
     
    249245    //
    250246
    251     BasicBlock * ifEntryBlock = iBuilder->GetInsertBlock();
    252     BasicBlock * ifBodyBlock = BasicBlock::Create(mMod->getContext(), "if.body", mFunction, 0);
    253     BasicBlock * ifEndBlock = BasicBlock::Create(mMod->getContext(), "if.end", mFunction, 0);
     247    BasicBlock * const ifEntryBlock = iBuilder->GetInsertBlock();
     248    BasicBlock * const ifBodyBlock = BasicBlock::Create(mMod->getContext(), "if.body", mFunction, 0);
     249    BasicBlock * const ifEndBlock = BasicBlock::Create(mMod->getContext(), "if.end", mFunction, 0);
    254250   
    255251    PabloBlock * ifBody = ifStatement->getBody();
    256252   
    257     Value * if_test_value = compileExpression(ifStatement->getCondition());
     253    Value * const condition = compileExpression(ifStatement->getCondition());
    258254   
    259255    mCarryManager->enterScope(ifBody);
    260     iBuilder->CreateCondBr(mCarryManager->generateBitBlockOrSummaryTest(if_test_value), ifBodyBlock, ifEndBlock);
     256    iBuilder->CreateCondBr(mCarryManager->generateSummaryTest(condition), ifBodyBlock, ifEndBlock);
    261257   
    262258    // Entry processing is complete, now handle the body of the if.
    263259    iBuilder->SetInsertPoint(ifBodyBlock);
    264260   
    265     mCarryManager->initializeCarryDataAtIfEntry();
    266261    compileBlock(ifBody);
    267     BasicBlock * ifBodyFinalBlock = iBuilder->GetInsertBlock();
    268 
    269     if (mCarryManager->blockHasCarries()) {
    270         mCarryManager->generateCarryOutSummaryCodeIfNeeded();
    271     }
    272 
    273     mCarryManager->ensureCarriesStoredLocal();
     262    BasicBlock * ifExitBlock = iBuilder->GetInsertBlock();
     263
     264    if (mCarryManager->hasCarries()) {
     265        mCarryManager->storeCarryOutSummary();
     266    }
     267    mCarryManager->blendCarrySummaryWithOuterSummary();
     268
    274269    iBuilder->CreateBr(ifEndBlock);
    275270    //End Block
     
    281276        assert (f != mMarkerMap.end());
    282277        phi->addIncoming(iBuilder->allZeroes(), ifEntryBlock);
    283         phi->addIncoming(f->second, ifBodyFinalBlock);
     278        phi->addIncoming(f->second, ifExitBlock);
    284279        mMarkerMap[assign] = phi;
    285280    }
    286281    // Create the phi Node for the summary variable, if needed.
    287     mCarryManager->buildCarryDataPhisAfterIfBody(ifEntryBlock, ifBodyFinalBlock);
     282    mCarryManager->buildCarryDataPhisAfterIfBody(ifEntryBlock, ifExitBlock);
    288283    mCarryManager->leaveScope();
    289284}
     
    317312    // (3) Next nodes: (a) values set up before loop, (b) modified values calculated in loop.
    318313
    319     mCarryManager->initializeCarryDataPhisAtWhileEntry(whileEntryBlock);
     314    mCarryManager->initializeWhileEntryCarryDataPhis(whileEntryBlock);
    320315
    321316    // for any Next nodes in the loop body, initialize to (a) pre-loop value.
     
    335330    compileBlock(whileBody);
    336331
    337     BasicBlock * whileBodyFinalBlock = iBuilder->GetInsertBlock();
    338 
    339     if (mCarryManager->blockHasCarries()) {
    340         mCarryManager->generateCarryOutSummaryCodeIfNeeded();
    341     }
    342     mCarryManager->extendCarryDataPhisAtWhileBodyFinalBlock(whileBodyFinalBlock);
     332    BasicBlock * whileExitBlock = iBuilder->GetInsertBlock();
     333
     334    if (mCarryManager->hasCarries()) {
     335        mCarryManager->storeCarryOutSummary();
     336    }
     337    mCarryManager->finalizeWhileBlockCarryDataPhis(whileExitBlock);
    343338
    344339    // Terminate the while loop body with a conditional branch back.
     
    352347            throw std::runtime_error("Next node expression was not compiled!");
    353348        }
    354         nextPhis[i]->addIncoming(f->second, whileBodyFinalBlock);
     349        nextPhis[i]->addIncoming(f->second, whileExitBlock);
    355350    }
    356351
     
    380375    }
    381376    else if (const Call* call = dyn_cast<Call>(stmt)) {
    382         //Call the callee once and store the result in the marker map.
    383         if (mMarkerMap.count(call) != 0) {
     377        // Call the callee once and store the result in the marker map.
     378        if (mMarkerMap.count(call)) {
    384379            return;
    385380        }
     
    429424    }
    430425    else if (const Advance * adv = dyn_cast<Advance>(stmt)) {
    431         Value* strm_value = compileExpression(adv->getExpr());
    432         int shift = adv->getAdvanceAmount();
    433         unsigned advance_index = adv->getLocalAdvanceIndex();
    434         expr = mCarryManager->advanceCarryInCarryOut(advance_index, shift, strm_value);
     426        Value * const strm_value = compileExpression(adv->getExpr());
     427        expr = mCarryManager->advanceCarryInCarryOut(adv->getLocalAdvanceIndex(), adv->getAdvanceAmount(), strm_value);
    435428    }
    436429    else if (const Mod64Advance * adv = dyn_cast<Mod64Advance>(stmt)) {
    437         Value* strm_value = compileExpression(adv->getExpr());
    438         int shift = adv->getAdvanceAmount();
    439         expr = iBuilder->simd_slli(64, strm_value, shift);
     430        Value * const strm_value = compileExpression(adv->getExpr());
     431        expr = iBuilder->simd_slli(64, strm_value, adv->getAdvanceAmount());
    440432    }
    441433    else if (const MatchStar * mstar = dyn_cast<MatchStar>(stmt)) {
    442         Value * marker = compileExpression(mstar->getMarker());
    443         Value * cc = compileExpression(mstar->getCharClass());
    444         Value * marker_and_cc = iBuilder->simd_and(marker, cc);
    445         unsigned carry_index = mstar->getLocalCarryIndex();
    446         Value * sum = mCarryManager->addCarryInCarryOut(carry_index, marker_and_cc, cc);
     434        Value * const marker = compileExpression(mstar->getMarker());
     435        Value * const cc = compileExpression(mstar->getCharClass());
     436        Value * const marker_and_cc = iBuilder->simd_and(marker, cc);
     437        Value * const sum = mCarryManager->addCarryInCarryOut(mstar->getLocalCarryIndex(), marker_and_cc, cc);
    447438        expr = iBuilder->simd_or(iBuilder->simd_xor(sum, cc), marker);
    448439    }
    449440    else if (const Mod64MatchStar * mstar = dyn_cast<Mod64MatchStar>(stmt)) {
    450         Value * marker = compileExpression(mstar->getMarker());
    451         Value * cc = compileExpression(mstar->getCharClass());
    452         Value * marker_and_cc = iBuilder->simd_and(marker, cc);
    453         Value * sum = iBuilder->simd_add(64, marker_and_cc, cc);
     441        Value * const marker = compileExpression(mstar->getMarker());
     442        Value * const cc = compileExpression(mstar->getCharClass());
     443        Value * const marker_and_cc = iBuilder->simd_and(marker, cc);
     444        Value * const sum = iBuilder->simd_add(64, marker_and_cc, cc);
    454445        expr = iBuilder->simd_or(iBuilder->simd_xor(sum, cc), marker);
    455446    }
    456447    else if (const ScanThru * sthru = dyn_cast<ScanThru>(stmt)) {
    457         Value * marker_expr = compileExpression(sthru->getScanFrom());
    458         Value * cc_expr = compileExpression(sthru->getScanThru());
    459         unsigned carry_index = sthru->getLocalCarryIndex();
    460         Value * sum = mCarryManager->addCarryInCarryOut(carry_index, marker_expr, cc_expr);
     448        Value * const  marker_expr = compileExpression(sthru->getScanFrom());
     449        Value * const  cc_expr = compileExpression(sthru->getScanThru());
     450        Value * const  sum = mCarryManager->addCarryInCarryOut(sthru->getLocalCarryIndex(), marker_expr, cc_expr);
    461451        expr = iBuilder->simd_and(sum, iBuilder->simd_not(cc_expr));
    462452    }
    463453    else if (const Mod64ScanThru * sthru = dyn_cast<Mod64ScanThru>(stmt)) {
    464         Value * marker_expr = compileExpression(sthru->getScanFrom());
    465         Value * cc_expr = compileExpression(sthru->getScanThru());
    466         Value * sum = iBuilder->simd_add(64, marker_expr, cc_expr);
     454        Value * const marker_expr = compileExpression(sthru->getScanFrom());
     455        Value * const cc_expr = compileExpression(sthru->getScanThru());
     456        Value * const sum = iBuilder->simd_add(64, marker_expr, cc_expr);
    467457        expr = iBuilder->simd_and(sum, iBuilder->simd_not(cc_expr));
    468458    }
    469459    else if (const Count * c = dyn_cast<Count>(stmt)) {
    470         unsigned count_index = c->getGlobalCountIndex();
    471         Value * to_count = compileExpression(c->getExpr());
    472         expr = mCarryManager->popCount(to_count, count_index);
    473     }
    474     else {
    475         llvm::raw_os_ostream cerr(std::cerr);
    476         PabloPrinter::print(stmt, cerr);
    477         throw std::runtime_error("Unrecognized Pablo Statement! can't compile.");
     460        Value * const to_count = compileExpression(c->getExpr());
     461        expr = mCarryManager->popCount(to_count, c->getGlobalCountIndex());
     462    } else {
     463        std::string tmp;
     464        llvm::raw_string_ostream msg(tmp);
     465        msg << "Internal error: ";
     466        PabloPrinter::print(stmt, msg);
     467        msg << " is not a recognized statement in the Pablo compiler.";
     468        throw std::runtime_error(msg.str());
    478469    }
    479470    mMarkerMap[stmt] = expr;
Note: See TracChangeset for help on using the changeset viewer.