Changeset 4270


Ignore:
Timestamp:
Oct 25, 2014, 4:41:50 PM (5 years ago)
Author:
nmedfort
Message:

Minor changes.

Location:
icGREP/icgrep-devel/icgrep
Files:
10 edited

Legend:

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

    r4260 r4270  
    4343}
    4444
    45 void CC_Compiler::compile(const CC_NameMap & nameMap) {
     45std::vector<Var *> CC_Compiler::compile(const CC_NameMap & nameMap) {
    4646    for (Name * name : nameMap) {
    4747        compile_re(name);
    4848    }
     49    return std::move(mBasisBit);
    4950}
    5051
  • icGREP/icgrep-devel/icgrep/cc/cc_compiler.h

    r4249 r4270  
    2222public:
    2323
    24     typedef std::vector<pablo::Var *>       BasisBitVars;
    25 
    2624    CC_Compiler(pablo::PabloBlock & cg, const Encoding encoding, const std::string basis_pattern = "basis");
    2725
    28     void compile(const CC_NameMap & nameMap);
    29 
    30     const BasisBitVars & getBasisBitVars() const {
    31         return mBasisBit;
    32     }
     26    std::vector<pablo::Var *> compile(const CC_NameMap & nameMap);
    3327
    3428private:
     
    4943    pablo::PabloAST * tempify(pablo::PabloAST * value);
    5044    pablo::PabloBlock &         mCG;
    51     BasisBitVars                mBasisBit;
     45    std::vector<pablo::Var *>   mBasisBit;
    5246    const Encoding              mEncoding;
    5347};
  • icGREP/icgrep-devel/icgrep/compiler.cpp

    r4268 r4270  
    9797
    9898    CC_Compiler cc_compiler(main, encoding);
    99     cc_compiler.compile(nameMap);
     99    auto basisBits = cc_compiler.compile(nameMap);
    100100    #ifdef DEBUG_PRINT_PBIX_AST
    101101    //Print to the terminal the AST that was generated by the character class compiler.
     
    110110    #endif
    111111
    112     PabloCompiler pablo_compiler(cc_compiler.getBasisBitVars(), encoding.getBits());
     112    PabloCompiler pablo_compiler(basisBits);
    113113    unsigned long long cycles = 0;
    114114    double timer = 0;
  • icGREP/icgrep-devel/icgrep/pablo/analysis/useanalysis.cpp

    r4268 r4270  
    11#include "useanalysis.h"
     2#include <queue>
    23
    34namespace pablo {
     
    56void UseAnalysis::optimize(PabloBlock & block) {
    67    UseAnalysis analyzer;
    7     analyzer.traverse(analyzer.mRoot, block.statements());
     8    analyzer.gatherUseDefInformation(analyzer.mRoot, block.statements());
    89
    910}
    1011
    11 void UseAnalysis::traverse(const Vertex v, StatementList & statements) {
     12void UseAnalysis::identifyDeadVariables() {
     13    std::queue<Vertex> Q;
     14    // gather up all of the nodes that aren't output assignments and have no users
     15    const auto vMap = get(vertex_name, mUseDefGraph);
     16    VertexIterator vi, vi_end;
     17    for (std::tie(vi, vi_end) = vertices(mUseDefGraph); vi != vi_end; ++vi) {
     18        const Vertex v = *vi;
     19        if (out_degree(v) == 0) {
     20            const PabloAST * n = vMap[v];
     21            if (isa<Assign>(n) && (cast<Assign>(n)->isOutputAssignment())) {
     22                continue;
     23            }
     24            Q.push(v);
     25        }
     26    }
     27    while (!Q.empty()) {
     28        const Vertex v = Q.front();
     29        Q.pop();
     30        InEdgeIterator ei, ei_end;
     31        for (std::tie(ei, ei_end) = in_edges(v, mUseDefGraph); ei != ei_end; ++ei) {
     32            const Vertex u = source(*ei, mUseDefGraph);
     33            if (out_degree(u, mUseDefGraph) == 1) {
     34                Q.push(u);
     35            }
     36        }
     37        clear_in_edges(v, mUseDefGraph);
     38    }
     39}
     40
     41void UseAnalysis::gatherUseDefInformation(const Vertex v, StatementList & statements) {
    1242    for (PabloAST * stmt : statements) {
    1343        const Vertex u = find(stmt);
    1444        add_edge(u, v, mUseDefGraph);
    1545        if (const Assign * assign = dyn_cast<Assign>(stmt)) {
    16             traverse(u, assign->getExpr());
     46            gatherUseDefInformation(u, assign->getExpr());
    1747        }
    1848        if (const Next * next = dyn_cast<Next>(stmt)) {
    19             traverse(u, next->getExpr());
     49            gatherUseDefInformation(u, next->getExpr());
    2050        }
    2151        else if (If * ifStatement = dyn_cast<If>(stmt)) {
    22             traverse(u, ifStatement->getCondition());
    23             traverse(u, ifStatement->getBody());
     52            gatherUseDefInformation(u, ifStatement->getCondition());
     53            gatherUseDefInformation(u, ifStatement->getBody());
    2454        }
    2555        else if (While * whileStatement = dyn_cast<While>(stmt)) {
    26             traverse(u, whileStatement->getCondition());
    27             traverse(u, whileStatement->getBody());
     56            gatherUseDefInformation(u, whileStatement->getCondition());
     57            gatherUseDefInformation(u, whileStatement->getBody());
    2858        }
    2959    }
    3060}
    3161
    32 void UseAnalysis::traverse(const Vertex v, PabloAST * expr) {
     62void UseAnalysis::gatherUseDefInformation(const Vertex v, PabloAST * expr) {
    3363    const Vertex u = find(expr);
    3464    add_edge(u, v, mUseDefGraph);
    3565    if (const And * pablo_and = dyn_cast<const And>(expr)) {
    36         traverse(u, pablo_and->getExpr1());
    37         traverse(u, pablo_and->getExpr2());
     66        gatherUseDefInformation(u, pablo_and->getExpr1());
     67        gatherUseDefInformation(u, pablo_and->getExpr2());
    3868    }
    3969    else if (const Or * pablo_or = dyn_cast<const Or>(expr)) {
    40         traverse(u, pablo_or->getExpr1());
    41         traverse(u, pablo_or->getExpr2());
     70        gatherUseDefInformation(u, pablo_or->getExpr1());
     71        gatherUseDefInformation(u, pablo_or->getExpr2());
    4272    }
    4373    else if (const Sel * pablo_sel = dyn_cast<const Sel>(expr)) {
    44         traverse(u, pablo_sel->getCondition());
    45         traverse(u, pablo_sel->getTrueExpr());
    46         traverse(u, pablo_sel->getFalseExpr());
     74        gatherUseDefInformation(u, pablo_sel->getCondition());
     75        gatherUseDefInformation(u, pablo_sel->getTrueExpr());
     76        gatherUseDefInformation(u, pablo_sel->getFalseExpr());
    4777    }
    4878    else if (const Not * pablo_not = dyn_cast<const Not>(expr)) {
    49         traverse(u, pablo_not->getExpr());
     79        gatherUseDefInformation(u, pablo_not->getExpr());
    5080    }
    5181    else if (const Advance * adv = dyn_cast<const Advance>(expr)) {
    52         traverse(u, adv->getExpr());
     82        gatherUseDefInformation(u, adv->getExpr());
    5383    }
    5484    else if (const MatchStar * mstar = dyn_cast<const MatchStar>(expr)) {
    55         traverse(u, mstar->getMarker());
    56         traverse(u, mstar->getCharClass());
     85        gatherUseDefInformation(u, mstar->getMarker());
     86        gatherUseDefInformation(u, mstar->getCharClass());
    5787    }
    5888    else if (const ScanThru * sthru = dyn_cast<const ScanThru>(expr)) {
    59         traverse(u, sthru->getScanFrom());
    60         traverse(u, sthru->getScanThru());
     89        gatherUseDefInformation(u, sthru->getScanFrom());
     90        gatherUseDefInformation(u, sthru->getScanThru());
    6191    }
    6292}
  • icGREP/icgrep-devel/icgrep/pablo/analysis/useanalysis.h

    r4266 r4270  
    1212class UseAnalysis
    1313{
    14     typedef adjacency_list<hash_setS, vecS, directedS, property<vertex_name_t, PabloAST*>> UseDefGraph;
    15     typedef UseDefGraph::vertex_descriptor Vertex;
     14    typedef adjacency_list<hash_setS, vecS, bidirectionalS, property<vertex_name_t, PabloAST*>> UseDefGraph;
     15    typedef graph_traits<UseDefGraph>::vertex_descriptor Vertex;
     16    typedef graph_traits<UseDefGraph>::vertex_iterator VertexIterator;
     17    typedef graph_traits<UseDefGraph>::in_edge_iterator InEdgeIterator;
    1618    typedef std::unordered_map<PabloAST*, Vertex> UseDefMap;
    1719public:
    1820    static void optimize(PabloBlock & block);
    1921private:
    20     void traverse(const Vertex parent, StatementList & statements);
    21     void traverse(const Vertex parent, PabloAST * expr);
     22    void identifyDeadVariables();
     23
     24    void gatherUseDefInformation(const Vertex parent, StatementList & statements);
     25    void gatherUseDefInformation(const Vertex parent, PabloAST * expr);
    2226    Vertex find(const PabloAST * const node);
    2327    UseAnalysis();
  • icGREP/icgrep-devel/icgrep/pablo/codegenstate.h

    r4268 r4270  
    136136        inline ExpressionMap(MapType * predecessor, PabloBlock * parent)
    137137        : mPredecessor(predecessor)
    138         , mCodeGenState(*parent)
     138        , mCurrentBlock(*parent)
    139139        {
    140140
     
    161161                return f;
    162162            }
    163             Functor mf(mCodeGenState);
     163            Functor mf(mCurrentBlock);
    164164            PabloAST * const expr = mf(std::forward<Args>(args)..., std::forward<Params>(params)...);
    165165            insert(std::move(key), expr);
     
    192192    private:
    193193        MapType * const             mPredecessor;
    194         PabloBlock &                mCodeGenState;
     194        PabloBlock &                mCurrentBlock;
    195195        std::map<Key, PabloAST *>   mMap;
    196196    };
  • icGREP/icgrep-devel/icgrep/pablo/optimizers/pablo_automultiplexing.cpp

    r4242 r4270  
    1 #include <pablo/optimizers/pablo_automultiplexing.hpp>
     1#include "pablo_automultiplexing.hpp"
    22
    33namespace pablo {
  • icGREP/icgrep-devel/icgrep/pablo/pabloAST.h

    r4264 r4270  
    99
    1010#include <llvm/Support/Casting.h>
    11 #include <llvm/IR/Value.h>
    1211#include <vector>
    1312
     
    1514
    1615namespace pablo {
     16
     17class PabloBlock;
    1718
    1819class PabloAST {
     
    2324        , Assign
    2425        , Call
    25         , CharClass
    2626        , If
    2727        , MatchStar
     
    4343protected:
    4444    inline PabloAST(const ClassTypeId id)
    45     : mClassTypeId(id) {
     45    : mClassTypeId(id)
     46    {
    4647
    4748    }
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r4268 r4270  
    7474namespace pablo {
    7575
    76 PabloCompiler::PabloCompiler(const BasisBitVars & basisBitVars, int bits)
    77 : mBits(bits)
    78 , mBasisBitVars(basisBitVars)
     76PabloCompiler::PabloCompiler(const std::vector<Var*> & basisBits)
     77: mBasisBits(basisBits)
    7978, mMod(new Module("icgrep", getGlobalContext()))
    8079, mBasicBlock(nullptr)
    8180, mExecutionEngine(nullptr)
    82 , mXi64Vect(VectorType::get(IntegerType::get(mMod->getContext(), 64), BLOCK_SIZE / 64))
    83 , mXi128Vect(VectorType::get(IntegerType::get(mMod->getContext(), 128), BLOCK_SIZE / 128))
     81, mBitBlockType(VectorType::get(IntegerType::get(mMod->getContext(), 64), BLOCK_SIZE / 64))
    8482, mBasisBitsInputPtr(nullptr)
    8583, mCarryQueueIdx(0)
     
    8785, mNestingDepth(0)
    8886, mCarryQueueSize(0)
    89 , mZeroInitializer(ConstantAggregateZero::get(mXi64Vect))
    90 , mOneInitializer(ConstantVector::getAllOnesValue(mXi64Vect))
     87, mZeroInitializer(ConstantAggregateZero::get(mBitBlockType))
     88, mOneInitializer(ConstantVector::getAllOnesValue(mBitBlockType))
    9189, mFunctionType(nullptr)
    9290, mFunc_process_block(nullptr)
     
    165163
    166164    //The basis bits structure
    167     for (unsigned i = 0; i < mBits; ++i) {
     165    for (unsigned i = 0; i != mBasisBits.size(); ++i) {
    168166        IRBuilder<> b(mBasicBlock);
    169167        Value* indices[] = {b.getInt64(0), b.getInt32(i)};
    170         const String * const name = mBasisBitVars[i]->getName();
     168        const String * const name = mBasisBits[i]->getName();
    171169        Value * gep = b.CreateGEP(mBasisBitsAddr, indices);
    172170        LoadInst * basisBit = b.CreateAlignedLoad(gep, BLOCK_SIZE/8, false, name->str());
     
    239237    }
    240238    std::vector<Type*>StructTy_struct_Basis_bits_fields;
    241     for (int i = 0; i < mBits; i++)
    242     {
    243         StructTy_struct_Basis_bits_fields.push_back(mXi64Vect);
     239    for (int i = 0; i != mBasisBits.size(); i++)
     240    {
     241        StructTy_struct_Basis_bits_fields.push_back(mBitBlockType);
    244242    }
    245243    if (structBasisBits->isOpaque()) {
     
    253251    //The carry q array.
    254252    //A pointer to the BitBlock vector.
    255     functionTypeArgs.push_back(PointerType::get(mXi64Vect, 0));
     253    functionTypeArgs.push_back(PointerType::get(mBitBlockType, 0));
    256254
    257255    //The output structure.
     
    262260    if (outputStruct->isOpaque()) {
    263261        std::vector<Type*>fields;
    264         fields.push_back(mXi64Vect);
    265         fields.push_back(mXi64Vect);
     262        fields.push_back(mBitBlockType);
     263        fields.push_back(mBitBlockType);
    266264        outputStruct->setBody(fields, /*isPacked=*/false);
    267265    }
     
    434432            throw std::runtime_error("Unknown unicode category \"" + callee->str() + "\"");
    435433            #undef CHECK_GENERAL_CODE_CATEGORY
    436             Value * unicodeCategory = mMod->getOrInsertFunction("__get_category_" + callee->str(), mXi64Vect, mBasisBitsInputPtr, NULL);
     434            Value * unicodeCategory = mMod->getOrInsertFunction("__get_category_" + callee->str(), mBitBlockType, mBasisBitsInputPtr, NULL);
    437435            if (unicodeCategory == nullptr) {
    438436                throw std::runtime_error("Could not create static method call for unicode category \"" + callee->str() + "\"");
     
    601599        unsigned index = 0;
    602600        for (index = 0; index != whileStatement->getInclusiveCarryCount(); ++index) {
    603             PHINode * phi = bCond.CreatePHI(mXi64Vect, 2);
     601            PHINode * phi = bCond.CreatePHI(mBitBlockType, 2);
    604602            phi->addIncoming(mCarryQueueVector[baseCarryQueueIdx + index], mBasicBlock);
    605603            mCarryQueueVector[baseCarryQueueIdx + index] = mZeroInitializer; // (use phi for multi-carry mode.)
     
    608606        // and for any Next nodes in the loop body
    609607        for (Next * n : nextNodes) {
    610             PHINode * phi = bCond.CreatePHI(mXi64Vect, 2, n->getName()->str());
     608            PHINode * phi = bCond.CreatePHI(mBitBlockType, 2, n->getName()->str());
    611609            auto f = mMarkerMap.find(n->getName());
    612610            assert (f != mMarkerMap.end());
     
    675673    }
    676674    else if (const Var * var = dyn_cast<Var>(expr))
    677     {       
     675    {
    678676        auto f = mMarkerMap.find(var->getName());
    679677        assert (f != mMarkerMap.end());
     
    702700    {
    703701        Value* strm_value = compileExpression(adv->getExpr());
    704                 int shift = adv->getAdvanceAmount();
     702        int shift = adv->getAdvanceAmount();
    705703        retVal = genAdvanceWithCarry(strm_value, shift);
    706704    }
     
    813811    IRBuilder<> b(mBasicBlock);
    814812    Value* i128_val = b.CreateBitCast(e, IntegerType::get(mMod->getContext(), BLOCK_SIZE));
    815     return b.CreateBitCast(b.CreateLShr(i128_val, BLOCK_SIZE - 1, namehint), mXi64Vect);
     813    return b.CreateBitCast(b.CreateLShr(i128_val, BLOCK_SIZE - 1, namehint), mBitBlockType);
    816814}
    817815
     
    819817    IRBuilder<> b(mBasicBlock);
    820818    Value* i128_val = b.CreateBitCast(e, IntegerType::get(mMod->getContext(), BLOCK_SIZE));
    821     return b.CreateBitCast(b.CreateShl(i128_val, 64, namehint), mXi64Vect);
     819    return b.CreateBitCast(b.CreateShl(i128_val, 64, namehint), mBitBlockType);
    822820}
    823821
     
    858856        Value* strm_longint = b.CreateBitCast(strm_value, IntegerType::get(mMod->getContext(), BLOCK_SIZE));
    859857        Value* adv_longint = b.CreateOr(b.CreateShl(strm_longint, shift_amount), carryq_longint, "advance");
    860         Value* result_value = b.CreateBitCast(adv_longint, mXi64Vect);
    861         Value* carry_out = b.CreateBitCast(b.CreateLShr(strm_longint, BLOCK_SIZE - shift_amount, "advance_out"), mXi64Vect);
     858    Value* result_value = b.CreateBitCast(adv_longint, mBitBlockType);
     859    Value* carry_out = b.CreateBitCast(b.CreateLShr(strm_longint, BLOCK_SIZE - shift_amount, "advance_out"), mBitBlockType);
    862860        //CarryQ - carry out:
    863861        genCarryOutStore(carry_out, carryIdx);
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.h

    r4268 r4270  
    1414#include <pablo/codegenstate.h>
    1515#include <pablo/pabloAST.h>
    16 #include <cc/cc_compiler.h>
    1716#include "unicode_categories.h"
    1817#include <iostream>
     
    8887
    8988public:
    90     typedef cc::CC_Compiler::BasisBitVars BasisBitVars;
    91     PabloCompiler(const BasisBitVars & basisBitVars, int bits);
     89    PabloCompiler(const std::vector<Var *> & basisBitVars);
    9290    ~PabloCompiler();
    9391    LLVM_Gen_RetVal compile(PabloBlock & pb);
     
    118116    CarryQueueVector                    mCarryQueueVector;
    119117
    120     int                                 mBits;   
    121     const BasisBitVars &                mBasisBitVars;
     118    const std::vector<Var *> &          mBasisBits;
    122119
    123120    Module* const                       mMod;
     
    125122    ExecutionEngine*                    mExecutionEngine;
    126123
    127     VectorType* const                   mXi64Vect;
    128     VectorType* const                   mXi128Vect;
     124    VectorType* const                   mBitBlockType;
    129125    PointerType*                        mBasisBitsInputPtr;
    130126
Note: See TracChangeset for help on using the changeset viewer.