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

#include "llvm/IR/PassManager.h"

namespace llvm {

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

} // namespace llvm

#endif // LLVM_TRANSFORMS_ARTYOMLAVROVLAB1_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
ArtyomLavrovlab1
)
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/ArtyomLavrov/ArtyomLavrovlab1.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 @@ -239,6 +239,7 @@ FUNCTION_PASS("make-guards-explicit", MakeGuardsExplicitPass())
FUNCTION_PASS("gvn-hoist", GVNHoistPass())
FUNCTION_PASS("gvn-sink", GVNSinkPass())
FUNCTION_PASS("helloworld", HelloWorldPass())
FUNCTION_PASS("ArtyomLavrovlab1", ArtyomLavrovlab1Pass())
FUNCTION_PASS("infer-address-spaces", InferAddressSpacesPass())
FUNCTION_PASS("instcombine", InstCombinePass())
FUNCTION_PASS("instcount", InstCountPass())
Expand Down
50 changes: 50 additions & 0 deletions llvm/lib/Transforms/ArtyomLavrov/ArtyomLavrovlab1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include "llvm/Transforms/ArtyomLavrov/ArtyomLavrovlab1.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/ADT/Statistic.h"
#include <set>

#define DEBUG_TYPE "ArtyomLavrovlab1"

using namespace llvm;

ALWAYS_ENABLED_STATISTIC(FuncCounter, "Function counter");
ALWAYS_ENABLED_STATISTIC(BlockCounter, "Block counter");
ALWAYS_ENABLED_STATISTIC(OpCounter, "Arithmetic operation counter");
ALWAYS_ENABLED_STATISTIC(LoopCounter, "Loop counter");

PreservedAnalyses DenisKabanovLab1Pass::run(Function &F,
FunctionAnalysisManager &AM) {
errs() << "function: " << F.getName() << "\n";
FuncCounter++;
for (auto BB = F.begin(); BB != F.end(); ++BB){
errs() << " base block: " << BB->getName() << "\n";
BlockCounter++;
for (auto I = BB->begin(); I != BB->end(); ++I){
errs() << " instruction: " << I->getOpcode() << "\n";
// id - instruction
// 1 - return
// 13 - "+"
// 15 - "-"
// 17 - "*"
// 20 - "/"
// 23 - "%"
std::set<int> Operations{13, 15, 17, 20, 23};
if (Operations.find(I->getOpcode()) != Operations.end())
OpCounter++;
}
}

//}
auto& LA = AM.getResult<LoopAnalysis>(F);
for (auto& L : LA){
errs() << " loop:" << L->getName() << "\n";
LoopCounter++;
}
errs() << "Total stats after function: " << F.getName()
<< "\n\tFunction counter: " << FuncCounter
<< "\n\tBlock counter: " << BlockCounter
<< "\n\tArithmetic operation counter: " << OpCounter
<< "\n\tLoop counter: " << LoopCounter << "\n";
return PreservedAnalyses::all();
}
13 changes: 13 additions & 0 deletions llvm/lib/Transforms/ArtyomLavrov/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
add_llvm_component_library(LLVMArtyomLavrovlab1
ArtyomLavrovlab1.cpp

DEPENDS
intrinsics_gen

COMPONENT_NAME
ArtyomLavrovlab1

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