summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llc/llc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/tools/llc/llc.cpp')
-rw-r--r--llvm/tools/llc/llc.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp
index e219c948d26..252952bf70f 100644
--- a/llvm/tools/llc/llc.cpp
+++ b/llvm/tools/llc/llc.cpp
@@ -25,6 +25,8 @@
#include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/CodeGen/TargetPassConfig.h"
#include "llvm/IR/DataLayout.h"
+#include "llvm/IR/DiagnosticInfo.h"
+#include "llvm/IR/DiagnosticPrinter.h"
#include "llvm/IR/IRPrintingPasses.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/LegacyPassManager.h"
@@ -111,6 +113,11 @@ static cl::opt<bool> DiscardValueNames(
cl::desc("Discard names from Value (other than GlobalValue)."),
cl::init(false), cl::Hidden);
+static cl::opt<bool> ExitOnError(
+ "exit-on-error",
+ cl::desc("Exit as soon as an error is encountered."),
+ cl::init(false), cl::Hidden);
+
static int compileModule(char **, LLVMContext &);
static std::unique_ptr<tool_output_file>
@@ -181,6 +188,17 @@ GetOutputStream(const char *TargetName, Triple::OSType OS,
return FDOut;
}
+static void DiagnosticHandler(const DiagnosticInfo &DI, void *Context) {
+ bool *HasError = static_cast<bool *>(Context);
+ if (DI.getSeverity() == DS_Error)
+ *HasError = true;
+
+ DiagnosticPrinterRawOStream DP(errs());
+ errs() << LLVMContext::getDiagnosticMessagePrefix(DI.getSeverity()) << ": ";
+ DI.print(DP);
+ errs() << "\n";
+}
+
// main - Entry point for the llc compiler.
//
int main(int argc, char **argv) {
@@ -215,6 +233,12 @@ int main(int argc, char **argv) {
Context.setDiscardValueNames(DiscardValueNames);
+ // Set a diagnostic handler that doesn't exit on the first error
+ if (!ExitOnError) {
+ bool HasError = false;
+ Context.setDiagnosticHandler(DiagnosticHandler, &HasError);
+ }
+
// Compile the module TimeCompilations times to give better compile time
// metrics.
for (unsigned I = TimeCompilations; I; --I)
@@ -441,6 +465,12 @@ static int compileModule(char **argv, LLVMContext &Context) {
PM.run(*M);
+ if (!ExitOnError) {
+ auto HasError = *static_cast<bool *>(Context.getDiagnosticContext());
+ if (HasError)
+ return 1;
+ }
+
// Compare the two outputs and make sure they're the same
if (CompileTwice) {
if (Buffer.size() != CompileTwiceBuffer.size() ||
OpenPOWER on IntegriCloud