Commit Graph

3850 Commits

Author SHA1 Message Date
Michael Kruse 420c4863a9 [Simplify] Actually remove unsed instruction from region header.
Since r312249 instructions of a entry block of region statements are
not marked as root anymore and hence can theoretically be removed
if unused. Theoretically, because the instruction list was not changed.

Still, MemoryAccesses for unused instructions were removed. This lead
to a failed assertion in the code generator  when the MemoryAccess for
the still listed instruction was not found.

This hould fix the
Assertion failed: ArrayAccess && "No array access found for instruction!",
file ScopInfo.h, line 1494
compiler crashes.

llvm-svn: 312566
2017-09-05 19:44:39 +00:00
Tobias Grosser 1a695b1d6c [CodegenCleanup] Use old GVN pass instead of NewGVN
It seems NewGVN still has some problems: llvm.org/PR34452, we will switch back
after they have been resolved.

llvm-svn: 312480
2017-09-04 11:04:33 +00:00
Tobias Grosser 8703e38380 [ISLTools]: Move singleton to isl++
llvm-svn: 312476
2017-09-04 10:05:29 +00:00
Tobias Grosser 3575afd739 [DeLICM] Move some functions to isl++ [NFC]
llvm-svn: 312475
2017-09-04 10:05:25 +00:00
Tobias Grosser d6e0679c4e [ForwardOp] Remove read accesses for all instructions that have been moved
Before this patch, OpTree did not consider forwarding an operand tree consisting
of only single LoadInst as useful. The motivation was that, like an access to a
read-only variable, it would just replace one MemoryAccess by another. However,
in contrast to read-only accesses, this would replace a scalar access by an
array access, which is something worth doing.

In addition, leaving scalar MemoryAccess is problematic in that VirtualUse
prioritizes inter-Stmt use over intra-Stmt. It was possible that the same LLVM
value has a MemoryAccess for accessing the remote Stmt's LoadInst as well as
having the same LoadInst in its own instruction list (due to being forwarded
from another operand tree).

With this patch we ensure that if a LoadInst is forwarded is any operand tree,
also the operand tree containing just the LoadInst is forwarded as well, which
effectively removes the scalar MemoryAccess such that only the array access
remains, not both.

Thanks Michael for the detailed explanation.

Reviewers: Meinersbur, bellu, singam-sanjay, gareevroman

Subscribers: hfinkel, pollydev, llvm-commits

Tags: #polly

Differential Revision: https://reviews.llvm.org/D37424

llvm-svn: 312456
2017-09-03 19:52:15 +00:00
Tobias Grosser 701d943d12 [IslAst] Do not assert in case of empty min/max alias locations
In certain situations, the context in the isl_ast_build could result for the
min/max locations of our alias sets to become empty, which would cause an
internal error in isl, which is then unable to derive a value for these
expressions. Check these conditions before code generating expressions and
instead assume that alias check succeeded. This is valid, as the corresponding
memory accesses will not be executed under any valid context.

This fixed llvm.org/PR34432. Thanks to Qirun Zhang for reporting.

llvm-svn: 312455
2017-09-03 19:47:19 +00:00
Tobias Grosser 6b1e461329 [IslAst] Move buildCondition to isl++
llvm-svn: 312452
2017-09-03 18:31:44 +00:00
Tobias Grosser 99ccf05694 [ScopHelper] Do not crash on unreachable blocks
This resolves llvm.org/PR34433. Thanks to Zhendong Su for reporting.

llvm-svn: 312451
2017-09-03 18:01:22 +00:00
Michael Kruse 7954a221f3 [ForwardOpTree] Fix typos. NFC.
llvm-svn: 312446
2017-09-03 16:09:38 +00:00
Tobias Grosser 4baedc70d1 [ScopDetect/Info] Look through PHIs that follow an error block
In case a PHI node follows an error block we can assume that the incoming value
can only come from the node that is not an error block. As a result, conditions
that seemed non-affine before are now in fact affine.

llvm-svn: 312410
2017-09-02 08:25:55 +00:00
Siddharth Bhat 3928e3f50a [ISLNodeBuilder] Materialize Fortran array sizes of arrays without memory accesses.
In Polly, we specifically add a paramter to represent the outermost dimension
 size of fortran arrays. We do this because this information is statically
 available from the fortran metadata generated by dragonegg.
 However, we were only materializing these parameters (meaning, creating an
 llvm::Value to back the isl_id) from *memory accesses*. This is wrong,
 we should materialize parameters from *scop array info*.

 It is wrong because if there is a case where we detect 2 fortran arrays,
 but only one of them is accessed, we may not materialize the other array's
 dimensions at all.

 This is incorrect. We fix this by looping over all
 `polly::ScopArrayInfo` in a scop, rather that just all `polly::MemoryAccess`.

 Differential Revision: https://reviews.llvm.org/D37379

llvm-svn: 312350
2017-09-01 18:55:43 +00:00
Michael Kruse 0c6c555beb Fix Memory Access of failing tests.
Mark scalar dependences for different statements belonging to same BB
as 'Inter'.

Contributed-by: Nandini Singhal <cs15mtech01004@iith.ac.in>

Differential Revision: https://reviews.llvm.org/D37147

llvm-svn: 312324
2017-09-01 11:36:52 +00:00
Roman Gareev 1cb3491620 Run GVN during the cleanup
Currently, GVN can be necessary to eliminate redundant instructions in case
of, for instance, GEMM and float type. This patch makes GVN be run during
the cleanup.

Reviewed-by: Tobias Grosser <tobias@grosser.es>,
             Michael Kruse <llvm@meinersbur.de>

Differential Revision: https://reviews.llvm.org/D37340

llvm-svn: 312307
2017-09-01 06:52:28 +00:00
Tobias Grosser 04567fd480 Drop unused statistic counter
llvm-svn: 312304
2017-09-01 02:17:10 +00:00
Mandeep Singh Grang c2774a549b [polly] Fix non-deterministic output due to iteration of unordered ScopArrayInfo
Summary:
This fixes the following failures in the reverse iteration builder:
http://lab.llvm.org:8011/builders/reverse-iteration/builds/25

    Polly :: MaximalStaticExpansion/working_deps_between_inners.ll
    Polly :: MaximalStaticExpansion/working_expansion_multiple_dependences_per_statement.ll
    Polly :: MaximalStaticExpansion/working_expansion_multiple_instruction_per_statement.ll
    Polly :: MaximalStaticExpansion/working_phi_expansion.ll

Reviewers: simbuerg, Eugene.Zelenko, grosser, zinob, bollu

Reviewed By: grosser

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D37349

llvm-svn: 312273
2017-08-31 20:10:30 +00:00
Roman Gareev 6589748920 Use the information about the target cache provided by the TargetTransformInfo.
Reviewed-by: Tobias Grosser <tobias@grosser.es>

Differential Revision: https://reviews.llvm.org/D37178

llvm-svn: 312255
2017-08-31 17:07:54 +00:00
Tobias Grosser 2307f86c47 [ForwardOpTree] Allow forwarding in the presence of region statements
Summary:
After region statements now also have instruction lists, this is a
straightforward extension.

Reviewers: Meinersbur, bollu, singam-sanjay, gareevroman

Reviewed By: Meinersbur

Subscribers: hfinkel, pollydev, llvm-commits

Tags: #polly

Differential Revision: https://reviews.llvm.org/D37298

llvm-svn: 312249
2017-08-31 16:04:49 +00:00
Siddharth Bhat 56572c6a5e [PPCGCodeGen] Convert intrinsics to libdevice functions whenever possible.
This is useful when we face certain intrinsics such as `llvm.exp.*`
which cannot be lowered by the NVPTX backend while other intrinsics can.

So, we would need to keep blacklists of intrinsics that cannot be
handled by the NVPTX backend. It is much simpler to try and promote
all intrinsics to libdevice versions.

This patch makes function/intrinsic very uniform, and will always try to use
a libdevice version if it exists.

Differential Revision: https://reviews.llvm.org/D37056

llvm-svn: 312239
2017-08-31 13:03:37 +00:00
Tobias Grosser c43d0360cc [BlockGenerator] Generate entry block of regions from instruction lists
The adds code generation support for the previous commit.

This patch has been re-applied, after the memory issue in the previous patch
has been fixed.

llvm-svn: 312211
2017-08-31 03:17:35 +00:00
Tobias Grosser bd15d13d4e [ScopInfo] Use statement lists for entry blocks of region statements
By using statement lists in the entry blocks of region statements, instruction
level analyses also work on region statements.

We currently only model the entry block of a region statements, as this is
sufficient for most transformations the known-passes currently execute. Modeling
instructions in the presence of control flow (e.g. infinite loops) is left
out to not increase code complexity too much. It can be added when good use
cases are found.

This change set is reapplied, after a memory corruption issue had been fixed.

llvm-svn: 312210
2017-08-31 03:15:56 +00:00
Tobias Grosser d3edc16416 Revert "[ScopInfo] Use statement lists for entry blocks of region statements"
This reverts commit r312128. It aused some memory issues.

llvm-svn: 312209
2017-08-31 02:43:49 +00:00
Tobias Grosser 6f1f5cbb5b Revert "[BlockGenerator] Generate entry block of regions from instruction lists"
This reverts commit r312129. It caused some memory issues.

llvm-svn: 312208
2017-08-31 02:43:27 +00:00
Adrian Prantl 6120801066 Adapt testcase to LLVM change in DIGlobalVariableExpression.
llvm-svn: 312147
2017-08-30 18:12:35 +00:00
Tobias Grosser 1e34508bcc [BlockGenerator] Generate entry block of regions from instruction lists
The adds code generation support for the previous commit.

llvm-svn: 312129
2017-08-30 15:08:30 +00:00
Tobias Grosser 6fbe4c8501 [ScopInfo] Use statement lists for entry blocks of region statements
By using statement lists in the entry blocks of region statements, instruction
level analyses also work on region statements.

We currently only model the entry block of a region statements, as this is
sufficient for most transformations the known-passes currently execute. Modeling
instructions in the presence of control flow (e.g. infinite loops) is left
out to not increase code complexity too much. It can be added when good use
cases are found.

llvm-svn: 312128
2017-08-30 15:08:21 +00:00
Michael Kruse f3387836d0 [ScopBuilder/ScopInfo] Move reduction detection to ScopBuilder. NFC.
Reduction detection is only executed in the SCoP building phase.
Hence it fits better into ScopBuilder to separate
SCoP-construction from SCoP modeling.

llvm-svn: 312118
2017-08-30 13:05:08 +00:00
Michael Kruse 35aa9d862e [ScopBuilder/ScopInfo] Move ScopStmt::collectSurroundingLoops to ScopBuilder. NFC.
This method is only called in the SCoP building phase.
Therefore it fits better into ScopBuilder to separate
SCoP-construction from SCoP modeling.

llvm-svn: 312117
2017-08-30 13:05:01 +00:00
Michael Kruse eb83141f9e [ScopBuilder/ScopInfo] Move ScopStmt::buildDomain to ScopBuilder. NFC.
This method is only called in the SCoP building phase.
Therefore it fits better into ScopBuilder to separate
SCoP-construction from SCoP modeling.

llvm-svn: 312116
2017-08-30 13:04:54 +00:00
Michael Kruse a29f8c03d4 [ScopBuilder/ScopInfo] Move ScopStmt::buildAccessRelations to ScopBuilder. NFC.
This method is only called in the SCoP building phase.
Therefore it fits better into ScopBuilder to separate
SCoP-construction from SCoP modeling.

This mostly mechanical change makes ScopBuilder directly access some of
ScopStmt/MemoryAccess private fields. We add ScopBuilder as a friend
class and will add proper accessor functions sometime later.

llvm-svn: 312115
2017-08-30 13:04:46 +00:00
Michael Kruse f6eb3a2ed2 [ScopBuilder/ScopInfo] Move and inline Scop::init into ScopBuilder::buildScop. NFC.
The method is only needed in the SCoP building phase, and doesn't need
to be part of the general API.

llvm-svn: 312114
2017-08-30 13:04:39 +00:00
Michael Kruse 860870b7b0 [ScopBuilder] Report to dbgs() on SCoP bailout. NFC.
This allows to use -debug to see that a SCoP was found in ScopDetect,
but dismissed by ScopBuilder.

llvm-svn: 312113
2017-08-30 11:52:03 +00:00
Michael Kruse 591255183b [ScopBuilder] Introduce metadata for splitting scop statement.
This patch allows annotating of metadata in ir instruction
(with "polly_split_after"), which specifies where to split a particular
scop statement.

Contributed-by: Nandini Singhal <cs15mtech01004@iith.ac.in>

Differential Revision: https://reviews.llvm.org/D36402

llvm-svn: 312107
2017-08-30 10:11:06 +00:00
Michael Kruse 99cc9ded41 Do not consider mem intrinsics as error.
The intrinsics memset, memcopy and memmove do have their memory accesses
modeled by ScopBuilder. Do not consider them error-case behavior.

Test case will come with a future patch that requires memory intrinsics
outside of error blocks.

llvm-svn: 312021
2017-08-29 18:27:47 +00:00
Michael Kruse 25d3f85a43 Skip ignored intrinsics.
Commit r252725 introduced a "return false" if an ignored intrinsics was
found. The consequence of this was that the mere existence of an ignored
intrinsic (such as llvm.dbg.value) before a call that would have
qualified the block to be an error block, to not be an error block.

The obvious goal was to just skip ignored intrinsics, not changing the
meaning of what an error block is.

llvm-svn: 312020
2017-08-29 18:27:42 +00:00
Siddharth Bhat 7de7abb09c [ScopInfo] Fix comment grammar. "..to be build" -> "..to be built". [NFC]
llvm-svn: 311995
2017-08-29 11:46:14 +00:00
Michael Kruse 4728184342 [ZoneAlgo] More fine-grained bail-out.
ZoneAlgo used to bail out for the complete SCoP if it encountered
something violating its assumption. This meant the neither OpTree can
forward any load nor DeLICM do anything in such cases, even if their
transformations are unrelated to the violations.

This patch adds a list of compatible elements (currently with the
granularity of entire arrays) that can be used for analysis. OpTree
and DeLICM can then check whether their transformations only concern
compatible elements, and skip non-compatible ones.

This will be useful for e.g. Polybench's benchmarks covariance,
correlation, bicg, doitgen, durbin, gramschmidt, adi that have
assumption violation, but which are not necessarily relevant
for all transformations.

Differential Revision: https://reviews.llvm.org/D37219

llvm-svn: 311929
2017-08-28 20:39:07 +00:00
Tobias Grosser ee8ad1c0ff [IslAst] Do not compare arrays in alias check which are known to be identical
This possibly helps to avoid run-time check failures in the COSMO kernels.

