[llvm] [Instrumentor] Improve stub printer (for C/C++ and value packs) (PR #198366)
Ethan Luis McDonough via llvm-commits
llvm-commits at lists.llvm.org
Sat May 23 01:38:05 PDT 2026
================
@@ -0,0 +1,124 @@
+//===-- Instrumentor Runtime Stub -----------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file is auto-generated by the LLVM Instrumentor pass.
+// It provides stub implementations of instrumentation runtime functions
+// that print human-readable information about instrumentation events.
+//
+// Generated with runtime prefix: __instrumentor_
+//
+//===----------------------------------------------------------------------===//
+
+#include <inttypes.h>
+#include <stdint.h>
+#include <stdio.h>
+#include "default_rt.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void __instrumentor_pre_module(char *module_name, char *target_triple, int32_t id) {
+ printf("module pre -- module_name: %s, target_triple: %s, id: %" PRId32 "\n", module_name, target_triple, id);
+}
+
+void __instrumentor_post_module(char *module_name, char *target_triple, int32_t id) {
+ printf("module post -- module_name: %s, target_triple: %s, id: %" PRId32 "\n", module_name, target_triple, id);
+}
+
+void *__instrumentor_pre_global(void *address, int32_t address_space, int64_t declared_size, int64_t alignment, char *name, int64_t initial_value, int8_t is_constant, int8_t is_definition, int32_t id) {
+ printf("global pre -- address: %p, address_space: %" PRId32 ", declared_size: %" PRId64 ", alignment: %" PRId64 ", name: %s, initial_value: %" PRId64 ", is_constant: %" PRId32 ", is_definition: %" PRId32 ", id: %" PRId32 "\n", address, address_space, declared_size, alignment, name, initial_value, is_constant, is_definition, id);
+ return address;
+}
+
+void *__instrumentor_pre_global_ind(void *address, int32_t address_space, int64_t declared_size, int64_t alignment, char *name, int64_t *initial_value_ptr, int8_t is_constant, int8_t is_definition, int32_t id) {
+ printf("global pre -- address: %p, address_space: %" PRId32 ", declared_size: %" PRId64 ", alignment: %" PRId64 ", name: %s, initial_value: %p, is_constant: %" PRId32 ", is_definition: %" PRId32 ", id: %" PRId32 "\n", address, address_space, declared_size, alignment, name, initial_value_ptr, is_constant, is_definition, id);
+ return address;
+}
+
+void __instrumentor_post_global(void *address, int32_t address_space, int64_t declared_size, int64_t alignment, char *name, int64_t initial_value, int8_t is_constant, int8_t is_definition, int32_t id) {
+ printf("global post -- address: %p, address_space: %" PRId32 ", declared_size: %" PRId64 ", alignment: %" PRId64 ", name: %s, initial_value: %" PRId64 ", is_constant: %" PRId32 ", is_definition: %" PRId32 ", id: %" PRId32 "\n", address, address_space, declared_size, alignment, name, initial_value, is_constant, is_definition, id);
+}
+
+void __instrumentor_post_global_ind(void *address, int32_t address_space, int64_t declared_size, int64_t alignment, char *name, int64_t *initial_value_ptr, int8_t is_constant, int8_t is_definition, int32_t id) {
+ printf("global post -- address: %p, address_space: %" PRId32 ", declared_size: %" PRId64 ", alignment: %" PRId64 ", name: %s, initial_value: %p, is_constant: %" PRId32 ", is_definition: %" PRId32 ", id: %" PRId32 "\n", address, address_space, declared_size, alignment, name, initial_value_ptr, is_constant, is_definition, id);
+}
+
+void __instrumentor_pre_function(void *address, char *name, int32_t num_arguments, void *arguments, int8_t is_main, int32_t id) {
+ printf("function pre -- address: %p, name: %s, num_arguments: %" PRId32 ", arguments: [value pack at %p], is_main: %" PRId32 ", id: %" PRId32 "\n", address, name, num_arguments, arguments, is_main, id);
+ ValuePackIterator iter_arguments;
+ initValuePackIterator(&iter_arguments, arguments, num_arguments);
+ while (iter_arguments.index < iter_arguments.count) {
+ ValuePackHeader header_arguments = getValuePackHeader(&iter_arguments);
+ const void *data_arguments = getValuePackData(&iter_arguments);
+ printf(" [%u] type=%s size=%u data=%p\n", iter_arguments.index, getLLVMTypeIDName(header_arguments.type_id), header_arguments.size, data_arguments);
+ nextValuePack(&iter_arguments);
+ }
+}
+
+void __instrumentor_post_function(void *address, char *name, int32_t num_arguments, void *arguments, int8_t is_main, int32_t id) {
+ printf("function post -- address: %p, name: %s, num_arguments: %" PRId32 ", arguments: [value pack at %p], is_main: %" PRId32 ", id: %" PRId32 "\n", address, name, num_arguments, arguments, is_main, id);
+ ValuePackIterator iter_arguments;
+ initValuePackIterator(&iter_arguments, arguments, num_arguments);
+ while (iter_arguments.index < iter_arguments.count) {
+ ValuePackHeader header_arguments = getValuePackHeader(&iter_arguments);
+ const void *data_arguments = getValuePackData(&iter_arguments);
+ printf(" [%u] type=%s size=%u data=%p\n", iter_arguments.index, getLLVMTypeIDName(header_arguments.type_id), header_arguments.size, data_arguments);
+ nextValuePack(&iter_arguments);
+ }
+}
+
+void __instrumentor_pre_unreachable(int32_t id) {
+ printf("unreachable pre -- id: %" PRId32 "\n", id);
+}
+
+void *__instrumentor_pre_load(void *pointer, int32_t pointer_as, int64_t value_size, int64_t alignment, int32_t value_type_id, int32_t atomicity_ordering, int8_t sync_scope_id, int8_t is_volatile, int32_t id) {
+ printf("load pre -- pointer: %p, pointer_as: %" PRId32 ", value_size: %" PRId64 ", alignment: %" PRId64 ", value_type_id: %" PRId32 ", atomicity_ordering: %" PRId32 ", sync_scope_id: %" PRId32 ", is_volatile: %" PRId32 ", id: %" PRId32 "\n", pointer, pointer_as, value_size, alignment, value_type_id, atomicity_ordering, sync_scope_id, is_volatile, id);
+ return pointer;
+}
+
+int64_t __instrumentor_pre_alloca(int64_t size, int64_t alignment, int32_t id) {
+ printf("alloca pre -- size: %" PRId64 ", alignment: %" PRId64 ", id: %" PRId32 "\n", size, alignment, id);
+ return size;
+}
----------------
EthanLuisMcDonough wrote:
`diff -b default_rt.c %S/default_rt.c` fails on my machine because `alloca` functions are printed before any of the other instruction functions.
https://github.com/llvm/llvm-project/pull/198366
More information about the llvm-commits
mailing list