|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
From af289e04413504c3bdc252e08c3fe17bf7ea6dc8 Mon Sep 17 00:00:00 2001
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
From: Peter Collingbourne <peter@pcc.me.uk>
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
Date: Wed, 30 Mar 2016 22:05:13 +0000
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
Subject: [PATCH] Cloning: Reduce complexity of debug info cloning and fix
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
correctness issue.
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
Commit r260791 contained an error in that it would introduce a cross-module
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
reference in the old module. It also introduced O(N^2) complexity in the
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
module cloner by requiring the entire module to be visited for each function.
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
Fix both of these problems by avoiding use of the CloneDebugInfoMetadata
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
function (which is only designed to do intra-module cloning) and cloning
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
function-attached metadata in the same way that we clone all other metadata.
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
Differential Revision: http://reviews.llvm.org/D18583
|
|
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@264935 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 | 13 +++++++++++--
|
|
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 | 6 ++++++
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
4 files changed, 17 insertions(+), 8 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 0bae2bd..4f006f2 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,11 +130,6 @@ 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 05b0a17..8e1715a 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 |
@@ -119,6 +119,15 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
.addAttributes(NewFunc->getContext(), AttributeSet::FunctionIndex,
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
OldAttrs.getFnAttributes()));
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+ SmallVector<std::pair<unsigned, MDNode *>, 1> MDs;
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+ OldFunc->getAllMetadata(MDs);
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+ for (auto MD : MDs)
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+ NewFunc->setMetadata(
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+ MD.first,
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+ MapMetadata(MD.second, VMap,
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+ ModuleLevelChanges ? RF_None : RF_NoModuleLevelChanges,
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+ TypeMapper, Materializer));
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
// Loop over all of the basic blocks in the function, cloning them as
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
// appropriate. Note that we save BE this way in order to handle cloning of
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
// recursive functions into themselves.
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
@@ -187,8 +196,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 |
-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 |
+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 |
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 494e275..929f51b 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 |
@@ -138,7 +138,6 @@ 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 b761e4e..f06a20f 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 |
@@ -464,6 +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, OldModuleUnchanged) {
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+ DebugInfoFinder Finder;
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+ Finder.processModule(*OldM);
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
585426 |
+ EXPECT_EQ(1U, Finder.subprogram_count());
|
|
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();
|