|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
From 11adcc4de0797c83e61ae0240927f0bafcf041a9 Mon Sep 17 00:00:00 2001
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
From: Keno Fischer <kfischer@college.harvard.edu>
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
Date: Sat, 13 Feb 2016 02:04:29 +0000
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
Subject: [PATCH] [Cloning] Clone every Function's Debug Info
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
Summary:
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
Export the CloneDebugInfoMetadata utility, which clones all debug info
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
associated with a function into the first module. Also use this function
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
in CloneModule on each function we clone (the CloneFunction entrypoint
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
already does this).
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
Without this, cloning a module will lead to DI quality regressions,
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
especially since r252219 reversed the Function <-> DISubprogram edge
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
(before we could get lucky and have this edge preserved if the
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
DISubprogram itself was, e.g. due to location metadata).
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
This was verified to fix missing debug information in julia and
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
a unittest to verify the new behavior is included.
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
Patch by Yichao Yu! Thanks!
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
Reviewers: loladiro, pcc
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
Differential Revision: http://reviews.llvm.org/D17165
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@260791 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
Alpine maintainer notes:
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
- Corresponds to llvm-D17165-D18583.patch in Julia.
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
---
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
include/llvm/Transforms/Utils/Cloning.h | 5 +++++
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
lib/Transforms/Utils/CloneFunction.cpp | 4 ++--
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
lib/Transforms/Utils/CloneModule.cpp | 1 +
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
unittests/Transforms/Utils/Cloning.cpp | 25 +++++++++++++++++++++++++
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
4 files changed, 33 insertions(+), 2 deletions(-)
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
diff --git a/include/llvm/Transforms/Utils/Cloning.h b/include/llvm/Transforms/Utils/Cloning.h
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
index 4f006f2..0bae2bd 100644
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
--- a/include/llvm/Transforms/Utils/Cloning.h
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+++ b/include/llvm/Transforms/Utils/Cloning.h
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
@@ -130,6 +130,11 @@ Function *CloneFunction(const Function *F, ValueToValueMapTy &VMap,
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
bool ModuleLevelChanges,
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
ClonedCodeInfo *CodeInfo = nullptr);
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+/// Clone the module-level debug info associated with OldFunc. The cloned data
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+/// will point to NewFunc instead.
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+void CloneDebugInfoMetadata(Function *NewFunc, const Function *OldFunc,
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+ ValueToValueMapTy &VMap);
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
/// Clone OldFunc into NewFunc, transforming the old arguments into references
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
/// to VMap values. Note that if NewFunc already has basic blocks, the ones
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
/// cloned into it will be added to the end of the function. This function
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
diff --git a/lib/Transforms/Utils/CloneFunction.cpp b/lib/Transforms/Utils/CloneFunction.cpp
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
index 6454afb..8b5692a 100644
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
--- a/lib/Transforms/Utils/CloneFunction.cpp
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+++ b/lib/Transforms/Utils/CloneFunction.cpp
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
@@ -187,8 +187,8 @@ static void AddOperand(DICompileUnit *CU, DISubprogramArray SPs,
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
// Clone the module-level debug info associated with OldFunc. The cloned data
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
// will point to NewFunc instead.
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
-static void CloneDebugInfoMetadata(Function *NewFunc, const Function *OldFunc,
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
- ValueToValueMapTy &VMap) {
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+void llvm::CloneDebugInfoMetadata(Function *NewFunc, const Function *OldFunc,
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+ ValueToValueMapTy &VMap) {
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
DebugInfoFinder Finder;
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
Finder.processModule(*OldFunc->getParent());
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
diff --git a/lib/Transforms/Utils/CloneModule.cpp b/lib/Transforms/Utils/CloneModule.cpp
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
index 53de62a..b16a02a 100644
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
--- a/lib/Transforms/Utils/CloneModule.cpp
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+++ b/lib/Transforms/Utils/CloneModule.cpp
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
@@ -136,6 +136,7 @@ std::unique_ptr<Module> llvm::CloneModule(
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
VMap[&*J] = &*DestI++;
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
}
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+ CloneDebugInfoMetadata(F, &*I, VMap);
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
SmallVector<ReturnInst*, 8> Returns; // Ignore returns cloned.
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
CloneFunctionInto(F, &*I, VMap, /*ModuleLevelChanges=*/true, Returns);
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
}
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
diff --git a/unittests/Transforms/Utils/Cloning.cpp b/unittests/Transforms/Utils/Cloning.cpp
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
index 25e322e..b761e4e 100644
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
--- a/unittests/Transforms/Utils/Cloning.cpp
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+++ b/unittests/Transforms/Utils/Cloning.cpp
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
@@ -423,6 +423,7 @@ class CloneModule : public ::testing::Test {
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
void SetupModule() { OldM = new Module("", C); }
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
void CreateOldModule() {
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+ DIBuilder DBuilder(*OldM);
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
IRBuilder<> IBuilder(C);
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
auto *FuncType = FunctionType::get(Type::getVoidTy(C), false);
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
@@ -431,9 +432,25 @@ class CloneModule : public ::testing::Test {
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
auto *F =
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
Function::Create(FuncType, GlobalValue::PrivateLinkage, "f", OldM);
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
F->setPersonalityFn(PersFn);
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+ // Create debug info
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+ auto *File = DBuilder.createFile("filename.c", "/file/dir/");
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+ DITypeRefArray ParamTypes = DBuilder.getOrCreateTypeArray(None);
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+ DISubroutineType *DFuncType = DBuilder.createSubroutineType(ParamTypes);
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+ auto *CU =
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+ DBuilder.createCompileUnit(dwarf::DW_LANG_C99, "filename.c",
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+ "/file/dir", "CloneModule", false, "", 0);
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+ // Function DI
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+ auto *Subprogram = DBuilder.createFunction(CU, "f", "f", File, 4, DFuncType,
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+ true, true, 3, 0, false);
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+ F->setSubprogram(Subprogram);
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
auto *Entry = BasicBlock::Create(C, "", F);
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
IBuilder.SetInsertPoint(Entry);
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
IBuilder.CreateRetVoid();
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+ // Finalize the debug info
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+ DBuilder.finalize();
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
}
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
void CreateNewModule() { NewM = llvm::CloneModule(OldM).release(); }
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
@@ -447,4 +464,12 @@ TEST_F(CloneModule, Verify) {
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
EXPECT_FALSE(verifyModule(*NewM));
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
}
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+TEST_F(CloneModule, Subprogram) {
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+ Function *NewF = NewM->getFunction("f");
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+ DISubprogram *SP = NewF->getSubprogram();
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+ EXPECT_TRUE(SP != nullptr);
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+ EXPECT_EQ(SP->getName(), "f");
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+ EXPECT_EQ(SP->getFile()->getFilename(), "filename.c");
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+ EXPECT_EQ(SP->getLine(), (unsigned)4);
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+}
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
}
|