[llvm-dev] Custom Instruction Cost Model to LLVM RISC-V Backend

Henrik Olsson via llvm-dev llvm-dev at lists.llvm.org
Wed May 27 14:13:47 PDT 2020


I'm unclear on whether it works with automatic variables. Testing it in
clang gives an error message "automatic variable qualified with address
space".
However here is an LLVM discussion on the semantics of alloca with
different address spaces:
https://lists.llvm.org/pipermail/llvm-dev/2015-August/089706.html
Some people seem to have gotten multiple separate stacks working, according
to my skim read.
So it might potentially be technically supported in LLVM, but not in clang.

/Henrik


On Wed, May 27, 2020 at 7:42 PM Bandhav Veluri <bandhav.veluri00 at gmail.com>
wrote:

> Thanks a lot Henrik!
>
> I figured following would mark a pointer to a specific address space:
>
> #define __myaddrspace __attribute__((address_space(1)))
>
> __myaddrspace int* data;
>
> And, I was able to verify loads being annotated to be from addrspace 1 in
> the generated IR. Would this work for automatic variables as well?
>
> In regards to using this in the backend, do I have to just modify the
> source, or is it possible to load a library at runtime, like we load a
> frontend pass?
>
> On Tue, May 26, 2020 at 12:37 PM Henrik Olsson <hnrklssn at gmail.com> wrote:
>
>> Hi Bandhav,
>>
>> While I'm unfamiliar with the details of codegen and cost modelling in
>> LLVM, it is possible to declare multiple address spaces for a target, mark
>> pointers as belonging to a specific address space, and cast between them.
>> To quote the language reference "For targets that support them, address
>> spaces may affect how optimizations are performed and/or what target
>> instructions are used to access the variable.", which sounds quite hopeful
>> for your usecase. If nothing else, you could probably model the loads from
>> different address spaces as being different instructions, even if they are
>> in the end the same instruction in the output machine code, and tag them
>> with different costs.
>>
>> Hope this helps,
>> Henrik
>>
>> On Tue, May 26, 2020 at 4:55 AM Bandhav Veluri via llvm-dev <
>> llvm-dev at lists.llvm.org> wrote:
>>
>>> Hi,
>>>
>>> I’m working on a RISC-V architecture that has instruction costs
>>> different from those in the default cost model. Is there an out-of-source
>>> way to provide llc with custom cost model? Or, does this need a change in
>>> LLVM backend?
>>>
>>> Also, the cost model is not totally static. For example, loads from
>>> 0x1000-0x1ffc take 1 cycle, whereas loads from address > 0x80000000, take
>>> 10-100 cycles. Is it possible to model these costs in the scheduler?
>>> Requiring programmer to define custom pointer types to mark pointers, to
>>> one or the other address space, is okay. Is there a way to model different
>>> costs for different pointer types?
>>>
>>> Thank you,
>>> Bandhav
>>> _______________________________________________
>>> LLVM Developers mailing list
>>> llvm-dev at lists.llvm.org
>>> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200527/a67189d0/attachment.html>


More information about the llvm-dev mailing list