[llvm-dev] How to add and test new pseudo instruction

Vladimir Miloserdov via llvm-dev llvm-dev at lists.llvm.org
Sat Apr 16 02:06:06 PDT 2016


I want to add new register to Sparc back-end for educational purposes.
I also want to add new pseudo instruction that would add its argument
to this register. And the most complicated (to my mind) - I want to be
able to test (use) it from C source: something like int x = 5;
__domyinstruction(x); /* adds five */ int y = __getmyregister();

I think I can add register (by simply add a line to
SparcRegisterInfo.td file). But adding instruction is a bit more
complicated as I have to add a SelectionDAG pattern in
SparcInstrInfo.td. As far as I understand I have to add:
def MYINSTRUCTION: Pseudo<(outs IntRegs:$dst), (ins IntRegs:$src),
            "; some asm code", [SelectionDAG pattern list]>;
So I don't know how to write this pattern and I'm not sure I need it.
All I want is to add some kind of built-in function to Clang that
would somehow produce MYINSTRUCTION. And currently I don't have any
idea of how to implement __getmyregister(). Any tips?

Thank you, yours,
Vladimir M.

More information about the llvm-dev mailing list