|
16 | 16 | #include "llvm/Analysis/CFGPrinter.h"
|
17 | 17 | #include "llvm/Support/FileSystem.h"
|
18 | 18 | #include "llvm/Support/GraphWriter.h"
|
| 19 | +#include <unordered_set> |
| 20 | + |
| 21 | +static std::unordered_set<std::string> nameObj; |
19 | 22 |
|
20 | 23 | namespace llvm {
|
21 | 24 |
|
@@ -83,10 +86,28 @@ struct DOTGraphTraitsViewer
|
83 | 86 | StringRef Name;
|
84 | 87 | };
|
85 | 88 |
|
| 89 | +static void shortenFileName(std::string &FN, unsigned char len = 250) { |
| 90 | + |
| 91 | + FN = FN.substr(0, len); |
| 92 | + |
| 93 | + auto strLen = FN.length(); |
| 94 | + while (strLen > 0) { |
| 95 | + if (auto it = nameObj.find(FN); it != nameObj.end()) { |
| 96 | + FN = FN.substr(0, --len); |
| 97 | + } else { |
| 98 | + nameObj.insert(FN); |
| 99 | + break; |
| 100 | + } |
| 101 | + strLen--; |
| 102 | + } |
| 103 | +} |
| 104 | + |
86 | 105 | template <typename GraphT>
|
87 | 106 | void printGraphForFunction(Function &F, GraphT Graph, StringRef Name,
|
88 | 107 | bool IsSimple) {
|
89 |
| - std::string Filename = Name.str() + "." + F.getName().str() + ".dot"; |
| 108 | + std::string Filename = Name.str() + "." + F.getName().str(); |
| 109 | + shortenFileName(Filename); |
| 110 | + Filename = Filename + ".dot"; |
90 | 111 | std::error_code EC;
|
91 | 112 |
|
92 | 113 | errs() << "Writing '" << Filename << "'...";
|
@@ -272,6 +293,7 @@ class DOTGraphTraitsModulePrinterWrapperPass : public ModulePass {
|
272 | 293 |
|
273 | 294 | bool runOnModule(Module &M) override {
|
274 | 295 | GraphT Graph = AnalysisGraphTraitsT::getGraph(&getAnalysis<AnalysisT>());
|
| 296 | + shortenFileName(Name); |
275 | 297 | std::string Filename = Name + ".dot";
|
276 | 298 | std::error_code EC;
|
277 | 299 |
|
@@ -301,7 +323,9 @@ class DOTGraphTraitsModulePrinterWrapperPass : public ModulePass {
|
301 | 323 | template <typename GraphT>
|
302 | 324 | void WriteDOTGraphToFile(Function &F, GraphT &&Graph,
|
303 | 325 | std::string FileNamePrefix, bool IsSimple) {
|
304 |
| - std::string Filename = FileNamePrefix + "." + F.getName().str() + ".dot"; |
| 326 | + std::string Filename = FileNamePrefix + "." + F.getName().str(); |
| 327 | + shortenFileName(Filename); |
| 328 | + Filename = Filename + ".dot"; |
305 | 329 | std::error_code EC;
|
306 | 330 |
|
307 | 331 | errs() << "Writing '" << Filename << "'...";
|
|
0 commit comments