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
8 changes: 4 additions & 4 deletions llvm/lib/Transforms/Utils/PetarCountCttz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ int countCttzIntrinsicAppearance=0;
PreservedAnalyses PetarCountCttzPass::run(Function &F, FunctionAnalysisManager &AM) {

errs() << "Function name: " << F.getName() << "\n";
errs() << "\n-------------------------------\n";
errs() << "Instructions within this function!\n";
//errs() << "\n-------------------------------\n";
//errs() << "Instructions within this function!\n";
for(BasicBlock& BB: F){
for(Instruction& I: BB){
errs()<< I.getName() << "\n";
//errs()<< I.getName() << "\n";
IntrinsicInst *II = dyn_cast<IntrinsicInst>(&I);

if(II && (II->getIntrinsicID() == Intrinsic::cttz))
countCttzIntrinsicAppearance++;
}
}
errs() << "\n-------------------------------\n";
//errs() << "\n-------------------------------\n";
errs() << "Total number of cttz intrinsic appearances is equal to: " << countCttzIntrinsicAppearance << ".\n";

return PreservedAnalyses::all();
Expand Down
48 changes: 48 additions & 0 deletions llvm/test/Transforms/Util/petar-count-cttz.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
; RUN: opt -disable-output -passes=petarcountcttz %s 2>&1 | FileCheck %s

; CHECK: Function name: cttz_64_eq_select
; CHECK-NEXT: Total number of cttz intrinsic appearances is equal to: 1.
declare i64 @llvm.cttz.i64(i64, i1)
define i64 @cttz_64_eq_select(i64 %v) nounwind {

%cnt = tail call i64 @llvm.cttz.i64(i64 %v, i1 true)
%tobool = icmp eq i64 %v, 0
%.op = add nuw nsw i64 %cnt, 6
%add = select i1 %tobool, i64 5, i64 %.op
ret i64 %add
}

; CHECK-NEXT: Function name: cttz_64_ne_select
; CHECK-NEXT: Total number of cttz intrinsic appearances is equal to: 2.
define i64 @cttz_64_ne_select(i64 %v) nounwind {

%cnt = tail call i64 @llvm.cttz.i64(i64 %v, i1 true)
%tobool = icmp ne i64 %v, 0
%.op = add nuw nsw i64 %cnt, 6
%add = select i1 %tobool, i64 %.op, i64 5
ret i64 %add
}

; CHECK-NEXT: Function name: cttz_32_eq_select
; CHECK-NEXT: Total number of cttz intrinsic appearances is equal to: 3.
declare i32 @llvm.cttz.i32(i32, i1)
define i32 @cttz_32_eq_select(i32 %v) nounwind {

%cnt = tail call i32 @llvm.cttz.i32(i32 %v, i1 true)
%tobool = icmp eq i32 %v, 0
%.op = add nuw nsw i32 %cnt, 6
%add = select i1 %tobool, i32 5, i32 %.op
ret i32 %add
}

; CHECK-NEXT: Function name: cttz_32_ne_select
; CHECK-NEXT: Total number of cttz intrinsic appearances is equal to: 4.
define i32 @cttz_32_ne_select(i32 %v) nounwind {

%cnt = tail call i32 @llvm.cttz.i32(i32 %v, i1 true)
%tobool = icmp ne i32 %v, 0
%.op = add nuw nsw i32 %cnt, 6
%add = select i1 %tobool, i32 %.op, i32 5
ret i32 %add
}

6 changes: 6 additions & 0 deletions petar_notes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
LLVM project
Author: Chris Lattner
Master thesis title: Semantic detection of a CRC function for RISCV in LLVM

What have I learned so far?