This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by skan on Apr 15 2020, 12:10 AM.

Details

Summary

The function in X86MCCodeEmitter has too many parameters to make it look
messy, and some parameters are unnecessary. This is the first patch to
reduce their parameters.

The follwing operations are cheap

unsigned Opcode = MI.getOpcode();
const MCInstrDesc &Desc = MCII.get(Opcode);
uint64_t TSFlags = Desc.TSFlags;

So if we pass a MCInst, we don't need to pass MCInstrDesc;
if we pass a MCInstrDesc, we don't need to pass TSFlags.

Diff Detail

Event Timeline

skan created this revision.Apr 15 2020, 12:10 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 15 2020, 12:10 AM
skan added a subscriber: annita.zhang.
skan marked an inline comment as done.Apr 15 2020, 1:35 AM
skan added inline comments.
llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
1309–1310

Comment to myself: Plan to fix this "FIXME" in Part2

It's better to add NFC in the title.
The type of TSFlags is uint64_t instead of const uint64_t, is it possible this value been changed during function call?

skan retitled this revision from [X86][MC] Reduce the parameters of functions in X86MCCodeEmitter(Part I) to [X86][MC][NFC] Reduce the parameters of functions in X86MCCodeEmitter(Part I).Apr 15 2020, 2:12 AM
skan added a comment.Apr 15 2020, 2:14 AM

It's better to add NFC in the title.
The type of TSFlags is uint64_t instead of const uint64_t, is it possible this value been changed during function call?

As far as I know, TSFlags is constant during function call. (At least in this file it's constant) @craig.topper

craig.topper accepted this revision.Apr 15 2020, 2:05 PM

This patch LGTM. The comments are all for future work.

llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
644

While you're cleaning up things in this file? Can you merge this if with the "MemoryOperand != -1" above. The only negative value returned by getMemoryOperandNo is -1 so these ifs are the same. Separate patch.

656

Also fix this to be CamelCase not snake_case.

1309–1310

Pretty sure REX prefix has to come after 0xF2 so I don't think that can be fixed.

1312

Should we just make determineREXPrefix be emitREXPrefix and move the emitByte into it. Its more arguments, but more consistent.

This revision is now accepted and ready to land.Apr 15 2020, 2:05 PM
This revision was automatically updated to reflect the committed changes.