5.2 Reading the dumps: from a file name to the pass that wrote it

Source references in this chapter are to GCC 15.2.0 (releases/gcc-15.2.0).

You add -fdump-tree-all to see what the optimiser did to a loop. The directory fills with files named like count.c.007t.gimple. A colleague on GCC 14 sends the same dump as count.c.006t.gimple. A script that opened count.c.005t.original finds nothing after the upgrade. Each file came from one step inside cc1, and the name says which step, once you know how GCC builds it.

A dump file name is the base name, a number from one counter, a letter for the kind of dump, and the pass name. cc1 hands out the numbers when it starts, before it reads -O2.

This chapter assumes Chapter 5.1, for the three representations and for count.c, the function that all of Part V compiles, and Chapter 1.4, for how -dumpdir and -dumpbase place every auxiliary file.

Nothing here needs a GCC build. The commands run on an installed gcc, and every source file below can be read on the GCC mirror at the pin. The chapter shows no compiler output, because the book reads the pin as source. Where the source fixes a result, the text says what you will see.

The four parts of count.c.007t.gimple: get_dump_file_name

$ gcc -O2 -c -fdump-tree-all -fdump-rtl-all count.c
$ ls count.c.*

One function in gcc/dumpfile.cc builds every one of those names:

  /* If available, use the command line dump filename. */
  if (dfi->pfilename)
    return xstrdup (dfi->pfilename);

  if (dfi->num < 0)
    dump_id[0] = '\0';
  else
    {
      /* (null), LANG, TREE, RTL, IPA.  */
      char suffix = " ltri"[dfi->dkind];

      if (snprintf (dump_id, sizeof (dump_id), ".%03d%c", dfi->num, suffix) < 0)
	dump_id[0] = '\0';
    }

  if (part != -1)
    {
       char part_id[8];
       snprintf (part_id, sizeof (part_id), ".%i", part);
       return concat (dump_base_name, dump_id, part_id, dfi->suffix, NULL);
    }
  else
    return concat (dump_base_name, dump_id, dfi->suffix, NULL);

Listing 5.2-1: get_dump_file_name (gcc/dumpfile.cc:340-362).

Read count.c.007t.gimple against the last line:

  1. count.c is dump_base_name. The driver passes -dumpdir and -dumpbase count.c to cc1, as Chapter 1.4 showed, and finish_options joins the two (gcc/opts.cc:1066-1085). The base keeps the .c. With -c, the files land next to count.o. The GCC manual documents this placement, and the example foo.c.???r.final, under -o in Overall Options (invoke.texi:1780-1801).
  2. .007 is the dump's number, printed with %03d. The zero padding makes ls list the files in number order.
  3. t is the kind. The string " ltri" is indexed by enum dump_kind, whose values are DK_none, DK_lang, DK_tree, DK_rtl and DK_ipa (gcc/dumpfile.h:63-70). So l is a front-end dump, t a tree dump, r an RTL dump and i an IPA dump. GENERIC and GIMPLE are both made of tree nodes (Chapter 5.1), so both get t. The GENERIC dump .original is a t file.
  4. .gimple is the suffix. For a pass, it is a dot, the pass name and an instance number.

The first branch is the escape hatch. -fdump-tree-gimple=out.txt sets pfilename, and that name replaces all four parts. The names stdout, - and stderr open the standard streams instead of a file (dumpfile.cc:370-385).

The Developer Options node of the GCC manual documents this rule, and the four letters (Developer Options, invoke.texi:20349-20362). It also says that "the pass number is determined by the order passes are registered with the compiler's pass manager". The rest of this chapter reads that order in the source.

One counter for every dump: dump_register

Every dump that registers while cc1 runs gets its number from one line, int num = m_next_dump++; (dumpfile.cc:221). The counter starts at 1 (:183), and the same counter serves all four letters. No two dumps in one cc1 share a number, so the letter never decides the order of an ls.

