llvm.org GIT mirror llvm / be2d4e7
Fix llvm-extract -delete's lazy loading to materialize the functions that will not be deleted, rather than the ones that will. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@114614 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 10 years ago
2 changed file(s) with 56 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
0 ; RUN: llvm-extract -func foo -S < %s | FileCheck %s
1 ; RUN: llvm-extract -delete -func foo -S < %s | FileCheck --check-prefix=DELETE %s
2 ; RUN: llvm-as < %s > %t
3 ; RUN: llvm-extract -func foo -S %t | FileCheck %s
4 ; RUN: llvm-extract -delete -func foo -S %t | FileCheck --check-prefix=DELETE %s
5
6 ; llvm-extract uses lazy bitcode loading, so make sure it correctly reads
7 ; from bitcode files in addition to assembly files.
8
9 ; CHECK: define void @foo() {
10 ; CHECK: ret void
11 ; CHECK: }
12 ; DELETE: define void @bar() {
13 ; DELETE: ret void
14 ; DELETE: }
15
16 define void @foo() {
17 ret void
18 }
19 define void @bar() {
20 ret void
21 }
2525 #include "llvm/Support/raw_ostream.h"
2626 #include "llvm/Support/SystemUtils.h"
2727 #include "llvm/System/Signals.h"
28 #include "llvm/ADT/SmallPtrSet.h"
2829 #include
2930 using namespace llvm;
3031
101102 }
102103
103104 // Materialize requisite global values.
104 for (size_t i = 0, e = GVs.size(); i != e; ++i) {
105 GlobalValue *GV = GVs[i];
106 if (GV->isMaterializable()) {
107 std::string ErrInfo;
108 if (GV->Materialize(&ErrInfo)) {
109 errs() << argv[0] << ": error reading input: " << ErrInfo << "\n";
110 return 1;
105 if (!DeleteFn)
106 for (size_t i = 0, e = GVs.size(); i != e; ++i) {
107 GlobalValue *GV = GVs[i];
108 if (GV->isMaterializable()) {
109 std::string ErrInfo;
110 if (GV->Materialize(&ErrInfo)) {
111 errs() << argv[0] << ": error reading input: " << ErrInfo << "\n";
112 return 1;
113 }
114 }
115 }
116 else {
117 // Deleting. Materialize every GV that's *not* in GVs.
118 SmallPtrSet GVSet(GVs.begin(), GVs.end());
119 for (Module::global_iterator I = M->global_begin(), E = M->global_end();
120 I != E; ++I) {
121 GlobalVariable *G = I;
122 if (!GVSet.count(G) && G->isMaterializable()) {
123 std::string ErrInfo;
124 if (G->Materialize(&ErrInfo)) {
125 errs() << argv[0] << ": error reading input: " << ErrInfo << "\n";
126 return 1;
127 }
128 }
129 }
130 for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) {
131 Function *F = I;
132 if (!GVSet.count(F) && F->isMaterializable()) {
133 std::string ErrInfo;
134 if (F->Materialize(&ErrInfo)) {
135 errs() << argv[0] << ": error reading input: " << ErrInfo << "\n";
136 return 1;
137 }
111138 }
112139 }
113140 }