[llvm-commits] CVS: llvm/tools/llc/llc.cpp

Chris Lattner lattner at cs.uiuc.edu
Sun Sep 3 21:15:22 PDT 2006



Changes in directory llvm/tools/llc:

llc.cpp updated: 1.139 -> 1.140
---
Log message:

Completely rearchitect the interface between targets and the pass manager.
This pass:

1. Splits TargetMachine into TargetMachine (generic targets, can be implemented
any way, like the CBE) and LLVMTargetMachine (subclass of TM that is used by
things using libcodegen and other support).
2. Instead of having each target fully populate the passmgr for file or JIT
   output, move all this to common code, and give targets hooks they can
   implement.
3. Commonalize the target population stuff between file emission and JIT
   emission.
4. All (native code) codegen stuff now happens in a FunctionPassManager, which
   paves the way for "fast -O0" stuff in the CFE later, and now LLC could
   lazily stream .bc files from disk to use less memory.
5. There are now many fewer #includes and the targets don't depend on the 
   scalar xforms or libanalysis anymore (but codegen does).
6. Changing common code generator pass ordering stuff no longer requires 
   touching all targets.
7. The JIT now has the option of "-fast" codegen or normal optimized codegen,
   which is now orthogonal to the fact that JIT'ing is being done.


---
Diffs of the changes:  (+110 -79)

 llc.cpp |  189 +++++++++++++++++++++++++++++++++++++---------------------------
 1 files changed, 110 insertions(+), 79 deletions(-)


Index: llvm/tools/llc/llc.cpp
diff -u llvm/tools/llc/llc.cpp:1.139 llvm/tools/llc/llc.cpp:1.140
--- llvm/tools/llc/llc.cpp:1.139	Sun Sep  3 13:38:30 2006
+++ llvm/tools/llc/llc.cpp	Sun Sep  3 23:14:57 2006
@@ -101,6 +101,69 @@
   return outputFilename;
 }
 
+static std::ostream *GetOutputStream(const char *ProgName) {
+  if (OutputFilename != "") {
+    if (OutputFilename == "-")
+      return &std::cout;
+
+    // Specified an output filename?
+    if (!Force && std::ifstream(OutputFilename.c_str())) {
+      // If force is not specified, make sure not to overwrite a file!
+      std::cerr << ProgName << ": error opening '" << OutputFilename
+                << "': file exists!\n"
+                << "Use -f command line argument to force output\n";
+      return 0;
+    }
+    // Make sure that the Out file gets unlinked from the disk if we get a
+    // SIGINT
+    sys::RemoveFileOnSignal(sys::Path(OutputFilename));
+
+    return new std::ofstream(OutputFilename.c_str());
+  }
+  
+  if (InputFilename == "-") {
+    OutputFilename = "-";
+    return &std::cout;
+  }
+
+  OutputFilename = GetFileNameRoot(InputFilename);
+    
+  switch (FileType) {
+  case TargetMachine::AssemblyFile:
+    if (MArch->Name[0] != 'c' || MArch->Name[1] != 0)  // not CBE
+      OutputFilename += ".s";
+    else
+      OutputFilename += ".cbe.c";
+    break;
+  case TargetMachine::ObjectFile:
+    OutputFilename += ".o";
+    break;
+  case TargetMachine::DynamicLibrary:
+    OutputFilename += LTDL_SHLIB_EXT;
+    break;
+  }
+  
+  if (!Force && std::ifstream(OutputFilename.c_str())) {
+    // If force is not specified, make sure not to overwrite a file!
+    std::cerr << ProgName << ": error opening '" << OutputFilename
+                          << "': file exists!\n"
+                          << "Use -f command line argument to force output\n";
+    return 0;
+  }
+  
+  // Make sure that the Out file gets unlinked from the disk if we get a
+  // SIGINT
+  sys::RemoveFileOnSignal(sys::Path(OutputFilename));
+  
+  std::ostream *Out = new std::ofstream(OutputFilename.c_str());
+  if (!Out->good()) {
+    std::cerr << ProgName << ": error opening " << OutputFilename << "!\n";
+    delete Out;
+    return 0;
+  }
+  
+  return Out;
+}
 
 // main - Entry point for the llc compiler.
 //
@@ -148,91 +211,59 @@
     assert(target.get() && "Could not allocate target machine!");
     TargetMachine &Target = *target.get();
 
-    // Build up all of the passes that we want to do to the module...
-    PassManager Passes;
-    Passes.add(new TargetData(*Target.getTargetData()));
-
-#ifndef NDEBUG
-    if(!NoVerify)
-      Passes.add(createVerifierPass());
-#endif
-
     // Figure out where we are going to send the output...
