/// non-equivalent at link time. For example, if a function has weak linkage
/// then the code defining it may be replaced by different code.
bool mayBeOverridden() const {
- switch (getLinkage()) {
- case WeakAnyLinkage:
- case LinkOnceAnyLinkage:
- case CommonLinkage:
- case ExternalWeakLinkage:
- return true;
-
- case AvailableExternallyLinkage:
- case LinkOnceODRLinkage:
- case WeakODRLinkage:
- // The above three cannot be overridden but can be de-refined.
-
- case ExternalLinkage:
- case AppendingLinkage:
- case InternalLinkage:
- case PrivateLinkage:
- return false;
- }
-
- llvm_unreachable("Fully covered switch above!");
+ return isMayBeOverriddenLinkage(getLinkage());
}
protected:
return Linkage == CommonLinkage;
}
+ /// Whether the definition of this global may be replaced by something
+ /// non-equivalent at link time. For example, if a function has weak linkage
+ /// then the code defining it may be replaced by different code.
+ static bool isMayBeOverriddenLinkage(LinkageTypes Linkage) {
+ switch (Linkage) {
+ case WeakAnyLinkage:
+ case LinkOnceAnyLinkage:
+ case CommonLinkage:
+ case ExternalWeakLinkage:
+ return true;
+
+ case AvailableExternallyLinkage:
+ case LinkOnceODRLinkage:
+ case WeakODRLinkage:
+ // The above three cannot be overridden but can be de-refined.
+
+ case ExternalLinkage:
+ case AppendingLinkage:
+ case InternalLinkage:
+ case PrivateLinkage:
+ return false;
+ }
+ llvm_unreachable("Fully covered switch above!");
+ }
+
/// Whether the definition of this global may be discarded if it is not used
/// in its compilation unit.
static bool isDiscardableIfUnused(LinkageTypes Linkage) {
CalleeSummaryList,
[&](const std::unique_ptr<GlobalValueSummary> &SummaryPtr) {
auto *GVSummary = SummaryPtr.get();
- if (GlobalValue::isWeakAnyLinkage(GVSummary->linkage()))
- // There is no point in importing weak symbols, we can't inline them
+ if (GlobalValue::isMayBeOverriddenLinkage(GVSummary->linkage()))
+ // There is no point in importing these, we can't inline them
return false;
if (auto *AS = dyn_cast<AliasSummary>(GVSummary)) {
GVSummary = &AS->getAliasee();
; PROMOTE-DAG: define linkonce 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 (never import weak)
+; 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: @linkonceODRfuncLinkonceAlias = linkonce 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()
ret void
}
+define linkonce void @linkoncefunc2() #0 {
+entry:
+ ret void
+}
+
define internal i32 @staticfunc() #0 {
entry:
ret i32 1
call void (...) @setfuncptr()
call void (...) @callfuncptr()
call void (...) @weakfunc()
+ call void (...) @linkoncefunc2()
call void (...) @referencelargelinkonce()
ret i32 0
}
; CHECK-DAG: declare void @weakfunc(...)
declare void @weakfunc(...) #1
+; Won't import linkonce func
+; CHECK-DAG: declare void @linkoncefunc2(...)
+declare void @linkoncefunc2(...) #1
+
; INSTLIMDEF-DAG: Import funcwithpersonality
; INSTLIMDEF-DAG: define available_externally hidden void @funcwithpersonality.llvm.{{.*}}() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
; INSTLIM5-DAG: declare hidden void @funcwithpersonality.llvm.{{.*}}()