[clang] [compiler-rt] [libcxx] [Instrumentor] Add runtime examples: [1/N] A flop counter (PR #205698)

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 25 09:13:30 PDT 2026


================
@@ -0,0 +1,164 @@
+//===-- flop_counter_runtime.cpp - FLOP Counter Runtime ------------------===//
+//
+// 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 implements the runtime for counting floating-point operations.
+// It hooks into instrumentation points inserted by the LLVM Instrumentor pass.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../instrumentor_runtime.h"
+
+#include <atomic>
+#include <cinttypes>
+#include <cstdint>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+
+namespace {
+
+/// FLOP counter statistics (thread-safe using atomics)
+struct FlopCounterStats {
+  std::atomic<uint64_t> TotalFlops{0};
----------------
jdoerfert wrote:

Not before c++20 (https://stackoverflow.com/a/59099824)

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


More information about the llvm-commits mailing list