Skip to content

Commit 707d337

Browse files
committed
Minor changes
1 parent 2dbf124 commit 707d337

16 files changed

Lines changed: 63 additions & 73 deletions

File tree

external/googletest

Submodule googletest updated 329 files

include/phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "boost/container/flat_set.hpp"
3131
#include "boost/graph/adjacency_list.hpp"
3232

33+
#include "llvm/ADT/DenseSet.h"
3334
#include "llvm/ADT/StringRef.h"
3435
#include "llvm/IR/Constants.h"
3536
#include "llvm/IR/InstrTypes.h"
@@ -72,7 +73,7 @@ class LLVMBasedICFG
7273
LLVMTypeHierarchy *TH;
7374
LLVMPointsToInfo *PT;
7475
std::unique_ptr<Resolver> Res;
75-
std::unordered_set<const llvm::Function *> VisitedFunctions;
76+
llvm::DenseSet<const llvm::Function *> VisitedFunctions;
7677
llvm::SmallPtrSet<llvm::Function *, 2> UserEntryPoints;
7778

7879
GlobalCtorTy GlobalCtors;
@@ -88,7 +89,7 @@ class LLVMBasedICFG
8889

8990
// Map indirect calls to the number of possible targets found for it. Fixpoint
9091
// is not reached when more targets are found.
91-
std::unordered_map<const llvm::Instruction *, unsigned> IndirectCalls;
92+
llvm::DenseMap<const llvm::Instruction *, unsigned> IndirectCalls;
9293
// The VertexProperties for our call-graph.
9394
struct VertexProperties {
9495
const llvm::Function *F = nullptr;

include/phasar/PhasarLLVM/ControlFlow/Resolver/CHAResolver.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ class CHAResolver : public Resolver {
3333

3434
~CHAResolver() override = default;
3535

36-
std::set<const llvm::Function *>
37-
resolveVirtualCall(const llvm::CallBase *CallSite) override;
36+
FunctionSetTy resolveVirtualCall(const llvm::CallBase *CallSite) override;
3837
};
3938
} // namespace psr
4039

include/phasar/PhasarLLVM/ControlFlow/Resolver/DTAResolver.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ class DTAResolver : public CHAResolver {
6161

6262
~DTAResolver() override = default;
6363

64-
std::set<const llvm::Function *>
65-
resolveVirtualCall(const llvm::CallBase *CallSite) override;
64+
FunctionSetTy resolveVirtualCall(const llvm::CallBase *CallSite) override;
6665

6766
void otherInst(const llvm::Instruction *Inst) override;
6867
};

include/phasar/PhasarLLVM/ControlFlow/Resolver/NOResolver.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,14 @@ class NOResolver final : public Resolver {
3636

3737
void preCall(const llvm::Instruction *Inst) override;
3838

39-
void handlePossibleTargets(
40-
const llvm::CallBase *CallSite,
41-
std::set<const llvm::Function *> &PossibleTargets) override;
39+
void handlePossibleTargets(const llvm::CallBase *CallSite,
40+
FunctionSetTy &PossibleTargets) override;
4241

4342
void postCall(const llvm::Instruction *Inst) override;
4443

45-
std::set<const llvm::Function *>
46-
resolveVirtualCall(const llvm::CallBase *CallSite) override;
44+
FunctionSetTy resolveVirtualCall(const llvm::CallBase *CallSite) override;
4745

48-
std::set<const llvm::Function *>
49-
resolveFunctionPointer(const llvm::CallBase *CallSite) override;
46+
FunctionSetTy resolveFunctionPointer(const llvm::CallBase *CallSite) override;
5047

5148
void otherInst(const llvm::Instruction *Inst) override;
5249
};

include/phasar/PhasarLLVM/ControlFlow/Resolver/OTFResolver.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,14 @@ class OTFResolver : public CHAResolver {
5353

5454
void preCall(const llvm::Instruction *Inst) override;
5555

56-
void handlePossibleTargets(
57-
const llvm::CallBase *CallSite,
58-
std::set<const llvm::Function *> &CalleeTargets) override;
56+
void handlePossibleTargets(const llvm::CallBase *CallSite,
57+
FunctionSetTy &CalleeTargets) override;
5958

6059
void postCall(const llvm::Instruction *Inst) override;
6160

62-
std::set<const llvm::Function *>
63-
resolveVirtualCall(const llvm::CallBase *CallSite) override;
61+
FunctionSetTy resolveVirtualCall(const llvm::CallBase *CallSite) override;
6462

65-
std::set<const llvm::Function *>
66-
resolveFunctionPointer(const llvm::CallBase *CallSite) override;
63+
FunctionSetTy resolveFunctionPointer(const llvm::CallBase *CallSite) override;
6764

6865
static std::set<const llvm::Type *>
6966
getReachableTypes(const LLVMPointsToInfo::PointsToSetTy &Values);

include/phasar/PhasarLLVM/ControlFlow/Resolver/RTAResolver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class RTAResolver : public CHAResolver {
3434

3535
~RTAResolver() override = default;
3636

37-
virtual std::set<const llvm::Function *>
37+
virtual FunctionSetTy
3838
resolveVirtualCall(const llvm::CallBase *CallSite) override;
3939
};
4040
} // namespace psr

include/phasar/PhasarLLVM/ControlFlow/Resolver/Resolver.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include <set>
2121
#include <string>
2222

