Commit Graph

708 Commits

Author SHA1 Message Date
Tobias Grosser c84a1995fe GPGPU: add scop parameters to kernel arguments
llvm-svn: 275955
2016-07-19 07:33:06 +00:00
Tobias Grosser f6044bd0ef GPGPU: add host iterators to kernel arguments
llvm-svn: 275954
2016-07-19 07:32:55 +00:00
Tobias Grosser 472f9654c8 GPGPU: add intrinsic functions to obtain a kernels thread and block ids
llvm-svn: 275953
2016-07-19 07:32:44 +00:00
Tobias Grosser 32837fe313 GPGPU: create kernel function skeleton
Create for each kernel a separate LLVM-IR module containing a single function
marked as kernel function and taking one pointer for each array referenced
by this kernel. Add debugging output to verify the kernels are generated
correctly.

llvm-svn: 275952
2016-07-19 07:32:38 +00:00
Tobias Grosser b9fc860a57 GPGPU: collect array references
Initialize the list of references to a GPU array to ensure that the arrays that
need to be passed to kernel calls are computed correctly.  Furthermore, the very
same information is also necessary to compute synchronization correctly. As the
functionality to compute these references is already available, what is left for
us to do is only to connect the necessary functionality to compute array
reference information.

llvm-svn: 275798
2016-07-18 15:44:32 +00:00
Tobias Grosser 1fb9b64dc0 GPGPU: Pull implementation out of class definition
This will allow us to see the full class definition even after we add
non-trivial implementations of the different member functions.

llvm-svn: 275797
2016-07-18 15:44:25 +00:00
Tobias Grosser 38fc0aed08 GPGPU: Create host control flow
Create LLVM-IR for all host-side control flow of a given GPU AST. We implement
this by introducing a new GPUNodeBuilder class derived from IslNodeBuilder.  The
IslNodeBuilder will take care of generating all general-purpose ast nodes, but
we provide our own createUser implementation to handle the different GPU
specific user statements. For now, we just skip any user statement and only
generate a host-code sceleton, but in subsequent commits we will add handling of
normal ScopStmt's performing computations, kernel calls, as well as host-device
data transfers. We will also introduce run-time check generation and LICM in
subsequent commits.

llvm-svn: 275783
2016-07-18 11:56:39 +00:00
Tobias Grosser 2025173494 GPGPU: Format statements scheduled on the host ourselves
Otherwise ppcg would try to call into pet functionality that this not available,
which obviously will cause trouble. As we can easily print these statements
ourselves, we just do so.

llvm-svn: 275579
2016-07-15 17:12:41 +00:00
Tobias Grosser 2341fe9e76 GPGPU: Use schedule whole components for scheduler
This option increases the scalability of the scheduler and allows us to remove
the 'gisting' workaround we introduced in r275565 to handle a more complicated
test case. Another benefit of using this option is also that the generated
code looks a lot more streamlined.

Thanks to Sven Verdoolaege for reminding me of this option.

llvm-svn: 275573
2016-07-15 16:15:47 +00:00
Tobias Grosser e4725437e8 GPGPU: Drop domain constraints from flow dependences
This works around a shortcoming of the isl scheduler, which even for some
smaller test cases does not terminate in case domain constraints are part
of the flow dependences.

llvm-svn: 275565
2016-07-15 14:43:04 +00:00
Tobias Grosser 6293ba6973 GPGPU: Add memory reference tag ids to tagged accesses
It seems we forgot to actually add the memory access ids to the tagged accesses,
but instead just tagged the accesses with empty isl_ids. This issue was found
by inspection and without code generation it is difficult to test just by
itself. We fix it for now without test case and expect our code generation
tests to cover this later on.

llvm-svn: 275557
2016-07-15 12:44:27 +00:00
Tobias Grosser 2d010daf85 GPGPU: Make sure scops with more than one array work
We use this opportunity to add a test case containing a scalar parameter.

llvm-svn: 275547
2016-07-15 10:51:14 +00:00
Tobias Grosser b307ed4d08 GPGPU: Free options to avoid memory leak
ppcg does not free the option structs for us. To avoid a memory leak we do this
ourselves.

llvm-svn: 275546
2016-07-15 10:32:22 +00:00
Tobias Grosser a56f8f8e58 GPGPU: Shorten ppcg include paths to avoid conflict with cuda.h
Instead of directly linking to ppcg's main source directory, we link to the
parent director. This allows us to access ppcg's include files with
'ppcg/cuda.h' and avoids a conflict with NVIDIA's cuda.h header.

Also drop an include directory that is currently not used.

llvm-svn: 275536
2016-07-15 07:50:36 +00:00
Tobias Grosser 60f63b49f2 GPGPU: Model array access information
This allows us to derive host-device and device-host data-transfers.

llvm-svn: 275535
2016-07-15 07:05:54 +00:00
Tobias Grosser 69b4675180 GPGPU: Generate an AST for the GPU-mapped schedule
For this we need to provide an explicit list of statements as they occur in
the polly::Scop to ppcg.

We also setup basic AST printing facilities to facilitate debugging. To allow
code reuse some (minor) changes in ppcg are have been necessary.

llvm-svn: 275436
2016-07-14 15:51:37 +00:00
Tobias Grosser 60c6002570 GPGPU: Add dummy implementation for ast expression construction
Instead of calling to a pet function that does not return anything, we pass
our own dummy implementation to ppcg that always returns a nullptr. This
ensures that the list of ast expressions always contains a nullptr and we do
not accidentally free a random (uninitalized) pointer. This resolves the
last valgrind warning we see.

We provide an implementation for this function, when the generated AST
expressions can be used and consequently can be tested.

llvm-svn: 275435
2016-07-14 15:51:32 +00:00
Tobias Grosser 4eaedde530 GPGPU: Use a tile size of 32 by default
The tile size was previously uninitialized. As a result, it was often zero (aka.
no tiling), which is not what we want in general. More importantly, there was
the risk for arbitrary tile sizes to be choosen, which we did not observe, but
which still is highly problematic.

