[PATCH] D58260: [INLINER] allow inlining of blockaddresses if sole uses are callbrs

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 30 12:14:25 PDT 2019


efriedma added a comment.

In D58260#1483021 <https://reviews.llvm.org/D58260#1483021>, @void wrote:

> Right. My point is that it's equivalent to passing a pointer around, except that the pointer cannot be dereferenced anywhere except the originating function. (For the purposes of what Nick's trying to do, "originating function" includes code that's inlined into a function.) As long as IPSCCP and the like don't violate that constraint, passing the pointer around isn't going to cause semantic changes to the program. (A function that tries to jump to a block address that's not within that function is already undefined and still should be.)


Oh, you're saying that if we're inlining a function that contains an indirectbr, but we aren't inlining the indirectbr, we can allow inlining as long as we as the blockaddress still points to the original function.  That's abstractly reasonable, but it probably breaks the Linux kernel's _THIS_IP_ macro (and therefore, I'm guessing, isn't what gcc does).



================
Comment at: llvm/include/llvm/Analysis/LazyCallGraph.h:1094
+              break;
+            }
         if (Visited.insert(BA->getFunction()).second)
----------------
srhines wrote:
> nickdesaulniers wrote:
> > Is there a better way to express `SomeConstant->getFunction()`?  I guess not, since the constant can appear in multiple functions?  Is there a better way to do what I'm trying to do here?
> I don't think there is a much better way to detect this, but BA->getFunction() will always return the same result here, so abstracting that out (e.g. FunctionContainingBlockAddress) would make this more obvious.
> 
> One other (possibly silly) question. Is it possible for a use of a blockaddress to be not contained in an Instruction (i.e. as part of the definition of some other global constant)? I don't think that makes sense in the IR, so perhaps it is forbidden some other way, but I just wanted to double check.
> Is it possible for a use of a blockaddress to be not contained in an Instruction

Yes; C testcase:

```
void f() { static void*p = &&Z; goto *p; Z:return; }
```

------

I'm not sure why we aren't just ignoring blockaddress constants here; they shouldn't really be relevant to the call graph.  You can't get the address of a function from a blockaddress.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D58260





More information about the llvm-commits mailing list