GCC Middle and Back End API Reference
auto-profile.cc File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "backend.h"
#include "tree.h"
#include "gimple.h"
#include "predict.h"
#include "alloc-pool.h"
#include "tree-pass.h"
#include "ssa.h"
#include "cgraph.h"
#include "gcov-io.h"
#include "diagnostic-core.h"
#include "profile.h"
#include "langhooks.h"
#include "cfgloop.h"
#include "tree-cfg.h"
#include "tree-cfgcleanup.h"
#include "tree-into-ssa.h"
#include "gimple-iterator.h"
#include "value-prof.h"
#include "symbol-summary.h"
#include "sreal.h"
#include "ipa-cp.h"
#include "ipa-prop.h"
#include "ipa-fnsummary.h"
#include "ipa-inline.h"
#include "tree-inline.h"
#include "auto-profile.h"
#include "tree-pretty-print.h"
#include "gimple-pretty-print.h"
Include dependency graph for auto-profile.cc:

Data Structures

class  autofdo::edge_info
 
class  autofdo::count_info
 
struct  autofdo::string_compare
 
class  autofdo::string_table
 
class  autofdo::function_instance
 
class  autofdo::autofdo_source_profile
 

Namespaces

namespace  autofdo
 

Macros

#define INCLUDE_MAP
 
#define INCLUDE_SET
 
#define DEFAULT_AUTO_PROFILE_FILE   "fbdata.afdo"
 
#define AUTO_PROFILE_VERSION   2
 
#define AFDO_EINFO(e)
 

Typedefs

typedef std::pair< tree, unsigned > autofdo::decl_lineno
 
typedef auto_vec< decl_linenoautofdo::inline_stack
 
typedef auto_vec< char * > autofdo::string_vector
 
typedef std::map< unsigned, gcov_typeautofdo::icall_target_map
 
typedef std::set< gimple * > autofdo::stmt_set
 
typedef std::set< basic_blockautofdo::bb_set
 
typedef std::set< edgeautofdo::edge_set
 

Functions

static char * autofdo::get_original_name (const char *name)
 
static unsigned autofdo::get_combined_location (location_t loc, tree decl)
 
static tree autofdo::get_function_decl_from_block (tree block)
 
static void autofdo::get_inline_stack (location_t locus, inline_stack *stack)
 
static unsigned autofdo::get_relative_location_for_stmt (gimple *stmt)
 
static bool autofdo::has_indirect_call (basic_block bb)
 
static void autofdo::fake_read_autofdo_module_profile ()
 
static void autofdo::read_profile (void)
 
static bool autofdo::afdo_indirect_call (gimple_stmt_iterator *gsi, const icall_target_map &map, bool transform)
 
static bool autofdo::afdo_vpt (gimple_stmt_iterator *gsi, const icall_target_map &map, bool transform)
 
static bool autofdo::is_bb_annotated (const basic_block bb, const bb_set &annotated)
 
static void autofdo::set_bb_annotated (basic_block bb, bb_set *annotated)
 
static bool autofdo::afdo_set_bb_count (basic_block bb, const stmt_set &promoted)
 
static void autofdo::afdo_find_equiv_class (bb_set *annotated_bb)
 
static bool autofdo::afdo_propagate_edge (bool is_succ, bb_set *annotated_bb)
 
static void autofdo::afdo_propagate_circuit (const bb_set &annotated_bb)
 
static void autofdo::afdo_propagate (bb_set *annotated_bb)
 
static void autofdo::afdo_calculate_branch_prob (bb_set *annotated_bb)
 
static bool autofdo::afdo_vpt_for_early_inline (stmt_set *promoted_stmts)
 
static void autofdo::afdo_annotate_cfg (const stmt_set &promoted_stmts)
 
static unsigned int autofdo::early_inline ()
 
static unsigned int autofdo::auto_profile (void)
 
void read_autofdo_file (void)
 
void end_auto_profile (void)
 
bool afdo_callsite_hot_enough_for_early_inline (struct cgraph_edge *edge)
 
