@@ -21483,6 +21483,17 @@ aarch64_expand_builtin_va_start (tree valist, rtx nextarg ATTRIBUTE_UNUSED)
2148321483 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2148421484}
2148521485
21486+ #ifdef TARGET_AARCH64_MS_ABI
21487+
21488+ static void
21489+ aarch64_ms_abi_expand_builtin_va_start (tree valist, rtx nextarg)
21490+ {
21491+ nextarg = plus_constant (Pmode, nextarg, -cfun->gr_saved * UNITS_PER_WORD); // -56
21492+ std_expand_builtin_va_start (valist, nextarg);
21493+ }
21494+
21495+ #endif
21496+
2148621497/* Implement TARGET_GIMPLIFY_VA_ARG_EXPR. */
2148721498
2148821499static tree
@@ -21787,7 +21798,7 @@ aarch64_setup_incoming_varargs (cumulative_args_t cum_v,
2178721798{
2178821799 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
2178921800 CUMULATIVE_ARGS local_cum;
21790- int gr_saved = cfun->va_list_gpr_size;
21801+ cfun-> gr_saved = cfun->va_list_gpr_size;
2179121802 int vr_saved = cfun->va_list_fpr_size;
2179221803
2179321804 /* The caller has advanced CUM up to, but not beyond, the last named
@@ -21800,7 +21811,7 @@ aarch64_setup_incoming_varargs (cumulative_args_t cum_v,
2180021811 /* Found out how many registers we need to save.
2180121812 Honor tree-stdvar analysis results. */
2180221813 if (cfun->va_list_gpr_size)
21803- gr_saved = MIN (NUM_ARG_REGS - local_cum.aapcs_ncrn,
21814+ cfun-> gr_saved = MIN (NUM_ARG_REGS - local_cum.aapcs_ncrn,
2180421815 cfun->va_list_gpr_size / UNITS_PER_WORD);
2180521816 if (cfun->va_list_fpr_size)
2180621817 vr_saved = MIN (NUM_FP_ARG_REGS - local_cum.aapcs_nvrn,
@@ -21814,18 +21825,18 @@ aarch64_setup_incoming_varargs (cumulative_args_t cum_v,
2181421825
2181521826 if (!no_rtl)
2181621827 {
21817- if (gr_saved > 0)
21828+ if (cfun-> gr_saved > 0)
2181821829 {
2181921830 rtx ptr, mem;
2182021831
2182121832 /* virtual_incoming_args_rtx should have been 16-byte aligned. */
2182221833 ptr = plus_constant (Pmode, virtual_incoming_args_rtx,
21823- - gr_saved * UNITS_PER_WORD);
21834+ - cfun-> gr_saved * UNITS_PER_WORD);
2182421835 mem = gen_frame_mem (BLKmode, ptr);
2182521836 set_mem_alias_set (mem, get_varargs_alias_set ());
2182621837
2182721838 move_block_from_reg (local_cum.aapcs_ncrn + R0_REGNUM,
21828- mem, gr_saved);
21839+ mem, cfun-> gr_saved);
2182921840 }
2183021841 if (vr_saved > 0)
2183121842 {
@@ -21837,7 +21848,7 @@ aarch64_setup_incoming_varargs (cumulative_args_t cum_v,
2183721848 /* Set OFF to the offset from virtual_incoming_args_rtx of
2183821849 the first vector register. The VR save area lies below
2183921850 the GR one, and is aligned to 16 bytes. */
21840- off = -ROUND_UP (gr_saved * UNITS_PER_WORD,
21851+ off = -ROUND_UP (cfun-> gr_saved * UNITS_PER_WORD,
2184121852 STACK_BOUNDARY / BITS_PER_UNIT);
2184221853 off -= vr_saved * UNITS_PER_VREG;
2184321854
@@ -21858,7 +21869,7 @@ aarch64_setup_incoming_varargs (cumulative_args_t cum_v,
2185821869 /* We don't save the size into *PRETEND_SIZE because we want to avoid
2185921870 any complication of having crtl->args.pretend_args_size changed. */
2186021871 cfun->machine->frame.saved_varargs_size
21861- = (ROUND_UP (gr_saved * UNITS_PER_WORD,
21872+ = (ROUND_UP (cfun-> gr_saved * UNITS_PER_WORD,
2186221873 STACK_BOUNDARY / BITS_PER_UNIT)
2186321874 + vr_saved * UNITS_PER_VREG);
2186421875}
@@ -22634,9 +22645,12 @@ static const char *
2263422645aarch64_mangle_type (const_tree type)
2263522646{
2263622647 /* The AArch64 ABI documents say that "__va_list" has to be
22637- mangled as if it is in the "std" namespace. */
22648+ mangled as if it is in the "std" namespace.
22649+ The Windows Arm64 ABI uses just an address of the first variadict argument. */
22650+ #ifndef TARGET_AARCH64_MS_ABI
2263822651 if (lang_hooks.types_compatible_p (CONST_CAST_TREE (type), va_list_type))
2263922652 return "St9__va_list";
22653+ #endif
2264022654
2264122655 /* Half-precision floating point types. */
2264222656 if (SCALAR_FLOAT_TYPE_P (type) && TYPE_PRECISION (type) == 16)
@@ -30986,8 +31000,10 @@ aarch64_run_selftests (void)
3098631000#undef TARGET_ASM_PRINT_PATCHABLE_FUNCTION_ENTRY
3098731001#define TARGET_ASM_PRINT_PATCHABLE_FUNCTION_ENTRY aarch64_print_patchable_function_entry
3098831002
31003+ #ifndef TARGET_AARCH64_MS_ABI
3098931004#undef TARGET_BUILD_BUILTIN_VA_LIST
3099031005#define TARGET_BUILD_BUILTIN_VA_LIST aarch64_build_builtin_va_list
31006+ #endif
3099131007
3099231008#undef TARGET_CALLEE_COPIES
3099331009#define TARGET_CALLEE_COPIES hook_bool_CUMULATIVE_ARGS_arg_info_false
@@ -31058,7 +31074,11 @@ aarch64_run_selftests (void)
3105831074#define TARGET_EXPAND_BUILTIN aarch64_expand_builtin
3105931075
3106031076#undef TARGET_EXPAND_BUILTIN_VA_START
31077+ #ifdef TARGET_AARCH64_MS_ABI
31078+ #define TARGET_EXPAND_BUILTIN_VA_START aarch64_ms_abi_expand_builtin_va_start
31079+ #else
3106131080#define TARGET_EXPAND_BUILTIN_VA_START aarch64_expand_builtin_va_start
31081+ #endif
3106231082
3106331083#undef TARGET_FOLD_BUILTIN
3106431084#define TARGET_FOLD_BUILTIN aarch64_fold_builtin
@@ -31098,8 +31118,10 @@ aarch64_run_selftests (void)
3109831118#undef TARGET_GIMPLE_FOLD_BUILTIN
3109931119#define TARGET_GIMPLE_FOLD_BUILTIN aarch64_gimple_fold_builtin
3110031120
31121+ #ifndef TARGET_AARCH64_MS_ABI
3110131122#undef TARGET_GIMPLIFY_VA_ARG_EXPR
3110231123#define TARGET_GIMPLIFY_VA_ARG_EXPR aarch64_gimplify_va_arg_expr
31124+ #endif
3110331125
3110431126#undef TARGET_INIT_BUILTINS
3110531127#define TARGET_INIT_BUILTINS aarch64_init_builtins
0 commit comments