[llvm-dev] Reserve ARM register for only section of the program

Tim Northover via llvm-dev llvm-dev at lists.llvm.org
Sat Jun 10 17:40:51 PDT 2017


On 9 June 2017 at 10:02, Nisal Menuka via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
> 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.

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).

Cheers.

Tim.


More information about the llvm-dev mailing list