A few dumps are not passes. They sit in a static table, and they get their numbers here:

  lang_hooks.register_dumps (this);
  /* If this assert fails, some FE registered more than
     FIRST_ME_AUTO_NUMBERED_DUMP - FIRST_AUTO_NUMBERED_DUMP
     dump files.  Bump FIRST_ME_AUTO_NUMBERED_DUMP accordingly.  */
  gcc_assert (m_next_dump <= FIRST_ME_AUTO_NUMBERED_DUMP);
  m_next_dump = FIRST_ME_AUTO_NUMBERED_DUMP;
  dump_files[TDI_original].num = m_next_dump++;
  dump_files[TDI_gimple].num = m_next_dump++;
  dump_files[TDI_nested].num = m_next_dump++;

Listing 5.2-2: register_dumps (gcc/dumpfile.cc:263-271).

The front end registers its own dumps first. C++ registers four, .class, .module, .raw and .coro, which become 001l to 004l (gcc/cp/cp-objcp-common.cc:605-617). C registers none, because its hook is the empty default (gcc/langhooks.cc:339-341). Then the counter jumps to FIRST_ME_AUTO_NUMBERED_DUMP, which is 6 (dumpfile.cc:109-110), whatever the front end did. So at the pin, for C and C++ alike, .original is 006t, .gimple is 007t and .nested is 008t. The first pass takes the next number.

Three IPA entries in the same table never get a number. .cgraph, .type-inheritance and .ipa-clones keep the 0 they start with (dumpfile.cc:101-103), so their files carry 000i.

GCC 15 moved the start of the middle-end numbers up by one. At releases/gcc-14.2.0, FIRST_ME_AUTO_NUMBERED_DUMP is 5 (gcc/dumpfile.cc:108), and C++ registers three dumps (gcc/cp/cp-objcp-common.cc:602-609). GCC 15 added .coro and raised the constant to 6. GCC 14 writes count.c.005t.original, and GCC 15 writes count.c.006t.original, for a C file that has no C++ in it.

Pass dumps follow passes.def, depth first: register_dump_files

The pass manager's constructor builds the tree of passes from pass-instances.def, a copy of passes.def that the build generates (gcc/Makefile.in:2681-2684). Chapter 5.3 shows how that file lists and instantiates the passes. After it builds the tree, the constructor registers the dumps, list by list:

  register_dump_files (all_lowering_passes);
  register_dump_files (all_small_ipa_passes);
  register_dump_files (all_regular_ipa_passes);
  register_dump_files (all_late_ipa_passes);
  register_dump_files (all_passes);

Listing 5.2-3: the end of the pass_manager constructor (gcc/passes.cc:1654-1658).

Each call walks one list:

  do
    {
      if (pass->name && pass->name[0] != '*')
        register_one_dump_file (pass);

      if (pass->sub)
        register_dump_files (pass->sub);

      pass = pass->next;
    }
  while (pass);

Listing 5.2-4: register_dump_files (gcc/passes.cc:899-909).

The comment above the registration code states the rule in one sentence: "We want to do this depth first, and independent of whether the pass is enabled or not" (passes.cc:823-825). Three things follow.

A pass group's members come right after the group. pass_all_optimizations holds most of the GIMPLE optimisers (gcc/passes.def:198-382), and its own name, *all_optimizations (passes.cc:550), starts with a star.

A name that starts with * gets no number and no file. The internals manual documents this, and the space prefix, under Pass manager (gcc/doc/passes.texi:170-176). A pass named no-opt dfinit dumps as dfinit (gcc/df-core.cc:761).

One list holds the GIMPLE and the RTL passes. all_passes ends its GIMPLE part with pass_expand (passes.def:453). The RTL passes follow inside pass_rest_of_compilation, down to pass_final (passes.def:455-563). So the t files of the passes come before the r files, and the r files start at expand. Three tree dumps that register late are the exception, and they appear below, next to register_pass. final is not the last numbered pass. pass_df_finish comes after it (passes.def:565), and its name is dfinish (df-core.cc:831).

The numbers give the order in which one function meets the passes. The manual calls this "generally the same as the order of execution". They do not give the time order across functions. The comment above the constructor says that the lowering passes run on every function before the IPA passes start (passes.cc:1555-1576).

Reading the suffix and the switch: ccp2, split2, -fdump-tree-ccp

register_one_dump_file makes the suffix and the switch names together (gcc/passes.cc:846-892). The suffix is a dot, the pass name and an instance number. The type of the pass picks the letter and the switch prefix: ipa- and i for IPA passes, tree- and t for GIMPLE passes, rtl- and r for the rest. Chapter 5.3 shows where the name and the instance number come from. Three facts are enough to read a file name.

