Ignore:
Timestamp:
Dec 23, 2015, 11:47:47 AM (3 years ago)
Author:
cameron
Message:

Add IRBuilder functionality to IDISA_Builder; eliminate separate mBuilder

File:
1 edited

Legend:

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

    r4892 r4898  
    5858PabloCompiler::PabloCompiler(Type * bitBlockType)
    5959: mMod(nullptr)
    60 , mBuilder(nullptr)
    6160, mCarryManager(nullptr)
    6261, mBitBlockType(bitBlockType)
     
    110109    mMod = module;
    111110
    112     mBuilder = new IRBuilder<>(mMod->getContext());
    113 
    114111#if (BLOCK_SIZE == 256)
    115112    if ((strncmp(lGetSystemISA(), "avx2", 4) == 0)) {
    116         iBuilder = new IDISA::IDISA_AVX2_Builder(mBitBlockType);
     113        iBuilder = new IDISA::IDISA_AVX2_Builder(mMod, mBitBlockType);
    117114        //std::cerr << "IDISA_AVX2_Builder selected\n";
    118115    }
    119116    else{
    120         iBuilder = new IDISA::IDISA_Builder(mBitBlockType);
     117        iBuilder = new IDISA::IDISA_Builder(mMod, mBitBlockType);
    121118        //std::cerr << "Generic IDISA_Builder selected\n";
    122119    }
    123120#else   
    124     iBuilder = new IDISA::IDISA_Builder(mBitBlockType);
     121    iBuilder = new IDISA::IDISA_Builder(mMod, mBitBlockType);
    125122#endif
    126     iBuilder->initialize(mMod, mBuilder);
    127 
    128     mCarryManager = new CarryManager(mBuilder, iBuilder);
     123
     124    mCarryManager = new CarryManager(iBuilder);
    129125   
    130126    GenerateFunction(*function);
    131127   
    132     mBuilder->SetInsertPoint(BasicBlock::Create(mMod->getContext(), "entry", mFunction,0));
     128    iBuilder->SetInsertPoint(BasicBlock::Create(mMod->getContext(), "entry", mFunction,0));
    133129
    134130    //The basis bits structure
    135131    for (unsigned i = 0; i != function->getNumOfParameters(); ++i) {
    136         Value* indices[] = {mBuilder->getInt64(0), mBuilder->getInt32(i)};
    137         Value * gep = mBuilder->CreateGEP(mInputAddressPtr, indices);
    138         LoadInst * basisBit = mBuilder->CreateAlignedLoad(gep, iBuilder->getBitBlockWidth()/8, false, function->getParameter(i)->getName()->to_string());
     132        Value* indices[] = {iBuilder->getInt64(0), iBuilder->getInt32(i)};
     133        Value * gep = iBuilder->CreateGEP(mInputAddressPtr, indices);
     134        LoadInst * basisBit = iBuilder->CreateAlignedLoad(gep, iBuilder->getBitBlockWidth()/8, false, function->getParameter(i)->getName()->to_string());
    139135        mMarkerMap[function->getParameter(i)] = basisBit;
    140136        if (DumpTrace) {
     
    156152
    157153    if (DumpTrace) {
    158         iBuilder->genPrintRegister("mBlockNo", mBuilder->CreateAlignedLoad(mBuilder->CreateBitCast(mCarryManager->getBlockNoPtr(), PointerType::get(mBitBlockType, 0)), iBuilder->getBitBlockWidth()/8, false));
     154        iBuilder->genPrintRegister("mBlockNo", iBuilder->CreateAlignedLoad(iBuilder->CreateBitCast(mCarryManager->getBlockNoPtr(), PointerType::get(mBitBlockType, 0)), iBuilder->getBitBlockWidth()/8, false));
    159155    }
    160156   
     
    166162
    167163    //Terminate the block
    168     ReturnInst::Create(mMod->getContext(), mBuilder->GetInsertBlock());
     164    ReturnInst::Create(mMod->getContext(), iBuilder->GetInsertBlock());
    169165   
    170166    // Clean up
    171167    delete mCarryManager; mCarryManager = nullptr;
    172168    delete iBuilder; iBuilder = nullptr;
    173     delete mBuilder; mBuilder = nullptr;
     169    delete iBuilder; iBuilder = nullptr;
    174170    mMod = nullptr; // don't delete this. It's either owned by the ExecutionEngine or the calling function.
    175171
     
    253249    //
    254250
    255     BasicBlock * ifEntryBlock = mBuilder->GetInsertBlock();
     251    BasicBlock * ifEntryBlock = iBuilder->GetInsertBlock();
    256252    BasicBlock * ifBodyBlock = BasicBlock::Create(mMod->getContext(), "if.body", mFunction, 0);
    257253    BasicBlock * ifEndBlock = BasicBlock::Create(mMod->getContext(), "if.end", mFunction, 0);
     
    262258   
    263259    mCarryManager->enterScope(ifBody);
    264     mBuilder->CreateCondBr(mCarryManager->generateBitBlockOrSummaryTest(if_test_value), ifBodyBlock, ifEndBlock);
     260    iBuilder->CreateCondBr(mCarryManager->generateBitBlockOrSummaryTest(if_test_value), ifBodyBlock, ifEndBlock);
    265261   
    266262    // Entry processing is complete, now handle the body of the if.
    267     mBuilder->SetInsertPoint(ifBodyBlock);
     263    iBuilder->SetInsertPoint(ifBodyBlock);
    268264   
    269265    mCarryManager->initializeCarryDataAtIfEntry();
     
    272268        mCarryManager->generateCarryOutSummaryCodeIfNeeded();
    273269    }
    274     BasicBlock * ifBodyFinalBlock = mBuilder->GetInsertBlock();
     270    BasicBlock * ifBodyFinalBlock = iBuilder->GetInsertBlock();
    275271    mCarryManager->ensureCarriesStoredLocal();
    276     mBuilder->CreateBr(ifEndBlock);
     272    iBuilder->CreateBr(ifEndBlock);
    277273    //End Block
    278     mBuilder->SetInsertPoint(ifEndBlock);
     274    iBuilder->SetInsertPoint(ifEndBlock);
    279275    for (const PabloAST * node : ifStatement->getDefined()) {
    280276        const Assign * assign = cast<Assign>(node);
    281         PHINode * phi = mBuilder->CreatePHI(mBitBlockType, 2, assign->getName()->value());
     277        PHINode * phi = iBuilder->CreatePHI(mBitBlockType, 2, assign->getName()->value());
    282278        auto f = mMarkerMap.find(assign);
    283279        assert (f != mMarkerMap.end());
     
    295291    PabloBlock * const whileBody = whileStatement->getBody();
    296292   
    297     BasicBlock * whileEntryBlock = mBuilder->GetInsertBlock();
     293    BasicBlock * whileEntryBlock = iBuilder->GetInsertBlock();
    298294    BasicBlock * whileBodyBlock = BasicBlock::Create(mMod->getContext(), "while.body", mFunction, 0);
    299295    BasicBlock * whileEndBlock = BasicBlock::Create(mMod->getContext(), "while.end", mFunction, 0);
     
    310306    // the loop.
    311307
    312     mBuilder->CreateBr(whileBodyBlock);
    313     mBuilder->SetInsertPoint(whileBodyBlock);
     308    iBuilder->CreateBr(whileBodyBlock);
     309    iBuilder->SetInsertPoint(whileBodyBlock);
    314310
    315311    //
     
    323319    // for any Next nodes in the loop body, initialize to (a) pre-loop value.
    324320    for (const Next * n : nextNodes) {
    325         PHINode * phi = mBuilder->CreatePHI(mBitBlockType, 2, n->getName()->value());
     321        PHINode * phi = iBuilder->CreatePHI(mBitBlockType, 2, n->getName()->value());
    326322        auto f = mMarkerMap.find(n->getInitial());
    327323        assert (f != mMarkerMap.end());
     
    337333    compileBlock(whileBody);
    338334
    339     BasicBlock * whileBodyFinalBlock = mBuilder->GetInsertBlock();
     335    BasicBlock * whileBodyFinalBlock = iBuilder->GetInsertBlock();
    340336
    341337    if (mCarryManager->blockHasCarries()) {
     
    345341
    346342    // Terminate the while loop body with a conditional branch back.
    347     mBuilder->CreateCondBr(iBuilder->bitblock_any(compileExpression(whileStatement->getCondition())), whileBodyBlock, whileEndBlock);
     343    iBuilder->CreateCondBr(iBuilder->bitblock_any(compileExpression(whileStatement->getCondition())), whileBodyBlock, whileEndBlock);
    348344
    349345    // and for any Next nodes in the loop body
     
    357353    }
    358354
    359     mBuilder->SetInsertPoint(whileEndBlock);
     355    iBuilder->SetInsertPoint(whileEndBlock);
    360356    --mWhileDepth;
    361357
     
    407403
    408404
    409         AllocaInst * outputStruct = mBuilder->CreateAlloca(outputType);
    410         mBuilder->CreateCall2(externalFunction, mInputAddressPtr, outputStruct);
    411         Value * outputPtr = mBuilder->CreateGEP(outputStruct, std::vector<Value *>({ mBuilder->getInt32(0), mBuilder->getInt32(0) }));
    412         expr = mBuilder->CreateAlignedLoad(outputPtr, iBuilder->getBitBlockWidth() / 8, false);
     405        AllocaInst * outputStruct = iBuilder->CreateAlloca(outputType);
     406        iBuilder->CreateCall2(externalFunction, mInputAddressPtr, outputStruct);
     407        Value * outputPtr = iBuilder->CreateGEP(outputStruct, std::vector<Value *>({ iBuilder->getInt32(0), iBuilder->getInt32(0) }));
     408        expr = iBuilder->CreateAlignedLoad(outputPtr, iBuilder->getBitBlockWidth() / 8, false);
    413409    }
    414410    else if (const And * pablo_and = dyn_cast<And>(stmt)) {
     
    510506    }
    511507    if (LLVM_UNLIKELY(marker->getType()->isPointerTy())) {
    512         marker = mBuilder->CreateAlignedLoad(marker, iBuilder->getBitBlockWidth()/8, false);
    513     }
    514     Value* indices[] = {mBuilder->getInt64(0), mBuilder->getInt32(index)};
    515     Value* gep = mBuilder->CreateGEP(mOutputAddressPtr, indices);
     508        marker = iBuilder->CreateAlignedLoad(marker, iBuilder->getBitBlockWidth()/8, false);
     509    }
     510    Value* indices[] = {iBuilder->getInt64(0), iBuilder->getInt32(index)};
     511    Value* gep = iBuilder->CreateGEP(mOutputAddressPtr, indices);
    516512    if (marker->getType() != mBitBlockType) {
    517         marker = mBuilder->CreateBitCast(marker, mBitBlockType);
    518     }
    519     mBuilder->CreateAlignedStore(marker, gep, iBuilder->getBitBlockWidth()/8, false);
    520 }
    521 
    522 }
     513        marker = iBuilder->CreateBitCast(marker, mBitBlockType);
     514    }
     515    iBuilder->CreateAlignedStore(marker, gep, iBuilder->getBitBlockWidth()/8, false);
     516}
     517
     518}
Note: See TracChangeset for help on using the changeset viewer.