mirror of
https://forge.sourceware.org/marek/gcc.git
synced 2026-02-22 03:47:02 -05:00
The patch enables time profile based reordering with AutoFDO with -fauto-profile -fprofile-reorder-functions, by mapping timestamps obtained from perf into node->tp_first_run. The rationale for doing this is: (1) GCC already implements time-profile function reordering with PGO, the patch enables it with AutoFDO. (2) While time profile ordering is primarly meant for optimizing startup time, we've also observed good effects on code-locality for large internal workloads. (3) Possibly useful for function reordering when accurate profile annotation is hard with AutoFDO -- For eg, if branch samples are missing (due to absence of LBR like structure). On AutoFDO tools side, a corresponding patch extends gcov to emit 64-bit perf timestamp that records first execution of function, which loosely corresponds to PGO's time_profile counter. The timestamp is stored adjacent to head field in toplevel function info. On GCC side, this patch makes the following changes: (1) Changes to auto-profile pass: The patch adds a new field timestamp to function_instance, and populates it in read_function_instance. It maintains a new timestamp_info_map from timestamp -> <name, tp_first_run>, which maps timestamps sorted in ascending order to (1..N), so lowest ordered timestamp is mapped to 1 and so on. The rationale for this is that timestamps are 64-bit integers, and we don't need the full 64-bit range for ordering by tp_first_run. During annotation, the timestamp associated with function_instance is looked up in timestamp_info_map, and corresponding mapped value is assigned to node->tp_first_run. Dhruv's sourcefile tracking patch already handles LTO privatized symbols. The patch adds a workaround for mismatched/empty filenames, which should go away when the issues with AutoFDO tools dwarf parsing are resolved. (2) Param to disable profile driven opts. The patch adds param auto-profile-reorder-only which only enables time-profile reordering with AutoFDO: (a) Useful as a debugging aid to isolate regression to either function reordering or profile driven opts. (b) As a stopgap measure to avoid regressions with AutoFDO profile driven opts. (c) Possibly useful for architectures which do not support branch sampling. gcc/ChangeLog: * auto-profile.cc: (string_table::filenames): New method. (function_instance::timestamp_): New member. (function_instance::timestamp): New accessor for timestamp_ member. (function_instance::set_timestamp): New function. (function_instance::prop_timestamp): Likewise. (function_instance::prop_timestamp_1): Likewise. (function_instance::function_instance): Initialize timestamp_ to 0. (function_instance::read_function_instance): Adjust prototype by replacing head_count with toplevel param with default value true, and stream in head_count and timestamp values from gcov file. (autofdo::timestamp_info_map): New std::map. (autofdo_source_profile::get_function_instance_by_decl): New argument filename with default value NULL. (autofdo_source_profile::read): Populate timestamp_info_map and propagate timestamp to inlined instances from toplevel function. (afdo_annotate_cfg): Assign node->tp_first_run based on timestamp_info_map and bail out of annotation if param_auto_profile_reorder_only is enabled. * params.opt: New param auto-profile-reorder-only. Signed-off-by: Prathamesh Kulkarni <prathameshk@nvidia.com>
66 KiB
66 KiB