[llvm-dev] Allocating global variables to physical registers

David Spickett via llvm-dev llvm-dev at lists.llvm.org
Mon Feb 1 01:42:41 PST 2021


Sounds like "Global Named Register Variables". E.g.
clang ... -ffixed-r3 ...
register unsigned arm_r3 __asm("r3");

I know these are supported for Arm. See:
https://reviews.llvm.org/D3797
https://reviews.llvm.org/D68862 (includes test files that'll show you
how to use it from C)

I don't know whether that will "just work" for your backend (I assume
you need some option to mark the reserved register) but it should give
you a starting point.

Thanks,
David Spickett.

On Sat, 30 Jan 2021 at 01:34, Dobby HouseElf via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
>
> Hello all,
>
> Is it possible to assign specific physical register(s) to a 'special' global variable at the time of code generation phase in LLVM?
>
> Details: I have a Mips-like target and following Cpu0 tutorial, I added my custom backend to LLVM. I have a global variable that I want to use in many places in the program. I define a global variable in the program like, 'test.cpp' - 'int special;'
> I want to assign / allocate a specific physical register in my backend to this special global variable.
>
> Current status: Using 'llc -debug', I see that during the register allocation (greedy), the address of 'special' variable goes to a general purpose register and then it loads in a random general purpose register.
>
> I don't know if it is possible what I am trying to do? At which compilation stage should I try?
> I read somewhere that using 'register' keyword is not good idea.
>
> Thank you very much.
> Excuse my English.
> Please help!
>
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev


More information about the llvm-dev mailing list