[llvm] Coroutines: Cleanup typed pointer code in CoroFrame.cpp (PR #67141)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 22 07:05:43 PDT 2023
https://github.com/ruiling created https://github.com/llvm/llvm-project/pull/67141
None
>From 6e50e873027c663cc01c3a8538981a12db7ba941 Mon Sep 17 00:00:00 2001
From: Ruiling Song <ruiling.song at amd.com>
Date: Fri, 22 Sep 2023 22:00:29 +0800
Subject: [PATCH] Coroutines: Cleanup typed pointer code in CoroFrame.cpp
---
llvm/lib/Transforms/Coroutines/CoroFrame.cpp | 34 +++-----------------
1 file changed, 5 insertions(+), 29 deletions(-)
diff --git a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp
index 40b0650deda51e1..d6e5c6c03e5ff34 100644
--- a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp
+++ b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp
@@ -1682,15 +1682,6 @@ static Instruction *splitBeforeCatchSwitch(CatchSwitchInst *CatchSwitch) {
return CleanupRet;
}
-static void createFramePtr(coro::Shape &Shape) {
- auto *CB = Shape.CoroBegin;
- IRBuilder<> Builder(CB->getNextNode());
- StructType *FrameTy = Shape.FrameTy;
- PointerType *FramePtrTy = FrameTy->getPointerTo();
- Shape.FramePtr =
- cast<Instruction>(Builder.CreateBitCast(CB, FramePtrTy, "FramePtr"));
-}
-
// Replace all alloca and SSA values that are accessed across suspend points
// with GetElementPointer from coroutine frame + loads and stores. Create an
// AllocaSpillBB that will become the new entry block for the resume parts of
@@ -1702,7 +1693,6 @@ static void createFramePtr(coro::Shape &Shape) {
// becomes:
//
// %hdl = coro.begin(...)
-// %FramePtr = bitcast i8* hdl to %f.frame*
// br label %AllocaSpillBB
//
// AllocaSpillBB:
@@ -1781,8 +1771,7 @@ static void insertSpills(const FrameDataInfo &FrameData, coro::Shape &Shape) {
Type *ByValTy = nullptr;
if (auto *Arg = dyn_cast<Argument>(Def)) {
// For arguments, we will place the store instruction right after
- // the coroutine frame pointer instruction, i.e. bitcast of
- // coro.begin from i8* to %f.frame*.
+ // the coroutine frame pointer instruction, i.e. coro.begin.
InsertPt = Shape.getInsertPtAfterFramePtr()->getIterator();
// If we're spilling an Argument, make sure we clear 'nocapture'
@@ -1987,16 +1976,12 @@ static void insertSpills(const FrameDataInfo &FrameData, coro::Shape &Shape) {
// to the pointer in the frame.
for (const auto &Alias : A.Aliases) {
auto *FramePtr = GetFramePointer(Alloca);
- auto *FramePtrRaw =
- Builder.CreateBitCast(FramePtr, Type::getInt8PtrTy(C));
auto &Value = *Alias.second;
auto ITy = IntegerType::get(C, Value.getBitWidth());
- auto *AliasPtr = Builder.CreateGEP(Type::getInt8Ty(C), FramePtrRaw,
+ auto *AliasPtr = Builder.CreateGEP(Type::getInt8Ty(C), FramePtr,
ConstantInt::get(ITy, Value));
- auto *AliasPtrTyped =
- Builder.CreateBitCast(AliasPtr, Alias.first->getType());
Alias.first->replaceUsesWithIf(
- AliasPtrTyped, [&](Use &U) { return DT.dominates(CB, U); });
+ AliasPtr, [&](Use &U) { return DT.dominates(CB, U); });
}
}
@@ -2769,17 +2754,8 @@ static void sinkLifetimeStartMarkers(Function &F, coro::Shape &Shape,
// Sink lifetime.start markers to dominate block when they are
// only used outside the region.
if (Valid && Lifetimes.size() != 0) {
- // May be AI itself, when the type of AI is i8*
- auto *NewBitCast = [&](AllocaInst *AI) -> Value* {
- if (isa<AllocaInst>(Lifetimes[0]->getOperand(1)))
- return AI;
- auto *Int8PtrTy = Type::getInt8PtrTy(F.getContext());
- return CastInst::Create(Instruction::BitCast, AI, Int8PtrTy, "",
- DomBB->getTerminator());
- }(AI);
-
auto *NewLifetime = Lifetimes[0]->clone();
- NewLifetime->replaceUsesOfWith(NewLifetime->getOperand(1), NewBitCast);
+ NewLifetime->replaceUsesOfWith(NewLifetime->getOperand(1), AI);
NewLifetime->insertBefore(DomBB->getTerminator());
// All the outsided lifetime.start markers are no longer necessary.
@@ -3122,7 +3098,7 @@ void coro::buildCoroutineFrame(
Shape.ABI == coro::ABI::Async)
sinkSpillUsesAfterCoroBegin(F, FrameData, Shape.CoroBegin);
Shape.FrameTy = buildFrameType(F, Shape, FrameData);
- createFramePtr(Shape);
+ Shape.FramePtr = Shape.CoroBegin;
// For now, this works for C++ programs only.
buildFrameDebugInfo(F, Shape, FrameData);
insertSpills(FrameData, Shape);
More information about the llvm-commits
mailing list