Ignore:
Timestamp:
May 6, 2016, 3:28:07 PM (3 years ago)
Author:
cameron
Message:

Refactor: move grep-specific code out of toolchain

File:
1 edited

Legend:

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

    r5026 r5033  
    1919
    2020#include <llvm/Support/CommandLine.h>
    21 #include <llvm/CodeGen/CommandFlags.h>
    22 #include <llvm/Support/SourceMgr.h>
    23 #include <llvm/Support/TargetSelect.h>
    24 #include <llvm/Support/Host.h>
    25 #include <llvm/Support/raw_ostream.h>
    26 
     21
     22#include <toolchain.h>
    2723#include <re/re_cc.h>
    2824#include <cc/cc_compiler.h>
     
    3228#include <kernels/u8u16_pipeline.h>
    3329
    34 // Dynamic processor detection
    35 #define ISPC_LLVM_VERSION ISPC_LLVM_3_6
    36 #include <util/ispc.cpp>
    37 
    3830#include <utf_encoding.h>
    3931
     
    4840static cl::list<std::string> inputFiles(cl::Positional, cl::desc("<input file ...>"), cl::OneOrMore);
    4941
    50 static cl::OptionCategory eIRDumpOptions("LLVM IR Dump Options", "These options control dumping of LLVM IR.");
    51 static cl::opt<bool> DumpGeneratedIR("dump-generated-IR", cl::init(false), cl::desc("Print LLVM IR generated by Pablo Compiler."), cl::cat(eIRDumpOptions));
    52 
    53 static cl::OptionCategory cMachineCodeOptimization("Machine Code Optimizations", "These options control back-end compilier optimization levels.");
    54 
    55 static cl::opt<char> OptLevel("O", cl::desc("Optimization level. [-O0, -O1, -O2, or -O3] (default = '-O0')"),
    56                               cl::cat(cMachineCodeOptimization), cl::Prefix, cl::ZeroOrMore, cl::init('0'));
    57 
    58 
    59 //
    60 //  Functions taken from toolchain.cpp and modified for casefold
    61 //  JIT_t_ExecutionEngine : remove object cache
    62 //  icgrep_Linking:   unneeded?
    63 //  all others: definitely unneeded
    64 //
    65 
    66 ExecutionEngine * JIT_to_ExecutionEngine (Module * m) {
    67 
    68     InitializeNativeTarget();
    69     InitializeNativeTargetAsmPrinter();
    70     InitializeNativeTargetAsmParser();
    71 
    72     PassRegistry * Registry = PassRegistry::getPassRegistry();
    73     initializeCore(*Registry);
    74     initializeCodeGen(*Registry);
    75     initializeLowerIntrinsicsPass(*Registry);
    76 
    77     std::string errMessage;
    78     EngineBuilder builder(std::move(std::unique_ptr<Module>(m)));
    79     builder.setErrorStr(&errMessage);
    80     builder.setMCPU(sys::getHostCPUName());
    81     CodeGenOpt::Level optLevel = CodeGenOpt::Level::None;
    82     switch (OptLevel) {
    83         case '0': optLevel = CodeGenOpt::None; break;
    84         case '1': optLevel = CodeGenOpt::Less; break;
    85         case '2': optLevel = CodeGenOpt::Default; break;
    86         case '3': optLevel = CodeGenOpt::Aggressive; break;
    87         default: errs() << OptLevel << " is an invalid optimization level.\n";
    88     }
    89     builder.setOptLevel(optLevel);
    90 
    91     if ((strncmp(lGetSystemISA(), "avx2", 4) == 0)) {
    92             std::vector<std::string> attrs;
    93             attrs.push_back("avx2");
    94             builder.setMAttrs(attrs);
    95     }
    96 
    97     // builder.selectTarget();
    98 
    99     //builder.setOptLevel(mMaxWhileDepth ? CodeGenOpt::Level::Less : CodeGenOpt::Level::None);
    100     ExecutionEngine * engine = builder.create();
    101     if (engine == nullptr) {
    102         throw std::runtime_error("Could not create ExecutionEngine: " + errMessage);
    103     }
    104     return engine;
    105 }
    10642
    10743
     
    283219    Module * M = new Module("u8u16", getGlobalContext());
    284220   
    285     IDISA::IDISA_Builder * idb = GetIDISA_Builder(M);
     221    IDISA::IDISA_Builder * idb = IDISA::GetIDISA_Builder(M);
    286222
    287223    kernel::PipelineBuilder pipelineBuilder(M, idb);
     
    295231
    296232    llvm::Function * main_IR = pipelineBuilder.ExecuteKernels();
    297    
    298     if (DumpGeneratedIR) {
    299         M->dump();
    300     }
    301233   
    302234    verifyModule(*M, &dbgs());
Note: See TracChangeset for help on using the changeset viewer.