[llvm-branch-commits] [clang] [llvm] [Instrumentor] Allow multiple config files with different filters (PR #196235)
https://github.com/jdoerfert updated
https://github.com/llvm/llvm-project/pull/196235
>From 358b5e8d422262551c12a3b02c4832624eb76f07 Mon Sep 17 00:00:00 2001
From: Johannes Doerfert
Date: Wed, 6 May 2026 20:26:11 -0700
Subject: [PATCH] [Instrumentor] Allow multiple config files with different
filters
To instrument different functions in different ways we allow to provide
multiple config files now. Each file will result in one instrumentation
run. Multiple files can be passed via command line option or listed in
a "summary" file that is passed via command line option (to keep the
command length managable).
---
.../Instrumentor/InstrumentorStackUsage.cpp | 2 +-
.../Instrumentor/InstrumentorUnreachable.cpp | 2 +-
.../llvm/Transforms/IPO/Instrumentor.h| 12 +++-
.../Transforms/IPO/InstrumentorConfigFile.h | 6 ++
llvm/lib/Transforms/IPO/Instrumentor.cpp | 67 +++
.../Transforms/IPO/InstrumentorConfigFile.cpp | 37 ++
.../Instrumentor/alloca_and_function.ll | 40 +--
.../Instrumentor/bad_function_regexp.ll | 2 +-
.../Instrumentation/Instrumentor/counters.ll | 2 +-
.../Instrumentor/function_regex.ll| 2 +-
.../Instrumentor/generate_bad_rt.ll | 2 +-
.../Instrumentor/generate_rt.ll | 2 +-
.../Instrumentor/load_store.ll| 2 +-
.../Instrumentor/load_store_args.ll | 2 +-
.../Instrumentor/load_store_noreplace.ll | 2 +-
.../Instrumentor/multi_config.ll | 56
.../Instrumentor/multi_config_1.json | 12
.../Instrumentor/multi_config_2.json | 12
.../Instrumentor/multi_config_3.json | 12
.../Instrumentor/multi_config_4.json | 16 +
.../Instrumentor/multi_config_paths | 2 +
.../Instrumentor/read_config.ll | 2 +-
22 files changed, 248 insertions(+), 46 deletions(-)
create mode 100644 llvm/test/Instrumentation/Instrumentor/multi_config.ll
create mode 100644 llvm/test/Instrumentation/Instrumentor/multi_config_1.json
create mode 100644 llvm/test/Instrumentation/Instrumentor/multi_config_2.json
create mode 100644 llvm/test/Instrumentation/Instrumentor/multi_config_3.json
create mode 100644 llvm/test/Instrumentation/Instrumentor/multi_config_4.json
create mode 100644 llvm/test/Instrumentation/Instrumentor/multi_config_paths
diff --git a/clang/test/Instrumentor/InstrumentorStackUsage.cpp
b/clang/test/Instrumentor/InstrumentorStackUsage.cpp
index ade099764143c..f941a6d470241 100644
--- a/clang/test/Instrumentor/InstrumentorStackUsage.cpp
+++ b/clang/test/Instrumentor/InstrumentorStackUsage.cpp
@@ -1,6 +1,6 @@
// NOTE: Assertions have been autogenerated by utils/update_test_checks.py
// RUN: %clangxx -O0 %S/StackUsageRT.cpp -o %t.StackUsageRT.o -c
-// RUN: %clangxx -O0 -mllvm -enable-instrumentor -mllvm
-instrumentor-read-config-file=%S/StackUsageRT.json %t.StackUsageRT.o -o %t %s
+// RUN: %clangxx -O0 -mllvm -enable-instrumentor -mllvm
-instrumentor-read-config-files=%S/StackUsageRT.json %t.StackUsageRT.o -o %t %s
// RUN: %t | FileCheck %s
static void foobar(int *A, int N) {
diff --git a/clang/test/Instrumentor/InstrumentorUnreachable.cpp
b/clang/test/Instrumentor/InstrumentorUnreachable.cpp
index 5fa0c9b5318ef..310c8c6763d0c 100644
--- a/clang/test/Instrumentor/InstrumentorUnreachable.cpp
+++ b/clang/test/Instrumentor/InstrumentorUnreachable.cpp
@@ -1,6 +1,6 @@
// NOTE: Assertions have been autogenerated by utils/update_test_checks.py
// RUN: %clangxx -O0 %S/UnreachableRT.cpp -o %t.UnreachableRT.o -c
-// RUN: %clangxx -O0 -mllvm -enable-instrumentor -mllvm
-instrumentor-read-config-file=%S/UnreachableRT.json %t.UnreachableRT.o -o %t
%s
+// RUN: %clangxx -O0 -mllvm -enable-instrumentor -mllvm
-instrumentor-read-config-files=%S/UnreachableRT.json %t.UnreachableRT.o -o %t
%s
// RUN: not %t 2>&1 | FileCheck %s --check-prefix=FIRST
// RUN: not %t arg 2>&1 | FileCheck %s --check-prefix=SECOND
diff --git a/llvm/include/llvm/Transforms/IPO/Instrumentor.h
b/llvm/include/llvm/Transforms/IPO/Instrumentor.h
index ba3ad2498c873..50875f266b205 100644
--- a/llvm/include/llvm/Transforms/IPO/Instrumentor.h
+++ b/llvm/include/llvm/Transforms/IPO/Instrumentor.h
@@ -348,7 +348,16 @@ struct InstrumentationConfig {
virtual ~InstrumentationConfig() {}
/// Construct an instrumentation configuration with the base options.
- InstrumentationConfig() : SS(StringAllocator) {
+ InstrumentationConfig() : SS(StringAllocator) {}
+
+ /// Initialize the config to a clean base state without loosing cached values
+ /// that can be reused across configurations.
+ virtual void init(InstrumentorIRBuilderTy &IIRB) {
+// Clear previous configurations but not the caches.
+BaseConfigurationOptions.clear();
+for (auto &Map : IChoices)
+ Map.clear();
+
RuntimePrefix = BaseConfigurationOption::createStringOption(
*this, "runtime_prefix",
[llvm-branch-commits] [clang] [llvm] [Instrumentor] Allow multiple config files with different filters (PR #196235)
https://github.com/jdoerfert updated
https://github.com/llvm/llvm-project/pull/196235
>From 527a1e834ba484106a4c697c34e94163b99b0a9d Mon Sep 17 00:00:00 2001
From: Johannes Doerfert
Date: Wed, 6 May 2026 20:26:11 -0700
Subject: [PATCH] [Instrumentor] Allow multiple config files with different
filters
To instrument different functions in different ways we allow to provide
multiple config files now. Each file will result in one instrumentation
run. Multiple files can be passed via command line option or listed in
a "summary" file that is passed via command line option (to keep the
command length managable).
---
.../Instrumentor/InstrumentorStackUsage.cpp | 2 +-
.../Instrumentor/InstrumentorUnreachable.cpp | 2 +-
.../llvm/Transforms/IPO/Instrumentor.h| 12 +++-
.../Transforms/IPO/InstrumentorConfigFile.h | 6 ++
llvm/lib/Transforms/IPO/Instrumentor.cpp | 67 +++
.../Transforms/IPO/InstrumentorConfigFile.cpp | 37 ++
.../Instrumentor/alloca_and_function.ll | 40 +--
.../Instrumentation/Instrumentor/counters.ll | 2 +-
.../Instrumentor/function_regex.ll| 2 +-
.../Instrumentor/generate_bad_rt.ll | 2 +-
.../Instrumentor/generate_rt.ll | 2 +-
.../Instrumentor/load_store.ll| 2 +-
.../Instrumentor/load_store_args.ll | 2 +-
.../Instrumentor/load_store_noreplace.ll | 2 +-
.../Instrumentor/multi_config.ll | 56
.../Instrumentor/multi_config_1.json | 12
.../Instrumentor/multi_config_2.json | 12
.../Instrumentor/multi_config_3.json | 12
.../Instrumentor/multi_config_4.json | 16 +
.../Instrumentor/multi_config_paths | 2 +
.../Instrumentor/read_config.ll | 2 +-
21 files changed, 247 insertions(+), 45 deletions(-)
create mode 100644 llvm/test/Instrumentation/Instrumentor/multi_config.ll
create mode 100644 llvm/test/Instrumentation/Instrumentor/multi_config_1.json
create mode 100644 llvm/test/Instrumentation/Instrumentor/multi_config_2.json
create mode 100644 llvm/test/Instrumentation/Instrumentor/multi_config_3.json
create mode 100644 llvm/test/Instrumentation/Instrumentor/multi_config_4.json
create mode 100644 llvm/test/Instrumentation/Instrumentor/multi_config_paths
diff --git a/clang/test/Instrumentor/InstrumentorStackUsage.cpp
b/clang/test/Instrumentor/InstrumentorStackUsage.cpp
index 15a2714652a3f..36f1762bcde43 100644
--- a/clang/test/Instrumentor/InstrumentorStackUsage.cpp
+++ b/clang/test/Instrumentor/InstrumentorStackUsage.cpp
@@ -1,6 +1,6 @@
// NOTE: Assertions have been autogenerated by utils/update_test_checks.py
// RUN: %clangxx -O0 %S/StackUsageRT.cpp -o %t.StackUsageRT.o -c
-// RUN: %clangxx -O0 -mllvm -enable-instrumentor -mllvm
-instrumentor-read-config-file=%S/StackUsageRT.json %t.StackUsageRT.o -o %t %s
+// RUN: %clangxx -O0 -mllvm -enable-instrumentor -mllvm
-instrumentor-read-config-files=%S/StackUsageRT.json %t.StackUsageRT.o -o %t %s
// RUN: %t | FileCheck %s
static void foobar(int *A, int N) {
diff --git a/clang/test/Instrumentor/InstrumentorUnreachable.cpp
b/clang/test/Instrumentor/InstrumentorUnreachable.cpp
index 0caf07a1e9496..a0e2ff79f95fb 100644
--- a/clang/test/Instrumentor/InstrumentorUnreachable.cpp
+++ b/clang/test/Instrumentor/InstrumentorUnreachable.cpp
@@ -1,6 +1,6 @@
// NOTE: Assertions have been autogenerated by utils/update_test_checks.py
// RUN: %clangxx -O0 -I%llvm_bin_dir/include/ -I%llvm_src_dir/include/
%S/UnreachableRT.cpp -o %t.UnreachableRT.o -c
-// RUN: %clangxx -O0 -L%llvm_bin_dir/lib -lLLVMSupport -lLLVMDemangle -mllvm
-enable-instrumentor -mllvm
-instrumentor-read-config-file=%S/UnreachableRT.json %t.UnreachableRT.o -o %t
%s
+// RUN: %clangxx -O0 -L%llvm_bin_dir/lib -lLLVMSupport -lLLVMDemangle -mllvm
-enable-instrumentor -mllvm
-instrumentor-read-config-files=%S/UnreachableRT.json %t.UnreachableRT.o -o %t
%s
// RUN: %t 2>&1 | FileCheck %s --check-prefix=FIRST
// RUN: %t arg 2>&1 | FileCheck %s --check-prefix=SECOND
diff --git a/llvm/include/llvm/Transforms/IPO/Instrumentor.h
b/llvm/include/llvm/Transforms/IPO/Instrumentor.h
index 63a37931e98dc..84622a0b4d1bf 100644
--- a/llvm/include/llvm/Transforms/IPO/Instrumentor.h
+++ b/llvm/include/llvm/Transforms/IPO/Instrumentor.h
@@ -347,7 +347,16 @@ struct InstrumentationConfig {
virtual ~InstrumentationConfig() {}
/// Construct an instrumentation configuration with the base options.
- InstrumentationConfig() : SS(StringAllocator) {
+ InstrumentationConfig() : SS(StringAllocator) {}
+
+ /// Initialize the config to a clean base state without loosing cached values
+ /// that can be reused across configurations.
+ virtual void init(InstrumentorIRBuilderTy &IIRB) {
+// Clear previous configurations but not the caches.
+BaseConfigurationOptions.clear();
+for (auto &Map : IChoices)
+ Map.clear();
+
Runtim
[llvm-branch-commits] [clang] [llvm] [Instrumentor] Allow multiple config files with different filters (PR #196235)
llvmorg-github-actions[bot] wrote:
@llvm/pr-subscribers-llvm-transforms
Author: Johannes Doerfert (jdoerfert)
Changes
To instrument different functions in different ways we allow to provide
multiple config files now. Each file will result in one instrumentation run.
Multiple files can be passed via command line option or listed in a "summary"
file that is passed via command line option (to keep the command length
managable).
---
Patch is 25.68 KiB, truncated to 20.00 KiB below, full version:
https://github.com/llvm/llvm-project/pull/196235.diff
21 Files Affected:
- (modified) clang/test/Instrumentor/InstrumentorStackUsage.cpp (+1-1)
- (modified) clang/test/Instrumentor/InstrumentorUnreachable.cpp (+1-1)
- (modified) llvm/include/llvm/Transforms/IPO/Instrumentor.h (+11-1)
- (modified) llvm/include/llvm/Transforms/IPO/InstrumentorConfigFile.h (+6)
- (modified) llvm/lib/Transforms/IPO/Instrumentor.cpp (+52-14)
- (modified) llvm/lib/Transforms/IPO/InstrumentorConfigFile.cpp (+38)
- (modified) llvm/test/Instrumentation/Instrumentor/alloca_and_function.ll
(+20-20)
- (modified) llvm/test/Instrumentation/Instrumentor/counters.ll (+1-1)
- (modified) llvm/test/Instrumentation/Instrumentor/function_regex.ll (+1-1)
- (modified) llvm/test/Instrumentation/Instrumentor/generate_bad_rt.ll (+1-1)
- (modified) llvm/test/Instrumentation/Instrumentor/generate_rt.ll (+1-1)
- (modified) llvm/test/Instrumentation/Instrumentor/load_store.ll (+1-1)
- (modified) llvm/test/Instrumentation/Instrumentor/load_store_args.ll (+1-1)
- (modified) llvm/test/Instrumentation/Instrumentor/load_store_noreplace.ll
(+1-1)
- (added) llvm/test/Instrumentation/Instrumentor/multi_config.ll (+56)
- (added) llvm/test/Instrumentation/Instrumentor/multi_config_1.json (+12)
- (added) llvm/test/Instrumentation/Instrumentor/multi_config_2.json (+12)
- (added) llvm/test/Instrumentation/Instrumentor/multi_config_3.json (+12)
- (added) llvm/test/Instrumentation/Instrumentor/multi_config_4.json (+16)
- (added) llvm/test/Instrumentation/Instrumentor/multi_config_paths (+2)
- (modified) llvm/test/Instrumentation/Instrumentor/read_config.ll (+1-1)
``diff
diff --git a/clang/test/Instrumentor/InstrumentorStackUsage.cpp
b/clang/test/Instrumentor/InstrumentorStackUsage.cpp
index 15a2714652a3f..36f1762bcde43 100644
--- a/clang/test/Instrumentor/InstrumentorStackUsage.cpp
+++ b/clang/test/Instrumentor/InstrumentorStackUsage.cpp
@@ -1,6 +1,6 @@
// NOTE: Assertions have been autogenerated by utils/update_test_checks.py
// RUN: %clangxx -O0 %S/StackUsageRT.cpp -o %t.StackUsageRT.o -c
-// RUN: %clangxx -O0 -mllvm -enable-instrumentor -mllvm
-instrumentor-read-config-file=%S/StackUsageRT.json %t.StackUsageRT.o -o %t %s
+// RUN: %clangxx -O0 -mllvm -enable-instrumentor -mllvm
-instrumentor-read-config-files=%S/StackUsageRT.json %t.StackUsageRT.o -o %t %s
// RUN: %t | FileCheck %s
static void foobar(int *A, int N) {
diff --git a/clang/test/Instrumentor/InstrumentorUnreachable.cpp
b/clang/test/Instrumentor/InstrumentorUnreachable.cpp
index 7a716bed62d53..128fb1cee862f 100644
--- a/clang/test/Instrumentor/InstrumentorUnreachable.cpp
+++ b/clang/test/Instrumentor/InstrumentorUnreachable.cpp
@@ -1,6 +1,6 @@
// NOTE: Assertions have been autogenerated by utils/update_test_checks.py
// RUN: %clangxx -O0 -I%llvm_bin_dir/include/ -I%llvm_src_dir/include/
%S/UnreachableRT.cpp -o %t.UnreachableRT.o -c
-// RUN: %clangxx -O0 -L%llvm_bin_dir/lib -lLLVMSupport -lLLVMDemangle -mllvm
-enable-instrumentor -mllvm
-instrumentor-read-config-file=%S/UnreachableRT.json %t.UnreachableRT.o -o %t
%s
+// RUN: %clangxx -O0 -L%llvm_bin_dir/lib -lLLVMSupport -lLLVMDemangle -mllvm
-enable-instrumentor -mllvm
-instrumentor-read-config-files=%S/UnreachableRT.json %t.UnreachableRT.o -o %t
%s
// RUN: not %t 2>&1 | FileCheck %s --check-prefix=FIRST
// RUN: not %t arg 2>&1 | FileCheck %s --check-prefix=SECOND
diff --git a/llvm/include/llvm/Transforms/IPO/Instrumentor.h
b/llvm/include/llvm/Transforms/IPO/Instrumentor.h
index a5859fc20505c..49e00eac1f63d 100644
--- a/llvm/include/llvm/Transforms/IPO/Instrumentor.h
+++ b/llvm/include/llvm/Transforms/IPO/Instrumentor.h
@@ -343,7 +343,16 @@ struct InstrumentationConfig {
virtual ~InstrumentationConfig() {}
/// Construct an instrumentation configuration with the base options.
- InstrumentationConfig() : SS(StringAllocator) {
+ InstrumentationConfig() : SS(StringAllocator) {}
+
+ /// Initialize the config to a clean base state without loosing cached values
+ /// that can be reused across configurations.
+ virtual void init(InstrumentorIRBuilderTy &IIRB) {
+// Clear previous configurations but not the caches.
+BaseConfigurationOptions.clear();
+for (auto &Map : IChoices)
+ Map.clear();
+
RuntimePrefix = BaseConfigurationOption::getStringOption(
*this, "runtime_prefix", "The runtime API prefix.", "__instrumentor_");
RuntimeStubsFile = BaseConfi
