Ignore:
Timestamp:
Mar 18, 2018, 11:27:16 AM (17 months ago)
Author:
cameron
Message:

Restructuring step

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

Legend:

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

    r5856 r5913  
    33#include <IR_Gen/idisa_target.h>
    44#include <toolchain/toolchain.h>
     5#include <llvm/Support/DynamicLibrary.h>           // for LoadLibraryPermanently
     6#include <llvm/ExecutionEngine/RuntimeDyld.h>
     7#include <llvm/ExecutionEngine/RTDyldMemoryManager.h>
    58#include <llvm/ExecutionEngine/ExecutionEngine.h>  // for EngineBuilder
    69#include <llvm/IR/LegacyPassManager.h>             // for PassManager
     
    4750    InitializeNativeTargetAsmPrinter();
    4851    InitializeNativeTargetAsmParser();
    49 
    50     PassRegistry * Registry = PassRegistry::getPassRegistry();
    51     initializeCore(*Registry);
    52     initializeCodeGen(*Registry);
    53     initializeLowerIntrinsicsPass(*Registry);
     52    llvm::sys::DynamicLibrary::LoadLibraryPermanently(nullptr);
     53
     54    preparePassManager();
    5455
    5556    std::string errMessage;
     
    143144}
    144145
    145 void ParabixDriver::finalizeObject() {
    146 
    147     legacy::PassManager PM;
     146void ParabixDriver::preparePassManager() {
     147    PassRegistry * Registry = PassRegistry::getPassRegistry();
     148    initializeCore(*Registry);
     149    initializeCodeGen(*Registry);
     150    initializeLowerIntrinsicsPass(*Registry);
     151   
    148152    if (LLVM_UNLIKELY(codegen::ShowUnoptimizedIROption != codegen::OmittedOption)) {
    149153        if (LLVM_LIKELY(mIROutputStream == nullptr)) {
     
    155159            }
    156160        }
    157         PM.add(createPrintModulePass(*mIROutputStream));
     161        mPassManager.add(createPrintModulePass(*mIROutputStream));
    158162    }
    159163    if (IN_DEBUG_MODE || LLVM_UNLIKELY(codegen::DebugOptionIsSet(codegen::VerifyIR))) {
    160         PM.add(createVerifierPass());
    161     }
    162     PM.add(createPromoteMemoryToRegisterPass());    // Promote stack variables to constants or PHI nodes
    163     PM.add(createCFGSimplificationPass());          // Remove dead basic blocks and unnecessary branch statements / phi nodes
    164     PM.add(createEarlyCSEPass());                   // Simple common subexpression elimination pass
    165     PM.add(createInstructionCombiningPass());       // Simple peephole optimizations and bit-twiddling.
    166     PM.add(createReassociatePass());                // Canonicalizes commutative expressions
    167     PM.add(createGVNPass());                        // Global value numbering redundant expression elimination pass
    168     PM.add(createCFGSimplificationPass());          // Repeat CFG Simplification to "clean up" any newly found redundant phi nodes
    169 
     164        mPassManager.add(createVerifierPass());
     165    }
     166    mPassManager.add(createPromoteMemoryToRegisterPass());    // Promote stack variables to constants or PHI nodes
     167    mPassManager.add(createCFGSimplificationPass());          // Remove dead basic blocks and unnecessary branch statements / phi nodes
     168    mPassManager.add(createEarlyCSEPass());                   // Simple common subexpression elimination pass
     169    mPassManager.add(createInstructionCombiningPass());       // Simple peephole optimizations and bit-twiddling.
     170    mPassManager.add(createReassociatePass());                // Canonicalizes commutative expressions
     171    mPassManager.add(createGVNPass());                        // Global value numbering redundant expression elimination pass
     172    mPassManager.add(createCFGSimplificationPass());          // Repeat CFG Simplification to "clean up" any newly found redundant phi nodes
     173   
    170174    if (LLVM_UNLIKELY(codegen::ShowIROption != codegen::OmittedOption)) {
    171175        if (LLVM_LIKELY(mIROutputStream == nullptr)) {
     
    177181            }
    178182        }
    179         PM.add(createPrintModulePass(*mIROutputStream));
    180     }
    181 
     183        mPassManager.add(createPrintModulePass(*mIROutputStream));
     184    }
     185   
    182186#if LLVM_VERSION_INTEGER >= LLVM_VERSION_CODE(3, 7, 0)
    183187    if (LLVM_UNLIKELY(codegen::ShowASMOption != codegen::OmittedOption)) {
     
    188192            mASMOutputStream = new raw_fd_ostream(STDERR_FILENO, false, true);
    189193        }
    190         if (LLVM_UNLIKELY(mTarget->addPassesToEmitFile(PM, *mASMOutputStream, TargetMachine::CGFT_AssemblyFile))) {
     194        if (LLVM_UNLIKELY(mTarget->addPassesToEmitFile(mPassManager, *mASMOutputStream, TargetMachine::CGFT_AssemblyFile))) {
    191195            report_fatal_error("LLVM error: could not add emit assembly pass");
    192196        }
    193197    }
    194198#endif
     199}
     200
     201
     202void ParabixDriver::finalizeObject() {
    195203
    196204    Module * module = nullptr;
     
    201209            module = kernel->getModule(); assert (module);
    202210            module->setTargetTriple(mMainModule->getTargetTriple());
    203             PM.run(*module);
     211            mPassManager.run(*module);
    204212        }
    205213        module = mMainModule;
    206214        iBuilder->setKernel(nullptr);
    207         PM.run(*mMainModule);
     215        mPassManager.run(*mMainModule);
    208216        for (Kernel * const kernel : mPipeline) {
    209217            if (LLVM_UNLIKELY(kernel->getModule() == nullptr)) {
     
    220228
    221229bool ParabixDriver::hasExternalFunction(llvm::StringRef functionName) const {
    222     return mEngine->getPointerToNamedFunction(functionName, false) != nullptr;
     230    return RTDyldMemoryManager::getSymbolAddressInProcess(functionName);
    223231}
    224232
  • icGREP/icgrep-devel/icgrep/toolchain/cpudriver.h

    r5735 r5913  
    22#define CPUDRIVER_H
    33#include "driver.h"
     4#include <llvm/IR/LegacyPassManager.h>             // for PassManager
    45
    56namespace llvm { class ExecutionEngine; }
     
    2930
    3031private:
     32    void preparePassManager();
    3133
    3234    llvm::Function * addLinkFunction(llvm::Module * mod, llvm::StringRef name, llvm::FunctionType * type, void * functionPtr) const override;
     
    3436private:
    3537    llvm::TargetMachine *                                   mTarget;
     38    llvm::legacy::PassManager                               mPassManager;
    3639    llvm::ExecutionEngine *                                 mEngine;
    3740    ParabixObjectCache *                                    mCache;
Note: See TracChangeset for help on using the changeset viewer.