Commit Graph

2199 Commits

Author SHA1 Message Date
Michael Kruse 054729b420 Add script to update isl
The script will checkout the most recent master from
http://repo.or.cz/isl.git into /tmp, create a distribution tarball, and
extract it as replacement of lib/External/isl. After that it can be
committed to the Polly repository.

llvm-svn: 254497
2015-12-02 09:34:46 +00:00
Tobias Grosser 2fd89da90d Remove non-debug printing of domain set
Contributed-by: Chris Jenneisch <chrisj@codeaurora.org>

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

llvm-svn: 254343
2015-11-30 22:59:41 +00:00
Tobias Grosser 3a6ac9f9b5 ScopInfo: Further simplify code
Acc==MA implies Acc->getAccessInstruction() == MA->getAccessInstruction().

Suggested as post-commit review for 254305 by Michael Kruse.

llvm-svn: 254327
2015-11-30 21:13:43 +00:00
Tobias Grosser ef9ca5db16 ScopInfo: Replace while/iterator construct with std::remove_if
The use of C++'s high-level iterator functionality instead of two while loops
and explicit iterator handling improves readability of this code.

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

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

llvm-svn: 254305
2015-11-30 17:20:40 +00:00
Michael Kruse 4c86a1d97b IR cleanup after CodeGeneration
Re-run canonicalization passes after Polly's code generation.

The set of passes currently added here are nearly all the passes between
--polly-position=early and --polly-position=before-vectorizer, i.e. all
passes that would usually run after Polly.

In order to run these only if Polly actually modified the code, we add a
function attribute "polly-optimzed" to a function that contains
generated code. The cleanup pass is skipped if the function does not
have this attribute.

There is no support by the (legacy) PassManager to run passes only under
some conditions. One could have wrapped all transformation passes to run
only when CodeGeneration changed the code, but the analyses would run
anyway. This patch creates an independent pass manager. The
disadvantages are that all analyses have to re-run even if preserved and
it does not honor compiler switches like the PassManagerBuilder does.

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

llvm-svn: 254150
2015-11-26 12:36:25 +00:00
Michael Kruse cba170e4d0 Introduce origin/kind for exit PHI node accesses
Previously, accesses that originate from PHI nodes in the exit block
were registered as SCALAR. In some context they are treated as scalars,
but it makes a difference in others. We used to check whether the
AccessInstruction is a terminator to differentiate the cases.

This patch introduces an MemoryAccess origin EXIT_PHI and a
ScopArrayInfo kind KIND_EXIT_PHI to make this case more explicit. No
behavioural change intended.

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

llvm-svn: 254149
2015-11-26 12:26:06 +00:00
Tobias Grosser 2f8e43d677 ScopInfo: Add support for delinearizing fortran arrays
gfortran (and fortran in general?) does not compute the address of an array
element directly from the array sizes (e.g., %s0, %s1), but takes first the
maximum of the sizes and 0 (e.g., max(0, %s0)) before multiplying the resulting
value with the per-dimension array subscript expressions. To successfully
delinearize index expressions as we see them in fortran, we first filter 'smax'
expressions out of the SCEV expression, use them to guess array size parameters
and only then continue with the existing delinearization.

llvm-svn: 253995
2015-11-24 17:06:38 +00:00
Tobias Grosser 4927c8e606 ScopInfo: Add option to ignore integer wrapping
llvm-svn: 253976
2015-11-24 12:50:02 +00:00
Tobias Grosser d68ba42556 ScopInfo: Split hasAffineMemoryAccesses() into multiple functions [NFC]
This makes the overall code more readable.

llvm-svn: 253951
2015-11-24 05:00:36 +00:00
Tobias Grosser 4745eb1aca Update format to match clang-format in trunk
llvm-svn: 253910
2015-11-23 20:04:04 +00:00
Tobias Grosser 5ef2bc316d Use SmallVector instead of std::vector
This was proposed as post-commit review comment for commit r253818.

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

llvm-svn: 253862
2015-11-23 10:18:23 +00:00
Tobias Grosser 9737c7b431 ScopInfo: Remove domains of error blocks (and blocks they dominate) early on
Trying to build up access functions for any of these blocks is likely to fail,
as error blocks may contain invalid/non-representable instructions, and blocks
dominated by error blocks may reference such instructions, which wil also cause
failures. As all of these blocks are anyhow assumed to not be executed, we can
just remove them early on.

This fixes http://llvm.org/PR25596

llvm-svn: 253818
2015-11-22 11:06:51 +00:00
Tobias Grosser 020fa09a3c Remove -polly-code-generator=isl from many test cases
This is the default since a long time. Setting it again does not add value
in any of these test cases.

llvm-svn: 253800
2015-11-21 23:05:48 +00:00
Tobias Grosser fb3fb0a309 isl: Update to isl-0.15-136-g4d5654a
The most interesting change for Polly in this isl update is 4d5654af which
in certain cases can speed up the construction of run-time checks from an isl
set consisting of several disjuncts significantly.

llvm-svn: 253794
2015-11-21 20:48:39 +00:00
Johannes Doerfert a2a74f09fc Do not enforce lcssa
At some point we enforced lcssa for the loop surrounding the entry block.
  This is not only questionable as it does not check any other loop but also
  not needed any more.

llvm-svn: 253789
2015-11-21 17:00:02 +00:00
Johannes Doerfert dec27df588 [FIX] Get the correct loop that surrounds a region
llvm-svn: 253788
2015-11-21 16:56:13 +00:00
Tobias Grosser b39c96aa19 ScopInfo: Ensure unique names for parameter names coming from load instructions
In case the original parameter instruction does not have a name, but it comes
from a load instruction where the base pointer has a name we used the name of
the load instruction to give some more intuition of where the parameter came
from. To ensure this works also through GEPs which may have complex offsets,
we originally just dropped the offsets and _only_ used the base pointer name.
As this can result in multiple parameters to get the same name, we now prefix
the parameter ID to ensure parameter names are unique. This will make it easier
to understand debug output.

This change does not affect correctness, as parameter IDs (even of the same
name) can always be distinguished through the SCEV pointer stored inside them.

llvm-svn: 253330
2015-11-17 11:54:51 +00:00
Tobias Grosser f920fb19f1 ScopInfo: Reset compute operations before starting compute out region
Without this change we may start to refuse scops in larger compilation units
just because a lot of code has already been compiled earlier.

Found by inspection. I do not yet have a good test case for this.

llvm-svn: 253050
2015-11-13 16:56:13 +00:00
Johannes Doerfert a4b77c079b [FIX] Bail if access function is not divisible by element size.
llvm-svn: 252942
2015-11-12 20:15:32 +00:00
Johannes Doerfert 55b3d8b831 Consistenly use getTypeAllocSize for size estimation.
Only when we check for wrapping we want to use the store size, for all
  other cases we use the alloc size now.

Suggested by: Tobias Grosser <tobias@grosser.es>

llvm-svn: 252941
2015-11-12 20:15:08 +00:00
Tobias Grosser 2ac2338a03 ScopInfo: Add function to retrieve all memory accesses in a scop
llvm-svn: 252894
2015-11-12 14:07:13 +00:00
Tobias Grosser e5a3514e4a ScopInfo: Use lambda functions to reduce code duplication.
llvm-svn: 252893
2015-11-12 14:07:09 +00:00
Tobias Grosser bc29e0b27c RegionGenerator: Only introduce subregion.ivs for loops fully within a subregion
IVs of loops for which the loop header is in the subregion, but not the entire
loop may be incremented outside of the subregion and can consequently not be
kept private to the subregion. Instead, they need to and are modeled as virtual
loops in the iteration domains. As this is the case, generating new subregion
induction variables for such loops is not needed and indeed wrong as they would
hide the virtual induction variables modeled in the scop.

