Skip to content

Commit

Permalink
Add tests for ModuleClone and BasicBlockTracer passes.
Browse files Browse the repository at this point in the history
Assert on tracing calls in cloned functions. Assert on not having
tracing calls in original functions.
  • Loading branch information
Pavel-Durov committed Sep 22, 2024
1 parent 65e56f8 commit 43507e0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
6 changes: 3 additions & 3 deletions llvm/lib/Transforms/Yk/BasicBlockTracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ struct YkBasicBlockTracer : public ModulePass {
// FIXME: This cause the ykjit to crash when executing compiled
// trace at: https://github.com/ykjit/yk/blob/master/ykrt/src/mt.rs#L366
// Skip cloned functions
// if (F.getName().startswith(YK_CLONE_PREFIX)) {
// continue;
// }
if (F.getName().startswith(YK_CLONE_PREFIX)) {
continue;
}
for (auto &BB : F) {
builder.SetInsertPoint(&*BB.getFirstInsertionPt());
builder.CreateCall(TraceFunc, {builder.getInt32(FunctionIndex),
Expand Down
11 changes: 8 additions & 3 deletions llvm/test/Transforms/Yk/ModuleClone.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; RUN: llc -stop-after=yk-module-clone-pass --yk-module-clone < %s | FileCheck %s
; RUN: llc -stop-after=yk-basicblock-tracer-pass --yk-module-clone --yk-basicblock-tracer < %s | FileCheck %s

source_filename = "ModuleClone.c"
target triple = "x86_64-pc-linux-gnu"
Expand Down Expand Up @@ -40,7 +40,7 @@ entry:
}

; ======================================================================
; Original functions
; Original functions - should have trace calls
; ======================================================================
; File header checks
; CHECK: source_filename = "ModuleClone.c"
Expand All @@ -63,6 +63,7 @@ entry:
; Check original function: my_func
; CHECK-LABEL: define dso_local i32 @my_func(i32 %x)
; CHECK-NEXT: entry:
; CHECK-NEXT: call void @__yk_trace_basicblock({{.*}})
; CHECK-NEXT: %0 = add i32 %x, 1
; CHECK-NEXT: %func_ptr = alloca ptr, align 8
; CHECK-NEXT: store ptr @func_inc_with_address_taken, ptr %func_ptr, align 8
Expand All @@ -73,13 +74,15 @@ entry:
; Check original function: main
; CHECK-LABEL: define dso_local i32 @main()
; CHECK-NEXT: entry:
; CHECK-NEXT: call void @__yk_trace_basicblock({{.*}})
; CHECK-NEXT: %0 = call i32 @my_func(i32 10)
; CHECK-NEXT: %1 = load i32, ptr @my_global
; CHECK-NEXT: %2 = call i32 (ptr, ...) @printf

; Check that func_inc_with_address_taken is present in its original form
; CHECK-LABEL: define dso_local i32 @func_inc_with_address_taken(i32 %x)
; CHECK-NEXT: entry:
; CHECK-NEXT: call void @__yk_trace_basicblock({{.*}})
; CHECK-NEXT: %0 = add i32 %x, 1
; CHECK-NEXT: ret i32 %0

Expand All @@ -91,11 +94,12 @@ entry:
; CHECK-NOT: define dso_local i32 @__yk_clone_func_inc_with_address_taken

; ======================================================================
; Cloned functions
; Cloned functions - should have no trace calls
; ======================================================================
; Check cloned function: __yk_clone_my_func
; CHECK-LABEL: define dso_local i32 @__yk_clone_my_func(i32 %x)
; CHECK-NEXT: entry:
; CHECK-NOT: call void @__yk_trace_basicblock({{.*}})
; CHECK-NEXT: %0 = add i32 %x, 1
; CHECK-NEXT: %func_ptr = alloca ptr, align 8
; CHECK-NEXT: store ptr @func_inc_with_address_taken, ptr %func_ptr, align 8
Expand All @@ -106,6 +110,7 @@ entry:
; Check cloned function: __yk_clone_main
; CHECK-LABEL: define dso_local i32 @__yk_clone_main()
; CHECK-NEXT: entry:
; CHECK-NOT: call void @__yk_trace_basicblock({{.*}})
; CHECK-NEXT: %0 = call i32 @__yk_clone_my_func(i32 10)
; CHECK-NEXT: %1 = load i32, ptr @my_global
; CHECK-NEXT: %2 = call i32 (ptr, ...) @printf

0 comments on commit 43507e0

Please sign in to comment.