[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:55 PDT 2026


================
@@ -227,11 +228,44 @@ bool InstrumentorImpl::instrumentFunction(Function &Fn) {
     return Changed;
 
   InstrumentationCaches ICaches;
+  SmallVector<Instruction *> FinalTIs;
   ReversePostOrderTraversal<Function *> 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 &ChoiceIt : IConf.IChoices[InstrumentationLocation::FUNCTION_PRE]) {
+    if (!ChoiceIt.second->Enabled)
+      continue;
+    // Count epochs eagerly.
+    ++IIRB.Epoch;
+
+    IIRB.IRB.SetInsertPointPastAllocas(cast<Function>(FPtr));
+    ensureDbgLoc(IIRB.IRB);
+    ChoiceIt.second->instrument(FPtr, IConf, IIRB, ICaches);
+    IIRB.returnAllocas();
+  }
 
+  for (auto &ChoiceIt :
+       IConf.IChoices[InstrumentationLocation::FUNCTION_POST]) {
+    if (!ChoiceIt.second->Enabled)
+      continue;
+    // Count epochs eagerly.
+    ++IIRB.Epoch;
+
+    for (auto *FinalTI : FinalTIs) {
----------------
arsenm wrote:

No auto 

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


More information about the llvm-branch-commits mailing list