On Tue, Aug 22, 2023 at 10:43:54AM +0200, Tobias Burnus wrote: > On 22.08.23 09:25, Richard Biener wrote: > > On Mon, Aug 21, 2023 at 6:23 PM Tobias Burnus <tob...@codesourcery.com> > > wrote: > > > ... > > Err, so the OMP standard doesn't put any constraints on what to allow > > inside the > > variants? Is declare variant always at the toplevel? > > Actually, the OpenMP specification only states the following – which is less > than I claimed: > > "If the context selector of a begin declare variant directive contains traits > in the device > or implementation set that are known never to be compatible with an OpenMP > context during > the current compilation, the preprocessed code that follows the begin declare > variant > directive up to its paired end directive is elided."
The reason for the way how GCC implements the offloading is make sure the layout of types/variables/functions is the same so that the host and offloading side can actually interoperate. I think it is much cleaner design. The unfortunate thing is that LLVM decided to do it differently, by separate parsing/compilation for host cases and device cases. That allows the various preprocessor games and the like, but on the other side allows the user to make host vs. offloading inoperable - say #ifdefing out some members of a struct, using different attributes which cause different alignment and the like. If source comes from a pipe, what do you do so that you can preprocess multiple times? The offloading compilation still needs to be some weird hybrid of the offloading target and host target, because e.g. the structure/variable layout/alignment etc. decisions need to be done according to host target. The worst thing is that the bad way LLVM decided to implement this later leaks into the standard, where some people who propose new features just don't think that it could be implemented differently and that results in cases like the begin declare variant eliding what is in between. It takes time to adjust the wording so that it is acceptable even for the GCC way of doing offloading and sometimes we aren't successful at it. So, the long term question is if we should't give up and do it with separate parsing as well. But that would be a lot of work... Jakub