This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by skan on Apr 15 2020, 11:52 PM.

Details

Summary

We determine the REX prefix used by instruction in determineREXPrefix,
and this value is used in `emitMemModRMByte' and used as the return
value of emitOpcodePrefix.

Before this patch, REX was passed as reference to emitPrefixImpl, it
is strange and not necessary, e.g, we have to write

bool Rex = false;
emitPrefixImpl(CurOp, CurByte, Rex, MI, STI, OS);

in emitPrefix even if Rex will not be used.

So we let HasREX be the return value of emitPrefixImpl. The HasREX is passed
from emitREXPrefix to emitOpcodePrefix and then to
emitPrefixImpl. This makes sense since REX is a kind of opcode prefix
and of course is a prefix.

Diff Detail

Event Timeline

skan created this revision.Apr 15 2020, 11:52 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 15 2020, 11:52 PM
craig.topper added inline comments.
llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
1401

Why not return it as a bool from emitREXPrefix?

craig.topper added inline comments.Apr 16 2020, 12:26 AM
llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
1283

Don't we need to check that REX is non-zero before emitting the byte? Am I missing something?

skan marked an inline comment as done.Apr 16 2020, 12:27 AM
skan added inline comments.
llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
1401

To myself, it seems more nature to return a REX ... . I am not sure if furture instruction's encoding will depends on the value of REX. Do you mean it is better to return REX as bool?

skan marked an inline comment as done.Apr 16 2020, 12:33 AM
skan added inline comments.
llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
1283

you are right. I missed this

skan updated this revision to Diff 257975.Apr 16 2020, 12:40 AM

Address part of review comments
Check the REX is not zero before emitting it

skan marked an inline comment as done.Apr 16 2020, 12:54 AM
skan added inline comments.
llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
659–660

Comment to myself: plan to eliminate CurByte as possible by using OS.tell() in Part III.

craig.topper added inline comments.Apr 16 2020, 3:26 PM
llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
1401

Nothing looks at the value, the presence of REX is all that is important so we should just return HasREX. I"m not very concerned that we're going to need to know the value of the REX prefix in the future.

skan updated this revision to Diff 258227.Apr 16 2020, 8:15 PM

Address review comments

skan edited the summary of this revision. (Show Details)Apr 16 2020, 8:16 PM
This revision is now accepted and ready to land.Apr 16 2020, 8:56 PM
This revision was automatically updated to reflect the committed changes.