From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH 1/2] flowgraph: add a function to calculate the Lowest Common Denominator
Date: Fri, 4 Dec 2020 18:16:03 +0100 [thread overview]
Message-ID: <20201204171604.69635-2-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20201204171604.69635-1-luc.vanoostenryck@gmail.com>
The lowest dominator common to two given BBs is useful to know for
some optimizations like the placement of common sub-expressions.
So, add a function calculating it using the info from the dominator tree.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
flowgraph.c | 15 +++++++++++++++
flowgraph.h | 4 ++++
2 files changed, 19 insertions(+)
diff --git a/flowgraph.c b/flowgraph.c
index 73c29fc9f894..7db0290da31c 100644
--- a/flowgraph.c
+++ b/flowgraph.c
@@ -221,3 +221,18 @@ bool domtree_dominates(struct basic_block *a, struct basic_block *b)
}
return false;
}
+
+struct basic_block *bb_common_dominator(struct basic_block *a, struct basic_block *b)
+{
+ // walk op the domtree until the levels *and* the BBs match
+ while (a != b) {
+ int la = a->dom_level;
+ int lb = b->dom_level;
+
+ if (la >= lb)
+ a = a->idom;
+ if (lb >= la)
+ b = b->idom;
+ }
+ return a;
+}
diff --git a/flowgraph.h b/flowgraph.h
index 5a9c26073554..15f3156fdd4a 100644
--- a/flowgraph.h
+++ b/flowgraph.h
@@ -30,4 +30,8 @@ void domtree_build(struct entrypoint *ep);
// @return: ``true`` if @a dominates @b, ``false`` otherwise.
bool domtree_dominates(struct basic_block *a, struct basic_block *b);
+///
+// Find the lowest common dominator of two basic blocks.
+struct basic_block *bb_common_dominator(struct basic_block *a, struct basic_block *b);
+
#endif
--
2.29.2
next prev parent reply other threads:[~2020-12-04 17:19 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-04 17:16 [RFC PATCH 0/2] cse: place common expressions in the Lowest Common Dominator Luc Van Oostenryck
2020-12-04 17:16 ` Luc Van Oostenryck [this message]
2020-12-04 17:16 ` [PATCH 2/2] " Luc Van Oostenryck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201204171604.69635-2-luc.vanoostenryck@gmail.com \
--to=luc.vanoostenryck@gmail.com \
--cc=linux-sparse@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).