[llvm] Clang-format coroutine files ahead of refactoring (PR #95583)

Tyler Nowicki via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 14 11:49:27 PDT 2024


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

To clean things up before refactoring apply clang-format changes to the coroutine sources. The files in lib/Transforms/Coroutines deviated from clang-format in a number of places.

>From ca46bd191f67e18600a1ea6315c9e36c4a9fa8ac Mon Sep 17 00:00:00 2001
From: tnowicki <tnowicki.nowicki at amd.com>
Date: Fri, 14 Jun 2024 14:04:31 -0400
Subject: [PATCH] Run clang-format on coroutine files ahead of refactoring

To clean things up before refactoring I ran clang-format on the
coroutine files. The files in lib/Transforms/Coroutines deviated from
clang-format in a number of places.
---
 .../lib/Transforms/Coroutines/CoroCleanup.cpp |   7 +-
 llvm/lib/Transforms/Coroutines/CoroEarly.cpp  | 120 +++++++++---------
 llvm/lib/Transforms/Coroutines/CoroElide.cpp  |  21 ++-
 llvm/lib/Transforms/Coroutines/CoroFrame.cpp  |  91 ++++++-------
 llvm/lib/Transforms/Coroutines/CoroInstr.h    |  21 ++-
 llvm/lib/Transforms/Coroutines/CoroInternal.h |  21 ++-
 llvm/lib/Transforms/Coroutines/Coroutines.cpp |  58 +++++----
 7 files changed, 168 insertions(+), 171 deletions(-)

diff --git a/llvm/lib/Transforms/Coroutines/CoroCleanup.cpp b/llvm/lib/Transforms/Coroutines/CoroCleanup.cpp
index 3e3825fcd50e2..ba933c0917e1c 100644
--- a/llvm/lib/Transforms/Coroutines/CoroCleanup.cpp
+++ b/llvm/lib/Transforms/Coroutines/CoroCleanup.cpp
@@ -8,10 +8,10 @@
 
 #include "llvm/Transforms/Coroutines/CoroCleanup.h"
 #include "CoroInternal.h"
+#include "llvm/IR/Function.h"
 #include "llvm/IR/IRBuilder.h"
 #include "llvm/IR/InstIterator.h"
 #include "llvm/IR/PassManager.h"
-#include "llvm/IR/Function.h"
 #include "llvm/Transforms/Scalar/SimplifyCFG.h"
 
 using namespace llvm;
@@ -25,7 +25,7 @@ struct Lowerer : coro::LowererBase {
   Lowerer(Module &M) : LowererBase(M), Builder(Context) {}
   bool lower(Function &F);
 };
-}
+} // namespace
 
 static void lowerSubFn(IRBuilder<> &Builder, CoroSubFnInst *SubFn) {
   Builder.SetInsertPoint(SubFn);
@@ -114,8 +114,7 @@ static bool declaresCoroCleanupIntrinsics(const Module &M) {
           "llvm.coro.async.size.replace", "llvm.coro.async.resume"});
 }
 
-PreservedAnalyses CoroCleanupPass::run(Module &M,
-                                       ModuleAnalysisManager &MAM) {
+PreservedAnalyses CoroCleanupPass::run(Module &M, ModuleAnalysisManager &MAM) {
   if (!declaresCoroCleanupIntrinsics(M))
     return PreservedAnalyses::all();
 
diff --git a/llvm/lib/Transforms/Coroutines/CoroEarly.cpp b/llvm/lib/Transforms/Coroutines/CoroEarly.cpp
index 489106422e199..a45fe61125690 100644
--- a/llvm/lib/Transforms/Coroutines/CoroEarly.cpp
+++ b/llvm/lib/Transforms/Coroutines/CoroEarly.cpp
@@ -38,7 +38,7 @@ class Lowerer : public coro::LowererBase {
                              ->getPointerTo()) {}
   void lowerEarlyIntrinsics(Function &F);
 };
-}
+} // namespace
 
 // Replace a direct call to coro.resume or coro.destroy with an indirect call to
 // an address returned by coro.subfn.addr intrinsic. This is done so that
