Ignore:
Timestamp:
Jul 12, 2015, 3:52:43 PM (4 years ago)
Author:
nmedfort
Message:

Start of work to make the pablo compiler reenterant. Fixed bug that prevented it from using Less optimization level.

Location:
icGREP/icgrep-devel/icgrep/pablo
Files:
2 edited

Legend:

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

    r4659 r4661  
    7474, mBuilder(&LLVM_Builder)
    7575, mCarryManager(nullptr)
    76 , mExecutionEngine(nullptr)
    7776, mBitBlockType(VectorType::get(IntegerType::get(mMod->getContext(), 64), BLOCK_SIZE / 64))
    7877, mInputPtr(nullptr)
     
    8685, mOutputAddressPtr(nullptr)
    8786, mMaxWhileDepth(0)
    88 , mPrintRegisterFunction(nullptr)
    89 {
    90     //Create the jit execution engine.up
    91     InitializeNativeTarget();
    92     InitializeNativeTargetAsmPrinter();
    93     InitializeNativeTargetAsmParser();
     87, mPrintRegisterFunction(nullptr) {
     88
    9489}
    9590
     
    114109}
    115110
    116 CompiledPabloFunction PabloCompiler::compile(PabloFunction & function)
    117 {
     111CompiledPabloFunction PabloCompiler::compile(PabloFunction & function) {
    118112    mWhileDepth = 0;
    119113    mIfDepth = 0;
    120114    mMaxWhileDepth = 0;
    121115    mCarryManager = new CarryManager(mMod, mBuilder, mBitBlockType, mZeroInitializer, mOneInitializer);
    122    
     116
     117    Examine(function.getEntryBlock());
     118   
     119    InitializeNativeTarget();
     120    InitializeNativeTargetAsmPrinter();
     121    InitializeNativeTargetAsmParser();
     122
    123123    std::string errMessage;
    124124#ifdef USE_LLVM_3_5
     
    133133#endif
    134134    builder.setOptLevel(mMaxWhileDepth ? CodeGenOpt::Level::Less : CodeGenOpt::Level::None);
    135     mExecutionEngine = builder.create();
    136     if (mExecutionEngine == nullptr) {
     135    ExecutionEngine * ee = builder.create();
     136    if (ee == nullptr) {
    137137        throw std::runtime_error("Could not create ExecutionEngine: " + errMessage);
    138138    }
    139139
    140140    GenerateFunction(function);
    141     DeclareFunctions();
    142 
    143     Examine(function.getEntryBlock());
    144     DeclareCallFunctions();
     141    DeclareFunctions(ee);
     142    DeclareCallFunctions(ee);
    145143
    146144    mWhileDepth = 0;
     
    191189    verifyModule(*mMod, &dbgs());
    192190
    193     mExecutionEngine->finalizeObject();
     191    ee->finalizeObject();
    194192
    195193    delete mCarryManager;
     
    197195
    198196    //Return the required size of the carry data area to the process_block function.
    199     return CompiledPabloFunction(totalCarryDataSize * sizeof(BitBlock), mFunction, mExecutionEngine);
     197    return CompiledPabloFunction(totalCarryDataSize * sizeof(BitBlock), mFunction, ee);
    200198}
    201199
     
    314312}
    315313
    316 inline void PabloCompiler::DeclareFunctions() {
     314inline void PabloCompiler::DeclareFunctions(ExecutionEngine * ee) {
    317315    if (DumpTrace || TraceNext) {
    318316        //This function can be used for testing to print the contents of a register from JIT'd code to the terminal window.
    319317        mPrintRegisterFunction = mMod->getOrInsertFunction("wrapped_print_register", Type::getVoidTy(getGlobalContext()), Type::getInt8PtrTy(getGlobalContext()), mBitBlockType, NULL);
    320         mExecutionEngine->addGlobalMapping(cast<GlobalValue>(mPrintRegisterFunction), (void *)&wrapped_print_register);
     318        ee->addGlobalMapping(cast<GlobalValue>(mPrintRegisterFunction), (void *)&wrapped_print_register);
    321319    }
    322320}
     
    340338}
    341339
    342 void PabloCompiler::DeclareCallFunctions() {
     340void PabloCompiler::DeclareCallFunctions(ExecutionEngine * ee) {
    343341    for (auto mapping : mCalleeMap) {
    344342        const String * callee = mapping.first;
     
    351349                throw std::runtime_error("Could not create static method call for external function \"" + callee->to_string() + "\"");
    352350            }
    353             mExecutionEngine->addGlobalMapping(cast<GlobalValue>(externalValue), fn_ptr);
     351            ee->addGlobalMapping(cast<GlobalValue>(externalValue), fn_ptr);
    354352            mCalleeMap[callee] = externalValue;
    355353        }
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.h

    r4659 r4661  
    6767    CompiledPabloFunction(size_t carryDataSize, Function * function, ExecutionEngine * executionEngine);
    6868
     69    inline Function * getLLVMFunction() const {
     70        return mFunction;
     71    }
     72
     73    inline ExecutionEngine * getExecutionEngine() const {
     74        return mExecutionEngine;
     75    }
     76
    6977    inline CompiledPabloFunction(CompiledPabloFunction && cpf)
    7078    : CarryDataSize(cpf.CarryDataSize)
     
    101109    ~PabloCompiler();
    102110    void InstallExternalFunction(std::string C_fn_name, void * fn_ptr);
    103     CompiledPabloFunction compile(pablo::PabloFunction &function);
     111    CompiledPabloFunction compile(pablo::PabloFunction & function);
     112    Module * getModule();
    104113private:
    105114    void GenerateFunction(PabloFunction & function);
    106     void DeclareFunctions();
     115    void DeclareFunctions(ExecutionEngine * ee);
    107116    void Examine(PabloBlock & blk);
    108     void DeclareCallFunctions();
     117    void DeclareCallFunctions(ExecutionEngine * ee);
    109118    void SetOutputValue(Value * marker, const unsigned index);
    110119
     
    147156    IRBuilder <> *                      mBuilder;
    148157    CarryManager *                      mCarryManager;
    149     ExecutionEngine*                    mExecutionEngine;
    150158
    151159    VectorType* const                   mBitBlockType;
     
    173181};
    174182
     183inline Module * PabloCompiler::getModule() {
     184    return mMod;
     185}
     186
    175187}
    176188
Note: See TracChangeset for help on using the changeset viewer.