Skip to content

Commit

Permalink
use orderedset to select largest type
Browse files Browse the repository at this point in the history
  • Loading branch information
jumormt committed Jan 27, 2024
1 parent 2bace31 commit af14e7a
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions svf-llvm/lib/ObjTypeInference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ const Type *ObjTypeInference::fwInferObjType(const Value *startValue)
auto vIt = _valueToInferSites.find(pUser);
if (canUpdate)
{
if (vIt != _valueToInferSites.end() && !vIt->second.empty())
if (vIt != _valueToInferSites.end())
{
infersites.insert(vIt->second.begin(), vIt->second.end());
}
Expand Down Expand Up @@ -352,11 +352,9 @@ const Type *ObjTypeInference::fwInferObjType(const Value *startValue)
if (canUpdate)
{
Set<const Type *> types;
for (const auto &infersite: infersites)
{
types.insert(infersiteToType(infersite));
}
_valueToInferSites[curValue] = infersites;
std::transform(infersites.begin(), infersites.end(), std::inserter(types, types.begin()),
infersiteToType);
_valueToInferSites[curValue] = SVFUtil::move(infersites);
_valueToType[curValue] = selectLargestType(types);
}
}
Expand Down Expand Up @@ -408,7 +406,7 @@ Set<const Value *> ObjTypeInference::bwfindAllocations(const Value *startValue)
auto vIt = _valueToAllocs.find(pUser);
if (canUpdate)
{
if (vIt != _valueToAllocs.end() && !vIt->second.empty())
if (vIt != _valueToAllocs.end())
{
sources.insert(vIt->second.begin(), vIt->second.end());
}
Expand Down Expand Up @@ -484,7 +482,7 @@ Set<const Value *> ObjTypeInference::bwfindAllocations(const Value *startValue)
}
if (canUpdate)
{
_valueToAllocs[curValue] = sources;
_valueToAllocs[curValue] = SVFUtil::move(sources);
}
}
Set<const Value *> srcs = _valueToAllocs[startValue];
Expand Down Expand Up @@ -558,13 +556,13 @@ const Type *ObjTypeInference::selectLargestType(Set<const Type *> &objTys)
{
if (objTys.empty()) return nullptr;
// map type size to types from with key in descending order
OrderedMap<u32_t, Set<const Type *>, std::greater<int>> typeSzToTypes;
OrderedMap<u32_t, OrderedSet<const Type *>, std::greater<int>> typeSzToTypes;
for (const Type *ty: objTys)
{
typeSzToTypes[objTyToNumFields(ty)].insert(ty);
}
assert(!typeSzToTypes.empty() && "typeSzToTypes cannot be empty");
Set<const Type *> largestTypes;
OrderedSet<const Type *> largestTypes;
std::tie(std::ignore, largestTypes) = *typeSzToTypes.begin();
assert(!largestTypes.empty() && "largest element cannot be empty");
return *largestTypes.begin();
Expand Down

0 comments on commit af14e7a

Please sign in to comment.