Skip to content

Commit

Permalink
Set original functions to be optimised and cloned as unoptimised.
Browse files Browse the repository at this point in the history
Interpreter starts always in optimised (non-tracing) mode, therefore
the original module should be set as optimised.
  • Loading branch information
Pavel-Durov committed Jan 9, 2025
1 parent db94724 commit 9124981
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 20 deletions.
2 changes: 1 addition & 1 deletion llvm/include/llvm/Transforms/Yk/ModuleClone.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "llvm/Pass.h"

#define YK_CLONE_PREFIX "__yk_opt_"
#define YK_CLONE_PREFIX "__yk_unopt_"
#define YK_CLONE_MODULE_CP_COUNT 2

namespace llvm {
Expand Down
8 changes: 5 additions & 3 deletions llvm/lib/Transforms/Yk/BasicBlockTracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ struct YkBasicBlockTracer : public ModulePass {
uint32_t FunctionIndex = 0;
for (auto &F : M) {
uint32_t BlockIndex = 0;
if (F.getName().startswith(YK_CLONE_PREFIX)) {
continue;
}
// FIXME: Once control point transition is implemented,
// only add tracing calls to unopt version.
// if (!F.getName().startswith(YK_CLONE_PREFIX)) {
// continue;
// }
for (auto &BB : F) {
builder.SetInsertPoint(&*BB.getFirstInsertionPt());
builder.CreateCall(TraceFunc, {builder.getInt32(FunctionIndex),
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/Transforms/Yk/ModuleClone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
// and are not cloned.
//
// - **Cloned Function Naming:**
// - The cloned functions are renamed by adding the prefix `__yk_opt_` to
// - The cloned functions are renamed by adding the prefix `__yk_unopt_` to
// their original names. This distinguishes them from the original
// functions.
//
// - **Optimisation Intent:**
// - The **cloned functions** (those with the `__yk_opt_` prefix) are
// intended to be the **optimised versions** of the functions.
// - The **original functions** remain **unoptimised**.
// - The **cloned functions** (those with the `__yk_unopt_` prefix) are
// intended to be the **unoptimised versions** of the functions.
// - The **original functions** remain **optimised**.
//
//===----------------------------------------------------------------------===//

Expand Down
4 changes: 3 additions & 1 deletion llvm/lib/Transforms/Yk/ShadowStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
#include "llvm/IR/Verifier.h"
#include "llvm/InitializePasses.h"
#include "llvm/Pass.h"
#include "llvm/Transforms/Yk/ModuleClone.h"

#include <map>

Expand Down Expand Up @@ -316,7 +317,8 @@ class YkShadowStack : public ModulePass {
// skip declarations.
continue;
}
if (F.getName() == MAIN) {

if (F.getName() == MAIN || F.getName().startswith(YK_CLONE_PREFIX)) {
// We've handled main already.
continue;
}
Expand Down
22 changes: 11 additions & 11 deletions llvm/test/Transforms/Yk/ModuleClone.ll
Original file line number Diff line number Diff line change
Expand Up @@ -105,33 +105,33 @@ entry:
; ======================================================================
; Functions with their addresses taken should not be cloned.
; `func_inc_with_address_taken` is used by pointer and thus remains unaltered.
; CHECK-NOT: define dso_local i32 @__yk_opt_func_inc_with_address_taken
; CHECK-NOT: define dso_local i32 @__yk_unopt_func_inc_with_address_taken

; ======================================================================
; Cloned functions - should have no trace calls
; ======================================================================
; Check cloned function: __yk_opt_inc
; CHECK-LABEL: define dso_local i32 @__yk_opt_inc(i32 %x)
; Check cloned function: __yk_unopt_inc
; CHECK-LABEL: define dso_local i32 @__yk_unopt_inc(i32 %x)
; CHECK-NEXT: entry:
; CHECK-NOT: call void @yk_trace_basicblock({{.*}})
; CHECK-NEXT: call void @__yk_trace_basicblock({{.*}})
; CHECK-NEXT: %0 = add i32 %x, 1
; CHECK-NEXT: ret i32 %0

; Check cloned function: __yk_opt_my_func
; CHECK-LABEL: define dso_local i32 @__yk_opt_my_func(i32 %x)
; Check cloned function: __yk_unopt_my_func
; CHECK-LABEL: define dso_local i32 @__yk_unopt_my_func(i32 %x)
; CHECK-NEXT: entry:
; CHECK-NOT: call void @__yk_trace_basicblock({{.*}})
; 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
; CHECK-NEXT: %1 = load ptr, ptr %func_ptr, align 8
; CHECK-NEXT: %2 = call i32 %1(i32 42)
; CHECK-NEXT: ret i32 %2

; Check cloned function: __yk_opt_main
; CHECK-LABEL: define dso_local i32 @__yk_opt_main()
; Check cloned function: __yk_unopt_main
; CHECK-LABEL: define dso_local i32 @__yk_unopt_main()
; CHECK-NEXT: entry:
; CHECK-NOT: call void @__yk_trace_basicblock({{.*}})
; CHECK-NEXT: %0 = call i32 @__yk_opt_my_func(i32 10)
; CHECK-NEXT: call void @__yk_trace_basicblock({{.*}})
; CHECK-NEXT: %0 = call i32 @__yk_unopt_my_func(i32 10)
; CHECK-NEXT: %1 = load i32, ptr @my_global
; CHECK-NEXT: %2 = call i32 (ptr, ...) @printf

0 comments on commit 9124981

Please sign in to comment.