-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
Conversation
@llvm/pr-subscribers-mc Author: None (aengelke) ChangesDue 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:
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);
}
|
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? |
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. |
Thanks for the explanation! |
Due to alignment, MCFragment was 1 byte over the 8 byte boundary, so folding to bools into bitfields gives a nice space reduction.
4c31b47
to
e034a43
Compare
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.
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.