GCC Middle and Back End API Reference
graph.cc File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "backend.h"
#include "cfghooks.h"
#include "pretty-print.h"
#include "diagnostic-core.h"
#include "cfganal.h"
#include "cfgloop.h"
#include "graph.h"
#include "dumpfile.h"
Include dependency graph for graph.cc:

Functions

static FILEopen_graph_file (const char *base, const char *mode)
 
static void draw_cfg_node (pretty_printer *pp, int funcdef_no, basic_block bb)
 
static void draw_cfg_node_succ_edges (pretty_printer *pp, int funcdef_no, basic_block bb)
 
static void draw_cfg_nodes_no_loops (pretty_printer *pp, struct function *fun)
 
static void draw_cfg_nodes_for_loop (pretty_printer *pp, int funcdef_no, class loop *loop)
 
static void draw_cfg_nodes (pretty_printer *pp, struct function *fun)
 
static void draw_cfg_edges (pretty_printer *pp, struct function *fun)
 
void DEBUG_FUNCTION print_graph_cfg (FILE *fp, struct function *fun)
 
void DEBUG_FUNCTION print_graph_cfg (FILE *fp, struct function *fun, dump_flags_t flags)
 
void print_graph_cfg (const char *base, struct function *fun)
 
static void start_graph_dump (FILE *fp, const char *base)
 
static void end_graph_dump (FILE *fp)
 
void clean_graph_dump_file (const char *base)
 
void finish_graph_dump_file (const char *base)
 

Variables

static const char *const graph_ext = ".dot"
 

Function Documentation

◆ clean_graph_dump_file()

void clean_graph_dump_file ( const char * base)
Similar as clean_dump_file, but this time for graph output files.   

References ggc_alloc(), open_graph_file(), and start_graph_dump().

Referenced by execute_function_dump(), and pass_init_dump_file().

◆ draw_cfg_edges()

static void draw_cfg_edges ( pretty_printer * pp,
struct function * fun )
static
Draw all edges in the CFG.  Retreating edges are drawin as not
constraining, this makes the layout of the graph better.   

References bitmap_bit_p, bitmap_set_bit, draw_cfg_node_succ_edges(), ENTRY_BLOCK, EXIT_BLOCK, FOR_ALL_BB_FN, FOR_EACH_BB_FN, FOR_EACH_EDGE, function::funcdef_no, ggc_alloc(), mark_dfs_back_edges(), pp_flush(), pp_printf(), and basic_block_def::succs.

Referenced by print_graph_cfg().

◆ draw_cfg_node()

static void draw_cfg_node ( pretty_printer * pp,
int funcdef_no,
basic_block bb )
static
Disable warnings about quoting issues in the pp_xxx calls below
that (intentionally) don't follow GCC diagnostic conventions.   
Draw a basic block BB belonging to the function with FUNCDEF_NO
as its unique number.   

References BB_PARTITION, dump_bb_for_graph(), ENTRY_BLOCK, EXIT_BLOCK, funcdef_no, ggc_alloc(), basic_block_def::index, pp_flush(), pp_left_brace, pp_printf(), pp_right_brace, pp_string(), and pp_write_text_to_stream().

Referenced by draw_cfg_nodes_for_loop(), and draw_cfg_nodes_no_loops().

◆ draw_cfg_node_succ_edges()

static void draw_cfg_node_succ_edges ( pretty_printer * pp,
int funcdef_no,
basic_block bb )
static
Draw all successor edges of a basic block BB belonging to the function
with FUNCDEF_NO as its unique number.   

References color(), FOR_EACH_EDGE, funcdef_no, ggc_alloc(), pp_flush(), pp_printf(), REG_BR_PROB_BASE, and basic_block_def::succs.

Referenced by draw_cfg_edges().

◆ draw_cfg_nodes()

static void draw_cfg_nodes ( pretty_printer * pp,
struct function * fun )
static
Draw all the basic blocks in the CFG in case the loop tree is available.
All loop bodys are printed in clusters.   

References cfun, draw_cfg_nodes_for_loop(), draw_cfg_nodes_no_loops(), function::funcdef_no, get_loop(), and loops_for_fn().

Referenced by print_graph_cfg().

◆ draw_cfg_nodes_for_loop()

