Changeset 4096


Ignore:
Timestamp:
Aug 29, 2014, 4:47:16 PM (5 years ago)
Author:
linmengl
Message:

generate llvm.uadd.with.overflow. add 'make check' target to run greptest.py.

Location:
icGREP/icgrep-devel
Files:
4 edited

Legend:

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

    r4087 r4096  
    1212# regexp tests.
    1313# </datafile>
    14 # 
     14#
    1515# <grepcase regexp="in" datafile="simple1" grepcount="2"/>
    1616# <grepcase regexp="[A-Z]" datafile="simple1" grepcount="1"/>
    17 # 
     17#
    1818# </greptest>
    1919
     
    2929        if name == 'datafile':
    3030                idFound = False
    31                 for a in attrs: 
    32                         if a == 'id':   
     31                for a in attrs:
     32                        if a == 'id':
    3333                                filename = attrs[a]
    3434                                idFound = True
    35                 if not idFound: 
     35                if not idFound:
    3636                        print "Expecting id attribute for datafile, but none found."
    3737                        exit(-1)
     
    6464                datafile = None
    6565                expected_count = None
    66                 for a in attrs: 
    67                         if a == 'regexp':       
     66                for a in attrs:
     67                        if a == 'regexp':
    6868                                regexp = attrs[a]
    6969                        elif a == 'datafile':
     
    8181                if m == None or m.group(0) != expected_count:
    8282                        print("Test failure: regexp {%s} on datafile {%s} expecting {%s} got {%s}" % (regexp, datafile, expected_count, grep_out))
     83                        exit(1)
    8384                else:
    8485                        if options.verbose:
     
    9495        QA_dir = os.path.dirname(sys.argv[0])
    9596        option_parser = optparse.OptionParser(usage='python %prog [options] <grep_executable>', version='1.0')
    96         option_parser.add_option('-d', '--datafile_dir', 
     97        option_parser.add_option('-d', '--datafile_dir',
    9798                          dest = 'datafile_dir', type='string', default='/tmp',
    9899                          help = 'directory for test files.')
    99         option_parser.add_option('-t', '--testcases', 
     100        option_parser.add_option('-t', '--testcases',
    100101                          dest = 'testcases', type='string', default='greptest.xml',
    101102                          help = 'grep test case file (XML format).')
    102         option_parser.add_option('-e', '--exec_dir', 
     103        option_parser.add_option('-e', '--exec_dir',
    103104                          dest = 'exec_dir', type='string', default='.',
    104105                          help = 'executable directory')
    105         option_parser.add_option('-v', '--verbose', 
     106        option_parser.add_option('-v', '--verbose',
    106107                          dest = 'verbose', action='store_true', default=False,
    107108                          help = 'verbose output: show successful tests')
     
    116117        make_data_files(grep_test_spec)
    117118        run_tests(grep_test_spec)
    118        
    119119
     120
  • icGREP/icgrep-devel/icgrep/CMakeLists.txt

    r3991 r4096  
    33project (icgrep)
    44
     5enable_testing()
    56# The version number.
    67set (icgrep_VERSION_MAJOR 0)
    78set (icgrep_VERSION_MINOR 8)
    8  
     9
    910# configure a header file to pass some of the CMake settings
    1011# to the source code
     
    3738llvm_map_components_to_libraries(REQ_LLVM_LIBRARIES mcjit native)
    3839
    39  
     40
    4041add_library(PabloADT pe_advance.cpp  pe_all.cpp  pe_and.cpp pe_call.cpp pe_charclass.cpp  pe_matchstar.cpp pe_scanthru.cpp pe_not.cpp  pe_or.cpp  pe_pabloe.cpp  pe_sel.cpp  pe_var.cpp  pe_xor.cpp ps_assign.cpp  ps_if.cpp  ps_pablos.cpp  ps_while.cpp printer_pablos.cpp)
    4142
     
    4546
    4647#include_directories("${PROJECT_BINARY_DIR}")
    47 include_directories("${PROJECT_SOURCE_DIR}") 
     48include_directories("${PROJECT_SOURCE_DIR}")
    4849include_directories("${PROJECT_SOURCE_DIR}/include")
    4950include_directories("${PROJECT_SOURCE_DIR}/include/simd-lib")
    5051include_directories("${PROJECT_SOURCE_DIR}/include/simd-lib/idisa_cpp")
    51  
     52
    5253# add the executable
    5354add_executable(icgrep icgrep.cpp llvm_gen.cpp llvm_gen_helper.cpp utf_encoding.cpp cc_codegenobject.cpp  cc_compiler.cpp  cc_compiler_helper.cpp re_simplifier.cpp re_reducer.cpp re_nullable.cpp re_compiler.cpp pbix_compiler.cpp  symbol_generator.cpp utf8_encoder.cpp unicode_categories.h unicode_categories-flat.h unicode_categories-simple.h)
     
    5657
    5758set(CMAKE_CXX_FLAGS_RELEASE "-std=gnu++0x -O3 -msse2")
     59
     60add_test(
     61  NAME greptest
     62  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA
     63  COMMAND python greptest.py ${CMAKE_BINARY_DIR}/icgrep)
     64
     65add_custom_target (check
     66  COMMAND ${CMAKE_CTEST_COMMAND}
     67  DEPENDS icgrep)
  • icGREP/icgrep-devel/icgrep/llvm_gen.cpp

    r4089 r4096  
    551551    // to call->  b.CreateCall(mFunc_print_register, unicode_category);
    552552
     553    // Type Definitions for llvm.uadd.with.overflow.i128
     554    std::vector<Type*>StructTy_0_fields;
     555    StructTy_0_fields.push_back(IntegerType::get(mMod->getContext(), 128));
     556    StructTy_0_fields.push_back(IntegerType::get(mMod->getContext(), 1));
     557    StructType *StructTy_0 = StructType::get(mMod->getContext(), StructTy_0_fields, /*isPacked=*/false);
     558
     559    std::vector<Type*>FuncTy_1_args;
     560    FuncTy_1_args.push_back(IntegerType::get(mMod->getContext(), 128));
     561    FuncTy_1_args.push_back(IntegerType::get(mMod->getContext(), 128));
     562    FunctionType* FuncTy_1 = FunctionType::get(
     563                                              /*Result=*/StructTy_0,
     564                                              /*Params=*/FuncTy_1_args,
     565                                              /*isVarArg=*/false);
     566
     567    mFunc_llvm_uadd_with_overflow_i128 = mMod->getFunction("llvm.uadd.with.overflow.i128");
     568    if (!mFunc_llvm_uadd_with_overflow_i128) {
     569        mFunc_llvm_uadd_with_overflow_i128 = Function::Create(
     570          /*Type=*/FuncTy_1,
     571          /*Linkage=*/GlobalValue::ExternalLinkage,
     572          /*Name=*/"llvm.uadd.with.overflow.i128", mMod); // (external, no body)
     573        mFunc_llvm_uadd_with_overflow_i128->setCallingConv(CallingConv::C);
     574    }
     575    AttributeSet mFunc_llvm_uadd_with_overflow_i128_PAL;
     576    {
     577        SmallVector<AttributeSet, 4> Attrs;
     578        AttributeSet PAS;
     579        {
     580          AttrBuilder B;
     581          B.addAttribute(Attribute::NoUnwind);
     582          B.addAttribute(Attribute::ReadNone);
     583          PAS = AttributeSet::get(mMod->getContext(), ~0U, B);
     584        }
     585
     586        Attrs.push_back(PAS);
     587        mFunc_llvm_uadd_with_overflow_i128_PAL = AttributeSet::get(mMod->getContext(), Attrs);
     588    }
     589    mFunc_llvm_uadd_with_overflow_i128->setAttributes(mFunc_llvm_uadd_with_overflow_i128_PAL);
     590
     591    //Starts on process_block
    553592    SmallVector<AttributeSet, 4> Attrs;
    554593    AttributeSet PAS;
     
    11091148}
    11101149
     1150SumWithOverflowPack LLVM_Generator::genUaddOverflow(Value* int128_e1, Value* int128_e2) {
     1151    std::vector<Value*> struct_res_params;
     1152    struct_res_params.push_back(int128_e1);
     1153    struct_res_params.push_back(int128_e2);
     1154    CallInst* struct_res = CallInst::Create(mFunc_llvm_uadd_with_overflow_i128, struct_res_params, "uadd_overflow_res", mBasicBlock);
     1155    struct_res->setCallingConv(CallingConv::C);
     1156    struct_res->setTailCall(false);
     1157    AttributeSet struct_res_PAL;
     1158    struct_res->setAttributes(struct_res_PAL);
     1159
     1160    SumWithOverflowPack ret;
     1161
     1162    std::vector<unsigned> int128_sum_indices;
     1163    int128_sum_indices.push_back(0);
     1164    ret.sum = ExtractValueInst::Create(struct_res, int128_sum_indices, "sum", mBasicBlock);
     1165
     1166    std::vector<unsigned> int1_obit_indices;
     1167    int1_obit_indices.push_back(1);
     1168    ret.obit = ExtractValueInst::Create(struct_res, int1_obit_indices, "obit", mBasicBlock);
     1169
     1170    return ret;
     1171}
     1172
     1173
    11111174Value* LLVM_Generator::genAddWithCarry(Value* e1, Value* e2) {
    11121175    IRBuilder<> b(mBasicBlock);
     
    11181181    Value* carryq_value = genCarryInLoad(mptr_carry_q, this_carry_idx);
    11191182
    1120     Value* carrygen = b.CreateAnd(e1, e2, "carrygen");
    1121     Value* carryprop = b.CreateOr(e1, e2, "carryprop");
    1122     Value* digitsum = b.CreateAdd(e1, e2, "digitsum");
    1123     Value* partial = b.CreateAdd(digitsum, carryq_value, "partial");
    1124     Value* digitcarry = b.CreateOr(carrygen, b.CreateAnd(carryprop, genNot(partial)));
    1125     Value* mid_carry_in = genShiftLeft64(b.CreateLShr(digitcarry, 63), "mid_carry_in");
    1126 
    1127     Value* sum = b.CreateAdd(partial, mid_carry_in, "sum");
    1128     Value* carry_out = genShiftRight127(b.CreateOr(carrygen, b.CreateAnd(carryprop, genNot(sum))), "carry_out");
    1129 
    1130     //CarryQ - carry out:
     1183    //new code chunk, use llvm.uadd.with.overflow.i128
     1184    CastInst* int128_e1 = new BitCastInst(e1, IntegerType::get(mMod->getContext(), 128), "e1_128", mBasicBlock);
     1185    CastInst* int128_e2 = new BitCastInst(e2, IntegerType::get(mMod->getContext(), 128), "e2_128", mBasicBlock);
     1186    CastInst* int128_carryq_value = new BitCastInst(carryq_value, IntegerType::get(mMod->getContext(), 128), "carryq_128", mBasicBlock);
     1187
     1188    SumWithOverflowPack sumpack0, sumpack1;
     1189
     1190    sumpack0 = genUaddOverflow(int128_e1, int128_e2);
     1191    sumpack1 = genUaddOverflow(sumpack0.sum, int128_carryq_value);
     1192
     1193    Value* obit = b.CreateOr(sumpack0.obit, sumpack1.obit, "carry_bit");
     1194    Value* ret_sum = b.CreateBitCast(sumpack1.sum, m64x2Vect, "ret_sum");
     1195
     1196    /*obit is the i1 carryout, zero extend and insert it into a v2i64 vector.*/
     1197    ConstantAggregateZero* const_packed_5 = ConstantAggregateZero::get(m64x2Vect);
     1198    ConstantInt* const_int32_6 = ConstantInt::get(mMod->getContext(), APInt(32, StringRef("0"), 10));
     1199    CastInst* int64_o0 = new ZExtInst(obit, IntegerType::get(mMod->getContext(), 64), "o0", mBasicBlock);
     1200    InsertElementInst* carry_out = InsertElementInst::Create(const_packed_5, int64_o0, const_int32_6, "carry_out", mBasicBlock);
     1201
    11311202    Value* void_1 = genCarryOutStore(carry_out, mptr_carry_q, this_carry_idx);
    11321203
    1133     return sum;
     1204    return ret_sum;
     1205    //new code chunk ends
     1206
     1207    //Old code chunk, calculate carry through logical ops
     1208    //Value* carrygen = b.CreateAnd(e1, e2, "carrygen");
     1209    //Value* carryprop = b.CreateOr(e1, e2, "carryprop");
     1210    //Value* digitsum = b.CreateAdd(e1, e2, "digitsum");
     1211    //Value* partial = b.CreateAdd(digitsum, carryq_value, "partial");
     1212    //Value* digitcarry = b.CreateOr(carrygen, b.CreateAnd(carryprop, genNot(partial)));
     1213    //Value* mid_carry_in = genShiftLeft64(b.CreateLShr(digitcarry, 63), "mid_carry_in");
     1214
     1215    //Value* sum = b.CreateAdd(partial, mid_carry_in, "sum");
     1216    //Value* carry_out = genShiftRight127(b.CreateOr(carrygen, b.CreateAnd(carryprop, genNot(sum))), "carry_out");
     1217    //Value* void_1 = genCarryOutStore(carry_out, mptr_carry_q, this_carry_idx);
     1218
     1219    //return sum;
     1220    //Old code chunk ends
    11341221}
    11351222
  • icGREP/icgrep-devel/icgrep/llvm_gen.h

    r4091 r4096  
    88#define LLVM_GENERATOR_H
    99
    10 #define USE_LLVM_3_4
    11 //#define DUMP_GENERATED_IR
     10#define USE_LLVM_3_5
     11#define DUMP_GENERATED_IR
    1212
    1313//Regular Expressions
     
    112112};
    113113
     114struct SumWithOverflowPack {
     115  Value *sum;
     116  Value *obit;
     117};
     118
    114119class LLVM_Generator
    115120{
     
    144149    Value* genNot(Value* e, const Twine &namehint = "");
    145150
     151    SumWithOverflowPack genUaddOverflow(Value *e1, Value *e2);
     152
    146153    int         mBits;
    147154    std::map<std::string, std::string> m_name_map;
     
    174181    FunctionType* mFuncTy_0;
    175182    Function*     mFunc_process_block;
     183    Function*     mFunc_llvm_uadd_with_overflow_i128;
    176184
    177185    Constant*     mFunc_print_register;
Note: See TracChangeset for help on using the changeset viewer.