23+
#include "llvm/ADT/DenseSet.h"
24+
2325
namespace llvm {
2426
class Instruction;
2527
class CallBase;
@@ -49,23 +51,22 @@ class Resolver {
4951
const llvm::CallBase *CallSite);
5052

5153
public:
54+
using FunctionSetTy = llvm::SmallDenseSet<const llvm::Function *, 4>;
55+
5256
Resolver(ProjectIRDB &IRDB, LLVMTypeHierarchy &TH);
5357

5458
virtual ~Resolver() = default;
5559

5660
virtual void preCall(const llvm::Instruction *Inst);
5761

58-
virtual void
59-
handlePossibleTargets(const llvm::CallBase *CallSite,
60-
std::set<const llvm::Function *> &PossibleTargets);
62+
virtual void handlePossibleTargets(const llvm::CallBase *CallSite,
63+
FunctionSetTy &PossibleTargets);
6164

6265
virtual void postCall(const llvm::Instruction *Inst);
6366

64-
virtual std::set<const llvm::Function *>
65-
resolveVirtualCall(const llvm::CallBase *CallSite) = 0;
67+
virtual FunctionSetTy resolveVirtualCall(const llvm::CallBase *CallSite) = 0;
6668

67-
virtual std::set<const llvm::Function *>
68-
resolveFunctionPointer(const llvm::CallBase *CallSite);
69+
virtual FunctionSetTy resolveFunctionPointer(const llvm::CallBase *CallSite);
6970

7071
virtual void otherInst(const llvm::Instruction *Inst);
7172
};

lib/PhasarLLVM/ControlFlow/LLVMBasedICFG.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,11 @@ void LLVMBasedICFG::processFunction(const llvm::Function *F, Resolver &Resolver,
244244
}
245245

246246
// iterate all instructions of the current function
247+
Resolver::FunctionSetTy PossibleTargets;
247248
for (const auto &I : llvm::instructions(F)) {
248249
if (const auto *CS = llvm::dyn_cast<llvm::CallBase>(&I)) {
249250
Resolver.preCall(&I);
250251

251-
set<const llvm::Function *> PossibleTargets;
252252
// check if function call can be resolved statically
253253
if (CS->getCalledFunction() != nullptr) {
254254
PossibleTargets.insert(CS->getCalledFunction());
@@ -272,8 +272,8 @@ void LLVMBasedICFG::processFunction(const llvm::Function *F, Resolver &Resolver,
272272
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG)
273273
<< "Found dynamic call-site: "
274274
<< " " << llvmIRToString(CS));
275-
// IndirectCalls[CS] = 0;
276-
IndirectCalls.emplace(CS, 0);
275+
IndirectCalls[CS] = 0;
276+
277277
FixpointReached = false;
278278
continue;
279279
}
@@ -308,6 +308,7 @@ void LLVMBasedICFG::processFunction(const llvm::Function *F, Resolver &Resolver,
308308
} else {
309309
Resolver.otherInst(&I);
310310
}
311+
PossibleTargets.clear();
311312
}
312313
}
313314

@@ -332,17 +333,15 @@ bool LLVMBasedICFG::constructDynamicCall(const llvm::Instruction *I,
332333
if (const auto *CallSite = llvm::dyn_cast<llvm::CallBase>(I)) {
333334
Resolver.preCall(I);
334335

335-
set<const llvm::Function *> PossibleTargets;
336336
// the function call must be resolved dynamically
337337
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG)
338338
<< "Looking into dynamic call-site: ");
339339
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) << " " << llvmIRToString(I));
340340
// call the resolve routine
341-
if (LLVMBasedICFG::isVirtualFunctionCall(CallSite)) {
342-
PossibleTargets = Resolver.resolveVirtualCall(CallSite);
343-
} else {
344-
PossibleTargets = Resolver.resolveFunctionPointer(CallSite);
345-
}
341+
342+
auto PossibleTargets = LLVMBasedICFG::isVirtualFunctionCall(CallSite)
343+
? Resolver.resolveVirtualCall(CallSite)
344+
: Resolver.resolveFunctionPointer(CallSite);
346345

347346
assert(IndirectCalls.count(I));
348347

@@ -656,10 +655,9 @@ LLVMBasedICFG::getCallersOf(const llvm::Function *F) const {
656655
set<const llvm::Instruction *>
657656
LLVMBasedICFG::getCallsFromWithin(const llvm::Function *F) const {
658657
set<const llvm::Instruction *> CallSites;
659-
for (llvm::const_inst_iterator I = llvm::inst_begin(F), E = llvm::inst_end(F);
660-
I != E; ++I) {
661-
if (llvm::isa<llvm::CallBase>(*I)) {
662-
CallSites.insert(&(*I));
658+
for (const auto &I : llvm::instructions(F)) {
659+
if (llvm::isa<llvm::CallBase>(I)) {
660+
CallSites.insert(&I);
663661
}
664662
}
665663
return CallSites;

lib/PhasarLLVM/ControlFlow/Resolver/CHAResolver.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ using namespace psr;
3131
CHAResolver::CHAResolver(ProjectIRDB &IRDB, LLVMTypeHierarchy &TH)
3232
: Resolver(IRDB, TH) {}
3333

34-
set<const llvm::Function *>
35-
CHAResolver::resolveVirtualCall(const llvm::CallBase *CallSite) {
34+
auto CHAResolver::resolveVirtualCall(const llvm::CallBase *CallSite)
35+
-> FunctionSetTy {
3636
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) << "Call virtual function: ");
3737
// Leading to SEGFAULT in Unittests. Error only when run in Debug mode
3838
// << llvmIRToString(CallSite));
@@ -58,7 +58,7 @@ CHAResolver::resolveVirtualCall(const llvm::CallBase *CallSite) {
5858
// also insert all possible subtypes vtable entries
5959
auto FallbackTys = Resolver::TH->getSubTypes(ReceiverTy);
6060

61-
set<const llvm::Function *> PossibleCallees;
61+
FunctionSetTy PossibleCallees;
6262

6363
for (const auto &FallbackTy : FallbackTys) {
6464
const auto *Target =

0 commit comments

Comments
 (0)