llvm-svn: 311920
2017-08-28 20:17:02 +00:00
Michael Kruse a4f447c2a4 [PM] Properly require and preserve OptimizationRemarkEmitter. NFCI.
Properly require and preserve the OptimizationRemarkEmitter for use in
ScopPass. Previously one had to get the ORE from ScopDetection because
CodeGeneration did not mark it as preserved. It would need to be
recomputed which results in the legacy PM to throw away all previous
SCoP analysis.

This also changes the implementation of ScopPass::getAnalysisUsage to
not unconditionally preserve all passes, but only those needed to be
preserved by any SCoP pass (at least when using the legacy PM). This
allows invalidating DependenceInfo (and IslAstInfo) in case the pass
would cause them to change (e.g. OpTree, DeLICM, MaximalArrayExpansion)

JSONImporter should also invalidate the DependenceInfo. In this patch
it marks DependenceInfo as preserved anyway because some regression
tests depend on it.

Differential Revision: https://reviews.llvm.org/D37010

llvm-svn: 311888
2017-08-28 14:07:33 +00:00
Michael Kruse e983e6b1c5 [ZoneAlgo] Print rejection reasons to llvm::dbgs(). NFC.
llvm-svn: 311885
2017-08-28 11:22:23 +00:00
Tobias Grosser 93ab558d2e [Detect] Consider nested loop profitable if entry block is not in loop
In cases where the entry block of a scop was not contained in a loop that was
part of the scop region and at the same time there was a loop surrounding the
scop, we missed to count the loops in the scop and consequently did not consider
the scop profitable. We correct this by only moving to the loop parent, in case
the current loop is loop contained in the scop.

This increases the number of loops in COSMO which we assume to be profitable
from 3974 to 4981.

llvm-svn: 311863
2017-08-27 21:39:25 +00:00
Philipp Schaad 8cb2e3245c [Polly][GPGPU] Fixed undefined reference for CUDA's managed memory in Runtime library.
llvm-svn: 311848
2017-08-27 12:50:51 +00:00
Eugene Zelenko a32707d5b1 [Polly] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).
llvm-svn: 311802
2017-08-25 21:35:27 +00:00
Eugene Zelenko 9248fde53a [Polly] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).
llvm-svn: 311704
2017-08-24 21:22:41 +00:00
Tobias Grosser 6d0970f64e Revert "[polly] Fix ScopDetectionDiagnostic test failure caused by r310940"
This reverts commit 950849ece9bb8fdd2b41e3ec348b9653b4e37df6.

This commit broke various buildbots.

llvm-svn: 311692
2017-08-24 19:47:15 +00:00
Michael Kruse b795bfc0d4 [CodeGen] Detect impossible partial write conditions more reliably.
Whether a partial write is tautological/unsatisfiable not only
depends on the access domain, but also on the domain covered
by its node in the AST.

In the example below, there are two instances of Stmt_cond_false. It may have a partial write access that is not executed in instance Stmt_cond_false(0).

      for (int c0 = 0; c0 < tmp5; c0 += 1) {
        Stmt_for_body344(c0);
        if (tmp5 >= c0 + 2)
          Stmt_cond_false(c0);
        Stmt_cond_end(c0);
      }
      if (tmp5 <= 0) {
        Stmt_for_body344(0);
        Stmt_cond_false(0);
        Stmt_cond_end(0);
      }

Isl cannot derive a subscript for an array element that is never accessed.
This caused an error in that no subscript expression has been generated
in IslNodeBuilder::createNewAccesses, but BlockGenerator expected one
to exist because there is an execution of that write, just not in that
ast node.

Fixed by instead of determining whether the access domain is empty,
inspect whether isl generated a constant "false" ast expression in
the current ast node.

This should fix a compiler crash of the aosp buildbot.

llvm-svn: 311663
2017-08-24 14:51:35 +00:00
Siddharth Bhat 78027437e6 [Polly] [PPCGCodeGeneration] Mild refactoring of checking validity of functions in a kernel.
This is a stylistic change to make the function a little more readable.
Also add a debug print to show what instruction contains a use of a
function we don't understand in the kernel.

Differential Revision: https://reviews.llvm.org/D37058

llvm-svn: 311648
2017-08-24 09:54:15 +00:00
Andreas Simbuerger e478e2de83 [Polly][WIP] Scalar fully indexed expansion
Summary:
This patch comes directly after https://reviews.llvm.org/D34982 which allows fully indexed expansion of MemoryKind::Array. This patch allows expansion for MemoryKind::Value and MemoryKind::PHI.

MemoryKind::Value seems to be working with no majors modifications of D34982. A test case has been added. Unfortunatly, no "run time" checks can be done for now because as @Meinersbur explains in a comment on D34982, DependenceInfo need to be cleared and reset to take expansion into account in the remaining part of the Polly pipeline. There is no way to do that in Polly for now.

MemoryKind::PHI is not working. Test case is in place, but not working. To expand MemoryKind::Array, we expand first the write and then after the reads. For MemoryKind::PHI, the idea of the current implementation is to exchange the "roles" of the read and write and expand first the read according to its domain and after the writes.
But with this strategy, I still encounter the problem of union_map in new access map.
For example with the following source code (source code of the test case) :

```
void mse(double A[Ni], double B[Nj]) {
  int i,j;
  double tmp = 6;
  for (i = 0; i < Ni; i++) {
    for (int j = 0; j<Nj; j++) {
      tmp = tmp + 2;
    }
    B[i] = tmp;
  }
}
```

Polly gives us the following statements and memory accesses :

```
    Statements {
    	Stmt_for_body
            Domain :=
                { Stmt_for_body[i0] : 0 <= i0 <= 9999 };
            Schedule :=
                { Stmt_for_body[i0] -> [i0, 0, 0] };
            ReadAccess :=	[Reduction Type: NONE] [Scalar: 1]
                { Stmt_for_body[i0] -> MemRef_tmp_04__phi[] };
            MustWriteAccess :=	[Reduction Type: NONE] [Scalar: 1]
                { Stmt_for_body[i0] -> MemRef_tmp_11__phi[] };
            Instructions {
                  %tmp.04 = phi double [ 6.000000e+00, %entry.split ], [ %add.lcssa, %for.end ]
            }
    	Stmt_for_inc
            Domain :=
                { Stmt_for_inc[i0, i1] : 0 <= i0 <= 9999 and 0 <= i1 <= 9999 };
            Schedule :=
                { Stmt_for_inc[i0, i1] -> [i0, 1, i1] };
            MustWriteAccess :=	[Reduction Type: NONE] [Scalar: 1]
                { Stmt_for_inc[i0, i1] -> MemRef_tmp_11__phi[] };
            ReadAccess :=	[Reduction Type: NONE] [Scalar: 1]
                { Stmt_for_inc[i0, i1] -> MemRef_tmp_11__phi[] };
            MustWriteAccess :=	[Reduction Type: NONE] [Scalar: 1]
                { Stmt_for_inc[i0, i1] -> MemRef_add_lcssa__phi[] };
            Instructions {
                  %tmp.11 = phi double [ %tmp.04, %for.body ], [ %add, %for.inc ]
                  %add = fadd double %tmp.11, 2.000000e+00
                  %exitcond = icmp ne i32 %inc, 10000
            }
    	Stmt_for_end
            Domain :=
                { Stmt_for_end[i0] : 0 <= i0 <= 9999 };
            Schedule :=
                { Stmt_for_end[i0] -> [i0, 2, 0] };
            MustWriteAccess :=	[Reduction Type: NONE] [Scalar: 1]
                { Stmt_for_end[i0] -> MemRef_tmp_04__phi[] };
            ReadAccess :=	[Reduction Type: NONE] [Scalar: 1]
                { Stmt_for_end[i0] -> MemRef_add_lcssa__phi[] };
            MustWriteAccess :=	[Reduction Type: NONE] [Scalar: 0]
                { Stmt_for_end[i0] -> MemRef_B[i0] };
            Instructions {
                  %add.lcssa = phi double [ %add, %for.inc ]
                  store double %add.lcssa, double* %arrayidx, align 8
                  %exitcond5 = icmp ne i64 %indvars.iv.next, 10000
            }
    }

```

and the following dependences :
```
{ Stmt_for_inc[i0, 9999] -> Stmt_for_end[i0] : 0 <= i0 <= 9999;
Stmt_for_inc[i0, i1] -> Stmt_for_inc[i0, 1 + i1] : 0 <= i0 <= 9999 and 0 <= i1 <= 9998;
Stmt_for_body[i0] -> Stmt_for_inc[i0, 0] : 0 <= i0 <= 9999;
Stmt_for_end[i0] -> Stmt_for_body[1 + i0] : 0 <= i0 <= 9998 }
```

When trying to expand this memory access :
```
{ Stmt_for_inc[i0, i1] -> MemRef_tmp_11__phi[] };
```

The new access map would look like this :
```
{ Stmt_for_inc[i0, 9999] -> MemRef_tmp_11__phi_exp[i0] : 0 <= i0 <= 9999; Stmt_for_inc[i0, i1] ->MemRef_tmp_11__phi_exp[i0, 1 + i1] : 0 <= i0 <= 9999 and 0 <= i1 <= 9998 }
```

The idea to implement the expansion for PHI access is an idea from @Meinersbur and I don't understand why my implementation does not work. I should have miss something in the understanding of the idea.

Contributed by: Nicolas Bonfante <nicolas.bonfante@gmail.com>

Reviewers: Meinersbur, simbuerg, bollu

Reviewed By: Meinersbur

Subscribers: llvm-commits, pollydev, Meinersbur

Differential Revision: https://reviews.llvm.org/D36647

llvm-svn: 311619
2017-08-24 00:04:45 +00:00
Michael Kruse 06ed529205 Add more statistics.
Add statistics about
- Which optimizations are applied
- Number of loops in Scops at various stages
- Number of scalar/singleton writes at various stages representative
  for scalar false dependencies
- Number of parallel loops

These will be useful to find regressions due to moving Polly further
down of LLVM's pass pipeline.

Differential Revision: https://reviews.llvm.org/D37049

llvm-svn: 311553
2017-08-23 13:50:30 +00:00
Michael Kruse 7fac28fa4f [ScopDetect] Include zero-iteration loops in loop count.
Loop with zero iteration are, syntactically, loops. They have been
excluded from the loop counter even for the non-profitable counters.
This seems to be unintentially as the sentinel value of '0' minimal
iterations does exclude such loops.

Fix by never considering the iteration count when the sentinel
value of 0 is found.

This makes the recently added NumTotalLoops couter redundant
with NumLoopsOverall, which now is equivalent. Hence, NumTotalLoops
is removed as well.

Note: The test case 'ScopDetect/statistics.ll' effectively does not
check profitability, because -polly-process-unprofitable is passed
to all test cases.

llvm-svn: 311551
2017-08-23 13:29:59 +00:00
Michael Kruse 99fba1fd52 [ScopInliner] Fix hidden overload warning. NFC.
By exposing the the hidden member, but as private.

llvm-svn: 311550
2017-08-23 13:07:43 +00:00
Michael Kruse a1579aab46 [MaximumStaticExpansion] Avoid warning in release builds.
Conditionally compile function only used in an assert().

llvm-svn: 311549
2017-08-23 12:50:02 +00:00
Michael Kruse 3044dc51cf [PPCGCodeGen] Fix compiler warning: '<': signed/unsigned mismatch. NFC.
MSVC warns about comparison between a signed and unsigned integer.
The rules of C(++) define that an unsigned comparison has to be
carried-out in this case. This is unlikely to be intended.

Fix by assigning the loop's upper bound to a signed integer first.
This also avoids repeated evaluation of the invariant upper bound.

llvm-svn: 311548
2017-08-23 12:45:25 +00:00
Michael Kruse 594386e773 [ScopInfo] Remove stray semicolon. NFC.
llvm-svn: 311547
2017-08-23 12:34:37 +00:00
Tobias Grosser d680edfb98 Move include/isl-noexceptions.h to include/isl/isl-noexceptions.h
llvm-svn: 311504
2017-08-22 22:04:22 +00:00
Jakub Kuderski 0ac1e585fc [polly] Fix ScopDetectionDiagnostic test failure caused by r310940
Summary:
ScopDetection used to check if a loop withing a region was infinite and emitted a diagnostic in such cases. After r310940 there's no point checking against that situation, as infinite loops don't appear in regions anymore.

The test failure was observed on these two polly buildbots:
http://lab.llvm.org:8011/builders/polly-arm-linux/builds/8368
http://lab.llvm.org:8011/builders/polly-amd64-linux/builds/10310

This patch XFAILs `ReportLoopHasNoExit.ll` and turns infinite loop detection into an assert.

Reviewers: grosser, sanjoy, bollu

Reviewed By: grosser

Subscribers: efriedma, aemerson, kristof.beyls, dberlin, llvm-commits

Tags: #polly

Differential Revision: https://reviews.llvm.org/D36776

llvm-svn: 311503
2017-08-22 22:01:53 +00:00
Tobias Grosser 4a07bbe3f6 [IRBuilder] Only emit alias scop metadata for arrays, but not scalars
Summary:
There is no need to emit alias metadata for scalars, as basicaa will easily
distinguish them from arrays. This reduces the size of the metadata we generate.
This is especially useful after we moved to -polly-position=before-vectorizer,
where a lot more scalar dependences are introduced, which increased the size of
the alias analysis metadata and made us commonly reach the limits after which
we do not emit alias metadata that have been introduced to prevent quadratic
growth of this alias metadata.

This improves 2mm performance from 1.5 seconds to 0.17 seconds.

Reviewers: Meinersbur, bollu, singam-sanjay

Reviewed By: Meinersbur

Subscribers: pollydev, llvm-commits

Tags: #polly

Differential Revision: https://reviews.llvm.org/D37028

llvm-svn: 311498
2017-08-22 21:58:48 +00:00
Eugene Zelenko bff61d220e [Polly] Satisfy Clang-format for r311489 changes, but it's weird that Clang-format didn't complain about headers order in previous versions (NFC).
llvm-svn: 311494
2017-08-22 21:47:17 +00:00
Eugene Zelenko 0c4c2ce0b0 [Polly] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).
llvm-svn: 311489
2017-08-22 21:25:51 +00:00
Roman Gareev 6bfeba24d3 [NFC] Fix the broken comment.
llvm-svn: 311477
2017-08-22 17:43:03 +00:00
Roman Gareev 0956a606ff Disable the Loop Vectorizer in case of GEMM
Currently, in case of GEMM and the pattern matching based optimizations, we
use only the SLP Vectorizer out of two LLVM vectorizers. Since the Loop
Vectorizer can get in the way of optimal code generation, we disable the Loop
Vectorizer for the innermost loop using mark nodes and emitting the
corresponding metadata.

