Skip to content

Commit 5746e1f

Browse files
committed
Add patch from http://reviews.llvm.org/D17165 to fix replutil test
Add http://reviews.llvm.org/D18583 as well Concatenate the two patches together
1 parent b12ea96 commit 5746e1f

File tree

2 files changed

+227
-0
lines changed

2 files changed

+227
-0
lines changed

deps/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,8 @@ $(eval $(call LLVM_PATCH,llvm-D14260))
726726
$(eval $(call LLVM_PATCH,llvm-3.8.0_winshlib))
727727
# Cygwin and openSUSE still use win32-threads mingw, https://llvm.org/bugs/show_bug.cgi?id=26365
728728
$(eval $(call LLVM_PATCH,llvm-3.8.0_threads))
729+
# fix replutil test on unix
730+
$(eval $(call LLVM_PATCH,llvm-D17165-D18583))
729731
endif # LLVM_VER
730732

731733
ifeq ($(LLVM_VER),3.7.1)

deps/llvm-D17165-D18583.patch

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
From 11adcc4de0797c83e61ae0240927f0bafcf041a9 Mon Sep 17 00:00:00 2001
2+
From: Keno Fischer <[email protected]>
3+
Date: Sat, 13 Feb 2016 02:04:29 +0000
4+
Subject: [PATCH] [Cloning] Clone every Function's Debug Info
5+
6+
Summary:
7+
Export the CloneDebugInfoMetadata utility, which clones all debug info
8+
associated with a function into the first module. Also use this function
9+
in CloneModule on each function we clone (the CloneFunction entrypoint
10+
already does this).
11+
12+
Without this, cloning a module will lead to DI quality regressions,
13+
especially since r252219 reversed the Function <-> DISubprogram edge
14+
(before we could get lucky and have this edge preserved if the
15+
DISubprogram itself was, e.g. due to location metadata).
16+
17+
This was verified to fix missing debug information in julia and
18+
a unittest to verify the new behavior is included.
19+
20+
Patch by Yichao Yu! Thanks!
21+
22+
Reviewers: loladiro, pcc
23+
Differential Revision: http://reviews.llvm.org/D17165
24+
25+
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@260791 91177308-0d34-0410-b5e6-96231b3b80d8
26+
---
27+
include/llvm/Transforms/Utils/Cloning.h | 5 +++++
28+
lib/Transforms/Utils/CloneFunction.cpp | 4 ++--
29+
lib/Transforms/Utils/CloneModule.cpp | 1 +
30+
unittests/Transforms/Utils/Cloning.cpp | 25 +++++++++++++++++++++++++
31+
4 files changed, 33 insertions(+), 2 deletions(-)
32+
33+
diff --git a/include/llvm/Transforms/Utils/Cloning.h b/include/llvm/Transforms/Utils/Cloning.h
34+
index 4f006f2..0bae2bd 100644
35+
--- a/include/llvm/Transforms/Utils/Cloning.h
36+
+++ b/include/llvm/Transforms/Utils/Cloning.h
37+
@@ -130,6 +130,11 @@ Function *CloneFunction(const Function *F, ValueToValueMapTy &VMap,
38+
bool ModuleLevelChanges,
39+
ClonedCodeInfo *CodeInfo = nullptr);
40+
41+
+/// Clone the module-level debug info associated with OldFunc. The cloned data
42+
+/// will point to NewFunc instead.
43+
+void CloneDebugInfoMetadata(Function *NewFunc, const Function *OldFunc,
44+
+ ValueToValueMapTy &VMap);
45+
+
46+
/// Clone OldFunc into NewFunc, transforming the old arguments into references
47+
/// to VMap values. Note that if NewFunc already has basic blocks, the ones
48+
/// cloned into it will be added to the end of the function. This function
49+
diff --git a/lib/Transforms/Utils/CloneFunction.cpp b/lib/Transforms/Utils/CloneFunction.cpp
50+
index 6454afb..8b5692a 100644
51+
--- a/lib/Transforms/Utils/CloneFunction.cpp
52+
+++ b/lib/Transforms/Utils/CloneFunction.cpp
53+
@@ -187,8 +187,8 @@ static void AddOperand(DICompileUnit *CU, DISubprogramArray SPs,
54+
55+
// Clone the module-level debug info associated with OldFunc. The cloned data
56+
// will point to NewFunc instead.
57+
-static void CloneDebugInfoMetadata(Function *NewFunc, const Function *OldFunc,
58+
- ValueToValueMapTy &VMap) {
59+
+void llvm::CloneDebugInfoMetadata(Function *NewFunc, const Function *OldFunc,
60+
+ ValueToValueMapTy &VMap) {
61+
DebugInfoFinder Finder;
62+
Finder.processModule(*OldFunc->getParent());
63+
64+
diff --git a/lib/Transforms/Utils/CloneModule.cpp b/lib/Transforms/Utils/CloneModule.cpp
65+
index 53de62a..b16a02a 100644
66+
--- a/lib/Transforms/Utils/CloneModule.cpp
67+
+++ b/lib/Transforms/Utils/CloneModule.cpp
68+
@@ -136,6 +136,7 @@ std::unique_ptr<Module> llvm::CloneModule(
69+
VMap[&*J] = &*DestI++;
70+
}
71+
72+
+ CloneDebugInfoMetadata(F, &*I, VMap);
73+
SmallVector<ReturnInst*, 8> Returns; // Ignore returns cloned.
74+
CloneFunctionInto(F, &*I, VMap, /*ModuleLevelChanges=*/true, Returns);
75+
}
76+
diff --git a/unittests/Transforms/Utils/Cloning.cpp b/unittests/Transforms/Utils/Cloning.cpp
77+
index 25e322e..b761e4e 100644
78+
--- a/unittests/Transforms/Utils/Cloning.cpp
79+
+++ b/unittests/Transforms/Utils/Cloning.cpp
80+
@@ -423,6 +423,7 @@ class CloneModule : public ::testing::Test {
81+
void SetupModule() { OldM = new Module("", C); }
82+
83+
void CreateOldModule() {
84+
+ DIBuilder DBuilder(*OldM);
85+
IRBuilder<> IBuilder(C);
86+
87+
auto *FuncType = FunctionType::get(Type::getVoidTy(C), false);
88+
@@ -431,9 +432,25 @@ class CloneModule : public ::testing::Test {
89+
auto *F =
90+
Function::Create(FuncType, GlobalValue::PrivateLinkage, "f", OldM);
91+
F->setPersonalityFn(PersFn);
92+
+
93+
+ // Create debug info
94+
+ auto *File = DBuilder.createFile("filename.c", "/file/dir/");
95+
+ DITypeRefArray ParamTypes = DBuilder.getOrCreateTypeArray(None);
96+
+ DISubroutineType *DFuncType = DBuilder.createSubroutineType(ParamTypes);
97+
+ auto *CU =
98+
+ DBuilder.createCompileUnit(dwarf::DW_LANG_C99, "filename.c",
99+
+ "/file/dir", "CloneModule", false, "", 0);
100+
+ // Function DI
101+
+ auto *Subprogram = DBuilder.createFunction(CU, "f", "f", File, 4, DFuncType,
102+
+ true, true, 3, 0, false);
103+
+ F->setSubprogram(Subprogram);
104+
+
105+
auto *Entry = BasicBlock::Create(C, "", F);
106+
IBuilder.SetInsertPoint(Entry);
107+
IBuilder.CreateRetVoid();
108+
+
109+
+ // Finalize the debug info
110+
+ DBuilder.finalize();
111+
}
112+
113+
void CreateNewModule() { NewM = llvm::CloneModule(OldM).release(); }
114+
@@ -447,4 +464,12 @@ TEST_F(CloneModule, Verify) {
115+
EXPECT_FALSE(verifyModule(*NewM));
116+
}
117+
118+
+TEST_F(CloneModule, Subprogram) {
119+
+ Function *NewF = NewM->getFunction("f");
120+
+ DISubprogram *SP = NewF->getSubprogram();
121+
+ EXPECT_TRUE(SP != nullptr);
122+
+ EXPECT_EQ(SP->getName(), "f");
123+
+ EXPECT_EQ(SP->getFile()->getFilename(), "filename.c");
124+
+ EXPECT_EQ(SP->getLine(), (unsigned)4);
125+
+}
126+
}
127+
From af289e04413504c3bdc252e08c3fe17bf7ea6dc8 Mon Sep 17 00:00:00 2001
128+
From: Peter Collingbourne <[email protected]>
129+
Date: Wed, 30 Mar 2016 22:05:13 +0000
130+
Subject: [PATCH] Cloning: Reduce complexity of debug info cloning and fix
131+
correctness issue.
132+
133+
Commit r260791 contained an error in that it would introduce a cross-module
134+
reference in the old module. It also introduced O(N^2) complexity in the
135+
module cloner by requiring the entire module to be visited for each function.
136+
Fix both of these problems by avoiding use of the CloneDebugInfoMetadata
137+
function (which is only designed to do intra-module cloning) and cloning
138+
function-attached metadata in the same way that we clone all other metadata.
139+
140+
Differential Revision: http://reviews.llvm.org/D18583
141+
142+
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@264935 91177308-0d34-0410-b5e6-96231b3b80d8
143+
---
144+
include/llvm/Transforms/Utils/Cloning.h | 5 -----
145+
lib/Transforms/Utils/CloneFunction.cpp | 13 +++++++++++--
146+
lib/Transforms/Utils/CloneModule.cpp | 1 -
147+
unittests/Transforms/Utils/Cloning.cpp | 6 ++++++
148+
4 files changed, 17 insertions(+), 8 deletions(-)
149+
150+
diff --git a/include/llvm/Transforms/Utils/Cloning.h b/include/llvm/Transforms/Utils/Cloning.h
151+
index 0bae2bd..4f006f2 100644
152+
--- a/include/llvm/Transforms/Utils/Cloning.h
153+
+++ b/include/llvm/Transforms/Utils/Cloning.h
154+
@@ -130,11 +130,6 @@ Function *CloneFunction(const Function *F, ValueToValueMapTy &VMap,
155+
bool ModuleLevelChanges,
156+
ClonedCodeInfo *CodeInfo = nullptr);
157+
158+
-/// Clone the module-level debug info associated with OldFunc. The cloned data
159+
-/// will point to NewFunc instead.
160+
-void CloneDebugInfoMetadata(Function *NewFunc, const Function *OldFunc,
161+
- ValueToValueMapTy &VMap);
162+
-
163+
/// Clone OldFunc into NewFunc, transforming the old arguments into references
164+
/// to VMap values. Note that if NewFunc already has basic blocks, the ones
165+
/// cloned into it will be added to the end of the function. This function
166+
diff --git a/lib/Transforms/Utils/CloneFunction.cpp b/lib/Transforms/Utils/CloneFunction.cpp
167+
index 05b0a17..8e1715a 100644
168+
--- a/lib/Transforms/Utils/CloneFunction.cpp
169+
+++ b/lib/Transforms/Utils/CloneFunction.cpp
170+
@@ -119,6 +119,15 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
171+
.addAttributes(NewFunc->getContext(), AttributeSet::FunctionIndex,
172+
OldAttrs.getFnAttributes()));
173+
174+
+ SmallVector<std::pair<unsigned, MDNode *>, 1> MDs;
175+
+ OldFunc->getAllMetadata(MDs);
176+
+ for (auto MD : MDs)
177+
+ NewFunc->setMetadata(
178+
+ MD.first,
179+
+ MapMetadata(MD.second, VMap,
180+
+ ModuleLevelChanges ? RF_None : RF_NoModuleLevelChanges,
181+
+ TypeMapper, Materializer));
182+
+
183+
// Loop over all of the basic blocks in the function, cloning them as
184+
// appropriate. Note that we save BE this way in order to handle cloning of
185+
// recursive functions into themselves.
186+
@@ -187,8 +196,8 @@ static void AddOperand(DICompileUnit *CU, DISubprogramArray SPs,
187+
188+
// Clone the module-level debug info associated with OldFunc. The cloned data
189+
// will point to NewFunc instead.
190+
-void llvm::CloneDebugInfoMetadata(Function *NewFunc, const Function *OldFunc,
191+
- ValueToValueMapTy &VMap) {
192+
+static void CloneDebugInfoMetadata(Function *NewFunc, const Function *OldFunc,
193+
+ ValueToValueMapTy &VMap) {
194+
DebugInfoFinder Finder;
195+
Finder.processModule(*OldFunc->getParent());
196+
197+
diff --git a/lib/Transforms/Utils/CloneModule.cpp b/lib/Transforms/Utils/CloneModule.cpp
198+
index 494e275..929f51b 100644
199+
--- a/lib/Transforms/Utils/CloneModule.cpp
200+
+++ b/lib/Transforms/Utils/CloneModule.cpp
201+
@@ -138,7 +138,6 @@ std::unique_ptr<Module> llvm::CloneModule(
202+
VMap[&*J] = &*DestI++;
203+
}
204+
205+
- CloneDebugInfoMetadata(F, &*I, VMap);
206+
SmallVector<ReturnInst*, 8> Returns; // Ignore returns cloned.
207+
CloneFunctionInto(F, &*I, VMap, /*ModuleLevelChanges=*/true, Returns);
208+
}
209+
diff --git a/unittests/Transforms/Utils/Cloning.cpp b/unittests/Transforms/Utils/Cloning.cpp
210+
index b761e4e..f06a20f 100644
211+
--- a/unittests/Transforms/Utils/Cloning.cpp
212+
+++ b/unittests/Transforms/Utils/Cloning.cpp
213+
@@ -464,6 +464,12 @@ TEST_F(CloneModule, Verify) {
214+
EXPECT_FALSE(verifyModule(*NewM));
215+
}
216+
217+
+TEST_F(CloneModule, OldModuleUnchanged) {
218+
+ DebugInfoFinder Finder;
219+
+ Finder.processModule(*OldM);
220+
+ EXPECT_EQ(1U, Finder.subprogram_count());
221+
+}
222+
+
223+
TEST_F(CloneModule, Subprogram) {
224+
Function *NewF = NewM->getFunction("f");
225+
DISubprogram *SP = NewF->getSubprogram();

0 commit comments

Comments
 (0)