Skip to content

Commit

Permalink
transform (coroutines): move any misplaced entry-block allocas to the…
Browse files Browse the repository at this point in the history
… start of the entry block before lowering
  • Loading branch information
niaow authored and aykevl committed Sep 21, 2021
1 parent ecd8c2d commit 1573826
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions transform/coroutines.go
Expand Up @@ -763,6 +763,27 @@ func (c *coroutineLoweringPass) lowerCallReturn(caller *asyncFunc, call llvm.Val
// lowerFuncCoro transforms an async function into a coroutine by lowering async operations to `llvm.coro` intrinsics.
// See https://llvm.org/docs/Coroutines.html for more information on these intrinsics.
func (c *coroutineLoweringPass) lowerFuncCoro(fn *asyncFunc) {
// Ensure that any alloca instructions in the entry block are at the start.
// Otherwise, block splitting would result in unintended behavior.
{
// Skip alloca instructions at the start of the block.
inst := fn.fn.FirstBasicBlock().FirstInstruction()
for !inst.IsAAllocaInst().IsNil() {
inst = llvm.NextInstruction(inst)
}

// Find any other alloca instructions and move them after the other allocas.
c.builder.SetInsertPointBefore(inst)
for !inst.IsNil() {
next := llvm.NextInstruction(inst)
if !inst.IsAAllocaInst().IsNil() {
inst.RemoveFromParentAsInstruction()
c.builder.Insert(inst)
}
inst = next
}
}

returnType := fn.fn.Type().ElementType().ReturnType()

// Prepare coroutine state.
Expand Down

0 comments on commit 1573826

Please sign in to comment.