erichkeane wrote:

> I am afraid this will break all existing CUDA/HIP programs since they expect 
> to be able to parse the builtins for both host and device targets.
> 
> In the spirit of single source, the compiler sees the entire code for all 
> targets, including host target and all device targets. It is supposed to have 
> AST for all host and device targets. Ideally, it should generate a 
> heterogeneous IR that is for all host and device targets, and eventually 
> generate a heterogeneous executable that includes everything. That would make 
> some optimizations across host and device IR possible. It is just due to 
> current limitation of LLVM/Clang, we generate and process IR separately for 
> each host and device target.
> 
> I think at least during parsing/sema/AST clang could and should see code and 
> AST for both host and device, since that helps avoid inconsistency between 
> host and device. Therefore it is necessary to see builtins for both host and 
> device. Clang only needs to make sure they are only emitted for the supported 
> target.

This is/was my concern.  However, upon thinking further, as long as we 
RECOGNIZE/Parse/etc the builtins, it is OK I think if we report 
"!__has_builtin".

That is:
```
void foo() {
#if __has_builtin(__builtin_x86_thing)
__builtin_x86_thing();
#else
__builtin_x86_thing(); // woops, not has_builtin!
#endif
}
```

NEEDS to still work, even if the `__has_builtin` answer is 'no'.



https://github.com/llvm/llvm-project/pull/121839
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to