Reviewed-by: Tobias Grosser <tobias@grosser.es>

Differential Revision: https://reviews.llvm.org/D36928

llvm-svn: 311473
2017-08-22 17:38:46 +00:00
Michael Kruse 595b77bc0b [ScopInfo] Fix typos in comment. NFC.
llvm-svn: 311472
2017-08-22 17:32:51 +00:00
Siddharth Bhat 14544a8068 [GPUJIT] Make max managed pointers an environment variable.
This was originally a `#define`. It is much easier to play around with
this as an environment variable when we run on large programs.

Differential Revision: https://reviews.llvm.org/D37012

llvm-svn: 311471
2017-08-22 17:32:27 +00:00
Michael Kruse a28260f486 [test] Do not pipe binary data to FileCheck.
llvm-svn: 311470
2017-08-22 17:09:56 +00:00
Michael Kruse 5b228bbb12 [ScopDetection] Add stat for total number of loops.
The total number of loops is useful as a baseline comparing how many
loops have been optimized in different configurations.

llvm-svn: 311469
2017-08-22 17:09:51 +00:00
Siddharth Bhat cb5155bf6d [ManagedMemoryRewrite] Use `unit64_t` to store size, not `int`.
llvm-svn: 311440
2017-08-22 09:30:37 +00:00
Siddharth Bhat 603544863f [ManagedMemoryRewrite] Get size in bytes rather than in bits and dividing by 8.
llvm-svn: 311439
2017-08-22 09:27:41 +00:00
Tobias Grosser 6683c81af8 test/GPGPU/invalid-kernel-assert-verifymodule.ll also requires assertions
llvm-svn: 311423
2017-08-22 03:12:29 +00:00
Michael Kruse f281ae5992 [test] Add some test cases for computeArrayUnused.
llvm-svn: 311404
2017-08-21 23:04:55 +00:00
Michael Kruse ade14269cd [DeLICM] Fix unused zone for writes without in-between read.
The implementation of computeArrayUnused did not consider writes without
reads before, except for the first write in the SCoP. This caused it to
'forget' writes directly following another write.

This patch re-adds the entire reaching defintion of a write that has not
been covered before by a read.

This fixes Polybench 4.2 2mm where only one of the matrix-multiplication
was detected.

llvm-svn: 311403
2017-08-21 23:04:45 +00:00
Siddharth Bhat a8c329b0eb [ManagedMemoryRewrite] slightly tweak debug output style. [NFC]
llvm-svn: 311361
2017-08-21 18:58:33 +00:00
Siddharth Bhat 557ce3a8b0 [ManagedMemoryRewrite] Print reasons for skipping global array to dbgs(). [NFC]
llvm-svn: 311360
2017-08-21 18:52:15 +00:00
Tobias Grosser 0dd42512ff [ZoneAlgorithm] Move computeScalarReachingDefinition to c++
llvm-svn: 311336
2017-08-21 14:19:40 +00:00
Siddharth Bhat 0a198dc18a [ManagedMemoryRewrite] hide debug output behing DEBUG(...). [NFC]
llvm-svn: 311331
2017-08-21 12:51:57 +00:00
Siddharth Bhat 7bc77e87c8 [ScopInfo] Add option to treat all function parameters as dereferencible.
Dragonegg generates most function parameters as pointers to the actual
parameters. However, it does not mark these parameters with the
dereferencable attribute.

Polly is conservative when it comes to invariant load
hoisting, thus we add runtime checks to invariant load hoisted pointers
when we do not know that pointers are dereferencable. This is correct behaviour,
but is a performance penalty.

Add a flag that allows all pointer parameters to be dereferencable. That
way, polly can speculatively load-hoist paramters to functions without
runtime checks.

Differential Revision: https://reviews.llvm.org/D36461

llvm-svn: 311329
2017-08-21 11:57:04 +00:00
Siddharth Bhat 7b9f5ca27e [PPCGCodeGeneration] Enable `polly-codegen-perf-monitoring` for PPCGCodegen.
This feature was not enabled for `PPCGCodeGeneration`. Now that this is
enabled, we can benchmark Scops that have been optimised with
`-polly-codegen-ppcg` with the `-polly-codegen-perf-monitoring` option.

Differential Revision: https://reviews.llvm.org/D36934

llvm-svn: 311328
2017-08-21 11:44:01 +00:00
Tobias Grosser b09bd74da8 [GPGPU] Add llvm.powi to the libdevice supported functions
These intrinsics are used in COSMO.

llvm-svn: 311324
2017-08-21 09:52:08 +00:00
Tobias Grosser 5170b6627a [GPGPU] Add log / logf to the libdevice supported functions
These two functions are used in COSMO

llvm-svn: 311322
2017-08-21 09:00:31 +00:00
Michael Kruse d091bf8d8e [MatMul] Make MatMul detection independent of internal isl representations.
The pattern recognition for MatMul is restrictive.

The number of "disjuncts" in the isl_map containing constraint
information was previously required to be 1
(as per isl_*_coalesce - which should ideally produce a domain map with
a single disjunct, but does not under some circumstances).

This was changed and made more flexible.

Contributed-by: Annanay Agarwal <cs14btech11001@iith.ac.in>

Differential Revision: https://reviews.llvm.org/D36460

llvm-svn: 311302
2017-08-20 21:31:11 +00:00
Siddharth Bhat 9a5a278f78 [GPUJIT] Switch from Runtime API calls for managed memory to Driver API calls.
We now load the function pointer for `cuMemAllocManaged` dynamically, so
it should be possible to compile `GPUJIT` on non-CUDA systems again.

It should now be possible to link on non-cuda systems again.

Thanks to Philipp Schaad for noticing this inconsitency.

Differential Revision: https://reviews.llvm.org/D36921

llvm-svn: 311289
2017-08-20 13:38:04 +00:00
Tobias Grosser e32498c9c3 Revert "[GPGPU] Simplify PPCGSCop to reduce compile time [NFC]"
We still see some issues with parameter space mismatches. Revert this to get
a clean baseline. We will recommit after these issues have been resolved.

This reverts commit 0e360a14194f722ded7aa2bc9d4be2ed2efeeb49.

llvm-svn: 311268
2017-08-19 23:49:26 +00:00
Tobias Grosser 9041118983 [ManagedMemoryRewrite] Make pass more robust and fix memory issue
Instead of using Twines and temporary expressions, we do string manipulation
through a std::string. This resolves a memory corruption issue, which likely
was caused by twines loosing their underlying string too soon.

llvm-svn: 311264
2017-08-19 23:03:45 +00:00
Siddharth Bhat 205a78a6f9 [ManagedMemoryRewrite] Iterate over operands of the expanded instruction, not the constantexpr itself.
- We should iterate over `I`, which is `Cur` expanded out to an
instruction, and not `Cur` itself.

- This is a bugfix.

Differential Revision: https://reviews.llvm.org/D36923

llvm-svn: 311261
2017-08-19 20:52:11 +00:00
Tobias Grosser ecb94a0392 [GPGPU] Correctly initialize array order and fixed_element information
Summary:
This information is necessary for PPCG to perform correct life range reordering.
With these changes applied we can live-range reorder some of the important
kernels in COSMO.

We also update and rename one test case, which previously could not be optimized
and now is optimized thanks to live-range reordering. To preserve test coverage
we add a new test case scalar-writes-in-scop-requires-abort.ll, which exercises
our automatic abort in case of scalar writes in the kernel.

Reviewers: Meinersbur, bollu, singam-sanjay

Subscribers: nemanjai, pollydev, llvm-commits, kbarton

Tags: #polly

Differential Revision: https://reviews.llvm.org/D36929

llvm-svn: 311259
2017-08-19 20:21:22 +00:00
Philipp Schaad 50139f0f38 [PPCG] Only add Kernel argument sizes for OpenCL, not CUDA runtime
Kernel argument sizes now only get appended to the kernel launch parameter list if the OpenCL runtime is selected, not if CUDA runtime is chosen.

Differential revision: D36925

llvm-svn: 311248
2017-08-19 17:04:57 +00:00
Tobias Grosser 9f2eb24c06 Clarify the intend of the run-time check
llvm-svn: 311243
2017-08-19 16:26:39 +00:00
Tobias Grosser 43df2020e7 [GPGPU] Collect parameter dimension used in MemoryAccesses
When using -polly-ignore-integer-wrapping and -polly-acc-codegen-managed-memory
we add parameter dimensions lazily to the domains, which results in PPCG not
including parameter dimensions that are only used in memory accesses in the
kernel space. To make sure these parameters are still passed to the kernel, we
collect these parameter dimensions and align the kernel's parameter space
before code-generating it.

llvm-svn: 311239
2017-08-19 12:58:28 +00:00
Tobias Grosser d5f1fad77c [Polly] Run early cse + memory SSA to remove redundancies in the input code
This allows us to get rid of many identical loads as they commonly appear in
Fortran code.

llvm-svn: 311231
2017-08-19 08:44:46 +00:00
Andreas Simbuerger 8d5b257d02 [Polly][Bug fix] Wrong dependences filtering during Fully Indexed expansion
Summary:
When trying to expand memory accesses, the current version of Polly uses statement Level dependences. The actual implementation is not working in case of multiple dependences per statement. For example in the following source code :
```
void mse(double A[Ni], double B[Nj], double C[Nj], double D[Nj]) {
  int i,j;
  for (j = 0; j < Ni; j++) {
    for (int i = 0; i<Nj; i++)
S:    B[i] = i;
    for (int i = 0; i<Nj; i++)
T:    D[i] = i;

U:  A[j] = B[j];
      C[j] = D[j];
  }
}
```
The statement U has two dependences with S and T. The current version of polly fails during expansion.

This patch aims to fix this bug. For that, we use Reference Level dependences to be able to filter dependences according to statement and memory ref. The principle of expansion remains the same as before.

We also noticed that we need to bail out if load come after store (at the same position) in same statement. So a check was added to isExpandable.

Contributed by: Nicholas Bonfante <nicolas.bonfante@insa-lyon.fr>

Reviewers: Meinersbur, simbuerg, bollu

Reviewed By: Meinersbur, simbuerg

Subscribers: pollydev, llvm-commits

Differential Revision: https://reviews.llvm.org/D36791

llvm-svn: 311165
2017-08-18 15:01:18 +00:00
Tobias Grosser ec02acfb98 [GPGPU] Simplify PPCGSCop to reduce compile time [NFC]
Summary:
Drop unused parameter dimensions to reduce the size of the sets we are working
with. Especially the computed dependences tend to accumulate a lot of parameters
that are present in the input memory accesses, but often not necessary to
express the actual dependences. As isl represents maps and sets with dense
matrices, reducing the dimensionality of isl sets commonly reduces code
generation performance.

This reduces compile time from 17 to 11 seconds for our test case. While this is
not impressive, this patch helped me to identify the previous two performance
improvements and additionally also increases readability of the isl data
structures we use.

Reviewers: Meinersbur, bollu, singam-sanjay

Reviewed By: bollu

Subscribers: nemanjai, pollydev, llvm-commits, kbarton

Tags: #polly

Differential Revision: https://reviews.llvm.org/D36869

llvm-svn: 311161
2017-08-18 13:38:12 +00:00
Siddharth Bhat 656e629572 [Polly] [PPCGCodeGeneration] Print current Scop and loop depth in PPCGCodeGen. [NFC]
Differential Revision: https://reviews.llvm.org/D36871

llvm-svn: 311158
2017-08-18 13:16:58 +00:00
Tobias Grosser 861a387fac [GPGPU] Do not create copy statements when targetting managed memory
Summary:
They are not used and consequently do not even need to be computed. This reduces
the overall compile time for our kernel from 1m33s to 17s.

Reviewers: Meinersbur, bollu, singam-sanjay

Reviewed By: bollu

Subscribers: nemanjai, pollydev, llvm-commits, kbarton

Tags: #polly

Differential Revision: https://reviews.llvm.org/D36868

llvm-svn: 311157
2017-08-18 13:11:05 +00:00
Tobias Grosser 62acb344d0 [GPGPU] Synchronize after each kernel, not each copy out
Summary:
This change reduces the overall number of synchronize calls for kernels with
a lot of output data at the cost of additional synchronize calls for kernels
launched in sequence without any device to host transfers in between. As the
latter pattern is a lot less frequent, this seems a better tradeoff.

Even though the above motivation would be motivation enough, this is just
a step towards enabling ppcg to not compute to and from device copy calls
at all, which would be incorrect in case we still relied on these calls to
place our synchronization statements.

Reviewers: Meinersbur, bollu, singam-sanjay

Reviewed By: bollu

Subscribers: nemanjai, kbarton, pollydev, llvm-commits

Tags: #polly

Differential Revision: https://reviews.llvm.org/D36867

llvm-svn: 311155
2017-08-18 12:55:58 +00:00
Siddharth Bhat dd616e9519 [ScpInliner] Move DEBUG-TYPE to below all includes to prevent cross-module interaction. [NFC]
This fixes compile errors.

llvm-svn: 311130
2017-08-17 22:21:16 +00:00
Tobias Grosser fa03cb7687 [GPGPU] Only collect the access that belong to an array [NFC]
This avoid the construction of very large sets and in many cases also keeps the
number of parameters low. As a result, we see a compile time reduction from 5
minutes to only slightly above 1 minute for one of our larger test cases.

llvm-svn: 311127
2017-08-17 22:04:53 +00:00
Siddharth Bhat b46847c035 [ScopInliner] Add a simple Scop-based inliner to polly.
We add a ScopInliner pass which inlines functions based on a simple heuristic:
Let `g` call `f`.
If we can model all of `f` as a Scop, we inline `f` into `g`.

This requires `-polly-detect-full-function` to be enabled. So, the pass
asserts that `-polly-detect-full-function` is enabled.

Differential Revision: https://reviews.llvm.org/D36832

llvm-svn: 311126
2017-08-17 21:57:23 +00:00
Tobias Grosser d2e57981fd [GPGPU] Move getExtend to C++ [NFC]
llvm-svn: 311123
2017-08-17 21:20:28 +00:00
Siddharth Bhat a2c4112791 [ManagedMemoryRewrite] Rewrite malloc, free correctly inside `Constant`s.
Reuse the machinery built for replacing global arrays to replace malloc/free as
well. Example replacement that was missed earlier:

```
call void \
    bitcast (void (i8*)* @free to void (%custom_type*)*) (%custom_type* %13)
```

- Since the `bitcast` is a `ConstantExpr`, `replaceAllUsesWith` would miss
this. We don't miss this anymore.

Differential Revision: https://reviews.llvm.org/D36825

