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

Kan Shengchen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 18 02:40:44 PDT 2020


skan created this revision.
skan added reviewers: craig.topper, pengfei.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
skan added a reviewer: MaskRay.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78419

Files:
  llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78419.258497.patch
Type: text/x-patch
Size: 33985 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200418/2525b4b8/attachment.bin>


More information about the llvm-commits mailing list