[PATCH] D54498: AbstractCallSite -- A unified interface for (in)direct and callback calls
Johannes Doerfert via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 14 10:13:57 PST 2018
jdoerfert added a comment.
In https://reviews.llvm.org/D54498#1298715, @bollu wrote:
> I have a question in the context of optimising sequential programs -- I'm interested in optimising across a trampoline call, since I have a haskell-like lazy language, which lowers CPS into LLVM-IR by constructing a trampoline. Example IR here <https://gist.github.com/bollu/8834682e5970550afcd6a0c991777fe1#file-ackermann-ll-L220>
>
> Would the `AbstractCallSite` representation allow one to represent the control flow between:
>
> trampoline -> fn1 -> trampoline -> fn2 -> ...
>
Sure, especially if the front-end provides the information, e.g., in form of metadata. I already use these abstract call sites to bridge more than one
function. Take pthreads for example. Since the interface is fixed (a single void * is passed), we cannot simply run argument promotion to expose the
actual passed values directly. Instead, I have a pass that introduces even more functions which are then bridged through an abstract call site. Thus,
we start with
bar(void *S) {
// body
}
foo() {
pthread_create(bar, S);
}
and transform it to
__entry_bar(void (void*) __unused__, void *S) {
pthread_create(bar, S);
}
bar(void *S) {
__body_bar(S);
}
__body_bar(void *S) {
// body
}
foo() {
__entry_bar(__body_bar, S);
}
Afterwards, the abstract call is used to model `__entry_bar -> __body_bar` inside of `foo`, with the pass through argument `S`. Note that the code is **actually valid** LLVM-IR and that we can now use argument promotion to
expand the struct and make the parameter/argument connection explicit for other passes, e.g., constant propagation.
I hope this makes sense and helps you a bit.
> And could this infrastructure help implement a pass that would resolve these custom stack pushes and pops?
That is a good question which I cannot answer for sure right now. I guess it could be useful, if the front-end provides enough information.
Repository:
rL LLVM
https://reviews.llvm.org/D54498
More information about the llvm-commits
mailing list