[PATCH] D63312: [Attributor] Deduce attributes for non-exact functions

Johannes Doerfert via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 13 19:04:34 PDT 2019


jdoerfert created this revision.
jdoerfert added reviewers: uenoku, sstefan1, homerdin, hfinkel, fedor.sergeev, chandlerc, nlopes, nicholas, arsenm, reames.
Herald added subscribers: bollu, hiraditya, wdng.
Herald added a project: LLVM.

In the LLVM test suite and SPEC2006, ~67% of all function declarations
are non-exact, thus they can be replaced at link-time. While we cannot
generally use them to perform inter-procedural (IP) reasoning, it is
allowed to "internalize" them first and derive IP information
afterwards. In fact, we can use the information we derived assuming they
have exact definitions to reason if internalization might be beneficial.

This patch allows the Attributor to employ shallow wrappers, the
cheapest internalization method I could think of. A shallow wrapper is a
function with the same type (and attributes) as the original one. Inside
the wrapper there is only call to the original one and a return of the
result. The scheme is shown below:

Assuming the declaration of looks like:

  rty F(aty0 arg0, ..., atyN argN);

The wrapper will then look as follows:

  rty wrapper(aty0 arg0, ..., atyN argN) {
    return F(arg0, ..., argN);
  }

Once the wrapper was created we can change the linkage type of the
original function to internal which allows us to use it for recursive
reasoning. We can also manifest the results, e.g., annotate the
arguments with attributes.

Shallow wrappers are cheap because the new internal function has a
single call site. This likely means we inline them later which results
in "similar" code as we started out with except that passes in-between
the Attributor and the inliner can use the annotated information.

A separate patch will introduce deep wrappers that replace the known
uses of the function with the internalized version. Afterwards, we need
to work on a cost heuristic. I will also see if we can disable inlining
for "wrapper-like" functions and post my findings on the list.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63312

Files:
  llvm/include/llvm/Transforms/IPO/Attributor.h
  llvm/lib/Transforms/IPO/Attributor.cpp
  llvm/test/Transforms/FunctionAttrs/arg_returned.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63312.204686.patch
Type: text/x-patch
Size: 13516 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190614/d6fa817c/attachment.bin>


More information about the llvm-commits mailing list