llvm-svn: 275418
2016-07-14 14:14:02 +00:00
Tobias Grosser bd81a7eebc Fix formatting
llvm-svn: 275397
2016-07-14 10:53:00 +00:00
Tobias Grosser aef5196f75 GPGPU: Map initial schedule to GPU schedule
This change now applies ppcg's GPU mapping on our initial schedule. For this
to work, we need to also initialize the set of all names (isl_ids) used in
the scop as well as the program context.

llvm-svn: 275396
2016-07-14 10:51:52 +00:00
Tobias Grosser 681bd5688f GPGPU: Do not dump schedule by default
llvm-svn: 275395
2016-07-14 10:51:47 +00:00
Tobias Grosser f384594d5e GPGPU: compute new schedule from polly scop
To do so we copy the necessary information to compute an initial schedule from
polly::Scop to ppcg's scop. Most of the necessary information is directly
available and only needs to be passed on to ppcg, with the exception of 'tagged'
access relations, access relations that additionally carry information about
which memory access an access relation originates from.

We could possibly perform the construction of tagged accesses as part of
ScopInfo, but as this format is currently specific to ppcg we do not do this
yet, but keep this functionality local to our GPU code generation.

After the scop has been initialized, we compute data dependences and ask ppcg to
compute an initial schedule. Some of this functionality is already available in
polly::DependenceInfo and polly::ScheduleOptimizer, but to keep differences
to ppcg small we use ppcg's functionality here. We may later investiage if
a closer integration of these tools makes sense.

llvm-svn: 275390
2016-07-14 10:22:25 +00:00
Tobias Grosser e938517e37 GPGPU: create default initialized PPCG scop and gpu program
At this stage, we do not yet modify the IR but just generate a default
initialized ppcg_scop and gpu_prog and free both immediately. Both will later be
filled with data from the polly::Scop and are needed to use PPCG for GPU
schedule generation. This commit does not yet perform any GPU code generation,
but ensures that the basic infrastructure has been put in place.

We also add a simple test case to ensure the new code is run and use this
opportunity to verify that GPU_CODEGEN tests are only run if GPU code generation
has been enabled in cmake.

llvm-svn: 275389
2016-07-14 10:22:19 +00:00
Tobias Grosser 9dfe4e7c05 Add accelerator code generation pass skeleton
Add a new pass to serve as basis for automatic accelerator mapping in Polly.
The pass structure and the analyses preserved are copied from
CodeGeneration.cpp, as we will rely on IslNodeBuilder and IslExprBuilder for
LLVM-IR code generation.

Polly's accelerator code generation is enabled with -polly-target=gpu

I would like to use this commit as opportunity to thank Yabin Hu for his work in
the context of two Google summer of code projects during which he implemented
initial prototypes of the Polly accelerator code generation -- in parts this
code is already available in todays Polly (e.g., tools/GPURuntime). More will
come as part of the upcoming Polly ACC changes.

Reviewers: Meinersbur

Subscribers: pollydev, llvm-commits

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

llvm-svn: 275275
2016-07-13 15:54:58 +00:00
Tobias Grosser faef9a7667 Fix gcc compile failure
Commit r275056 introduced a gcc compile failure due to us using two
types named 'Type', the first being the newly introduced member variable
'Type' the second being llvm::Type. We resolve this issue by renaming
the newly introduced member variable to AccessType.

llvm-svn: 275057
2016-07-11 12:27:04 +00:00
Tobias Grosser 4e2d9c45b9 InvariantEquivClassTy: Use struct instead of 4-tuple to increase readability
Summary:
With a struct we can use named accessors instead of generic std::get<3>()
calls. This increases readability of the source code.

Reviewers: jdoerfert

Subscribers: pollydev, llvm-commits

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

llvm-svn: 275056
2016-07-11 12:15:10 +00:00
Justin Bogner e2467baba8 Update for llvm r274769
llvm-svn: 274777
2016-07-07 18:03:30 +00:00
Tobias Grosser 932ec01328 isl: isl-0.17.1-164-gcbba1b6
This is a regular maintenance update to ensure the latest version of isl is
tested.

Interesting Changes:

  - AST nodes and expressions are now printed as YAML

llvm-svn: 274614
2016-07-06 09:11:00 +00:00
George Burgess IV 1a046de897 Try to fix polly buildbots.
Broken by r274589.

llvm-svn: 274595
2016-07-06 02:21:00 +00:00
Tobias Grosser 29a4dd92b7 CodegenCleanup: Drop CFLAA pass from codegen cleanup sequence
Since r274197 -polly-position=before-vectorizer caused various LNT failures
for example in SingleSource/Benchmarks/Linpack. These failures seem to only
occur when the CFLAA pass is scheduled in our codegen-cleanup passes, which
suggests that the way we call this AA pass is somehow problematic.  As this pass
is not of high importance, we drop the pass for now to prevent these failures
from happening. At a later point, we might investigate more in-depth why this
specific usage scenario caused correctness issues.

llvm-svn: 274427
2016-07-02 07:58:13 +00:00
Tobias Grosser 522478d2c0 clang-tidy: Add llvm namespace comments
llvm commonly adds a comment to the closing brace of a namespace to indicate
which namespace is closed. clang-tidy provides with llvm-namespace-comment
a handy tool to check for this habit. We use it to ensure we consitently use
namespace comments in Polly.

There are slightly different styles in how namespaces are closed in LLVM. As
there is no large difference between the different comment styles we go for the
style clang-tidy suggests by default.

To reproduce this fix run:

for i in `ls tools/polly/lib/*/*.cpp`; \
  clang-tidy -checks='-*,llvm-namespace-comment' -p build $i -fix \
  -header-filter=".*"; \
done

This cleanup was suggested by Eugene Zelenko <eugene.zelenko@gmail.com> in
http://reviews.llvm.org/D21488 and was split out to increase readability.

