[LLVMdev] How to extend llvm IR and frontend?
John McCall
rjmccall at apple.com
Fri Jan 21 20:46:14 PST 2011
On Jan 21, 2011, at 10:23 AM, Frits van Bommel wrote:
> On Fri, Jan 21, 2011 at 4:32 PM, Aaron Myles Landwehr <snaphat at gmail.com> wrote:
>> Hypothetically, suppose I have a generic system with multiple address spaces
>> such that each address space is accessed using different instructions.
>> Now suppose, I wanted to add a new keywords 'foo' and 'bar' to the front of
>> c variables and function return types such that the following would be
>> valid:
>> foo void* a;
>> foo void* somefunc(){...}
>> bar int b;
>> int somefunc2(bar int*){...}
>
> How about putting
>
> #define foo __attribute__((address_space(256)))
> #define bar __attribute__((address_space(257)))
>
> in some header? (Or on the command line, or in clang's default #defines, ...)
> Though maybe they'd need to be in a slightly different place; the
> example in the documentation
> (http://clang.llvm.org/docs/LanguageExtensions.html) is
>
> #define GS_RELATIVE __attribute__((address_space(256)))
> int foo(int GS_RELATIVE *P) {
> return *P;
> }
>
> so maybe it won't work if they're in front of the declaration.
That would work fine. The attribute works like a normal qualifier: just like 'int const *'
and 'const int *' both mean "pointer to const int", 'GS_RELATIVE int *' and
'int GS_RELATIVE *' both mean "pointer to int object in address space 256".
Whereas 'int * GS_RELATIVE *' means "pointer to pointer object in address
space 256 that points to int object in generic address space".
John.
More information about the llvm-dev
mailing list