From 51ec8b2357a936e3a17a9dc10cff74c736d7133a Mon Sep 17 00:00:00 2001 From: Teresa Johnson Date: Tue, 12 Jan 2016 17:48:44 +0000 Subject: [PATCH] [ThinLTO] Handle an external call from an import to an alias in dest The findExternalCalls routine ignores calls to functions already defined in the dest module. This was not handling the case where the definition in the current module is actually an alias to a function call. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@257493 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/IPO/FunctionImport.cpp | 2 ++ .../FunctionImport/Inputs/funcimport_alias.ll | 7 ++++++ .../FunctionImport/funcimport_alias.ll | 25 +++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 test/Transforms/FunctionImport/Inputs/funcimport_alias.ll create mode 100644 test/Transforms/FunctionImport/funcimport_alias.ll diff --git a/lib/Transforms/IPO/FunctionImport.cpp b/lib/Transforms/IPO/FunctionImport.cpp index 11418edbf7b..5e0df950511 100644 --- a/lib/Transforms/IPO/FunctionImport.cpp +++ b/lib/Transforms/IPO/FunctionImport.cpp @@ -133,6 +133,8 @@ static void findExternalCalls(const Module &DestModule, Function &F, // Ignore functions already present in the destination module auto *SrcGV = DestModule.getNamedValue(ImportedName); if (SrcGV) { + if (GlobalAlias *SGA = dyn_cast(SrcGV)) + SrcGV = SGA->getBaseObject(); assert(isa(SrcGV) && "Name collision during import"); if (!cast(SrcGV)->isDeclaration()) { DEBUG(dbgs() << DestModule.getModuleIdentifier() << ": Ignoring " diff --git a/test/Transforms/FunctionImport/Inputs/funcimport_alias.ll b/test/Transforms/FunctionImport/Inputs/funcimport_alias.ll new file mode 100644 index 00000000000..f897aeda6ce --- /dev/null +++ b/test/Transforms/FunctionImport/Inputs/funcimport_alias.ll @@ -0,0 +1,7 @@ +declare void @analias() + +define void @callanalias() #0 { +entry: + call void @analias() + ret void +} diff --git a/test/Transforms/FunctionImport/funcimport_alias.ll b/test/Transforms/FunctionImport/funcimport_alias.ll new file mode 100644 index 00000000000..0a6c4372557 --- /dev/null +++ b/test/Transforms/FunctionImport/funcimport_alias.ll @@ -0,0 +1,25 @@ +; Do setup work for all below tests: generate bitcode and combined index +; RUN: llvm-as -function-summary %s -o %t.bc +; RUN: llvm-as -function-summary %p/Inputs/funcimport_alias.ll -o %t2.bc +; RUN: llvm-lto -thinlto -o %t3 %t.bc %t2.bc %t3.bc + +; Do the import now. Ensures that the importer handles an external call +; from imported callanalias() to a function that is defined already in +; the dest module, but as an alias. +; RUN: opt -function-import -summary-file %t3.thinlto.bc %s -S | FileCheck %s + +define i32 @main() #0 { +entry: + call void @callanalias() + ret i32 0 +} + +@analias = alias void (), void ()* @globalfunc + +define void @globalfunc() #0 { +entry: + ret void +} + +declare void @callanalias() #1 +; CHECK-DAG: define available_externally void @callanalias() -- 2.34.1