Ignore:
Timestamp:
Aug 18, 2015, 12:16:01 PM (4 years ago)
Author:
cameron
Message:

Factor out execution engine code from Pablo compiler into new JIT_to_ExecutionEngine routine.

File:
1 edited

Legend:

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

    r4726 r4730  
    1313#include "compiler.h"
    1414#include "pablo/pablo_compiler.h"
     15#include <llvm/IR/Function.h>
     16#include <llvm/ExecutionEngine/ExecutionEngine.h>
     17#include <llvm/ExecutionEngine/MCJIT.h>
     18#include <llvm/IRReader/IRReader.h>
     19#include <llvm/Support/SourceMgr.h>
     20#include <llvm/Support/CommandLine.h>
     21#include <llvm/Support/TargetSelect.h>
     22#include <llvm/Support/Host.h>
     23
    1524#include "do_grep.h"
    16 
    17 #include "llvm/Support/CommandLine.h"
    1825
    1926static cl::OptionCategory aRegexSourceOptions("Regular Expression Options",
     
    3845static cl::list<std::string> regexVector("e", cl::desc("Regular expression"), cl::ZeroOrMore, cl::cat(aRegexSourceOptions));
    3946static cl::opt<std::string> RegexFilename("f", cl::desc("Take regular expressions (one per line) from a file"), cl::value_desc("regex file"), cl::init(""), cl::cat(aRegexSourceOptions));
     47
     48
     49
     50ExecutionEngine * JIT_to_ExecutionEngine (llvm::Function * f) {
     51
     52    InitializeNativeTarget();
     53    InitializeNativeTargetAsmPrinter();
     54    InitializeNativeTargetAsmParser();
     55
     56    std::string errMessage;
     57    EngineBuilder builder(std::move(std::unique_ptr<Module>(f->getParent())));
     58    builder.setErrorStr(&errMessage);
     59    builder.setMCPU(sys::getHostCPUName());
     60
     61    //builder.setOptLevel(mMaxWhileDepth ? CodeGenOpt::Level::Less : CodeGenOpt::Level::None);
     62    ExecutionEngine * engine = builder.create();
     63    if (engine == nullptr) {
     64        throw std::runtime_error("Could not create ExecutionEngine: " + errMessage);
     65    }
     66    //engine->addGlobalMapping(cast<GlobalValue>(mPrintRegisterFunction), (void *)&wrapped_print_register);
     67    // engine->addGlobalMapping(externalFunction, proto->getFunctionPtr());
     68
     69    engine->finalizeObject();
     70    return engine;
     71}
    4072
    4173
     
    106138    if (CaseInsensitive) globalFlags |= re::CASE_INSENSITIVE_MODE_FLAG;
    107139   
    108     const auto llvm_codegen = icgrep::compile(encoding, regexVector, globalFlags);
    109     if (llvm_codegen.FunctionPointer) {
    110         GrepExecutor grepEngine = GrepExecutor(llvm_codegen.FunctionPointer);
     140   
     141    llvm::Function * llvm_codegen = icgrep::compile(encoding, regexVector, globalFlags);
     142   
     143    llvm::ExecutionEngine * engine = JIT_to_ExecutionEngine(llvm_codegen);
     144   
     145    void * functionPointer = engine->getPointerToFunction(llvm_codegen);
     146   
     147    if (functionPointer) {
     148        GrepExecutor grepEngine = GrepExecutor(functionPointer);
    111149        grepEngine.setCountOnlyOption(CountOnly);
    112150        grepEngine.setNormalizeLineBreaksOption(NormalizeLineBreaks);
     
    120158    }
    121159   
     160    //engine->freeMachineCodeForFunction(llvm_codegen); // This function only prints a "not supported" message. Reevaluate with LLVM 3.6.
     161    delete engine;
     162
    122163    return 0;
    123164}
Note: See TracChangeset for help on using the changeset viewer.