[llvm-dev] How to get emitted size of MachineInstr in MachineFunction pass?

K Jelesnianski via llvm-dev llvm-dev at lists.llvm.org
Thu Oct 25 07:18:34 PDT 2018


Dear dev-list,

I currently have a X86 machineFunctionPass and realized there are more
corner cases than I realized. I need to keep my custom jump transformations
aligned and therefore would like to fill the rest of the space with NOOPs.

I understand that hexcode code ASM is emitted/encoded by the ASMPrinter. In
the past I have gotten the size via 2 compilations (1 to collect asm size
data, 2nd to perform fixup alignment where needed), but am looking for a
cleaner self contained solution.

In the past I used this code, creating a function in X86AsmPrinter class
unsigned int instSize;
SmallString<256> Code;
SmallVector<MCFixup, 4> Fixups;
raw_svector_ostream VecOS(Code);
CodeEmitter->encodeInstruction(Inst, VecOS, Fixups, STI);
instSize = Code.size();

So far, I have already tried to get the size of the opcode at least via:
size= MachineInstr->getDesc().getSize();
but it returns zero, indicating that the encoding size cannot be determined
yet according to the LLVM doxygen, but why? We are already know our target
ISA is X86 and if I do a dump of the MachineInstr, the opcodes and
operands/registers seem already finalized....

So the questions are:
1) Is it possible to temporarily encode a given MachineInstr to a temporary
buffer in a machineFunctionPass?? If so, how?
2) Is it possible to create an instance of CodeEmitter within a
machineFunctionPass to make it possible to run the above code? If so, how?

Thanks in advance.
Sincerely,

K Jelesnianski
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20181025/2099dd10/attachment.html>


More information about the llvm-dev mailing list