Commit Graph

875 Commits

Author SHA1 Message Date
Michael Kruse
7860c5fe4e [IslAst] Fix InParallelFor nesting.
IslAst could mark two nested outer loops as "OutermostParallel". It
caused that the code generator tried to OpenMP-parallelize both loops,
which it is not prepared loop.

It was because the recursive AST build algorithm managed a flag
"InParallelFor" to ensure that no nested loop is also marked as
"OutermostParallel". Unfortunatetly the same flag was used by nodes
marked as SIMD, and reset to false after the SIMD node. Since loops can
be marked as SIMD inside "OutermostParallel" loops, the recursive
algorithm again tried to mark loops as "OutermostParellel" although
still nested inside another "OutermostParallel" loop.

The fix exposed another bug: The function "astScheduleDimIsParallel" was
only called when a loop was potentially "OutermostParallel" or
"InnermostParallel", but as a side-effect also determines the minimum
dependence distance. Hence, changing when we need to know whether a loop
is "OutermostParallel" also changed which loop was annotated with
"#pragma minimal dependence distance".

Moreover, some complex condition linked with "InParallelFor" determined
whether a loop should be an "InnermostParallel" loop. It missed some
situations where it would not use mark as such although being inside an
SIMD mark node, and therefore not be annotated using "#pragma simd".

The changes in particular:

1. Split the "InParallelFor" flag into an "InParallelFor" and an
   "InSIMD" flag.

2. Unconditionally call "astScheduleDimIsParallel" for its side-effects
   and store the result in "InParallel" for later use.

3. Simplify the condition when a loop is "InnermostParallel".

Fixes llvm.org/PR33153 and llvm.org/PR38073.

llvm-svn: 343212
2018-09-27 13:39:37 +00:00
Tobias Grosser
4beb2f964b [PerfMonitor] Fix rdtscp callsites
Summary:
Update all rdtscp callsites in PerfMonitor so that they conform with the signature changes introduced in r341698.

Reviewers: grosser, bollu

Subscribers: llvm-commits

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

llvm-svn: 341946
2018-09-11 14:17:44 +00:00
Tobias Grosser
5f865032db PPCG codegen
The latest version of the isl C++ bindings does not export the 'set'
method yet. Fall back to the C interface until this method can be
exported.

llvm-svn: 338512
2018-08-01 10:48:38 +00:00
Michael Kruse
42ad818265 [Polly-ACC] Fix compilation after r338450. NFC.
llvm-svn: 338462
2018-08-01 00:27:29 +00:00
Michael Kruse
e873673b0c [CodeGen] Convert IslNodeBuilder::getNumberOfIterations to isl++. NFC.
llvm-svn: 338451
2018-07-31 23:01:50 +00:00
Michael Kruse
f16378b080 [CodeGen] Convert IslNodeBuilder::createForSequential to isl++. NFC.
llvm-svn: 338450
2018-07-31 22:43:04 +00:00
Michael Kruse
ade2242e7e [CodeGen] Convert IslNodeBuilder::getUpperBound to isl++. NFC.
llvm-svn: 338449
2018-07-31 22:42:59 +00:00
Tobias Grosser
670482db8b [IslNodeBuilder] Use isl++ to replace foreach_set with for loop
llvm-svn: 337247
2018-07-17 07:08:01 +00:00
Michael Kruse
9f305371d9 [CodeGen] Fix potential null pointer dereference. NFC.
ScalarEvolution::getSCEV dereferences its argument, s.t. passing nullptr
leads to undefined behaviour.

Check for nullptr before calling it instead of checking its argument
afterwards.

llvm-svn: 336350
2018-07-05 13:44:50 +00:00
Siddharth Bhat
936c74ad0d [PPCGCodeGen] Change printf to outs() to prevent garbled output. [NFC]
Summary:
It appears that llvm uses unbuffered C++ streams. So, we should not
mix C and C++ stream operations, because that will give us mixed
up output.

Reviewers: efriedma, jdoerfert, Meinersbur, gareevroman, sebpop, zinob, huihuiz, pollydev, grosser, singam-sanjay, philip.pfaffe

