Changeset 5616


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

Bug fixes for IR/ASM writing

Location:
icGREP/icgrep-devel/icgrep/toolchain
Files:
3 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}
  • icGREP/icgrep-devel/icgrep/toolchain/cpudriver.h

    r5493 r5616  
    55namespace llvm { class ExecutionEngine; }
    66namespace llvm { class TargetMachine; }
     7namespace llvm { class raw_fd_ostream; }
    78
    89class ParabixObjectCache;
     
    3334    llvm::ExecutionEngine *                                 mEngine;
    3435    ParabixObjectCache *                                    mCache;
     36    // NOTE: when printing the IR/ASM, we cannot assume they're completely finished after finalizeObject is executed. Instead we store a
     37    // pointer and delete them once the driver (and any processing) is complete. This prevents us from reclaiming the memory early but
     38    // also avoids a potential segmentation fault when writing large files.
     39    llvm::raw_fd_ostream *                                  mIROutputStream;
     40    llvm::raw_fd_ostream *                                  mASMOutputStream;
    3541};
    3642
  • icGREP/icgrep-devel/icgrep/toolchain/toolchain.cpp

    r5521 r5616  
    3131                        clEnumValEnd), cl::cat(CodeGenOptions));
    3232
    33 static cl::opt<const char *> IROutputFilenameOption("dump-generated-IR-output", cl::init(nullptr),
     33static cl::opt<std::string> IROutputFilenameOption("dump-generated-IR-output", cl::init(""),
    3434                                                       cl::desc("output IR filename"), cl::cat(CodeGenOptions));
    3535
    3636#ifndef USE_LLVM_3_6
    37 static cl::opt<const char *> ASMOutputFilenameOption("asm-output", cl::init(nullptr),
     37static cl::opt<std::string> ASMOutputFilenameOption("asm-output", cl::init(""),
    3838                                                    cl::desc("output ASM filename"), cl::cat(CodeGenOptions));
    3939
     
    4949                                                   cl::desc("Enable object caching"), cl::cat(CodeGenOptions));
    5050
    51 static cl::opt<const char *> ObjectCacheDirOption("object-cache-dir", cl::init(nullptr),
     51static cl::opt<std::string> ObjectCacheDirOption("object-cache-dir", cl::init(""),
    5252                                                 cl::desc("Path to the object cache diretory"), cl::cat(CodeGenOptions));
    5353
     
    173173        EnableObjectCache = false;
    174174    }
    175 
    176     ObjectCacheDir = ObjectCacheDirOption;
    177     IROutputFilename = IROutputFilenameOption;
    178     ObjectCacheDir = ObjectCacheDirOption;
     175    ObjectCacheDir = ObjectCacheDirOption.empty() ? nullptr : ObjectCacheDirOption.data();
     176    IROutputFilename = IROutputFilenameOption.empty() ? nullptr : IROutputFilenameOption.data();
     177    ASMOutputFilename = ASMOutputFilenameOption.empty() ? nullptr : ASMOutputFilenameOption.data();
    179178    Options = InitTargetOptionsFromCodeGenFlags();
    180179    #ifndef USE_LLVM_3_6
Note: See TracChangeset for help on using the changeset viewer.