Hi, On Fri, Sep 17 2021, Kewen.Lin wrote: > [...] > > Against v2 [2], this v3 addressed Martin's review comments: > - Replace HWI auto_vec with unsigned int for target_info > to avoid overkill (also Segher's comments), adjust some > places need to be updated for this change. > - Annotate target_info won't be streamed for offloading > target compilers. > - Scan for all gimple statements instead of those with > non-zero size/time weights. > > Against v1 [1], the v2 addressed Richi's and Segher's review > comments, mainly consists of: > - Extend it to cover non always_inline. > - Exclude the case for offload streaming. > - Some function naming and formatting issues. > - Adjust rs6000_can_inline_p. > - Add new cases. > > Bootstrapped and regress-tested on powerpc64le-linux-gnu Power9. > > Any comments are highly appreciated! > > [1] https://gcc.gnu.org/pipermail/gcc-patches/2021-September/578555.html > [2] https://gcc.gnu.org/pipermail/gcc-patches/2021-September/579045.html > ------ > gcc/ChangeLog: > > PR ipa/102059 > * config/rs6000/rs6000-call.c (rs6000_fn_has_any_of_these_mask_bits): > New function. > * config/rs6000/rs6000-internal.h > (rs6000_fn_has_any_of_these_mask_bits): New declare. > * config/rs6000/rs6000.c (TARGET_NEED_IPA_FN_TARGET_INFO): New macro. > (TARGET_UPDATE_IPA_FN_TARGET_INFO): Likewise. > (rs6000_need_ipa_fn_target_info): New function. > (rs6000_update_ipa_fn_target_info): Likewise. > (rs6000_can_inline_p): Adjust for ipa function summary target info. > * config/rs6000/rs6000.h (RS6000_FN_TARGET_INFO_HTM): New macro. > * ipa-fnsummary.c (ipa_dump_fn_summary): Adjust for ipa function > summary target info. > (analyze_function_body): Adjust for ipa function summary target > info and call hook rs6000_need_ipa_fn_target_info and > rs6000_update_ipa_fn_target_info. > (ipa_merge_fn_summary_after_inlining): Adjust for ipa function > summary target info. > (inline_read_section): Likewise. > (ipa_fn_summary_write): Likewise. > * ipa-fnsummary.h (ipa_fn_summary::target_info): New member. > * doc/tm.texi: Regenerate. > * doc/tm.texi.in (TARGET_UPDATE_IPA_FN_TARGET_INFO): Document new > hook. > (TARGET_NEED_IPA_FN_TARGET_INFO): Likewise. > * target.def (update_ipa_fn_target_info): New hook. > (need_ipa_fn_target_info): Likewise. > * targhooks.c (default_need_ipa_fn_target_info): New function. > (default_update_ipa_fn_target_info): Likewise. > * targhooks.h (default_update_ipa_fn_target_info): New declare. > (default_need_ipa_fn_target_info): Likewise. >
[...] > diff --git a/gcc/target.def b/gcc/target.def > index 28a34f1d51b..28ff639684b 100644 > --- a/gcc/target.def > +++ b/gcc/target.def > @@ -6600,6 +6600,41 @@ specific target options and the caller does not use > the same options.", > bool, (tree caller, tree callee), > default_target_can_inline_p) > > +DEFHOOK > +(update_ipa_fn_target_info, > + "Allow target to analyze all gimple statements for the given function to\n\ > +record and update some target specific information for inlining. A > typical\n\ > +example is that a caller with one isa feature disabled is normally not\n\ > +allowed to inline a callee with that same isa feature enabled even which > is\n\ > +attributed by always_inline, but with the conservative analysis on all\n\ > +statements of the callee if we are able to guarantee the callee does not\n\ > +exploit any instructions from the mismatch isa feature, it would be safe > to\n\ > +allow the caller to inline the callee.\n\ > +@var{info} is one @code{unsigned int} value to record information in which\n\ > +one set bit indicates one corresponding feature is detected in the > analysis,\n\ > +@var{stmt} is the statement being analyzed. Return true if target still\n\ > +need to analyze the subsequent statements, otherwise return false to stop\n\ > +subsequent analysis.\n\ > +The default version of this hook returns false.", > + bool, (unsigned int& info, const gimple* stmt), > + default_update_ipa_fn_target_info) > + > +DEFHOOK > +(need_ipa_fn_target_info, > + "Allow target to check early whether it is necessary to analyze all > gimple\n\ > +statements in the given function to update target specific information for\n\ > +inlining. See hook @code{update_ipa_fn_target_info} for usage example of\n\ > +target specific information. This hook is expected to be invoked ahead of\n\ > +the iterating with hook @code{update_ipa_fn_target_info}.\n\ > +@var{decl} is the function being analyzed, @var{info} is the same as what\n\ > +in hook @code{update_ipa_fn_target_info}, target can do one time update\n\ > +into @var{info} without iterating for some case. Return true if target\n\ > +decides to analyze all gimple statements to collect information, otherwise\n\ > +return false.\n\ > +The default version of this hook returns false.", > + bool, (const_tree decl, unsigned int& info), > + default_need_ipa_fn_target_info) > + > DEFHOOK > (relayout_function, > "This target hook fixes function @var{fndecl} after attributes are > processed.\n\ > diff --git a/gcc/targhooks.c b/gcc/targhooks.c > index c9b5208853d..5ba539cef1a 100644 > --- a/gcc/targhooks.c > +++ b/gcc/targhooks.c > @@ -1765,6 +1765,22 @@ default_target_can_inline_p (tree caller, tree callee) > return callee_opts == caller_opts; > } > > +/* By default, return false to not need to collect any target information > + for inlining. Target maintainer should re-define the hook if the > + target want to take advantage of it. */ > + > +bool > +default_need_ipa_fn_target_info (const_tree, uint16_t &) > +{ > + return false; > +} > + > +bool > +default_update_ipa_fn_target_info (uint16_t &, const gimple *) > +{ > + return false; > +} The parameters have uint16_t type here but you apparently decided to use unsigned int everywhere else, you probably forgot to change them here too. Martin