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

Initial attempt to improve debugging capabilities with compilation stack traces on error.

File:
1 edited

Legend:

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

    r5473 r5486  
    3131                        clEnumValEnd), cl::cat(CodeGenOptions));
    3232
    33 static cl::opt<std::string> IROutputFilenameOption("dump-generated-IR-output", cl::init(""),
     33static cl::opt<const char *> IROutputFilenameOption("dump-generated-IR-output", cl::init(nullptr),
    3434                                                       cl::desc("output IR filename"), cl::cat(CodeGenOptions));
    3535
    3636#ifndef USE_LLVM_3_6
    37 static cl::opt<std::string> ASMOutputFilenameOption("asm-output", cl::init(""),
     37static cl::opt<const char *> ASMOutputFilenameOption("asm-output", cl::init(nullptr),
    3838                                                    cl::desc("output ASM filename"), cl::cat(CodeGenOptions));
    3939
     
    4646
    4747
    48 static cl::opt<bool> EnableObjectCacheOption("enable-object-cache",
    49                                              cl::init(true), cl::desc("Enable object caching"), cl::cat(CodeGenOptions));
    50 
    51 static cl::opt<std::string> ObjectCacheDirOption("object-cache-dir",
    52                                                  cl::init(""), cl::desc("Path to the object cache diretory"), cl::cat(CodeGenOptions));
     48static cl::opt<bool, true> EnableObjectCacheOption("enable-object-cache", cl::location(EnableObjectCache), cl::init(true),
     49                                                   cl::desc("Enable object caching"), cl::cat(CodeGenOptions));
     50
     51static cl::opt<const char *> ObjectCacheDirOption("object-cache-dir", cl::init(nullptr),
     52                                                 cl::desc("Path to the object cache diretory"), cl::cat(CodeGenOptions));
    5353
    5454
     
    5757
    5858
    59 static cl::opt<int, true> SegmentSizeOption("segment-size", cl::location(SegmentSize),
    60                                             cl::desc("Segment Size"), cl::value_desc("positive integer"), cl::init(1));
     59static cl::opt<int, true> SegmentSizeOption("segment-size", cl::location(SegmentSize), cl::init(1),
     60                                            cl::desc("Segment Size"), cl::value_desc("positive integer"));
    6161
    6262static cl::opt<int, true> BufferSegmentsOption("buffer-segments", cl::location(BufferSegments), cl::init(1),
     
    6464
    6565
    66 static cl::opt<int, true> ThreadNumOption("thread-num", cl::location(ThreadNum), cl::init(2),
     66static cl::opt<int> ThreadNumOption("thread-num", cl::init(2),
    6767                                          cl::desc("Number of threads used for segment pipeline parallel"), cl::value_desc("positive integer"));
    6868
    6969
    7070static cl::opt<bool, true> EnableAssertsOption("ea", cl::location(EnableAsserts), cl::init(IN_DEBUG_MODE),
    71                                                cl::desc("Enable Asserts"));
     71                                               cl::desc("Enable Asserts"), cl::cat(CodeGenOptions));
    7272
    7373static cl::opt<bool, true> EnableCycleCountOption("ShowKernelCycles", cl::location(EnableCycleCounter), cl::init(false),
    74                                                   cl::desc("Count and report CPU cycles per kernel"), cl::cat(CodeGenOptions));
    75 
    76 static cl::opt<bool, true> pipelineParallelOption("enable-pipeline-parallel", cl::location(pipelineParallel),
     74                                             cl::desc("Count and report CPU cycles per kernel"), cl::cat(CodeGenOptions));
     75
     76static cl::opt<bool, true> pipelineParallelOption("enable-pipeline-parallel", cl::location(PipelineParallel), cl::init(false),
    7777                                                  cl::desc("Enable multithreading with pipeline parallelism."), cl::cat(CodeGenOptions));
    7878   
    79 static cl::opt<bool, true> segmentPipelineParallelOption("enable-segment-pipeline-parallel", cl::location(segmentPipelineParallel),
     79static cl::opt<bool, true> segmentPipelineParallelOption("enable-segment-pipeline-parallel", cl::location(SegmentPipelineParallel),
    8080                                                         cl::desc("Enable multithreading with segment pipeline parallelism."), cl::cat(CodeGenOptions));
    8181
    82 static cl::opt<bool> USENVPTX("NVPTX", cl::init(false),
    83                               cl::desc("Run on GPU only."));
     82static cl::opt<bool, true> NVPTXOption("NVPTX", cl::location(NVPTX), cl::init(false),
     83                                 cl::desc("Run on GPU only."), cl::cat(CodeGenOptions));
    8484
    8585static cl::opt<int, true> GroupNumOption("group-num", cl::location(GroupNum), cl::init(256),
    86                                          cl::desc("NUmber of groups declared on GPU"), cl::value_desc("positive integer"));
    87 
    88 
    89 const CodeGenOpt::Level OptLevel = [](const char optLevel) {
    90     switch (optLevel) {
    91         case '0': return CodeGenOpt::None;
    92         case '1': return CodeGenOpt::Less;
    93         case '2': return CodeGenOpt::Default;
    94         case '3': return CodeGenOpt::Aggressive;
    95         default: report_fatal_error(std::string(1,optLevel) + " is an invalid optimization level.");
    96     }
    97 }(OptLevelOption);
    98 
    99 bool pipelineParallel;
    100 bool segmentPipelineParallel;
    101 const std::string ASMOutputFilename = ASMOutputFilenameOption;
    102 const std::string IROutputFilename = IROutputFilenameOption;
    103 const std::string ObjectCacheDir = ObjectCacheDirOption;
     86                                         cl::desc("NUmber of groups declared on GPU"), cl::value_desc("positive integer"), cl::cat(CodeGenOptions));
     87
     88CodeGenOpt::Level OptLevel;
     89
     90bool PipelineParallel;
     91
     92bool SegmentPipelineParallel;
     93
     94const char * ASMOutputFilename;
     95
     96const char * IROutputFilename;
     97
     98const char * ObjectCacheDir;
     99
    104100int BlockSize;
     101
    105102int SegmentSize;
     103
    106104int BufferSegments;
     105
    107106int ThreadNum;
     107
    108108bool EnableAsserts;
     109
    109110bool EnableCycleCounter;
    110 const bool EnableObjectCache = EnableObjectCacheOption && (DebugOptions.getBits() == 0);
    111 bool NVPTX;
     111
     112bool EnableObjectCache;
     113
     114bool NVPTX = [](const bool nvptx) {
     115    #ifndef CUDA_ENABLED
     116    if (nvptx) {
     117        report_fatal_error("CUDA compiler is not supported.");
     118    }
     119    #endif
     120    return nvptx;
     121}(NVPTXOption);
     122
    112123int GroupNum;
    113124
    114125const llvm::Reloc::Model RelocModel = ::RelocModel;
     126
    115127const llvm::CodeModel::Model CMModel = ::CMModel;
     128
    116129const std::string MArch = ::MArch;
     130
    117131const std::string RunPass = ::RunPass;
     132
    118133const llvm::TargetMachine::CodeGenFileType FileType = ::FileType;
     134
    119135const std::string StopAfter = ::StopAfter;
     136
    120137const std::string StartAfter = ::StartAfter;
    121 #ifndef USE_LLVM_3_6
    122 const TargetOptions Options = [](const bool asmVerbose) {
    123     TargetOptions opt = InitTargetOptionsFromCodeGenFlags();
    124     opt.MCOptions.AsmVerbose = AsmVerbose;
    125     return opt;
    126 }(AsmVerbose);
    127 #else
    128 const TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
    129 #endif
     138
     139TargetOptions Options;
    130140
    131141const cl::OptionCategory * codegen_flags() {
     
    149159}
    150160
    151 
    152 }
    153 
    154 void setNVPTXOption() {
    155     codegen::NVPTX = codegen::USENVPTX;
    156     if (codegen::NVPTX) {
    157         #ifndef CUDA_ENABLED
     161std::string ProgramName;
     162
     163void ParseCommandLineOptions(int argc, const char * const *argv, std::initializer_list<const cl::OptionCategory *> hiding) {
     164    AddParabixVersionPrinter();
     165    codegen::ProgramName = argv[0];
     166    #ifndef USE_LLVM_3_6
     167    if (hiding.size() != 0) {
     168        cl::HideUnrelatedOptions(ArrayRef<const cl::OptionCategory *>(hiding));
     169    }
     170    #endif
     171    cl::ParseCommandLineOptions(argc, argv);
     172    if (DebugOptions.getBits()) {
     173        EnableObjectCache = false;
     174    }
     175
     176    ThreadNum = (PipelineParallel || SegmentPipelineParallel) ? 2 : 1;
     177
     178    ObjectCacheDir = ObjectCacheDirOption;
     179    IROutputFilename = IROutputFilenameOption;
     180    ObjectCacheDir = ObjectCacheDirOption;
     181    Options = InitTargetOptionsFromCodeGenFlags();
     182    #ifndef USE_LLVM_3_6
     183    Options.MCOptions.AsmVerbose = AsmVerbose;
     184    #endif
     185    switch (OptLevelOption) {
     186        case '0': OptLevel = CodeGenOpt::None; break;
     187        case '1': OptLevel = CodeGenOpt::Less; break;
     188        case '2': OptLevel = CodeGenOpt::Default; break;
     189        case '3': OptLevel = CodeGenOpt::Aggressive; break;
     190        default: report_fatal_error(std::string(1, OptLevelOption) + " is an invalid optimization level.");
     191    }
     192    #ifndef CUDA_ENABLED
     193    if (NVPTX) {
    158194        report_fatal_error("CUDA compiler is not supported.");
    159         #endif
    160     }
     195    }
     196    #endif
     197}
     198
    161199}
    162200
    163201void printParabixVersion () {
    164     raw_ostream &OS = outs();
    165     OS << "Parabix (http://parabix.costar.sfu.ca/):\n  " << "Parabix revision " << PARABIX_VERSION << "\n";
     202    outs() << "Parabix (http://parabix.costar.sfu.ca/):\n  " << "Parabix revision " << PARABIX_VERSION << "\n";
    166203}
    167204
Note: See TracChangeset for help on using the changeset viewer.