Ignore:
Timestamp:
Apr 25, 2017, 2:33:31 PM (2 years ago)
Author:
nmedfort
Message:

Changes towards separate compilation

Location:
icGREP/icgrep-devel/icgrep/toolchain
Files:
1 added
1 moved

Legend:

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

    r5424 r5425  
    66
    77#include "toolchain.h"
     8#include <IR_Gen/idisa_target.h>
    89#include <llvm/CodeGen/CommandFlags.h>             // for InitTargetOptionsF...
    910#include <llvm/ExecutionEngine/ExecutionEngine.h>  // for EngineBuilder
     
    2627#include <llvm/Transforms/Utils/Local.h>
    2728#include <llvm/IR/Module.h>
    28 #include <kernels/object_cache.h>
    29 #include <kernels/pipeline.h>
     29#include <toolchain/object_cache.h>
     30#include <toolchain/pipeline.h>
    3031#include <kernels/kernel.h>
    3132#include <sys/stat.h>
     
    7172bool EnableCycleCounter;
    7273#ifndef NDEBUG
    73 #define DEFAULT_TO_TRUE_IN_DEBUG_MODE true
     74#define IN_DEBUG_MODE true
    7475#else
    75 #define DEFAULT_TO_TRUE_IN_DEBUG_MODE false
     76#define IN_DEBUG_MODE false
    7677#endif
    7778
     
    8081static cl::opt<int, true> BufferSegmentsOption("buffer-segments", cl::location(BufferSegments), cl::desc("Buffer Segments"), cl::value_desc("positive integer"), cl::init(1));
    8182static cl::opt<int, true> ThreadNumOption("thread-num", cl::location(ThreadNum), cl::desc("Number of threads used for segment pipeline parallel"), cl::value_desc("positive integer"), cl::init(2));
    82 static cl::opt<bool, true> EnableAssertsOption("ea", cl::location(EnableAsserts), cl::desc("Enable Asserts"), cl::init(DEFAULT_TO_TRUE_IN_DEBUG_MODE));
     83static cl::opt<bool, true> EnableAssertsOption("ea", cl::location(EnableAsserts), cl::desc("Enable Asserts"), cl::init(IN_DEBUG_MODE));
    8384static cl::opt<bool, true> EnableCycleCountOption("ShowKernelCycles", cl::location(EnableCycleCounter), cl::desc("Count and report CPU cycles per kernel"), cl::init(false), cl::cat(CodeGenOptions));
    8485
     
    159160}
    160161
    161 ParabixDriver::ParabixDriver(IDISA::IDISA_Builder * iBuilder)
    162 : iBuilder(iBuilder)
    163 , mMainModule(iBuilder->getModule())
     162ParabixDriver::ParabixDriver(std::string && moduleName)
     163: mContext(new llvm::LLVMContext())
     164, mMainModule(new Module(moduleName, *mContext))
     165, iBuilder(nullptr)
    164166, mTarget(nullptr)
    165167, mEngine(nullptr)
    166 , mCache(nullptr)
    167 {
     168, mCache(nullptr) {
     169
    168170    InitializeNativeTarget();
    169171    InitializeNativeTargetAsmPrinter();
     
    182184
    183185    builder.setTargetOptions(opts);
    184     builder.setVerifyModules(true);
     186    builder.setVerifyModules(IN_DEBUG_MODE);
    185187    CodeGenOpt::Level optLevel = CodeGenOpt::Level::None;
    186188    switch (codegen::OptLevel) {
     
    194196
    195197    setAllFeatures(builder);
    196 
    197198    mEngine = builder.create();
    198199    if (mEngine == nullptr) {
     
    209210        mEngine->setObjectCache(mCache);
    210211    }
     212
     213    mMainModule->setTargetTriple(mTarget->getTargetTriple().getTriple());
     214
     215    iBuilder.reset(IDISA::GetIDISA_Builder(mMainModule));
     216    iBuilder->setDriver(this);
    211217}
    212218
    213219ExternalFileBuffer * ParabixDriver::addExternalBuffer(std::unique_ptr<ExternalFileBuffer> b, Value * externalBuf) {
    214     ExternalFileBuffer * rawBuf = b.get();
    215220    mOwnedBuffers.push_back(std::move(b));
     221    ExternalFileBuffer * rawBuf = cast<ExternalFileBuffer>(mOwnedBuffers.back().get());
    216222    rawBuf->setStreamSetBuffer(externalBuf);
    217223    return rawBuf;
     
    252258    }
    253259    #endif
     260
    254261    // note: instantiation of all kernels must occur prior to initialization
    255262    for (const auto & k : mPipeline) {
     
    275282}
    276283
    277 void ParabixDriver::addExternalLink(kernel::KernelBuilder & kb, llvm::StringRef name, FunctionType * type, void * functionPtr) const {
    278     assert ("addKernelCall or makeKernelCall must be called before addExternalLink" && (kb.getModule() != nullptr));
    279     mEngine->addGlobalMapping(cast<Function>(kb.getModule()->getOrInsertFunction(name, type)), functionPtr);
    280 }
    281 
    282 uint64_t file_size(const uint32_t fd) {
    283     struct stat st;
    284     if (LLVM_UNLIKELY(fstat(fd, &st) != 0)) {
    285         st.st_size = 0;
    286     }
    287     return st.st_size;
     284Function * ParabixDriver::LinkFunction(Module * mod, llvm::StringRef name, FunctionType * type, void * functionPtr) const {
     285    assert ("addKernelCall or makeKernelCall must be called before LinkFunction" && (mod != nullptr));
     286    Function * f = cast<Function>(mod->getOrInsertFunction(name, type));
     287    mEngine->addGlobalMapping(f, functionPtr);
     288    return f;
    288289}
    289290
     
    328329    }
    329330    #endif
    330 
    331     FunctionType * fileSizeType = FunctionType::get(iBuilder->getInt64Ty(), { iBuilder->getInt32Ty() });
    332     mEngine->addGlobalMapping(cast<Function>(mMainModule->getOrInsertFunction("file_size", fileSizeType)), (void *)&file_size);
    333331
    334332    PM.run(*m);
Note: See TracChangeset for help on using the changeset viewer.