Open hungryzzz opened 11 months ago
The function may be inlined into the caller before the instrumentation so that the remaining out of line copy does not have any count. The inline instance will have no zero count.
I dump the LLVM IR and find that the function is invoked explicitly so I don't think it is related to inlining. I've also checked that sort_array
is the only one caller to call the _ZNSt14basic_ifstreamIcSt11char_traitsIcEEC1Ev
.
# clang++ -fprofile-generate -O2 bubble_sort.cpp -S -emit-llvm -o bubble.ll
; Function Attrs: mustprogress uwtable
define dso_local void @_Z10sort_arrayv() local_unnamed_addr #5 personality ptr @__gxx_personality_v0 {
%1 = alloca %"class.std::basic_ifstream", align 8
%2 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef 40000)
call void @llvm.lifetime.start.p0(i64 520, ptr nonnull %1) #13
call void @_ZNSt14basic_ifstreamIcSt11char_traitsIcEEC1Ev(ptr noundef nonnull align 8 dereferenceable(256) %1)
%3 = getelementptr inbounds %"class.std::basic_ifstream", ptr %1, i64 0, i32 1
%4 = invoke noundef ptr @_ZNSt13basic_filebufIcSt11char_traitsIcEE4openEPKcSt13_Ios_Openmode(ptr noundef nonnull align 8 dereferenceable(240) %3, ptr noundef nonnull @.str.1, i32 noundef 8)
to label %5 unwind label %40
Given your observation, another possibility is that the actual callee body is defined in the library not instrumented. You can use the linker trace symbol option to see where the function is defined.
Description
Hi, I set the
-fprofile-generate
option to enable thePGOInstrumentationGen
pass and collect the function counts when execution.But I find that a function whose profiling count is zero will be invoked during execution, I think maybe there is something wrong in
PGOInstrumentationGen
pass.Steps to reproduce
The result of
llvm-profdata show
is as follows, it shows that the total counts is zero which indicates that the function_ZNSt14basic_ifstreamIcSt11char_traitsIcEEC1Ev
will not be executed.Then I use
gdb
to debug it, and find that the function_ZNSt14basic_ifstreamIcSt11char_traitsIcEEC1Ev
will be entered.Environment
The test case is attached here. case.zip