[llvm] [NFC][Coroutines] Use structured binding with llvm::enumerate in CoroSplit (PR #116879)

Tyler Nowicki via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 19 14:02:56 PST 2024


https://github.com/TylerNowicki created https://github.com/llvm/llvm-project/pull/116879

Avoid repeated calls to value() and index() using structured binding with llvm::enumerate.

>From a97faf875523c131f3b988cf3085906a36cf7ec1 Mon Sep 17 00:00:00 2001
From: tnowicki <tyler.nowicki at amd.com>
Date: Tue, 19 Nov 2024 17:00:05 -0500
Subject: [PATCH] [Coroutines] Use structured binding with llvm::enumerate

---
 llvm/lib/Transforms/Coroutines/CoroSplit.cpp | 42 ++++++++++----------
 1 file changed, 21 insertions(+), 21 deletions(-)

diff --git a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp
index 55951e54518bd2..8a5bae9f6f0d4b 100644
--- a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp
+++ b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp
@@ -628,11 +628,11 @@ void CoroCloner::replaceRetconOrAsyncSuspendUses() {
     return;
 
   // Otherwise, we need to create an aggregate.
-  Value *Agg = PoisonValue::get(NewS->getType());
-  for (auto Arg : llvm::enumerate(Args))
-    Agg = Builder.CreateInsertValue(Agg, Arg.value(), Arg.index());
+  Value *Aggr = PoisonValue::get(NewS->getType());
+  for (auto [Idx, Arg] : llvm::enumerate(Args))
+    Aggr = Builder.CreateInsertValue(Aggr, Arg, Idx);
 
-  NewS->replaceAllUsesWith(Agg);
+  NewS->replaceAllUsesWith(Aggr);
 }
 
 void CoroCloner::replaceCoroSuspends() {
@@ -1834,8 +1834,8 @@ void coro::AsyncABI::splitCoroutine(Function &F, coro::Shape &Shape,
 
   // Create a continuation function for each of the suspend points.
   Clones.reserve(Shape.CoroSuspends.size());
-  for (auto CS : llvm::enumerate(Shape.CoroSuspends)) {
-    auto *Suspend = cast<CoroSuspendAsyncInst>(CS.value());
+  for (auto [Idx, CS] : llvm::enumerate(Shape.CoroSuspends)) {
+    auto *Suspend = cast<CoroSuspendAsyncInst>(CS);
 
     // Create the clone declaration.
     auto ResumeNameSuffix = ".resume.";
@@ -1851,8 +1851,8 @@ void coro::AsyncABI::splitCoroutine(Function &F, coro::Shape &Shape,
     }
     auto *Continuation = createCloneDeclaration(
         F, Shape,
-        UseSwiftMangling ? ResumeNameSuffix + Twine(CS.index()) + "_"
-                         : ResumeNameSuffix + Twine(CS.index()),
+        UseSwiftMangling ? ResumeNameSuffix + Twine(Idx) + "_"
+                         : ResumeNameSuffix + Twine(Idx),
         NextF, Suspend);
     Clones.push_back(Continuation);
 
@@ -1885,12 +1885,12 @@ void coro::AsyncABI::splitCoroutine(Function &F, coro::Shape &Shape,
   }
 
   assert(Clones.size() == Shape.CoroSuspends.size());
-  for (auto CS : llvm::enumerate(Shape.CoroSuspends)) {
-    auto *Suspend = CS.value();
-    auto *Clone = Clones[CS.index()];
+  for (auto [Idx, CS] : llvm::enumerate(Shape.CoroSuspends)) {
+    auto *Suspend = CS;
+    auto *Clone = Clones[Idx];
 
-    CoroCloner::createClone(F, "resume." + Twine(CS.index()), Shape, Clone,
-                            Suspend, TTI);
+    CoroCloner::createClone(F, "resume." + Twine(Idx), Shape, Clone, Suspend,
+                            TTI);
   }
 }
 
@@ -1947,12 +1947,12 @@ void coro::AnyRetconABI::splitCoroutine(Function &F, coro::Shape &Shape,
 
   // Create a continuation function for each of the suspend points.
   Clones.reserve(Shape.CoroSuspends.size());
-  for (auto CS : llvm::enumerate(Shape.CoroSuspends)) {
-    auto Suspend = cast<CoroSuspendRetconInst>(CS.value());
+  for (auto [Idx, CS] : llvm::enumerate(Shape.CoroSuspends)) {
+    auto Suspend = cast<CoroSuspendRetconInst>(CS);
 
     // Create the clone declaration.
     auto Continuation = createCloneDeclaration(
-        F, Shape, ".resume." + Twine(CS.index()), NextF, nullptr);
+        F, Shape, ".resume." + Twine(Idx), NextF, nullptr);
     Clones.push_back(Continuation);
 
     // Insert a branch to the unified return block immediately before
@@ -2016,12 +2016,12 @@ void coro::AnyRetconABI::splitCoroutine(Function &F, coro::Shape &Shape,
   }
 
   assert(Clones.size() == Shape.CoroSuspends.size());
-  for (auto CS : llvm::enumerate(Shape.CoroSuspends)) {
-    auto Suspend = CS.value();
-    auto Clone = Clones[CS.index()];
+  for (auto [Idx, CS] : llvm::enumerate(Shape.CoroSuspends)) {
+    auto Suspend = CS;
+    auto Clone = Clones[Idx];
 
-    CoroCloner::createClone(F, "resume." + Twine(CS.index()), Shape, Clone,
-                            Suspend, TTI);
+    CoroCloner::createClone(F, "resume." + Twine(Idx), Shape, Clone, Suspend,
+                            TTI);
   }
 }
 



More information about the llvm-commits mailing list