Re: [patch 2/5] add hook to track when splitting is complete
On Sat, Oct 21, 2017 at 11:17 PM, Sandra Loosemorewrote: > On 10/20/2017 02:24 AM, Richard Biener wrote: >> >> On Fri, Oct 20, 2017 at 4:09 AM, Sandra Loosemore >> wrote: >>> >>> This patch adds a function to indicate whether the split1 pass has run >>> yet. This is used in part 3 of the patch set to decide whether 32-bit >>> symbolic constant expressions are permitted, e.g. in >>> TARGET_LEGITIMATE_ADDRESS_P and the movsi expander. >>> >>> Since there's currently no usable hook for querying the pass manager >>> where it is relative to another pass, I implemented this using a >>> target-specific pass that runs directly after split1 and does nothing >>> but set a flag. >> >> >> "Nice" hack ;) The only currently existing way would be to add a property >> to the IL state like >> >> const pass_data pass_data_split_all_insns = >> { >>RTL_PASS, /* type */ >>"split1", /* name */ >>OPTGROUP_NONE, /* optinfo_flags */ >>TV_NONE, /* tv_id */ >>0, /* properties_required */ >>PROP_rtl_split_insns, /* properties_provided */ >>0, /* properties_destroyed */ >> >> and test that via cfun->curr_properties & PROP_rtl_split_insns >> >> Having run split might be a important enough change to warrant this. >> Likewise reload_completed and reload_in_progress could be transitioned >> to IL properties. >> >> Richard. > > > Well, here's a new version of this patch that implements what you suggested > above. It's certainly simpler than the original version, or the WIP patch I > posted before to add a general hook based on enumerating the passes. Is > this OK? +#define PROP_rtl_split_insns (1 << 17) /* split1 completed. */ /* RTL has insns split. */ that is, do not mention 'split1' specifically. Ok with that change. Thanks, Richard. > -Sandra >
Re: [patch 2/5] add hook to track when splitting is complete
On 10/20/2017 02:24 AM, Richard Biener wrote: On Fri, Oct 20, 2017 at 4:09 AM, Sandra Loosemorewrote: This patch adds a function to indicate whether the split1 pass has run yet. This is used in part 3 of the patch set to decide whether 32-bit symbolic constant expressions are permitted, e.g. in TARGET_LEGITIMATE_ADDRESS_P and the movsi expander. Since there's currently no usable hook for querying the pass manager where it is relative to another pass, I implemented this using a target-specific pass that runs directly after split1 and does nothing but set a flag. "Nice" hack ;) The only currently existing way would be to add a property to the IL state like const pass_data pass_data_split_all_insns = { RTL_PASS, /* type */ "split1", /* name */ OPTGROUP_NONE, /* optinfo_flags */ TV_NONE, /* tv_id */ 0, /* properties_required */ PROP_rtl_split_insns, /* properties_provided */ 0, /* properties_destroyed */ and test that via cfun->curr_properties & PROP_rtl_split_insns Having run split might be a important enough change to warrant this. Likewise reload_completed and reload_in_progress could be transitioned to IL properties. Richard. Well, here's a new version of this patch that implements what you suggested above. It's certainly simpler than the original version, or the WIP patch I posted before to add a general hook based on enumerating the passes. Is this OK? -Sandra 2017-10-21 Sandra Loosemore gcc/ * tree-hass.h (PROP_rtl_split_insns): Define. * recog.c (pass_data_split_all_insns): Provide PROP_rtl_split_insns. * config/nios2/nios2.c: Adjust includes. (nios2_symbolic_constant_allowed): New. diff --git a/gcc/tree-pass.h b/gcc/tree-pass.h index 9f76d82..21bde1c 100644 --- a/gcc/tree-pass.h +++ b/gcc/tree-pass.h @@ -223,6 +223,7 @@ protected: current choices have been optimized. */ #define PROP_gimple_lomp_dev (1 << 16) /* done omp_device_lower */ +#define PROP_rtl_split_insns (1 << 17) /* split1 completed. */ #define PROP_trees \ (PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh | PROP_gimple_lomp) diff --git a/gcc/recog.c b/gcc/recog.c index b8e9b1b..6bf8164 100644 --- a/gcc/recog.c +++ b/gcc/recog.c @@ -3862,7 +3862,7 @@ const pass_data pass_data_split_all_insns = OPTGROUP_NONE, /* optinfo_flags */ TV_NONE, /* tv_id */ 0, /* properties_required */ - 0, /* properties_provided */ + PROP_rtl_split_insns, /* properties_provided */ 0, /* properties_destroyed */ 0, /* todo_flags_start */ 0, /* todo_flags_finish */ diff --git a/gcc/config/nios2/nios2.c b/gcc/config/nios2/nios2.c index 3e55673..f5963d4 100644 --- a/gcc/config/nios2/nios2.c +++ b/gcc/config/nios2/nios2.c @@ -48,6 +48,7 @@ #include "langhooks.h" #include "stor-layout.h" #include "builtins.h" +#include "tree-pass.h" /* This file should be included last. */ #include "target-def.h" @@ -1976,6 +1977,19 @@ nios2_validate_compare (machine_mode mode, rtx *cmp, rtx *op1, rtx *op2) /* Addressing modes and constants. */ +/* Symbolic constants are split into high/lo_sum pairs during the + split1 pass. After that, they are not considered legitimate addresses. + This function returns true if in a pre-split context where these + constants are allowed. */ +static bool +nios2_symbolic_constant_allowed (void) +{ + /* The reload_completed check is for the benefit of + nios2_asm_output_mi_thunk and perhaps other places that try to + emulate a post-reload pass. */ + return !(cfun->curr_properties & PROP_rtl_split_insns) && !reload_completed; +} + /* Return true if X is constant expression with a reference to an "ordinary" symbol; not GOT-relative, not GP-relative, not TLS. */ static bool
Re: [patch 2/5] add hook to track when splitting is complete
On Fri, Oct 20, 2017 at 4:09 AM, Sandra Loosemorewrote: > This patch adds a function to indicate whether the split1 pass has run > yet. This is used in part 3 of the patch set to decide whether 32-bit > symbolic constant expressions are permitted, e.g. in > TARGET_LEGITIMATE_ADDRESS_P and the movsi expander. > > Since there's currently no usable hook for querying the pass manager > where it is relative to another pass, I implemented this using a > target-specific pass that runs directly after split1 and does nothing > but set a flag. "Nice" hack ;) The only currently existing way would be to add a property to the IL state like const pass_data pass_data_split_all_insns = { RTL_PASS, /* type */ "split1", /* name */ OPTGROUP_NONE, /* optinfo_flags */ TV_NONE, /* tv_id */ 0, /* properties_required */ PROP_rtl_split_insns, /* properties_provided */ 0, /* properties_destroyed */ and test that via cfun->curr_properties & PROP_rtl_split_insns Having run split might be a important enough change to warrant this. Likewise reload_completed and reload_in_progress could be transitioned to IL properties. Richard. > -Sandra >
[patch 2/5] add hook to track when splitting is complete
This patch adds a function to indicate whether the split1 pass has run yet. This is used in part 3 of the patch set to decide whether 32-bit symbolic constant expressions are permitted, e.g. in TARGET_LEGITIMATE_ADDRESS_P and the movsi expander. Since there's currently no usable hook for querying the pass manager where it is relative to another pass, I implemented this using a target-specific pass that runs directly after split1 and does nothing but set a flag. -Sandra 2017-10-19 Sandra Loosemoregcc/ * config/nios2/nios2_protos.h (nios2_init_expanders): Declare. * config/nios2/nios2.c: Adjust includes. (split_completed): New. (nios2_symbolic_constant_allowed): New. (nios2_init_expanders): New. (nios2_postsplit_pass_data): New. (class pass_nios2_postsplit): New. (make_nios2_postsplit): New. (nios2_option_override): Register postsplit pass. * config/nios2/nios2.h (INIT_EXPANDERS): Define. diff --git a/gcc/config/nios2/nios2-protos.h b/gcc/config/nios2/nios2-protos.h index 4478334..925d46a 100644 --- a/gcc/config/nios2/nios2-protos.h +++ b/gcc/config/nios2/nios2-protos.h @@ -28,6 +28,7 @@ extern void nios2_expand_prologue (void); extern void nios2_expand_epilogue (bool); extern bool nios2_expand_return (void); extern void nios2_function_profiler (FILE *, int); +extern void nios2_init_expanders (void); #ifdef RTX_CODE extern bool nios2_emit_move_sequence (rtx *, machine_mode); diff --git a/gcc/config/nios2/nios2.c b/gcc/config/nios2/nios2.c index 659250a..120adb5 100644 --- a/gcc/config/nios2/nios2.c +++ b/gcc/config/nios2/nios2.c @@ -47,6 +47,8 @@ #include "toplev.h" #include "langhooks.h" #include "stor-layout.h" +#include "tree-pass.h" +#include "context.h" #include "builtins.h" /* This file should be included last. */ @@ -101,6 +103,71 @@ static int custom_code_index[256]; static bool custom_code_conflict = false; +/* Support for target-specific postsplit pass. */ + +/* Symbolic constants are split into high/lo_sum pairs during the + split1 pass. After that, they are not considered legitimate addresses. + In order to keep track of whether or not we can generate or recognize + symbolic constants, we use a target-specific pass that runs + immediately after split1 and does nothing but set a flag we can check. */ + +static bool split_completed = false; + +static bool +nios2_symbolic_constant_allowed (void) +{ + /* The reload_completed check is for the benefit of + nios2_asm_output_mi_thunk and perhaps other places that try to + emulate a post-reload pass. */ + return !split_completed && !reload_completed; +} + +/* Use INIT_EXPANDERS to ensure that split_completed is reset before + compiling every function. */ +void +nios2_init_expanders (void) +{ + split_completed = false; +} + +namespace { + +static const pass_data nios2_postsplit_pass_data = +{ + RTL_PASS, // type + "nios2_postsplit", // name + OPTGROUP_NONE, // optinfo_flags + TV_REST_OF_COMPILATION,// tv_id + 0, // properties_required + 0, // properties_provided + 0, // properties_destroyed + 0, // todo_flags_start + 0 // todo_flags_finish +}; + +class pass_nios2_postsplit : public rtl_opt_pass +{ + public: + pass_nios2_postsplit (gcc::context *ctxt) +: rtl_opt_pass (nios2_postsplit_pass_data, ctxt) + {} + + virtual unsigned int execute (function *) +{ + split_completed = true; + return 0; +} +}; + +} /* Anonymous namespace */ + +rtl_opt_pass * +make_nios2_postsplit (gcc::context *ctxt) +{ + return new pass_nios2_postsplit (ctxt); +} + + /* Definition of builtin function types for nios2. */ #define N2_FTYPES\ @@ -1407,6 +1474,12 @@ nios2_option_override (void) nios2_custom_check_insns (); + /* Register target-specific passes. */ + opt_pass *postsplit = make_nios2_postsplit (g); + struct register_pass_info finish_split_info += { postsplit, "split1", 1, PASS_POS_INSERT_AFTER }; + register_pass (_split_info); + /* Save the initial options in case the user does function specific options. */ target_option_default_node = target_option_current_node diff --git a/gcc/config/nios2/nios2.h b/gcc/config/nios2/nios2.h index 10bebfb..d077dc5 100644 --- a/gcc/config/nios2/nios2.h +++ b/gcc/config/nios2/nios2.h @@ -503,6 +503,9 @@ do {\ #define ASM_PREFERRED_EH_DATA_FORMAT(CODE, GLOBAL) \ (flag_pic ? DW_EH_PE_aligned : DW_EH_PE_sdata4) +/* Target-specific initialization. */ +#define INIT_EXPANDERS nios2_init_expanders () + /* Misc. parameters. */ #define STORE_FLAG_VALUE 1