9
9
10
10
#include " phasar/PhasarLLVM/Passes/GeneralStatisticsAnalysis.h"
11
11
12
+ #include " phasar/PhasarLLVM/Utils/AllocatedTypes.h"
12
13
#include " phasar/PhasarLLVM/Utils/LLVMShorthands.h"
13
14
#include " phasar/Utils/Logger.h"
14
15
#include " phasar/Utils/NlohmannLogging.h"
@@ -41,31 +42,6 @@ static bool isAddressTaken(const llvm::Function &Fun) noexcept {
41
42
return false ;
42
43
}
43
44
44
- template <typename Set>
45
- static void collectAllocatedTypes (const llvm::CallBase *CallSite, Set &Into) {
46
- for (const auto *User : CallSite->users ()) {
47
- if (const auto *Cast = llvm::dyn_cast<llvm::BitCastInst>(User);
48
- Cast && Cast->getDestTy ()->isPointerTy () &&
49
- !Cast->getDestTy ()->isOpaquePointerTy ()) {
50
- const auto *ElemTy = Cast->getDestTy ()->getNonOpaquePointerElementType ();
51
- if (ElemTy->isStructTy ()) {
52
- // finally check for ctor call
53
- for (const auto *User : Cast->users ()) {
54
- if (llvm::isa<llvm::CallBase>(User)) {
55
- // potential call to the structures ctor
56
- const auto *CTor = llvm::cast<llvm::CallBase>(User);
57
- if (CTor->getCalledFunction () &&
58
- CTor->getCalledFunction ()->getArg (0 )->getType () ==
59
- Cast->getDestTy ()) {
60
- Into.insert (ElemTy);
61
- }
62
- }
63
- }
64
- }
65
- }
66
- }
67
- }
68
-
69
45
llvm::AnalysisKey GeneralStatisticsAnalysis::Key; // NOLINT
70
46
GeneralStatistics GeneralStatisticsAnalysis::runOnModule (llvm::Module &M) {
71
47
PHASAR_LOG_LEVEL (INFO, " Running GeneralStatisticsAnalysis" );
@@ -131,7 +107,6 @@ GeneralStatistics GeneralStatisticsAnalysis::runOnModule(llvm::Module &M) {
131
107
// check for alloca instruction for possible types
132
108
if (const llvm::AllocaInst *Alloc =
133
109
llvm::dyn_cast<llvm::AllocaInst>(&I)) {
134
- Stats.AllocatedTypes .insert (Alloc->getAllocatedType ());
135
110
// do not add allocas from llvm internal functions
136
111
Stats.AllocaInstructions .insert (&I);
137
112
++Stats.AllocationSites ;
@@ -186,9 +161,6 @@ GeneralStatistics GeneralStatisticsAnalysis::runOnModule(llvm::Module &M) {
186
161
// do not add allocas from llvm internal functions
187
162
Stats.AllocaInstructions .insert (&I);
188
163
++Stats.AllocationSites ;
189
- // check if an instance of a user-defined type is allocated on the
190
- // heap
191
- collectAllocatedTypes (CallSite, Stats.AllocatedTypes );
192
164
}
193
165
} else {
194
166
++Stats.IndCalls ;
@@ -197,6 +169,9 @@ GeneralStatistics GeneralStatisticsAnalysis::runOnModule(llvm::Module &M) {
197
169
}
198
170
}
199
171
}
172
+
173
+ Stats.AllocatedTypes = collectAllocatedTypes (M);
174
+
200
175
// check for global pointers
201
176
for (const auto &Global : M.globals ()) {
202
177
++Stats.Globals ;
@@ -323,7 +298,7 @@ template <typename T> struct AlignNum {
323
298
}
324
299
};
325
300
template <typename T> AlignNum (llvm::StringRef, T) -> AlignNum<T>;
326
- AlignNum (llvm::StringRef, size_t , size_t )-> AlignNum<double >;
301
+ AlignNum (llvm::StringRef, size_t , size_t ) -> AlignNum<double >;
327
302
} // namespace
328
303
329
304
llvm::raw_ostream &psr::operator <<(llvm::raw_ostream &OS,
0 commit comments