Nisal Menuka via llvm-dev
2017-Jun-09 17:02 UTC
[llvm-dev] Reserve ARM register for only section of the program
Hi, 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 Nisal
Tim Northover via llvm-dev
2017-Jun-11 00:40 UTC
[llvm-dev] Reserve ARM register for only section of the program
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.
Tim Northover via llvm-dev
2017-Jun-13 02:54 UTC
[llvm-dev] Reserve ARM register for only section of the program
Hi Nisal, (Adding llvm-dev back again; best to keep these things public in case they help someone else in the future). On 12 June 2017 at 19:43, Nisal Menuka <nisalmenuka23 at gmail.com> wrote:> 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. Cheers. Tim.
Nisal Menuka via llvm-dev
2017-Jun-14 19:33 UTC
[llvm-dev] Reserve ARM register for only section of the program
Hi, Thanks a lot. Is it possible to implement that functionality as a pragma? Ex. .. [code] ... #pragma A .. .. #pragma B .. .. Lets say I want to reserve registers X9 and X10 only within pragma A and B. Is it possible to achieve this in llvm? Thanks Nisal On Mon, Jun 12, 2017 at 9:54 PM, Tim Northover <t.p.northover at gmail.com> wrote:> Hi Nisal, > > (Adding llvm-dev back again; best to keep these things public in case > they help someone else in the future). > > On 12 June 2017 at 19:43, Nisal Menuka <nisalmenuka23 at gmail.com> wrote: >> 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. > > Cheers. > > Tim.
Possibly Parallel Threads
- Reserve ARM register for only section of the program
- How vregs are assigned to operands in IR
- [bug report] null ptr deref in nouveau_platform_probe (tegra186-p2771-0000)
- nonparametric covariance analysis
- [LLVMdev] ScheduleDAGInstrs computes deps using IR Values that may be invalid