|
19 | 19 |
|
20 | 20 | #include "llvm/Analysis/CFGPrinter.h"
|
21 | 21 | #include "llvm/ADT/PostOrderIterator.h"
|
| 22 | +#include "llvm/InitializePasses.h" |
| 23 | +#include "llvm/Pass.h" |
22 | 24 | #include "llvm/Support/CommandLine.h"
|
23 | 25 | #include "llvm/Support/FileSystem.h"
|
24 | 26 | #include "llvm/Support/GraphWriter.h"
|
@@ -109,6 +111,37 @@ PreservedAnalyses CFGOnlyViewerPass::run(Function &F,
|
109 | 111 | return PreservedAnalyses::all();
|
110 | 112 | }
|
111 | 113 |
|
| 114 | +namespace { |
| 115 | +struct CFGPrinterLegacyPass : public FunctionPass { |
| 116 | + static char ID; // Pass identification, replacement for typeid |
| 117 | + CFGPrinterLegacyPass() : FunctionPass(ID) { |
| 118 | + initializeCFGPrinterLegacyPassPass(*PassRegistry::getPassRegistry()); |
| 119 | + } |
| 120 | + |
| 121 | + bool runOnFunction(Function &F) override { |
| 122 | + if (!CFGFuncName.empty() && !F.getName().contains(CFGFuncName)) |
| 123 | + return false; |
| 124 | + auto *BPI = &getAnalysis<BranchProbabilityInfoWrapperPass>().getBPI(); |
| 125 | + auto *BFI = &getAnalysis<BlockFrequencyInfoWrapperPass>().getBFI(); |
| 126 | + writeCFGToDotFile(F, BFI, BPI, getMaxFreq(F, BFI)); |
| 127 | + return false; |
| 128 | + } |
| 129 | + |
| 130 | + void print(raw_ostream &OS, const Module * = nullptr) const override {} |
| 131 | + |
| 132 | + void getAnalysisUsage(AnalysisUsage &AU) const override { |
| 133 | + FunctionPass::getAnalysisUsage(AU); |
| 134 | + AU.addRequired<BlockFrequencyInfoWrapperPass>(); |
| 135 | + AU.addRequired<BranchProbabilityInfoWrapperPass>(); |
| 136 | + AU.setPreservesAll(); |
| 137 | + } |
| 138 | +}; |
| 139 | +} // namespace |
| 140 | + |
| 141 | +char CFGPrinterLegacyPass::ID = 0; |
| 142 | +INITIALIZE_PASS(CFGPrinterLegacyPass, "dot-cfg", |
| 143 | + "Print CFG of function to 'dot' file", false, true) |
| 144 | + |
112 | 145 | PreservedAnalyses CFGPrinterPass::run(Function &F,
|
113 | 146 | FunctionAnalysisManager &AM) {
|
114 | 147 | if (!CFGFuncName.empty() && !F.getName().contains(CFGFuncName))
|
@@ -156,6 +189,10 @@ void Function::viewCFGOnly(const BlockFrequencyInfo *BFI,
|
156 | 189 | viewCFG(true, BFI, BPI);
|
157 | 190 | }
|
158 | 191 |
|
| 192 | +FunctionPass *llvm::createCFGPrinterLegacyPassPass() { |
| 193 | + return new CFGPrinterLegacyPass(); |
| 194 | +} |
| 195 | + |
159 | 196 | /// Find all blocks on the paths which terminate with a deoptimize or
|
160 | 197 | /// unreachable (i.e. all blocks which are post-dominated by a deoptimize
|
161 | 198 | /// or unreachable). These paths are hidden if the corresponding cl::opts
|
|
0 commit comments