A pass listed once has no instance number, as in .expand and .final. A pass listed more than once is numbered 1, 2 and so on, in passes.def order. pass_ccp appears five times (passes.def:80, :204, :260, :354 and :396), so the files are ccp1 to ccp5.

A trailing digit is not always an instance number. split1 to split5 are five different passes, with the digit in the name itself (gcc/recog.cc:4481, :4526). .split2 is not the second instance of a pass called split.

Each dump has two switch names, tree-ccp2 for one instance and tree-ccp as a glob for all of them (passes.cc:877-878). The matching code tries exact names first:

  for (i = TDI_none + 1; i != TDI_end; i++)
    any |= dump_switch_p_1 (arg, &dump_files[i], false);

  /* Don't glob if we got a hit already */
  if (!any)
    for (i = TDI_none + 1; i != TDI_end; i++)
      any |= dump_switch_p_1 (arg, &dump_files[i], true);

  for (i = 0; i < m_extra_dump_files_in_use; i++)
    any |= dump_switch_p_1 (arg, &m_extra_dump_files[i], false);

  if (!any)
    for (i = 0; i < m_extra_dump_files_in_use; i++)
      any |= dump_switch_p_1 (arg, &m_extra_dump_files[i], true);

Listing 5.2-5: exact names, then globs (gcc/dumpfile.cc:1927-1940).

So -fdump-tree-ccp2 enables one dump, and -fdump-tree-ccp enables all five. -fdump-tree-all is a switch whose entry has no suffix, and it enables every dump of its kind (dumpfile.cc:1912-1915). It turns on t dumps only. Add -fdump-rtl-all and -fdump-ipa-all for the other kinds.

-fdump- itself is one option, Joined, in gcc/common.opt (common.opt:1608-1610). The option parser accepts any text after it, and dump_switch_p checks that text against the dumps that registered. A typo gets "unrecognized command-line option" with a "did you mean" hint (dumpfile.cc:1942-1955). So the valid -fdump- switches are the dumps that registered in your cc1. The manual's procedure for finding one starts from -fdump-passes, under -fdump-tree (Developer Options, invoke.texi:20977-21002).

Words after the pass name, such as -details in -fdump-tree-vect-details, are split at each -, and an = starts a file name (dumpfile.cc:1817-1878). The same node documents each word. One detail it does not give: details also turns on the three message kinds that -fopt-info prints (dumpfile.cc:128-130).

Numbered before -O2 is read: general_init and the gate

The counter runs at cc1 start-up:

  /* Create the singleton holder for global state.  This creates the
     dump manager.  */
  g = new gcc::context ();

  /* Allow languages and middle-end to register their dumps before the
     optimization passes.  */
  g->get_dumps ()->register_dumps ();

  /* Create the passes.  */
  g->set_passes (new gcc::pass_manager (g));

Listing 5.2-6: general_init (gcc/toplev.cc:1145-1154).

toplev::main calls general_init at toplev.cc:2296 and decode_options at :2331. The number of a built-in pass depends on the cc1 binary, not on -O, -f or -m. The options decide something else: which files appear.

  gate_status = pass->gate (cfun);
  gate_status = override_gate_status (pass, current_function_decl, gate_status);
  ...
  if (!gate_status)
    {
      ...
      current_pass = NULL;
      return false;
    }
  ...
  pass_init_dump_file (pass);

Listing 5.2-7: execute_one_pass, abridged (gcc/passes.cc:2605-2644).

A pass whose gate says no returns before its dump file opens. A pass that runs writes the function after it runs, even if it changed nothing (passes.cc:2734-2735). So a missing number means that the pass did not run, or that its kind of dump was not enabled. A file identical to the one before it means that the pass ran and changed nothing.

