Eliminate duplicate or unneccesary #include's
[oota-llvm.git] / tools / llc / llc.cpp
index c4422adfbafc42803360d9adc26a0651651846b6..6f6ab2ade66a0baaa0e606eabd4083ed3e8153a0 100644 (file)
 #include "llvm/Transforms/Instrumentation/TraceValues.h"
 #include "llvm/Transforms/ChangeAllocations.h"
 #include "llvm/Transforms/HoistPHIConstants.h"
+#include "llvm/Transforms/Scalar/DecomposeMultiDimRefs.h"
 #include "llvm/Assembly/PrintModulePass.h"
 #include "llvm/Bytecode/WriteBytecodePass.h"
 #include "llvm/Transforms/ConstantMerge.h"
 #include "llvm/Module.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
 #include "llvm/PassManager.h"
 #include "Support/CommandLine.h"
+#include "Support/Signals.h"
 #include <memory>
-#include <string>
 #include <fstream>
 using std::string;
 
@@ -28,13 +29,13 @@ static cl::Flag   Force         ("f", "Overwrite output files");
 static cl::Flag   DumpAsm       ("d", "Print bytecode before native code generation", cl::Hidden);
 
 enum TraceLevel {
-  TraceOff, TraceMethods, TraceBasicBlocks
+  TraceOff, TraceFunctions, TraceBasicBlocks
 };
 
 static cl::Enum<enum TraceLevel> TraceValues("trace", cl::NoFlags,
-  "Trace values through methods or basic blocks",
+  "Trace values through functions or basic blocks",
   clEnumValN(TraceOff        , "off",        "Disable trace code"),
-  clEnumValN(TraceMethods    , "method",     "Trace each method"),
+  clEnumValN(TraceFunctions  , "function",   "Trace each function"),
   clEnumValN(TraceBasicBlocks, "basicblock", "Trace each basic block"), 0);
 
 
@@ -82,18 +83,23 @@ int main(int argc, char **argv) {
   Passes.add(createHoistPHIConstantsPass());
 
   if (TraceValues != TraceOff) {   // If tracing enabled...
-    // Insert trace code in all methods in the module
+    // Insert trace code in all functions in the module
     if (TraceValues == TraceBasicBlocks)
       Passes.add(createTraceValuesPassForBasicBlocks());
-    else if (TraceValues == TraceMethods)
-      Passes.add(createTraceValuesPassForMethod());
+    else if (TraceValues == TraceFunctions)
+      Passes.add(createTraceValuesPassForFunction());
     else
       assert(0 && "Bad value for TraceValues!");
 
     // Eliminate duplication in constant pool
     Passes.add(createDynamicConstantMergePass());
-      
-    // Then write out the module with tracing code before code generation 
+  }
+  
+  // Decompose multi-dimensional refs into a sequence of 1D refs
+  Passes.add(createDecomposeMultiDimRefsPass());
+  
+  // Write out the module with tracing code just before code generation
+  if (TraceValues != TraceOff) {   // If tracing enabled...
     assert(InputFilename != "-" &&
            "files on stdin not supported with tracing");
     string traceFileName = GetFileNameRoot(InputFilename) + ".trace.bc";
@@ -104,7 +110,7 @@ int main(int argc, char **argv) {
            << "Use -f command line argument to force output\n";
       return 1;
     }
-
+    
     std::ostream *os = new std::ofstream(traceFileName.c_str());
     if (!os->good()) {
       cerr << "Error opening " << traceFileName
@@ -123,7 +129,7 @@ int main(int argc, char **argv) {
   
   // If LLVM dumping after transformations is requested, add it to the pipeline
   if (DumpAsm)
-    Passes.add(new PrintMethodPass("Code after xformations: \n", &cerr));
+    Passes.add(new PrintFunctionPass("Code after xformations: \n", &cerr));
 
   // Figure out where we are going to send the output...
   std::ostream *Out = 0;
@@ -135,6 +141,10 @@ int main(int argc, char **argv) {
       return 1;
     }
     Out = new std::ofstream(OutputFilename.c_str());
+
+    // Make sure that the Out file gets unlink'd from the disk if we get a
+    // SIGINT
+    RemoveFileOnSignal(OutputFilename);
   } else {
     if (InputFilename == "-") {
       OutputFilename = "-";
@@ -156,6 +166,9 @@ int main(int argc, char **argv) {
         delete Out;
         return 1;
       }
+      // Make sure that the Out file gets unlink'd from the disk if we get a
+      // SIGINT
+      RemoveFileOnSignal(OutputFilename);
     }
   }