Ignore:
Timestamp:
Dec 14, 2015, 2:01:49 PM (4 years ago)
Author:
cameron
Message:

Move AVX2 specific IDISA function implementations into subclassed builder

Location:
icGREP/icgrep-devel/icgrep/pablo
Files:
2 edited

Legend:

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

    r4873 r4892  
    1616#include <sstream>
    1717#include <IDISA/idisa_builder.h>
     18#include <IDISA/idisa_avx_builder.h>
    1819#include <llvm/IR/Verifier.h>
    1920#include <llvm/Pass.h>
     
    6061, mCarryManager(nullptr)
    6162, mBitBlockType(bitBlockType)
    62 , iBuilder(mBitBlockType)
     63, iBuilder(nullptr)
    6364, mInputType(nullptr)
    6465, mWhileDepth(0)
     
    6869, mOutputAddressPtr(nullptr)
    6970, mMaxWhileDepth(0) {
     71   
     72   
    7073
    7174}
     
    9093}
    9194
     95// Dynamic AVX2 confirmation
     96#if (BLOCK_SIZE == 256)
     97#define ISPC_LLVM_VERSION ISPC_LLVM_3_6
     98#include <ispc.cpp>
     99#endif
     100   
    92101llvm::Function * PabloCompiler::compile(PabloFunction * function, Module * module) {
    93102
     
    103112    mBuilder = new IRBuilder<>(mMod->getContext());
    104113
    105     iBuilder.initialize(mMod, mBuilder);
    106 
    107     mCarryManager = new CarryManager(mBuilder, &iBuilder);
     114#if (BLOCK_SIZE == 256)
     115    if ((strncmp(lGetSystemISA(), "avx2", 4) == 0)) {
     116        iBuilder = new IDISA::IDISA_AVX2_Builder(mBitBlockType);
     117        //std::cerr << "IDISA_AVX2_Builder selected\n";
     118    }
     119    else{
     120        iBuilder = new IDISA::IDISA_Builder(mBitBlockType);
     121        //std::cerr << "Generic IDISA_Builder selected\n";
     122    }
     123#else   
     124    iBuilder = new IDISA::IDISA_Builder(mBitBlockType);
     125#endif
     126    iBuilder->initialize(mMod, mBuilder);
     127
     128    mCarryManager = new CarryManager(mBuilder, iBuilder);
    108129   
    109130    GenerateFunction(*function);
     
    115136        Value* indices[] = {mBuilder->getInt64(0), mBuilder->getInt32(i)};
    116137        Value * gep = mBuilder->CreateGEP(mInputAddressPtr, indices);
    117         LoadInst * basisBit = mBuilder->CreateAlignedLoad(gep, iBuilder.getBitBlockWidth()/8, false, function->getParameter(i)->getName()->to_string());
     138        LoadInst * basisBit = mBuilder->CreateAlignedLoad(gep, iBuilder->getBitBlockWidth()/8, false, function->getParameter(i)->getName()->to_string());
    118139        mMarkerMap[function->getParameter(i)] = basisBit;
    119140        if (DumpTrace) {
    120             iBuilder.genPrintRegister(function->getParameter(i)->getName()->to_string(), basisBit);
     141            iBuilder->genPrintRegister(function->getParameter(i)->getName()->to_string(), basisBit);
    121142        }
    122143    }
     
    135156
    136157    if (DumpTrace) {
    137         iBuilder.genPrintRegister("mBlockNo", mBuilder->CreateAlignedLoad(mBuilder->CreateBitCast(mCarryManager->getBlockNoPtr(), PointerType::get(mBitBlockType, 0)), iBuilder.getBitBlockWidth()/8, false));
     158        iBuilder->genPrintRegister("mBlockNo", mBuilder->CreateAlignedLoad(mBuilder->CreateBitCast(mCarryManager->getBlockNoPtr(), PointerType::get(mBitBlockType, 0)), iBuilder->getBitBlockWidth()/8, false));
    138159    }
    139160   
     
    149170    // Clean up
    150171    delete mCarryManager; mCarryManager = nullptr;
     172    delete iBuilder; iBuilder = nullptr;
    151173    delete mBuilder; mBuilder = nullptr;
    152174    mMod = nullptr; // don't delete this. It's either owned by the ExecutionEngine or the calling function.
     
    260282        auto f = mMarkerMap.find(assign);
    261283        assert (f != mMarkerMap.end());
    262         phi->addIncoming(iBuilder.allZeroes(), ifEntryBlock);
     284        phi->addIncoming(iBuilder->allZeroes(), ifEntryBlock);
    263285        phi->addIncoming(f->second, ifBodyFinalBlock);
    264286        mMarkerMap[assign] = phi;
     
    323345
    324346    // Terminate the while loop body with a conditional branch back.
    325     mBuilder->CreateCondBr(iBuilder.bitblock_any(compileExpression(whileStatement->getCondition())), whileBodyBlock, whileEndBlock);
     347    mBuilder->CreateCondBr(iBuilder->bitblock_any(compileExpression(whileStatement->getCondition())), whileBodyBlock, whileEndBlock);
    326348
    327349    // and for any Next nodes in the loop body
     
    388410        mBuilder->CreateCall2(externalFunction, mInputAddressPtr, outputStruct);
    389411        Value * outputPtr = mBuilder->CreateGEP(outputStruct, std::vector<Value *>({ mBuilder->getInt32(0), mBuilder->getInt32(0) }));
    390         expr = mBuilder->CreateAlignedLoad(outputPtr, iBuilder.getBitBlockWidth() / 8, false);
     412        expr = mBuilder->CreateAlignedLoad(outputPtr, iBuilder->getBitBlockWidth() / 8, false);
    391413    }
    392414    else if (const And * pablo_and = dyn_cast<And>(stmt)) {
    393         expr = iBuilder.simd_and(compileExpression(pablo_and->getOperand(0)), compileExpression(pablo_and->getOperand(1)));
     415        expr = iBuilder->simd_and(compileExpression(pablo_and->getOperand(0)), compileExpression(pablo_and->getOperand(1)));
    394416    }
    395417    else if (const Or * pablo_or = dyn_cast<Or>(stmt)) {
    396         expr = iBuilder.simd_or(compileExpression(pablo_or->getOperand(0)), compileExpression(pablo_or->getOperand(1)));
     418        expr = iBuilder->simd_or(compileExpression(pablo_or->getOperand(0)), compileExpression(pablo_or->getOperand(1)));
    397419    }
    398420    else if (const Xor * pablo_xor = dyn_cast<Xor>(stmt)) {
    399         expr = iBuilder.simd_xor(compileExpression(pablo_xor->getOperand(0)), compileExpression(pablo_xor->getOperand(1)));
     421        expr = iBuilder->simd_xor(compileExpression(pablo_xor->getOperand(0)), compileExpression(pablo_xor->getOperand(1)));
    400422    }
    401423    else if (const Sel * sel = dyn_cast<Sel>(stmt)) {
    402424        Value* ifMask = compileExpression(sel->getCondition());
    403         Value* ifTrue = iBuilder.simd_and(ifMask, compileExpression(sel->getTrueExpr()));
    404         Value* ifFalse = iBuilder.simd_and(iBuilder.simd_not(ifMask), compileExpression(sel->getFalseExpr()));
    405         expr = iBuilder.simd_or(ifTrue, ifFalse);
     425        Value* ifTrue = iBuilder->simd_and(ifMask, compileExpression(sel->getTrueExpr()));
     426        Value* ifFalse = iBuilder->simd_and(iBuilder->simd_not(ifMask), compileExpression(sel->getFalseExpr()));
     427        expr = iBuilder->simd_or(ifTrue, ifFalse);
    406428    }
    407429    else if (const Not * pablo_not = dyn_cast<Not>(stmt)) {
    408         expr = iBuilder.simd_not(compileExpression(pablo_not->getExpr()));
     430        expr = iBuilder->simd_not(compileExpression(pablo_not->getExpr()));
    409431    }
    410432    else if (const Advance * adv = dyn_cast<Advance>(stmt)) {
     
    417439        Value* strm_value = compileExpression(adv->getExpr());
    418440        int shift = adv->getAdvanceAmount();
    419         expr = iBuilder.simd_slli(64, strm_value, shift);
     441        expr = iBuilder->simd_slli(64, strm_value, shift);
    420442    }
    421443    else if (const MatchStar * mstar = dyn_cast<MatchStar>(stmt)) {
    422444        Value * marker = compileExpression(mstar->getMarker());
    423445        Value * cc = compileExpression(mstar->getCharClass());
    424         Value * marker_and_cc = iBuilder.simd_and(marker, cc);
     446        Value * marker_and_cc = iBuilder->simd_and(marker, cc);
    425447        unsigned carry_index = mstar->getLocalCarryIndex();
    426448        Value * sum = mCarryManager->addCarryInCarryOut(carry_index, marker_and_cc, cc);
    427         expr = iBuilder.simd_or(iBuilder.simd_xor(sum, cc), marker);
     449        expr = iBuilder->simd_or(iBuilder->simd_xor(sum, cc), marker);
    428450    }
    429451    else if (const Mod64MatchStar * mstar = dyn_cast<Mod64MatchStar>(stmt)) {
    430452        Value * marker = compileExpression(mstar->getMarker());
    431453        Value * cc = compileExpression(mstar->getCharClass());
    432         Value * marker_and_cc = iBuilder.simd_and(marker, cc);
    433         Value * sum = iBuilder.simd_add(64, marker_and_cc, cc);
    434         expr = iBuilder.simd_or(iBuilder.simd_xor(sum, cc), marker);
     454        Value * marker_and_cc = iBuilder->simd_and(marker, cc);
     455        Value * sum = iBuilder->simd_add(64, marker_and_cc, cc);
     456        expr = iBuilder->simd_or(iBuilder->simd_xor(sum, cc), marker);
    435457    }
    436458    else if (const ScanThru * sthru = dyn_cast<ScanThru>(stmt)) {
     
    439461        unsigned carry_index = sthru->getLocalCarryIndex();
    440462        Value * sum = mCarryManager->addCarryInCarryOut(carry_index, marker_expr, cc_expr);
    441         expr = iBuilder.simd_and(sum, iBuilder.simd_not(cc_expr));
     463        expr = iBuilder->simd_and(sum, iBuilder->simd_not(cc_expr));
    442464    }
    443465    else if (const Mod64ScanThru * sthru = dyn_cast<Mod64ScanThru>(stmt)) {
    444466        Value * marker_expr = compileExpression(sthru->getScanFrom());
    445467        Value * cc_expr = compileExpression(sthru->getScanThru());
    446         Value * sum = iBuilder.simd_add(64, marker_expr, cc_expr);
    447         expr = iBuilder.simd_and(sum, iBuilder.simd_not(cc_expr));
     468        Value * sum = iBuilder->simd_add(64, marker_expr, cc_expr);
     469        expr = iBuilder->simd_and(sum, iBuilder->simd_not(cc_expr));
    448470    }
    449471    else if (const Count * c = dyn_cast<Count>(stmt)) {
     
    459481    mMarkerMap[stmt] = expr;
    460482    if (DumpTrace) {
    461         iBuilder.genPrintRegister(stmt->getName()->to_string(), expr);
     483        iBuilder->genPrintRegister(stmt->getName()->to_string(), expr);
    462484    }
    463485   
     
    466488Value * PabloCompiler::compileExpression(const PabloAST * expr) {
    467489    if (isa<Ones>(expr)) {
    468         return iBuilder.allOnes();
     490        return iBuilder->allOnes();
    469491    }
    470492    else if (isa<Zeroes>(expr)) {
    471         return iBuilder.allZeroes();
     493        return iBuilder->allZeroes();
    472494    }
    473495    auto f = mMarkerMap.find(expr);
     
    488510    }
    489511    if (LLVM_UNLIKELY(marker->getType()->isPointerTy())) {
    490         marker = mBuilder->CreateAlignedLoad(marker, iBuilder.getBitBlockWidth()/8, false);
     512        marker = mBuilder->CreateAlignedLoad(marker, iBuilder->getBitBlockWidth()/8, false);
    491513    }
    492514    Value* indices[] = {mBuilder->getInt64(0), mBuilder->getInt32(index)};
     
    495517        marker = mBuilder->CreateBitCast(marker, mBitBlockType);
    496518    }
    497     mBuilder->CreateAlignedStore(marker, gep, iBuilder.getBitBlockWidth()/8, false);
    498 }
    499 
    500 }
     519    mBuilder->CreateAlignedStore(marker, gep, iBuilder->getBitBlockWidth()/8, false);
     520}
     521
     522}
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.h

    r4870 r4892  
    103103
    104104    Type* const                   mBitBlockType;
    105     IDISA::IDISA_Builder                iBuilder;
     105    IDISA::IDISA_Builder *              iBuilder;
    106106    PointerType*                        mInputType;
    107107
Note: See TracChangeset for help on using the changeset viewer.