Index: lib/Transforms/IPO/SampleProfile.cpp =================================================================== --- lib/Transforms/IPO/SampleProfile.cpp +++ lib/Transforms/IPO/SampleProfile.cpp @@ -648,19 +648,16 @@ const FunctionSamples * SampleProfileLoader::findCalleeFunctionSamples(const Instruction &Inst) const { const DILocation *DIL = Inst.getDebugLoc(); - if (!DIL) { + if (!DIL) return nullptr; - } - - StringRef CalleeName; - if (const CallInst *CI = dyn_cast(&Inst)) - if (Function *Callee = CI->getCalledFunction()) - CalleeName = Callee->getName(); const FunctionSamples *FS = findFunctionSamples(Inst); if (FS == nullptr) return nullptr; + StringRef CalleeName; + if (Function *Callee = CallSite(const_cast(&Inst)).getCalledFunction()) + CalleeName = Callee->getName(); return FS->findFunctionSamplesAt(LineLocation(FunctionSamples::getOffset(DIL), DIL->getBaseDiscriminator()), CalleeName); Index: test/Transforms/SampleProfile/Inputs/invoke.prof =================================================================== --- /dev/null +++ test/Transforms/SampleProfile/Inputs/invoke.prof @@ -0,0 +1,10 @@ +_Z3foov:120:20 + 2: 20 + 2.1: 21 + 2.2: 22 + 2.1: _Z12bar_noexceptv:0 + 1: 34 + 2.2: _Z3barv:0 + 1: 0 + 2.2: Other:35 + 1: 35 Index: test/Transforms/SampleProfile/invoke.ll =================================================================== --- /dev/null +++ test/Transforms/SampleProfile/invoke.ll @@ -0,0 +1,132 @@ +; RUN: opt < %s -S -add-discriminators -sample-profile -sample-profile-file=%S/Inputs/invoke.prof | FileCheck %s +; ModuleID = 'invoke.bc' +source_filename = "invoke.cpp" +target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-apple-macosx10.14.0" + +; Function Attrs: nounwind ssp uwtable +define void @_Z3barv() #0 !dbg !8 { +entry: + ret void, !dbg !11 +} + +; Function Attrs: ssp uwtable +define void @_Z3foov() #1 personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) !dbg !12 { +entry: + %exn.slot = alloca i8* + %ehselector.slot = alloca i32 + call void @_Z12bar_noexceptv() #4, !dbg !13 + call void @_Z12bar_noexceptv() #4, !dbg !15 + ; we should not inline this... + ; CHECK: invoke void @_Z3barv + invoke void @_Z3barv() + to label %invoke.cont unwind label %lpad, !dbg !16 + +invoke.cont: ; preds = %entry + br label %try.cont, !dbg !17 + +lpad: ; preds = %entry + %0 = landingpad { i8*, i32 } + catch i8* null, !dbg !18 + %1 = extractvalue { i8*, i32 } %0, 0, !dbg !18 + store i8* %1, i8** %exn.slot, align 8, !dbg !18 + %2 = extractvalue { i8*, i32 } %0, 1, !dbg !18 + store i32 %2, i32* %ehselector.slot, align 4, !dbg !18 + br label %catch, !dbg !18 + +catch: ; preds = %lpad + %exn = load i8*, i8** %exn.slot, align 8, !dbg !17 + %3 = call i8* @__cxa_begin_catch(i8* %exn) #4, !dbg !17 + invoke void @__cxa_rethrow() #5 + to label %unreachable unwind label %lpad1, !dbg !19 + +lpad1: ; preds = %catch + %4 = landingpad { i8*, i32 } + cleanup, !dbg !21 + %5 = extractvalue { i8*, i32 } %4, 0, !dbg !21 + store i8* %5, i8** %exn.slot, align 8, !dbg !21 + %6 = extractvalue { i8*, i32 } %4, 1, !dbg !21 + store i32 %6, i32* %ehselector.slot, align 4, !dbg !21 + invoke void @__cxa_end_catch() + to label %invoke.cont2 unwind label %terminate.lpad, !dbg !22 + +invoke.cont2: ; preds = %lpad1 + br label %eh.resume, !dbg !22 + +try.cont: ; preds = %invoke.cont + ret void, !dbg !23 + +eh.resume: ; preds = %invoke.cont2 + %exn3 = load i8*, i8** %exn.slot, align 8, !dbg !22 + %sel = load i32, i32* %ehselector.slot, align 4, !dbg !22 + %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn3, 0, !dbg !22 + %lpad.val4 = insertvalue { i8*, i32 } %lpad.val, i32 %sel, 1, !dbg !22 + resume { i8*, i32 } %lpad.val4, !dbg !22 + +terminate.lpad: ; preds = %lpad1 + %7 = landingpad { i8*, i32 } + catch i8* null, !dbg !22 + %8 = extractvalue { i8*, i32 } %7, 0, !dbg !22 + call void @__clang_call_terminate(i8* %8) #6, !dbg !22 + unreachable, !dbg !22 + +unreachable: ; preds = %catch + unreachable +} + +; Function Attrs: nounwind +declare void @_Z12bar_noexceptv() #2 + +declare i32 @__gxx_personality_v0(...) + +declare i8* @__cxa_begin_catch(i8*) + +declare void @__cxa_rethrow() + +declare void @__cxa_end_catch() + +; Function Attrs: noinline noreturn nounwind +define linkonce_odr hidden void @__clang_call_terminate(i8*) #3 { + %2 = call i8* @__cxa_begin_catch(i8* %0) #4 + call void @_ZSt9terminatev() #6 + unreachable +} + +declare void @_ZSt9terminatev() + +attributes #0 = { nounwind ssp uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="penryn" "target-features"="+cx16,+fxsr,+mmx,+sahf,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { ssp uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="penryn" "target-features"="+cx16,+fxsr,+mmx,+sahf,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #2 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="penryn" "target-features"="+cx16,+fxsr,+mmx,+sahf,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #3 = { noinline noreturn nounwind } +attributes #4 = { nounwind } +attributes #5 = { noreturn } +attributes #6 = { noreturn nounwind } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4, !5, !6} +!llvm.ident = !{!7} + +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 8.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: GNU) +!1 = !DIFile(filename: "invoke.cpp", directory: "examples") +!2 = !{} +!3 = !{i32 2, !"Dwarf Version", i32 4} +!4 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{i32 1, !"wchar_size", i32 4} +!6 = !{i32 7, !"PIC Level", i32 2} +!7 = !{!"clang version 8.0.0"} +!8 = distinct !DISubprogram(name: "bar", linkageName: "_Z3barv", scope: !1, file: !1, line: 2, type: !9, scopeLine: 2, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2) +!9 = !DISubroutineType(types: !10) +!10 = !{null} +!11 = !DILocation(line: 3, column: 1, scope: !8) +!12 = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov", scope: !1, file: !1, line: 6, type: !9, scopeLine: 6, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2) +!13 = !DILocation(line: 8, column: 5, scope: !14) +!14 = distinct !DILexicalBlock(scope: !12, file: !1, line: 7, column: 7) +!15 = !DILocation(line: 8, column: 21, scope: !14) +!16 = !DILocation(line: 8, column: 37, scope: !14) +!17 = !DILocation(line: 9, column: 3, scope: !14) +!18 = !DILocation(line: 13, column: 1, scope: !14) +!19 = !DILocation(line: 11, column: 5, scope: !20) +!20 = distinct !DILexicalBlock(scope: !12, file: !1, line: 10, column: 15) +!21 = !DILocation(line: 13, column: 1, scope: !20) +!22 = !DILocation(line: 12, column: 3, scope: !20) +!23 = !DILocation(line: 13, column: 1, scope: !12)