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
Original file line number Diff line number Diff line change
@@ -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<BulatovDmitriyCountPass> {
public:
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
};
} // namespace llvm

#endif // LLVM_TRANSFORMS_BULATOVDMITRIYCOUNT_BULATOVDMITRIYCOUNT_H_
1 change: 1 addition & 0 deletions llvm/lib/Passes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ add_llvm_component_library(LLVMPasses
Coroutines
IPO
InstCombine
BulatovDmitriyCount
ObjCARC
Scalar
Support
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Passes/PassBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Passes/PassRegistry.def
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
35 changes: 35 additions & 0 deletions llvm/lib/Transforms/BulatovDmitriyCount/BulatovDmitriyCount.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <set>
#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 <unsigned int> 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<LoopAnalysis>(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();
}
13 changes: 13 additions & 0 deletions llvm/lib/Transforms/BulatovDmitriyCount/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
add_llvm_component_library(LLVMBulatovDmitriyCount
BulatovDmitriyCount.cpp

DEPENDS
intrinsics_gen

COMPONENT_NAME
BulatovDmitriyCount

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(BulatovDmitriyCount)