[llvm-dev] "Custom" plus "libcall" legalisation

Joan Lluch via llvm-dev llvm-dev at lists.llvm.org
Thu Apr 18 12:27:53 PDT 2019


Hi all,

I am developing a LLVM backend for a custom architecture which will be used for demonstration purposes in an academic environment.

I have already achieved some major goals and the backend is already producing correct assembly code in most circumstances.

However, I have now an issue that I do not know how to solve. I want to implement an instruction that should be lowered as ‘custom' or as ‘libcall' depending on the operators. Particularly, I want that shift instructions (namely SRA, SHL and SRL) get lowered to ‘custom' code when the shift amount is a constant, but I want to call a function otherwise. So far, I have set the operation action to ‘custom’. In the LowerShifts function I determine whether the shift amount is a constant, and I generate custom code for that case. When the shift amount is not a constant, I return a target-specific ISD, which is lately processed as a Custom Inserter. 

I want to replace the Custom Inserter by a call to a function (or libcall?), but I am lost at the way to implement that. I can think on several scenarios, but none of them seems to be easy or clear to me. Ideally, I would want to create the libcall directly form the the LowerShift custom code, but I do know if that is even possible. This leads to the following questions:

(1) Is there a way to convert the ‘custom’ legalisation to ‘libcall’, once I determine (In LowerShifts) that the shift amount was not a constant?
(2) Can I create function call node from my LowerShifts function?
(3) I have separate Shift instructions for constant and non constant shifts in MyTargetInstrInfo.td. Is there a way to get the shift instructions legalised as ‘custom’ or as ‘libcall’ depending on the case?
(4) In case I keep the Custom Inserter, can I emit code to call a function from that? If so, how?
(5) Any other suggestions to achieve the desired behaviour?

Any replies would be appreciated.

Thank you very much.
(Sorry for my English)

Joan Lluch
Puigsacalm, 7 
17458 - Fornells de la Selva
Girona

Tel: 620 28 45 13

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190418/d5d44797/attachment.html>


More information about the llvm-dev mailing list