Reviewed By: philip.pfaffe

Subscribers: nemanjai, kbarton

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

llvm-svn: 336288
2018-07-04 16:51:27 +00:00
Philip Pfaffe
d71493cb06 [polly-acc] change cl_get_* return types to 32/64bit
Summary:
This patch changes the return types for ocl_get_* functions during SPIR code generation. Because these functions return size_t types, the return type needs to be changed to the actual size of size_t on the device.

Based on work by Michal Babej and Pekka Jääskeläinen

Patch by: Alain Denzler

Reviewers: grosser, philip.pfaffe, bollu

Reviewed By: grosser, philip.pfaffe

Subscribers: nemanjai, kbarton, llvm-commits

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

llvm-svn: 336080
2018-07-02 07:40:47 +00:00
Philip Pfaffe
66a05ad672 Simplify the implementation of getCUDALibDeviceFunction. NFC.
Summary:
The function is currently awfully complicated. Drop the IILE and use
StringRef over std::string.

Reviewers: Meinersbur, grosser, bollu

Reviewed By: Meinersbur

Subscribers: nemanjai, kbarton, bollu, llvm-commits, pollydev

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

llvm-svn: 334695
2018-06-14 08:54:55 +00:00
Philip Pfaffe
e6e1828004 Run clang-format
llvm-svn: 334172
2018-06-07 08:32:13 +00:00
Philip Pfaffe
30c5e4ad35 Fix a missing lambda return type that tripped the builders
llvm-svn: 334166
2018-06-07 07:50:55 +00:00
Tobias Grosser
6a6d9df78e getDependences to new C++ interface
Reviewers: Meinersbur, grosser, bollu, cs15btech11044, jdoerfert

Reviewed By: grosser

Subscribers: pollydev, llvm-commits

Tags: #polly

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

llvm-svn: 334092
2018-06-06 13:10:32 +00:00
Tobias Grosser
a998f98ba6 Fix formatting
llvm-svn: 333988
2018-06-05 09:03:46 +00:00
David Blaikie
4490465db7 Update for a header file move in LLVM
llvm-svn: 333956
2018-06-04 21:23:32 +00:00
Philip Pfaffe
c06a6380a0 [Acc] Re-land r326643 to finally fix PR33208.
Other than before, don't clear out LI entirely but only those relevant
loops.

llvm-svn: 333089
2018-05-23 14:52:35 +00:00
Peter Collingbourne
9a45114b3c CodeGen: Add a dwo output file argument to addPassesToEmitFile and hook it up to dwo output.
Part of PR37466.

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

llvm-svn: 332881
2018-05-21 20:16:41 +00:00
Nicola Zaghen
349506a926 [polly] Update uses of DEBUG macro to LLVM_DEBUG.
The DEBUG() macro is very generic so it might clash with other projects.
The renaming was done as follows:
- git grep -l 'DEBUG' | xargs sed -i 's/\bDEBUG\s\?(/LLVM_DEBUG(/g'
- git diff -U0 master | ../clang/tools/clang-format/clang-format-diff.py -i -p1 -style LLVM

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

llvm-svn: 332352
2018-05-15 13:37:17 +00:00
Tobias Grosser
8dae41a1cb Remove another set or release() calls
llvm-svn: 331129
2018-04-29 00:57:38 +00:00
Tobias Grosser
d3d3d6b75d Remove the last uses of isl::give and isl::take
llvm-svn: 331126
2018-04-29 00:28:26 +00:00
Michael Kruse
e819fffee3 [CodeGen] Print executed statement instances at runtime.
Add the options -polly-codegen-trace-stmts and
-polly-codegen-trace-scalars. When enabled, adds a call to the
beginning of every generated statement that prints the executed
statement instance. With -polly-codegen-trace-scalars, it also prints
the value of all scalars that are used in the statement, and PHIs
defined in the beginning of the statement.

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