-Og shows the effect. At -O2, the *all_optimizations group runs, with the gate optimize >= 1 && !optimize_debug (passes.cc:568-571). At -Og, the *all_optimizations_g group runs instead, with the gate optimize >= 1 && optimize_debug (passes.cc:606-609). The pass_ccp inside the -Og group is the fifth in passes.def. Its gate reads flag_tree_ccp (gcc/tree-ssa-ccp.cc:3063), which is on from level 1 (opts.cc:597), and -Og selects level 1 (opts.cc:796-800). So after IPA, an -Og compile writes ccp5 and none of ccp2 to ccp4, and ccp5 has the same number that it would have at -O2. At -O0 the flag is off, and no ccp file appears.

$ gcc -O2 -c -fdump-tree-all count.c && ls count.c.* > o2.txt && rm count.c.*
$ gcc -Og -c -fdump-tree-all count.c && ls count.c.* > og.txt && rm count.c.*
$ diff o2.txt og.txt

Each line of that diff is a pass that ran at one level and not at the other. A file that both levels wrote has the same name in both lists.

What moves a number: the release, the target, register_pass

Three things change the numbers, and no optimisation option is among them.

The release. passes.def changes between releases, and so did FIRST_ME_AUTO_NUMBERED_DUMP. The manual says that "the numeric codes are not stable and may change from one version of GCC to another" (invoke.texi:21001-21002). Match dumps by name in scripts: count.c.*t.ccp2, count.c.*r.expand.

The target. pass-instances.def is built from passes.def and $(PASSES_EXTRA). x86 adds config/i386/i386-passes.def (gcc/config/i386/t-i386:23), and Arm adds arm-passes.def (gcc/config/arm/t-arm:205). These files insert passes at named places:

  INSERT_PASS_AFTER (pass_postreload_cse, 1, pass_insert_vzeroupper);
  INSERT_PASS_AFTER (pass_late_combine, 1, pass_stv, false /* timode_p */);

Listing 5.2-8: two x86 passes join the list (gcc/config/i386/i386-passes.def:27-28).

At the pin, every x86 insertion lands in the RTL part, the first one after pass_rtl_ifcvt (i386-passes.def:39, passes.def:471). Arm inserts one pass, bti, before pass_shorten_branches (arm-passes.def:21). So gcc on x86-64 and arm-none-eabi-gcc, both 15.2, agree on every t number and on the number of expand. Their later r numbers differ.

register_pass after start-up. A pass that joins the list after the constructor goes through pass_manager::register_pass (passes.cc:1499-1553), and takes the next free numbers, above every built-in pass. Plugins do this. So does the SH port, from its option-override hook (gcc/config/sh/sh.cc:792-817). This is the case that the manual describes: passes "numbered higher than the pass named final, even if they are executed earlier" (invoke.texi:20356-20359). The manual also lists "target-specific passes" there. That holds for SH, but not for x86, Arm and AArch64 (gcc/config/aarch64/t-aarch64:152), which merge their passes at build time and number them in sequence.

Three tree dumps also register after the pass manager: .statistics, .earlydebug and .debug (toplev.cc:1158-1159). With -fdump-tree-all, any of them that is written sorts after the RTL files.

Diffing consecutive dumps to find the pass that changed your code

Each file holds the function as it stood after its pass (passes.cc:2734-2735). So compare each file with the one before it, and the first difference names the pass that made it. The manual does not teach this technique.

