[llvm] r199075 - [PM] Wire up support for printing assembly output from the opt command.

Chandler Carruth chandlerc at gmail.com
Sun Jan 12 21:16:45 PST 2014


Author: chandlerc
Date: Sun Jan 12 23:16:45 2014
New Revision: 199075

URL: http://llvm.org/viewvc/llvm-project?rev=199075&view=rev
Log:
[PM] Wire up support for printing assembly output from the opt command.
This lets us round-trip IR in the expected manner with the opt tool.

Modified:
    llvm/trunk/test/Other/new-pass-manager.ll
    llvm/trunk/tools/opt/NewPMDriver.cpp

Modified: llvm/trunk/test/Other/new-pass-manager.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/new-pass-manager.ll?rev=199075&r1=199074&r2=199075&view=diff
==============================================================================
--- llvm/trunk/test/Other/new-pass-manager.ll (original)
+++ llvm/trunk/test/Other/new-pass-manager.ll Sun Jan 12 23:16:45 2014
@@ -23,6 +23,12 @@
 ; CHECK-FUNCTION-PRINT: Finished function pass manager
 ; CHECK-FUNCTION-PRINT: Finished module pass manager
 
+; RUN: opt -S -o - -passes='no-op-module,no-op-module' %s \
+; RUN:     | FileCheck %s --check-prefix=CHECK-NOOP
+; CHECK-NOOP: define void @foo() {
+; CHECK-NOOP:   ret void
+; CHECK-NOOP: }
+
 define void @foo() {
   ret void
 }

Modified: llvm/trunk/tools/opt/NewPMDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/NewPMDriver.cpp?rev=199075&r1=199074&r2=199075&view=diff
==============================================================================
--- llvm/trunk/tools/opt/NewPMDriver.cpp (original)
+++ llvm/trunk/tools/opt/NewPMDriver.cpp Sun Jan 12 23:16:45 2014
@@ -16,10 +16,12 @@
 #include "NewPMDriver.h"
 #include "Passes.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/IR/IRPrintingPasses.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/PassManager.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/ToolOutputFile.h"
 
 using namespace llvm;
@@ -28,15 +30,26 @@ using namespace opt_tool;
 bool llvm::runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M,
                            tool_output_file *Out, StringRef PassPipeline,
                            OutputKind OK) {
-  // Before executing passes, print the final values of the LLVM options.
-  cl::PrintOptionValues();
-
   ModulePassManager MPM;
   if (!parsePassPipeline(MPM, PassPipeline)) {
     errs() << Arg0 << ": unable to parse pass pipeline description.\n";
     return false;
   }
 
+  // Add any relevant output pass at the end of the pipeline.
+  switch (OK) {
+  case OK_NoOutput:
+    break; // No output pass needed.
+  case OK_OutputAssembly:
+    MPM.addPass(PrintModulePass(Out->os()));
+    break;
+  case OK_OutputBitcode:
+    llvm::report_fatal_error("Bitcode output is not yet implemented!");
+  }
+
+  // Before executing passes, print the final values of the LLVM options.
+  cl::PrintOptionValues();
+
   // Now that we have all of the passes ready, run them.
   MPM.run(&M);
 





More information about the llvm-commits mailing list