Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions llvm/include/llvm/Analysis/DOTGraphTraitsPass.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
#include "llvm/Analysis/CFGPrinter.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/GraphWriter.h"
#include <unordered_set>

static std::unordered_set<std::string> nameObj;

namespace llvm {

Expand Down Expand Up @@ -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 <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 << "'...";
Expand Down Expand Up @@ -272,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;

Expand Down Expand Up @@ -301,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 << "'...";
Expand Down