diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2011-02-20 12:57:14 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2011-02-20 12:57:14 +0000 | 
| commit | cf099d11218cb6f6c5cce947d6738e347f07fb12 (patch) | |
| tree | d2b61ce94e654cb01a254d2195259db5f9cc3f3c /tools/llvm-extract/llvm-extract.cpp | |
| parent | 49011b52fcba02a6051957b84705159f52fae4e4 (diff) | |
Notes
Diffstat (limited to 'tools/llvm-extract/llvm-extract.cpp')
| -rw-r--r-- | tools/llvm-extract/llvm-extract.cpp | 45 | 
1 files changed, 36 insertions, 9 deletions
diff --git a/tools/llvm-extract/llvm-extract.cpp b/tools/llvm-extract/llvm-extract.cpp index 91a59e5a56da..8c2f43a4f7d2 100644 --- a/tools/llvm-extract/llvm-extract.cpp +++ b/tools/llvm-extract/llvm-extract.cpp @@ -23,9 +23,10 @@  #include "llvm/Support/IRReader.h"  #include "llvm/Support/ManagedStatic.h"  #include "llvm/Support/PrettyStackTrace.h" -#include "llvm/Support/raw_ostream.h" +#include "llvm/Support/ToolOutputFile.h"  #include "llvm/Support/SystemUtils.h" -#include "llvm/System/Signals.h" +#include "llvm/Support/Signals.h" +#include "llvm/ADT/SmallPtrSet.h"  #include <memory>  using namespace llvm; @@ -102,13 +103,39 @@ int main(int argc, char **argv) {    }    // 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; +  if (!DeleteFn) +    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; +        } +      } +    } +  else { +    // Deleting. Materialize every GV that's *not* in GVs. +    SmallPtrSet<GlobalValue *, 8> GVSet(GVs.begin(), GVs.end()); +    for (Module::global_iterator I = M->global_begin(), E = M->global_end(); +         I != E; ++I) { +      GlobalVariable *G = I; +      if (!GVSet.count(G) && G->isMaterializable()) { +        std::string ErrInfo; +        if (G->Materialize(&ErrInfo)) { +          errs() << argv[0] << ": error reading input: " << ErrInfo << "\n"; +          return 1; +        } +      } +    } +    for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) { +      Function *F = I; +      if (!GVSet.count(F) && F->isMaterializable()) { +        std::string ErrInfo; +        if (F->Materialize(&ErrInfo)) { +          errs() << argv[0] << ": error reading input: " << ErrInfo << "\n"; +          return 1; +        }        }      }    }  | 
