Ignore:
Timestamp:
Feb 20, 2016, 11:33:14 AM (4 years ago)
Author:
cameron
Message:

Revert scanmatchgen changes

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

Legend:

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

    r4935 r4936  
    44 */
    55
    6 #include "kernel.h"
     6
    77#include "scanmatchgen.h"
    88#include <llvm/IR/Intrinsics.h>
     
    3232    return iBuilder->CreateAnd(bits_minus1, bits);
    3333}
    34        
    35        
    36 void generateScanWordRoutine(Module * m, IDISA::IDISA_Builder * iBuilder, int scanwordBitWidth, Type * kernelStuctType) {
     34
     35/*
     36       
     37void write_matches_ending_in_segment(scanword_t matches, scanword_t lbreaks, ssize_t segmentPos, ssize_t & pendingLineStart, int & lineNum) {
     38    scanword_t remaining_matches = matches;
     39    scanword_t remaining_LBs = lbreaks;
     40    while (remaining_matches != 0) {
     41        // Find all the line marks prior to the match position
     42        scanword_t priorLineMarks = ForwardZeroesMask(remaining_matches) & remaining_LBs;
     43        if (priorLineMarks != 0) {
     44            int matchLineNum = lineNum + popcount(priorLineMarks);
     45            // The last of these line marks prior to the match position is the
     46            // starting positions of the matched line.
     47            matchLineStart = segmentPos + segmentBitWidth - CountReverseZeroes(priorLineMarks);
     48        }
     49        else {
     50            matchLineNum = lineNum;
     51            matchLineStart = pendingLineStart;
     52        }
     53        // The line end is marked by the match posiiton.
     54        matchLineEnd = segmentPos + CountForwardZeroes(remaining_matches);
     55        call write_match(matchLineNum, matchLineStart, matchLineEnd);
     56       
     57        remaining_matches = ResetLowestBit(remaining_matches);
     58        remaining_LBs = remaining_LBs ^ priorLineMarks;
     59        lineNum = matchLineNum;
     60    }
     61    if (remaining_LBs != 0) {
     62        lineNum += popcount(remaining_LBs);
     63        pendingLineStart = segmentPos + segmentBitWidth - CountReverseZeroes(remaining_LBs);
     64    }
     65}   
     66        */
     67
     68       
     69       
     70void generateScanSegmentRoutine(Module * m, IDISA::IDISA_Builder * iBuilder, int segBitWidth) {
    3771    LLVMContext & ctxt = m->getContext();
    38     Type * T = iBuilder->getIntNTy(scanwordBitWidth);   
    39     Type * S = PointerType::get(iBuilder->getIntNTy(8), 0);
     72    Type * T = iBuilder->getIntNTy(segBitWidth);
    4073    Type * returnType = StructType::get(ctxt, std::vector<Type *>({T, T}));
    41     FunctionType * functionType = FunctionType::get(returnType, std::vector<Type *>({kernelStuctType, T, T, T, T, T}), false);
     74    FunctionType * functionType = FunctionType::get(returnType, std::vector<Type *>({T, T, T, T, T}), false);
    4275    Function * sFunction;
    4376       
     
    5184    AttributeSet AttrSet = AttributeSet::get(ctxt, Attrs);
    5285   
    53     sFunction = Function::Create(functionType, GlobalValue::ExternalLinkage, "scan_matches_in_scanword", m);
     86    sFunction = Function::Create(functionType, GlobalValue::ExternalLinkage, "scan_matches_in_segment", m);
    5487    sFunction->setCallingConv(CallingConv::C);
    5588    sFunction->setAttributes(AttrSet);
    5689       
    5790    Function::arg_iterator args = sFunction->arg_begin();
    58     Value * this_input_parm = args++;
    59     this_input_parm->setName("this");
    6091    Value * matches_input_parm = args++;
    6192    matches_input_parm->setName("matches");
    6293    Value * record_breaks_input_parm = args++;
    6394    record_breaks_input_parm->setName("breaks");
    64     Value * scanwordPos = args++;
    65     scanwordPos->setName("scanwordPos");
     95    Value * segmentPos = args++;
     96    segmentPos->setName("segmentPos");
    6697    Value * recordStart_input_parm = args++;
    6798    recordStart_input_parm->setName("pendingLineStart");
     
    69100    recordNum_input_parm->setName("lineNum");
    70101   
    71     Constant * matchProcessor = m->getOrInsertFunction("wrapped_report_match", Type::getVoidTy(ctxt), T, T, T, S, T, S, NULL);
     102    Constant * matchProcessor = m->getOrInsertFunction("wrapped_report_match", Type::getVoidTy(ctxt), T, T, T, NULL);
     103
    72104   
    73105    iBuilder->SetInsertPoint(BasicBlock::Create(ctxt, "entry", sFunction,0));
     
    84116       
    85117    // The match scanner works with a loop involving four variables:
    86     // (a) the bit stream scanword of matches marking the ends of selected records,
    87     // (b) the bit stream scanword of record_breaks marking the ends of all records,
     118    // (a) the bit stream segment of matches marking the ends of selected records,
     119    // (b) the bit stream segment of record_breaks marking the ends of all records,
    88120    // (c) the integer lastRecordNum indicating the number of records processed so far,
    89121    // (d) the index lastRecordStart indicating the file position of the last record.
     
    122154    Value * matchRecordNum = iBuilder->CreateAdd(generatePopcount(iBuilder, prior_breaks), recordNum_phi);
    123155    Value * reverseDistance = generateCountReverseZeroes(iBuilder, prior_breaks);
    124     Value * width = ConstantInt::get(T, scanwordBitWidth);
    125     Value * matchRecordStart = iBuilder->CreateAdd(scanwordPos, iBuilder->CreateSub(width, reverseDistance));
     156    Value * width = ConstantInt::get(T, segBitWidth);
     157    Value * matchRecordStart = iBuilder->CreateAdd(segmentPos, iBuilder->CreateSub(width, reverseDistance));
    126158    iBuilder->CreateBr(loop_final_block);
    127159   
     
    136168    matchRecordStart_phi->addIncoming(recordStart_phi, process_matches_loop_entry);
    137169    matchRecordStart_phi->addIncoming(matchRecordStart, prior_breaks_block);
    138     Value * matchRecordEnd = iBuilder->CreateAdd(scanwordPos, generateCountForwardZeroes(iBuilder, matches_phi));
    139 
    140     Value* filebuf_gep = iBuilder->CreateGEP(this_input_parm, {iBuilder->getInt64(0), iBuilder->getInt32(0), iBuilder->getInt32(7)});
    141     Value* filebufptr = iBuilder->CreateLoad(filebuf_gep, "filebuf");
    142 
    143     Value* filesize_gep = iBuilder->CreateGEP(this_input_parm, {iBuilder->getInt64(0), iBuilder->getInt32(0), iBuilder->getInt32(8)});
    144     Value* filesize = iBuilder->CreateLoad(filesize_gep, "filensize");
    145 
    146     Value* filename_gep = iBuilder->CreateGEP(this_input_parm, {iBuilder->getInt64(0), iBuilder->getInt32(0), iBuilder->getInt32(9)});
    147     Value* filenameptr = iBuilder->CreateLoad(filename_gep, "filename");
    148 
    149     iBuilder->CreateCall(matchProcessor, std::vector<Value *>({matchRecordNum_phi, matchRecordStart_phi, matchRecordEnd, filebufptr, filesize, filenameptr}));
     170    Value * matchRecordEnd = iBuilder->CreateAdd(segmentPos, generateCountForwardZeroes(iBuilder, matches_phi));
     171    iBuilder->CreateCall(matchProcessor, std::vector<Value *>({matchRecordNum_phi, matchRecordStart_phi, matchRecordEnd}));
    150172    Value * remaining_matches = generateResetLowestBit(iBuilder, matches_phi);
    151173    Value * remaining_breaks = iBuilder->CreateXor(record_breaks_phi, prior_breaks);
     
    168190    Value * final_record_num = iBuilder->CreateAdd(recordNum_phi, break_count);
    169191    Value * reverseZeroes = generateCountReverseZeroes(iBuilder, record_breaks_phi);
    170     Value * pendingLineStart = iBuilder->CreateAdd(scanwordPos, iBuilder->CreateSub(width, reverseZeroes));
     192    Value * pendingLineStart = iBuilder->CreateAdd(segmentPos, iBuilder->CreateSub(width, reverseZeroes));
    171193    iBuilder->CreateBr(return_block);
    172194   
     
    180202    finalRecordStart_phi->addIncoming(pendingLineStart, remaining_breaks_block);
    181203    Value * retVal = UndefValue::get(returnType);
    182     retVal = iBuilder->CreateInsertValue(retVal, finalRecordStart_phi, 0);
    183     retVal = iBuilder->CreateInsertValue(retVal, finalRecordCount_phi, 1);
     204    retVal = iBuilder->CreateInsertValue(retVal, finalRecordCount_phi, 0);
     205    retVal = iBuilder->CreateInsertValue(retVal, finalRecordStart_phi, 1);
    184206    iBuilder->CreateRet(retVal);
    185207   
     
    187209
    188210
    189 void generateScanMatch(Module * m, IDISA::IDISA_Builder * iBuilder, int scanwordBitWidth, KernelBuilder * kBuilder){
    190    
    191    
    192     Type * T = iBuilder->getIntNTy(scanwordBitWidth);
    193     Type * S = PointerType::get(iBuilder->getIntNTy(8), 0);
    194     int fieldCount = iBuilder->getBitBlockWidth()/scanwordBitWidth;
    195     Type * scanwordVectorType =  VectorType::get(T, fieldCount);
    196 
    197     kBuilder->addKernelInputStream(1, "matches");
    198     kBuilder->addKernelInputStream(1, "breaks");
    199     //use index
    200     int blockPosIdx = kBuilder->extendKernelInternalStateType(T);
    201     int lineStartIdx = kBuilder->extendKernelInternalStateType(T);
    202     int lineNumIdx = kBuilder->extendKernelInternalStateType(T);
    203     int fileBufIdx = kBuilder->extendKernelInternalStateType(S);
    204     int bufSizeIdx = kBuilder->extendKernelInternalStateType(T);
    205     int fileNameIdx = kBuilder->extendKernelInternalStateType(S);
    206 
    207     int segBlocks = kBuilder->getSegmentBlocks();
    208 
    209     kBuilder->PrepareDoBlockFunction();
    210 
    211     Type * kernelStuctType = PointerType::get(kBuilder->getKernelStructType(), 0);
    212     generateScanWordRoutine(m, iBuilder, scanwordBitWidth, kernelStuctType);
    213 
    214     struct Inputs inputs = kBuilder->openDoBlock();
    215     struct Outputs outputs;   
    216     Value * kernelStuctParam = kBuilder->getKernelStructParam();
    217    
    218     Value * scanwordPos = kBuilder->getKernelInternalState(blockPosIdx);
    219     Value * recordStart = kBuilder->getKernelInternalState(lineStartIdx);
    220     Value * recordNum = kBuilder->getKernelInternalState(lineNumIdx);
    221     Value * wordResult = nullptr;
    222 
    223     Function * wordScanFcn = m->getFunction("scan_matches_in_scanword");
    224     for(int j=0; j<segBlocks; j++){
    225         Value * matchWordVector = iBuilder->CreateBitCast(inputs.streams[j][0], scanwordVectorType);
    226         Value * breakWordVector = iBuilder->CreateBitCast(inputs.streams[j][1], scanwordVectorType);
    227         for(int i=0; i<segBlocks*iBuilder->getBitBlockWidth()/scanwordBitWidth; i++){
    228 
    229             Value * matchWord = iBuilder->CreateExtractElement(matchWordVector, ConstantInt::get(T, i));
    230             Value * recordBreaksWord = iBuilder->CreateExtractElement(breakWordVector, ConstantInt::get(T, i));
    231             wordResult = iBuilder->CreateCall(wordScanFcn, std::vector<Value *>({kernelStuctParam, matchWord, recordBreaksWord, scanwordPos, recordStart, recordNum}));
    232             scanwordPos = iBuilder->CreateAdd(scanwordPos, ConstantInt::get(T, scanwordBitWidth));
    233             recordStart = iBuilder->CreateExtractValue(wordResult, std::vector<unsigned>({0}));
    234             recordNum = iBuilder->CreateExtractValue(wordResult, std::vector<unsigned>({1}));
    235         }
     211void generateScanBitBlockRoutine(Module * m, IDISA::IDISA_Builder * iBuilder, int segBitWidth) {
     212    LLVMContext & ctxt = m->getContext();
     213    Type * B = iBuilder->getBitBlockType();
     214    Type * T = iBuilder->getIntNTy(segBitWidth);
     215    generateScanSegmentRoutine(m, iBuilder, segBitWidth);
     216    int fieldCount = iBuilder->getBitBlockWidth()/segBitWidth;
     217    Type * segmentVectorType =  VectorType::get(T, fieldCount);
     218   
     219   
     220    Type * returnType = StructType::get(ctxt, std::vector<Type *>({T, T}));
     221    FunctionType * functionType = FunctionType::get(returnType, std::vector<Type *>({B, B, T, T, T}), false);
     222    Function * sFunction;
     223   
     224    SmallVector<AttributeSet, 6> Attrs;
     225    Attrs.push_back(AttributeSet::get(ctxt, ~0U, std::vector<Attribute::AttrKind>({ Attribute::NoUnwind, Attribute::UWTable })));
     226    Attrs.push_back(AttributeSet::get(ctxt, 1, std::vector<Attribute::AttrKind>({})));
     227    Attrs.push_back(AttributeSet::get(ctxt, 2, std::vector<Attribute::AttrKind>({})));
     228    Attrs.push_back(AttributeSet::get(ctxt, 3, std::vector<Attribute::AttrKind>({})));
     229    Attrs.push_back(AttributeSet::get(ctxt, 4, std::vector<Attribute::AttrKind>({})));
     230    Attrs.push_back(AttributeSet::get(ctxt, 5, std::vector<Attribute::AttrKind>({})));
     231    AttributeSet AttrSet = AttributeSet::get(ctxt, Attrs);
     232    sFunction = Function::Create(functionType, GlobalValue::ExternalLinkage, "scan_matches_in_bitblock", m);
     233    sFunction->setCallingConv(CallingConv::C);
     234    sFunction->setAttributes(AttrSet);
     235   
     236   
     237   
     238    Function::arg_iterator args = sFunction->arg_begin();
     239    Value * matches_input_parm = args++;
     240    matches_input_parm->setName("matches");
     241    Value * record_breaks_input_parm = args++;
     242    record_breaks_input_parm->setName("breaks");
     243    Value * blockPos = args++;
     244    blockPos->setName("blockPos");
     245    Value * recordStart_input_parm = args++;
     246    recordStart_input_parm->setName("pendingLineStart");
     247    Value * recordNum_input_parm = args++;
     248    recordNum_input_parm->setName("lineNum");
     249   
     250    iBuilder->SetInsertPoint(BasicBlock::Create(ctxt, "entry", sFunction,0));
     251   
     252    Value * matchSegVector = iBuilder->CreateBitCast(matches_input_parm, segmentVectorType);
     253    Value * breakSegVector = iBuilder->CreateBitCast(record_breaks_input_parm, segmentVectorType);
     254    Value * segmentPos = blockPos;
     255    Value * recordStart = recordStart_input_parm;
     256    Value * recordNum = recordNum_input_parm;
     257    Value * segResult = nullptr;
     258    Function * segScanFcn = m->getFunction("scan_matches_in_segment");
     259    for (uint64_t i = 0; i < iBuilder->getBitBlockWidth()/segBitWidth; i++) {
     260        Value * matchSeg = iBuilder->CreateExtractElement(matchSegVector, ConstantInt::get(T, i));
     261        Value * recordBreaksSeg = iBuilder->CreateExtractElement(breakSegVector, ConstantInt::get(T, i));
     262        segResult = iBuilder->CreateCall(segScanFcn, std::vector<Value *>({matchSeg, recordBreaksSeg, segmentPos, recordStart, recordNum}));
     263        segmentPos = iBuilder->CreateAdd(segmentPos, ConstantInt::get(T, segBitWidth));
     264        recordStart = iBuilder->CreateExtractValue(segResult, std::vector<unsigned>({0}));
     265        recordNum = iBuilder->CreateExtractValue(segResult, std::vector<unsigned>({1}));
    236266    }
    237 
    238     kBuilder->changeKernelInternalState(blockPosIdx, scanwordPos);
    239     kBuilder->changeKernelInternalState(lineStartIdx, recordStart);
    240     kBuilder->changeKernelInternalState(lineNumIdx, recordNum);
    241 
    242     kBuilder->closeDoBlock(outputs);
    243 
    244     kBuilder->finalizeMethods();
    245 }
    246 
    247 
    248 
     267    iBuilder->CreateRet(segResult);
     268}
     269
     270
     271
     272
  • icGREP/icgrep-devel/icgrep/kernels/scanmatchgen.h

    r4935 r4936  
    1111#include <llvm/IR/Module.h>
    1212       
    13 void generateScanBitBlockRoutine(Module * m, IDISA::IDISA_Builder * iBuilder, int segBitWidth, Type * kernelStuctType);
    14 
    15 void generateScanMatch(Module * m, IDISA::IDISA_Builder * iBuilder, int segBitWidth, KernelBuilder * kBuilder);
     13void generateScanBitBlockRoutine(Module * m, IDISA::IDISA_Builder * iBuilder, int segBitWidth);
    1614
    1715#endif // SCANMATCHGEN_H
Note: See TracChangeset for help on using the changeset viewer.