Skip to content

[BOLT][NFC] Keep input icount for disassembled functions #101091

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

aaupov
Copy link
Contributor

@aaupov aaupov commented Jul 29, 2024

Preserve input instruction count for profile density computation (#101094).
Set it right after disassembly, if it has succeeded.

This way, we address two issues:

  • overhead: otherwise, we'd need to iterate over basic blocks to get
    instruction count.
  • availability: non-simple functions in non-relocation mode (=BOLT split
    functions in BOLTed binaries) don't have CFG, so it's impossible to
    get the number of instructions.

Created using spr 1.3.4
@llvmbot
Copy link
Member

llvmbot commented Jul 29, 2024

@llvm/pr-subscribers-bolt

Author: Amir Ayupov (aaupov)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/101091.diff

2 Files Affected:

  • (modified) bolt/include/bolt/Core/BinaryFunction.h (+6)
  • (modified) bolt/lib/Core/BinaryFunction.cpp (+2)
diff --git a/bolt/include/bolt/Core/BinaryFunction.h b/bolt/include/bolt/Core/BinaryFunction.h
index 24c7db2f5d69c..2c8e23999b60c 100644
--- a/bolt/include/bolt/Core/BinaryFunction.h
+++ b/bolt/include/bolt/Core/BinaryFunction.h
@@ -242,6 +242,9 @@ class BinaryFunction {
   /// Original size of the function.
   uint64_t Size;
 
+  /// Original instruction count of the function, if disassembly succeeded.
+  uint64_t InputInstructionCount{0};
+
   /// Address of the function in output.
   uint64_t OutputAddress{0};
 
@@ -2173,6 +2176,9 @@ class BinaryFunction {
   /// Get the number of instructions within this function.
   uint64_t getInstructionCount() const;
 
+  /// Get the original number of instructions.
+  uint64_t getInputInstructionCount() const { return InputInstructionCount; }
+
   const CFIInstrMapType &getFDEProgram() const { return FrameInstructions; }
 
   void moveRememberRestorePair(BinaryBasicBlock *BB);
diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp
index ea09371b57e8a..1f5869cd0ab73 100644
--- a/bolt/lib/Core/BinaryFunction.cpp
+++ b/bolt/lib/Core/BinaryFunction.cpp
@@ -1499,6 +1499,8 @@ Error BinaryFunction::disassemble() {
 
   clearList(Relocations);
 
+  InputInstructionCount = Instructions.size();
+
   if (!IsSimple) {
     clearList(Instructions);
     return createNonFatalBOLTError("");

@aaupov aaupov closed this Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants