This is an archive of the discontinued LLVM Phabricator instance.

[X86][MC] Emit instructions into SmallVector
ClosedPublic

Authored by aengelke on Mar 10 2023, 6:57 AM.

Details

Summary

Depends on D145791

Storing instruction bytes directly in a SmallVector instead of a
raw_ostream yields better encoding performance (in some applications,
the improvment is ~1% of the complete back-end time).

Diff Detail

Event Timeline

aengelke created this revision.Mar 10 2023, 6:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 10 2023, 6:57 AM
aengelke requested review of this revision.Mar 10 2023, 6:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 10 2023, 6:57 AM

It'd be very useful to know why replacing raw_svector_ostream (which is really just a SmallVectorImpl<char> wrapper itself) is so much slower than using SmallVector directly

It essentially boils down to having function calls for every written byte, which adds up. I haven't tested with (Thin)LTO yet, but a quick glance at the disassembly of a Fedora-built LLVM (which uses ThinLTO) seems to indicate that such function calls are not eliminated.

MaskRay accepted this revision.Mar 10 2023, 11:34 AM

I have an analysis of the code path: https://reviews.llvm.org/D145791#4185609
There are some if conditions, virtual function calls, SmallVector range append overhead which cannot be eliminated.

This revision is now accepted and ready to land.Mar 10 2023, 11:34 AM
Amir requested changes to this revision.Mar 10 2023, 2:59 PM
Amir added a subscriber: Amir.

Please also take care of BOLT call sites.

This revision now requires changes to proceed.Mar 10 2023, 2:59 PM
aengelke updated this revision to Diff 511346.Apr 6 2023, 3:01 AM

No changes, just to trigger rebuild from updated D145791.

aengelke updated this revision to Diff 511360.Apr 6 2023, 4:01 AM

Formatting fixes

@Amir The BOLT problems were already addressed with an updated version of D145791; this patch should not affect any BOLT uses. Tests also pass now.

Amir accepted this revision.Apr 10 2023, 12:58 PM

No objections now, and MaskRay has approved it so feel free to land

This revision is now accepted and ready to land.Apr 10 2023, 12:58 PM
This revision was automatically updated to reflect the committed changes.
skan added a subscriber: skan.Apr 11 2023, 7:01 PM