From 941bcf2f3b498b39177baaf0dc70239b22b80c27 Mon Sep 17 00:00:00 2001 From: Petar Tesic Date: Thu, 6 Jul 2023 09:33:38 +0200 Subject: [PATCH 1/2] Code refactoring and test added for the count cttz pass! --- llvm/lib/Transforms/Utils/PetarCountCttz.cpp | 8 ++-- llvm/test/Transforms/Util/petar-count-cttz.ll | 48 +++++++++++++++++++ 2 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 llvm/test/Transforms/Util/petar-count-cttz.ll diff --git a/llvm/lib/Transforms/Utils/PetarCountCttz.cpp b/llvm/lib/Transforms/Utils/PetarCountCttz.cpp index 33a7af390d32e..93ad2457cac3b 100644 --- a/llvm/lib/Transforms/Utils/PetarCountCttz.cpp +++ b/llvm/lib/Transforms/Utils/PetarCountCttz.cpp @@ -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(&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(); diff --git a/llvm/test/Transforms/Util/petar-count-cttz.ll b/llvm/test/Transforms/Util/petar-count-cttz.ll new file mode 100644 index 0000000000000..941cffca4587a --- /dev/null +++ b/llvm/test/Transforms/Util/petar-count-cttz.ll @@ -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 +} + From 4d52336e9d219ec931829f3450082b2af183a4ad Mon Sep 17 00:00:00 2001 From: Petar Tesic Date: Thu, 13 Jul 2023 10:53:14 +0200 Subject: [PATCH 2/2] Added some notes! --- petar_notes.txt | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 petar_notes.txt diff --git a/petar_notes.txt b/petar_notes.txt new file mode 100644 index 0000000000000..e4afaf2f2e203 --- /dev/null +++ b/petar_notes.txt @@ -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? +