changed () {
  set -- count.c.[0-9][0-9][0-9]$1.*
  while [ $# -ge 2 ]; do
    cmp -s "$1" "$2" || echo "$1 -> $2"
    shift
  done
}
changed t
changed r

Run it in the directory of the dumps. Each line names a pair of consecutive files that differ. The second file of the pair is the pass to read, with diff -u on the two files. Keep the two letters apart, because a GIMPLE dump and an RTL dump never compare as text. Run the loop on plain dumps first. A -details dump adds the pass's own notes, so every pair would differ. When you have the pass, run again with -fdump-tree-<pass>-details for its reasoning.

Four things can mislead the diff.

A * pass changes code and writes nothing. *strip_predict_hints replaces each __builtin_expect call with its first argument (gcc/predict.cc:4307-4370, name at :4377). Its change shows up in the next named file.

IPA passes write i files. With -fdump-tree-all alone, a change that an IPA pass made, such as inlining, appears in the next t file. Add -fdump-ipa-all to give those passes files of their own.

.original and .gimple are not pass dumps. The C front end writes .original (gcc/c-family/c-gimplify.cc:785-797) and the gimplifier writes .gimple (gcc/gimplify.cc:21160). Their difference is the whole of gimplification, which Chapter 5.4 reads.

Two compilations are not two passes. To compare one dump from two compilers, or from two option sets, use -fdump-noaddr and -fdump-unnumbered. The manual documents both as aids to diff (Developer Options, invoke.texi:20688 and :20700).

From a dump name to the source file: the pass's name string

The text after the number is the pass's name field, minus the instance number and minus any prefix before a space. Search for it as a string in a checkout of the pin:

$ grep -rn '"ccp",' gcc --include='*.cc'

The hit to keep is the one inside a pass_data initializer:

const pass_data pass_data_ccp =
{
  GIMPLE_PASS, /* type */
  "ccp", /* name */
  OPTGROUP_NONE, /* optinfo_flags */
  TV_TREE_CCP, /* tv_id */
  ( PROP_cfg | PROP_ssa ), /* properties_required */
  0, /* properties_provided */
  0, /* properties_destroyed */
  0, /* todo_flags_start */
  TODO_update_address_taken, /* todo_flags_finish */
};

Listing 5.2-9: the descriptor that names ccp (gcc/tree-ssa-ccp.cc:3036-3047).

That is the file. The class next to it, pass_ccp, holds the gate and the execute method (tree-ssa-ccp.cc:3049-3067). The factory make_pass_ccp (:3077) is what NEXT_PASS (pass_ccp, ...) in passes.def calls. Count those NEXT_PASS lines to place ccp2: it is the second, at passes.def:204. An RTL dump works the same way. "expand", finds gcc/cfgexpand.cc:6976, the entry point of Chapter 5.5. Chapter 5.3 takes the descriptor and its fields apart.

-fopt-info: the second stream of every dump

Each dump has two streams: pstream, the dump file, and alt_stream, the -fopt-info output (gcc/dumpfile.h:295-331). The internals manual describes both under Dump files and streams (gcc/doc/optinfo.texi:81-107). A message that a pass prints with dump_printf_loc can go to either stream, or to both.

-fopt-info picks passes by group, and a pass joins groups in its descriptor. The group comes from optinfo_flags (passes.cc:879), every IPA pass is in ipa (:864), and a pass with no group goes into OTHER (:883-884). No keyword names OTHER (dumpfile.cc:171-180), so only optall reaches those passes. The vectorizer, vect, is in both loop and vec (gcc/tree-vectorizer.cc:1224-1228).

The GCC manual documents the keywords and the defaults under -fopt-info (Developer Options, invoke.texi:21006-21141). In the code, a missing message kind becomes optimized, a missing group becomes all groups, and a missing file becomes stderr (dumpfile.cc:2053-2068). This is the command for "why did this loop not vectorise?":

$ gcc -O2 -c -fopt-info-vec-missed count.c

At -O2 the vectorizer runs, with the very-cheap cost model (opts.cc:664-665, :679-680). Each line starts with file:line:column: missed: (dumpfile.cc:473-490). If the vectorizer analyses the loop and gives up, it prints this:

  if (!loop_vinfo)
    if (dump_enabled_p ())
      if (opt_problem *problem = loop_vinfo.get_problem ())
	{
	  dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
			   "couldn't vectorize loop\n");
	  problem->emit_and_clear ();
	}

Listing 5.2-10: the top-level "missed" message (gcc/tree-vectorizer.cc:1099-1106).

The reason comes from problem->emit_and_clear (). The analysis recorded it deep in its call stack, where messages count as internals, and emit_and_clear prints it again at the top level, marked MSG_PRIORITY_REEMITTED (gcc/optinfo.cc:114-129). The design comment in gcc/opt-problem.h:27-108 explains why. The two streams filter in opposite ways:

  • -fopt-info keeps user-facing and re-emitted messages, and drops internals (dumpfile.cc:1973-1976). Add -internals to see them.
  • A dump file keeps user-facing messages and internals, and drops the re-emitted copy (dumpfile.cc:1827-1831).

So -fdump-tree-vect-details shows each step of the analysis, with the reason where it happened. -fopt-info-vec-missed shows the loop and its reason on your terminal.

The last dump is the assembly: -dp

