Skip to content

Commit 0ca612e

Browse files
committed
added alignment to coro_init, coro_size now returns size_t
1 parent a2bad2e commit 0ca612e

File tree

4 files changed

+26
-17
lines changed

4 files changed

+26
-17
lines changed

include/llvm/IR/Intrinsics.td

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,10 +587,12 @@ def int_experimental_gc_relocate : Intrinsic<[llvm_any_ty],
587587
//===------------------------ Coroutine Intrinsics ---------------===//
588588
// These are documented in docs/Coroutines.rst
589589

590-
def int_experimental_coro_init : Intrinsic<[llvm_ptr_ty], [llvm_ptr_ty, llvm_ptr_ty, llvm_ptr_ty], []>;
590+
def int_experimental_coro_init : Intrinsic<[llvm_ptr_ty],
591+
[llvm_ptr_ty, llvm_i32_ty,
592+
llvm_ptr_ty, llvm_ptr_ty], []>;
591593
def int_experimental_coro_fork : Intrinsic<[llvm_i1_ty], [], []>;
592594
def int_experimental_coro_frame : Intrinsic<[llvm_ptr_ty], [], []>;
593-
def int_experimental_coro_size : Intrinsic<[llvm_i32_ty], [], [IntrNoMem]>;
595+
def int_experimental_coro_size : Intrinsic<[llvm_anyint_ty], [], [IntrNoMem]>;
594596

595597
def int_experimental_coro_resume_end : Intrinsic<[], [], []>;
596598
def int_experimental_coro_elide : Intrinsic<[llvm_ptr_ty], [], []>;

lib/Transforms/Coroutines/CoroSplit.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -494,23 +494,16 @@ struct CoroSplit4 : CoroutineCommon {
494494
}
495495

496496
static AllocaInst* getPromiseAlloca(IntrinsicInst* CoroInit, CoroutineCommon* CC) {
497-
auto PromiseAlloca = CoroInit->getArgOperand(1);
497+
auto PromiseAlloca = CoroInit->getArgOperand(2);
498498
if (isa<ConstantPointerNull>(PromiseAlloca))
499499
return nullptr;
500500

501501
// replace the promise arg to coro.init with null
502502
// otherwise, we will end up with use before def once we replace
503503
// allocas with gep instructions relative to coroutine frame which is
504504
// the result of coro.init call
505-
CoroInit->setArgOperand(1, ConstantPointerNull::get(CC->bytePtrTy));
506-
507-
if (auto BI = dyn_cast<BitCastInst>(PromiseAlloca)) {
508-
PromiseAlloca = BI->getOperand(0);
509-
}
510-
else if (auto GEP = dyn_cast<GetElementPtrInst>(PromiseAlloca)) {
511-
assert(GEP->hasAllZeroIndices() && "expecting GEP equivalent of BitCast");
512-
PromiseAlloca = GEP->getOperand(0);
513-
}
505+
CoroInit->setArgOperand(2, ConstantPointerNull::get(CC->bytePtrTy));
506+
PromiseAlloca = PromiseAlloca->stripPointerCasts();
514507
return cast<AllocaInst>(PromiseAlloca);
515508
}
516509

@@ -634,8 +627,9 @@ struct CoroSplit4 : CoroutineCommon {
634627
}
635628
CD->FrameTy->setBody(typeArray);
636629

637-
APInt size(32, DL.getTypeAllocSize(CD->FrameTy));
638-
ReplaceIntrinsicWith(*ThisFunction, Intrinsic::experimental_coro_size, ConstantInt::get(int32Ty, size));
630+
ReplaceIntrinsicWithIntConstant(
631+
*ThisFunction, Intrinsic::experimental_coro_size,
632+
DL.getTypeAllocSize(CD->FrameTy));
639633
}
640634

641635
SmallString<16> Scratch;

lib/Transforms/Coroutines/CoroutineCommon.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,24 @@ void llvm::CoroutineCommon::MoveInReverseOrder(InstrSetVector const &Instrs,
170170
}
171171
}
172172

173-
void CoroutineCommon::ReplaceIntrinsicWith(Function &func, Intrinsic::ID id, Value *framePtr) {
173+
void CoroutineCommon::ReplaceIntrinsicWithIntConstant(Function &func, Intrinsic::ID id, unsigned int Val) {
174174
for (auto it = inst_begin(func), end = inst_end(func); it != end;) {
175175
Instruction& I = *it++;
176176
if (IntrinsicInst* intrin = dyn_cast<IntrinsicInst>(&I))
177177
if (intrin->getIntrinsicID() == id) {
178-
intrin->replaceAllUsesWith(framePtr);
178+
auto V = ConstantInt::get(intrin->getType(), Val);
179+
intrin->replaceAllUsesWith(V);
180+
intrin->eraseFromParent();
181+
}
182+
}
183+
}
184+
185+
void CoroutineCommon::ReplaceIntrinsicWith(Function &func, Intrinsic::ID id, Value *V) {
186+
for (auto it = inst_begin(func), end = inst_end(func); it != end;) {
187+
Instruction& I = *it++;
188+
if (IntrinsicInst* intrin = dyn_cast<IntrinsicInst>(&I))
189+
if (intrin->getIntrinsicID() == id) {
190+
intrin->replaceAllUsesWith(V);
179191
intrin->eraseFromParent();
180192
}
181193
}

lib/Transforms/Coroutines/CoroutineCommon.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ struct LLVM_LIBRARY_VISIBILITY CoroutineCommon {
9696
static void MoveInReverseOrder(InstrSetVector const &Instrs,
9797
Instruction *InsertBefore);
9898

99-
static void ReplaceIntrinsicWith(Function &func, Intrinsic::ID id, Value *framePtr);
99+
static void ReplaceIntrinsicWith(Function &F, Intrinsic::ID id, Value *framePtr);
100+
static void ReplaceIntrinsicWithIntConstant(Function &F, Intrinsic::ID id, unsigned int Val);
100101

101102
void ReplaceCoroDone(IntrinsicInst *intrin);
102103

0 commit comments

Comments
 (0)