llvm-svn: 311121
2017-08-17 20:26:38 +00:00
Tobias Grosser abc5416be1 [GPGPU] Make test case independent of LLVM names
In release builds LLVM may not pass along LLVM names consistently. We make the
test cases independent of the LLVM-IR names to avoid spurious test case
failures.

llvm-svn: 311118
2017-08-17 20:09:02 +00:00
Siddharth Bhat 8a2c07f6d4 [ManagedMemoryRewrite] Learn how to rewrite global arrays, allocas.
- If we have global arrays, we would like to rewrite them to global
  pointers which are allocated using `cudaMallocManaged`.

- If we have allocas in a function, we would like to rewrite them to
  heap-allocations with `cudaMallocManaged` and `cudaFree`.

- With these rewrite mechanisms, we can offload _any_ function to the
  GPU with no code rewrite whatsover.

Differential Revision: https://reviews.llvm.org/D36516

llvm-svn: 311080
2017-08-17 11:22:52 +00:00
Tobias Grosser ed6a4acc7f Add rewrite by-reference parameter pass
Summary:
This pass detangles induction variables from functions, which take variables by
reference. Most fortran functions compiled with gfortran pass variables by
reference. Unfortunately a common pattern, printf calls of induction variables,
prevent in this situation the promotion of the induction variable to a register,
which again inhibits any kind of loop analysis. To work around this issue
we developed a specialized pass which introduces separate alloca slots for
known-read-only references, which indicate the mem2reg pass that the induction
variables can be promoted to registers and consquently enable SCEV to work.

We currently hardcode the information that a function
_gfortran_transfer_integer_write does not read its second parameter, as
dragonegg does not add the right annotations and we cannot change old dragonegg
releases. Hopefully flang will produce the right annotations.

Reviewers: Meinersbur, bollu, singam-sanjay

Reviewed By: bollu

Subscribers: mgorny, pollydev, llvm-commits

Tags: #polly

Differential Revision: https://reviews.llvm.org/D36800

llvm-svn: 311066
2017-08-17 05:25:08 +00:00
Tobias Grosser 5502eb0986 Add missing 'REQUIRES' line
llvm-svn: 311046
2017-08-16 22:02:03 +00:00
Tobias Grosser e2a45f32dc [GPGPU] Also record invariant loads as kernel subtree values
Before this change kernels that used invariant loads would have resulted in
invalid PTX code.

llvm-svn: 311042
2017-08-16 21:37:53 +00:00
Michael Kruse 91e55322b9 [ScopInfo] Clarify comment. NFC.
Contributed-by: Nandini Singhal <cs15mtech01004@iith.ac.in>

Differential Revision: https://reviews.llvm.org/D36760

llvm-svn: 310999
2017-08-16 09:28:02 +00:00
Jakub Kuderski 8fb57125b0 [Polly] XFAIL ReportLoopHasNoExit tests after r310940
ReportLoopHasNoExit started failing after r310940 that added
infinite loops to postdominators. The change made regions not
contain infinite loops anymore.

This patch unbreaks the polly tree by XFAILING the
ReportLoopHasNoExit test. Full fix is under review in D36776.

llvm-svn: 310980
2017-08-16 00:18:39 +00:00
Siddharth Bhat bb30377c5a [Polly] [GPUJIT] Set min size to 1 on CUDA allocation calls. [NFC]
Requesting size 0 allocations from `cuMalloc` / `cuMallocManaged` fails.
If there is a size 0 allocation that can be statically proved, the we
fail at PPCGCodeGeneration. This is because if size 0 allocation could
take place, we should not generate code that tries to use this array.

However, there are cases where we cannot statically prove this, and at
runtime we get a request for 0 bytes of memory. We choose to allocate
size 1 to allow the program to continue running.

Differential Revision: https://reviews.llvm.org/D36751

llvm-svn: 310941
2017-08-15 18:21:38 +00:00
Tobias Grosser b8417531dd [Polly] Move ScopStmt::checkForReductions to islpp. NFC.
Reviewers: grosser, bollu

Differential Revision: https://reviews.llvm.org/D36714

llvm-svn: 310908
2017-08-15 03:45:55 +00:00
Tobias Grosser 1e09c1363c Move ScopStmt::getSchedule to islpp. NFC.
Reviewers: grosser, Meinersbur, bollu

Differential Revision: https://reviews.llvm.org/D36660

llvm-svn: 310815
2017-08-14 06:49:06 +00:00
Tobias Grosser 990cbb4310 [Polly] Move Scop::restrictDomains to islpp. NFC.
Reviewers: grosser, Meinersbur, bollu

Differential Revision: https://reviews.llvm.org/D36659

llvm-svn: 310814
2017-08-14 06:49:01 +00:00
Tobias Grosser 6e78cc6b12 [ScopInfo] Translate ParameterIds to isl++
llvm-svn: 310795
2017-08-13 17:54:51 +00:00
Reid Kleckner 8d719a27f5 Fix two warnings in polly, -Wmismatched-tags and -Wreorder
llvm-svn: 310667
2017-08-10 21:46:22 +00:00
Philip Pfaffe 7b5eaa6f62 Add missing license text to two headers. NFC.
llvm-svn: 310612
2017-08-10 15:40:36 +00:00
Philip Pfaffe c3bcdc2f1a [JSON] Make the failure to parse a jscop file a hard error
Summary:
Before, if we fail to parse a jscop file, this will be reported as an
error and importing is aborted. However, this isn't actually strong
enough, since although the import is aborted, the scop has already been
modified and is very likely broken. Instead, make this a hard failure
and throw an LLVM error. This new behaviour requires small changes to
the tests for the legacy pass, namely using `not` to verify the error.
Further, fixed the jscop file for the
base_pointer_load_is_inst_inside_invariant_1 testcase.

Reviewed By: Meinersbur

Split out of D36578.

llvm-svn: 310599
2017-08-10 14:53:25 +00:00
Philip Pfaffe 47bf15c34f [JSON][PM] Port json import/export over to new pm
Summary:
I pulled out all functionality into static functions, and use those both
in the legacy passes and in the new ones.

Reviewers: grosser, Meinersbur, bollu

Reviewed By: Meinersbur

Subscribers: llvm-commits, pollydev

Differential Revision: https://reviews.llvm.org/D36578

llvm-svn: 310597
2017-08-10 14:45:09 +00:00
Philip Pfaffe e18f3f6708 Fix 310555: Require pollyacc instead of asserts
llvm-svn: 310595
2017-08-10 14:21:04 +00:00
Philip Pfaffe 0360e5a3c2 Fix r310304: Fix the lit testcases.
In opt, Polly passes are only available after -load.

llvm-svn: 310581
2017-08-10 10:54:26 +00:00
Tobias Grosser 4db39c4829 Add missing 'REQUIRES' line
llvm-svn: 310555
2017-08-10 08:11:47 +00:00
Tobias Grosser cff9696e11 [GPGPU] Make the ast_build available to block generator
This is necessary for partial writes (as used by delicm) to work.

llvm-svn: 310553
2017-08-10 08:00:56 +00:00
Philip Pfaffe f43e7c2e97 [Polly][PM] Improve invalidation in the Scop-Pipeline
Summary:
During code generation for a Scop we modify the IR of a function.
While this shouldn't affect a Scop in the formal sense, the implementation
caches various information about the IR such as SCEV expressions for bounds or
parameters. This cached information needs to be updated or invalidated. To this
end, SPMUpdater allows passes to report when they've invalidated a Scop to the
PassManager, which will then flush and recompute all Scops. This in turn
invalidates all iterators, so references to Scops shouldn't be held.

Reviewers: grosser, Meinersbur, bollu

Reviewed By: grosser

Subscribers: llvm-commits, pollydev

Differential Revision: https://reviews.llvm.org/D36524

llvm-svn: 310551
2017-08-10 07:43:46 +00:00
Siddharth Bhat 9298ff2dee [ManagedMemoryRewrite] [Polly] Erase original malloc and free. [NFC]
We do not need to keep `malloc` and `free` around since they are
replaced by `polly_{malloc,free}Managed.`

llvm-svn: 310504
2017-08-09 18:19:46 +00:00
Michael Kruse cd3b9fedc7 Remove dependency of Scop::getStmtFor(Inst) on getStmtFor(BB). NFC.
We are working towards removing uses of Scop::getStmtFor(BB). In this
patch, we remove dependency of Scop::getStmtFor(Inst) on getStmtFor(BB).
To do so, we introduce a map of instructions to their corresponding scop
statements and use it to get the instructions' statement.

Contributed-by: Nandini Singhal <cs15mtech01004@iith.ac.in>

Differential Revision: https://reviews.llvm.org/D35663

llvm-svn: 310494
2017-08-09 16:45:37 +00:00
Siddharth Bhat 5a1f872623 [ManagedMemoryRewrite] Remove test case that was submitted by mistake. [NFC]
llvm-svn: 310473
2017-08-09 13:34:54 +00:00
Siddharth Bhat c4a4af47f3 [ManagedMemoryRewrite] Introduce a new pass to rewrite modules to use managed memory.
This pass is useful to automatically convert a codebase that uses malloc/free
to use their managed memory counterparts.

Currently, rewrite malloc and free to the `polly_{malloc,free}Managed` variants.

A future patch will teach ManagedMemoryRewrite to rewrite global arrays
as pointers to globally allocated managed memory.

Differential Revision: https://reviews.llvm.org/D36513

llvm-svn: 310471
2017-08-09 12:59:23 +00:00
Michael Kruse 40d083956c [CodeGen] Use isLatestArrayKind().
Codegen with -polly-parallel queried the unmapped MemoryAccess, but only
the MemoryKind after mapping is relevant for codegen.

This should fix various fails of the
perf-x86_64-penryn-O3-polly-parallel-fast buildbot.

llvm-svn: 310466
2017-08-09 12:27:51 +00:00
Michael Kruse 36550bac0d [ForwardOpTree] Set DEBUG_TYPE to "polly-optree".
The previous value of "polly-delicm" was forgotten to to be changed when
ForwardOpTree was split from DeLICM.

Thanks to Tobias for noticing!

llvm-svn: 310465
2017-08-09 12:27:35 +00:00
Michael Kruse 630fc7b82a [ISLTools/ZoneAlgo] Make distributeDomain and filterKnownValInst isl_error_quota proof.
distributeDomain() and filterKnownValInst() are used in a scop
of ForwardOpTree that limits the number of isl operations.
Therefore some isl functions may return null after any operation.

Remove assertion that assume non-null results and handle
isl_*_foreach returning isl::stat::error.

I hope this fixes the crash of the asop buildbot at ihevc_recon.c.

llvm-svn: 310461
2017-08-09 11:21:40 +00:00
Michael Kruse 8756b3fbec [ZoneAlgo] Add motivation for exception. NFC.
Suggested-by: Hongbin Zheng <etherzhhb@gmail.com>
llvm-svn: 310455
2017-08-09 09:29:15 +00:00
Michael Kruse a9033aaba2 [ZoneAlgo] Consolditate condition. NFC.
No need to create an OptimizationRemarkMissed object if we are not going
to use it anyway.

llvm-svn: 310454
2017-08-09 09:29:09 +00:00
Siddharth Bhat 34eeabbca3 [PPCGCodeGeneration] Compute element size in bytes for arrays correctly.
Previously, we used to compute this with `elementSizeInBits / 8`. This
would yield an element size of 0 when the array had element size < 8 in
bits.

To fix this, ask data layout what the size in bytes should be.

Differential Revision: https://reviews.llvm.org/D36459

llvm-svn: 310448
2017-08-09 08:29:16 +00:00
Michael Kruse 235726ee4b [test] Add descriptions and pseudocode to tests. NFC.
llvm-svn: 310385
2017-08-08 17:26:19 +00:00
Michael Kruse ce67358281 [DeLICM/ZoneAlgo] Remove duplicate code. NFC.
DeLICM and ZoneAlgo both implemented filterKnownValInst.

Declare ZoneAlgo's version in the header and let DeLCIM use it.

llvm-svn: 310381
2017-08-08 17:00:27 +00:00
Roman Gareev 1563f039f5 Use SCEV information for the second level aliasing
We introduce another level of alias metadata to distinguish the individual
non-aliasing accesses that have inter iteration alias-free base pointers
marked with "Inter iteration alias-free" mark nodes. To distinguish two
accesses, the comparison of raw pointers representing base pointers is used.

In case of, for example, ublas's prod function that implements GEMM, and
DeLiCM we can get accesses to same location represented by different raw
pointers. Consequently, we create different alias sets that can prevent
accesses from, for example, being sinked or hoisted.

To avoid the issue, we compare the corresponding SCEV information instead
of the corresponding raw pointers.

Reviewed-by: Tobias Grosser <tobias@grosser.es>

Differential Revision: https://reviews.llvm.org/D35761

llvm-svn: 310380
2017-08-08 16:50:28 +00:00
Roman Gareev dbde718676 Do not use isl_set_project_out to get all loop prefixes
Currently, only convex isolation sets can be efficiently processed by isl.
Consequently, as a temporary solution, we use a different algorithm for partial
tile isolation that helps to build convex isolation sets in some cases.

Reviewed-by: Tobias Grosser <tobias@grosser.es>

Differential Revision: https://reviews.llvm.org/D36278

llvm-svn: 310374
2017-08-08 16:15:33 +00:00
Tobias Grosser 79d9c29310 [RegisterPasses] Run polly-simplify also right after scop modeling
This allows us to get rid of stores that are overwritten within the very same
basic block, without ever being read beforehand. This simplification is
necessary for delicm to run on pb4's correlation.

llvm-svn: 310369
2017-08-08 15:14:46 +00:00
Siddharth Bhat 9aca1cb519 [NFC] [PPCGCodeGen] Add missing REQUIRES: pollyacc line.
llvm-svn: 310354
2017-08-08 12:26:37 +00:00
Siddharth Bhat 83fe6b546d [ScopInfo] [NFC] Typo fix.
"to conservative" -> "too conservative".

llvm-svn: 310353
2017-08-08 12:26:32 +00:00
Siddharth Bhat 71dfb3eb07 [Polly] [PPCGCodeGeneration] Handle failing of invariant load hoisting gracefully.
To do this, we replicate what `CodeGeneration` does. We expose
`markNodeUnreachable` from `CodeGeneration` to `PPCGCodeGeneration`.

Differential Revision: https://reviews.llvm.org/D36457

llvm-svn: 310350
2017-08-08 12:00:59 +00:00
Michael Kruse 27c010a22e [DeLICM] Properly handle PHI writes becoming empty partial writes.
It is possible that partial writes are empty (write is never executed).
In this case, when in PHINode's incoming edge is never taken such that
the incoming write becomes an empty partial write, if enabled. The
issue is that when converting the union_map to an map, it's space
cannot be derived from the union_map itself. Rather, we need to
determine its space independently.

