[PATCH] D147155: [BOLT][NFC] Simplify instrumentFunction v2

Amir Ayupov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 29 06:55:11 PDT 2023


Amir created this revision.
Amir added a reviewer: bolt.
Herald added a reviewer: rafauler.
Herald added subscribers: treapster, ayermolo.
Herald added a reviewer: maksfb.
Herald added a project: All.
Amir requested review of this revision.
Herald added subscribers: llvm-commits, yota9.
Herald added a project: LLVM.

Extract InstrumentEdge


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147155

Files:
  bolt/lib/Passes/Instrumentation.cpp


Index: bolt/lib/Passes/Instrumentation.cpp
===================================================================
--- bolt/lib/Passes/Instrumentation.cpp
+++ bolt/lib/Passes/Instrumentation.cpp
@@ -370,6 +370,23 @@
     bool HasJumpTable = false;
     bool IsInvokeBlock = InvokeBlocks.count(&BB) > 0;
 
+    auto InstrumentEdge = [&](BinaryFunction &TargetFunction,
+                              BinaryBasicBlock &TargetBB, uint64_t FromOffset,
+                              uint64_t TargetOffset,
+                              BinaryBasicBlock::iterator &I) {
+      // Do not instrument edges in the spanning tree
+      if (llvm::is_contained(STOutSet[&BB], &TargetBB)) {
+        auto L = BC.scopeLock();
+        createEdgeDescription(*FuncDesc, Function, FromOffset, BBToID[&BB],
+                              Function, TargetOffset, BBToID[&TargetBB],
+                              /*Instrumented=*/false);
+      } else {
+        instrumentOneTarget(SplitWorklist, SplitInstrs, I, Function, BB,
+                            FromOffset, TargetFunction, &TargetBB, TargetOffset,
+                            IsLeafFunction, IsInvokeBlock, FuncDesc,
+                            BBToID[&BB], BBToID[&TargetBB]);
+      }
+    };
     for (auto I = BB.begin(); I != BB.end(); ++I) {
       const MCInst &Inst = *I;
       if (!BC.MIB->getOffset(Inst))
@@ -404,36 +421,13 @@
         continue;
       }
       if (TargetFunc) {
-        // Do not instrument edges in the spanning tree
-        if (llvm::is_contained(STOutSet[&BB], TargetBB)) {
-          auto L = BC.scopeLock();
-          createEdgeDescription(*FuncDesc, Function, FromOffset, BBToID[&BB],
-                                Function, ToOffset, BBToID[TargetBB],
-                                /*Instrumented=*/false);
-          continue;
-        }
-        instrumentOneTarget(SplitWorklist, SplitInstrs, I, Function, BB,
-                            FromOffset, *TargetFunc, TargetBB, ToOffset,
-                            IsLeafFunction, IsInvokeBlock, FuncDesc,
-                            BBToID[&BB], BBToID[TargetBB]);
+        InstrumentEdge(*TargetFunc, *TargetBB, FromOffset, ToOffset, I);
         continue;
       }
 
       if (IsJumpTable) {
-        for (BinaryBasicBlock *&Succ : BB.successors()) {
-          // Do not instrument edges in the spanning tree
-          if (llvm::is_contained(STOutSet[&BB], &*Succ)) {
-            auto L = BC.scopeLock();
-            createEdgeDescription(*FuncDesc, Function, FromOffset, BBToID[&BB],
-                                  Function, Succ->getInputOffset(),
-                                  BBToID[&*Succ], /*Instrumented=*/false);
-            continue;
-          }
-          instrumentOneTarget(
-              SplitWorklist, SplitInstrs, I, Function, BB, FromOffset, Function,
-              &*Succ, Succ->getInputOffset(), IsLeafFunction, IsInvokeBlock,
-              FuncDesc, BBToID[&BB], BBToID[&*Succ]);
-        }
+        for (BinaryBasicBlock &Succ : llvm::make_pointee_range(BB.successors()))
+          InstrumentEdge(Function, Succ, FromOffset, Succ.getInputOffset(), I);
         continue;
       }
 
@@ -464,18 +458,7 @@
         continue;
       FromOffset = *BC.MIB->getOffset(*LastInstr);
 
-      // Do not instrument edges in the spanning tree
-      if (llvm::is_contained(STOutSet[&BB], FTBB)) {
-        auto L = BC.scopeLock();
-        createEdgeDescription(*FuncDesc, Function, FromOffset, BBToID[&BB],
-                              Function, FTBB->getInputOffset(), BBToID[FTBB],
-                              /*Instrumented=*/false);
-        continue;
-      }
-      instrumentOneTarget(SplitWorklist, SplitInstrs, I, Function, BB,
-                          FromOffset, Function, FTBB, FTBB->getInputOffset(),
-                          IsLeafFunction, IsInvokeBlock, FuncDesc, BBToID[&BB],
-                          BBToID[FTBB]);
+      InstrumentEdge(Function, *FTBB, FromOffset, FTBB->getInputOffset(), I);
     }
   } // End of BBs loop
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147155.509353.patch
Type: text/x-patch
Size: 4029 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230329/ad37635a/attachment.bin>


More information about the llvm-commits mailing list