Skip to content

[MC] Reduce size of MCDataFragment by 8 bytes #95293

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

Merged
merged 1 commit into from
Jun 13, 2024

Conversation

aengelke
Copy link
Contributor

@aengelke aengelke commented Jun 12, 2024

Due to alignment, MCEncodedFragment was 1 byte over the 8 byte boundary, so folding to bools into bitfields in MCFragment gives a nice space reduction of MCDataFragment from 224 to 216 bytes.

@aengelke aengelke requested a review from MaskRay June 12, 2024 19:38
@llvmbot llvmbot added the mc Machine (object) code label Jun 12, 2024
@llvmbot
Copy link
Member

llvmbot commented Jun 12, 2024

@llvm/pr-subscribers-mc

Author: None (aengelke)

Changes

Due to alignment, MCFragment was 1 byte over the 8 byte boundary, so folding to bools into bitfields gives a nice space reduction from 224 to 216 bytes.


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

2 Files Affected:

  • (modified) llvm/include/llvm/MC/MCFragment.h (+2-2)
  • (modified) llvm/lib/MC/MCFragment.cpp (+1-1)
diff --git a/llvm/include/llvm/MC/MCFragment.h b/llvm/include/llvm/MC/MCFragment.h
index 45599c940659e..d33160f4ff010 100644
--- a/llvm/include/llvm/MC/MCFragment.h
+++ b/llvm/include/llvm/MC/MCFragment.h
@@ -73,8 +73,8 @@ class MCFragment {
   FragmentType Kind;
 
 protected:
-  bool HasInstructions;
-  bool LinkerRelaxable = false;
+  bool HasInstructions : 1;
+  bool LinkerRelaxable : 1;
 
   MCFragment(FragmentType Kind, bool HasInstructions,
              MCSection *Parent = nullptr);
diff --git a/llvm/lib/MC/MCFragment.cpp b/llvm/lib/MC/MCFragment.cpp
index 6d97e8ce552ba..f245f39a87e9f 100644
--- a/llvm/lib/MC/MCFragment.cpp
+++ b/llvm/lib/MC/MCFragment.cpp
@@ -200,7 +200,7 @@ uint64_t llvm::computeBundlePadding(const MCAssembler &Assembler,
 MCFragment::MCFragment(FragmentType Kind, bool HasInstructions,
                        MCSection *Parent)
     : Parent(Parent), Atom(nullptr), Offset(~UINT64_C(0)), LayoutOrder(0),
-      Kind(Kind), HasInstructions(HasInstructions) {
+      Kind(Kind), HasInstructions(HasInstructions), LinkerRelaxable(false) {
   if (Parent && !isa<MCDummyFragment>(*this))
     Parent->addFragment(*this);
 }

@nikic
Copy link
Contributor

nikic commented Jun 12, 2024

Somewhat confused here. We have an unsigned, followed by uint8_t and two bools. That should fit into 8 bytes?

And why is MCFragment currently 224 bytes? Isn't it just 40?

@aengelke
Copy link
Contributor Author

aengelke commented Jun 12, 2024

MCDataFragment goes from 224 to 216 bytes, MCFragment from 39 to 38. MCEncodedFragment adds two bytes and now goes from 41 to 40 bytes. In the C++ Itanium ABI, there is no padding after base classes.

Edit: I made the comment a bit clearer. Sorry for not providing enough data in the initial message.

@nikic
Copy link
Contributor

nikic commented Jun 12, 2024

Thanks for the explanation!

@MaskRay
Copy link
Member

MaskRay commented Jun 12, 2024

Before the removal of SubsectionNumber (#95077) and IsBeingLaidOut (9d0754a), sizeof(MCDataFragment) was 232 It's now 224. Yes! With some bit fields we can decrease it to 216.

Due to alignment, MCFragment was 1 byte over the 8 byte boundary, so
folding to bools into bitfields gives a nice space reduction.
@aengelke aengelke merged commit 846e47e into llvm:main Jun 13, 2024
5 of 6 checks passed
@aengelke aengelke deleted the perf/mcfragsize branch June 13, 2024 10:05
EthanLuisMcDonough pushed a commit to EthanLuisMcDonough/llvm-project that referenced this pull request Aug 13, 2024
Due to alignment, the first two fields of MCEncodedFragment are
currently at bytes 40 and 41, so 1 byte over the 8 byte boundary,
causing 7 bytes padding to be inserted for the following pointer.

Fold two bools of MCFragment into bitfields to reduce move the two
fields of MCEncodedFragment one byte earlier to remove the padding
bytes. This works, as in the Itanium ABI, there is no padding after
base classes.

This gives a space reduction of MCDataFragment from 224 to 216 bytes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mc Machine (object) code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants