Skip to content

Commit 52a918e

Browse files
committed
revert back to using the metadata
1 parent acb4146 commit 52a918e

File tree

13 files changed

+22
-139
lines changed

13 files changed

+22
-139
lines changed

clang/lib/CodeGen/CGCoroutine.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,8 @@ struct GetReturnObjectManager {
709709
auto *GroAlloca = dyn_cast_or_null<llvm::AllocaInst>(
710710
GroEmission.getOriginalAllocatedAddress().getPointer());
711711
assert(GroAlloca && "expected alloca to be emitted");
712-
Builder.CreateCall(CGF.CGM.getIntrinsic(llvm::Intrinsic::coro_outside_frame), {GroAlloca});
712+
GroAlloca->setMetadata(llvm::LLVMContext::MD_coro_outside_frame,
713+
llvm::MDNode::get(CGF.CGM.getLLVMContext(), {}));
713714

714715
// Remember the top of EHStack before emitting the cleanup.
715716
auto old_top = CGF.EHStack.stable_begin();
@@ -858,8 +859,10 @@ void CodeGenFunction::EmitCoroutineBody(const CoroutineBodyStmt &S) {
858859
// If the original param is in an alloca, exclude it from the coroutine
859860
// frame. The parameter copy will be part of the frame.
860861
Address ParmAddr = GetAddrOfLocalVar(Parm);
861-
if (auto *ParmAlloca = dyn_cast<llvm::AllocaInst>(ParmAddr.getBasePointer())) {
862-
Builder.CreateCall(CGM.getIntrinsic(llvm::Intrinsic::coro_outside_frame), {ParmAlloca});
862+
if (auto *ParmAlloca =
863+
dyn_cast<llvm::AllocaInst>(ParmAddr.getBasePointer())) {
864+
ParmAlloca->setMetadata(llvm::LLVMContext::MD_coro_outside_frame,
865+
llvm::MDNode::get(CGM.getLLVMContext(), {}));
863866
}
864867
}
865868
for (auto *PM : S.getParamMoves()) {

clang/test/CodeGenCoroutines/coro-gro.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,11 @@ void doSomething() noexcept;
3030
int f() {
3131
// CHECK: %[[RetVal:.+]] = alloca i32
3232
// CHECK: %[[GroActive:.+]] = alloca i1
33-
// CHECK: %[[CoroGro:.+]] = alloca %struct.GroType
33+
// CHECK: %[[CoroGro:.+]] = alloca %struct.GroType, {{.*}} !coro.outside.frame ![[OutFrameMetadata:.+]]
3434

3535
// CHECK: %[[Size:.+]] = call i64 @llvm.coro.size.i64()
3636
// CHECK: call noalias noundef nonnull ptr @_Znwm(i64 noundef %[[Size]])
3737
// CHECK: store i1 false, ptr %[[GroActive]]
38-
// CHECK: call void @llvm.coro.outside.frame(ptr %[[CoroGro]])
3938
// CHECK: call void @_ZNSt16coroutine_traitsIiJEE12promise_typeC1Ev(
4039
// CHECK: call void @_ZNSt16coroutine_traitsIiJEE12promise_type17get_return_objectEv({{.*}} %[[CoroGro]]
4140
// CHECK: store i1 true, ptr %[[GroActive]]
@@ -107,3 +106,4 @@ invoker g() {
107106
// CHECK: call void @_ZN7invoker15invoker_promise17get_return_objectEv({{.*}} %[[AggRes]]
108107
co_return;
109108
}
109+
// CHECK: ![[OutFrameMetadata]] = !{}

clang/test/CodeGenCoroutines/coro-params.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ void consume(int,int,int,int) noexcept;
7272
// CHECK: define{{.*}} void @_Z1fi8MoveOnly11MoveAndCopy10TrivialABI(i32 noundef %val, ptr noundef %[[MoParam:.+]], ptr noundef %[[McParam:.+]], i32 %[[TrivialParam:.+]]) #0 personality ptr @__gxx_personality_v0
7373
void f(int val, MoveOnly moParam, MoveAndCopy mcParam, TrivialABI trivialParam) {
7474
// CHECK: %[[TrivialAlloca:.+]] = alloca %struct.TrivialABI,
75+
// CHECK-SAME: !coro.outside.frame
7576
// CHECK: %[[MoCopy:.+]] = alloca %struct.MoveOnly,
7677
// CHECK: %[[McCopy:.+]] = alloca %struct.MoveAndCopy,
7778
// CHECK: %[[TrivialCopy:.+]] = alloca %struct.TrivialABI,
7879
// CHECK: store i32 %val, ptr %[[ValAddr:.+]]
7980

8081
// CHECK: call ptr @llvm.coro.begin(
81-
// CHECK: @llvm.coro.outside.frame(ptr %[[TrivialAlloca]])
8282
// CHECK: call void @_ZN8MoveOnlyC1EOS_(ptr {{[^,]*}} %[[MoCopy]], ptr noundef nonnull align 4 dereferenceable(4) %[[MoParam]])
8383
// CHECK-NEXT: call void @llvm.lifetime.start.p0(
8484
// CHECK-NEXT: call void @_ZN11MoveAndCopyC1EOS_(ptr {{[^,]*}} %[[McCopy]], ptr noundef nonnull align 4 dereferenceable(4) %[[McParam]]) #
@@ -226,11 +226,12 @@ void consume(int) noexcept;
226226
// may be destroyed before the destructor call.
227227
void msabi(MSParm p) {
228228
// MSABI: define{{.*}} void @"?msabi@@YAXUMSParm@@@Z"(i32 %[[Param:.+]])
229-
// MSABI: %[[ParamAlloca:.+]] = alloca %struct.MSParm
230-
// MSABI: %[[ParamCopy:.+]] = alloca %struct.MSParm
231229

232230
// The parameter's local alloca is marked not part of the frame.
233-
// MSABI: call void @llvm.coro.outside.frame(ptr %[[ParamAlloca]])
231+
// MSABI: %[[ParamAlloca:.+]] = alloca %struct.MSParm
232+
// MSABI-SAME: !coro.outside.frame
233+
234+
// MSABI: %[[ParamCopy:.+]] = alloca %struct.MSParm
234235

235236
consume(p.val);
236237
// The parameter's copy is used by the coroutine.

llvm/docs/Coroutines.rst

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,30 +1641,6 @@ the function call.
16411641
ptr %ctxt, ptr %task, ptr %actor)
16421642
unreachable
16431643
1644-
1645-
.. _coro.outside.frame:
1646-
1647-
'llvm.coro.outside.frame' Intrinsic
1648-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1649-
::
1650-
1651-
declare void @llvm.coro.outside.frame(ptr %p)
1652-
1653-
Overview:
1654-
"""""""""
1655-
1656-
TODO
1657-
1658-
Arguments:
1659-
""""""""""
1660-
1661-
TODO
1662-
1663-
Semantics:
1664-
""""""""""
1665-
1666-
TODO
1667-
16681644
.. _coro.suspend:
16691645
.. _suspend points:
16701646

@@ -2209,7 +2185,6 @@ Metadata
22092185
'``coro.outside.frame``' Metadata
22102186
---------------------------------
22112187

2212-
TODO: Deprecate/remove
22132188
``coro.outside.frame`` metadata may be attached to an alloca instruction to
22142189
to signify that it shouldn't be promoted to the coroutine frame, useful for
22152190
filtering allocas out by the frontend when emitting internal control mechanisms.

llvm/include/llvm/IR/Intrinsics.td

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,8 +1778,6 @@ def int_coro_alloca_alloc : Intrinsic<[llvm_token_ty],
17781778
[llvm_anyint_ty, llvm_i32_ty], []>;
17791779
def int_coro_alloca_get : Intrinsic<[llvm_ptr_ty], [llvm_token_ty], []>;
17801780
def int_coro_alloca_free : Intrinsic<[], [llvm_token_ty], []>;
1781-
def int_coro_outside_frame : Intrinsic<[], [llvm_ptr_ty],
1782-
[IntrNoMem, NoCapture<ArgIndex<0>>]>;
17831781

17841782
// Coroutine Manipulation Intrinsics.
17851783

llvm/include/llvm/Transforms/Coroutines/CoroInstr.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -796,22 +796,6 @@ class CoroAllocaFreeInst : public IntrinsicInst {
796796
}
797797
};
798798

799-
/// This represents the llvm.coro.outside.frame instruction.
800-
class CoroOutsideFrameInst : public IntrinsicInst {
801-
enum { PtrArg };
802-
803-
public:
804-
Value *getPtr() const { return getArgOperand(PtrArg); } // XXX: Could we require it to be an alloca?
805-
806-
// Methods to support type inquiry through isa, cast, and dyn_cast:
807-
static bool classof(const IntrinsicInst *I) {
808-
return I->getIntrinsicID() == Intrinsic::coro_outside_frame;
809-
}
810-
static bool classof(const Value *V) {
811-
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
812-
}
813-
};
814-
815799
} // End namespace llvm.
816800

817801
#endif // LLVM_TRANSFORMS_COROUTINES_COROINSTR_H

llvm/include/llvm/Transforms/Coroutines/CoroShape.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ struct Shape {
5757
SmallVector<AnyCoroSuspendInst *, 4> CoroSuspends;
5858
SmallVector<CoroAwaitSuspendInst *, 4> CoroAwaitSuspends;
5959
SmallVector<CallInst *, 2> SymmetricTransfers;
60-
SmallVector<CoroOutsideFrameInst *, 8> OutsideFrames;
6160

6261
// Values invalidated by replaceSwiftErrorOps()
6362
SmallVector<CallInst *, 2> SwiftErrorOps;
@@ -70,7 +69,6 @@ struct Shape {
7069
CoroSuspends.clear();
7170
CoroAwaitSuspends.clear();
7271
SymmetricTransfers.clear();
73-
OutsideFrames.clear();
7472

7573
SwiftErrorOps.clear();
7674

llvm/lib/Transforms/Coroutines/CoroSplit.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2015,13 +2015,7 @@ static void doSplitCoroutine(Function &F, SmallVectorImpl<Function *> &Clones,
20152015
simplifySuspendPoints(Shape);
20162016

20172017
normalizeCoroutine(F, Shape, TTI);
2018-
20192018
ABI.buildCoroutineFrame(OptimizeFrame);
2020-
2021-
// @llvm.coro.outside.frame no longer needed after the frame has been built.
2022-
for (Instruction *I : Shape.OutsideFrames)
2023-
I->eraseFromParent();
2024-
20252019
replaceFrameSizeAndAlignment(Shape);
20262020

20272021
bool isNoSuspendCoroutine = Shape.CoroSuspends.empty();

llvm/lib/Transforms/Coroutines/Coroutines.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,6 @@ void coro::Shape::analyze(Function &F,
286286
}
287287
}
288288
break;
289-
case Intrinsic::coro_outside_frame:
290-
OutsideFrames.push_back(cast<CoroOutsideFrameInst>(II));
291-
break;
292289
}
293290
}
294291
}

llvm/lib/Transforms/Coroutines/SpillUtils.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -426,17 +426,11 @@ static void collectFrameAlloca(AllocaInst *AI, const coro::Shape &Shape,
426426
if (AI == Shape.SwitchLowering.PromiseAlloca)
427427
return;
428428

429-
// TODO: Deprecate/remove.
430429
// The __coro_gro alloca should outlive the promise, make sure we
431430
// keep it outside the frame.
432431
if (AI->hasMetadata(LLVMContext::MD_coro_outside_frame))
433432
return;
434433

435-
for (const CoroOutsideFrameInst *I : Shape.OutsideFrames) {
436-
if (I->getPtr() == AI)
437-
return;
438-
}
439-
440434
// The code that uses lifetime.start intrinsic does not work for functions
441435
// with loops without exit. Disable it on ABIs we know to generate such
442436
// code.

0 commit comments

Comments
 (0)