Skip to content
28 changes: 14 additions & 14 deletions include/phasar/PhasarLLVM/Passes/GeneralStatisticsAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ namespace psr {
class GeneralStatistics {
private:
friend class GeneralStatisticsAnalysis;
size_t functions = 0;
size_t globals = 0;
size_t basicblocks = 0;
size_t allocationsites = 0;
size_t callsites = 0;
size_t instructions = 0;
size_t storeInstructions = 0;
size_t loadInstructions = 0;
size_t memIntrinsic = 0;
size_t globalPointers = 0;
std::set<const llvm::Type *> allocatedTypes;
std::set<const llvm::Instruction *> allocaInstructions;
std::set<const llvm::Instruction *> retResInstructions;
size_t Functions = 0;
size_t Globals = 0;
size_t BasicBlocks = 0;
size_t AllocationSites = 0;
size_t CallSites = 0;
size_t Instructions = 0;
size_t StoreInstructions = 0;
size_t LoadInstructions = 0;
size_t MemIntrinsics = 0;
size_t GlobalPointers = 0;
std::set<const llvm::Type *> AllocatedTypes;
std::set<const llvm::Instruction *> AllocaInstructions;
std::set<const llvm::Instruction *> RetResInstructions;

public:
/**
Expand Down Expand Up @@ -145,7 +145,7 @@ class GeneralStatisticsAnalysis
/// The pass itself stores the results.
using Result = GeneralStatistics;

explicit GeneralStatisticsAnalysis();
explicit GeneralStatisticsAnalysis() = default;

GeneralStatistics run(llvm::Module &M, llvm::ModuleAnalysisManager &AM);
};
Expand Down
2 changes: 1 addition & 1 deletion include/phasar/PhasarPass/PhasarPass.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace psr {

class PhasarPass : public llvm::ModulePass {
public:
static char ID;
static inline char ID = 12;

explicit PhasarPass();
PhasarPass(const PhasarPass &) = delete;
Expand Down
2 changes: 1 addition & 1 deletion include/phasar/PhasarPass/PhasarPrinterPass.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace psr {

class PhasarPrinterPass : public llvm::ModulePass {
public:
static char ID;
static inline char ID = 12; // NOLINT FIXME: make const when LLVM supports it

explicit PhasarPrinterPass();
PhasarPrinterPass(const PhasarPrinterPass &) = delete;
Expand Down
3 changes: 2 additions & 1 deletion lib/PhasarLLVM/Passes/ExampleModulePass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ llvm::AnalysisKey ExampleModulePass::Key;
ExampleModulePass::ExampleModulePass() = default;

llvm::PreservedAnalyses
ExampleModulePass::run(llvm::Module &M, llvm::ModuleAnalysisManager &MAM) {
ExampleModulePass::run(llvm::Module & /*M*/,
llvm::ModuleAnalysisManager & /*MAM*/) {
cout << "ExampleModulePass::run()\n";
return llvm::PreservedAnalyses::all();
}
Expand Down
87 changes: 42 additions & 45 deletions lib/PhasarLLVM/Passes/GeneralStatisticsAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,29 @@ using namespace psr;

namespace psr {

llvm::AnalysisKey GeneralStatisticsAnalysis::Key;

GeneralStatisticsAnalysis::GeneralStatisticsAnalysis() = default;

llvm::AnalysisKey GeneralStatisticsAnalysis::Key; // NOLINT
GeneralStatistics
GeneralStatisticsAnalysis::run(llvm::Module &M,
llvm::ModuleAnalysisManager &AM) {
llvm::ModuleAnalysisManager & /*AM*/) {
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), INFO)
<< "Running GeneralStatisticsAnalysis");
static const std::set<std::string> MemAllocatingFunctions = {
"operator new(unsigned long)", "operator new[](unsigned long)", "malloc",
"calloc", "realloc"};
for (auto &F : M) {
++Stats.functions;
++Stats.Functions;
for (auto &BB : F) {
++Stats.basicblocks;
++Stats.BasicBlocks;
for (auto &I : BB) {
// found one more instruction
++Stats.instructions;
++Stats.Instructions;
// check for alloca instruction for possible types
if (const llvm::AllocaInst *Alloc =
llvm::dyn_cast<llvm::AllocaInst>(&I)) {
Stats.allocatedTypes.insert(Alloc->getAllocatedType());
Stats.AllocatedTypes.insert(Alloc->getAllocatedType());
// do not add allocas from llvm internal functions
Stats.allocaInstructions.insert(&I);
++Stats.allocationsites;
Stats.AllocaInstructions.insert(&I);
++Stats.AllocationSites;
} // check bitcast instructions for possible types
else {
for (auto *User : I.users()) {
Expand All @@ -72,30 +69,30 @@ GeneralStatisticsAnalysis::run(llvm::Module &M,
}
// check for return or resume instructions
if (llvm::isa<llvm::ReturnInst>(I) || llvm::isa<llvm::ResumeInst>(I)) {
Stats.retResInstructions.insert(&I);
Stats.RetResInstructions.insert(&I);
}
// check for store instructions
if (llvm::isa<llvm::StoreInst>(I)) {
++Stats.storeInstructions;
++Stats.StoreInstructions;
}
// check for load instructions
if (llvm::isa<llvm::LoadInst>(I)) {
++Stats.loadInstructions;
++Stats.LoadInstructions;
}
// check for llvm's memory intrinsics
if (llvm::isa<llvm::MemIntrinsic>(I)) {
++Stats.memIntrinsic;
++Stats.MemIntrinsics;
}
// check for function calls
if (llvm::isa<llvm::CallInst>(I) || llvm::isa<llvm::InvokeInst>(I)) {
++Stats.callsites;
++Stats.CallSites;
const llvm::CallBase *CallSite = llvm::cast<llvm::CallBase>(&I);
if (CallSite->getCalledFunction()) {
if (MemAllocatingFunctions.count(llvm::demangle(
CallSite->getCalledFunction()->getName().str()))) {
// do not add allocas from llvm internal functions
Stats.allocaInstructions.insert(&I);
++Stats.allocationsites;
Stats.AllocaInstructions.insert(&I);
++Stats.AllocationSites;
// check if an instance of a user-defined type is allocated on the
// heap
for (auto *User : I.users()) {
Expand All @@ -113,7 +110,7 @@ GeneralStatisticsAnalysis::run(llvm::Module &M,
if (CTor->getCalledFunction() &&
getNthFunctionArgument(CTor->getCalledFunction(), 0)
->getType() == Cast->getDestTy()) {
Stats.allocatedTypes.insert(
Stats.AllocatedTypes.insert(
Cast->getDestTy()->getPointerElementType());
}
}
Expand All @@ -130,9 +127,9 @@ GeneralStatisticsAnalysis::run(llvm::Module &M,
// check for global pointers
for (auto &Global : M.globals()) {
if (Global.getType()->isPointerTy()) {
++Stats.globalPointers;
++Stats.GlobalPointers;
}
++Stats.globals;
++Stats.Globals;
}
// register stuff in PAMM
// For performance reasons (and out of sheer convenience) we simply initialize
Expand Down Expand Up @@ -163,29 +160,29 @@ GeneralStatisticsAnalysis::run(llvm::Module &M,
<< "GeneralStatisticsAnalysis summary for module: '"
<< M.getName().str() << "'");
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), INFO)
<< "Instructions : " << Stats.instructions);
<< "Instructions : " << Stats.Instructions);
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), INFO)
<< "Allocated Types : " << Stats.allocatedTypes.size());
<< "Allocated Types : " << Stats.AllocatedTypes.size());
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), INFO)
<< "Allocation Sites : " << Stats.allocationsites);
<< "Allocation Sites : " << Stats.AllocationSites);
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), INFO)
<< "Basic Blocks : " << Stats.basicblocks);
<< "Basic Blocks : " << Stats.BasicBlocks);
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), INFO)
<< "Calls Sites : " << Stats.callsites);
<< "Calls Sites : " << Stats.CallSites);
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), INFO)
<< "Functions : " << Stats.functions);
<< "Functions : " << Stats.Functions);
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), INFO)
<< "Globals : " << Stats.globals);
<< "Globals : " << Stats.Globals);
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), INFO)
<< "Global Pointer : " << Stats.globalPointers);
<< "Global Pointer : " << Stats.GlobalPointers);
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), INFO)
<< "Memory Intrinsics : " << Stats.memIntrinsic);
<< "Memory Intrinsics : " << Stats.MemIntrinsics);
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), INFO)
<< "Store Instructions : " << Stats.storeInstructions);
<< "Store Instructions : " << Stats.StoreInstructions);
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), INFO) << ' ');
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), INFO)
<< "Allocated Types << " << Stats.allocatedTypes.size());
for (const auto *Type : Stats.allocatedTypes) {
<< "Allocated Types << " << Stats.AllocatedTypes.size());
for (const auto *Type : Stats.AllocatedTypes) {
std::string TypeStr;
llvm::raw_string_ostream Rso(TypeStr);
Type->print(Rso);
Expand All @@ -196,38 +193,38 @@ GeneralStatisticsAnalysis::run(llvm::Module &M,
return Stats;
}

size_t GeneralStatistics::getAllocationsites() const { return allocationsites; }
size_t GeneralStatistics::getAllocationsites() const { return AllocationSites; }

size_t GeneralStatistics::getFunctioncalls() const { return callsites; }
size_t GeneralStatistics::getFunctioncalls() const { return CallSites; }

size_t GeneralStatistics::getInstructions() const { return instructions; }
size_t GeneralStatistics::getInstructions() const { return Instructions; }

size_t GeneralStatistics::getGlobalPointers() const { return globalPointers; }
size_t GeneralStatistics::getGlobalPointers() const { return GlobalPointers; }

size_t GeneralStatistics::getBasicBlocks() const { return basicblocks; }
size_t GeneralStatistics::getBasicBlocks() const { return BasicBlocks; }

size_t GeneralStatistics::getFunctions() const { return functions; }
size_t GeneralStatistics::getFunctions() const { return Functions; }

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

size_t GeneralStatistics::getMemoryIntrinsics() const { return memIntrinsic; }
size_t GeneralStatistics::getMemoryIntrinsics() const { return MemIntrinsics; }

size_t GeneralStatistics::getStoreInstructions() const {
return storeInstructions;
return StoreInstructions;
}

set<const llvm::Type *> GeneralStatistics::getAllocatedTypes() const {
return allocatedTypes;
return AllocatedTypes;
}

set<const llvm::Instruction *>
GeneralStatistics::getAllocaInstructions() const {
return allocaInstructions;
return AllocaInstructions;
}

set<const llvm::Instruction *>
GeneralStatistics::getRetResInstructions() const {
return retResInstructions;
return RetResInstructions;
}

} // namespace psr
3 changes: 2 additions & 1 deletion lib/PhasarLLVM/Passes/ValueAnnotationPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ size_t ValueAnnotationPass::UniqueValueId = 0;
ValueAnnotationPass::ValueAnnotationPass() = default;

