[X86] Add WinCall Calling Convention and x86_64apx-windows(-gnu/-msvc) triplets #215585
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
````````git-clang-format --diff origin/main HEAD --extensions cpp,c,h -- clang/test/CIR/CodeGen/wincall.c clang/test/CodeGen/X86/wincall-abi.c clang/test/CodeGen/X86/wincall-abi2.c clang/test/CodeGen/X86/wincall-msabi.c clang/test/CodeGen/X86/wincall-sysv.c clang/test/CodeGen/X86/wincall-uefi.c clang/test/CodeGen/wincall.c clang/test/CodeGenCXX/wincall-mangle.cpp clang/test/Driver/wincall-x86_64apx.c clang/test/Sema/callingconv-wincall.c clang/include/clang-c/Index.h clang/include/clang/Basic/LangOptions.h clang/include/clang/Basic/Specifiers.h clang/lib/AST/ASTContext.cpp clang/lib/AST/Expr.cpp clang/lib/AST/ItaniumMangle.cpp clang/lib/AST/Mangle.cpp clang/lib/AST/MicrosoftMangle.cpp clang/lib/AST/Type.cpp clang/lib/AST/TypePrinter.cpp clang/lib/Basic/Targets.cpp clang/lib/Basic/Targets/X86.cpp clang/lib/Basic/Targets/X86.h clang/lib/CIR/CodeGen/CIRGenModule.cpp clang/lib/CIR/CodeGen/CIRGenTypes.cpp clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp clang/lib/CodeGen/CGCall.cpp clang/lib/CodeGen/CGDebugInfo.cpp clang/lib/CodeGen/CodeGenModule.cpp clang/lib/CodeGen/Targets/X86.cpp clang/lib/Driver/ToolChains/Clang.cpp clang/lib/Driver/ToolChains/MSVC.cpp clang/lib/Driver/ToolChains/MinGW.cpp clang/lib/Parse/ParseDecl.cpp clang/lib/Parse/ParseDeclCXX.cpp clang/lib/Parse/ParseTentative.cpp clang/lib/Sema/SemaDeclAttr.cpp clang/lib/Sema/SemaExpr.cpp clang/lib/Sema/SemaLambda.cpp clang/lib/Sema/SemaType.cpp clang/test/Preprocessor/init-x86.c clang/tools/libclang/CXType.cpp llvm/include/llvm/AsmParser/LLToken.h llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h llvm/include/llvm/IR/CallingConv.h llvm/include/llvm/TargetParser/Triple.h llvm/lib/AsmParser/LLLexer.cpp llvm/lib/AsmParser/LLParser.cpp llvm/lib/IR/AsmWriter.cpp llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp llvm/lib/Target/X86/X86RegisterInfo.cpp llvm/lib/Target/X86/X86Subtarget.cpp llvm/lib/Target/X86/X86Subtarget.h llvm/lib/Target/X86/X86TargetMachine.cpp llvm/lib/TargetParser/Triple.cpp llvm/unittests/TargetParser/TripleTest.cpp --diff_from_common_commit
``
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````diff --git a/clang/lib/CodeGen/Targets/X86.cpp b/clang/lib/CodeGen/Targets/X86.cpp
index 24e7bb7bd..e0437e202 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -3632,8 +3632,7 @@ ABIArgInfo WinX86_64ABIInfo::classify(QualType Ty, unsigned &FreeSSERegs,
bool IsScalarFP =
FieldTy->isFloatingType() && !FieldTy->isComplexType();
if (IsScalarFP && FieldLLTy->isFloatingPointTy() &&
- getContext().getTypeSize(Ty) ==
- getContext().getTypeSize(FieldTy))
+ getContext().getTypeSize(Ty) == getContext().getTypeSize(FieldTy))
return ABIArgInfo::getDirect(FieldLLTy);
}
}
diff --git a/llvm/lib/Target/X86/X86TargetMachine.cpp b/llvm/lib/Target/X86/X86TargetMachine.cpp
index 2cf7f812b..f7f80812a 100644
--- a/llvm/lib/Target/X86/X86TargetMachine.cpp
+++ b/llvm/lib/Target/X86/X86TargetMachine.cpp
@@ -238,11 +238,12 @@ X86TargetMachine::getSubtargetImpl(const Function &F) const {
// The WinCall calling convention (x86_wincallcc) passes the fifth and later
// integer arguments in the APX extended GPRs R16-R19. A function therefore
- // needs the egpr feature when it either uses WinCall itself or calls a WinCall
- // function, because the backend sizes its physical register tables from
- // X86RegisterInfo::getNumSupportedRegs(), which only covers R16-R19 when egpr
- // is enabled. The frontend accepts `wincall` on any x86-64 target, so this
- // cannot be left to the triple the way the x86_64apx sub-architecture does.
+ // needs the egpr feature when it either uses WinCall itself or calls a
+ // WinCall function, because the backend sizes its physical register tables
+ // from X86RegisterInfo::getNumSupportedRegs(), which only covers R16-R19 when
+ // egpr is enabled. The frontend accepts `wincall` on any x86-64 target, so
+ // this cannot be left to the triple the way the x86_64apx sub-architecture
+ // does.
bool NeedsWinCallEGPR = F.getCallingConv() == CallingConv::X86_WinCall;
if (!NeedsWinCallEGPR)
for (const BasicBlock &BB : F) {
</details>
1. APX (EVEX) also implies AVX512, which means all instructions are expected VEX/EVEX encoded. Can we eliminate the use of vzeroupper under WinCall based on this?
Also, based assumptions of AVX512, can we make better use of ZMM and ZMM16-31 in WinCall Calling Convention? I think i128/i256/i512 can all be passed via XMM/YMM/ZMM rather than GPR.
2. long double need to be clarified: MSVC long double is f64, while GNU long double is f80.
I think the new ABI should unify MSVC/GNU long double to f64 to truly get rid of x87.
3. complex-type scalar and vector arguments should also be passed via XMM/YMM/ZMM.
1. APX (EVEX) also implies AVX512, which means all instructions are expected VEX/EVEX encoded. Can we eliminate the use of vzeroupper under WinCall based on this?
Also, based assumptions of AVX512, can we make better use of ZMM and ZMM16-31 in WinCall Calling Convention? I think i128/i256/i512 can all be passed via XMM/YMM/ZMM rather than GPR.
2. long double need to be clarified: MSVC long double is f64, while GNU long double is f80.
I think the new ABI should unify MSVC/GNU long double to f64 to truly get rid of x87.
3. complex-type scalar and vector arguments should also be passed via XMM/YMM/ZMM.
good ideas. i will feed into ai to let it check whether they would cause inconsistency
There are also some suitable defines for x86_64apx-windows triple:
1. unwindv3 shall be the only supported version.
2. ~~cfguard,ehguard and cetcompat shall be default.~~
3. the stack must always remain 64-byte aligned. This would be very helpful for gcc, since gcc still cannot support AVX512 on Windows correctly due to 16-byte stack alignment.
4. for libcxx, shall LIBCXX_ABI_VERSION default to 2?
5. due to more GPR available, shall -fno-omit-frame-pointer be default?
2. long double need to be clarified: MSVC long double is f64, while GNU long double is f80.
I think the new ABI should unify MSVC/GNU long double to f64 to truly get rid of x87.
Would it break abi?
> 2. long double need to be clarified: MSVC long double is f64, while GNU long double is f80.
> I think the new ABI should unify MSVC/GNU long double to f64 to truly get rid of x87.
> Would it break abi?
Obviously yes, but hasn't x86_64apx-windows already defined a new ABI? By the way, recent mingw-w64 already supports -mlong-double-64.
Since Windows API doesn't support f80, and long double isn't very common, I think it's reasonable to break the long double ABI.
i
> > 2. long double need to be clarified: MSVC long double is f64, while GNU long double is f80.
> > I think the new ABI should unify MSVC/GNU long double to f64 to truly get rid of x87.
>
>
> Would it break abi?
> Obviously yes, but hasn't x86_64apx-windows already defined a new ABI? By the way, recent mingw-w64 already supports -mlong-double-64.
> Since Windows API doesn't support f80, and long double isn't very common, I think it's reasonable to break the long double ABI.
but what libstdc++-6.dll? wouldn't it use long double in iostream operator<<>>?
but what libstdc++-6.dll? wouldn't it use long double in iostream operator<<>>?
Should x86_64apx-windows-gnu users use a full x86_64apx-windows-gnu toolchain? If yes, long double will work normally since libstdc++ is also built with -mlong-double-64.
> but what libstdc++-6.dll? wouldn't it use long double in iostream operator<<>>?
> Should x86_64apx-windows-gnu users use a full x86_64apx-windows-gnu toolchain? If yes, long double will work normally since libstdc++ is also built with -mlong-double-64.
looks like we need standard library devs to do their work. better ask @jwakely on this
<!--PREMERGE ADVISOR COMMENT: Linux-->
:penguin: Linux x64 Test Results
161868 tests passed
2328 tests skipped
Failed Tests
(click on a test name to see its output)
Clang
<details>
<summary>Clang.CodeGen/X86/wincall-uefi.c</summary>
Exit Code: 1
Command Output (stdout):
--
# RUN: at line 1
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang -cc1 -internal-isystem /home/gha/actions-runner/_work/llvm-project/llvm-project/build/lib/clang/24/include -nostdsysteminc -triple x86_64apx-unknown-uefi -o - -emit-llvm /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CodeGen/X86/wincall-uefi.c | /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CodeGen/X86/wincall-uefi.c
# executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang -cc1 -internal-isystem /home/gha/actions-runner/_work/llvm-project/llvm-project/build/lib/clang/24/include -nostdsysteminc -triple x86_64apx-unknown-uefi -o - -emit-llvm /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CodeGen/X86/wincall-uefi.c
# note: command had no output on stdout or stderr
# executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CodeGen/X86/wincall-uefi.c
# note: command had no output on stdout or stderr
# RUN: at line 2
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang -cc1 -internal-isystem /home/gha/actions-runner/_work/llvm-project/llvm-project/build/lib/clang/24/include -nostdsysteminc -triple x86_64apx-unknown-uefi -O2 -mframe-pointer=all -o - -S /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CodeGen/X86/wincall-uefi.c | /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck -check-prefix=FRAME /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CodeGen/X86/wincall-uefi.c
# executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang -cc1 -internal-isystem /home/gha/actions-runner/_work/llvm-project/llvm-project/build/lib/clang/24/include -nostdsysteminc -triple x86_64apx-unknown-uefi -O2 -mframe-pointer=all -o - -S /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CodeGen/X86/wincall-uefi.c
# note: command had no output on stdout or stderr
# executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck -check-prefix=FRAME /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CodeGen/X86/wincall-uefi.c
# note: command had no output on stdout or stderr
# RUN: at line 3
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang -cc1 -internal-isystem /home/gha/actions-runner/_work/llvm-project/llvm-project/build/lib/clang/24/include -nostdsysteminc -triple x86_64apx-unknown-uefi -o - -emit-llvm /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CodeGen/X86/wincall-uefi.c | /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck -check-prefix=SEH /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CodeGen/X86/wincall-uefi.c
# executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang -cc1 -internal-isystem /home/gha/actions-runner/_work/llvm-project/llvm-project/build/lib/clang/24/include -nostdsysteminc -triple x86_64apx-unknown-uefi -o - -emit-llvm /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CodeGen/X86/wincall-uefi.c
# note: command had no output on stdout or stderr
# executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck -check-prefix=SEH /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CodeGen/X86/wincall-uefi.c
# .---command stderr------------
# | /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CodeGen/X86/wincall-uefi.c:30:9: error: SEH: expected string not found in input
# | // SEH: !llvm.module.flags = !{!0}
# | ^
# | <stdin>:1:1: note: scanning from here
# | ; ModuleID = '/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CodeGen/X86/wincall-uefi.c'
# | ^
# | <stdin>:60:1: note: possible intended match here
# | !llvm.module.flags = !{!2, !3}
# | ^
# |
# | Input file: <stdin>
# | Check file: /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CodeGen/X86/wincall-uefi.c
# |
# | -dump-input=help explains the following input dump.
# |
# | Input was:
# | <<<<<<
# | 1: ; ModuleID = '/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CodeGen/X86/wincall-uefi.c'
# | check:30'0 { search range start (exclusive)
# | check:30'1 error: no match found in search range
# | 2: source_filename = "/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CodeGen/X86/wincall-uefi.c"
# | 3: target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
# | 4: target triple = "x86_64apx-unknown-uefi"
# | 5:
# | 6: ; Function Attrs: noinline nounwind optnone
# | .
# | .
# | .
# | 55:
# | 56: attributes #0 = { noinline nounwind optnone "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+avx,+avx2,+avx512f,+ccmp,+crc32,+cx8,+egpr,+f16c,+fma,+jmpabs,+mmx,+ndd,+nf,+popcnt,+ppx,+push2pop2,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave,+zu" }
# | 57: attributes #1 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+avx,+avx2,+avx512f,+ccmp,+crc32,+cx8,+egpr,+f16c,+fma,+jmpabs,+mmx,+ndd,+nf,+popcnt,+ppx,+push2pop2,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave,+zu" }
# | 58:
# | 59: !llvm.dbg.cu = !{!0}
# | 60: !llvm.module.flags = !{!2, !3}
# | check:30'2 ? possible intended match
# | 61: !llvm.ident = !{!4}
# | 62:
# | 63: !0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang version 24.0.0git (https://github.com/llvm/llvm-project 8d3ae96615bc72de06a5338df6608454dbdbed05)", isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug, splitDebugInlining: false, nameTableKind: None)
# | 64: !1 = !DIFile(filename: "/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CodeGen/X86/<stdin>", directory: "")
# | 65: !2 = !{i32 2, !"Debug Info Version", i32 3}
# | 66: !3 = !{i32 2, !"winx64-eh-unwind", i32 3}
# | 67: !4 = !{!"clang version 24.0.0git (https://github.com/llvm/llvm-project 8d3ae96615bc72de06a5338df6608454dbdbed05)"}
# | check:30'3 } search range end (exclusive)
# | >>>>>>
# `-----------------------------
# error: command failed with exit status: 1
--
</details>
If these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the infrastructure label.
There are also some suitable defines for x86_64apx-windows triple:
> 1. unwindv3 shall be the only supported version.
2. cfguard,ehguard and cetcompat shall be default.
3. the stack must always remain 64-byte aligned. This would be very helpful for gcc, since gcc still cannot support AVX512 on Windows correctly due to 16-byte stack alignment.
4. for libcxx, shall LIBCXX_ABI_VERSION default to 2?
5. due to more GPR available, shall -fno-omit-frame-pointer be default?
I have several questions.
1. what is unwindv3?
2. What's the point of making cfguard,ehguard and cetcompat default. Would they cause performance or other issues?
1. what is unwindv3?
https://github.com/llvm/llvm-project/pull/200249
https://learn.microsoft.com/en-us/cpp/build/x64-unwind-information-v3?view=msvc-170
https://www.linkedin.com/pulse/x86-64-unwind-v3-here-pedro-miguel-sequeira-de-justo-teixeira-wkrpc/
This is required by APX, but by default, unwindv3 is only issued when EGPR is actually used, which is meaningless for x86_64apx-windows.
2\. What's the point of making cfguard,ehguard and cetcompat default. Would they cause performance or other issues?
These are unrelated to APX, but given all APX CPUs necessarily support CET, making it default provides a meaningful way to enhance the security baseline for the new ABI - especially since the performance overhead is negligible and it helps mitigate some speculative vulnerabilities.
or other issues?
CET might be problematic for older binaries, but since all x86_64apx-windows code will be rebuilt, this is no longer an issue.
* the stack must always remain 64-byte aligned. This would be very helpful for gcc, since gcc still cannot support AVX512 on Windows correctly due to 16-byte stack alignment.
I think these CFGs protections still cause very high performance overhead. better just wait for x86 memory tagging instead
5. due to more GPR available, shall -fno-omit-frame-pointer be default?
i think this is very bad. more GPR available does not mean certain programs are not going to need all of them. One more register is crucial for some programs. We should never waste any register.
i have added all the compiler side changes you want to add except the -fno-omit-frame-pointer. One register cost is huge tbh
i think this is very bad. more GPR available does not mean certain programs are not going to need all of them. One more register is crucial for some programs. We should never waste any register.
> i have added all the compiler side changes you want to add except the -fno-omit-frame-pointer. One register cost is huge tbh
Microsoft actually enforced this for arm64:
Code within Windows is compiled with frame pointers enabled (/Oy-) to enable fast stack walking. Generally, x29 (fp) points to the next link in the chain, which is an {fp, lr} pair, indicating the pointer to the previous frame on the stack and the return address. Third-party code is encouraged to enable frame pointers as well, to allow for improved profiling and tracing.
https://github.com/llvm/llvm-project/pull/147354 [win][aarch64] Always reserve frame pointers for Arm64 Windows
I don't really have an opinion on this, but Microsoft might want to keep frame pointers in the new ABI.
> i think this is very bad. more GPR available does not mean certain programs are not going to need all of them. One more register is crucial for some programs. We should never waste any register.
> i have added all the compiler side changes you want to add except the -fno-omit-frame-pointer. One register cost is huge tbh
> Microsoft actually enforced this for arm64:
> https://learn.microsoft.com/en-us/cpp/build/arm64-windows-abi-conventions?view=msvc-170#stack-walking
> > Code within Windows is compiled with frame pointers enabled (/Oy-) to enable fast stack walking. Generally, x29 (fp) points to the next link in the chain, which is an {fp, lr} pair, indicating the pointer to the previous frame on the stack and the return address. Third-party code is encouraged to enable frame pointers as well, to allow for improved profiling and tracing.
> #147354 [win][aarch64] Always reserve frame pointers for Arm64 Windows
> I don't really have an opinion on this, but Microsoft might want to keep frame pointers in the new ABI.
we do not need fast stack walking since i am also implementing herbceptions which will replace current C++ exceptions. on aarch64, they only encourage not enforce. So it is not a problem. you can use it in your code if you want
i have added all the compiler side changes you want to add except the -fno-omit-frame-pointer.
What do you think about pass i128/i256/i512 (_BitInt) arguments via XMM/YMM/ZMM?
x86 backend can lower basic i128/i256/i512 arithmetic to AVX512, so doing so can reduce some GPR<->FPU overhead. (i128 multiplication may be an exception)
That's not enough - need VLX at least. Maybe could request AVX10.2?
This may need coordination with x86 EAG, but as things stand, all CPUs that support APX will likely support AVX10.2.
"What do you think about pass i128/i256/i512 (_BitInt) arguments via XMM/YMM/ZMM?"
Very bad. we should avoid floating point registers as much as possible. Many kernels have strict rules on banning floating point registers. Plus fp registers can have latency issues and others. Always just use GPRs before using MM registers.
Additionally personally, when defining the ISA baseline for x86_64apx or "x86-64-v5", include GFNI and VPCLMULDQ will be useful for improving vector bitwise operations lowering, see previous GFNI vXi8 and pext/pdep work.
https://github.com/llvm/llvm-project/pull/215231#issuecomment-5238798831
Very bad. we should avoid floating point registers as much as possible. Many kernels have strict rules on banning floating point registers. Plus fp registers can have latency issues and others. Always just use GPRs before using MM registers.
On recent AVX-512 CPUs, ZMM instructions no longer cause throttling as they did in the past.
Many kernels have strict rules on banning floating point registers.
I thought x86_64apx is a usermode-only ABI?
> Very bad. we should avoid floating point registers as much as possible. Many kernels have strict rules on banning floating point registers. Plus fp registers can have latency issues and others. Always just use GPRs before using MM registers.
> On recent AVX-512 CPUs, ZMM instructions no longer cause throttling as they did in the past.
> > Many kernels have strict rules on banning floating point registers.
> I thought x86_64apx is a usermode-only ABI?
not a usermode-only abi. it should apply to uefi, cygwin/msys, win kernel etc too i think. but i haven't yet finished it. plus other x86_64 os may use the calling convention too in some specific windows related code such as limine bootloader
https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#machine-types
Since arm64ec has different PE/COFF machine types, should we define a new one for x86_64apx as well?
https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#machine-types
> Since arm64ec has different PE/COFF machine types, should we define a new one for x86_64apx as well?
i think no. x86_64apx is just x86_64 with better calling convention. arm64ec is pretty useless in reality
To get more visibility, it’s best to create an RFC at https://discourse.llvm.org/
https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#machine-types
> Since arm64ec has different PE/COFF machine types, should we define a new one for x86_64apx as well?
the entire arm64ec, arm64x are just hot mess. arm64ec is a terrible mistake
the wincall is supposed to be compatible with existing as much as possible. Adding new header is completely far away from the goal
Does x86 (32-bit) have a similar problem? I recall things like std::string_view weren't optimized properly due to the calling convention, too.
Does x86 (32-bit) have a similar problem? I recall things like std::string_view weren't optimized properly due to the calling convention, too.
no
As far as I know, APX is only supported in 64-bit long mode.
Does x86 (32-bit) have a similar problem? I recall things like std::string_view weren't optimized properly due to the calling convention, too.
Well. Technically the nuance is that on i686 (aka 32 bit windows) windows has stdcall and fastcall and they are different.
but neither case if i remember correctly would cause a std::span to be passed/returned differently from a pointer + size combo. Because the size is 8 which satisifies the 1,2,4,8 size requirement. but on x86_64 they did not expand it to 16 cause issues like this, plus the rdx is no longer used for returning even 32bit uses edx for the 2nd parameter.
WinCall is trying to fix issues like this too.
However, if i rememebered correctly 32 bit windows has some other minor issues.
I think on 32-bit x86 there was a mregparm=3, can something like this be introduced on x64 or does this draft cc defeat the purpose of such parameters
I think on 32-bit x86 there was a mregparm=3, can something like this be introduced on x64 or does this draft cc defeat the purpose of such parameters
wincall should not do anything to i686 but only x86_64
<!--PREMERGE ADVISOR COMMENT: Windows-->
:window: Windows x64 Test Results
148928 tests passed
2301 tests skipped
Failed Tests
(click on a test name to see its output)
Clang
<details>
<summary>Clang.CodeGen/X86/wincall-uefi.c</summary>
Exit Code: 1
Command Output (stdout):
--
# RUN: at line 1
c:\_work\llvm-project\llvm-project\build\bin\clang.exe -cc1 -internal-isystem C:\_work\llvm-project\llvm-project\build\lib\clang\24\include -nostdsysteminc -triple x86_64apx-unknown-uefi -o - -emit-llvm C:\_work\llvm-project\llvm-project\clang\test\CodeGen\X86\wincall-uefi.c | c:\_work\llvm-project\llvm-project\build\bin\filecheck.exe C:\_work\llvm-project\llvm-project\clang\test\CodeGen\X86\wincall-uefi.c
# executed command: 'c:\_work\llvm-project\llvm-project\build\bin\clang.exe' -cc1 -internal-isystem 'C:\_work\llvm-project\llvm-project\build\lib\clang\24\include' -nostdsysteminc -triple x86_64apx-unknown-uefi -o - -emit-llvm 'C:\_work\llvm-project\llvm-project\clang\test\CodeGen\X86\wincall-uefi.c'
# note: command had no output on stdout or stderr
# executed command: 'c:\_work\llvm-project\llvm-project\build\bin\filecheck.exe' 'C:\_work\llvm-project\llvm-project\clang\test\CodeGen\X86\wincall-uefi.c'
# note: command had no output on stdout or stderr
# RUN: at line 2
c:\_work\llvm-project\llvm-project\build\bin\clang.exe -cc1 -internal-isystem C:\_work\llvm-project\llvm-project\build\lib\clang\24\include -nostdsysteminc -triple x86_64apx-unknown-uefi -O2 -mframe-pointer=all -o - -S C:\_work\llvm-project\llvm-project\clang\test\CodeGen\X86\wincall-uefi.c | c:\_work\llvm-project\llvm-project\build\bin\filecheck.exe -check-prefix=FRAME C:\_work\llvm-project\llvm-project\clang\test\CodeGen\X86\wincall-uefi.c
# executed command: 'c:\_work\llvm-project\llvm-project\build\bin\clang.exe' -cc1 -internal-isystem 'C:\_work\llvm-project\llvm-project\build\lib\clang\24\include' -nostdsysteminc -triple x86_64apx-unknown-uefi -O2 -mframe-pointer=all -o - -S 'C:\_work\llvm-project\llvm-project\clang\test\CodeGen\X86\wincall-uefi.c'
# note: command had no output on stdout or stderr
# executed command: 'c:\_work\llvm-project\llvm-project\build\bin\filecheck.exe' -check-prefix=FRAME 'C:\_work\llvm-project\llvm-project\clang\test\CodeGen\X86\wincall-uefi.c'
# note: command had no output on stdout or stderr
# RUN: at line 3
c:\_work\llvm-project\llvm-project\build\bin\clang.exe -cc1 -internal-isystem C:\_work\llvm-project\llvm-project\build\lib\clang\24\include -nostdsysteminc -triple x86_64apx-unknown-uefi -o - -emit-llvm C:\_work\llvm-project\llvm-project\clang\test\CodeGen\X86\wincall-uefi.c | c:\_work\llvm-project\llvm-project\build\bin\filecheck.exe -check-prefix=SEH C:\_work\llvm-project\llvm-project\clang\test\CodeGen\X86\wincall-uefi.c
# executed command: 'c:\_work\llvm-project\llvm-project\build\bin\clang.exe' -cc1 -internal-isystem 'C:\_work\llvm-project\llvm-project\build\lib\clang\24\include' -nostdsysteminc -triple x86_64apx-unknown-uefi -o - -emit-llvm 'C:\_work\llvm-project\llvm-project\clang\test\CodeGen\X86\wincall-uefi.c'
# note: command had no output on stdout or stderr
# executed command: 'c:\_work\llvm-project\llvm-project\build\bin\filecheck.exe' -check-prefix=SEH 'C:\_work\llvm-project\llvm-project\clang\test\CodeGen\X86\wincall-uefi.c'
# .---command stderr------------
# | C:\_work\llvm-project\llvm-project\clang\test\CodeGen\X86\wincall-uefi.c:30:9: error: SEH: expected string not found in input
# | // SEH: !llvm.module.flags = !{!0}
# | ^
# | <stdin>:1:1: note: scanning from here
# | ; ModuleID = 'C:\_work\llvm-project\llvm-project\clang\test\CodeGen\X86\wincall-uefi.c'
# | ^
# | <stdin>:60:1: note: possible intended match here
# | !llvm.module.flags = !{!2, !3}
# | ^
# |
# | Input file: <stdin>
# | Check file: C:\_work\llvm-project\llvm-project\clang\test\CodeGen\X86\wincall-uefi.c
# |
# | -dump-input=help explains the following input dump.
# |
# | Input was:
# | <<<<<<
# | 1: ; ModuleID = 'C:\_work\llvm-project\llvm-project\clang\test\CodeGen\X86\wincall-uefi.c'
# | check:30'0 { search range start (exclusive)
# | check:30'1 error: no match found in search range
# | 2: source_filename = "C:\\_work\\llvm-project\\llvm-project\\clang\\test\\CodeGen\\X86\\wincall-uefi.c"
# | 3: target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
# | 4: target triple = "x86_64apx-unknown-uefi"
# | 5:
# | 6: ; Function Attrs: noinline nounwind optnone
# | .
# | .
# | .
# | 55:
# | 56: attributes #0 = { noinline nounwind optnone "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+avx,+avx2,+avx512f,+ccmp,+crc32,+cx8,+egpr,+f16c,+fma,+jmpabs,+mmx,+ndd,+nf,+popcnt,+ppx,+push2pop2,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave,+zu" }
# | 57: attributes #1 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+avx,+avx2,+avx512f,+ccmp,+crc32,+cx8,+egpr,+f16c,+fma,+jmpabs,+mmx,+ndd,+nf,+popcnt,+ppx,+push2pop2,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave,+zu" }
# | 58:
# | 59: !llvm.dbg.cu = !{!0}
# | 60: !llvm.module.flags = !{!2, !3}
# | check:30'2 ? possible intended match
# | 61: !llvm.ident = !{!4}
# | 62:
# | 63: !0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang version 24.0.0git (https://github.com/llvm/llvm-project 8d3ae96615bc72de06a5338df6608454dbdbed05)", isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug, splitDebugInlining: false, nameTableKind: None)
# | 64: !1 = !DIFile(filename: "C:\\_work\\llvm-project\\llvm-project\\clang\\test\\CodeGen\\X86\\<stdin>", directory: "")
# | 65: !2 = !{i32 2, !"Debug Info Version", i32 3}
# | 66: !3 = !{i32 2, !"winx64-eh-unwind", i32 3}
# | 67: !4 = !{!"clang version 24.0.0git (https://github.com/llvm/llvm-project 8d3ae96615bc72de06a5338df6608454dbdbed05)"}
# | check:30'3 } search range end (exclusive)
# | >>>>>>
# `-----------------------------
# error: command failed with exit status: 1
--
</details>
If these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the infrastructure label.
As far as I know, APX is only supported in 64-bit long mode.
That is the whole point. You get support when you buy new hardware. Or it confuses the user.
Andarwinux
trcrsired
I am proposing a new x86_64 windows calling convention wincall.
See History:
https://developercommunity.visualstudio.com/t/std::span-is-not-zero-cost-because-of-th/1429284
See draft details:
https://github.com/trcrsired/llvm-project/blob/wincall/llvm/docs/WinCall.md
Welcome everyone to review it and give me some feedback, Thanks.