Skip to content

Commit

Permalink
Final Impls, DIBTH Identifier Impl not working
Browse files Browse the repository at this point in the history
  • Loading branch information
mxHuber committed Apr 10, 2024
1 parent 7f79712 commit a347b7d
Show file tree
Hide file tree
Showing 21 changed files with 288 additions and 227 deletions.
5 changes: 0 additions & 5 deletions include/phasar/ControlFlow/CallGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,10 @@
#include "phasar/Utils/StableVector.h"
#include "phasar/Utils/Utilities.h"

#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/IR/Function.h"
#include "llvm/Support/raw_ostream.h"

#include "nlohmann/json.hpp"

#include <cstddef>
#include <functional>
#include <string>
#include <utility>
Expand Down
4 changes: 3 additions & 1 deletion include/phasar/PhasarLLVM/Passes/GeneralStatisticsAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ struct GeneralStatistics {
"instead")]] const std::set<const llvm::Instruction *> &
getRetResInstructions() const;

[[nodiscard]] [[deprecated("Please use printAsJson() instead")]] nlohmann::json getAsJson() const;
[[nodiscard]] [[deprecated(
"Please use printAsJson() instead")]] nlohmann::json
getAsJson() const;
void printAsJson(llvm::raw_ostream &OS = llvm::outs()) const;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,55 +17,30 @@
#include <string>