llvm::PreservedAnalyses
ValueAnnotationPass::run(llvm::Module &M, llvm::ModuleAnalysisManager &AM) {
ValueAnnotationPass::run(llvm::Module &M,
llvm::ModuleAnalysisManager & /*AM*/) {
LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), INFO)
<< "Running ValueAnnotationPass");
auto &Context = M.getContext();
Expand Down
14 changes: 6 additions & 8 deletions lib/PhasarPass/PhasarPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@

namespace psr {

char PhasarPass::ID = 12;

PhasarPass::PhasarPass() : llvm::ModulePass(ID) {}

llvm::StringRef PhasarPass::getPassName() const { return "PhasarPass"; }
Expand Down Expand Up @@ -181,7 +179,7 @@ bool PhasarPass::runOnModule(llvm::Module &M) {
return false;
}

bool PhasarPass::doInitialization(llvm::Module &M) {
bool PhasarPass::doInitialization(llvm::Module & /*M*/) {
llvm::outs() << "PhasarPass::doInitialization()\n";
initializeLogger(InitLogger);
// check the user's parameters
Expand All @@ -198,7 +196,7 @@ bool PhasarPass::doInitialization(llvm::Module &M) {
return false;
}

bool PhasarPass::doFinalization(llvm::Module &M) {
bool PhasarPass::doFinalization(llvm::Module & /*M*/) {
llvm::outs() << "PhasarPass::doFinalization()\n";
return false;
}
Expand All @@ -207,12 +205,12 @@ void PhasarPass::getAnalysisUsage(llvm::AnalysisUsage &AU) const {}

void PhasarPass::releaseMemory() {}

void PhasarPass::print(llvm::raw_ostream &O, const llvm::Module *M) const {
void PhasarPass::print(llvm::raw_ostream &O, const llvm::Module * /*M*/) const {
O << "I am a PhasarPass Analysis Result ;-)\n";
}

static llvm::RegisterPass<PhasarPass> Phasar("phasar", "PhASAR Pass",
false /* Only looks at CFG */,
false /* Analysis Pass */);
static const llvm::RegisterPass<PhasarPass>
Phasar("phasar", "PhASAR Pass", false /* Only looks at CFG */,
false /* Analysis Pass */);

} // namespace psr
6 changes: 2 additions & 4 deletions lib/PhasarPass/PhasarPrinterPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

namespace psr {

char PhasarPrinterPass::ID = 12;

PhasarPrinterPass::PhasarPrinterPass() : llvm::ModulePass(ID) {}

llvm::StringRef PhasarPrinterPass::getPassName() const {
Expand All @@ -32,12 +30,12 @@ bool PhasarPrinterPass::runOnModule(llvm::Module &M) {
return false;
}

bool PhasarPrinterPass::doInitialization(llvm::Module &M) {
bool PhasarPrinterPass::doInitialization(llvm::Module & /*M*/) {
llvm::outs() << "PhasarPrinterPass::doInitialization()\n";
return false;
}

bool PhasarPrinterPass::doFinalization(llvm::Module &M) {
bool PhasarPrinterPass::doFinalization(llvm::Module & /*M*/) {
llvm::outs() << "PhasarPrinterPass::doFinalization()\n";
return false;
}
Expand Down