Ignore:
Timestamp:
Jan 13, 2018, 11:57:43 AM (12 months ago)
Author:
nmedfort
Message:

Pablo support for byte comparisions; LineFeed? kernel processes byte streams directly. Some clean up of PabloBuilder? functionality.

File:
1 edited

Legend:

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

    r5709 r5828  
    1717#include <pablo/pe_matchstar.h>
    1818#include <pablo/pe_ones.h>
    19 #include <pablo/pe_phi.h>
     19#include <pablo/pe_pack.h>
     20#include <pablo/pe_repeat.h>
    2021#include <pablo/pe_scanthru.h>
    2122#include <pablo/pe_string.h>
     
    2829#include <llvm/Support/raw_os_ostream.h>
    2930
    30 #define CHECK_SAME_TYPE(A, B) \
    31     assert ("DIFFERING CONTEXTS" && (&((A)->getType()->getContext()) == &((B)->getType()->getContext()))); \
    32     assert ("DIFFERING TYPES" && ((A)->getType() == (B)->getType()))
    33 
    3431using namespace llvm;
    3532
    3633namespace pablo {
    3734
    38 
    39 Phi * PabloBlock::createPhi(Type * type) {
    40     return new (mAllocator) Phi(type, mAllocator);
    41 }
     35#ifndef NDEBUG
     36inline void checkSameType(const Type * const A, const Type * const B) {
     37    assert ("DIFFERING CONTEXTS" && (&(A->getContext()) == &(B->getContext())));
     38    assert ("DIFFERING TYPES" && (A == B));
     39}
     40inline void checkSameType(const PabloAST * const A, const PabloAST * const B) {
     41    checkSameType(A->getType(), B->getType());
     42}
     43#define CHECK_SAME_TYPE(A, B) checkSameType(A, B)
     44#else
     45#define CHECK_SAME_TYPE(A, B)
     46#endif
    4247
    4348/// UNARY CREATE FUNCTIONS
     
    8792    return insertAtInsertionPoint(new (mAllocator) AtEOF(expr, name, mAllocator));
    8893}
    89    
    90    
     94
    9195/// BINARY CREATE FUNCTIONS
    9296
    93 Advance * PabloBlock::createAdvance(PabloAST * expr, PabloAST * shiftAmount, String * name) {
     97Advance * PabloBlock::createAdvance(PabloAST * expr, Integer * shiftAmount, String * name) {
    9498    if (name == nullptr) {
    9599        name = makeName("advance");
     
    98102}
    99103
    100 Lookahead * PabloBlock::createLookahead(PabloAST * expr, PabloAST * shiftAmount, String * name) {
     104Lookahead * PabloBlock::createLookahead(PabloAST * expr, Integer * shiftAmount, String * name) {
    101105    if (name == nullptr) {
    102106        name = makeName("lookahead");
     
    105109}
    106110
    107 Extract * PabloBlock::createExtract(PabloAST * array, PabloAST * index, String * name) {
     111Extract * PabloBlock::createExtract(Var * array, Integer * index) {
    108112    assert (array && index);
    109     if (name == nullptr) {
    110         std::string tmp;
    111         raw_string_ostream out(tmp);
    112         array->print(out);
    113         out << '[';
    114         index->print(out);
    115         out << ']';
    116         name = makeName(out.str());
    117     }
    118113    Type * type = array->getType();
    119114    if (LLVM_LIKELY(isa<ArrayType>(type))) {
     
    124119        out << "cannot extract element from ";
    125120        array->print(out);
    126         out << " : not a StreamType or ArrayType";
     121        out << ": ";
     122        type->print(out);
     123        out << " is not an array type";
    127124        throw std::runtime_error(out.str());
    128125    }
    129     return insertAtInsertionPoint(new (mAllocator) Extract(array, index, name, type, mAllocator));
     126    return new (mAllocator) Extract(array, index, type, mAllocator);
    130127}
    131128
     
    186183
    187184LessThan * PabloBlock::createLessThan(PabloAST * expr1, PabloAST * expr2) {
    188     CHECK_SAME_TYPE(expr1, expr2);
    189     IntegerType * const int1Ty = getParent()->getInt1Ty();
    190     return new (mAllocator) LessThan(int1Ty, expr1, expr2, mAllocator);
    191 }
    192 
    193 enum class AssignErrorType {
    194     TypeMismatch
    195     , ReadOnlyVar
    196     , NotAVariable
    197 };
    198 
    199 static void reportAssignError(PabloAST * const var, PabloAST * const value, const AssignErrorType type) {
    200     std::string tmp;
    201     raw_string_ostream out(tmp);
    202     out << "Cannot assign ";
    203     value->print(out);
    204     out << " to ";
    205     var->print(out);
    206     out << ": ";
    207     switch (type) {
    208         case AssignErrorType::TypeMismatch:
    209             out << "type mismatch ";
    210             value->getType()->print(out);
    211             out << " vs. ";
    212             var->getType()->print(out);
    213             break;
    214         case AssignErrorType::ReadOnlyVar:
    215             var->print(out);
    216             out << " is read only";
    217             break;
    218         case AssignErrorType::NotAVariable:
    219             var->print(out);
    220             out << " is not a variable";
    221             break;
    222     }
    223     llvm::report_fatal_error(out.str());
     185    const Type * const t1 = expr1->getType()->isArrayTy() ? expr1->getType()->getArrayElementType() : expr1->getType();
     186    const Type * const t2 = expr2->getType()->isArrayTy() ? expr2->getType()->getArrayElementType() : expr2->getType();
     187    CHECK_SAME_TYPE(t1, t2);
     188    Type * ty = getParent()->getInt1Ty();
     189    if (t1->isVectorTy() || t2->isVectorTy()) {
     190        ty = VectorType::get(ty, 0);
     191    }
     192    return new (mAllocator) LessThan(ty, expr1, expr2, mAllocator);
     193}
     194
     195Equals * PabloBlock::createEquals(PabloAST * expr1, PabloAST * expr2) {
     196    const Type * const t1 = expr1->getType()->isArrayTy() ? expr1->getType()->getArrayElementType() : expr1->getType();
     197    const Type * const t2 = expr2->getType()->isArrayTy() ? expr2->getType()->getArrayElementType() : expr2->getType();
     198    CHECK_SAME_TYPE(t1, t2);
     199    Type * ty = getParent()->getInt1Ty();
     200    if (t1->isVectorTy() || t2->isVectorTy()) {
     201        ty = VectorType::get(ty, 0);
     202    }
     203    return new (mAllocator) Equals(ty, expr1, expr2, mAllocator);
    224204}
    225205
    226206Assign * PabloBlock::createAssign(PabloAST * const var, PabloAST * const value) {
    227207    CHECK_SAME_TYPE(var, value);
    228 
    229     if (LLVM_UNLIKELY(var->getType() != value->getType())) {
    230         reportAssignError(var, value, AssignErrorType::TypeMismatch);
    231     }
    232 
    233     PabloAST * test = var;
    234     for (;;) {
    235         if (LLVM_LIKELY(isa<Var>(test))) {
    236             if (LLVM_UNLIKELY(cast<Var>(test)->isReadOnly())) {
    237                 reportAssignError(var, value, AssignErrorType::ReadOnlyVar);
    238             }
    239             break;
    240         } else if (isa<Extract>(test)) {
    241             test = cast<Extract>(test)->getArray();
     208    Var * test = nullptr;
     209    if (isa<Extract>(var)) {
     210        test = cast<Extract>(var)->getArray();
     211    } else if (isa<Var>(var)) {
     212        test = cast<Var>(var);
     213    }
     214    if (LLVM_UNLIKELY(test == nullptr || test->isReadOnly())) {
     215        std::string tmp;
     216        raw_string_ostream out(tmp);
     217        out << "cannot assign ";
     218        value->print(out);
     219        out << " to ";
     220        var->print(out);
     221        out << ": ";
     222        var->print(out);
     223        if (test == nullptr) {
     224            out << " must be an Extract expression or Var declaration";
    242225        } else {
    243             reportAssignError(var, value, AssignErrorType::NotAVariable);
     226            out << " is read only";
    244227        }
    245     }
    246 
     228        report_fatal_error(out.str());
     229    }
    247230    return insertAtInsertionPoint(new (mAllocator) Assign(var, value, mAllocator));
    248231}
     
    289272
    290273If * PabloBlock::createIf(PabloAST * condition, PabloBlock * body) {
    291     assert (condition);
     274    assert (condition && body);
    292275    If * const node = insertAtInsertionPoint(new (mAllocator) If(condition, body, mAllocator));
    293276    body->setBranch(node);
     
    296279
    297280While * PabloBlock::createWhile(PabloAST * condition, PabloBlock * body) {
    298     assert (condition);
     281    assert (condition && body);
    299282    While * const node = insertAtInsertionPoint(new (mAllocator) While(condition, body, mAllocator));
    300283    body->setBranch(node);
     
    302285}
    303286
     287Repeat * PabloBlock::createRepeat(Integer * fieldWidth, PabloAST * value, String * name) {
     288    assert (fieldWidth && value);
     289    if (name == nullptr) {
     290        name = makeName("fill");
     291    }
     292    Type * const type = VectorType::get(IntegerType::get(value->getType()->getContext(), fieldWidth->value()), 0);
     293    return insertAtInsertionPoint(new (mAllocator) Repeat(fieldWidth, value, type, name, mAllocator));
     294}
     295
     296PackH * PabloBlock::createPackH(Integer * fieldWidth, PabloAST * value, String * name) {
     297    assert (fieldWidth && value);
     298    if (name == nullptr) {
     299        name = makeName("packh");
     300    }
     301    Type * const type = VectorType::get(IntegerType::get(value->getType()->getContext(), fieldWidth->value()), 0);
     302    return insertAtInsertionPoint(new (mAllocator) PackH(fieldWidth, value, name, type, mAllocator));
     303}
     304
     305PackL * PabloBlock::createPackL(Integer * fieldWidth, PabloAST * value, String * name) {
     306    assert (fieldWidth && value);
     307    if (name == nullptr) {
     308        name = makeName("packl");
     309    }
     310    Type * const type = VectorType::get(IntegerType::get(value->getType()->getContext(), fieldWidth->value()), 0);
     311    return insertAtInsertionPoint(new (mAllocator) PackL(fieldWidth, value, name, type, mAllocator));
     312}
     313
    304314/// TERNARY CREATE FUNCTIONS
    305315
     
    312322}
    313323
    314 IndexedAdvance * PabloBlock::createIndexedAdvance(PabloAST * expr, PabloAST * indexStream, PabloAST * shiftAmount, String * name) {
     324IndexedAdvance * PabloBlock::createIndexedAdvance(PabloAST * expr, PabloAST * indexStream, Integer * shiftAmount, String * name) {
    315325    if (name == nullptr) {
    316326        name = makeName("indexed_advance");
Note: See TracChangeset for help on using the changeset viewer.