@@ -66,8 +66,8 @@ void Lowerer::lowerCoroPromise(CoroPromiseInst *Intrin) {
   auto *SampleStruct =
       StructType::get(Context, {AnyResumeFnPtrTy, AnyResumeFnPtrTy, Int8Ty});
   const DataLayout &DL = TheModule.getDataLayout();
-  int64_t Offset = alignTo(
-      DL.getStructLayout(SampleStruct)->getElementOffset(2), Alignment);
+  int64_t Offset =
+      alignTo(DL.getStructLayout(SampleStruct)->getElementOffset(2), Alignment);
   if (Intrin->isFromPromise())
     Offset = -Offset;
 
@@ -104,7 +104,7 @@ void Lowerer::lowerCoroDone(IntrinsicInst *II) {
 static void buildDebugInfoForNoopResumeDestroyFunc(Function *NoopFn) {
   Module &M = *NoopFn->getParent();
   if (M.debug_compile_units().empty())
-     return;
+    return;
 
   DICompileUnit *CU = *M.debug_compile_units_begin();
   DIBuilder DB(M, /*AllowUnresolved*/ false, CU);
@@ -113,7 +113,7 @@ static void buildDebugInfoForNoopResumeDestroyFunc(Function *NoopFn) {
       DB.createSubroutineType(DB.getOrCreateTypeArray(Params));
   StringRef Name = NoopFn->getName();
   auto *SP = DB.createFunction(
-      CU, /*Name=*/Name, /*LinkageName=*/Name, /*File=*/ CU->getFile(),
+      CU, /*Name=*/Name, /*LinkageName=*/Name, /*File=*/CU->getFile(),
       /*LineNo=*/0, SubroutineType, /*ScopeLine=*/0, DINode::FlagArtificial,
       DISubprogram::SPFlagDefinition);
   NoopFn->setSubprogram(SP);
@@ -143,11 +143,11 @@ void Lowerer::lowerCoroNoop(IntrinsicInst *II) {
     ReturnInst::Create(C, Entry);
 
     // Create a constant struct for the frame.
-    Constant* Values[] = {NoopFn, NoopFn};
-    Constant* NoopCoroConst = ConstantStruct::get(FrameTy, Values);
-    NoopCoro = new GlobalVariable(M, NoopCoroConst->getType(), /*isConstant=*/true,
-                                GlobalVariable::PrivateLinkage, NoopCoroConst,
-                                "NoopCoro.Frame.Const");
+    Constant *Values[] = {NoopFn, NoopFn};
+    Constant *NoopCoroConst = ConstantStruct::get(FrameTy, Values);
+    NoopCoro = new GlobalVariable(
+        M, NoopCoroConst->getType(), /*isConstant=*/true,
+        GlobalVariable::PrivateLinkage, NoopCoroConst, "NoopCoro.Frame.Const");
   }
 
   Builder.SetInsertPoint(II);
@@ -176,57 +176,57 @@ void Lowerer::lowerEarlyIntrinsics(Function &F) {
       continue;
 
     switch (CB->getIntrinsicID()) {
-      default:
-        continue;
-      case Intrinsic::coro_free:
-        CoroFrees.push_back(cast<CoroFreeInst>(&I));
-        break;
-      case Intrinsic::coro_suspend:
-        // Make sure that final suspend point is not duplicated as CoroSplit
-        // pass expects that there is at most one final suspend point.
-        if (cast<CoroSuspendInst>(&I)->isFinal())
-          CB->setCannotDuplicate();
-        HasCoroSuspend = true;
-        break;
-      case Intrinsic::coro_end_async:
-      case Intrinsic::coro_end:
-        // Make sure that fallthrough coro.end is not duplicated as CoroSplit
-        // pass expects that there is at most one fallthrough coro.end.
-        if (cast<AnyCoroEndInst>(&I)->isFallthrough())
-          CB->setCannotDuplicate();
-        break;
-      case Intrinsic::coro_noop:
-        lowerCoroNoop(cast<IntrinsicInst>(&I));
-        break;
-      case Intrinsic::coro_id:
-        if (auto *CII = cast<CoroIdInst>(&I)) {
-          if (CII->getInfo().isPreSplit()) {
-            assert(F.isPresplitCoroutine() &&
-                   "The frontend uses Swtich-Resumed ABI should emit "
-                   "\"presplitcoroutine\" attribute for the coroutine.");
-            setCannotDuplicate(CII);
-            CII->setCoroutineSelf();
-            CoroId = cast<CoroIdInst>(&I);
-          }
+    default:
+      continue;
+    case Intrinsic::coro_free:
+      CoroFrees.push_back(cast<CoroFreeInst>(&I));
+      break;
+    case Intrinsic::coro_suspend:
+      // Make sure that final suspend point is not duplicated as CoroSplit
+      // pass expects that there is at most one final suspend point.
+      if (cast<CoroSuspendInst>(&I)->isFinal())
+        CB->setCannotDuplicate();
+      HasCoroSuspend = true;
+      break;
+    case Intrinsic::coro_end_async:
+    case Intrinsic::coro_end:
+      // Make sure that fallthrough coro.end is not duplicated as CoroSplit
+      // pass expects that there is at most one fallthrough coro.end.
+      if (cast<AnyCoroEndInst>(&I)->isFallthrough())
+        CB->setCannotDuplicate();
+      break;
+    case Intrinsic::coro_noop:
+      lowerCoroNoop(cast<IntrinsicInst>(&I));
+      break;
+    case Intrinsic::coro_id:
+      if (auto *CII = cast<CoroIdInst>(&I)) {
+        if (CII->getInfo().isPreSplit()) {
+          assert(F.isPresplitCoroutine() &&
+                 "The frontend uses Swtich-Resumed ABI should emit "
+                 "\"presplitcoroutine\" attribute for the coroutine.");
+          setCannotDuplicate(CII);
+          CII->setCoroutineSelf();
+          CoroId = cast<CoroIdInst>(&I);
         }
-        break;
-      case Intrinsic::coro_id_retcon:
-      case Intrinsic::coro_id_retcon_once:
-      case Intrinsic::coro_id_async:
-        F.setPresplitCoroutine();
-        break;
-      case Intrinsic::coro_resume:
-        lowerResumeOrDestroy(*CB, CoroSubFnInst::ResumeIndex);
-        break;
-      case Intrinsic::coro_destroy:
-        lowerResumeOrDestroy(*CB, CoroSubFnInst::DestroyIndex);
-        break;
-      case Intrinsic::coro_promise:
-        lowerCoroPromise(cast<CoroPromiseInst>(&I));
-        break;
-      case Intrinsic::coro_done:
-        lowerCoroDone(cast<IntrinsicInst>(&I));
-        break;
+      }
+      break;
+    case Intrinsic::coro_id_retcon:
+    case Intrinsic::coro_id_retcon_once:
+    case Intrinsic::coro_id_async:
+      F.setPresplitCoroutine();
+      break;
+    case Intrinsic::coro_resume:
+      lowerResumeOrDestroy(*CB, CoroSubFnInst::ResumeIndex);
+      break;
+    case Intrinsic::coro_destroy:
+      lowerResumeOrDestroy(*CB, CoroSubFnInst::DestroyIndex);
+      break;
+    case Intrinsic::coro_promise:
+      lowerCoroPromise(cast<CoroPromiseInst>(&I));
+      break;
+    case Intrinsic::coro_done:
+      lowerCoroDone(cast<IntrinsicInst>(&I));
+      break;
     }
   }
 
diff --git a/llvm/lib/Transforms/Coroutines/CoroElide.cpp b/llvm/lib/Transforms/Coroutines/CoroElide.cpp
index 74b5ccb7b9b71..a6634510b86dc 100644
--- a/llvm/lib/Transforms/Coroutines/CoroElide.cpp
+++ b/llvm/lib/Transforms/Coroutines/CoroElide.cpp
@@ -430,19 +430,18 @@ bool CoroIdElider::attemptElide() {
     NumOfCoroElided++;
 
 #ifndef NDEBUG
-      if (!CoroElideInfoOutputFilename.empty())
-        *getOrCreateLogFile() << "Elide " << CalleeCoroutineName << " in "
-                              << FEI.ContainingFunction->getName() << "\n";
+    if (!CoroElideInfoOutputFilename.empty())
+      *getOrCreateLogFile() << "Elide " << CalleeCoroutineName << " in "
+                            << FEI.ContainingFunction->getName() << "\n";
 #endif
 
-      ORE.emit([&]() {
-        return OptimizationRemark(DEBUG_TYPE, "CoroElide", CoroId)
-               << "'" << ore::NV("callee", CalleeCoroutineName)
-               << "' elided in '" << ore::NV("caller", CallerFunctionName)
-               << "' (frame_size="
-               << ore::NV("frame_size", FrameSizeAndAlign->first) << ", align="
-               << ore::NV("align", FrameSizeAndAlign->second.value()) << ")";
-      });
+    ORE.emit([&]() {
+      return OptimizationRemark(DEBUG_TYPE, "CoroElide", CoroId)
+             << "'" << ore::NV("callee", CalleeCoroutineName) << "' elided in '"
+             << ore::NV("caller", CallerFunctionName) << "' (frame_size="
+             << ore::NV("frame_size", FrameSizeAndAlign->first) << ", align="
+             << ore::NV("align", FrameSizeAndAlign->second.value()) << ")";
+    });
   } else {
     ORE.emit([&]() {
       auto Remark = OptimizationRemarkMissed(DEBUG_TYPE, "CoroElide", CoroId)
diff --git a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp
index 8e829a53aeca2..1918d88d62244 100644
--- a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp
+++ b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp
@@ -602,7 +602,7 @@ class FrameTypeBuilder {
   std::optional<Align> MaxFrameAlignment;
 
   SmallVector<Field, 8> Fields;
-  DenseMap<Value*, unsigned> FieldIndexByKey;
+  DenseMap<Value *, unsigned> FieldIndexByKey;
 
 public:
   FrameTypeBuilder(LLVMContext &Context, const DataLayout &DL,
@@ -869,8 +869,7 @@ void FrameTypeBuilder::addFieldForAllocas(const Function &F,
     SWI->setDefaultDest(DestBB);
   }
   // This Debug Info could tell us which allocas are merged into one slot.
-  LLVM_DEBUG(for (auto &AllocaSet
-                  : NonOverlapedAllocas) {
+  LLVM_DEBUG(for (auto &AllocaSet : NonOverlapedAllocas) {
     if (AllocaSet.size() > 1) {
       dbgs() << "In Function:" << F.getName() << "\n";
       dbgs() << "Find Union Set "
@@ -900,7 +899,7 @@ void FrameTypeBuilder::finish(StructType *Ty) {
   StructAlign = SizeAndAlign.second;
 
   auto getField = [](const OptimizedStructLayoutField &LayoutField) -> Field & {
-    return *static_cast<Field *>(const_cast<void*>(LayoutField.Id));
+    return *static_cast<Field *>(const_cast<void *>(LayoutField.Id));
   };
 
   // We need to produce a packed struct type if there's a field whose
@@ -915,7 +914,7 @@ void FrameTypeBuilder::finish(StructType *Ty) {
   }();
 
   // Build the struct body.
-  SmallVector<Type*, 16> FieldTypes;
+  SmallVector<Type *, 16> FieldTypes;
   FieldTypes.reserve(LayoutFields.size() * 3 / 2);
   uint64_t LastOffset = 0;
   for (auto &LayoutField : LayoutFields) {
@@ -929,8 +928,8 @@ void FrameTypeBuilder::finish(StructType *Ty) {
     assert(Offset >= LastOffset);
     if (Offset != LastOffset) {
       if (Packed || alignTo(LastOffset, F.TyAlignment) != Offset)
-        FieldTypes.push_back(ArrayType::get(Type::getInt8Ty(Context),
-                                            Offset - LastOffset));
+        FieldTypes.push_back(
+            ArrayType::get(Type::getInt8Ty(Context), Offset - LastOffset));
     }
 
     F.Offset = Offset;
@@ -1145,10 +1144,9 @@ static void buildFrameDebugInfo(Function &F, coro::Shape &Shape,
   unsigned LineNum = PromiseDIVariable->getLine();
 
   DICompositeType *FrameDITy = DBuilder.createStructType(
-      DIS->getUnit(), Twine(F.getName() + ".coro_frame_ty").str(),
-      DFile, LineNum, Shape.FrameSize * 8,
-      Shape.FrameAlign.value() * 8, llvm::DINode::FlagArtificial, nullptr,
-      llvm::DINodeArray());
+      DIS->getUnit(), Twine(F.getName() + ".coro_frame_ty").str(), DFile,
+      LineNum, Shape.FrameSize * 8, Shape.FrameAlign.value() * 8,
+      llvm::DINode::FlagArtificial, nullptr, llvm::DINodeArray());
   StructType *FrameTy = Shape.FrameTy;
   SmallVector<Metadata *, 16> Elements;
   DataLayout Layout = F.getParent()->getDataLayout();
@@ -1387,8 +1385,8 @@ static StructType *buildFrameType(Function &F, coro::Shape &Shape,
   case coro::ABI::Retcon:
   case coro::ABI::RetconOnce: {
     auto Id = Shape.getRetconCoroId();
-    Shape.RetconLowering.IsFrameInlineInStorage
-      = (B.getStructSize() <= Id->getStorageSize() &&
+    Shape.RetconLowering.IsFrameInlineInStorage =
+        (B.getStructSize() <= Id->getStorageSize() &&
          B.getStructAlign() <= Id->getStorageAlignment());
     break;
   }
@@ -1799,8 +1797,8 @@ static void insertSpills(const FrameDataInfo &FrameData, coro::Shape &Shape) {
       // AllocaInst. So We cast GEP to the AllocaInst here to re-use
       // the Frame storage.
       //
-      // Note: If we change the strategy dealing with alignment, we need to refine
-      // this casting.
+      // Note: If we change the strategy dealing with alignment, we need to
+      // refine this casting.
       if (GEP->getType() != Orig->getType())
         return Builder.CreateAddrSpaceCast(GEP, Orig->getType(),
                                            Orig->getName() + Twine(".cast"));
@@ -2406,7 +2404,7 @@ static bool isSuspendBlock(BasicBlock *BB) {
   return isa<AnyCoroSuspendInst>(BB->front());
 }
 
-typedef SmallPtrSet<BasicBlock*, 8> VisitedBlocksSet;
+typedef SmallPtrSet<BasicBlock *, 8> VisitedBlocksSet;
 
 /// Does control flow starting at the given block ever reach a suspend
 /// instruction before reaching a block in VisitedOrFreeBBs?
@@ -2451,10 +2449,12 @@ static bool willLeaveFunctionImmediatelyAfter(BasicBlock *BB,
                                               unsigned depth = 3) {
   // If we've bottomed out our depth count, stop searching and assume
   // that the path might loop back.
-  if (depth == 0) return false;
+  if (depth == 0)
+    return false;
 
   // If this is a suspend block, we're about to exit the resumption function.
-  if (isSuspendBlock(BB)) return true;
+  if (isSuspendBlock(BB))
+    return true;
 
   // Recurse into the successors.
   for (auto *Succ : successors(BB)) {
@@ -2472,7 +2472,8 @@ static bool localAllocaNeedsStackSave(CoroAllocaAllocInst *AI) {
   // the coro resumption frame.
   for (auto *U : AI->users()) {
     auto FI = dyn_cast<CoroAllocaFreeInst>(U);
-    if (!FI) continue;
+    if (!FI)
+      continue;
 
     if (!willLeaveFunctionImmediatelyAfter(FI->getParent()))
       return true;
@@ -2484,8 +2485,8 @@ static bool localAllocaNeedsStackSave(CoroAllocaAllocInst *AI) {
 
 /// Turn each of the given local allocas into a normal (dynamic) alloca
 /// instruction.
-static void lowerLocalAllocas(ArrayRef<CoroAllocaAllocInst*> LocalAllocas,
-                              SmallVectorImpl<Instruction*> &DeadInsts) {
+static void lowerLocalAllocas(ArrayRef<CoroAllocaAllocInst *> LocalAllocas,
+                              SmallVectorImpl<Instruction *> &DeadInsts) {
   for (auto *AI : LocalAllocas) {
     IRBuilder<> Builder(AI);
 
@@ -2504,9 +2505,9 @@ static void lowerLocalAllocas(ArrayRef<CoroAllocaAllocInst*> LocalAllocas,
       if (isa<CoroAllocaGetInst>(U)) {
         U->replaceAllUsesWith(Alloca);
 
-      // Replace frees with stackrestores.  This is safe because
-      // alloca.alloc is required to obey a stack discipline, although we
-      // don't enforce that structurally.
+        // Replace frees with stackrestores.  This is safe because
+        // alloca.alloc is required to obey a stack discipline, although we
+        // don't enforce that structurally.
       } else {
         auto FI = cast<CoroAllocaFreeInst>(U);
         if (StackSave) {
@@ -2524,9 +2525,9 @@ static void lowerLocalAllocas(ArrayRef<CoroAllocaAllocInst*> LocalAllocas,
 /// Turn the given coro.alloca.alloc call into a dynamic allocation.
 /// This happens during the all-instructions iteration, so it must not
 /// delete the call.
-static Instruction *lowerNonLocalAlloca(CoroAllocaAllocInst *AI,
-                                        coro::Shape &Shape,
-                                   SmallVectorImpl<Instruction*> &DeadInsts) {
+static Instruction *
+lowerNonLocalAlloca(CoroAllocaAllocInst *AI, coro::Shape &Shape,
+                    SmallVectorImpl<Instruction *> &DeadInsts) {
   IRBuilder<> Builder(AI);
   auto Alloc = Shape.emitAlloc(Builder, AI->getSize(), nullptr);
 
@@ -2567,11 +2568,10 @@ static Value *emitGetSwiftErrorValue(IRBuilder<> &Builder, Type *ValueTy,
 static Value *emitSetSwiftErrorValue(IRBuilder<> &Builder, Value *V,
                                      coro::Shape &Shape) {
   // Make a fake function pointer as a sort of intrinsic.
-  auto FnTy = FunctionType::get(Builder.getPtrTy(),
-                                {V->getType()}, false);
+  auto FnTy = FunctionType::get(Builder.getPtrTy(), {V->getType()}, false);
   auto Fn = ConstantPointerNull::get(Builder.getPtrTy());
 
-  auto Call = Builder.CreateCall(FnTy, Fn, { V });
+  auto Call = Builder.CreateCall(FnTy, Fn, {V});
   Shape.SwiftErrorOps.push_back(Call);
 
   return Call;
@@ -2638,9 +2638,9 @@ static void eliminateSwiftErrorAlloca(Function &F, AllocaInst *Alloca,
 /// and then loading and storing in the prologue and epilog.
 ///
 /// The argument keeps the swifterror flag.
-static void eliminateSwiftErrorArgument(Function &F, Argument &Arg,
-                                        coro::Shape &Shape,
-                             SmallVectorImpl<AllocaInst*> &AllocasToPromote) {
+static void
+eliminateSwiftErrorArgument(Function &F, Argument &Arg, coro::Shape &Shape,
+                            SmallVectorImpl<AllocaInst *> &AllocasToPromote) {
   IRBuilder<> Builder(F.getEntryBlock().getFirstNonPHIOrDbg());
 
   auto ArgTy = cast<PointerType>(Arg.getType());
@@ -2658,14 +2658,14 @@ static void eliminateSwiftErrorArgument(Function &F, Argument &Arg,
 
   // Find all the suspends in the function and save and restore around them.
   for (auto *Suspend : Shape.CoroSuspends) {
-    (void) emitSetAndGetSwiftErrorValueAround(Suspend, Alloca, Shape);
+    (void)emitSetAndGetSwiftErrorValueAround(Suspend, Alloca, Shape);
   }
 
   // Find all the coro.ends in the function and restore the error value.
   for (auto *End : Shape.CoroEnds) {
     Builder.SetInsertPoint(End);
     auto FinalValue = Builder.CreateLoad(ValueTy, Alloca);
-    (void) emitSetSwiftErrorValue(Builder, FinalValue, Shape);
+    (void)emitSetSwiftErrorValue(Builder, FinalValue, Shape);
   }
 
   // Now we can use the alloca logic.
@@ -2676,11 +2676,12 @@ static void eliminateSwiftErrorArgument(Function &F, Argument &Arg,
 /// Eliminate all problematic uses of swifterror arguments and allocas
 /// from the function.  We'll fix them up later when splitting the function.
 static void eliminateSwiftError(Function &F, coro::Shape &Shape) {
-  SmallVector<AllocaInst*, 4> AllocasToPromote;
+  SmallVector<AllocaInst *, 4> AllocasToPromote;
 
   // Look for a swifterror argument.
   for (auto &Arg : F.args()) {
-    if (!Arg.hasSwiftErrorAttr()) continue;
+    if (!Arg.hasSwiftErrorAttr())
+      continue;
 
     eliminateSwiftErrorArgument(F, Arg, Shape, AllocasToPromote);
     break;
@@ -2689,7 +2690,8 @@ static void eliminateSwiftError(Function &F, coro::Shape &Shape) {
   // Look for swifterror allocas.
   for (auto &Inst : F.getEntryBlock()) {
     auto Alloca = dyn_cast<AllocaInst>(&Inst);
-    if (!Alloca || !Alloca->isSwiftError()) continue;
+    if (!Alloca || !Alloca->isSwiftError())
+      continue;
 
     // Clear the swifterror flag.
     Alloca->setSwiftError(false);
@@ -2772,7 +2774,7 @@ static void sinkLifetimeStartMarkers(Function &F, coro::Shape &Shape,
   }
 
   for (Instruction &I : instructions(F)) {
-    AllocaInst* AI = dyn_cast<AllocaInst>(&I);
+    AllocaInst *AI = dyn_cast<AllocaInst>(&I);
     if (!AI)
       continue;
 
@@ -2780,8 +2782,8 @@ static void sinkLifetimeStartMarkers(Function &F, coro::Shape &Shape,
       bool Valid = true;
       SmallVector<Instruction *, 1> Lifetimes;
 
-      auto isLifetimeStart = [](Instruction* I) {
-        if (auto* II = dyn_cast<IntrinsicInst>(I))
+      auto isLifetimeStart = [](Instruction *I) {
+        if (auto *II = dyn_cast<IntrinsicInst>(I))
           return II->getIntrinsicID() == Intrinsic::lifetime_start;
         return false;
       };
@@ -3100,8 +3102,7 @@ void coro::buildCoroutineFrame(
   if (Shape.ABI != coro::ABI::Async || !Shape.CoroSuspends.empty())
     eliminateSwiftError(F, Shape);
 
-  if (Shape.ABI == coro::ABI::Switch &&
-      Shape.SwitchLowering.PromiseAlloca) {
+  if (Shape.ABI == coro::ABI::Switch && Shape.SwitchLowering.PromiseAlloca) {
     Shape.getSwitchCoroId()->clearPromise();
   }
 
@@ -3150,8 +3151,8 @@ void coro::buildCoroutineFrame(
 
   const DominatorTree DT(F);
   FrameDataInfo FrameData;
-  SmallVector<CoroAllocaAllocInst*, 4> LocalAllocas;
-  SmallVector<Instruction*, 4> DeadInstructions;
+  SmallVector<CoroAllocaAllocInst *, 4> LocalAllocas;
+  SmallVector<Instruction *, 4> DeadInstructions;
   if (Shape.ABI != coro::ABI::Async && Shape.ABI != coro::ABI::Retcon &&
       Shape.ABI != coro::ABI::RetconOnce)
     sinkLifetimeStartMarkers(F, Shape, Checker, DT);
diff --git a/llvm/lib/Transforms/Coroutines/CoroInstr.h b/llvm/lib/Transforms/Coroutines/CoroInstr.h
index a31703fe01304..ba1a143f386bb 100644
--- a/llvm/lib/Transforms/Coroutines/CoroInstr.h
+++ b/llvm/lib/Transforms/Coroutines/CoroInstr.h
@@ -246,9 +246,7 @@ class LLVM_LIBRARY_VISIBILITY AnyCoroIdRetconInst : public AnyCoroIdInst {
     return cast<ConstantInt>(getArgOperand(AlignArg))->getAlignValue();
   }
 
-  Value *getStorage() const {
-    return getArgOperand(StorageArg);
-  }
+  Value *getStorage() const { return getArgOperand(StorageArg); }
 
   /// Return the prototype for the continuation function.  The type,
   /// attributes, and calling convention of the continuation function(s)
@@ -270,8 +268,8 @@ class LLVM_LIBRARY_VISIBILITY AnyCoroIdRetconInst : public AnyCoroIdInst {
   // Methods to support type inquiry through isa, cast, and dyn_cast:
   static bool classof(const IntrinsicInst *I) {
     auto ID = I->getIntrinsicID();
-    return ID == Intrinsic::coro_id_retcon
-        || ID == Intrinsic::coro_id_retcon_once;
+    return ID == Intrinsic::coro_id_retcon ||
+           ID == Intrinsic::coro_id_retcon_once;
   }
   static bool classof(const Value *V) {
     return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
@@ -279,8 +277,7 @@ class LLVM_LIBRARY_VISIBILITY AnyCoroIdRetconInst : public AnyCoroIdInst {
 };
 
 /// This represents the llvm.coro.id.retcon instruction.
-class LLVM_LIBRARY_VISIBILITY CoroIdRetconInst
-    : public AnyCoroIdRetconInst {
+class LLVM_LIBRARY_VISIBILITY CoroIdRetconInst : public AnyCoroIdRetconInst {
 public:
   // Methods to support type inquiry through isa, cast, and dyn_cast:
   static bool classof(const IntrinsicInst *I) {
@@ -594,7 +591,8 @@ class LLVM_LIBRARY_VISIBILITY CoroSuspendAsyncInst : public AnyCoroSuspendInst {
 };
 
 /// This represents the llvm.coro.suspend.retcon instruction.
-class LLVM_LIBRARY_VISIBILITY CoroSuspendRetconInst : public AnyCoroSuspendInst {
+class LLVM_LIBRARY_VISIBILITY CoroSuspendRetconInst
+    : public AnyCoroSuspendInst {
 public:
   op_iterator value_begin() { return arg_begin(); }
   const_op_iterator value_begin() const { return arg_begin(); }
@@ -738,10 +736,9 @@ class LLVM_LIBRARY_VISIBILITY CoroAsyncEndInst : public AnyCoroEndInst {
 /// This represents the llvm.coro.alloca.alloc instruction.
 class LLVM_LIBRARY_VISIBILITY CoroAllocaAllocInst : public IntrinsicInst {
   enum { SizeArg, AlignArg };
+
 public:
-  Value *getSize() const {
-    return getArgOperand(SizeArg);
-  }
+  Value *getSize() const { return getArgOperand(SizeArg); }
   Align getAlignment() const {
     return cast<ConstantInt>(getArgOperand(AlignArg))->getAlignValue();
   }
@@ -758,6 +755,7 @@ class LLVM_LIBRARY_VISIBILITY CoroAllocaAllocInst : public IntrinsicInst {
 /// This represents the llvm.coro.alloca.get instruction.
 class LLVM_LIBRARY_VISIBILITY CoroAllocaGetInst : public IntrinsicInst {
   enum { AllocArg };
+
 public:
   CoroAllocaAllocInst *getAlloc() const {
     return cast<CoroAllocaAllocInst>(getArgOperand(AllocArg));
@@ -775,6 +773,7 @@ class LLVM_LIBRARY_VISIBILITY CoroAllocaGetInst : public IntrinsicInst {
 /// This represents the llvm.coro.alloca.free instruction.
 class LLVM_LIBRARY_VISIBILITY CoroAllocaFreeInst : public IntrinsicInst {
   enum { AllocArg };
+
 public:
   CoroAllocaAllocInst *getAlloc() const {
     return cast<CoroAllocaAllocInst>(getArgOperand(AllocArg));
diff --git a/llvm/lib/Transforms/Coroutines/CoroInternal.h b/llvm/lib/Transforms/Coroutines/CoroInternal.h
index 5716fd0ea4ab9..adbb8b80e4b53 100644
--- a/llvm/lib/Transforms/Coroutines/CoroInternal.h
+++ b/llvm/lib/Transforms/Coroutines/CoroInternal.h
@@ -83,7 +83,7 @@ struct LLVM_LIBRARY_VISIBILITY Shape {
   SmallVector<CoroSizeInst *, 2> CoroSizes;
   SmallVector<CoroAlignInst *, 2> CoroAligns;
   SmallVector<AnyCoroSuspendInst *, 4> CoroSuspends;
-  SmallVector<CallInst*, 2> SwiftErrorOps;
+  SmallVector<CallInst *, 2> SwiftErrorOps;
   SmallVector<CoroAwaitSuspendInst *, 4> CoroAwaitSuspends;
   SmallVector<CallInst *, 2> SymmetricTransfers;
 
@@ -157,8 +157,7 @@ struct LLVM_LIBRARY_VISIBILITY Shape {
   }
 
   AnyCoroIdRetconInst *getRetconCoroId() const {
-    assert(ABI == coro::ABI::Retcon ||
-           ABI == coro::ABI::RetconOnce);
+    assert(ABI == coro::ABI::Retcon || ABI == coro::ABI::RetconOnce);
     return cast<AnyCoroIdRetconInst>(CoroBegin->getId());
   }
 
@@ -183,8 +182,8 @@ struct LLVM_LIBRARY_VISIBILITY Shape {
 
   PointerType *getSwitchResumePointerType() const {
     assert(ABI == coro::ABI::Switch);
-  assert(FrameTy && "frame type not assigned");
-  return cast<PointerType>(FrameTy->getElementType(SwitchFieldIndex::Resume));
+    assert(FrameTy && "frame type not assigned");
+    return cast<PointerType>(FrameTy->getElementType(SwitchFieldIndex::Resume));
   }
 
   FunctionType *getResumeFunctionType() const {
@@ -204,22 +203,20 @@ struct LLVM_LIBRARY_VISIBILITY Shape {
     llvm_unreachable("Unknown coro::ABI enum");
   }
 
-  ArrayRef<Type*> getRetconResultTypes() const {
-    assert(ABI == coro::ABI::Retcon ||
-           ABI == coro::ABI::RetconOnce);
+  ArrayRef<Type *> getRetconResultTypes() const {
+    assert(ABI == coro::ABI::Retcon || ABI == coro::ABI::RetconOnce);
     auto FTy = CoroBegin->getFunction()->getFunctionType();
 
     // The safety of all this is checked by checkWFRetconPrototype.
     if (auto STy = dyn_cast<StructType>(FTy->getReturnType())) {
       return STy->elements().slice(1);
     } else {
-      return ArrayRef<Type*>();
+      return ArrayRef<Type *>();
     }
   }
 
-  ArrayRef<Type*> getRetconResumeTypes() const {
-    assert(ABI == coro::ABI::Retcon ||
-           ABI == coro::ABI::RetconOnce);
+  ArrayRef<Type *> getRetconResumeTypes() const {
+    assert(ABI == coro::ABI::Retcon || ABI == coro::ABI::RetconOnce);
 
     // The safety of all this is checked by checkWFRetconPrototype.
     auto FTy = RetconLowering.ResumePrototype->getFunctionType();
diff --git a/llvm/lib/Transforms/Coroutines/Coroutines.cpp b/llvm/lib/Transforms/Coroutines/Coroutines.cpp
index 1a92bc1636257..c9b8ee7763131 100644
--- a/llvm/lib/Transforms/Coroutines/Coroutines.cpp
+++ b/llvm/lib/Transforms/Coroutines/Coroutines.cpp
@@ -216,8 +216,7 @@ void coro::Shape::buildFrom(Function &F) {
         CoroSuspends.push_back(Suspend);
         if (Suspend->isFinal()) {
           if (HasFinalSuspend)
-            report_fatal_error(
-              "Only one suspend point can be marked as final");
+            report_fatal_error("Only one suspend point can be marked as final");
           HasFinalSuspend = true;
           FinalSuspendIndex = CoroSuspends.size() - 1;
         }
@@ -233,7 +232,7 @@ void coro::Shape::buildFrom(Function &F) {
 
         if (CoroBegin)
           report_fatal_error(
-                "coroutine should have exactly one defining @llvm.coro.begin");
+              "coroutine should have exactly one defining @llvm.coro.begin");
         CB->addRetAttr(Attribute::NonNull);
         CB->addRetAttr(Attribute::NoAlias);
         CB->removeFnAttr(Attribute::NoDuplicate);
@@ -334,9 +333,9 @@ void coro::Shape::buildFrom(Function &F) {
   case Intrinsic::coro_id_retcon_once: {
     auto ContinuationId = cast<AnyCoroIdRetconInst>(Id);
     ContinuationId->checkWellFormed();
-    this->ABI = (IdIntrinsic == Intrinsic::coro_id_retcon
-                  ? coro::ABI::Retcon
-                  : coro::ABI::RetconOnce);
+    this->ABI =
+        (IdIntrinsic == Intrinsic::coro_id_retcon ? coro::ABI::Retcon
+                                                  : coro::ABI::RetconOnce);
     auto Prototype = ContinuationId->getPrototype();
     this->RetconLowering.ResumePrototype = Prototype;
     this->RetconLowering.Alloc = ContinuationId->getAllocFunction();
@@ -392,7 +391,7 @@ void coro::Shape::buildFrom(Function &F) {
 
       // Check that the result type of the suspend matches the resume types.
       Type *SResultTy = Suspend->getType();
-      ArrayRef<Type*> SuspendResultTys;
+      ArrayRef<Type *> SuspendResultTys;
       if (SResultTy->isVoidTy()) {
         // leave as empty array
       } else if (auto SResultStructTy = dyn_cast<StructType>(SResultTy)) {
@@ -433,8 +432,7 @@ void coro::Shape::buildFrom(Function &F) {
   }
 
   // Move final suspend to be the last element in the CoroSuspends vector.
-  if (ABI == coro::ABI::Switch &&
-      SwitchLowering.HasFinalSuspend &&
+  if (ABI == coro::ABI::Switch && SwitchLowering.HasFinalSuspend &&
       FinalSuspendIndex != CoroSuspends.size() - 1)
     std::swap(CoroSuspends[FinalSuspendIndex], CoroSuspends.back());
 
@@ -448,7 +446,8 @@ static void propagateCallAttrsFromCallee(CallInst *Call, Function *Callee) {
   // TODO: attributes?
 }
 
-static void addCallToCallGraph(CallGraph *CG, CallInst *Call, Function *Callee){
+static void addCallToCallGraph(CallGraph *CG, CallInst *Call,
+                               Function *Callee) {
   if (CG)
     (*CG)[Call->getFunction()]->addCalledFunction(Call, (*CG)[Callee]);
 }
@@ -462,9 +461,9 @@ Value *coro::Shape::emitAlloc(IRBuilder<> &Builder, Value *Size,
   case coro::ABI::Retcon:
   case coro::ABI::RetconOnce: {
     auto Alloc = RetconLowering.Alloc;
-    Size = Builder.CreateIntCast(Size,
-                                 Alloc->getFunctionType()->getParamType(0),
-                                 /*is signed*/ false);
+    Size =
+        Builder.CreateIntCast(Size, Alloc->getFunctionType()->getParamType(0),
+                              /*is signed*/ false);
     auto *Call = Builder.CreateCall(Alloc, Size);
     propagateCallAttrsFromCallee(Call, Alloc);
     addCallToCallGraph(CG, Call, Alloc);
@@ -485,8 +484,8 @@ void coro::Shape::emitDealloc(IRBuilder<> &Builder, Value *Ptr,
   case coro::ABI::Retcon:
   case coro::ABI::RetconOnce: {
     auto Dealloc = RetconLowering.Dealloc;
-    Ptr = Builder.CreateBitCast(Ptr,
-                                Dealloc->getFunctionType()->getParamType(0));
+    Ptr =
+        Builder.CreateBitCast(Ptr, Dealloc->getFunctionType()->getParamType(0));
     auto *Call = Builder.CreateCall(Dealloc, Ptr);
     propagateCallAttrsFromCallee(Call, Dealloc);
     addCallToCallGraph(CG, Call, Dealloc);
@@ -525,27 +524,32 @@ static void checkWFRetconPrototype(const AnyCoroIdRetconInst *I, Value *V) {
     if (FT->getReturnType()->isPointerTy()) {
       ResultOkay = true;
     } else if (auto SRetTy = dyn_cast<StructType>(FT->getReturnType())) {
-      ResultOkay = (!SRetTy->isOpaque() &&
-                    SRetTy->getNumElements() > 0 &&
+      ResultOkay = (!SRetTy->isOpaque() && SRetTy->getNumElements() > 0 &&
                     SRetTy->getElementType(0)->isPointerTy());
     } else {
       ResultOkay = false;
     }
     if (!ResultOkay)
-      fail(I, "llvm.coro.id.retcon prototype must return pointer as first "
-              "result", F);
+      fail(I,
+           "llvm.coro.id.retcon prototype must return pointer as first "
+           "result",
+           F);
 
     if (FT->getReturnType() !=
-          I->getFunction()->getFunctionType()->getReturnType())
-      fail(I, "llvm.coro.id.retcon prototype return type must be same as"
-              "current function return type", F);
+        I->getFunction()->getFunctionType()->getReturnType())
+      fail(I,
+           "llvm.coro.id.retcon prototype return type must be same as"
+           "current function return type",
+           F);
   } else {
     // No meaningful validation to do here for llvm.coro.id.unique.once.
   }
 
   if (FT->getNumParams() == 0 || !FT->getParamType(0)->isPointerTy())
-    fail(I, "llvm.coro.id.retcon.* prototype must take pointer as "
-            "its first parameter", F);
+    fail(I,
+         "llvm.coro.id.retcon.* prototype must take pointer as "
+         "its first parameter",
+         F);
 }
 
 /// Check that the given value is a well-formed allocator.
@@ -558,8 +562,7 @@ static void checkWFAlloc(const Instruction *I, Value *V) {
   if (!FT->getReturnType()->isPointerTy())
     fail(I, "llvm.coro.* allocator must return a pointer", F);
 
-  if (FT->getNumParams() != 1 ||
-      !FT->getParamType(0)->isIntegerTy())
+  if (FT->getNumParams() != 1 || !FT->getParamType(0)->isIntegerTy())
     fail(I, "llvm.coro.* allocator must take integer as only param", F);
 }
 
@@ -573,8 +576,7 @@ static void checkWFDealloc(const Instruction *I, Value *V) {
   if (!FT->getReturnType()->isVoidTy())
     fail(I, "llvm.coro.* deallocator must return void", F);
 
-  if (FT->getNumParams() != 1 ||
-      !FT->getParamType(0)->isPointerTy())
+  if (FT->getNumParams() != 1 || !FT->getParamType(0)->isPointerTy())
     fail(I, "llvm.coro.* deallocator must take pointer as only param", F);
 }
 



More information about the llvm-commits mailing list