Question about MachineFunction Pass

Hi,

I wrote a machinefunction pass to try to see what's going on. Does it mean that it is target machine dependent pass, like x86? However, after compile it, I found there wasnot command option I registered. I used regular way to do it like RegisterOpt <...> X("... ", "... "), but I cannot see the optimized option when I use opt -load ../../lib/Debug/libxxx.so --help. And from LLVM source code, I saw some passes use runOnMachineFunction(MachineFunction &MF), but there is no API like registerOpt. what does it mean? Thanks

For MachineFunction pass, the doc says it is not allowed to do any of the following:
  1.. Modify any LLVM Instructions, BasicBlocks or Functions.
  2.. Modify a MachineFunction other than the one currently being processed.
  3.. Add or remove MachineFunctions from the current Module.
  4.. Add or remove global variables from the current Module.
  5.. Maintain state across invocations of runOnMachineFunction (including global data)
It seems I cannot insert some instructions, right?

For MachineInstr.h and MachineInstrBuilder.h and X86InstrBuilder.h, I am just wondering if we can construct some X86 assemble instruction? if so, can we insert the X86 assemble instruction to bytecode( bytecode is IR code which should be conflicted with X86 asm) if I used runOnMachineFunction pass ?

I wrote a machinefunction pass to try to see what's going on. Does it
mean that it is target machine dependent pass, like x86? However, after
compile it, I found there wasnot command option I registered. I used
regular way to do it like RegisterOpt <...> X("... ", "... "), but I
cannot see the optimized option when I use opt -load
../../lib/Debug/libxxx.so --help. And from LLVM source code, I saw some
passes use runOnMachineFunction(MachineFunction &MF), but there is no
API like registerOpt. what does it mean? Thanks

MachineFunctionPass instances are part of the code generator. As such,
they are not supposed to modify the LLVM code and their output does not go
to bytecode.

You *can* write target specific (e.g. the X86 floating point stackifier
pass) or target independent passes (e.g. the register allocators) with
MachineFunctionPass's, but I don't think this is what you really want to
do.

For MachineFunction pass, the doc says it is not allowed to do any of the following:

MachineFunctionPass's are even more restricted than FunctionPass's.

It seems I cannot insert some instructions, right?

Correct.

For MachineInstr.h and MachineInstrBuilder.h and X86InstrBuilder.h, I am
just wondering if we can construct some X86 assemble instruction? if so,

Yes.

can we insert the X86 assemble instruction to bytecode( bytecode is IR
code which should be conflicted with X86 asm) if I used
runOnMachineFunction pass ?

No you can't do this yet, and when you can, it won't be with a
MachineFunctionPass. What you are really trying to do is use a form of
inline assembly in the LLVM bytecode. Unfortunately, we do not support
this feature yet, but it is on the mid-range "todo list". I don't know of
anyone who is planning on tackling the job yet though.

Why do you want to insert assembly language?

-Chris

How can I declare a function prototype in C/C++ such that the gcc front end
won't mangle the name? I was told that extern would work once but it
doesn't.

Use :
   
   extern "C" void func();

The "C" is the key.