Ignore:
Timestamp:
May 10, 2017, 4:26:11 PM (2 years ago)
Author:
nmedfort
Message:

Large refactoring step. Removed IR generation code from Kernel (formally KernelBuilder?) and moved it into the new KernelBuilder? class.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/editd/editdscan_kernel.cpp

    r5436 r5440  
    1313namespace kernel {
    1414
    15 void editdScanKernel::generateDoBlockMethod() {
    16     auto savePoint = iBuilder->saveIP();
    17     Function * scanWordFunction = generateScanWordRoutine(iBuilder->getModule());
    18     iBuilder->restoreIP(savePoint);
     15void editdScanKernel::generateDoBlockMethod(const std::unique_ptr<kernel::KernelBuilder> & idb) {
     16    auto savePoint = idb->saveIP();
     17    Function * scanWordFunction = generateScanWordRoutine(idb);
     18    idb->restoreIP(savePoint);
    1919
    20     const unsigned fieldCount = iBuilder->getBitBlockWidth() / mScanwordBitWidth;
    21     Type * T = iBuilder->getIntNTy(mScanwordBitWidth);
     20    const unsigned fieldCount = idb->getBitBlockWidth() / mScanwordBitWidth;
     21    Type * T = idb->getIntNTy(mScanwordBitWidth);
    2222    VectorType * scanwordVectorType =  VectorType::get(T, fieldCount);
    23     Value * blockNo = getScalarField("BlockNo");
    24     Value * scanwordPos = iBuilder->CreateMul(blockNo, ConstantInt::get(blockNo->getType(), iBuilder->getBitBlockWidth()));
     23    Value * blockNo = idb->getScalarField("BlockNo");
     24    Value * scanwordPos = idb->CreateMul(blockNo, ConstantInt::get(blockNo->getType(), idb->getBitBlockWidth()));
    2525   
    2626    std::vector<Value * > matchWordVectors;
    2727    for(unsigned d = 0; d <= mEditDistance; d++) {
    28         Value * matches = loadInputStreamBlock("matchResults", iBuilder->getInt32(d));
    29         matchWordVectors.push_back(iBuilder->CreateBitCast(matches, scanwordVectorType));
     28        Value * matches = idb->loadInputStreamBlock("matchResults", idb->getInt32(d));
     29        matchWordVectors.push_back(idb->CreateBitCast(matches, scanwordVectorType));
    3030    }
    3131   
    3232    for(unsigned i = 0; i < fieldCount; ++i) {
    3333        for(unsigned d = 0; d <= mEditDistance; d++) {
    34             Value * matchWord = iBuilder->CreateExtractElement(matchWordVectors[d], ConstantInt::get(T, i));
    35             iBuilder->CreateCall(scanWordFunction, {matchWord, iBuilder->getInt32(d), scanwordPos});
     34            Value * matchWord = idb->CreateExtractElement(matchWordVectors[d], ConstantInt::get(T, i));
     35            idb->CreateCall(scanWordFunction, {matchWord, idb->getInt32(d), scanwordPos});
    3636        }
    37         scanwordPos = iBuilder->CreateAdd(scanwordPos, ConstantInt::get(T, mScanwordBitWidth));
     37        scanwordPos = idb->CreateAdd(scanwordPos, ConstantInt::get(T, mScanwordBitWidth));
    3838    }
    3939
    40     setScalarField("BlockNo", iBuilder->CreateAdd(blockNo, iBuilder->getSize(1)));
     40    idb->setScalarField("BlockNo", idb->CreateAdd(blockNo, idb->getSize(1)));
    4141}
    4242
    43 Function * editdScanKernel::generateScanWordRoutine(Module * m) const {
     43Function * editdScanKernel::generateScanWordRoutine(const std::unique_ptr<KernelBuilder> &iBuilder) const {
    4444
    4545    IntegerType * T = iBuilder->getIntNTy(mScanwordBitWidth);
     46    Module * const m = iBuilder->getModule();
    4647
    4748    Function * scanFunc = cast<Function>(m->getOrInsertFunction("scan_word", iBuilder->getVoidTy(), T, iBuilder->getInt32Ty(), T, nullptr));
     
    5758
    5859    Constant * matchProcessor = m->getOrInsertFunction("wrapped_report_pos", iBuilder->getVoidTy(), T, iBuilder->getInt32Ty(), nullptr);
    59 
    60     BasicBlock * entryBlock = BasicBlock::Create(m->getContext(), "entry", scanFunc, 0);
    61 
    62     BasicBlock * matchesCondBlock = BasicBlock::Create(m->getContext(), "matchesCond", scanFunc, 0);
    63     BasicBlock * matchesLoopBlock = BasicBlock::Create(m->getContext(), "matchesLoop", scanFunc, 0);
    64     BasicBlock * matchesDoneBlock = BasicBlock::Create(m->getContext(), "matchesDone", scanFunc, 0);
     60    BasicBlock * entryBlock = BasicBlock::Create(iBuilder->getContext(), "entry", scanFunc, 0);
     61    BasicBlock * matchesCondBlock = BasicBlock::Create(iBuilder->getContext(), "matchesCond", scanFunc, 0);
     62    BasicBlock * matchesLoopBlock = BasicBlock::Create(iBuilder->getContext(), "matchesLoop", scanFunc, 0);
     63    BasicBlock * matchesDoneBlock = BasicBlock::Create(iBuilder->getContext(), "matchesDone", scanFunc, 0);
    6564
    6665    iBuilder->SetInsertPoint(entryBlock);
Note: See TracChangeset for help on using the changeset viewer.