This fixes test-suite's MultiSource/Benchmarks/ASC_Sequoia/CrystalMk.

llvm-svn: 310348
2017-08-08 11:27:12 +00:00
Siddharth Bhat 8ff723dcf1 [NFC] [GPUJIT] Print line number & size information on allocateMemoryForDeviceCuda failure
- It's useful to know the amount of memory asked for since, for example,
  asking for `0` bytes of memory is illegal.

- Line number is helpful since we print the same message in the function
  at different points.

llvm-svn: 310340
2017-08-08 09:03:27 +00:00
Tobias Grosser 327e9ecb0d [ScheduleOptimizer] Make matmul pattern detection work with delicm output
In certain cases delicm might decide to not leave the original array write in
the loop body, but to remove it and instead leave a transformed phi node as
write access. This commit teached the matmul pattern detection to order the
memory accesses according to when the access actually happens and use this
information to detect the new pattern. This makes pattern based matmul
optimization work for 2mm and 3mm in polybench 4 after
polly-position=before-vectorizer has been enabled.

llvm-svn: 310338
2017-08-08 06:15:15 +00:00
Tobias Grosser 50206d8f57 Change Polly's position to "before-vectorizer"
Polly has traditionally always been executed at the beginning of the pass
pipeline as LLVM's inliner and DeLICM passes introduced plenty of scalar
dependences which prevented any kind of useful high-level loop optimizations
later in the pass pipeline. With DeLICM now being available, Polly can also
run optimizations when folded into the pass pipeline. This has the benefit
that Polly should now be more effective on C++ code and as an additional bonus,
no additional early canonicalization phase must be run. As a result, Polly
touches the code only if it applies a transformation. Code that does not
benefit from Polly is not touched and consequently will have the very same
execution time as without Polly enabled. Random performance changes, as could
sometimes be observed with polly-position=early are consequently not possible
any more. If performance is changed, this is due to Polly is choosing to
perform a transformation. If this choice is wrong, it can be fixed directly
in Polly.

http://polly.llvm.org/docs/Architecture.html#polly-in-the-llvm-pass-pipeline

llvm-svn: 310319
2017-08-07 22:33:34 +00:00
Tobias Grosser 736c44c848 [test] Add some missing options that become necessary after the recent default changes
llvm-svn: 310315
2017-08-07 22:10:23 +00:00
Tobias Grosser 32f64ed22b [DeLICM] Enable partial writes
This allows us to remove more scalar dependences. While this feature is still
rather experimental, we want to give it sufficient test coverage.

llvm-svn: 310314
2017-08-07 22:06:07 +00:00
Tobias Grosser ad73f6a7b3 Enable delicm to automatically remove scalar loop carried dependences
While this code is still rather we enable it by default to get better test
coverage.

llvm-svn: 310313
2017-08-07 22:04:20 +00:00
Tobias Grosser a98081c9f5 [test] Add one more test case for the previous commit
llvm-svn: 310312
2017-08-07 22:02:06 +00:00
Tobias Grosser 2ef378120d [ZoneAlgo] Allow two writes that write identical values into same array slot
Two write statements which write into the very same array slot generally are
conflicting. However, in case the value that is written is identical, this
does not cause any problem. Hence, allow such write pairs in this specific
situation.

llvm-svn: 310311
2017-08-07 22:01:29 +00:00
Andreas Simbuerger 81fb6b3e40 [Polly] Fully-Indexed static expansion
This commit implements the initial version of fully-indexed static
expansion.

```
 for(int i = 0; i<Ni; i++)
   for(int j = 0; j<Ni; j++)
S:     B[j] = j;
T: A[i] = B[i]
```

After the pass, we want this :
```
 for(int i = 0; i<Ni; i++)
   for(int j = 0; j<Ni; j++)
S:     B[i][j] = j;
T: A[i] = B[i][i]
```

For now we bail (fail) in the following cases:
  - Scalar access
  - Multiple writes per SAI
  - MayWrite Access
  - Expansion that leads to an access to the original array

Furthermore: We still miss checks for escaping references to the array
base pointers. A future commit will add the missing escape-checks to
stay correct in those cases. The expansion is still locked behind a
CLI-Option and should not yet be used.

Patch contributed by: Nicholas Bonfante <bonfante.nicolas@gmail.com>

Reviewers: simbuerg, Meinersbur, bollu

Reviewed By: Meinersbur

Subscribers: mgorny, llvm-commits, pollydev

Differential Revision: https://reviews.llvm.org/D34982

llvm-svn: 310304
2017-08-07 20:54:20 +00:00
Tobias Grosser d70ea7fed0 [GPGPU] Remove redundant constructors
llvm-svn: 310284
2017-08-07 19:20:57 +00:00
Michael Kruse 70af4f579d [ForwardOpTree] Use known array content analysis to forward load instructions.
This is an addition to the -polly-optree pass that reuses the array
content analysis from DeLICM to find array elements that contain the
same value as the value loaded when the target statement instance
is executed.

The analysis is now enabled by default.

The known content analysis could also be used to rematerialize any
llvm::Value that was written to some array element, but currently
only loads are forwarded.

Differential Revision: https://reviews.llvm.org/D36380

llvm-svn: 310279
2017-08-07 18:40:29 +00:00
Tobias Grosser 305d3164f2 [ScopInfo] Make Scop::canAlwaysBeHoisted a member function
llvm-svn: 310236
2017-08-07 00:10:11 +00:00
Tobias Grosser e69b272260 [ScopInfo] Move Scop::addInvariantLoads to isl++ [NFC]
llvm-svn: 310235
2017-08-06 23:50:25 +00:00
Tobias Grosser 61bd3a4840 [ScopInfo] Move Scop::getPwAffOnly to isl++ [NFC]
llvm-svn: 310231
2017-08-06 21:42:38 +00:00
Tobias Grosser 31df6f31c0 [ScopInfo] Move Scop::getDomains to isl++ [NFC]
llvm-svn: 310230
2017-08-06 21:42:25 +00:00
Tobias Grosser 04ec2eb8c9 [ScopInfo] Move Scop::getInvalidContext to isl++ [NFC]
llvm-svn: 310229
2017-08-06 21:42:16 +00:00
Tobias Grosser e127033f98 [ScopInfo] Move Scop::getAssumedContext to isl++ [NFC]
llvm-svn: 310228
2017-08-06 21:42:09 +00:00
Tobias Grosser 232fdad4f2 [ScopInfo] Move Scop::addNonEmptyDomainConstraints to isl++ [NFC]
llvm-svn: 310225
2017-08-06 20:19:26 +00:00
Tobias Grosser b65ccc4302 [ScopInfo] Translate Scop::getParamSpace to isl++ [NFC]
llvm-svn: 310224
2017-08-06 20:11:59 +00:00
Tobias Grosser 8ea1fc19b3 [ScopInfo] Translate Scop::getContext to isl++ [NFC]
llvm-svn: 310221
2017-08-06 19:52:38 +00:00
Tobias Grosser 9a63570b13 [ScopInfo] Translate Scop::getIdForParam to isl++ [NFC]
llvm-svn: 310220
2017-08-06 19:31:27 +00:00
Tobias Grosser 5ab39ff224 [ScopInfo] Move get*Writes/getReads/getAccesses to isl++
llvm-svn: 310219
2017-08-06 19:22:27 +00:00
Tobias Grosser b2e6598a7f Remove functional changes that sneaked in by accident in r308892
llvm-svn: 310218
2017-08-06 18:59:19 +00:00
Tobias Grosser 132860afe5 [ScopInfo] Move ScopStmt::setAstBuild/getAstBuild to isl++
llvm-svn: 310216
2017-08-06 17:53:04 +00:00
Tobias Grosser 6ad1640a1d [ScopInfo] Move ScopStmt::getSchedule to isl++
llvm-svn: 310215
2017-08-06 17:45:28 +00:00
Tobias Grosser 2f3041fc6a [ScopInfo] Move getPredecessorDomainConstraints to isl++ [NFC]
llvm-svn: 310214
2017-08-06 17:31:38 +00:00
Tobias Grosser d16f927781 [ScopInfo] Move InvariantAccess to isl++ [NFC]
llvm-svn: 310213
2017-08-06 17:25:14 +00:00
Tobias Grosser dfd20b7949 [ScopInfo] Update comments to refer to isl++ [NFC]
llvm-svn: 310212
2017-08-06 17:25:09 +00:00
Tobias Grosser 27db02b247 [ScopInfo] Move ScopArrayInfo::ScopArrayInfo to isl++ [NFC]
llvm-svn: 310211
2017-08-06 17:25:05 +00:00
Tobias Grosser 85048eff1a [ScopInfo] Move ScopStmt::ScopStmt to isl++ [NFC]
llvm-svn: 310210
2017-08-06 17:24:59 +00:00
Tobias Grosser dcf8d696ff Move ScopInfo::getDomain(), getDomainSpace(), getDomainId() to isl++
llvm-svn: 310209
2017-08-06 16:39:52 +00:00
Tobias Grosser a9b5bbac78 Move ScopStmt::Domain to isl++
llvm-svn: 310207
2017-08-06 16:11:53 +00:00
Tobias Grosser cb0224ad59 Update to a newer version of isl++
llvm-svn: 310206
2017-08-06 15:56:45 +00:00
Tobias Grosser 8b40f8c6c7 Update to isl-0.18-812-g565da6e
This update is mostly a maintenance update, but also exposes a couple of new
functions that will be needed for the next version of the isl++ bindings.

llvm-svn: 310205
2017-08-06 15:51:16 +00:00
Tobias Grosser bfee458d0f [Scopinfo] Fix memory corruption issue that sneaked into the previous commit
llvm-svn: 310204
2017-08-06 15:47:04 +00:00
Tobias Grosser 2332fa3604 [ScopInfo] Move InvalidDomain to isl++ [NFC]
llvm-svn: 310203
2017-08-06 15:36:48 +00:00
Tobias Grosser 2b7479b1af [Polly] Fix for the JSON Exporter
Summary:
Small patch to fix the JSON exporter.

Currently, using "opt -polly-export-jscop" does not generate jscop files, but gives an error:
*** Error in `opt': corrupted double-linked list: 0x0000000000bc4bb0 ***

Updated the function getAccessRelationStr() to work with the current version of getAccessRelation(), fixing the JSON exporter

Reviewers: bollu, grosser

Reviewed By: grosser

Subscribers: grosser, llvm-commits, pollydev

Tags: #polly

Differential Revision: https://reviews.llvm.org/D36370

llvm-svn: 310199
2017-08-06 11:41:10 +00:00
Tobias Grosser aabfbfa5fc Add missing 'REQUIRES: pollyacc' line
llvm-svn: 310197
2017-08-06 11:21:09 +00:00
Tobias Grosser b99c11710c [GPGPU] Make sure managed arrays are prepared at the beginning of the scop
Summary:
This resolves some "instruction does not dominate use" errors, as we used to
prepare the arrays at the location of the first kernel, which not necessarily
dominated all other kernel calls.

Reviewers: Meinersbur, bollu, singam-sanjay

Subscribers: nemanjai, pollydev, llvm-commits, kbarton

Differential Revision: https://reviews.llvm.org/D36372

llvm-svn: 310196
2017-08-06 11:10:38 +00:00
Tobias Grosser 5b307cdb8a [GPGPU] Rename all, not only the first libdevice function
llvm-svn: 310194
2017-08-06 03:04:15 +00:00
Siddharth Bhat e53c924b0f [Polly] [PPCGCodeGeneration] Deal with loops outside the Scop correctly in PPCGCodeGeneration.
A Scop with a loop outside it is not handled currently by
PPCGCodeGeneration. The test case is such that the Scop has only one inner loop
that is detected. This currently breaks codegen.

The fix is to reuse the existing mechanism in `IslNodeBuilder` within
`GPUNodeBuilder.

Differential Revision: https://reviews.llvm.org/D36290

llvm-svn: 310193
2017-08-06 02:39:05 +00:00
Siddharth Bhat 0caed1fbe6 [IslNodeBuilder] [NFC] Refactor creation of loop induction variables of loops outside scops.
This logic is duplicated, so we refactor it into a separate function.
 This will be used in a later patch to teach PPCGCodeGen code generation
 for loops that are outside the scop.

 Differential Revision: https://reviews.llvm.org/D36310

llvm-svn: 310192
2017-08-06 02:07:11 +00:00
Tobias Grosser f2068ef7dd [Polly] Fix typo. NFC.
Reviewers: grosser, Meinersbur, bollu

Differential Revision: https://reviews.llvm.org/D36356

llvm-svn: 310187
2017-08-05 20:03:13 +00:00
Tobias Grosser f9308489eb Add forgotten CMakeLists.txt file in unit-test
llvm-svn: 310177
2017-08-05 09:44:11 +00:00
Tobias Grosser 00f25d0915 Fix spelling error in previous commit
llvm-svn: 310176
2017-08-05 09:39:00 +00:00
Tobias Grosser feae3dfe9f [unittests] Add unittest for getPartialTilePrefixes
In https://reviews.llvm.org/D36278 it was pointed out that the behavior of
getPartialTilePrefixes is not very well understood. To allow for a better
understanding, we first provide some basic unittests.

llvm-svn: 310175
2017-08-05 09:38:09 +00:00
Michael Kruse 138a3fbae1 [DeLICM] Refactor ZoneAlgorithm into ZoneAlgo.cpp. NFC.
Extract ZoneAlgorithm from DeLICM.cpp into its own file.
It will gain a second use by the load forwarding part of
-polly-optree.

llvm-svn: 310146
2017-08-04 22:51:23 +00:00
Siddharth Bhat 638316da5b [PPCGCodeGeneration] [NFC] Log every location from which PPCGCodegen bails.
This is useful when trying to understand why no GPU code was produced.

Differential Revision: https://reviews.llvm.org/D36318

llvm-svn: 310103
2017-08-04 19:36:40 +00:00
Michael Kruse a9a7086319 [ForwardOpTree] Refactor out forwardSpeculatable(). NFC.
The method forwardSpeculatable forwards speculatively executable
instructions and is currently the only way to forward an
instruction.

In the future we intend to add more methods.

llvm-svn: 310056
2017-08-04 12:28:42 +00:00
Philip Pfaffe 96d2143f20 [PM] Make the new-pm passes behave more like the legacy passes
Summary:
Testing the new-pm passes becomes much easier once they behave more like the
old passes in terms of the order in which Scops are processed and printed. This
requires three changes:
- ScopInfo: Use an ordered map to store scops
- ScopInfo: Iterate and print Scops in reverse order to match legacy PM behaviour
- ScopDetection: print function name in ScopAnalysisPrinter

Reviewers: grosser, Meinersbur, bollu

Reviewed By: grosser

Subscribers: pollydev, llvm-commits

Differential Revision: https://reviews.llvm.org/D36303

llvm-svn: 310052
2017-08-04 11:28:51 +00:00
Philip Pfaffe 6ea444e671 [NFC] Fix r310036: Appease clang-format
llvm-svn: 310039
2017-08-04 08:26:45 +00:00
Philip Pfaffe b24beb6f46 [NFC] ScopPass: Remove unused AnalysisKey from OwningInnerAnalysisManagerProxy
llvm-svn: 310036
2017-08-04 08:12:31 +00:00
Michael Kruse 1046aa3148 [VirtualInstruction] Handle MetadataAsValue as constant.
The complication of bspatch.cc of the AOSP buildbot currently fails
presumably because the occurance of a MetadataAsValue in an operand.
This kind of value can occur as operands of intrinsics, the typical
example being the debug intrinsics.

Polly currently ignores the debug intrinsics and it is not yet clear
which other intrinic might occur. For such cases, and to unbreak the
AOSP buildbot, treat a MetadataAsValue as a constant because it can be
referenced without modification in generated code.

llvm-svn: 309992
2017-08-03 22:00:01 +00:00
Michael Kruse 672c011460 [VirtualInstruction] Avoid use of getStmtFor(BB). NFC.
With this patch, we get rid of the last use of getStmtFor(BB). Here
this is done by getting the last statement of the incoming block in
case the user is a phi node; otherwise just fetching the statement
comprising the instruction for which the virtual use is being created.

Differential Revision: https://reviews.llvm.org/D36268

llvm-svn: 309947
2017-08-03 15:27:00 +00:00
Tobias Grosser c1cfe0a828 Add missing REQUIRES line
llvm-svn: 309943
2017-08-03 14:46:53 +00:00
Tobias Grosser b5563c6817 Make sure that all parameter dimensions are set in schedule
Summary:
In case the option -polly-ignore-parameter-bounds is set, not all parameters
will be added to context and domains. This is useful to keep the size of the
sets and maps we work with small. Unfortunately, for AST generation it is
necessary to ensure all parameters are part of the schedule tree. Hence,
we modify the GPGPU code generation to make sure this is the case.

To obtain the necessary information we expose a new function
Scop::getFullParamSpace(). We also make a couple of functions const to be
able to make SCoP::getFullParamSpace() const.

Reviewers: Meinersbur, bollu, gareevroman, efriedma, huihuiz, sebpop, simbuerg

Subscribers: nemanjai, kbarton, pollydev, llvm-commits

Tags: #polly

Differential Revision: https://reviews.llvm.org/D36243

llvm-svn: 309939
2017-08-03 13:51:15 +00:00
Michael Kruse 291fd8074e [test] Fix test case without Polly-ACC.
llvm-svn: 309938
2017-08-03 13:44:31 +00:00
Siddharth Bhat eadf76d34a [PPCGCodeGeneration] Construct `isl_multi_pw_aff` of PPCGArray.bounds even when polly-ignore-parameter-bounds is turned on.
When we have `-polly-ignore-parameter-bounds`, `Scop::Context` does not contain
all the paramters present in the program.

The construction of the `isl_multi_pw_aff` requires all the indivisual `pw_aff`
to have the same parameter dimensions. To achieve this, we used to realign
every `pw_aff` with `Scop::Context`. However, in conjunction with
`-polly-ignore-parameter-bounds`, this is now incorrect, since `Scop::Context`
does not contain all parameters.

We set this up correctly by creating a space that has all the parameters
used by all the `isl_pw_aff`. Then, we realign all `isl_pw_aff` to this space.

llvm-svn: 309934
2017-08-03 12:09:33 +00:00
Tobias Grosser a195576118 Enable simplify and forward-op-tree by default
These passes have been tested over the last month and should generally help
to remove scalar data dependences in Polly. We enable them to give them even
wider test coverage. Large performance regressions and any kind of correctness
regressions are not expected.

llvm-svn: 309878
2017-08-02 20:12:27 +00:00
Tobias Grosser 7b45af13ce Move setNewAccessRelation to isl++
llvm-svn: 309871
2017-08-02 19:27:25 +00:00
Tobias Grosser 6d58804cc2 Move ScopStmt::setAccessRelation to isl++
llvm-svn: 309870
2017-08-02 19:27:16 +00:00
Tobias Grosser 18ca9e5119 Replace asserts with llvm_unreachable to clarify intent
llvm-svn: 309856
2017-08-02 19:11:46 +00:00
Philip Pfaffe 33aef072c1 Fix r309826: Appease clang-format check.
llvm-svn: 309853
2017-08-02 18:26:48 +00:00
Singapuram Sanjay Srivallabh 1f9ab16c4e Fix code format on r309826
Summary:
Fix code format on r309826 / D35458

Reviewers: grosser, bollu

Reviewed By: grosser

Subscribers: pollydev

Tags: #polly

Differential Revision: https://reviews.llvm.org/D36232

llvm-svn: 309845
2017-08-02 17:56:39 +00:00
Philip Pfaffe 8f1872fb27 Fix r309826: Move intantiation and specialization of OwningScopAnalysisManagerFunctionProxy to the polly namespace.
When compiling with clang, explicit instantiation of the
OwningScopAnalysisManagerFunctionProxy needs to happen within the polly
namespace. Same goes with the specialization of its run method.

llvm-svn: 309835
2017-08-02 17:25:45 +00:00
Philip Pfaffe a70e2649ab [Polly][PM][WIP] Polly pass registration
Summary:
This patch is a first attempt at registering Polly passes with the LLVM tools. Tool plugins are still unsupported, but this registration is usable from the tools if Polly is linked into them (albeit requiring minimal patches to those tools). Registration requires a small amount of machinery (the owning analysis proxies), necessary for injecting ScopAnalysisManager objects into the calling tools.

This patch is marked WIP because the registration is incomplete. Parsing manual pipelines is fully supported, but default pass injection into the O3 pipeline is lacking, mostly because there is opportunity for some redesign here, I believe. The first point of order would be insertion points. I think it makes sense to run before the vectorizers. Running Polly Early, however, is weird. Mostly because it actually is the default (which to me is unexpected), and because Polly runs it's own O1 pipeline. Why not instead insert it at an appropriate place somewhere after simplification happend? Running after the loop optimizers seems intuitive, but it also seems wasteful, since multiple consecutive loops might well be a single scop, and we don't need to run for all of them.

My second request for comments would be regarding all those smallish helper passes we have,  like PollyViewer, PollyPrinter, PollyImportJScop. Right now these are controlled by command line options, deciding whether they should be part of the Polly pipeline. What is your opinion on treating them like real passes, and have the user write an appropriate pipeline if they want to use any of them?

Reviewers: grosser, Meinersbur, bollu

Reviewed By: grosser

Subscribers: llvm-commits, pollydev

Tags: #polly

Differential Revision: https://reviews.llvm.org/D35458

llvm-svn: 309826
2017-08-02 15:52:25 +00:00
Singapuram Sanjay Srivallabh 188053af5e Remove debug metadata from copied instruction to prevent GPUModule verification failure
Summary:
**Remove debug metadata from instruction to be copied to prevent the source file's debug metadata being copied into GPUModule and eventually failing Module verification and ASM string codegeneration.**

When copying the instruction onto the Module meant for the GPU, debug metadata attached to an instruction causes all related metadata to be pulled into the Module, including the DICompileUnit, which is not listed in llvm.dbg.cu of the Module. This fails the verification of the Module and generation of the ASM string.

The only debug metadata of the instruction, the DebugLoc, is unset by this patch.

This patch reattempts https://reviews.llvm.org/D35630 by targeting only those instructions that are to end up in a Module meant for the GPU.

Reviewers: grosser, bollu

Reviewed By: grosser

Subscribers: pollydev

Tags: #polly

Differential Revision: https://reviews.llvm.org/D36161

llvm-svn: 309822
2017-08-02 15:20:07 +00:00
Philip Pfaffe f081ec7609 [PM] Fix proxy invalidation
Summary: I made a mistake in handling transitive invalidation of analysis results. I've updated the list of preserved analyses as well as the correct result dependences.

The Invalidator passed through the invalidate() path can be used to
transitively invalidate analyses. It frequently happens that analysis
results depend on other analyses, and thus store references to their
results. When the dependee now gets invalidated, the depender needs to
be invalidated as well. This is the purpose of the Invalidator object,
which can be used to check whether some dependee analysis is in the
process of being invalidated. I originally was checking the wrong
dependee analyses, which is an actual error, you can only check analysis
results that are in the cache (which they are if you've captured their
reference). The invalidation I'm handling inside the proxy deals with
the standard analyses the proxy passes into the Scop pipeline, since I'm
capturing their reference.

This checking allows us to actually preserve a couple of results outside
of the proxy, since the Scop pipeline shouldn't break those, or
otherwise should update them accordingly.

Reviewers: grosser, Meinersbur, bollu

Reviewed By: grosser

Subscribers: pollydev, llvm-commits

Differential Revision: https://reviews.llvm.org/D36216

llvm-svn: 309811
2017-08-02 13:18:49 +00:00
Siddharth Bhat f23bb4a8ba [GPUJIT] Add GPUJIT APIs for allocating and freeing managed memory.
We introduce `polly_mallocManaged` and `polly_freeManaged` as
proxies for `cudaMallocManaged` / `cudaFree`. This is currently not
used by Polly. It is auxiliary code that is used in `COSMO`.

This is useful because `polly_mallocManaged` matches the signature of `malloc`,
while `cudaMallocManaged` does not. We introduce `polly_freeManaged` for
symmetry.

We use this in COSMO to use the unified memory feature of the newer
CUDA APIs (>= 6).

Differential Revision: https://reviews.llvm.org/D35991

llvm-svn: 309808
2017-08-02 12:23:22 +00:00
Philip Pfaffe ead67dbbd6 [SI][NewPM] Collect loop count statistics
llvm-svn: 309807
2017-08-02 11:14:41 +00:00
Philip Pfaffe f5a4394ad6 [SD] Set PollyUseRuntimeAliasChecks correctly
llvm-svn: 309805
2017-08-02 11:08:01 +00:00
Siddharth Bhat b1a52abd87 [GPUJIT] Teach GPUJIT to use a pre-existing CUDA context if available.
On mixing the driver and runtime APIs, it is quite possible that a
context already exists due to runtime API usage. In this case, Polly should
try to use the same context.

This patch teaches GPUJIT to detect that a context exists and how to
pick up this context.

Without this, calling `cudaMallocManaged`, for example, before a
polly-generated kernel launch causes P100 to *hang*.