llvm-svn: 273621
2016-06-23 22:17:27 +00:00
Tobias Grosser 616449df6d Add missing copyright header
This cleanup was suggested by Eugene Zelenko <eugene.zelenko@gmail.com> in
http://reviews.llvm.org/D21488 and was split out to increase readability.

llvm-svn: 273436
2016-06-22 16:29:28 +00:00
Tobias Grosser 8dd653d983 clang-tidy: apply modern-use-nullptr fixes
Instead of using 0 or NULL use the C++11 nullptr symbol when referencing null
pointers.

This cleanup was suggested by Eugene Zelenko <eugene.zelenko@gmail.com> in
http://reviews.llvm.org/D21488 and was split out to increase readability.

llvm-svn: 273435
2016-06-22 16:22:00 +00:00
Michael Kruse 6b4e928285 Replace ScalarReplAggregatesPass by SROAPass.
ScalarReplAggregatesPass was deprecated and replaced by SROAPass.
ScalarReplAggregatesPass got finally removed in LLVM commit r272737, hence this
patch is also a compile fix.

llvm-svn: 272783
2016-06-15 13:21:28 +00:00
Tobias Grosser 43de17872a Recommit: "Simplify min/max expression generation"
As part of this simplification we pull complex logic out of the loop body and
skip the previously redundantly executed first loop iteration.

This is a partial recommit of r271514 and r271535 which where in conflict with
the revert in r272483 and consequently also had to be reverted temporarily.  The
original patch was contributed by Johannes Doerfert.

This patch is mostly a NFC, but dropping the first loop iteration can sometimes
result in slightly simpler code.

llvm-svn: 272502
2016-06-12 04:49:41 +00:00
Tobias Grosser 3717aa5ddb This reverts recent expression type changes
The recent expression type changes still need more discussion, which will happen
on phabricator or on the mailing list. The precise list of commits reverted are:

- "Refactor division generation code"
- "[NFC] Generate runtime checks after the SCoP"
- "[FIX] Determine insertion point during SCEV expansion"
- "Look through IntToPtr & PtrToInt instructions"
- "Use minimal types for generated expressions"
- "Temporarily promote values to i64 again"
- "[NFC] Avoid unnecessary comparison for min/max expressions"
- "[Polly] Fix -Wunused-variable warnings (NFC)"
- "[NFC] Simplify min/max expression generation"
- "Simplify the type adjustment in the IslExprBuilder"

Some of them are just reverted as we would otherwise get conflicts. I will try
to re-commit them if possible.

llvm-svn: 272483
2016-06-11 19:17:15 +00:00
Johannes Doerfert 8448071d3e Refactor division generation code
This patch refactors the code generation for divisions. This allows to
  always generate a shift for a power-of-two division and to utilize
  information about constant divisors in order to truncate the result
  type.

llvm-svn: 271898
2016-06-06 14:56:17 +00:00
Johannes Doerfert c0ece9b67e [NFC] Generate runtime checks after the SCoP
We now generate runtime checks __after__ the SCoP code generation and
  not before, though they are still inserted at the same position int
  the code. This allows to modify the runtime check during SCoP code
  generation.

llvm-svn: 271894
2016-06-06 13:32:52 +00:00
Johannes Doerfert 6a6a671c72 [NFC] Simplify code
llvm-svn: 271889
2016-06-06 12:13:24 +00:00
Johannes Doerfert 0767a511ba Use minimal types for generated expressions
We now use the minimal necessary bit width for the generated code. If
  operations might overflow (add/sub/mul) we will try to adjust the types in
  order to ensure a non-wrapping computation. If the type adjustment is not
  possible, thus the necessary type is bigger than the type value of
  --polly-max-expr-bit-width, we will use assumptions to verify the computation
  will not wrap. However, for run-time checks we cannot build assumptions but
  instead utilize overflow tracking intrinsics.

llvm-svn: 271878
2016-06-06 09:57:41 +00:00
Michael Kruse 5c527f9963 Fix modulo compared to zero.
In case of modulo compared to zero, we need to do signed modulo
operation as unsigned can give different results based on whether the
dividend is negative or not.

This addresses llvm.org/PR27707

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

Reviewers: _jdoerfert, grosser, Meinersbur

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

llvm-svn: 271707
2016-06-03 18:51:48 +00:00
Johannes Doerfert 6393ef135c Temporarily promote values to i64 again
Operands of binary operations that might overflow will be temporarily
  promoted to i64 again, though that is not a sound solution for the problem.

llvm-svn: 271538
2016-06-02 17:09:22 +00:00
Johannes Doerfert 4cf79d4ca4 [NFC] Avoid unnecessary comparison for min/max expressions
llvm-svn: 271535
2016-06-02 16:58:12 +00:00
Matthew Simpson acae9e3b30 [Polly] Fix -Wunused-variable warnings (NFC)
llvm-svn: 271518
2016-06-02 14:26:38 +00:00
Johannes Doerfert 47f15f6d7e [NFC] Simplify min/max expression generation
llvm-svn: 271514
2016-06-02 11:20:52 +00:00
Johannes Doerfert d36553753e Simplify the type adjustment in the IslExprBuilder
We now have a simple function to adjust/unify the types of two (or three)
  operands before an operation that requieres the same type for all operands.
  Due to this change we will not promote parameters that are added to i64
  anymore if that is not needed.

llvm-svn: 271513
2016-06-02 11:15:57 +00:00
Johannes Doerfert a91c85a5b9 [FIX] Ensure wrapping checks for unary expressions
llvm-svn: 271512
2016-06-02 11:08:43 +00:00
Johannes Doerfert 99191c78c2 Decouple SCoP building logic from pass
Created a new pass ScopInfoRegionPass. As name suggests, it is a
  region pass and it is there to preserve compatibility with our
  existing Polly passes.  ScopInfoRegionPass will return a SCoP object
  for a valid region while the creation of the SCoP stays in the
  ScopInfo class.

  Contributed-by: Utpal Bora <cs14mtech11017@iith.ac.in>
  Reviewed-by: Tobias Grosser <tobias@grosser.es>,
               Johannes Doerfert <doerfert@cs.uni-saarland.de>

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

