Assert that we have all use/users in the getters.
[oota-llvm.git] / tools / llvm-extract / llvm-extract.cpp
index ca228da74d848914c0fedf9954a98f9e82b8d51c..1da456d33f52dd832fb3ba966d42f8ba929e06f8 100644 (file)
@@ -236,23 +236,28 @@ int main(int argc, char **argv) {
   } else {
     // Deleting. Materialize every GV that's *not* in GVs.
     SmallPtrSet<GlobalValue *, 8> GVSet(GVs.begin(), GVs.end());
-    for (auto &G : M->globals()) {
-      if (!GVSet.count(&G))
-        Materialize(G);
-    }
     for (auto &F : *M) {
       if (!GVSet.count(&F))
         Materialize(F);
     }
   }
 
+  {
+    std::vector<GlobalValue *> Gvs(GVs.begin(), GVs.end());
+    legacy::PassManager Extract;
+    Extract.add(createGVExtractionPass(Gvs, DeleteFn));
+    Extract.run(*M);
+
+    // Now that we have all the GVs we want, mark the module as fully
+    // materialized.
+    // FIXME: should the GVExtractionPass handle this?
+    M->materializeAll();
+  }
+
   // In addition to deleting all other functions, we also want to spiff it
   // up a little bit.  Do this now.
   legacy::PassManager Passes;
 
-  std::vector<GlobalValue*> Gvs(GVs.begin(), GVs.end());
-
-  Passes.add(createGVExtractionPass(Gvs, DeleteFn));
   if (!DeleteFn)
     Passes.add(createGlobalDCEPass());           // Delete unreachable globals
   Passes.add(createStripDeadDebugInfoPass());    // Remove dead debug info