llvm-extract.cpp (212793) | llvm-extract.cpp (218885) |
---|---|
1//===- llvm-extract.cpp - LLVM function extraction utility ----------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// --- 9 unchanged lines hidden (view full) --- 18#include "llvm/Assembly/PrintModulePass.h" 19#include "llvm/Bitcode/ReaderWriter.h" 20#include "llvm/Transforms/IPO.h" 21#include "llvm/Target/TargetData.h" 22#include "llvm/Support/CommandLine.h" 23#include "llvm/Support/IRReader.h" 24#include "llvm/Support/ManagedStatic.h" 25#include "llvm/Support/PrettyStackTrace.h" | 1//===- llvm-extract.cpp - LLVM function extraction utility ----------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// --- 9 unchanged lines hidden (view full) --- 18#include "llvm/Assembly/PrintModulePass.h" 19#include "llvm/Bitcode/ReaderWriter.h" 20#include "llvm/Transforms/IPO.h" 21#include "llvm/Target/TargetData.h" 22#include "llvm/Support/CommandLine.h" 23#include "llvm/Support/IRReader.h" 24#include "llvm/Support/ManagedStatic.h" 25#include "llvm/Support/PrettyStackTrace.h" |
26#include "llvm/Support/raw_ostream.h" | 26#include "llvm/Support/ToolOutputFile.h" |
27#include "llvm/Support/SystemUtils.h" | 27#include "llvm/Support/SystemUtils.h" |
28#include "llvm/System/Signals.h" | 28#include "llvm/Support/Signals.h" 29#include "llvm/ADT/SmallPtrSet.h" |
29#include <memory> 30using namespace llvm; 31 32// InputFilename - The filename to read from. 33static cl::opt<std::string> 34InputFilename(cl::Positional, cl::desc("<input bitcode file>"), 35 cl::init("-"), cl::value_desc("filename")); 36 --- 60 unchanged lines hidden (view full) --- 97 errs() << argv[0] << ": program doesn't contain function named '" 98 << ExtractFuncs[i] << "'!\n"; 99 return 1; 100 } 101 GVs.push_back(GV); 102 } 103 104 // Materialize requisite global values. | 30#include <memory> 31using namespace llvm; 32 33// InputFilename - The filename to read from. 34static cl::opt<std::string> 35InputFilename(cl::Positional, cl::desc("<input bitcode file>"), 36 cl::init("-"), cl::value_desc("filename")); 37 --- 60 unchanged lines hidden (view full) --- 98 errs() << argv[0] << ": program doesn't contain function named '" 99 << ExtractFuncs[i] << "'!\n"; 100 return 1; 101 } 102 GVs.push_back(GV); 103 } 104 105 // Materialize requisite global values. |
105 for (size_t i = 0, e = GVs.size(); i != e; ++i) { 106 GlobalValue *GV = GVs[i]; 107 if (GV->isMaterializable()) { 108 std::string ErrInfo; 109 if (GV->Materialize(&ErrInfo)) { 110 errs() << argv[0] << ": error reading input: " << ErrInfo << "\n"; 111 return 1; | 106 if (!DeleteFn) 107 for (size_t i = 0, e = GVs.size(); i != e; ++i) { 108 GlobalValue *GV = GVs[i]; 109 if (GV->isMaterializable()) { 110 std::string ErrInfo; 111 if (GV->Materialize(&ErrInfo)) { 112 errs() << argv[0] << ": error reading input: " << ErrInfo << "\n"; 113 return 1; 114 } |
112 } 113 } | 115 } 116 } |
117 else { 118 // Deleting. Materialize every GV that's *not* in GVs. 119 SmallPtrSet<GlobalValue *, 8> GVSet(GVs.begin(), GVs.end()); 120 for (Module::global_iterator I = M->global_begin(), E = M->global_end(); 121 I != E; ++I) { 122 GlobalVariable *G = I; 123 if (!GVSet.count(G) && G->isMaterializable()) { 124 std::string ErrInfo; 125 if (G->Materialize(&ErrInfo)) { 126 errs() << argv[0] << ": error reading input: " << ErrInfo << "\n"; 127 return 1; 128 } 129 } 130 } 131 for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) { 132 Function *F = I; 133 if (!GVSet.count(F) && F->isMaterializable()) { 134 std::string ErrInfo; 135 if (F->Materialize(&ErrInfo)) { 136 errs() << argv[0] << ": error reading input: " << ErrInfo << "\n"; 137 return 1; 138 } 139 } 140 } |
|
114 } 115 116 // In addition to deleting all other functions, we also want to spiff it 117 // up a little bit. Do this now. 118 PassManager Passes; 119 Passes.add(new TargetData(M.get())); // Use correct TargetData 120 121 Passes.add(createGVExtractionPass(GVs, DeleteFn)); --- 26 unchanged lines hidden --- | 141 } 142 143 // In addition to deleting all other functions, we also want to spiff it 144 // up a little bit. Do this now. 145 PassManager Passes; 146 Passes.add(new TargetData(M.get())); // Use correct TargetData 147 148 Passes.add(createGVExtractionPass(GVs, DeleteFn)); --- 26 unchanged lines hidden --- |