Ignore:
Timestamp:
Oct 16, 2018, 2:29:44 PM (7 months ago)
Author:
nmedfort
Message:

Added RE_Inspector.

Migrated RE passes to RE_Transformer.

Incorporated Memoizer functionality into RE_Transformer/Inspector.

Removed Memoizer.

Bug fix for unicode_set.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/pablo/builder.cpp

    r6129 r6173  
    1818#include <pablo/ps_assign.h>
    1919#include <boost/preprocessor/variadic/elem.hpp>
     20#include <type_traits>
    2021
    2122using namespace llvm;
    2223
    2324namespace pablo {
     25
     26using TypeId = PabloAST::ClassTypeId;
    2427
    2528#define GET(I, ...) \
    2629    reinterpret_cast<decltype(BOOST_PP_VARIADIC_ELEM(I, __VA_ARGS__))>(arg##I)
    2730
    28 #define MAKE_UNARY(NAME, TYPE, ARGS...) \
     31#define MAKE_UNARY(TYPE, ARGS...) \
     32[&](){ /* immediately invoked lambda */ \
    2933struct __##NAME { \
    3034    inline PabloAST * operator()(void * const arg0) { \
    31         return mPb->NAME(GET(0, ARGS)); \
     35        return mPb->create##TYPE(GET(0, ARGS)); \
    3236    } \
    3337    inline __##NAME(PabloBlock * const pb) : mPb(pb) {} \
     
    3640}; \
    3741__##NAME functor(mPb); \
    38 PabloAST * result = mExprTable.findUnaryOrCall(std::move(functor), TYPE, ARGS)
    39 
    40 #define MAKE_NAMED_UNARY(NAME, TYPE, PREFIX, ARGS...) \
     42return cast<TYPE>(mExprTable.findUnaryOrCall(std::move(functor), TypeId::TYPE, ARGS)); \
     43}()
     44
     45#define MAKE_NAMED_UNARY(TYPE, PREFIX, ARGS...) \
     46[&](){ /* immediately invoked lambda */  \
    4147struct __##NAME { \
    4248    inline PabloAST * operator()(void * const arg0) { \
    43         return mPb->NAME(GET(0, ARGS), mPrefix); \
     49        return mPb->create##TYPE(GET(0, ARGS), mPrefix); \
    4450    } \
    4551    inline __##NAME(PabloBlock * const pb, const llvm::StringRef & prefix) : mPb(pb), mPrefix(prefix) {} \
     
    4955}; \
    5056__##NAME functor(mPb, prefix); \
    51 PabloAST * result = mExprTable.findUnaryOrCall(std::move(functor), TYPE, ARGS)
    52 
    53 #define MAKE_BINARY(NAME, TYPE, ARGS...) \
     57return cast<TYPE>(mExprTable.findUnaryOrCall(std::move(functor), TypeId::TYPE, ARGS)); \
     58}()
     59
     60#define MAKE_BINARY(TYPE, ARGS...) \
     61[&](){ /* immediately invoked lambda */  \
    5462struct __##NAME { \
    5563    inline PabloAST * operator()(void * const arg0, void * const arg1) { \
    56         return mPb->NAME(GET(0, ARGS), GET(1, ARGS)); \
     64        return mPb->create##TYPE(GET(0, ARGS), GET(1, ARGS)); \
    5765    } \
    5866    inline __##NAME(PabloBlock * const pb) : mPb(pb) {} \
     
    6169}; \
    6270__##NAME functor(mPb); \
    63 PabloAST * result = mExprTable.findBinaryOrCall(std::move(functor), TYPE, ARGS)
    64 
    65 #define MAKE_NAMED_BINARY(NAME, TYPE, PREFIX, ARGS...) \
     71return cast<TYPE>(mExprTable.findBinaryOrCall(std::move(functor), TypeId::TYPE, ARGS)); \
     72}()
     73
     74#define MAKE_NAMED_BINARY(TYPE, PREFIX, ARGS...) \
     75[&](){ /* immediately invoked lambda */  \
    6676struct __##NAME { \
    6777    inline PabloAST * operator()(void * const arg0, void * const arg1) { \
    68         return mPb->NAME(GET(0, ARGS), GET(1, ARGS), mPrefix); \
     78        return mPb->create##TYPE(GET(0, ARGS), GET(1, ARGS), mPrefix); \
    6979    } \
    7080    inline __##NAME(PabloBlock * const pb, const llvm::StringRef & prefix) : mPb(pb), mPrefix(prefix) {} \
     
    7484}; \
    7585__##NAME functor(mPb, PREFIX); \
    76 PabloAST * result = mExprTable.findBinaryOrCall(std::move(functor), TYPE, ARGS)
    77 
    78 #define MAKE_TERNARY(NAME, TYPE, ARGS...) \
     86return cast<TYPE>(mExprTable.findBinaryOrCall(std::move(functor), TypeId::TYPE, ARGS)); \
     87}()
     88
     89#define MAKE_TERNARY(TYPE, ARGS...) \
     90[&](){ /* immediately invoked lambda */  \
    7991struct __##NAME { \
    8092    inline PabloAST * operator()(void * const arg0, void * const arg1, void * const arg2) { \
    81         return mPb->NAME(GET(0, ARGS), GET(1, ARGS), GET(2, ARGS)); \
     93        return mPb->create##TYPE(GET(0, ARGS), GET(1, ARGS), GET(2, ARGS)); \
    8294    } \
    8395    inline __##NAME(PabloBlock * const pb) : mPb(pb) {} \
     
    8698}; \
    8799__##NAME functor(mPb); \
    88 PabloAST * result = mExprTable.findTernaryOrCall(std::move(functor), TYPE, ARGS)
    89 
    90 #define MAKE_NAMED_TERNARY(NAME, TYPE, PREFIX, ARGS...) \
     100return cast<TYPE>(mExprTable.findTernaryOrCall(std::move(functor), TypeId::TYPE, ARGS)); \
     101}()
     102
     103#define MAKE_NAMED_TERNARY(TYPE, PREFIX, ARGS...) \
     104[&](){ /* immediately invoked lambda */  \
    91105struct __##NAME { \
    92106    inline PabloAST * operator()(void * const arg0, void * const arg1, void * const arg2) { \
    93         return mPb->NAME(GET(0, ARGS), GET(1, ARGS), GET(2, ARGS), mPrefix); \
     107        return mPb->create##TYPE(GET(0, ARGS), GET(1, ARGS), GET(2, ARGS), mPrefix); \
    94108    } \
    95109    inline __##NAME(PabloBlock * const pb, const llvm::StringRef & prefix) : mPb(pb), mPrefix(prefix) {} \
     
    99113}; \
    100114__##NAME functor(mPb, PREFIX); \
    101 PabloAST * result = mExprTable.findTernaryOrCall(std::move(functor), TYPE, ARGS)
    102 
    103 using TypeId = PabloAST::ClassTypeId;
     115return cast<TYPE>(mExprTable.findTernaryOrCall(std::move(functor), TypeId::TYPE, ARGS)); \
     116}()
    104117
    105118PabloAST * PabloBuilder::createAdvance(PabloAST * expr, not_null<Integer *> shiftAmount) {
     
    107120        return expr;
    108121    }
    109     MAKE_BINARY(createAdvance, TypeId::Advance, expr, shiftAmount.get());
    110     return result;
     122    return MAKE_BINARY(Advance, expr, shiftAmount.get());
    111123}
    112124
     
    115127        return expr;
    116128    }
    117     MAKE_NAMED_BINARY(createAdvance, TypeId::Advance, prefix, expr, shiftAmount.get());
    118     return result;
     129    return MAKE_NAMED_BINARY(Advance, prefix, expr, shiftAmount.get());
    119130}
    120131
     
    129140        return createAdvanceThenScanTo(createAnd(expr, indexStream), indexStream);
    130141    }
    131     MAKE_TERNARY(createIndexedAdvance, TypeId::IndexedAdvance, expr, indexStream, shiftAmount.get());
    132     return result;
     142    return MAKE_TERNARY(IndexedAdvance, expr, indexStream, shiftAmount.get());
    133143}
    134144
     
    143153        return createAdvanceThenScanTo(expr, indexStream, prefix);
    144154    }
    145     MAKE_NAMED_TERNARY(createIndexedAdvance, TypeId::IndexedAdvance, prefix, expr, indexStream, shiftAmount.get());
    146     return result;
     155    return MAKE_NAMED_TERNARY(IndexedAdvance, prefix, expr, indexStream, shiftAmount.get());
    147156}
    148157   
    149158Extract * PabloBuilder::createExtract(Var * array, not_null<Integer *> index) {
    150     MAKE_BINARY(createExtract, TypeId::Extract, array, index.get());
    151     return cast<Extract>(result);
     159    return MAKE_BINARY(Extract, array, index.get());
    152160}
    153161
     
    156164        return expr;
    157165    }
    158     MAKE_BINARY(createLookahead, TypeId::Lookahead, expr, shiftAmount.get());
    159     return result;
     166    return MAKE_BINARY(Lookahead, expr, shiftAmount.get());
    160167}
    161168
     
    164171        return expr;
    165172    }
    166     MAKE_NAMED_BINARY(createLookahead, TypeId::Lookahead, prefix, expr, shiftAmount.get());
    167     return result;
     173    return MAKE_NAMED_BINARY(Lookahead, prefix, expr, shiftAmount.get());
    168174}
    169175
     
    178184        return not1->getOperand(0);
    179185    }
    180     MAKE_UNARY(createNot, TypeId::Not, expr);
    181     return result;
     186    return MAKE_UNARY(Not, expr);
    182187}
    183188
     
    192197        return not1->getOperand(0);
    193198    }
    194     MAKE_NAMED_UNARY(createNot, TypeId::Not, prefix, expr);
    195     return result;
     199    return MAKE_NAMED_UNARY(Not, prefix, expr);
    196200}
    197201
    198202PabloAST * PabloBuilder::createCount(PabloAST * expr) {
    199     MAKE_UNARY(createCount, TypeId::Count, expr);
    200     return result;
     203    return MAKE_UNARY(Count, expr);
    201204}
    202205
    203206PabloAST * PabloBuilder::createCount(PabloAST * expr, const llvm::StringRef & prefix) {
    204     MAKE_NAMED_UNARY(createCount, TypeId::Count, prefix, expr);
    205     return result;
     207    return MAKE_NAMED_UNARY(Count, prefix, expr);
    206208}
    207209
    208210PabloAST * PabloBuilder::createRepeat(not_null<Integer *> fieldWidth, PabloAST * value) {
    209     MAKE_BINARY(createRepeat, TypeId::Repeat, fieldWidth.get(), value);
    210     return result;
     211    return MAKE_BINARY(Repeat, fieldWidth.get(), value);
    211212}
    212213
    213214PabloAST * PabloBuilder::createRepeat(not_null<Integer *> fieldWidth, PabloAST * value, const llvm::StringRef & prefix) {
    214     MAKE_NAMED_BINARY(createRepeat, TypeId::Repeat, prefix, fieldWidth.get(), value);
    215     return result;
     215    return MAKE_NAMED_BINARY(Repeat, prefix, fieldWidth.get(), value);
    216216}
    217217
    218218   
    219219PabloAST * PabloBuilder::createPackL(not_null<Integer *> fieldWidth, PabloAST * value) {
    220     MAKE_BINARY(createPackL, TypeId::PackL, fieldWidth.get(), value);
    221     return result;
     220    return MAKE_BINARY(PackL, fieldWidth.get(), value);
    222221}
    223222
    224223PabloAST * PabloBuilder::createPackH(not_null<Integer *> fieldWidth, PabloAST * value) {
    225     MAKE_BINARY(createPackH, TypeId::PackH, fieldWidth.get(), value);
    226     return result;
     224    return MAKE_BINARY(PackH, fieldWidth.get(), value);
    227225}
    228226
     
    255253        std::swap(expr1, expr2);
    256254    }
    257     MAKE_BINARY(createAnd, TypeId::And, expr1, expr2);
    258     return result;
     255    return MAKE_BINARY(And, expr1, expr2);
    259256}
    260257
     
    286283        std::swap(expr1, expr2);
    287284    }
    288     MAKE_NAMED_BINARY(createAnd, TypeId::And, prefix, expr1, expr2);
    289     return result;
     285    return MAKE_NAMED_BINARY(And, prefix, expr1, expr2);
    290286}
    291287
     
    333329        std::swap(expr1, expr2);
    334330    }
    335     MAKE_BINARY(createOr, TypeId::Or, expr1, expr2);
    336     return result;
     331    return MAKE_BINARY(Or, expr1, expr2);
    337332}
    338333
     
    380375        std::swap(expr1, expr2);
    381376    }
    382     MAKE_NAMED_BINARY(createOr, TypeId::Or, prefix, expr1, expr2);
    383     return result;
     377    return MAKE_NAMED_BINARY(Or, prefix, expr1, expr2);
    384378}
    385379
     
    403397        std::swap(expr1, expr2);
    404398    }
    405     MAKE_BINARY(createXor, TypeId::Xor, expr1, expr2);
    406     return result;
     399    return MAKE_BINARY(Xor, expr1, expr2);
    407400}
    408401
     
    426419        std::swap(expr1, expr2);
    427420    }
    428     MAKE_NAMED_BINARY(createXor, TypeId::Xor, prefix, expr1, expr2);
    429     return result;
     421    return MAKE_NAMED_BINARY(Xor, prefix, expr1, expr2);
    430422}
    431423
     
    442434        }
    443435    }
    444     MAKE_BINARY(createAdd, TypeId::Add, expr1, expr2);
    445     return result;
     436    return MAKE_BINARY(Add, expr1, expr2);
    446437}
    447438
     
    458449        }
    459450    }
    460     MAKE_BINARY(createSubtract, TypeId::Subtract, expr1, expr2);
    461     return result;
     451    return MAKE_BINARY(Subtract, expr1, expr2);
    462452}
    463453
     
    466456        return getInteger(cast<Integer>(expr1)->value() < cast<Integer>(expr2)->value() ? 1 : 0);
    467457    }
    468     MAKE_BINARY(createLessThan, TypeId::LessThan, expr1, expr2);
    469     return result;
     458    return MAKE_BINARY(LessThan, expr1, expr2);
    470459}
    471460
     
    474463        return getInteger(cast<Integer>(expr1)->value() == cast<Integer>(expr2)->value() ? 1 : 0);
    475464    }
    476     MAKE_BINARY(createEquals, TypeId::Equals, expr1, expr2);
    477     return result;
     465    return MAKE_BINARY(Equals, expr1, expr2);
    478466}
    479467
    480468PabloAST * PabloBuilder::createInFile(PabloAST * expr) {
    481469    if (isa<Zeroes>(expr)) return expr;
    482     MAKE_UNARY(createInFile, TypeId::InFile, expr);
    483     return result;
     470    return MAKE_UNARY(InFile, expr);
    484471}
    485472
    486473PabloAST * PabloBuilder::createInFile(PabloAST * expr, const llvm::StringRef & prefix) {
    487     MAKE_NAMED_UNARY(createInFile, TypeId::InFile, prefix, expr);
    488     return result;
     474    return MAKE_NAMED_UNARY(InFile, prefix, expr);
    489475}
    490476
    491477PabloAST * PabloBuilder::createAtEOF(PabloAST * expr) {
    492     MAKE_UNARY(createAtEOF, TypeId::AtEOF, expr);
    493     return result;
     478    return MAKE_UNARY(AtEOF, expr);
    494479}
    495480
    496481PabloAST * PabloBuilder::createAtEOF(PabloAST * expr, const llvm::StringRef & prefix) {
    497     MAKE_NAMED_UNARY(createAtEOF, TypeId::AtEOF, prefix, expr);
    498     return result;
     482    return MAKE_NAMED_UNARY(AtEOF, prefix, expr);
    499483}
    500484
     
    503487        return marker;
    504488    }
    505     MAKE_BINARY(createMatchStar, TypeId::MatchStar, marker, charclass);
    506     return result;
     489    return MAKE_BINARY(MatchStar, marker, charclass);
    507490}
    508491
     
    511494        return marker;
    512495    }
    513     MAKE_NAMED_BINARY(createMatchStar, TypeId::MatchStar, prefix, marker, charclass);
    514     return result;
     496    return MAKE_NAMED_BINARY(MatchStar, prefix, marker, charclass);
    515497}
    516498
     
    519501        return from;
    520502    }
    521     MAKE_BINARY(createScanThru, TypeId::ScanThru, from, thru);
    522     return result;
     503    return MAKE_BINARY(ScanThru, from, thru);
    523504}
    524505
     
    527508        return from;
    528509    }
    529     MAKE_NAMED_BINARY(createScanThru, TypeId::ScanThru, prefix, from, thru);
    530     return result;
     510    return MAKE_NAMED_BINARY(ScanThru, prefix, from, thru);
    531511}
    532512
     
    535515        return from;
    536516    }
    537     MAKE_BINARY(createScanTo, TypeId::ScanTo, from, to);
    538     return result;
     517    return MAKE_BINARY(ScanTo, from, to);
    539518}
    540519
     
    543522        return from;
    544523    }
    545     MAKE_NAMED_BINARY(createScanTo, TypeId::ScanTo, prefix, from, to);
    546     return result;
     524    return MAKE_NAMED_BINARY(ScanTo, prefix, from, to);
    547525}
    548526
     
    551529        return from;
    552530    }
    553     MAKE_BINARY(createAdvanceThenScanThru, TypeId::AdvanceThenScanThru, from, thru);
    554     return result;
     531    return MAKE_BINARY(AdvanceThenScanThru, from, thru);
    555532}
    556533
     
    559536        return from;
    560537    }
    561     MAKE_NAMED_BINARY(createAdvanceThenScanThru, TypeId::AdvanceThenScanThru, prefix, from, thru);
    562     return result;
     538    return MAKE_NAMED_BINARY(AdvanceThenScanThru, prefix, from, thru);
    563539}
    564540
     
    567543        return from;
    568544    }
    569     MAKE_BINARY(createAdvanceThenScanTo, TypeId::ScanTo, from, to);
    570     return result;
     545    return MAKE_BINARY(AdvanceThenScanTo, from, to);
    571546}
    572547
     
    575550        return from;
    576551    }
    577     MAKE_NAMED_BINARY(createAdvanceThenScanTo, TypeId::ScanTo, prefix, from, to);
    578     return result;
     552    return MAKE_NAMED_BINARY(AdvanceThenScanTo, prefix, from, to);
    579553}
    580554
     
    599573        return createXor(condition, trueExpr);
    600574    }
    601     MAKE_TERNARY(createSel, TypeId::Sel, condition, trueExpr, falseExpr);
    602     return result;
     575    return MAKE_TERNARY(Sel, condition, trueExpr, falseExpr);
    603576}
    604577
     
    623596        return createXor(condition, trueExpr);
    624597    }
    625     MAKE_NAMED_TERNARY(createSel, TypeId::Sel, prefix, condition, trueExpr, falseExpr);
    626     return result;
    627 }
    628 
    629 }
     598    return MAKE_NAMED_TERNARY(Sel, prefix, condition, trueExpr, falseExpr);
     599}
     600
     601}
Note: See TracChangeset for help on using the changeset viewer.