//===- Transforms/IPO/SampleProfileProbe.h ----------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // /// \file /// This file provides the interface for the pseudo probe implementation for /// AutoFDO. // //===----------------------------------------------------------------------===// #ifndef LLVM_TRANSFORMS_IPO_SAMPLEPROFILEPROBE_H #define LLVM_TRANSFORMS_IPO_SAMPLEPROFILEPROBE_H #include "llvm/Analysis/LazyCallGraph.h" #include "llvm/IR/PassManager.h" #include "llvm/IR/PassInstrumentation.h" #include "llvm/ProfileData/SampleProf.h" #include <unordered_map> namespace llvm { class BasicBlock; class Function; class Instruction; class Loop; class PassInstrumentationCallbacks; class TargetMachine; class Module; usingnamespacesampleprof; BlockIdMap; InstructionIdMap; // Map from tuples of Probe id and inline stack hash code to distribution // factors. ProbeFactorMap; FuncProbeFactorMap; // A pseudo probe verifier that can be run after each IR passes to detect the // violation of updating probe factors. In principle, the sum of distribution // factor for a probe should be identical before and after a pass. For a // function pass, the factor sum for a probe would be typically 100%. class PseudoProbeVerifier { … }; /// Sample profile pseudo prober. /// /// Insert pseudo probes for block sampling and value sampling. class SampleProfileProber { … }; class SampleProfileProbePass : public PassInfoMixin<SampleProfileProbePass> { … }; // Pseudo probe distribution factor updater. // Sample profile annotation can happen in both LTO prelink and postlink. The // postlink-time re-annotation can degrade profile quality because of prelink // code duplication transformation, such as loop unrolling, jump threading, // indirect call promotion etc. As such, samples corresponding to a source // location may be aggregated multiple times in postlink. With a concept of // distribution factor for pseudo probes, samples can be distributed among // duplicated probes reasonable based on the assumption that optimizations // duplicating code well-maintain the branch frequency information (BFI). This // pass updates distribution factors for each pseudo probe at the end of the // prelink pipeline, to reflect an estimated portion of the real execution // count. class PseudoProbeUpdatePass : public PassInfoMixin<PseudoProbeUpdatePass> { … }; } // end namespace llvm #endif // LLVM_TRANSFORMS_IPO_SAMPLEPROFILEPROBE_H