How can I reserve an ARM register for only a part of the code?
Example: lets say I have 3 functions, A(), B() and C(). I want to
prohibit compiler from using a register (lets say X9 in ARM 64) in
function C() only.
I think that by AArch64RegisterInfo::getReservedRegs function, a
register can be reserved for the whole program. But, I need to reserve
for only part of the code.
Can I implement a custom #pragma to do it?
Thanks and Best
There's ABI-blessed support for reserving x18 on AArch64 already via
the -ffixed-x18 Clang option. This gets propagated through to a
"+reserve-x18" entry (or not) in each function's target-features list,
so theoretically compiling your different functions in different
translation units would have the effect you want.
It's also exposed dynamically via
__attribute__((target("reserve-x18"))). Adding a pragma wouldn't be
impossible, but I'm not generally in favour of pragmas personally.
Their scopes are far too vague and broad.
Extending it to other registers would be significantly more
controversial I think. There are potentially complex ABI implications
and we don't want to be left maintaining that non-standard mess (well,
I don't; others might).
(Adding llvm-dev back again; best to keep these things public in case
they help someone else in the future).
I am a first year graduate student at Rice University, I'm looking to
reserve registers X9 and X10 for one of my research projects. I have
some questions regarding this and greatly appreciate any help you can
provide (I am a newbee when it comes to hacking compilers).
1. Is it possible to reserve X9 and X10 by the same methodology used
to reserve X18 in LLVM?
It should be (x9 and x10 are very similar to x18, with no other
special purposes in the ABI), but you'll have to implement it
yourself. Searching for all uses of X18 in lib/Target/AArch64 and
adding your own code for the others would be a good place to get
started. For Clang the key phrase is "fixed_x18".
You're going to have more work to do for the interworking though. For
example if a function with -ffixed-x9-x10 calls one without, you'll
probably have to implement code to save those two registers at the
callsite and restore them afterwards because the callee will be
treating them as temporaries.
2. Else can you suggest a method to achieve it?
If you didn't need interworking I'd probably suggest just
unconditionally reserving them, which would be substantially simpler
(a 2-4 line change in LLVM).
But from what you've said so far I think following x18's
implementation is probably your best bet. It's most of the way there,
and already piped through to Clang in a usable way.
Thanks a lot. Is it possible to implement that functionality as a pragma?
Lets say I want to reserve registers X9 and X10 only within pragma A
and B. Is it possible to achieve this in llvm?
Anything's possible. I've never implemented a pragma before though, so
I have no idea where you'd start. Maybe ask in cfe-dev or look at how
an existing one is handled (e.g. fp_contract to pick a random