From 950410367360e9adff36489f6f2015da883f3a3c Mon Sep 17 00:00:00 2001 From: Pavel Durov Date: Fri, 10 Jan 2025 16:17:27 +0000 Subject: [PATCH] Set original functions to be optimised and cloned as unoptimised. Interpreter starts always in optimised (non-tracing) mode, therefore the original module should be set as optimised. --- llvm/include/llvm/Transforms/Yk/ModuleClone.h | 2 +- llvm/lib/Transforms/Yk/BasicBlockTracer.cpp | 5 ++--- llvm/lib/Transforms/Yk/ModuleClone.cpp | 8 +++---- llvm/lib/Transforms/Yk/ShadowStack.cpp | 4 +++- llvm/test/Transforms/Yk/ModuleClone.ll | 22 +++++++++---------- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/llvm/include/llvm/Transforms/Yk/ModuleClone.h b/llvm/include/llvm/Transforms/Yk/ModuleClone.h index ab96d339fc0abf..94ad9358395cae 100644 --- a/llvm/include/llvm/Transforms/Yk/ModuleClone.h +++ b/llvm/include/llvm/Transforms/Yk/ModuleClone.h @@ -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 { diff --git a/llvm/lib/Transforms/Yk/BasicBlockTracer.cpp b/llvm/lib/Transforms/Yk/BasicBlockTracer.cpp index 32975eadc097fe..2206fe75d787f9 100644 --- a/llvm/lib/Transforms/Yk/BasicBlockTracer.cpp +++ b/llvm/lib/Transforms/Yk/BasicBlockTracer.cpp @@ -43,9 +43,8 @@ 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. for (auto &BB : F) { builder.SetInsertPoint(&*BB.getFirstInsertionPt()); builder.CreateCall(TraceFunc, {builder.getInt32(FunctionIndex), diff --git a/llvm/lib/Transforms/Yk/ModuleClone.cpp b/llvm/lib/Transforms/Yk/ModuleClone.cpp index 0184d8ecda24f6..f9a847f7940067 100644 --- a/llvm/lib/Transforms/Yk/ModuleClone.cpp +++ b/llvm/lib/Transforms/Yk/ModuleClone.cpp @@ -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**. // //===----------------------------------------------------------------------===// diff --git a/llvm/lib/Transforms/Yk/ShadowStack.cpp b/llvm/lib/Transforms/Yk/ShadowStack.cpp index be52a8a3afd705..1f5b0366070761 100644 --- a/llvm/lib/Transforms/Yk/ShadowStack.cpp +++ b/llvm/lib/Transforms/Yk/ShadowStack.cpp @@ -92,6 +92,7 @@ #include "llvm/IR/Verifier.h" #include "llvm/InitializePasses.h" #include "llvm/Pass.h" +#include "llvm/Transforms/Yk/ModuleClone.h" #include @@ -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; } diff --git a/llvm/test/Transforms/Yk/ModuleClone.ll b/llvm/test/Transforms/Yk/ModuleClone.ll index ff8bf898a8e074..cd69ce5bba3e33 100644 --- a/llvm/test/Transforms/Yk/ModuleClone.ll +++ b/llvm/test/Transforms/Yk/ModuleClone.ll @@ -105,22 +105,22 @@ 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 @@ -128,10 +128,10 @@ entry: ; 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