This fixes a miscompile in MultiSource/Benchmarks/Ptrdist/bc and
MultiSource/Benchmarks/nbench/. Thanks Michael and Johannes for their
investiagations and helpful observations regarding this bug.

llvm-svn: 252860
2015-11-12 07:34:09 +00:00
Johannes Doerfert 2af10e2eed Use parameter constraints provided via llvm.assume
If an llvm.assume dominates the SCoP entry block and the assumed condition
  can be expressed as an affine inequality we will now add it to the context.

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

llvm-svn: 252851
2015-11-12 03:25:01 +00:00
Johannes Doerfert d84493e52e Emit remarks for taken assumptions
Differential Revision: http://reviews.llvm.org/D14412

llvm-svn: 252848
2015-11-12 02:33:38 +00:00
Johannes Doerfert 0cf4e0aa42 Emit remark about aliasing pointers
llvm-svn: 252847
2015-11-12 02:32:51 +00:00
Johannes Doerfert 48fe86f1ff Emit SCoP source location as remark during ScopInfo
This removes a similar feature from ScopDetection, though with
  -polly-report that feature present twice anyway.

llvm-svn: 252846
2015-11-12 02:32:32 +00:00
Johannes Doerfert fdbf201fc9 [FIX] Do not generate code for parameters referencing dead values
Check if a value that is referenced by a parameter is dead and do not
generate code for the parameter in such a case.

llvm-svn: 252813
2015-11-11 22:40:51 +00:00
Tobias Grosser e19fca4525 ScopInfo: Bailing out means assigning isl_set_empty to the AssumedContext
I got this the other way around in 252750. Thank you Johannes for noticing.

llvm-svn: 252795
2015-11-11 20:21:39 +00:00
Tobias Grosser 910cf26811 ScopInfo: Do not try to model the memory accesses in an error block
Error blocks may contain arbitrary instructions, among them some which we can
not modeled correctly. As we do not generate ScopStmts for error blocks anyhow
there is no point in trying to generate access functions for them.

This fixes llvm.org/PR25494

llvm-svn: 252794
2015-11-11 20:15:49 +00:00
Johannes Doerfert 9d7899ef9c [NFC] Simplify code
llvm-svn: 252792
2015-11-11 20:01:31 +00:00
Tobias Grosser 316b5b2507 ScopInfo: Remove unused return value [NFC]
llvm-svn: 252780
2015-11-11 19:28:14 +00:00
Tobias Grosser a52b4da039 ScopInfo: Free set after compute out has been triggered
In certain cases isl will not free the return values of operations for which
a computeout has been triggered. Hence, make sure we free it explicitly.

No test, as I did not manage to reduce one yet.

llvm-svn: 252766
2015-11-11 17:59:53 +00:00
Tobias Grosser 4cd07b1188 ScopInfo: Bound compute time spent in boundary context construction
For complex inputs our current approach of construction the boundary context
may in rare cases become computationally so expensive that it is better to
abort. This change adds a compute out check that bounds the compuations we
spend on boundary context construction and bails out if this limit is reached.

We can probably make our boundary construction algorithm more efficient, but
this requires some more investigation and probably also some additional changes
to isl. Until these have been added, we bound the compile time to ensure our
buildbots are green.

llvm-svn: 252758
2015-11-11 17:34:02 +00:00
Tobias Grosser 20a4c0c205 ScopInfo: Limit the number of disjuncts in assumed context
In certain rare cases (mostly -polly-process-unprofitable on large sequences
of conditions - often without any loop), we see some compile-time timeouts due
to the construction of an overly complex assumption context. This change limits
the number of disjuncts to 150 (adjustable), to prevent us from creating
assumptions contexts that are too large for even the compilation to finish.

The limit has been choosen as large as possible to make sure we do not
unnecessarily drop test coverage. If such cases also appear in
-polly-process-unprofitable=false mode we may need to think about this again,
as the current limitations may still allow assumptions that are way to complex
to be checked profitably at run-time.

There is also certainly room for improvement regarding how (and how efficient)
we construct an assumed context, but this requires some more thinking.

This completes llvm.org/PR25458

llvm-svn: 252750
2015-11-11 16:22:36 +00:00
Tobias Grosser e3d1f1c0b0 ScopDetection: Tighten the check for always executed 'error blocks'
Basic blocks that are always executed can not be error blocks as their execution
can not possibly be an unlikely event. In this commit we tighten the check
if an error block to basic blcoks that do not dominate the exit condition, but
that dominate all exiting blocks of the scop.

llvm-svn: 252726
2015-11-11 13:25:13 +00:00
Tobias Grosser b12b006c4b ScopDetection: Do not allow blocks to reference operands in error blocks
r252713 introduced a couple of regressions due to later basic blocks refering
to instructions defined in error blocks which have not yet been modeled.

This commit is currently just encoding limitations of our modeling and code
generation backends to ensure correctness. In theory, we should be able to
generate and optimize such regions, as everything that is dominated by an error
region is assumed to not be executed anyhow. We currently just lack the code
to make this happen in practice.

llvm-svn: 252725
2015-11-11 12:44:18 +00:00
Tobias Grosser 56e3fefbdc test: Shorten test case to reduce 'make polly-check' time
Thinking more about the last commit I came to realize that for testing the
new functionality it is sufficient to verify that the iteration domains
we construct for a simple test case do not contain any of the complexity that
caused compile time issues for larger inputs.

llvm-svn: 252714
2015-11-11 09:19:15 +00:00
Tobias Grosser b76cd3cc56 ScopInfo: Pass domain constraints through error blocks
Previously, we just skipped error blocks during scop construction. With
this change we make sure we can construct domains for error blocks such that
these domains can be forwarded to subsequent basic blocks.

This change ensures that basic blocks that post-dominate and are dominated by
a basic block that branches to an error condition have the very same iteration
domain as the branching basic block. Before, this change we would construct
a domain that excludes all error conditions. Such domains could become _very_
complex and were undesirable to build.

Another solution would have been to drop these constraints using a
dominance/post-dominance check instead of modeling the error blocks. Such
a solution could also work in case of unreachable statements or infinite
loops in the scop. However, as we currently (to my believe incorrectly) model
unreachable basic blocks in the post-dominance tree, such a solution is not
yet feasible and requires first a change to LLVM's post-dominance tree
construction.

This commit addresses the most sever compile time issue reported in:
http://llvm.org/PR25458

llvm-svn: 252713
2015-11-11 08:42:20 +00:00
Johannes Doerfert dcfedf3505 [FIX] Cast pre-loaded values correctly or reload them with adjusted type.
Especially for structs, the SAI object of a base pointer does not
describe all the types that the user might expect when he loads from
that base pointer. While we will still cast integers and pointers we
will now reload the value with the correct type if floating point and
non-floating point values are involved. However, there are now TODOs
where we use bitcasts instead of a proper conversion or reloading.

This fixes bug 25479.