simple_ipa_opt_passmake_pass_ipa_auto_profile (gcc::context *ctxt)
 

Variables

static string_tableautofdo::afdo_string_table
 
static autofdo_source_profileautofdo::afdo_source_profile
 
static gcov_summaryautofdo::afdo_profile_info
 

Macro Definition Documentation

◆ AFDO_EINFO

#define AFDO_EINFO ( e)
Value:
((class edge_info *) e->aux)
Definition tree-ssa-dom.cc:67
Intermediate edge info used when propagating AutoFDO profile information.
We can't edge->count() directly since it's computed from edge's probability
while probability is yet not decided during propagation.   

Referenced by autofdo::afdo_calculate_branch_prob(), autofdo::afdo_propagate_circuit(), and autofdo::afdo_propagate_edge().

◆ AUTO_PROFILE_VERSION

#define AUTO_PROFILE_VERSION   2

Referenced by autofdo::read_profile().

◆ DEFAULT_AUTO_PROFILE_FILE

#define DEFAULT_AUTO_PROFILE_FILE   "fbdata.afdo"
The following routines implements AutoFDO optimization.

  This optimization uses sampling profiles to annotate basic block counts
  and uses heuristics to estimate branch probabilities.

  There are three phases in AutoFDO:

  Phase 1: Read profile from the profile data file.
    The following info is read from the profile datafile:
       * string_table: a map between function name and its index.
       * autofdo_source_profile: a map from function_instance name to
         function_instance. This is represented as a forest of
         function_instances.
       * WorkingSet: a histogram of how many instructions are covered for a
         given percentage of total cycles. This is describing the binary
         level information (not source level). This info is used to help
         decide if we want aggressive optimizations that could increase
         code footprint (e.g. loop unroll etc.)
    A function instance is an instance of function that could either be a
    standalone symbol, or a clone of a function that is inlined into another
    function.

  Phase 2: Early inline + value profile transformation.
    Early inline uses autofdo_source_profile to find if a callsite is:
       * inlined in the profiled binary.
       * callee body is hot in the profiling run.
    If both condition satisfies, early inline will inline the callsite
    regardless of the code growth.
    Phase 2 is an iterative process. During each iteration, we also check
    if an indirect callsite is promoted and inlined in the profiling run.
    If yes, vpt will happen to force promote it and in the next iteration,
    einline will inline the promoted callsite in the next iteration.

  Phase 3: Annotate control flow graph.
    AutoFDO uses a separate pass to:
       * Annotate basic block count
       * Estimate branch probability

  After the above 3 phases, all profile is readily annotated on the GCC IR.
  AutoFDO tries to reuse all FDO infrastructure as much as possible to make
  use of the profile. E.g. it uses existing mechanism to calculate the basic
  block/edge frequency, as well as the cgraph node/edge count.

Referenced by read_autofdo_file().

◆ INCLUDE_MAP

#define INCLUDE_MAP
Read and annotate call graph profile from the auto profile data file.
   Copyright (C) 2014-2024 Free Software Foundation, Inc.
   Contributed by Dehao Chen (dehao@google.com)

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.

GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3.  If not see
<http://www.gnu.org/licenses/>.   

◆ INCLUDE_SET

#define INCLUDE_SET

Function Documentation

◆ afdo_callsite_hot_enough_for_early_inline()

bool afdo_callsite_hot_enough_for_early_inline ( struct cgraph_edge * edge)

◆ end_auto_profile()

void end_auto_profile ( void )
Free the resources.   

References autofdo::afdo_source_profile, autofdo::afdo_string_table, NULL, and profile_info.

Referenced by compile_file().

◆ make_pass_ipa_auto_profile()

simple_ipa_opt_pass * make_pass_ipa_auto_profile ( gcc::context * ctxt)

◆ read_autofdo_file()

void read_autofdo_file ( void )
Read the profile from the profile data file.   

References autofdo::afdo_profile_info, DEFAULT_AUTO_PROFILE_FILE, NULL, autofdo::read_profile(), gcov_summary::runs, and gcov_summary::sum_max.

Referenced by coverage_init().