diff --git a/llvm/include/llvm/Transforms/BulatovDmitriyCount/BulatovDmitriyCount.h b/llvm/include/llvm/Transforms/BulatovDmitriyCount/BulatovDmitriyCount.h new file mode 100644 index 0000000000000..28ce761d59b44 --- /dev/null +++ b/llvm/include/llvm/Transforms/BulatovDmitriyCount/BulatovDmitriyCount.h @@ -0,0 +1,15 @@ +#ifndef LLVM_TRANSFORMS_BULATOVDMITRIYCOUNT_BULATOVDMITRIYCOUNT_H_ +#define LLVM_TRANSFORMS_BULATOVDMITRIYCOUNT_BULATOVDMITRIYCOUNT_H_ + +#include "llvm/Analysis/LoopInfo.h" +#include "llvm/IR/PassManager.h" + +namespace llvm { + class BulatovDmitriyCountPass : + public PassInfoMixin { + public: + PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); + }; +} // namespace llvm + +#endif // LLVM_TRANSFORMS_BULATOVDMITRIYCOUNT_BULATOVDMITRIYCOUNT_H_ diff --git a/llvm/lib/Passes/CMakeLists.txt b/llvm/lib/Passes/CMakeLists.txt index 89e960f01e2eb..5f1710b80c236 100644 --- a/llvm/lib/Passes/CMakeLists.txt +++ b/llvm/lib/Passes/CMakeLists.txt @@ -18,6 +18,7 @@ add_llvm_component_library(LLVMPasses Coroutines IPO InstCombine + BulatovDmitriyCount ObjCARC Scalar Support diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp index e118633c7ea61..d34ffceaf907a 100644 --- a/llvm/lib/Passes/PassBuilder.cpp +++ b/llvm/lib/Passes/PassBuilder.cpp @@ -135,6 +135,7 @@ #include "llvm/Transforms/Instrumentation/PoisonChecking.h" #include "llvm/Transforms/Instrumentation/SanitizerCoverage.h" #include "llvm/Transforms/Instrumentation/ThreadSanitizer.h" +#include "llvm/Transforms/BulatovDmitriyCount/BulatovDmitriyCount.h" #include "llvm/Transforms/ObjCARC.h" #include "llvm/Transforms/Scalar/ADCE.h" #include "llvm/Transforms/Scalar/AlignmentFromAssumptions.h" diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def index fef3aba69e25f..165b48179c065 100644 --- a/llvm/lib/Passes/PassRegistry.def +++ b/llvm/lib/Passes/PassRegistry.def @@ -251,6 +251,7 @@ FUNCTION_PASS("libcalls-shrinkwrap", LibCallsShrinkWrapPass()) FUNCTION_PASS("lint", LintPass()) FUNCTION_PASS("inject-tli-mappings", InjectTLIMappings()) FUNCTION_PASS("instnamer", InstructionNamerPass()) +FUNCTION_PASS("bulatovdmitriy-count", BulatovDmitriyCountPass()) FUNCTION_PASS("loweratomic", LowerAtomicPass()) FUNCTION_PASS("lower-expect", LowerExpectIntrinsicPass()) FUNCTION_PASS("lower-guard-intrinsic", LowerGuardIntrinsicPass()) diff --git a/llvm/lib/Transforms/BulatovDmitriyCount/BulatovDmitriyCount.cpp b/llvm/lib/Transforms/BulatovDmitriyCount/BulatovDmitriyCount.cpp new file mode 100644 index 0000000000000..fa856980240c1 --- /dev/null +++ b/llvm/lib/Transforms/BulatovDmitriyCount/BulatovDmitriyCount.cpp @@ -0,0 +1,35 @@ +#include +#include "llvm/ADT/Statistic.h" +#include "llvm/IR/InstIterator.h" +#include "llvm/Transforms/BulatovDmitriyCount/BulatovDmitriyCount.h" + +#define DEBUG_TYPE "BulatovDmitriyCount" + +ALWAYS_ENABLED_STATISTIC(funNum, "Number of functions"); +ALWAYS_ENABLED_STATISTIC(lpNum, "Number of loops"); +ALWAYS_ENABLED_STATISTIC(bbNum, "Number of BB"); +ALWAYS_ENABLED_STATISTIC(opsNum, "Number of arithmetic OPS"); + +llvm::PreservedAnalyses llvm::BulatovDmitriyCountPass::run(Function &F, FunctionAnalysisManager &AM) { + std::set artmInstr {Instruction::Add, Instruction::FAdd, + Instruction::Sub, Instruction::FSub, + Instruction::Mul, Instruction::SDiv, + Instruction::UDiv, Instruction::FDiv}; + for (auto & bb : F) { + ++bbNum; + for (auto & in : bb) { + auto code = in.getOpcode(); + if (artmInstr.count(code)) { + ++opsNum; + } + } + } + ++funNum; + auto & lpAn = AM.getResult(F); + lpNum += lpAn.end() - lpAn.begin(); + errs() << "Number of functions: " << funNum << "\n"; + errs() << "Number of loops: " << lpNum << "\n"; + errs() << "Number of BB: " << bbNum << "\n"; + errs() << "Number of arithmetic OPS: " << opsNum << "\n"; + return PreservedAnalyses::all(); +} diff --git a/llvm/lib/Transforms/BulatovDmitriyCount/CMakeLists.txt b/llvm/lib/Transforms/BulatovDmitriyCount/CMakeLists.txt new file mode 100644 index 0000000000000..eec376a1d6989 --- /dev/null +++ b/llvm/lib/Transforms/BulatovDmitriyCount/CMakeLists.txt @@ -0,0 +1,13 @@ +add_llvm_component_library(LLVMBulatovDmitriyCount + BulatovDmitriyCount.cpp + + DEPENDS + intrinsics_gen + + COMPONENT_NAME + BulatovDmitriyCount + + LINK_COMPONENTS + Core + Support + ) diff --git a/llvm/lib/Transforms/CMakeLists.txt b/llvm/lib/Transforms/CMakeLists.txt index dda5f6de11e32..7d1e6e949a3f5 100644 --- a/llvm/lib/Transforms/CMakeLists.txt +++ b/llvm/lib/Transforms/CMakeLists.txt @@ -9,3 +9,4 @@ add_subdirectory(Hello) add_subdirectory(ObjCARC) add_subdirectory(Coroutines) add_subdirectory(CFGuard) +add_subdirectory(BulatovDmitriyCount)