[OpenCL] Question about pre-linking passes required to build OpenCL program

Hi,

We typically need to apply some transformations to the IR between clang and the standard linker. I am wondering if other OpenCL platforms require the same as well?

I'm wondering if we all need such transformations (likely target specific). Is there any way to collaborate on a common infrastructure for pre-linking transformation that would reduce the size of the additions we have to make?

Thanks.

Sam

Hi Sam,

It seems to be generally useful to the community. Could you give some examples of those transformations that can be shared?

Also I am guessing this will be a part of LLVM code base. Do you intend it to be publically available on the master branch? If yes, perhaps llvm-dev should be added to the discussion too.

Cheers,

Anastasia

Hi Anastasia,

I’m glad to hear there could be some support for such a mechanism. On our side, we use such pre-link passes to interface with the specifics of our built-in function library. For example, we transform printf calls into a form that interacts with our library. We also transform calls to pipe functions, kernel enqueue related functions, and transform calls to the atomic functions to corresponding LLVM atomic instructions (and keep track of the memory scope elsewhere currently). You may have noticed that we have a proposal out to enable the atomic instructions to directly carry a memory scope.

Thanks,

Brian

  • llvm-dev

Hi Brian,

For example, we transform printf calls into a form that interacts with our library. We also transform calls to pipe functions, kernel enqueue related functions, and transform calls to the atomic functions to corresponding LLVM atomic instructions (and keep track of the memory scope elsewhere currently).

Sounds like most of the transformation are affecting OpenCL 2.0. It would be nice to see progress with the latest standards on LLVM side too.

You may have noticed that we have a proposal out to enable the atomic instructions to directly carry a memory scope.

Yes, but probably need to look more into this.

Thanks,

Anastasia

+ llvm-dev

*From:* Sumner, Brian
*Sent:* Tuesday, May 10, 2016 3:11 PM
*To:* Anastasia Stulova <Anastasia.Stulova@arm.com>; Liu, Yaxun (Sam) <
Yaxun.Liu@amd.com>; cfe-dev (cfe-dev@lists.llvm.org) <
cfe-dev@lists.llvm.org>; Pan, Xiuli <xiuli.pan@intel.com>; Bader, Alexey (
alexey.bader@intel.com) <alexey.bader@intel.com>
*Cc:* Stellard, Thomas <Tom.Stellard@amd.com>; Mekhanoshin, Stanislav <
Stanislav.Mekhanoshin@amd.com>; nd <nd@arm.com>

*Subject:* RE: [OpenCL] Question about pre-linking passes required to
build OpenCL program

Hi Anastasia,

I’m glad to hear there could be some support for such a mechanism. On our
side, we use such pre-link passes to interface with the specifics of our
built-in function library. For example, we transform printf calls into a
form that interacts with our library. We also transform calls to pipe
functions, kernel enqueue related functions, and transform calls to the
atomic functions to corresponding LLVM atomic instructions (and keep track
of the memory scope elsewhere currently). You may have noticed that we
have a proposal out to enable the atomic instructions to directly carry a
memory scope.

Hi Sam / Brian,

We have similar passes related to builtin functions but they are rather
specific to our implementation and not too complex. We don't do much else
before linking. What do you envision as the common infrastructure here?

Thanks,
Jeff

Hi Jeff,

Here is a rough idea for adding pre-linking passes to Clang.

Currently the linking/opt/llvm-codegen is performed by BackendConsumer::HandleTranslationUnit in CodeGenAction.cpp.

Basically,

· There is no pre-linking passes.

· BackendConsumer::HandleTranslationUnit links with modules provided by command line.

· Then it calls EmitBackendOutput to do opt/llvm-codegen, where

o It creats EmitAssemblyHelper

o EmitAssemblyHelper creates all passes for opt and llvm-codegen

o It then run all these passes

EmitAssemblyHelper knows about the target and uses hooks TargetMachine::addPassesToEmitFile to add passes for llvm-codegen.

There are two types of pre-linking passes:

· Target specific, which should stay in each target’s own directory

· Shared by different targets, which may be added to proper directories under llvm/lib

For target-specific pre-linking pass, we may add a hook TargetMachine::addPrelinkingPasses, which adds these passes.

We can move the linking step into EmitAssemblyHelper. And let EmitAssemblyHelper add common pre-linking passes and target-specific pre-linking passes.

Sam