Ignore:
Timestamp:
Jul 18, 2015, 10:18:34 AM (4 years ago)
Author:
nmedfort
Message:

First attempt to intergrate 'generate_predefined_ucd_functions' into build process.

Location:
icGREP/icgrep-devel/icgrep
Files:
12 deleted
13 edited

Legend:

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

    r4661 r4684  
    5555
    5656if(ENABLE_MULTIPLEXING)
    57 find_package(Boost COMPONENTS system)
     57find_package(Boost COMPONENTS system REQUIRED)
    5858else()
    5959find_package(Boost)
     
    6666
    6767add_library(PabloADT ${PABLO_SRC})
    68 add_library(RegExpADT re/re_re.cpp re/re_cc.cpp re/re_parser.cpp re/re_rep.cpp re/parsefailure.cpp re/re_nullable.cpp re/re_simplifier.cpp re/re_compiler.cpp re/printer_re.cpp re/re_diff.cpp re/re_intersect.cpp re/re_analysis.cpp)
     68add_library(RegExpADT re/re_re.cpp re/re_cc.cpp re/re_rep.cpp re/re_diff.cpp re/re_intersect.cpp re/printer_re.cpp)
     69add_library(RegExpCompiler re/re_parser.cpp re/parsefailure.cpp re/re_nullable.cpp re/re_simplifier.cpp re/re_compiler.cpp re/re_analysis.cpp)
    6970add_library(CCADT cc/cc_namemap.cpp cc/cc_compiler.cpp utf8_encoder.cpp UCD/CaseFolding_txt.cpp)
    70 add_library(UCDlib UCD/unicode_set.cpp UCD/ucd_compiler.cpp UCD/PropertyObjects.cpp UCD/precompiled_gc.cpp UCD/precompiled_sc.cpp UCD/precompiled_scx.cpp UCD/precompiled_blk.cpp UCD/precompiled_derivedcoreproperties.cpp UCD/precompiled_proplist.cpp UCD/resolve_properties.cpp)
    71 
     71add_library(UCDlib UCD/unicode_set.cpp UCD/ucd_compiler.cpp UCD/PropertyObjects.cpp UCD/resolve_properties.cpp)
     72
     73
     74# add the executable
     75target_link_libraries (PabloADT ${REQ_LLVM_LIBRARIES})
     76target_link_libraries (CCADT PabloADT)
     77target_link_libraries (UCDlib RegExpADT PabloADT CCADT)
     78target_link_libraries (RegExpADT PabloADT CCADT UCDlib)
     79target_link_libraries (RegExpCompiler RegExpADT)
     80
     81# add the executable
     82add_executable(generate_predefined_ucd_functions generate_predefined_ucd_functions.cpp)
     83target_link_libraries (generate_predefined_ucd_functions RegExpADT UCDlib PabloADT CCADT ${REQ_LLVM_LIBRARIES})
     84
     85set(PRECOMPILED_PROPERTIES_OBJ ${PROJECT_BINARY_DIR}/precompiled_properties.o)
     86set(PRECOMPILED_FILES ${PRECOMPILED_PROPERTIES_OBJ} ${PROJECT_SOURCE_DIR}/UCD/precompiled_properties.cpp)
     87
     88if(ENABLE_MULTIPLEXING)
     89set(MULTIPLEXING_FLAG -multiplexing)
     90endif()
     91
     92add_custom_command(OUTPUT ${PRECOMPILED_FILES}
     93  COMMAND generate_predefined_ucd_functions
     94  ARGS -o ${PRECOMPILED_PROPERTIES_OBJ} -dir ${PROJECT_SOURCE_DIR}/UCD/ -lib $<TARGET_FILE:UCDlib> ${MULTIPLEXING_FLAG}
     95  DEPENDS generate_predefined_ucd_functions
     96  COMMENT "Building predefined UCD functions..."
     97  VERBATIM)
     98
     99add_custom_target(run_generate_predefined_ucd_functions ALL DEPENDS ${PRECOMPILED_FILES})
     100
     101add_executable(icgrep icgrep.cpp do_grep.cpp compiler.cpp ${PRECOMPILED_FILES})
     102target_link_libraries (icgrep UCDlib PabloADT RegExpCompiler CCADT ${REQ_LLVM_LIBRARIES})
     103
     104add_dependencies(icgrep run_generate_predefined_ucd_functions)
     105add_dependencies(RegExpCompiler run_generate_predefined_ucd_functions)
    72106
    73107IF(Boost_FOUND)
     
    97131
    98132include_directories("${PROJECT_SOURCE_DIR}")
    99 include_directories("${PROJECT_SOURCE_DIR}/re")
    100 include_directories("${PROJECT_SOURCE_DIR}/cc")
    101 include_directories("${PROJECT_SOURCE_DIR}/pablo")
    102 include_directories("${PROJECT_SOURCE_DIR}/UCD")
    103 include_directories("${PROJECT_SOURCE_DIR}/include")
    104 include_directories("${PROJECT_SOURCE_DIR}/include/simd-lib")
    105 include_directories("${PROJECT_SOURCE_DIR}/include/simd-lib/idisa_cpp")
    106 
    107 # add the executable
    108 add_executable(icgrep icgrep.cpp do_grep.cpp compiler.cpp)
    109 add_executable(generate_predefined_ucd_functions generate_predefined_ucd_functions.cpp)
    110 
    111 target_link_libraries (PabloADT ${REQ_LLVM_LIBRARIES})
    112 target_link_libraries (CCADT PabloADT RegExpADT)
    113 target_link_libraries (UCDlib PabloADT CCADT)
    114 target_link_libraries (RegExpADT PabloADT CCADT UCDlib)
    115 target_link_libraries (icgrep UCDlib PabloADT RegExpADT CCADT ${REQ_LLVM_LIBRARIES})
    116 target_link_libraries (generate_predefined_ucd_functions UCDlib PabloADT CCADT ${REQ_LLVM_LIBRARIES})
    117133
    118134#Check compiler support for 0x / 11
  • icGREP/icgrep-devel/icgrep/UCD/resolve_properties.cpp

    r4674 r4684  
    1515#include "UCD/PropertyObjectTable.h"
    1616#include "UCD/PropertyValueAliases.h"
    17 #include <boost/algorithm/string/case_conv.hpp>
    1817#include <string>
    1918#include <iostream>
     
    3130};
    3231
    33 inline std::string lowercase(const std::string & name) {
    34     std::locale loc;
    35     return boost::algorithm::to_lower_copy(name, loc);
    36 }
    37 
    3832inline int GetPropertyValueEnumCode(const UCD::property_t type, const std::string & value) {
    3933    return property_object_table[type]->GetPropertyValueEnumCode(value);
     
    8983        }
    9084        if (valit->second == Binary_ns::Y) {
    91             property->setFunctionName("__get_" + lowercase(property_enum_name[theprop]) + "_Y");
     85            property->setFunctionName("__get_" + property_enum_name[theprop] + "_Y");
    9286        }
    9387        else {
    94             Name * binprop = parser->createName("__get_" + lowercase(property_enum_name[theprop]) + "_Y");
     88            Name * binprop = parser->createName("__get_" + property_enum_name[theprop] + "_Y");
    9589            property->setDefinition(makeDiff(makeAny(), binprop));
    9690        }
     
    168162                auto theprop = propit->second;
    169163                if (isa<BinaryPropertyObject>(property_object_table[theprop])) {
    170                     property->setFunctionName("__get_" + lowercase(property_enum_name[theprop]) + "_Y");
     164                    property->setFunctionName("__get_" + property_enum_name[theprop] + "_Y");
    171165                }
    172166                else {
  • icGREP/icgrep-devel/icgrep/compiler.cpp

    r4681 r4684  
    2222#include <pablo/optimizers/pablo_automultiplexing.hpp>
    2323#endif
    24 #include "UCD/precompiled_gc.h"
    25 #include "UCD/precompiled_sc.h"
    26 #include "UCD/precompiled_scx.h"
    27 #include "UCD/precompiled_blk.h"
    28 #include "UCD/precompiled_derivedcoreproperties.h"
    29 #include "UCD/precompiled_proplist.h"
    3024#include <llvm/Support/CommandLine.h>
    3125#include <pablo/function.h>
     
    176170
    177171    PabloCompiler pablo_compiler;
    178     if (UsePregeneratedUnicode()) {
    179         install_property_gc_fn_ptrs(pablo_compiler);
    180         install_property_sc_fn_ptrs(pablo_compiler);
    181         install_property_scx_fn_ptrs(pablo_compiler);
    182         install_property_blk_fn_ptrs(pablo_compiler);
    183         install_property_DerivedCoreProperties_fn_ptrs(pablo_compiler);
    184         install_property_PropList_fn_ptrs(pablo_compiler);
    185     }
    186172    try {
    187173        CompiledPabloFunction retVal = pablo_compiler.compile(function);
  • icGREP/icgrep-devel/icgrep/generate_predefined_ucd_functions.cpp

    r4680 r4684  
    3535#include "llvm/Support/FileSystem.h"
    3636#include <llvm/Transforms/Scalar.h>
    37 #include <boost/algorithm/string/case_conv.hpp>
    3837#include <iostream>
    3938
     
    4342using namespace llvm;
    4443
    45 inline std::string lowercase(const std::string & name) {
    46     std::locale loc;
    47     return boost::algorithm::to_lower_copy(name, loc);
    48 }
    49 
    5044static cl::opt<std::string>
    51 ObjectFilename("o", cl::desc("Output Object filename"), cl::value_desc("filename"));
     45ObjectFilename("o", cl::desc("Output object filename"), cl::value_desc("filename"), cl::Required);
    5246
    5347static cl::opt<std::string>
    54 PropertyFilename("p", cl::desc("Install Property filename"), cl::value_desc("filename"));
     48UCDSourcePath("dir", cl::desc("UCD source code directory"), cl::value_desc("directory"), cl::Required);
     49
     50static cl::opt<std::string>
     51UCDLibraryPath("lib", cl::desc("Static UCD library path"), cl::value_desc("filename"), cl::Required);
    5552
    5653#ifdef ENABLE_MULTIPLEXING
     
    7168    PabloBuilder builder(function.getEntryBlock());
    7269    // Build the unicode set function
    73     ucdCompiler.generateWithDefaultIfHierarchy(set, builder);
     70    PabloAST * target = ucdCompiler.generateWithDefaultIfHierarchy(set, builder);
     71    function.setResult(0, builder.createAssign("matches", target));
    7472    // Optimize it at the pablo level
    7573    Simplifier::optimize(function);
     
    9189 ** ------------------------------------------------------------------------------------------------------------- */
    9290
    93 void writePropertyInstaller(property_list && properties) {
    94 
     91void writePrecompiledProperties(property_list && properties) {
     92
     93    const std::string headerFilename = UCDSourcePath + "/precompiled_properties.h";
    9594    #ifdef USE_LLVM_3_5
    9695    std::string error;
    97     raw_fd_ostream out(PropertyFilename.c_str(), error, sys::fs::F_None);
     96    raw_fd_ostream header(headerFilename.c_str(), error, sys::fs::F_None);
    9897    if (!error.empty()) {
    9998        throw std::runtime_error(error);
     
    101100    #else
    102101    std::error_code error;
    103     raw_fd_ostream out(PropertyFilename, error, sys::fs::F_None);
     102    raw_fd_ostream header(headerFilename, error, sys::fs::F_None);
    104103    if (error) {
    105104        throw std::runtime_error(error.message());
     
    107106    #endif
    108107
    109     out << "#ifndef PROPERTYINSTALL\n";
    110     out << "#define PROPERTYINSTALL\n\n";
    111     out << "#include <include/simd-lib/bitblock.hpp>\n";
    112     out << "#include <pablo/pablo_compiler.h>\n\n";
    113     out << "namespace UCD {\n\n";
    114     out << "struct Input {\n    BitBlock bit[8];\n};\n\n";
    115     out << "struct Output {\n    BitBlock bit[1];\n};\n\n";
     108    header << "#ifndef PRECOMPILED_PROPERTIES\n";
     109    header << "#define PRECOMPILED_PROPERTIES\n\n";
     110    header << "#include <string>\n\n";
     111    header << "#include <tuple>\n";
     112    header << "namespace UCD {\n\n";
     113    header << "using ExternalProperty = std::tuple<void *, unsigned, unsigned, size_t>;\n\n";
     114    header << "const ExternalProperty & resolveExternalProperty(const std::string & name);\n\n";
     115    header << "}\n\n";
     116    header << "#endif\n";
     117    header.close();
     118
     119    const std::string cppFilename = UCDSourcePath + "/precompiled_properties.cpp";
     120    #ifdef USE_LLVM_3_5
     121    raw_fd_ostream cpp(cppFilename.c_str(), error, sys::fs::F_None);
     122    if (!error.empty()) {
     123        throw std::runtime_error(error);
     124    }
     125    #else
     126    raw_fd_ostream cpp(cppFilename, error, sys::fs::F_None);
     127    if (error) {
     128        throw std::runtime_error(error.message());
     129    }
     130    #endif
     131
     132    cpp << "#include \"precompiled_properties.h\"\n";
     133    cpp << "#include <include/simd-lib/bitblock.hpp>\n";
     134    cpp << "#include <stdexcept>\n";
     135    cpp << "#include <unordered_map>\n\n";
     136    cpp << "namespace UCD {\n\n";
     137    cpp << "struct Input {\n    BitBlock bit[8];\n};\n\n";
     138    cpp << "struct Output {\n    BitBlock bit[1];\n};\n\n";
    116139    for (auto prop : properties) {
    117         out << "extern \"C\" void " + prop.first + "(const Input &, BitBlock *, Output &);\n";
    118     }
    119     out << "\nvoid install_properties(pablo::PabloCompiler & p) {\n";
    120     for (auto prop : properties) {
    121         out << "    p.InstallExternalFunction(\"" + prop.first + "\", reinterpret_cast<void *>(&" + prop.first + "), " + std::to_string(prop.second) + ");\n";
    122     }
    123     out << "}\n}\n\n#endif\n";
    124     out.close();
     140        cpp << "extern \"C\" void " + prop.first + "(const Input &, BitBlock *, Output &);\n";
     141    }
     142
     143    cpp << "\nconst static std::unordered_map<std::string, ExternalProperty> ExternalPropertyMap = {\n";
     144    for (auto itr = properties.begin(); itr != properties.end(); ) {
     145        cpp << "    {\"" + itr->first + "\", std::make_tuple(reinterpret_cast<void *>(&" + itr->first + "), 8, 1, " + std::to_string(itr->second) + ")}";
     146        if (++itr != properties.end()) {
     147            cpp << ",";
     148        }
     149        cpp << "\n";
     150    }
     151    cpp << "};\n\n";
     152
     153    cpp << "const ExternalProperty & resolveExternalProperty(const std::string & name) {\n";
     154    cpp << "    auto f = ExternalPropertyMap.find(name);\n";
     155    cpp << "    if (f == ExternalPropertyMap.end())\n";
     156    cpp << "        throw std::runtime_error(\"No external property named \\\"\" + name + \"\\\" found!\");\n";
     157    cpp << "    return f->second;\n";
     158    cpp << "}\n\n}\n";
     159
     160    cpp.close();
     161
    125162}
    126163
     
    160197    verifyModule(*module, &dbgs());
    161198
    162     writePropertyInstaller(std::move(properties));
     199    writePrecompiledProperties(std::move(properties));
    163200
    164201    return module;
     
    252289int main(int argc, char *argv[]) {
    253290    cl::ParseCommandLineOptions(argc, argv, "UCD Compiler\n");
    254     if (PropertyFilename.empty()) {
    255         PropertyFilename = "PropertyInstall.h";
    256     }
    257     if (ObjectFilename.empty()) {
    258         ObjectFilename = "pregenerated_properties.o";
    259     }
    260291    Module * module = generateUCDModule();
    261292    compileUCDModule(module);
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.cpp

    r4683 r4684  
    77
    88#include <include/simd-lib/bitblock.hpp>
     9#include <pablo/carry_data.h>
     10#include <pablo/codegenstate.h>
     11#include <pablo/carry_manager.h>
     12#include <pablo/pabloAST.h>
    913#include <stdexcept>
    1014#include <pablo/carry_data.h>
     
    1519
    1620namespace pablo {
    17  
    1821
    1922unsigned CarryManager::initialize(PabloBlock * pb, Value * carryPtr) {
  • icGREP/icgrep-devel/icgrep/pablo/expression_map.hpp

    r4681 r4684  
    33
    44#include <pablo/pabloAST.h>
    5 #include <llvm/ADT/ArrayRef.h>
     5#include <slab_allocator.h>
    66#include <map>
    77
     
    9393};
    9494
     95
     96struct VarArgMap {
     97
     98    friend struct ExpressionTable;
     99
     100    struct Key {
     101        inline Key(PabloAST::ClassTypeId type, unsigned args, PabloAST ** arg) : mType(type), mArgs(args), mArg(arg) {}
     102        inline Key(const Key & key) = default;
     103        inline Key(Key && key) = default;
     104        inline bool operator < (const Key & other) const {
     105            if (mType != other.mType)
     106                return mType < other.mType;
     107            if (mArgs != other.mArgs)
     108                return mArgs < other.mArgs;
     109            for (unsigned i = 0; i != mArgs; ++i) {
     110                if (mArg[i] != other.mArg[i]) {
     111                    return mArg[i] < other.mArg[i];
     112                }
     113            }
     114            return false;
     115        }
     116    private:
     117        PabloAST::ClassTypeId         mType;
     118        unsigned                      mArgs;
     119        PabloAST **                   mArg;
     120    };
     121
     122    using Allocator = LLVMAllocator;
     123    using MapAllocator = LLVMAllocatorProxy<std::pair<Key, PabloAST *>>;
     124    using Map = std::map<Key, PabloAST *>; // , std::less<Key>, MapAllocator
     125
     126    explicit VarArgMap(VarArgMap * predecessor = nullptr)
     127    : mPredecessor(predecessor) {
     128
     129    }
     130
     131    explicit VarArgMap(VarArgMap && other) noexcept
     132    : mPredecessor(other.mPredecessor)
     133    , mMap(std::move(other.mMap)) {
     134
     135    }
     136
     137    VarArgMap & operator=(VarArgMap && other) {
     138        mPredecessor = other.mPredecessor;
     139        mMap = std::move(other.mMap);
     140        return *this;
     141    }
     142
     143    template <class Functor, typename... Params>
     144    inline PabloAST * findOrCall(Functor && functor, const PabloAST::ClassTypeId type, std::initializer_list<PabloAST *> args, Params... params) {
     145        PabloAST * const f = find(type, args);
     146        if (f) {
     147            return f;
     148        }
     149        PabloAST * const object = functor(args, std::forward<Params>(params)...);
     150        PabloAST ** const args_copy = mAllocator.Allocate<PabloAST *>(args.size());
     151        std::copy(args.begin(), args.end(), args_copy);
     152        Key key(type, args.size(), args_copy);
     153        mMap.insert(std::make_pair(std::move(key), object));
     154        return object;
     155    }
     156
     157    inline std::pair<PabloAST *, bool> findOrAdd(PabloAST * object, const PabloAST::ClassTypeId type, std::initializer_list<PabloAST *> args) {
     158        PabloAST * const entry = find(type, args);
     159        if (entry) {
     160            return std::make_pair(entry, false);
     161        }
     162        PabloAST ** const args_copy = mAllocator.Allocate<PabloAST *>(args.size());
     163        std::copy(args.begin(), args.end(), args_copy);
     164        Key key(type, args.size(), args_copy);
     165        mMap.insert(std::make_pair(std::move(key), object));
     166        return std::make_pair(object, true);
     167    }
     168
     169    inline PabloAST * find(const PabloAST::ClassTypeId type, const std::initializer_list<PabloAST *> args) const {
     170        PabloAST * value[args.size()];
     171        std::copy(args.begin(), args.end(), value);
     172        return find(std::move(Key(type, args.size(), value)));
     173    }
     174
     175private:
     176
     177    inline PabloAST * find(Key && key) const {
     178        // check this map to see if we have it
     179        auto itr = mMap.find(key);
     180        if (itr != mMap.end()) {
     181            return itr->second;
     182        }
     183        // check any previous maps to see if it exists
     184        auto * pred = mPredecessor;
     185        while (pred) {
     186            itr = pred->mMap.find(key);
     187            if (itr == pred->mMap.end()) {
     188                pred = pred->mPredecessor;
     189                continue;
     190            }
     191            return itr->second;
     192        }
     193        return nullptr;
     194    }
     195
     196private:
     197    VarArgMap *     mPredecessor;
     198    Allocator       mAllocator;
     199    Map             mMap;
     200};
     201
    95202struct ExpressionTable {
    96203
     
    125232    template <class Functor, typename... Params>
    126233    inline PabloAST * findUnaryOrCall(Functor && functor, const PabloAST::ClassTypeId type, PabloAST * expr, Params... params) {
    127         return mUnary.findOrCall(std::move(functor), type, expr, std::forward<Params>(params)...);
     234        return mUnary.findOrCall(std::move(functor), type,  expr , std::forward<Params>(params)...);
    128235    }
    129236
  • icGREP/icgrep-devel/icgrep/pablo/function.cpp

    r4680 r4684  
    55namespace pablo {
    66
    7 Prototype::Prototype(const PabloAST::ClassTypeId type, std::string && name, const unsigned numOfParameters, const unsigned numOfResults, const unsigned requiredStateSpace)
     7Prototype::Prototype(const PabloAST::ClassTypeId type, std::string && name, const unsigned numOfParameters, const unsigned numOfResults, const unsigned requiredStateSpace, void * functionPtr)
    88: PabloAST(type)
    99, mName(new String(name, false)) // <-- Should there be a global pool to assert that no two prototypes have the same name?
    1010, mNumOfParameters(numOfParameters)
    1111, mNumOfResults(numOfResults)
    12 , mRequiredStateSpace(requiredStateSpace) {
     12, mRequiredStateSpace(requiredStateSpace)
     13, mFunctionPtr(functionPtr) {
    1314
    1415}
    1516
    1617PabloFunction::PabloFunction(std::string && name, const unsigned numOfParameters, const unsigned numOfResults)
    17 : Prototype(ClassTypeId::Function, std::move(name), numOfParameters, numOfResults, 0)
     18: Prototype(ClassTypeId::Function, std::move(name), numOfParameters, numOfResults, 0, nullptr)
    1819, mEntryBlock(PabloBlock::Create(mSymbolTable))
    1920, mParameters(reinterpret_cast<Var **>(mAllocator.allocate(sizeof(Var *) * numOfParameters)))
  • icGREP/icgrep-devel/icgrep/pablo/function.h

    r4680 r4684  
    2222    }
    2323
    24     static inline bool classof(const void *) {
     24    static inline bool classof(void *) {
    2525        return false;
    2626    }
    2727
    28     static Prototype * Create(std::string name, const unsigned inputVariables, const unsigned outputVariables, const unsigned requiredStateSpace);
     28    static Prototype * Create(std::string name, const unsigned inputVariables, const unsigned outputVariables, const unsigned requiredStateSpace, void * functionPtr = nullptr);
    2929
    3030    const String * getName() const {
     
    4545    }
    4646
    47 protected:
    48     // Should only be modified by a pablo::Function after compilation
    49     void setRequiredStateSpace(const unsigned value) {
    50         mRequiredStateSpace = value;
     47    void * getFunctionPtr() const {
     48        return mFunctionPtr;
    5149    }
    5250
    53     Prototype(const PabloAST::ClassTypeId type, std::string && name, const unsigned numOfParameters, const unsigned numOfResults, const unsigned requiredStateSpace);
     51protected:
     52    Prototype(const PabloAST::ClassTypeId type, std::string && name, const unsigned numOfParameters, const unsigned numOfResults, const unsigned requiredStateSpace, void * functionPtr);
    5453protected:
    5554    const String * const    mName;
     
    5756    const unsigned          mNumOfResults;
    5857    unsigned                mRequiredStateSpace;
     58    void *                  mFunctionPtr;
    5959};
    6060
    61 inline Prototype * Prototype::Create(std::string name, const unsigned numOfParameters, const unsigned numOfResults, const unsigned requiredStateSpace) {
    62     return new Prototype(PabloAST::ClassTypeId::Prototype, std::move(name), numOfParameters, numOfResults, requiredStateSpace);
     61inline Prototype * Prototype::Create(std::string name, const unsigned numOfParameters, const unsigned numOfResults, const unsigned requiredStateSpace, void * functionPtr) {
     62    return new Prototype(PabloAST::ClassTypeId::Prototype, std::move(name), numOfParameters, numOfResults, requiredStateSpace, functionPtr);
    6363}
    6464
     
    7979    }
    8080
    81     static inline bool classof(const void *) {
     81    static inline bool classof(void *) {
    8282        return false;
    8383    }
     
    144144    }
    145145
     146    void setRequiredStateSpace(const unsigned value) {
     147        mRequiredStateSpace = value;
     148    }
     149
     150    void setFunctionPtr(void * functionPtr) {
     151        mFunctionPtr = functionPtr;
     152    }
     153
    146154    virtual ~PabloFunction() { }
    147155
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r4682 r4684  
    6868PabloCompiler::PabloCompiler()
    6969: mMod(nullptr)
     70, mExecutionEngine(nullptr)
    7071, mBuilder(nullptr)
    7172, mCarryManager(nullptr)
     73, mCarryOffset(0)
    7274, mBitBlockType(VectorType::get(IntegerType::get(getGlobalContext(), 64), BLOCK_SIZE / 64))
    7375, iBuilder(mBitBlockType)
     
    8991}
    9092   
    91 void PabloCompiler::InstallExternalFunction(std::string C_fn_name, void * fn_ptr, const size_t carrySize) {
    92     mExternalMap.insert(std::make_pair(C_fn_name, fn_ptr));
    93 }
    9493
    9594void PabloCompiler::genPrintRegister(std::string regName, Value * bitblockValue) {
     
    128127    #endif
    129128    builder.setOptLevel(mMaxWhileDepth ? CodeGenOpt::Level::Less : CodeGenOpt::Level::None);
    130     ExecutionEngine * engine = builder.create();
    131     if (engine == nullptr) {
     129    mExecutionEngine = builder.create();
     130    if (mExecutionEngine == nullptr) {
    132131        throw std::runtime_error("Could not create ExecutionEngine: " + errMessage);
    133132    }
    134     DeclareFunctions(engine);
    135     DeclareCallFunctions(engine);
     133    DeclareFunctions();
    136134
    137135    auto func = compile(function, mMod);
     
    144142    verifyModule(*module, &dbgs());
    145143
    146     engine->finalizeObject();
     144    mExecutionEngine->finalizeObject();
     145    ExecutionEngine * engine = mExecutionEngine;
     146    mExecutionEngine = nullptr; // <-- pass ownership of the execution engine to the caller
    147147
    148148    return CompiledPabloFunction(func.second, func.first, engine);
     
    176176    }
    177177       
    178     unsigned totalCarryDataSize = mCarryManager->initialize(&(function.getEntryBlock()), mCarryDataPtr);
     178    mCarryOffset = mCarryManager->initialize(&(function.getEntryBlock()), mCarryDataPtr);
    179179   
    180180    //Generate the IR instructions for the function.
     
    202202
    203203    //Return the required size of the carry data area to the process_block function.
    204     return std::make_pair(mFunction, totalCarryDataSize * sizeof(BitBlock));
     204    return std::make_pair(mFunction, mCarryOffset * sizeof(BitBlock));
    205205}
    206206
     
    348348}
    349349
    350 inline void PabloCompiler::DeclareFunctions(ExecutionEngine * const engine) {
     350inline void PabloCompiler::DeclareFunctions() {
    351351    if (DumpTrace || TraceNext) {
    352352        //This function can be used for testing to print the contents of a register from JIT'd code to the terminal window.
    353353        mPrintRegisterFunction = mMod->getOrInsertFunction("wrapped_print_register", Type::getVoidTy(mMod->getContext()), Type::getInt8PtrTy(mMod->getContext()), mBitBlockType, NULL);
    354         if (engine) engine->addGlobalMapping(cast<GlobalValue>(mPrintRegisterFunction), (void *)&wrapped_print_register);
    355     }
    356 }
    357    
    358 void PabloCompiler::DeclareCallFunctions(ExecutionEngine * const engine) {
    359     for (auto mapping : mCalleeMap) {
    360         const String * callee = mapping.first;
    361         auto ei = mExternalMap.find(callee->value());
    362         if (ei != mExternalMap.end()) {
    363 
    364             Type * inputType = PointerType::get(StructType::get(mMod->getContext(), std::vector<Type *>{8, mBitBlockType}), 0);
    365             Type * carryType = PointerType::get(mBitBlockType, 0);
    366             Type * outputType = PointerType::get(StructType::get(mMod->getContext(), std::vector<Type *>{1, mBitBlockType}), 0);
    367             FunctionType * functionType = FunctionType::get(Type::getVoidTy(mMod->getContext()), std::vector<Type *>{inputType, carryType, outputType}, false);
    368 
    369             //Starts on process_block
    370             SmallVector<AttributeSet, 3> Attrs;
    371             Attrs.push_back(AttributeSet::get(mMod->getContext(), 1U, { Attribute::ReadOnly, Attribute::NoCapture }));
    372             Attrs.push_back(AttributeSet::get(mMod->getContext(), 2U, { Attribute::NoCapture }));
    373             Attrs.push_back(AttributeSet::get(mMod->getContext(), 3U, { Attribute::ReadNone, Attribute::NoCapture }));
    374             AttributeSet AttrSet = AttributeSet::get(mMod->getContext(), Attrs);
    375 
    376             Function * externalFunction = cast<Function>(mMod->getOrInsertFunction(callee->value(), functionType, AttrSet));
    377             if (LLVM_UNLIKELY(externalFunction == nullptr)) {
    378                 throw std::runtime_error("Could not create static method call for external function \"" + callee->to_string() + "\"");
    379             }
    380             externalFunction->setCallingConv(llvm::CallingConv::C);
    381 
    382             if (engine) engine->addGlobalMapping(externalFunction, ei->second);
    383             mCalleeMap[callee] = externalFunction;
    384         }
    385         else {
    386             throw std::runtime_error("External function \"" + callee->to_string() + "\" not installed");
    387         }
     354        if (mExecutionEngine) mExecutionEngine->addGlobalMapping(cast<GlobalValue>(mPrintRegisterFunction), (void *)&wrapped_print_register);
    388355    }
    389356}
     
    583550            return;
    584551        }
    585         auto ci = mCalleeMap.find(call->getCallee());
    586         if (LLVM_UNLIKELY(ci == mCalleeMap.end())) {
    587             throw std::runtime_error("Unexpected error locating static function for \"" + call->getCallee()->to_string() + "\"");
    588         }       
    589 
    590         Function * function = ci->second;
    591         auto arg = function->getArgumentList().begin();
    592         Value * carryFramePtr = ConstantPointerNull::get(cast<PointerType>((++arg)->getType()));
    593         AllocaInst * outputStruct = mBuilder->CreateAlloca(cast<PointerType>((++arg)->getType())->getElementType());
    594         mBuilder->CreateCall3(function, mInputAddressPtr, carryFramePtr, outputStruct);
     552
     553        const Prototype * proto = call->getPrototype();
     554        const String * callee = proto->getName();
     555
     556        Type * inputType = StructType::get(mMod->getContext(), std::vector<Type *>{proto->getNumOfParameters(), mBitBlockType});
     557        Type * carryType = mBitBlockType;
     558        Type * outputType = StructType::get(mMod->getContext(), std::vector<Type *>{proto->getNumOfResults(), mBitBlockType});
     559        FunctionType * functionType = FunctionType::get(Type::getVoidTy(mMod->getContext()), std::vector<Type *>{PointerType::get(inputType, 0), PointerType::get(carryType, 0), PointerType::get(outputType, 0)}, false);
     560
     561        //Starts on process_block
     562        SmallVector<AttributeSet, 3> Attrs;
     563        Attrs.push_back(AttributeSet::get(mMod->getContext(), 1U, { Attribute::ReadOnly, Attribute::NoCapture }));
     564        Attrs.push_back(AttributeSet::get(mMod->getContext(), 2U, { Attribute::NoCapture }));
     565        Attrs.push_back(AttributeSet::get(mMod->getContext(), 3U, { Attribute::ReadNone, Attribute::NoCapture }));
     566        AttributeSet AttrSet = AttributeSet::get(mMod->getContext(), Attrs);
     567
     568        Function * externalFunction = cast<Function>(mMod->getOrInsertFunction(callee->value(), functionType, AttrSet));
     569        if (LLVM_UNLIKELY(externalFunction == nullptr)) {
     570            throw std::runtime_error("Could not create static method call for external function \"" + callee->to_string() + "\"");
     571        }
     572        externalFunction->setCallingConv(llvm::CallingConv::C);
     573
     574        if (mExecutionEngine) mExecutionEngine->addGlobalMapping(externalFunction, proto->getFunctionPtr());
     575
     576        // add mCarryOffset to mCarryDataPtr
     577        Value * carryFramePtr = mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(mCarryOffset));
     578        AllocaInst * outputStruct = mBuilder->CreateAlloca(outputType);
     579        mBuilder->CreateCall3(externalFunction, mInputAddressPtr, carryFramePtr, outputStruct);
    595580        Value * outputPtr = mBuilder->CreateGEP(outputStruct, { mBuilder->getInt32(0), mBuilder->getInt32(0) });
    596581        expr = mBuilder->CreateAlignedLoad(outputPtr, BLOCK_SIZE / 8, false);
     582
     583        mCarryOffset += (proto->getRequiredStateSpace() + (BLOCK_SIZE / 8) - 1) / (BLOCK_SIZE / 8);
    597584    }
    598585    else if (const And * pablo_and = dyn_cast<And>(stmt)) {
     
    796783   
    797784void PabloCompiler::SetOutputValue(Value * marker, const unsigned index) {
    798     assert (marker);
    799     if (marker->getType()->isPointerTy()) {
     785    if (LLVM_UNLIKELY(marker == nullptr)) {
     786        throw std::runtime_error("Cannot set result " + std::to_string(index) + " to Null");
     787    }
     788    if (LLVM_UNLIKELY(marker->getType()->isPointerTy())) {
    800789        marker = mBuilder->CreateAlignedLoad(marker, BLOCK_SIZE/8, false);
    801790    }
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.h

    r4674 r4684  
    107107    PabloCompiler();
    108108    ~PabloCompiler();
    109     void InstallExternalFunction(std::string C_fn_name, void * fn_ptr, const size_t carrySize = 0);
    110109    CompiledPabloFunction compile(pablo::PabloFunction & function);
    111110    std::pair<Function *, size_t> compile(pablo::PabloFunction & function, Module *module);
     
    113112private:
    114113    void GenerateFunction(PabloFunction & function);
    115     void DeclareFunctions(ExecutionEngine * const engine);
     114    void DeclareFunctions();
    116115    void Examine(PabloFunction & function);
    117116    void Examine(PabloBlock & block);
    118     void DeclareCallFunctions(ExecutionEngine * const engine);
     117
    119118    void SetOutputValue(Value * marker, const unsigned index);
    120119
     
    150149
    151150    Module *                            mMod;
     151    ExecutionEngine *                   mExecutionEngine;
    152152    IRBuilder <> *                      mBuilder;
    153153
    154154    CarryManager *                      mCarryManager;
     155    size_t                              mCarryOffset;
    155156
    156157    VectorType* const                   mBitBlockType;
     
    173174    unsigned                            mMaxWhileDepth;
    174175
    175     std::map<std::string, void *>       mExternalMap;
    176176    CalleeMap                           mCalleeMap;
    177177
  • icGREP/icgrep-devel/icgrep/re/re_compiler.cpp

    r4681 r4684  
    2121#include <cc/cc_namemap.hpp>
    2222#include <pablo/codegenstate.h>
     23#include <UCD/ucd_compiler.hpp>
     24#include <UCD/precompiled_properties.h>
    2325#include <UCD/resolve_properties.h>
    2426#include <assert.h>
     
    4042static cl::opt<bool> DisablePregeneratedUnicode("disable-pregenerated-unicode", cl::init(false),
    4143                     cl::desc("disable use of pregenerated Unicode character class sets"), cl::cat(fREcompilationOptions));
    42 
    4344using namespace pablo;
    4445
    4546namespace re {
    46 
    47 bool UsePregeneratedUnicode() {
    48     return !DisablePregeneratedUnicode;
    49 }
    5047
    5148RE_Compiler::RE_Compiler(pablo::PabloFunction & function, cc::CC_Compiler & ccCompiler)
     
    6158, mLoopVariants()
    6259, mPB(*ccCompiler.getBuilder().getPabloBlock(), ccCompiler.getBuilder())
    63 , mUCDCompiler(ccCompiler)
    6460, mFunction(function)
    6561{
     
    275271    }
    276272    else if (name->getType() == Name::Type::UnicodeProperty) {
    277         if (UsePregeneratedUnicode()) {
    278             var = pb.createCall(Prototype::Create(name->getFunctionName(), 8, 1, 0), mCCCompiler.getBasisBits());
     273        if (DisablePregeneratedUnicode) {
     274            UCD::UCDCompiler ucdCompiler(mCCCompiler);
     275            var = ucdCompiler.generateWithDefaultIfHierarchy(UCD::resolveUnicodeSet(name), pb);
    279276        }
    280277        else {
    281             var = mUCDCompiler.generateWithDefaultIfHierarchy(UCD::resolveUnicodeSet(name), pb);
     278            const UCD::ExternalProperty & ep = UCD::resolveExternalProperty(name->getFunctionName());
     279            var = pb.createCall(Prototype::Create(name->getFunctionName(), std::get<1>(ep), std::get<2>(ep), std::get<3>(ep), std::get<0>(ep)), mCCCompiler.getBasisBits());
    282280        }
    283281    }
  • icGREP/icgrep-devel/icgrep/re/re_compiler.h

    r4681 r4684  
    1212#include <cc/cc_compiler.h>
    1313#include <pablo/builder.hpp>
    14 #include <UCD/ucd_compiler.hpp>
    1514#include <string>
    1615#include <list>
     
    3938
    4039namespace re {
    41 
    42 bool UsePregeneratedUnicode();
    4340
    4441enum MarkerPosition {FinalMatchByte, InitialPostPositionByte, FinalPostPositionByte};
     
    104101    std::vector<pablo::Next *>                      mLoopVariants; // <- rethink name
    105102    pablo::PabloBuilder                             mPB;
    106     UCD::UCDCompiler                                mUCDCompiler;
    107103    pablo::PabloFunction &                          mFunction;
    108104};
  • icGREP/icgrep-devel/icgrep/re/re_nullable.cpp

    r4249 r4684  
    11#include "re_nullable.h"
    2 #include "re_cc.h"
    3 #include "re_start.h"
    4 #include "re_end.h"
    5 #include "re_alt.h"
    6 #include "re_rep.h"
    7 #include "re_simplifier.h"
    8 #include <printer_re.h>
     2#include <re/re_cc.h>
     3#include <re/re_start.h>
     4#include <re/re_end.h>
     5#include <re/re_alt.h>
     6#include <re/re_rep.h>
     7#include <re/re_simplifier.h>
     8#include <re/printer_re.h>
    99#include <iostream>
    1010/*
Note: See TracChangeset for help on using the changeset viewer.