[PM] Add an enum for describing the desired output strategy, and run
authorChandler Carruth <chandlerc@gmail.com>
Mon, 13 Jan 2014 03:08:40 +0000 (03:08 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Mon, 13 Jan 2014 03:08:40 +0000 (03:08 +0000)
that through the interface rather than a simple bool. This should allow
starting to wire up real output to round-trip IR through opt with the
new pass manager.

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

tools/opt/NewPMDriver.cpp
tools/opt/NewPMDriver.h
tools/opt/opt.cpp

index e577995e26030d8e549eb8a3f3fae1384f863cc1..b05da36d28121b5adb61c2c68e58f067f8bb8a3e 100644 (file)
 #include "llvm/Support/ToolOutputFile.h"
 
 using namespace llvm;
+using namespace opt_tool;
 
 bool llvm::runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M,
                            tool_output_file *Out, StringRef PassPipeline,
-                           bool NoOutput) {
+                           OutputKind OK) {
   // Before executing passes, print the final values of the LLVM options.
   cl::PrintOptionValues();
 
@@ -40,7 +41,7 @@ bool llvm::runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M,
   MPM.run(&M);
 
   // Declare success.
-  if (!NoOutput)
+  if (OK != OK_NoOutput)
     Out->keep();
   return true;
 }
index 17ac75be5494c0ecedc6a7f7c224201bf58a1f21..2ae1ad5d8383cf06d1e22e4d4066b7dc5a039263 100644 (file)
@@ -28,6 +28,14 @@ class LLVMContext;
 class Module;
 class tool_output_file;
 
+namespace opt_tool {
+enum OutputKind {
+  OK_NoOutput,
+  OK_OutputAssembly,
+  OK_OutputBitcode
+};
+}
+
 /// \brief Driver function to run the new pass manager over a module.
 ///
 /// This function only exists factored away from opt.cpp in order to prevent
@@ -36,7 +44,7 @@ class tool_output_file;
 /// when the transition finishes.
 bool runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M,
                      tool_output_file *Out, StringRef PassPipeline,
-                     bool NoOutput);
+                     opt_tool::OutputKind OK);
 }
 
 #endif
index 92b63bd830350cb8bc6b1f0841b4c95a42a061b6..c4ab3426509fc34e3b586d4ee3a719766c66b84c 100644 (file)
@@ -49,6 +49,7 @@
 #include <algorithm>
 #include <memory>
 using namespace llvm;
+using namespace opt_tool;
 
 // The OptimizationList is automatically populated with registered Passes by the
 // PassNameParser.
@@ -670,14 +671,19 @@ int main(int argc, char **argv) {
     if (CheckBitcodeOutputToConsole(Out->os(), !Quiet))
       NoOutput = true;
 
-  if (PassPipeline.getNumOccurrences() > 0)
+  if (PassPipeline.getNumOccurrences() > 0) {
+    OutputKind OK = OK_NoOutput;
+    if (!NoOutput)
+      OK = OutputAssembly ? OK_OutputAssembly : OK_OutputBitcode;
+
     // The user has asked to use the new pass manager and provided a pipeline
     // string. Hand off the rest of the functionality to the new code for that
     // layer.
     return runPassPipeline(argv[0], Context, *M.get(), Out.get(), PassPipeline,
-                           NoOutput)
+                           OK)
                ? 0
                : 1;
+  }
 
   // Create a PassManager to hold and optimize the collection of passes we are
   // about to build.