static void draw_cfg_nodes_for_loop ( pretty_printer * pp,
int funcdef_no,
class loop * loop )
static
Draw all the basic blocks in LOOP.  Print the blocks in breath-first
order to get a good ranking of the nodes.  This function is recursive:
It first prints inner loops, then the body of LOOP itself.   

References cfun, draw_cfg_node(), draw_cfg_nodes_for_loop(), EXIT_BLOCK_PTR_FOR_FN, free(), funcdef_no, get_loop_body(), get_loop_body_in_bfs_order(), ggc_alloc(), loop::header, i, loop::inner, loop::latch, loop_depth(), basic_block_def::loop_father, NULL, loop::num, loop::num_nodes, and pp_printf().

Referenced by draw_cfg_nodes(), and draw_cfg_nodes_for_loop().

◆ draw_cfg_nodes_no_loops()

static void draw_cfg_nodes_no_loops ( pretty_printer * pp,
struct function * fun )
static
Draw all the basic blocks in the CFG in case loops are not available.
First compute a topological order of the blocks to get a good ranking of
the nodes.  Then, if any nodes are not reachable from ENTRY, add them at
the end.   

References BASIC_BLOCK_FOR_FN, bitmap_bit_p, bitmap_clear(), bitmap_set_bit, draw_cfg_node(), FOR_ALL_BB_FN, free(), function::funcdef_no, ggc_alloc(), i, basic_block_def::index, last_basic_block_for_fn, n_basic_blocks_for_fn, NULL, pre_and_rev_post_order_compute_fn(), and visited.

Referenced by draw_cfg_nodes().

◆ end_graph_dump()

static void end_graph_dump ( FILE * fp)
static
End the dump of a graph.   

References ggc_alloc().

Referenced by finish_graph_dump_file().

◆ finish_graph_dump_file()

void finish_graph_dump_file ( const char * base)
Do final work on the graph output file.   

References end_graph_dump(), ggc_alloc(), and open_graph_file().

Referenced by emergency_dump_function(), and gcc::pass_manager::finish_optimization_passes().

◆ open_graph_file()

static FILE * open_graph_file ( const char * base,
const char * mode )
static
Open a file with MODE for dumping our graph to.
Return the file pointer.   

References fatal_error(), fopen, ggc_alloc(), graph_ext, input_location, and NULL.

Referenced by clean_graph_dump_file(), finish_graph_dump_file(), and print_graph_cfg().

◆ print_graph_cfg() [1/3]

void print_graph_cfg ( const char * base,
struct function * fun )
Print a graphical representation of the CFG of function FUN.
First print all basic blocks.  Draw all edges at the end to get
subgraphs right for GraphViz, which requires nodes to be defined
before edges to cluster nodes properly.   

References ggc_alloc(), open_graph_file(), and print_graph_cfg().

◆ print_graph_cfg() [2/3]

void DEBUG_FUNCTION print_graph_cfg ( FILE * fp,
struct function * fun )
Print a graphical representation of the CFG of function FUN.
First print all basic blocks.  Draw all edges at the end to get
subgraphs right for GraphViz, which requires nodes to be defined
before edges to cluster nodes properly.   

References draw_cfg_edges(), draw_cfg_nodes(), function_name(), ggc_alloc(), pp_flush(), and pp_printf().

Referenced by execute_function_dump(), print_graph_cfg(), and print_graph_cfg().

◆ print_graph_cfg() [3/3]

void DEBUG_FUNCTION print_graph_cfg ( FILE * fp,
struct function * fun,
dump_flags_t flags )
Overload with additional flag argument.   

References dump_flags, ggc_alloc(), and print_graph_cfg().

◆ start_graph_dump()

static void start_graph_dump ( FILE * fp,
const char * base )
static

Variable Documentation

◆ graph_ext

const char* const graph_ext = ".dot"
static
Output routines for graphical representation.
   Copyright (C) 1998-2024 Free Software Foundation, Inc.
   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
   Rewritten for DOT output by Steven Bosscher, 2012.

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/>.   
DOT files with the .dot extension are recognized as document templates
by a well-known piece of word processing software out of Redmond, WA.
Therefore some recommend using the .gv extension instead.  Obstinately
ignore that recommendation...   

Referenced by open_graph_file().