Skip to content

Commit 217e1d6

Browse files
committed
Darwin, Arm64 : Proof-of-principle hack Fortran to use descriptors for nested.
This adds a descriptor-based implementation and then addresses Issue gcc-mirror#32 by adjusting the nested function hack to use bit 1 rather than bit 2. NOTE: that Arm reserve both bits 0 and 1 for furture use, so that this is no less a hack than using bit 2 - but it might be a somewhat more compatible hack. Tested with the example in Issue gcc-mirror#32 (otherwise, there's no real change in the testsuite).
1 parent 3d5244d commit 217e1d6

File tree

6 files changed

+30
-2
lines changed

6 files changed

+30
-2
lines changed

gcc/c/c-lang.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ enum c_language_kind c_language = clk_c;
3838
#undef LANG_HOOKS_INIT_TS
3939
#define LANG_HOOKS_INIT_TS c_common_init_ts
4040

41+
#undef LANG_HOOKS_CUSTOM_FUNCTION_DESCRIPTORS
42+
#define LANG_HOOKS_CUSTOM_FUNCTION_DESCRIPTORS true
43+
4144
#if CHECKING_P
4245
#undef LANG_HOOKS_RUN_LANG_SELFTESTS
4346
#define LANG_HOOKS_RUN_LANG_SELFTESTS selftest::run_c_tests

gcc/config/aarch64/aarch64.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26573,9 +26573,9 @@ aarch64_libgcc_floating_mode_supported_p
2657326573
#define TARGET_DWARF_POLY_INDETERMINATE_VALUE \
2657426574
aarch64_dwarf_poly_indeterminate_value
2657526575

26576-
/* The architecture reserves bits 0 and 1 so use bit 2 for descriptors. */
26576+
/* The architecture reserves bits 0 and 1 but hack 1 for now. */
2657726577
#undef TARGET_CUSTOM_FUNCTION_DESCRIPTORS
26578-
#define TARGET_CUSTOM_FUNCTION_DESCRIPTORS 4
26578+
#define TARGET_CUSTOM_FUNCTION_DESCRIPTORS 2
2657926579

2658026580
#undef TARGET_HARD_REGNO_NREGS
2658126581
#define TARGET_HARD_REGNO_NREGS aarch64_hard_regno_nregs

gcc/config/i386/darwin.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,3 +308,8 @@ along with GCC; see the file COPYING3. If not see
308308
#define CLEAR_INSN_CACHE(beg, end) \
309309
extern void sys_icache_invalidate(void *start, size_t len); \
310310
sys_icache_invalidate ((beg), (size_t)((end)-(beg)))
311+
312+
/* Make sure that any code we generate is compatible with the Fortran/Ada
313+
function descriptor impl. */
314+
#undef FUNCTION_BOUNDARY
315+
#define FUNCTION_BOUNDARY 16

gcc/fortran/f95-lang.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ static const struct attribute_spec gfc_attribute_table[] =
175175
#define LANG_HOOKS_BUILTIN_FUNCTION gfc_builtin_function
176176
#define LANG_HOOKS_GET_ARRAY_DESCR_INFO gfc_get_array_descr_info
177177
#define LANG_HOOKS_ATTRIBUTE_TABLE gfc_attribute_table
178+
#undef LANG_HOOKS_CUSTOM_FUNCTION_DESCRIPTORS
179+
#define LANG_HOOKS_CUSTOM_FUNCTION_DESCRIPTORS true
178180

179181
struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
180182

gcc/fortran/trans-expr.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7637,6 +7637,8 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym,
76377637
arglist = retargs;
76387638

76397639
/* Generate the actual call. */
7640+
bool is_proc_ptr_comp = gfc_is_proc_ptr_comp (expr);
7641+
76407642
if (base_object == NULL_TREE)
76417643
conv_function_val (se, sym, expr, args);
76427644
else
@@ -7662,6 +7664,11 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym,
76627664

76637665
fntype = TREE_TYPE (TREE_TYPE (se->expr));
76647666
se->expr = build_call_vec (TREE_TYPE (fntype), se->expr, arglist);
7667+
tree ff = CALL_EXPR_FN (se->expr);
7668+
if (ff && INDIRECT_REF_P (ff))
7669+
ff = TREE_OPERAND (ff, 0);
7670+
if (is_proc_ptr_comp || !ff || VAR_P (ff) || TREE_CODE (ff) == PARM_DECL)
7671+
CALL_EXPR_BY_DESCRIPTOR (se->expr) = true;
76657672

76667673
/* Allocatable scalar function results must be freed and nullified
76677674
after use. This necessitates the creation of a temporary to

gcc/fortran/trans.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,14 @@ gfc_build_addr_expr (tree type, tree t)
332332
else
333333
natural_type = build_pointer_type (base_type);
334334

335+
/* If this is a nested function that uses the static chain, or if
336+
optimization is disabled (a static chain will be added automatically)
337+
then call by descriptor. */
338+
bool fn_with_static_chain = false;
339+
if (TREE_CODE (t) == FUNCTION_DECL
340+
&& (DECL_STATIC_CHAIN (t) || (!optimize && decl_function_context (t))))
341+
fn_with_static_chain = true;
342+
335343
if (TREE_CODE (t) == INDIRECT_REF)
336344
{
337345
if (!type)
@@ -350,6 +358,9 @@ gfc_build_addr_expr (tree type, tree t)
350358
if (type && natural_type != type)
351359
t = convert (type, t);
352360

361+
if (fn_with_static_chain)
362+
FUNC_ADDR_BY_DESCRIPTOR (t) = true;
363+
353364
return t;
354365
}
355366

0 commit comments

Comments
 (0)