namespace psr {
struct GeneralStatisticsAnalysisData {
struct GeneralStatisticsAnalysisSerializer {
size_t Functions = 0;
size_t ExternalFunctions = 0;
size_t FunctionDefinitions = 0;
size_t AddressTakenFunctions = 0;
size_t Globals = 0;
size_t GlobalConsts = 0;
size_t ExternalGlobals = 0;
size_t GlobalsDefinitions = 0;
size_t BasicBlocks = 0;
size_t AllocationSites = 0;
size_t CallSites = 0;
size_t DebugIntrinsics = 0;
size_t Instructions = 0;
size_t StoreInstructions = 0;
size_t LoadInstructions = 0;
size_t MemIntrinsics = 0;
size_t Branches = 0;
size_t Switches = 0;
size_t GetElementPtrs = 0;
size_t LandingPads = 0;
size_t PhiNodes = 0;
size_t NumInlineAsm = 0;
size_t IndCalls = 0;
size_t TotalNumOperands = 0;
size_t TotalNumUses = 0;
size_t TotalNumPredecessorBBs = 0;
size_t TotalNumSuccessorBBs = 0;
size_t MaxNumOperands = 0;
size_t MaxNumUses = 0;
size_t MaxNumPredecessorBBs = 0;
size_t MaxNumSuccessorBBs = 0;
size_t NumInstWithMultipleUses = 0;
size_t NumInstsUsedOutsideBB = 0;
size_t NonVoidInsts = 0;
// const llvm::Type * , serialized with MetadataID
std::set<size_t> AllocatedTypes;
// const llvm::Instruction * , serialized with MetadataID
std::set<size_t> AllocaInstructions;
// const llvm::Instruction * , serialized with MetadataID
std::set<size_t> RetResInstructions;
size_t NumberOfAllocaInstructions = 0;
std::string ModuleName{};

GeneralStatisticsAnalysisData() noexcept = default;
GeneralStatisticsAnalysisSerializer() noexcept = default;
void printAsJson(llvm::raw_ostream &OS);

static GeneralStatisticsAnalysisData deserializeJson(const llvm::Twine &Path);
static GeneralStatisticsAnalysisData
loadJsonString(llvm::StringRef JsonAsString);
};

} // namespace psr
Expand Down
3 changes: 1 addition & 2 deletions include/phasar/PhasarLLVM/Pointer/LLVMAliasSetData.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

namespace psr {
struct LLVMAliasSetData {
// AliasSets
std::vector<std::string> AliasSets;
std::vector<std::vector<std::string>> AliasSets;
std::vector<std::string> AnalyzedFunctions;

LLVMAliasSetData() noexcept = default;
Expand Down
6 changes: 6 additions & 0 deletions include/phasar/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ class LLVMTypeHierarchy
* @param IRDB ProjectIRCompiledDB object.
*/
LLVMTypeHierarchy(LLVMProjectIRDB &IRDB);
LLVMTypeHierarchy(LLVMProjectIRDB &IRDB,
const LLVMTypeHierarchyData &SerializedData);

/**
* @brief Creates a LLVMStructTypeHierarchy based on the
Expand Down Expand Up @@ -195,6 +197,10 @@ class LLVMTypeHierarchy

[[nodiscard]] bool hasVFTable(const llvm::StructType *Type) const override;

[[nodiscard]] const auto &getAllVTables() const noexcept {
return TypeVFTMap;
}

[[nodiscard]] const LLVMVFTable *
getVFTable(const llvm::StructType *Type) const override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
namespace psr {
struct LLVMTypeHierarchyData {
std::string PhasarConfigJsonTypeHierarchyID;
// key = vertex, value = edges
llvm::StringMap<std::vector<std::string>> TypeGraph;

LLVMTypeHierarchyData() noexcept = default;
Expand Down
2 changes: 1 addition & 1 deletion include/phasar/PhasarLLVM/TypeHierarchy/LLVMVFTableData.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct LLVMVFTableData {
std::vector<std::string> VFT;

LLVMVFTableData() noexcept = default;
void printAsJson(llvm::raw_ostream &OS);
void printAsJson(llvm::raw_ostream &OS) const;

static LLVMVFTableData deserializeJson(const llvm::Twine &Path);
static LLVMVFTableData loadJsonString(llvm::StringRef JsonAsString);
Expand Down
11 changes: 1 addition & 10 deletions include/phasar/Pointer/AliasInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,16 +241,7 @@ class AliasInfoRef : public AnalysisPropertiesMixin<AliasInfoRef<V, N>> {
static_cast<const ConcreteAA *>(AA)->print(OS);
},
[](const void *AA) {
/// TODO:
/// durchlesen, wie type traits in c++ funktionieren
/// ->in aliasinfo.h checken ob getAsJson existiert, ansonsten leeres
/// JSON

if (static_cast<const ConcreteAA *>(AA)->getAsJson()) {
return static_cast<const ConcreteAA *>(AA)->getAsJson();
}

return nlohmann::json();
return static_cast<const ConcreteAA *>(AA)->getAsJson();
},
[](const void *AA, llvm::raw_ostream &OS) {
static_cast<const ConcreteAA *>(AA)->printAsJson(OS);
Expand Down
54 changes: 24 additions & 30 deletions lib/PhasarLLVM/Passes/GeneralStatisticsAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include "phasar/PhasarLLVM/Passes/GeneralStatisticsAnalysis.h"

#include "phasar/PhasarLLVM/Passes/GeneralStatisticsAnalysisData.h"
#include "phasar/PhasarLLVM/Passes/GeneralStatisticsAnalysisSerializer.h"
#include "phasar/PhasarLLVM/Utils/LLVMShorthands.h"
#include "phasar/Utils/Logger.h"
#include "phasar/Utils/PAMMMacros.h"
Expand Down Expand Up @@ -288,36 +288,30 @@ GeneralStatistics::getRetResInstructions() const {
return RetResInstructions;
}

/// TODO: Fabian fragen, welche Impl hier zu verwenden ist.
/// Alte Impl:
/*
nlohmann::json GeneralStatistics::getAsJson() const {
nlohmann::json J;
J["ModuleName"] = ModuleName;
J["Instructions"] = Instructions;
J["Functions"] = Functions;
J["ExternalFunctions"] = ExternalFunctions;
J["FunctionDefinitions"] = FunctionDefinitions;
J["AddressTakenFunctions"] = AddressTakenFunctions;
J["AllocaInstructions"] = AllocaInstructions.size();
J["CallSites"] = CallSites;
J["IndirectCallSites"] = IndCalls;
J["MemoryIntrinsics"] = MemIntrinsics;
J["DebugIntrinsics"] = DebugIntrinsics;
J["InlineAssembly"] = NumInlineAsm;
J["GlobalVariables"] = Globals;
J["Branches"] = Branches;
J["GetElementPtrs"] = GetElementPtrs;
J["BasicBlocks"] = BasicBlocks;
J["PhiNodes"] = PhiNodes;
J["LandingPads"] = LandingPads;
J["GlobalConsts"] = GlobalConsts;
return J;
}
*/
void GeneralStatistics::printAsJson(llvm::raw_ostream &OS) const {
GeneralStatisticsAnalysisData Data;
Data.printAsJson(OS);
GeneralStatisticsAnalysisSerializer Ser;

Ser.Functions = Functions;
Ser.ExternalFunctions = ExternalFunctions;
Ser.FunctionDefinitions = FunctionDefinitions;
Ser.AddressTakenFunctions = AddressTakenFunctions;
Ser.Globals = Globals;
Ser.GlobalConsts = GlobalConsts;
Ser.BasicBlocks = BasicBlocks;
Ser.CallSites = CallSites;
Ser.DebugIntrinsics = DebugIntrinsics;
Ser.Instructions = Instructions;
Ser.MemIntrinsics = MemIntrinsics;
Ser.Branches = Branches;
Ser.GetElementPtrs = GetElementPtrs;
Ser.LandingPads = LandingPads;
Ser.PhiNodes = PhiNodes;
Ser.NumInlineAsm = NumInlineAsm;
Ser.IndCalls = IndCalls;
Ser.NumberOfAllocaInstructions = AllocaInstructions.size();
Ser.ModuleName = ModuleName;

Ser.printAsJson(OS);
}

nlohmann::json GeneralStatistics::getAsJson() const {
Expand Down
138 changes: 0 additions & 138 deletions lib/PhasarLLVM/Passes/GeneralStatisticsAnalysisData.cpp

This file was deleted.

Loading

0 comments on commit a347b7d

Please sign in to comment.