Commit Graph

2043 Commits

Author SHA1 Message Date
Johannes Doerfert 757a32b5b3 [FIX] Approximate non-affine loops correctly
Before isValidCFG() could hide the fact that a loop is non-affine by
  over-approximation. This is problematic if a subregion of the loop contains
  an exit/latch block and is over-approximated. Now we do not over-approximate
  in the isValidCFG function if we check loop control.  If such control is
  non-affine the whole loop is over-approximated, not only a subregion.

llvm-svn: 249273
2015-10-04 14:54:27 +00:00
Johannes Doerfert 30ffb6fcb6 [FIX] Check loop latches for valid control too.
This patch cannot be tested on its own as the isValidCFG currently
  hides the fact that control is actually non-affine with
  over-approximation. This will be corrected in the next patch and a
  test for non-affine latches will be added.

llvm-svn: 249272
2015-10-04 14:53:18 +00:00
Johannes Doerfert 8dba07770f [NFC] Remove unused classes
llvm-svn: 249271
2015-10-04 14:52:43 +00:00
Tobias Grosser d78616f98a Make ScopAnnotator a function-local variable to ensure it is freed at each run
When the ScopAnnotator was a class member variable some of the maps it contains
have not been properly cleared. As a result we had dangling pointers to
llvm::Value(s) which got detected by the AssertingVH we recently added.

No test case as this issue is hard to reproduce reliably as subsequent
optimizations need to delete some of the llvm::Values we still keep in our
lists.

llvm-svn: 249269
2015-10-04 11:19:13 +00:00
Tobias Grosser ecdfae6b15 IRBuilder: Use AssertingVH
llvm-svn: 249268
2015-10-04 10:18:56 +00:00
Tobias Grosser 5762b31df4 Use AssertingVH for ValueToValue Maps
By using AssertingVH we will see assertions in case Values to which still
pointers in our maps exists are deleted. This is very useful as we previously
had some bugs that were caused by such stale Value pointers.

llvm-svn: 249267
2015-10-04 10:18:49 +00:00
Tobias Grosser 2f1acac610 BlockGenerator: Use plain Value * instead of const Value *
The use of const qualified Value pointers prevents the use of AssertingVH. We
could probably think of adding const support to AssertingVH, but as const
correctness seems to currently provide limited benefit in Polly, we do not do
this yet.

llvm-svn: 249266
2015-10-04 10:18:45 +00:00
Tobias Grosser 9646e3fe4b BlockGenerators: Use auto to be less sensitive to type changes
llvm-svn: 249265
2015-10-04 10:18:39 +00:00
Tobias Grosser f4bb7a6a4d Consolidate the different ValueMapTypes we are using
There have been various places where llvm::DenseMap<const llvm::Value *,
llvm::Value *> types have been defined, but all types have been expected to be
identical. We make this more clear by consolidating the different types and use
BlockGenerator::ValueMapT wherever there is a need for types to match
BlockGenerator::ValueMapT.

llvm-svn: 249264
2015-10-04 10:18:32 +00:00
Tobias Grosser 1d45c6dadd IslExprBuilder: Use AssertingVH for IdToValueTy
llvm-svn: 249239
2015-10-03 17:20:00 +00:00
Tobias Grosser b28ee0fbb0 ScopInfo: Use AssertingVH in maps
By using asserting value handles, we will get assertions when we forget to clear
any of the Value maps instead of difficult to debug undefined behavior.

llvm-svn: 249238
2015-10-03 17:19:53 +00:00
Tobias Grosser e9cb5a0983 BlockGenerator: Use AssertingVH in maps
By using asserting value handles, we will get assertions when we forget to clear
any of the Value maps instead of difficult to debug undefined behavior.

llvm-svn: 249237
2015-10-03 17:19:49 +00:00
Michael Kruse afe0670863 Bail-out early if all statements have been simplified away
Treat the scop as invalid instead of creating dummy domains.

llvm-svn: 249151
2015-10-02 16:33:27 +00:00
Johannes Doerfert 3e7d171866 [FIX] Repair broken commit
The last invariant load fix was based on a later patch not
  polly/master, thus needs to be adjusted.

llvm-svn: 249145
2015-10-02 15:35:03 +00:00
Johannes Doerfert 8930f4846c [FIX] Do not hoist from inside a non-affine subregion
We have to skip accesses in non-affine subregions during hoisting as
  they might not be executed under the same condition as the entry of
  the non-affine subregion.

llvm-svn: 249139
2015-10-02 14:51:00 +00:00
Michael Kruse cac948ef46 Earlier creation of ScopStmt objects
This moves the construction of ScopStmt to the beginning of the 
ScopInfo pass. The late creation was a result of the earlier separation 
of ScopInfo and TempScopInfo. This will avoid introducing more 
ScopStmt-like maps in future commits. The AccFuncMap will also be 
removed in some future commit. DomainMap might also be included into 
ScopStmt.

The order in which ScopStmt are created changes and initially creates 
empty statements that are removed in a simplification.

Differential Revision: http://reviews.llvm.org/D13341

llvm-svn: 249132
2015-10-02 13:53:07 +00:00
Johannes Doerfert 911951f4f8 Hand down referenced & globally mapped values to the subfunction
If a value is globally mapped (IslNodeBuilder::ValueMap) and
  referenced in the code that will be put into a subfunction, we hand
  down the new value to the subfunction.

  This patch also removes code that handed down all invariant loads to
  the subfunction. Instead, only needed invariant loads are given to the
  subfunction. There are two possible reasons for an invariant load to
  be handed down:
    1) The invariant load is used in a block that is placed in the
       subfunction but which is not the parent of the load. In this
       case, the scalar access that will read the loaded value, will
       cause its base pointer (the preloaded value) to be handed down to
       the subfunction.
    2) The invariant load is defined and used in a block that is placed
       in the subfunction. With this patch we will hand down the
       preloaded value to the subfunction as the invariant load is
       globally mapped to that value.

llvm-svn: 249126
2015-10-02 13:11:27 +00:00
Johannes Doerfert 478a7de18b [NFC] Make the ScopDetection analysis a member of the Scop class
llvm-svn: 249125
2015-10-02 13:09:31 +00:00
Johannes Doerfert f56738041e Make the SCoP generation resistent wrt. error blocks
When error blocks are not terminated by an unreachable they have successors
  that might only be reachable via error blocks. Additionally, branches in
  error blocks are not checked during SCoP detection, thus we might not be able
  to handle them. With this patch we do not try to model error block exit
  conditions. Anything that is only reachable via error blocks is ignored too,
  as it will not be executed in the optimized version of the SCoP anyway.

llvm-svn: 249099
2015-10-01 23:48:18 +00:00
Johannes Doerfert f80f3b0449 Allow user defined error functions
The user can provide function names with
    -polly-error-functions=name1,name2,name3
  that will be treated as error functions. Any call to them is assumed
  not to be executed.

  This feature is mainly for developers to play around with the new
  "error block" feature.

llvm-svn: 249098
2015-10-01 23:45:51 +00:00
Johannes Doerfert 850d346302 [FIX] Parallel codegen for invariant loads
Hand down all preloaded values to the parallel subfunction.

llvm-svn: 249010
2015-10-01 13:40:36 +00:00
Johannes Doerfert e46925f324 [FIX] Erase stall results during the SCoP detection
With this patch we erase cached results for regions that are invalid
  as early as possible. If we do not (as before), it is possible that
  two expanded regions will have the same address and the tracked
  results for both are mixed. Currently this would "only" cause
  pessimism in later passes but that will change when we allow invariant
  loads in the SCoP.  Additionally, it triggers non-deterministic
  results as we might dismiss a later region because of results cached
  for an earlier one.

  There is no test case as the problem occurs only non-deterministically.

llvm-svn: 249000
2015-10-01 10:59:14 +00:00
Johannes Doerfert 47128f3af7 [FIX] Reintroduce an include needed to locally compile Polly
llvm-svn: 248947
2015-09-30 21:19:44 +00:00
Johannes Doerfert 59984322c3 [FIX] Handle identity mappings in the ScopExpander
If the VMap in the ScopExpander contains identity mappings
  we now ignore the mapping.

Reported-by: Tobias Grosser <tobias@grosser.es>
llvm-svn: 248946
2015-09-30 21:12:12 +00:00
Tobias Grosser fd9d07eac1 Drop unneeded includes
llvm-svn: 248937
2015-09-30 20:20:42 +00:00
Johannes Doerfert bb9387444c [FIX] Remove unknown variable
llvm-svn: 248926
2015-09-30 17:31:31 +00:00
Johannes Doerfert c0729a3216 Move remapping functionality in the ScopExpander
Because we handle more than SCEV does it is not possible to rewrite an
  expression on the top-level using the SCEVParameterRewriter only. With
  this patch we will do the rewriting on demand only and also
  recursively, thus not only on the top-level.

llvm-svn: 248916
2015-09-30 16:52:03 +00:00
Johannes Doerfert 6206d7a67c [FIX] Clear all maps between runs
llvm-svn: 248915
2015-09-30 16:51:05 +00:00
Tobias Grosser aff56c8a78 Reapply "BlockGenerator: Generate synthesisable instructions only on-demand"
Instructions which we can synthesis from a SCEV expression are not
generated directly, but only when they are used as an operand of
another instruction. This avoids generating unnecessary instructions
and works more reliably than first inserting them and then deleting
them later on.

This commit was reverted in r248860 due to a remaining miscompile, where
we forgot to synthesis the operand values that were referenced from scalar
writes. test/Isl/CodeGen/scalar-store-from-same-bb.ll tests that we do this
now correctly.

llvm-svn: 248900
2015-09-30 13:36:54 +00:00
Tobias Grosser 33cb9f9419 BlockGenerator: Extract value synthesis into its own function [NFC]
This will allow us to reuse this code in a subsequent commit.

llvm-svn: 248893
2015-09-30 11:56:19 +00:00
Johannes Doerfert ebfd72493c [NFC] Extract materialization of parameters
llvm-svn: 248882
2015-09-30 09:52:08 +00:00
Johannes Doerfert ef19ead20e [FIX] Use escape logic for invariant loads
Before we unconditinoally forced all users outside the SCoP to use
  the preloaded value. However, if the SCoP is not executed due to the
  runtime checks, we need to use the original value because it might not
  be invariant in the first place.

llvm-svn: 248881
2015-09-30 09:43:20 +00:00
Michael Kruse 76e924d31b Assign scop directly
This makes ScopInfo's scop member available earlier to other methods which will make some planned changes simpler.

No behavioral change intended

llvm-svn: 248879
2015-09-30 09:16:07 +00:00
Johannes Doerfert c1db67e218 Identify and hoist definitively invariant loads
As a first step in the direction of assumed invariant loads (loads
  that are not written in some context) we now detect and hoist
  definitively invariant loads. These invariant loads will be preloaded
  in the code generation and used in the optimized version of the SCoP.
  If the load is only conditionally executed the preloaded version will
  also only be executed under the same condition, hence we will never
  access memory that wouldn't have been accessed otherwise. This is also
  the most distinguishing feature to licm.

  As hoisting can make statements empty we will simplify the SCoP and
  remove empty statements that would otherwise cause artifacts in the
  code generation.

