[PATCH] D155153: [BOLT][NFC] Add post-CFG processing to MetadataRewriter interface

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


This revision was automatically updated to reflect the committed changes.
Closed by commit rGdd630d831cd2: [BOLT][NFC] Add post-CFG processing to MetadataRewriter interface (authored by maksfb).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155153

Files:
  bolt/include/bolt/Rewrite/MetadataManager.h
  bolt/include/bolt/Rewrite/MetadataRewriter.h
  bolt/include/bolt/Rewrite/RewriteInstance.h
  bolt/lib/Rewrite/MetadataManager.cpp
  bolt/lib/Rewrite/RewriteInstance.cpp


Index: bolt/lib/Rewrite/RewriteInstance.cpp
===================================================================
--- bolt/lib/Rewrite/RewriteInstance.cpp
+++ bolt/lib/Rewrite/RewriteInstance.cpp
@@ -722,6 +722,8 @@
 
   postProcessFunctions();
 
+  processMetadataPostCFG();
+
   if (opts::DiffOnly)
     return Error::success();
 
@@ -2920,6 +2922,10 @@
   processProfileDataPreCFG();
 }
 
+void RewriteInstance::processMetadataPostCFG() {
+  MetadataManager.runInitializersPostCFG();
+}
+
 void RewriteInstance::processProfileDataPreCFG() {
   if (!ProfileReader)
     return;
Index: bolt/lib/Rewrite/MetadataManager.cpp
===================================================================
--- bolt/lib/Rewrite/MetadataManager.cpp
+++ bolt/lib/Rewrite/MetadataManager.cpp
@@ -32,6 +32,18 @@
   }
 }
 
+void MetadataManager::runInitializersPostCFG() {
+  for (auto &Rewriter : Rewriters) {
+    LLVM_DEBUG(dbgs() << "BOLT-DEBUG: invoking " << Rewriter->getName()
+                      << " after CFG construction\n");
+    if (Error E = Rewriter->postCFGInitializer()) {
+      errs() << "BOLT-ERROR: while running " << Rewriter->getName()
+             << " in CFG state: " << toString(std::move(E)) << '\n';
+      exit(1);
+    }
+  }
+}
+
 void MetadataManager::runFinalizersAfterEmit() {
   for (auto &Rewriter : Rewriters) {
     LLVM_DEBUG(dbgs() << "BOLT-DEBUG: invoking " << Rewriter->getName()
Index: bolt/include/bolt/Rewrite/RewriteInstance.h
===================================================================
--- bolt/include/bolt/Rewrite/RewriteInstance.h
+++ bolt/include/bolt/Rewrite/RewriteInstance.h
@@ -171,6 +171,9 @@
   /// Process metadata in special sections before CFG is built for functions.
   void processMetadataPreCFG();
 
+  /// Process metadata in special sections after CFG is built for functions.
+  void processMetadataPostCFG();
+
   /// Update debug and other auxiliary information in the file.
   void updateMetadata();
 
Index: bolt/include/bolt/Rewrite/MetadataRewriter.h
===================================================================
--- bolt/include/bolt/Rewrite/MetadataRewriter.h
+++ bolt/include/bolt/Rewrite/MetadataRewriter.h
@@ -49,6 +49,9 @@
   /// contents of the section. Functions are in pre-cfg state.
   virtual Error preCFGInitializer() { return Error::success(); }
 
+  /// Run the rewriter once the functions are in CFG state.
+  virtual Error postCFGInitializer() { return Error::success(); }
+
   /// Finalize section contents based on the new context after the new code is
   /// emitted.
   virtual Error postEmitFinalizer() { return Error::success(); }
Index: bolt/include/bolt/Rewrite/MetadataManager.h
===================================================================
--- bolt/include/bolt/Rewrite/MetadataManager.h
+++ bolt/include/bolt/Rewrite/MetadataManager.h
@@ -33,6 +33,9 @@
   /// CFG is not yet built.
   void runInitializersPreCFG();
 
+  /// Execute metadata initializers after CFG was constructed for functions.
+  void runInitializersPostCFG();
+
   /// Run finalization step of rewriters after code has been emitted.
   void runFinalizersAfterEmit();
 };


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155153.540124.patch
Type: text/x-patch
Size: 3140 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230713/bc1881e6/attachment.bin>


More information about the llvm-commits mailing list