This is an archive of the discontinued LLVM Phabricator instance.

[InstrProf] Support for external functions in text format.
ClosedPublic

Authored by mtrofin on Mar 20 2018, 4:14 PM.

Details

Summary

External functions appearing as indirect call targets could not be
found in the SymTab, and the value:counter record was represented,
in the text format, using an empty string for the name. This would
then cause a silent parsing error when reading.

This CL:

  • adds explicit support for such functions
  • fixes the places where we would not propagate errors when reading
  • addresses a performance issue due to eager resorting of the SymTab.

Diff Detail

Repository
rL LLVM

Event Timeline

mtrofin created this revision.Mar 20 2018, 4:14 PM
mtrofin retitled this revision from [InstrProf] Support calls to external indirect funcs in text format to [InstrProf] Support for external functions in text format..Mar 20 2018, 4:15 PM
mtrofin edited the summary of this revision. (Show Details)
mtrofin added reviewers: xur, eraman.
mtrofin added a reviewer: davidxl.
davidxl added inline comments.Mar 20 2018, 4:42 PM
include/llvm/ProfileData/InstrProf.h
430 ↗(On Diff #139219)

Why do we need to do this? Is it better to return an empty string and skip the entry when it is empty?

479 ↗(On Diff #139219)

Sorted = false should be executed only when insertion succeeds.

mtrofin updated this revision to Diff 139224.Mar 20 2018, 4:53 PM

Skip dirty-ing the SymTab on unsuccessful name insertions.

mtrofin marked an inline comment as done.Mar 20 2018, 4:54 PM
mtrofin added inline comments.
include/llvm/ProfileData/InstrProf.h
430 ↗(On Diff #139219)

Just to distinguish it from an erroneous input.

davidxl added inline comments.Mar 20 2018, 10:03 PM
lib/ProfileData/InstrProfWriter.cpp
361 ↗(On Diff #139224)

What I suggested is that instead of emitting a fake target with a name that may collide with a real function, just skip the target (or better emit some comments here). Of course, the value of ND needs to be precomputed/adjusted first.

mtrofin added inline comments.Mar 20 2018, 10:36 PM
lib/ProfileData/InstrProfWriter.cpp
361 ↗(On Diff #139224)

Wouldn't we lose a counter value in that case? (which would shift thresholds, for example)

I share the concern of potential (albeit low probability) name collision. How about building a name using invalid characters, such as space - since the reader matches on ':' (so the external symbol name could be "External Symbol")

davidxl added inline comments.Mar 20 2018, 11:03 PM
lib/ProfileData/InstrProfWriter.cpp
361 ↗(On Diff #139224)

Ok. Also avoid using __llvm which is a reserved namespace for profiling library symbols.

mtrofin updated this revision to Diff 139340.Mar 21 2018, 11:54 AM

Changed symbol name

mtrofin marked an inline comment as done.Mar 21 2018, 11:55 AM
This revision is now accepted and ready to land.Mar 21 2018, 12:02 PM
This revision was automatically updated to reflect the committed changes.