how to make llvm_any_pointer match pointer in any address space

Hi, I am trying to add address space in my backend. I have added an intrinsic:

        def int_mytarget_padd : Intrinsic<[], [llvm_anyptr_ty, llvm_anyptr_ty, llvm_anyptr_ty], []>;

then in test.c I wrote:

        #define MEM1 __attribute__((address_space(1)))
        #define MEM2 __attribute__((address_space(2)))
        #define MEM3 __attribute__((address_space(3)))

        void llvm_mytarget_padd(void *dst, void *op1, void* op2) asm("llvm.mytarget_padd");

        int func(int MEM3 *c, int MEM2 *a, int MEM2 *b) {
            llvm_mytarget_padd(c, a, b);
            return 0;
       }

Errors occured:

       passing '__attribute__((address_space(1))) int *' to parameter of type 'void *' changes address space of pointer

I change argument to `void MEM3 *dst, void MEM1 *op1, void MEM2*op2` in declaration of `llvm_mytarget_padd`, then compilation complete.
I want to make each parameter of `llvm_mytarget_padd` be of any address space , any suggestion?

Yours,
Winter

Hi, I am trying to add address space in my backend. I have added an intrinsic:

         def int_mytarget_padd : Intrinsic<[], [llvm_anyptr_ty, llvm_anyptr_ty, llvm_anyptr_ty], []>;

then in test.c I wrote:

         #define MEM1 __attribute__((address_space(1)))
         #define MEM2 __attribute__((address_space(2)))
         #define MEM3 __attribute__((address_space(3)))

         void llvm_mytarget_padd(void *dst, void *op1, void* op2) asm("llvm.mytarget_padd");

Don't do this; it's a bug that this gets lowered to an LLVM intrinsic.

         int func(int MEM3 *c, int MEM2 *a, int MEM2 *b) {
             llvm_mytarget_padd(c, a, b);
             return 0;
        }

Errors occured:

        passing '__attribute__((address_space(1))) int *' to parameter of type 'void *' changes address space of pointer

I change argument to `void MEM3 *dst, void MEM1 *op1, void MEM2*op2` in declaration of `llvm_mytarget_padd`, then compilation complete.
I want to make each parameter of `llvm_mytarget_padd` be of any address space , any suggestion?

The correct way to define a clang builtin is in Builtins.def, or one of related files for target-specific builtins like BuiltinsX86.def. If your builtin has a type that can't be expressed in a straightforward way in C, you can mark it with the "t" flag, and write custom type-checking code in SemaChecking.cpp.

-Eli