]> git.ipfire.org Git - thirdparty/gcc.git/commit
Make end_sequence return the insn sequence
authorRichard Sandiford <richard.sandiford@arm.com>
Fri, 16 May 2025 12:24:01 +0000 (13:24 +0100)
committerRichard Sandiford <richard.sandiford@arm.com>
Fri, 16 May 2025 12:24:01 +0000 (13:24 +0100)
commit84269eeecf3c31a7f6be1f210f5e6c38d0c01e31
tree4488b6c536738f598f840fbf401cf01c73ad86ba
parentc07ba5398be194cc390934ae159f7941890bd848
Make end_sequence return the insn sequence

The start_sequence/end_sequence interface was a big improvement over
the previous state, but one slightly awkward thing about it is that
you have to call get_insns before end_sequence in order to get the
insn sequence itself:

   To get the contents of the sequence just made, you must call
   `get_insns' *before* calling here.

We therefore have quite a lot of code like this:

  insns = get_insns ();
  end_sequence ();
  return insns;

It would seem simpler to write:

  return end_sequence ();

instead.

I can see three main potential objections to this:

(1) It isn't obvious whether ending the sequence would return the first
    or the last instruction.  But although some code reads *both* the
    first and the last instruction, I can't think of a specific case
    where code would want *only* the last instruction.  All the emit
    functions take the first instruction rather than the last.

(2) The "end" in end_sequence might imply the C++ meaning of an exclusive
    endpoint iterator.  But for an insn sequence, the exclusive endpoint
    is always the null pointer, so it would never need to be returned.
    That said, we could rename the function to something like
    "finish_sequence" or "complete_sequence" if this is an issue.

(3) There might have been an intention that start_sequence/end_sequence
    could in future reclaim memory for unwanted sequences, and so an
    explicit get_insns was used to indicate that the caller does want
    the sequence.

    But that sort of memory reclaimation has never been added,
    and now that the codebase is C++, it would be easier to handle
    using RAII.  I think reclaiming memory would be difficult to do in
    any case, since some code records the individual instructions that
    they emit, rather than using get_insns.

gcc/
* rtl.h (end_sequence): Return the sequence.
* emit-rtl.cc (end_sequence): Likewise.
gcc/emit-rtl.cc
gcc/rtl.h