Skip to content

Commit 207da54

Browse files
committed
SWDEV-303548 - Put everything in the coro namespace and fixup class names
1 parent a2150ba commit 207da54

File tree

3 files changed

+74
-65
lines changed

3 files changed

+74
-65
lines changed

llvm/lib/Transforms/Coroutines/CoroCloner.h

Lines changed: 51 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
// functions.
1010
//===----------------------------------------------------------------------===//
1111

12-
#pragma once
12+
#ifndef LLVM_LIB_TRANSFORMS_COROUTINES_COROCLONER_H
13+
#define LLVM_LIB_TRANSFORMS_COROUTINES_COROCLONER_H
1314

1415
#include "llvm/IR/Function.h"
1516
#include "llvm/IR/IRBuilder.h"
@@ -18,32 +19,33 @@
1819
#include "llvm/Transforms/Coroutines/CoroInstr.h"
1920
#include "llvm/Transforms/Utils/ValueMapper.h"
2021

21-
using namespace llvm;
22+
namespace llvm {
2223

23-
class CoroCloner {
24-
public:
25-
enum class Kind {
26-
/// The shared resume function for a switch lowering.
27-
SwitchResume,
24+
namespace coro {
25+
26+
enum class CloneKind {
27+
/// The shared resume function for a switch lowering.
28+
SwitchResume,
2829

29-
/// The shared unwind function for a switch lowering.
30-
SwitchUnwind,
30+
/// The shared unwind function for a switch lowering.
31+
SwitchUnwind,
3132

32-
/// The shared cleanup function for a switch lowering.
33-
SwitchCleanup,
33+
/// The shared cleanup function for a switch lowering.
34+
SwitchCleanup,
3435

35-
/// An individual continuation function.
36-
Continuation,
36+
/// An individual continuation function.
37+
Continuation,
3738

38-
/// An async resume function.
39-
Async,
40-
};
39+
/// An async resume function.
40+
Async,
41+
};
4142

43+
class BaseCloner {
4244
protected:
4345
Function &OrigF;
4446
const Twine &Suffix;
4547
coro::Shape &Shape;
46-
Kind FKind;
48+
CloneKind FKind;
4749
IRBuilder<> Builder;
4850
TargetTransformInfo &TTI;
4951

@@ -56,37 +58,38 @@ class CoroCloner {
5658
AnyCoroSuspendInst *ActiveSuspend = nullptr;
5759

5860
/// Create a cloner for a continuation lowering.
59-
CoroCloner(Function &OrigF, const Twine &Suffix, coro::Shape &Shape,
61+
BaseCloner(Function &OrigF, const Twine &Suffix, coro::Shape &Shape,
6062
Function *NewF, AnyCoroSuspendInst *ActiveSuspend,
6163
TargetTransformInfo &TTI)
6264
: OrigF(OrigF), Suffix(Suffix), Shape(Shape),
63-
FKind(Shape.ABI == coro::ABI::Async ? Kind::Async : Kind::Continuation),
65+
FKind(Shape.ABI == ABI::Async ? CloneKind::Async
66+
: CloneKind::Continuation),
6467
Builder(OrigF.getContext()), TTI(TTI), NewF(NewF),
6568
ActiveSuspend(ActiveSuspend) {
66-
assert(Shape.ABI == coro::ABI::Retcon ||
67-
Shape.ABI == coro::ABI::RetconOnce || Shape.ABI == coro::ABI::Async);
69+
assert(Shape.ABI == ABI::Retcon || Shape.ABI == ABI::RetconOnce ||
70+
Shape.ABI == ABI::Async);
6871
assert(NewF && "need existing function for continuation");
6972
assert(ActiveSuspend && "need active suspend point for continuation");
7073
}
7174

7275
public:
73-
CoroCloner(Function &OrigF, const Twine &Suffix, coro::Shape &Shape,
74-
Kind FKind, TargetTransformInfo &TTI)
76+
BaseCloner(Function &OrigF, const Twine &Suffix, coro::Shape &Shape,
77+
CloneKind FKind, TargetTransformInfo &TTI)
7578
: OrigF(OrigF), Suffix(Suffix), Shape(Shape), FKind(FKind),
7679
Builder(OrigF.getContext()), TTI(TTI) {}
7780

78-
virtual ~CoroCloner() {}
81+
virtual ~BaseCloner() {}
7982

8083
/// Create a clone for a continuation lowering.
8184
static Function *createClone(Function &OrigF, const Twine &Suffix,
8285
coro::Shape &Shape, Function *NewF,
8386
AnyCoroSuspendInst *ActiveSuspend,
8487
TargetTransformInfo &TTI) {
85-
assert(Shape.ABI == coro::ABI::Retcon ||
86-
Shape.ABI == coro::ABI::RetconOnce || Shape.ABI == coro::ABI::Async);
87-
TimeTraceScope FunctionScope("CoroCloner");
88+
assert(Shape.ABI == ABI::Retcon || Shape.ABI == ABI::RetconOnce ||
89+
Shape.ABI == ABI::Async);
90+
TimeTraceScope FunctionScope("BaseCloner");
8891

89-
CoroCloner Cloner(OrigF, Suffix, Shape, NewF, ActiveSuspend, TTI);
92+
BaseCloner Cloner(OrigF, Suffix, Shape, NewF, ActiveSuspend, TTI);
9093
Cloner.create();
9194
return Cloner.getFunction();
9295
}
@@ -101,15 +104,15 @@ class CoroCloner {
101104
protected:
102105
bool isSwitchDestroyFunction() {
103106
switch (FKind) {
104-
case Kind::Async:
105-
case Kind::Continuation:
106-
case Kind::SwitchResume:
107+
case CloneKind::Async:
108+
case CloneKind::Continuation:
109+
case CloneKind::SwitchResume:
107110
return false;
108-
case Kind::SwitchUnwind:
109-
case Kind::SwitchCleanup:
111+
case CloneKind::SwitchUnwind:
112+
case CloneKind::SwitchCleanup:
110113
return true;
111114
}
112-
llvm_unreachable("Unknown CoroCloner::Kind enum");
115+
llvm_unreachable("Unknown ClonerKind enum");
113116
}
114117

115118
void replaceEntryBlock();
@@ -122,25 +125,31 @@ class CoroCloner {
122125
void handleFinalSuspend();
123126
};
124127

125-
class CoroSwitchCloner : public CoroCloner {
128+
class SwitchCloner : public BaseCloner {
126129
protected:
127130
/// Create a cloner for a switch lowering.
128-
CoroSwitchCloner(Function &OrigF, const Twine &Suffix, coro::Shape &Shape,
129-
Kind FKind, TargetTransformInfo &TTI)
130-
: CoroCloner(OrigF, Suffix, Shape, FKind, TTI) {}
131+
SwitchCloner(Function &OrigF, const Twine &Suffix, coro::Shape &Shape,
132+
CloneKind FKind, TargetTransformInfo &TTI)
133+
: BaseCloner(OrigF, Suffix, Shape, FKind, TTI) {}
131134

132135
void create() override;
133136

134137
public:
135138
/// Create a clone for a switch lowering.
136139
static Function *createClone(Function &OrigF, const Twine &Suffix,
137-
coro::Shape &Shape, Kind FKind,
140+
coro::Shape &Shape, CloneKind FKind,
138141
TargetTransformInfo &TTI) {
139-
assert(Shape.ABI == coro::ABI::Switch);
140-
TimeTraceScope FunctionScope("CoroCloner");
142+
assert(Shape.ABI == ABI::Switch);
143+
TimeTraceScope FunctionScope("SwitchCloner");
141144

142-
CoroSwitchCloner Cloner(OrigF, Suffix, Shape, FKind, TTI);
145+
SwitchCloner Cloner(OrigF, Suffix, Shape, FKind, TTI);
143146
Cloner.create();
144147
return Cloner.getFunction();
145148
}
146149
};
150+
151+
} // end namespace coro
152+
153+
} // end namespace llvm
154+
155+
#endif // LLVM_LIB_TRANSFORMS_COROUTINES_COROCLONER_H

llvm/lib/Transforms/Coroutines/CoroFrame.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1133,7 +1133,7 @@ static void insertSpills(const FrameDataInfo &FrameData, coro::Shape &Shape) {
11331133
bool AllowUnresolved = false;
11341134
// This dbg.declare is preserved for all coro-split function
11351135
// fragments. It will be unreachable in the main function, and
1136-
// processed by coro::salvageDebugInfo() by CoroCloner.
1136+
// processed by coro::salvageDebugInfo() by BaseCloner.
11371137
if (UseNewDbgInfoFormat) {
11381138
DbgVariableRecord *NewDVR = new DbgVariableRecord(
11391139
ValueAsMetadata::get(CurrentReload), DDI->getVariable(),

llvm/lib/Transforms/Coroutines/CoroSplit.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ static void replaceCoroEnd(AnyCoroEndInst *End, const coro::Shape &Shape,
402402
// is possible since the coroutine is considered suspended at the final suspend
403403
// point if promise.unhandled_exception() exits via an exception), we can
404404
// remove the last case.
405-
void CoroCloner::handleFinalSuspend() {
405+
void coro::BaseCloner::handleFinalSuspend() {
406406
assert(Shape.ABI == coro::ABI::Switch &&
407407
Shape.SwitchLowering.HasFinalSuspend);
408408

@@ -466,7 +466,7 @@ static Function *createCloneDeclaration(Function &OrigF, coro::Shape &Shape,
466466
/// arguments to the continuation function.
467467
///
468468
/// This assumes that the builder has a meaningful insertion point.
469-
void CoroCloner::replaceRetconOrAsyncSuspendUses() {
469+
void coro::BaseCloner::replaceRetconOrAsyncSuspendUses() {
470470
assert(Shape.ABI == coro::ABI::Retcon || Shape.ABI == coro::ABI::RetconOnce ||
471471
Shape.ABI == coro::ABI::Async);
472472

@@ -514,7 +514,7 @@ void CoroCloner::replaceRetconOrAsyncSuspendUses() {
514514
NewS->replaceAllUsesWith(Aggr);
515515
}
516516

517-
void CoroCloner::replaceCoroSuspends() {
517+
void coro::BaseCloner::replaceCoroSuspends() {
518518
Value *SuspendResult;
519519

520520
switch (Shape.ABI) {
@@ -551,7 +551,7 @@ void CoroCloner::replaceCoroSuspends() {
551551
}
552552
}
553553

554-
void CoroCloner::replaceCoroEnds() {
554+
void coro::BaseCloner::replaceCoroEnds() {
555555
for (AnyCoroEndInst *CE : Shape.CoroEnds) {
556556
// We use a null call graph because there's no call graph node for
557557
// the cloned function yet. We'll just be rebuilding that later.
@@ -630,11 +630,11 @@ collectDbgVariableIntrinsics(Function &F) {
630630
return {Intrinsics, DbgVariableRecords};
631631
}
632632

633-
void CoroCloner::replaceSwiftErrorOps() {
633+
void coro::BaseCloner::replaceSwiftErrorOps() {
634634
::replaceSwiftErrorOps(*NewF, Shape, &VMap);
635635
}
636636

637-
void CoroCloner::salvageDebugInfo() {
637+
void coro::BaseCloner::salvageDebugInfo() {
638638
auto [Worklist, DbgVariableRecords] = collectDbgVariableIntrinsics(*NewF);
639639
SmallDenseMap<Argument *, AllocaInst *, 4> ArgToAllocaMap;
640640

@@ -671,7 +671,7 @@ void CoroCloner::salvageDebugInfo() {
671671
for_each(DbgVariableRecords, RemoveOne);
672672
}
673673

674-
void CoroCloner::replaceEntryBlock() {
674+
void coro::BaseCloner::replaceEntryBlock() {
675675
// In the original function, the AllocaSpillBlock is a block immediately
676676
// following the allocation of the frame object which defines GEPs for
677677
// all the allocas that have been moved into the frame, and it ends by
@@ -739,7 +739,7 @@ void CoroCloner::replaceEntryBlock() {
739739
}
740740

741741
/// Derive the value of the new frame pointer.
742-
Value *CoroCloner::deriveNewFramePointer() {
742+
Value *coro::BaseCloner::deriveNewFramePointer() {
743743
// Builder should be inserting to the front of the new entry block.
744744

745745
switch (Shape.ABI) {
@@ -863,7 +863,7 @@ static void addSwiftSelfAttrs(AttributeList &Attrs, LLVMContext &Context,
863863

864864
/// Clone the body of the original function into a resume function of
865865
/// some sort.
866-
void CoroCloner::create() {
866+
void coro::BaseCloner::create() {
867867
assert(NewF);
868868

869869
// Replace all args with dummy instructions. If an argument is the old frame
@@ -1090,18 +1090,18 @@ void CoroCloner::create() {
10901090
salvageDebugInfo();
10911091
}
10921092

1093-
void CoroSwitchCloner::create() {
1093+
void coro::SwitchCloner::create() {
10941094
// Create a new function matching the original type
10951095
NewF = createCloneDeclaration(OrigF, Shape, Suffix, OrigF.getParent()->end(),
10961096
ActiveSuspend);
10971097

10981098
// Clone the function
1099-
CoroCloner::create();
1099+
coro::BaseCloner::create();
11001100

11011101
// Eliminate coro.free from the clones, replacing it with 'null' in cleanup,
11021102
// to suppress deallocation code.
11031103
coro::replaceCoroFree(cast<CoroIdInst>(VMap[Shape.CoroBegin->getId()]),
1104-
/*Elide=*/FKind == CoroCloner::Kind::SwitchCleanup);
1104+
/*Elide=*/FKind == coro::CloneKind::SwitchCleanup);
11051105
}
11061106

11071107
static void updateAsyncFuncPointerContextSize(coro::Shape &Shape) {
@@ -1378,12 +1378,12 @@ struct SwitchCoroutineSplitter {
13781378
// setting new entry block and replacing coro.suspend an appropriate value
13791379
// to force resume or cleanup pass for every suspend point.
13801380
createResumeEntryBlock(F, Shape);
1381-
auto *ResumeClone = CoroSwitchCloner::createClone(
1382-
F, ".resume", Shape, CoroCloner::Kind::SwitchResume, TTI);
1383-
auto *DestroyClone = CoroSwitchCloner::createClone(
1384-
F, ".destroy", Shape, CoroCloner::Kind::SwitchUnwind, TTI);
1385-
auto *CleanupClone = CoroSwitchCloner::createClone(
1386-
F, ".cleanup", Shape, CoroCloner::Kind::SwitchCleanup, TTI);
1381+
auto *ResumeClone = coro::SwitchCloner::createClone(
1382+
F, ".resume", Shape, coro::CloneKind::SwitchResume, TTI);
1383+
auto *DestroyClone = coro::SwitchCloner::createClone(
1384+
F, ".destroy", Shape, coro::CloneKind::SwitchUnwind, TTI);
1385+
auto *CleanupClone = coro::SwitchCloner::createClone(
1386+
F, ".cleanup", Shape, coro::CloneKind::SwitchCleanup, TTI);
13871387

13881388
postSplitCleanup(*ResumeClone);
13891389
postSplitCleanup(*DestroyClone);
@@ -1772,8 +1772,8 @@ void coro::AsyncABI::splitCoroutine(Function &F, coro::Shape &Shape,
17721772
auto *Suspend = CS;
17731773
auto *Clone = Clones[Idx];
17741774

1775-
CoroCloner::createClone(F, "resume." + Twine(Idx), Shape, Clone, Suspend,
1776-
TTI);
1775+
coro::BaseCloner::createClone(F, "resume." + Twine(Idx), Shape, Clone,
1776+
Suspend, TTI);
17771777
}
17781778
}
17791779

@@ -1903,8 +1903,8 @@ void coro::AnyRetconABI::splitCoroutine(Function &F, coro::Shape &Shape,
19031903
auto Suspend = CS;
19041904
auto Clone = Clones[Idx];
19051905

1906-
CoroCloner::createClone(F, "resume." + Twine(Idx), Shape, Clone, Suspend,
1907-
TTI);
1906+
coro::BaseCloner::createClone(F, "resume." + Twine(Idx), Shape, Clone,
1907+
Suspend, TTI);
19081908
}
19091909
}
19101910

0 commit comments

Comments
 (0)