llvm-svn: 252706
2015-11-11 06:20:25 +00:00
Johannes Doerfert fc4bfc465a [FIX] Create empty invariant equivalence classes
We now create all invariant equivalence classes for required invariant loads
  instead of creating them on-demand. This way we can check if a parameter
  references an invariant load that is actually not executed and was therefor
  not materialized. If that happens the parameter is not materialized either.

This fixes bug 25469.

llvm-svn: 252701
2015-11-11 04:30:07 +00:00
Tobias Grosser 6abc75af4c ScopInfo: Introduce ArrayKind
Since 252422 we do not only distinguish two ScopArrayInfo kinds, PHI nodes
and others, but work with three kind of ScopArrayInfo objects. SCALAR, PHI and
ARRAY objects. Instead of keeping two boolean flags isPHI and isScalar and
wonder what an ScopArrayInfo object of kind (!isScalar && isPHI) is, we
list now explicitly the three different possible types of memory objects.

This change also allows us to remove the confusing nested pairs that have
been used in ArrayInfoMapTy.

llvm-svn: 252620
2015-11-10 17:31:31 +00:00
Tobias Grosser 8b05278b4e tests: Add test that has a single pointer both as scalar read and array base
In case we also model scalar reads it can happen that a pointer appears in both
a scalar read access as well as the base pointer of an array access. As this
is a little surprising, we add a specific test case to document this behaviour.
To my understanding it should be OK to have a read from an array A[] and
read/write accesses to A[...]. isl is treating these arrays as unrelated as
their dimensionality differs. This seems to be correct as A[] remains constant
throughout the execution of the scop and is not affected by the reads/writes to
A[...]. If this causes confusion, it might make sense to make this behaviour
more obvious by using different names (e.g., A_scalar[], A[...]).

llvm-svn: 252615
2015-11-10 16:23:30 +00:00
Tobias Grosser 98e566e213 Simplify test case
Commit r252422 introduced an unnecessary complicated test case. Reduce it to
the part that actually triggered the original issue.

llvm-svn: 252611
2015-11-10 15:42:44 +00:00
Tobias Grosser b43cc62fe1 stringFromIslObj: Do not crash when printing 'null' objects
No test case, as this code path is currently only used for debugging.

llvm-svn: 252609
2015-11-10 15:09:44 +00:00
Tobias Grosser 262538435f ScopInfo: Make getDimensionSize better reflect which dimensions carry sizes
In polly the first dimensions of an array as well as all scalars do not carry
any size information. This commit makes this explicit in the interface of
getDimensionSize. Before this commit getDimensionSize(0) returned the size of
the first dimension that carried a size. After this commit getDimensionSize(i)
will either return the size of dimension 'i' or assert in case 'i' does not
carry a size or does not exist at all.

This very same behaviour was already present in getDimensionSizePw(). This
commit also adds assertions that ensure getDimensionSizePw() is called
appropriately.

llvm-svn: 252607
2015-11-10 14:24:21 +00:00
Tobias Grosser 4ea2e07a60 ScopInfo: Make printing of ScopArrayInfo more similar to declarations in C
Memory references are now printed as follows:

           Old                          New
Scalars:   i64 MemRef_val[*]            i64 MemRef_val;
Arrays:    i64 MemRef_A[*][%m][%o][8]   i64 MemRef_A[*][%m][%o];

We do not print any more information about the element size in the type. Such
information has already been available in a comment after the scalar/array
declaration. It was redundant and did not match well with what people were used
from C.

llvm-svn: 252602
2015-11-10 14:02:54 +00:00
Michael Kruse c993739e0d Fix non-affine generated entering node not being recognized as dominating
Scalar reloads in the generated entering block were not recognized as
dominating the subregions locks when there were multiple entering
nodes. This resulted in values defined in there not being copied.

As a fix, we unconditionally add the BBMap of the generated entering
node to the generated entry. This fixes part of llvm.org/PR25439.

This reverts 252449 and reapplies r252445. Its test was failing
indeterministically due to r252375 which was reverted in r252522.

llvm-svn: 252540
2015-11-09 23:33:40 +00:00
Michael Kruse d6fb6f1b0c Fix dominance when subregion exit is outside scop
The dominance of the generated non-affine subregion block was based on
the scop's merge block, therefore resulted in an invalid DominanceTree.
It resulted in some values as assumed to be unusable in the actual
generated exit block.

We detect the case that the exit block has been moved and decide
dominance using the BB at the original exit. If we create another exit
node, that exit nodes is dominated by the one generated from where the
original exit resides. This fixes llvm.org/PR25438 and part of
llvm.org/PR25439.

llvm-svn: 252526
2015-11-09 23:07:38 +00:00
Michael Kruse ebffcbeefa Revert r252375 "Fix non-affine region dominance of implicitely stored values"
It introduced indeterminism as it was iterating over an address-indexed
hashtable. The corresponding bug PR25438 will be fixed in a successive
commit.

llvm-svn: 252522
2015-11-09 22:37:29 +00:00
Johannes Doerfert 7a6e292d86 [FIX] Use same alloca for invariant loads and the scalar users
llvm-svn: 252451
2015-11-09 06:28:45 +00:00
Johannes Doerfert 544b23a1ef Revert "Fix non-affine generated entering node not being recognized as dominating"
This reverts commit 9775824b265e574fc541e975d64d3e270243b59d due to a
failing unit test.

Please check and correct the unit test and commit again.

llvm-svn: 252449
2015-11-09 06:04:05 +00:00
Michael Kruse fd9c89e84b Fix non-affine generated entering node not being recognized as dominating
Scalar reloads in the generated entering block were not recognized as
dominating the subregions locks when there were multiple entering
nodes. This resulted in values defined in there not being copied.

As a fix, we unconditionally add the BBMap of the generated entering
node to the generated entry. This fixes part of llvm.org/PR25439.

llvm-svn: 252445
2015-11-09 05:00:30 +00:00
Johannes Doerfert 188542fda9 [FIX] Initialize incoming scalar memory locations for PHIs
llvm-svn: 252437
2015-11-09 00:21:21 +00:00
Johannes Doerfert 80c716df2b [NFC] Remove unused variable.
llvm-svn: 252436
2015-11-09 00:21:04 +00:00
Johannes Doerfert f85ad0411f [FIX] Carefully simplify assumptions in the presence of error blocks
If a SCoP contains error blocks we cannot use the domain constraints
  to simplify the assumptions as the domain is already influenced by the
  assumptions we took. Before this patch we did that and some assumptions
  became self-fulfilling as they were implied by the domain constraints.

llvm-svn: 252424
2015-11-08 20:16:39 +00:00
Johannes Doerfert a768624f14 [FIX] Introduce different SAI objects for scalar and memory accesses
Even if a scalar and memory access have the same base pointer, we cannot use
  one SAI object as the type but also the number of dimensions are wrong. For
  the attached test case this caused a crash in the invariant load hoisting,
  though it could cause various other problems too.

This fixes bug 25428 and a execution time bug in MallocBench/cfrac.

Reported-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
llvm-svn: 252422
2015-11-08 19:12:05 +00:00
Johannes Doerfert 3797707695 [FIX] Use unreachable to indicate dead code and repair dominance
When we bail out early we make the partially build new code path
  practically dead, though it was not unreachable. To remove dominance
  problems we now make it not only dead but also prevent the control
  flow to join with the original code path, thus allow to use original
  values after the SCoP without any PHI nodes.

This fixes bug 25447.

llvm-svn: 252420
2015-11-08 17:57:41 +00:00
Johannes Doerfert 1dd6e37af4 Verify IR after we bail out
The bail out in r252412 left the code generation without verifying the (so
  far) generated IR. This will change now and ensure we always run the
  verifier.

