diff --git a/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h b/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h index 07c08bc1cc3bc..182cc11867042 100644 --- a/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h +++ b/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h @@ -16,6 +16,9 @@ #include "llvm/Analysis/CFGPrinter.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/GraphWriter.h" +#include + +static std::unordered_set nameObj; namespace llvm { @@ -83,10 +86,28 @@ struct DOTGraphTraitsViewer StringRef Name; }; +static void shortenFileName(std::string &FN, unsigned char len = 250) { + + FN = FN.substr(0, len); + + auto strLen = FN.length(); + while (strLen > 0) { + if (auto it = nameObj.find(FN); it != nameObj.end()) { + FN = FN.substr(0, --len); + } else { + nameObj.insert(FN); + break; + } + strLen--; + } +} + template void printGraphForFunction(Function &F, GraphT Graph, StringRef Name, bool IsSimple) { - std::string Filename = Name.str() + "." + F.getName().str() + ".dot"; + std::string Filename = Name.str() + "." + F.getName().str(); + shortenFileName(Filename); + Filename = Filename + ".dot"; std::error_code EC; errs() << "Writing '" << Filename << "'..."; @@ -272,6 +293,7 @@ class DOTGraphTraitsModulePrinterWrapperPass : public ModulePass { bool runOnModule(Module &M) override { GraphT Graph = AnalysisGraphTraitsT::getGraph(&getAnalysis()); + shortenFileName(Name); std::string Filename = Name + ".dot"; std::error_code EC; @@ -301,7 +323,9 @@ class DOTGraphTraitsModulePrinterWrapperPass : public ModulePass { template void WriteDOTGraphToFile(Function &F, GraphT &&Graph, std::string FileNamePrefix, bool IsSimple) { - std::string Filename = FileNamePrefix + "." + F.getName().str() + ".dot"; + std::string Filename = FileNamePrefix + "." + F.getName().str(); + shortenFileName(Filename); + Filename = Filename + ".dot"; std::error_code EC; errs() << "Writing '" << Filename << "'...";