From b426a8a99bcad81ecbb41d1f2a2e83738c29d8e1 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 10 Nov 2026 11:32:21 -0300 Subject: llvm: a pass that instruments for animation, its runtime, ztrace cc llvm/pass.cpp is an LLVM pass plugin: lines, stores, loads, calls and variables, each call into the runtime carrying names and type descriptions, selected by globs (-ztrace-only, -ztrace-mem), before the optimizer by default. src/instr/rt.zig is the runtime (libztrace-rt.a), which also answers clang's own coverage and -finstrument-functions hooks; src/instr/types.zig the grammar of the type descriptions and its parser. ztrace cc adds all of it to a compiler command. test-llvm compiles fib, two sorts, a linked list and a BFS through ztrace cc and asserts on their recordings; bench-llvm measures what each selection costs. Co-Authored-By: Claude Fable 5.2 --- targets/instr_list.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 targets/instr_list.c (limited to 'targets/instr_list.c') diff --git a/targets/instr_list.c b/targets/instr_list.c new file mode 100644 index 0000000..aaa6c8a --- /dev/null +++ b/targets/instr_list.c @@ -0,0 +1,46 @@ +// A linked list of five squares, built at its head and then reversed in +// place, argv[1] times (by default once). The last list is left standing. +// Exits with the sum of its values. +#include + +struct node { + int value; + struct node *next; +}; + +static struct node *list; + +static struct node *push(struct node *head, int value) { + struct node *n = malloc(sizeof *n); + n->value = value; + n->next = head; + return n; +} + +static struct node *reverse(struct node *head) { + struct node *prev = NULL; + while (head) { + struct node *next = head->next; + head->next = prev; + prev = head; + head = next; + } + return prev; +} + +int main(int argc, char **argv) { + int rounds = argc > 1 ? atoi(argv[1]) : 1; + int sum = 0; + while (rounds-- > 0) { + while (list) { + struct node *next = list->next; + free(list); + list = next; + } + for (int i = 1; i <= 5; i++) list = push(list, i * i); + list = reverse(list); + sum = 0; + for (struct node *n = list; n; n = n->next) sum += n->value; + } + return sum; +} -- cgit v1.3