#ifndef LLVM_ANALYSIS_DOTGRAPHTRAITSPASS_H
#define LLVM_ANALYSIS_DOTGRAPHTRAITSPASS_H
#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 {
template <typename Result, typename GraphT = Result *>
struct DefaultAnalysisGraphTraits { … };
template <typename GraphT>
void viewGraphForFunction(Function &F, GraphT Graph, StringRef Name,
bool IsSimple) { … }
template <typename AnalysisT, bool IsSimple,
typename GraphT = typename AnalysisT::Result *,
typename AnalysisGraphTraitsT =
DefaultAnalysisGraphTraits<typename AnalysisT::Result &, GraphT>>
struct DOTGraphTraitsViewer
: PassInfoMixin<DOTGraphTraitsViewer<AnalysisT, IsSimple, GraphT,
AnalysisGraphTraitsT>> {
DOTGraphTraitsViewer(StringRef GraphName) : … { … }
virtual bool processFunction(Function &F,
const typename AnalysisT::Result &Result) { … }
PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM) { … };
protected:
~DOTGraphTraitsViewer() { … }
private:
StringRef Name;
};
static inline void shortenFileName(std::string &FN, unsigned char len = 250) { … }
template <typename GraphT>
void printGraphForFunction(Function &F, GraphT Graph, StringRef Name,
bool IsSimple) { … }
template <typename AnalysisT, bool IsSimple,
typename GraphT = typename AnalysisT::Result *,
typename AnalysisGraphTraitsT =
DefaultAnalysisGraphTraits<typename AnalysisT::Result &, GraphT>>
struct DOTGraphTraitsPrinter
: PassInfoMixin<DOTGraphTraitsPrinter<AnalysisT, IsSimple, GraphT,
AnalysisGraphTraitsT>> {
DOTGraphTraitsPrinter(StringRef GraphName) : … { … }
virtual bool processFunction(Function &F,
const typename AnalysisT::Result &Result) { … }
PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM) { … };
protected:
~DOTGraphTraitsPrinter() { … }
private:
StringRef Name;
};
template <typename AnalysisT, typename GraphT = AnalysisT *>
struct LegacyDefaultAnalysisGraphTraits { … };
template <typename AnalysisT, bool IsSimple, typename GraphT = AnalysisT *,
typename AnalysisGraphTraitsT =
LegacyDefaultAnalysisGraphTraits<AnalysisT, GraphT>>
class DOTGraphTraitsViewerWrapperPass : public FunctionPass {
public:
DOTGraphTraitsViewerWrapperPass(StringRef GraphName, char &ID)
: … { … }
virtual bool processFunction(Function &F, AnalysisT &Analysis) { … }
bool runOnFunction(Function &F) override { … }
void getAnalysisUsage(AnalysisUsage &AU) const override { … }
private:
std::string Name;
};
template <typename AnalysisT, bool IsSimple, typename GraphT = AnalysisT *,
typename AnalysisGraphTraitsT =
LegacyDefaultAnalysisGraphTraits<AnalysisT, GraphT>>
class DOTGraphTraitsPrinterWrapperPass : public FunctionPass {
public:
DOTGraphTraitsPrinterWrapperPass(StringRef GraphName, char &ID)
: … { … }
virtual bool processFunction(Function &F, AnalysisT &Analysis) { … }
bool runOnFunction(Function &F) override { … }
void getAnalysisUsage(AnalysisUsage &AU) const override { … }
private:
std::string Name;
};
template <typename AnalysisT, bool IsSimple, typename GraphT = AnalysisT *,
typename AnalysisGraphTraitsT =
LegacyDefaultAnalysisGraphTraits<AnalysisT, GraphT>>
class DOTGraphTraitsModuleViewerWrapperPass : public ModulePass {
public:
DOTGraphTraitsModuleViewerWrapperPass(StringRef GraphName, char &ID)
: … { … }
bool runOnModule(Module &M) override { … }
void getAnalysisUsage(AnalysisUsage &AU) const override { … }
private:
std::string Name;
};
template <typename AnalysisT, bool IsSimple, typename GraphT = AnalysisT *,
typename AnalysisGraphTraitsT =
LegacyDefaultAnalysisGraphTraits<AnalysisT, GraphT>>
class DOTGraphTraitsModulePrinterWrapperPass : public ModulePass {
public:
DOTGraphTraitsModulePrinterWrapperPass(StringRef GraphName, char &ID)
: … { … }
bool runOnModule(Module &M) override { … }
void getAnalysisUsage(AnalysisUsage &AU) const override { … }
private:
std::string Name;
};
template <typename GraphT>
void WriteDOTGraphToFile(Function &F, GraphT &&Graph,
std::string FileNamePrefix, bool IsSimple) { … }
}
#endif