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/casefold.cpp

    r5026 r5033  
    1010#include <sstream>
    1111
     12#include <toolchain.h>
    1213#include <llvm/IR/Function.h>
    1314#include <llvm/IR/Module.h>
    1415#include <llvm/ExecutionEngine/ExecutionEngine.h>
    15 #include <llvm/ExecutionEngine/MCJIT.h>
    16 #include <llvm/IRReader/IRReader.h>
    1716#include <llvm/Support/CommandLine.h>
    18 #include <llvm/CodeGen/CommandFlags.h>
    19 #include <llvm/Support/SourceMgr.h>
    20 #include <llvm/Support/TargetSelect.h>
    21 #include <llvm/Support/Host.h>
    22 #include <llvm/Support/raw_ostream.h>
    23 
    2417#include <re/re_cc.h>
    2518#include <cc/cc_compiler.h>
     
    2821#include <IDISA/idisa_target.h>
    2922#include <kernels/casefold_pipeline.h>
    30 
    31 // Dynamic processor detection
    32 #define ISPC_LLVM_VERSION ISPC_LLVM_3_6
    33 #include <util/ispc.cpp>
    3423
    3524#include <utf_encoding.h>
     
    4534static cl::list<std::string> inputFiles(cl::Positional, cl::desc("<input file ...>"), cl::OneOrMore);
    4635
    47 
    48 static cl::OptionCategory cMachineCodeOptimization("Machine Code Optimizations", "These options control back-end compilier optimization levels.");
    49 
    50 static cl::opt<char> OptLevel("O", cl::desc("Optimization level. [-O0, -O1, -O2, or -O3] (default = '-O0')"),
    51                               cl::cat(cMachineCodeOptimization), cl::Prefix, cl::ZeroOrMore, cl::init('0'));
    52 
    53 
    54 //
    55 //  Functions taken from toolchain.cpp and modified for casefold
    56 //  JIT_t_ExecutionEngine : remove object cache
    57 //  icgrep_Linking:   unneeded?
    58 //  all others: definitely unneeded
    59 //
    60 
    61 ExecutionEngine * JIT_to_ExecutionEngine (Module * m) {
    62 
    63     InitializeNativeTarget();
    64     InitializeNativeTargetAsmPrinter();
    65     InitializeNativeTargetAsmParser();
    66 
    67     PassRegistry * Registry = PassRegistry::getPassRegistry();
    68     initializeCore(*Registry);
    69     initializeCodeGen(*Registry);
    70     initializeLowerIntrinsicsPass(*Registry);
    71 
    72     std::string errMessage;
    73     EngineBuilder builder(std::move(std::unique_ptr<Module>(m)));
    74     builder.setErrorStr(&errMessage);
    75     builder.setMCPU(sys::getHostCPUName());
    76     CodeGenOpt::Level optLevel = CodeGenOpt::Level::None;
    77     switch (OptLevel) {
    78         case '0': optLevel = CodeGenOpt::None; break;
    79         case '1': optLevel = CodeGenOpt::Less; break;
    80         case '2': optLevel = CodeGenOpt::Default; break;
    81         case '3': optLevel = CodeGenOpt::Aggressive; break;
    82         default: errs() << OptLevel << " is an invalid optimization level.\n";
    83     }
    84     builder.setOptLevel(optLevel);
    85 
    86     if ((strncmp(lGetSystemISA(), "avx2", 4) == 0)) {
    87             std::vector<std::string> attrs;
    88             attrs.push_back("avx2");
    89             builder.setMAttrs(attrs);
    90     }
    91 
    92     // builder.selectTarget();
    93 
    94     //builder.setOptLevel(mMaxWhileDepth ? CodeGenOpt::Level::Less : CodeGenOpt::Level::None);
    95     ExecutionEngine * engine = builder.create();
    96     if (engine == nullptr) {
    97         throw std::runtime_error("Could not create ExecutionEngine: " + errMessage);
    98     }
    99     return engine;
    100 }
    10136
    10237
     
    13267    Module * M = new Module("casefold", getGlobalContext());
    13368   
    134     IDISA::IDISA_Builder * idb = GetIDISA_Builder(M);
     69    IDISA::IDISA_Builder * idb = IDISA::GetIDISA_Builder(M);
    13570
    13671    kernel::PipelineBuilder pipelineBuilder(M, idb);
Note: See TracChangeset for help on using the changeset viewer.