llvm-svn: 330864
2018-04-25 19:43:49 +00:00
David Blaikie
60dc462b04 Fixup Polly for an LLVM header file change.
llvm-svn: 330679
2018-04-24 02:23:41 +00:00
Tobias Grosser
c49f115b27 [RuntimeDebugBuilder] Do not break for 64 bit integers
In r330292 this assert was turned incorrectly into an unreachable, but
the correct behavior (thanks Michael) is to assert for anything that is
not 64 bit, but falltrough for 64 bit. I document this in the source
code.

llvm-svn: 330309
2018-04-19 05:38:12 +00:00
Tobias Grosser
b20ae44ed0 [RuntimeDebugBuilder] Turn assert into an unreachable
llvm-svn: 330289
2018-04-18 20:18:43 +00:00
Michael Kruse
4485ae0890 [CodeGen] Allow undefined loads in statement instances outside context.
A check in assert-builds was meant to verify that a load provides a
value in all statement instances (i.e. its domain).  The domain is
commonly gist'ed within the parameter context to contain fewer
constraints.  However, statement instances outside the context are
no valid executions, hence the value provided can be undefined.

Refine the check for valid loads to only needed to be defined within
the SCoP context.

In addition, the JSONImporter had to be changed to allow importing
access relations that are broader than the current access relation,
but still defined over all statement instances.

This should fix the compiler crash in test-suite's oggenc of the
-polly-process-unprofitable buildbot.

llvm-svn: 329655
2018-04-10 01:20:51 +00:00
Michael Kruse
388730c9e0 [CodeGen] Convert BlockGenerator::generateScalarLoads to isl++. NFC.
llvm-svn: 329654
2018-04-10 01:20:47 +00:00
Huihui Zhang
71e54ccd06 [Polly][IslAst] Fix minimal dependence distance.
Summary:
When checking the parallelism of a scheduling dimension, we first check if excluding reduction dependences the loop is parallel or not.
If the loop is not parallel, then we need to return the minimal dependence distance of all data dependences, including the previously subtracted reduction dependences.


Reviewers: grosser, Meinersbur, efriedma, eli.friedman, jdoerfert, bollu

Reviewed By: Meinersbur

Subscribers: llvm-commits, pollydev

Tags: #polly

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

llvm-svn: 329214
2018-04-04 18:08:13 +00:00
Reid Kleckner
757c8cf615 Fix polly build after r328717
llvm-svn: 328728
2018-03-28 19:56:26 +00:00
David Blaikie
fd94eee3b9 Update for LLVM header movement
llvm-svn: 328169
2018-03-21 23:21:10 +00:00
Tobias Grosser
3a99893618 Adjust to clang-format changes
llvm-svn: 328005
2018-03-20 17:16:32 +00:00
Philip Pfaffe
4d50ab86e6 Revert "[Acc] Fix for PR33208"
This reverts commit r326643. Fix didn't really fix anything.

llvm-svn: 326656
2018-03-03 15:34:49 +00:00
Philip Pfaffe
a8f7cc8ec9 [Acc] Fix for PR33208
During codegen, Polly attempts to clear all loops from ScalarEvolution
and LoopInfo, and it does so one block at a time. This causes undefined
behaviour, since this way a loop header might be removed from a loop
before the entire loop is erased, causing ScalarEvolution to run into an
error.

Instead, just delete the entire loop atomically. This fixes currently
failing testcases.

llvm-svn: 326643
2018-03-03 10:47:37 +00:00
Tobias Grosser
718d04c653 Use isl::manage_copy to simplify calls to isl::manage(isl_.._copy())
As part of this cleanup a couple of unnecessary isl::manage(obj.copy()) pattern
are eliminated as well.

We checked for all potential cleanups by scanning for:

  "grep -R isl::manage\( lib/ | grep copy"

llvm-svn: 325558
2018-02-20 07:26:58 +00:00
Michael Kruse
271deb17b0 [CodeGen] Fix noalias annotations for memcpy/memmove.
Memory transfer instructions take two pointers. It is not defined to
which of those a noalias annotation applies. To ensure correctness,
do not add noalias annotations to memcpy/memmove instructions anymore.

