How to add a custom instruction based on RISCV Vector extension in LLVM

Hi! Community

Here I want to add a custom instruction based on RISCV Vector extension. In RISCV Vector extension, we know that there is an instruction vwmaccu which function is Vector Widening Integer Multiply-Add. I want to add a custom instruction which is parallel to “vwmaccu”, in other words, the function is very similar to it. For example, “Vector Widening Integer Multiply-Shift” to realize some specific application. The instruction format could be basically similar, except that funct6 is different to distinguish functions. And then I will add some arithmetic logic to a RISCV core to implement the function(but it is future work).

I want to know what I need to modify or add in complier level to implement such instruction.

Thank you in advance!


adding a new instruction is not easily explained in a single post but you can find many examples on the internet. E.g.

Alternatively, the book Learn LLVM 12 contains an example of how to add a new instruction at end of chapter 9.



Thank you very much for the document! I will try to solve it.