Ignore:
Timestamp:
Aug 21, 2017, 11:57:06 AM (2 years ago)
Author:
nmedfort
Message:

Bug fixes for IR/ASM writing

File:
1 edited

Legend:

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

    r5510 r5616  
    3535, mTarget(nullptr)
    3636, mEngine(nullptr)
    37 , mCache(nullptr) {
     37, mCache(nullptr)
     38, mIROutputStream(nullptr)
     39, mASMOutputStream(nullptr) {
    3840
    3941    InitializeNativeTarget();
     
    142144
    143145    legacy::PassManager PM;
    144     std::unique_ptr<raw_fd_ostream> IROutputStream(nullptr);
    145146    if (LLVM_UNLIKELY(codegen::DebugOptionIsSet(codegen::ShowUnoptimizedIR))) {
    146         if (codegen::IROutputFilename) {
    147             std::error_code error;
    148             IROutputStream.reset(new raw_fd_ostream(codegen::IROutputFilename, error, sys::fs::OpenFlags::F_None));
    149         } else {
    150             IROutputStream.reset(new raw_fd_ostream(STDERR_FILENO, false, false));
    151         }
    152         PM.add(createPrintModulePass(*IROutputStream));
     147        if (LLVM_LIKELY(mIROutputStream == nullptr)) {
     148            if (codegen::IROutputFilename) {
     149                std::error_code error;
     150                mIROutputStream = new raw_fd_ostream(codegen::IROutputFilename, error, sys::fs::OpenFlags::F_None);
     151            } else {
     152                mIROutputStream = new raw_fd_ostream(STDERR_FILENO, false, true);
     153            }
     154        }
     155        PM.add(createPrintModulePass(*mIROutputStream));
    153156    }
    154157    if (IN_DEBUG_MODE || LLVM_UNLIKELY(codegen::DebugOptionIsSet(codegen::VerifyIR))) {
     
    164167
    165168    if (LLVM_UNLIKELY(codegen::DebugOptionIsSet(codegen::ShowIR))) {
    166         if (LLVM_LIKELY(IROutputStream == nullptr)) {
     169        if (LLVM_LIKELY(mIROutputStream == nullptr)) {
    167170            if (codegen::IROutputFilename) {
    168171                std::error_code error;
    169                 IROutputStream.reset(new raw_fd_ostream(codegen::IROutputFilename, error, sys::fs::OpenFlags::F_None));
     172                mIROutputStream = new raw_fd_ostream(codegen::IROutputFilename, error, sys::fs::OpenFlags::F_None);
    170173            } else {
    171                 IROutputStream.reset(new raw_fd_ostream(STDERR_FILENO, false, false));
    172             }
    173         }
    174         PM.add(createPrintModulePass(*IROutputStream));
     174                mIROutputStream = new raw_fd_ostream(STDERR_FILENO, false, true);
     175            }
     176        }
     177        PM.add(createPrintModulePass(*mIROutputStream));
    175178    }
    176179
    177180    #ifndef USE_LLVM_3_6
    178     std::unique_ptr<raw_fd_ostream> ASMOutputStream(nullptr);
    179181    if (LLVM_UNLIKELY(codegen::DebugOptionIsSet(codegen::ShowASM))) {
    180182        if (codegen::ASMOutputFilename) {
    181183            std::error_code error;
    182             ASMOutputStream.reset(new raw_fd_ostream(codegen::ASMOutputFilename, error, sys::fs::OpenFlags::F_None));
     184            mASMOutputStream = new raw_fd_ostream(codegen::ASMOutputFilename, error, sys::fs::OpenFlags::F_None);
    183185        } else {
    184             ASMOutputStream.reset(new raw_fd_ostream(STDERR_FILENO, false, false));
    185         }
    186         if (LLVM_UNLIKELY(mTarget->addPassesToEmitFile(PM, *ASMOutputStream, TargetMachine::CGFT_AssemblyFile))) {
     186            mASMOutputStream = new raw_fd_ostream(STDERR_FILENO, false, true);
     187        }
     188        if (LLVM_UNLIKELY(mTarget->addPassesToEmitFile(PM, *mASMOutputStream, TargetMachine::CGFT_AssemblyFile))) {
    187189            report_fatal_error("LLVM error: could not add emit assembly pass");
    188190        }
     
    235237    delete mCache;
    236238    delete mTarget;
    237 }
     239    delete mIROutputStream;
     240    delete mASMOutputStream;
     241}
Note: See TracChangeset for help on using the changeset viewer.