Ignore:
Timestamp:
Mar 11, 2016, 4:44:53 PM (4 years ago)
Author:
nmedfort
Message:

Added ability to name internal state types; removed unnecessary predefined states. Some progress towards supporting segment size > 1

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/kernels/scanmatchgen.cpp

    r4959 r4970  
    3737}
    3838
    39 Function * generateScanWordRoutine(Module * m, IDISA::IDISA_Builder * iBuilder, unsigned scanwordBitWidth, Type * kernelStuctType, bool isNameExpression) {
     39Function * generateScanWordRoutine(Module * m, IDISA::IDISA_Builder * iBuilder, unsigned scanwordBitWidth, KernelBuilder * const kBuilder, bool isNameExpression) {
    4040
    4141    Function * function = m->getFunction("scan_matches_in_scanword");
     
    4848    Type * S = PointerType::get(iBuilder->getIntNTy(8), 0);
    4949    Type * returnType = StructType::get(ctxt, std::vector<Type *>({T, T}));
    50     FunctionType * functionType = FunctionType::get(returnType, std::vector<Type *>({kernelStuctType, T, T, T, T, T}), false);
     50    FunctionType * functionType = FunctionType::get(returnType, std::vector<Type *>({PointerType::get(kBuilder->getKernelStructType(), 0), T, T, T, T, T}), false);
    5151
    5252    SmallVector<AttributeSet, 6> Attrs;
     
    7777    Value * recordNum_input_parm = args++;
    7878    recordNum_input_parm->setName("lineNum");
     79
    7980    Constant * matchProcessor;
    80     if(isNameExpression)
     81    if (isNameExpression) {
    8182        matchProcessor = m->getOrInsertFunction("insert_codepoints", Type::getVoidTy(ctxt), T, T, T, S, nullptr);
    82     else
     83    } else {
    8384        matchProcessor = m->getOrInsertFunction("wrapped_report_match", Type::getVoidTy(ctxt), T, T, T, S, T, S, nullptr);
    84 
     85    }
    8586    iBuilder->SetInsertPoint(BasicBlock::Create(ctxt, "entry", function,0));
    8687
     
    147148    matchRecordNum_phi->addIncoming(matchRecordNum, prior_breaks_block);
    148149    matchRecordStart_phi->addIncoming(recordStart_phi, process_matches_loop_entry);
    149     matchRecordStart_phi->addIncoming(matchRecordStart, prior_breaks_block);
     150    matchRecordStart_phi->addIncoming(matchRecordStart, prior_breaks_block);   
    150151    Value * matchRecordEnd = iBuilder->CreateAdd(scanwordPos, generateCountForwardZeroes(iBuilder, matches_phi));
    151152
    152     Value* filebuf_gep = iBuilder->CreateGEP(this_input_parm, {iBuilder->getInt64(0), iBuilder->getInt32(0), iBuilder->getInt32(7)});
     153    Value* filebuf_gep = kBuilder->getInternalState("FileBuf", this_input_parm);
    153154    Value* filebufptr = iBuilder->CreateLoad(filebuf_gep, "filebuf");
    154155
    155     Value* filesize_gep = iBuilder->CreateGEP(this_input_parm, {iBuilder->getInt64(0), iBuilder->getInt32(0), iBuilder->getInt32(8)});
    156     Value* filesize = iBuilder->CreateLoad(filesize_gep, "filensize");
    157 
    158     Value* filename_gep = iBuilder->CreateGEP(this_input_parm, {iBuilder->getInt64(0), iBuilder->getInt32(0), iBuilder->getInt32(9)});
    159     Value* filenameptr = iBuilder->CreateLoad(filename_gep, "filename");
    160 
    161     if(isNameExpression)
     156    if (isNameExpression) {
    162157        iBuilder->CreateCall(matchProcessor, std::vector<Value *>({matchRecordNum_phi, matchRecordStart_phi, matchRecordEnd, filebufptr}));
    163     else
     158    } else {
     159        Value * filesize_gep = kBuilder->getInternalState("FileSize", this_input_parm);
     160        Value * filesize = iBuilder->CreateLoad(filesize_gep, "filesize");
     161
     162        Value * filename_gep = kBuilder->getInternalState("FileName", this_input_parm);
     163        Value * filenameptr = iBuilder->CreateLoad(filename_gep, "filename");
     164
    164165        iBuilder->CreateCall(matchProcessor, std::vector<Value *>({matchRecordNum_phi, matchRecordStart_phi, matchRecordEnd, filebufptr, filesize, filenameptr}));
     166    }
     167
    165168    Value * remaining_matches = generateResetLowestBit(iBuilder, matches_phi);
    166169    Value * remaining_breaks = iBuilder->CreateXor(record_breaks_phi, prior_breaks);
     
    203206
    204207
    205 void generateScanMatch(Module * m, IDISA::IDISA_Builder * iBuilder, unsigned scanWordBitWidth, KernelBuilder * kBuilder, bool isNameExpression){
     208void generateScanMatch(Module * m, IDISA::IDISA_Builder * iBuilder, unsigned scanWordBitWidth, KernelBuilder * kBuilder, bool isNameExpression) {
    206209
    207210
     
    214217    kBuilder->addInputStream(1, "breaks");
    215218    //use index
    216     unsigned blockPosIdx = kBuilder->addInternalStateType(T);
    217     unsigned lineStartIdx = kBuilder->addInternalStateType(T);
    218     unsigned lineNumIdx = kBuilder->addInternalStateType(T);
    219     kBuilder->addInternalStateType(S);
    220     kBuilder->addInternalStateType(T);
    221     kBuilder->addInternalStateType(S);
     219    const unsigned lineStart = kBuilder->addInternalState(T, "LineStart");
     220    const unsigned lineNum = kBuilder->addInternalState(T, "LineNum");
     221    kBuilder->addInternalState(S, "FileBuf");
     222    kBuilder->addInternalState(T, "FileSize");
     223    kBuilder->addInternalState(S, "FileName");
    222224
    223225    Function * function = kBuilder->prepareFunction();
    224226
    225     Type * kernelStuctType = PointerType::get(kBuilder->getKernelStructType(), 0);
    226 
    227     Function * scanWordFunction = generateScanWordRoutine(m, iBuilder, scanWordBitWidth, kernelStuctType, isNameExpression);
     227    // Type * kernelStuctType = PointerType::get(kBuilder->getKernelStructType(), 0);
     228
     229    Function * scanWordFunction = generateScanWordRoutine(m, iBuilder, scanWordBitWidth, kBuilder, isNameExpression);
    228230
    229231    iBuilder->SetInsertPoint(&function->getEntryBlock());
     
    231233    Value * kernelStuctParam = kBuilder->getKernelStructParam();
    232234
    233     Value * scanwordPos = iBuilder->CreateBlockAlignedLoad(kBuilder->getInternalState(blockPosIdx));
    234     Value * recordStart = iBuilder->CreateBlockAlignedLoad(kBuilder->getInternalState(lineStartIdx));
    235     Value * recordNum = iBuilder->CreateBlockAlignedLoad(kBuilder->getInternalState(lineNumIdx));
     235    Value * scanwordPos = iBuilder->CreateBlockAlignedLoad(kBuilder->getInternalState("BlockNo"));
     236    scanwordPos = iBuilder->CreateMul(scanwordPos, ConstantInt::get(scanwordPos->getType(), iBuilder->getBitBlockWidth()));
     237
     238    Value * recordStart = iBuilder->CreateBlockAlignedLoad(kBuilder->getInternalState(lineStart));
     239    Value * recordNum = iBuilder->CreateBlockAlignedLoad(kBuilder->getInternalState(lineNum));
     240
    236241    Value * wordResult = nullptr;
    237242
    238243    const unsigned segmentBlocks = kBuilder->getSegmentBlocks();
    239244    const unsigned scanWordBlocks =  segmentBlocks * fieldCount;
    240 
    241245    for(unsigned j = 0; j < segmentBlocks; ++j) {
    242 
    243246        Value * matchWordVector = iBuilder->CreateBitCast(iBuilder->CreateBlockAlignedLoad(kBuilder->getInputStream(0)), scanwordVectorType);
    244247        Value * breakWordVector = iBuilder->CreateBitCast(iBuilder->CreateBlockAlignedLoad(kBuilder->getInputStream(1)), scanwordVectorType);
    245 
    246248        for(unsigned i = 0; i < scanWordBlocks; ++i){
    247249            Value * matchWord = iBuilder->CreateExtractElement(matchWordVector, ConstantInt::get(T, i));
     
    254256        kBuilder->increment();
    255257    }
    256 
    257     kBuilder->setInternalState(blockPosIdx, scanwordPos);
    258     kBuilder->setInternalState(lineStartIdx, recordStart);
    259     kBuilder->setInternalState(lineNumIdx, recordNum);
    260 
     258    kBuilder->setInternalState(lineStart, recordStart);
     259    kBuilder->setInternalState(lineNum, recordNum);
    261260    kBuilder->finalize();
    262261}
Note: See TracChangeset for help on using the changeset viewer.