[llvm] a06e63f - NFC. Refactor DOTGraphTraits::isNodeHidden
Artur Pilipenko via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 3 11:27:24 PDT 2021
Author: Artur Pilipenko
Date: 2021-06-03T11:27:06-07:00
New Revision: a06e63fa522f5125f1912b7e0a1d578425b5ea5f
URL: https://github.com/llvm/llvm-project/commit/a06e63fa522f5125f1912b7e0a1d578425b5ea5f
DIFF: https://github.com/llvm/llvm-project/commit/a06e63fa522f5125f1912b7e0a1d578425b5ea5f.diff
LOG: NFC. Refactor DOTGraphTraits::isNodeHidden
Restructure handling of cfg-hide-unreachable-paths and
cfg-hide-deoptimize-paths options so as to make it easier
to introduce new types of hidden blocks.
Added:
Modified:
llvm/include/llvm/Analysis/CFGPrinter.h
llvm/lib/Analysis/CFGPrinter.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/CFGPrinter.h b/llvm/include/llvm/Analysis/CFGPrinter.h
index 53700798b6b30..db0f9c8ab7e7b 100644
--- a/llvm/include/llvm/Analysis/CFGPrinter.h
+++ b/llvm/include/llvm/Analysis/CFGPrinter.h
@@ -123,7 +123,7 @@ template <>
struct DOTGraphTraits<DOTFuncInfo *> : public DefaultDOTGraphTraits {
// Cache for is hidden property
- llvm::DenseMap<const BasicBlock *, bool> isHiddenBasicBlock;
+ llvm::DenseMap<const BasicBlock *, bool> isOnDeoptOrUnreachablePath;
DOTGraphTraits(bool isSimple = false) : DefaultDOTGraphTraits(isSimple) {}
@@ -296,7 +296,7 @@ struct DOTGraphTraits<DOTFuncInfo *> : public DefaultDOTGraphTraits {
return Attrs;
}
bool isNodeHidden(const BasicBlock *Node, const DOTFuncInfo *CFGInfo);
- void computeHiddenNodes(const Function *F);
+ void computeDeoptOrUnreachablePaths(const Function *F);
};
} // End llvm namespace
diff --git a/llvm/lib/Analysis/CFGPrinter.cpp b/llvm/lib/Analysis/CFGPrinter.cpp
index b981925542c6c..f9fb584a61416 100644
--- a/llvm/lib/Analysis/CFGPrinter.cpp
+++ b/llvm/lib/Analysis/CFGPrinter.cpp
@@ -270,31 +270,37 @@ FunctionPass *llvm::createCFGOnlyPrinterLegacyPassPass() {
return new CFGOnlyPrinterLegacyPass();
}
-void DOTGraphTraits<DOTFuncInfo *>::computeHiddenNodes(const Function *F) {
+/// Find all blocks on the paths which terminate with a deoptimize or
+/// unreachable (i.e. all blocks which are post-dominated by a deoptimize
+/// or unreachable). These paths are hidden if the corresponding cl::opts
+/// are enabled.
+void DOTGraphTraits<DOTFuncInfo *>::computeDeoptOrUnreachablePaths(
+ const Function *F) {
auto evaluateBB = [&](const BasicBlock *Node) {
if (succ_empty(Node)) {
const Instruction *TI = Node->getTerminator();
- isHiddenBasicBlock[Node] =
+ isOnDeoptOrUnreachablePath[Node] =
(HideUnreachablePaths && isa<UnreachableInst>(TI)) ||
(HideDeoptimizePaths && Node->getTerminatingDeoptimizeCall());
return;
}
- isHiddenBasicBlock[Node] =
+ isOnDeoptOrUnreachablePath[Node] =
llvm::all_of(successors(Node), [this](const BasicBlock *BB) {
- return isHiddenBasicBlock[BB];
+ return isOnDeoptOrUnreachablePath[BB];
});
};
/// The post order traversal iteration is done to know the status of
- /// isHiddenBasicBlock for all the successors on the current BB.
+ /// isOnDeoptOrUnreachablePath for all the successors on the current BB.
llvm::for_each(post_order(&F->getEntryBlock()), evaluateBB);
}
bool DOTGraphTraits<DOTFuncInfo *>::isNodeHidden(const BasicBlock *Node,
const DOTFuncInfo *CFGInfo) {
- // If both restricting flags are false, all nodes are displayed.
- if (!HideUnreachablePaths && !HideDeoptimizePaths)
- return false;
- if (isHiddenBasicBlock.find(Node) == isHiddenBasicBlock.end())
- computeHiddenNodes(Node->getParent());
- return isHiddenBasicBlock[Node];
+ if (HideUnreachablePaths || HideDeoptimizePaths) {
+ if (isOnDeoptOrUnreachablePath.find(Node) ==
+ isOnDeoptOrUnreachablePath.end())
+ computeDeoptOrUnreachablePaths(Node->getParent());
+ return isOnDeoptOrUnreachablePath[Node];
+ }
+ return false;
}
More information about the llvm-commits
mailing list