Differential Revision: http://reviews.llvm.org/D13194

llvm-svn: 248861
2015-09-29 23:47:21 +00:00
Johannes Doerfert f6343d74ef Revert "BlockGenerator: Generate synthesisable instructions only on-demand"
This reverts commit 07830c18d789ee72812d5b5b9b4f8ce72ebd4207.

  The commit broke at least one test in lnt,
    MultiSource/Benchmarks/Ptrdist/bc/number.c
  was miss compiled and the test produced a wrong result.

  One Polly test case that was added later was adjusted too.

llvm-svn: 248860
2015-09-29 23:43:40 +00:00
Tobias Grosser 81f005617e Replace default destructors by {} destructors
Hope this fixes the buildbots for now.

llvm-svn: 248823
2015-09-29 19:52:09 +00:00
Tobias Grosser 7dce3a60f2 Add default region generator
This hopefully helps to to address the following compile error on our buildbots

BlockGenerators.h:683:7: error: looser throw specifier for ‘virtual
polly::RegionGenerator::~RegionGenerator()’
BlockGenerators.h:164:11: error:   overriding ‘virtual polly::BlockGenerator::~BlockGenerator() noexcept
(true)`

llvm-svn: 248812
2015-09-29 18:07:17 +00:00
Tobias Grosser 98b3ee50ff Codegen: Support memory accesses with different types
Every once in a while we see code that accesses memory with different types,
e.g. to perform operations on a piece of memory using type 'float', but to copy
data to this memory using type 'int'. Modeled in C, such codes look like:

    void foo(float A[], float B[]) {
      for (long i = 0; i < 100; i++)
        *(int *)(&A[i]) = *(int *)(&B[i]);
      for (long i = 0; i < 100; i++)
        A[i] += 10;
    }

We already used the correct types during normal operations, but fall back to our
detected type as soon as we import changed memory access functions. For these
memory accesses we may generate invalid IR due to a mismatch between the element
type of the array we detect and the actual type used in the memory access.  To
address this issue, we always cast the newly created address of a memory access
back to the type of the memory access where the address will be used.

llvm-svn: 248781
2015-09-29 06:44:38 +00:00
David Blaikie 6163f67ad0 Remove unnecessary default dtor. The base dtor is already virtual and the derived dtor adds nothing.
llvm-svn: 248765
2015-09-29 00:12:50 +00:00
David Blaikie 8e9ea2a439 Make Polly -Wdeprecated clean by explicitly making BlockGenerator copy constructible
This is a bit of an awkward API and I'm not sure what the right solution
is. Having a publicly copy constructible base class makes it easy to
accidentally slice derived objects in a number of contexts.

llvm-svn: 248764
2015-09-29 00:00:29 +00:00
Tobias Grosser 95e59aaa54 OpenMP: Name addresses in subfunction structure
While debugging, this makes it easier to understand due to which memory
reference these stores have been introduced.

llvm-svn: 248717
2015-09-28 16:46:38 +00:00
Tobias Grosser 28b9a14b07 BlockGenerator: Generate synthesisable instructions only on-demand
Instructions which we can synthesis from a SCEV expression are not generated
directly, but only when they are used as an operand of another instruction. This
avoids generating unnecessary instruction and works more reliably than first
inserting them and then deleting them later on.

Suggested-by: Johannes Doerfert <doerfert@cs.uni-saarland.de>

Differential Revision: http://reviews.llvm.org/D13208

llvm-svn: 248712
2015-09-28 13:47:50 +00:00
Michael Kruse 5c0f97d537 Improve comments related to MemoryAccess::MemoryOrigin; NFC
llvm-svn: 248705
2015-09-28 10:06:50 +00:00
Johannes Doerfert 58a7c75c86 [NFC] Add accidentally removed comment line
llvm-svn: 248704
2015-09-28 09:48:53 +00:00
Johannes Doerfert 9a132f36c3 Allow switch instructions in SCoPs
This patch allows switch instructions with affine conditions in the
  SCoP. Also switch instructions in non-affine subregions are allowed.
  Both did not require much changes to the code, though there was some
  refactoring needed to integrate them without code duplication.

  In the llvm-test suite the number of profitable SCoPs increased from
  135 to 139 but more importantly we can handle more benchmarks and user
  inputs without preprocessing.

Differential Revision: http://reviews.llvm.org/D13200

llvm-svn: 248701
2015-09-28 09:33:22 +00:00
Tobias Grosser f223cdf17e [tests] Add memory writes to make this scop not trivially empty
llvm-svn: 248697
2015-09-28 07:37:06 +00:00
Johannes Doerfert f32f5f2305 Remove obsolete check
This check was needed at some point but seems not useful anymore. Only
  one adjustment in the domain generation was needed to cope with the
  cases this check prevented from happening before.

llvm-svn: 248695
2015-09-28 01:30:37 +00:00
Johannes Doerfert 91ad092bb2 [NFC] Remove unused SCoP diagnostic
llvm-svn: 248694
2015-09-28 01:29:44 +00:00
Tobias Grosser 0722a1e5d5 BlockGenerator: Be less agressive with deleting dead instructions
We now only delete trivially dead instructions in the BB we copy (copyBB), but
not in any other BB.  Only for copyBB we know that there will _never_ be any
future uses of instructions that have no use after copyBB has been generated.
Other instructions in the AST that have been generated by IslNodeBuilder may
look dead at the moment, but may possibly still be referenced by GlobalMaps. If
we delete them now, later uses would break surprisingly.

We do not have a test case that breaks due to us deleting too many instructions.
This issue was found by inspection.

llvm-svn: 248688
2015-09-27 19:50:16 +00:00
Tobias Grosser a43b6e935c Drop unused variable
llvm-svn: 248687
2015-09-27 17:54:50 +00:00
Johannes Doerfert 45be64464b [NFC] Consistenly use commented and annotated ScopPass functions
The changes affect methods that are part of the Pass interface and
  include:
    - Comments that describe the methods purpose.
    - A consistent use of the keywords override and virtual.
  Additionally, the printScop method is now optional and removed from
  SCoP passes that do not implement it.

llvm-svn: 248685
2015-09-27 15:43:29 +00:00
Johannes Doerfert 0f37630849 [NFC] Use releaseMemory to release internal memory
llvm-svn: 248684
2015-09-27 15:42:28 +00:00
Tobias Grosser 0ff79e586d BlockGenerator: Simplify code generated for region statements
After having generated a new user statement a couple of inefficient or
trivially dead instructions may remain. This commit runs instruction
simplification over the newly generated blocks to ensure unneeded
instructions are removed right away.

This commit does adds simplification for non-affine subregions which was not
yet part of 248681.

llvm-svn: 248683
2015-09-27 11:35:00 +00:00
Tobias Grosser 412f9774f8 [CodeGen test] Replace undef values with some defined constants
Otherwise, part of the computation will be just simplified away when we add
instruction simplification support to the RegionGenerator.

llvm-svn: 248682
2015-09-27 11:34:53 +00:00
Tobias Grosser 1b9d25a42d BlockGenerator: Simplify code generated for scop statements
After having generated a new user statement a couple of inefficient or trivially
dead instructions may remain. This commit runs instruction simplification over
the newly generated blocks to ensure unneeded instructions are removed right
away.

This commit does not yet add simplification for non-affine subregions.

llvm-svn: 248681
2015-09-27 11:17:22 +00:00
Johannes Doerfert 284e67828f [NFC] Remove obsolete member
llvm-svn: 248675
2015-09-26 20:58:29 +00:00
Johannes Doerfert fb19dd694c Create parallel code in a separate block
This commit basically reverts r246427 but still solves the issue
  tackled by that commit. Instead of emitting initialization code in the
  beginning of the start block we now generate parallel code in its own
  block and thereby guarantee separation. This is necessary as we cannot
  generate code for hoisted loads prior to the start block but it still
  needs to be placed prior to everything else.

llvm-svn: 248674
2015-09-26 20:57:59 +00:00
Michael Kruse caac2b6930 Fix typo
llvm-svn: 248670
2015-09-26 15:51:44 +00:00
Tobias Grosser 06c495c2b0 Add test case from llvm.org/PR17187
The new domain construction algorithm now correctly models this test case (and
derives an empty run-time condition). Add this test case to ensure we do not
regress.

llvm-svn: 248669
2015-09-26 14:27:54 +00:00
Johannes Doerfert 12155a9ef4 Add test case from open bug
The bug (15771) was fixed already with the new domain generation
  but the test case was not added till now.

llvm-svn: 248668
2015-09-26 14:03:29 +00:00
Johannes Doerfert c6987c18de [FIX] Use the surrounding loop for non-affine SCoP regions
When the whole SCoP is a non-affine region we need to use the
  surrounding loop in the construction of the schedule as that is
  the one that will be looked up after the schedule generation.

  This fixes bug 24947

llvm-svn: 248667
2015-09-26 13:41:43 +00:00
Tobias Grosser bbda083c75 Add test case for delinearization through bitcasts
This was forgotten in r247928

llvm-svn: 248663
2015-09-26 08:55:59 +00:00
Tobias Grosser 99c70dd8d1 Ensure memory accesses to the same array have identical dimensionality
When recovering multi-dimensional memory accesses, it may happen that different
accesses to the same base array are recovered with different dimensionality.
This patch ensures that the dimensionalities are unified by adding zero valued
dimensions to acesses with lower dimensionality. When starting to model
fixed-size arrays as multi-dimensional in 247906, this has not been taken
care of.

llvm-svn: 248662
2015-09-26 08:55:54 +00:00
Michael Kruse 8d0b734e71 Let MemoryAccess remember its purpose
There are three possible reasons to add a memory memory access: For explicit load and stores, for llvm::Value defs/uses, and to emulate PHI nodes (the latter two called implicit accesses). Previously MemoryAccess only stored IsPHI. Register accesses could be identified through the isScalar() method if it was no IsPHI. isScalar() determined the number of dimensions of the underlaying array, scalars represented by zero dimensions.

For the work on de-LICM, implicit accesses can have more than zero dimensions, making the distinction of isScalars() useless, hence now stored explicitly in the MemoryAccess. Instead, we replace it by isImplicit() and avoid the term scalar for zero-dimensional arrays as it might be confused with llvm::Value which are also often referred to as scalars (or alternatively, as registers).

No behavioral change intended, under the condition that it was impossible to create explicit accesses to zero-dimensional "arrays".

llvm-svn: 248616
2015-09-25 21:21:00 +00:00
Michael Kruse 33d6c0bbc5 Use per-Purpose overloads for MemoryAccess creation
This makes the intent of each created object clearer and allows to add more specific asserts. The bug fixed in r248535 has been discovered this way.

No functional change intended; everything should behave as before.

llvm-svn: 248603
2015-09-25 18:53:27 +00:00
Tobias Grosser c90ed44b31 [cmake] terminate isl/stdint.h with a newline
This avoids warnings of the form:
  stdint.h:1:20: warning: no newline at end of file [-Wnewline-eof]

llvm-svn: 248570
2015-09-25 11:45:26 +00:00
Tobias Grosser c2bb0cbe00 Sort includes using Chandler's sort_includes.py script
llvm-svn: 248568
2015-09-25 09:49:19 +00:00
Tobias Grosser 8016f3a4f5 Add missing PHI to test case
llvm-svn: 248563
2015-09-25 05:41:30 +00:00
Tobias Grosser da95a4a7c7 Handle read-only scalars used in PHI-nodes correctly
This change addresses three issues:

  - Read only scalars that enter a PHI node through an edge that comes from
    outside the scop are not modeled any more, as such PHI nodes will always
    be initialized to this initial value right before the SCoP is entered.
  - For PHI nodes that depend on a scalar value that is defined outside the
    scop, but where the scalar values is passed through an edge that itself
    comes from a BB that is part of the region, we introduce in this basic
    block a read of the out-of-scop value to ensure it's value is available
    to write it into the PHI alloc location.
  - Read only uses of scalars by PHI nodes are ignored in the general read only
    handling code, as they are taken care of by the general PHI node modeling
    code.

llvm-svn: 248535
2015-09-24 20:59:59 +00:00
Michael Kruse 26ed65e00d Fix comparison signed/unsigned mismatch warning; NFC
llvm-svn: 248520
2015-09-24 17:32:49 +00:00
Tobias Grosser 2553ebc79d Mark a couple of issues as done
llvm-svn: 248492
2015-09-24 14:30:14 +00:00
Michael Kruse b280ded108 Rename Polly_isl to PollyISL
Library names in the LLVM framework usually do not contain underscores.

llvm-svn: 248487
2015-09-24 12:38:49 +00:00
Michael Kruse 2d0ece960f Remove Analysis Output of TempScopInfo
After the merge of TempScopInfo into ScopInfo the analysis output 
remained because of the existing unit tests. These remains are removed 
and the units tests converted to match the equivalent output of 
ScopInfo's analysis output. The unit tests are also moved into the
directory of ScopInfo tests.

Differential Revision: http://reviews.llvm.org/D13116

llvm-svn: 248485
2015-09-24 11:41:21 +00:00
Michael Kruse 519b3cfd27 Compile ISL into its own library
Refactor all ISL-related cmake build instructions into its own 
CMakeLists.txt and build as a separate library.

This is useful to apply ISL-related build flags to ISL only and not to 
Polly's files. Also, it the separation of both projects becomes clearer.

Proposed name of the library is Polly_isl. It is not "isl" to avoid 
mix-up with potentially installed libisl.{a|so}.

Tested configurations:
- Windows with cmake 3.2
- Ubuntu with cmake 3.0.2 
- Ubuntu with cmake 3.0.2  BUILD_SHARED_LIBS on
- Ubuntu with cmake 2.8.12.2 (LLVM minimum version)
- Ubuntu out-of-LLVM-tree

Differential Revision: http://reviews.llvm.org/D12810

llvm-svn: 248484
2015-09-24 11:30:22 +00:00
Johannes Doerfert e526de5a47 Make MIN_LOOP_TRIP_COUNT a static constant
llvm-svn: 248192
2015-09-21 19:10:11 +00:00
Tobias Grosser b1c39429d9 Do not model delinearized and linearized access relation for a single access
A missing return statement that previously did not have a visibly negative
effect caused after some data-structure changes in r248024 multi-dimensional
accesses to be modeled both multi-dimensional as well as linearized. This
commit adds the missing return to avoid the incorrect double modeling as
well as the compile time increases it caused.

llvm-svn: 248171
2015-09-21 16:19:25 +00:00
Johannes Doerfert 6a72a2af13 Use <nsw> AddRecs in the affinator to avoid bounded assumptions
If we encounter a <nsw> tagged AddRec for a loop we know the trip count of
  that loop has to be bounded or the semantics is undefined anyway. Hence, we
  only need to add unbounded assumptions if no such AddRec is known.

llvm-svn: 248128
2015-09-20 16:59:23 +00:00
Johannes Doerfert 707a406078 Add bounded loop assumption
So far we ignored the unbounded parts of the iteration domain, however
  we need to assume they do not occure at all to remain sound if they do.

llvm-svn: 248126
2015-09-20 16:38:19 +00:00
Johannes Doerfert f2cc86edae Simplify domain generation
We now add loop carried information during the second traversal of the
  region instead of in a intermediate step in-between. This makes the
  generation simpler, removes code and should even be faster.

llvm-svn: 248125
2015-09-20 16:15:32 +00:00
Johannes Doerfert 0c1123a831 [FIX] Repair test case that was unprofitable
llvm-svn: 248124
2015-09-20 16:14:41 +00:00
Johannes Doerfert 06c57b594c Allow loops with multiple back edges
In order to allow multiple back edges we:
    - compute the conditions under which each back edge is taken
    - build the union over all these conditions, thus the condition that
      any back edge is taken
    - apply the same logic to the union we applied to a single back edge

llvm-svn: 248120
2015-09-20 15:00:20 +00:00
Johannes Doerfert 7175bdfbe4 Add loop trip count based heuristic for SCoP detection
As we currently do not perform any optimizations that targets (or is
  even aware) small trip counts we will skip them when we count the
  loops in a region.

llvm-svn: 248119
2015-09-20 14:56:54 +00:00
Johannes Doerfert b276bde162 [NFC] Remove obsolete diagnostic for unstructured control flow
llvm-svn: 248118
2015-09-20 14:55:50 +00:00
Michael Kruse 84f70acd68 Remove unused variable Dimension [NFC]
llvm-svn: 248026
2015-09-18 20:03:32 +00:00
Michael Kruse e2bccbbfb2 Merge IRAccess into MemoryAccess
All MemoryAccess objects will be owned by ScopInfo::AccFuncMap which 
previously stored the IRAccess objects. Instead of creating new 
MemoryAccess objects, the already created ones are reused, but their 
order might be different now. Some fields of IRAccess and MemoryAccess 
had the same meaning and are merged.

This is the last step of fusioning TempScopInfo.{h|cpp} and 
ScopInfo.{h.cpp}. Some refactoring might still make sense.

Differential Revision: http://reviews.llvm.org/D12843

llvm-svn: 248024
2015-09-18 19:59:43 +00:00
Tobias Grosser b09455dee0 Store EscapeMap as Value* instead of AllocInst
This currently does not change the behavior in Polly, but it allows us to later
also overwrite the EscapeMap with our GlobalMap.

llvm-svn: 247970
2015-09-18 06:01:11 +00:00
Tobias Grosser 6f36d9ab01 Delinearize multi-dimensional arrays through bitcasts
In some cases instcombine introduces bitcasts that slightly obfuscate the
multi-dimensionality of an array. This patch teaches our fixed-size
delinearization how to look through bitcasts.

llvm-svn: 247928
2015-09-17 20:16:21 +00:00
Tobias Grosser 0537f41de5 Do not use the assumed context in the dependence analysis any more
This information is implicitly available through the multi-dimensionality of
memory accesses. This reduces compile time for 3mm from 430ms to 400ms and
should generally benefit compile time for cases where the assumed context
is complex.

llvm-svn: 247907
2015-09-17 17:28:19 +00:00
Tobias Grosser 5fd8c0961e Model fixed-size multi-dimensional arrays if possible multi-dimensional
If the GEP instructions give us enough insights, model scalar accesses as
multi-dimensional (and generate the relevant run-time checks to ensure
correctness). This will allow us to simplify the dependence computation in
a subsequent commit.

llvm-svn: 247906
2015-09-17 17:28:15 +00:00
Tobias Grosser faf8f6f62e Extract function that derives the index expressions of a GEP instruction [NFC]
We currently use this functionality to add run-time assumptions that check its
in-bound property.

llvm-svn: 247893
2015-09-17 15:47:52 +00:00
Tobias Grosser e375d8058a Add option to enable/disable reduction usage in dependence analysis
llvm-svn: 247781
2015-09-16 09:50:17 +00:00
Johannes Doerfert 883f8c1d2f Use modulo semantic to generate non-integer-overflow assumptions
This will allow to generate non-wrap assumptions for integer expressions
  that are part of the SCoP. We compare the common isl representation of
  the expression with one computed with modulo semantic. For all parameter
  combinations they are not equal we can have integer overflows.

  The nsw flags are respected when the modulo representation is computed,
  nuw and nw flags are ignored for now.

  In order to not increase compile time to much, the non-wrap assumptions
  are collected in a separate boundary context instead of the assumed
  context. This helps compile time as the boundary context can become
  complex and it is therefor not advised to use it in other operations
  except runtime check generation. However, the assumed context is e.g.,
  used to tighten dependences. While the boundary context might help to
  tighten the assumed context it is doubtful that it will help in practice
  (it does not effect lnt much) as the boundary (or no-wrap assumptions)
  only restrict the very end of the possible value range of parameters.

  PET uses a different approach to compute the no-wrap context, though lnt runs
  have shown that this version performs slightly better for us.

llvm-svn: 247732
2015-09-15 22:52:53 +00:00
Johannes Doerfert cef616fe2d Use blocks instead of domains in SCEVAffinator
Due to the new domain generation, the SCoP keeps track of the domain
  for all blocks, thus the SCEVAffinator can now work with blocks to avoid
  duplication of the domains.

llvm-svn: 247731
2015-09-15 22:49:04 +00:00
Johannes Doerfert b20f151d56 Coalesce the constructed domains early
llvm-svn: 247728
2015-09-15 22:11:49 +00:00
Michael Kruse da8d6203f4 Fix after renamed CMake cache entry
LLVM_EXTERNAL_CLANG_BUILD was changed to LLVM_TOOL_CLANG_BUILD in
r242059.

llvm-svn: 247675
2015-09-15 10:51:15 +00:00
Michael Kruse fa62b1763c Run polly-check-format with unit tests
Add polly-check-format as dependency of check-polly if clang-format is 
available in the same build.

Differential Revision: http://reviews.llvm.org/D12850

llvm-svn: 247600
2015-09-14 19:11:48 +00:00
Michael Kruse 69f3788c36 Revise polly-{update|check}-format targets
Summary:
Make clang-format run on each file independently using
add_custom_format (instead using a shell script in utils/). The targets
polly-{update|check}-format depend on these.

The primary motivation is to make them work on Windows, but also
improves them generally:
- Each file update/check can run in parallel (Although they do not take
  long to run anyway)
- Implicit dependency on clang-format, so it recompiles if necessary
- polly-check-format shows the formatting difference if failing

Differential Revision: http://reviews.llvm.org/D12837

llvm-svn: 247581
2015-09-14 16:59:50 +00:00
Michael Kruse 2846877d88 Replace some SmallVector-typed parameters by ArrayRef
ArrayRef avoids making implementation details such as the number of stack elements to be part of the function signature.

llvm-svn: 247572
2015-09-14 15:45:33 +00:00
Tobias Grosser aaadc5302c [test] Load Polly before using the polly flags
llvm-svn: 247551
2015-09-14 11:49:05 +00:00
Johannes Doerfert 334f9e87c6 [FIX] XFAIL test that depends on pending LLVM commit
llvm-svn: 247550
2015-09-14 11:45:34 +00:00
Tobias Grosser 0b13890042 Fix formatting
llvm-svn: 247549
2015-09-14 11:38:06 +00:00
Johannes Doerfert e114dc024e [FIX] Handle error blocks in non-affine regions correctly
llvm-svn: 247545
2015-09-14 11:15:58 +00:00
Johannes Doerfert 40fa56f59f [FIX] Allow the whole SCoP to be a non-affine subregion
llvm-svn: 247544
2015-09-14 11:15:07 +00:00
Johannes Doerfert 36255eecd8 Revert r247278 "Disable support for modulo expressions"
This reverts commit 00c5b6ca8832439193036aadaaaee92a43236219.

  We can handle modulo expressions in the domain again.

llvm-svn: 247542
2015-09-14 11:14:23 +00:00
Johannes Doerfert ca1e38fa43 Propagate exit conditions as described in the PET paper
At some point we build loop trip counts using this method. It was replaced by
  a simpler trick that works only for affine (e.g., not modulo) constraints and
  relies on the removal of unbounded parts. In order to allow modulo constrains
  again we go back to the former, more accurate method.

llvm-svn: 247540
2015-09-14 11:12:52 +00:00
Michael Kruse 9d08009dff Merge TempScop into Scop
Summary:
TempScop is basically a holder for AccFuncMap, the dictionary from BasicBlocks to IRAccess lists. We move the list into polly::Scop and remove the polly::TempScop class.

There is one small change in behavior: If ScopInfo finds that its AssumedContext is impossible, it bails out by deleting the Scop object. The TempScop::print (invoked with opt -polly-scops -analyze) cannot print the AccFuncMap anymore as it would with a separate TempScop.

Differential Revision: http://reviews.llvm.org/D12803

llvm-svn: 247480
2015-09-11 21:41:48 +00:00
Michael Kruse 84bf8a3bc4 Introspect llvm-config --assertion-mode in cmake out-of-tree builds
When compiling Polly without LLVM sources but with system-installed
LLVM, the build process would not honor the LLVM_ENABLE_ASSERTIONS
setting LLVM was compiled with, but effectively assume that it is
switched off when compiling. During unit-tests llvm-lit would still
query the LLVM_ENABLE_ASSERTIONS flag and enable tests which require
assertions. Even if enabled for LLVM, Polly does not output its debug
info and statistics in this this mode such that 7 tests fail.

To fix, we query llvm-config --assertion-mode and if on, enable
assertions as HandleLLVMOptions.cmake would do.

We cannot reliably use HandleLLVMOptions.cmake itself as the host's
LLVM build might have been built using automake and distributions
change file locations (e.g. Debian to
/usr/share/llvm-${VERSION}/cmake/HandleLLVMOptions.cmake).

llvm-svn: 247470
2015-09-11 20:47:14 +00:00
Tobias Grosser 98cf5696fa Fix some typos in comments
llvm-svn: 247441
2015-09-11 18:26:59 +00:00
Sylvestre Ledru 3e94031632 Update autoconf too: Analysis/TempScopInfo.cpp has been removed
llvm-svn: 247419
2015-09-11 15:05:29 +00:00
Michael Kruse 07d5df4db8 Fix out-of-range access in test case
The function use_after_scop would iterate from 0 to 1024 and accessing element A[1024] where A has only valid indexes from 0 to 1023. Polly detects the situation of unconditionally undefined behavior and bail out in ScopInfo as non-feasible for optimization.

Other tests add impossible context assumptions as well, hance might show the same problem.

llvm-svn: 247412
2015-09-11 13:45:05 +00:00
Michael Kruse ef3cf01d1c Add Polly header files to IDE projects
llvm-svn: 247398
2015-09-11 09:01:55 +00:00
David Blaikie 0afc1e4ecc Update polly for explicit type parameter to global alias change
llvm-svn: 247382
2015-09-11 03:42:32 +00:00
Tobias Grosser 34b11fc197 XFAIL tests that require an additional LLVM patch to work
llvm-svn: 247338
2015-09-10 21:32:29 +00:00
Johannes Doerfert 90db75ed24 Runtime error check elimination
Hoist runtime checks in the loop nest if they guard an "error" like event.
  Such events are recognized as blocks with an unreachable terminator or a call
  to the ubsan function that deals with out of bound accesses. Other "error"
  events can be added easily.

  We will ignore these blocks when we detect/model/optmize and code generate SCoPs
  but we will make sure that they would not have been executed using the assumption
  framework.

llvm-svn: 247310
2015-09-10 17:51:27 +00:00
Johannes Doerfert f4fa9879fb [FIX] Do not assume only one loop can be left at a time
llvm-svn: 247291
2015-09-10 15:53:59 +00:00
Johannes Doerfert b68cffb5df Allow general loops with one latch
As we do not rely on ScalarEvolution any more we do not need to get
  the backedge taken count. Additionally, our domain generation handles
  everything that is affine and has one latch and our ScopDetection will
  over-approximate everything else.

  This change will therefor allow loops with:
    - one latch
    - exiting conditions that are affine

  Additionally, it will not check for structured control flow anymore.
  Hence, loops and conditionals are not necessarily single entry single
  exit regions any more.

Differential Version: http://reviews.llvm.org/D12758

llvm-svn: 247289
2015-09-10 15:27:46 +00:00
Michael Kruse d868b5d509 Merge TempScopInfo into ScopInfo
The TempScopInfo (-polly-analyze-ir) pass is removed and its work taken
over by ScopInfo (-polly-scops). Several tests depend on
-polly-analyze-ir and use -polly-scops instead which for the moment
prints the output of both passes. This again is not expected by some
other tests, especially those with negative searches, which have been
adapted.

Differential Version: http://reviews.llvm.org/D12694

llvm-svn: 247288
2015-09-10 15:25:24 +00:00
Michael Kruse 9cc1b9d31e Clean-up unit tests
Remove redundant flags and duplicate invocations of the same test.

llvm-svn: 247285
2015-09-10 14:42:09 +00:00
Johannes Doerfert 32ae76e7f9 [NFC] Remove obsolete arguments
Remove some arguments that survived the recent changes but are not
  used any more.

llvm-svn: 247280
2015-09-10 13:12:02 +00:00
Johannes Doerfert 5b9ff8b667 Replace ScalarEvolution based domain generation
This patch replaces the last legacy part of the domain generation, namely the
ScalarEvolution part that was used to obtain loop bounds. We now iterate over
the loops in the region and propagate the back edge condition to the header
blocks. Afterwards we propagate the new information once through the whole
region. In this process we simply ignore unbounded parts of the domain and
thereby assume the absence of infinite loops.

  + This patch already identified a couple of broken unit tests we had for
    years.
  + We allow more loops already and the step to multiple exit and multiple back
    edges is minimal.
  + It allows to model the overflow checks properly as we actually visit
    every block in the SCoP and know where which condition is evaluated.
  - It is currently not compatible with modulo constraints in the
    domain.

Differential Revision: http://reviews.llvm.org/D12499

llvm-svn: 247279
2015-09-10 13:00:06 +00:00
Johannes Doerfert 171f07ed71 Disable support for modulo expressions
The support for modulo expressions is not comlete and makes the new
  domain generation harder. As the currently broken domain generation
  needs to be replaced, we will first swap in the new, fixed domain
  generation and make it compatible with the modulo expressions later.

llvm-svn: 247278
2015-09-10 12:56:46 +00:00
Michael Kruse 7bf3944d23 Merge TempScopInfo.{cpp|h} into ScopInfo.{cpp|h}
This prepares for a series of patches that merges TempScopInfo into ScopInfo to
reduce Polly's code complexity. Only ScopInfo.{cpp|h} will be left thereafter.
Moving the code of TempScopInfo in one commit makes the mains diffs simpler to
understand.

In detail, merging the following classes is planned:
TempScopInfo into ScopInfo
TempScop into Scop
IRAccess into MemoryAccess

Only moving code, no functional changes intended.

Differential Version: http://reviews.llvm.org/D12693

llvm-svn: 247274
2015-09-10 12:46:52 +00:00
Chandler Carruth 66ef16b289 [PM] Update Polly for the new AA infrastructure landed in r247167.
llvm-svn: 247198
2015-09-09 22:13:56 +00:00
Michael Kruse d16550de92 Fix typo: zycle -> cycle [NFC]
llvm-svn: 247172
2015-09-09 18:20:31 +00:00
Johannes Doerfert 7ca8dc2d2d Disable support for pointer expressions
The support for pointer expressions is broken as it can only handle
  some patterns in the IslExprBuilder. We should to treat pointers in
  expressions the same as integers at some point and revert this patch.

llvm-svn: 247147
2015-09-09 14:19:04 +00:00
Michael Kruse da943ce613 Generate gitversion.h in autoconf builds
Add a custom makefile rule to generate lib/External/isl/gitversion.h
from GIT_HEAD_ID and trigger it using BULIT_SOURCES to ensure the file
exists before compilation starts.

The latest ISL creates gitversion.h from Makefile.am only, instead also
from configure.ac in previous version. While the Polly build invokes
configure, it does not invoke ISL's make such that the file was missing.

Invoking ISL's make would come with additional problems such as
triggering automake because of not preserved file time stamps.
Re-running automake might not be successful on other system
configurations for instance because it was preconfigured without
--with-clang option.

llvm-svn: 247142
2015-09-09 13:15:11 +00:00
Tobias Grosser f1ac57c6cd IslNodeBuilder: Add virtual function to obtain the schedule of an ast node
Not all users of our IslNodeBuilder will attach scheduling information to the
AST in the same way IslAstInfo is doing it today. By going through a virtual
function when extracting the schedule of an AST node other users can provide
their own functions for extract scheduling information in case they attach
scheduling information in a different way to the AST nodes.

No functional change for Polly itself intended.

llvm-svn: 247126
2015-09-09 09:24:38 +00:00
Johannes Doerfert 717b866798 Allow PHI nodes in the region exit block
While we do not need to model PHI nodes in the region exit (as it is not part
  of the SCoP), we need to prepare for the case that the exit block is split in
  code generation to create a single exiting block. If this will happen, hence
  if the region did not have a single exiting block before, we will model the
  operands of the PHI nodes as escaping scalars in the SCoP.

Differential Revision: http://reviews.llvm.org/D12051

llvm-svn: 247078
2015-09-08 21:44:27 +00:00
Tobias Grosser 02e6589bda Move more compile-time bailouts into -polly-detect-unprofitable
Instead of having two separate options
-polly-detect-scops-in-functions-without-loops and
-polly-detect-scops-in-regions-without-loops we now just use
-polly-detect-unprofitable to force the detection of scops ignoring any compile
time saving bailout heuristics.

llvm-svn: 247057
2015-09-08 19:46:41 +00:00
Tobias Grosser b8f3690e15 Add first run-time bounds elimination test case
llvm-svn: 247020
2015-09-08 16:02:19 +00:00
Tobias Grosser a89dc57b41 Do not use '.' in subfunction names
Certain backends, e.g. NVPTX, do not support '.' in function names. Hence,
we ensure all '.' are replaced by '_' when generating function names for
subfunctions. For the current OpenMP code generation, this is not strictly
necessary, but future uses cases (e.g. GPU offloading) need this issue to be
fixed.

llvm-svn: 246980
2015-09-08 06:22:17 +00:00
Tobias Grosser 12e650d682 Drop alias metadata in checks of RuntimeDebugBuilder test
Our alias metadata is currently not emitted in a deterministic order. As it
is not needed in this test, we just drop it for now (but keep in mind to fix
this).

llvm-svn: 246942
2015-09-06 08:59:50 +00:00
Tobias Grosser 86bc93a9b2 Add option -polly-codegen-add-debug-printing
When this option is enabled, Polly will emit printf calls for each scalar
load/and store which dump the scalar value loaded/stored at run time.

This patch also refactors the RuntimeDebugBuilder to use variadic templates
when generating CPU printfs. As result, it now becomes easier to print
strings that consist of a set of arguments. Also, as a single printf
call is emitted, it is more likely for such strings to be emitted atomically
if executed multi-threaded.

llvm-svn: 246941
2015-09-06 08:47:57 +00:00
Tobias Grosser e58d358171 RuntimeDebugPrinter: Simplify code [NFC]
llvm-svn: 246940
2015-09-06 07:17:54 +00:00
Tobias Grosser e3d8c05c5f Add some more documentation and structure to the collection of subtree references
Some of the structures are renamed, subfunction introduced to clarify the
individual steps and comments are added describing their functionality.

llvm-svn: 246929
2015-09-05 15:45:25 +00:00
Tobias Grosser abcec37f64 IslNodeBuilder: Only obtain the isl_ast_build, when needed
In the common case, the access functions are not modified, hence there is no
need to obtain the IslAstBuild context at all. This should not only be minimally
faster, but this also allows the IslNodeBuilder to work on asts that are not
annotated with isl_ast_builds as long as the memory accesses are not modified.

llvm-svn: 246928
2015-09-05 13:03:57 +00:00
Tobias Grosser 8eae8361fc RegionGenerator: Do not modify GlobalMaps
By inspection the update of the GlobalMaps in the RegionGenerator seems unneed,
and is removed as also no test cases fail when dropping this. Johannes Doerfert
confirmed that this is indeed save:

"I think that code was needed when we did not use the scalar codegen by default.
Now everything defined in a non-affine region should be communicated via memory
and reloaded in the user block. Hence, we should be good removing this code."

llvm-svn: 246926
2015-09-05 11:26:30 +00:00
Tobias Grosser 113a4a4cbb Add forgotten .jscop file
llvm-svn: 246925
2015-09-05 10:58:13 +00:00
Tobias Grosser 72b80672d9 OpenMP: Name the values passed to the subfunciton according to the original llvm::Values
llvm-svn: 246924
2015-09-05 10:41:19 +00:00
Tobias Grosser 0d8874c0f6 OpenMP codegen: support generation of multi-dimensional access functions
When computing the index expressions for new, multi-dimensional memory accesses
these new index expressions may reference original llvm::Values that are not
transfered into the OpenMP subfunction. Using GlobalMap we now replace
references to such values with the rewritten values that have e.g. been passed
to the OpenMP subfunction.

llvm-svn: 246923
2015-09-05 10:32:56 +00:00
Tobias Grosser bc13260775 BlockGenerator: Make GlobalMap a member variable
The GlobalMap variable used in BlockGenerator should always reference the same
list througout the entire code generation, hence we can make it a member
variable to avoid passing it around through every function call.

History: Before we switched to the SCEV based code generation the GlobalMap
also contained a mapping form old to new induction variables, hence it was
different for each ScopStmt, which is why we passed it as function argument
to copyStmt. The new SCEV based code generation now uses a separate mapping
called LTS -> LoopToSCEV that maps each original loop to a new loop iteration
variable provided as a SCEVExpr. The GlobalMap is currently mostly used for
OpenMP code generation, where references to parameters in the original function
need to be rewritten to the locations of these variables after they have been
passed to the subfunction.

Suggested-by: Johannes Doerfert <doerfert@cs.uni-saarland.de>
llvm-svn: 246920
2015-09-05 09:56:54 +00:00
Tobias Grosser 6f73008506 Allow the import of multi-dimensional access functions
Originally, we disallowed the import of multi-dimensional access functions due
to our code generation not supporting the generation of new address expressions
for multi-dimensional memory accesses. When building our run-time alias check
infrastructure we added code generation support for multi-dimensional address
calculations.  Hence, we can now savely allow the import of new
multi-dimensional access functions.

llvm-svn: 246917
2015-09-05 07:46:47 +00:00
Tobias Grosser 166c422952 Use uppercase variable names [NFC]
llvm-svn: 246916
2015-09-05 07:46:40 +00:00
Tobias Grosser 2df884f95a ScopInfo: use project_out instead of remove_dims
By just removing dimensions (and the constraints they are involved in) we
may loose information about the dimensions we do not remove. By instead
using project_out, we are sure all constraints on the outer dimensions are
preserved.

No test case, as this error condition is very unlikely to be triggered by
isl's current code. We still 'fix' this, as isl gives little guarantees
regarding the behavior of remove_divs.

llvm-svn: 246567
2015-09-01 18:17:41 +00:00
Tobias Grosser f560ca90ef Update isl to isl-0.15-129-gb086c90
llvm-svn: 246552
2015-09-01 15:42:13 +00:00
Tobias Grosser 1dcfb7a1e6 ScopInfo: Add test case for two loops following right after each other
This case probably does not happen for LLVM generated code that is in loop
simplify form, but Polly does support such kind of loops. This commit ensures we
have test coverage as well.

llvm-svn: 246543
2015-09-01 11:33:13 +00:00
Tobias Grosser 40820ca286 Fix another typo in the subloop counting
... as well as the corresponding test cases.

Thank's Johannes for finding this bug.

llvm-svn: 246483
2015-08-31 21:04:51 +00:00
Johannes Doerfert 5f912d3797 Do Not Model Unbounded Loops
Code generation currently does not expect unbounded loops. When
  using ISL to compute the loop trip count, if we find that the
  iteration domain remains unbounded, we invalidate the Scop by
  creating an infeasible context.

Contributed-by: Matthew Simpson <mssimpso@codeaurora.org>

This fixes PR24634.

Differential Revision: http://reviews.llvm.org/D12493

llvm-svn: 246477
2015-08-31 19:58:24 +00:00
Johannes Doerfert f08bd00229 Build the domains with correct number of dimensions
Instead of building domains with MaxLoopDepth dimensions, we now build
  the domains such that they have the right amount of dimensions all the
  time.

llvm-svn: 246443
2015-08-31 13:56:32 +00:00
Johannes Doerfert 4e8907f495 [NFC] Add isl_set output stream operator
llvm-svn: 246442
2015-08-31 13:54:36 +00:00
Tobias Grosser d213d52d0e Always use the branch instructions to model the PHI-node writes
Before this commit we did this only for Arguments or Constants, but indeed
an instruction may define a value a lot higher up in the dominance tree, but
the actual write generally needs to happen right before branching to the
PHI node. Otherwise, the writes of different branches into PHI nodes may get
intermixed if they lay higher up in the dominance tree.

llvm-svn: 246441
2015-08-31 13:45:54 +00:00
Tobias Grosser 050e0cbc0e ScopDetection: Correctly count the loops in a region
There is no reason the loops in a region need to touch either entry or exit
block. Hence, we need to look through all loops that may touch the region as
well as their children to understand if our region has at least two loops.

llvm-svn: 246433
2015-08-31 12:08:11 +00:00
Tobias Grosser 44b34b0e8a Also build scalar dependences for store instructions
While ignoring read-only scalar dependences it was not necessary to consider
store instructins, but as store instructions can be the target of a scalar
read-only dependency we need to consider them for the construction of scalar
read-only dependences.

llvm-svn: 246429
2015-08-31 11:15:00 +00:00
Tobias Grosser 9f3d55cf3d Generate scalar initialization loads at the beginning of the start BB
Our OpenMP code generation generated part of its launching code directly into
the start basic block and without this change the scalar initialization was
run _after_ the OpenMP threads have been launched. This resulted in
uninitialized scalar values to be used.

llvm-svn: 246427
2015-08-31 11:06:19 +00:00
Tobias Grosser f93451802a OpenMP-codegen: Correctly pass function arguments to subfunctions
Before we only checked if certain instructions can be expanded by us. Now we
check any value, including function arguments.

llvm-svn: 246425
2015-08-31 09:05:43 +00:00
Tobias Grosser 58758ef4ea Enable modeling of scalar read-only dependences
Even though these are not strictly necessary for sequential code generation,
we still model both for sequential and parallel code generation to reduce
the set of configurations that needs to be tested. If this turns out, against
what we currently see, to be significant overhead, we can decide to limit this
feature again to parallel code-generation use cases only.

llvm-svn: 246420
2015-08-31 06:46:32 +00:00
Tobias Grosser d86bf4271c Do not model scalar references to constant values
llvm-svn: 246418
2015-08-31 06:37:25 +00:00
Tobias Grosser 64c0ff4141 Add support for scalar dependences to OpenMP code generation
Scalar dependences between scop statements have caused troubles during parallel
code generation as we did not pass on the new stack allocation created for such
scalars to the parallel subfunctions. This change now detects all scalar
reads/writes in parallel subfunctions, creates the allocas for these scalar
objects, passes the resulting memory locations to the subfunctions and ensures
that within the subfunction requests for these memory locations will return the
rewritten values.

Johannes suggested as a future optimization to privatizing some of the scalars
in the subfunction.

llvm-svn: 246414
2015-08-31 05:52:24 +00:00
Johannes Doerfert 96425c2574 Traverse the SCoP to compute non-loop-carried domain conditions
In order to compute domain conditions for conditionals we will now
  traverse the region in the ScopInfo once and build the domains for
  each block in the region. The SCoP statements can then use these
  constraints when they build their domain.

  The reason behind this change is twofold:
    1) This removes a big chunk of preprocessing logic from the
       TempScopInfo, namely the Conditionals we used to build there.
       Additionally to moving this logic it is also simplified. Instead
       of walking the dominance tree up for each basic block in the
       region (as we did before), we now traverse the region only
       once in order to collect the domain conditions.
    2) This is the first step towards the isl based domain creation.
       The second step will traverse the region similar to this step,
       however it will propagate back edge conditions. Once both are in
       place this conditional handling will allow multiple exit loops
       additional logic.

Reviewers: grosser

Differential Revision: http://reviews.llvm.org/D12428

llvm-svn: 246398
2015-08-30 21:13:53 +00:00
Johannes Doerfert b1e3bbb7c9 [FIX] Keep a copy of the Domain set in the SCEVAffinator
llvm-svn: 246397
2015-08-30 19:52:06 +00:00
Tobias Grosser 2fc50df900 Do not store into a temporary twine
For some reason, this causes memory corruption issues. Let's just avoid it.

llvm-svn: 246396
2015-08-30 19:51:01 +00:00
Tobias Grosser c0091a77f9 Store scalar dependences from outside the scop into alloca locations
We already modeled read-only dependences to scalar values defined outside the
scop as memory reads and also generated read accesses from the corresponding
alloca instructions that have been used to pass these scalar values around
during code generation. However, besides for PHI nodes that have already been
handled, we failed to store the orignal read-only scalar values into these
alloc. This commit extends the initialization of scalar values to all read-only
scalar values used within the scop.

llvm-svn: 246394
2015-08-30 19:19:34 +00:00
Tobias Grosser b649e26a50 getNewScalarValue: Get ScalarMap directly from member variable [NFC]
There is no need to pass the ScalarMap to getNewScalarValue as this
map is (indirectly) used when calling getOrCreateScalarAlloca.

llvm-svn: 246390
2015-08-30 17:37:55 +00:00
Tobias Grosser 655a4570cd createScalarInitialization: Always store PHI-node value
The current code really tries hard to use getNewScalarValue(), which checks if
not the original value, but a possible copy or demoted value needs to be stored.
In this calling context it seems, that we _always_ use the ScalarValue that
comes from the incoming PHI node, but never any other value. As also no test
cases fail, it seems right to just drop this call to getNewScalarValue and
remove the parameters that are not needed any more.

Johannes suggested that code like this might be needed for parallel code
generation with offloading, but it was still unclear if/what exactly would
be needed. As the parallel code generation does currently not support scalars
at all, we will remove this code for now and add relevant code back when
complitng the support of scalars in the parallel code generation.

Reviewers: jdoerfert

Subscribers: pollydev, llvm-commits

Differential Revision: http://reviews.llvm.org/D12470

llvm-svn: 246389
2015-08-30 17:32:39 +00:00
Tobias Grosser e83a396b1d Ignore debug intrinsics and do not model their potential scalar metadata reads
Our code generation currently does not support scalar references to metadata
values. Hence, it would crash if we try to model scalar dependences to metadata
values. Fortunately, for one of the common uses, debug information, we can
for now just ignore the relevant intrinsics and consequently the issue of how
to model scalar dependences to metadata.

llvm-svn: 246388
2015-08-30 16:57:20 +00:00
Tobias Grosser 9c0ffe3a1d Remove some code duplication [NFC]
llvm-svn: 246387
2015-08-30 16:57:15 +00:00
Tobias Grosser fcfac082ea Minor code style improvement [NFC]
llvm-svn: 246386
2015-08-30 16:01:58 +00:00
Tobias Grosser 2985400a0e Remove isNew from getOrCreateAlloca
This commit drops some dead code. Specifically, there is no need to initialize
the virtual memory locations of scalars in BlockGenerator::handleOutsideUsers,
the function that initalizes the escape map that keeps track of out-of-scope
uses of scalar values. We already model instructions inside the scop that
are used outside the scope (escaping instructions) as scalar memory writes at
the position of the instruction. As a result, the virtual memory location of
this instructions is already initialized when code-generating the corresponding
virtual scalar write and consequently does not need to be initialized later on
when generating the set of escaping values.

Code references:

In TempScopInfo::buildScalarDependences we detect scalar cross-statement
dependences for all instructions (including PHIs) that have uses outside of the
scop's region:

  // Check whether or not the use is in the SCoP.
  if (!R->contains(UseParent)) {
    AnyCrossStmtUse = true;
    continue;
  }

We use this information in TempScopInfo::buildAccessFunctions were we build
scalar write memory accesses for all these instructions:

  if (!isa<StoreInst>(Inst) &&
    buildScalarDependences(Inst, &R, NonAffineSubRegion)) {
    // If the Instruction is used outside the statement, we need to build the
    // write access.
    IRAccess ScalarAccess(IRAccess::MUST_WRITE, Inst, ZeroOffset, 1, true,
                          Inst);
    Functions.push_back(std::make_pair(ScalarAccess, Inst));
  }

Reviewers: jdoerfert

Subscribers: pollydev, llvm-commits

Differential Revision: http://reviews.llvm.org/D12472

llvm-svn: 246383
2015-08-30 15:03:59 +00:00
Tobias Grosser 51b65d9370 Drop alias tags from vector test case
They are not really part of what is tested here.

llvm-svn: 246382
2015-08-30 14:06:30 +00:00
Tobias Grosser f8d55f7e4e Remove some code duplication when creating Allocas [NFC]
llvm-svn: 246364
2015-08-29 18:12:03 +00:00
Duncan P. N. Exon Smith adbcf12029 DI: Fix testcases after LLVM r246327
I ran the script from r246327 and it touched all the right files;
committing now to hopefully right the bots, but if my check-polly
doesn't come back clean I'll keep looking.

http://lab.llvm.org:8011/builders/polly-amd64-linux/builds/33648

llvm-svn: 246341
2015-08-28 22:01:49 +00:00
Johannes Doerfert b409fdc0d7 [NFC] Make SCEVAffinator work without a statement
llvm-svn: 246290
2015-08-28 09:24:35 +00:00
Tobias Grosser 6dc4441884 IslNodeBuilder: Make functionality available to subclasses
llvm-svn: 246287
2015-08-28 08:30:52 +00:00
Tobias Grosser 3f2783b254 IslNodeBuilder: Add function to export BlockGenerator
llvm-svn: 246286
2015-08-28 08:23:38 +00:00
Tobias Grosser b79a67df78 BlockGenerator: Make scalar memory locations accessible
For external users, the memory locations into which we generate scalar values
may be of interest. This change introduces two functions that allow to obtain
(or create) the AllocInsts for a given BasePointer.

We use this change to simplify the code in BlockGenerators.

llvm-svn: 246285
2015-08-28 08:23:35 +00:00
Tobias Grosser 1e5a8c1a5c Virtualize the IslNodeBuilder
This allows users to extend the IslNodeBuilder to create their own optimization
passes. This feature is not used in Polly's codebase itself, but as these
funtions are not performance critical, the cost of making experiments of
external users easier seems low enough to do so.

llvm-svn: 246281
2015-08-28 07:07:04 +00:00
Tobias Grosser ed21a1fc7e Do not detect Scops with only one loop.
If a region does not have more than one loop, we do not identify it as
a Scop in ScopDetection. The main optimizations Polly is currently performing
(tiling, preparation for outer-loop vectorization and loop fusion) are unlikely
to have a positive impact on individual loops. In some cases, Polly's run-time
alias checks or conditional hoisting may still have a positive impact, but those
are mostly enabling transformations which LLVM already performs for individual
loops. As we do not focus on individual loops, we leave them untouched to not
introduce compile time regressions and execution time noise. This results in
good compile time reduction (oourafft: -73.99%, smg2000: -56.25%).

Contributed-by: Pratik Bhatu <cs12b1010@iith.ac.in>

Reviewers: grosser

Differential Revision: http://reviews.llvm.org/D12268

llvm-svn: 246161
2015-08-27 16:55:18 +00:00
Tobias Grosser 2d1ed0bfa7 BlockGenerator: Add the possiblity to pass a set of new access functions
This change allows the BlockGenerator to be reused in contexts where we want to
provide different/modified isl_ast_expressions, which are not only changed to
a different access relation than the original statement, but which may indeed
be different for each code-generated instance of the statement.

We ensure testing of this feature by moving Polly's support to import changed
access functions through a jscop file to use the BlockGenerators support for
generating arbitary access functions if provided.

This commit should not change the behavior of Polly for now. The diff is rather
large, but most changes are due to us passing the NewAccesses hash table through
functions. This style, even though rather verbose, matches what is done
throughout the BlockGenerator with other per-statement properties.

llvm-svn: 246144
2015-08-27 07:28:16 +00:00
Johannes Doerfert d020b77295 Use ISL to Determine Loop Trip Count
Use ISL to compute the loop trip count when scalar evolution is unable to do
  so.

Contributed-by: Matthew Simpson <mssimpso@codeaurora.org>

Differential Revision: http://reviews.llvm.org/D9444

llvm-svn: 246142
2015-08-27 06:53:52 +00:00
Tobias Grosser 01c8f5f354 [Vectorizer] Detect strides in multi-dimensional arrays
The original code was only correct for one-dimensional arrays, but derived
incorrect strides for multi-dimensional arrays.

llvm-svn: 245888
2015-08-24 22:20:46 +00:00
Tobias Grosser 39f9f30e8b Only derive number of loop iterations for loops we can actually vectorize
llvm-svn: 245870
2015-08-24 20:11:34 +00:00
Tobias Grosser fa57e9b7e6 Make our data-locality schedule tree transforms externally accessible
Other passes which perform different optimizations might be interested in
also applying data-locality transformations as part of their overall
transformation.

llvm-svn: 245824
2015-08-24 06:01:47 +00:00
Tobias Grosser 1ac884d73a Use marker nodes to annotate the different levels of tiling
Currently, marker nodes are ignored during AST generation, but visible in the
-debug-only=polly-ast output.

llvm-svn: 245809
2015-08-23 09:11:00 +00:00
Tobias Grosser 75296901f7 Fix 'unused variable' warning in NASSERTS build
llvm-svn: 245723
2015-08-21 19:23:21 +00:00
Roman Gareev c49724f008 Manually check a loop form
Add manual check of a loop form and return non-negative number of iterations
in case of trivially vectorizable loop.

llvm-svn: 245680
2015-08-21 09:08:14 +00:00
Tobias Grosser daaed0e19f Do not intersect with AssumedContext in calculateMinMaxAccess
Originally, we intersected the iteration space with the AssumedContext before
computing the minimal/maximal memory offset in our run-time alias checks. With
this patch we drop this intersection as the AssumedContext can - for larger or
more complex scops - become very complicated (contain many disjuncts). When
intersecting an object with many disjuncts with other objects, the number of
disjuncts in these other objects also increases quickly. As a result, the
compile time is unnecessarily increased. This patch now drops the intersection
with the assumed context to ensure we do not pay unnecessary compile time
costs.

With this patch we see -3.17% reduction in compile time for 3mm with default
flags and -17.87% when compiling 3mm with -DPOLYBENCH_USE_C99_PROTO flag. We
did not observe any regressions in LNT.

Contributed-by: Pratik Bhatu <cs12b1010@iith.ac.in>

Reviewers: grosser

Differential Revision: http://reviews.llvm.org/D12198

llvm-svn: 245617
2015-08-20 21:29:26 +00:00
Tobias Grosser fc490a99f5 Do really not unroll the vector loop in combination with register tiling
The previous commit lacked a test case for register tiling + pre-vectorization
and we obviously got it immediately wrong.

llvm-svn: 245599
2015-08-20 19:08:16 +00:00
Tobias Grosser d83b8a83ec Add option to control reduction detection
llvm-svn: 245598
2015-08-20 19:08:11 +00:00
Tobias Grosser 40985016b2 Fix formatting
llvm-svn: 245597
2015-08-20 19:08:05 +00:00
Johannes Doerfert 120de4be96 Simplify the SCoP creation and bookkeeping
To avoid multiple exits and the resulting complicated conditions when
  creating a SCoP we now use the single hasFeasibleRuntimeContext()
  check to decide if a SCoP should be dismissed right after
  construction. If building runtime checks failed the assumed context is
  made infeasible, hence the optimized version will never be executed
  and the SCoP can be dismissed.

llvm-svn: 245593
2015-08-20 18:30:08 +00:00
Johannes Doerfert 5d5b30649a Check feasibility for the runtime check context wrt. the domain.
If nothing is executed we can bail out early. Otherwise we can use the
  constraints that ensure at least one statement is executed for
  simplification.

llvm-svn: 245585
2015-08-20 18:06:30 +00:00
Johannes Doerfert 4eed5bea54 Link ScopArrayInfo objects
We will record if a SAI is the base of another SAI or derived from it.
  This will allow to reason about indirect base pointers later on and
  allows a clearer picture of indirection also in the SCoP dump.

llvm-svn: 245584
2015-08-20 18:04:22 +00:00
Tobias Grosser 42e2489553 Add experimental support for trivial register tiling
Register tiling in Polly is for now just an additional level of tiling which
is fully unrolled. It is disabled by default. To make this useful for more than
experiments, we still need a cost function as well as possibly further
optimizations that teach LLVM to actually put some of the values we got into
scalar registers.

llvm-svn: 245564
2015-08-20 13:45:05 +00:00
Tobias Grosser 0483271662 Add support for two-level tiling
By default we only use one level of tiling for loops, but in general tiling
for multiple levels is trivial for us. Hence, we add a set of options that
allow people to play with a second level of tiling. If this is profitable for
some cases we can work on heuristics that allow us to identify these cases
and use two-level tiling for them.

llvm-svn: 245563
2015-08-20 13:45:02 +00:00
Tobias Grosser 862b9b5239 Factor out check for tileable band node.
llvm-svn: 245559
2015-08-20 12:32:45 +00:00
Tobias Grosser 9bdea573bd Introduce tileBand function to simplify code
llvm-svn: 245558
2015-08-20 12:22:37 +00:00
Tobias Grosser d891b54132 Add some forgotten isl memory annotations
llvm-svn: 245557
2015-08-20 12:16:23 +00:00
Johannes Doerfert 43788c5783 Check for feasible runtime check context early
Instead of generating code for an empty assumed context we bail out
  early. As the number of assumptions we generate increases this becomes
  more and more important. Additionally, this change will allow us to
  hide internal contexts that are only used in runtime checks e.g., a
  boundary context with constraints not suited for simplifications.

llvm-svn: 245540
2015-08-20 05:58:56 +00:00
Tobias Grosser b0da42fb55 Generate alias metadata even in OpenMP mode
To make alias scope metadata generation work in OpenMP mode we now provide
the ScopAnnotator with information about the base pointer rewrite that happens
when passing arrays into the OpenMP subfunction.

llvm-svn: 245451
2015-08-19 16:04:35 +00:00
Tobias Grosser d8e3c8c665 Fix typo
llvm-svn: 245441
2015-08-19 14:22:48 +00:00
Tobias Grosser 07c1c2fcc9 Make prevectorization width configurable
Polly uses 'prevectorization' to enable outer loop vectorization. When
vectorizing an outer loop, we strip-mine <number-of-prevec-dims> loop
iterations which are than interchanged to the innermost level such that LLVM's
inner loop vectorizer (or Polly's simple vectorizer) can easily vectorize this
loop. The number of loop iterations to strip-mine is now configurable with the
option -polly-prevect-width=<number-of-prevec-dims>.

This is mostly a debugging option. We should probably add a heuristic that
derives the number of prevectorization dimensions from the target data and
the data types used.

llvm-svn: 245424
2015-08-19 08:46:11 +00:00
Tobias Grosser 161c9081e5 Do not use negative option name
Instead of -polly-no-tiling, we use -polly-tiling=false to disable tiling.

llvm-svn: 245423
2015-08-19 08:22:06 +00:00
Tobias Grosser f10f4636ff Simplify tiling code a bit
We only need to allocate the tile size vector if we actually want to perform
a tiling.

llvm-svn: 245422
2015-08-19 08:03:37 +00:00
Michael Kruse d568a3e20d Update test case multidim_indirect_access.ll
This test was written to check the workings of IndependentBlocks on
arrays which doesn't do such transformations anymore. The test itself
is still useful to check that the region is rejected as SCoP.  

llvm-svn: 245353
2015-08-18 21:08:41 +00:00
Michael Kruse acb6ade757 Move early exit to the beginning of the function
If the function exits early there is no reason to enter the loop.

llvm-svn: 245316
2015-08-18 17:25:48 +00:00
Roman Gareev f2bd72e00d Use isl_set_is_subset instead of isl_set_is_equal
It helps to detect correct strides in case of parametric constraints of Stride
in MemoryAccess::isStrideX.

Reviewers: grosser
llvm-svn: 245303
2015-08-18 16:12:05 +00:00
Tobias Grosser c0f8452592 Fix test cases which fail due to changes in isl's set representation
llvm-svn: 245301
2015-08-18 15:28:02 +00:00
Tobias Grosser cf9ebb63d6 Use schedule trees to compute dependences
This patch changes Polly to compute the data-dependences on the schedule tree
instead of a flat schedule representation. Calculating dependences directly on
the schedule tree results in some good compile-time improvements (adi : -23.35%,
3mm : -9.57%), as the structure of the schedule can be exploited for increased
efficiency.

Earlier experiments with schedule tree based dependence analysis in Polly showed
some compile-time regressions. These regressions arose due to the schedule tree
based dependence analysis not taking into account the domain constraints of the
schedule tree. As a result, the computed dependences were different and this
difference caused in some cases the schedule optimizer to take a very long time.
Since isl version fe865996 the schedule tree based dependence analysis takes
domain constraints into account, which fixes the earlier compile-time issues.

Contributed-by: Pratik Bhatu <cs12b1010@iith.ac.in>
llvm-svn: 245300
2015-08-18 15:05:29 +00:00
Roman Gareev 079968e4cf test commit revert
test commit revert

llvm-svn: 245299
2015-08-18 14:56:50 +00:00
Roman Gareev 6753df4bb6 test commit
test commit

llvm-svn: 245298
2015-08-18 14:54:27 +00:00
Michael Kruse d2b0360197 Fix Codegen adding a second exit out of region
executeScopConditionally would destroy a predecessor region if it the
scop's entry was the region's exit block by forking it to polly.start
and thus creating a secnd exit out of the region. This patch "shrinks"
the predecessor region s.t. polly.split_new_and_old is not the 
region's exit anymore. 

llvm-svn: 245294
2015-08-18 13:14:42 +00:00
Johannes Doerfert e69e1141d9 Introduce the ScopExpander as a SCEVExpander replacement
The SCEVExpander cannot deal with all SCEVs Polly allows in all kinds
  of expressions. To this end we introduce a ScopExpander that handles
  the additional expressions separatly and falls back to the
  SCEVExpander for everything else.

Reviewers: grosser, Meinersbur

Subscribers: #polly

Differential Revision: http://reviews.llvm.org/D12066

llvm-svn: 245288
2015-08-18 11:56:00 +00:00
Tobias Grosser 77c0f5a3b7 Drop dead and disable code from IndependentBlocks
Since Polly has now support for the code generation of scalar and PHI
dependences this code was unused and is now dropped.

llvm-svn: 245284
2015-08-18 09:30:28 +00:00
Johannes Doerfert d86f2157e5 Add a field to the memory access class for a related value.
The new field in the MemoryAccess allows us to track a value related
  to that access:
    - For real memory accesses the value is the loaded result or the
      stored value.
    - For straigt line scalar accesses it is the access instruction
      itself.
    - For PHI operand accesses it is the operand value.

  We use this value to simplify code which deduced information about the value
  later in the Polly pipeline and was known to be error prone.

Reviewers: grosser, Meinsersbur

Subscribers: #polly

Differential Revision: http://reviews.llvm.org/D12062

llvm-svn: 245213
2015-08-17 10:58:17 +00:00
Tobias Grosser c5bcf246d1 Fix Polly after SCEV port to new pass manager
This fixes compilation after LLVM commit r245193.

llvm-svn: 245211
2015-08-17 10:57:08 +00:00
Johannes Doerfert e1fa6da356 [FIX] Create location if a needed value was not yet demoted
This allows the code generation to continue working even if a needed
  value (that is reloaded anyway) was not yet demoted. Instead of
  failing it will now create the location for future demotion to memory
  and load from that location. The stores will use the same location and
  by construction execute before the load even if the textual order in
  the generated AST is otherwise.

Reviewers: grosser, Meinersbur

Subscribers: #polly

Differential Revision: http://reviews.llvm.org/D12072

llvm-svn: 245203
2015-08-17 09:38:46 +00:00
Tobias Grosser 3278b7cd7c Add 2nd test case for sdiv/srem instructions in a SCEV
llvm-svn: 245186
2015-08-16 19:53:21 +00:00
Johannes Doerfert eca5282dd0 [FIX] Add XFAIL to crashing test case
llvm-svn: 245180
2015-08-16 14:54:16 +00:00
Johannes Doerfert 45545ff782 Build the ScopStmt domain in-place.
This will build the statement domains in-place, hence using the
  ScopStmt::Domain member instead of some intermediate isl_set.

llvm-svn: 245179
2015-08-16 14:36:01 +00:00
Johannes Doerfert c594dc9ed0 Add a crashing test case for the scalar code generation
This test case crashes the scalar code generation as we are not
  consistent with the usage of the assumed context. To be precise, we
  use the assumed context for the dependence analysis but not to
  restrict the domains of the statements.

  A step by step explanation of the problem is given in the test case.

llvm-svn: 245176
2015-08-16 11:12:22 +00:00
Tobias Grosser 8a9c2353f9 Add -polly-context option to provide additional context information
This option allows the user to provide additional information about parameter
values as an isl_set. To specify that N has the value 1024, we can provide
the context -polly-context='[N] -> {: N = 1024}'.

llvm-svn: 245175
2015-08-16 10:19:29 +00:00
Johannes Doerfert ddb83d0f6d Remove trivially true condition
llvm-svn: 245174
2015-08-16 08:35:40 +00:00
Tobias Grosser 234a48270e AST Generation Paper published in TOPLAS
The July issue of TOPLAS contains a 50 page discussion of the AST generation
techniques used in Polly. This discussion gives not only an in-depth
description of how we (re)generate an imperative AST from our polyhedral based
mathematical program description, but also gives interesting insights about:

- Schedule trees: A tree-based mathematical program description that enables us
to perform loop transformations on an abstract level, while issues like the
generation of the correct loop structure and loop bounds will be taken care of
by our AST generator.

- Polyhedral unrolling: We discuss techniques that allow the unrolling of
non-trivial loops in the context of parameteric loop bounds, complex tile
shapes and conditionally executed statements. Such unrolling support enables
the generation of predicated code e.g. in the context of GPGPU computing.

- Isolation for full/partial tile separation: We discuss native support for
handling full/partial tile separation and -- in general -- native support for
isolation of boundary cases to enable smooth code generation for core
computations.

- AST generation with modulo constraints: We discuss how modulo mappings are
lowered to efficient C/LLVM code.

- User-defined constraint sets for run-time checks We discuss how arbitrary
sets of constraints can be used to automatically create run-time checks that
ensure a set of constrainst actually hold. This feature is very useful to
verify at run-time various assumptions that have been taken program
optimization.

Polyhedral AST generation is more than scanning polyhedra
Tobias Grosser, Sven Verdoolaege, Albert Cohen
ACM Transations on Programming Languages and Systems (TOPLAS), 37(4), July 2015

llvm-svn: 245157
2015-08-15 09:34:33 +00:00
Tobias Grosser 4c45542595 Update link to Polly paper
By going through my personal website, people can go directly to the paper.

llvm-svn: 245156
2015-08-15 09:34:28 +00:00
Michael Kruse 82a1c7de09 Make TempScopInfo a RegionPass
This modifies the order in which Polly passes are executed.

Assuming a function has two scops (A and B), the order before was:

FunctionPassManager
  ScopDetection
  IndependentBlocks
  TempScopInfo for A and B
  RegionPassManager
    ScopInfo for A
    DependenceInfo for A
    IslScheduleOptimizer for A
    IslAstInfo for A
    CodeGeneration for A
    ScopInfo for B
    DependenceInfo for B
    IslScheduleOptimizer for B
    IslAstInfo for B
    CodeGeneration for B

After this patch:

FunctionPassManager
  ScopDetection
  IndependentBlocks
  RegionPassManager
    TempScopInfo for A
    ScopInfo for A
    DependenceInfo for A
    IslScheduleOptimizer for A
    IslAstInfo for A
    CodeGeneration for A
    TempScopInfo for B
    ScopInfo for B
    DependenceInfo for B
    IslScheduleOptimizer for B
    IslAstInfo for B
    CodeGeneration for B

TempScopInfo for B might store information and references to the IR
that CodeGeneration for A might modify. Changing the order ensures that
the IR is not modified from the analysis of a region until code
generation.

Reviewers: grosser

Differential Revision: http://reviews.llvm.org/D12014

llvm-svn: 245091
2015-08-14 20:10:27 +00:00
Tobias Grosser bccd1b0af0 Fix test case after recent LLVM changes
llvm-svn: 244954
2015-08-13 21:08:15 +00:00
Tobias Grosser 7e584168ab Manuallt simplify test case
llvm-svn: 244907
2015-08-13 16:33:32 +00:00
Michael Kruse 5a8ddd74a5 Remove unimplemented private method getTempScop
llvm-svn: 244906
2015-08-13 16:28:04 +00:00
Michael Kruse 2da3872a99 Add test case for SCEV synthesizing
CodeGenerator currently tries to generate code for a parameter using
values values that are computed later.

llvm-svn: 244903
2015-08-13 15:53:53 +00:00
Tobias Grosser 0164b8ff70 Enable code generation of scalar dependences from function arguments
This change extends the BlockGenerator to not only allow Instructions as
base elements of scalar dependences, but any llvm::Value. This allows
us to code-generate scalar dependences which reference function arguments, as
they arise when moddeling read-only scalar dependences.

llvm-svn: 244874
2015-08-13 08:07:39 +00:00
Tobias Grosser 72e8f5999e Make sure we increment the reference counter when passing out the isl_pw_aff
llvm-svn: 244758
2015-08-12 15:45:41 +00:00
Tobias Grosser d46fd5ed95 Make the dimension sizes of in ScopArrayInfo available as isl_pw_affs
This makes it easier to reason about the size of an array dimension with isl.

llvm-svn: 244757
2015-08-12 15:27:16 +00:00
Johannes Doerfert 5451544a17 Remove identity operation from SCEVAffinator
llvm-svn: 244736
2015-08-12 10:58:01 +00:00
Johannes Doerfert 33d98a3f45 Revert r244459 'Make StmtSet a list'
llvm-svn: 244735
2015-08-12 10:55:52 +00:00
Johannes Doerfert 3f0a2a325f Add caching to the SCEVAffinator
While the compile time is not affected by this patch much it will
  allow us to look at all translated expressions after the SCoP is build
  in a convenient way. Additionally, bigger SCoPs or SCoPs with
  repeating complicated expressions might benefit from the cache later
  on.

Reviewers: grosser, Meinersbur

Subscribers: #polly

Differential Revision: http://reviews.llvm.org/D11975

llvm-svn: 244734
2015-08-12 10:46:33 +00:00
Johannes Doerfert f363bfb730 [FIX] Typo
llvm-svn: 244733
2015-08-12 10:45:20 +00:00
Johannes Doerfert 916736ef73 Expose the SCEVAffinator and make it a member of a SCoP (cont'd)
Added missing documentation and linked to the correct revision.

Differential Revision: http://reviews.llvm.org/D11974

llvm-svn: 244731
2015-08-12 10:28:45 +00:00
Johannes Doerfert 574182d394 Expose the SCEVAffinator and make it a member of a SCoP.
This change has three major advantages:
    - The ScopInfo becomes smaller.
    - It allows to use the SCEVAffinator from outside the ScopInfo.
    - A member object allows state which in turn allows e.g., caching.

Differential Revision: http://reviews.llvm.org/D9099

llvm-svn: 244730
2015-08-12 10:19:50 +00:00
Johannes Doerfert 9e0daff91e Make arc unit work with ninja builds
In order to find the llvm-obj directory it has to be (or a soft link
  to it) at one of the following locations:

    ${POLLY_SRC_DIR}/build
    ${POLLY_SRC_DIR}.build
    ${POLLY_SRC_DIR}-build
    s/${POLLY_SRC_DIR}/src/build

  Alternatively, the environment variable $POLLY_BIN_DIR can point to it.

llvm-svn: 244727
2015-08-12 09:02:20 +00:00
Johannes Doerfert a7ba98caa2 Adjusted arc linter config for modern version of arcanist
llvm-svn: 244726
2015-08-12 09:01:16 +00:00
Tobias Grosser a77cea49d1 Always model PHI nodes in scop (if not in same nonaffine subregion)
Before we only modeled PHI nodes if at least one incoming basic block was itself
part of the region, now we always model them except if all of their operands are
part of a single non-affine subregion which we model as a black-box.

This change only affects PHI nodes in the entry block, that have exactly one
incoming edge. Before this change, we did not model them and as a result code
generation would not know how to code generate them. With this change, code
generation can code generate them like any other PHI node.

This issue was exposed by r244606. Before this change simplifyRegion would have
moved these PHI nodes out of the SCoP, so we would never have tried to code
generate them. We could implement this behavior again, but changing the IR
after the scop has been modeled and transformed always adds a risk of us
invalidating earlier analysis results. It seems more save and overall also more
consistent to just model and handle this one-entry-edge PHI nodes like any
other PHI node in the scop.

Solution proposed by:  Michael Kruse  <llvm@meinersbur.de>

llvm-svn: 244721
2015-08-12 07:48:54 +00:00
Michael Kruse fba24b3775 Add another test case with trival PHI in entry BB
This one was extracted from the test-suite's pifft and caused a
miscompilation because a scalar was not written to its alloca address.

llvm-svn: 244720
2015-08-12 07:34:55 +00:00
Michael Kruse 4f9caf2b28 Add test case for entry node with trivial PHI
This is a break-down from the test-suite's oggenc where Polly currently
crashes. 

llvm-svn: 244692
2015-08-11 23:09:19 +00:00
Michael Kruse 9c483c5834 Assign regions to all BBs from CodeGeneration
In order to have a valid region analysis, we assign all newly created blocks to the parent of the scop's region. This is correct for any pre-existing regions (including the scop's region and its parent), but does not discover any region inside the generated code. For Polly this is not necessary because we do not want to re-run Polly on its own generated code anyway.

Reviewers: grosser

Part of Differential Revision: http://reviews.llvm.org/D11867

llvm-svn: 244608
2015-08-11 14:47:37 +00:00
Michael Kruse 22370884c4 Revise the simplification of regions
The previous code had several problems:

For newly created BasicBlocks it did not (always) call RegionInfo::setRegionFor in order to update its analysis. At the moment RegionInfo does not verify its BBMap, but will in the future. This is fixed by determining the region new BBs belong to and set it accordingly. The new executeScopConditionally() requires accurate getRegionFor information. 

Which block is created by SplitEdge depends on the incoming and outgoing edges of the blocks it connects, which makes handling its output more difficult than it needs to be. Especially for finding which block has been created an to assign a region to it for the setRegionFor problem above. This patch uses an implementation for splitEdge that always creates a block between the predecessor and successor. simplifyRegion has also been simplified by using SplitBlockPredecessors instead of SplitEdge. Isolating the entries and exits have been refectored into individual functions.

Previously simplifyRegion did more than just ensuring that there is only one entering and one exiting edge. It ensured that the entering block had no other outgoing edge which was necessary for executeScopConditionally(). Now the latter uses the alternative splitEdge implementation which can handle this situation so simplifyRegion really only needs to simplify the region.

Also, executeScopConditionally assumed that there can be no PHI nodes in blocks with one incoming edge. This is wrong and LCSSA deliberately produces such edges. However, previous passes ensured that there can be no such PHIs in exit nodes, but which will no longer hold in the future.

The new code that the property that it preserves the identity of region block (the property that the memory address of the BasicBlock containing the instructions remains the same; new blocks only contain PHI nodes and a terminator), especially the entry block. As a result, there is no need to update the reference to the BasicBlock of ScopStmt that contain its instructions because they have been moved to other basic blocks.

Reviewers: grosser

Part of Differential Revision: http://reviews.llvm.org/D11867 

llvm-svn: 244606
2015-08-11 14:39:21 +00:00
Michael Kruse 23d0e83aa3 Introduce splitBlock and use it in splitEntryBlockForAlloca
RegionInfo::splitBlock did not update RegionInfo correctly. Specifically, it tried to make the new block the entry block if possible. This breaks for nested regions that have edges to the old block. 

We simply do not change the entry block. Updating RegionInfo becomes trivial as both block will always be in the same region.

splitEntryBlockForAlloca makes use of the new splitBlock.

Reviewers: grosser

Part of Differential Revision: http://reviews.llvm.org/D11867

llvm-svn: 244600
2015-08-11 14:04:06 +00:00
Tobias Grosser 6e3ba33b07 Update isl to isl-0.15-117-ge42acfe
Besides other changes this version of isl contains a fundamental fix to memory
corruption issues we have seen with imath-32 backed isl_ints.

This update also contains a fix that ensures that the schedule-tree based
version of isl's dependence analysis takes the domain of the schedule into
account.

llvm-svn: 244585
2015-08-11 11:31:18 +00:00
Tobias Grosser c186ac7aea BlockGenerator: Do not store 'store' statements in BBMap
A store statement has no return value and can consequently not be referenced
from another statement.

llvm-svn: 244576
2015-08-11 08:13:15 +00:00
Michael Kruse 874b5c2197 Correct non-existing past participle of split in filename
llvm-svn: 244478
2015-08-10 18:37:34 +00:00
Johannes Doerfert d6c30160e7 Make StmtSet a list.
With a deque (or any other sequential container) it is not sound to
  take the address of the elements when the container is still under
  construction. With a pointer based container this is save.

llvm-svn: 244459
2015-08-10 16:47:20 +00:00