r351629 - Emit !callback metadata and introduce the callback attribute

Doerfert, Johannes Rudolf via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 22 09:28:30 PST 2019


On 01/22, Chandler Carruth wrote:
> On Sat, Jan 19, 2019 at 2:18 AM Johannes Doerfert via cfe-commits <
> cfe-commits at lists.llvm.org> wrote:
> 
> > Author: jdoerfert
> > Date: Fri Jan 18 21:36:54 2019
> > New Revision: 351629
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=351629&view=rev
> > Log:
> > Emit !callback metadata and introduce the callback attribute
> >
> >   With commit r351627, LLVM gained the ability to apply (existing) IPO
> >   optimizations on indirections through callbacks, or transitive calls.
> >   The general idea is that we use an abstraction to hide the middle man
> >   and represent the callback call in the context of the initial caller.
> >   It is described in more detail in the commit message of the LLVM patch
> >   r351627, the llvm::AbstractCallSite class description, and the
> >   language reference section on callback-metadata.
> >
> >   This commit enables clang to emit !callback metadata that is
> >   understood by LLVM. It does so in three different cases:
> >     1) For known broker functions declarations that are directly
> >        generated, e.g., __kmpc_fork_call for the OpenMP pragma parallel.
> >     2) For known broker functions that are identified by their name and
> >        source location through the builtin detection, e.g.,
> >        pthread_create from the POSIX thread API.
> >     3) For user annotated functions that carry the "callback(callee, ...)"
> >        attribute. The attribute has to include the name, or index, of
> >        the callback callee and how the passed arguments can be
> >        identified (as many as the callback callee has). See the callback
> >        attribute documentation for detailed information.
> >
> > Differential Revision: https://reviews.llvm.org/D55483
> >
> > ==============================================================================
> > --- cfe/trunk/test/CodeGen/callback_pthread_create.c (added)
> > +++ cfe/trunk/test/CodeGen/callback_pthread_create.c Fri Jan 18 21:36:54
> > 2019
> > @@ -0,0 +1,32 @@
> > +// RUN: %clang -O1 %s -S -c -emit-llvm -o - | FileCheck %s
> > +// RUN: %clang -O1 %s -S -c -emit-llvm -o - | opt -ipconstprop -S |
> > FileCheck --check-prefix=IPCP %s
> > +
> > +// CHECK: declare !callback ![[cid:[0-9]+]] dso_local i32 @pthread_create
> > +// CHECK: ![[cid]] = !{![[cidb:[0-9]+]]}
> > +// CHECK: ![[cidb]] = !{i64 2, i64 3, i1 false}
> > +
> > +#include <pthread.h>
> 
> 
> Another thing I notecide is that this code assumes the system has
> `pthread.h` -- what about systems without it? I mean, you can disable the
> test, but it seems bad to lose test coverage just because of that.
 
So far, I disabled the test with a later addition which makes sure this
test is only run under Linux. I'm unsure why we loose coverage because
of that?

> I would much prefer that you provide your own stub `pthread.h` in the
> Inputs/... tree of the test suite and use that to test this in a portable
> way.

I do not completely follow but I'm open to improving the test. Basically
I have to make sure the builtin recognition will trigger on the header
file and the contained declaration. If we can somehow do this in a
portable way I'm all for it. Is that how we test other builtin gnu extensions?

Cheers,
  Johannes


> > +
> > +const int GlobalVar = 0;
> > +
> > +static void *callee0(void *payload) {
> > +// IPCP:      define internal i8* @callee0
> > +// IPCP-NEXT:   entry:
> > +// IPCP-NEXT:     ret i8* null
> > +  return payload;
> > +}
> > +
> > +static void *callee1(void *payload) {
> > +// IPCP:      define internal i8* @callee1
> > +// IPCP-NEXT:   entry:
> > +// IPCP-NEXT:     ret i8* bitcast (i32* @GlobalVar to i8*)
> > +  return payload;
> > +}
> > +
> > +void foo() {
> > +  pthread_t MyFirstThread;
> > +  pthread_create(&MyFirstThread, NULL, callee0, NULL);
> > +
> > +  pthread_t MySecondThread;
> > +  pthread_create(&MySecondThread, NULL, callee1, (void *)&GlobalVar);
> > +}
> >
> > Added: cfe/trunk/test/CodeGenCXX/attr-callback.cpp
> > URL:
> > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/attr-callback.cpp?rev=351629&view=auto
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190122/c01969d7/attachment-0001.sig>


More information about the cfe-commits mailing list