Skip to content

Commit 4c59f80

Browse files
committed
Coroutines: Cleanup typed pointer code in CoroFrame.cpp. NFC
1 parent 64c50a6 commit 4c59f80

File tree

1 file changed

+5
-29
lines changed

1 file changed

+5
-29
lines changed

llvm/lib/Transforms/Coroutines/CoroFrame.cpp

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,15 +1682,6 @@ static Instruction *splitBeforeCatchSwitch(CatchSwitchInst *CatchSwitch) {
16821682
return CleanupRet;
16831683
}
16841684

1685-
static void createFramePtr(coro::Shape &Shape) {
1686-
auto *CB = Shape.CoroBegin;
1687-
IRBuilder<> Builder(CB->getNextNode());
1688-
StructType *FrameTy = Shape.FrameTy;
1689-
PointerType *FramePtrTy = FrameTy->getPointerTo();
1690-
Shape.FramePtr =
1691-
cast<Instruction>(Builder.CreateBitCast(CB, FramePtrTy, "FramePtr"));
1692-
}
1693-
16941685
// Replace all alloca and SSA values that are accessed across suspend points
16951686
// with GetElementPointer from coroutine frame + loads and stores. Create an
16961687
// AllocaSpillBB that will become the new entry block for the resume parts of
@@ -1702,7 +1693,6 @@ static void createFramePtr(coro::Shape &Shape) {
17021693
// becomes:
17031694
//
17041695
// %hdl = coro.begin(...)
1705-
// %FramePtr = bitcast i8* hdl to %f.frame*
17061696
// br label %AllocaSpillBB
17071697
//
17081698
// AllocaSpillBB:
@@ -1781,8 +1771,7 @@ static void insertSpills(const FrameDataInfo &FrameData, coro::Shape &Shape) {
17811771
Type *ByValTy = nullptr;
17821772
if (auto *Arg = dyn_cast<Argument>(Def)) {
17831773
// For arguments, we will place the store instruction right after
1784-
// the coroutine frame pointer instruction, i.e. bitcast of
1785-
// coro.begin from i8* to %f.frame*.
1774+
// the coroutine frame pointer instruction, i.e. coro.begin.
17861775
InsertPt = Shape.getInsertPtAfterFramePtr()->getIterator();
17871776

17881777
// If we're spilling an Argument, make sure we clear 'nocapture'
@@ -1987,16 +1976,12 @@ static void insertSpills(const FrameDataInfo &FrameData, coro::Shape &Shape) {
19871976
// to the pointer in the frame.
19881977
for (const auto &Alias : A.Aliases) {
19891978
auto *FramePtr = GetFramePointer(Alloca);
1990-
auto *FramePtrRaw =
1991-
Builder.CreateBitCast(FramePtr, Type::getInt8PtrTy(C));
19921979
auto &Value = *Alias.second;
19931980
auto ITy = IntegerType::get(C, Value.getBitWidth());
1994-
auto *AliasPtr = Builder.CreateGEP(Type::getInt8Ty(C), FramePtrRaw,
1981+
auto *AliasPtr = Builder.CreateGEP(Type::getInt8Ty(C), FramePtr,
19951982
ConstantInt::get(ITy, Value));
1996-
auto *AliasPtrTyped =
1997-
Builder.CreateBitCast(AliasPtr, Alias.first->getType());
19981983
Alias.first->replaceUsesWithIf(
1999-
AliasPtrTyped, [&](Use &U) { return DT.dominates(CB, U); });
1984+
AliasPtr, [&](Use &U) { return DT.dominates(CB, U); });
20001985
}
20011986
}
20021987

@@ -2769,17 +2754,8 @@ static void sinkLifetimeStartMarkers(Function &F, coro::Shape &Shape,
27692754
// Sink lifetime.start markers to dominate block when they are
27702755
// only used outside the region.
27712756
if (Valid && Lifetimes.size() != 0) {
2772-
// May be AI itself, when the type of AI is i8*
2773-
auto *NewBitCast = [&](AllocaInst *AI) -> Value* {
2774-
if (isa<AllocaInst>(Lifetimes[0]->getOperand(1)))
2775-
return AI;
2776-
auto *Int8PtrTy = Type::getInt8PtrTy(F.getContext());
2777-
return CastInst::Create(Instruction::BitCast, AI, Int8PtrTy, "",
2778-
DomBB->getTerminator());
2779-
}(AI);
2780-
27812757
auto *NewLifetime = Lifetimes[0]->clone();
2782-
NewLifetime->replaceUsesOfWith(NewLifetime->getOperand(1), NewBitCast);
2758+
NewLifetime->replaceUsesOfWith(NewLifetime->getOperand(1), AI);
27832759
NewLifetime->insertBefore(DomBB->getTerminator());
27842760

27852761
// All the outsided lifetime.start markers are no longer necessary.
@@ -3121,7 +3097,7 @@ void coro::buildCoroutineFrame(
31213097
Shape.ABI == coro::ABI::Async)
31223098
sinkSpillUsesAfterCoroBegin(F, FrameData, Shape.CoroBegin);
31233099
Shape.FrameTy = buildFrameType(F, Shape, FrameData);
3124-
createFramePtr(Shape);
3100+
Shape.FramePtr = Shape.CoroBegin;
31253101
// For now, this works for C++ programs only.
31263102
buildFrameDebugInfo(F, Shape, FrameData);
31273103
insertSpills(FrameData, Shape);

0 commit comments

Comments
 (0)