[Polly] Don't prune non-external function itself from dump.
GitOrigin-RevId: e4f3f2c0c5f22ddfe86d16ba09fd0171bed0f2b3
diff --git a/lib/Support/DumpFunctionPass.cpp b/lib/Support/DumpFunctionPass.cpp
index 313fc71..a14e0ef 100644
--- a/lib/Support/DumpFunctionPass.cpp
+++ b/lib/Support/DumpFunctionPass.cpp
@@ -43,9 +43,15 @@
return GV == &F;
};
std::unique_ptr<Module> CM = CloneModule(*M, VMap, ShouldCloneDefinition);
+ Function *NewF = cast<Function>(VMap.lookup(&F));
+ assert(NewF && "Expected selected function to be cloned");
LLVM_DEBUG(dbgs() << "Global DCE...\n");
+ // Stop F itself from being pruned
+ GlobalValue::LinkageTypes OrigLinkage = NewF->getLinkage();
+ NewF->setLinkage(GlobalValue::ExternalLinkage);
+
{
ModuleAnalysisManager MAM;
ModulePassManager MPM;
@@ -58,6 +64,9 @@
MPM.run(*CM, MAM);
}
+ // Restore old linkage
+ NewF->setLinkage(OrigLinkage);
+
LLVM_DEBUG(dbgs() << "Write to file '" << Dumpfile << "'...\n");
std::unique_ptr<ToolOutputFile> Out;
diff --git a/test/Support/dumpfunction.ll b/test/Support/dumpfunction.ll
index 70b586b..243322f 100644
--- a/test/Support/dumpfunction.ll
+++ b/test/Support/dumpfunction.ll
@@ -22,7 +22,7 @@
@callee_alias = dso_local unnamed_addr alias void(i32, double*, i32), void(i32, double*, i32 )* @callee
-define void @callee(i32 %n, double* noalias nonnull %A, i32 %i) {
+define internal void @callee(i32 %n, double* noalias nonnull %A, i32 %i) {
entry:
br label %for
@@ -49,7 +49,7 @@
}
-define void @caller(i32 %n, double* noalias nonnull %A) {
+define internal void @caller(i32 %n, double* noalias nonnull %A) {
entry:
br label %for