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
17 changes: 17 additions & 0 deletions llvm/include/llvm/Transforms/EliseTorbaCount/EliseTorbaCount.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef LLVM_TRANSFORMS_ELISETORBACOUNT_ELISETORBACOUNT_H
#define LLVM_TRANSFORMS_ELISETORBACOUNT_ELISETORBACOUNT_H

#include "llvm/IR/PassManager.h"

namespace llvm {

class LPMUpdater;

class EliseTorbaCountPass : public PassInfoMixin<EliseTorbaCountPass> {
public:
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
};

} // namespace llvm

#endif // LLVM_TRANSFORMS_ELISETORBACOUNT_ELISETORBACOUNT_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
EliseTorbaCount
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/EliseTorbaCount/EliseTorbaCount.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 @@ -256,6 +256,7 @@ FUNCTION_PASS("lower-expect", LowerExpectIntrinsicPass())
FUNCTION_PASS("lower-guard-intrinsic", LowerGuardIntrinsicPass())
FUNCTION_PASS("lower-constant-intrinsics", LowerConstantIntrinsicsPass())
FUNCTION_PASS("lower-widenable-condition", LowerWidenableConditionPass())
FUNCTION_PASS("elisetoba-count", EliseTorbaCountPass())
FUNCTION_PASS("guard-widening", GuardWideningPass())
FUNCTION_PASS("load-store-vectorizer", LoadStoreVectorizerPass())
FUNCTION_PASS("loop-simplify", LoopSimplifyPass())
Expand Down
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(EliseTorbaCount)
10 changes: 10 additions & 0 deletions llvm/lib/Transforms/EliseTorbaCount/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
add_llvm_component_library(LLVMEliseTorbaCount
EliseTorbaCount.cpp

DEPENDS
intrinsics_gen

LINK_COMPONENTS
Core
Support
)
43 changes: 43 additions & 0 deletions llvm/lib/Transforms/EliseTorbaCount/EliseTorbaCount.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "llvm/Transforms/EliseTorbaCount/EliseTorbaCount.h"

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

#define DEBUG_TYPE "elisetorba-count"

using namespace llvm;

ALWAYS_ENABLED_STATISTIC(OP_count, "Math operations Amount");
ALWAYS_ENABLED_STATISTIC(BB_count, "BasicBlocks Amount");
ALWAYS_ENABLED_STATISTIC(Loop_count, "Loops Amount");

PreservedAnalyses EliseTorbaCountPass::run(Function &F,
FunctionAnalysisManager &AM) {

for (auto BB = F.begin(); BB != F.end(); ++BB) ++BB_count;

for (const auto& I : instructions(F)) {
switch (I.getOpcode()) {
case Instruction::Add:
case Instruction::Sub:
case Instruction::FSub:
case Instruction::FAdd:
case Instruction::Mul:
case Instruction::FMul:
case Instruction::FDiv:
case Instruction::SDiv:
case Instruction::UDiv:
++OP_count;
}
}

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

errs() << "BasicBlocks: " << BB_count << "\n"
<< "Math operations: " << OP_count << "\n"
<< "Loops: " << Loop_count << "\n";

return PreservedAnalyses::all();
}