aboutsummaryrefslogtreecommitdiff
path: root/gcc/target.def
diff options
context:
space:
mode:
authorRichard Sandiford <richard.sandiford@arm.com>2023-11-11 17:29:00 +0000
committerRichard Sandiford <richard.sandiford@arm.com>2023-11-11 17:29:00 +0000
commitfc8458e20a524d053f576d64a606e21f8bd03b84 (patch)
treecbc6c5ce4ffd98c7b4dfc0846b3e98e45d67d902 /gcc/target.def
parent493b0038d7d04986c7de977074d095e4eb7d9a27 (diff)
downloadgcc-fc8458e20a524d053f576d64a606e21f8bd03b84.zip
gcc-fc8458e20a524d053f576d64a606e21f8bd03b84.tar.gz
gcc-fc8458e20a524d053f576d64a606e21f8bd03b84.tar.bz2
mode-switching: Add a backprop hook
This patch adds a way for targets to ask that selected mode changes be brought forward, through a combination of: (1) requiring a mode in blocks where the entity was previously transparent (2) pushing the transition at the head of a block onto incomging edges SME has two uses for this: - A "one-shot" entity that, for any given path of execution, either stays off or makes exactly one transition from off to on. This relies only on (1) above; see the hook description for more info. The main purpose of using mode-switching for this entity is to shrink-wrap the code that requires it. - A second entity for which all transitions must be from known modes, which is enforced using a combination of (1) and (2). More specifically, (1) looks for edges B1->B2 for which: - B2 requires a specific mode and - B1 does not guarantee a specific starting mode In this system, such an edge is only possible if the entity is transparent in B1. (1) then forces B1 to require some safe common mode. Applying this inductively means that all incoming edges are from known modes. If different edges give different starting modes, (2) pushes the transitions onto the edges themselves; this only happens if the entity is not transparent in some predecessor block. The patch also uses the back-propagation as an excuse to do a simple on-the-fly optimisation. Hopefully the comments in the patch explain things a bit better. gcc/ * target.def (mode_switching.backprop): New hook. * doc/tm.texi.in (TARGET_MODE_BACKPROP): New @hook. * doc/tm.texi: Regenerate. * mode-switching.cc (struct bb_info): Add single_succ. (confluence_info): Add transp field. (single_succ_confluence_n, single_succ_transfer): New functions. (backprop_confluence_n, backprop_transfer): Likewise. (optimize_mode_switching): Use them. Push mode transitions onto a block's incoming edges, if the backprop hook requires it.
Diffstat (limited to 'gcc/target.def')
-rw-r--r--gcc/target.def29
1 files changed, 29 insertions, 0 deletions
diff --git a/gcc/target.def b/gcc/target.def
index b08ede6..0996da0 100644
--- a/gcc/target.def
+++ b/gcc/target.def
@@ -7071,6 +7071,35 @@ for the given arguments.",
int, (int entity, int mode1, int mode2), NULL)
DEFHOOK
+(backprop,
+ "If defined, the mode-switching pass uses this hook to back-propagate mode\n\
+requirements through blocks that have no mode requirements of their own.\n\
+Specifically, @var{mode1} is the mode that @var{entity} has on exit\n\
+from a block B1 (say) and @var{mode2} is the mode that the next block\n\
+requires @var{entity} to have. B1 does not have any mode requirements\n\
+of its own.\n\
+\n\
+The hook should return the mode that it prefers or requires @var{entity}\n\
+to have in B1, or the number of modes if there is no such requirement.\n\
+If the hook returns a required mode for more than one of B1's outgoing\n\
+edges, those modes are combined as for @code{TARGET_MODE_CONFLUENCE}.\n\
+\n\
+For example, suppose there is a ``one-shot'' entity that,\n\
+for a given execution of a function, either stays off or makes exactly\n\
+one transition from off to on. It is safe to make the transition at any\n\
+time, but it is better not to do so unnecessarily. This hook allows the\n\
+function to manage such an entity without having to track its state at\n\
+runtime. Specifically. the entity would have two modes, 0 for off and\n\
+1 for on, with 2 representing ``don't know''. The system is forbidden from\n\
+transitioning from 2 to 1, since 2 represents the possibility that the\n\
+entity is already on (and the aim is to avoid having to emit code to\n\
+check for that case). This hook would therefore return 1 when @var{mode1}\n\
+is 2 and @var{mode2} is 1, which would force the entity to be on in the\n\
+source block. Applying this inductively would remove all transitions\n\
+in which the previous state is unknown.",
+ int, (int entity, int mode1, int mode2), NULL)
+
+DEFHOOK
(entry,
"If this hook is defined, it is evaluated for every @var{entity} that\n\
needs mode switching. It should return the mode that @var{entity} is\n\