CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
104 lines
3.8 KiB
C++
104 lines
3.8 KiB
C++
//===- MachineBranchProbabilityInfo.cpp - Machine Branch Probability Info -===//
|
|
//
|
|
// 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This analysis uses probability info stored in Machine Basic Blocks.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
|
|
#include "llvm/CodeGen/MachineBasicBlock.h"
|
|
#include "llvm/InitializePasses.h"
|
|
#include "llvm/Support/CommandLine.h"
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
using namespace llvm;
|
|
|
|
INITIALIZE_PASS(MachineBranchProbabilityInfoWrapperPass, "machine-branch-prob",
|
|
"Machine Branch Probability Analysis", false, true)
|
|
namespace llvm {
|
|
cl::opt<unsigned>
|
|
StaticLikelyProb("static-likely-prob",
|
|
cl::desc("branch probability threshold in percentage"
|
|
" to be considered very likely"),
|
|
cl::init(80), cl::Hidden);
|
|
|
|
cl::opt<unsigned> ProfileLikelyProb(
|
|
"profile-likely-prob",
|
|
cl::desc("branch probability threshold in percentage to be considered"
|
|
" very likely when profile is available"),
|
|
cl::init(51), cl::Hidden);
|
|
} // namespace llvm
|
|
|
|
MachineBranchProbabilityAnalysis::Result
|
|
MachineBranchProbabilityAnalysis::run(MachineFunction &,
|
|
MachineFunctionAnalysisManager &) {
|
|
return MachineBranchProbabilityInfo();
|
|
}
|
|
|
|
PreservedAnalyses
|
|
MachineBranchProbabilityPrinterPass::run(MachineFunction &MF,
|
|
MachineFunctionAnalysisManager &MFAM) {
|
|
OS << "Printing analysis 'Machine Branch Probability Analysis' for machine "
|
|
"function '"
|
|
<< MF.getName() << "':\n";
|
|
auto &MBPI = MFAM.getResult<MachineBranchProbabilityAnalysis>(MF);
|
|
for (const MachineBasicBlock &MBB : MF) {
|
|
for (const MachineBasicBlock *Succ : MBB.successors())
|
|
MBPI.printEdgeProbability(OS << " ", &MBB, Succ);
|
|
}
|
|
return PreservedAnalyses::all();
|
|
}
|
|
|
|
char MachineBranchProbabilityInfoWrapperPass::ID = 0;
|
|
|
|
MachineBranchProbabilityInfoWrapperPass::
|
|
MachineBranchProbabilityInfoWrapperPass()
|
|
: ImmutablePass(ID) {}
|
|
|
|
void MachineBranchProbabilityInfoWrapperPass::anchor() {}
|
|
|
|
AnalysisKey MachineBranchProbabilityAnalysis::Key;
|
|
|
|
bool MachineBranchProbabilityInfo::invalidate(
|
|
MachineFunction &, const PreservedAnalyses &PA,
|
|
MachineFunctionAnalysisManager::Invalidator &) {
|
|
auto PAC = PA.getChecker<MachineBranchProbabilityAnalysis>();
|
|
return !PAC.preservedWhenStateless();
|
|
}
|
|
|
|
BranchProbability
|
|
MachineBranchProbabilityInfo::getEdgeProbability(const MachineBasicBlock *Src,
|
|
unsigned SuccIdx) const {
|
|
return Src->getSuccProbability(Src->succ_begin() + SuccIdx);
|
|
}
|
|
|
|
BranchProbability MachineBranchProbabilityInfo::getEdgeProbability(
|
|
const MachineBasicBlock *Src, const MachineBasicBlock *Dst) const {
|
|
// This is a linear search. Try to use the const_succ_iterator version when
|
|
// possible.
|
|
return Src->getSuccProbability(find(Src->successors(), Dst));
|
|
}
|
|
|
|
bool MachineBranchProbabilityInfo::isEdgeHot(
|
|
const MachineBasicBlock *Src, const MachineBasicBlock *Dst) const {
|
|
BranchProbability HotProb(StaticLikelyProb, 100);
|
|
return getEdgeProbability(Src, Dst) > HotProb;
|
|
}
|
|
|
|
raw_ostream &MachineBranchProbabilityInfo::printEdgeProbability(
|
|
raw_ostream &OS, const MachineBasicBlock *Src,
|
|
const MachineBasicBlock *Dst) const {
|
|
|
|
const BranchProbability Prob = getEdgeProbability(Src, Dst);
|
|
OS << "edge " << printMBBReference(*Src) << " -> " << printMBBReference(*Dst)
|
|
<< " probability is " << Prob
|
|
<< (isEdgeHot(Src, Dst) ? " [HOT edge]\n" : "\n");
|
|
|
|
return OS;
|
|
}
|