Skip to content

Commit

Permalink
Implicit vertex index
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianbs96 committed Apr 20, 2024
1 parent fe605e9 commit 53e222e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct DIBasedTypeHierarchyData {
// DITypes and llvm::Function * are serialized by serializing their names and
// using the DebugInfoFinder to deserialize them

llvm::StringMap<size_t> TypeToVertex;
std::vector<std::string> VertexTypes;
std::vector<std::pair<uint32_t, uint32_t>> TransitiveDerivedIndex;
std::vector<std::string> Hierarchy;
std::vector<std::vector<std::string>> VTables;
Expand Down
32 changes: 21 additions & 11 deletions lib/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,17 +259,23 @@ static const llvm::DIType *stringToDIType(const LLVMProjectIRDB *IRDB,
llvm::report_fatal_error("DIType doesn't exist");
}

// NOLINTNEXTLINE
static constexpr char NullFunName[] = "__null__";

DIBasedTypeHierarchy::DIBasedTypeHierarchy(
const LLVMProjectIRDB *IRDB, const DIBasedTypeHierarchyData &SerializedData)
: TransitiveDerivedIndex(SerializedData.TransitiveDerivedIndex) {

VertexTypes.resize(SerializedData.TypeToVertex.size());
TypeToVertex.reserve(SerializedData.TypeToVertex.size());
for (const auto &Curr : SerializedData.TypeToVertex) {
const auto *Ty = stringToDICompositeType(IRDB, Curr.getKey());
TypeToVertex.try_emplace(Ty, Curr.getValue());
NameToType.try_emplace(Curr.getKey(), Ty);
VertexTypes.at(Curr.getValue()) = Ty;
VertexTypes.reserve(SerializedData.VertexTypes.size());
TypeToVertex.reserve(SerializedData.VertexTypes.size());
size_t Idx = 0;
for (const auto &Curr : SerializedData.VertexTypes) {
const auto *Ty = stringToDICompositeType(IRDB, Curr);
VertexTypes.push_back(Ty);
TypeToVertex.try_emplace(Ty, Idx);
NameToType.try_emplace(Curr, Ty);

++Idx;
}

Hierarchy.reserve(SerializedData.Hierarchy.size());
Expand All @@ -282,6 +288,9 @@ DIBasedTypeHierarchy::DIBasedTypeHierarchy(

CurrVTable.reserve(Curr.size());
for (const auto &FuncName : Curr) {
if (FuncName == NullFunName) {
CurrVTable.push_back(nullptr);
}
CurrVTable.push_back(IRDB->getFunction(FuncName));
}

Expand Down Expand Up @@ -368,9 +377,10 @@ DIBasedTypeHierarchy::getAsJson() const {
DIBasedTypeHierarchyData DIBasedTypeHierarchy::getTypeHierarchyData() const {
DIBasedTypeHierarchyData Data;

for (const auto &Curr : TypeToVertex) {
Data.TypeToVertex.try_emplace(getTypeName(Curr.getFirst()),
Curr.getSecond());
Data.VertexTypes.reserve(VertexTypes.size());

for (const auto &Curr : VertexTypes) {
Data.VertexTypes.push_back(getTypeName(Curr));
}

Data.TransitiveDerivedIndex = TransitiveDerivedIndex;
Expand All @@ -389,7 +399,7 @@ DIBasedTypeHierarchyData DIBasedTypeHierarchy::getTypeHierarchyData() const {
CurrVTableAsString.push_back(Func->getName().str());
continue;
}
CurrVTableAsString.emplace_back("Null");
CurrVTableAsString.emplace_back(NullFunName);
}

Data.VTables.push_back(std::move(CurrVTableAsString));
Expand Down
11 changes: 2 additions & 9 deletions lib/PhasarLLVM/TypeHierarchy/DIBasedTypeHierarchyData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ namespace psr {
static DIBasedTypeHierarchyData getDataFromJson(const nlohmann::json &Json) {
DIBasedTypeHierarchyData Data;

for (const auto &[Key, Value] : Json["TypeToVertex"].items()) {
Data.TypeToVertex.try_emplace(Key, Value.get<size_t>());
}
Data.VertexTypes = Json["VertexTypes"].get<std::vector<std::string>>();

Data.TransitiveDerivedIndex =
Json["TransitiveDerivedIndex"]
Expand All @@ -47,13 +45,8 @@ static DIBasedTypeHierarchyData getDataFromJson(const nlohmann::json &Json) {
void DIBasedTypeHierarchyData::printAsJson(llvm::raw_ostream &OS) {
nlohmann::json Json;

auto &JTypeToVertex = Json["TypeToVertex"];
for (const auto &Curr : TypeToVertex) {
JTypeToVertex[Curr.getKey()] = Curr.getValue();
}

Json["VertexTypes"] = VertexTypes;
Json["TransitiveDerivedIndex"] = TransitiveDerivedIndex;

Json["Hierarchy"] = Hierarchy;

auto &JVTables = Json["VTables"];
Expand Down

0 comments on commit 53e222e

Please sign in to comment.