karolherbst wrote:

> > Without static, _CLC_INLINE (inline) function in header is problematic in 
> > C: when function is not inlined in a TU, compiler assumes it will be 
> > provided by another file (which won't happen) and generates declaration for 
> > __clc_flush_denormal_if_not_supported in that TU.
> 
> I was under the impression that C just requires an "anchor" definition in a 
> source file, as explained in https://en.cppreference.com/c/language/inline:
> 
> > If a function is declared `inline` in some translation units, it does not 
> > need to be declared `inline` everywhere: at most one translation unit may 
> > also provide a regular, non-inline non-static function, or a function 
> > declared `extern inline`. This one translation unit is said to provide the 
> > external definition. In order to avoid undefined behavior, one external 
> > definition must exist in the program if the name of the function with 
> > external linkage is used in an expression, see [one definition 
> > rule](https://en.cppreference.com/c/language/extern#One_definition_rule).
> 
> The example illustrates how this is done:
> 
> > Header file "test.h"
> > ```c
> > #ifndef TEST_H_INCLUDED
> > #define TEST_H_INCLUDED
> > 
> > inline int sum(int a, int b)
> > {
> >     return a + b;
> > }
> > 
> > #endif
> > ```
> > 
> > 
> >     
> >       
> >     
> > 
> >       
> >     
> > 
> >     
> >   
> > Source file "sum.c"
> > ```c
> > #include "test.h"
> > 
> > extern inline int sum(int a, int b); // provides external definition
> > ```
> 
> Wouldn't it be possible to provide such an anchor definition in libclc? The 
> problem with `static` in header files is that every translation unit gets 
> their own copy of the function, and in this case it doesn't seem to be 
> inlined. (Otherwise there would be no error.) Those duplicate copies are 
> probably not a big issue for OpenCL, but it could still blow up the size of 
> the library unnecessarily.

Yeah maybe, but 1. this issue doesn't exist on 23 and on GPUs you are generally 
more aggressive with inlining anyway and the function in question is rather 
small. I'm more concerned about the actual implementation because on most GPUs 
you can implement this function in 0 instructions.

https://github.com/llvm/llvm-project/pull/207264
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to