Changeset 4421


Ignore:
Timestamp:
Jan 15, 2015, 10:51:25 AM (4 years ago)
Author:
cameron
Message:

Support for multiblock shift; wrapped_print_register

Location:
icGREP/icgrep-devel
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/QA/greptest.xml

    r4402 r4421  
    3535=yyyyyyyyyyyyyyyyyyyyyyyyy;
    3636=zzzzzzzzzzzzzzzzzzzzzzzzzz;
     37=0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789;
     38=01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789;
     39=012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789;
     40=0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789;
     41=01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789;
     42=012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789;
     43=0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789;
    3744</datafile>
    3845
     
    388395<grepcase regexp="(?i)[A-T]{6}" datafile="bounded_charclass" grepcount="15"/>
    389396<grepcase regexp="(?i)=S[A-T]S*;" datafile="bounded_charclass" grepcount="1"/>
     397<grepcase regexp="=[0-9]{100};" datafile="bounded_charclass" grepcount="1"/>
     398<grepcase regexp="=[0-9]{50,};" datafile="bounded_charclass" grepcount="7"/>
     399<grepcase regexp="=[0-9]{140};" datafile="bounded_charclass" grepcount="1"/>
     400<grepcase regexp="=[0-9a-z]{12,200};" datafile="bounded_charclass" grepcount="22"/>
     401
    390402
    391403<grepcase regexp="^D[zabcdefoy]g" datafile="RangeAltSeqMatchStarKplusWhileNotOptAny" grepcount="7"/>
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r4417 r4421  
    100100    InitializeNativeTargetAsmParser();
    101101    DefineTypes();
    102     DeclareFunctions();
    103102}
    104103
     
    134133        throw std::runtime_error("Could not create ExecutionEngine: " + errMessage);
    135134    }
     135    DeclareFunctions();
    136136
    137137    DeclareCallFunctions();
     
    261261{
    262262    //This function can be used for testing to print the contents of a register from JIT'd code to the terminal window.
    263     //mFunc_print_register = mMod->getOrInsertFunction("wrapped_print_register", Type::getVoidTy(getGlobalContext()), mXi64Vect, NULL);
    264     //mExecutionEngine->addGlobalMapping(cast<GlobalValue>(mFunc_print_register), (void *)&wrapped_print_register);
     263    mFunc_print_register = mMod->getOrInsertFunction("wrapped_print_register", Type::getVoidTy(getGlobalContext()), mBitBlockType, NULL);
     264    mExecutionEngine->addGlobalMapping(cast<GlobalValue>(mFunc_print_register), (void *)&wrapped_print_register);
    265265    // to call->  b.CreateCall(mFunc_print_register, unicode_category);
    266266
     
    396396}
    397397
     398//
     399// CarryNumbering: sequential numbers associated with each
     400// carry-generating operation encountered in a traversal of the
     401// Pablo AST.    Carry-generating operations are MatchStar, ScanThru,
     402// and so on.
     403// AdvanceNumbering: sequential numbers associated with each Advance
     404// operation encountered in tree traversal, with the following modifications.
     405//   (a) an additional AdvanceQueue entry is created for each if-statement
     406//       having more than one carry or advance opreation within it.  This
     407//       additional entry is a summary entry which must be nonzero to
     408//       indicate that there are carry or advance bits associated with
     409//       any operation within the if-structure (at any nesting level).
     410//   (b) advancing by a large amount may require multiple advance entries.
     411//       the number of advance entries for an operation Adv(x, n) is
     412//       (n - 1) / BLOCK_SIZE + 1
     413//
     414// Note that the initial carry/advance numbering is determined by the
     415// Examine function.  The values determined at this stage must be consistent
     416// with the later numbering calculated during actual statement compilation.
     417//
     418// Examine precomputes some CarryNumbering and AdvanceNumbering, as
     419// well as mMaxNestingDepth of while loops.
     420//
    398421void PabloCompiler::Examine(StatementList & stmts) {
    399422    for (Statement * stmt : stmts) {
     
    457480    }
    458481    else if (Advance * adv = dyn_cast<Advance>(expr)) {
    459         ++mAdvanceQueueSize;
     482        int shift_amount = adv->getAdvanceAmount();
     483        int advEntries = (shift_amount - 1) / BLOCK_SIZE + 1;
     484        mAdvanceQueueSize += advEntries;
    460485        Examine(adv->getExpr());
    461486    }
     
    10331058
    10341059Value* PabloCompiler::genAdvanceWithCarry(Value* strm_value, int shift_amount) {
    1035 
    10361060    IRBuilder<> b(mBasicBlock);
    1037 
    1038     const auto advanceIdx = mAdvanceQueueIdx++;
     1061    int advEntries = (shift_amount - 1) / BLOCK_SIZE + 1;
     1062    int block_shift = shift_amount % BLOCK_SIZE;
     1063    const auto storeIdx = mAdvanceQueueIdx;
     1064    const auto loadIdx = mAdvanceQueueIdx + advEntries - 1;
     1065    mAdvanceQueueIdx += advEntries;
     1066    Value* result_value;
     1067   
    10391068#ifdef USE_LONG_INTEGER_SHIFT
    1040     Value* advanceq_longint = b.CreateBitCast(genAdvanceInLoad(advanceIdx), IntegerType::get(mMod->getContext(), BLOCK_SIZE));
     1069    Value* advanceq_longint = b.CreateBitCast(genAdvanceInLoad(loadIdx), IntegerType::get(mMod->getContext(), BLOCK_SIZE));
    10411070    Value* strm_longint = b.CreateBitCast(strm_value, IntegerType::get(mMod->getContext(), BLOCK_SIZE));
    1042     Value* adv_longint = b.CreateOr(b.CreateShl(strm_longint, shift_amount), b.CreateLShr(advanceq_longint, BLOCK_SIZE - shift_amount), "advance");
    1043     Value* result_value = b.CreateBitCast(adv_longint, mBitBlockType);
    1044     genAdvanceOutStore(strm_value, advanceIdx);
     1071    Value* adv_longint = b.CreateOr(b.CreateShl(strm_longint, block_shift), b.CreateLShr(advanceq_longint, BLOCK_SIZE - block_shift), "advance");
     1072    result_value = b.CreateBitCast(adv_longint, mBitBlockType);
     1073    genAdvanceOutStore(strm_value, storeIdx);
    10451074
    10461075    return result_value;
    10471076#elif (BLOCK_SIZE == 128)
    1048     if (shift_amount == 1) {
    1049         Value* advanceq_value = genShiftHighbitToLow(genAdvanceInLoad(advanceIdx));
    1050         Value* srli_1_value = b.CreateLShr(strm_value, 63);
    1051         Value* packed_shuffle;
    1052         Constant* const_packed_1_elems [] = {b.getInt32(0), b.getInt32(2)};
    1053         Constant* const_packed_1 = ConstantVector::get(const_packed_1_elems);
    1054         packed_shuffle = b.CreateShuffleVector(advanceq_value, srli_1_value, const_packed_1);
    1055 
    1056         Constant* const_packed_2_elems[] = {b.getInt64(1), b.getInt64(1)};
    1057         Constant* const_packed_2 = ConstantVector::get(const_packed_2_elems);
    1058 
    1059         Value* shl_value = b.CreateShl(strm_value, const_packed_2);
    1060         Value* result_value = b.CreateOr(shl_value, packed_shuffle, "advance");
    1061 
    1062         //CarryQ - carry out:
    1063         genAdvanceOutStore(strm_value, advanceIdx);
    1064 
    1065         return result_value;
    1066     }
    1067     else if (shift_amount < 64) {
    1068         // This is the preferred logic, but is too slow for the general case.
    1069         // We need to speed up our custom LLVM for this code.
    1070         Value* advanceq_longint = b.CreateBitCast(genAdvanceInLoad(advanceIdx), IntegerType::get(mMod->getContext(), BLOCK_SIZE));
    1071         Value* strm_longint = b.CreateBitCast(strm_value, IntegerType::get(mMod->getContext(), BLOCK_SIZE));
    1072         Value* adv_longint = b.CreateOr(b.CreateShl(strm_longint, shift_amount), b.CreateLShr(advanceq_longint, BLOCK_SIZE - shift_amount), "advance");
    1073         Value* result_value = b.CreateBitCast(adv_longint, mBitBlockType);
    1074         genAdvanceOutStore(strm_value, advanceIdx);
    1075 
    1076         return result_value;
    1077     }
    1078     else {//if (shift_amount >= 64) {
    1079         throw std::runtime_error("Shift amount >= 64 in Advance is currently unsupported.");
    1080     }
     1077    if (advEntries == 1) {
     1078        if (block_shift == 1) {
     1079            Value* advanceq_value = genShiftHighbitToLow(genAdvanceInLoad(loadIdx));
     1080            Value* srli_1_value = b.CreateLShr(strm_value, 63);
     1081            Value* packed_shuffle;
     1082            Constant* const_packed_1_elems [] = {b.getInt32(0), b.getInt32(2)};
     1083            Constant* const_packed_1 = ConstantVector::get(const_packed_1_elems);
     1084            packed_shuffle = b.CreateShuffleVector(advanceq_value, srli_1_value, const_packed_1);
     1085
     1086            Constant* const_packed_2_elems[] = {b.getInt64(1), b.getInt64(1)};
     1087            Constant* const_packed_2 = ConstantVector::get(const_packed_2_elems);
     1088
     1089            Value* shl_value = b.CreateShl(strm_value, const_packed_2);
     1090            result_value = b.CreateOr(shl_value, packed_shuffle, "advance");
     1091        }
     1092        else { //if (block_shift < BLOCK_SIZE) {
     1093            // This is the preferred logic, but is too slow for the general case.
     1094            // We need to speed up our custom LLVM for this code.
     1095            Value* advanceq_longint = b.CreateBitCast(genAdvanceInLoad(loadIdx), IntegerType::get(mMod->getContext(), BLOCK_SIZE));
     1096            Value* strm_longint = b.CreateBitCast(strm_value, IntegerType::get(mMod->getContext(), BLOCK_SIZE));
     1097            Value* adv_longint = b.CreateOr(b.CreateShl(strm_longint, block_shift), b.CreateLShr(advanceq_longint, BLOCK_SIZE - block_shift), "advance");
     1098            result_value = b.CreateBitCast(adv_longint, mBitBlockType);
     1099        }
     1100    }
     1101    else {
     1102        if (block_shift == 0) {
     1103            result_value = genAdvanceInLoad(loadIdx);
     1104        }
     1105        else {
     1106            // The advance is based on the two oldest bit blocks in the advance queue.
     1107            Value* advanceq_longint = b.CreateBitCast(genAdvanceInLoad(loadIdx), IntegerType::get(mMod->getContext(), BLOCK_SIZE));
     1108            Value* strm_longint = b.CreateBitCast(genAdvanceInLoad(loadIdx-1), IntegerType::get(mMod->getContext(), BLOCK_SIZE));
     1109            Value* adv_longint = b.CreateOr(b.CreateShl(strm_longint, block_shift), b.CreateLShr(advanceq_longint, BLOCK_SIZE - block_shift), "longadvance");
     1110            result_value = b.CreateBitCast(adv_longint, mBitBlockType);
     1111            //b.CreateCall(mFunc_print_register, genAdvanceInLoad(loadIdx));
     1112            //b.CreateCall(mFunc_print_register, strm_value);
     1113            //b.CreateCall(mFunc_print_register, result_value);
     1114        }
     1115        // copy entries from previous blocks forward
     1116        for (int i = storeIdx; i < loadIdx; i++) {
     1117            genAdvanceOutStore(genAdvanceInLoad(i), i+1);
     1118        }
     1119    }
     1120    genAdvanceOutStore(strm_value, storeIdx);
     1121    return result_value;
    10811122#else
    10821123    //BLOCK_SIZE == 256
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.h

    r4417 r4421  
    146146    std::map<std::string, void *>       mExternalMap;
    147147    StringToValueMap                    mCalleeMap;
     148
     149    Constant * mFunc_print_register;
    148150};
    149151
Note: See TracChangeset for help on using the changeset viewer.