Suggested-by: Tobias Grosser <tobias@grosser.es>
llvm-svn: 252419
2015-11-08 16:34:17 +00:00
Johannes Doerfert c4898504ea [FIX] Bail out if there is a dependence cycle between invariant loads
While the program cannot cause a dependence cycle between invariant
  loads, additional constraints (e.g., to ensure finite loops) can
  introduce them. It is hard to detect them in the SCoP description,
  thus we will only check for them at code generation time. If such a
  recursion is detected we will bail out the code generation and place a
  "false" runtime check to guarantee the original code is used.

  This fixes bug 25443.

llvm-svn: 252412
2015-11-07 19:46:04 +00:00
Johannes Doerfert 44483c5599 [FIX] Remove all invariant load occurences from own execution context
llvm-svn: 252411
2015-11-07 19:45:27 +00:00
Michael Kruse 0651480b97 Fix non-affine region dominance of implicitely stored values
After loop versioning, a dominance check of a non-affine subregion's
exit node causes the dominance check to always fail on any block in the
subregion if it shares the same exit block with the scop. The
subregion's exit block has become polly_merge_new_and_old, which also
receives the control flow of the generated code. This would cause that
any value for implicit stores is assumed to be not from the scop.

We check dominance with the generated exit node instead.

This fixes llvm.org/PR25438

llvm-svn: 252375
2015-11-07 00:36:50 +00:00
Duncan P. N. Exon Smith b8f58b53dd polly/ADT: Remove implicit ilist iterator conversions, NFC
Remove all the implicit ilist iterator conversions from polly, in
preparation for making them illegal in ADT.  There was one oddity I came
across: at line 95 of lib/CodeGen/LoopGenerators.cpp, there was a
post-increment `Builder.GetInsertPoint()++`.

Since it was a no-op, I removed it, but I admit I wonder if it might be
a bug (both before and after this change)?  Perhaps it should be a
pre-increment?

llvm-svn: 252357
2015-11-06 22:56:54 +00:00
Tobias Grosser 712229ec59 Add missing '%loadPolly' to test case
llvm-svn: 252302
2015-11-06 14:03:35 +00:00
Michael Kruse ddb6528ba6 Fix reuse of non-dominating synthesized value in subregion exit
We were adding all generated values in non-affine subregions to be used
for the subregions generated exit block. The thought was that only
values that are dominating the original exit block can be used there.
But it is possible for synthesizable values to be expanded in any
block. If the same values is also used for implicit writes, it would
try to reuse already synthesized values even if not dominating the exit
block.

The fix is to only add values to the list of values usable in the exit
block only if it is dominating the exit block. This fixes
llvm.org/PR25412.

llvm-svn: 252301
2015-11-06 13:51:24 +00:00
Tobias Grosser 6578f001bf Adjust debug metadata to LLVM changes in 252219
llvm-svn: 252273
2015-11-06 06:27:39 +00:00
Tobias Grosser f1bfd75221 ScopInfo: Allocate globally unique memory access identifiers
Before this commit memory reference identifiers have only been unique per
basic block, but not per (non-affine) ScopStmt. This commit now uses the
MemoryAccess base pointer to uniquely identify each Memory access.

llvm-svn: 252200
2015-11-05 20:15:37 +00:00
Tobias Grosser 4bf262a0f2 RunTimeDebugBuilder: Allocate memory _after_ knowing how much is needed
This fixes a memory corruption issue, where we accessed more memory than
actually allocated.

llvm-svn: 252197
2015-11-05 19:43:34 +00:00
Michael Kruse 27149cf32d Use per-BB value maps for non-exit BBs
For generating scalar writes of non-affine subregions, all except phi
writes are generated in the exit block. The phi writes are generated in
the incoming block for which we errornously used the same BBMap. This
can conflict if a value for one block is synthesized, and then reused
for another block which is not dominated by the first block. This is
fixed by using block-specific BBMaps for phi writes.

llvm-svn: 252172
2015-11-05 16:17:17 +00:00
Michael Kruse f714d470d7 Fix escaping value to subregion entry node phi
An incoming value from a block the is not inside the scop is an
external use, even if the phi is inside the scop. A previous fix in
r251208 did not apply if the phi is inside a non-affine subregion. We
move the check for this phi case before the non-affine subregion check.

llvm-svn: 252157
2015-11-05 13:18:43 +00:00
Johannes Doerfert 22892687f7 [FIX] Simplify and correct preloading of base pointer origin
To simplify and correct the preloading of a base pointer origin, e.g.,
  the base pointer for the current indirect invariant load, we now just
  check if there is an invariant access class that involves the base
  pointer of the current class.

llvm-svn: 251962
2015-11-03 19:15:33 +00:00
Johannes Doerfert eca9e890b9 Remove read-only statements from the SCoP
We do not need to model read-only statements in the SCoP as they will
  not cause any side effects that are visible to the outside anyway.
  Removing them should safe us time and might even simplify the ASTs we
  generate.

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

llvm-svn: 251948
2015-11-03 16:54:49 +00:00
Johannes Doerfert e071f6d637 [NFC] Name invariant load parameters after base pointer
This just makes the debug output nices sometimes.

llvm-svn: 251947
2015-11-03 16:49:59 +00:00
Johannes Doerfert 475d8e3f42 [FIX] Ensure base pointer origin was preloaded already
If a base pointer of a preloaded value has a base pointer origin, thus it is
  an indirect invariant load, we have to make sure the base pointer origin is
  preloaded first.

llvm-svn: 251946
2015-11-03 16:49:02 +00:00
Johannes Doerfert d6fc0701ee [FIX] Carefully rewrite parameters wrt. invariant equivalence classes
ScalarEvolution doesn't allow the operands of an AddRec to be variant in the
  loop of the AddRec. When we rewrite parameter SCEVs it might seem like the
  new SCEV violates this property and ScalarEvolution will trigger an
  assertion. To avoid this we move the start part out of an AddRec when we
  rewrite it, thus avoid the operands to be possibly variant completely.

llvm-svn: 251945
2015-11-03 16:47:58 +00:00
Johannes Doerfert 3181c2ef72 [FIX] Correctly update SAI base pointer
If a base pointer load is preloaded, we have change the base pointer of
  the derived SAI. However, as the derived SAI relationship is is
  coarse grained, we need to check if we actually preloaded the base
  pointer or a different element of the base pointer SAI array.

llvm-svn: 251881
2015-11-03 01:42:59 +00:00
Johannes Doerfert dca2837b76 [FIX] Do not crash in the presence of infinite loops.
llvm-svn: 251870
2015-11-03 00:28:07 +00:00
Johannes Doerfert 907456fe04 [FIX] Use appropriately sized types for big constants
llvm-svn: 251869
2015-11-03 00:26:22 +00:00
Tobias Grosser 8286b83f97 ScopInfo: Bail out in case of mismatching array dimension sizes
In some cases different memory accesses access the very same array using a
different multi-dimensional array layout where the same dimensions have
different sizes. Instead of asserting when encountering this issue, we
gracefully bail out for this scop.

This fixes llvm.org/PR25252

llvm-svn: 251791
2015-11-02 11:29:32 +00:00
Tobias Grosser f423c1200f Remove old and redundant options
We remove -polly-detect-unprofitable and -polly-no-early-exit. Both have been
superseeded by -polly-process-unprofitable and were only kept as aliases for
our buildbots to continue to work. As all buildbots have been moved to the new
options, we can now remove the old ones for good.