This is a part of (https://reviews.llvm.org/D35991) that was extracted
out.

Differential Revision: https://reviews.llvm.org/D36162

llvm-svn: 309802
2017-08-02 09:19:42 +00:00
Michael Kruse fd35089689 [ForwardOpTree] Execute canForwardTree also in release builds.
Commit r309730 moved the call to canForwardTree into an assert(), even
though this function has side-effects if its DoIt parameter is true. To
avoid a warning in release builds, do an (void)Execution of its result
instead.

To avoid such confusion in the future, rename
canForwardTree() to forwardTree().

llvm-svn: 309753
2017-08-01 22:15:04 +00:00
Michael Kruse bc88a78cb4 [Simplify] Rewrite redundant write detection algorithm.
The previous algorithm was to search a writes and the sours of its value
operand, and see whether the write just stores the same read value back,
which includes a search whether there is another write access between
them. This is O(n^2) in the max number of accesses in a statement
(+ the complexity of isl comparing the access functions).

The new algorithm is more similar to the one used for searching for
overwrites and coalescable writes. It scans over all accesses in order
of execution while tracking which array elements still have the same
value since it was read. This is O(n), not counting the complexity
within isl. It should be more reliable than trying to catch all
non-conforming cases in the previous approach. It is also less code.

We now also support if the write is a partial write of the read's
domain, and to some extent non-affine subregions.

Differential Revision: https://reviews.llvm.org/D36137

llvm-svn: 309734
2017-08-01 20:01:34 +00:00
Reid Kleckner 859c1e606a Silence -Wunused-variable warning in NDEBUG builds
llvm-svn: 309730
2017-08-01 19:53:01 +00:00
Michael Kruse 693ef99935 [Simplify] Improve scalability.
With a lot of reads and writes to the same array in a statement,
some isl sets that capture the state between access can become
complex such that isl takes more considerable time and memory
for operations on them.

The problems identified were:

- is_subset() takes considerable time with many disjoints in the
  arguments. We limit the number of disjoints to 4, any additional
  information is thrown away.

- subtract() can lead to many disjoints. We instead assume that any
  array element is possibly accessed, which removes all disjoints.

- subtract_domain() may lead to considerable processing, even if all
  elements are are to be removed. Instead, we remove determine and
  remove the affected spaces manually. No behaviour is changed.

llvm-svn: 309728
2017-08-01 19:39:11 +00:00
Tobias Grosser e327eebccb Update to isl-0.18-809-gd5b4535
This fixes some undefined behavior in the isl schedule tree code.

llvm-svn: 309727
2017-08-01 19:37:50 +00:00
Siddharth Bhat 1ec9cba4e3 [NFC] Add 'REQUIRES: pollyacc' on 'test/GPGPU/invariant-load-hoisting-of-array.ll'
- Should fix broken build due to `r309681`.

llvm-svn: 309686
2017-08-01 14:52:18 +00:00
Siddharth Bhat 442e722c1e [GPUJIT] Call `cuProfilerStop` before destroying the context to flush profiler cache.
This is necessary to get accurate traces from `nvprof` / `nvcc`.
Otherwise, we lose some profiling information.

Differential Revision: https://reviews.llvm.org/D35940

llvm-svn: 309682
2017-08-01 14:36:24 +00:00
Siddharth Bhat edf9581e4c [PPCGCodeGeneration] Correct usage of llvm::Value with getLatestValue.
It is possible that the `HostPtr` that coresponds to an array could be
invariant load hoisted. Make sure we use the invariant load hoisted
value by using `IslNodeBuilder::getLatestValue`.

Differential Revision: https://reviews.llvm.org/D36001

llvm-svn: 309681
2017-08-01 14:26:39 +00:00
Siddharth Bhat f2cfd2a4db [NFC] [IslNodeBuilder, GPUNodeBuilder] Unify mechanism for looking up replacement Values.
We populate `IslNodeBuilder::ValueMap` which contains replacements for
`llvm::Value`s. There was no simple method to pick up a replacement if
it exists, otherwise fall back to the original.

Create a method `IslNodeBuilder::getLatestValue` which provides this
functionality.

This will be used in a later patch to fix bugs in `PPCGCodeGeneration`
where the latest value is not being used.

Differential Revision: https://reviews.llvm.org/D36000

llvm-svn: 309674
2017-08-01 12:15:51 +00:00
Siddharth Bhat 4d5820d171 [NFC] [PPCGCodeGeneration] Convert GPUNodeBuilder::getGridSizes to isl++.
llvm-svn: 309671
2017-08-01 10:45:41 +00:00
Siddharth Bhat ccbf4b509c [NFC] [PPCGCodeGeneration] Convert GPUNodeBuilder::getArrayOffset to isl++.
llvm-svn: 309669
2017-08-01 09:58:55 +00:00
Michael Kruse 9f6e41cdba [ForwardOpTree] Support synthesizable values.
This allows -polly-optree to move instructions that depend on
synthesizable values.

The difficulty for synthesizable values is that their value depends on
the location. When it is moved over a loop header, and the SCEV
expression depends on the loop induction variable (SCEVAddRecExpr), it
would use the current induction variable instead of the last one.

At the moment we cannot forward PHI nodes such that crossing the header
of loops referenced by SCEVAddRecExpr is not possible (assuming the loop
header has at least two incoming blocks: for entering the loop and the
backedge, such any instruction to be forwarded must have a phi between
use and definition).

A remaining issue is when the forwarded value is used after the loop,
but is only synthesizable inside the loop. This happens e.g. if
ScalarEvolution is unable to determine the number of loop iterations or
the initial loop value. We do not forward in this situation.

Differential Revision: https://reviews.llvm.org/D36102

llvm-svn: 309609
2017-07-31 19:46:21 +00:00
Michael Kruse 57cc92b790 [Simplify] Remove all kinds of redundant scalar writes.
In addition to array and PHI writes, also allow scalar value writes.
The only kind of write not allowed are writes by functions
(including memcpy/memmove/memset).

llvm-svn: 309582
2017-07-31 17:04:55 +00:00
Tobias Grosser 8fc6cdfb1c [GPGPU] Add support for NVIDIA libdevice
Summary:
This allows us to map functions such as exp, expf, expl, for which no
LLVM intrinsics exist. Instead, we link to NVIDIA's libdevice which provides
high-performance implementations of a wide range of (math) functions. We
currently link only a small subset, the exp, cos and copysign functions. Other
functions will be enabled as needed.

Reviewers: bollu, singam-sanjay

Reviewed By: bollu

Subscribers: tstellar, tra, nemanjai, pollydev, mgorny, llvm-commits, kbarton

Tags: #polly

Differential Revision: https://reviews.llvm.org/D35703

llvm-svn: 309560
2017-07-31 14:03:16 +00:00
Tobias Grosser 39977e4e76 Revert "Remove Debug metadata from copied instruction to prevent Module verification failure"
This reverts commit r309490 as it triggers on our AOSP buildbut error messages
of the form:

inlinable function call in a function with debug info must have a !dbg location

llvm-svn: 309556
2017-07-31 11:43:38 +00:00
Tobias Grosser 7639db8ed9 [IslNodeBuilder] Remove unused instruction
Suggested-by: Maximilian Falkenstein <falkensm@student.ethz.ch>
llvm-svn: 309533
2017-07-31 01:59:23 +00:00
Singapuram Sanjay Srivallabh cf9a813368 Remove Debug metadata from copied instruction to prevent Module verification failure
Summary:
**Remove debug metadata from instruction to be copied to prevent the source file's debug metadata being copied into GPUModule and eventually failing Module verification and ASM string codegeneration.**

When copying the instruction onto the Module meant for the GPU, debug metadata attached to an instruction causes all related metadata to be pulled into the Module, including the DICompileUnit, which is not listed in llvm.dbg.cu of the Module. This fails the verification of the Module and generation of the ASM string.

The only debug metadata of the instruction, the DebugLoc, is unset by this patch.

Reviewers: grosser, bollu, Meinersbur

Reviewed By: grosser, bollu

Subscribers: pollydev

Tags: #polly

Differential Revision: https://reviews.llvm.org/D35630

llvm-svn: 309490
2017-07-29 18:03:49 +00:00
Michael Kruse ce9617f4fe [Simplify] Implement write accesses coalescing.
Write coalescing combines write accesses that

- Write the same llvm::Value.
- Write to the same array.
- Unless they do not write anything in a statement instance (partial
  writes), write to the same element.
- There is no other access between them that accesses the same element.

This is particularly useful after DeLICM, which leaves partial writes to
disjoint domains.

Differential Revision: https://reviews.llvm.org/D36010

llvm-svn: 309489
2017-07-29 16:21:16 +00:00
Michael Kruse 4335c3992a [test] Add test case for -polly-simplify. NFC.
llvm-svn: 309458
2017-07-29 00:06:06 +00:00
Michael Kruse 8e41d2baab [Simplify] Do not remove dependencies of phis within region stmts.
These were wrongly assumed to be phi nodes that require
MemoryKind::PHI accesses.

llvm-svn: 309454
2017-07-28 23:22:32 +00:00
Michael Kruse fd7f40961b [VirtualInstruction] Do not iterate over a region statement's instruction list. NFC.
It should be empty anyways. In this case it would even be redundant
because we just all all instructions in region statements.

llvm-svn: 309453
2017-07-28 23:22:23 +00:00
Adrian Prantl 99c4a5fb8e Remove offset parameter from llvm.dbg.value intrinsics in testcase
llvm-svn: 309433
2017-07-28 21:08:53 +00:00
Michael Kruse 0137d80ad4 [VirtualInstruction] Remove assertion. NFC.
ScopStmt::contains is currently implemented on the basis of BasicBlock
and does not take the instruction list into account. Therefore any
instruction copied by -polly-optree into another statement currently
triggers that assertion.

Remove that assertion for now. We might re-enable it when the
implementation of ScopStmt::contains changes.

llvm-svn: 309421
2017-07-28 19:26:24 +00:00
Michael Kruse c99209b4b2 [test] Fix typo in filename. NFC.
llvm-svn: 309403
2017-07-28 16:57:56 +00:00
Michael Kruse 6c8f91b908 [Simplify] Fix typo in statistics output. NFC.
llvm-svn: 309402
2017-07-28 16:57:51 +00:00
Michael Kruse 34a77780c5 [Simplify] Remove empty partial accesses first. NFC.
So follow-up cleanup do not need special handling for such accesses.

llvm-svn: 309401
2017-07-28 16:57:45 +00:00
Siddharth Bhat 4ebeb3568a [PPCGCodeGeneration] Check that invariant load hoisting succeeded.
If we fail, throw an error for now. We can gracefully handle this later.

llvm-svn: 309387
2017-07-28 14:48:32 +00:00
Siddharth Bhat 0a1177b58e [ScopDetect] add `-polly-ignore-func` flag to ignore functions by name.
Ignore all functions whose name match a regex. Useful because creating a
regex that does *not* match a string is somewhat hard.

Example:
https://stackoverflow.com/questions/1240275/how-to-negate-specific-word-in-regex

llvm-svn: 309377
2017-07-28 11:47:24 +00:00
Tobias Grosser c0678c016f Add missing namespace comment
llvm-svn: 309373
2017-07-28 09:33:06 +00:00
Tobias Grosser 25271b91b2 [GPGPU] Do not require the Scop::Context to have information about all parameters
llvm-svn: 309368
2017-07-28 06:49:44 +00:00
Tobias Grosser 30caae6d23 [GPGPU] Fix compilation issue with latest CUDA upgrade to i128
llvm-svn: 309366
2017-07-28 06:38:49 +00:00
Hans Wennborg ce99589225 Tiny docs fix
llvm-svn: 309300
2017-07-27 18:14:00 +00:00
Tobias Grosser adcbee5433 Update isl to isl-0.18-800-g4018f45
This fixes a bug in isl_flow where triggering the compute out could result in
undefined or unexpected behavior. This fixes some recent regressions we saw
in the android buildbots. Thanks Eli Friedman for reducing the corresponding
test cases.

llvm-svn: 309274
2017-07-27 14:48:02 +00:00
Michael Kruse a508a4e619 [ScopBuilder/Simplify] Refactor isEscaping. NFC.
ScopBuilder and Simplify (through VirtualInstruction.cpp) previously
used this functionality in their own implementation. Refactor them
both into a common one into the Scop class.

BlockGenerator also makes use of a similiar functionality, but also
records outside users and takes place after region simplification.
Merging it as well would be more complicated.

llvm-svn: 309273
2017-07-27 14:39:52 +00:00
Michael Kruse 8a8aca4299 [Simplify] Count PHINodes in simplifiable exit nodes as escaping use.
After region exit simplification, the incoming block of a phi node in
the SCoP region's exit block lands outside of the region. Since we
treat SCoPs as if this already happened, we need to account for that
when looking for outside uses of scalars (i.e. escaping scalars).

llvm-svn: 309271
2017-07-27 14:09:31 +00:00
Michael Kruse eca86cee64 [ScopInfo] Never print instruction list of region stmts.
A region statement's instruction list is always empty and ignored by the code
generator. Don't give the impression that it means anything.

llvm-svn: 309197
2017-07-26 22:01:33 +00:00
Michael Kruse cedd7a74e1 [Simplify] Do not setInstructions() of region stmts. NFC.
The instruction list is ignored for region statements, there
is no reason to set it.

llvm-svn: 309196
2017-07-26 22:01:28 +00:00
Michael Kruse 95b39da8ae [Simplify] Fix invalid removal write for escaping values.
A PHI node's incoming block is the user of its operand, not the PHI's parent.

Assuming the PHINode's parent being the user lead to the removal of a
MemoryAccesses because its use was assumed to be inside of the SCoP.

llvm-svn: 309164
2017-07-26 19:58:15 +00:00
Roman Gareev 2e580538be [ScheduleOptimizer] Translate to C++ bindings
Translate the ScheduleOptimizer to use the new isl C++ bindings.

Reviewed-by: Michael Kruse <llvm@meinersbur.de>

Differential Revision: https://reviews.llvm.org/D35845

llvm-svn: 309119
2017-07-26 14:59:15 +00:00
Michael Kruse 1df1aac014 [ScopInfo] Avoid use of getStmtFor(BB). NFC.
Since there will be no more a 1:1 correspondence between statements and
basic blocks, we would like to get rid of the method getStmtFor(BB)
and its uses. Here we remove one of its uses in ScopInfo by fetching
the statement in which the call instruction lies.

Contributed-by: Nandini Singhal <cs15mtech01004@iith.ac.in>

Differential Revision: https://reviews.llvm.org/D35691

llvm-svn: 309110
2017-07-26 13:25:28 +00:00
Michael Kruse 11ed062258 [SCEVValidator] Loop exit values of loops before the SCoP are synthesizable.
In the following loop:

   int i;
   for (i = 0; i < func(); i+=1)
     ;
SCoP:
   for (int j = 0; j<n; j+=1)
     S(i, j)

The value i is synthesizable in the SCoP that includes only the j-loop.
This is because i is fixed within the SCoP, it is irrelevant whether
it originates from another loop.

This fixes a strange case where a PHI was synthesiable in a SCoP,
but not its incoming value, triggering an assertion.

This should fix MultiSource/Applications/sgefa/sgefa of the
perf-x86_64-penryn-O3-polly-before-vectorizer-unprofitable buildbot.

llvm-svn: 309109
2017-07-26 13:05:45 +00:00
Tobias Grosser 9ddcf8e6ac Revert accidental isl changes in 308923
It seems I still had some incomplete changes in the tree when committing.
In general, we only import changes from isl upstream. In this case, the
changes were especially unfortunate, as they broke the error management
in isl_flow.c and consequently caused regressions.

Thanks to Michael Kruse for spotting this mistake.

llvm-svn: 309039
2017-07-25 22:15:47 +00:00
Michael Kruse 8d89179e33 [ScopInfo] Rename ScopStmt::contains(BB) to represents(BB). NFC.
In future, there will be no more a 1:1 correspondence between statements
and basic blocks, the name `contains` does not correctly capture their
relationship. A BB may infact comprise of multiple statements; hence we
describe a statement 'representing' a basic block.

Differential Revision: https://reviews.llvm.org/D35838

llvm-svn: 308982
2017-07-25 16:25:37 +00:00
Philip Pfaffe 85cc5687df [IslAst] Untangle IslAst lit-testcases from specifics of the legacy-PM
Summary:
This consists instances of two changes:

- Accept any order of checks for a specific loop form, that appear in different order in the new vs legacy-PM.
- Remove checks for specific regions.

Reviewers: grosser

Reviewed By: grosser

Subscribers: pollydev, llvm-commits

Tags: #polly

Differential Revision: https://reviews.llvm.org/D35837

llvm-svn: 308976
2017-07-25 15:07:42 +00:00
Michael Kruse b6317007b4 [ScopInfo] Fix assertion for PHIs not in a region stmts entry.
A PHI node within a region statement is legal, but does not have
a MemoryKind::PHI access.

llvm-svn: 308973
2017-07-25 13:28:39 +00:00
Siddharth Bhat 43f178bbc9 [PPCGCodeGeneration] Skip arrays with empty extent.
Invariant load hoisted scalars, and arrays whose size we can statically compute
to be 0 do not need to be allocated as arrays.

Invariant load hoisted scalars are sent to the kernel directly as parameters.

Earlier, we used to allocate `0` bytes of memory for these because our
computation of size from `PPCGCodeGeneration::getArraySize` would result in `0`.

Now, since we don't invariant loads as arrays in PPCGCodeGeneration, this
problem does not occur anymore.

Differential Revision: https://reviews.llvm.org/D35795

llvm-svn: 308971
2017-07-25 12:35:36 +00:00
Tobias Grosser d7065e5df5 Move MemoryAccess::isStride* to isl++
llvm-svn: 308927
2017-07-24 20:50:22 +00:00
Tobias Grosser b739cb42f5 Move MemoryAccess::InvalidDomain to isl++
llvm-svn: 308923
2017-07-24 20:30:34 +00:00
Tobias Grosser cdf471baef Move MemoryAccess::getPwAff to isl++
llvm-svn: 308895
2017-07-24 16:36:34 +00:00
Tobias Grosser 1f6ba7e238 Move MemoryAccess::MemoryAccess to isl++
llvm-svn: 308893
2017-07-24 16:22:32 +00:00
Tobias Grosser 206e9e3b3b Move ScopArrayInfo::getFromAccessFunction and getFromId to isl++
llvm-svn: 308892
2017-07-24 16:22:27 +00:00
Michael Kruse 54071126d8 [ForwardOpTree] Properly indent enumeration in comment. NFC.
llvm-svn: 308887
2017-07-24 15:34:03 +00:00
Michael Kruse 67752076bc [ForwardOpTree] Rename FD_CanForward to FD_CanForwardLeaf. NFC.
To make the meaning and distinction to FD_CanForwardTree clearer.

llvm-svn: 308886
2017-07-24 15:33:58 +00:00
Michael Kruse d85e345ce0 [ForwardOpTree] Add comments to ForwardingDecision items. NFC.
In particular, explain the difference between FD_CanForward
and FD_CanForwardTree.

llvm-svn: 308885
2017-07-24 15:33:53 +00:00
Michael Kruse 07e8c36dc7 [ForwardOpTree] Support read-only value uses.
Read-only values (values defined before the SCoP) require special
handing with -polly-analyze-read-only-scalars=true (which is the
default). If active, each use of a value requires a read access.
When a copied value uses a read-only value, we must also ensure that
such a MemoryAccess is available or is created.

Differential Revision: https://reviews.llvm.org/D35764

llvm-svn: 308876
2017-07-24 12:43:27 +00:00
Siddharth Bhat e2699b572e [Polly] [NFC] [ScopDetection] Make `polly-only-func` perform regex scop name match.
Summary:

- We were using `.count` in `StringRef`, which matches substrings.
- We may want to use this for equality as well.
- Generalise this, so allow regexes as a parameter to `polly-only-func`.

Differential Revision: https://reviews.llvm.org/D35728

llvm-svn: 308875
2017-07-24 12:40:52 +00:00
Michael Kruse 5b8a9095e8 [ForwardOpTree] Fix mixup in comment. NFC.
The cases DoIt==false and DoIt==true were mixed up.

Thanks to Siddharth for noticing.

llvm-svn: 308874
2017-07-24 12:39:46 +00:00
Michael Kruse 25a688165b [ScopInfo] Fix typo in method name. NFC.
prependInstrunction -> prependInstruction

Thanks Nandini for noticing.

llvm-svn: 308873
2017-07-24 12:39:41 +00:00
Siddharth Bhat f7face4bc4 Convert GPUNodeBuilder::getArraySize to islcpp.
Note: PPCGCodeGeneration::pollyBuildAstExprForStmt is at
      https://reviews.llvm.org/D35770

Differential Revision: https://reviews.llvm.org/D35771

llvm-svn: 308870
2017-07-24 09:08:21 +00:00
Siddharth Bhat 35de900917 [NFC] Move PPCGCodeGeneration::pollyBuildAstExprForStmt to isl++.
Differential Revision: https://reviews.llvm.org/D35771

llvm-svn: 308869
2017-07-24 08:34:24 +00:00
Tobias Grosser 325812ac6d Simplify: Adopt for translation of MemoryAccess::getAccessRelation
For some reason this one was missed earlier.

llvm-svn: 308845
2017-07-23 08:15:28 +00:00
Tobias Grosser 1959dbda75 Move MemoryAccess::get*ArrayId to isl++
llvm-svn: 308843
2017-07-23 04:08:59 +00:00
Tobias Grosser 3b196131b5 Move applyScheduleToAccessRelation to isl++
llvm-svn: 308842
2017-07-23 04:08:52 +00:00
Tobias Grosser 6a87036e0f Move MemoryAccess::getAddressFunction to isl++
llvm-svn: 308841
2017-07-23 04:08:45 +00:00
Tobias Grosser 1515f6b937 Move MemoryAccess::NewAccessRelation to isl++
We also move related accessor functions

llvm-svn: 308840
2017-07-23 04:08:38 +00:00
Tobias Grosser 22da5f087a Move MemoryAccess::getOriginalAccessRelation to isl++
llvm-svn: 308839
2017-07-23 04:08:27 +00:00
Tobias Grosser 0c4c2eef75 Move MemoryAccess::AccessRelation to isl++
llvm-svn: 308838
2017-07-23 04:08:22 +00:00
Tobias Grosser b6e7a85a6d Move MemoryAccess::createBasicAccessMap to isl++
llvm-svn: 308837
2017-07-23 04:08:17 +00:00
Tobias Grosser fe46c3ff3a Move MemoryAccess::id to isl++
llvm-svn: 308836
2017-07-23 04:08:11 +00:00
Michael Kruse ab8f0d57df [Simplify] Remove partial write accesses with empty domain.
If the access relation's domain is empty, the access will never be
executed. We can just remove it.

We only remove write accesses. Partial read accesses are not yet
supported and instructions in the statement might require the
llvm::Value holding the read's result to be defined.

llvm-svn: 308830
2017-07-22 20:33:09 +00:00
Michael Kruse e52ebd1ae4 [ScopInfo] Adapt indentation of instruction list printing.
Change the indention of the last brace to align with the opening line.

Before:

            Instructions {
                  %val = fadd double %arg, 2.100000e+01
                  store double %val, double* %A
                }

After:

            Instructions {
                  %val = fadd double %arg, 2.100000e+01
                  store double %val, double* %A
            }

llvm-svn: 308828
2017-07-22 16:44:39 +00:00
Michael Kruse e5f4706a55 [ForwardOpTree] Support hoisted invariant loads.
Hoisted loads can be trivially supported because there are no
MemoryAccess to be modified, the loaded value is just available
at code generation.

llvm-svn: 308826
2017-07-22 14:30:02 +00:00
Michael Kruse a6b2de3b59 [ForwardOpTree] Introduce the -polly-optree pass.
This pass 'forwards' operand trees into statements that use them in
order to avoid scalar dependencies.

This minimal implementation handles only the case of speculatable
instructions. We will successively add support for:
- Hoisted loads
- Read-only values
- Synthesizable values
- Loads
- PHIs
- Forwarding only parts of the tree

Differential Revision: https://reviews.llvm.org/D35754

llvm-svn: 308825
2017-07-22 14:02:47 +00:00
Tobias Grosser 77eef90f50 Move ScopArrayInfo to isl++
This moves the full ScopArrayInfo class to isl++

llvm-svn: 308801
2017-07-21 23:07:56 +00:00
Philip Pfaffe 8f6c48e2aa Untangle ScopInfo lit-testcases from specifics of the legacy-PM
Summary:
For the ScopInfo lit testsuite, this patch removes some dependences on output behaviour of the legacy PM.

In most cases, these tests checked the tool output for labels created by the pass printer in the legacy PM. This doesn't work for the new PM anymore. Untangling the testcases is the first step to porting the testsuite for the new PM infrastructure.

Reviewers: grosser, Meinersbur, bollu

Reviewed By: grosser

Subscribers: llvm-commits, pollydev

Tags: #polly

Differential Revision: https://reviews.llvm.org/D35727

llvm-svn: 308754
2017-07-21 16:47:36 +00:00
Philipp Schaad 2f3073b5cb [Polly][GPGPU] Added SPIR Code Generation and Corresponding Runtime Support for Intel
Summary:
Added SPIR Code Generation to the PPCG Code Generator. This can be invoked using
the polly-gpu-arch flag value 'spir32' or 'spir64' for 32 and 64 bit code respectively.
In addition to that, runtime support has been added to execute said SPIR code on Intel
GPU's, where the system is equipped with Intel's open source driver Beignet (development
version). This requires the cmake flag 'USE_INTEL_OCL' to be turned on, and the polly-gpu-runtime
flag value to be 'libopencl'.
The transformation of LLVM IR to SPIR is currently quite a hack, consisting in part of regex
string transformations.
Has been tested (working) with Polybench 3.2 on an Intel i7-5500U (integrated graphics chip).

Reviewers: bollu, grosser, Meinersbur, singam-sanjay

Reviewed By: grosser, singam-sanjay

Subscribers: pollydev, nemanjai, mgorny, Anastasia, kbarton

Tags: #polly

Differential Revision: https://reviews.llvm.org/D35185

llvm-svn: 308751
2017-07-21 16:11:06 +00:00
Michael Kruse e186013149 Annotate dump() functions with LLVM_DUMP_METHOD. NFC.
llvm-svn: 308749
2017-07-21 15:54:13 +00:00
Michael Kruse 5d5184698d [ScopInfo] Don't compile dump() functions into non-assert builds. NFC.
This follows a convention used in LLVM.

llvm-svn: 308748
2017-07-21 15:54:07 +00:00
Michael Kruse cd4c977b8b [ScopInfo] Print instructions in dump().
Print a statement's instruction on dump() regardless of
-polly-print-instructions. dump() is supposed to be used in the debugger
only and never in regression tests. While debugging, get all the
information we have and we are not bound to break anything. For non-dump
purposes of print, forward the setting of -polly-print-instructions as
parameters.

Some calls to print() had to be changed because the
PollyPrintInstructions setting is only available in ScopInfo.cpp.
In ScheduleOptimizer.cpp, dump() was used in regression tests.
That's not what dump() is for.

The print parameter "PrintInstructions" will also be useful for an
explicit print SCoP pass in a future patch.

llvm-svn: 308746
2017-07-21 15:35:53 +00:00
Siddharth Bhat 06d4ed6787 [NFC] [RegisterPasses] Fix typo: To early -> too early.
llvm-svn: 308743
2017-07-21 15:12:03 +00:00
Siddharth Bhat a0fb8b23e1 [NFC] [PPCGCodeGeneration] Print `verifyModule` failure to debug stream.
If verifyModule fails, it is helpful to know why it failed. Add a log to
the debug stream that prints the failure.

llvm-svn: 308727
2017-07-21 11:21:44 +00:00
Tobias Grosser 018103d34e Fix typo in function name Bllock -> Block
llvm-svn: 308715
2017-07-21 06:00:38 +00:00
Tobias Grosser 1eeedf4829 [IslNodeBuilder] Relax complexity check in invariant loads and run it early
When performing invariant load hoisting we check that invariant load expressions
are not too complex. Up to this commit, we performed this check by counting the
sum of dimensions in the access range as a very simple heuristic. This heuristic
is a little too conservative, as it prevents hoisting for any scops with a
very large number of parameters. Hence, we update the heuristic to only count
existentially quantified dimensions and set dimensions. We expect this to still
detect the problematic expressions in h264 because of which this check was
originally introduced.

For some unknown reason, this complexity check was originally committed in
IslNodeBuilder. It really belongs in ScopInfo, as there is no point in
optimizing a program which we could have known earlier cannot be code generated.
The benefit of running the check early is that we can avoid to even hoist checks
that are expensive to code generate as invariant loads. This can be seen in
the changed tests, where we now indeed detect the scop, but just not invariant
load hoist the complicated access.

We also improve the formatting of the code, document it, and use isl++ to
simplify expressions.

llvm-svn: 308659
2017-07-20 19:55:19 +00:00
Tobias Grosser 54491db687 Support fabs and copysign in Polly-ACC
llvm-svn: 308649
2017-07-20 18:26:34 +00:00
Michael Kruse b936c4b332 [PPCG] Compile fix for MSVC.
Visual Studio, even the 2017 version, does not support C99 VLAs.

For VLA paramters, the length of the outermost dimension is not
required anyway, so remove it.

llvm-svn: 308643
2017-07-20 18:04:54 +00:00
Michael Kruse 1ce6791e7e [ScopInfo] Get a list of statements for a region node. NFC.
When constructing a schedule true and there are multiple statements for
a basic block, create a sequence node for these statements.

Contributed-by: Nandini Singhal <cs15mtech01004@iith.ac.in>

Differential Revision: https://reviews.llvm.org/D35679

llvm-svn: 308635
2017-07-20 17:18:58 +00:00
Michael Kruse 6eba4b1031 [ScopInfo] Remove dependency of Scop::getLastStmtFor(BB) on getStmtFor(BB). NFC.
We are working towards removing uses of Scop::getStmtFor(BB). In this
patch, we remove dependency of Scop::getLastStmtFor(BB) on
getStmtFor(BB). To do so, we get the list of all statements
corresponding to the BB and then fetch the last one.

Contributed-by: Nandini Singhal <cs15mtech01004@iith.ac.in>

Differential Revision: https://reviews.llvm.org/D35665

llvm-svn: 308633
2017-07-20 17:08:50 +00:00
Michael Kruse c4d8f9b11a Fix indention in comment. NFC.
llvm-svn: 308632
2017-07-20 16:52:22 +00:00
Michael Kruse 3562f272cf [ScopInfo] Use map for lookupPHIReadOf. NFC.
Introduce previously missing PHIReads analogous the the already existing
PHIWrites/ValueWrites/ValueReads maps. PHIReads was initially not
required and the later introduced lookupPHIReadOf() used a linear
search instead.

With PHIReads, lookupPHIReadOf() can now also do a map lookup and remove
any surprising performance/behaviour differences to lookupPHIWriteOf(),
lookupValueWriteOf() and lookupValueReadOf().

llvm-svn: 308630
2017-07-20 16:47:57 +00:00
Michael Kruse 22058c3fbb [Simplify] Remove unused instructions and accesses.
Use a mark-and-sweep algorithm to find and remove unused instructions
and MemoryAccesses. This is useful in particular to remove scalar
writes that are never used anywhere. A scalar write in a loop induces
a write-after-write dependency that stops the loop iterations to be
rescheduled. Such writes can be a result of previous transformations
such as DeLICM and operand tree forwarding.

It adds a new class VirtualInstruction that represents an instruction in
a particular statement. At the moment an instruction can only belong to
the statement that represents a BasicBlock. In the future, instructions
can be in one of multiple statements representing a BasicBlock
(Nandini's work), in different statements than its BasicBlock would
indicate, and even multiple statements at once (by forwarding operand
trees). It also integrates nicely with the VirtualUse class.

ScopStmt::contains(Instruction*) currently uses the instruction's parent
BasicBlock to check whether it contains the instruction. It will need to
check the actual statement list when one of the aforementioned features
become possible.

Differential Revision: https://reviews.llvm.org/D35656

llvm-svn: 308626
2017-07-20 16:21:55 +00:00
Siddharth Bhat 9e3db2b756 [PPCGCodeGen] [3/3] Update PPCGCodeGen + tests to latest ppcg.
This commit *WILL COMPILE*.

1. `PPCG` now uses `isl_multi_pw_aff` instead of an array of `pw_aff`.
   This needs us to adjust how we index array bounds and how we construct
   array bounds.

2. `PPCG` introduces two new kinds of nodes: `init_device` and `clear_device`.
   We should investigate what the correct way to handle these are.

3. `PPCG` has gotten smarter with its use of live range reordering, so some of
   the tests have a qualitative improvement.

4. `PPCG` changed its output style, so many test cases need to be updated to
   fit the new style for `polly-acc-dump-code` checks.

Differential Revision: https://reviews.llvm.org/D35677

llvm-svn: 308625
2017-07-20 15:48:36 +00:00