llvm-svn: 271259
2016-05-31 09:41:04 +00:00
Sanjoy Das 03bcb910de [Polly] Remove usage of the `apply` function
Summary:
API-wise `apply` is a somewhat unidiomatic one-off function, and
removing the only(?) use in polly will let me remove it from SCEV's
exposed interface.

Reviewers: jdoerfert, Meinersbur, grosser

Subscribers: grosser, mcrosier, pollydev

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

llvm-svn: 271177
2016-05-29 07:33:16 +00:00
Michael Kruse 996fb611b3 Remove some unused local variables. NFC.
Found by clang static analyzer (http://llvm.org/reports/scan-build/)
and Visual Studio.

llvm-svn: 270432
2016-05-23 13:00:41 +00:00
Johannes Doerfert 0f0d209bec Use the SCoP directly for canSynthesize [NFC]
llvm-svn: 270429
2016-05-23 12:47:09 +00:00
Johannes Doerfert ef74443c97 Duplicate part of the Region interface in the Scop class [NFC]
This allows to use the SCoP directly for various queries,
  thus to hide the underlying region more often.

llvm-svn: 270426
2016-05-23 12:42:38 +00:00
Johannes Doerfert 952b5304bc Add and use Scop::contains(Loop/BasicBlock/Instruction) [NFC]
llvm-svn: 270424
2016-05-23 12:40:48 +00:00
Johannes Doerfert 3f52e35471 Directly access information through the Scop class [NFC]
llvm-svn: 270421
2016-05-23 12:38:05 +00:00
Johannes Doerfert 38a012c46b Simplify BlockGenerator::handleOutsideUsers interface [NFC]
llvm-svn: 270411
2016-05-23 09:14:07 +00:00
Johannes Doerfert a61eda7698 [FIX] Let ScalarEvolution forget hoisted values
We have to rethink the handling of escaping values in order to make
  this kind of "fixes" go away.

llvm-svn: 270409
2016-05-23 09:02:54 +00:00
Johannes Doerfert 404a0f81ea Check overflows in RTCs and bail accordingly
We utilize assumptions on the input to model IR in polyhedral world.
  To verify these assumptions we version the code and guard it with a
  runtime-check (RTC). However, since the RTCs are themselves generated
  from the polyhedral representation we generate them under the same
  assumptions that they should verify. In other words, the guarantees
  that we try to provide with the RTCs do not hold for the RTCs
  themselves. To this end it is necessary to employ a different check
  for the RTCs that will verify the assumptions did hold for them too.

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

llvm-svn: 269299
2016-05-12 15:12:43 +00:00
Johannes Doerfert e243753a4d Simplify access relation for invariant loads early [NFC]
llvm-svn: 269046
2016-05-10 11:59:59 +00:00
Johannes Doerfert 5f173d414e Prevent complex access ranges with low number of pieces.
Previously we checked the number of pieces to decide whether or not a
  invariant load was to complex to be generated. However, there are
  cases when e.g., divisions cause the complexity to spike regardless of
  the number of pieces. To this end we now check the number of totally
  involved dimensions which will increase with the number of pieces but
  also the number of divisions.

llvm-svn: 269045
2016-05-10 11:46:57 +00:00
Tobias Grosser 1022ca5646 Codegen: Enable the detection of min/max expressions
Min/max expressions are easier to read and can in some cases also result in
more concise IR that is generated as the min/max --- when lowered to a
cmp+select pattern -- commonly has a simpler condition then the ternary
condition isl would normally generate.

llvm-svn: 268855
2016-05-07 08:03:44 +00:00
Michael Kruse bc150127ae Rename Conjuncts -> Disjunctions. NFC.
The check for complexity compares the number of polyhedra in a set,
which are combined by disjunctions (union, "OR"),
not conjunctions (intersection, "AND").

llvm-svn: 268223
2016-05-02 12:25:18 +00:00
Tobias Grosser 2e27a0f5fd BlockGenerator: Drop leftover debug statement
llvm-svn: 267874
2016-04-28 12:31:05 +00:00
Johannes Doerfert 8ab2803b63 [FIX] Propagate execution domain of invariant loads
If the base pointer of an invariant load is is loaded conditionally, that
  condition needs to hold for the invariant load too. The structure of the
  program will imply this for domain constraints but not for imprecisions in
  the modeling. To this end we will propagate the execution context of base
  pointers during code generation and thus ensure the derived pointer does
  not access an invalid base pointer.

llvm-svn: 267707
2016-04-27 12:49:11 +00:00
Johannes Doerfert 517d8d2f94 Check only loop control of loops that are part of the region
This also removes a duplicated line of code in the region generator
  that caused a SPEC benchmark to fail with the new SCoPs.

llvm-svn: 267404
2016-04-25 13:37:24 +00:00
Johannes Doerfert 561d36b320 Allow pointer expressions in SCEVs again.
In r247147 we disabled pointer expressions because the IslExprBuilder did not
  fully support them. This patch reintroduces them by simply treating them as
  integers. The only special handling for pointers that is left detects the
  comparison of two address_of operands and uses an unsigned compare.

llvm-svn: 265894
2016-04-10 09:50:10 +00:00
Johannes Doerfert 3c6a99b818 Add __isl_give annotations to return types [NFC]
llvm-svn: 265882
2016-04-09 21:55:23 +00:00
Johannes Doerfert a9dc529442 Collect and verify generated parallel subfunctions
We verify the optimized function now for a long time and it helped to track
  down bugs early. This will now also happen for all parallel subfunctions we
  generate.

llvm-svn: 265823
2016-04-08 18:16:02 +00:00
Johannes Doerfert 7b81103589 [FIX] Look through div & srem instructions in SCEVs
The findValues() function did not look through div & srem instructions
  that were part of the argument SCEV. However, in different other
  places we already look through it. This mismatch caused us to preload
  values in the wrong order.

llvm-svn: 265775
2016-04-08 10:25:58 +00:00
Johannes Doerfert 6ba927148d [FIX] Adjust the insert point for non-affine region PHIs
If a non-affine region PHI is generated we should not move the insert
  point prior to the synthezised value in the same block as we might
  split that block at the insert point later on. Only if the incoming
  value should be placed in a different block we should change the
  insertion point.

llvm-svn: 265132
2016-04-01 11:25:47 +00:00
Tobias Grosser b339594f5d CodegenCleanup: Drop -load-combine pass
This pass is not enabled in the default tool chain and currently can run into an
infinite loop, due to other parts of LLVM generating incorrect IR
(http://llvm.org/PR27065) -- which is not executed and consequently does not
seem to disturb other passes.  As this pass is not really needed, we can just
drop it to get our build clean.

This fixes the timeout issues in MultiSource/Benchmarks/MiBench/consumer-jpeg
and MultiSource/Benchmarks/mediabench/jpeg/jpeg-6a/cjpeg for
-polly-position=before-vectorizer -polly-process-unprofitable.. Unfortunately,
we are still left with a miscompile in cjpeg.

llvm-svn: 264396
2016-03-25 12:11:06 +00:00
Johannes Doerfert 47197fe3f3 Add namespace for struct [NFC]
This will clean up the doxygen documentation.

llvm-svn: 264272
2016-03-24 13:20:52 +00:00
Tobias Grosser bfb6a9683b Codegen:Do not invalidate dominator tree when bailing out during code generation
When codegenerating invariant loads in some rare cases we cannot generate code
and bail out. This change ensures that we maintain a valid dominator tree
in these situations. This fixes llvm.org/PR26736

Contributed-by: Matthias Reisinger <d412vv1n@gmail.com>
llvm-svn: 264142
2016-03-23 06:57:51 +00:00
Michael Kruse faedfcbf6d [BlockGenerator] Fix PHI merges for MK_Arrays.
Value merging is only necessary for scalars when they are used outside
of the scop. While an array's base pointer can be used after the scop,
it gets an extra ScopArrayInfo of type MK_Value. We used to generate
phi's for both of them, where one was assuming the reault of the other
phi would be the original value, because it has already been replaced by
the previous phi. This resulted in IR that the current IR verifier
allows, but is probably illegal.

This reduces the number of LNT test-suite fails with
-polly-position=before-vectorizer -polly-process-unprofitable
from 16 to 10.

Also see llvm.org/PR26718.

llvm-svn: 262629
2016-03-03 17:20:43 +00:00
Hongbin Zheng 2a798853f8 Allow the client of DependenceInfo to obtain dependences at different granularities.
llvm-svn: 262591
2016-03-03 08:15:33 +00:00
Michael Kruse c7e0d9c216 Fix non-synthesizable loop exit values.
Polly recognizes affine loops that ScalarEvolution does not, in
particular those with loop conditions that depend on hoisted invariant
loads. Check for SCEVAddRec dependencies on such loops and do not
consider their exit values as synthesizable because SCEVExpander would
generate them as expressions that depend on the original induction
variables. These are not available in generated code.

llvm-svn: 262404
2016-03-01 21:44:06 +00:00
Johannes Doerfert 066dbf3f8e Track assumptions and restrictions separatly
In order to speed up compile time and to avoid random timeouts we now
  separately track assumptions and restrictions. In this context
  assumptions describe parameter valuations we need and restrictions
  describe parameter valuations we do not allow. During AST generation
  we create a runtime check for both, whereas the one for the
  restrictions is negated before a conjunction is build.

  Except the In-Bounds assumptions we currently only track restrictions.

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

llvm-svn: 262328
2016-03-01 13:06:28 +00:00
Johannes Doerfert abadd71da1 [FIX] Prevent compile time problems due to complex invariant loads
This cures the symptoms we see in h264 of SPEC2006 but not the cause.

llvm-svn: 262327
2016-03-01 13:05:14 +00:00
Tobias Grosser 64ca00c344 IslAst: Expose run-time check generation as individual function
This allows to construct run-time checks for a scop without having to generate
a full AST. This is currently not taken advantage of in Polly itself, but
external users may benefit from this feature.

llvm-svn: 262009
2016-02-26 12:59:38 +00:00
Hongbin Zheng defd098612 Adapt to LLVM head, again
llvm-svn: 261905
2016-02-25 17:54:42 +00:00
Hongbin Zheng 566c614525 Revert "Adapt to LLVM head. NFC"
This reverts commit 4d3753b9646a69c00d234ccd6e91dc3d0ea5d643.

llvm-svn: 261892
2016-02-25 16:46:17 +00:00
Hongbin Zheng f4e35f9cb9 Adapt to LLVM head. NFC
llvm-svn: 261886
2016-02-25 16:36:09 +00:00
Michael Kruse 8f25b0cb4d Use inline local variable declaration. NFC.
llvm-svn: 261876
2016-02-25 15:52:43 +00:00
Johannes Doerfert a792098047 Support calls with known ModRef function behaviour
Check the ModRefBehaviour of functions in order to decide whether or
  not a call instruction might be acceptable.

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

llvm-svn: 261866
2016-02-25 14:08:48 +00:00
Michael Kruse f33c125dd2 Fix DomTree preservation for generated subregions.
The generated dedicated subregion exit block was assumed to have the same
dominance relation as the original exit block. This is incorrect if the exit
block receives other edges than only from the subregion, which results in that
e.g. the subregion's entry block does not dominate the exit block.

llvm-svn: 261865
2016-02-25 14:08:48 +00:00
Michael Kruse 375cb5fe0a Introduce ScopStmt::getEntryBlock(). NFC.
This replaces an ungly inline ternary operator pattern.

llvm-svn: 261792
2016-02-24 22:08:24 +00:00
Michael Kruse 6f7721f02b Introduce Scop::getStmtFor. NFC.
Replace Scop::getStmtForBasicBlock and Scop::getStmtForRegionNode, and
add overloads for llvm::Instruction and llvm::RegionNode.

getStmtFor and overloads become the common interface to get the Stmt
that contains something. Named after LoopInfo::getLoopFor and
RegionInfo::getRegionFor.

llvm-svn: 261791
2016-02-24 22:08:19 +00:00
Michael Kruse eac9726e8c Add assertions checking def dominates use. NFC.
This is also be caught by the function verifier, but disconnected from
the place that produced it. Catch it already at creation to be able to
reason more directly about the cause.

llvm-svn: 261790
2016-02-24 22:08:14 +00:00
Roman Gareev 11001e1534 Annotation of SIMD loops
Use 'mark' nodes annotate a SIMD loop during ScheduleTransformation and skip
parallelism checks.

The buildbot shows the following compile/execution time changes:

  Compile time:
    Improvements    Δ     Previous  Current  σ
    …/gesummv      -6.06% 0.2640    0.2480   0.0055
    …/gemver       -4.46% 0.4480    0.4280   0.0044
    …/covariance   -4.31% 0.8360    0.8000   0.0065
    …/adi          -3.23% 0.9920    0.9600   0.0065
    …/doitgen      -2.53% 0.9480    0.9240   0.0090
    …/3mm          -2.33% 1.0320    1.0080   0.0087

  Execution time:
    Regressions     Δ     Previous  Current  σ
    …/viterbi       1.70% 5.1840    5.2720   0.0074
    …/smallpt       1.06% 12.4920   12.6240  0.0040

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

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

llvm-svn: 261620
2016-02-23 09:00:13 +00:00
Tobias Grosser 820cf20a98 IslAst: Expose IslAst class in header file [NFC]
This allows other passes and transformations to use some of the existing AST
building infrastructure. This is not yet used in Polly itself.

llvm-svn: 261496
2016-02-21 20:01:28 +00:00
Tobias Grosser 2b809d1390 BlockGenerator: Drop unnecessary return value
llvm-svn: 261473
2016-02-21 15:44:34 +00:00
Tobias Grosser 58e585444a Codegen: Print error in Polly code verification and allow to disable verfication.
We now always print the reason why the code did not pass the LLVM verifier and
we also allow to disable verfication with -polly-codegen-verify=false. Before
this change the first assertion had generally no information why or what might
have gone wrong and it was also impossible to -view-cfg without recompile. This
change makes debugging bugs that result in incorrect IR a lot easier.

llvm-svn: 261320
2016-02-19 11:07:12 +00:00
Hongbin Zheng 8831eb7db4 [Refactor] Move isl_ctx into Scop.
After we moved isl_ctx into Scop, we need to free the isl_ctx after
  freeing all isl objects, which requires the ScopInfo pass to be freed
  at last. But this is not guaranteed by the PassManager, and we need
  extra code to free the isl_ctx at the right time.

  We introduced a shared pointer to manage the isl_ctx, and distribute
  it to all analyses that create isl objects. As such, whenever we free
  an analyses with the shared_ptr (and also free the isl objects which
  are created by the analyses), we decrease the (shared) reference
  counter of the shared_ptr by 1. Whenever the reference counter reach
  0 in the releaseMemory function of an analysis, that analysis will
  be the last one that hold any isl objects, and we can safely free the
  isl_ctx with that analysis.

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

llvm-svn: 261100
2016-02-17 15:49:21 +00:00
Johannes Doerfert 2c3ffc04f3 Replace getLoopForInst by getLoopForStmt
This patch was extracted from http://reviews.llvm.org/D13611.

llvm-svn: 260958
2016-02-16 12:36:14 +00:00
Johannes Doerfert 6a7c3e4bac Set AST Build for all statements [NFC]
llvm-svn: 260956
2016-02-16 12:11:03 +00:00
Tobias Grosser 652f780894 CodeGeneration: Add back verification of generated code
This got accidentally dropped in r260025

llvm-svn: 260857
2016-02-14 20:56:49 +00:00
Johannes Doerfert 96e5471139 Separate invariant equivalence classes by type
We now distinguish invariant loads to the same memory location if they
  have different types. This will cause us to pre-load an invariant
  location once for each type that is used to access it. However, we can
  thereby avoid invalid casting, especially if an array is accessed
  though different typed/sized invariant loads.

  This basically reverts the changes in r260023 but keeps the test
  cases.

llvm-svn: 260045
2016-02-07 17:30:13 +00:00
Johannes Doerfert adeab372ca Simplify code [NFC]
llvm-svn: 260030
2016-02-07 13:57:32 +00:00
Tobias Grosser 8ebdc2dd53 Make memory accesses with different element types optional
We also disable this feature by default, as there are still some issues in
combination with invariant load hoisting that slipped through my initial
testing.

llvm-svn: 260025
2016-02-07 08:48:57 +00:00
Tobias Grosser 107cd5f5f6 IslNodeBuilder: Invariant load hoisting of elements with differing sizes
Always use access-instruction pointer type to load the invariant values.
Otherwise mismatches between ScopArrayInfo element type and memory access
element type will result in invalid casts. These type mismatches are after
r259784 a lot more common and also arise with types of different size, which
have not been handled before.

Interestingly, this change actually simplifies the code, as we now have only
one code path that is always taken, rather then a standard code path for the
common case and a "fixup" code path that replaces the standard code path in
case of mismatching types.

llvm-svn: 260009
2016-02-06 21:23:39 +00:00
Tobias Grosser d840fc7277 Support accesses with differently sized types to the same array
This allows code such as:

void multiple_types(char *Short, char *Float, char *Double) {
  for (long i = 0; i < 100; i++) {
    Short[i] = *(short *)&Short[2 * i];
    Float[i] = *(float *)&Float[4 * i];
    Double[i] = *(double *)&Double[8 * i];
  }
}

To model such code we use as canonical element type of the modeled array the
smallest element type of all original array accesses, if type allocation sizes
are multiples of each other. Otherwise, we use a newly created iN type, where N
is the gcd of the allocation size of the types used in the accesses to this
array. Accesses with types larger as the canonical element type are modeled as
multiple accesses with the smaller type.

For example the second load access is modeled as:

  { Stmt_bb2[i0] -> MemRef_Float[o0] : 4i0 <= o0 <= 3 + 4i0 }

To support code-generating these memory accesses, we introduce a new method
getAccessAddressFunction that assigns each statement instance a single memory
location, the address we load from/store to. Currently we obtain this address by
taking the lexmin of the access function. We may consider keeping track of the
memory location more explicitly in the future.

We currently do _not_ handle multi-dimensional arrays and also keep the
restriction of not supporting accesses where the offset expression is not a
multiple of the access element type size. This patch adds tests that ensure
we correctly invalidate a scop in case these accesses are found. Both types of
accesses can be handled using the very same model, but are left to be added in
the future.

We also move the initialization of the scop-context into the constructor to
ensure it is already available when invalidating the scop.

Finally, we add this as a new item to the 2.9 release notes

Reviewers: jdoerfert, Meinersbur

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

llvm-svn: 259784
2016-02-04 13:18:42 +00:00
Tobias Grosser e2c31210b2 Revert "Support loads with differently sized types from a single array"
This reverts commit (@259587). It needs some further discussions.

llvm-svn: 259629
2016-02-03 05:53:27 +00:00
Tobias Grosser 5d3fc1ea43 Support loads with differently sized types from a single array
We support now code such as:

void multiple_types(char *Short, char *Float, char *Double) {
  for (long i = 0; i < 100; i++) {
    Short[i] = *(short *)&Short[2 * i];
    Float[i] = *(float *)&Float[4 * i];
    Double[i] = *(double *)&Double[8 * i];
  }
}

To support such code we use as element type of the modeled array the smallest
element type of all original array accesses. Accesses with larger types are
modeled as multiple accesses with the smaller type.

For example the second load access is modeled as:

  { Stmt_bb2[i0] -> MemRef_Float[o0] : 4i0 <= o0 <= 3 + 4i0 }

To support jscop-rewritable memory accesses we need each statement instance to
only be assigned a single memory location, which will be the address at which
we load the value. Currently we obtain this address by taking the lexmin of
the access function. We may consider keeping track of the memory location more
explicitly in the future.

llvm-svn: 259587
2016-02-02 22:05:29 +00:00
Johannes Doerfert 800e17a75c Add const keyword to MemoryAccess argument [NFC]
llvm-svn: 259504
2016-02-02 14:16:01 +00:00
Michael Kruse 70131d3416 Introduce MemAccInst helper class; NFC
MemAccInst wraps the common members of LoadInst and StoreInst. Also use
of this class in:
- ScopInfo::buildMemoryAccess
- BlockGenerator::generateLocationAccessed
- ScopInfo::addArrayAccess
- Scop::buildAliasGroups
- Replace every use of polly::getPointerOperand

Reviewers: jdoerfert, grosser

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

llvm-svn: 258947
2016-01-27 17:09:17 +00:00
Michael Kruse ee6a4fc680 Unique phi write accesses
Ensure that there is at most one phi write access per PHINode and
ScopStmt. In particular, this would be possible for non-affine
subregions with multiple exiting blocks. We replace multiple MAY_WRITE
accesses by one MUST_WRITE access. The written value is constructed
using a PHINode of all exiting blocks. The interpretation of the PHI
WRITE's "accessed value" changed from the incoming value to the PHI like
for PHI READs since there is no unique incoming value.

Because region simplification shuffles around PHI nodes -- particularly
with exit node PHIs -- the PHINodes at analysis time does not always
exist anymore in the code generation pass. We instead remember the
incoming block/value pair in the MemoryAccess.

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

llvm-svn: 258809
2016-01-26 13:33:27 +00:00
Tobias Grosser f2cdd144e5 BlockGenerators: Replace getNewScalarValue with getNewValue
Both functions implement the same functionality, with the difference that
getNewScalarValue assumes that globals and out-of-scop scalars can be directly
reused without loading them from their corresponding stack slot. This is correct
for sequential code generation, but causes issues with outlining code e.g. for
OpenMP code generation. getNewValue handles such cases correctly.

Hence, we can replace getNewScalarValue with getNewValue. This is not only more
future proof, but also eliminates a bunch of code.

The only functionality that was available in getNewScalarValue that is lost
is the on-demand creation of scalar values. However, this is not necessary any
more as scalars are always loaded at the beginning of each basic block and will
consequently always be available when scalar stores are generated. As this was
not the case in older versions of Polly, it seems the on-demand loading is just
some older code that has not yet been removed.

Finally, generateScalarLoads also generated loads for values that are loop
invariant, available in GlobalMap and which are preferred over the ones loaded
in generateScalarLoads. Hence, we can just skip the code generation of such
scalar values, avoiding the generation of dead code.

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

llvm-svn: 258799
2016-01-26 10:01:35 +00:00
Tobias Grosser 5c7f16be6b BlockGenerators: Avoid redundant map lookup [NFC]
llvm-svn: 258660
2016-01-24 14:16:59 +00:00
Johannes Doerfert 370cf00c9f Make sure we preserve alignment information after hoisting invariant load
In Polly, after hoisting loop invariant loads outside loop, the alignment
information for hoisted loads are missing, this patch restore them.

Contributed-by: Lawrence Hu <lawrence@codeaurora.org>

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

llvm-svn: 258105
2016-01-19 00:17:21 +00:00
Roman Gareev b0c4e49a37 Fix of r257495.
Remove redundant "FPM->add(createDemoteRegisterToMemoryPass());"

llvm-svn: 257514
2016-01-12 20:47:48 +00:00
Roman Gareev 6ebc01c973 We do not need to schedule another loop interchange pass after Polly, as Polly
should perform loop interchanges itself.

This also fixes a bug we see due to the "loop-interchange" pass producing
incorrect IR when compiling linpack-pc.c from the LLVM test-suite with
"-polly-position=before-vectorizer".

Reviewed-by: Tobias Grosser <tobias@grosser.es>
llvm-svn: 257495
2016-01-12 17:59:06 +00:00
Johannes Doerfert 5dced2693e Refactor canSynthesize in the BlockGenerators [NFC]
llvm-svn: 256269
2015-12-22 19:08:49 +00:00
Johannes Doerfert 28f8ac1db2 Treat inline assembly as a constant in the code generation.
llvm-svn: 256267
2015-12-22 19:08:24 +00:00
Johannes Doerfert 42df8d1db6 Reduce indention in BlockGenerator::trySynthesizeNewValue [NFC]
llvm-svn: 256266
2015-12-22 19:08:01 +00:00
Tobias Grosser fcabb155c1 BlockGenerators: Remove unnecessary const_cast
llvm-svn: 256227
2015-12-22 01:41:25 +00:00
Tobias Grosser 5624d3c978 Adjust formatting to clang-format changes in 256149
llvm-svn: 256151
2015-12-21 12:38:56 +00:00
Tobias Grosser 184a4926b3 BlockGenerator: Use getArrayAccessFor for vector code generation
getAccessFor does not guarantee a certain access to be returned in case an
instruction is related to multiple accesses. However, in the vector code
generation we want to know the stride of the array access of a store
instruction. By using getArrayAccessFor we ensure we always get the correct
memory access.

This patch fixes a potential bug, but I was unable to produce a failing test
case. Several existing test cases cover this code, but all of them already
passed out of luck (or the specific but not-guaranteed order in which we build
memory accesses).

llvm-svn: 255715
2015-12-15 23:50:01 +00:00
Tobias Grosser a69d4f0d83 VectorBlockGenerator: Generate scalar loads for vector statements
When generating scalar loads/stores separately the vector code has not been
updated. This commit adds code to generate scalar loads for vector code as well
as code to assert in case scalar stores are encountered within a vector loop.

llvm-svn: 255714
2015-12-15 23:49:58 +00:00
Tobias Grosser 0921477248 ScopInfo: Look up first (and only) array access
When rewriting the access functions of load/store statements, we are only
interested in the actual array memory location. The current code just took
the very first memory access, which could be a scalar or an array access. As
a result, we failed to update access functions even though this was requested
via .jscop.

llvm-svn: 255713
2015-12-15 23:49:53 +00:00
Michael Kruse 5bbc0e1888 Fix typos; NFC
llvm-svn: 255580
2015-12-14 23:41:32 +00:00
Tobias Grosser 9bd0dad926 BlockGenerator: Do not use fast-path for external constants
This change should not change the behavior of Polly today, but it allows
external constants to be remapped e.g. when targetting multiple LLVM modules.

llvm-svn: 255506
2015-12-14 16:19:59 +00:00
Tobias Grosser 6f764bbd9c BlockGenerator: Drop unneeded const_casts
llvm-svn: 255505
2015-12-14 16:19:54 +00:00
Tobias Grosser a535dff471 ScopInfo: Harmonize the different array kinds
Over time different vocabulary has been introduced to describe the different
memory objects in Polly, resulting in different - often inconsistent - naming
schemes in different parts of Polly. We now standartize this to the following
scheme:

  KindArray, KindValue, KindPHI, KindExitPHI
             | ------- isScalar -----------|

In most cases this naming scheme has already been used previously (this
minimizes changes and ensures we remain consistent with previous publications).
The main change is that we remove KindScalar to clearify the difference between
a scalar as a memory object of kind Value, PHI or ExitPHI and a value (former
KindScalar) which is a memory object modeling a llvm::Value.

We also move all documentation to the Kind* enum in the ScopArrayInfo class,
remove the second enum in the MemoryAccess class and update documentation to be
formulated from the perspective of the memory object, rather than the memory
access. The terms "Implicit"/"Explicit", formerly used to describe memory
accesses, have been dropped. From the perspective of memory accesses they
described the different memory kinds well - especially from the perspective of
code generation - but just from the perspective of a memory object it seems more
straightforward to talk about scalars and arrays, rather than explicit and
implicit arrays. The last comment is clearly subjective, though. A less
subjective reason to go for these terms is the historic use both in mailing list
discussions and publications.

llvm-svn: 255467
2015-12-13 19:59:01 +00:00
Tobias Grosser 2d3d4ec860 executeScopConditionally: Introduce special exiting block
When introducing separate control flow for the original and optimized code we
introduce now a special 'ExitingBlock':

      \   /
    EnteringBB
        |
    SplitBlock---------\
   _____|_____         |
  /  EntryBB  \    StartBlock
  |  (region) |        |
  \_ExitingBB_/   ExitingBlock
        |              |
    MergeBlock---------/
        |
      ExitBB
      /    \

This 'ExitingBlock' contains code such as the final_reloads for scalars, which
previously were just added to whichever statement/loop_exit/branch-merge block
had been generated last. Having an explicit basic block makes it easier to
find these constructs when looking at the CFG.

llvm-svn: 255107
2015-12-09 11:38:22 +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
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 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 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
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 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
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 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
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
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 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
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 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 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 907456fe04 [FIX] Use appropriately sized types for big constants
llvm-svn: 251869
2015-11-03 00:26:22 +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 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
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 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 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
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 26e59ee746 Drop unused parameter from handleOutsideUsers
llvm-svn: 250606
2015-10-17 08:25:54 +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
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
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 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 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 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 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 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
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 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 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
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
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 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
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
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 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
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
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 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 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