Skip to content

Commit 08abd7a

Browse files
committed
Further speedup OTFResolver::resolveFunctionPointer
1 parent 707d337 commit 08abd7a

3 files changed

Lines changed: 21 additions & 3 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@
1919

2020
#include <set>
2121
#include <string>
22+
#include <unordered_map>
2223
#include <unordered_set>
2324
#include <utility>
2425
#include <vector>
2526

2627
#include "phasar/PhasarLLVM/ControlFlow/Resolver/CHAResolver.h"
2728
#include "phasar/PhasarLLVM/Pointer/LLVMPointsToInfo.h"
29+
#include "llvm/ADT/DenseSet.h"
30+
#include "llvm/ADT/TinyPtrVector.h"
2831

2932
namespace llvm {
3033
class Instruction;

lib/PhasarLLVM/ControlFlow/LLVMBasedICFG.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
#include <cassert>
18+
#include <chrono>
1819
#include <initializer_list>
1920
#include <memory>
2021
#include <ostream>

lib/PhasarLLVM/ControlFlow/Resolver/OTFResolver.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#include <memory>
1818

19+
#include "llvm/ADT/DenseMapInfo.h"
20+
#include "llvm/ADT/Hashing.h"
1921
#include "llvm/ADT/SmallPtrSet.h"
2022
#include "llvm/ADT/SmallVector.h"
2123
#include "llvm/IR/Constants.h"
@@ -138,9 +140,16 @@ auto OTFResolver::resolveFunctionPointer(const llvm::CallBase *CallSite)
138140
if (const auto *FTy = llvm::dyn_cast<llvm::FunctionType>(
139141
CallSite->getCalledOperand()->getType()->getPointerElementType())) {
140142

141-
const auto PTS = PT.getPointsToSet(CallSite->getCalledOperand());
143+
const auto PTS =
144+
PT.getPointsToSet(CallSite->getCalledOperand(), CallSite);
145+
146+
llvm::SmallVector<const llvm::GlobalVariable *, 2> GlobalVariableWL;
147+
llvm::SmallVector<const llvm::ConstantAggregate *> ConstantAggregateWL;
142148

143149
for (const auto *P : *PTS) {
150+
GlobalVariableWL.clear();
151+
ConstantAggregateWL.clear();
152+
144153
if (P->getType()->isPointerTy() &&
145154
P->getType()->getPointerElementType()->isFunctionTy()) {
146155
if (const auto *F = llvm::dyn_cast<llvm::Function>(P)) {
@@ -149,8 +158,7 @@ auto OTFResolver::resolveFunctionPointer(const llvm::CallBase *CallSite)
149158
}
150159
}
151160
}
152-
llvm::SmallVector<const llvm::GlobalVariable *> GlobalVariableWL;
153-
llvm::SmallVector<const llvm::ConstantAggregate *> ConstantAggregateWL;
161+
154162
if (const auto *CE = llvm::dyn_cast<llvm::ConstantExpr>(P)) {
155163
for (const auto &Op : CE->operands()) {
156164
if (const auto *GVOp = llvm::dyn_cast<llvm::GlobalVariable>(Op)) {
@@ -161,6 +169,11 @@ auto OTFResolver::resolveFunctionPointer(const llvm::CallBase *CallSite)
161169
if (const auto *GVP = llvm::dyn_cast<llvm::GlobalVariable>(P)) {
162170
GlobalVariableWL.push_back(GVP);
163171
}
172+
173+
if (GlobalVariableWL.empty()) {
174+
continue;
175+
}
176+
164177
for (const auto *GV : GlobalVariableWL) {
165178
if (!GV->hasInitializer()) {
166179
continue;
@@ -173,6 +186,7 @@ auto OTFResolver::resolveFunctionPointer(const llvm::CallBase *CallSite)
173186
}
174187
llvm::SmallPtrSet<const llvm::ConstantAggregate *, 4>
175188
VisitedConstantAggregates;
189+
176190
while (!ConstantAggregateWL.empty()) {
177191
const auto *ConstAggregateItem = ConstantAggregateWL.pop_back_val();
178192
// We may have already processed the item, avoid an infinite loop

0 commit comments

Comments
 (0)