This is an archive of the discontinued LLVM Phabricator instance.

[MC] Align fragments when -mc-relax-all flag is used
ClosedPublic

Authored by phosek on May 26 2015, 4:19 PM.

Details

Summary

Ensure that fragments are bundle aligned when instruction bundling
is enabled and the -mc-relax-all flag is set. This is implicitly
assumed by the bundle padding implementation but this assumption
does not hold when custom alignment is being used.

The change was tested by running PNaCl toolchain trybots with
-mc-relax-all flag set.

Fixes https://code.google.com/p/nativeclient/issues/detail?id=4063

Diff Detail

Repository
rL LLVM

Event Timeline

phosek updated this revision to Diff 26549.May 26 2015, 4:19 PM
phosek retitled this revision from to Align fragments when -mc-relax-all flag is used.
phosek updated this object.
phosek edited the test plan for this revision. (Show Details)
phosek added a reviewer: eliben.
phosek added a subscriber: mseaborn.

Can you add a bit more context in the commit message:

  • Link to the NaCl bug URL.
  • Say that this is fixing a regression from the earlier "-mc-relax-all" change, which caused ".align" to produce non-validating output. Are there any other directives that output new fragments that this change would fix?

Also, can you say how you tested this, please? Did you run the PNaCl toolchain trybots with "-mc-relax-all" added in pnacl-translate.py?

lib/MC/MCAssembler.cpp
259 ↗(On Diff #26549)

Can you explain this part of the change in the commit message?

Presumably, without this change, ".align 16" would cause an extra 32 bytes of no-ops to be added?

589 ↗(On Diff #26549)

How about adding more context? i.e.:

"""
Without -mc-relax-all, we emit one instruction per fragment. These fragments don't contain no-op bundle padding, so the fragments make no assumption about their alignment.

With -mc-relax-all, we emit multiple instructions per fragment, with no-op bundle padding inside fragments, which means these fragments potentially assume they are bundle-aligned. (At least, a fragment that is larger than the bundle size will assume it is bundle-aligned.) This means that if we end up with multiple fragments, we must emit bundle padding between fragments.

".align N" is an example of a directive that introduces multiple fragments. It might be better to add a special case to handle ".align N" by emitting within-fragment padding (which would produce less padding when N is less than the bundle size), but for now we don't.
"""

test/MC/X86/AlignedBundling/misaligned-bundle-group.s
17 ↗(On Diff #26549)

How about using "call" as a more realistic example, since that is what's used with align_to_end?

test/MC/X86/AlignedBundling/misaligned-bundle.s
13 ↗(On Diff #26549)

It's quite difficult to tell, by reading this test, what it's intended to be testing for.

For a start, how about commenting how many bytes these instructions are meant to be?
e.g.
movl $0x1, (%esp) // 7 bytes [or 5 bytes?]

How about checking for these instructions and their offsets in the output too? The same applies to the other test.

phosek retitled this revision from Align fragments when -mc-relax-all flag is used to [MC] Align fragments when -mc-relax-all flag is used.May 29 2015, 11:33 AM
phosek updated this revision to Diff 27342.Jun 8 2015, 3:43 PM
  • Added comment to provide more context
phosek edited reviewers, added: mseaborn; removed: eliben.Jun 8 2015, 4:19 PM
phosek set the repository for this revision to rL LLVM.
phosek edited subscribers, added: Unknown Object (MLST); removed: mseaborn.
phosek updated this object.Jun 17 2015, 5:14 PM
phosek updated this object.
phosek added inline comments.Jun 17 2015, 5:20 PM
lib/MC/MCAssembler.cpp
589 ↗(On Diff #26549)

Done.

test/MC/X86/AlignedBundling/misaligned-bundle-group.s
17 ↗(On Diff #26549)

Done.

test/MC/X86/AlignedBundling/misaligned-bundle.s
13 ↗(On Diff #26549)

Done.

mseaborn edited edge metadata.Jun 20 2015, 3:46 PM

LGTM, thanks.

test/MC/X86/AlignedBundling/misaligned-bundle-group.s
2 ↗(On Diff #27342)

Nit: Split line with another "\" to keep lines <=80 chars?

phosek updated this revision to Diff 28616.Jun 26 2015, 6:20 PM
phosek edited edge metadata.
  • Use proper line length
phosek added inline comments.Jun 26 2015, 6:21 PM
test/MC/X86/AlignedBundling/misaligned-bundle-group.s
2 ↗(On Diff #27342)

Done.

phosek updated this revision to Diff 28617.Jun 26 2015, 6:24 PM
  • Use proper line length
mseaborn accepted this revision.Jun 26 2015, 6:36 PM
mseaborn edited edge metadata.

LGTM again (this time with "accept revision" selected)

This revision is now accepted and ready to land.Jun 26 2015, 6:36 PM
This revision was automatically updated to reflect the committed changes.