From 3bf4dc102f4ffa2262b9a8d678d732ce66b08f81 Mon Sep 17 00:00:00 2001 From: David Neto Date: Fri, 29 Jul 2016 11:24:57 -0400 Subject: [PATCH] Add BasicBlock methods: dominates postdominates --- source/val/BasicBlock.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/source/val/BasicBlock.h b/source/val/BasicBlock.h index ffba779..dd1014c 100644 --- a/source/val/BasicBlock.h +++ b/source/val/BasicBlock.h @@ -31,6 +31,7 @@ #include +#include #include #include #include @@ -127,6 +128,22 @@ class BasicBlock { /// Returns true if the id of the BasicBlock matches bool operator==(const uint32_t& other_id) const { return other_id == id_; } + /// Returns true if this block dominates the other block. + /// Assumes dominators have been computed. + bool dominates(const BasicBlock& other) const { + return (this == &other) || + !(other.dom_end() == + std::find(other.dom_begin(), other.dom_end(), this)); + } + + /// Returns true if this block postdominates the other block. + /// Assumes dominators have been computed. + bool postdominates(const BasicBlock& other) const { + return (this == &other) || + !(other.pdom_end() == + std::find(other.pdom_begin(), other.pdom_end(), this)); + } + /// @brief A BasicBlock dominator iterator class /// /// This iterator will iterate over the (post)dominators of the block -- 2.7.4