[llvm] r281640 - [PM] Port CFGViewer and CFGPrinter to the new Pass Manager
Sriraman Tallam via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 15 11:35:28 PDT 2016
Author: tmsriram
Date: Thu Sep 15 13:35:27 2016
New Revision: 281640
URL: http://llvm.org/viewvc/llvm-project?rev=281640&view=rev
Log:
[PM] Port CFGViewer and CFGPrinter to the new Pass Manager
Differential Revision: https://reviews.llvm.org/D24592
Modified:
llvm/trunk/include/llvm/Analysis/CFGPrinter.h
llvm/trunk/include/llvm/InitializePasses.h
llvm/trunk/lib/Analysis/Analysis.cpp
llvm/trunk/lib/Analysis/CFGPrinter.cpp
llvm/trunk/lib/Passes/PassBuilder.cpp
llvm/trunk/lib/Passes/PassRegistry.def
llvm/trunk/test/Other/2007-06-05-PassID.ll
Modified: llvm/trunk/include/llvm/Analysis/CFGPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/CFGPrinter.h?rev=281640&r1=281639&r2=281640&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/CFGPrinter.h (original)
+++ llvm/trunk/include/llvm/Analysis/CFGPrinter.h Thu Sep 15 13:35:27 2016
@@ -7,6 +7,10 @@
//
//===----------------------------------------------------------------------===//
//
+// This file defines a 'dot-cfg' analysis pass, which emits the
+// cfg.<fnname>.dot file for each function in the program, with a graph of the
+// CFG for that function.
+//
// This file defines external functions that can be called to explicitly
// instantiate the CFG printer.
//
@@ -19,9 +23,34 @@
#include "llvm/IR/Constants.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Instructions.h"
+#include "llvm/IR/PassManager.h"
#include "llvm/Support/GraphWriter.h"
namespace llvm {
+class CFGViewerPass
+ : public PassInfoMixin<CFGViewerPass> {
+public:
+ PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
+};
+
+class CFGOnlyViewerPass
+ : public PassInfoMixin<CFGOnlyViewerPass> {
+public:
+ PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
+};
+
+class CFGPrinterPass
+ : public PassInfoMixin<CFGPrinterPass> {
+public:
+ PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
+};
+
+class CFGOnlyPrinterPass
+ : public PassInfoMixin<CFGOnlyPrinterPass> {
+public:
+ PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
+};
+
template<>
struct DOTGraphTraits<const Function*> : public DefaultDOTGraphTraits {
@@ -152,8 +181,8 @@ struct DOTGraphTraits<const Function*> :
namespace llvm {
class FunctionPass;
- FunctionPass *createCFGPrinterPass ();
- FunctionPass *createCFGOnlyPrinterPass ();
+ FunctionPass *createCFGPrinterLegacyPassPass ();
+ FunctionPass *createCFGOnlyPrinterLegacyPassPass ();
} // End llvm namespace
#endif
Modified: llvm/trunk/include/llvm/InitializePasses.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/InitializePasses.h?rev=281640&r1=281639&r2=281640&view=diff
==============================================================================
--- llvm/trunk/include/llvm/InitializePasses.h (original)
+++ llvm/trunk/include/llvm/InitializePasses.h Thu Sep 15 13:35:27 2016
@@ -80,11 +80,11 @@ void initializeBoundsCheckingPass(PassRe
void initializeBranchFolderPassPass(PassRegistry&);
void initializeBranchProbabilityInfoWrapperPassPass(PassRegistry&);
void initializeBreakCriticalEdgesPass(PassRegistry&);
-void initializeCFGOnlyPrinterPass(PassRegistry&);
-void initializeCFGOnlyViewerPass(PassRegistry&);
-void initializeCFGPrinterPass(PassRegistry&);
+void initializeCFGOnlyViewerLegacyPassPass(PassRegistry&);
+void initializeCFGPrinterLegacyPassPass(PassRegistry&);
+void initializeCFGOnlyPrinterLegacyPassPass(PassRegistry&);
void initializeCFGSimplifyPassPass(PassRegistry&);
-void initializeCFGViewerPass(PassRegistry&);
+void initializeCFGViewerLegacyPassPass(PassRegistry&);
void initializeCFLAndersAAWrapperPassPass(PassRegistry&);
void initializeCFLSteensAAWrapperPassPass(PassRegistry&);
void initializeCallGraphDOTPrinterPass(PassRegistry&);
Modified: llvm/trunk/lib/Analysis/Analysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/Analysis.cpp?rev=281640&r1=281639&r2=281640&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/Analysis.cpp (original)
+++ llvm/trunk/lib/Analysis/Analysis.cpp Thu Sep 15 13:35:27 2016
@@ -30,10 +30,10 @@ void llvm::initializeAnalysis(PassRegist
initializeCallGraphPrinterLegacyPassPass(Registry);
initializeCallGraphViewerPass(Registry);
initializeCostModelAnalysisPass(Registry);
- initializeCFGViewerPass(Registry);
- initializeCFGPrinterPass(Registry);
- initializeCFGOnlyViewerPass(Registry);
- initializeCFGOnlyPrinterPass(Registry);
+ initializeCFGViewerLegacyPassPass(Registry);
+ initializeCFGPrinterLegacyPassPass(Registry);
+ initializeCFGOnlyViewerLegacyPassPass(Registry);
+ initializeCFGOnlyPrinterLegacyPassPass(Registry);
initializeCFLAndersAAWrapperPassPass(Registry);
initializeCFLSteensAAWrapperPassPass(Registry);
initializeDependenceAnalysisWrapperPassPass(Registry);
Modified: llvm/trunk/lib/Analysis/CFGPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/CFGPrinter.cpp?rev=281640&r1=281639&r2=281640&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/CFGPrinter.cpp (original)
+++ llvm/trunk/lib/Analysis/CFGPrinter.cpp Thu Sep 15 13:35:27 2016
@@ -23,10 +23,10 @@
using namespace llvm;
namespace {
- struct CFGViewer : public FunctionPass {
+ struct CFGViewerLegacyPass : public FunctionPass {
static char ID; // Pass identifcation, replacement for typeid
- CFGViewer() : FunctionPass(ID) {
- initializeCFGOnlyViewerPass(*PassRegistry::getPassRegistry());
+ CFGViewerLegacyPass() : FunctionPass(ID) {
+ initializeCFGViewerLegacyPassPass(*PassRegistry::getPassRegistry());
}
bool runOnFunction(Function &F) override {
@@ -42,14 +42,21 @@ namespace {
};
}
-char CFGViewer::ID = 0;
-INITIALIZE_PASS(CFGViewer, "view-cfg", "View CFG of function", false, true)
+char CFGViewerLegacyPass::ID = 0;
+INITIALIZE_PASS(CFGViewerLegacyPass, "view-cfg", "View CFG of function", false, true)
+
+PreservedAnalyses CFGViewerPass::run(Function &F,
+ FunctionAnalysisManager &AM) {
+ F.viewCFG();
+ return PreservedAnalyses::all();
+}
+
namespace {
- struct CFGOnlyViewer : public FunctionPass {
+ struct CFGOnlyViewerLegacyPass : public FunctionPass {
static char ID; // Pass identifcation, replacement for typeid
- CFGOnlyViewer() : FunctionPass(ID) {
- initializeCFGOnlyViewerPass(*PassRegistry::getPassRegistry());
+ CFGOnlyViewerLegacyPass() : FunctionPass(ID) {
+ initializeCFGOnlyViewerLegacyPassPass(*PassRegistry::getPassRegistry());
}
bool runOnFunction(Function &F) override {
@@ -65,29 +72,39 @@ namespace {
};
}
-char CFGOnlyViewer::ID = 0;
-INITIALIZE_PASS(CFGOnlyViewer, "view-cfg-only",
+char CFGOnlyViewerLegacyPass::ID = 0;
+INITIALIZE_PASS(CFGOnlyViewerLegacyPass, "view-cfg-only",
"View CFG of function (with no function bodies)", false, true)
+PreservedAnalyses CFGOnlyViewerPass::run(Function &F,
+ FunctionAnalysisManager &AM) {
+ F.viewCFGOnly();
+ return PreservedAnalyses::all();
+}
+
+static void writeCFGToDotFile(Function &F) {
+ std::string Filename = ("cfg." + F.getName() + ".dot").str();
+ errs() << "Writing '" << Filename << "'...";
+
+ std::error_code EC;
+ raw_fd_ostream File(Filename, EC, sys::fs::F_Text);
+
+ if (!EC)
+ WriteGraph(File, (const Function*)&F);
+ else
+ errs() << " error opening file for writing!";
+ errs() << "\n";
+}
+
namespace {
- struct CFGPrinter : public FunctionPass {
+ struct CFGPrinterLegacyPass : public FunctionPass {
static char ID; // Pass identification, replacement for typeid
- CFGPrinter() : FunctionPass(ID) {
- initializeCFGPrinterPass(*PassRegistry::getPassRegistry());
+ CFGPrinterLegacyPass() : FunctionPass(ID) {
+ initializeCFGPrinterLegacyPassPass(*PassRegistry::getPassRegistry());
}
bool runOnFunction(Function &F) override {
- std::string Filename = ("cfg." + F.getName() + ".dot").str();
- errs() << "Writing '" << Filename << "'...";
-
- std::error_code EC;
- raw_fd_ostream File(Filename, EC, sys::fs::F_Text);
-
- if (!EC)
- WriteGraph(File, (const Function*)&F);
- else
- errs() << " error opening file for writing!";
- errs() << "\n";
+ writeCFGToDotFile(F);
return false;
}
@@ -99,29 +116,25 @@ namespace {
};
}
-char CFGPrinter::ID = 0;
-INITIALIZE_PASS(CFGPrinter, "dot-cfg", "Print CFG of function to 'dot' file",
+char CFGPrinterLegacyPass::ID = 0;
+INITIALIZE_PASS(CFGPrinterLegacyPass, "dot-cfg", "Print CFG of function to 'dot' file",
false, true)
+PreservedAnalyses CFGPrinterPass::run(Function &F,
+ FunctionAnalysisManager &AM) {
+ writeCFGToDotFile(F);
+ return PreservedAnalyses::all();
+}
+
namespace {
- struct CFGOnlyPrinter : public FunctionPass {
+ struct CFGOnlyPrinterLegacyPass : public FunctionPass {
static char ID; // Pass identification, replacement for typeid
- CFGOnlyPrinter() : FunctionPass(ID) {
- initializeCFGOnlyPrinterPass(*PassRegistry::getPassRegistry());
+ CFGOnlyPrinterLegacyPass() : FunctionPass(ID) {
+ initializeCFGOnlyPrinterLegacyPassPass(*PassRegistry::getPassRegistry());
}
bool runOnFunction(Function &F) override {
- std::string Filename = ("cfg." + F.getName() + ".dot").str();
- errs() << "Writing '" << Filename << "'...";
-
- std::error_code EC;
- raw_fd_ostream File(Filename, EC, sys::fs::F_Text);
-
- if (!EC)
- WriteGraph(File, (const Function*)&F, true);
- else
- errs() << " error opening file for writing!";
- errs() << "\n";
+ writeCFGToDotFile(F);
return false;
}
void print(raw_ostream &OS, const Module* = nullptr) const override {}
@@ -132,11 +145,17 @@ namespace {
};
}
-char CFGOnlyPrinter::ID = 0;
-INITIALIZE_PASS(CFGOnlyPrinter, "dot-cfg-only",
+char CFGOnlyPrinterLegacyPass::ID = 0;
+INITIALIZE_PASS(CFGOnlyPrinterLegacyPass, "dot-cfg-only",
"Print CFG of function to 'dot' file (with no function bodies)",
false, true)
+PreservedAnalyses CFGOnlyPrinterPass::run(Function &F,
+ FunctionAnalysisManager &AM) {
+ writeCFGToDotFile(F);
+ return PreservedAnalyses::all();
+}
+
/// viewCFG - This function is meant for use from the debugger. You can just
/// say 'call F->viewCFG()' and a ghostview window should pop up from the
/// program, displaying the CFG of the current function. This depends on there
@@ -155,11 +174,11 @@ void Function::viewCFGOnly() const {
ViewGraph(this, "cfg" + getName(), true);
}
-FunctionPass *llvm::createCFGPrinterPass () {
- return new CFGPrinter();
+FunctionPass *llvm::createCFGPrinterLegacyPassPass () {
+ return new CFGPrinterLegacyPass();
}
-FunctionPass *llvm::createCFGOnlyPrinterPass () {
- return new CFGOnlyPrinter();
+FunctionPass *llvm::createCFGOnlyPrinterLegacyPassPass () {
+ return new CFGOnlyPrinterLegacyPass();
}
Modified: llvm/trunk/lib/Passes/PassBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Passes/PassBuilder.cpp?rev=281640&r1=281639&r2=281640&view=diff
==============================================================================
--- llvm/trunk/lib/Passes/PassBuilder.cpp (original)
+++ llvm/trunk/lib/Passes/PassBuilder.cpp Thu Sep 15 13:35:27 2016
@@ -28,6 +28,7 @@
#include "llvm/Analysis/CFLSteensAliasAnalysis.h"
#include "llvm/Analysis/CGSCCPassManager.h"
#include "llvm/Analysis/CallGraph.h"
+#include "llvm/Analysis/CFGPrinter.h"
#include "llvm/Analysis/DemandedBits.h"
#include "llvm/Analysis/DependenceAnalysis.h"
#include "llvm/Analysis/DominanceFrontier.h"
Modified: llvm/trunk/lib/Passes/PassRegistry.def
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Passes/PassRegistry.def?rev=281640&r1=281639&r2=281640&view=diff
==============================================================================
--- llvm/trunk/lib/Passes/PassRegistry.def (original)
+++ llvm/trunk/lib/Passes/PassRegistry.def Thu Sep 15 13:35:27 2016
@@ -139,6 +139,8 @@ FUNCTION_PASS("consthoist", ConstantHois
FUNCTION_PASS("correlated-propagation", CorrelatedValuePropagationPass())
FUNCTION_PASS("dce", DCEPass())
FUNCTION_PASS("dse", DSEPass())
+FUNCTION_PASS("dot-cfg", CFGPrinterPass())
+FUNCTION_PASS("dot-cfg-only", CFGOnlyPrinterPass())
FUNCTION_PASS("early-cse", EarlyCSEPass(/*UseMemorySSA=*/false))
FUNCTION_PASS("early-cse-memssa", EarlyCSEPass(/*UseMemorySSA=*/true))
FUNCTION_PASS("gvn-hoist", GVNHoistPass())
@@ -190,6 +192,8 @@ FUNCTION_PASS("verify<domtree>", Dominat
FUNCTION_PASS("verify<loops>", LoopVerifierPass())
FUNCTION_PASS("verify<memoryssa>", MemorySSAVerifierPass())
FUNCTION_PASS("verify<regions>", RegionInfoVerifierPass())
+FUNCTION_PASS("view-cfg", CFGViewerPass())
+FUNCTION_PASS("view-cfg-only", CFGOnlyViewerPass())
#undef FUNCTION_PASS
#ifndef LOOP_ANALYSIS
Modified: llvm/trunk/test/Other/2007-06-05-PassID.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/2007-06-05-PassID.ll?rev=281640&r1=281639&r2=281640&view=diff
==============================================================================
--- llvm/trunk/test/Other/2007-06-05-PassID.ll (original)
+++ llvm/trunk/test/Other/2007-06-05-PassID.ll Thu Sep 15 13:35:27 2016
@@ -1,4 +1,5 @@
;RUN: opt < %s -analyze -dot-cfg-only 2>/dev/null
+;RUN: opt < %s -analyze -passes=dot-cfg-only 2>/dev/null
;PR 1497
define void @foo() {
More information about the llvm-commits
mailing list