#include "llvm/CodeGen/MIRSampleProfile.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/Analysis/BlockFrequencyInfoImpl.h"
#include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
#include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
#include "llvm/CodeGen/MachineDominators.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineLoopInfo.h"
#include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h"
#include "llvm/CodeGen/MachinePostDominators.h"
#include "llvm/CodeGen/Passes.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/PseudoProbe.h"
#include "llvm/InitializePasses.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Utils/SampleProfileLoaderBaseImpl.h"
#include "llvm/Transforms/Utils/SampleProfileLoaderBaseUtil.h"
#include <optional>
usingnamespacellvm;
usingnamespacesampleprof;
usingnamespacellvm::sampleprofutil;
ProfileCount;
#define DEBUG_TYPE …
static cl::opt<bool> ShowFSBranchProb(
"show-fs-branchprob", cl::Hidden, cl::init(false),
cl::desc("Print setting flow sensitive branch probabilities"));
static cl::opt<unsigned> FSProfileDebugProbDiffThreshold(
"fs-profile-debug-prob-diff-threshold", cl::init(10),
cl::desc("Only show debug message if the branch probility is greater than "
"this value (in percentage)."));
static cl::opt<unsigned> FSProfileDebugBWThreshold(
"fs-profile-debug-bw-threshold", cl::init(10000),
cl::desc("Only show debug message if the source branch weight is greater "
" than this value."));
static cl::opt<bool> ViewBFIBefore("fs-viewbfi-before", cl::Hidden,
cl::init(false),
cl::desc("View BFI before MIR loader"));
static cl::opt<bool> ViewBFIAfter("fs-viewbfi-after", cl::Hidden,
cl::init(false),
cl::desc("View BFI after MIR loader"));
namespace llvm {
extern cl::opt<bool> ImprovedFSDiscriminator;
}
char MIRProfileLoaderPass::ID = …;
INITIALIZE_PASS_BEGIN(MIRProfileLoaderPass, DEBUG_TYPE,
"Load MIR Sample Profile",
false, false)
INITIALIZE_PASS_DEPENDENCY(MachineBlockFrequencyInfoWrapperPass)
INITIALIZE_PASS_DEPENDENCY(MachineDominatorTreeWrapperPass)
INITIALIZE_PASS_DEPENDENCY(MachinePostDominatorTreeWrapperPass)
INITIALIZE_PASS_DEPENDENCY(MachineLoopInfoWrapperPass)
INITIALIZE_PASS_DEPENDENCY(MachineOptimizationRemarkEmitterPass)
INITIALIZE_PASS_END(MIRProfileLoaderPass, DEBUG_TYPE, "Load MIR Sample Profile",
false, false)
char &llvm::MIRProfileLoaderPassID = …;
FunctionPass *
llvm::createMIRProfileLoaderPass(std::string File, std::string RemappingFile,
FSDiscriminatorPass P,
IntrusiveRefCntPtr<vfs::FileSystem> FS) { … }
namespace llvm {
extern cl::opt<GVDAGType> ViewBlockLayoutWithBFI;
extern cl::opt<std::string> ViewBlockFreqFuncName;
std::optional<PseudoProbe> extractProbe(const MachineInstr &MI) { … }
namespace afdo_detail {
template <> struct IRTraits<MachineBasicBlock> { … };
}
class MIRProfileLoader final
: public SampleProfileLoaderBaseImpl<MachineFunction> { … };
template <>
void SampleProfileLoaderBaseImpl<MachineFunction>::computeDominanceAndLoopInfo(
MachineFunction &F) { … }
void MIRProfileLoader::setBranchProbs(MachineFunction &F) { … }
bool MIRProfileLoader::doInitialization(Module &M) { … }
bool MIRProfileLoader::runOnFunction(MachineFunction &MF) { … }
}
MIRProfileLoaderPass::MIRProfileLoaderPass(
std::string FileName, std::string RemappingFileName, FSDiscriminatorPass P,
IntrusiveRefCntPtr<vfs::FileSystem> FS)
: … { … }
bool MIRProfileLoaderPass::runOnMachineFunction(MachineFunction &MF) { … }
bool MIRProfileLoaderPass::doInitialization(Module &M) { … }
void MIRProfileLoaderPass::getAnalysisUsage(AnalysisUsage &AU) const { … }