Changeset 4657 for icGREP


Ignore:
Timestamp:
Jul 10, 2015, 4:51:39 PM (4 years ago)
Author:
nmedfort
Message:

Initial introduction of a PabloFunction? type.

Location:
icGREP/icgrep-devel/icgrep
Files:
1 added
25 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/CMakeLists.txt

    r4654 r4657  
    6060endif()
    6161
    62 SET(PABLO_SRC pablo/pabloAST.cpp pablo/ps_assign.cpp pablo/ps_if.cpp pablo/ps_while.cpp pablo/codegenstate.cpp pablo/builder.cpp pablo/symbol_generator.cpp pablo/printer_pablos.cpp pablo/pablo_compiler.cpp pablo/optimizers/pablo_simplifier.cpp pablo/optimizers/pablo_codesinking.cpp pablo/carry_data.cpp pablo/carry_manager.cpp IDISA/idisa_builder.cpp)
     62SET(PABLO_SRC pablo/pabloAST.cpp pablo/ps_assign.cpp pablo/ps_if.cpp pablo/ps_while.cpp pablo/function.cpp pablo/codegenstate.cpp pablo/builder.cpp pablo/symbol_generator.cpp pablo/printer_pablos.cpp pablo/pablo_compiler.cpp pablo/optimizers/pablo_simplifier.cpp pablo/optimizers/pablo_codesinking.cpp pablo/carry_data.cpp pablo/carry_manager.cpp IDISA/idisa_builder.cpp)
    6363IF (ENABLE_MULTIPLEXING)
    6464SET(PABLO_SRC ${PABLO_SRC} pablo/optimizers/pablo_automultiplexing.cpp)
  • icGREP/icgrep-devel/icgrep/cc/cc_compiler.cpp

    r4617 r4657  
    2020#include <pablo/codegenstate.h>
    2121#include <pablo/builder.hpp>
     22#include <pablo/function.h>
    2223#include <stdexcept>
    2324
     
    2728namespace cc {
    2829
    29 CC_Compiler::CC_Compiler(PabloBlock & entry, const Encoding & encoding, const std::string basis_pattern)
    30 : mBuilder(entry)
     30CC_Compiler::CC_Compiler(PabloFunction & function, const Encoding & encoding, const std::string prefix)
     31: mBuilder(function.getEntryBlock())
    3132, mBasisBit(encoding.getBits())
    32 , mEncoding(encoding)
    33 {
    34     for (int i = 0; i < mEncoding.getBits(); i++) {
    35         mBasisBit[i] = mBuilder.createVar(basis_pattern + std::to_string(i));
     33, mEncoding(encoding) {
     34    for (unsigned i = 0; i != encoding.getBits(); i++) {
     35        Var * var = mBuilder.createVar(prefix + std::to_string(i));
     36        function.addParameter(var);
     37        mBasisBit[encoding.getBits() - i - 1] = var;
    3638    }
    3739}
     
    267269
    268270inline Var * CC_Compiler::getBasisVar(const int i) const {
    269     return mBasisBit[(mEncoding.getBits() - 1) - i];
     271    return mBasisBit[i];
    270272}
    271273
  • icGREP/icgrep-devel/icgrep/cc/cc_compiler.h

    r4622 r4657  
    1313#include <string>
    1414
     15
     16namespace pablo {
     17    class PabloFunction;
     18}
     19
    1520namespace cc {
    1621
     
    2227    using Vars = std::vector<pablo::Var *>;
    2328
    24     CC_Compiler(pablo::PabloBlock & entry, const Encoding & encoding, const std::string basis_pattern = "basis");
    25 
    26     const Vars & getBasisBits(const CC_NameMap & nameMap) const;
     29    CC_Compiler(pablo::PabloFunction & function, const Encoding & encoding, const std::string prefix = "basis");
    2730
    2831    pablo::Assign * compileCC(const re::CC *cc);
     
    7477}
    7578
    76 inline const CC_Compiler::Vars & CC_Compiler::getBasisBits(const CC_NameMap &) const {
    77     return mBasisBit;
    78 }
    79 
    8079inline pablo::PabloBuilder & CC_Compiler::getBuilder() {
    8180    return mBuilder;
  • icGREP/icgrep-devel/icgrep/compiler.cpp

    r4648 r4657  
    3030#include "resolve_properties.h"
    3131#include <llvm/Support/CommandLine.h>
     32#include <pablo/function.h>
    3233#include <re/printer_re.h>
    3334#include <pablo/printer_pablos.h>
     
    134135    }
    135136
    136     SymbolGenerator symbolGenerator;
    137     PabloBlock & main = PabloBlock::Create(symbolGenerator);
    138 
    139     CC_Compiler cc_compiler(main, encoding);
     137    PabloFunction function = PabloFunction::Create();
     138
     139    CC_Compiler cc_compiler(function, encoding);
    140140   
    141141    cc_compiler.compileByteClasses(re_ast);
    142142   
    143     auto basisBits = cc_compiler.getBasisBits(nameMap);
    144143    if (PrintCompiledCCcode) {
    145144      //Print to the terminal the AST that was generated by the character class compiler.
    146145      llvm::raw_os_ostream cerr(std::cerr);
    147146      cerr << "CC AST:" << "\n";
    148       PabloPrinter::print(main.statements(), cerr);
     147      PabloPrinter::print(function.getEntryBlock().statements(), cerr);
    149148    }
    150149   
    151150    RE_Compiler re_compiler(cc_compiler);
    152151    re_compiler.initializeRequiredStreams();
    153     re_compiler.finalizeMatchResult(re_compiler.compile(re_ast));
     152    re_compiler.finalizeMatchResult(function, re_compiler.compile(re_ast));
    154153
    155154    if (PrintCompiledREcode) {
     
    157156        llvm::raw_os_ostream cerr(std::cerr);
    158157        cerr << "Initial Pablo AST:\n";
    159         PabloPrinter::print(main.statements(), cerr);
     158        PabloPrinter::print(function.getEntryBlock().statements(), cerr);
    160159    }
    161160
    162161    // Scan through the pablo code and perform DCE and CSE
    163162    if (!DisablePabloCSE) {
    164         Simplifier::optimize(main);
     163        Simplifier::optimize(function);
    165164    }
    166165    if (PabloSinkingPass) {
    167         CodeSinking::optimize(main);
     166        CodeSinking::optimize(function);
    168167    }
    169168    #ifdef ENABLE_MULTIPLEXING
    170169    if (EnableMultiplexing) {
    171         AutoMultiplexing::optimize(basisBits, main);
     170        AutoMultiplexing::optimize(function);
    172171    }
    173172    #endif
     
    176175      llvm::raw_os_ostream cerr(std::cerr);
    177176      cerr << "Final Pablo AST:\n";
    178       PabloPrinter::print(main.statements(), cerr);
    179     }
    180 
    181     PabloCompiler pablo_compiler(basisBits);
     177      PabloPrinter::print(function.getEntryBlock().statements(), cerr);
     178    }
     179
     180    PabloCompiler pablo_compiler;
    182181    if (UsePregeneratedUnicode()) {
    183182        install_property_gc_fn_ptrs(pablo_compiler);
     
    189188    }
    190189    try {
    191         CompiledPabloFunction retVal = pablo_compiler.compile(main);
     190        CompiledPabloFunction retVal = pablo_compiler.compile(function);
    192191        releaseSlabAllocatorMemory();
    193192        return retVal;
  • icGREP/icgrep-devel/icgrep/pablo/builder.hpp

    r4646 r4657  
    5757    Call * createCall(String * name);
    5858
    59     Assign * createAssign(const std::string && prefix, PabloAST * expr, const int outputIndex = -1) {
    60         return mPb->createAssign(std::move(prefix), expr, outputIndex);
     59    Assign * createAssign(const std::string && prefix, PabloAST * expr) {
     60        return mPb->createAssign(std::move(prefix), expr);
    6161    }
    6262
  • icGREP/icgrep-devel/icgrep/pablo/codegenstate.cpp

    r4650 r4657  
    4040/// UNARY CREATE FUNCTIONS
    4141
    42 Assign * PabloBlock::createAssign(const std::string && prefix, PabloAST * expr, const int outputIndex)  {
    43     return insertAtInsertionPoint(new Assign(expr, outputIndex, makeName(prefix, false)));
     42Assign * PabloBlock::createAssign(const std::string && prefix, PabloAST * expr)  {
     43    return insertAtInsertionPoint(new Assign(expr, makeName(prefix, false)));
    4444}
    4545
  • icGREP/icgrep-devel/icgrep/pablo/codegenstate.h

    r4650 r4657  
    8383    }
    8484
    85     Assign * createAssign(const std::string && prefix, PabloAST * expr, const int outputIndex = -1);
     85    Assign * createAssign(const std::string && prefix, PabloAST * expr);
    8686
    8787    inline Var * createVar(const std::string name) {
  • icGREP/icgrep-devel/icgrep/pablo/function.cpp

    r4656 r4657  
    11#include "function.h"
     2#include <pablo/codegenstate.h>
    23
    34namespace pablo {
    45
    5 Function::Function(std::initializer_list<Argument> args)
     6PabloFunction::PabloFunction()
    67: PabloAST(ClassTypeId::Function)
    7 , mArgumentList(args.begin(), args.end(), reinterpret_cast<ArgumentListAllocator &>(mVectorAllocator)) {
    8     for (Argument & arg : args) {
    9         std::get<1>(arg)->addUser(this);
    10     }
     8, mEntryBlock(PabloBlock::Create(mSymbolTable))
     9, mParameters(reinterpret_cast<ParamAllocator &>(mVectorAllocator))
     10, mResults(reinterpret_cast<ResultAllocator &>(mVectorAllocator)) {
     11
    1112}
    1213
    13 Function::Function(const std::vector<Argument> & args)
    14 : PabloAST(ClassTypeId::Function)
    15 , mArgumentList(args.begin(), args.end(), reinterpret_cast<ArgumentListAllocator &>(mVectorAllocator)) {
    16     for (Argument & arg : args) {
    17         std::get<1>(arg)->addUser(this);
    18     }
    1914}
    20 
    21 
    22 }
  • icGREP/icgrep-devel/icgrep/pablo/function.h

    r4656 r4657  
    33
    44#include <pablo/pabloAST.h>
     5#include <pablo/pe_var.h>
     6#include <pablo/ps_assign.h>
     7#include <pablo/symbol_generator.h>
    58
    69namespace pablo {
     
    811class Var;
    912class Assign;
     13class PabloBlock;
    1014
    11 enum class ArgumentType {
    12     In = 0
    13     , Out = 1
    14     , InOut = 2
    15 };
     15class PabloFunction : public PabloAST {
     16    friend class PabloBlock;
     17    using ParamAllocator = VectorAllocator::rebind<Var *>::other;
     18    using Parameters = std::vector<Var *, ParamAllocator>;
     19    using ResultAllocator = VectorAllocator::rebind<Assign *>::other;
     20    using Results = std::vector<Assign *, ResultAllocator>;
     21public:
    1622
    17 using Argument = std::pair<ArgumentType, PabloAST *>;
    18 
    19 class Function : public PabloAST {
    20     using ArgumentListAllocator = VectorAllocator::rebind<Argument>::other;
    21     using ArgumentListType = std::vector<Argument, ArgumentListAllocator>;
    22     friend class PabloBlock;
    23 public:
    2423    static inline bool classof(const PabloAST * e) {
    2524        return e->getClassTypeId() == ClassTypeId::Function;
    2625    }
     26
    2727    static inline bool classof(const void *) {
    2828        return false;
    2929    }
    30     virtual ~Function() { }
     30
     31    static PabloFunction Create();
     32
    3133    virtual bool operator==(const PabloAST & other) const {
    3234        return &other == this;
    3335    }
     36
     37    PabloBlock & getEntryBlock() {
     38        return mEntryBlock;
     39    }
     40
     41    const PabloBlock & getEntryBlock() const {
     42        return mEntryBlock;
     43    }
     44
     45    const Parameters & getParameters() const {
     46        return mParameters;
     47    }
     48
     49    const Results & getResults() const {
     50        return mResults;
     51    }
     52
     53    Var * getParameter(const unsigned index) {
     54        return mParameters[index];
     55    }
     56
     57    const Var * getParameter(const unsigned index) const {
     58        return mParameters[index];
     59    }
     60
     61    void addParameter(Var * value) {
     62        mParameters.push_back(value); value->addUser(this);
     63    }
     64
     65    Assign * getResult(const unsigned index) {
     66        return mResults[index];
     67    }
     68
     69    const Assign * getResult(const unsigned index) const {
     70        return mResults[index];
     71    }
     72
     73    void addResult(Assign * value) {
     74        mResults.push_back(value); value->addUser(this);
     75    }
     76
     77    void setResult(const unsigned index, PabloAST * value) {
     78        getResult(index)->setExpression(value);
     79    }
     80
     81    SymbolGenerator & getSymbolTable() {
     82        return mSymbolTable;
     83    }
     84
     85    virtual ~PabloFunction() { }
     86
    3487protected:
    35     Function();
    36     Function(std::initializer_list<Argument *> args);
    37     Function(const std::vector<Argument *> & args);
     88    PabloFunction();
    3889private:
    39     ArgumentListType        mArgumentList;
     90    PabloBlock &        mEntryBlock;
     91    Parameters          mParameters;
     92    Results             mResults;
     93    SymbolGenerator     mSymbolTable;
    4094};
     95
     96inline PabloFunction PabloFunction::Create() {
     97    return PabloFunction();
     98}
    4199
    42100}
  • icGREP/icgrep-devel/icgrep/pablo/optimizers/pablo_automultiplexing.cpp

    r4650 r4657  
    22#include <include/simd-lib/builtins.hpp>
    33#include <pablo/builder.hpp>
     4#include <pablo/function.h>
    45#include <pablo/printer_pablos.h>
    56#include <boost/container/flat_set.hpp>
     
    9899namespace pablo {
    99100
    100 bool AutoMultiplexing::optimize(const std::vector<Var *> & input, PabloBlock & entry) {
     101bool AutoMultiplexing::optimize(PabloFunction & function) {
    101102
    102103    std::random_device rd;
     
    106107    LOG("Seed:                    " << seed);
    107108
    108     AutoMultiplexing am(input);
     109    AutoMultiplexing am;
    109110    RECORD_TIMESTAMP(start_initialize);
    110     am.initialize(entry);
     111    am.initialize(function);
    111112    RECORD_TIMESTAMP(end_initialize);
    112113
    113114    LOG("Initialize:              " << (end_initialize - start_initialize));
    114115
    115     LOG_NUMBER_OF_ADVANCES(entry);
     116    LOG_NUMBER_OF_ADVANCES(function.getEntryBlock());
    116117
    117118    RECORD_TIMESTAMP(start_characterize);
    118     am.characterize(entry);
     119    am.characterize(function.getEntryBlock());
    119120    RECORD_TIMESTAMP(end_characterize);
    120121
     
    144145
    145146        RECORD_TIMESTAMP(start_topological_sort);
    146         am.topologicalSort(entry);
     147        am.topologicalSort(function.getEntryBlock());
    147148        RECORD_TIMESTAMP(end_topological_sort);
    148149        LOG("TopologicalSort:         " << (end_topological_sort - start_topological_sort));
     
    167168 * the proper variable ordering.
    168169 ** ------------------------------------------------------------------------------------------------------------- */
    169 void AutoMultiplexing::initialize(PabloBlock & entry) {
     170void AutoMultiplexing::initialize(PabloFunction & function) {
    170171
    171172    flat_map<const PabloAST *, unsigned> map;   
     
    175176    // Scan through and collect all the advances, calls, scanthrus and matchstars ...
    176177    unsigned n = 0, m = 0;
    177     for (Statement * stmt = entry.front(); ; ) {
     178    for (Statement * stmt = function.getEntryBlock().front(); ; ) {
    178179        while ( stmt ) {
    179180            ++n;
     
    227228    m = 0;
    228229
    229     const Statement * stmt = entry.front();
     230    const Statement * stmt = function.getEntryBlock().front();
    230231    for (;;) {
    231232        while ( stmt ) {
     
    284285
    285286    // Initialize the BDD engine ...
    286     mManager = Cudd_Init((complexStatements + mBaseVariables.size()), 0, CUDD_UNIQUE_SLOTS, CUDD_CACHE_SLOTS, 0);
     287    mManager = Cudd_Init((complexStatements + function.getParameters().size()), 0, CUDD_UNIQUE_SLOTS, CUDD_CACHE_SLOTS, 0);
    287288    Cudd_AutodynDisable(mManager);
    288289
    289290    // Map the predefined 0/1 entries
    290     mCharacterizationMap[entry.createZeroes()] = Zero();
    291     mCharacterizationMap[entry.createOnes()] = One();
     291    mCharacterizationMap[function.getEntryBlock().createZeroes()] = Zero();
     292    mCharacterizationMap[function.getEntryBlock().createOnes()] = One();
    292293
    293294    // Order the variables so the input Vars are pushed to the end; they ought to
    294295    // be the most complex to resolve.
    295296    unsigned i = complexStatements;
    296     for (const Var * var : mBaseVariables) {
     297    for (const Var * var : function.getParameters()) {
    297298        mCharacterizationMap[var] = Cudd_bddIthVar(mManager, i++);
    298299    }
  • icGREP/icgrep-devel/icgrep/pablo/optimizers/pablo_automultiplexing.hpp

    r4650 r4657  
    1919
    2020class PabloBuilder;
     21class PabloFunction;
    2122
    2223class AutoMultiplexing {
     
    3738
    3839public:
    39     static bool optimize(const std::vector<Var *> & input, PabloBlock & entry);
     40    static bool optimize(PabloFunction & function);
    4041protected:
    41     void initialize(PabloBlock & entry);
     42    void initialize(PabloFunction & function);
    4243    void characterize(PabloBlock &block);
    4344    DdNode * characterize(Statement * const stmt);
     
    5051    void multiplexSelectedIndependentSets() const;
    5152    void topologicalSort(PabloBlock & entry) const;
    52     inline AutoMultiplexing(const std::vector<Var *> & vars)
     53    inline AutoMultiplexing()
    5354    : mVariables(0)
    5455    , mConstraintGraph(0)
    55     , mBaseVariables(vars)
    5656    {
    5757    }
     
    8181    AdvanceVector               mAdvance;
    8282    MultiplexSetGraph           mMultiplexSetGraph;
    83     const std::vector<Var *> &  mBaseVariables;
    8483    RecentCharacterizations     mRecentCharacterizations;
    8584};
  • icGREP/icgrep-devel/icgrep/pablo/optimizers/pablo_codesinking.cpp

    r4521 r4657  
    11#include "pablo_codesinking.hpp"
     2#include <pablo/function.h>
    23
    34namespace pablo {
    45
    5 bool CodeSinking::optimize(PabloBlock & block)
     6bool CodeSinking::optimize(PabloFunction & function)
    67{
    78    CodeSinking lcf;
    8     lcf.sink(block);
     9    lcf.sink(function.getEntryBlock());
    910    return true;
    1011}
  • icGREP/icgrep-devel/icgrep/pablo/optimizers/pablo_codesinking.hpp

    r4521 r4657  
    77
    88namespace pablo {
     9
     10class PabloFunction;
    911
    1012class CodeSinking {
     
    2729
    2830public:
    29     static bool optimize(PabloBlock & block);
     31    static bool optimize(PabloFunction & function);
    3032protected:
    3133    void sink(PabloBlock & block);
  • icGREP/icgrep-devel/icgrep/pablo/optimizers/pablo_simplifier.cpp

    r4611 r4657  
    22#include <pablo/codegenstate.h>
    33#include <pablo/expression_map.hpp>
    4 
     4#include <pablo/function.h>
    55#include <pablo/printer_pablos.h>
    66
     
    99namespace pablo {
    1010
    11 bool Simplifier::optimize(PabloBlock & block) {
    12     eliminateRedundantCode(block);
    13     deadCodeElimination(block);
    14     eliminateRedundantComplexStatements(block);
     11bool Simplifier::optimize(PabloFunction & function) {
     12    eliminateRedundantCode(function.getEntryBlock());
     13    deadCodeElimination(function.getEntryBlock());
     14    eliminateRedundantComplexStatements(function.getEntryBlock());
    1515    return true;
    1616}
     
    5959                }
    6060                else {
    61                     stmt = assign->replaceWith(assign->getExpr());
     61                    stmt = assign->replaceWith(assign->getExpression());
    6262                }
    6363                continue;
     
    8080            for (auto i = defVars.begin(); i != defVars.end(); ) {
    8181                Assign * defVar = cast<Assign>(*i);
    82                 if (LLVM_UNLIKELY(isa<Zeroes>(defVar->getExpr()))) {
     82                if (LLVM_UNLIKELY(isa<Zeroes>(defVar->getExpression()))) {
    8383                    i = defVars.erase(i);
    8484                    defVar->replaceWith(block.createZeroes(), false, true);
  • icGREP/icgrep-devel/icgrep/pablo/optimizers/pablo_simplifier.hpp

    r4569 r4657  
    77
    88struct ExpressionTable;
     9class PabloFunction;
    910
    1011class Simplifier {
    1112public:
    12     static bool optimize(PabloBlock & block);
     13    static bool optimize(PabloFunction & function);
    1314protected:
    1415    Simplifier();
  • icGREP/icgrep-devel/icgrep/pablo/pabloAST.cpp

    r4656 r4657  
    108108    }
    109109    PabloAST * priorValue = getOperand(index);
    110     // Test just to be sure that we don't have multiple operands pointing to
    111     // what we're replacing. If not, remove this from the prior value's
    112     // user list.
    113     unsigned count = 0;
    114     for (unsigned i = 0; i != getNumOperands(); ++i) {
    115         count += (getOperand(i) == priorValue) ? 1 : 0;
    116     }
    117     assert (count >= 1);
    118     if (LLVM_LIKELY(count == 1)) {
    119         priorValue->removeUser(this);
     110    if (LLVM_LIKELY(priorValue != nullptr)) {
     111        // Test just to be sure that we don't have multiple operands pointing to
     112        // what we're replacing. If not, remove this from the prior value's
     113        // user list.
     114        unsigned count = 0;
     115        for (unsigned i = 0; i != getNumOperands(); ++i) {
     116            count += (getOperand(i) == priorValue) ? 1 : 0;
     117        }
     118        assert (count >= 1);
     119        if (LLVM_LIKELY(count == 1)) {
     120            priorValue->removeUser(this);
     121        }
    120122    }
    121123    mOperand[index] = value;
  • icGREP/icgrep-devel/icgrep/pablo/pabloAST.h

    r4656 r4657  
    2828    friend class While;
    2929    friend class PabloBlock;
    30     friend class Function;
     30    friend class PabloFunction;
    3131    friend class SymbolGenerator;
    3232public:
     
    221221        for (PabloAST * const op : operands) {
    222222            mOperand[i++] = op;
    223             op->addUser(this);
     223            if (LLVM_LIKELY(op != nullptr)) {
     224                op->addUser(this);
     225            }
    224226        }
    225227    }
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r4654 r4657  
    1010#include <pablo/carry_manager.h>
    1111#include <pablo/printer_pablos.h>
     12#include <pablo/function.h>
    1213#include <cc/cc_namemap.hpp>
    1314#include <re/re_name.h>
     
    6465namespace pablo {
    6566
    66 PabloCompiler::PabloCompiler(const std::vector<Var*> & basisBits)
    67 : mBasisBits(basisBits)
     67PabloCompiler::PabloCompiler()
    6868#ifdef USE_LLVM_3_5
    69 , mMod(new Module("icgrep", getGlobalContext()))
     69: mMod(new Module("icgrep", getGlobalContext()))
    7070#else
    71 , mModOwner(make_unique<Module>("icgrep", getGlobalContext()))
     71: mModOwner(make_unique<Module>("icgrep", getGlobalContext()))
    7272, mMod(mModOwner.get())
    7373#endif
     
    8484, mFunctionType(nullptr)
    8585, mFunction(nullptr)
    86 , mBasisBitsAddr(nullptr)
     86, mParameterAddr(nullptr)
    8787, mOutputAddrPtr(nullptr)
    8888, mMaxWhileDepth(0)
     
    9393    InitializeNativeTargetAsmPrinter();
    9494    InitializeNativeTargetAsmParser();
    95     DefineTypes();
    9695}
    9796
     
    116115}
    117116
    118 CompiledPabloFunction PabloCompiler::compile(PabloBlock & pb)
     117CompiledPabloFunction PabloCompiler::compile(PabloFunction & function)
    119118{
    120119    mWhileDepth = 0;
     
    139138        throw std::runtime_error("Could not create ExecutionEngine: " + errMessage);
    140139    }
     140
     141    DefineTypes(function);
    141142    DeclareFunctions();
    142143
    143     Examine(pb);
     144    Examine(function.getEntryBlock());
    144145    DeclareCallFunctions();
    145146
    146147    Function::arg_iterator args = mFunction->arg_begin();
    147     mBasisBitsAddr = args++;
    148     mBasisBitsAddr->setName("basis_bits");
     148    mParameterAddr = args++;
     149    mParameterAddr->setName("basis_bits");
    149150    mCarryDataPtr = args++;
    150151    mCarryDataPtr->setName("carry_data");
     
    159160
    160161    //The basis bits structure
    161     for (unsigned i = 0; i != mBasisBits.size(); ++i) {
     162
     163    for (unsigned i = 0; i != function.getParameters().size(); ++i) {
    162164        Value* indices[] = {mBuilder->getInt64(0), mBuilder->getInt32(i)};
    163         Value * gep = mBuilder->CreateGEP(mBasisBitsAddr, indices);
    164         LoadInst * basisBit = mBuilder->CreateAlignedLoad(gep, BLOCK_SIZE/8, false, mBasisBits[i]->getName()->to_string());
    165         mMarkerMap.insert(std::make_pair(mBasisBits[i], basisBit));
     165        Value * gep = mBuilder->CreateGEP(mParameterAddr, indices);
     166        LoadInst * basisBit = mBuilder->CreateAlignedLoad(gep, BLOCK_SIZE/8, false, function.getParameter(i)->getName()->to_string());
     167        mMarkerMap.insert(std::make_pair(function.getParameter(i), basisBit));
    166168    }
    167169       
    168     unsigned totalCarryDataSize = mCarryManager->initialize(&pb, mCarryDataPtr);
     170    unsigned totalCarryDataSize = mCarryManager->initialize(&(function.getEntryBlock()), mCarryDataPtr);
    169171   
    170172    //Generate the IR instructions for the function.
    171     compileBlock(pb);
     173    compileBlock(function.getEntryBlock());
    172174   
    173175    mCarryManager->generateBlockNoIncrement();
     
    179181    if (LLVM_UNLIKELY(mWhileDepth != 0)) {
    180182        throw std::runtime_error("Non-zero nesting depth error (" + std::to_string(mWhileDepth) + ")");
     183    }
     184
     185    // Write the output values out
     186    for (unsigned i = 0; i != function.getResults().size(); ++i) {
     187        SetOutputValue(mMarkerMap[function.getResult(i)], i);
    181188    }
    182189
     
    193200    mExecutionEngine->finalizeObject();
    194201
     202    delete mCarryManager;
     203    mCarryManager = nullptr;
     204
    195205    //Return the required size of the carry data area to the process_block function.
    196206    return CompiledPabloFunction(totalCarryDataSize * sizeof(BitBlock), mFunction, mExecutionEngine);
    197207}
    198208
    199 void PabloCompiler::DefineTypes()
    200 {
     209void PabloCompiler::DefineTypes(PabloFunction & function) {
     210
    201211    StructType * structBasisBits = mMod->getTypeByName("struct.Basis_bits");
    202212    if (structBasisBits == nullptr) {
    203213        structBasisBits = StructType::create(mMod->getContext(), "struct.Basis_bits");
    204214    }
    205     std::vector<Type*>StructTy_struct_Basis_bits_fields;
    206     for (int i = 0; i != mBasisBits.size(); i++)
    207     {
     215    std::vector<Type*> StructTy_struct_Basis_bits_fields;
     216    for (int i = 0; i != function.getParameters().size(); i++) {
    208217        StructTy_struct_Basis_bits_fields.push_back(mBitBlockType);
    209218    }
     
    227236    if (outputStruct->isOpaque()) {
    228237        std::vector<Type*>fields;
    229         fields.push_back(mBitBlockType);
    230         fields.push_back(mBitBlockType);
     238        for (int i = 0; i != function.getResults().size(); i++) {
     239            fields.push_back(mBitBlockType);
     240        }
    231241        outputStruct->setBody(fields, /*isPacked=*/false);
    232242    }
    233     PointerType* outputStructPtr = PointerType::get(outputStruct, 0);
     243    PointerType * outputStructPtr = PointerType::get(outputStruct, 0);
    234244
    235245    //The &output parameter.
     
    555565    Value * expr = nullptr;
    556566    if (const Assign * assign = dyn_cast<const Assign>(stmt)) {
    557         expr = compileExpression(assign->getExpr());
    558         if (LLVM_UNLIKELY(assign->isOutputAssignment())) {
    559             SetOutputValue(expr, assign->getOutputIndex());
    560         }
     567        expr = compileExpression(assign->getExpression());
    561568    }
    562569    else if (const Next * next = dyn_cast<const Next>(stmt)) {
     
    583590            throw std::runtime_error("Unexpected error locating static function for \"" + call->getCallee()->to_string() + "\"");
    584591        }
    585         expr = mBuilder->CreateCall(ci->second, mBasisBitsAddr);
     592        expr = mBuilder->CreateCall(ci->second, mParameterAddr);
    586593    }
    587594    else if (const And * pablo_and = dyn_cast<And>(stmt)) {
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.h

    r4647 r4657  
    4848class PabloAST;
    4949class PabloBlock;
     50class PabloFunction;
    5051class String;
    5152class Var;
     
    9798
    9899public:
    99     PabloCompiler(const std::vector<Var *> & basisBitVars);
     100    PabloCompiler();
    100101    ~PabloCompiler();
    101102    void InstallExternalFunction(std::string C_fn_name, void * fn_ptr);
    102     CompiledPabloFunction compile(PabloBlock & pb);
     103    CompiledPabloFunction compile(pablo::PabloFunction &function);
    103104private:
    104     void DefineTypes();
     105    void DefineTypes(PabloFunction & function);
    105106    void DeclareFunctions();
    106107    void Examine(PabloBlock & blk);
     
    138139    CarryQueueVector                    mCarryOutVector;
    139140
    140     const std::vector<Var *> &          mBasisBits;
    141141#ifdef USE_LLVM_3_5
    142142    Module* const                       mMod;
     
    165165
    166166
    167     Value*                              mBasisBitsAddr;
     167    Value*                              mParameterAddr;
    168168    Value*                              mOutputAddrPtr;
    169169
  • icGREP/icgrep-devel/icgrep/pablo/pe_var.h

    r4650 r4657  
    4646    : PabloAST(ClassTypeId::Var)
    4747    , mName(cast<String>(var)) {
    48         var->addUser(this);
     48
    4949    }
    5050private:
  • icGREP/icgrep-devel/icgrep/pablo/printer_pablos.cpp

    r4643 r4657  
    6868    }
    6969    else if (const Assign * an = dyn_cast<const Assign>(stmt)) {
    70         if (an->isOutputAssignment()) {
    71             strm << "output.";
    72         }
     70//        if (an->isOutputAssignment()) {
     71//            strm << "output.";
     72//        }
    7373        strm << an->getName() << " = ";
    74         print(an->getExpr(), strm);
     74        print(an->getExpression(), strm);
    7575    }
    7676    else if (const Next * next = dyn_cast<const Next>(stmt)) {       
  • icGREP/icgrep-devel/icgrep/pablo/ps_assign.cpp

    r4433 r4657  
    22#include <pablo/ps_if.h>
    33#include <pablo/pe_next.h>
     4#include <pablo/function.h>
    45
    56namespace pablo {
    67
    78bool Assign::superfluous() const {
    8     if (LLVM_UNLIKELY(isOutputAssignment())) {
    9         // If this Assign is an assignment to an output variable, it cannot be superfluous.
    10         return false;
    11     }
    129    for (const PabloAST * inst : users()) {       
    13         if (isa<Next>(inst)) {
    14             // If this Assign has a Next node, it cannot be superfluous.
     10        if (isa<Next>(inst) || isa<PabloFunction>(inst) || isa<If>(inst)) {
    1511            return false;
    16         }
    17         if (isa<If>(inst)) {
    18             // If this Assign is a defined variable of an If node, it cannot be superfluous.
    19             const auto & dv = cast<If>(inst)->getDefined();
    20             if (LLVM_UNLIKELY(std::find(dv.begin(), dv.end(), this) != dv.end())) {
    21                 return false;
    22             }
    2312        }
    2413    }
  • icGREP/icgrep-devel/icgrep/pablo/ps_assign.h

    r4650 r4657  
    2525    virtual ~Assign() {
    2626    }
    27     inline PabloAST * getExpr() const {
     27    inline PabloAST * getExpression() const {
    2828        return getOperand(0);
    2929    }
    30     inline bool isOutputAssignment() const {
    31         return mOutputIndex >= 0;
    32     }
    33     inline int getOutputIndex() const {
    34         return mOutputIndex;
     30    inline void setExpression(PabloAST * value) {
     31        return setOperand(0, value);
    3532    }
    3633    bool superfluous() const;
    3734protected:
    38     explicit Assign(PabloAST * expr, int outputIndex, String * name)
     35    explicit Assign(PabloAST * expr, String * name)
    3936    : Statement(ClassTypeId::Assign, {expr}, name)
    40     , mOutputIndex(outputIndex)
    4137    {
    4238
    4339    }
    44 private:
    45     const int           mOutputIndex;
    4640};
    4741
  • icGREP/icgrep-devel/icgrep/re/re_compiler.cpp

    r4650 r4657  
    2121#include <cc/cc_namemap.hpp>
    2222#include <pablo/codegenstate.h>
     23#include <pablo/function.h>
    2324#include <resolve_properties.h>
    2425#include <assert.h>
     
    175176}
    176177
    177 void RE_Compiler::finalizeMatchResult(MarkerType match_result) {
     178void RE_Compiler::finalizeMatchResult(PabloFunction & function, MarkerType match_result) {
    178179    //These three lines are specifically for grep.
    179180    PabloAST * lb = UNICODE_LINE_BREAK ? mUnicodeLineBreak : mLineFeed;
    180     PabloAST * v = markerVar(match_result);
    181     mPB.createAssign("matches", mPB.createAnd(mPB.createMatchStar(v, mPB.createNot(lb)), lb), 0);
    182     mPB.createAssign("lf", mPB.createAnd(lb, mPB.createNot(mCRLF)), 1);
     181    PabloAST * v = markerVar(match_result);   
     182    function.addResult(mPB.createAssign("matches", mPB.createAnd(mPB.createMatchStar(v, mPB.createNot(lb)), lb)));
     183    function.addResult(mPB.createAssign("lf", mPB.createAnd(lb, mPB.createNot(mCRLF))));
    183184}
    184185
  • icGREP/icgrep-devel/icgrep/re/re_compiler.h

    r4641 r4657  
    2020class CC_NameMap;
    2121}
     22
     23namespace pablo {
     24class PabloFunction;
     25}
     26
    2227
    2328/*   Marker streams represent the results of matching steps.
     
    5661    RE_Compiler(cc::CC_Compiler & ccCompiler);
    5762    void initializeRequiredStreams();
    58     void finalizeMatchResult(MarkerType match_result);
     63    void finalizeMatchResult(pablo::PabloFunction & function, MarkerType match_result);
    5964    MarkerType compile(RE * re) {
    6065        return compile(re, mPB);
Note: See TracChangeset for help on using the changeset viewer.