Provide LLVM IR and OpenMP LLVM IR as input in a Pass

Hi all,

I am going to build a Pass/es that verify OpenMP code.

When we compile an OpenMP program we give the option “-fopenmp” to clang.
In this way the LLVM IR code obtained will reflect also the “#pragma” keywords in the code, let’s call it "OpenMP LLVM IR".

In my Pass/es before obtaining the OpenMP LLVM IR, I need to do some operation in the LLVM IR, that is the IR code obtained compiling the program without the flag “-fopenmp”.

So, to be clear my working flow would be:

- Run MyPass with in input the LLVM IR
- Do some operation on it and get results
- Run MyPass again or a different one (MyPass2) with in input the OpenMP LLVM IR and the results of the previous operations
- Do other operations

Would it be possible doing something like this? Do you have any idea how should I proceed?

I hope this is clear and you can give me some suggestion.

Thanks.
Best Regards,
Simone

Hi all,
I am going to build a Pass/es that verify OpenMP code.

When we compile an OpenMP program we give the option “-fopenmp” to clang.

In this way the LLVM IR code obtained will reflect also the “#pragma” keywords in the code, let’s call it “OpenMP LLVM IR”.

In my Pass/es before obtaining the OpenMP LLVM IR, I need to do some operation in the LLVM IR, that is the IR code obtained compiling the program without the flag “-fopenmp”.

So, to be clear my working flow would be:

  • Run MyPass with in input the LLVM IR
  • Do some operation on it and get results
  • Run MyPass again or a different one (MyPass2) with in input the OpenMP LLVM IR and the results of the previous operations
  • Do other operations

Would it be possible doing something like this? Do you have any idea how should I proceed?

I hope this is clear and you can give me some suggestion.

Thanks.

Best Regards,
Simone

From: "Simone Atzeni" <simone.at@gmail.com>
To: llvmdev@cs.uiuc.edu, cfe-dev@cs.uiuc.edu, openmp-dev@dcs-maillist2.engr.illinois.edu
Sent: Tuesday, October 21, 2014 3:17:07 PM
Subject: Re: [LLVMdev] [cfe-dev][Openmp-dev] Provide LLVM IR and OpenMP LLVM IR as input in a Pass

Hi all,
I am going to build a Pass/es that verify OpenMP code.

When we compile an OpenMP program we give the option “-fopenmp” to
clang.

In this way the LLVM IR code obtained will reflect also the “#pragma
keywords in the code, let’s call it "OpenMP LLVM IR".

In my Pass/es before obtaining the OpenMP LLVM IR, I need to do some
operation in the LLVM IR, that is the IR code obtained compiling the
program without the flag “-fopenmp”.

So, to be clear my working flow would be:

- Run MyPass with in input the LLVM IR

- Do some operation on it and get results

- Run MyPass again or a different one (MyPass2) with in input the
OpenMP LLVM IR and the results of the previous operations

- Do other operations

Would it be possible doing something like this? Do you have any idea
how should I proceed?

I think it would be better if you gave us some idea of what you're trying to do. clang's OpenMP implementation turns the OpenMP pragmas into function calls to the runtime library. You can run passes on this IR as you would any other IR. When you say, "Do some operation on it and get results" do you mean generating code, linking and executing that code?

-Hal

Hi Hal,

thanks for your answer.

I think it would be better if you gave us some idea of what you’re trying to do. clang’s OpenMP implementation turns the OpenMP pragmas into function calls to the runtime library. You can run passes on this IR as you would any other IR. When you say, “Do some operation on it and get results” do you mean generating code, linking and executing that code?

-Hal

I want to use the pass Polly to find any data dependence in the code.
Since it does not work on OpenMP, I was thinking to apply it on the not-OpenMP IR, then I need the results of Polly to apply other passes to the OpenMP IR.

That is why I need both.

Best,
Simone

From: "Simone Atzeni" <simone.at@gmail.com>
To: "Hal Finkel" <hfinkel@anl.gov>
Cc: llvmdev@cs.uiuc.edu, cfe-dev@cs.uiuc.edu, openmp-dev@dcs-maillist2.engr.illinois.edu
Sent: Tuesday, October 21, 2014 3:42:03 PM
Subject: Re: [LLVMdev] [cfe-dev][Openmp-dev] Provide LLVM IR and OpenMP LLVM IR as input in a Pass

Hi Hal,

thanks for your answer.

I think it would be better if you gave us some idea of what you're
trying to do. clang's OpenMP implementation turns the OpenMP pragmas
into function calls to the runtime library. You can run passes on
this IR as you would any other IR. When you say, "Do some operation
on it and get results" do you mean generating code, linking and
executing that code?

