Skip to content

Commit

Permalink
Low-hanging fruits in resolvers
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianbs96 committed Apr 20, 2024
1 parent 355af01 commit f5e3ecb
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 19 deletions.
4 changes: 1 addition & 3 deletions include/phasar/PhasarLLVM/ControlFlow/Resolver/OTFResolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,14 @@ class Value;

namespace psr {

class LLVMBasedICFG;
class LLVMTypeHierarchy;

class OTFResolver : public Resolver {
protected:
LLVMBasedICFG &ICF;
LLVMAliasInfoRef PT;

public:
OTFResolver(LLVMProjectIRDB &IRDB, LLVMTypeHierarchy &TH, LLVMBasedICFG &ICF,
OTFResolver(LLVMProjectIRDB &IRDB, LLVMTypeHierarchy &TH,
LLVMAliasInfoRef PT);

~OTFResolver() override = default;
Expand Down
8 changes: 4 additions & 4 deletions include/phasar/PhasarLLVM/ControlFlow/Resolver/Resolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ namespace psr {
class LLVMProjectIRDB;
class LLVMTypeHierarchy;
enum class CallGraphAnalysisType;
class LLVMBasedICFG;
class LLVMPointsToInfo;

[[nodiscard]] std::optional<unsigned>
Expand Down Expand Up @@ -83,9 +82,10 @@ class Resolver {

[[nodiscard]] virtual std::string str() const = 0;

static std::unique_ptr<Resolver>
create(CallGraphAnalysisType Ty, LLVMProjectIRDB *IRDB, LLVMTypeHierarchy *TH,
LLVMBasedICFG *ICF = nullptr, LLVMAliasInfoRef PT = nullptr);
static std::unique_ptr<Resolver> create(CallGraphAnalysisType Ty,
LLVMProjectIRDB *IRDB,
LLVMTypeHierarchy *TH,
LLVMAliasInfoRef PT = nullptr);
};
} // namespace psr

Expand Down
2 changes: 1 addition & 1 deletion lib/PhasarLLVM/ControlFlow/LLVMBasedICFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ LLVMBasedICFG::LLVMBasedICFG(LLVMProjectIRDB *IRDB,
PT = PTOwn.asRef();
}

auto CGRes = Resolver::create(CGType, IRDB, this->TH.get(), this, PT);
auto CGRes = Resolver::create(CGType, IRDB, this->TH.get(), PT);
initialize(IRDB, *CGRes, EntryPoints, TH, S, IncludeGlobals);
}

Expand Down
6 changes: 3 additions & 3 deletions lib/PhasarLLVM/ControlFlow/Resolver/OTFResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
using namespace psr;

OTFResolver::OTFResolver(LLVMProjectIRDB &IRDB, LLVMTypeHierarchy &TH,
LLVMBasedICFG &ICF, LLVMAliasInfoRef PT)
: Resolver(IRDB, TH), ICF(ICF), PT(PT) {}
LLVMAliasInfoRef PT)
: Resolver(IRDB, TH), PT(PT) {}

void OTFResolver::preCall(const llvm::Instruction *Inst) {}

Expand All @@ -60,7 +60,7 @@ void OTFResolver::handlePossibleTargets(const llvm::CallBase *CallSite,
}
// handle return value
if (CalleeTarget->getReturnType()->isPointerTy()) {
for (const auto &ExitPoint : ICF.getExitPointsOf(CalleeTarget)) {
for (const auto &ExitPoint : psr::getAllExitPoints(CalleeTarget)) {
// get the function's return value
if (const auto *Ret = llvm::dyn_cast<llvm::ReturnInst>(ExitPoint)) {
// introduce alias to the returned value
Expand Down
5 changes: 1 addition & 4 deletions lib/PhasarLLVM/ControlFlow/Resolver/RTAResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ void RTAResolver::resolveAllocatedStructTypes() {
}

llvm::DenseSet<const llvm::StructType *> AllocatedStructTypes;
const llvm::StringSet<> MemAllocatingFunctions = {"_Znwm", "_Znam", "malloc",
"calloc", "realloc"};

for (const auto *Fun : IRDB.getAllFunctions()) {
for (const auto &Inst : llvm::instructions(Fun)) {
Expand All @@ -114,8 +112,7 @@ void RTAResolver::resolveAllocatedStructTypes() {
// check if an instance of a user-defined type is allocated on the
// heap

if (!MemAllocatingFunctions.contains(
CallSite->getCalledFunction()->getName())) {
if (!isHeapAllocatingFunction(CallSite->getCalledFunction())) {
continue;
}
/// TODO: Does this iteration over the users make sense?
Expand Down
6 changes: 2 additions & 4 deletions lib/PhasarLLVM/ControlFlow/Resolver/Resolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ auto Resolver::resolveFunctionPointer(const llvm::CallBase *CallSite)
FunctionSetTy CalleeTargets;

for (const auto *F : IRDB.getAllFunctions()) {
if (isConsistentCall(CallSite, F)) {
if (F->hasAddressTaken() && isConsistentCall(CallSite, F)) {
CalleeTargets.insert(F);
}
}
Expand All @@ -158,7 +158,6 @@ void Resolver::otherInst(const llvm::Instruction *Inst) {}
std::unique_ptr<Resolver> Resolver::create(CallGraphAnalysisType Ty,
LLVMProjectIRDB *IRDB,
LLVMTypeHierarchy *TH,
LLVMBasedICFG *ICF,
LLVMAliasInfoRef PT) {
assert(IRDB != nullptr);

Expand All @@ -179,9 +178,8 @@ std::unique_ptr<Resolver> Resolver::create(CallGraphAnalysisType Ty,
"The VTA callgraph algorithm is not implemented yet");
case CallGraphAnalysisType::OTF:
assert(TH != nullptr);
assert(ICF != nullptr);
assert(PT);
return std::make_unique<OTFResolver>(*IRDB, *TH, *ICF, PT);
return std::make_unique<OTFResolver>(*IRDB, *TH, PT);
case CallGraphAnalysisType::Invalid:
llvm::report_fatal_error("Invalid callgraph algorithm specified");
}
Expand Down

0 comments on commit f5e3ecb

Please sign in to comment.