[llvm-branch-commits] [clang] [llvm] [Instrumentor] Add Alloca and Function support; stack usage example (PR #195378)

Matt Arsenault via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon May 4 06:18:56 PDT 2026


================
@@ -535,6 +557,96 @@ struct InstructionIO : public InstrumentationOpportunity {
   }
 };
 
+/// The instrumentation opportunity for functions.
+struct FunctionIO : public InstrumentationOpportunity {
+  FunctionIO(bool IsPRE)
+      : InstrumentationOpportunity(
+            InstrumentationLocation(InstrumentationLocation(
+                IsPRE ? InstrumentationLocation::FUNCTION_PRE
+                      : InstrumentationLocation::FUNCTION_POST))) {}
+  virtual ~FunctionIO() {};
+
+  enum ConfigKind {
+    PassAddress = 0,
+    PassName,
+    PassNumArguments,
+    PassArguments,
+    ReplaceArguments,
+    PassIsMain,
+    PassId,
+    NumConfig,
+  };
+
+  struct ConfigTy final : public BaseConfigTy<ConfigKind> {
+    std::function<bool(Argument &)> ArgFilter;
+
+    ConfigTy(bool Enable = true) : BaseConfigTy(Enable) {}
+  } Config;
+
+  StringRef getName() const override { return "function"; }
+
+  void init(InstrumentationConfig &IConf, LLVMContext &Ctx,
+            ConfigTy *UserConfig = nullptr);
+
+  static Value *getFunctionAddress(Value &V, Type &Ty,
+                                   InstrumentationConfig &IConf,
+                                   InstrumentorIRBuilderTy &IIRB);
+  static Value *getFunctionName(Value &V, Type &Ty,
+                                InstrumentationConfig &IConf,
+                                InstrumentorIRBuilderTy &IIRB);
+  Value *getNumArguments(Value &V, Type &Ty, InstrumentationConfig &IConf,
+                         InstrumentorIRBuilderTy &IIRB);
+  Value *getArguments(Value &V, Type &Ty, InstrumentationConfig &IConf,
+                      InstrumentorIRBuilderTy &IIRB);
+  Value *setArguments(Value &V, Value &NewV, InstrumentationConfig &IConf,
+                      InstrumentorIRBuilderTy &IIRB);
+  static Value *isMainFunction(Value &V, Type &Ty, InstrumentationConfig &IConf,
+                               InstrumentorIRBuilderTy &IIRB);
+
+  static void populate(InstrumentationConfig &IConf, LLVMContext &Ctx) {
+    for (auto IsPRE : {true, false}) {
+      auto *AIC = IConf.allocate<FunctionIO>(IsPRE);
+      AIC->init(IConf, Ctx);
+    }
+  }
+};
+
+/// The instrumentation opportunity for alloca instructions.
+struct AllocaIO : public InstructionIO<Instruction::Alloca> {
----------------
arsenm wrote:

final? 

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


More information about the llvm-branch-commits mailing list