https://github.com/shahidiqbal13 updated https://github.com/llvm/llvm-project/pull/72654
>From b6bfb18e25c111baf6c95a0a4a1c3d667bb25b6d Mon Sep 17 00:00:00 2001 From: Shahid Iqbal <shahidiqba...@gmail.com> Date: Thu, 16 Nov 2023 11:26:43 -0500 Subject: [PATCH 1/7] TESTING infra --- clang/NOTES.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clang/NOTES.txt b/clang/NOTES.txt index f06ea8c70cd3409..c83dda52a1fc21e 100644 --- a/clang/NOTES.txt +++ b/clang/NOTES.txt @@ -4,6 +4,8 @@ //===---------------------------------------------------------------------===// +//TESTING git infra// + To time GCC preprocessing speed without output, use: "time gcc -MM file" This is similar to -Eonly. >From 7662d4f177d32c3159c1c48b11ce3884e4ea78c8 Mon Sep 17 00:00:00 2001 From: Shahid Iqbal <shahidiqba...@gmail.com> Date: Fri, 17 Nov 2023 09:26:31 -0500 Subject: [PATCH 2/7] PR#72453 : Exceeding maximum file name length --- llvm/include/llvm/Analysis/DOTGraphTraitsPass.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h b/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h index 07c08bc1cc3bcb6..f78d8ff52ee3932 100644 --- a/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h +++ b/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h @@ -17,6 +17,8 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/GraphWriter.h" +#define MAX_FILENAME_LEN 255 + namespace llvm { /// Default traits class for extracting a graph from an analysis pass. @@ -94,7 +96,7 @@ void printGraphForFunction(Function &F, GraphT Graph, StringRef Name, raw_fd_ostream File(Filename, EC, sys::fs::OF_TextWithCRLF); std::string GraphName = DOTGraphTraits<GraphT>::getGraphName(Graph); - if (!EC) + if (!EC && (Filename.length() <= MAX_FILENAME_LEN )) WriteGraph(File, Graph, IsSimple, GraphName + " for '" + F.getName() + "' function"); else @@ -280,7 +282,7 @@ class DOTGraphTraitsModulePrinterWrapperPass : public ModulePass { raw_fd_ostream File(Filename, EC, sys::fs::OF_TextWithCRLF); std::string Title = DOTGraphTraits<GraphT>::getGraphName(Graph); - if (!EC) + if (!EC && (Filename.length() <= MAX_FILENAME_LEN )) WriteGraph(File, Graph, IsSimple, Title); else errs() << " error opening file for writing!"; @@ -310,7 +312,7 @@ void WriteDOTGraphToFile(Function &F, GraphT &&Graph, std::string GraphName = DOTGraphTraits<GraphT>::getGraphName(Graph); std::string Title = GraphName + " for '" + F.getName().str() + "' function"; - if (!EC) + if (!EC && (Filename.length() <= MAX_FILENAME_LEN )) WriteGraph(File, Graph, IsSimple, Title); else errs() << " error opening file for writing!"; >From d3d33e5bfe907b761ecb9065fe45b698c3ce0672 Mon Sep 17 00:00:00 2001 From: Shahid Iqbal <shahidiqba...@gmail.com> Date: Fri, 17 Nov 2023 09:48:43 -0500 Subject: [PATCH 3/7] Reverted the earlier test text --- clang/NOTES.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/clang/NOTES.txt b/clang/NOTES.txt index c83dda52a1fc21e..f06ea8c70cd3409 100644 --- a/clang/NOTES.txt +++ b/clang/NOTES.txt @@ -4,8 +4,6 @@ //===---------------------------------------------------------------------===// -//TESTING git infra// - To time GCC preprocessing speed without output, use: "time gcc -MM file" This is similar to -Eonly. >From 41c19e2ceee80cce8a60d0fd869958a0783ddb7f Mon Sep 17 00:00:00 2001 From: Shahid Iqbal <shahidiqba...@gmail.com> Date: Fri, 17 Nov 2023 10:06:52 -0500 Subject: [PATCH 4/7] Code refactoring --- llvm/include/llvm/Analysis/DOTGraphTraitsPass.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h b/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h index f78d8ff52ee3932..f7ab6df3b4dd819 100644 --- a/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h +++ b/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h @@ -96,7 +96,7 @@ void printGraphForFunction(Function &F, GraphT Graph, StringRef Name, raw_fd_ostream File(Filename, EC, sys::fs::OF_TextWithCRLF); std::string GraphName = DOTGraphTraits<GraphT>::getGraphName(Graph); - if (!EC && (Filename.length() <= MAX_FILENAME_LEN )) + if (!EC && (Filename.length() <= MAX_FILENAME_LEN)) WriteGraph(File, Graph, IsSimple, GraphName + " for '" + F.getName() + "' function"); else @@ -282,7 +282,7 @@ class DOTGraphTraitsModulePrinterWrapperPass : public ModulePass { raw_fd_ostream File(Filename, EC, sys::fs::OF_TextWithCRLF); std::string Title = DOTGraphTraits<GraphT>::getGraphName(Graph); - if (!EC && (Filename.length() <= MAX_FILENAME_LEN )) + if (!EC && (Filename.length() <= MAX_FILENAME_LEN)) WriteGraph(File, Graph, IsSimple, Title); else errs() << " error opening file for writing!"; @@ -312,7 +312,7 @@ void WriteDOTGraphToFile(Function &F, GraphT &&Graph, std::string GraphName = DOTGraphTraits<GraphT>::getGraphName(Graph); std::string Title = GraphName + " for '" + F.getName().str() + "' function"; - if (!EC && (Filename.length() <= MAX_FILENAME_LEN )) + if (!EC && (Filename.length() <= MAX_FILENAME_LEN)) WriteGraph(File, Graph, IsSimple, Title); else errs() << " error opening file for writing!"; >From 74f8c4e1f05de8449e0b27507f8a541e4695b3f4 Mon Sep 17 00:00:00 2001 From: Shahid Iqbal <shahidiqba...@gmail.com> Date: Sat, 18 Nov 2023 06:33:12 -0500 Subject: [PATCH 5/7] Updated fix --- .../llvm/Analysis/DOTGraphTraitsPass.h | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h b/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h index f7ab6df3b4dd819..6731bef9678d272 100644 --- a/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h +++ b/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h @@ -17,7 +17,7 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/GraphWriter.h" -#define MAX_FILENAME_LEN 255 +static std::vector<std::string> nameObj; namespace llvm { @@ -85,10 +85,29 @@ struct DOTGraphTraitsViewer StringRef Name; }; +static void shortenFileName(std::string &FN, unsigned char len = 250) { + + FN = FN.substr(0, len); + if (nameObj.empty()) + nameObj.push_back(FN); + + else { + for (auto it = nameObj.begin(); it != nameObj.end(); it++) { + if (*it == FN) { + FN = FN.substr(0, --len); + nameObj.push_back(FN); + break; + } + } + } +} + template <typename GraphT> 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 << "'..."; @@ -96,7 +115,7 @@ void printGraphForFunction(Function &F, GraphT Graph, StringRef Name, raw_fd_ostream File(Filename, EC, sys::fs::OF_TextWithCRLF); std::string GraphName = DOTGraphTraits<GraphT>::getGraphName(Graph); - if (!EC && (Filename.length() <= MAX_FILENAME_LEN)) + if (!EC) WriteGraph(File, Graph, IsSimple, GraphName + " for '" + F.getName() + "' function"); else @@ -274,6 +293,7 @@ class DOTGraphTraitsModulePrinterWrapperPass : public ModulePass { bool runOnModule(Module &M) override { GraphT Graph = AnalysisGraphTraitsT::getGraph(&getAnalysis<AnalysisT>()); + shortenFileName(Name); std::string Filename = Name + ".dot"; std::error_code EC; @@ -282,7 +302,7 @@ class DOTGraphTraitsModulePrinterWrapperPass : public ModulePass { raw_fd_ostream File(Filename, EC, sys::fs::OF_TextWithCRLF); std::string Title = DOTGraphTraits<GraphT>::getGraphName(Graph); - if (!EC && (Filename.length() <= MAX_FILENAME_LEN)) + if (!EC) WriteGraph(File, Graph, IsSimple, Title); else errs() << " error opening file for writing!"; @@ -303,7 +323,9 @@ class DOTGraphTraitsModulePrinterWrapperPass : public ModulePass { template <typename GraphT> 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 << "'..."; @@ -312,7 +334,7 @@ void WriteDOTGraphToFile(Function &F, GraphT &&Graph, std::string GraphName = DOTGraphTraits<GraphT>::getGraphName(Graph); std::string Title = GraphName + " for '" + F.getName().str() + "' function"; - if (!EC && (Filename.length() <= MAX_FILENAME_LEN)) + if (!EC) WriteGraph(File, Graph, IsSimple, Title); else errs() << " error opening file for writing!"; >From 3945cf93bd2bbca9f32516a5041c7ac69cafd289 Mon Sep 17 00:00:00 2001 From: Shahid Iqbal <shahidiqba...@gmail.com> Date: Mon, 20 Nov 2023 04:39:39 -0500 Subject: [PATCH 6/7] Updated fix with set as DS --- llvm/include/llvm/Analysis/DOTGraphTraitsPass.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h b/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h index 6731bef9678d272..90e20210a117af9 100644 --- a/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h +++ b/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h @@ -16,8 +16,9 @@ #include "llvm/Analysis/CFGPrinter.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/GraphWriter.h" +#include <unordered_set> -static std::vector<std::string> nameObj; +static std::unordered_set<std::string> nameObj; namespace llvm { @@ -89,15 +90,18 @@ static void shortenFileName(std::string &FN, unsigned char len = 250) { FN = FN.substr(0, len); if (nameObj.empty()) - nameObj.push_back(FN); + nameObj.insert(FN); else { - for (auto it = nameObj.begin(); it != nameObj.end(); it++) { - if (*it == FN) { + auto strLen = FN.length(); + while (strLen > 0) { + if (auto it = nameObj.find(FN); it != nameObj.end()) { FN = FN.substr(0, --len); - nameObj.push_back(FN); + } else { + nameObj.insert(FN); break; } + strLen--; } } } >From f6ecae531c84c76a0d89cef981b3e4176da4871f Mon Sep 17 00:00:00 2001 From: Shahid Iqbal <shahidiqba...@gmail.com> Date: Tue, 21 Nov 2023 04:03:05 -0500 Subject: [PATCH 7/7] updated , removed earlier check --- .../llvm/Analysis/DOTGraphTraitsPass.h | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h b/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h index 90e20210a117af9..182cc118670425d 100644 --- a/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h +++ b/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h @@ -89,20 +89,16 @@ struct DOTGraphTraitsViewer static void shortenFileName(std::string &FN, unsigned char len = 250) { FN = FN.substr(0, len); - if (nameObj.empty()) - nameObj.insert(FN); - - else { - 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--; + + 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--; } } _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits