2014-08-14 01:49:16 +08:00
|
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
2011-10-23 18:57:53 +08:00
|
|
|
"http://www.w3.org/TR/html4/strict.dtd">
|
|
|
|
<!-- Material used from: HTML 4.01 specs: http://www.w3.org/TR/html401/ -->
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
|
|
|
<title>Polly - Load Polly into clang</title>
|
|
|
|
<link type="text/css" rel="stylesheet" href="menu.css">
|
|
|
|
<link type="text/css" rel="stylesheet" href="content.css">
|
|
|
|
</head>
|
|
|
|
<body>
|
2013-12-20 06:50:10 +08:00
|
|
|
<div id="box">
|
2011-10-23 18:57:53 +08:00
|
|
|
<!--#include virtual="menu.html.incl"-->
|
|
|
|
<div id="content">
|
|
|
|
<!--=====================================================================-->
|
|
|
|
<h1>Load Polly into clang and automatically run it at -O3</h1>
|
|
|
|
<!--=====================================================================-->
|
|
|
|
|
2011-11-18 03:10:48 +08:00
|
|
|
<p><b>Warning:</b> Even though this example makes it very easy to use Polly,
|
|
|
|
you should be aware that Polly is a young research project. It is expected
|
|
|
|
to crash, produce invalid code or to hang in complex calculations even for
|
|
|
|
simple examples. In case you see such a problem, please check the <a
|
|
|
|
href="bugs.html">Bug database</a> and consider reporting a bug.
|
2011-10-26 10:09:11 +08:00
|
|
|
<p>
|
2011-11-18 03:10:48 +08:00
|
|
|
<b>Warning II:</b> clang/LLVM/Polly need to be in sync. This means
|
2011-10-26 10:09:11 +08:00
|
|
|
you need to compile them yourself from a recent svn/git checkout</b>
|
2011-11-18 03:10:48 +08:00
|
|
|
<h2>Load Polly into clang</h2>
|
|
|
|
|
2014-03-20 05:31:09 +08:00
|
|
|
By default Polly is configured as a shared library plugin that is loaded in
|
|
|
|
tools like clang, opt, and bugpoint when they start their execution.
|
|
|
|
|
2011-11-18 03:10:48 +08:00
|
|
|
By loading Polly into clang (or opt) the Polly options become automatically
|
|
|
|
available. You can load Polly either by adding the relevant commands to
|
|
|
|
the CPPFLAGS or by creating an alias.
|
|
|
|
|
|
|
|
<pre class="code">
|
|
|
|
$ export CPPFLAGS="-Xclang -load -Xclang ${POLLY_BUILD_DIR}/lib/LLVMPolly.so"
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
or
|
|
|
|
<pre class="code">
|
|
|
|
$ alias pollycc clang -Xclang -load -Xclang ${POLLY_BUILD_DIR}/lib/LLVMPolly.so
|
|
|
|
</pre>
|
|
|
|
|
2014-03-20 05:31:09 +08:00
|
|
|
To avoid having to load Polly in the tools, Polly can optionally be configured
|
|
|
|
with cmake to be statically linked in the tools:
|
|
|
|
|
|
|
|
<pre class="code">
|
|
|
|
$ cmake -D LINK_POLLY_INTO_TOOLS:Bool=ON
|
|
|
|
</pre>
|
|
|
|
|
2011-11-18 03:10:48 +08:00
|
|
|
<h2>Optimizing with Polly</h2>
|
|
|
|
|
2012-02-01 08:08:10 +08:00
|
|
|
Optimizing with Polly is as easy as adding <b>-O3 -mllvm -polly</b> to your
|
|
|
|
compiler flags (Polly is only available at -O3).
|
2011-10-26 09:27:53 +08:00
|
|
|
|
2012-02-01 04:24:21 +08:00
|
|
|
<pre class="code">pollycc -O3 -mllvm -polly file.c</pre>
|
2011-10-23 18:57:53 +08:00
|
|
|
|
2011-10-23 19:17:06 +08:00
|
|
|
<h2>Automatic OpenMP code generation</h2>
|
2011-10-23 18:57:53 +08:00
|
|
|
|
|
|
|
To automatically detect parallel loops and generate OpenMP code for them you
|
2011-11-10 22:00:00 +08:00
|
|
|
also need to add <b>-mllvm -enable-polly-openmp -lgomp</b> to your CFLAGS.
|
2011-10-23 18:57:53 +08:00
|
|
|
|
2012-03-07 22:30:54 +08:00
|
|
|
<pre class="code">pollycc -O3 -mllvm -polly -mllvm -enable-polly-openmp -lgomp file.c</pre>
|
2011-10-23 19:17:06 +08:00
|
|
|
|
2011-10-24 04:59:40 +08:00
|
|
|
<h2>Automatic Vector code generation</h2>
|
|
|
|
|
2011-11-10 22:00:00 +08:00
|
|
|
Automatic vector code generation can be enabled by adding <b>-mllvm
|
2012-05-06 18:22:57 +08:00
|
|
|
-polly-vectorizer=polly</b> to your CFLAGS.
|
2011-10-24 04:59:40 +08:00
|
|
|
|
2012-05-06 18:22:57 +08:00
|
|
|
<pre class="code">pollycc -O3 -mllvm -polly -mllvm -polly-vectorizer=polly file.c</pre>
|
2011-10-24 04:59:40 +08:00
|
|
|
|
2011-12-14 20:21:31 +08:00
|
|
|
<h2>Extract a preoptimized LLVM-IR file</h2>
|
|
|
|
|
|
|
|
Often it is useful to derive from a C-file the LLVM-IR code that is actually
|
|
|
|
optimized by Polly. Normally the LLVM-IR is automatically generated from
|
|
|
|
the C code by first lowering C to LLVM-IR (clang) and by subsequently applying a
|
|
|
|
set of preparing transformations on the LLVM-IR. To get the LLVM-IR after the
|
|
|
|
preparing transformations have been applied run Polly with '-O0'.
|
|
|
|
|
|
|
|
<pre class="code">pollycc -O0 -mllvm -polly -S -emit-llvm file.c</pre>
|
|
|
|
|
2011-10-23 19:17:06 +08:00
|
|
|
<h2>Further options</h2>
|
|
|
|
|
|
|
|
Polly supports further options that are mainly useful for the development or
|
|
|
|
the
|
2011-11-10 22:00:00 +08:00
|
|
|
analysis of Polly. The relevant options can be added to clang by appending
|
|
|
|
<b>-mllvm -option-name</b> to the CFLAGS or the clang
|
2011-10-23 19:17:06 +08:00
|
|
|
command line.
|
|
|
|
|
|
|
|
<h3>Limit Polly to a single function</h3>
|
|
|
|
To limit the execution of Polly to a single function, use the option
|
2011-11-10 22:00:00 +08:00
|
|
|
<b>-polly-detect-only=functionname</b>.
|
2011-10-23 19:17:06 +08:00
|
|
|
|
2011-10-24 04:59:11 +08:00
|
|
|
<h3>Disable LLVM-IR generation</h3>
|
|
|
|
Polly normally regenerates LLVM-IR from the Polyhedral representation. To only
|
|
|
|
see the effects of the preparing transformation, but to disable Polly code
|
2011-11-10 22:00:00 +08:00
|
|
|
generation add the option <b>polly-no-codegen</b>.
|
2011-10-24 04:59:11 +08:00
|
|
|
|
2011-10-24 04:59:14 +08:00
|
|
|
<h3>Graphical view of the SCoPs</h3>
|
|
|
|
|
|
|
|
Polly can use graphviz to show the SCoPs it detects in a program. The relevant
|
2011-11-10 22:00:00 +08:00
|
|
|
options are <b>-polly-show</b>, <b>-polly-show-only</b>, <b>-polly-dot</b> and
|
|
|
|
<b>-polly-dot-only</b>. The 'show' options automatically run dotty or another
|
2011-10-24 04:59:14 +08:00
|
|
|
graphviz viewer to show the scops graphically. The 'dot' options store for each
|
|
|
|
function a dot file that highlights the detected SCoPs. If 'only' is appended at
|
|
|
|
the end of the option, the basic blocks are shown without the statements the
|
|
|
|
contain.
|
2011-10-24 04:59:11 +08:00
|
|
|
|
2012-04-25 00:12:30 +08:00
|
|
|
<h3>Change/Disable the Optimizer</h3>
|
|
|
|
Polly uses by default the isl scheduling optimizer. The isl optimizer optimizes
|
|
|
|
for data-locality and parallelism using the <a
|
2012-08-15 13:02:25 +08:00
|
|
|
href="http://pluto-compiler.sf.net">Pluto</a> algorithm. For research it is also
|
2012-04-25 00:12:30 +08:00
|
|
|
possible to run <a
|
|
|
|
href="http://www-rocq.inria.fr/~pouchet/software/pocc/">PoCC</a> as external
|
|
|
|
optimizer. PoCC provides access to the original Pluto implementation. To use
|
|
|
|
PoCC add <b>-polly-optimizer=pocc</b> to the command line (only available if
|
2014-08-14 01:49:16 +08:00
|
|
|
Polly was compiled with scoplib support) [removed after <a href="http://llvm.org/releases/download.html#3.4.2">LLVM 3.4.2</a>].
|
|
|
|
To disable the optimizer entirely use the option <b>-polly-optimizer=none</b>.
|
2011-10-24 04:59:32 +08:00
|
|
|
|
2011-10-24 04:59:44 +08:00
|
|
|
<h3>Disable tiling in the optimizer</h3>
|
|
|
|
By default both optimizers perform tiling, if possible. In case this is not
|
2011-11-10 22:00:00 +08:00
|
|
|
wanted the option <b>-polly-no-tiling</b> can be used to disable it. (This
|
|
|
|
option disables tiling for both optimizers).
|
2011-11-10 20:47:26 +08:00
|
|
|
|
|
|
|
<h3>Ignore possible aliasing</h3>
|
|
|
|
By default we only detect scops, if we can prove that the different array bases
|
2011-11-10 22:00:00 +08:00
|
|
|
can not alias. This is correct do if we optimize automatically. However,
|
|
|
|
without special user annotations like 'restrict' we can often not prove that
|
|
|
|
no aliasing is possible. In case the user knows no aliasing can happen in the
|
|
|
|
code the <b>-polly-ignore-aliasing</b> can be used to disable the check for
|
|
|
|
possible aliasing.
|
2011-11-15 19:38:36 +08:00
|
|
|
|
2012-04-25 00:12:34 +08:00
|
|
|
<h3>Import / Export</h3>
|
|
|
|
The flags <b>-polly-import</b> and <b>-polly-export</b> allow the export and
|
|
|
|
reimport of the polyhedral representation. By exporting, modifying and
|
|
|
|
reimporting the polyhedral representation externally calculated transformations
|
|
|
|
can be applied. This enables external optimizers or the manual optimization of
|
|
|
|
specific SCoPs.
|
2011-10-23 18:57:53 +08:00
|
|
|
</div>
|
2013-12-20 06:50:10 +08:00
|
|
|
</div>
|
2011-10-23 18:57:53 +08:00
|
|
|
</body>
|
|
|
|
</html>
|