diff mbox series

doc: Fixes to RTL-SSA sample code

Message ID ZN34fH4L2SfD5smj@arm.com
State New
Headers show
Series doc: Fixes to RTL-SSA sample code | expand

Commit Message

Alex Coplan Aug. 17, 2023, 10:37 a.m. UTC
Hi,

This patch fixes up the code examples in the RTL-SSA documentation (the
sections on making insn changes) to reflect the current API.

The main issues are as follows:
 - rtl_ssa::recog takes an obstack_watermark & as the first parameter.
   Presumably this is intended to be the change attempt, so I've updated
   the examples to pass this through.
 - The variants of recog and restrict_movement that take an ignore
   predicate have been renamed with an _ignoring suffix, so I've
   updated callers to use those names.
 - A couple of minor "obvious" fixes to add a missing address-of
   operator and correct a variable name.

OK for trunk?

Thanks,
Alex

gcc/ChangeLog:

	* doc/rtl.texi: Fix up sample code for RTL-SSA insn changes.

Comments

Richard Sandiford Aug. 17, 2023, 10:47 a.m. UTC | #1
Alex Coplan <alex.coplan@arm.com> writes:
> Hi,
>
> This patch fixes up the code examples in the RTL-SSA documentation (the
> sections on making insn changes) to reflect the current API.
>
> The main issues are as follows:
>  - rtl_ssa::recog takes an obstack_watermark & as the first parameter.
>    Presumably this is intended to be the change attempt, so I've updated
>    the examples to pass this through.
>  - The variants of recog and restrict_movement that take an ignore
>    predicate have been renamed with an _ignoring suffix, so I've
>    updated callers to use those names.
>  - A couple of minor "obvious" fixes to add a missing address-of
>    operator and correct a variable name.
>
> OK for trunk?

