[llvm] Documentation: Fix C++ examples in MemorySSA documentation (PR #92802)

Yuxuan Chen via llvm-commits llvm-commits at lists.llvm.org
Mon May 20 12:34:01 PDT 2024


https://github.com/yuxuanchen1997 updated https://github.com/llvm/llvm-project/pull/92802

>From 09ca8861cdff427d87580dc058f883a07d8fc61a Mon Sep 17 00:00:00 2001
From: Yuxuan Chen <ych at meta.com>
Date: Mon, 20 May 2024 11:20:57 -0700
Subject: [PATCH 1/2] Documentation: Fix C++ examples in MemorySSA
 documentation

---
 llvm/docs/MemorySSA.rst | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/llvm/docs/MemorySSA.rst b/llvm/docs/MemorySSA.rst
index 17d2c9af96c23..27e105b2a1ef9 100644
--- a/llvm/docs/MemorySSA.rst
+++ b/llvm/docs/MemorySSA.rst
@@ -295,9 +295,9 @@ A code snippet for such a walk looks like this:
 .. code-block:: c++
 
   MemoryDef *Def;  // find who's optimized or defining for this MemoryDef
-  for (auto& U : Def->uses()) {
-    MemoryAccess *MA = cast<MemoryAccess>(Use.getUser());
-    if (auto *DefUser = cast_of_null<MemoryDef>MA)
+  for (auto &U : Def->uses()) {
+    MemoryAccess *MA = cast<MemoryAccess>(U.getUser());
+    if (auto *DefUser = cast_of_null<MemoryDef>(MA))
       if (DefUser->isOptimized() && DefUser->getOptimized() == Def) {
         // User who is optimized to Def
       } else {
@@ -312,19 +312,18 @@ the store.
 .. code-block:: c++
 
   checkUses(MemoryAccess *Def) { // Def can be a MemoryDef or a MemoryPhi.
-    for (auto& U : Def->uses()) {
-      MemoryAccess *MA = cast<MemoryAccess>(Use.getUser());
-      if (auto *MU = cast_of_null<MemoryUse>MA) {
+    for (auto &U : Def->uses()) {
+      MemoryAccess *MA = cast<MemoryAccess>(U.getUser());
+      if (auto *MU = cast_of_null<MemoryUse>(MA)) {
         // Process MemoryUse as needed.
-      }
-      else {
+      } else {
         // Process MemoryDef or MemoryPhi as needed.
 
         // As a user can come up twice, as an optimized access and defining
         // access, keep a visited list.
 
         // Check transitive uses as needed
-        checkUses (MA); // use a worklist for an iterative algorithm
+        checkUses(MA); // use a worklist for an iterative algorithm
       }
     }
   }

>From 758523bb0f528036d1f73c61da4d4a582e93ddd7 Mon Sep 17 00:00:00 2001
From: Yuxuan Chen <ych at meta.com>
Date: Mon, 20 May 2024 12:33:48 -0700
Subject: [PATCH 2/2] cast_or_null is spelt wrong

---
 llvm/docs/MemorySSA.rst | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/docs/MemorySSA.rst b/llvm/docs/MemorySSA.rst
index 27e105b2a1ef9..6f76d079e4fe3 100644
--- a/llvm/docs/MemorySSA.rst
+++ b/llvm/docs/MemorySSA.rst
@@ -297,7 +297,7 @@ A code snippet for such a walk looks like this:
   MemoryDef *Def;  // find who's optimized or defining for this MemoryDef
   for (auto &U : Def->uses()) {
     MemoryAccess *MA = cast<MemoryAccess>(U.getUser());
-    if (auto *DefUser = cast_of_null<MemoryDef>(MA))
+    if (auto *DefUser = cast_or_null<MemoryDef>(MA))
       if (DefUser->isOptimized() && DefUser->getOptimized() == Def) {
         // User who is optimized to Def
       } else {
@@ -314,7 +314,7 @@ the store.
   checkUses(MemoryAccess *Def) { // Def can be a MemoryDef or a MemoryPhi.
     for (auto &U : Def->uses()) {
       MemoryAccess *MA = cast<MemoryAccess>(U.getUser());
-      if (auto *MU = cast_of_null<MemoryUse>(MA)) {
+      if (auto *MU = cast_or_null<MemoryUse>(MA)) {
         // Process MemoryUse as needed.
       } else {
         // Process MemoryDef or MemoryPhi as needed.



More information about the llvm-commits mailing list