Skip to content

Commit b214b9f

Browse files
committed
extended general statistics with global consts information
1 parent 492a1e3 commit b214b9f

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

include/phasar/PhasarLLVM/Passes/GeneralStatisticsAnalysis.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class GeneralStatistics {
4949
size_t Branches = 0;
5050
size_t GetElementPtrs = 0;
5151
size_t PhiNodes = 0;
52+
size_t GlobalConsts = 0;
5253
std::set<const llvm::Type *> AllocatedTypes;
5354
std::set<const llvm::Instruction *> AllocaInstructions;
5455
std::set<const llvm::Instruction *> RetResInstructions;
@@ -90,6 +91,11 @@ class GeneralStatistics {
9091
*/
9192
[[nodiscard]] size_t getGlobals() const;
9293

94+
/**
95+
* @brief Returns the number of constant globals.
96+
*/
97+
[[nodiscard]] size_t getGlobalConsts() const;
98+
9399
/**
94100
* @brief Returns the number of memory intrinsics.
95101
*/

lib/PhasarLLVM/Passes/GeneralStatisticsAnalysis.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ GeneralStatistics GeneralStatisticsAnalysis::runOnModule(llvm::Module &M) {
130130
++Stats.GlobalPointers;
131131
}
132132
++Stats.Globals;
133+
if (Global.isConstant()) {
134+
++Stats.GlobalConsts;
135+
}
133136
}
134137
// register stuff in PAMM
135138
// For performance reasons (and out of sheer convenience) we simply initialize
@@ -167,6 +170,7 @@ GeneralStatistics GeneralStatisticsAnalysis::runOnModule(llvm::Module &M) {
167170
PHASAR_LOG_LEVEL(INFO, "Functions : " << Stats.Functions);
168171
PHASAR_LOG_LEVEL(INFO, "Globals : " << Stats.Globals);
169172
PHASAR_LOG_LEVEL(INFO, "Global Pointer : " << Stats.GlobalPointers);
173+
PHASAR_LOG_LEVEL(INFO, "Global Consts : " << Stats.GlobalConsts);
170174
PHASAR_LOG_LEVEL(INFO, "Memory Intrinsics : " << Stats.MemIntrinsics);
171175
PHASAR_LOG_LEVEL(INFO,
172176
"Store Instructions : " << Stats.StoreInstructions);
@@ -197,6 +201,8 @@ size_t GeneralStatistics::getFunctions() const { return Functions; }
197201

198202
size_t GeneralStatistics::getGlobals() const { return Globals; }
199203

204+
size_t GeneralStatistics::getGlobalConsts() const { return GlobalConsts; }
205+
200206
size_t GeneralStatistics::getMemoryIntrinsics() const { return MemIntrinsics; }
201207

202208
size_t GeneralStatistics::getStoreInstructions() const {
@@ -233,6 +239,8 @@ nlohmann::json GeneralStatistics::getAsJson() const {
233239
J["GetElementPtrs"] = GetElementPtrs;
234240
J["BasicBlocks"] = BasicBlocks;
235241
J["PhiNodes"] = PhiNodes;
242+
J["GlobalConsts"] = GlobalConsts;
243+
J["GlobalPointers"] = GlobalPointers;
236244
return J;
237245
}
238246

@@ -244,6 +252,8 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
244252
<< "LLVM IR instructions:\t" << Statistics.Instructions << "\n"
245253
<< "Functions:\t" << Statistics.Functions << "\n"
246254
<< "Global Variables:\t" << Statistics.Globals << "\n"
255+
<< "Global Variable Consts:\t" << Statistics.GlobalConsts << "\n"
256+
<< "Global Pointers:\t" << Statistics.GlobalPointers << "\n"
247257
<< "Alloca Instructions:\t" << Statistics.AllocaInstructions.size()
248258
<< "\n"
249259
<< "Call Sites:\t" << Statistics.CallSites << "\n"

0 commit comments

Comments
 (0)