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_bfs.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 targets/instr_bfs.c (limited to 'targets/instr_bfs.c') diff --git a/targets/instr_bfs.c b/targets/instr_bfs.c new file mode 100644 index 0000000..a7b176e --- /dev/null +++ b/targets/instr_bfs.c @@ -0,0 +1,39 @@ +// Breadth-first search from vertex 0 of a seven-vertex graph, one vertex +// out of reach, argv[1] times (by default once). Exits with the number of +// vertices reached. +#include + +#define N 7 +static const int edges[][2] = {{0, 1}, {0, 2}, {1, 3}, {2, 3}, {3, 4}, {4, 5}}; +static int adjacent[N][N]; +static int distance[N]; +static int order[N]; + +static int bfs(int from) { + int queue[N], head = 0, tail = 0; + for (int v = 0; v < N; v++) distance[v] = -1; + distance[from] = 0; + queue[tail++] = from; + while (head < tail) { + int v = queue[head]; + order[head++] = v; + for (int w = 0; w < N; w++) { + if (adjacent[v][w] && distance[w] < 0) { + distance[w] = distance[v] + 1; + queue[tail++] = w; + } + } + } + return tail; +} + +int main(int argc, char **argv) { + int rounds = argc > 1 ? atoi(argv[1]) : 1; + int reached = 0; + for (unsigned i = 0; i < sizeof edges / sizeof *edges; i++) { + adjacent[edges[i][0]][edges[i][1]] = 1; + adjacent[edges[i][1]][edges[i][0]] = 1; + } + while (rounds-- > 0) reached = bfs(0); + return reached; +} -- cgit v1.3