1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 11:42:57 +01:00
llvm-mirror/lib/Transforms/IPO
Hongtao Yu 4cefe8e200 [CSSPGO] Pseudo probes for function calls.
An indirect call site needs to be probed for its potential call targets. With CSSPGO a direct call also needs a probe so that a calling context can be represented by a stack of callsite probes. Unlike pseudo probes for basic blocks that are in form of standalone intrinsic call instructions, pseudo probes for callsites have to be attached to the call instruction, thus a separate instruction would not work.

One possible way of attaching a probe to a call instruction is to use a special metadata that carries information about the probe. The special metadata will have to make its way through the optimization pipeline down to object emission. This requires additional efforts to maintain the metadata in various places. Given that the `!dbg` metadata is a first-class metadata and has all essential support in place , leveraging the `!dbg` metadata as a channel to encode pseudo probe information is probably the easiest solution.

With the requirement of not inflating `!dbg` metadata that is allocated for almost every instruction, we found that the 32-bit DWARF discriminator field which mainly serves AutoFDO can be reused for pseudo probes. DWARF discriminators distinguish identical source locations between instructions and with pseudo probes such support is not required. In this change we are using the discriminator field to encode the ID and type of a callsite probe and the encoded value will be unpacked and consumed right before object emission. When a callsite is inlined, the callsite discriminator field will go with the inlined instructions. The `!dbg` metadata of an inlined instruction is in form of a scope stack. The top of the stack is the instruction's original `!dbg` metadata and the bottom of the stack is for the original callsite of the top-level inliner. Except for the top of the stack, all other elements of the stack actually refer to the nested inlined callsites whose discriminator field (which actually represents a calliste probe) can be used together to represent the inline context of an inlined PseudoProbeInst or CallInst.

To avoid collision with the baseline AutoFDO in various places that handles dwarf discriminators where a check against  the `-pseudo-probe-for-profiling` switch is not available, a special encoding scheme is used to tell apart a pseudo probe discriminator from a regular discriminator. For the regular discriminator, if all lowest 3 bits are non-zero, it means the discriminator is basically empty and all higher 29 bits can be reversed for pseudo probe use.

Callsite pseudo probes are inserted in `SampleProfileProbePass` and a target-independent MIR pass `PseudoProbeInserter` is added to unpack the probe ID/type from `!dbg`.

Note that with this work the switch -debug-info-for-profiling will not work with -pseudo-probe-for-profiling anymore. They cannot be used at the same time.

Reviewed By: wmi

Differential Revision: https://reviews.llvm.org/D91756
2020-12-02 13:45:20 -08:00
..
AlwaysInliner.cpp [AlwaysInliner] Call mergeAttributesForInlining after inlining 2020-11-13 12:01:35 -08:00
Annotation2Metadata.cpp Add pass to add !annotate metadata from @llvm.global.annotations. 2020-11-16 14:57:11 +00:00
ArgumentPromotion.cpp [ArgumentPromotion]: Copy function metadata after promoting arguments 2020-09-10 13:08:57 -04:00
Attributor.cpp [Attributor] Finalize the CGUpdater after each SCC 2020-10-27 22:07:56 -05:00
AttributorAttributes.cpp [Attributor][FIX] Properly promote arguments pointers to arrays 2020-10-29 00:45:32 -05:00
BarrierNoopPass.cpp
BlockExtractor.cpp [BlockExtract][NewPM] Port -extract-blocks to NPM 2020-10-21 12:51:11 -07:00
CalledValuePropagation.cpp
CMakeLists.txt [CSSPGO] Pseudo probe instrumentation pass 2020-11-30 10:16:54 -08:00
ConstantMerge.cpp [Alignment][NFC] migrate DataLayout::getPreferredAlignment 2020-06-29 11:24:36 +00:00
CrossDSOCFI.cpp
DeadArgumentElimination.cpp [DAE] MarkLive in MarkValue(MaybeLive) if any use is live 2020-10-02 10:55:08 -07:00
ElimAvailExtern.cpp
ExtractGV.cpp
ForceFunctionAttrs.cpp Revert "[IR] add fn attr for no_stack_protector; prevent inlining on mismatch" 2020-11-17 17:27:14 -08:00
FunctionAttrs.cpp [AA] Split up LocationSize::unknown() 2020-11-26 18:39:55 +01:00
FunctionImport.cpp Fix some clang-tidy bugprone-argument-comment issues 2020-09-19 20:41:25 -07:00
GlobalDCE.cpp
GlobalOpt.cpp [SVE]Clarify TypeSize comparisons in llvm/lib/Transforms 2020-10-23 09:15:17 +01:00
GlobalSplit.cpp
HotColdSplitting.cpp Revert "[PM/CC1] Add -f[no-]split-cold-code CC1 option to toggle splitting" 2020-10-19 12:31:14 +02:00
InferFunctionAttrs.cpp
Inliner.cpp [llvm][inliner] Reuse the inliner pass to implement 'always inliner' 2020-11-30 12:03:39 -08:00
InlineSimple.cpp
Internalize.cpp
IPO.cpp Revert "[IRSim][IROutliner] Adding the extraction basics for the IROutliner." 2020-11-27 19:55:57 -06:00
LoopExtractor.cpp [LoopExtract][NewPM] Port -loop-extract to NPM 2020-10-13 22:55:42 -07:00
LowerTypeTests.cpp [AArch64] Add BTI to CFI jumptables. 2020-09-29 13:50:23 +02:00
MergeFunctions.cpp
OpenMPOpt.cpp [OpenMPIRBuilder] forward arguments as pointers to outlined function 2020-12-02 14:59:41 +01:00
PartialInlining.cpp [PartialInliner]: Handle code regions in a switch stmt cases 2020-11-02 14:32:45 -05:00
PassManagerBuilder.cpp Revert "[IRSim][IROutliner] Adding the extraction basics for the IROutliner." 2020-11-27 19:55:57 -06:00
PruneEH.cpp [PruneEH][NFC] Use CallGraphUpdater in PruneEH 2020-09-14 14:43:19 -07:00
SampleProfile.cpp Revert "clang-misexpect: Profile Guided Validation of Performance Annotations in LLVM" 2020-11-14 13:12:38 +03:00
SampleProfileProbe.cpp [CSSPGO] Pseudo probes for function calls. 2020-12-02 13:45:20 -08:00
SCCP.cpp
StripDeadPrototypes.cpp
StripSymbols.cpp [NewPM] Port strip* passes to NPM 2020-09-15 18:25:12 -07:00
SyntheticCountsPropagation.cpp [CallGraph] Add support for callback call sites 2020-07-01 13:44:11 -07:00
ThinLTOBitcodeWriter.cpp
WholeProgramDevirt.cpp [ThinLTO/WPD] Enable -wholeprogramdevirt-skip in ThinLTO backends 2020-11-24 09:35:07 -08:00