[PATCH] D155156: [BOLT] Attach ORC info to instructions in CFG

Maksim Panchenko via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 13 11:12:34 PDT 2023


maksfb updated this revision to Diff 540125.
maksfb added a comment.

Fix comment.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155156/new/

https://reviews.llvm.org/D155156

Files:
  bolt/lib/Rewrite/LinuxKernelRewriter.cpp


Index: bolt/lib/Rewrite/LinuxKernelRewriter.cpp
===================================================================
--- bolt/lib/Rewrite/LinuxKernelRewriter.cpp
+++ bolt/lib/Rewrite/LinuxKernelRewriter.cpp
@@ -118,6 +118,9 @@
   /// Read ORC unwind information and annotate instructions.
   Error readORCTables();
 
+  /// Update ORC for functions once CFG is constructed.
+  Error processORCPostCFG();
+
   /// Update ORC data in the binary.
   Error rewriteORCTables();
 
@@ -139,6 +142,13 @@
     return Error::success();
   }
 
+  Error postCFGInitializer() override {
+    if (Error E = processORCPostCFG())
+      return E;
+
+    return Error::success();
+  }
+
   Error postEmitFinalizer() override {
     updateLKMarkers();
 
@@ -517,6 +527,41 @@
   return Error::success();
 }
 
+Error LinuxKernelRewriter::processORCPostCFG() {
+  // Propagate ORC to the rest of the function. We can annotate every
+  // instruction in every function, but to minimize the overhead, we annotate
+  // the first instruction in every basic block to reflect the state at the
+  // entry. This way, the ORC state can be calculated based on annotations
+  // regardless of the basic block layout. Note that if we insert/delete
+  // instructions, we must take care to attach ORC info to the new/deleted ones.
+  for (BinaryFunction &BF : llvm::make_second_range(BC.getBinaryFunctions())) {
+    if (!BF.hasORC())
+      continue;
+
+    std::optional<ORCState> CurrentState;
+    for (BinaryBasicBlock &BB : BF) {
+      for (MCInst &Inst : BB) {
+        ErrorOr<ORCState> State =
+            BC.MIB->tryGetAnnotationAs<ORCState>(Inst, "ORC");
+
+        if (State) {
+          CurrentState = *State;
+          continue;
+        }
+
+        if (!CurrentState)
+          continue;
+
+        // While printing ORC, attach info to every instruction for convenience.
+        if (opts::PrintORC || &Inst == &BB.front())
+          BC.MIB->addAnnotation(Inst, "ORC", *CurrentState);
+      }
+    }
+  }
+
+  return Error::success();
+}
+
 Error LinuxKernelRewriter::rewriteORCTables() {
   // TODO:
   return Error::success();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155156.540125.patch
Type: text/x-patch
Size: 2120 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230713/5beda7f4/attachment.bin>


More information about the llvm-commits mailing list