Ignore:
Timestamp:
May 6, 2017, 4:05:05 PM (2 years ago)
Author:
nmedfort
Message:

Continued refactoring work.

Location:
icGREP/icgrep-devel/icgrep/toolchain
Files:
6 edited

Legend:

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

    r5431 r5435  
    2222// file exists.
    2323//
    24 ParabixObjectCache::ParabixObjectCache(const std::string &dir): mCachePath(dir) {}
    2524
    26 ParabixObjectCache::ParabixObjectCache() {
    27     // $HOME/.cache/icgrep
    28     // TODO use path::user_cache_directory once we have llvm >= 3.7.
    29     sys::path::home_directory(mCachePath);
    30     sys::path::append(mCachePath, ".cache", "parabix");
     25#define MONTH_1 \
     26    ((__DATE__ [0] == 'O' || __DATE__ [0] == 'N' || __DATE__ [0] == 'D') ? '1' : '0')
     27#define MONTH_2 \
     28    (__DATE__ [2] == 'n' ? (__DATE__ [1] == 'a' ? '1' : '6') \
     29    : __DATE__ [2] == 'b' ? '2' \
     30    : __DATE__ [2] == 'r' ? (__DATE__ [0] == 'M' ? '3' : '4') \
     31    : __DATE__ [2] == 'y' ? '5' \
     32    : __DATE__ [2] == 'l' ? '7' \
     33    : __DATE__ [2] == 'g' ? '8' \
     34    : __DATE__ [2] == 'p' ? '9' \
     35    : __DATE__ [2] == 't' ? '0' \
     36    : __DATE__ [2] == 'v' ? '1' : '2')
     37#define DAY_1 (__DATE__[4] == ' ' ? '0' : __DATE__[4])
     38#define DAY_2 (__DATE__[5])
     39#define YEAR_1 (__DATE__[9])
     40#define YEAR_2 (__DATE__[10])
     41#define HOUR_1 (__TIME__[0])
     42#define HOUR_2 (__TIME__[1])
     43#define MINUTE_1 (__TIME__[3])
     44#define MINUTE_2 (__TIME__[4])
     45#define SECOND_1 (__TIME__[6])
     46#define SECOND_2 (__TIME__[7])
    3147
    32     const std::string Version = PARABIX_VERSION;
    33     const std::string Date = __DATE__;
    34     const std::string Time = __TIME__;
    35     const std::string DateStamp = Date.substr(7) + Date.substr(0, 3) + (Date[4] == ' ' ? Date.substr(5, 1) : Date.substr(4, 2));
    36     mCachePrefix = Version + "_" + DateStamp + "@" + Time;
    37 }
     48const static auto CACHE_PREFIX = PARABIX_VERSION +
     49                          std::string{'@',
     50                          MONTH_1, MONTH_2, DAY_1, DAY_2, YEAR_1, YEAR_2,
     51                          HOUR_1, HOUR_2, MINUTE_1, MINUTE_2, SECOND_1, SECOND_2,
     52                          '_'};
    3853
    39 bool ParabixObjectCache::loadCachedObjectFile(kernel::KernelBuilder * const kernel) {
     54bool ParabixObjectCache::loadCachedObjectFile(kernel::Kernel * const kernel) {
    4055    if (LLVM_LIKELY(kernel->isCachable())) {
    4156
     
    5772        // No, check for an existing cache file.
    5873        Path objectName(mCachePath);
    59         sys::path::append(objectName, mCachePrefix + moduleId + ".o");
     74        sys::path::append(objectName, CACHE_PREFIX);
     75        objectName.append(moduleId);
     76        objectName.append(".o");
     77
    6078        auto objectBuffer = MemoryBuffer::getFile(objectName.c_str(), -1, false);
    6179        if (objectBuffer) {
     
    91109
    92110        Path objectName(mCachePath);
    93         sys::path::append(objectName, mCachePrefix + moduleId + ".o");
     111        sys::path::append(objectName, CACHE_PREFIX);
     112        objectName.append(moduleId);
     113        objectName.append(".o");
    94114
    95115        if (LLVM_LIKELY(!mCachePath.empty())) {
     
    102122        outfile.close();
    103123
    104         // Check for a kernel signature.
     124        // If this kernel has a signature, write it.
    105125        const auto sig = mKernelSignatureMap.find(moduleId);
    106126        if (LLVM_UNLIKELY(sig != mKernelSignatureMap.end())) {
     
    114134
    115135/*  May need this.
    116  
     136
    117137void ParabixObjectCache::removeCacheFile(std::string ModuleID) {
    118138    Path CacheName(CacheDir);
     
    134154}
    135155
     156inline ParabixObjectCache::Path ParabixObjectCache::getDefaultPath() {
     157    // $HOME/.cache/parabix/
     158    Path cachePath;
     159    // TODO use path::user_cache_directory once we have llvm >= 3.7.
     160    sys::path::home_directory(cachePath);
     161    sys::path::append(cachePath, ".cache", "parabix");
     162    return cachePath;
     163}
     164
     165ParabixObjectCache::ParabixObjectCache()
     166: mCachePath(std::move(getDefaultPath())) {
     167
     168}
     169
     170ParabixObjectCache::ParabixObjectCache(const std::string & dir)
     171: mCachePath(dir) {
     172
     173}
  • icGREP/icgrep-devel/icgrep/toolchain/object_cache.h

    r5431 r5435  
    1717namespace llvm { class MemoryBuffer; }
    1818namespace llvm { class MemoryBufferRef; }
    19 namespace kernel { class KernelBuilder; }
     19namespace kernel { class Kernel; }
    2020
    2121// The ParabixObjectCache is a two-level cache compatible with the requirements
     
    3535    template <typename K, typename V>
    3636    using Map = boost::container::flat_map<K, V>;
    37     using CacheEntry = std::pair<kernel::KernelBuilder *, std::unique_ptr<llvm::MemoryBuffer>>;
     37    using CacheEntry = std::pair<kernel::Kernel *, std::unique_ptr<llvm::MemoryBuffer>>;
    3838    using CacheMap = Map<llvm::Module *, CacheEntry>;
    3939public:
    40 
    41 //    enum Status {
    42 //        Failed
    43 //        , Succeeded
    44 //        , ObjectFileLocked
    45 //    };
    46 
    47     ParabixObjectCache(const std::string &dir);
    4840    ParabixObjectCache();
    49     bool loadCachedObjectFile(kernel::KernelBuilder * const kernel);
     41    ParabixObjectCache(const std::string & dir);
     42    bool loadCachedObjectFile(kernel::Kernel * const kernel);
    5043    void notifyObjectCompiled(const llvm::Module *M, llvm::MemoryBufferRef Obj) override;
    5144    std::unique_ptr<llvm::MemoryBuffer> getObject(const llvm::Module * M) override;
     45protected:
     46    static Path getDefaultPath();
    5247private:
    53 //    CacheMap        mCachedObject;
    54 
    5548    Map<std::string, std::string>                           mKernelSignatureMap;
    5649    Map<std::string, std::unique_ptr<llvm::MemoryBuffer>>   mCachedObjectMap;
    57     Path                                                    mCachePath;
    58     Path                                                    mCachePrefix;
     50    const Path                                              mCachePath;
    5951};
    6052
  • icGREP/icgrep-devel/icgrep/toolchain/pipeline.cpp

    r5425 r5435  
    2222using FlatSet = boost::container::flat_set<Value>;
    2323
    24 Function * makeThreadFunction(std::unique_ptr<IDISA::IDISA_Builder> & b, const std::string & name) {
     24Function * makeThreadFunction(IDISA::IDISA_Builder * const b, const std::string & name) {
    2525    Function * const f = Function::Create(FunctionType::get(b->getVoidTy(), {b->getVoidPtrTy()}, false), Function::InternalLinkage, name, b->getModule());
    2626    f->setCallingConv(CallingConv::C);
     
    3838 * fashion such that processing of segment S_i by the full pipeline is carried out by thread i mod T.
    3939 ** ------------------------------------------------------------------------------------------------------------- */
    40 void generateSegmentParallelPipeline(std::unique_ptr<IDISA::IDISA_Builder> & iBuilder, const std::vector<KernelBuilder *> & kernels) {
     40void generateSegmentParallelPipeline(IDISA::IDISA_Builder * const iBuilder, const std::vector<Kernel *> & kernels) {
    4141
    4242    const unsigned n = kernels.size();
     
    101101        iBuilder->SetInsertPoint(segmentWait);
    102102        const unsigned waitIdx = codegen::DebugOptionIsSet(codegen::SerializeThreads) ? (n - 1) : k;
     103        kernels[waitIdx]->setBuilder(iBuilder);
    103104        Value * const processedSegmentCount = kernels[waitIdx]->acquireLogicalSegmentNo();
     105
     106
    104107        assert (processedSegmentCount->getType() == segNo->getType());
    105108        Value * const ready = iBuilder->CreateICmpEQ(segNo, processedSegmentCount);
     
    113116
    114117            iBuilder->SetInsertPoint(completionTest);
    115             iBuilder->CreateCondBr(kernel->getTerminationSignal(), exitBlock, segmentLoopBody);
     118
     119            kernel->setBuilder(iBuilder);
     120            Value * terminationSignal = kernel->getTerminationSignal();
     121
     122            iBuilder->CreateCondBr(terminationSignal, exitBlock, segmentLoopBody);
    116123            iBuilder->SetInsertPoint(exitBlock);
    117124            // Ensure that the next thread will also exit.
     
    130137        }
    131138
     139        kernel->setBuilder(iBuilder);
    132140        kernel->createDoSegmentCall(args);       
    133141        if (!kernel->hasNoTerminateAttribute()) {
     
    137145        const auto & outputs = kernel->getStreamOutputs();
    138146        for (unsigned i = 0; i < outputs.size(); ++i) {
     147            kernel->setBuilder(iBuilder);
    139148            Value * const produced = kernel->getProducedItemCount(outputs[i].name, terminated);
    140149            const StreamSetBuffer * const buf = kernel->getStreamSetOutputBuffer(i);
     
    143152        }
    144153        for (unsigned i = 0; i < inputs.size(); ++i) {
     154            kernel->setBuilder(iBuilder);
    145155            Value * const processedItemCount = kernel->getProcessedItemCount(inputs[i].name);
    146             const StreamSetBuffer * const buf = kernel->getStreamSetInputBuffer(i);
     156            const StreamSetBuffer * const buf = kernel->getStreamSetInputBuffer(i);           
    147157            auto f = consumedPos.find(buf);
    148158            if (f == consumedPos.end()) {
     
    153163            }
    154164        }
    155 
     165        kernel->setBuilder(iBuilder);
    156166        kernel->releaseLogicalSegmentNo(nextSegNo);
    157167    }
     
    162172    for (const auto consumed : consumedPos) {
    163173        const StreamSetBuffer * const buf = consumed.first;
    164         KernelBuilder * k = buf->getProducer();
    165         const auto & outputs = k->getStreamSetOutputBuffers();
     174        Kernel * kernel = buf->getProducer();
     175        const auto & outputs = kernel->getStreamSetOutputBuffers();
    166176        for (unsigned i = 0; i < outputs.size(); ++i) {
    167177            if (outputs[i] == buf) {
    168                 k->setConsumedItemCount(k->getStreamOutputs()[i].name, consumed.second);
     178                kernel->setBuilder(iBuilder);
     179                kernel->setConsumedItemCount(kernel->getStreamOutputs()[i].name, consumed.second);
    169180                break;
    170181            }
     
    210221
    211222    for (unsigned i = 0; i < n; ++i) {
    212         kernels[i]->releaseLogicalSegmentNo(iBuilder->getSize(0));
     223        auto kernel = kernels[i];
     224        kernel->setBuilder(iBuilder);
     225        kernel->releaseLogicalSegmentNo(iBuilder->getSize(0));
    213226    }
    214227
     
    243256 * @brief generateParallelPipeline
    244257 ** ------------------------------------------------------------------------------------------------------------- */
    245 void generateParallelPipeline(std::unique_ptr<IDISA::IDISA_Builder> & iBuilder, const std::vector<KernelBuilder *> &kernels) {
     258void generateParallelPipeline(IDISA::IDISA_Builder * const iBuilder, const std::vector<Kernel *> &kernels) {
    246259
    247260    Module * const m = iBuilder->getModule();
     
    278291
    279292    for (auto & kernel : kernels) {
     293        kernel->setBuilder(iBuilder);
    280294        kernel->releaseLogicalSegmentNo(iBuilder->getSize(0));
    281295    }
     
    372386        Value * inputWaitCond = iBuilder->getTrue();
    373387        for (unsigned k : kernelSet) {
    374             producerSegNo[k] = kernels[k]->acquireLogicalSegmentNo();
     388            Kernel * kernel = kernels[k];
     389            kernel->setBuilder(iBuilder);
     390            producerSegNo[k] = kernel->acquireLogicalSegmentNo();
    375391            assert (producerSegNo[k]->getType() == segNo->getType());
    376392            inputWaitCond = iBuilder->CreateAnd(inputWaitCond, iBuilder->CreateICmpULT(segNo, producerSegNo[k]));
     
    429445        iBuilder->CreatePThreadJoinCall(threadId, status);
    430446    }
    431 
    432447}
    433448
     
    435450 * @brief generatePipelineLoop
    436451 ** ------------------------------------------------------------------------------------------------------------- */
    437 void generatePipelineLoop(std::unique_ptr<IDISA::IDISA_Builder> & iBuilder, const std::vector<KernelBuilder *> & kernels) {
     452void generatePipelineLoop(IDISA::IDISA_Builder * const iBuilder, const std::vector<Kernel *> & kernels) {
    438453
    439454    BasicBlock * entryBlock = iBuilder->GetInsertBlock();
     
    477492        }
    478493
     494        kernel->setBuilder(iBuilder);
    479495        kernel->createDoSegmentCall(args);
    480496        if (!kernel->hasNoTerminateAttribute()) {
    481             terminated = iBuilder->CreateOr(terminated, kernel->getTerminationSignal());
     497            Value * terminatedSignal = kernel->getTerminationSignal();
     498            terminated = iBuilder->CreateOr(terminated, terminatedSignal);
     499            kernel->setBuilder(iBuilder);
    482500        }
    483501        for (unsigned i = 0; i < outputs.size(); ++i) {
     
    489507
    490508        for (unsigned i = 0; i < inputs.size(); ++i) {
     509            kernel->setBuilder(iBuilder);
    491510            Value * const processedItemCount = kernel->getProcessedItemCount(inputs[i].name);
    492511            const StreamSetBuffer * const buf = kernel->getStreamSetInputBuffer(i);
     512
    493513            auto f = consumedPos.find(buf);
    494514            if (f == consumedPos.end()) {
     
    505525            cycleCountStart = cycleCountEnd;
    506526        }
     527
     528        kernel->setBuilder(iBuilder);
    507529        Value * const segNo = kernel->acquireLogicalSegmentNo();
    508         kernel->releaseLogicalSegmentNo(iBuilder->CreateAdd(segNo, iBuilder->getSize(1)));
     530        Value * nextSegNo = iBuilder->CreateAdd(segNo, iBuilder->getSize(1));
     531        kernel->releaseLogicalSegmentNo(nextSegNo);
    509532    }
    510533
    511534    for (const auto consumed : consumedPos) {
    512535        const StreamSetBuffer * const buf = consumed.first;
    513         KernelBuilder * k = buf->getProducer();
     536        Kernel * k = buf->getProducer();
    514537        const auto & outputs = k->getStreamSetOutputBuffers();
    515538        for (unsigned i = 0; i < outputs.size(); ++i) {
    516539            if (outputs[i] == buf) {
     540                k->setBuilder(iBuilder);
    517541                k->setConsumedItemCount(k->getStreamOutputs()[i].name, consumed.second);
    518542                break;
     
    533557            Value * fCycles = iBuilder->CreateUIToFP(cycles, iBuilder->getDoubleTy());
    534558            std::string formatString = kernel->getName() + ": %7.2e items processed; %7.2e CPU cycles,  %6.2f cycles per item.\n";
    535             Value * stringPtr = iBuilder->CreatePointerCast(iBuilder->CreateGlobalString(formatString.c_str()), iBuilder->getInt8PtrTy());
     559            Value * stringPtr = iBuilder->CreatePointerCast(iBuilder->GetString(formatString), iBuilder->getInt8PtrTy());
    536560            iBuilder->CreateCall(iBuilder->GetDprintf(), {iBuilder->getInt32(2), stringPtr, fItems, fCycles, iBuilder->CreateFDiv(fCycles, fItems)});
    537561        }
  • icGREP/icgrep-devel/icgrep/toolchain/pipeline.h

    r5425 r5435  
    1010
    1111namespace IDISA { class IDISA_Builder; }
    12 namespace kernel { class KernelBuilder; }
     12namespace kernel { class Kernel; }
    1313
    14 void generateSegmentParallelPipeline(std::unique_ptr<IDISA::IDISA_Builder> & iBuilder, const std::vector<kernel::KernelBuilder *> & kernels);
    15 void generatePipelineLoop(std::unique_ptr<IDISA::IDISA_Builder> & iBuilder, const std::vector<kernel::KernelBuilder *> & kernels);
    16 void generateParallelPipeline(std::unique_ptr<IDISA::IDISA_Builder> &iBuilder, const std::vector<kernel::KernelBuilder *> & kernels);
     14void generateSegmentParallelPipeline(IDISA::IDISA_Builder * const iBuilder, const std::vector<kernel::Kernel *> & kernels);
     15void generatePipelineLoop(IDISA::IDISA_Builder * const iBuilder, const std::vector<kernel::Kernel *> & kernels);
     16void generateParallelPipeline(IDISA::IDISA_Builder * const iBuilder, const std::vector<kernel::Kernel *> & kernels);
    1717
    1818#endif // PIPELINE_H
  • icGREP/icgrep-devel/icgrep/toolchain/toolchain.cpp

    r5431 r5435  
    3131#include <kernels/kernel.h>
    3232#include <sys/stat.h>
     33#include <thread>
     34#include <boost/lockfree/queue.hpp>
    3335
    3436using namespace llvm;
     
    187189
    188190StreamSetBuffer * ParabixDriver::addBuffer(std::unique_ptr<StreamSetBuffer> b) {
    189     b->allocateBuffer(iBuilder.get());
     191    b->allocateBuffer(iBuilder);
    190192    mOwnedBuffers.emplace_back(std::move(b));
    191193    return mOwnedBuffers.back().get();
    192194}
    193195
    194 kernel::KernelBuilder * ParabixDriver::addKernelInstance(std::unique_ptr<kernel::KernelBuilder> kb) {
    195     kb->setBuilder(iBuilder.get());
     196kernel::Kernel * ParabixDriver::addKernelInstance(std::unique_ptr<kernel::Kernel> kb) {
    196197    mOwnedKernels.emplace_back(std::move(kb));
    197198    return mOwnedKernels.back().get();
    198199}
    199200
    200 void ParabixDriver::addKernelCall(kernel::KernelBuilder & kb, const std::vector<parabix::StreamSetBuffer *> & inputs, const std::vector<parabix::StreamSetBuffer *> & outputs) {
     201void ParabixDriver::addKernelCall(kernel::Kernel & kb, const std::vector<parabix::StreamSetBuffer *> & inputs, const std::vector<parabix::StreamSetBuffer *> & outputs) {
    201202    assert ("addKernelCall or makeKernelCall was already run on this kernel." && (kb.getModule() == nullptr));
    202203    mPipeline.emplace_back(&kb);
     204    kb.setBuilder(iBuilder.get());
    203205    kb.createKernelStub(inputs, outputs);
    204206}
    205207
    206 void ParabixDriver::makeKernelCall(kernel::KernelBuilder * kb, const std::vector<parabix::StreamSetBuffer *> & inputs, const std::vector<parabix::StreamSetBuffer *> & outputs) {
     208void ParabixDriver::makeKernelCall(kernel::Kernel * kb, const std::vector<parabix::StreamSetBuffer *> & inputs, const std::vector<parabix::StreamSetBuffer *> & outputs) {
    207209    assert ("addKernelCall or makeKernelCall was already run on this kernel." && (kb->getModule() == nullptr));
    208210    mPipeline.emplace_back(kb);
     211    kb->setBuilder(iBuilder.get());
    209212    kb->createKernelStub(inputs, outputs);
    210213}
     
    215218        report_fatal_error("Pipeline must contain at least one kernel");
    216219    } else {
    217         boost::container::flat_set<kernel::KernelBuilder *> K(mPipeline.begin(), mPipeline.end());
     220        boost::container::flat_set<kernel::Kernel *> K(mPipeline.begin(), mPipeline.end());
    218221        if (LLVM_UNLIKELY(K.size() != mPipeline.size())) {
    219222            report_fatal_error("Kernel definitions can only occur once in the pipeline");
     
    224227    // note: instantiation of all kernels must occur prior to initialization
    225228    for (const auto & k : mPipeline) {
     229        k->setBuilder(iBuilder.get());
    226230        k->addKernelDeclarations();
    227231    }
    228232    for (const auto & k : mPipeline) {
     233        k->setBuilder(iBuilder.get());
    229234        k->createInstance();
    230235    }
    231236    for (const auto & k : mPipeline) {
     237        k->setBuilder(iBuilder.get());
    232238        k->initializeInstance();
    233239    }
    234240    if (codegen::pipelineParallel) {
    235         generateParallelPipeline(iBuilder, mPipeline);
     241        generateParallelPipeline(iBuilder.get(), mPipeline);
    236242    } else if (codegen::segmentPipelineParallel) {
    237         generateSegmentParallelPipeline(iBuilder, mPipeline);
     243        generateSegmentParallelPipeline(iBuilder.get(), mPipeline);
    238244    } else {
    239245        codegen::ThreadNum = 1;
    240         generatePipelineLoop(iBuilder, mPipeline);
     246        generatePipelineLoop(iBuilder.get(), mPipeline);
    241247    }
    242248    for (const auto & k : mPipeline) {
     249        k->setBuilder(iBuilder.get());
    243250        k->finalizeInstance();
    244251    }
     
    295302    PM.run(*m);
    296303
    297     for (kernel::KernelBuilder * const kb : mPipeline) {
    298         m = kb->getModule();
     304    for (kernel::Kernel * const k : mPipeline) {
     305        m = k->getModule();
    299306        bool uncachedObject = true;
    300         if (mCache && mCache->loadCachedObjectFile(kb)) {
     307        if (mCache && mCache->loadCachedObjectFile(k)) {
    301308            uncachedObject = false;
    302309        }
    303310        if (uncachedObject) {
    304             iBuilder->setModule(kb->getModule());
    305             kb->generateKernel();
     311            iBuilder->setModule(m);
     312            k->setBuilder(iBuilder.get());
     313            k->generateKernel();
    306314            PM.run(*m);
    307315        }
     
    328336    delete mCache;
    329337}
     338
     339
     340//void ParabixDriver::linkAndFinalize() {
     341
     342//    using KernelQueue = boost::lockfree::queue<kernel::KernelBuilder *>;
     343
     344//    legacy::PassManager PM;
     345//    #ifndef NDEBUG
     346//    PM.add(createVerifierPass());
     347//    #endif
     348//    PM.add(createPromoteMemoryToRegisterPass()); //Force the use of mem2reg to promote stack variables.
     349//    PM.add(createReassociatePass());             //Reassociate expressions.
     350//    PM.add(createGVNPass());                     //Eliminate common subexpressions.
     351//    PM.add(createInstructionCombiningPass());    //Simple peephole optimizations and bit-twiddling.
     352//    PM.add(createCFGSimplificationPass());
     353
     354//    raw_fd_ostream * IROutputStream = nullptr;
     355//    if (LLVM_UNLIKELY(codegen::DebugOptionIsSet(codegen::ShowIR))) {
     356//        if (codegen::IROutputFilename.empty()) {
     357//            IROutputStream = new raw_fd_ostream(STDERR_FILENO, false, false);
     358//        } else {
     359//            std::error_code error;
     360//            IROutputStream = new raw_fd_ostream(codegen::IROutputFilename, error, sys::fs::OpenFlags::F_None);
     361//        }
     362//        PM.add(createPrintModulePass(*IROutputStream));
     363//        codegen::Jobs = 1; // TODO: set Jobs to 1 for now; these should be updated to pipe to a temporary buffer when Jobs > 1
     364//    }
     365
     366//    #ifndef USE_LLVM_3_6
     367//    raw_fd_ostream * ASMOutputStream = nullptr;
     368//    if (LLVM_UNLIKELY(codegen::DebugOptionIsSet(codegen::ShowASM))) {
     369//        if (codegen::ASMOutputFilename.empty()) {
     370//            ASMOutputStream = new raw_fd_ostream(STDERR_FILENO, false, false);
     371//        } else {
     372//            std::error_code error;
     373//            ASMOutputStream = new raw_fd_ostream(codegen::ASMOutputFilename, error, sys::fs::OpenFlags::F_None);
     374//        }
     375//        if (LLVM_UNLIKELY(mTarget->addPassesToEmitFile(PM, *ASMOutputStream, TargetMachine::CGFT_AssemblyFile))) {
     376//            report_fatal_error("LLVM error: could not add emit assembly pass");
     377//        }
     378//        codegen::Jobs = 1; // TODO: set Jobs to 1 for now; these should be updated to pipe to a temporary buffer when Jobs > 1
     379//    }
     380//    #endif
     381
     382//    KernelQueue Q(mPipeline.size() + 1);
     383//    for (kernel::KernelBuilder * kb : mPipeline) {
     384//        assert (kb);
     385//        Q.unsynchronized_push(kb);
     386//    }
     387
     388//    std::thread compilation_thread[codegen::Jobs];
     389//    for (int i = 0; i < codegen::Jobs; ++i) {
     390//        compilation_thread[i] = std::thread([&]{
     391//            kernel::KernelBuilder * kb = nullptr;
     392//            Module * m = nullptr;
     393//            try {
     394//                while (Q.pop(kb)) {
     395//                    m = kb->getModule();
     396//                    bool uncachedObject = true;
     397//                    if (mCache && mCache->loadCachedObjectFile(kb)) {
     398//                        uncachedObject = false;
     399//                    }
     400//                    if (uncachedObject) {
     401//                        Module * const cm = iBuilder->getModule();
     402//                        iBuilder->setModule(m);
     403//                        kb->generateKernel();
     404//                        PM.run(*m);
     405//                        iBuilder->setModule(cm);
     406//                    }
     407//                    mEngine->addModule(std::unique_ptr<Module>(m));
     408//                }
     409//            } catch (...) {
     410//                // clear the queue
     411//                while (Q.pop(kb));
     412//                // dump the result the module to the console
     413//                if (m) m->dump();
     414//                throw;
     415//            }
     416//        });
     417//    }
     418
     419//    PM.run(*mMainModule);
     420//    for (int i = 0; i < codegen::Jobs; ++i) {
     421//        compilation_thread[i].join();
     422//    }
     423//    mEngine->finalizeObject();
     424
     425//    delete IROutputStream;
     426//    #ifndef USE_LLVM_3_6
     427//    delete ASMOutputStream;
     428//    #endif
     429
     430//}
     431
     432
     433//            std::unique_ptr<IDISA::IDISA_Builder> idb(IDISA::GetIDISA_Builder(kb->getModule()));
     434//            idb->setDriver(this);
     435//            kb->setBuilder(idb.get());
  • icGREP/icgrep-devel/icgrep/toolchain/toolchain.h

    r5429 r5435  
    88#define TOOLCHAIN_H
    99#include <string>
    10 #include <IR_Gen/idisa_builder.h>
    1110#include <IR_Gen/FunctionTypeBuilder.h>
    1211#include <kernels/kernel.h>
     12#include <kernels/kernel_builder.h>
    1313#include <kernels/streamset.h>
    1414
     
    1919namespace llvm { namespace cl { class OptionCategory; } }
    2020namespace IDISA { class IDISA_Builder; }
    21 namespace kernel { class KernelBuilder; }
     21namespace kernel { class Kernel; }
    2222
    2323class ParabixObjectCache;
     
    6767    ~ParabixDriver();
    6868   
    69     IDISA::IDISA_Builder * getIDISA_Builder() { return iBuilder.get(); }
     69    const std::unique_ptr<IDISA::IDISA_Builder> & getBuilder() { return iBuilder; }
    7070   
    7171    parabix::ExternalBuffer * addExternalBuffer(std::unique_ptr<parabix::ExternalBuffer> b);
     
    7373    parabix::StreamSetBuffer * addBuffer(std::unique_ptr<parabix::StreamSetBuffer> b);
    7474   
    75     kernel::KernelBuilder * addKernelInstance(std::unique_ptr<kernel::KernelBuilder> kb);
     75    kernel::Kernel * addKernelInstance(std::unique_ptr<kernel::Kernel> kb);
    7676   
    77     void addKernelCall(kernel::KernelBuilder & kb, const std::vector<parabix::StreamSetBuffer *> & inputs, const std::vector<parabix::StreamSetBuffer *> & outputs);
     77    void addKernelCall(kernel::Kernel & kb, const std::vector<parabix::StreamSetBuffer *> & inputs, const std::vector<parabix::StreamSetBuffer *> & outputs);
    7878
    79     void makeKernelCall(kernel::KernelBuilder * kb, const std::vector<parabix::StreamSetBuffer *> & inputs, const std::vector<parabix::StreamSetBuffer *> & outputs);
     79    void makeKernelCall(kernel::Kernel * kb, const std::vector<parabix::StreamSetBuffer *> & inputs, const std::vector<parabix::StreamSetBuffer *> & outputs);
    8080   
    8181    void generatePipelineIR();
    8282   
    8383    template <typename ExternalFunctionType>
    84     llvm::Function * LinkFunction(kernel::KernelBuilder & kb, llvm::StringRef name, ExternalFunctionType * functionPtr) const;
     84    llvm::Function * LinkFunction(kernel::Kernel & kb, llvm::StringRef name, ExternalFunctionType * functionPtr) const;
    8585
    8686    void linkAndFinalize();
     
    100100    ParabixObjectCache *                    mCache;
    101101
    102     std::vector<kernel::KernelBuilder *>    mPipeline;
     102    std::vector<kernel::Kernel *>    mPipeline;
    103103    // Owned kernels and buffers that will persist with this ParabixDriver instance.
    104     std::vector<std::unique_ptr<kernel::KernelBuilder>> mOwnedKernels;
     104    std::vector<std::unique_ptr<kernel::Kernel>> mOwnedKernels;
    105105    std::vector<std::unique_ptr<parabix::StreamSetBuffer>> mOwnedBuffers;
    106106};
    107107
    108108template <typename ExternalFunctionType>
    109 llvm::Function * ParabixDriver::LinkFunction(kernel::KernelBuilder & kb, llvm::StringRef name, ExternalFunctionType * functionPtr) const {
     109llvm::Function * ParabixDriver::LinkFunction(kernel::Kernel & kb, llvm::StringRef name, ExternalFunctionType * functionPtr) const {
    110110    llvm::FunctionType * const type = FunctionTypeBuilder<ExternalFunctionType>::get(iBuilder->getContext());
    111111    assert ("FunctionTypeBuilder did not resolve a function type." && type);
Note: See TracChangeset for help on using the changeset viewer.