Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Фролова Ольга 19ПМИ-1 #174

Open
wants to merge 2 commits into
base: hse-21-labs
Choose a base branch
from
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/FoLgACount/FoLgACount.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef LLVM_TRANSFORMS_FOLGA_COUNT_H
#define LLVM_TRANSFORMS_FOLGA_COUNT_H

#include "llvm/IR/PassManager.h"

namespace llvm {

class LPMUpdater;

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

} // namespace llvm

#endif // LLVM_TRANSFORMS_FOLGA_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
FoLgACount
)
1 change: 1 addition & 0 deletions llvm/lib/Passes/PassBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "llvm/Analysis/BlockFrequencyInfo.h"
#include "llvm/Analysis/BranchProbabilityInfo.h"
#include "llvm/Analysis/CFGPrinter.h"
#include "llvm/Transforms/FoLgACount/FoLgACount.h"
#include "llvm/Analysis/CFLAndersAliasAnalysis.h"
#include "llvm/Analysis/CFLSteensAliasAnalysis.h"
#include "llvm/Analysis/CGSCCPassManager.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 @@ -280,6 +280,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("FoLgACount", FoLgACountPass())
FUNCTION_PASS("print", PrintFunctionPass(dbgs()))
FUNCTION_PASS("print<assumptions>", AssumptionPrinterPass(dbgs()))
FUNCTION_PASS("print<block-freq>", BlockFrequencyPrinterPass(dbgs()))
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(FoLgACount)
10 changes: 10 additions & 0 deletions llvm/lib/Transforms/FoLgACount/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
add_llvm_component_library(LLVMFoLgACount
FoLgACount.cpp

DEPENDS
intrinsics_gen

LINK_COMPONENTS
Core
Support
)
46 changes: 46 additions & 0 deletions llvm/lib/Transforms/FoLgACount/FoLgACount.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "llvm/Transforms/FoLgACount/FoLgACount.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/Analysis/LoopInfo.h"

#define DEBUG_TYPE "of-count"
#include "llvm/ADT/Statistic.h"

using namespace llvm;

ALWAYS_ENABLED_STATISTIC(Fun_Count, "Amount of functions");
ALWAYS_ENABLED_STATISTIC(Op_Count, "Amount of arithmetic operations");
ALWAYS_ENABLED_STATISTIC(BB_Count, "Amount of BasicBlocks");
ALWAYS_ENABLED_STATISTIC(Loop_Count, "Amount of Loops");

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

Fun_Count += 1;
auto& LA = AM.getResult<LoopAnalysis>(F);
for (auto& L : LA) {
Loop_Count += 1;
}
for (const BasicBlock &BB : F) {
BB_Count += 1;
for (const Instruction &I : BB) {
switch (I.getOpcode()) {
case Instruction::Add:
case Instruction::Sub:
case Instruction::Mul:
case Instruction::FAdd:
case Instruction::FSub:
case Instruction::FMul:
case Instruction::FDiv:
case Instruction::SDiv:
case Instruction::UDiv:
Op_Count += 1;
break;
}
}
}
errs() << " Amount of arithmetic operations " << Op_Count << "\n";
errs() << " Amount of functions " << Fun_Count << "\n";
errs() << " Amount of basic blocks " << BB_Count << "\n";
errs() << " Amount of loops " << Loop_Count << "\n";
return PreservedAnalyses::all();
}