Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions llvm/include/llvm/Transforms/BogomazovCount/BogomazovCount.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef LLVM_TRANSFORMS_BOGOMAZOV_COUNT_H
#define LLVM_TRANSFORMS_BOGOMAZOV_COUNT_H

#include "llvm/IR/PassManager.h"

namespace llvm {

class BogomazovCountPass : public PassInfoMixin<BogomazovCountPass> {
public:
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
};
} // namespace llvm

#endif // LLVM_TRANSFORMS_Bogomazov_COUNT_H
1 change: 1 addition & 0 deletions llvm/lib/Passes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ add_llvm_component_library(LLVMPasses
TransformUtils
Vectorize
Instrumentation
BogomazovCountPass
)
1 change: 1 addition & 0 deletions llvm/lib/Passes/PassBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
#include "llvm/Transforms/Instrumentation/SanitizerCoverage.h"
#include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
#include "llvm/Transforms/ObjCARC.h"
#include "llvm/Transforms/BogomazovCount/BogomazovCount.h"
#include "llvm/Transforms/Scalar/ADCE.h"
#include "llvm/Transforms/Scalar/AlignmentFromAssumptions.h"
#include "llvm/Transforms/Scalar/AnnotationRemarks.h"
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Passes/PassRegistry.def
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ FUNCTION_ALIAS_ANALYSIS("tbaa", TypeBasedAA())
#ifndef FUNCTION_PASS
#define FUNCTION_PASS(NAME, CREATE_PASS)
#endif
FUNCTION_PASS("BogomazovCount", BogomazovCountPass())
FUNCTION_PASS("aa-eval", AAEvaluator())
FUNCTION_PASS("adce", ADCEPass())
FUNCTION_PASS("add-discriminators", AddDiscriminatorsPass())
Expand Down Expand Up @@ -280,6 +281,7 @@ FUNCTION_PASS("objc-arc", ObjCARCOptPass())
FUNCTION_PASS("objc-arc-contract", ObjCARCContractPass())
FUNCTION_PASS("objc-arc-expand", ObjCARCExpandPass())
FUNCTION_PASS("pgo-memop-opt", PGOMemOPSizeOpt())
FUNCTION_PASS("BogomazovCount", BogomazovCountPass())
FUNCTION_PASS("print", PrintFunctionPass(dbgs()))
FUNCTION_PASS("print<assumptions>", AssumptionPrinterPass(dbgs()))
FUNCTION_PASS("print<block-freq>", BlockFrequencyPrinterPass(dbgs()))
Expand Down
62 changes: 62 additions & 0 deletions llvm/lib/Transforms/BogomazovCount/BogomazovCount.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include "llvm/Transforms/BogomazovCount/BogomazovCount.h"


#include "llvm/ADT/Statistic.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/Analysis/LoopInfo.h"

#define DEBUG_TYPE "BogomazovCount"

using namespace llvm;

ALWAYS_ENABLED_STATISTIC(F_count, "Number of functions");
ALWAYS_ENABLED_STATISTIC(BB_count, "BB amount");
ALWAYS_ENABLED_STATISTIC(OPS_count, "OPS amount");
ALWAYS_ENABLED_STATISTIC(loops_count, "Loops amount");


PreservedAnalyses BogomazovCountPass::run(Function &F, FunctionAnalysisManager &AM) {
F_count ++;

for (auto BB = F.begin(); BB != F.end(); ++BB) {
BB_count += 1;
for (auto I = BB->begin(); I != BB->end(); ++I) {
switch (I->getOpcode()) {
case Instruction::Add:
OPS_count += 1;
break;
case Instruction::FAdd:
OPS_count += 1;
break;
case Instruction::Mul:
OPS_count += 1;
break;
case Instruction::FDiv:
OPS_count += 1;
break;
case Instruction::SDiv:
OPS_count += 1;
break;
case Instruction::UDiv:
OPS_count += 1;
break;
case Instruction::Sub:
OPS_count += 1;
break;
case Instruction::FSub:
OPS_count += 1;
break;
}
}
}

auto& LA = AM.getResult<LoopAnalysis>(F);
for (auto& L : LA) ++loops_count;

errs() << "Functions: " << F_count << "\n"
<< "BB: " << BB_count << "\n"
<< "OPS: " << OPS_count << "\n"
<< "Loops: " << loops_count << "\n";

return PreservedAnalyses::all();
}
13 changes: 13 additions & 0 deletions llvm/lib/Transforms/BogomazovCount/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
add_llvm_component_library(LLVMBogomazovCountPass
BogomazovCount.cpp

DEPENDS
intrinsics_gen

COMPONENT_NAME
BogomazovCount

LINK_COMPONENTS
Core
Support
)
1 change: 1 addition & 0 deletions llvm/lib/Transforms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ add_subdirectory(Hello)
add_subdirectory(ObjCARC)
add_subdirectory(Coroutines)
add_subdirectory(CFGuard)
add_subdirectory(BogomazovCount)