[Mesa-dev] [PATCH 7/7] nir: add helper macros for running NIR passes

Thomas Helland thomashelland90 at gmail.com
Sun Oct 25 06:55:59 PDT 2015


2015-10-25 13:58 GMT+01:00 Rob Clark <robdclark at gmail.com>:
> On Sun, Oct 25, 2015 at 8:05 AM, Erik Faye-Lund <kusmabite at gmail.com> wrote:
>> On Sat, Oct 24, 2015 at 7:08 PM, Rob Clark <robdclark at gmail.com> wrote:
>>> From: Rob Clark <robclark at freedesktop.org>
>>>
>>> +#define NIR_PASS_PROGRESS(pass, nir, ...) ({               \
>>> +      assert(nir_shader_is_mutable(nir));                  \
>>> +      bool __ret = pass(nir, ##__VA_ARGS__);               \
>>> +      nir_validate_shader(nir);                            \
>>> +      if (__nir_test_clone()) {                            \
>>> +         nir = nir_shader_clone(ralloc_parent(nir), nir);  \
>>> +         nir_validate_shader(nir);                         \
>>> +      }                                                    \
>>> +      __ret;                                               \
>>> +   })
>>> +
>> <snip>0
>>> +      progress |= NIR_PASS_PROGRESS(nir_copy_prop, nir);
>>
>> This does not generate valid C code, but rather what looks like a GCC
>> extension. Is that really a good move?
>
> hmm, bleh.. it's used a lot in linux kernel, but it is a GNU C extension:
>
> https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html
>
> well, I guess at least llvm must support it (since I've heard of
> people building linux kernel w/ llvm), no idea about MSVC.  If it is
> supported by MSVC, then maybe we could use it?  Or is there any other
> compiler people use that doesn't?  It sure is a nice extension for
> macros..
>

Hi Rob,

If my memory is correct I stumbled across this last year, and
I believe the conclusion was that it could not be used in GLSL
as MSVC does not support GNU statement expressions, and
that codepath needs to be compilable by MSVC. I'm not sure
about NIR, I guess noone compiles that with MSVC as of now,
but maybe it will be done in the future, so I guess it is best to
"keep it safe" and avoid using this extension in this codepath.

This stackoverflow question[1] summarizes the support
(allthought the answers are probably a bit outdated).

I believe you could achieve at least parts of what you are
doing here by abusing a "do { ] while (false)".
However, returning values is a different story.

[1] http://stackoverflow.com/questions/6440021/compiler-support-of-gnu-statement-expression


Regards,
Thomas


> BR,
> -R
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list