[PATCH] D155153: [BOLT][NFC] Add post-CFG processing to MetadataRewriter interface
Maksim Panchenko via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 12 22:28:32 PDT 2023
maksfb created this revision.
maksfb added reviewers: treapster, jobnoorman, yota9, Amir, ayermolo, rafauler.
Herald added a project: All.
maksfb requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Add MetadataRewriter::postCFGInitializer().
Depends on D154815 <https://reviews.llvm.org/D154815>
Repository:
rG LLVM Github Monorepo
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
@@ -721,6 +721,8 @@
postProcessFunctions();
+ processMetadataPostCFG();
+
if (opts::DiffOnly)
return Error::success();
@@ -2917,6 +2919,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.539848.patch
Type: text/x-patch
Size: 3140 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230713/b72240b5/attachment.bin>
More information about the llvm-commits
mailing list