RFC: Metadata attachments to function definitions

Date: Tue, 14 Apr 2015 21:33:03 -0700
From: "Duncan P. N. Exon Smith" <dexonsmith@apple.com>
To: LLVM Developers Mailing List <llvmdev@cs.uiuc.edu>
Subject: [LLVMdev] RFC: Metadata attachments to function definitions
Message-ID: <BF4002F0-06DC-4A25-AF84-7D21AD48121A@apple.com>
Content-Type: text/plain; charset=us-ascii

`Function` definitions should support `MDNode` attachments, with a
similar syntax to instructions:

    define void @foo() nounwind !attach !0 {
      unreachable
    }
    !0 = !{}

Attachments wouldn't be allowed on declarations, just definitions.

There are two open problems this can help with:

1. For PGO, we need somewhere to attach the function entry count.
    Attaching to the function definition is a simple solution.

        define void @foo() !prof !0 {
          unreachable
        }
        !0 = !{i32 987}

That will be great. Would it be better if the type is i64? We really want
to avoid an overflow if possible. What is the type for the raw profile
data for region(0)?

Ivan

Date: Tue, 14 Apr 2015 21:33:03 -0700
From: "Duncan P. N. Exon Smith" <dexonsmith@apple.com>
To: LLVM Developers Mailing List <llvmdev@cs.uiuc.edu>
Subject: [LLVMdev] RFC: Metadata attachments to function definitions
Message-ID: <BF4002F0-06DC-4A25-AF84-7D21AD48121A@apple.com>
Content-Type: text/plain; charset=us-ascii

`Function` definitions should support `MDNode` attachments, with a
similar syntax to instructions:

   define void @foo() nounwind !attach !0 {
     unreachable
   }
   !0 = !{}

Attachments wouldn't be allowed on declarations, just definitions.

There are two open problems this can help with:

1. For PGO, we need somewhere to attach the function entry count.
   Attaching to the function definition is a simple solution.

       define void @foo() !prof !0 {
         unreachable
       }
       !0 = !{i32 987}

That will be great. Would it be better if the type is i64? We really want
to avoid an overflow if possible. What is the type for the raw profile
data for region(0)?

Right, of course; `i64` makes more sense for entry counts. BTW, I'm not
volunteering to implement this one myself, just to provide the metadata
infrastructure.

Date: Tue, 14 Apr 2015 21:33:03 -0700
From: "Duncan P. N. Exon Smith" <dexonsmith@apple.com>
To: LLVM Developers Mailing List <llvmdev@cs.uiuc.edu>
Subject: [LLVMdev] RFC: Metadata attachments to function definitions
Message-ID: <BF4002F0-06DC-4A25-AF84-7D21AD48121A@apple.com>
Content-Type: text/plain; charset=us-ascii

`Function` definitions should support `MDNode` attachments, with a
similar syntax to instructions:

   define void @foo() nounwind !attach !0 {
     unreachable
   }
   !0 = !{}

Attachments wouldn't be allowed on declarations, just definitions.

There are two open problems this can help with:

1. For PGO, we need somewhere to attach the function entry count.
   Attaching to the function definition is a simple solution.

       define void @foo() !prof !0 {
         unreachable
       }
       !0 = !{i32 987}

That will be great. Would it be better if the type is i64? We really
want
to avoid an overflow if possible. What is the type for the raw profile
data for region(0)?

Right, of course; `i64` makes more sense for entry counts. BTW, I'm not
volunteering to implement this one myself, just to provide the metadata
infrastructure.

Providing the metadata infrastructure - API for accessing the function
entry count profile metadata - will be more than enough. Thank you for
doing that.

The type in clang/lib/CodeGen/CodeGenPGO.h is a 64 bit:
  uint64_t getRegionCount(unsigned Counter)

Ivan

Since I need to add this, I'll put it on my todo list.

Diego.

Already clarified over IRC, but FTR: I *will* implement metadata attachments
to functions, but likely won't be doing the work to use them for PGO.

Sure. SGTM.

Diego.