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

Liu, Yaxun (Sam) via llvm-dev
Thu, 12 May 2016 15:16:07 -0000

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

From: Jeff Fifield [mailto:fifield at mtnhigh.net]
Sent: Wednesday, May 11, 2016 5:26 PM
To: Liu, Yaxun (Sam) <Yaxun.Liu at amd.com>
Cc: Sumner, Brian <Brian.Sumner at amd.com>; Anastasia Stulova
<Anastasia.Stulova at arm.com>; cfe-dev (cfe-dev at lists.llvm.org)
<cfe-dev at lists.llvm.org>; Pan, Xiuli <xiuli.pan at intel.com>;
Bader, Alexey (alexey.bader at intel.com) <alexey.bader at intel.com>;
llvm-dev at lists.llvm.org; Mekhanoshin, Stanislav <Stanislav.Mekhanoshin at
amd.com>; nd <nd at arm.com>; Stellard, Thomas <Tom.Stellard at
amd.com>
Subject: Re: [cfe-dev] [OpenCL] Question about pre-linking passes required to
build OpenCL program



On Tue, May 10, 2016 at 3:17 PM, Liu, Yaxun (Sam) via cfe-dev <cfe-dev at
lists.llvm.org<mailto:cfe-dev at lists.llvm.org>> wrote:
+ llvm-dev

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

Thanks,
Brian

From: Anastasia Stulova [mailto:Anastasia.Stulova at arm.com]
Sent: Tuesday, May 10, 2016 11:45 AM
To: Liu, Yaxun (Sam); cfe-dev (cfe-dev at lists.llvm.org<mailto:cfe-dev at
lists.llvm.org>); Pan, Xiuli; Bader, Alexey (alexey.bader at
intel.com<mailto:alexey.bader at intel.com>)
Cc: Stellard, Thomas; Sumner, Brian; Mekhanoshin, Stanislav; nd
Subject: RE: [OpenCL] Question about pre-linking passes required to build OpenCL
program

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

From: Liu, Yaxun (Sam) [mailto:Yaxun.Liu at amd.com]
Sent: 09 May 2016 21:14
To: cfe-dev (cfe-dev at lists.llvm.org<mailto:cfe-dev at lists.llvm.org>);
Anastasia Stulova; Pan, Xiuli; Bader, Alexey (alexey.bader at
intel.com<mailto:alexey.bader at intel.com>)
Cc: Stellard, Thomas; Sumner, Brian; Mekhanoshin, Stanislav
Subject: [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

_______________________________________________
cfe-dev mailing list
cfe-dev at lists.llvm.org<mailto:cfe-dev at lists.llvm.org>
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20160512/624bc921/attachment.html>