[llvm-dev] TableGen operand question

Dawid Retkiewicz via llvm-dev llvm-dev at lists.llvm.org
Thu Jun 9 02:41:44 PDT 2016


Hi,

As a way to learn LLVM, I'm trying to write a backend for the Microchip
PIC18 8-bit microcontroller.
On this device, the hardware stack is very small and is used only for
storing function return addresses.
A "real" software stack implementation is not very efficient because of the
limited instruction set, so for all the non-reentrant functions I've
decided to use a similar solution to the one used by Microchip's own XC8
compiler, which is to simulate the stack by assigning constant memory
locations to every function.
Local variables/parameters could then be accessed by using constant memory
addresses. Since this microcontroller can perform most instruction directly
on such addresses, this seems the most efficient way to handle the stack.

The issue I'm facing right now is how to resolve the stack addresses in the
LLVM backend.
For instance, when calling a function, I'd like to store its parameters
directly in the memory area assigned to this function.
If I understand correctly, the exact stack size (and thus the memory needed
by each function) cannot be determined before the epilogue/prologue
insertion pass.This means that the target memory location is not known
before this step.

My idea is to create an operand that would hold an identifier of the target
function and the memory offset, and replace this identifier with a real
memory address in a pass after emit prologue/epilogue.
However, I'm not sure how to achieve such thing in TableGen, and whether
it's at all possible.
I would be grateful for any tips/directions

Thanks,
Dawid Retkiewicz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160609/ebad74a6/attachment.html>


More information about the llvm-dev mailing list