[compiler-rt] [ctx_profile] Integration test (PR #92456)

Snehasish Kumar via llvm-commits llvm-commits at lists.llvm.org
Fri May 17 09:22:47 PDT 2024


================
@@ -0,0 +1,102 @@
+// Simple integration test for contextual instrumentation
+//
+// Copy the header defining ContextNode.
+// RUN: mkdir -p %t_include
+// RUN: cp %llvm_src/include/llvm/ProfileData/CtxInstrContextNode.h %t_include/
+//
+// Compile with ctx instrumentation "on". We treat "the_root" as callgraph root.
+// RUN: %clangxx %s -lclang_rt.ctx_profile -I%t_include -O2 -o %t.bin -mllvm -profile-context-root=the_root
+//
+// Run the binary, and observe the profile fetch handler's output.
+// RUN: %t.bin | FileCheck %s
+
+#include "CtxInstrContextNode.h"
+#include <cstdio>
+#include <iostream>
+
+using namespace llvm::ctx_profile;
+extern "C" bool __llvm_ctx_profile_fetch(void *Data,
+                                         bool (*Writer)(void *,
+                                                        const ContextNode &));
+
+extern "C" {
+__attribute__((noinline)) void someFunction(int I) {
+  if (I % 2)
+    printf("check odd\n");
+  else
+    printf("check even\n");
+}
+
+// block inlining because the pre-inliner otherwise will inline this - it's
+// too small.
+__attribute__((noinline)) void the_root() {
----------------
snehasish wrote:

`theRoot` to be consistent with `someFunction`.

https://github.com/llvm/llvm-project/pull/92456


More information about the llvm-commits mailing list