Ignore:
Timestamp:
Dec 26, 2015, 12:09:11 PM (3 years ago)
Author:
cameron
Message:

Dynamic generation of s2p code

File:
1 edited

Legend:

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

    r4871 r4900  
    2121#include <llvm/Support/SourceMgr.h>
    2222#include <llvm/Support/CommandLine.h>
     23#include <llvm/Support/Debug.h>
    2324#include <llvm/Support/TargetSelect.h>
    2425#include <llvm/Support/Host.h>
     26#include <llvm/IR/Verifier.h>
     27
     28#include <IDISA/s2p_gen.h>
    2529
    2630#include <re/re_re.h>
     
    136140    llvm::Function * icgrep_IR = nullptr;
    137141   
     142    Module * M = new Module("grepcode", getGlobalContext());
     143   
     144    IDISA::IDISA_Builder * idb = GetNativeIDISA_Builder(M, VectorType::get(IntegerType::get(getGlobalContext(), 64), BLOCK_SIZE/64));
     145   
     146    gen_s2p_function(M, idb);
     147
     148   
    138149    if (IRFileName == "") {       
    139150        re::RE * re_ast = get_icgrep_RE();
     
    143154
    144155        pablo_function_passes(function);
    145         pablo::PabloCompiler pablo_compiler(VectorType::get(IntegerType::get(getGlobalContext(), 64), BLOCK_SIZE/64));
     156       
     157       
     158        pablo::PabloCompiler pablo_compiler(M, idb);
    146159        try {
    147160            icgrep_IR = pablo_compiler.compile(function);
     
    157170        firstInputFile = 0;  // No regexp arguments; first positional argument is a file to process.
    158171        SMDiagnostic ParseErr;
    159         Module * M = parseIRFile(IRFileName, ParseErr, getGlobalContext()).release();
     172        M = parseIRFile(IRFileName, ParseErr, getGlobalContext()).release();
    160173        if (!M) {
    161174            throw std::runtime_error("Error in Parsing IR File " + IRFileName);
     
    163176        icgrep_IR = M->getFunction("process_block");
    164177    }
    165    
    166     llvm::ExecutionEngine * engine = JIT_to_ExecutionEngine(icgrep_IR);
    167    
    168     icgrep_Linking(icgrep_IR->getParent(), engine);
     178    llvm::Function * s2p_IR = M->getFunction("s2p_block");
     179
     180    if (s2p_IR == nullptr) {
     181        std::cerr << "No s2p_IR!\n";
     182        exit(1);
     183    }
     184   
     185    llvm::ExecutionEngine * engine = JIT_to_ExecutionEngine(M);
     186   
     187    icgrep_Linking(M, engine);
     188    verifyModule(*M, &dbgs());
    169189   
    170190    // Ensure everything is ready to go.
     
    172192   
    173193    // TODO getPointerToFunction() is deprecated. Investigate getFunctionAddress(string name) instead.
    174     void * icgrep_init_carry_ptr = engine->getPointerToFunction(icgrep_IR->getParent()->getFunction("process_block_initialize_carries"));
     194    void * icgrep_init_carry_ptr = engine->getPointerToFunction(M->getFunction("process_block_initialize_carries"));
    175195    void * icgrep_MCptr = engine->getPointerToFunction(icgrep_IR);
     196    void * s2p_MCptr = engine->getPointerToFunction(s2p_IR);
     197    if (s2p_MCptr == nullptr) {
     198        std::cerr << "No s2p_MCptr!\n";
     199        exit(1);
     200    }
    176201   
    177202    if (icgrep_MCptr) {
    178         GrepExecutor grepEngine(icgrep_init_carry_ptr, icgrep_MCptr);
     203        GrepExecutor grepEngine(s2p_MCptr, icgrep_init_carry_ptr, icgrep_MCptr);
    179204        grepEngine.setCountOnlyOption(CountOnly);
    180205        grepEngine.setNormalizeLineBreaksOption(NormalizeLineBreaks);
Note: See TracChangeset for help on using the changeset viewer.