[RFC] Adding CPS call support

It does look similar to LLVM Coroutines. I was considering adding a few more intrinsics to support CPS case, but, decided to defer until we have use cases and people willing to do the work J.

Coroutine passes chop up the function into smaller pieces at suspend points, a CPS call can be represented as a suspend point.

Currently a suspend point looks like this:

%sp1 = call token @llvm.coro.save()

; if this is a call, it will be replaced with tail call where calling convention allows

call i8 @llvm.coro.suspend(token %sp1) ;

Two extra intrinsics I was considering were:

%addr = i8* @llvm.resume.addr(tok) ; gives an address of an extracted continuation function.

@llvm.resume.value.(tok) ; gives a return value on resume

Int foo() {

PartA…

Int r = bar(args);

PartB …

}

It can get represented as:

Int foo() {

PartA

%sp1 = call token %llvm.coro.save()

%resume_addr = call @llvm.coro.resume.addr(%sp1)

call bar(args, %resume_addr)

call @llvm.coro.suspend(%sp1)

%r = call %llvm.coro.resume.value(%sp1)

PartB

}

Coroutine passes after foo() is optimized will extract the continuation into a separate function:

foo$resume1(int r) {

PartB

}

And suspend point will be replaced with a jump to bar()