llvm-svn: 251787
2015-11-02 10:13:32 +00:00
Tobias Grosser 3e9560200f RegionGenerator: Clear local maps after statement construction
These maps are only needed during the construction of a single region statement.
Clearing them is important, as we otherwise get an assert in case some of the
referenced values are erased before the RegionGenerator is deleted.

llvm-svn: 251341
2015-10-26 20:41:53 +00:00
Tobias Grosser 4dc909cbed tests: Add test cases for LLVM commit r251267
This fixes llvm.org/PR25242

llvm-svn: 251268
2015-10-25 22:56:42 +00:00
Tobias Grosser bf45e74254 ScopDetect: Bail out for non-simple memory accesses
Volatile or atomic memory accesses are currently not supported. Neither did
we think about any special handling needed nor do we support the unknown
instructions the alias set tracker turns them into sometimes. Before this
patch, us not supporting unkown instructions in an alias set caused the
following assertion failures:

Assertion `AG.size() > 1 && "Alias groups should contain at least two accesses"'
failed

llvm-svn: 251234
2015-10-25 13:48:40 +00:00
Tobias Grosser 27e19a022e Fix typo
llvm-svn: 251231
2015-10-25 12:05:14 +00:00
Tobias Grosser 4d935cd9aa tests: Add test case forgotten in 251191
llvm-svn: 251228
2015-10-25 10:55:40 +00:00
Tobias Grosser 907090c37c ScopDetection: Update DetectionContextMap accordingly
When verifying if a scop is still valid we rerun all analysis, but did not
update DetectionContextMap. This change ensures that information, e.g. about
non-affine regions, is correctly updated

llvm-svn: 251227
2015-10-25 10:55:35 +00:00
Tobias Grosser 51174cca30 ScopDetection: Do not crash if we find zero array size candidates for delinearization
llvm-svn: 251226
2015-10-25 08:40:44 +00:00
Tobias Grosser 5528dcdf25 ScopDetection: Always refuse multi-dimensional memory accesses with 'undef' in
the size expression.

We previously only checked if the size expression is 'undef', but allowed size
expressions of the form 'undef * undef' by accident. After this change we now
require size expressions to be affine which implies no 'undef' appears anywhere
in the expression.

llvm-svn: 251225
2015-10-25 08:40:38 +00:00
Tobias Grosser baffa091dd ScopInfo: PHI-node uses in the EntryNode with an incoming BB that is not part
of the Region are external.

During code generation we split off the parts of the PHI nodes in the entry
block, which have incoming blocks that are not part of the region. As these
split-off PHI nodes then are external uses, we consequently also need to model
these uses in ScopInfo.

llvm-svn: 251208
2015-10-24 20:55:27 +00:00
Tobias Grosser ffd6b3bb29 Add a missing '-S'
llvm-svn: 251199
2015-10-24 19:02:01 +00:00
Tobias Grosser a3f6edaee1 BlockGenerator: Do not assert when finding model PHI nodes defined outside the scop
Such PHI nodes can not only appear in the ExitBlock of the Scop, but indeed
any scalar PHI node above the scop and used in the scop is modeled as scalar
read access.

llvm-svn: 251198
2015-10-24 19:01:09 +00:00
Tobias Grosser 27d742da59 BlockGenerator: Directly handle multi-exit PHI nodes
This change adds code to directly code-generate multi-exit PHI nodes, instead
of trying to reuse the EscapeMap infrastructure for this. Using escape maps
adds a level of indirection that is hard to understand and - more importantly -
breaks in certain cases.

Specifically, the original code relied on simplifyRegion() to split the original
PHI node in two PHI nodes, one merging the values coming from within the scop
and a second that merges the first PHI node with the values that come from
outside the scop. To generate code the first PHI node is then just handled like
any other in-scop value that is used somewhere outside the scop. This fails for
the case where all values from inside the scop are identical, as the first PHI
node is in such cases automatically simplified and eliminated by LLVM right at
construction. As a result, there is no instruction that can be pass to the
EscapeMap handling, which means the references in the second PHI node are not
updated and may still reference values from within the original scop that do not
dominate it.

Our new code iterates directly over all modeled ScopArrayInfo objects that
represent multi-exit PHI nodes and generates code for them without relying on
the EscapeMap infrastructure. Hence, it works also for the case where the first
PHI node is eliminated.

llvm-svn: 251191
2015-10-24 17:41:29 +00:00
Tobias Grosser c73d8b0e18 ScopInfo: Drop unnecessary code
This case has already been taken care of in r250622 and was then accidentally
again committed in 250625.

llvm-svn: 251156
2015-10-23 22:36:22 +00:00
Johannes Doerfert 654c3284f4 [FIX] Do not hoist nested variant base pointers
This fixes bug 25249.

llvm-svn: 250958
2015-10-21 22:14:57 +00:00
Tobias Grosser ca7f5bb767 Full/partial tile separation for vectorization
We isolate full tiles from partial tiles to be able to, for example, vectorize
loops with parametric lower and/or upper bounds.

If we use -polly-vectorizer=stripmine, we can see execution-time improvements:
correlation from 1m7361s to 0m5720s (-67.05 %), covariance from 1m5561s to
0m5680s (-63.50 %), ary3 from 2m3201s to 1m2361s (-46.72 %), CrystalMk from
8m5565s to 7m4285s (-13.18 %).

The current full/partial tile separation increases compile-time more than
necessary. As a result, we see in compile time regressions, for example, for 3mm
from 0m6320s to 0m9881s (56.34%). Some of this compile time increase is expected
as we generate more IR and consequently more time is spent in the LLVM backends.
However, a first investiagation has shown that a larger portion of compile time
is unnecessarily spent inside Polly's parallelism detection and could be
eliminated by propagating existing knowledge about vector loop parallelism.
Before enabling -polly-vectorizer=stripmine by default, it is necessary to
address this compile-time issue.

Contributed-by: Roman Gareev <gareevroman@gmail.com>

Reviewers: jdoerfert, grosser

Subscribers: grosser, #polly

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

llvm-svn: 250809
2015-10-20 09:12:21 +00:00
Michael Kruse 48ea8efd59 Correct typo in CHECK line
Thanks Tobias for the hint.

llvm-svn: 250695
2015-10-19 10:51:20 +00:00
Michael Kruse dc12222287 Synthesize phi arguments in incoming block
New values were always synthesized in the block of the instruction
that needed them. This is incorrect for PHI node whose' value must be
defined in the respective incoming block. This patch temporarily moves
the builder's insert point to the incoming block while synthesizing phi
node arguments. 

This fixes PR25241 (http://llvm.org/bugs/show_bug.cgi?id=25241)

llvm-svn: 250693
2015-10-19 09:19:25 +00:00
Johannes Doerfert 9c28bfa72c [FIX] Only constant integer branch conditions are always affine
There are several different kinds of constants that could occur in a
  branch condition, however we can only handle the most interesting one
  namely constant integers. To this end we have to treat others as
  non-affine.

  This fixes bug 25244.

llvm-svn: 250669
2015-10-18 22:56:42 +00:00
Johannes Doerfert 30c2265f98 [FIX] Normalize loops outside the SCoP during schedule generation
We build the schedule based on a traversal of the region and accumulate
  information for each loop in it. The total schedule is associated with the
  loop surrounding the SCoP, though it can happen that there are blocks in the
  SCoP which are part of loops that are only partially in the SCoP. Instead of
  associating information with them (they are not part of the SCoP and
  consequently are not modeled) we have to associate the schedule information
  with the surrounding loop if any.

  This fixes bug 25240.

llvm-svn: 250668
2015-10-18 21:17:11 +00:00
Johannes Doerfert b864c2c3c9 [FIX] Do not try to hoist "empty" accesses
Accesses that have a relative offset (in bytes) that is not divisible
  by the type size (in bytes) will be represented as empty in the SCoP
  description. This is on its own not good but it also crashed the
  invariant load hoisting. This patch will fix the latter problem while
  the former should be addressed too.

  This fixes bug 25236.

llvm-svn: 250664
2015-10-18 19:50:18 +00:00
Johannes Doerfert bc7cff4c18 [FIX] Do not hoist invariant pointers with non-loaded base ptr in SCoP
If the base pointer of a load is invariant and defined in the SCoP but
  not loaded we cannot hoist the load as we would not hoist the base
  pointer definition.

  This fixes bug 25237.

llvm-svn: 250663
2015-10-18 19:49:25 +00:00
Johannes Doerfert af3e301a67 [FIX] Restructure invariant load equivalence classes
Sorting is replaced by a demand driven code generation that will pre-load a
  value when it is needed or, if it was not needed before, at some point
  determined by the order of invariant accesses in the program. Only in very
  little cases this demand driven pre-loading will kick in, though it will
  prevent us from generating faulty code. An example where it is needed is
  shown in:
    test/ScopInfo/invariant_loads_complicated_dependences.ll

  Invariant loads that appear in parameters but are not on the top-level (e.g.,
  the parameter is not a SCEVUnknown) will now be treated correctly.

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

llvm-svn: 250655
2015-10-18 12:39:19 +00:00
Johannes Doerfert d8b6ad255f [FIX] Cast preloaded values
Preloaded values have to match the type of their counterpart in the
  original code and not the type of the base array.

llvm-svn: 250654
2015-10-18 12:36:42 +00:00
Johannes Doerfert 01978cfa0c Remove independent blocks pass
Polly can now be used as a analysis only tool as long as the code
  generation is disabled. However, we do not have an alternative to the
  independent blocks pass in place yet, though in the relevant cases
  this does not seem to impact the performance much. Nevertheless, a
  virtual alternative that allows the same transformations without
  changing the input region will follow shortly.

llvm-svn: 250652
2015-10-18 12:28:00 +00:00
Tobias Grosser b8d27aab7d Revert to original BlockGenerator::getOrCreateAlloca(MemoryAccess &Access)
Expressing this in terms of BlockGenerator::getOrCreateAlloca(const
ScopArrayInfo *Array) does not work as the MemoryAccess BasePtr is in case of
invariant load hoisting different to the ScopArrayInfo BasePtr. Until this is
investigated and fixed, we move back to code that just uses the baseptr of
MemoryAccess.

llvm-svn: 250637
2015-10-18 00:51:13 +00:00
Tobias Grosser a4f0988df5 BlockGenerator: Add getOrCreateAlloca(const ScopArrayInfo *Array)
This allows the caller to get the alloca locations of an array without the
need to thank if Array is a PHI or a non-PHI Array. We directly make use of this
in BlockGenerator::getOrCreateAlloca(MemoryAccess &Access).

llvm-svn: 250628
2015-10-17 22:16:00 +00:00
Michael Kruse 8c1e5ec86a Return nullptr if MemoryAccess list is empty
Other places (e.g. hoistInvariantLoads) assume that an empty lookup
will return nullptr. The situation can currently not arise because
MemoryAccesses are not removed before hoistInvariantLoads.

llvm-svn: 250627
2015-10-17 22:11:07 +00:00
Tobias Grosser 05d7fa79b6 Format comment properly
While clang-format takes care that the line-length is not surpassed, the
resulting comments sometimes look not optimal. We re-flow the text in the
comment to avoid these ugly single-word lines.

llvm-svn: 250626
2015-10-17 21:46:28 +00:00
Michael Kruse 225f0d1ee2 Load/Store scalar accesses before/after the statement itself
Instead of generating implicit loads within basic blocks, put them 
before the instructions of the statment itself, including non-affine 
subregions. The region's entry node is dominating all blocks in the 
region and therefore the loaded value will be available there.

Implicit writes in block-stmts were already stored back at the end of 
the block. Now, also generate the stores of non-affine subregions when 
leaving the statement, i.e. in the exiting block.

This change is required for array-mapped implicits ("De-LICM") to 
ensure that there are no dependencies of demoted scalars within 
statments. Statement load all required values, operator on copied in 
registers, and then write back the changed value to the demoted memory. 
Lifetimes analysis within statements becomes unecessary.

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

llvm-svn: 250625
2015-10-17 21:36:00 +00:00
Michael Kruse 01cb379fed Avoid unnecessay .s2a write access when used only in PHIs
Accesses for exit node phis will be handled separately by 
buildPHIAccesses if there is more than one exiting edge, 
buildScalarDependences does not need to create additional SCALAR 
accesses.

This is a corrected version of r250517, which was reverted in r250607.

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

llvm-svn: 250622
2015-10-17 21:07:08 +00:00
Tobias Grosser ffa2446f28 BlockGenerator: Register outside users of scalars directly
Instead of checking at code generation time for each ScopStmt if a scalar has
external uses, we just iterate over the ScopArrayInfo descriptions we have and
check each of these for possible external uses.

Besides being somehow clearer, this approach has the benefit that we will always
create valid LLVM-IR even in case we disable the code generation of ScopStmt
bodies e.g. for testing purposes.

llvm-svn: 250608
2015-10-17 08:54:13 +00:00
Tobias Grosser 3839b422e6 Revert "Avoid unnecessay .s2a write access when used only in PHIs"
This reverts commit r250606 due to some bugs it introduced. After these bugs
have been resolved, we will add it back to tree.

llvm-svn: 250607
2015-10-17 08:54:05 +00:00
Tobias Grosser 26e59ee746 Drop unused parameter from handleOutsideUsers
llvm-svn: 250606
2015-10-17 08:25:54 +00:00
Michael Kruse e71893d580 Add testcase for r250517
llvm-svn: 250518
2015-10-16 15:17:26 +00:00
Michael Kruse aeceab770e Avoid unnecessay .s2a write access when used only in PHIs
PHI accesses will be handled separately by buildPHIAccesses,
buildScalarDependences does not need to create additional accesses.

llvm-svn: 250517
2015-10-16 15:14:40 +00:00
Tobias Grosser b860289dbd Add ScopInfo test case for r250411
llvm-svn: 250439
2015-10-15 18:26:06 +00:00
Tobias Grosser 473a5c3253 test: Correctly check for branch statements
In r250408 'CHECK-NEXT: br' lines were removed as they also matched a
'%polly.subregion.iv.inc' instruction and did consequently not check what they
were supposed to check. However, without these lines we can not test that the
.s2a instructions that are not any more generated since r250411 really are not
emitted. Hence, we add back the CHECK-NEXT lines to ensure there are really no
instructions generated between the store that we check for and the branch at the
end of the basic block. To ensure we do not match too early, we now check for
'br i1' or 'br label'.

llvm-svn: 250435
2015-10-15 18:04:20 +00:00
Michael Kruse 668af71b82 Do not add accesses for intra-ScopStmt scalar def-use chains
When pulling a llvm::Value to be written as a PHI write, the former
code did only check whether it is within the same basic block, but it
could also be the same non-affine subregion. In that case some 
unecessary pair of MemoryAccesses would have been created.

Two unit test were explicitely checking for the unecessary writes,
including the comments that the writes are unecessary. 

llvm-svn: 250411
2015-10-15 14:45:48 +00:00
Michael Kruse 90428328ee Remove "CHECK: br" from some unit tests
They happen to match
%polly.subregion.iv.inc = add i32 %polly.subregion.iv, 1
         ^^                                ^^
that is, are misleading in what they actually check.

llvm-svn: 250408
2015-10-15 14:40:40 +00:00
Tobias Grosser 5da48f392c Add -sort-includes to our automatic source code formatting
llvm-svn: 250393
2015-10-15 12:18:37 +00:00
Tobias Grosser 0e3a6b13a4 Sort includes using 'clang-format -sort-includes'
llvm-svn: 250392
2015-10-15 12:17:36 +00:00
Michael Kruse b987be12bf Add testcase for SCEV explansion in non-affine subregions
When sharing the same map from old to new value, CodeGeneration would
reuse the same new value for each basic block. However, the SCEV
expander might emit code in a basic block that does not dominate a use
of the SCEV in another basic block. This test checks whether both such
blocks have their own expanded new values. 

llvm-svn: 250389
2015-10-15 10:40:14 +00:00
Tobias Grosser 6b948d5efb [tests] More testing for PHI-nodes in non-affine regions
We harden one test case by ensuring no additional stores may possibly be
introduced between the stores we check for and the basic block terminator
statements.

We also add a test case for the situation where a value that is passed from
a non-affine region to a PHI node does not dominate the exit of the non-affine
region. This case has come up in patch reviews, so we make sure it is properly
handled today and in the future.

llvm-svn: 250217
2015-10-13 20:03:09 +00:00
Tobias Grosser f30be2f370 RegisterPasses: Optionally run inliner before Polly
This will allow us to optimize C++ template code with Polly. This support is
mostly for debugging purpose and individual experiments. The ultimate goal is
still to run Polly later in the pass manager when inlining already happened.

llvm-svn: 250092
2015-10-12 20:03:44 +00:00
Tobias Grosser d17183f20f Use EP_ModuleOptimizerEarly to run early polly passes,
instead of llvm::PassManagerBuilder::EP_EarlyAsPossible. This will allow us
to run actual module passes in Polly's canonicalization sequence, but should
otherwise have only little impact.

llvm-svn: 250091
2015-10-12 20:03:41 +00:00
Tobias Grosser e2c8275346 ScopInfo: Allow simple 'AddRec * Parameter' products in delinearization
We also allow such products for cases where 'Parameter' is loaded within the
scop, but where we can dynamically verify that the value of 'Parameter' remains
unchanged during the execution of the scop.

This change relies on Polly's new RequiredILS tracking infrastructure recently
contributed by Johannes.

llvm-svn: 250019
2015-10-12 08:02:30 +00:00
Tobias Grosser 3c037fd396 Delete leftover function declaration
The function's definition was already removed in r247289.

llvm-svn: 250015
2015-10-12 05:14:03 +00:00
Tobias Grosser 1c55e2b7f3 Also add -polly-no-early-exit back until LNT is restarted
llvm-svn: 249975
2015-10-11 13:49:27 +00:00
Tobias Grosser 3ecb71696b Add back -polly-detect-unprofitable as alias of -polly-process-unprofitable
This flag was still used in our LNT server. We leave it until it has been
removed from LNT as well.

llvm-svn: 249973
2015-10-11 13:39:17 +00:00
Johannes Doerfert 9b1f9c8b61 Allow eager evaluated binary && and || conditions
The domain generation can handle lazy && and || by default but eager
  evaluated expressions were dismissed as non-affine. With this patch we
  will allow arbitrary combinations of and/or bit-operations in the
  conditions of branches.

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

llvm-svn: 249971
2015-10-11 13:21:03 +00:00
Johannes Doerfert f363ed9804 [NFC] Move helper functions to ScopHelper
Helper functions in the BlockGenerators.h/cpp introduce dependences
  from the frontend to the backend of Polly. As they are used in
  ScopDetection, ScopInfo, etc. we move them to the ScopHelper file.

llvm-svn: 249919
2015-10-09 23:40:24 +00:00
David Blaikie 91e113d1dd Remove some unused variables in -Asserts builds
llvm-svn: 249866
2015-10-09 18:22:18 +00:00
Johannes Doerfert 697fdf891c Consolidate invariant loads
If a (assumed) invariant location is loaded multiple times we
  generated a parameter for each location. However, this caused compile
  time problems for several benchmarks (e.g., 445_gobmk in SPEC2006 and
  BT in the NAS benchmarks). Additionally, the code we generate is
  suboptimal as we preload the same location multiple times and perform
  the same checks on all the parameters that refere to the same value.

  With this patch we consolidate the invariant loads in three steps:
    1) During SCoP initialization required invariant loads are put in
       equivalence classes based on their pointer operand. One
       representing load is used to generate a parameter for the whole
       class, thus we never generate multiple parameters for the same
       location.
    2) During the SCoP simplification we remove invariant memory
       accesses that are in the same equivalence class. While doing so
       we build the union of all execution domains as it is only
       important that the location is at least accessed once.
    3) During code generation we only preload one element of each
       equivalence class with the unified execution domain. All others
       are mapped to that preloaded value.

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

llvm-svn: 249853
2015-10-09 17:12:26 +00:00
Johannes Doerfert f7e2967293 [FIX] Add missing projection for invariant load domains
This was left out from the original patch proposed in
    http://reviews.llvm.org/D13195
  even though it is needed to define an order invariant loads
  are hoisted.

llvm-svn: 249680
2015-10-08 11:05:57 +00:00
Johannes Doerfert c7ab83dfb7 Remove unused flag polly-allow-non-scev-backedge-taken-count
Drop an unused flag polly-allow-non-scev-backedge-taken-count and also
  its occurrences from the tests.

Contributed-by: Chris Jenneisch <chrisj@codeaurora.org>

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

llvm-svn: 249675
2015-10-08 10:05:48 +00:00
Johannes Doerfert c06b7d67cd Expose the detection context to ScopDetection users
ScopDetection users are interested in the detection context and access
  these via different get-methods. However, not all information was
  exposed though the number of maps to hold it was increasing steadily.
  With this change only the detection contexts the rejection log and the
  ValidRegions set are mapped. The former is needed, the second could be
  integrated in the first and the ValidRegions set is only needed for the
  deterministic order of the regions.

llvm-svn: 249614
2015-10-07 20:46:06 +00:00
Johannes Doerfert 08d90a3cee Treat conditionally executed non-pure calls as errors
This replaces the support for user defined error functions by a
  heuristic that tries to determine if a call to a non-pure function
  should be considered "an error". If so the block is assumed not to be
  executed at runtime. While treating all non-pure function calls as
  errors will allow a lot more regions to be analyzed, it will also
  cause us to dismiss a lot again due to an infeasible runtime context.
  This patch tries to limit that effect. A non-pure function call is
  considered an error if it is executed only in conditionally with
  regards to a cheap but simple heuristic.

llvm-svn: 249611
2015-10-07 20:32:43 +00:00
Johannes Doerfert d8dd8630b2 [NFC] Make LoopInfo a member and simplify arguments
llvm-svn: 249609
2015-10-07 20:31:36 +00:00
Johannes Doerfert 09e3697f44 Allow invariant loads in the SCoP description
This patch allows invariant loads to be used in the SCoP description,
  e.g., as loop bounds, conditions or in memory access functions.

  First we collect "required invariant loads" during SCoP detection that
  would otherwise make an expression we care about non-affine. To this
  end a new level of abstraction was introduced before
  SCEVValidator::isAffineExpr() namely ScopDetection::isAffine() and
  ScopDetection::onlyValidRequiredInvariantLoads(). Here we can decide
  if we want a load inside the region to be optimistically assumed
  invariant or not. If we do, it will be marked as required and in the
  SCoP generation we bail if it is actually not invariant. If we don't
  it will be a non-affine expression as before. At the moment we
  optimistically assume all "hoistable" (namely non-loop-carried) loads
  to be invariant. This causes us to expand some SCoPs and dismiss them
  later but it also allows us to detect a lot we would dismiss directly
  if we would ask e.g., AliasAnalysis::canBasicBlockModify(). We also
  allow potential aliases between optimistically assumed invariant loads
  and other pointers as our runtime alias checks are sound in case the
  loads are actually invariant. Together with the invariant checks this
  combination allows to handle a lot more than LICM can.

  The code generation of the invariant loads had to be extended as we
  can now have dependences between parameters and invariant (hoisted)
  loads as well as the other way around, e.g.,
    test/Isl/CodeGen/invariant_load_parameters_cyclic_dependence.ll
  First, it is important to note that we cannot have real cycles but
  only dependences from a hoisted load to a parameter and from another
  parameter to that hoisted load (and so on). To handle such cases we
  materialize llvm::Values for parameters that are referred by a hoisted
  load on demand and then materialize the remaining parameters. Second,
  there are new kinds of dependences between hoisted loads caused by the
  constraints on their execution. If a hoisted load is conditionally
  executed it might depend on the value of another hoisted load. To deal
  with such situations we sort them already in the ScopInfo such that
  they can be generated in the order they are listed in the
  Scop::InvariantAccesses list (see compareInvariantAccesses). The
  dependences between hoisted loads caused by indirect accesses are
  handled the same way as before.

llvm-svn: 249607
2015-10-07 20:17:36 +00:00
Johannes Doerfert 521dd5842f Move the ValueMapT declaration out of BlockGenerator
Value maps are created and used in many places and it is not always
  possible to include CodeGen/Blockgenerators.h. To this end, ValueMapT
  now lives in the ScopHelper.h which does not have any dependences itself.

  This patch also replaces uses of different other value map types with
  the ValueMapT.

llvm-svn: 249606
2015-10-07 20:15:56 +00:00
Tobias Grosser 6bab9f800b IRBuilder: Use Map.lookup instead of Map.find [NFC]
This simplifies the code.

Suggested-by: Johannes Doerfert
llvm-svn: 249545
2015-10-07 13:35:20 +00:00
Tobias Grosser d79cb0378b IRBuilder: Ensure we do not add empty map elements
Do not use "Map[Key] == nullptr" to check if a Key is in the map, but use
"Map.find(Key) == Map.end()". Map[Key] always adds Key into the map, a
side-effect we do not want.

Found by inspection. This is hard to test outside of a targetted unit test,
which seems too much overhead for this individual issue.

llvm-svn: 249544
2015-10-07 13:19:06 +00:00
Tobias Grosser 73725b8ba5 IRBuilder: Simplify code and reduce indention [NFC]
llvm-svn: 249543
2015-10-07 13:19:03 +00:00
Tobias Grosser 369c1d663b test: Add example of scalar that is reused accross loop
llvm-svn: 249527
2015-10-07 09:00:29 +00:00
David Blaikie ba2e4857b1 Fix configure checks when applied by the latest clang
Clang's been taught to warn on more things here (unused values when
calling pure functions and ignoring their result, for example).

It might be better to figure out how to have cmake compile these tests
without -Werror/without any warnings enabled. But this'll do for now & I
don't know enough about cmake to fix it any other way, or to understand
the tradeoffs in that space.

llvm-svn: 249472
2015-10-06 21:45:06 +00:00
Tobias Grosser 3593739cb2 IslAst: Give some hints why code generation might have been skipped
llvm-svn: 249427
2015-10-06 16:10:46 +00:00
Tobias Grosser 575aca8d43 Introduce -polly-process-unprofitable
This single option replaces -polly-detect-unprofitable and -polly-no-early-exit
and is supposed to be the only option that disables compile-time heuristics that
aim to bail out early on scops that are believed to not benefit from Polly
optimizations.

Suggested-by:  Johannes Doerfert
llvm-svn: 249426
2015-10-06 16:10:29 +00:00
Tobias Grosser f4ee371e60 tests: Drop -polly-detect-unprofitable and -polly-no-early-exit
These flags are now always passed to all tests and need to be disabled if
not needed. Disabling these flags, rather than passing them to almost all
tests, significantly simplfies our RUN: lines.

llvm-svn: 249422
2015-10-06 15:36:44 +00:00
Tobias Grosser 4fdcf7b813 test: By default disable Polly's compile-time profitability heuristics
llvm-svn: 249420
2015-10-06 15:30:26 +00:00
Tobias Grosser 935f62cf0d tests: Explicitly state if profitability tests should be used
Polly's profitability heuristic saves compile time by skipping trivial scops or
scops were we know no good optimization can be applied. For almost all our tests
this heuristic makes little sense as we aim for minimal test cases when testing
functionality. Hence, in almost all cases this heuristic is better be disabled.
In preparation of disabling Polly's compile time heuristic by default in the
test suite we first explicitly enable it in the couple of test cases that really
use it (or run with/without heuristic side-by-side).

llvm-svn: 249418
2015-10-06 15:19:35 +00:00
Tobias Grosser 1ac26d06fe test: Disable profitability heuristics to unfail LICM test case
This test case was XFAILed under the assumption Polly is unable to detect the
scop. However, disabling Polly's profitability heuristics is sufficient to
detect this scop.

llvm-svn: 249414
2015-10-06 15:10:19 +00:00
Tobias Grosser d76603fbe7 test: sdiv in loop bounds is supported since a while
By disabling our scop-profitability heuristics this becomes also visible in some
older test cases.

llvm-svn: 249411
2015-10-06 14:59:31 +00:00
Tobias Grosser b73c695aba tests: Drop outdated and unused lit variable
llvm-svn: 249401
2015-10-06 13:50:20 +00:00
Johannes Doerfert f17a78ef63 Remove non-executed statements during SCoP simplifcation
A statement with an empty domain complicates the invariant load
  hoisting and does not help any subsequent analysis or transformation.
  In fact it might introduce parameter dimensions or increase the
  schedule dimensionality. To this end, we remove statements with an
  empty domain early in the SCoP simplification.

llvm-svn: 249276
2015-10-04 15:00:05 +00:00
Johannes Doerfert 634909c2c9 [FIX] Domain generation for non-affine loops
llvm-svn: 249275
2015-10-04 14:57:41 +00:00
Johannes Doerfert f61df69423 [FIX] Count affine loops correctly
The "unprofitable" heuristic was broken and counted boxed loops
  even though we do not represent and optimize them.

llvm-svn: 249274
2015-10-04 14:56:08 +00:00
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