-Hal

I want to use the pass Polly to find any data dependence in the code.
Since it does not work on OpenMP,

Why not? The loops in the outlined OpenMP regions are just regular loops (with runtime bounds). Can polly not handle them?

I was thinking to apply it on the
not-OpenMP IR, then I need the results of Polly to apply other
passes to the OpenMP IR.

I don't think this will work for the OpenMP'd loops. The IR will look completely different, be in different functions, etc.

-Hal

I want to use the pass Polly to find any data dependence in the code.
Since it does not work on OpenMP,

Why not? The loops in the outlined OpenMP regions are just regular loops (with runtime bounds). Can polly not handle them?

I tried it, it does not work and I also talked already with the Polly developers. They are slightly different, for example when the pragmas are translated actually the compiler introduces new functions and Polly get confused.

I was thinking to apply it on the
not-OpenMP IR, then I need the results of Polly to apply other
passes to the OpenMP IR.

I don't think this will work for the OpenMP'd loops. The IR will look completely different, be in different functions, etc.

What I did, and it works, is to build a script that call clang with Polly the first time and write the results in a file, then call Clang again with OpenMP and at the point I can apply other passes on the OpenMP IR reading the Polly results from that file.
But it’s kind of a “dirty" solution, I was wondering if I can, in some way, introduce my own option "-myoption” that compile the code in both ways and make it available to the passes I want to call.

Simone

From: "Simone Atzeni" <simone.at@gmail.com>
To: "Hal Finkel" <hfinkel@anl.gov>
Cc: llvmdev@cs.uiuc.edu, cfe-dev@cs.uiuc.edu, openmp-dev@dcs-maillist2.engr.illinois.edu
Sent: Tuesday, October 21, 2014 3:52:38 PM
Subject: Re: [LLVMdev] [cfe-dev][Openmp-dev] Provide LLVM IR and OpenMP LLVM IR as input in a Pass

>> I want to use the pass Polly to find any data dependence in the
>> code.
>> Since it does not work on OpenMP,
>
> Why not? The loops in the outlined OpenMP regions are just regular
> loops (with runtime bounds). Can polly not handle them?

I tried it, it does not work and I also talked already with the Polly
developers. They are slightly different, for example when the
pragmas are translated actually the compiler introduces new
functions and Polly get confused.

Right. So the long-term solution here is to figure out what enhancements are necessary to the various components to make this work.

>
>> I was thinking to apply it on the
>> not-OpenMP IR, then I need the results of Polly to apply other
>> passes to the OpenMP IR.
>
> I don't think this will work for the OpenMP'd loops. The IR will
> look completely different, be in different functions, etc.

What I did, and it works, is to build a script that call clang with
Polly the first time and write the results in a file, then call
Clang again with OpenMP and at the point I can apply other passes on
the OpenMP IR reading the Polly results from that file.
But it’s kind of a “dirty" solution, I was wondering if I can, in
some way, introduce my own option "-myoption” that compile the code
in both ways and make it available to the passes I want to call.

Not currently.

-Hal

Yes, this is what I have been thinking.
I talked with the Polly developers and what they suggested me is to analyze the non-OpenMP IR code.
But since I need to compile the OpenMP code, they were proposing to instruct in some way the OpenMP front-end keep the original IR code (without OpenMP), for example via metadata.

Do you think this is something feasible?

Thanks.
Simone

From: "Simone Atzeni" <simone.at@gmail.com>
To: "Hal Finkel" <hfinkel@anl.gov>
Cc: llvmdev@cs.uiuc.edu, cfe-dev@cs.uiuc.edu, openmp-dev@dcs-maillist2.engr.illinois.edu
Sent: Tuesday, October 21, 2014 5:43:08 PM
Subject: Re: [LLVMdev] [cfe-dev][Openmp-dev] Provide LLVM IR and OpenMP LLVM IR as input in a Pass

Yes, this is what I have been thinking.
I talked with the Polly developers and what they suggested me is to
analyze the non-OpenMP IR code.
But since I need to compile the OpenMP code, they were proposing to
instruct in some way the OpenMP front-end keep the original IR code
(without OpenMP), for example via metadata.

Do you think this is something feasible?

You could probably hack it to do this (I believe that in effect, it will do this already if there is an "if" clause in the OpenMP pragma). If you insert "if" clauses dependent on some variable you understand, perhaps you could analyze the branches on that variable and base your analysis on that.

-Hal