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 Loosemore <san...@codesourcery.com> gcc/ * 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 (&finish_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