Skip to content

[win][arm64ec] Handle available_externally functions #151610

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions llvm/lib/Target/AArch64/AArch64Arm64ECCallLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -813,8 +813,8 @@ bool AArch64Arm64ECCallLowering::runOnModule(Module &Mod) {
}
}

if (!F.hasFnAttribute(Attribute::HybridPatchable) || F.isDeclaration() ||
F.hasLocalLinkage() ||
if (!F.hasFnAttribute(Attribute::HybridPatchable) ||
F.isDeclarationForLinker() || F.hasLocalLinkage() ||
F.getName().ends_with(HybridPatchableTargetSuffix))
continue;

Expand Down Expand Up @@ -857,7 +857,7 @@ bool AArch64Arm64ECCallLowering::runOnModule(Module &Mod) {

SetVector<GlobalValue *> DirectCalledFns;
for (Function &F : Mod)
if (!F.isDeclaration() &&
if (!F.isDeclarationForLinker() &&
F.getCallingConv() != CallingConv::ARM64EC_Thunk_Native &&
F.getCallingConv() != CallingConv::ARM64EC_Thunk_X64)
processFunction(F, DirectCalledFns, FnsMap);
Expand All @@ -869,7 +869,8 @@ bool AArch64Arm64ECCallLowering::runOnModule(Module &Mod) {
};
SmallVector<ThunkInfo> ThunkMapping;
for (Function &F : Mod) {
if (!F.isDeclaration() && (!F.hasLocalLinkage() || F.hasAddressTaken()) &&
if (!F.isDeclarationForLinker() &&
(!F.hasLocalLinkage() || F.hasAddressTaken()) &&
F.getCallingConv() != CallingConv::ARM64EC_Thunk_Native &&
F.getCallingConv() != CallingConv::ARM64EC_Thunk_X64) {
if (!F.hasComdat())
Expand Down Expand Up @@ -959,7 +960,7 @@ bool AArch64Arm64ECCallLowering::processFunction(
// unprototyped functions in C)
if (Function *F = CB->getCalledFunction()) {
if (!LowerDirectToIndirect || F->hasLocalLinkage() ||
F->isIntrinsic() || !F->isDeclaration())
F->isIntrinsic() || !F->isDeclarationForLinker())
continue;

DirectCalledFns.insert(F);
Expand Down
24 changes: 24 additions & 0 deletions llvm/test/CodeGen/AArch64/arm64ec-available-externally.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
; RUN: llc -mtriple arm64ec-windows-msvc -o - %s | FileCheck %s

; Arm64EC Regression Test: The Arm64EC Call Lowering was placing "available
; externally" items in COMDATs, which is not permitted by the module verifier.

define available_externally float @f() {
entry:
ret float 0x0
}

define i32 @caller() {
entry:
call float @f()
ret i32 0
}

; Normal function gets an entry thunk, but not an exit thunk.
; CHECK-DAG: $ientry_thunk$cdecl$i8$v:
; CHECK-NOT: $iexit_thunk$cdecl$i8$v:

; Available Externally function gets an exit thunk, but not an entry thunk.
; CHECK-DAG: $iexit_thunk$cdecl$f$v:
; CHECK-DAG: "#f$exit_thunk":
; CHECK-NOT: $ientry_thunk$cdecl$f$v: