[llvm-commits] [llvm] r112110 - /llvm/trunk/tools/llvm-extract/llvm-extract.cpp

Dan Gohman gohman at apple.com
Wed Aug 25 16:33:07 PDT 2010


Author: djg
Date: Wed Aug 25 18:33:07 2010
New Revision: 112110

URL: http://llvm.org/viewvc/llvm-project?rev=112110&view=rev
Log:
Convert llvm-extract to use lazy loading. This makes it substantially
faster on large modules.

Modified:
    llvm/trunk/tools/llvm-extract/llvm-extract.cpp

Modified: llvm/trunk/tools/llvm-extract/llvm-extract.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-extract/llvm-extract.cpp?rev=112110&r1=112109&r2=112110&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-extract/llvm-extract.cpp (original)
+++ llvm/trunk/tools/llvm-extract/llvm-extract.cpp Wed Aug 25 18:33:07 2010
@@ -71,9 +71,10 @@
   llvm_shutdown_obj Y;  // Call llvm_shutdown() on exit.
   cl::ParseCommandLineOptions(argc, argv, "llvm extractor\n");
 
+  // Use lazy loading, since we only care about selected global values.
   SMDiagnostic Err;
   std::auto_ptr<Module> M;
-  M.reset(ParseIRFile(InputFilename, Err, Context));
+  M.reset(getLazyIRFileModule(InputFilename, Err, Context));
 
   if (M.get() == 0) {
     Err.Print(argv[0], errs());
@@ -104,6 +105,18 @@
     GVs.push_back(GV);
   }
 
+  // Materialize requisite global values.
+  for (size_t i = 0, e = GVs.size(); i != e; ++i) {
+    GlobalValue *GV = GVs[i];
+    if (GV->isMaterializable()) {
+      std::string ErrInfo;
+      if (GV->Materialize(&ErrInfo)) {
+        errs() << argv[0] << ": error reading input: " << ErrInfo << "\n";
+        return 1;
+      }
+    }
+  }
+
   // In addition to deleting all other functions, we also want to spiff it
   // up a little bit.  Do this now.
   PassManager Passes;





More information about the llvm-commits mailing list