[clang] [llvm] [Instrumentor] Add Alloca and Function support; stack usage example (PR #195378)
@@ -231,11 +235,45 @@ bool InstrumentorImpl::instrumentFunction(Function &Fn) {
return Changed;
InstrumentationCaches ICaches;
+ SmallVector FinalTIs;
ReversePostOrderTraversal RPOT(&Fn);
- for (auto &It : RPOT)
+ for (auto &It : RPOT) {
for (auto &I : *It)
Changed |= instrumentInstruction(I, ICaches);
+auto *TI = It->getTerminator();
+if (!TI->getNumSuccessors())
+ FinalTIs.push_back(TI);
+ }
+
+ Value *FPtr = &Fn;
+ for (auto &[Name, IO] :
+ IConf.IChoices[InstrumentationLocation::FUNCTION_PRE]) {
+if (!IO->Enabled)
+ continue;
+// Count epochs eagerly.
+++IIRB.Epoch;
+
+IIRB.IRB.SetInsertPointPastAllocas(cast(FPtr));
+ensureDbgLoc(IIRB.IRB);
+IO->instrument(FPtr, IConf, IIRB, ICaches);
+IIRB.returnAllocas();
kevinsala wrote:
Is this safe to return the temporary allocas here? I'm wondering if they can
end up being re-used by another RT call and overwriting the value incorrectly.
I remember we had such an issue in the past.
https://github.com/llvm/llvm-project/pull/195378
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Instrumentor] Add Alloca and Function support; stack usage example (PR #195378)
https://github.com/jdoerfert updated
https://github.com/llvm/llvm-project/pull/195378
>From a4305765027e4f0555e4d9af7ceba8322ad720c1 Mon Sep 17 00:00:00 2001
From: Johannes Doerfert
Date: Mon, 11 May 2026 14:17:35 -0700
Subject: [PATCH 1/2] [Instrumentor] Use the pass builder's FileSystem for
reading files
In the IO sandbox, the old read calls caused the CI to fail. This
changes uses the PassBuilder's FileSystem the same way other passes
read files from disk (during CI).
---
.../llvm/Transforms/IPO/Instrumentor.h| 10 ++---
.../Transforms/IPO/InstrumentorConfigFile.h | 2 +-
llvm/lib/Passes/PassBuilderPipelines.cpp | 4 ++--
llvm/lib/Transforms/IPO/Instrumentor.cpp | 13 +++-
.../Transforms/IPO/InstrumentorConfigFile.cpp | 21 ++-
5 files changed, 38 insertions(+), 12 deletions(-)
diff --git a/llvm/include/llvm/Transforms/IPO/Instrumentor.h
b/llvm/include/llvm/Transforms/IPO/Instrumentor.h
index 7dfc342031579..331bbc259532e 100644
--- a/llvm/include/llvm/Transforms/IPO/Instrumentor.h
+++ b/llvm/include/llvm/Transforms/IPO/Instrumentor.h
@@ -15,6 +15,7 @@
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/EnumeratedArray.h"
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSwitch.h"
@@ -697,6 +698,9 @@ class InstrumentorPass : public
RequiredPassInfoMixin {
using InstrumentationConfig = instrumentor::InstrumentationConfig;
using InstrumentorIRBuilderTy = instrumentor::InstrumentorIRBuilderTy;
+ /// File system to be used for read operations.
+ IntrusiveRefCntPtr FS;
+
/// The configuration and IR builder provided by the user.
InstrumentationConfig *UserIConf;
InstrumentorIRBuilderTy *UserIIRB;
@@ -710,9 +714,9 @@ class InstrumentorPass : public
RequiredPassInfoMixin {
/// provided, a default builder is used. When the configuration is not
/// provided, it is read from the config file if available and otherwise a
/// default configuration is used.
- InstrumentorPass(InstrumentationConfig *IC = nullptr,
- InstrumentorIRBuilderTy *IIRB = nullptr)
- : UserIConf(IC), UserIIRB(IIRB) {}
+ InstrumentorPass(IntrusiveRefCntPtr FS = nullptr,
+ InstrumentationConfig *IC = nullptr,
+ InstrumentorIRBuilderTy *IIRB = nullptr);
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
};
diff --git a/llvm/include/llvm/Transforms/IPO/InstrumentorConfigFile.h
b/llvm/include/llvm/Transforms/IPO/InstrumentorConfigFile.h
index cae68f4b34f08..28efa77d772c4 100644
--- a/llvm/include/llvm/Transforms/IPO/InstrumentorConfigFile.h
+++ b/llvm/include/llvm/Transforms/IPO/InstrumentorConfigFile.h
@@ -25,7 +25,7 @@ void writeConfigToJSON(InstrumentationConfig &IConf,
StringRef OutputFile,
/// Read the configuration from the file with path \p InputFile into /p IConf.
bool readConfigFromJSON(InstrumentationConfig &IConf, StringRef InputFile,
-LLVMContext &Ctx);
+LLVMContext &Ctx, vfs::FileSystem &FS);
} // end namespace instrumentor
} // end namespace llvm
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp
b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 2d2867b9b84d1..b96f5626734d3 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -1648,7 +1648,7 @@
PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level,
// Run the Instrumentor pass late.
if (EnableInstrumentor)
-MPM.addPass(InstrumentorPass());
+MPM.addPass(InstrumentorPass(FS));
// Split out cold code. Splitting is done late to avoid hiding context from
// other optimizations and inadvertently regressing performance. The tradeoff
@@ -2429,7 +2429,7 @@ PassBuilder::buildO0DefaultPipeline(OptimizationLevel
Level,
invokeOptimizerLastEPCallbacks(MPM, Level, Phase);
if (EnableInstrumentor)
-MPM.addPass(InstrumentorPass());
+MPM.addPass(InstrumentorPass(FS));
if (isLTOPreLink(Phase))
addRequiredLTOPreLinkPasses(MPM);
diff --git a/llvm/lib/Transforms/IPO/Instrumentor.cpp
b/llvm/lib/Transforms/IPO/Instrumentor.cpp
index 33f00be11084a..eefa90b83742e 100644
--- a/llvm/lib/Transforms/IPO/Instrumentor.cpp
+++ b/llvm/lib/Transforms/IPO/Instrumentor.cpp
@@ -16,6 +16,7 @@
#include "llvm/Transforms/IPO/InstrumentorStubPrinter.h"
#include "llvm/ADT/PostOrderIterator.h"
+#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
@@ -42,6 +43,8 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Regex.h"
+#include "llvm/Support/VirtualFileSystem.h"
+#include "llvm/Transforms/Utils/ModuleUtils.h"
#include
#include
@@ -257,11 +260,19 @@ bool InstrumentorImpl::instrument() {
return Changed;
}
+InstrumentorPass::InstrumentorPass(IntrusiveRe
[clang] [llvm] [Instrumentor] Add Alloca and Function support; stack usage example (PR #195378)
https://github.com/kevinsala edited https://github.com/llvm/llvm-project/pull/195378 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Instrumentor] Add Alloca and Function support; stack usage example (PR #195378)
https://github.com/jdoerfert updated
https://github.com/llvm/llvm-project/pull/195378
>From be9e9135e78570b4c60345c6498967cc11d39411 Mon Sep 17 00:00:00 2001
From: Johannes Doerfert
Date: Mon, 11 May 2026 14:17:35 -0700
Subject: [PATCH 1/2] [Instrumentor] Use the pass builder's FileSystem for
reading files
In the IO sandbox, the old read calls caused the CI to fail. This
changes uses the PassBuilder's FileSystem the same way other passes
read files from disk (during CI).
---
.../llvm/Transforms/IPO/Instrumentor.h| 10 ++---
.../Transforms/IPO/InstrumentorConfigFile.h | 2 +-
llvm/lib/Passes/PassBuilderPipelines.cpp | 4 ++--
llvm/lib/Transforms/IPO/Instrumentor.cpp | 13 +++-
.../Transforms/IPO/InstrumentorConfigFile.cpp | 21 ++-
5 files changed, 38 insertions(+), 12 deletions(-)
diff --git a/llvm/include/llvm/Transforms/IPO/Instrumentor.h
b/llvm/include/llvm/Transforms/IPO/Instrumentor.h
index 7dfc342031579..331bbc259532e 100644
--- a/llvm/include/llvm/Transforms/IPO/Instrumentor.h
+++ b/llvm/include/llvm/Transforms/IPO/Instrumentor.h
@@ -15,6 +15,7 @@
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/EnumeratedArray.h"
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSwitch.h"
@@ -697,6 +698,9 @@ class InstrumentorPass : public
RequiredPassInfoMixin {
using InstrumentationConfig = instrumentor::InstrumentationConfig;
using InstrumentorIRBuilderTy = instrumentor::InstrumentorIRBuilderTy;
+ /// File system to be used for read operations.
+ IntrusiveRefCntPtr FS;
+
/// The configuration and IR builder provided by the user.
InstrumentationConfig *UserIConf;
InstrumentorIRBuilderTy *UserIIRB;
@@ -710,9 +714,9 @@ class InstrumentorPass : public
RequiredPassInfoMixin {
/// provided, a default builder is used. When the configuration is not
/// provided, it is read from the config file if available and otherwise a
/// default configuration is used.
- InstrumentorPass(InstrumentationConfig *IC = nullptr,
- InstrumentorIRBuilderTy *IIRB = nullptr)
- : UserIConf(IC), UserIIRB(IIRB) {}
+ InstrumentorPass(IntrusiveRefCntPtr FS = nullptr,
+ InstrumentationConfig *IC = nullptr,
+ InstrumentorIRBuilderTy *IIRB = nullptr);
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
};
diff --git a/llvm/include/llvm/Transforms/IPO/InstrumentorConfigFile.h
b/llvm/include/llvm/Transforms/IPO/InstrumentorConfigFile.h
index cae68f4b34f08..28efa77d772c4 100644
--- a/llvm/include/llvm/Transforms/IPO/InstrumentorConfigFile.h
+++ b/llvm/include/llvm/Transforms/IPO/InstrumentorConfigFile.h
@@ -25,7 +25,7 @@ void writeConfigToJSON(InstrumentationConfig &IConf,
StringRef OutputFile,
/// Read the configuration from the file with path \p InputFile into /p IConf.
bool readConfigFromJSON(InstrumentationConfig &IConf, StringRef InputFile,
-LLVMContext &Ctx);
+LLVMContext &Ctx, vfs::FileSystem &FS);
} // end namespace instrumentor
} // end namespace llvm
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp
b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 2d2867b9b84d1..b96f5626734d3 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -1648,7 +1648,7 @@
PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level,
// Run the Instrumentor pass late.
if (EnableInstrumentor)
-MPM.addPass(InstrumentorPass());
+MPM.addPass(InstrumentorPass(FS));
// Split out cold code. Splitting is done late to avoid hiding context from
// other optimizations and inadvertently regressing performance. The tradeoff
@@ -2429,7 +2429,7 @@ PassBuilder::buildO0DefaultPipeline(OptimizationLevel
Level,
invokeOptimizerLastEPCallbacks(MPM, Level, Phase);
if (EnableInstrumentor)
-MPM.addPass(InstrumentorPass());
+MPM.addPass(InstrumentorPass(FS));
if (isLTOPreLink(Phase))
addRequiredLTOPreLinkPasses(MPM);
diff --git a/llvm/lib/Transforms/IPO/Instrumentor.cpp
b/llvm/lib/Transforms/IPO/Instrumentor.cpp
index 33f00be11084a..eefa90b83742e 100644
--- a/llvm/lib/Transforms/IPO/Instrumentor.cpp
+++ b/llvm/lib/Transforms/IPO/Instrumentor.cpp
@@ -16,6 +16,7 @@
#include "llvm/Transforms/IPO/InstrumentorStubPrinter.h"
#include "llvm/ADT/PostOrderIterator.h"
+#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
@@ -42,6 +43,8 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Regex.h"
+#include "llvm/Support/VirtualFileSystem.h"
+#include "llvm/Transforms/Utils/ModuleUtils.h"
#include
#include
@@ -257,11 +260,19 @@ bool InstrumentorImpl::instrument() {
return Changed;
}
+InstrumentorPass::InstrumentorPass(IntrusiveRe
[clang] [llvm] [Instrumentor] Add Alloca and Function support; stack usage example (PR #195378)
https://github.com/kevinsala approved this pull request. LGTM, apart from the few comments https://github.com/llvm/llvm-project/pull/195378 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Instrumentor] Add Alloca and Function support; stack usage example (PR #195378)
https://github.com/kevinsala edited https://github.com/llvm/llvm-project/pull/195378 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Instrumentor] Add Alloca and Function support; stack usage example (PR #195378)
https://github.com/jdoerfert updated
https://github.com/llvm/llvm-project/pull/195378
>From a4305765027e4f0555e4d9af7ceba8322ad720c1 Mon Sep 17 00:00:00 2001
From: Johannes Doerfert
Date: Mon, 11 May 2026 14:17:35 -0700
Subject: [PATCH 1/2] [Instrumentor] Use the pass builder's FileSystem for
reading files
In the IO sandbox, the old read calls caused the CI to fail. This
changes uses the PassBuilder's FileSystem the same way other passes
read files from disk (during CI).
---
.../llvm/Transforms/IPO/Instrumentor.h| 10 ++---
.../Transforms/IPO/InstrumentorConfigFile.h | 2 +-
llvm/lib/Passes/PassBuilderPipelines.cpp | 4 ++--
llvm/lib/Transforms/IPO/Instrumentor.cpp | 13 +++-
.../Transforms/IPO/InstrumentorConfigFile.cpp | 21 ++-
5 files changed, 38 insertions(+), 12 deletions(-)
diff --git a/llvm/include/llvm/Transforms/IPO/Instrumentor.h
b/llvm/include/llvm/Transforms/IPO/Instrumentor.h
index 7dfc342031579..331bbc259532e 100644
--- a/llvm/include/llvm/Transforms/IPO/Instrumentor.h
+++ b/llvm/include/llvm/Transforms/IPO/Instrumentor.h
@@ -15,6 +15,7 @@
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/EnumeratedArray.h"
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSwitch.h"
@@ -697,6 +698,9 @@ class InstrumentorPass : public
RequiredPassInfoMixin {
using InstrumentationConfig = instrumentor::InstrumentationConfig;
using InstrumentorIRBuilderTy = instrumentor::InstrumentorIRBuilderTy;
+ /// File system to be used for read operations.
+ IntrusiveRefCntPtr FS;
+
/// The configuration and IR builder provided by the user.
InstrumentationConfig *UserIConf;
InstrumentorIRBuilderTy *UserIIRB;
@@ -710,9 +714,9 @@ class InstrumentorPass : public
RequiredPassInfoMixin {
/// provided, a default builder is used. When the configuration is not
/// provided, it is read from the config file if available and otherwise a
/// default configuration is used.
- InstrumentorPass(InstrumentationConfig *IC = nullptr,
- InstrumentorIRBuilderTy *IIRB = nullptr)
- : UserIConf(IC), UserIIRB(IIRB) {}
+ InstrumentorPass(IntrusiveRefCntPtr FS = nullptr,
+ InstrumentationConfig *IC = nullptr,
+ InstrumentorIRBuilderTy *IIRB = nullptr);
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
};
diff --git a/llvm/include/llvm/Transforms/IPO/InstrumentorConfigFile.h
b/llvm/include/llvm/Transforms/IPO/InstrumentorConfigFile.h
index cae68f4b34f08..28efa77d772c4 100644
--- a/llvm/include/llvm/Transforms/IPO/InstrumentorConfigFile.h
+++ b/llvm/include/llvm/Transforms/IPO/InstrumentorConfigFile.h
@@ -25,7 +25,7 @@ void writeConfigToJSON(InstrumentationConfig &IConf,
StringRef OutputFile,
/// Read the configuration from the file with path \p InputFile into /p IConf.
bool readConfigFromJSON(InstrumentationConfig &IConf, StringRef InputFile,
-LLVMContext &Ctx);
+LLVMContext &Ctx, vfs::FileSystem &FS);
} // end namespace instrumentor
} // end namespace llvm
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp
b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 2d2867b9b84d1..b96f5626734d3 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -1648,7 +1648,7 @@
PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level,
// Run the Instrumentor pass late.
if (EnableInstrumentor)
-MPM.addPass(InstrumentorPass());
+MPM.addPass(InstrumentorPass(FS));
// Split out cold code. Splitting is done late to avoid hiding context from
// other optimizations and inadvertently regressing performance. The tradeoff
@@ -2429,7 +2429,7 @@ PassBuilder::buildO0DefaultPipeline(OptimizationLevel
Level,
invokeOptimizerLastEPCallbacks(MPM, Level, Phase);
if (EnableInstrumentor)
-MPM.addPass(InstrumentorPass());
+MPM.addPass(InstrumentorPass(FS));
if (isLTOPreLink(Phase))
addRequiredLTOPreLinkPasses(MPM);
diff --git a/llvm/lib/Transforms/IPO/Instrumentor.cpp
b/llvm/lib/Transforms/IPO/Instrumentor.cpp
index 33f00be11084a..eefa90b83742e 100644
--- a/llvm/lib/Transforms/IPO/Instrumentor.cpp
+++ b/llvm/lib/Transforms/IPO/Instrumentor.cpp
@@ -16,6 +16,7 @@
#include "llvm/Transforms/IPO/InstrumentorStubPrinter.h"
#include "llvm/ADT/PostOrderIterator.h"
+#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
@@ -42,6 +43,8 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Regex.h"
+#include "llvm/Support/VirtualFileSystem.h"
+#include "llvm/Transforms/Utils/ModuleUtils.h"
#include
#include
@@ -257,11 +260,19 @@ bool InstrumentorImpl::instrument() {
return Changed;
}
+InstrumentorPass::InstrumentorPass(IntrusiveRe
[clang] [llvm] [Instrumentor] Add Alloca and Function support; stack usage example (PR #195378)
https://github.com/kevinsala edited https://github.com/llvm/llvm-project/pull/195378 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Instrumentor] Add Alloca and Function support; stack usage example (PR #195378)
https://github.com/jdoerfert updated
https://github.com/llvm/llvm-project/pull/195378
>From 9a4824c6613372738a758d7d418ca946df097595 Mon Sep 17 00:00:00 2001
From: Johannes Doerfert
Date: Fri, 1 May 2026 11:01:07 -0700
Subject: [PATCH] [Instrumentor] Add Alloca and Function support; stack usage
example
This adds support for alloca instrumentation and function pre/post
instrumentation. Alloca support follows load/store support directly.
Functions require special care to determine the insertion points.
Together, we can showcase how the stack high watermark can be profiled,
see InstrumentorStackUsage.cpp.
---
.../Instrumentor/InstrumentorStackUsage.cpp | 37 +++
clang/test/Instrumentor/StackUsageRT.cpp | 59
clang/test/Instrumentor/StackUsageRT.json | 54
clang/test/Instrumentor/lit.local.cfg | 2 +
.../llvm/Transforms/IPO/Instrumentor.h| 126 +++-
llvm/lib/Transforms/IPO/Instrumentor.cpp | 303 +-
.../Instrumentor/alloca_and_function.ll | 56
.../Instrumentor/default_config.json | 59
8 files changed, 681 insertions(+), 15 deletions(-)
create mode 100644 clang/test/Instrumentor/InstrumentorStackUsage.cpp
create mode 100644 clang/test/Instrumentor/StackUsageRT.cpp
create mode 100644 clang/test/Instrumentor/StackUsageRT.json
create mode 100644 clang/test/Instrumentor/lit.local.cfg
create mode 100644
llvm/test/Instrumentation/Instrumentor/alloca_and_function.ll
diff --git a/clang/test/Instrumentor/InstrumentorStackUsage.cpp
b/clang/test/Instrumentor/InstrumentorStackUsage.cpp
new file mode 100644
index 0..15a2714652a3f
--- /dev/null
+++ b/clang/test/Instrumentor/InstrumentorStackUsage.cpp
@@ -0,0 +1,37 @@
+// 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: %t | FileCheck %s
+
+static void foobar(int *A, int N) {
+ int B[100];
+ for (int i = 0; i < 100; ++i) {
+B[i] = i + N;
+ }
+ if (N-- > 0)
+foobar(B, N);
+ for (int i = 0; i < 100; ++i) {
+A[i] += B[i];
+ }
+}
+
+static void bar(int *A, int N) {
+ foobar(A, N);
+}
+
+int main(void) {
+ int A[100] = {0};
+ foobar(A, 4);
+ bar(A, 3);
+ foobar(A, 5);
+ foobar(A, 2);
+}
+
+// CHECK: Stack usage peaked at 2512 in
+// CHECK: - foobar(int*, int)
+// CHECK: - foobar(int*, int)
+// CHECK: - foobar(int*, int)
+// CHECK: - foobar(int*, int)
+// CHECK: - foobar(int*, int)
+// CHECK: - foobar(int*, int)
+// CHECK: - main
diff --git a/clang/test/Instrumentor/StackUsageRT.cpp
b/clang/test/Instrumentor/StackUsageRT.cpp
new file mode 100644
index 0..9f2b29b8f050d
--- /dev/null
+++ b/clang/test/Instrumentor/StackUsageRT.cpp
@@ -0,0 +1,59 @@
+//===-- examples/Instrumentor/stack_usage.c - An example Instrumentor use
-===//
+//
+// 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
+//
+//===--===//
+//
+//
+//===--===//
+
+#include
+#include
+#include
+
+struct StackTracker {
+ std::list CallStack;
+ int64_t FunctionStackUsage = 0;
+ int64_t TotalStackUsage = 0;
+
+ std::list HighWaterMarkCallStack;
+ int64_t HighWaterMark = 0;
+
+ ~StackTracker() {
+printf("Stack usage peaked at %lli in\n", HighWaterMark);
+HighWaterMarkCallStack.reverse();
+for (char *Name : HighWaterMarkCallStack)
+ printf("- %s\n", Name);
+ }
+
+ void enter(char *Name) {
+FunctionStackUsage = 0;
+CallStack.push_back(Name);
+ }
+ void exit(char *Name) {
+CallStack.pop_back();
+TotalStackUsage -= FunctionStackUsage;
+ }
+
+ void allocate(int64_t size) {
+TotalStackUsage += size;
+FunctionStackUsage += size;
+if (TotalStackUsage <= HighWaterMark)
+ return;
+HighWaterMark = TotalStackUsage;
+HighWaterMarkCallStack = CallStack;
+ }
+};
+
+static thread_local StackTracker ST;
+
+extern "C" {
+
+void __stack_usage_pre_function(char *Name) { ST.enter(Name); }
+
+void __stack_usage_post_function(char *Name) { ST.exit(Name); }
+
+void __stack_usage_pre_alloca(int64_t size) { ST.allocate(size); }
+}
diff --git a/clang/test/Instrumentor/StackUsageRT.json
b/clang/test/Instrumentor/StackUsageRT.json
new file mode 100644
index 0..491ab9cf5ea05
--- /dev/null
+++ b/clang/test/Instrumentor/StackUsageRT.json
@@ -0,0 +1,54 @@
+{
+ "configuration": {
+"runtime_prefix": "__stack_usage_",
+"runtime_prefix.description": "The runtime API prefix.",
+"demangle_function_names": true,
+"demangle_function_names.description": "Demangle functions names passed to
the
[clang] [llvm] [Instrumentor] Add Alloca and Function support; stack usage example (PR #195378)
github-actions[bot] wrote:
# :penguin: Linux x64 Test Results
* 173991 tests passed
* 3318 tests skipped
* 1 test failed
## Failed Tests
(click on a test name to see its output)
### Clang
Clang.Instrumentor/InstrumentorStackUsage.cpp
```
Exit Code: 1
Command Output (stdout):
--
# RUN: at line 2
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang
--driver-mode=g++ -O0
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/Instrumentor/StackUsageRT.cpp
-o
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/Instrumentor/Output/InstrumentorStackUsage.cpp.tmp.StackUsageRT.o
-c
# executed command:
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang
--driver-mode=g++ -O0
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/Instrumentor/StackUsageRT.cpp
-o
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/Instrumentor/Output/InstrumentorStackUsage.cpp.tmp.StackUsageRT.o
-c
# .---command stderr
# |
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/Instrumentor/StackUsageRT.cpp:25:47:
warning: format specifies type 'long long' but the argument has type 'int64_t'
(aka 'long') [-Wformat]
# |25 | printf("Stack usage peaked at %lli in\n", HighWaterMark);
# | | ^
# | | %li
# | 1 warning generated.
# `-
# RUN: at line 3
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang
--driver-mode=g++ -O0 -mllvm -enable-instrumentor -mllvm
-instrumentor-read-config-file=/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/Instrumentor/StackUsageRT.json
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/Instrumentor/Output/InstrumentorStackUsage.cpp.tmp.StackUsageRT.o
-o
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/Instrumentor/Output/InstrumentorStackUsage.cpp.tmp
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/Instrumentor/InstrumentorStackUsage.cpp
# executed command:
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang
--driver-mode=g++ -O0 -mllvm -enable-instrumentor -mllvm
-instrumentor-read-config-file=/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/Instrumentor/StackUsageRT.json
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/Instrumentor/Output/InstrumentorStackUsage.cpp.tmp.StackUsageRT.o
-o
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/Instrumentor/Output/InstrumentorStackUsage.cpp.tmp
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/Instrumentor/InstrumentorStackUsage.cpp
# .---command stderr
# | fatal error: error in backend: IO sandbox violation
# | clang: error: clang frontend command failed with exit code 70 (use -v to
see invocation)
# | clang version 23.0.0git (https://github.com/llvm/llvm-project
29079ce84dec586f175072b5216cc89b7194f4a5)
# | Target: x86_64-unknown-linux-gnu
# | Thread model: posix
# | InstalledDir:
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin
# | Build config: +assertions
# | clang: note: diagnostic msg:
# |
# |
# | PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
# | Preprocessed source(s) and associated run script(s) are located at:
# | clang: note: diagnostic msg:
/tmp/lit-tmp-ktxk4tj_/InstrumentorStackUsage-890091.cpp
# | clang: note: diagnostic msg:
/tmp/lit-tmp-ktxk4tj_/InstrumentorStackUsage-890091.sh
# | clang: note: diagnostic msg:
# |
# |
# `-
# error: command failed with exit status: 1
--
```
If these failures are unrelated to your changes (for example tests are broken
or flaky at HEAD), please open an issue at
https://github.com/llvm/llvm-project/issues and add the `infrastructure` label.
https://github.com/llvm/llvm-project/pull/195378
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Instrumentor] Add Alloca and Function support; stack usage example (PR #195378)
github-actions[bot] wrote: # :window: Windows x64 Test Results * 134459 tests passed * 3253 tests skipped * 1 test failed ## Failed Tests (click on a test name to see its output) ### Clang Clang.Instrumentor/InstrumentorStackUsage.cpp ``` Exit Code: 1 Command Output (stdout): -- # RUN: at line 2 c:\_work\llvm-project\llvm-project\build\bin\clang.exe --driver-mode=g++ -O0 C:\_work\llvm-project\llvm-project\clang\test\Instrumentor/StackUsageRT.cpp -o C:\_work\llvm-project\llvm-project\build\tools\clang\test\Instrumentor\Output\InstrumentorStackUsage.cpp.tmp.StackUsageRT.o -c # executed command: 'c:\_work\llvm-project\llvm-project\build\bin\clang.exe' --driver-mode=g++ -O0 'C:\_work\llvm-project\llvm-project\clang\test\Instrumentor/StackUsageRT.cpp' -o 'C:\_work\llvm-project\llvm-project\build\tools\clang\test\Instrumentor\Output\InstrumentorStackUsage.cpp.tmp.StackUsageRT.o' -c # note: command had no output on stdout or stderr # RUN: at line 3 c:\_work\llvm-project\llvm-project\build\bin\clang.exe --driver-mode=g++ -O0 -mllvm -enable-instrumentor -mllvm -instrumentor-read-config-file=C:\_work\llvm-project\llvm-project\clang\test\Instrumentor/StackUsageRT.json C:\_work\llvm-project\llvm-project\build\tools\clang\test\Instrumentor\Output\InstrumentorStackUsage.cpp.tmp.StackUsageRT.o -o C:\_work\llvm-project\llvm-project\build\tools\clang\test\Instrumentor\Output\InstrumentorStackUsage.cpp.tmp C:\_work\llvm-project\llvm-project\clang\test\Instrumentor\InstrumentorStackUsage.cpp # executed command: 'c:\_work\llvm-project\llvm-project\build\bin\clang.exe' --driver-mode=g++ -O0 -mllvm -enable-instrumentor -mllvm '-instrumentor-read-config-file=C:\_work\llvm-project\llvm-project\clang\test\Instrumentor/StackUsageRT.json' 'C:\_work\llvm-project\llvm-project\build\tools\clang\test\Instrumentor\Output\InstrumentorStackUsage.cpp.tmp.StackUsageRT.o' -o 'C:\_work\llvm-project\llvm-project\build\tools\clang\test\Instrumentor\Output\InstrumentorStackUsage.cpp.tmp' 'C:\_work\llvm-project\llvm-project\clang\test\Instrumentor\InstrumentorStackUsage.cpp' # .---command stderr # | fatal error: error in backend: IO sandbox violation # | PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script. # | Stack dump: # | 0. Program arguments: C:\\_work\\llvm-project\\llvm-project\\build\\bin\\clang.exe -cc1 -triple x86_64-pc-windows-msvc19.44.35226 -O0 -emit-obj -dumpdir C:\\_work\\llvm-project\\llvm-project\\build\\tools\\clang\\test\\Instrumentor\\Output\\InstrumentorStackUsage.cpp.tmp- -disable-free -clear-ast-before-backend -main-file-name InstrumentorStackUsage.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=none -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -fms-volatile -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -fdebug-compilation-dir=C:\\_work\\llvm-project\\llvm-project\\build\\tools\\clang\\test\\Instrumentor -fcoverage-compilation-dir=C:\\_work\\llvm-project\\llvm-project\\build\\tools\\clang\\test\\Instrumentor -resource-dir C:\\_work\\llvm-project\\llvm-project\\build\\lib\\clang\\23 -internal-isystem C:\\_work\\llvm-project\\llvm-project\\build\\lib\\clang\\23\\include -internal-isystem C:\\BuildTools\\VC\\Tools\\MSVC\\14.44.35207\\include -internal-isystem C:\\BuildTools\\VC\\Tools\\MSVC\\14.44.35207\\ATLMFC\\include -internal-isystem C:\\BuildTools\\VC\\Auxiliary\\VS\\include -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.26100.0\\ucrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10include\\10.0.26100.0um" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10include\\10.0.26100.0shared" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10include\\10.0.26100.0winrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10include\\10.0.26100.0cppwinrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\NETFXSDK\\4.8\\include\\um" -fdeprecated-macro -ferror-limit 19 -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.44.35226 -std=c++14 -fskip-odr-check-in-gmf -fdelayed-template-parsing -fcxx-exceptions -fexceptions -mllvm -enable-instrumentor -mllvm -instrumentor-read-config-file=C:\\_work\\llvm-project\\llvm-project\\clang\\test\\Instrumentor/StackUsageRT.json -faddrsig -o C:\\Users\\ContainerAdministrator\\AppData\\Local\\Temp\\lit-tmp-36sk3pb9\\InstrumentorStackUsage-d539c3.o -x c++ C:\\_work\\llvm-project\\llvm-project\\clang\\test\\Instrumentor\\InstrumentorStackUsage.cpp # | 1. parser at end of file # | 2. Optimizer # | 3. Running pass "instrumentor" on module "C:\_work\llvm-project\llvm-project\clang\test\Instrumentor\InstrumentorStackUsage.cpp" # | clang: error: clang frontend command failed with exit code 70 (use -v to see invocation) # |
