-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' into f-GetAsJsonRefactor
- Loading branch information
Showing
12 changed files
with
2,316 additions
and
89 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
76 changes: 76 additions & 0 deletions
76
include/phasar/PhasarLLVM/DataFlow/IfdsIde/FunctionDataFlowFacts.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#include "phasar/Utils/DefaultValue.h" | ||
|
||
#include "llvm/ADT/StringMap.h" | ||
#include "llvm/ADT/StringRef.h" | ||
|
||
#include <cstdint> | ||
#include <unordered_map> | ||
#include <variant> | ||
#include <vector> | ||
|
||
namespace psr::library_summary { | ||
|
||
struct Parameter { | ||
uint16_t Index{}; | ||
}; | ||
|
||
struct ReturnValue {}; | ||
|
||
struct DataFlowFact { | ||
DataFlowFact(Parameter Param) noexcept : Fact(Param) {} | ||
DataFlowFact(ReturnValue Ret) noexcept : Fact(Ret) {} | ||
|
||
std::variant<Parameter, ReturnValue> Fact; | ||
}; | ||
|
||
class FunctionDataFlowFacts { | ||
public: | ||
using ParamaterMappingTy = | ||
std::unordered_map<uint32_t, std::vector<DataFlowFact>>; | ||
|
||
FunctionDataFlowFacts() noexcept = default; | ||
|
||
// insert a set of data flow facts | ||
void insertSet(llvm::StringRef FuncKey, uint32_t Index, | ||
std::vector<DataFlowFact> OutSet) { | ||
Fdff[FuncKey].try_emplace(Index, std::move(OutSet)); | ||
} | ||
|
||
// insert a single data flow fact | ||
void addElement(llvm::StringRef FuncKey, uint32_t Index, DataFlowFact Out) { | ||
Fdff[FuncKey][Index].emplace_back(Out); | ||
} | ||
|
||
// get outset for a function an the parameter index | ||
[[nodiscard]] const std::vector<DataFlowFact> & | ||
getDataFlowFacts(llvm::StringRef FuncKey, uint32_t Index) const { | ||
auto It = Fdff.find(FuncKey); | ||
if (It != Fdff.end()) { | ||
auto Itt = It->second.find(Index); | ||
return Itt->second; | ||
} | ||
|
||
return getDefaultValue<std::vector<DataFlowFact>>(); | ||
} | ||
|
||
[[nodiscard]] auto begin() const noexcept { return Fdff.begin(); } | ||
[[nodiscard]] auto end() const noexcept { return Fdff.end(); } | ||
|
||
[[nodiscard]] size_t size() const noexcept { return Fdff.size(); } | ||
[[nodiscard]] bool empty() const noexcept { return size() == 0; } | ||
|
||
private: | ||
[[nodiscard]] const auto & | ||
getDataFlowFactsOrEmpty(llvm::StringRef FuncKey) const { | ||
auto It = Fdff.find(FuncKey); | ||
if (It != Fdff.end()) { | ||
return It->second; | ||
} | ||
|
||
return getDefaultValue<ParamaterMappingTy>(); | ||
} | ||
|
||
llvm::StringMap<ParamaterMappingTy> Fdff; | ||
}; | ||
|
||
} // namespace psr::library_summary |
74 changes: 74 additions & 0 deletions
74
include/phasar/PhasarLLVM/DataFlow/IfdsIde/LLVMFunctionDataFlowFacts.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#include "phasar/PhasarLLVM/DB/LLVMProjectIRDB.h" | ||
#include "phasar/PhasarLLVM/DataFlow/IfdsIde/FunctionDataFlowFacts.h" | ||
#include "phasar/Utils/DefaultValue.h" | ||
|
||
#include "llvm/IR/Argument.h" | ||
#include "llvm/IR/Function.h" | ||
|
||
#include <unordered_map> | ||
#include <vector> | ||
|
||
namespace psr::library_summary { | ||
|
||
class LLVMFunctionDataFlowFacts; | ||
[[nodiscard]] LLVMFunctionDataFlowFacts | ||
readFromFDFF(const FunctionDataFlowFacts &Fdff, const LLVMProjectIRDB &Irdb); | ||
|
||
class LLVMFunctionDataFlowFacts { | ||
public: | ||
LLVMFunctionDataFlowFacts() noexcept = default; | ||
using ParamaterMappingTy = FunctionDataFlowFacts::ParamaterMappingTy; | ||
|
||
/// insert a set of data flow facts | ||
void insertSet(const llvm::Function *Fun, uint32_t Index, | ||
std::vector<DataFlowFact> OutSet) { | ||
|
||
LLVMFdff[Fun].try_emplace(Index, std::move(OutSet)); | ||
} | ||
void insertSet(const llvm::Function *Fun, const llvm::Argument *Arg, | ||
std::vector<DataFlowFact> OutSet) { | ||
|
||
insertSet(Fun, Arg->getArgNo(), std::move(OutSet)); | ||
} | ||
|
||
void addElement(const llvm::Function *Fun, uint32_t Index, DataFlowFact Out) { | ||
LLVMFdff[Fun][Index].emplace_back(Out); | ||
} | ||
void addElement(const llvm::Function *Fun, const llvm::Argument *Arg, | ||
DataFlowFact Out) { | ||
addElement(Fun, Arg->getArgNo(), Out); | ||
} | ||
|
||
[[nodiscard]] bool contains(const llvm::Function *Fn) { | ||
return LLVMFdff.count(Fn); | ||
} | ||
|
||
[[nodiscard]] const std::vector<DataFlowFact> & | ||
getFacts(const llvm::Function *Fun, uint32_t Index) { | ||
auto Iter = LLVMFdff.find(Fun); | ||
if (Iter != LLVMFdff.end()) { | ||
return Iter->second[Index]; | ||
} | ||
return getDefaultValue<std::vector<DataFlowFact>>(); | ||
} | ||
[[nodiscard]] const std::vector<DataFlowFact> & | ||
getFacts(const llvm::Function *Fun, const llvm::Argument *Arg) { | ||
return getFacts(Fun, Arg->getArgNo()); | ||
} | ||
|
||
[[nodiscard]] const ParamaterMappingTy & | ||
getFactsForFunction(const llvm::Function *Fun) { | ||
auto Iter = LLVMFdff.find(Fun); | ||
if (Iter != LLVMFdff.end()) { | ||
return Iter->second; | ||
} | ||
return getDefaultValue<ParamaterMappingTy>(); | ||
} | ||
|
||
friend LLVMFunctionDataFlowFacts | ||
readFromFDFF(const FunctionDataFlowFacts &Fdff, const LLVMProjectIRDB &Irdb); | ||
|
||
private: | ||
std::unordered_map<const llvm::Function *, ParamaterMappingTy> LLVMFdff; | ||
}; | ||
} // namespace psr::library_summary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#pragma once | ||
|
||
namespace psr { | ||
namespace library_summary { | ||
class FunctionDataFlowFacts; | ||
} // namespace library_summary | ||
|
||
[[nodiscard]] const library_summary::FunctionDataFlowFacts &getLibCSummary(); | ||
} // namespace psr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
lib/PhasarLLVM/DataFlow/IfdsIde/LLVMFunctionDataFlowFacts.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include "phasar/PhasarLLVM/DataFlow/IfdsIde/LLVMFunctionDataFlowFacts.h" | ||
|
||
using namespace psr; | ||
using namespace psr::library_summary; | ||
|
||
LLVMFunctionDataFlowFacts | ||
library_summary::readFromFDFF(const FunctionDataFlowFacts &Fdff, | ||
const LLVMProjectIRDB &Irdb) { | ||
LLVMFunctionDataFlowFacts Llvmfdff; | ||
Llvmfdff.LLVMFdff.reserve(Fdff.size()); | ||
|
||
for (const auto &It : Fdff) { | ||
if (const llvm::Function *Fun = Irdb.getFunction(It.first())) { | ||
Llvmfdff.LLVMFdff.try_emplace(Fun, It.second); | ||
} | ||
} | ||
return Llvmfdff; | ||
} |
Oops, something went wrong.