Changeset 4432 for icGREP/icgrep-devel


Ignore:
Timestamp:
Jan 21, 2015, 3:16:19 PM (5 years ago)
Author:
nmedfort
Message:

Temporary check in.

Location:
icGREP/icgrep-devel/icgrep
Files:
1 added
1 deleted
34 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/cc/cc_compiler.cpp

    r4431 r4432  
    1010//Pablo Expressions
    1111#include <pablo/codegenstate.h>
    12 #include <pablo/pe_metadata.h>
    1312#include <re/re_alt.h>
    1413#include <re/re_cc.h>
     
    1918#include <re/re_intersect.h>
    2019#include <re/re_assertion.h>
    21 #include <re/printer_re.h>
    2220#include <cc/cc_namemap.hpp>
    23 #include <pablo/printer_pablos.h>
    24 #include <utility>
    25 #include <string>
    26 #include <list>
    27 #include <map>
    28 #include <algorithm>
    29 #include <boost/graph/adjacency_list.hpp>
    30 #include <cassert>
    31 #include <stdlib.h>
    3221#include <stdexcept>
    3322
    3423using namespace re;
    3524using namespace pablo;
    36 using namespace boost;
    3725
    3826namespace cc {
    3927
    40 CC_Compiler::CC_Compiler(PabloBlock & cg, const Encoding encoding, const bool annotateVariableConstraints, const std::string basis_pattern)
     28CC_Compiler::CC_Compiler(PabloBlock & cg, const Encoding encoding, const std::string basis_pattern)
    4129: mCG(cg)
    42 //, mAnnotateVariableConstraints(annotateVariableConstraints)
    4330, mBasisBit(encoding.getBits())
    4431, mEncoding(encoding)
     
    289276}
    290277
    291 void CC_Compiler::computeVariableConstraints() {
    292     typedef adjacency_list<vecS, vecS, directedS> ConstraintGraph;
    293     typedef adjacency_list<vecS, vecS, directedS> SubsetGraph;
    294 
    295     typedef graph_traits<ConstraintGraph>::out_edge_iterator ConstraintEdgeIterator;
    296     typedef graph_traits<SubsetGraph>::out_edge_iterator SubsetEdgeIterator;
    297 
    298     const auto n = mVariableVector.size();
    299 
    300     if (n == 0) {
    301         return;
    302     }
    303 
    304     // Compute the constraint and subset graphs.
    305     ConstraintGraph C(n);
    306     SubsetGraph S(n);
    307 
    308     for (auto i = 0; i != n; ++i) {
    309         const CC * const cc1 = mVariableVector[i].first;
    310 
    311         for (auto j = i + 1; j != n; ++j) {
    312             const CC * const cc2 = mVariableVector[j].first;
    313             switch(cc1->compare(cc2)) {
    314                 case CC::SetRelationship::OVERLAPPING:
    315                     add_edge(i, j, C);
    316                     add_edge(j, i, C);
    317                     break;
    318                 case CC::SetRelationship::SUBSET:
    319                     add_edge(i, j, S);
    320                     break;
    321                 case CC::SetRelationship::SUPERSET:
    322                     add_edge(j, i, S);
    323                     break;
    324                 default:
    325                     /* do nothing; here just to prevent warning */
    326                     break;
    327             }
    328         }
    329     }
    330 
    331     // Write out the constraints and subset relationships as metadata
    332     for (auto i = 0; i != n; ++i) {
    333         std::vector<PabloAST *> constraints;
    334         ConstraintEdgeIterator ci, ci_end;
    335         for (std::tie(ci, ci_end) = out_edges(i, C); ci != ci_end; ++ci) {
    336             constraints.push_back(mVariableVector[target(*ci, C)].second);
    337         }
    338 
    339         std::vector<PabloAST *> subsets;
    340         SubsetEdgeIterator si, si_end;
    341         for (std::tie(si, si_end) = out_edges(i, S); si != si_end; ++si) {
    342             subsets.push_back(mVariableVector[target(*si, S)].second);
    343         }
    344 
    345         Assign * assign = mVariableVector[i].second;
    346         if (!constraints.empty()) {
    347             assign->setMetadata("constraints", PMDSet::get(constraints.begin(), constraints.end()));
    348         }
    349         if (!subsets.empty()) {
    350             assign->setMetadata("subsets", PMDSet::get(subsets.begin(), subsets.end()));
    351         }
    352     }
    353 }
    354 
    355278} // end of namespace cc
  • icGREP/icgrep-devel/icgrep/cc/cc_compiler.h

    r4410 r4432  
    1212#include <pablo/pabloAST.h>
    1313#include <re/re_cc.h>
    14 #include <unordered_map>
    1514#include <string>
    16 #include <iostream>
    1715
    1816namespace cc {
     
    2422public:
    2523
    26     CC_Compiler(pablo::PabloBlock & cg, const Encoding encoding, const bool annotateVariableConstraints = false, const std::string basis_pattern = "basis");
     24    CC_Compiler(pablo::PabloBlock & cg, const Encoding encoding, const std::string basis_pattern = "basis");
    2725
    2826    std::vector<pablo::Var *> getBasisBits(const CC_NameMap & nameMap);
     
    4341    pablo::PabloAST * char_or_range_expr(const re::CodePointType lo, const re::CodePointType hi, pablo::PabloBlock & pb);
    4442    pablo::PabloAST * charset_expr(const re::CC *cc, pablo::PabloBlock & pb);
    45 
    46     void computeVariableConstraints();
    47 
    4843private:
    4944    pablo::PabloBlock &         mCG;
    50     //const bool                  mAnnotateVariableConstraints;
    5145    std::vector<pablo::Var *>   mBasisBit;
    5246    const Encoding              mEncoding;
  • icGREP/icgrep-devel/icgrep/pablo/codegenstate.cpp

    r4419 r4432  
    1515}
    1616
     17PabloAST * PabloBlock::createAdvance(PabloAST * expr, PabloAST * shiftAmount) {
     18    if (isa<Zeroes>(expr) || cast<Integer>(shiftAmount)->value() == 0) {
     19        return expr;
     20    }
     21    return insertAtInsertionPoint(new Advance(expr, shiftAmount, mSymbolGenerator, this));
     22}
     23
    1724PabloAST * PabloBlock::createAdvance(PabloAST * expr, const int shiftAmount) {
    1825    if (isa<Zeroes>(expr) || shiftAmount == 0) {
    1926        return expr;
    20     }
    21     return insertAtInsertionPoint(new Advance(expr, shiftAmount, mSymbolGenerator, this));
    22 }
    23 
    24 Call * PabloBlock::createCall(const std::string name) {
    25     return createCall(mSymbolGenerator->get(name));
     27    }   
     28    return insertAtInsertionPoint(new Advance(expr, mSymbolGenerator->getInteger(shiftAmount), mSymbolGenerator, this));
    2629}
    2730
     
    4144    }
    4245    return insertAtInsertionPoint(new Not(expr, this));
    43 }
    44 
    45 Var * PabloBlock::createVar(const std::string name) {
    46     return createVar(mSymbolGenerator->get(name));
    4746}
    4847
     
    214213
    215214PabloBlock::PabloBlock()
    216 : mZeroes(new Zeroes())
     215: PabloAST(PabloAST::ClassTypeId::Block)
     216, mZeroes(new Zeroes())
    217217, mOnes(new Ones())
    218218, mSymbolGenerator(new SymbolGenerator())
     219, mPredecessor(nullptr)
    219220{
    220221
     
    222223
    223224PabloBlock::PabloBlock(PabloBlock * predecessor)
    224 : mZeroes(predecessor->mZeroes) // inherit the original "Zeroes" variable for simplicity
     225: PabloAST(PabloAST::ClassTypeId::Block)
     226, mZeroes(predecessor->mZeroes) // inherit the original "Zeroes" variable for simplicity
    225227, mOnes(predecessor->mOnes) // inherit the original "Ones" variable for simplicity
    226228, mSymbolGenerator(predecessor->mSymbolGenerator)
     229, mPredecessor(predecessor)
    227230{
    228231
    229232}
    230233
    231 }
     234PabloBlock::~PabloBlock() {
     235    if (mPredecessor == nullptr) {
     236        delete mSymbolGenerator;
     237    }   
     238}
     239
     240}
  • icGREP/icgrep-devel/icgrep/pablo/codegenstate.h

    r4419 r4432  
    5252
    5353
    54 class PabloBlock : public StatementList {
     54class PabloBlock : public PabloAST, public StatementList {
    5555    friend class pablo::PabloAST;
     56    friend class Builder;
    5657public:
     58
     59    static inline bool classof(const PabloBlock *) {
     60        return true;
     61    }
     62    static inline bool classof(const Statement *) {
     63        return false;
     64    }
     65    static inline bool classof(const PabloAST * e) {
     66        return e->getClassTypeId() == ClassTypeId::Block;
     67    }
     68    static inline bool classof(const void *) {
     69        return false;
     70    }
    5771
    5872    inline static PabloBlock & Create() {
     
    6680    PabloAST * createAdvance(PabloAST * expr, const int shiftAmount);
    6781
     82    PabloAST * createAdvance(PabloAST * expr, PabloAST * shiftAmount);
     83
    6884    inline Zeroes * createZeroes() const {
    6985        return mZeroes;
     
    7490    }
    7591
    76     Call * createCall(const std::string name);
     92    inline Call * createCall(const std::string name) {
     93        return createCall(getName(name));
     94    }
    7795
    7896    Call * createCall(String * name);
     
    8098    Assign * createAssign(const std::string prefix, PabloAST * expr, const int outputIndex = -1);
    8199
    82     Var * createVar(const std::string name);
     100    inline Var * createVar(const std::string name) {
     101        return createVar(getName(name));
     102    }
    83103
    84104    Var * createVar(String * name);
     
    124144    }
    125145
     146    virtual ~PabloBlock();
     147
    126148protected:
    127149    PabloBlock();
    128150
    129151    PabloBlock(PabloBlock * predecessor);
    130 
    131     void * operator new (std::size_t size) noexcept {
    132         return PabloAST::mAllocator.allocate(size);
    133     }
    134152
    135153    template<typename Type>
     
    145163    Ones * const                                        mOnes;
    146164    SymbolGenerator * const                             mSymbolGenerator;
     165    PabloBlock *                                        mPredecessor;
    147166};
    148167
  • icGREP/icgrep-devel/icgrep/pablo/expression_map.hpp

    r4419 r4432  
    7575    ExpressionTable()
    7676    : mUnary(nullptr)
    77     , mUnaryWithInt(nullptr)
    7877    , mBinary(nullptr)
    7978    , mTernary(nullptr)
     
    8483    ExpressionTable(ExpressionTable * predecessor)
    8584    : mUnary(predecessor ? &(predecessor->mUnary) : nullptr)
    86     , mUnaryWithInt(predecessor ? &(predecessor->mUnaryWithInt) : nullptr)
    8785    , mBinary(predecessor ? &(predecessor->mBinary) : nullptr)
    8886    , mTernary(predecessor ? &(predecessor->mTernary) : nullptr)
     
    9290
    9391    std::pair<PabloAST *, bool> insert(Statement * stmt) {
    94         switch (stmt->getClassTypeId()) {
    95             case PabloAST::ClassTypeId::Advance:
    96                 return mUnaryWithInt.insert(stmt, stmt->getClassTypeId(), stmt->getOperand(0), cast<Advance>(stmt)->getAdvanceAmount());
     92        switch (stmt->getClassTypeId()) {           
    9793            case PabloAST::ClassTypeId::Assign:
    9894            case PabloAST::ClassTypeId::Call:
     
    107103                    return std::make_pair(commExpr, false);
    108104                }
     105            case PabloAST::ClassTypeId::Advance:
    109106            case PabloAST::ClassTypeId::ScanThru:
    110107            case PabloAST::ClassTypeId::MatchStar:
     
    121118private:
    122119    ExpressionMap<PabloAST *>                           mUnary;
    123     ExpressionMap<PabloAST *, int>                      mUnaryWithInt;
    124120    ExpressionMap<PabloAST *, PabloAST *>               mBinary;
    125121    ExpressionMap<PabloAST *, PabloAST *, PabloAST *>   mTernary;
  • icGREP/icgrep-devel/icgrep/pablo/optimizers/pablo_simplifier.cpp

    r4419 r4432  
    1111bool Simplifier::optimize(PabloBlock & block) {
    1212    eliminateRedundantCode(block);
     13    deadCodeElimination(block);
    1314
    14     deadCodeElimination(block);
    1515    return true;
    1616}
     17
     18inline static bool canTriviallyFold(const Statement * stmt) {
     19    for (unsigned i = 0; i != stmt->getNumOperands(); ++i) {
     20        switch (stmt->getOperand(i)->getClassTypeId()) {
     21            case PabloAST::ClassTypeId::Zeroes:
     22            case PabloAST::ClassTypeId::Ones:
     23                return true;
     24            default: break;
     25        }
     26    }
     27    return false;
     28}
     29
    1730
    1831void Simplifier::eliminateRedundantCode(PabloBlock & block, ExpressionTable * predecessor) {
     
    2538            // If we have an Assign whose users do not contain an If or Next node, we can replace its users with
    2639            // the Assign's expression directly. However, since Assigns were likely named for clarity, propagate
    27             // it's name upwards into the expression.
     40            // it's name upwards into the expression's statement.
    2841            if (assign->isConstant()) {
    2942                PabloAST * expr = assign->getExpr();
     
    4053        else { // non-Assign node
    4154
    42             bool canTriviallyFold = false;
    43 
    4455            // Do a trivial folding test to see if we're using all 0s or 1s as an operand.
    45             for (unsigned i = 0; i != stmt->getNumOperands(); ++i) {
    46                 if (isa<Zeroes>(stmt->getOperand(i)) || isa<Ones>(stmt->getOperand(i))) {
    47                     canTriviallyFold = true;
    48                     break;
    49                 }
    50             }
    51 
    52             if (canTriviallyFold) {
     56            if (canTriviallyFold(stmt)) {
    5357                PabloAST * expr = nullptr;
    5458                block.setInsertPoint(stmt->getPrevNode());
    5559                switch (stmt->getClassTypeId()) {
    5660                    case PabloAST::ClassTypeId::Advance:
    57                         expr = block.createAdvance(stmt->getOperand(0), cast<Advance>(stmt)->getAdvanceAmount());
     61                        expr = block.createAdvance(stmt->getOperand(0), stmt->getOperand(1));
    5862                        break;
    5963                    case PabloAST::ClassTypeId::And:
     
    8286                }
    8387                assert (expr);
    84                 stmt = stmt->replaceWith(expr);
     88                stmt = stmt->replaceWith(expr);               
    8589                // the next statement could be an Assign; just restart the loop.
    8690                continue;
    8791            }
    88 
    89             if (isa<If>(stmt)) {
     92            else if (isa<If>(stmt)) {
    9093                eliminateRedundantCode(cast<If>(stmt)->getBody(), &encountered);
    9194            }
     
    9396                eliminateRedundantCode(cast<While>(stmt)->getBody(), &encountered);
    9497            }
    95             else if (stmt->getNumUses() == 0) {               
     98            else if (stmt->getNumUses() == 0) {
     99                // If this statement has no users, we can discard it. If a future "identical" statement occurs that does
     100                // have users, we can use that statement instead.
    96101                stmt = stmt->eraseFromParent();
    97102                continue;
    98103            }
    99             // When we're creating the Pablo program, it's possible that statements may occur more than once.
    100             // By recording which statements have already been seen, we can detect which statements are redundant.
    101             const auto f = encountered.insert(stmt);
    102             if (!std::get<1>(f)) {
    103                 stmt->replaceAllUsesWith(std::get<0>(f));
    104                 stmt = stmt->eraseFromParent();
    105                 continue;
     104            else {
     105                // When we're creating the Pablo program, it's possible to have multiple instances of an "identical"
     106                // statement. By recording which statements have already been seen, we can detect the redundant statements
     107                // as any having the same type and operands. If so, we can replace its users with the prior statement.
     108                // and erase this statement from the AST
     109                const auto f = encountered.insert(stmt);
     110                if (!std::get<1>(f)) {
     111                    stmt->replaceAllUsesWith(std::get<0>(f));
     112                    stmt = stmt->eraseFromParent();
     113                    continue;
     114                }
    106115            }
    107116        }
  • icGREP/icgrep-devel/icgrep/pablo/pabloAST.cpp

    r4419 r4432  
    88#include <pablo/codegenstate.h>
    99#include <llvm/Support/Compiler.h>
    10 
    11 #include <pablo/printer_pablos.h>
    1210
    1311namespace pablo {
     
    8280}
    8381
    84 void PabloAST::setMetadata(const std::string & name, PMDNode * node) {
    85     if (LLVM_UNLIKELY(mMetadataMap == nullptr)) {
    86         mMetadataMap = new PMDNodeMap();
    87     }
    88     mMetadataMap->insert(std::make_pair(name, node));
    89 }
    90 
    91 PMDNode * PabloAST::getMetadata(const std::string & name) {
    92     if (LLVM_UNLIKELY(mMetadataMap == nullptr)) {
    93         return nullptr;
    94     }
    95     auto f = mMetadataMap->find(name);
    96     if (f == mMetadataMap->end()) {
    97         return nullptr;
    98     }
    99     return f->second;
    100 }
    101 
    10282void PabloAST::replaceAllUsesWith(PabloAST * expr) {
    103     #ifndef NDEBUG
    104     unsigned __userCount = getNumUses();
    105     #endif
    10683    while (!mUsers.empty()) {
    10784        PabloAST * user = mUsers.pop_back_val();
    108         assert(--__userCount == getNumUses());
    10985        if (isa<Statement>(user)) {
    11086            cast<Statement>(user)->replaceUsesOfWith(this, expr);
    11187        }
    112         assert(__userCount == getNumUses());
    113     }
    114     assert (getNumUses() == 0);
    115 }
    116 
    117 void Statement::setOperand(const unsigned index, PabloAST * value) {
     88    }
     89}
     90
     91void Statement::setOperand(const unsigned index, PabloAST * const value) {
    11892    assert (index < getNumOperands());
    119     if (LLVM_UNLIKELY(mOperand[index] == value)) {
     93    if (LLVM_UNLIKELY(getOperand(index) == value)) {
    12094        return;
    12195    }
    122     PabloAST * priorValue = mOperand[index];
    123     // Test just to be sure we don't have multiple operands pointing to
     96    PabloAST * priorValue = getOperand(index);
     97    // Test just to be sure that we don't have multiple operands pointing to
    12498    // what we're replacing. If not, remove this from the prior value's
    12599    // user list.
    126100    unsigned count = 0;
    127101    for (unsigned i = 0; i != getNumOperands(); ++i) {
    128         count += (mOperand[index] == priorValue) ? 1 : 0;
     102        count += (getOperand(index) == priorValue) ? 1 : 0;
    129103    }
    130104    assert (count >= 1);
     
    198172
    199173    // remove this statement from its operands' users list
    200     for (PabloAST * op : mOperand) {
     174    for (auto i = 0; i != mOperands; ++i) {
     175        PabloAST * const op = mOperand[i];
    201176        op->removeUser(this);
    202177    }
    203178
    204179    if (recursively) {
    205         for (PabloAST * op : mOperand) {
     180        for (auto i = 0; i != mOperands; ++i) {
     181            PabloAST * const op = mOperand[i];
    206182            if (op->getNumUses() == 0 && isa<Statement>(op)) {
    207183                cast<Statement>(op)->eraseFromParent(true);
     
    209185        }
    210186    }
    211 
    212187    return removeFromParent();
    213188}
     
    219194    replaceAllUsesWith(expr);
    220195    return eraseFromParent();
    221 }
    222 
    223 Statement::~Statement() {
    224 
    225196}
    226197
     
    242213}
    243214
    244 }
     215StatementList::~StatementList() {
     216
     217}
     218
     219}
  • icGREP/icgrep-devel/icgrep/pablo/pabloAST.h

    r4419 r4432  
    2121class PabloBlock;
    2222
    23 class PMDNode;
    24 
    2523class PabloAST {
    26     friend class PMDNode;
    2724    friend class Statement;
    2825    friend class Var;
     
    3128    friend class PabloBlock;
    3229    friend class SymbolGenerator;
    33     typedef std::unordered_map<std::string, PMDNode *> PMDNodeMap;
    34 
    3530public:
    3631
     
    3833    using user_iterator = Users::iterator;
    3934
    40     typedef SlabAllocator<4096> Allocator;
     35    typedef SlabAllocator<PabloAST *> Allocator;
    4136    enum class ClassTypeId : unsigned {
    4237        Advance
     
    5853        , Xor
    5954        , Zeroes
     55        , Block
    6056    };
    6157    inline ClassTypeId getClassTypeId() const {
     
    6359    }
    6460
    65     void setMetadata(const std::string & name, PMDNode * node);
    66 
    67     PMDNode * getMetadata(const std::string & name);
    68 
    6961    inline static void release_memory() {
    7062        mAllocator.release_memory();
     
    9991    inline PabloAST(const ClassTypeId id)
    10092    : mClassTypeId(id)
    101     , mMetadataMap(nullptr)
    10293    {
    10394
     
    10899    inline void removeUser(PabloAST * user) {
    109100        mUsers.remove(user);
     101    }
     102    virtual ~PabloAST() {
     103        mUsers.clear();
    110104    }
    111105    static Allocator        mAllocator;
     
    113107    const ClassTypeId       mClassTypeId;
    114108    Users                   mUsers;
    115     PMDNodeMap *            mMetadataMap;
    116109};
    117110
     
    148141    }
    149142
    150     inline void replaceUsesOfWith(PabloAST * from, PabloAST * to) {
     143    inline void replaceUsesOfWith(const PabloAST * const from, PabloAST * const to) {
    151144        for (unsigned i = 0; i != getNumOperands(); ++i) {
    152145            if (getOperand(i) == from) {
     
    161154    }
    162155
    163     void setOperand(const unsigned index, PabloAST * value);
     156    void setOperand(const unsigned index, PabloAST * const value);
    164157
    165158    inline unsigned getNumOperands() const {
    166         return mOperand.size();
     159        return mOperands;
    167160    }
    168161
     
    185178        return mParent;
    186179    }
     180    virtual ~Statement() {}
    187181protected:
    188     Statement(const ClassTypeId id, std::vector<PabloAST *> && operands, const String * name, PabloBlock * parent)
     182    Statement(const ClassTypeId id, std::initializer_list<PabloAST *> operands, const String * const name, PabloBlock * const parent)
    189183    : PabloAST(id)
    190184    , mName(name)
     
    192186    , mPrev(nullptr)
    193187    , mParent(parent)
    194     , mOperand(std::move(operands))
     188    , mOperands(operands.size())
     189    , mOperand(mAllocator.allocate(mOperands * sizeof(PabloAST *)))
    195190    {
    196         for (PabloAST * op : mOperand) {
     191        unsigned i = 0;
     192        for (PabloAST * const op : operands) {
     193            mOperand[i++] = op;
    197194            op->addUser(this);
    198195        }
    199196    }
    200     inline void setName(const String * name) {
     197    inline void setName(const String * const name) {
    201198        mName = name;
    202199    }
    203     virtual ~Statement() = 0;
    204 protected:
     200protected:   
    205201    const String *              mName;
    206202    Statement *                 mNext;
    207203    Statement *                 mPrev;
    208204    PabloBlock *                mParent;
    209     std::vector<PabloAST *>     mOperand;
    210 
     205    const unsigned              mOperands;
     206    // If we knew prior to construction how many operands were needed, we could
     207    // eliminate the mOperand pointer and simply use this[1] instead.
     208    PabloAST **                 mOperand;
    211209};
    212210
     
    450448    void insert(Statement * const statement);
    451449
     450    ~StatementList();
     451
    452452private:
    453453
  • icGREP/icgrep-devel/icgrep/pablo/pe_advance.h

    r4414 r4432  
    1010#include "pabloAST.h"
    1111#include <pablo/symbol_generator.h>
     12#include <pablo/pe_integer.h>
    1213
    1314namespace pablo {
     
    2526    }
    2627    inline PabloAST * getExpr() const {
    27         return mOperand[0];
     28        return getOperand(0);
    2829    }
    29     inline int getAdvanceAmount() const {
    30         return mShiftAmount;
     30    inline Integer::integer_t getAdvanceAmount() const {
     31        return cast<Integer>(getOperand(1))->value();
    3132    }
    3233protected:
    33     Advance(PabloAST * expr, int shiftAmount, SymbolGenerator * sg, PabloBlock * parent)
    34     : Statement(ClassTypeId::Advance, {expr}, sg->make("advance"), parent)
    35         , mShiftAmount(shiftAmount) {
    36 
     34    Advance(PabloAST * expr, PabloAST * shiftAmount, SymbolGenerator * sg, PabloBlock * parent)
     35    : Statement(ClassTypeId::Advance, {expr, shiftAmount}, sg->make("advance"), parent)
     36    {
     37        assert(isa<Integer>(shiftAmount));
    3738    }
    38 private:
    39         int const mShiftAmount;
    4039};
    4140
  • icGREP/icgrep-devel/icgrep/pablo/pe_and.cpp

    r4419 r4432  
    1414
    1515And::And(PabloAST * expr1, PabloAST * expr2, PabloBlock * parent)
    16 : Statement(ClassTypeId::And, {{expr1, expr2}}, parent->makeName("and"), parent)
     16: Statement(ClassTypeId::And, {expr1, expr2}, parent->makeName("and"), parent)
    1717{
    1818
  • icGREP/icgrep-devel/icgrep/pablo/pe_and.h

    r4419 r4432  
    2727    }
    2828    PabloAST * getExpr1() const {
    29         return mOperand[0];
     29        return getOperand(0);
    3030    }
    3131    PabloAST * getExpr2() const {
    32         return mOperand[1];
     32        return getOperand(1);
    3333    }
    3434protected:
  • icGREP/icgrep-devel/icgrep/pablo/pe_call.h

    r4414 r4432  
    2020    }
    2121    inline const String * getCallee() const {
    22         return cast<String>(mOperand[0]);
     22        return cast<String>(getOperand(0));
    2323    }
    2424protected:
  • icGREP/icgrep-devel/icgrep/pablo/pe_integer.h

    r4416 r4432  
    88class Integer : public PabloAST {
    99    friend class SymbolGenerator;
     10public:
    1011    typedef u_int64_t integer_t;
    1112    static inline bool classof(const PabloAST * e) {
  • icGREP/icgrep-devel/icgrep/pablo/pe_matchstar.h

    r4414 r4432  
    2323        return false;
    2424    }
    25     virtual ~MatchStar() {
    26     }
    2725    inline PabloAST * getMarker() const {
    28         return mOperand[0];
     26        return getOperand(0);
    2927    }
    3028    inline PabloAST * getCharClass() const  {
    31         return mOperand[1];
     29        return getOperand(1);
    3230    }
     31    virtual ~MatchStar() {}
    3332protected:
    3433    MatchStar(PabloAST * marker, PabloAST * cc, SymbolGenerator * sg, PabloBlock * parent)
    35     : Statement(ClassTypeId::MatchStar, {{marker, cc}}, sg->make("matchstar"), parent)
     34    : Statement(ClassTypeId::MatchStar, {marker, cc}, sg->make("matchstar"), parent)
    3635    {
    3736
  • icGREP/icgrep-devel/icgrep/pablo/pe_next.h

    r4416 r4432  
    2121    }
    2222    inline const Assign * getInitial() const {
    23         return cast<const Assign>(mOperand[0]);
     23        return cast<const Assign>(getOperand(0));
    2424    }
    2525    inline PabloAST * getExpr() const {
    26         return mOperand[1];
     26        return getOperand(1);
    2727    }
     28    virtual ~Next() {}
    2829protected:
    2930    Next(PabloAST * initial, PabloAST * expr, PabloBlock * parent)
    30     : Statement(ClassTypeId::Next, {{cast<Assign>(initial), expr}}, cast<Assign>(initial)->getName(), parent) {
     31    : Statement(ClassTypeId::Next, {cast<Assign>(initial), expr}, cast<Assign>(initial)->getName(), parent) {
    3132        this->addUser(initial);
    3233    }
  • icGREP/icgrep-devel/icgrep/pablo/pe_not.h

    r4419 r4432  
    2626    }
    2727    PabloAST * getExpr() const {
    28         return mOperand[0];
     28        return getOperand(0);
    2929    }
    3030protected:
  • icGREP/icgrep-devel/icgrep/pablo/pe_ones.h

    r4410 r4432  
    2424    virtual ~Ones() {
    2525    }
    26 //    virtual PabloAST * getOperand(const unsigned) const {
    27 //        assert (false);
    28 //        return nullptr;
    29 //    }
    30 //    virtual unsigned getNumOperands() const {
    31 //        return 0;
    32 //    }
    33 //    virtual void setOperand(const unsigned, PabloAST *) {
    34 //        assert (false);
    35 //    }
    3626    inline bool operator==(const Ones & other) const {
    3727        return true;
  • icGREP/icgrep-devel/icgrep/pablo/pe_or.cpp

    r4419 r4432  
    1515
    1616Or::Or(PabloAST * expr1, PabloAST * expr2, PabloBlock * parent)
    17 : Statement(ClassTypeId::Or, {{expr1, expr2}}, parent->makeName("or"), parent)
     17: Statement(ClassTypeId::Or, {expr1, expr2}, parent->makeName("or"), parent)
    1818{
    1919
  • icGREP/icgrep-devel/icgrep/pablo/pe_scanthru.h

    r4414 r4432  
    2626    }
    2727    PabloAST * getScanFrom() const {
    28         return mOperand[0];
     28        return getOperand(0);
    2929    }
    3030    PabloAST * getScanThru() const {
    31         return mOperand[1];
     31        return getOperand(1);
    3232    }
     33protected:
    3334    ScanThru(PabloAST * from, PabloAST * thru, SymbolGenerator * sg, PabloBlock * parent)
    34     : Statement(ClassTypeId::ScanThru, {{from, thru}}, sg->make("scanthru"), parent)
     35    : Statement(ClassTypeId::ScanThru, {from, thru}, sg->make("scanthru"), parent)
    3536    {
    3637
  • icGREP/icgrep-devel/icgrep/pablo/pe_sel.cpp

    r4419 r4432  
    1515
    1616Sel::Sel(PabloAST* if_expr, PabloAST* t_expr, PabloAST* f_expr, PabloBlock * parent)
    17 : Statement(ClassTypeId::Sel, {{if_expr, t_expr, f_expr}}, parent->makeName("sel"), parent)
     17: Statement(ClassTypeId::Sel, {if_expr, t_expr, f_expr}, parent->makeName("sel"), parent)
    1818{
    1919
  • icGREP/icgrep-devel/icgrep/pablo/pe_sel.h

    r4419 r4432  
    2727    }
    2828    inline PabloAST * getCondition() const {
    29         return mOperand[0];
     29        return getOperand(0);
    3030    }
    3131    inline PabloAST * getTrueExpr() const {
    32         return mOperand[1];
     32        return getOperand(1);
    3333    }
    3434    inline PabloAST * getFalseExpr() const {
    35         return mOperand[2];
     35        return getOperand(2);
    3636    }
    3737protected:
  • icGREP/icgrep-devel/icgrep/pablo/pe_xor.cpp

    r4419 r4432  
    1414
    1515Xor::Xor(PabloAST * expr1, PabloAST * expr2, PabloBlock * parent)
    16 : Statement(ClassTypeId::Xor, {{expr1, expr2}}, parent->makeName("xor"), parent)
     16: Statement(ClassTypeId::Xor, {expr1, expr2}, parent->makeName("xor"), parent)
    1717{
    1818
  • icGREP/icgrep-devel/icgrep/pablo/pe_xor.h

    r4419 r4432  
    2727    }
    2828    PabloAST * getExpr1() const {
    29         return mOperand[0];
     29        return getOperand(0);
    3030    }
    3131    PabloAST * getExpr2() const {
    32         return mOperand[1];
     32        return getOperand(1);
    3333    }
    3434protected:
  • icGREP/icgrep-devel/icgrep/pablo/ps_assign.cpp

    r4416 r4432  
    1010    }
    1111    for (const PabloAST * inst : users()) {
    12         if (isa<Next>(inst) || isa<If>(inst)) {
     12        if (isa<Next>(inst)) {
     13            return false;
     14        }
     15        if (isa<If>(inst)) {
     16            // if this Assign is the condition of an If node but not a defined var,
     17            // then this Assign is a "constant".
     18            if (cast<If>(inst)->getCondition() == this) {
     19                const auto & dv = cast<If>(inst)->getDefined();
     20                if (LLVM_LIKELY(std::find(dv.begin(), dv.end(), this) == dv.end())) {
     21                    continue;
     22                }
     23            }
    1324            return false;
    1425        }
  • icGREP/icgrep-devel/icgrep/pablo/ps_assign.h

    r4416 r4432  
    2626    }
    2727    inline PabloAST * getExpr() const {
    28         return mOperand[0];
     28        return getOperand(0);
    2929    }
    3030    inline bool isOutputAssignment() const {
  • icGREP/icgrep-devel/icgrep/pablo/ps_if.h

    r4419 r4432  
    2727    }
    2828    virtual ~If() {
     29        mDefined.clear();
    2930    }
    3031    inline PabloAST * getCondition() const {
    31         return mOperand[0];
     32        return getOperand(0);
    3233    }
    3334    inline PabloBlock & getBody() {
  • icGREP/icgrep-devel/icgrep/pablo/ps_while.h

    r4414 r4432  
    2424    }
    2525    inline PabloAST * getCondition() const {
    26         return mOperand[0];
     26        return getOperand(0);
    2727    }
    2828    inline PabloBlock & getBody() {
  • icGREP/icgrep-devel/icgrep/pablo/symbol_generator.cpp

    r4416 r4432  
    3030}
    3131
    32 Integer * SymbolGenerator::get(const integer_t value) {
     32Integer * SymbolGenerator::getInteger(const integer_t value) {
    3333    auto f = mIntegerMap.find(value);
    3434    Integer * result;
    3535    if (f == mIntegerMap.end()) {
    3636        result = new Integer(value);
     37        assert (result->value() == value);
    3738        mIntegerMap.insert(std::make_pair(value, result));
    3839    }
     
    5657}
    5758
     59SymbolGenerator::~SymbolGenerator() {
     60    for (auto itr : mStringMap) {
     61        delete itr.second;
     62    }
     63    for (auto itr : mIntegerMap) {
     64        delete itr.second;
     65    }
     66}
    5867
    5968}
  • icGREP/icgrep-devel/icgrep/pablo/symbol_generator.h

    r4416 r4432  
    2121public:
    2222    typedef u_int64_t integer_t;
    23 
    2423    String * get(const std::string name);
    2524    String * make(const std::string prefix);
    26     Integer * get(const integer_t value);
     25    Integer * getInteger(const integer_t value);
     26    ~SymbolGenerator();
    2727protected:
    28     SymbolGenerator();
    29     void* operator new (std::size_t size) noexcept {
    30         return PabloAST::mAllocator.allocate(size);
    31     }
     28    SymbolGenerator();   
    3229private:
    3330    std::unordered_map<std::string, unsigned>   mPrefixMap;   
  • icGREP/icgrep-devel/icgrep/re/re_alt.h

    r4272 r4432  
    1111#include "re_cc.h"
    1212#include <queue>
    13 #include <iostream>
    1413
    1514namespace re {
  • icGREP/icgrep-devel/icgrep/re/re_cc.cpp

    r4339 r4432  
    102102}
    103103
    104 CC::SetRelationship CC::compare(const CC * other) const {
    105 
    106     if (LLVM_UNLIKELY(other == this)) {
    107         return SetRelationship::EQUIVALENT;
    108     }
    109 
    110     auto ai = cbegin();
    111     const auto ai_end = cend();
    112     auto bi = other->cbegin();
    113     const auto bi_end = other->cend();
    114 
    115     bool nonSubset = false;
    116     bool nonSuperset = false;
    117     bool disjoint = true;
    118 
    119     while (ai != ai_end && bi != bi_end) {
    120         const CharSetItem & ra = *ai;
    121         const CharSetItem & rb = *bi;
    122 
    123         // _A_| ...
    124         //     |_B_
    125 
    126         // A may be a superset of B but it cannot be a subset of B
    127 
    128         if (ra.hi_codepoint < rb.lo_codepoint) {
    129             ++ai;
    130             nonSubset = true;
    131             continue;
    132         }
    133 
    134         //     |_A_
    135         // _B_| ...
    136 
    137         // A may be a subset of B but it cannot be a superset of B
    138 
    139 
    140         if (rb.hi_codepoint < ra.lo_codepoint) {
    141             ++bi;
    142             nonSuperset = true;
    143             continue;
    144         }
    145 
    146         disjoint = false;
    147 
    148         // |_A__
    149         //   |_B__
    150 
    151         // A may be a superset of B but it cannot be a subset of B nor can it be disjoint
    152 
    153         if (ra.lo_codepoint < rb.lo_codepoint) {
    154             nonSubset = true;
    155         }
    156 
    157         //   |_A__
    158         // |_B__
    159 
    160         // A may be a subset of B but it cannot be a superset of B nor can it be disjoint
    161 
    162         if (rb.lo_codepoint < ra.lo_codepoint) {
    163             nonSuperset = true;
    164         }
    165 
    166         // __A__| ...
    167         // __B______|
    168 
    169         // SUCC(A) may overlap B in some way; only increment A
    170 
    171         if (ra.hi_codepoint <= rb.hi_codepoint) {
    172             ++ai;
    173         }
    174 
    175         // __A______|
    176         // __B__| ...
    177 
    178         // SUCC(B) may overlap A in some way; only increment B
    179 
    180         if (rb.hi_codepoint <= ra.hi_codepoint) {
    181             ++bi;
    182         }
    183 
    184     }
    185     if (disjoint) {
    186         return SetRelationship::DISJOINT;
    187     }
    188 
    189     if (ai == ai_end && bi != bi_end) {
    190         nonSuperset = true;
    191     }
    192     else if (bi == bi_end && ai != ai_end) {
    193         nonSubset = true;
    194     }
    195 
    196     if (nonSubset && nonSuperset) {
    197         return SetRelationship::OVERLAPPING;
    198     }
    199     else if (nonSubset) {
    200         return SetRelationship::SUPERSET;
    201     }
    202     else if (nonSuperset) {
    203         return SetRelationship::SUBSET;
    204     }
    205     return SetRelationship::EQUIVALENT;
    206 }
    207 
    208104CC * subtractCC(const CC * cc1, const CC * cc2) {
    209105    CC * diff = makeCC();
  • icGREP/icgrep-devel/icgrep/re/re_cc.h

    r4337 r4432  
    3737        return false;
    3838    }
    39 
    40     enum class SetRelationship {
    41         SUBSET
    42         , SUPERSET       
    43         , OVERLAPPING
    44         , DISJOINT
    45         , EQUIVALENT
    46     };
    4739
    4840    typedef CharSetVector::iterator                 iterator;
     
    117109        return mSparseCharSet.empty();
    118110    }
    119 
    120     SetRelationship compare(const CC * other) const;
    121111
    122112    virtual ~CC() {}
  • icGREP/icgrep-devel/icgrep/re/re_re.h

    r4405 r4432  
    3737class RE {
    3838public:
    39     typedef SlabAllocator<1024> Allocator;
     39    typedef SlabAllocator<RE *> Allocator;
    4040    enum class ClassTypeId : unsigned {
    4141        Alt
  • icGREP/icgrep-devel/icgrep/slab_allocator.h

    r4272 r4432  
    66#include <new>
    77#include <algorithm>
    8 #include <iostream>
    98
    10 template <unsigned BasePoolSize>
     9template <typename T>
    1110class SlabAllocator {
    1211public:
    1312
    14     typedef std::size_t size_type;
    15     typedef void* pointer;
    16     typedef const void* const_pointer;
     13    enum { BasePoolSize = 4096 };
     14
     15    using value_type = T;
     16    using pointer = T*;
     17    using const_pointer = const T*;
     18    using reference = T&;
     19    using const_reference = const T&;
     20    using size_type = std::size_t;
     21    using difference_type = std::ptrdiff_t;
     22
     23    template<class U>
     24    struct rebind {
     25        typedef SlabAllocator<U> other;
     26    };
    1727
    1828    inline pointer allocate(size_type n) noexcept {
     
    2030            exit(-1);
    2131        }
    22         pointer ptr = static_cast<pointer>(mAllocationPtr);
     32        pointer ptr = reinterpret_cast<pointer>(mAllocationPtr);
    2333        mAllocationPtr += n;
    2434        mSpaceAvail -= n;
     
    2636    }
    2737
    28     inline void deallocate(pointer p) noexcept {
     38    inline void deallocate(pointer p, size_type n) noexcept {
    2939        /* do nothing */
    3040    }
     
    4959};
    5060
    51 template <unsigned BasePoolSize>
    52 SlabAllocator<BasePoolSize>::SlabAllocator()
     61template <typename T>
     62SlabAllocator<T>::SlabAllocator()
    5363: mSpaceAvail(BasePoolSize)
    5464, mAllocationPtr(mInitialChunk.space)
     
    5969}
    6070
    61 template <unsigned BasePoolSize>
    62 SlabAllocator<BasePoolSize>::~SlabAllocator() {
     71template <typename T>
     72SlabAllocator<T>::~SlabAllocator() {
    6373    release_memory();
    6474}
    6575
    66 template <unsigned BasePoolSize>
    67 void SlabAllocator<BasePoolSize>::release_memory() {
     76template <typename T>
     77void SlabAllocator<T>::release_memory() {
    6878    while (mCurrentChunk != &mInitialChunk) {
    6979        Chunk * n = mCurrentChunk;
     
    7585}
    7686
    77 template <unsigned BasePoolSize>
    78 bool SlabAllocator<BasePoolSize>::extend(const size_type n) noexcept {
     87template <typename T>
     88bool SlabAllocator<T>::extend(const size_type n) noexcept {
    7989    const size_type size = std::max<size_type>(n, mTotalSize) * 2;
    8090    Chunk * newChunk = (Chunk *)malloc(sizeof(Chunk) + size - BasePoolSize);
Note: See TracChangeset for help on using the changeset viewer.