The caused a miscompile with test-suite's MultiSource/Applications/obsequi.
Since r321138, the MemCpyOpt pass would remove memcpy/memmove calls if
known to copy uninitialized memory. In that case, it was initialized
by another memcpy, but the annotation for the target pointer said
it would not alias. The annotation was actually meant for the source
pointer, which was was an alloca and could not alias with the target
pointer.

llvm-svn: 321371
2017-12-22 17:44:53 +00:00
Michael Kruse
163cacb469 [CodeGen] Detect empty domain because of parameters context.
Isl does not allow generating isl_ast_expr from an isl_pw_aff that has an
empty domain (i.e. has no pieces). We already detected the case if the
isl_pw_aff comes with an empty domain.

isl_ast_build also considers the domain empty if it is disjoint with the
parameter context (e.g. parameters values that we exclude by runtime
versioning).

Intersect the access relation domain with the parameter context to
also detect such practically empty access domains. The effective
pointer used in the generated code is unimportand because it will never
be executed.

This fixes llvm.org/PR35362

llvm-svn: 318806
2017-11-21 22:11:10 +00:00
Michael Kruse
58166b13e0 Run polly-update-format. NFC.
polly-check-format has been failing since at least r318517,
due to more than one cause.

llvm-svn: 318795
2017-11-21 19:25:26 +00:00
Philip Pfaffe
00fd43b327 Port ScopInfo to the isl cpp bindings
Summary:
Most changes are mechanical, but in one place I changed the program semantics
by fixing a likely bug:

In `Scop::hasFeasibleRuntimeContext()`, I'm now explicitely handling the
error-case. Before, when the call to `addNonEmptyDomainConstraints()`
returned a null set, this (probably) accidentally worked because
isl_bool_error converts to true. I'm checking for nullptr now.

Reviewers: grosser, Meinersbur, bollu

Reviewed By: Meinersbur

Subscribers: nemanjai, kbarton, pollydev, llvm-commits

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

llvm-svn: 318632
2017-11-19 22:13:34 +00:00
Mandeep Singh Grang
02e789c9bf [polly] Remove redundant return [NFC]
Reviewers: grosser, bollu

Reviewed By: grosser

Subscribers: nemanjai, kbarton, llvm-commits

Tags: #polly

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

llvm-svn: 317922
2017-11-10 20:33:08 +00:00
Michael Kruse
06618bf71a [OpenMP] Fix reference collection of latest base ptrs.
When collecting base pointers that need to be made available in parallel
subfunctions, use the base pointer associated with the latest
ScopArrayInfo, instead of the original one.

llvm-svn: 316983
2017-10-31 10:28:22 +00:00
Philip Pfaffe
53c803871e [Acc] Do not statically dispatch into IslNodeBuilder's createFor
Summary:
When GPUNodeBuilder creates loops inside the kernel, it dispatches to
IslNodeBuilder. This however is surprisingly dangerous, since it accesses the
AST Node's user through the wrong type. This patch fixes this problem by
overriding createFor correctly.

This fixes PR35010.

Reviewers: grosser, bollu, Meinersbur

Reviewed By: Meinersbur

Subscribers: Meinersbur, nemanjai, pollydev, llvm-commits, kbarton

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

llvm-svn: 316872
2017-10-29 21:36:34 +00:00
Tobias Grosser
c52b71db15 [GPGPU] Make sure escaping invariant load hoisted scalars are preserved
We make sure that the final reload of an invariant scalar memory access uses the
same stack slot into which the invariant memory access was stored originally.
Earlier, this was broken as we introduce a new stack slot aside of the preload
stack slot, which remained uninitialized and caused our escaping loads to
contain garbage. This happened due to us clearing the pre-populated values
in EscapeMap after kernel code generation. We address this issue by preserving
the original host values and restoring them after kernel code generation.
EscapeMap is not expected to be used during kernel code generation, hence we
clear it during kernel generation to make sure that any unintended uses are
noticed.