OK.  Thanks for doing this.  I'm pretty sure the examples did
compile with one version of the API, but like you say, I forgot
to update it later. :(

Richard

> Thanks,
> Alex
>
> gcc/ChangeLog:
>
> 	* doc/rtl.texi: Fix up sample code for RTL-SSA insn changes.
>
> diff --git a/gcc/doc/rtl.texi b/gcc/doc/rtl.texi
> index 76aeafb8f15..0ed88f58821 100644
> --- a/gcc/doc/rtl.texi
> +++ b/gcc/doc/rtl.texi
> @@ -4964,7 +4964,7 @@ the pass should check whether the new pattern matches a target
>  instruction or satisfies the requirements of an inline asm:
>  
>  @smallexample
> -if (!rtl_ssa::recog (change))
> +if (!rtl_ssa::recog (attempt, change))
>    return false;
>  @end smallexample
>  
> @@ -5015,7 +5015,7 @@ if (!rtl_ssa::restrict_movement (change))
>  insn_change_watermark watermark;
>  // Use validate_change etc. to change INSN's pattern.
>  @dots{}
> -if (!rtl_ssa::recog (change)
> +if (!rtl_ssa::recog (attempt, change)
>      || !rtl_ssa::change_is_worthwhile (change))
>    return false;
>  
> @@ -5048,7 +5048,7 @@ For example, if a pass is changing exactly two instructions,
>  it might do:
>  
>  @smallexample
> -rtl_ssa::insn_change *changes[] = @{ &change1, change2 @};
> +rtl_ssa::insn_change *changes[] = @{ &change1, &change2 @};
>  @end smallexample
>  
>  where @code{change1}'s instruction must come before @code{change2}'s.
> @@ -5066,7 +5066,7 @@ in the correct order with respect to each other.
>  The way to do this is:
>  
>  @smallexample
> -if (!rtl_ssa::restrict_movement (change, insn_is_changing (changes)))
> +if (!rtl_ssa::restrict_movement_ignoring (change, insn_is_changing (changes)))
>    return false;
>  @end smallexample
>  
> @@ -5078,7 +5078,7 @@ changing instructions (which might, for example, no longer need
>  to clobber the flags register).  The way to do this is:
>  
>  @smallexample
> -if (!rtl_ssa::recog (change, insn_is_changing (changes)))
> +if (!rtl_ssa::recog_ignoring (attempt, change, insn_is_changing (changes)))
>    return false;
>  @end smallexample
>  
> @@ -5118,28 +5118,28 @@ Putting all this together, the process for a two-instruction change is:
>  @smallexample
>  auto attempt = crtl->ssa->new_change_attempt ();
>  
> -rtl_ssa::insn_change change (insn1);
> +rtl_ssa::insn_change change1 (insn1);
>  change1.new_defs = @dots{};
>  change1.new_uses = @dots{};
>  change1.move_range = @dots{};
>  
> -rtl_ssa::insn_change change (insn2);
> +rtl_ssa::insn_change change2 (insn2);
>  change2.new_defs = @dots{};
>  change2.new_uses = @dots{};
>  change2.move_range = @dots{};
>  
> -rtl_ssa::insn_change *changes[] = @{ &change1, change2 @};
> +rtl_ssa::insn_change *changes[] = @{ &change1, &change2 @};
>  
>  auto is_changing = insn_is_changing (changes);
> -if (!rtl_ssa::restrict_movement (change1, is_changing)
> -    || !rtl_ssa::restrict_movement (change2, is_changing))
> +if (!rtl_ssa::restrict_movement_ignoring (change1, is_changing)
> +    || !rtl_ssa::restrict_movement_ignoring (change2, is_changing))
>    return false;
>  
>  insn_change_watermark watermark;
>  // Use validate_change etc. to change INSN1's and INSN2's patterns.
>  @dots{}
> -if (!rtl_ssa::recog (change1, is_changing)
> -    || !rtl_ssa::recog (change2, is_changing)
> +if (!rtl_ssa::recog_ignoring (attempt, change1, is_changing)
> +    || !rtl_ssa::recog_ignoring (attempt, change2, is_changing)
>      || !rtl_ssa::changes_are_worthwhile (changes)
>      || !crtl->ssa->verify_insn_changes (changes))
>    return false;
diff mbox series

Patch

diff --git a/gcc/doc/rtl.texi b/gcc/doc/rtl.texi
index 76aeafb8f15..0ed88f58821 100644
--- a/gcc/doc/rtl.texi
+++ b/gcc/doc/rtl.texi
@@ -4964,7 +4964,7 @@  the pass should check whether the new pattern matches a target
 instruction or satisfies the requirements of an inline asm:
 
 @smallexample
-if (!rtl_ssa::recog (change))
+if (!rtl_ssa::recog (attempt, change))
   return false;
 @end smallexample
 
@@ -5015,7 +5015,7 @@  if (!rtl_ssa::restrict_movement (change))
 insn_change_watermark watermark;
 // Use validate_change etc. to change INSN's pattern.
 @dots{}
-if (!rtl_ssa::recog (change)
+if (!rtl_ssa::recog (attempt, change)
     || !rtl_ssa::change_is_worthwhile (change))
   return false;
 
@@ -5048,7 +5048,7 @@  For example, if a pass is changing exactly two instructions,
 it might do:
 
 @smallexample
-rtl_ssa::insn_change *changes[] = @{ &change1, change2 @};
+rtl_ssa::insn_change *changes[] = @{ &change1, &change2 @};
 @end smallexample
 
 where @code{change1}'s instruction must come before @code{change2}'s.
@@ -5066,7 +5066,7 @@  in the correct order with respect to each other.
 The way to do this is:
 
 @smallexample
-if (!rtl_ssa::restrict_movement (change, insn_is_changing (changes)))
+if (!rtl_ssa::restrict_movement_ignoring (change, insn_is_changing (changes)))
   return false;
 @end smallexample
 
@@ -5078,7 +5078,7 @@  changing instructions (which might, for example, no longer need
 to clobber the flags register).  The way to do this is:
 
 @smallexample
-if (!rtl_ssa::recog (change, insn_is_changing (changes)))
+if (!rtl_ssa::recog_ignoring (attempt, change, insn_is_changing (changes)))
   return false;
 @end smallexample
 
@@ -5118,28 +5118,28 @@  Putting all this together, the process for a two-instruction change is:
 @smallexample
 auto attempt = crtl->ssa->new_change_attempt ();
 
-rtl_ssa::insn_change change (insn1);
+rtl_ssa::insn_change change1 (insn1);
 change1.new_defs = @dots{};
 change1.new_uses = @dots{};
 change1.move_range = @dots{};
 
-rtl_ssa::insn_change change (insn2);
+rtl_ssa::insn_change change2 (insn2);
 change2.new_defs = @dots{};
 change2.new_uses = @dots{};
 change2.move_range = @dots{};
 
-rtl_ssa::insn_change *changes[] = @{ &change1, change2 @};
+rtl_ssa::insn_change *changes[] = @{ &change1, &change2 @};
 
 auto is_changing = insn_is_changing (changes);
-if (!rtl_ssa::restrict_movement (change1, is_changing)
-    || !rtl_ssa::restrict_movement (change2, is_changing))
+if (!rtl_ssa::restrict_movement_ignoring (change1, is_changing)
+    || !rtl_ssa::restrict_movement_ignoring (change2, is_changing))
   return false;
 
 insn_change_watermark watermark;
 // Use validate_change etc. to change INSN1's and INSN2's patterns.
 @dots{}
-if (!rtl_ssa::recog (change1, is_changing)
-    || !rtl_ssa::recog (change2, is_changing)
+if (!rtl_ssa::recog_ignoring (attempt, change1, is_changing)
+    || !rtl_ssa::recog_ignoring (attempt, change2, is_changing)
     || !rtl_ssa::changes_are_worthwhile (changes)
     || !crtl->ssa->verify_insn_changes (changes))
   return false;