[PM] Wire up support for printing assembly output from the opt command.
authorChandler Carruth <chandlerc@gmail.com>
Mon, 13 Jan 2014 05:16:45 +0000 (05:16 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Mon, 13 Jan 2014 05:16:45 +0000 (05:16 +0000)
This lets us round-trip IR in the expected manner with the opt tool.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199075 91177308-0d34-0410-b5e6-96231b3b80d8

test/Other/new-pass-manager.ll
tools/opt/NewPMDriver.cpp

index 48b97624b80418a961183329e3f1235f1eb20743..d7cfb5ec7a4028e128b0bc08f2f4245c8b2cf3ad 100644 (file)
 ; 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
 }
index b05da36d28121b5adb61c2c68e58f067f8bb8a3e..c7534e794a4e71c5bcca8e989fae6a68c86ae1fd 100644 (file)
 #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);