llvm-svn: 314894
2017-10-04 10:24:23 +00:00
Tobias Grosser
2fb847fbf6 [GPGPU] Set Polly's RTC to false in case invariant load hoisting fails
This matches the behavior we already have in lib/Codegen/CodeGeneration.cpp and
makes sure that we fall back to the original code. It seems when invariant load
hoisting was introduced to the GPGPU backend we missed to reset the RTC flag,
such that kernels where invariant load hoisting failed executed the 'optimized'
SCoP, which however is set to a simple 'unreachable'. Unsurprisingly, this
results in hard to debug issues that are a lot of fun to debug.

llvm-svn: 314624
2017-10-01 12:39:14 +00:00
Philip Pfaffe
859ef1c09e Fix the build after r314375
r314375 privatized Loop's constructor and replaced it with an Allocator.

llvm-svn: 314412
2017-09-28 12:20:24 +00:00
Tobias Grosser
75d133f0ac [IslExprBuilder] Do not generate RTC with more than 64 bit
Such RTCs may introduce integer wrapping intrinsics with more than 64 bit,
which are translated to library calls on AOSP that are not part of the
runtime and will consequently cause linker errors.

Thanks to Eli Friedman for reporting this issue and reducing the test case.

llvm-svn: 314065
2017-09-23 15:32:07 +00:00
Michael Kruse
0e370cf1a7 Check whether IslAstInfo and DependenceInfo were computed for the same Scop.
Since -polly-codegen reports itself to preserve DependenceInfo and IslAstInfo,
we might get those analysis that were computed by a different ScopInfo for a
different Scop structure. This would be unfortunate because DependenceInfo and
IslAstInfo hold references to resources allocated by
ScopInfo/ScopBuilder/Scop (e.g. isl_id). If -polly-codegen and
DependenceInfo/IslAstInfo do not agree on which Scop to use, unpredictable
things can happen.

When the ScopInfo/Scop object is freed, there is a high probability that the
new ScopInfo/Scop object will be created at the same heap position with the
same address. Comparing whether the Scop or ScopInfo address is the expected
therefore is unreliable.

Instead, we compare the address of the isl_ctx object. Both, DependenceInfo
and IslAstInfo must hold a reference to the isl_ctx object to ensure it is
not freed before the destruction of those analyses which might happen after
the destruction of the Scop/ScopInfo they refer to.  Hence, the isl_ctx
will not be freed and its address not reused as long there is a
DependenceInfo or IslAstInfo around.

This fixes llvm.org/PR34441

llvm-svn: 313842
2017-09-21 00:01:13 +00:00
Michael Kruse
0481d78c6c [CodegenCleanup] Update cleanup passes according (old) PassManagerBuilder.
Update CodegenCleanup using the function-level passes added by
populatePassManager that run between EP_EarlyAsPossible and
EP_VectorizerStart in -O3.

The changes in particular are:
- Added pass create arguments, e.g. ExpensiveCombines for InstCombine.
- Remove reroll pass. The option -reroll-loops is disabled by default.
- Add passes run with UnitAtATime, which is the default.
- Add instances of LibCallsShrinkWrap, TailCallElimination, SCCP
  (sparse conditional constant propagation), Float2Int
  that did not run before.
- Add instances of GVN as in the default pipeline.

Notes:
- GVNHoist, GVNSink, NewGVN are still disabled in the -O3 pipeline.
- The optimization level and other optimization parameters are not
  accessible outside of PassManagerBuilder, hence we cannot add passes
  depending on these.

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

llvm-svn: 312875
2017-09-09 21:43:49 +00:00
Michael Kruse
2f5cbc449a [CodeGen] Bitcast scalar writes to actual value.
The type of NewValue might change due to ScalarEvolution
looking though bitcasts. The synthesized NewValue therefore
becomes the type before the bitcast.

llvm-svn: 312718
2017-09-07 12:15:01 +00:00
Siddharth Bhat
e2950f46c6 [PPCGCodeGen] Document pre-composition with Zero in getExtent. [NFC]
It's weird at first glance that we do this, so I wrote up some
documentation on why we need to perform this process.

llvm-svn: 312715
2017-09-07 11:57:33 +00:00