[PATCH] D132084: [Cloning] handle blockaddress array clone in the same module

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 21 22:22:47 PDT 2022


efriedma added a comment.

In D132084#3736593 <https://reviews.llvm.org/D132084#3736593>, @ychen wrote:

> In D132084#3736529 <https://reviews.llvm.org/D132084#3736529>, @efriedma wrote:
>
>> I suspect the special case for "global blockaddress array" won't really trigger in practice; most uses of indirectbr involve the value escaping somehow, because otherwise there isn't really any value over just using a switch.  (I don't think your testcase is representative.)
>
> Could you share a test case that escapes or some example URL, please?  I could not find many by googling `computed gogo`. Probably there are better keywords.

It's really not that frequently used in general; people usually only go for it to squeeze out the last bit of performance out of an interpreter.

Maybe take a look at OCaml: https://github.com/ocaml/ocaml/blob/trunk/runtime/interp.c

>> IndirectBrExpandPass can handle all cases correctly; it's just not efficient, like I mentioned before.  And you probably don't want to do it without the caller explicitly asking for it.
>
> One test case I was thinking of is
>
>   bool doInterpret(Instruction*& nextIntruction, int& out, int x) {
>       static void* dispatch_table[] = {&&inc, &&suspend, &&stop};
>       #define DISPATCH() goto *dispatch_table[*nextIntruction++]
>   
>       if(x%2){ // x==7: store &&suspend, x==9: store &&inc
>          dispatch_table[0] = dispatch_table[x%3];
>          return false;
>       } else {
>          DISPATCH();
>       }
>   
>   inc:
>       ++out;
>       DISPATCH();
>   suspend:
>       return false;
>   stop:
>       return true;
>   }
>
> I don't think and am not sure if this is representative, but I guess it is valid?
>
> If this is cloned even after IndirectBrExpandPass (not necessarily for coroutine, but in general), it may or may not do the right thing depending on how the two instances are called.

The way IndirectBrExpandPass works is that it rewrites away all "blockaddress" constants.  Once the IR no longer contains any "blockaddress", whether or not you clone is irrelevant.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D132084/new/

https://reviews.llvm.org/D132084



More information about the llvm-commits mailing list