[llvm] 07b6013 - [CFGPrinter] Allow CFG dumps with a given filename (#112906)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 5 04:58:51 PST 2024
Author: Lewis Crawford
Date: 2024-11-05T12:58:48Z
New Revision: 07b6013e6f69bfdf46b9f2fa1bb4c76f9ef2376c
URL: https://github.com/llvm/llvm-project/commit/07b6013e6f69bfdf46b9f2fa1bb4c76f9ef2376c
DIFF: https://github.com/llvm/llvm-project/commit/07b6013e6f69bfdf46b9f2fa1bb4c76f9ef2376c.diff
LOG: [CFGPrinter] Allow CFG dumps with a given filename (#112906)
Add functions to print the CFG via the debugger using a specified
filename.
This is useful when comparing CFGs for the same function before vs after
a change, or when handling functions with names that are too long to be
file names.
Added:
Modified:
llvm/include/llvm/IR/Function.h
llvm/lib/Analysis/CFGPrinter.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/Function.h b/llvm/include/llvm/IR/Function.h
index 43bf36d6f1eec9..e7afcbd31420c1 100644
--- a/llvm/include/llvm/IR/Function.h
+++ b/llvm/include/llvm/IR/Function.h
@@ -942,9 +942,14 @@ class LLVM_ABI Function : public GlobalObject, public ilist_node<Function> {
///
void viewCFG() const;
+ /// viewCFG - This function is meant for use from the debugger. It works just
+ /// like viewCFG(), but generates the dot file with the given file name.
+ void viewCFG(const char *OutputFileName) const;
+
/// Extended form to print edge weights.
void viewCFG(bool ViewCFGOnly, const BlockFrequencyInfo *BFI,
- const BranchProbabilityInfo *BPI) const;
+ const BranchProbabilityInfo *BPI,
+ const char *OutputFileName = nullptr) const;
/// viewCFGOnly - This function is meant for use from the debugger. It works
/// just like viewCFG, but it does not include the contents of basic blocks
@@ -953,6 +958,10 @@ class LLVM_ABI Function : public GlobalObject, public ilist_node<Function> {
///
void viewCFGOnly() const;
+ /// viewCFG - This function is meant for use from the debugger. It works just
+ /// like viewCFGOnly(), but generates the dot file with the given file name.
+ void viewCFGOnly(const char *OutputFileName) const;
+
/// Extended form to print edge weights.
void viewCFGOnly(const BlockFrequencyInfo *BFI,
const BranchProbabilityInfo *BPI) const;
diff --git a/llvm/lib/Analysis/CFGPrinter.cpp b/llvm/lib/Analysis/CFGPrinter.cpp
index 67a15197058b73..af18fb6626e3bf 100644
--- a/llvm/lib/Analysis/CFGPrinter.cpp
+++ b/llvm/lib/Analysis/CFGPrinter.cpp
@@ -136,12 +136,18 @@ PreservedAnalyses CFGOnlyPrinterPass::run(Function &F,
///
void Function::viewCFG() const { viewCFG(false, nullptr, nullptr); }
+void Function::viewCFG(const char *OutputFileName) const {
+ viewCFG(false, nullptr, nullptr, OutputFileName);
+}
+
void Function::viewCFG(bool ViewCFGOnly, const BlockFrequencyInfo *BFI,
- const BranchProbabilityInfo *BPI) const {
+ const BranchProbabilityInfo *BPI,
+ const char *OutputFileName) const {
if (!CFGFuncName.empty() && !getName().contains(CFGFuncName))
return;
DOTFuncInfo CFGInfo(this, BFI, BPI, BFI ? getMaxFreq(*this, BFI) : 0);
- ViewGraph(&CFGInfo, "cfg" + getName(), ViewCFGOnly);
+ ViewGraph(&CFGInfo, OutputFileName ? OutputFileName : "cfg" + getName(),
+ ViewCFGOnly);
}
/// viewCFGOnly - This function is meant for use from the debugger. It works
@@ -151,6 +157,10 @@ void Function::viewCFG(bool ViewCFGOnly, const BlockFrequencyInfo *BFI,
///
void Function::viewCFGOnly() const { viewCFGOnly(nullptr, nullptr); }
+void Function::viewCFGOnly(const char *OutputFileName) const {
+ viewCFG(true, nullptr, nullptr, OutputFileName);
+}
+
void Function::viewCFGOnly(const BlockFrequencyInfo *BFI,
const BranchProbabilityInfo *BPI) const {
viewCFG(true, BFI, BPI);
More information about the llvm-commits
mailing list