MCCodeEmitter Pass?

I’ve looked everywhere, and I can’t seem to find a way to express a pass that is run with a specific target machine code emitter. I’m not sure what to do, because the code emitter is what I could myself define as just a wrapper around the existing one, but there can’t be more than one of them. Several of the classes that are around the MCStreamer pipeline time would be really valuable to allow a Pass in order to insert new components around existing ones at any of those points.

Is there any way to add a pass at this point in the pipeline stage?

The final objective is to obtain the machine opcode bytes of the actual final output that will be written to the object file.

You could get the machine opcodes at MCObjectStreamer::emitInstToFragment.

Well, the object has to be built and embedded into the target build pipeline in order to have the parameters to pass to emitInstToFragment. I don’t know how to modify the pipeline at that level using the LLVM API as there isn’t any guide to make that clear just yet.

In general, each instruction is emitted into a streamer for efficiency, which means we should not iterate over the instructions more than one time. Maybe adding a new pass for your purpose is not worthy, instead, inserting some codes in MCObjectStreamer::emitInstruction is one of the alternatives. However, if you do not care about the compiler time, you can take a look at X86AsmPrinter::EmitAndCountInstruction for reference.

How do you insert codes into an existing mc streamer object for a given target? I don’t generate the type parameters to that for the target, and I’d have to replicate the pipeline code outside of the dynamic call ancestry and data dependence history of that function to obtain a place holder where I could insert my own function before it. I would like to not have to modify LLVM code itself because I don’t think that that is achievable without making a shoddy hack and I would have to insert my code into that library.

Sorry, the question is too abstract for me and I do not have an answer for it. Maybe I can provide some ideas if it could be more concrete.