From 09ca8861cdff427d87580dc058f883a07d8fc61a Mon Sep 17 00:00:00 2001 From: Yuxuan Chen Date: Mon, 20 May 2024 11:20:57 -0700 Subject: [PATCH] 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 17d2c9af96c23e..27e105b2a1ef99 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(Use.getUser()); - if (auto *DefUser = cast_of_nullMA) + for (auto &U : Def->uses()) { + MemoryAccess *MA = cast(U.getUser()); + if (auto *DefUser = cast_of_null(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(Use.getUser()); - if (auto *MU = cast_of_nullMA) { + for (auto &U : Def->uses()) { + MemoryAccess *MA = cast(U.getUser()); + if (auto *MU = cast_of_null(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 } } }