summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-03-06 05:34:10 +0000
committerChris Lattner <sabre@nondot.org>2009-03-06 05:34:10 +0000
commitcc14d25dd99e891c586bd56aa41796abbe4ac3d8 (patch)
treefcc5b45f79eaf1d6db4860bcf6e0771d3022c24b
parent3f43a7021fae71c056f5e1afc60016cfd8193f68 (diff)
Change various llvm utilities to use PrettyStackTraceProgram in
their main routines. This makes the tools print their argc/argv commands if they crash. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66248 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/Scalar/JumpThreading.cpp34
-rw-r--r--tools/bugpoint/bugpoint.cpp6
-rw-r--r--tools/llc/llc.cpp6
-rw-r--r--tools/lli/lli.cpp5
-rw-r--r--tools/llvm-ar/llvm-ar.cpp9
-rw-r--r--tools/llvm-as/llvm-as.cpp7
-rw-r--r--tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp8
-rw-r--r--tools/llvm-db/llvm-db.cpp8
-rw-r--r--tools/llvm-dis/llvm-dis.cpp8
-rw-r--r--tools/llvm-extract/llvm-extract.cpp8
-rw-r--r--tools/llvm-ld/llvm-ld.cpp8
-rw-r--r--tools/llvm-link/llvm-link.cpp9
-rw-r--r--tools/llvm-nm/llvm-nm.cpp8
-rw-r--r--tools/llvm-prof/llvm-prof.cpp8
-rw-r--r--tools/llvm-ranlib/llvm-ranlib.cpp10
-rw-r--r--utils/TableGen/TableGen.cpp3
16 files changed, 112 insertions, 33 deletions
diff --git a/lib/Transforms/Scalar/JumpThreading.cpp b/lib/Transforms/Scalar/JumpThreading.cpp
index f96fc208ae..1f3e6b11c8 100644
--- a/lib/Transforms/Scalar/JumpThreading.cpp
+++ b/lib/Transforms/Scalar/JumpThreading.cpp
@@ -407,6 +407,12 @@ bool JumpThreading::ProcessBranchOnDuplicateCond(BasicBlock *PredBB,
return true;
}
+struct APIntUnsignedOrdering {
+ bool operator()(const APInt &LHS, const APInt &RHS) const {
+ return LHS.ult(RHS);
+ }
+};
+
/// ProcessSwitchOnDuplicateCond - We found a block and a predecessor of that
/// block that switch on exactly the same condition. This means that we almost
/// always know the direction of the edge in the DESTBB:
@@ -474,6 +480,34 @@ bool JumpThreading::ProcessSwitchOnDuplicateCond(BasicBlock *PredBB,
return true;
}
+#if 0
+ // Figure out on which of the condition allow us to get to DESTBB. If DESTBB
+ // is the default label, we compute the set of values COND is known not to be
+ // otherwise we compute the set of options that COND could be.
+ SmallVector<APInt, 16> KnownValues;
+ bool DestBBIsDefault = PredSI->getSuccessor(0) == DestBB;
+
+ if (DestBBIsDefault) {
+ // DestBB the default case. Collect the values where PredBB can't branch to
+ // DestBB.
+ for (unsigned i = 1/*skip default*/, e = PredSI->getNumCases(); i != e; ++i)
+ if (PredSI->getSuccessor(i) != DestBB)
+ KnownValues.push_back(PredSI->getCaseValue(i)->getValue());
+ } else {
+ // Not the default case. Collect the values where PredBB can branch to
+ // DestBB.
+ for (unsigned i = 1/*skip default*/, e = PredSI->getNumCases(); i != e; ++i)
+ if (PredSI->getSuccessor(i) == DestBB)
+ KnownValues.push_back(PredSI->getCaseValue(i)->getValue());
+ }
+
+ std::sort(KnownValues.begin(), KnownValues.end(), APIntUnsignedOrdering());
+ return false;
+ cerr << "\nFOUND THREAD BLOCKS:\n";
+ PredBB->dump();
+ DestBB->dump();
+#endif
+
return false;
}
diff --git a/tools/bugpoint/bugpoint.cpp b/tools/bugpoint/bugpoint.cpp
index 587077eb70..543512ce62 100644
--- a/tools/bugpoint/bugpoint.cpp
+++ b/tools/bugpoint/bugpoint.cpp
@@ -20,6 +20,7 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/PluginLoader.h"
+#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/System/Process.h"
#include "llvm/System/Signals.h"
#include "llvm/LinkAllVMCore.h"
@@ -64,12 +65,13 @@ static void BugpointInterruptFunction() {
}
int main(int argc, char **argv) {
- llvm_shutdown_obj X; // Call llvm_shutdown() on exit.
+ llvm::sys::PrintStackTraceOnErrorSignal();
+ llvm::PrettyStackTraceProgram X(argc, argv);
+ llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
cl::ParseCommandLineOptions(argc, argv,
"LLVM automatic testcase reducer. See\nhttp://"
"llvm.org/cmds/bugpoint.html"
" for more information.\n");
- sys::PrintStackTraceOnErrorSignal();
sys::SetInterruptFunction(BugpointInterruptFunction);
BugDriver D(argv[0], AsChild, FindBugs, TimeoutValue, MemoryLimit);
diff --git a/tools/llc/llc.cpp b/tools/llc/llc.cpp
index 087a77097b..c80e9296e8 100644
--- a/tools/llc/llc.cpp
+++ b/tools/llc/llc.cpp
@@ -31,6 +31,7 @@
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/PluginLoader.h"
+#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/RegistryParser.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Analysis/Verifier.h"
@@ -192,9 +193,10 @@ static raw_ostream *GetOutputStream(const char *ProgName) {
// main - Entry point for the llc compiler.
//
int main(int argc, char **argv) {
- llvm_shutdown_obj X; // Call llvm_shutdown() on exit.
- cl::ParseCommandLineOptions(argc, argv, "llvm system compiler\n");
sys::PrintStackTraceOnErrorSignal();
+ PrettyStackTraceProgram X(argc, argv);
+ llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
+ cl::ParseCommandLineOptions(argc, argv, "llvm system compiler\n");
// Load the module to be compiled...
std::string ErrorMessage;
diff --git a/tools/lli/lli.cpp b/tools/lli/lli.cpp
index fee48ed210..d62d332098 100644
--- a/tools/lli/lli.cpp
+++ b/tools/lli/lli.cpp
@@ -25,6 +25,7 @@
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/PluginLoader.h"
+#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/System/Process.h"
#include "llvm/System/Signals.h"
#include <iostream>
@@ -83,10 +84,12 @@ static void do_shutdown() {
// main Driver function
//
int main(int argc, char **argv, char * const *envp) {
+ sys::PrintStackTraceOnErrorSignal();
+ PrettyStackTraceProgram X(argc, argv);
+
atexit(do_shutdown); // Call llvm_shutdown() on exit.
cl::ParseCommandLineOptions(argc, argv,
"llvm interpreter & dynamic compiler\n");
- sys::PrintStackTraceOnErrorSignal();
// If the user doesn't want core files, disable them.
if (DisableCoreFiles)
diff --git a/tools/llvm-ar/llvm-ar.cpp b/tools/llvm-ar/llvm-ar.cpp
index 766d91cbd9..5d81fc7cf3 100644
--- a/tools/llvm-ar/llvm-ar.cpp
+++ b/tools/llvm-ar/llvm-ar.cpp
@@ -16,6 +16,7 @@
#include "llvm/Bitcode/Archive.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ManagedStatic.h"
+#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/System/Signals.h"
#include <iostream>
#include <algorithm>
@@ -686,7 +687,10 @@ doReplaceOrInsert(std::string* ErrMsg) {
// main - main program for llvm-ar .. see comments in the code
int main(int argc, char **argv) {
- llvm_shutdown_obj X; // Call llvm_shutdown() on exit.
+ // Print a stack trace if we signal out.
+ sys::PrintStackTraceOnErrorSignal();
+ PrettyStackTraceProgram X(argc, argv);
+ llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
// Have the command line options parsed and handle things
// like --help and --version.
@@ -695,9 +699,6 @@ int main(int argc, char **argv) {
" This program archives bitcode files into single libraries\n"
);
- // Print a stack trace if we signal out.
- sys::PrintStackTraceOnErrorSignal();
-
int exitCode = 0;
// Make sure we don't exit with "unhandled exception".
diff --git a/tools/llvm-as/llvm-as.cpp b/tools/llvm-as/llvm-as.cpp
index 72e32972d2..79ece8f106 100644
--- a/tools/llvm-as/llvm-as.cpp
+++ b/tools/llvm-as/llvm-as.cpp
@@ -21,6 +21,7 @@
#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ManagedStatic.h"
+#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Streams.h"
#include "llvm/Support/SystemUtils.h"
#include "llvm/Support/raw_ostream.h"
@@ -51,9 +52,11 @@ DisableVerify("disable-verify", cl::Hidden,
cl::desc("Do not run verifier on input LLVM (dangerous!)"));
int main(int argc, char **argv) {
- llvm_shutdown_obj X; // Call llvm_shutdown() on exit.
- cl::ParseCommandLineOptions(argc, argv, "llvm .ll -> .bc assembler\n");
+ // Print a stack trace if we signal out.
sys::PrintStackTraceOnErrorSignal();
+ PrettyStackTraceProgram X(argc, argv);
+ llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
+ cl::ParseCommandLineOptions(argc, argv, "llvm .ll -> .bc assembler\n");
int exitCode = 0;
std::ostream *Out = 0;
diff --git a/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp b/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
index 4f1e9e81c7..623bcaeae7 100644
--- a/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
+++ b/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
@@ -33,6 +33,7 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/System/Signals.h"
#include <map>
#include <fstream>
@@ -501,10 +502,11 @@ static int AnalyzeBitcode() {
int main(int argc, char **argv) {
- llvm_shutdown_obj X; // Call llvm_shutdown() on exit.
- cl::ParseCommandLineOptions(argc, argv, "llvm-bcanalyzer file analyzer\n");
-
+ // Print a stack trace if we signal out.
sys::PrintStackTraceOnErrorSignal();
+ PrettyStackTraceProgram X(argc, argv);
+ llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
+ cl::ParseCommandLineOptions(argc, argv, "llvm-bcanalyzer file analyzer\n");
return AnalyzeBitcode();
}
diff --git a/tools/llvm-db/llvm-db.cpp b/tools/llvm-db/llvm-db.cpp
index a4e8b526ce..04e616227b 100644
--- a/tools/llvm-db/llvm-db.cpp
+++ b/tools/llvm-db/llvm-db.cpp
@@ -15,6 +15,7 @@
#include "CLIDebugger.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ManagedStatic.h"
+#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/System/Signals.h"
#include <iostream>
using namespace llvm;
@@ -49,12 +50,15 @@ namespace {
// main Driver function
//
int main(int argc, char **argv, char * const *envp) {
- llvm_shutdown_obj X; // Call llvm_shutdown() on exit.
+ // Print a stack trace if we signal out.
+ sys::PrintStackTraceOnErrorSignal();
+ PrettyStackTraceProgram X(argc, argv);
+
+ llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
std::cout << "NOTE: llvm-db is known useless right now.\n";
try {
cl::ParseCommandLineOptions(argc, argv,
"llvm source-level debugger\n");
- sys::PrintStackTraceOnErrorSignal();
if (!Quiet)
std::cout << "llvm-db: The LLVM source-level debugger\n";
diff --git a/tools/llvm-dis/llvm-dis.cpp b/tools/llvm-dis/llvm-dis.cpp
index 89f19e1dae..471e5e2f5d 100644
--- a/tools/llvm-dis/llvm-dis.cpp
+++ b/tools/llvm-dis/llvm-dis.cpp
@@ -23,6 +23,7 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Streams.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/System/Signals.h"
@@ -45,10 +46,13 @@ static cl::opt<bool>
DontPrint("disable-output", cl::desc("Don't output the .ll file"), cl::Hidden);
int main(int argc, char **argv) {
- llvm_shutdown_obj X; // Call llvm_shutdown() on exit.
+ // Print a stack trace if we signal out.
+ sys::PrintStackTraceOnErrorSignal();
+ PrettyStackTraceProgram X(argc, argv);
+
+ llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
try {
cl::ParseCommandLineOptions(argc, argv, "llvm .bc -> .ll disassembler\n");
- sys::PrintStackTraceOnErrorSignal();
std::ostream *Out = &std::cout; // Default to printing to stdout.
std::string ErrorMessage;
diff --git a/tools/llvm-extract/llvm-extract.cpp b/tools/llvm-extract/llvm-extract.cpp
index 360630b41d..014d231a29 100644
--- a/tools/llvm-extract/llvm-extract.cpp
+++ b/tools/llvm-extract/llvm-extract.cpp
@@ -20,6 +20,7 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/System/Signals.h"
#include <iostream>
#include <memory>
@@ -56,9 +57,12 @@ ExtractGlobal("glob", cl::desc("Specify global to extract"), cl::init(""),
cl::value_desc("global"));
int main(int argc, char **argv) {
- llvm_shutdown_obj X; // Call llvm_shutdown() on exit.
- cl::ParseCommandLineOptions(argc, argv, "llvm extractor\n");
+ // Print a stack trace if we signal out.
sys::PrintStackTraceOnErrorSignal();
+ PrettyStackTraceProgram X(argc, argv);
+
+ llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
+ cl::ParseCommandLineOptions(argc, argv, "llvm extractor\n");
std::auto_ptr<Module> M;
diff --git a/tools/llvm-ld/llvm-ld.cpp b/tools/llvm-ld/llvm-ld.cpp
index 28187c932d..fd2e0f7cac 100644
--- a/tools/llvm-ld/llvm-ld.cpp
+++ b/tools/llvm-ld/llvm-ld.cpp
@@ -33,6 +33,7 @@
#include "llvm/Support/FileUtilities.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Streams.h"
#include "llvm/Support/SystemUtils.h"
#include "llvm/System/Signals.h"
@@ -501,14 +502,17 @@ extern void Optimize(Module*);
}
int main(int argc, char **argv, char **envp) {
- llvm_shutdown_obj X; // Call llvm_shutdown() on exit.
+ // Print a stack trace if we signal out.
+ sys::PrintStackTraceOnErrorSignal();
+ PrettyStackTraceProgram X(argc, argv);
+
+ llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
try {
// Initial global variable above for convenience printing of program name.
progname = sys::Path(argv[0]).getBasename();
// Parse the command line options
cl::ParseCommandLineOptions(argc, argv, "llvm linker\n");
- sys::PrintStackTraceOnErrorSignal();
// Construct a Linker (now that Verbose is set)
Linker TheLinker(progname, OutputFilename, Verbose);
diff --git a/tools/llvm-link/llvm-link.cpp b/tools/llvm-link/llvm-link.cpp
index 8c6541ff0f..15850f4717 100644
--- a/tools/llvm-link/llvm-link.cpp
+++ b/tools/llvm-link/llvm-link.cpp
@@ -19,6 +19,7 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Streams.h"
#include "llvm/System/Signals.h"
#include "llvm/System/Path.h"
@@ -79,10 +80,12 @@ static inline std::auto_ptr<Module> LoadFile(const std::string &FN) {
}
int main(int argc, char **argv) {
- llvm_shutdown_obj X; // Call llvm_shutdown() on exit.
- cl::ParseCommandLineOptions(argc, argv, "llvm linker\n");
+ // Print a stack trace if we signal out.
sys::PrintStackTraceOnErrorSignal();
- assert(InputFilenames.size() > 0 && "OneOrMore is not working");
+ PrettyStackTraceProgram X(argc, argv);
+
+ llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
+ cl::ParseCommandLineOptions(argc, argv, "llvm linker\n");
unsigned BaseArg = 0;
std::string ErrorMessage;
diff --git a/tools/llvm-nm/llvm-nm.cpp b/tools/llvm-nm/llvm-nm.cpp
index ca4654d793..344951051e 100644
--- a/tools/llvm-nm/llvm-nm.cpp
+++ b/tools/llvm-nm/llvm-nm.cpp
@@ -22,6 +22,7 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/System/Signals.h"
#include <algorithm>
#include <cctype>
@@ -166,9 +167,12 @@ static void DumpSymbolNamesFromFile(std::string &Filename) {
}
int main(int argc, char **argv) {
- llvm_shutdown_obj X; // Call llvm_shutdown() on exit.
- cl::ParseCommandLineOptions(argc, argv, "llvm symbol table dumper\n");
+ // Print a stack trace if we signal out.
sys::PrintStackTraceOnErrorSignal();
+ PrettyStackTraceProgram X(argc, argv);
+
+ llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
+ cl::ParseCommandLineOptions(argc, argv, "llvm symbol table dumper\n");
ToolName = argv[0];
if (BSDFormat) OutputFormat = bsd;
diff --git a/tools/llvm-prof/llvm-prof.cpp b/tools/llvm-prof/llvm-prof.cpp
index 8149875218..119dc1a117 100644
--- a/tools/llvm-prof/llvm-prof.cpp
+++ b/tools/llvm-prof/llvm-prof.cpp
@@ -21,6 +21,7 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/System/Signals.h"
#include <algorithm>
@@ -111,10 +112,13 @@ namespace {
int main(int argc, char **argv) {
- llvm_shutdown_obj X; // Call llvm_shutdown() on exit.
+ // Print a stack trace if we signal out.
+ sys::PrintStackTraceOnErrorSignal();
+ PrettyStackTraceProgram X(argc, argv);
+
+ llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
try {
cl::ParseCommandLineOptions(argc, argv, "llvm profile dump decoder\n");
- sys::PrintStackTraceOnErrorSignal();
// Read in the bitcode file...
std::string ErrorMessage;
diff --git a/tools/llvm-ranlib/llvm-ranlib.cpp b/tools/llvm-ranlib/llvm-ranlib.cpp
index cd17be890a..72106104c0 100644
--- a/tools/llvm-ranlib/llvm-ranlib.cpp
+++ b/tools/llvm-ranlib/llvm-ranlib.cpp
@@ -15,6 +15,7 @@
#include "llvm/Bitcode/Archive.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ManagedStatic.h"
+#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/System/Signals.h"
#include <iostream>
#include <iomanip>
@@ -42,7 +43,11 @@ void printSymbolTable(Archive* TheArchive) {
}
int main(int argc, char **argv) {
- llvm_shutdown_obj X; // Call llvm_shutdown() on exit.
+ // Print a stack trace if we signal out.
+ llvm::sys::PrintStackTraceOnErrorSignal();
+ llvm::PrettyStackTraceProgram X(argc, argv);
+
+ llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
// Have the command line options parsed and handle things
// like --help and --version.
@@ -52,9 +57,6 @@ int main(int argc, char **argv) {
" to an LLVM archive file."
);
- // Print a stack trace if we signal out.
- sys::PrintStackTraceOnErrorSignal();
-
int exitCode = 0;
// Make sure we don't exit with "unhandled exception".
diff --git a/utils/TableGen/TableGen.cpp b/utils/TableGen/TableGen.cpp
index 98a188ed83..147db12cf1 100644
--- a/utils/TableGen/TableGen.cpp
+++ b/utils/TableGen/TableGen.cpp
@@ -22,6 +22,7 @@
#include "llvm/System/Signals.h"
#include "llvm/Support/FileUtilities.h"
#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/PrettyStackTrace.h"
#include "CallingConvEmitter.h"
#include "CodeEmitterGen.h"
#include "RegisterInfoEmitter.h"
@@ -130,6 +131,8 @@ static bool ParseFile(const std::string &Filename,
}
int main(int argc, char **argv) {
+ sys::PrintStackTraceOnErrorSignal();
+ PrettyStackTraceProgram X(argc, argv);
cl::ParseCommandLineOptions(argc, argv);
// Parse the input file.