Page MenuHomePhabricator

Add function entry count metadata.
ClosedPublic

Authored by dnovillo on May 8 2015, 4:04 PM.

Details

Summary

This adds three Function methods to handle function entry counts:
setEntryCount(), hasEntryCount() and getEntryCount().

Entry counts are stored under the MD_prof metadata node with the name
"function_entry_count". They are unsigned 64 bit values set by profilers
(instrumentation and sample profiler changes coming up).

I had some internal debate about what to return when
Function::getEntryCount() is called without the function having its
metadata set. I don't want to return a special sentinel value, because
those are typically problematic down the road.

So, I added a Function::hasEntryCount() predicate. If
Function::getEntryCount() is called with no metadata present, it will
cause a compiler assertion.

Diff Detail

Repository
rL LLVM

Event Timeline

dnovillo updated this revision to Diff 25380.May 8 2015, 4:04 PM
dnovillo retitled this revision from to Add function entry count metadata..
dnovillo updated this object.
dnovillo edited the test plan for this revision. (Show Details)
dnovillo added reviewers: dexonsmith, bogner.
dnovillo added a subscriber: Unknown Object (MLST).
dnovillo updated this revision to Diff 25390.May 8 2015, 4:39 PM

Return Optional<uint64_t> from getEntryCount to indicate whether a count is available.

I'm getting several odd failures in the testsuite. Even though the new code
is only called from the unittest, I'm getting several related failures.
For example,

bin/opt -S test/Verifier/statepoint.ll -verify

Exit Code: 2

Command Output (stderr):

gc.statepoint mismatch in number of vararg call args

%safepoint_token = call i32 (void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(void ()* undef, i32 0, i32 0, i32 0, i32 5, i32 0, i32 0, i32 0, i32 10, i32 0, i8 addrspace(1)* %arg, i64 addrspace(1)* %cast, i8 addrspace(1)* %arg, i8 addrspace(1)* %arg)

gc.statepoint mismatch in number of vararg call args

%safepoint_token = call i32 (void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(void ()* undef, i32 0, i32 0, i32 0, i32 5, i32 0, i32 0, i32 0, i32 10, i32 0, i8 addrspace(1)* %arg, i64 addrspace(1)* %cast, i8 addrspace(1)* %arg, i8 addrspace(1)* %arg)

gc.statepoint mismatch in number of vararg call args

%0 = invoke i32 (void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(void ()* undef, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0, i8 addrspace(1)* %obj, i8 addrspace(1)* %obj1)
        to label %normal_dest unwind label %exceptional_return

It seems related to metadata, but I'm not sure how my patch could've triggered
this. Am I missing anything obvious?

Thanks.

dnovillo updated this revision to Diff 25488.May 11 2015, 11:50 AM

This update includes the following changes:

  • Return Optional<uint64_t> from getEntryCount to indicate whether a count is available.
  • Move setEntrycount() and getEntryCount() to lib/IR/Function.cpp.
  • Remove @brief from comments.
  • Add IR verification to !prof nodes and tests.
reames added a subscriber: reames.May 12 2015, 2:53 PM

Reading through the code, I was a left a bit confused as to the actual structure. Could you update with the LangRef update so that it's easier to review? Also, tests for correct usage would be helpful.

lib/IR/Function.cpp
995 ↗(On Diff #25488)

I'm mildly bothered by using the same name for two different pieces of metadata. Is there a reason not to use a different name here?

Before going any further discussing this, I'd like to see an example or
LangRef documentation with an example. I'm not even sure I read the
code right and don't want to waste time discussing something which might
be a result of a misread.

dnovillo updated this revision to Diff 25641.May 12 2015, 4:00 PM
  • Add documentation for function_entry_count counter.

LGTM w/ minor comments addressed. No further review needed.

docs/BranchWeightMetadata.rst
124 ↗(On Diff #25641)

"function header"? What's that? I assume you mean the definition or declaration itself?

operand -> operator

lib/IR/Verifier.cpp
1480 ↗(On Diff #25641)

cast rather than dyn_cast

test/Verifier/function-metadata.ll
3 ↗(On Diff #25641)

I still want to see a positive test example. Your example from the documentation would be a good one. Something to show that the profiling is valid when used properly.

This revision was automatically updated to reflect the committed changes.