#ifndef LLVM_TRANSFORMS_UTILS_LINELOGGER_H
#define LLVM_TRANSFORMS_UTILS_LINELOGGER_H
#include "llvm/IR/PassManager.h"
namespace llvm{
class LineLoggerPass : public PassInfoMixin<LineLoggerPass> {
public:
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
};
static bool isRequired() { return true; }
}
#endif
Above is LineLogger.h i added isrequired to True
clang++ -S -emit-llvm -Xclang -disabl
e-O0-optnone X.cpp -o X.ll
Above are the commands i am running to compile X.cpp
X.cpp (395 Bytes)
; ModuleID = 'X.cpp'
source_filename = "X.cpp"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
%"class.std::ios_base::Init" = type { i8 }
%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }
@_ZStL8__ioinit = internal global %"class.std::ios_base::Init" zeroinitializer, align 1
@__dso_handle = external hidden global i8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @_GLOBAL__sub_I_X.cpp, ptr null }]
; Function Attrs: noinline uwtable
define internal void @__cxx_global_var_init() #0 section ".text.startup" {
call void @_ZNSt8ios_base4InitC1Ev(ptr noundef nonnull align 1 dereferenceable(1) @_ZStL8__ioinit)
%1 = call i32 @__cxa_atexit(ptr @_ZNSt8ios_base4InitD1Ev, ptr @_ZStL8__ioinit, ptr @__dso_handle) #3
ret void
}
declare void @_ZNSt8ios_base4InitC1Ev(ptr noundef nonnull align 1 dereferenceable(1)) unnamed_addr #1
; Function Attrs: nounwind
declare void @_ZNSt8ios_base4InitD1Ev(ptr noundef nonnull align 1 dereferenceable(1)) unnamed_addr #2
; Function Attrs: nounwind
declare i32 @__cxa_atexit(ptr, ptr, ptr) #3
; Function Attrs: mustprogress noinline nounwind uwtable
define dso_local noundef i32 @_Z3retii(i32 noundef %0, i32 noundef %1) #4 {
%3 = alloca i32, align 4
%4 = alloca i32, align 4
%5 = alloca i32, align 4
%6 = alloca i32, align 4
store i32 %0, ptr %3, align 4
store i32 %1, ptr %4, align 4
store i32 0, ptr %5, align 4
store i32 1, ptr %6, align 4
br label %7
7: ; preds = %15, %2
%8 = load i32, ptr %6, align 4
%9 = load i32, ptr %3, align 4
%10 = icmp sle i32 %8, %9
br i1 %10, label %11, label %19
11: ; preds = %7
%12 = load i32, ptr %6, align 4
%13 = load i32, ptr %5, align 4
%14 = add nsw i32 %13, %12
store i32 %14, ptr %5, align 4
br label %15
15: ; preds = %11
%16 = load i32, ptr %6, align 4
%17 = load i32, ptr %4, align 4
%18 = add nsw i32 %16, %17
store i32 %18, ptr %6, align 4
br label %7, !llvm.loop !6
19: ; preds = %7
%20 = load i32, ptr %5, align 4
ret i32 %20
}
; Function Attrs: mustprogress noinline norecurse uwtable
define dso_local noundef i32 @main() #5 {
%1 = alloca i32, align 4
store i32 0, ptr %1, align 4
%2 = call noundef i32 @_Z3retii(i32 noundef 10, i32 noundef 2)
%3 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %2)
%4 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %3, i8 noundef signext 10)
ret i32 0
}
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8), i8 noundef signext) #1
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) #1
; Function Attrs: noinline uwtable
define internal void @_GLOBAL__sub_I_X.cpp() #0 section ".text.startup" {
call void @__cxx_global_var_init()
ret void
}
attributes #0 = { noinline uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nounwind "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nounwind }
attributes #4 = { mustprogress noinline nounwind uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #5 = { mustprogress noinline norecurse uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
!llvm.module.flags = !{!0, !1, !2, !3, !4}
!llvm.ident = !{!5}
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{i32 7, !"frame-pointer", i32 2}
!5 = !{!"clang version 18.0.0git (https://github.com/llvm/llvm-project.git 595d780b492d3de3f5653851e7d64c122472d71a)"}
!6 = distinct !{!6, !7}
!7 = !{!"llvm.loop.mustprogress"}
This is the .ll file i obtain
opt -disable-output ~/Prog/PE/X.ll -passes=linelogger
I am running above to call pass on X.ll
Even after changes i see no output
Running pass: ModuleToFunctionPassAdaptor on [module]
Running analysis: InnerAnalysisManagerProxy<llvm::AnalysisManager<llvm::Function>, llvm::Module> on [module]
Running pass: PassManager<llvm::Function> on __cxx_global_var_init (3 instructions)
Running pass: LineLoggerPass on __cxx_global_var_init (3 instructions)
Running pass: PassManager<llvm::Function> on _Z3retii (25 instructions)
Running pass: LineLoggerPass on _Z3retii (25 instructions)
Running pass: PassManager<llvm::Function> on main (6 instructions)
Running pass: LineLoggerPass on main (6 instructions)
Running pass: PassManager<llvm::Function> on _GLOBAL__sub_I_X.cpp (2 instructions)
Running pass: LineLoggerPass on _GLOBAL__sub_I_X.cpp (2 instructions)
Running pass: VerifierPass on [module]
Running analysis: VerifierAnalysis on [module]
This is on running opt with verbose option, pls help.