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

TimurZaytsev #161

Open
wants to merge 5 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/TimurZaytsev/TimurZaytsev.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef LLVM_TRANSFORMS_TIMURZAYTSEV_H
#define LLVM_TRANSFORMS_TIMURZAYTSEV_H

#include "llvm/IR/PassManager.h"

namespace llvm {

class LPMUpdater;

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

} // namespace llvm

#endif // LLVM_TRANSFORMS_TIMURZAYTSEV_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
TimurZaytsev
)
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/TimurZaytsev/TimurZaytsev.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 @@ -253,6 +253,7 @@ FUNCTION_PASS("inject-tli-mappings", InjectTLIMappings())
FUNCTION_PASS("instnamer", InstructionNamerPass())
FUNCTION_PASS("loweratomic", LowerAtomicPass())
FUNCTION_PASS("lower-expect", LowerExpectIntrinsicPass())
FUNCTION_PASS("TimurZaytsev", TimurZaytsevPass())
FUNCTION_PASS("lower-guard-intrinsic", LowerGuardIntrinsicPass())
FUNCTION_PASS("lower-constant-intrinsics", LowerConstantIntrinsicsPass())
FUNCTION_PASS("lower-widenable-condition", LowerWidenableConditionPass())
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(TimurZaytsev)
10 changes: 10 additions & 0 deletions llvm/lib/Transforms/TimurZaytsev/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
add_llvm_component_library(LLVMTimurZaytsev
TimurZaytsev.cpp

DEPENDS
intrinsics_gen

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

#define DEBUG_TYPE "TimurZaytsev"
#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(B_Count, "Amount of blocks");
ALWAYS_ENABLED_STATISTIC(Loop_Count, "Amount of loops");

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

Fun_Count++;
auto& LA = AM.getResult<LoopAnalysis>(F);
for (auto& L : LA) {
Loop_Count++;
}
for (const BasicBlock &BB : F) {
B_Count++;
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++;
break;
}
}
}
errs() << " Amount of arithmetic operations " << Op_Count << "\n";
errs() << " Amount of loops " << Loop_Count << "\n";
errs() << " Amount of functions " << Fun_Count << "\n";
errs() << " Amount of blocks " << B_Count << "\n";
return PreservedAnalyses::all();
}