-    std::ostream *Out = 0;
-    if (OutputFilename != "") {
-      if (OutputFilename != "-") {
-        // Specified an output filename?
-        if (!Force && std::ifstream(OutputFilename.c_str())) {
-          // If force is not specified, make sure not to overwrite a file!
-          std::cerr << argv[0] << ": error opening '" << OutputFilename
-                    << "': file exists!\n"
-                    << "Use -f command line argument to force output\n";
-          return 1;
-        }
-        Out = new std::ofstream(OutputFilename.c_str());
-
-        // Make sure that the Out file gets unlinked from the disk if we get a
-        // SIGINT
-        sys::RemoveFileOnSignal(sys::Path(OutputFilename));
-      } else {
-        Out = &std::cout;
+    std::ostream *Out = GetOutputStream(argv[0]);
+    if (Out == 0) return 1;
+    
+    // If this target requires addPassesToEmitWholeFile, do it now.  This is
+    // used by strange things like the C backend.
+    if (Target.WantsWholeFile()) {
+      PassManager PM;
+      PM.add(new TargetData(*Target.getTargetData()));
+      if (!NoVerify)
+        PM.add(createVerifierPass());
+      
+      // Ask the target to add backend passes as necessary.
+      if (Target.addPassesToEmitWholeFile(PM, *Out, FileType, Fast)) {
+        std::cerr << argv[0] << ": target does not support generation of this"
+                  << " file type!\n";
+        if (Out != &std::cout) delete Out;
+        // And the Out file is empty and useless, so remove it now.
+        sys::Path(OutputFilename).eraseFromDisk();
+        return 1;
       }
+      PM.run(mod);
     } else {
-      if (InputFilename == "-") {
-        OutputFilename = "-";
-        Out = &std::cout;
-      } else {
-        OutputFilename = GetFileNameRoot(InputFilename);
-
-        switch (FileType) {
-        case TargetMachine::AssemblyFile:
-          if (MArch->Name[0] != 'c' || MArch->Name[1] != 0)  // not CBE
-            OutputFilename += ".s";
-          else
-            OutputFilename += ".cbe.c";
-          break;
-        case TargetMachine::ObjectFile:
-          OutputFilename += ".o";
-          break;
-        case TargetMachine::DynamicLibrary:
-          OutputFilename += LTDL_SHLIB_EXT;
-          break;
-        }
-
-        if (!Force && std::ifstream(OutputFilename.c_str())) {
-          // If force is not specified, make sure not to overwrite a file!
-          std::cerr << argv[0] << ": error opening '" << OutputFilename
-                    << "': file exists!\n"
-                    << "Use -f command line argument to force output\n";
-          return 1;
-        }
-
-        Out = new std::ofstream(OutputFilename.c_str());
-        if (!Out->good()) {
-          std::cerr << argv[0] << ": error opening " << OutputFilename << "!\n";
-          delete Out;
-          return 1;
-        }
-
-        // Make sure that the Out file gets unlinked from the disk if we get a
-        // SIGINT
-        sys::RemoveFileOnSignal(sys::Path(OutputFilename));
+      // Build up all of the passes that we want to do to the module.
+      FunctionPassManager Passes(new ExistingModuleProvider(M.get()));
+      Passes.add(new TargetData(*Target.getTargetData()));
+      
+#ifndef NDEBUG
+      if (!NoVerify)
+        Passes.add(createVerifierPass());
+#endif
+    
+      // Ask the target to add backend passes as necessary.
+      if (Target.addPassesToEmitFile(Passes, *Out, FileType, Fast)) {
+        std::cerr << argv[0] << ": target does not support generation of this"
+                  << " file type!\n";
+        if (Out != &std::cout) delete Out;
+        // And the Out file is empty and useless, so remove it now.
+        sys::Path(OutputFilename).eraseFromDisk();
+        return 1;
       }
-    }
-
-    // Ask the target to add backend passes as necessary.
-    if (Target.addPassesToEmitFile(Passes, *Out, FileType, Fast)) {
-      std::cerr << argv[0] << ": target does not support generation of this"
-                << " file type!\n";
-      if (Out != &std::cout) delete Out;
-      // And the Out file is empty and useless, so remove it now.
-      sys::Path(OutputFilename).eraseFromDisk();
-      return 1;
-    } else {
+    
+      Passes.doInitialization();
+    
       // Run our queue of passes all at once now, efficiently.
-      Passes.run(*M.get());
+      // TODO: this could lazily stream functions out of the module.
+      for (Module::iterator I = mod.begin(), E = mod.end(); I != E; ++I)
+        if (!I->isExternal())
+          Passes.run(*I);
+      
+      Passes.doFinalization();
     }
-
+      
     // Delete the ostream if it's not a stdout stream
     if (Out != &std::cout) delete Out;
 






More information about the llvm-commits mailing list