Index: lib/Transforms/IPO/FunctionImport.cpp =================================================================== --- lib/Transforms/IPO/FunctionImport.cpp +++ lib/Transforms/IPO/FunctionImport.cpp @@ -126,16 +126,11 @@ if (GlobalValue::isInterposableLinkage(GVSummary->linkage())) // There is no point in importing these, we can't inline them return false; - if (auto *AS = dyn_cast(GVSummary)) { - GVSummary = &AS->getAliasee(); - // Alias can't point to "available_externally". However when we import - // linkOnceODR the linkage does not change. So we import the alias - // and aliasee only in this case. + if (isa(GVSummary)) + // Alias can't point to "available_externally". // FIXME: we should import alias as available_externally *function*, // the destination module does need to know it is an alias. - if (!GlobalValue::isLinkOnceODRLinkage(GVSummary->linkage())) - return false; - } + return false; auto *Summary = cast(GVSummary); @@ -221,14 +216,9 @@ } // "Resolve" the summary, traversing alias, const FunctionSummary *ResolvedCalleeSummary; - if (isa(CalleeSummary)) { - ResolvedCalleeSummary = cast( - &cast(CalleeSummary)->getAliasee()); - assert( - GlobalValue::isLinkOnceODRLinkage(ResolvedCalleeSummary->linkage()) && - "Unexpected alias to a non-linkonceODR in import list"); - } else - ResolvedCalleeSummary = cast(CalleeSummary); + assert(!isa(CalleeSummary) && + "Unexpected alias in import list"); + ResolvedCalleeSummary = cast(CalleeSummary); assert(ResolvedCalleeSummary->instCount() <= NewThreshold && "selectCallee() didn't honor the threshold"); @@ -721,13 +711,6 @@ } } for (GlobalAlias &GA : SrcModule->aliases()) { - // FIXME: This should eventually be controlled entirely by the summary. - if (FunctionImportGlobalProcessing::doImportAsDefinition( - &GA, &GlobalsToImport)) { - GlobalsToImport.insert(&GA); - continue; - } - if (!GA.hasName()) continue; auto GUID = GA.getGUID(); @@ -735,27 +718,9 @@ DEBUG(dbgs() << (Import ? "Is" : "Not") << " importing alias " << GUID << " " << GA.getName() << " from " << SrcModule->getSourceFileName() << "\n"); - if (Import) { - // Alias can't point to "available_externally". However when we import - // linkOnceODR the linkage does not change. So we import the alias - // and aliasee only in this case. This has been handled by - // computeImportForFunction() - GlobalObject *GO = GA.getBaseObject(); - assert(GO->hasLinkOnceODRLinkage() && - "Unexpected alias to a non-linkonceODR in import list"); -#ifndef NDEBUG - if (!GlobalsToImport.count(GO)) - DEBUG(dbgs() << " alias triggers importing aliasee " << GO->getGUID() - << " " << GO->getName() << " from " - << SrcModule->getSourceFileName() << "\n"); -#endif - if (Error Err = GO->materialize()) - return std::move(Err); - GlobalsToImport.insert(GO); - if (Error Err = GA.materialize()) - return std::move(Err); - GlobalsToImport.insert(&GA); - } + // Alias can't point to "available_externally", and won't be imported. + // This has been handled by computeImportForFunction() + assert(!Import && "Unexpected alias in import list"); } // Upgrade debug info after we're done materializing all the globals and we Index: lib/Transforms/Utils/FunctionImportUtils.cpp =================================================================== --- lib/Transforms/Utils/FunctionImportUtils.cpp +++ lib/Transforms/Utils/FunctionImportUtils.cpp @@ -151,25 +151,21 @@ return SGV->getLinkage(); case GlobalValue::LinkOnceAnyLinkage: - case GlobalValue::LinkOnceODRLinkage: - // These both stay the same when importing the definition. - // The ThinLTO pass will eventually force-import their definitions. - return SGV->getLinkage(); - case GlobalValue::WeakAnyLinkage: - // Can't import weak_any definitions correctly, or we might change the - // program semantics, since the linker will pick the first weak_any + // Can't import weak/linkonce_any definitions correctly, or we might change + // the program semantics, since the linker will pick the first such // definition and importing would change the order they are seen by the // linker. The module linking caller needs to enforce this. assert(!doImportAsDefinition(SGV)); // If imported as a declaration, it becomes external_weak. return SGV->getLinkage(); + case GlobalValue::LinkOnceODRLinkage: case GlobalValue::WeakODRLinkage: - // For weak_odr linkage, there is a guarantee that all copies will be - // equivalent, so the issue described above for weak_any does not exist, - // and the definition can be imported. It can be treated similarly - // to an imported externally visible global value. + // For weak/linkonce_odr linkage, there is a guarantee that all copies will + // be equivalent, so the issue described above for weak/linkonce_any does + // not exist, and the definition can be imported. It can be treated + // similarly to an imported externally visible global value. if (doImportAsDefinition(SGV) && !dyn_cast(SGV)) return GlobalValue::AvailableExternallyLinkage; else Index: test/Linker/funcimport.ll =================================================================== --- test/Linker/funcimport.ll +++ test/Linker/funcimport.ll @@ -59,11 +59,11 @@ ; IMPORTGLOB4-DAG: define available_externally void @globalfunc1 ; IMPORTGLOB4-DAG: declare void @weakalias -; An alias to an imported function is imported as alias if the function is not -; available_externally. +; An alias to an imported function is imported as declaration. ; RUN: llvm-link %t2.bc -summary-index=%t3.thinlto.bc -import=linkoncefunc:%t.bc -S | FileCheck %s --check-prefix=IMPORTGLOB5 -; IMPORTGLOB5-DAG: linkoncealias = alias void (...), bitcast (void ()* @linkoncefunc to void (...)*) -; IMPORTGLOB5-DAG: define linkonce_odr void @linkoncefunc() +; IMPORTGLOB5-NOT: @linkoncealias +; IMPORTGLOB5-DAG: define available_externally void @linkoncefunc() +; IMPORTGLOB5-NOT: @linkoncealias ; Ensure that imported static variable and function references are correctly ; promoted and renamed (including static constant variable). Index: test/ThinLTO/X86/alias_import.ll =================================================================== --- test/ThinLTO/X86/alias_import.ll +++ test/ThinLTO/X86/alias_import.ll @@ -2,13 +2,12 @@ ; RUN: opt -module-summary %p/Inputs/alias_import.ll -o %t2.bc ; RUN: llvm-lto -thinlto-action=thinlink -o %t.index.bc %t1.bc %t2.bc ; RUN: llvm-lto -thinlto-action=promote -thinlto-index %t.index.bc %t2.bc -o - | llvm-dis -o - | FileCheck %s --check-prefix=PROMOTE -; RUN: llvm-lto -thinlto-action=promote -thinlto-index %t.index.bc %t2.bc -o - | llvm-lto -thinlto-action=internalize -thinlto-index %t.index.bc -thinlto-module-id=%t2.bc - -o - | llvm-dis -o - | FileCheck %s --check-prefix=PROMOTE-INTERNALIZE +; RUN: llvm-lto -thinlto-action=promote -thinlto-index %t.index.bc %t2.bc -o - | llvm-lto -thinlto-action=internalize -exported-symbol=main -thinlto-index %t.index.bc -thinlto-module-id=%t2.bc - -o - | llvm-dis -o - | FileCheck %s --check-prefix=PROMOTE-INTERNALIZE ; RUN: llvm-lto -thinlto-action=import -thinlto-index %t.index.bc %t1.bc -o - | llvm-dis -o - | FileCheck %s --check-prefix=IMPORT ; -; Alias can't point to "available_externally", so we can only import an alias -; when we can import the aliasee with a linkage that won't be -; available_externally, i.e linkOnceODR. (FIXME this limitation could be lifted) +; Alias can't point to "available_externally", so we can't import aliases +; (FIXME this limitation could be lifted) ; PROMOTE-DAG: @globalfuncAlias = alias void (...), bitcast (void ()* @globalfunc to void (...)*) ; PROMOTE-DAG: @globalfuncWeakAlias = weak alias void (...), bitcast (void ()* @globalfunc to void (...)*) ; PROMOTE-DAG: @globalfuncLinkonceAlias = weak alias void (...), bitcast (void ()* @globalfunc to void (...)*) @@ -34,12 +33,9 @@ ; PROMOTE-DAG: @weakODRfuncLinkonceAlias = weak alias void (...), bitcast (void ()* @weakODRfunc to void (...)*) ; PROMOTE-DAG: @weakODRfuncWeakODRAlias = weak_odr alias void (...), bitcast (void ()* @weakODRfunc to void (...)*) ; PROMOTE-DAG: @weakODRfuncLinkonceODRAlias = weak_odr alias void (...), bitcast (void ()* @weakODRfunc to void (...)*) - -; Only alias to LinkonceODR aliasee can be imported ; PROMOTE-DAG: @linkonceODRfuncAlias = alias void (...), bitcast (void ()* @linkonceODRfunc to void (...)*) ; PROMOTE-DAG: @linkonceODRfuncWeakAlias = weak alias void (...), bitcast (void ()* @linkonceODRfunc to void (...)*) ; PROMOTE-DAG: @linkonceODRfuncWeakODRAlias = weak_odr alias void (...), bitcast (void ()* @linkonceODRfunc to void (...)*) -; Amongst these that are imported, check that we promote only linkonce->weak ; PROMOTE-DAG: @linkonceODRfuncLinkonceAlias = weak alias void (...), bitcast (void ()* @linkonceODRfunc to void (...)*) ; PROMOTE-DAG: @linkonceODRfuncLinkonceODRAlias = weak_odr alias void (...), bitcast (void ()* @linkonceODRfunc to void (...)*) @@ -51,16 +47,7 @@ ; PROMOTE-DAG: define weak void @linkoncefunc() ; PROMOTE-DAG: define weak void @weakfunc() -; On the import side now, verify that aliases to a linkonce_odr are imported, but the weak/linkonce (we can't inline them) -; IMPORT-DAG: declare void @linkonceODRfuncWeakAlias -; IMPORT-DAG: declare void @linkonceODRfuncLinkonceAlias -; IMPORT-DAG: @linkonceODRfuncAlias = alias void (...), bitcast (void ()* @linkonceODRfunc to void (...)*) -; IMPORT-DAG: @linkonceODRfuncWeakODRAlias = alias void (...), bitcast (void ()* @linkonceODRfunc to void (...)*) -; IMPORT-DAG: @linkonceODRfuncLinkonceODRAlias = linkonce_odr alias void (...), bitcast (void ()* @linkonceODRfunc to void (...)*) -; IMPORT-DAG: define linkonce_odr void @linkonceODRfunc() - - -; On the import side, these aliases are not imported (they don't point to a linkonce_odr) +; On the import side, aliases are not imported ; IMPORT-DAG: declare void @globalfuncAlias() ; IMPORT-DAG: declare void @globalfuncWeakAlias() ; IMPORT-DAG: declare void @globalfuncLinkonceAlias() @@ -81,13 +68,19 @@ ; IMPORT-DAG: declare void @linkoncefuncLinkonceAlias() ; IMPORT-DAG: declare void @linkoncefuncWeakODRAlias() ; IMPORT-DAG: declare void @linkoncefuncLinkonceODRAlias() +; IMPORT-DAG: declare void @linkonceODRfuncWeakAlias() +; IMPORT-DAG: declare void @linkonceODRfuncLinkonceAlias() +; IMPORT-DAG: declare void @linkonceODRfuncAlias() +; IMPORT-DAG: declare void @linkonceODRfuncWeakODRAlias() +; IMPORT-DAG: declare void @linkonceODRfuncLinkonceODRAlias() ; IMPORT-DAG: declare void @weakfuncAlias() ; IMPORT-DAG: declare void @weakfuncWeakAlias() ; IMPORT-DAG: declare void @weakfuncLinkonceAlias() ; IMPORT-DAG: declare void @weakfuncWeakODRAlias() ; IMPORT-DAG: declare void @weakfuncLinkonceODRAlias() -; Promotion + internalization should internalize all of these, except for aliases of +; Promotion + internalization should internalize all of these, because +; aliases can't be imported. ; linkonce_odr functions, because alias to linkonce_odr are the only aliases we will ; import (see selectCallee() in FunctionImport.cpp). ; PROMOTE-INTERNALIZE-DAG: @globalfuncAlias = internal alias void (...), bitcast (void ()* @globalfunc to void (...)*) @@ -100,11 +93,11 @@ ; PROMOTE-INTERNALIZE-DAG: @internalfuncLinkonceAlias = internal alias void (...), bitcast (void ()* @internalfunc to void (...)*) ; PROMOTE-INTERNALIZE-DAG: @internalfuncWeakODRAlias = internal alias void (...), bitcast (void ()* @internalfunc to void (...)*) ; PROMOTE-INTERNALIZE-DAG: @internalfuncLinkonceODRAlias = internal alias void (...), bitcast (void ()* @internalfunc to void (...)*) -; PROMOTE-INTERNALIZE-DAG: @linkonceODRfuncAlias = alias void (...), bitcast (void ()* @linkonceODRfunc to void (...)*) +; PROMOTE-INTERNALIZE-DAG: @linkonceODRfuncAlias = internal alias void (...), bitcast (void ()* @linkonceODRfunc to void (...)*) ; PROMOTE-INTERNALIZE-DAG: @linkonceODRfuncWeakAlias = internal alias void (...), bitcast (void ()* @linkonceODRfunc to void (...)*) ; PROMOTE-INTERNALIZE-DAG: @linkonceODRfuncLinkonceAlias = internal alias void (...), bitcast (void ()* @linkonceODRfunc to void (...)*) -; PROMOTE-INTERNALIZE-DAG: @linkonceODRfuncWeakODRAlias = weak_odr alias void (...), bitcast (void ()* @linkonceODRfunc to void (...)*) -; PROMOTE-INTERNALIZE-DAG: @linkonceODRfuncLinkonceODRAlias = weak_odr alias void (...), bitcast (void ()* @linkonceODRfunc to void (...)*) +; PROMOTE-INTERNALIZE-DAG: @linkonceODRfuncWeakODRAlias = internal alias void (...), bitcast (void ()* @linkonceODRfunc to void (...)*) +; PROMOTE-INTERNALIZE-DAG: @linkonceODRfuncLinkonceODRAlias = internal alias void (...), bitcast (void ()* @linkonceODRfunc to void (...)*) ; PROMOTE-INTERNALIZE-DAG: @weakODRfuncAlias = internal alias void (...), bitcast (void ()* @weakODRfunc to void (...)*) ; PROMOTE-INTERNALIZE-DAG: @weakODRfuncWeakAlias = internal alias void (...), bitcast (void ()* @weakODRfunc to void (...)*) ; PROMOTE-INTERNALIZE-DAG: @weakODRfuncLinkonceAlias = internal alias void (...), bitcast (void ()* @weakODRfunc to void (...)*) Index: test/ThinLTO/X86/select_right_alias_definition.ll =================================================================== --- test/ThinLTO/X86/select_right_alias_definition.ll +++ test/ThinLTO/X86/select_right_alias_definition.ll @@ -5,6 +5,11 @@ ; Make sure that we always select the right definition for alia foo, whatever ; order the files are linked in. +; This test will fail now that we don't import any aliases. Eventually +; we should import the alias as a copy of its aliasee, in which case +; this test can check that the appropriate aliasee was imported. +; XFAIL: * + ; Try with one order ; RUN: llvm-lto -thinlto-action=thinlink -o %t.index1.bc %t_main.bc %t1.bc %t2.bc ; RUN: llvm-lto -thinlto-action=import -thinlto-index %t.index1.bc %t_main.bc -o - | llvm-dis -o - | FileCheck %s --check-prefix=IMPORT @@ -24,4 +29,4 @@ define i32 @main() { %ret = call i32 @foo() ret i32 %ret -} \ No newline at end of file +} Index: test/Transforms/FunctionImport/funcimport.ll =================================================================== --- test/Transforms/FunctionImport/funcimport.ll +++ test/Transforms/FunctionImport/funcimport.ll @@ -40,12 +40,9 @@ ; CHECK-DAG: declare void @analias declare void @analias(...) #1 -; Aliases import the aliasee function +; Aliases are not imported declare void @linkoncealias(...) #1 -; INSTLIMDEF-DAG: Import linkoncealias -; INSTLIMDEF-DAG: Import linkoncefunc -; CHECK-DAG: define linkonce_odr void @linkoncefunc() -; CHECK-DAG: @linkoncealias = alias void (...), bitcast (void ()* @linkoncefunc to void (...)* +; CHECK-DAG: declare void @linkoncealias( ; INSTLIMDEF-DAG: Import referencestatics ; INSTLIMDEF-DAG: define available_externally i32 @referencestatics(i32 %i) !thinlto_src_module !0 { @@ -108,7 +105,7 @@ declare void @variadic(...) ; INSTLIMDEF-DAG: Import globalfunc2 -; INSTLIMDEF-DAG: 13 function-import - Number of functions imported +; INSTLIMDEF-DAG: 11 function-import - Number of functions imported ; CHECK-DAG: !0 = !{!"{{.*}}/Inputs/funcimport.ll"} ; The actual GUID values will depend on path to test.