Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions llvm/include/llvm/Analysis/CFGPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "llvm/Support/FormatVariadic.h"

#include <functional>
#include <optional>
#include <sstream>

namespace llvm {
Expand Down Expand Up @@ -75,6 +76,8 @@ class DOTFuncInfo {
using NodeIdFormatterTy =
std::function<std::optional<std::string>(const BasicBlock *)>;
std::optional<NodeIdFormatterTy> NodeIdFormatter;
bool HideDeoptimizePaths;
bool HideUnreachablePaths;

public:
DOTFuncInfo(const Function *F) : DOTFuncInfo(F, nullptr, nullptr, 0) {}
Expand All @@ -83,7 +86,9 @@ class DOTFuncInfo {
LLVM_ABI
DOTFuncInfo(const Function *F, const BlockFrequencyInfo *BFI,
const BranchProbabilityInfo *BPI, uint64_t MaxFreq,
std::optional<NodeIdFormatterTy> NodeIdFormatter = std::nullopt);
std::optional<NodeIdFormatterTy> NodeIdFormatter = std::nullopt,
std::optional<bool> HideDeoptimizePaths = std::nullopt,
std::optional<bool> HideUnreachablePaths = std::nullopt);

const BlockFrequencyInfo *getBFI() const { return BFI; }

Expand Down Expand Up @@ -114,6 +119,10 @@ class DOTFuncInfo {
std::optional<NodeIdFormatterTy> getNodeIdFormatter() {
return NodeIdFormatter;
}

bool hideDeoptimizePaths() const { return HideDeoptimizePaths; }

bool hideUnreachablePaths() const { return HideUnreachablePaths; }
};

template <>
Expand Down Expand Up @@ -346,7 +355,8 @@ struct DOTGraphTraits<DOTFuncInfo *> : public DefaultDOTGraphTraits {

LLVM_ABI bool isNodeHidden(const BasicBlock *Node,
const DOTFuncInfo *CFGInfo);
LLVM_ABI void computeDeoptOrUnreachablePaths(const Function *F);
LLVM_ABI void computeDeoptOrUnreachablePaths(const Function *F,
const DOTFuncInfo *CFGInfo);
};
} // namespace llvm

Expand Down
20 changes: 13 additions & 7 deletions llvm/lib/Analysis/CFGPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,14 @@ static void viewCFG(Function &F, const BlockFrequencyInfo *BFI,

DOTFuncInfo::DOTFuncInfo(const Function *F, const BlockFrequencyInfo *BFI,
const BranchProbabilityInfo *BPI, uint64_t MaxFreq,
std::optional<NodeIdFormatterTy> NodeIdFormatter)
std::optional<NodeIdFormatterTy> NodeIdFormatter,
std::optional<bool> HideDeoptimizePaths,
std::optional<bool> HideUnreachablePaths)
: F(F), BFI(BFI), BPI(BPI), MaxFreq(MaxFreq),
NodeIdFormatter(NodeIdFormatter) {
NodeIdFormatter(NodeIdFormatter),
HideDeoptimizePaths(HideDeoptimizePaths.value_or(::HideDeoptimizePaths)),
HideUnreachablePaths(
HideUnreachablePaths.value_or(::HideUnreachablePaths)) {
ShowHeat = false;
EdgeWeights = !!BPI; // Print EdgeWeights when BPI is available.
RawWeights = !!BFI; // Print RawWeights when BFI is available.
Expand Down Expand Up @@ -190,13 +195,14 @@ void Function::viewCFGOnly(const BlockFrequencyInfo *BFI,
/// or unreachable). These paths are hidden if the corresponding cl::opts
/// are enabled.
void DOTGraphTraits<DOTFuncInfo *>::computeDeoptOrUnreachablePaths(
const Function *F) {
const Function *F, const DOTFuncInfo *CFGInfo) {
auto evaluateBB = [&](const BasicBlock *Node) {
if (succ_empty(Node)) {
const Instruction *TI = Node->getTerminator();
isOnDeoptOrUnreachablePath[Node] =
(HideUnreachablePaths && isa<UnreachableInst>(TI)) ||
(HideDeoptimizePaths && Node->getTerminatingDeoptimizeCall());
(CFGInfo->hideUnreachablePaths() && isa<UnreachableInst>(TI)) ||
(CFGInfo->hideDeoptimizePaths() &&
Node->getTerminatingDeoptimizeCall());
return;
}
isOnDeoptOrUnreachablePath[Node] =
Expand All @@ -220,9 +226,9 @@ bool DOTGraphTraits<DOTFuncInfo *>::isNodeHidden(const BasicBlock *Node,
HideColdPaths)
return true;
}
if (HideUnreachablePaths || HideDeoptimizePaths) {
if (CFGInfo->hideUnreachablePaths() || CFGInfo->hideDeoptimizePaths()) {
if (!isOnDeoptOrUnreachablePath.contains(Node))
computeDeoptOrUnreachablePaths(Node->getParent());
computeDeoptOrUnreachablePaths(Node->getParent(), CFGInfo);
return isOnDeoptOrUnreachablePath[Node];
}
return false;
Expand Down