[PATCH] D155156: [BOLT] Attach ORC info to instructions in CFG
Maksim Panchenko via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 12 23:15:40 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.
Propagate Linux Kernel ORC information read from the file to the whole
function CFG once the graph has been built. We have a choice to either
attach ORC state annotation to every instruction, or to the first
instruction in the basic block to conserve processing memory. I chose to
attach to every instruction under --print-orc option which is currently
on by default.
Depends on D155153 <https://reviews.llvm.org/D155153>
Repository:
rG LLVM Github Monorepo
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
@@ -114,6 +114,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();
@@ -135,6 +138,13 @@
return Error::success();
}
+ Error postCFGInitializer() override {
+ if (Error E = processORCPostCFG())
+ return E;
+
+ return Error::success();
+ }
+
Error postEmitFinalizer() override {
updateLKMarkers();
@@ -512,6 +522,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.539855.patch
Type: text/x-patch
Size: 2123 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230713/0a10d0d2/attachment.bin>
More information about the llvm-commits
mailing list