> From: Dhruv Chawla <dhr...@nvidia.com> > > This patch modifies afdo_set_bb_count to propagate profile information > to outline copies of functions if they are not inlined. This information > gets lost otherwise. > > Signed-off-by: Dhruv Chawla <dhr...@nvidia.com> > > gcc/ChangeLog: > > * gcc/auto-profile.cc (count_info): Adjust comments. > (function_instance::in_afdo_source_profile): New function. > (function_instance::set_in_afdo_source_profile): Likewise. > (function_instance::get_callsites): Likewise. > (autofdo_source_profile::add_function_instance): Likewise. > (function_instance::in_afdo_source_profile_): New member. > (autofdo_source_profile::~autofdo_source_profile): Use > in_afdo_source_profile to prevent a double-free bug. > (afdo_set_bb_count): Propagate inline information to non-inlined > outline copy.
> @@ -230,6 +224,10 @@ public: > return head_count_; > } > > + bool in_afdo_source_profile () const { return in_afdo_source_profile_; } > + > + void set_in_afdo_source_profile () { in_afdo_source_profile_ = true; } > /* Map from source location to count_info. */ > position_count_map pos_counts; > + > + /* If this is an inline instance tracked in afdo_source_profile. */ > + bool in_afdo_source_profile_; What about calling it is_inline_instance? I think it is more self-explanatory of what it is useful for. > @@ -814,6 +825,24 @@ autofdo_source_profile::update_inlined_ind_target (gcall > *stmt, > return true; > } > > +/* Add a new function_instance entry if an inlined function is found in the > + profile that doesn't have a corresponding entry in the map. Return false > if > + the function_instance already exists, true if it doesn't. */ > + > +bool > +autofdo_source_profile::add_function_instance (function_instance *fun) > +{ > + int name = fun->name (); > + if (auto fun_it = map_.find (name); fun_it != map_.end ()) > + { > + fun_it->second->merge (fun); Assume that we have call chain foo->bar->baz and assume that this was inlined in the train run, while after early inlining we inline bar->baz but not foo->bar. Will we then also recursively merge foo->bar->baz profile into bar->baz? > @@ -1144,6 +1173,31 @@ afdo_set_bb_count (basic_block bb, const stmt_set > &promoted) > gimple *stmt = gsi_stmt (gsi); > if (gimple_clobber_p (stmt) || is_gimple_debug (stmt)) > continue; > + if (gimple_code (stmt) == GIMPLE_CALL) > + { > + tree fn = gimple_call_fndecl (stmt); > + function_instance *cur > + = afdo_source_profile->get_function_instance_by_decl ( > + current_function_decl); > + if (!cur || !fn) > + continue; I think we want to do the merging in a global pass before annotation starts (to solve the dependency). I think you can relatively cheaply walk all functions in callgraph, all edges and for each edge see if it the statement is inlined in profile and do the merging... Honza