diff options
author | dim <dim@FreeBSD.org> | 2015-12-30 13:13:10 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2015-12-30 13:13:10 +0000 |
commit | 9b5bf5c4f53d65d6a48722d7410ed7cb15f5ba3a (patch) | |
tree | b466a4817f79516eb1df8eae92bccf62ecc84003 /contrib/llvm/tools/llvm-extract/llvm-extract.cpp | |
parent | f09a28d1de99fda4f5517fb12670fc36552f4927 (diff) | |
parent | e194cd6d03d91631334d9d5e55b506036f423cc8 (diff) | |
download | FreeBSD-src-9b5bf5c4f53d65d6a48722d7410ed7cb15f5ba3a.zip FreeBSD-src-9b5bf5c4f53d65d6a48722d7410ed7cb15f5ba3a.tar.gz |
Update llvm to trunk r256633.
Diffstat (limited to 'contrib/llvm/tools/llvm-extract/llvm-extract.cpp')
-rw-r--r-- | contrib/llvm/tools/llvm-extract/llvm-extract.cpp | 53 |
1 files changed, 25 insertions, 28 deletions
diff --git a/contrib/llvm/tools/llvm-extract/llvm-extract.cpp b/contrib/llvm/tools/llvm-extract/llvm-extract.cpp index 936496c..1da456d 100644 --- a/contrib/llvm/tools/llvm-extract/llvm-extract.cpp +++ b/contrib/llvm/tools/llvm-extract/llvm-extract.cpp @@ -222,45 +222,42 @@ int main(int argc, char **argv) { } } - // Materialize requisite global values. - if (!DeleteFn) - for (size_t i = 0, e = GVs.size(); i != e; ++i) { - GlobalValue *GV = GVs[i]; - if (std::error_code EC = GV->materialize()) { - errs() << argv[0] << ": error reading input: " << EC.message() << "\n"; - return 1; - } + auto Materialize = [&](GlobalValue &GV) { + if (std::error_code EC = GV.materialize()) { + errs() << argv[0] << ": error reading input: " << EC.message() << "\n"; + exit(1); } - else { + }; + + // Materialize requisite global values. + if (!DeleteFn) { + for (size_t i = 0, e = GVs.size(); i != e; ++i) + Materialize(*GVs[i]); + } 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)) { - if (std::error_code EC = G.materialize()) { - errs() << argv[0] << ": error reading input: " << EC.message() - << "\n"; - return 1; - } - } - } for (auto &F : *M) { - if (!GVSet.count(&F)) { - if (std::error_code EC = F.materialize()) { - errs() << argv[0] << ": error reading input: " << EC.message() - << "\n"; - return 1; - } - } + 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 |