getInstruction() in the target disassembler will explicitly clear the MCInst operand list. Some targets were already doing this, but not all. Without this change, repeatedly passing in the same MCInst to getInstruction() will append the current instruction's operands to the previous instruction's operands.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
Wouldn't it be preferable to do the MI.clear() *within* decodeInstruction? It seems odd to define the interface so that every caller must call clear() itself ...
That sounds reasonable. Not every implementation of getInstruction() calls decodeInstruction(), but I can explicitly call MI.clear() in those cases. The only issue is that decodeInstruction() is an auto generated routine.
I'll update my patch.
In general, this looks good to me. As a stylistic preference, I'd rather place the .clear() calls closer to the initial .setOpcode() calls to keep the sequences that fill in the MCInst close together; see below.
lib/Target/X86/Disassembler/X86Disassembler.cpp | ||
---|---|---|
151 ↗ | (On Diff #31167) | I think this can be pushed down into translateInstruction(). |
utils/TableGen/FixedLenDecoderEmitter.cpp | ||
2093 ↗ | (On Diff #31167) | And this can be pushed down into the MCD::OPC_Decode case. (In the MCD::OPC_TryDecode case, we're using a temporary anyway.) |
- Integrate uweigand's feedback: move MI.clear() into MCD::OPC_Decode case and call MI.clear() inside of translateInstruction() for the X86 target.