The .s file can carry the same trail. With -S -dp, final writes a comment after the first line of each instruction:

      fprintf (asm_out_file, "\t%s %d\t",
	       ASM_COMMENT_START, INSN_UID (debug_insn));
      ...
      int num = INSN_CODE (debug_insn);
      fprintf (asm_out_file, "%s", insn_data[num].name);
      if (insn_data[num].n_alternatives > 1)
	fprintf (asm_out_file, "/%d", which_alternative);

Listing 5.2-11: output_asm_name, abridged (gcc/final.cc:3213-3226).

The number is the insn's UID, the same number that follows insn at the start of each instruction in the RTL dumps (gcc/print-rtl.cc:934-941). The name is the machine-description pattern that matched, and the alternative after the /. The GCC manual documents -dp under Developer Options (invoke.texi:20661), and -fverbose-asm under Code Gen Options (invoke.texi:19870). Chapter 5.6 follows a pattern name into the .md file.

$ gcc -O2 -S -dp count.c
QuestionWhere to look
Which pass changed this statement?-fdump-tree-all or -fdump-rtl-all, the changed loop, then diff -u on the pair
Which source file holds that pass?the dump suffix as a "name", string, then NEXT_PASS in passes.def
Did the pass run at all?whether its file exists, or -fdump-passes (Chapter 5.3)
Why did this loop not vectorise?-fopt-info-vec-missed, then -fdump-tree-vect-details
Which pattern made this instruction?-S -dp, then the .md file (Chapter 5.6)
Why does my colleague's file have another number?another release, another target's passes, or a plugin
What does the compiler think my types are?-dM -E (Chapter 2.6)

Three things to carry away

The name is base, number, letter and pass. " ltri" gives the letter, and the pass's name string gives the suffix.

The number is registration order, fixed before options. One counter, depth first through passes.def, so -O2 decides which files appear but not their numbers.

Diff neighbours, then grep the name. The first changed pair names the pass, and the pass_data string names its file.

Things that surprise people

-fdump-tree-ccp asks for five dumps. Without an instance number the switch is a glob over ccp1 to ccp5.

.split2 is a pass, not an instance. Some pass names end in a digit.

A t file can sort after final. .statistics, .earlydebug and .debug register after every pass.

final is not the last RTL dump. dfinish comes after it.

Upgrading from GCC 14 to 15 renumbers .original. A script that matches 005t stops matching.

Documentation coverage

The GCC manual documents the dump options in Developer Options (gcc/doc/invoke.texi:20326): the naming rule at :20349-20362, -dp at :20661, -fdump-noaddr and -fdump-unnumbered at :20688 and :20700, -fdump-passes at :20880, -fdump-tree with its option words at :20897, and -fopt-info at :21006. Where dumps land is documented under -o in Overall Options (:1768, with the dump example at :1780-1801). The internals manual documents the star and space rules for pass names in Pass manager (gcc/doc/passes.texi:146), and the two streams and the optimisation groups in Optimization info (gcc/doc/optinfo.texi).

What is not documented:

  • That one counter numbers every dump, of all four letters, and that the middle end restarts it at 6 whatever the front end registered. It was 5 before GCC 15.
  • That the numbers are fixed before cc1 reads its options, so -O changes which files appear and never their numbers.
  • That x86, Arm and AArch64 insert their target passes at build time, so those passes are numbered in sequence. The manual says target-specific passes are numbered after final, which holds only for passes registered at run time, such as SH's.
  • That a pass whose name starts with * can change the code and write no dump, as *strip_predict_hints does.
  • That a trailing digit can be part of a pass name, as in split2.
  • That .cgraph, .type-inheritance and .ipa-clones always carry 000i.
  • The diff technique, and the route from a dump name to its pass_data string and its NEXT_PASS lines.
  • That -fopt-info drops internal messages and keeps re-emitted ones, while a dump file does the opposite.

Next: the pass manager itself, how passes.def becomes the tree of passes that this chapter numbered, and how a gate decides whether a file appears.


All source references in this chapter are to GCC 15.2.0 (releases/gcc-15.2.0). Line numbers in other releases will differ; the surrounding code rarely does. Where behaviour itself changed across a major version, it is flagged inline.