Skip to content

Commit

Permalink
[MC] Move some bool members to MCFragment. NFC
Browse files Browse the repository at this point in the history
Move `AllowAutoPadding` to MCFragment, which reduce the
MCRelaxableFragment size by 8 bytes. While here, also move
`AlignToBundleEnd` next to `HasInstructions`. Functions that create
fragments are slightly shorter due to fewer byte zeroing instructions.

Although fewer in number than MCDataFragments, MCRelaxableFragment
objects still constitute a significant proportion warranting
optimization.
```
% clang -c sqlite3.i -w -g -Xclang -print-stats
...
   2206 assembler             - Number of emitted assembler fragments - align
  83980 assembler             - Number of emitted assembler fragments - data
     84 assembler             - Number of emitted assembler fragments - fill
 169462 assembler             - Number of emitted assembler fragments - total
  11396 assembler             - Number of emitted assembler fragments - relaxable
```

Pull Request: llvm#100976
  • Loading branch information
MaskRay authored Jul 29, 2024
1 parent 2c376fe commit fb70282
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
13 changes: 7 additions & 6 deletions llvm/include/llvm/MC/MCFragment.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,15 @@ class MCFragment {
FragmentType Kind;

protected:
/// Used by subclasses for better packing.
///
/// MCEncodedFragment
bool HasInstructions : 1;
bool AlignToBundleEnd : 1;
/// MCDataFragment
bool LinkerRelaxable : 1;
/// MCRelaxableFragment: x86-specific
bool AllowAutoPadding : 1;

MCFragment(FragmentType Kind, bool HasInstructions);

Expand Down Expand Up @@ -115,9 +122,6 @@ class MCDummyFragment : public MCFragment {
/// data.
///
class MCEncodedFragment : public MCFragment {
/// Should this fragment be aligned to the end of a bundle?
bool AlignToBundleEnd = false;

uint8_t BundlePadding = 0;

protected:
Expand Down Expand Up @@ -228,11 +232,8 @@ class MCDataFragment : public MCEncodedFragmentWithFixups<32, 4> {
/// relaxed during the assembler layout and relaxation stage.
///
class MCRelaxableFragment : public MCEncodedFragmentWithFixups<8, 1> {

/// The instruction this is a fragment for.
MCInst Inst;
/// Can we auto pad the instruction?
bool AllowAutoPadding = false;

public:
MCRelaxableFragment(const MCInst &Inst, const MCSubtargetInfo &STI)
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/MC/MCFragment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
using namespace llvm;

MCFragment::MCFragment(FragmentType Kind, bool HasInstructions)
: Kind(Kind), HasInstructions(HasInstructions), LinkerRelaxable(false) {}
: Kind(Kind), HasInstructions(HasInstructions), AlignToBundleEnd(false),
LinkerRelaxable(false), AllowAutoPadding(false) {}

void MCFragment::destroy() {
switch (Kind) {
Expand Down

0 comments on commit fb70282

Please sign in to comment.