[Openmp-dev] Knowing if an IR instruction will be executed by an OpenMP region

Ronan KERYELL ronan-list at keryell.fr
Wed Feb 11 09:05:50 PST 2015


>>>>> On Tue, 10 Feb 2015 11:19:39 +0000, "Cownie, James H" <james.h.cownie at intel.com> said:

    >> is there a way to understand if an LLVM IR instruction will be
    >> executed by an OpenMP constructs?

    James> The simple answer is "No", you can't in general tell at
    James> compile time whether code will be executed in parallel. (It
    James> could be in a separate compilation unit, or even a dynamic
    James> library which is only dlopened at runtime).

Yes, this is why the OpenMP API provides functions like
int omp_in_parallel(void);
to test it.

    James> Even without those practical examples, even knowing whether a
    James> given IR instruction will ever be executed is clearly the
    James> same as the halting problem...

This is true but let's focus on the cases when we know it is not
intractable... :-)

You can apply some interprocedural control flow analysis in the compiler
and in some cases be sure it is executed or not in parallel. Doing this
in the LTO phase is a way to go.

Another more pragmatic way is to rewrite some code bloc B by cloning it
in the following way:

if omp_in_parallel() {
  // We know that here B is executed in a parallel context
  B
}
else {
  // We know that here B is not executed in a parallel context
  B
}
and then go on with some optimizations on both paths.

So this is a dynamic+static approach which may worth it if B is big enough.

You may also use some partial evaluation late in the compilation phases
to figure out that in some case omp_in_parallel() returns always true or
false and then remove the dead code.
-- 
  Ronan KERYELL



More information about the Openmp-dev mailing list