This is an archive of the discontinued LLVM Phabricator instance.

[X86][MC][NFC] Reduce the parameters of functions in X86MCCodeEmitter(Part III)
ClosedPublic

Authored by skan on Apr 18 2020, 2:24 AM.

Details

Summary

When we encode an instruction, we need to know the number of bytes being
emitted to determine the fixups in X86MCCodeEmitter::emitImmediate.
There are only two callers for emitImmediate: emitMemModRMByte and
encodeInstruction.

Before this patch, we kept track of the current byte being emitted
by passing a reference parameter CurByte across all the emit*
funtions, which is ugly and unnecessary. For example, we don't have any
fixups when emitting prefixes, so we don't need to track this value.

In this patch, we use StartByte to record the initial status of the
streamer, and use OS.tell() to get the current status of the streamer
when we need to know the number of bytes being emitted. On one hand,
this eliminates the parameter CurByte for most emit* functions, on
the other hand, this make things clear: Only pass the parameter when we
really need it.

Diff Detail

Event Timeline

skan created this revision.Apr 18 2020, 2:24 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 18 2020, 2:24 AM
craig.topper added inline comments.Apr 18 2020, 11:56 AM
llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
1388

tell() returns a uint64_t and since you can't know how the encoder is being called, I think you have to assume you might have more than 2^32 bytes in the stream already.

skan updated this revision to Diff 258580.Apr 18 2020, 10:58 PM

Address review comments

MaskRay accepted this revision.Apr 19 2020, 3:21 PM

tell() returns a uint64_t and since you can't know how the encoder is being called, I think you have to assume you might have more than 2^32 bytes in the stream already.

You have addressed @craig.topper's comment but please remember to mark it as done (click done before arc diff)

This revision is now accepted and ready to land.Apr 19 2020, 3:21 PM
This revision was automatically updated to reflect the committed changes.
skan marked an inline comment as done.