[llvm] [GenericDomTree][NFC] Remove unnecessary `const_cast`s (PR #97638)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 3 14:14:27 PDT 2024


https://github.com/MagentaTreehouse created https://github.com/llvm/llvm-project/pull/97638

None

>From b2f79f6d1a6f9fdaed115017935ec264358f8668 Mon Sep 17 00:00:00 2001
From: Mingyi Chen <cmingyi01 at gmail.com>
Date: Wed, 3 Jul 2024 17:12:36 -0400
Subject: [PATCH] [GenericDomTree][NFC] Remove unnecessary const_casts

---
 llvm/include/llvm/Support/GenericDomTree.h | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/llvm/include/llvm/Support/GenericDomTree.h b/llvm/include/llvm/Support/GenericDomTree.h
index a8e178d6461e0..08ada7b5c43e3 100644
--- a/llvm/include/llvm/Support/GenericDomTree.h
+++ b/llvm/include/llvm/Support/GenericDomTree.h
@@ -419,7 +419,7 @@ class DominatorTreeBase {
   bool isReachableFromEntry(const NodeT *A) const {
     assert(!this->isPostDominator() &&
            "This is not implemented for post dominators");
-    return isReachableFromEntry(getNode(const_cast<NodeT *>(A)));
+    return isReachableFromEntry(getNode(A));
   }
 
   bool isReachableFromEntry(const DomTreeNodeBase<NodeT> *A) const { return A; }
@@ -939,11 +939,7 @@ bool DominatorTreeBase<NodeT, IsPostDom>::dominates(const NodeT *A,
   if (A == B)
     return true;
 
-  // Cast away the const qualifiers here. This is ok since
-  // this function doesn't actually return the values returned
-  // from getNode.
-  return dominates(getNode(const_cast<NodeT *>(A)),
-                   getNode(const_cast<NodeT *>(B)));
+  return dominates(getNode(A), getNode(B));
 }
 template <typename NodeT, bool IsPostDom>
 bool DominatorTreeBase<NodeT, IsPostDom>::properlyDominates(
@@ -951,11 +947,7 @@ bool DominatorTreeBase<NodeT, IsPostDom>::properlyDominates(
   if (A == B)
     return false;
 
-  // Cast away the const qualifiers here. This is ok since
-  // this function doesn't actually return the values returned
-  // from getNode.
-  return dominates(getNode(const_cast<NodeT *>(A)),
-                   getNode(const_cast<NodeT *>(B)));
+  return dominates(getNode(A), getNode(B));
 }
 
 } // end namespace llvm



More information about the llvm-commits mailing list