diff options
author | Duncan Sands <baldrick@free.fr> | 2012-06-27 16:23:48 +0000 |
---|---|---|
committer | Duncan Sands <baldrick@free.fr> | 2012-06-27 16:23:48 +0000 |
commit | 206fc30ab140edc7527d0dc48082e7d508c54cd8 (patch) | |
tree | 1239bc670f0e897c1ee5e03be8904850c5d36e5c | |
parent | 8fcf0e78709f42ea416c1e7e0650e57c9273bab2 (diff) | |
download | bcm5719-llvm-206fc30ab140edc7527d0dc48082e7d508c54cd8.tar.gz bcm5719-llvm-206fc30ab140edc7527d0dc48082e7d508c54cd8.zip |
When users ask for -mcpu=help or -mattr=help, just output the help without
requiring a module. Original patch by Sunay Ismail, simplified by Arnaud
de Grandmaison, then complicated by me (if a triple was specified on the
command line, output help for that triple, not for the default).
llvm-svn: 159268
-rw-r--r-- | llvm/tools/llc/llc.cpp | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp index 9b3ef8144c8..80953668751 100644 --- a/llvm/tools/llc/llc.cpp +++ b/llvm/tools/llc/llc.cpp @@ -365,20 +365,29 @@ int main(int argc, char **argv) { // Load the module to be compiled... SMDiagnostic Err; std::auto_ptr<Module> M; + Module *mod = 0; + Triple TheTriple; + + bool SkipModule = MCPU == "help" || + (!MAttrs.empty() && MAttrs.front() == "help"); + + // If user just wants to list available options, skip module loading + if (!SkipModule) { + M.reset(ParseIRFile(InputFilename, Err, Context)); + mod = M.get(); + if (mod == 0) { + Err.print(argv[0], errs()); + return 1; + } - M.reset(ParseIRFile(InputFilename, Err, Context)); - if (M.get() == 0) { - Err.print(argv[0], errs()); - return 1; + // If we are supposed to override the target triple, do so now. + if (!TargetTriple.empty()) + mod->setTargetTriple(Triple::normalize(TargetTriple)); + TheTriple = Triple(mod->getTargetTriple()); + } else { + TheTriple = Triple(Triple::normalize(TargetTriple)); } - Module &mod = *M.get(); - - // If we are supposed to override the target triple, do so now. - if (!TargetTriple.empty()) - mod.setTargetTriple(Triple::normalize(TargetTriple)); - // Figure out the target triple. - Triple TheTriple(mod.getTargetTriple()); if (TheTriple.getTriple().empty()) TheTriple.setTriple(sys::getDefaultTargetTriple()); @@ -441,6 +450,7 @@ int main(int argc, char **argv) { MCPU, FeaturesStr, Options, RelocModel, CMModel, OLvl)); assert(target.get() && "Could not allocate target machine!"); + assert(mod && "Should have exited after outputting help!"); TargetMachine &Target = *target.get(); if (DisableDotLoc) @@ -472,7 +482,7 @@ int main(int argc, char **argv) { if (const TargetData *TD = Target.getTargetData()) PM.add(new TargetData(*TD)); else - PM.add(new TargetData(&mod)); + PM.add(new TargetData(mod)); // Override default to generate verbose assembly. Target.setAsmVerbosityDefault(true); @@ -498,7 +508,7 @@ int main(int argc, char **argv) { // Before executing passes, print the final values of the LLVM options. cl::PrintOptionValues(); - PM.run(mod); + PM.run(*mod); } // Declare success. |