Commit Graph

3060 Commits

Author SHA1 Message Date
Michael Kruse
9cfab5e249 [Polly] Add support for -polly-dump-before/after with NPM.
The new pass manager does not allow adding module passes at the
-polly-position=before-vectorizer extension point. Introduce a
DumpFunctionPass that dumps only current function. In contrast to the
legacy pass manager's -polly-dump-before, each function will be dumped
into its own file. -polly-dump-before-file is still not supported.

The DumpFunctionPass uses llvm::CloneModule to copy the current function
into a new module and then write it into a file.
2021-08-22 20:43:35 -05:00
Michael Kruse
58e4e71fc8 [Polly] Introduce caching for the isErrorBlock function. NFC.
Compilation of the file insn-attrtab.c of the SPEC CPU 2017 502.gcc_r
benchmark takes excessive time (> 30min) with Polly enabled. Most time
is spent in the isErrorBlock function querying the DominatorTree.
The isErrorBlock is invoked redundantly over the course of ScopDetection
and ScopBuilder. This patch introduces a caching mechanism for its
result.

Instead of a free function, isErrorBlock is moved to ScopDetection where
its cache map resides. This also means that many functions directly or
indirectly calling isErrorBlock are not "const" anymore. The
DetectionContextMap was marked as "mutable", but IMHO it never should
have been since it stores the detection result.

502.gcc_r only takes excessive time with the new pass manager. The
reason seeams to be that it invalidates the ScopDetection analysis more
often than the legacy pass manager, for unknown reasons.
2021-08-18 14:05:50 -05:00
Michael Kruse
e8c8407aca [Polly] Break early when the result is known. NFC. 2021-08-18 12:41:04 -05:00
Michael Kruse
0f1e67fac2 [Polly] Fix possibly infinite loop.
The loop had no side-effect since first committed in 642594ae87.
While it is obvious what was intended, the code seems to never trigger.
2021-08-17 10:43:04 -05:00
Riccardo Mori
ce8272afb3 [Polly][Isl] Use isl::val::sub instead of isl::val::sub_ui. NFC
This is part of an effort to reduce the differences between the custom C++ bindings used right now by polly in `lib/External/isl/include/isl/isl-noxceptions.h` and the official isl C++ interface.

Changes made:
 -  Use `isl::val::sub` instead of `isl::val::sub_ui`
 - `isl-noexceptions.h` has been generated by 355e84163a

Depends on D107225

Reviewed By: Meinersbur

Differential Revision: https://reviews.llvm.org/D107293
2021-08-17 09:34:52 +02:00
Riccardo Mori
d3fdbda6b0 [Polly][Isl] Move to the new-polly-generator branch version of isl-noexceptions.h. NFCI
This is part of an effort to reduce the differences between the custom C++ bindings used right now by polly in `lib/External/isl/include/isl/isl-noxceptions.h` and the official isl C++ interface.

With this commit we are moving from the `polly-generator` branch to the `new-polly-generator` branch that is more mantainable and is based on the official C++ interface `cpp-checked.h`.

Changes made:
 - There are now many sublcasses for `isl::ast_node` representing different isl types. Use `isl::ast_node_for`, `isl::ast_node_user`, `isl::ast_node_block` and `isl::ast_node_mark` where needed.
 - There are now many sublcasses for `isl::schedule_node` representing different isl types. Use `isl::schedule_node_mark`, `isl::schedule_node_extension`, `isl::schedule_node_band` and `isl::schedule_node_filter` where needed.
 - Replace the `isl::*::dump` with `dumpIslObj` since the isl dump method is not exposed in the C++ interface.
 - `isl::schedule_node::get_child` has been renamed to `isl::schedule_node::child`
 - `isl::pw_multi_aff::get_pw_aff` has been renamed to `isl::pw_multi_aff::at`
 - The constructor `isl::union_map(isl::union_pw_multi_aff)` has been replaced with the static method `isl::union_map::from()`
 - Replace usages of `isl::val::add_ui` with `isl::val::add`
 - `isl::union_set_list::alloc` is now a constructor
 - All the `isl_size` values are now wrapped inside the class `isl::size` use `isl::size::release` to get the internal `isl_size` value where needed.
 - `isl-noexceptions.h` has been generated by 73f5ed1f4d

No functional change intended.

Reviewed By: Meinersbur

Differential Revision: https://reviews.llvm.org/D107225
2021-08-16 15:53:26 +02:00
Michael Kruse
5eeaac22af [Polly] Rename CodeGen -> generateCode. NFC.
To conform to function naming convention: camelCase and start with a
verb.
2021-08-13 12:46:07 -05:00
Michael Kruse
0232c1d10d [Polly] Decompose object construction and detection algorithm. NFC.
Avoid doing the detection work inside the constructor. In addition to
polymorphism being unintuitive in constructors and other design problems
such as if an exception is thrown, the ScopDetection class is usable
without detection in the sense of "no Scop found" or "function skipped".
2021-08-13 12:44:37 -05:00
Michael Kruse
9069082785 [Polly] Simplify domains before gist.
The compilation of the file
526.blender_r/src/blender/source/blender/editors/space_logic/logic_ops.c
from the SPEC CPU 2017 benchmarks took excessive time to compute

    InvalidDomain.gist_params(Ctx)

Simplifying beforehand, specifically using isl_set_detect_equalities,
reduces the computation time to a negible level again.
2021-08-12 08:48:14 -05:00
Tarindu Jayatilaka
7a797b2902 Take OptimizationLevel class out of Pass Builder
Pulled out the OptimizationLevel class from PassBuilder in order to be able to access it from within the PassManager and avoid include conflicts.

Reviewed By: mtrofin

Differential Revision: https://reviews.llvm.org/D107025
2021-07-29 21:57:23 -07:00
Riccardo Mori
ec3da1a43f Update isl to isl-0.24-69-g54aac5ac
This is needed for having the functions isl_{set,map}_n_basic_{set,map}
exported to the C++ interface.
Some tests have been modified to reflect the isl changes.
2021-07-27 17:38:12 +02:00
Riccardo Mori
2ae7d6d427 Revert "Update isl to isl-0.24-69-g54aac5ac"
This reverts commit 13f95cc3d1.

The commit makes some polly tests failing
2021-07-23 19:07:19 +02:00
Riccardo Mori
13f95cc3d1 Update isl to isl-0.24-69-g54aac5ac
This is needed for having the functions isl_{set,map}_n_basic_{set,map}
exported to the C++ interface
2021-07-23 18:46:48 +02:00
Riccardo Mori
84dfbf5a77 [Polly][Isl] Stop using isl::set::lex_le_set. NFC
This is part of an effort to reduce the differences between the custom C++ bindings used right now by polly in `lib/External/isl/include/isl/isl-noxceptions.h` and the official isl C++ interface.

Changes made:
 - Stop using `isl::set::lex_le_set`. The official way to do this is to use `isl::map::lex_le_at`
 - Removed `isl::set::lex_le_set` from `isl-noexceptions.h`
 - `isl-noexceptions.h` has been generated by this 266fea1d3d

Reviewed By: Meinersbur

Differential Revision: https://reviews.llvm.org/D106269
2021-07-19 17:23:56 +02:00
Riccardo Mori
159e072f81 [Polly] Use isl::set::tuple_dim instead of isl::set::dim. NFC
This is part of an effort to reduce the differences between the custom C++ bindings used right now by polly in `lib/External/isl/include/isl/isl-noxceptions.h` and the official isl C++ interface.

Note that not all the usages of `isl::set::dim` were replaced
2021-07-19 12:43:23 +02:00
Riccardo Mori
d5ee355f89 [Polly][Isl] Use isl::union_map::unite() instead of isl::union_map::add_map(). NFC
This is part of an effort to reduce the differences between the custom C++ bindings used right now by polly in `lib/External/isl/include/isl/isl-noxceptions.h` and the official isl C++ interface.

Changes made:
 - Use `isl::union_map::unite()` instead of `isl::union_map::add_map()`
 - `isl-noexceptions.h` has been generated by this 3f43ae29fa

Depends on D106059

Reviewed By: Meinersbur

Differential Revision: https://reviews.llvm.org/D106061
2021-07-19 12:11:00 +02:00
Riccardo Mori
bad3ebbaae [Polly][Isl] Stop generating isl::union_{set,map} from isl::space. NFC
This is part of an effort to reduce the differences between the custom C++ bindings used right now by polly in `lib/External/isl/include/isl/isl-noxceptions.h` and the official isl C++ interface.

Changes made:
 - Stop generating `isl::union_set` and isl::union_map` from `isl::space` and instead generate them from `isl::ctx`
 - Disable clang-format on `isl-noexceptions.h`
 - Removed `isl::union_{set,map}` generator from `isl::space` from `isl-noexceptions.h`
 - `isl-noexceptions.h` has been generated by this 87c3413b6f

Reviewed By: Meinersbur

Differential Revision: https://reviews.llvm.org/D106059
2021-07-19 11:24:53 +02:00
Eli Friedman
0ce9acf61d [polly] Fix uses of deprecated overload of IRBuilder::CreateGEP. 2021-07-18 18:43:01 -07:00
Eli Friedman
8422bfa3c3 [polly] Fix regression tests with POLLY_ENABLE_GPGPU_CODEGEN
Apparently there was a latent bug here.
2021-07-18 18:43:01 -07:00
Eli Friedman
43705149ed [polly] Get rid of a couple uses of PointerType::getElementType(). 2021-07-18 13:51:38 -07:00
Nikita Popov
2c68ecccc9 [OpaquePtr] Remove uses of CreateGEP() without element type
Remove uses of to-be-deprecated API. In cases where the correct
element type was not immediately obvious to me, fall back to
explicit getPointerElementType().
2021-07-17 22:56:27 +02:00
Nikita Popov
6225d0cc6e [OpaquePtr] Remove uses of CreateInBoundsGEP() without element type
Remove uses of to-be-deprecated API.

Unfortunately this one mostly just makes the use of
getPointerElementType() explicit, as the correct type to use
wasn't immediately available (deriving it from QualType is left
as an excercise to the reader).
2021-07-17 21:27:16 +02:00
Michael Kruse
7e29e57917 [Polly] Fix misleading debug message. NFC.
The number of parameters can be the reason for aliasing checks not being
generated, but most of the time it for other reasons.
2021-07-14 16:25:45 -05:00
Riccardo Mori
0813bd1696 [Polly][Isl] Use isl::*::ctx instead of isl::*::get_ctx. NFC
This is part of an effort to reduce the differences between the custom C++ bindings used right now by polly in `lib/External/isl/include/isl/isl-noxceptions.h` and the official isl C++ interface.

Changes made:
 - Use `isl::*::ctx()` instead of `isl::*::get_ctx()` (for example `isl::space::ctx()` instead of `isl::space::get_ctx()`)
 - Add `isl::` namespace in front of isl types to avoid confusion (for example `isl::space::ctx` and `isl::ctx`
 - `isl-noexceptions.h` has been generated by this b64e33c62d

Reviewed By: Meinersbur

Differential Revision: https://reviews.llvm.org/D105691
2021-07-09 21:14:14 +02:00
patacca
dddb225acf [Polly][Isl] Update isl to isl-0.24-52-gd7be01f7
This is needed because the functions `isl_union_{set,map}_get_{set,map}_list` have been exposed to the C++ interface
2021-07-09 12:27:55 +02:00
patacca
b55aedd0b8 [Polly][Isl] Use isl::union_set::unite() instead of isl::union_set::add_set(). NFC
This is part of an effort to reduce the differences between the custom C++ bindings used right now by polly in `lib/External/isl/include/isl/isl-noxceptions.h` and the official isl C++ interface.

Changes made:
 - Use `isl::union_set::unite()` instead of `isl::union_set::add_set()`
 - `isl-noexceptions.h` has been generated by this 390c44982b

Depends on D104994

Reviewed By: Meinersbur

Differential Revision: https://reviews.llvm.org/D105444
2021-07-07 16:26:55 +02:00
patacca
f482497c38 [Polly][Isl] Use isl::set::tuple_dim, isl::map::domain_tuple_dim and isl::map::range_tuple_dim. NFC
This is part of an effort to reduce the differences between the custom C++ bindings used right now by polly in `lib/External/isl/include/isl/isl-noxceptions.h` and the official isl C++ interface.

Changes made:
 - Use `isl::set::tuple_dim` instead of `isl::set::dim` and `isl::set::n_dim`
 - Use `isl::map::domain_tuple_dim` instead of `isl::map::dim`
 - Use `isl::map::range_tuple_dim` instead of `isl::map::dim`
 - isl-noexceptions.h has been generated by this 45576e1b42

Note that not all the usage of `isl::{set,map}::dim` where replaced

Reviewed By: Meinersbur

Differential Revision: https://reviews.llvm.org/D104994
2021-07-06 11:20:45 +02:00
patacca
3f9bf9f42a [Polly][Isl] Update isl to isl-0.24-47-g8853f375
This is needed for the new functions exposed in the C++ interface as used in https://reviews.llvm.org/D104994

Reviewed By: Meinersbur

Differential Revision: https://reviews.llvm.org/D105132
2021-07-04 19:50:39 +02:00
Michael Kruse
e2d4b02404 [Polly][ScopInliner] Indicate if the IR has changed.
Return true to indicate that the IR has changed if the nested pass
manager has changed it.

Fixes the ScopInliner tests in the LLVM_ENABLE_EXPENSIVE_CHECKS=ON
configuration.

Thanks to Alexandre Ganea for reporting.
2021-06-24 15:44:39 -05:00
patacca
2a629efc74 [Polly][Isl] Refactoring IslAstInfo::getBuild() and IslAstInfo::IslAstUserPayload::Build to use isl++. NFC
Polly uses algorithms from the Integer Set Library (isl), which is a library written in C and which is incompatible with the rest of the LLVM as it is written in C++.

Changes made:
 - Refactoring the method `IslAstInfo::getBuild()`
 - `IslAstInfo::IslAstUserPayload.Build` now uses C++ types instead of C types
 - Removing destructor of `IslAstInfo::IslAstUserPayload`

Reviewed By: Meinersbur

Differential Revision: https://reviews.llvm.org/D104370
2021-06-18 09:53:51 +02:00
Bjorn Pettersson
6aac2773d8 [polly][GPGPU] Fixup related to overloading exponent type in llvm.powi
Commit 4c7f820b2b changed the llvm.powi intrinsic to support
different 'int' sizes for the exponent. That happened to break
the IntrinsicToLibdeviceFunc mapping in PPCGCodeGeneration, which
obviously should have been updated as part of commit 4c7f820b2b
(https://reviews.llvm.org/D99439).

The shortcoming was found by buildbots that use
   -DPOLLY_ENABLE_GPGPU_CODEGEN=ON

This patch should fixup the problem.
2021-06-18 08:59:06 +02:00
patacca
cfe117def7 [Polly][Isl] Replacing isl method to_str() with stringFromIslObj(). NFC.
This is part of an effort to reduce the differences between the custom C++ bindings used right now by polly in `lib/External/isl/include/isl/isl-noxceptions.h` and the official isl C++ interface.

Changes made:
 - Removing method `to_str()` from all the classes in the isl C++ bindings.
 - Overload method `stringFromIslObj()` so it accepts isl C++ objects.
 - To keep backward compatibility `stringFromIslObj()` now accepts a value that is returned if the isl C object is `null` or doesn't have a string representation (by default it's an empty string). In some cases it's better to have the string "null" instead of an empty string.
 - isl-noexceptions.h has been generated by this d33ec3a3bb

Reviewed By: Meinersbur

Differential Revision: https://reviews.llvm.org/D104211
2021-06-15 14:22:10 +02:00
patacca
7c7978a122 [Polly][Isl] Removing explicit operator bool() from isl C++ bindings. NFC.
This is part of an effort to reduce the differences between the custom C++ bindings used right now by polly in `lib/External/isl/include/isl/isl-noxceptions.h` and the official isl C++ interface.

Changes made:
 - Removing explicit operator bool() from all the classes in the isl C++ bindings.
 - Replace each call to operator bool() to method `is_null()`.
 - isl-noexceptions.h has been generated by this 27396daac5

Reviewed By: Meinersbur

Differential Revision: https://reviews.llvm.org/D103976
2021-06-11 14:44:24 +02:00
Michael Kruse
a56bd7dec8 [Polly][Matmul] Re-pack A in every iteration.
Packed_A must be copied repeatedly, not just for the first iteration of
the outer tile.

This fixes llvm.org/PR50557
2021-06-09 15:19:52 -05:00
patacca
9b41d0958e [Polly][Isl] Removing nullptr constructor from C++ bindings. NFC.
[Polly][Isl] Removing nullptr constructor from C++ bindings. NFC.

This is part of an effort to reduce the differences between the custom C++ bindings used right now by polly in `lib/External/isl/include/isl/isl-noxceptions.h` and the official isl C++ interface.

Changes made:
 - Removed `std::nullptr_t` constructor from all the classes in the isl C++ bindings.
 - `isl-noexceptions.h` has been generated by this a7e00bea38

Reviewed By: Meinersbur

Differential Revision: https://reviews.llvm.org/D103751
2021-06-08 23:46:28 +02:00
patacca
f60ea691a9 Revert "[Polly][Isl] Removing nullptr constructor from C++ bindings. NFC."
This reverts commit be5e2fc7bf.

This introduced a building error for polly. https://lab.llvm.org/buildbot#builders/10/builds/4951
2021-06-08 17:12:10 +02:00
patacca
be5e2fc7bf [Polly][Isl] Removing nullptr constructor from C++ bindings. NFC.
[Polly][Isl] Removing nullptr constructor from C++ bindings. NFC.

This is part of an effort to reduce the differences between the custom C++ bindings used right now by polly in `lib/External/isl/include/isl/isl-noxceptions.h` and the official isl C++ interface.

Changes made:
 - Removed `std::nullptr_t` constructor from all the classes in the isl C++ bindings.
 - `isl-noexceptions.h` has been generated by this a7e00bea38

Reviewed By: Meinersbur

Differential Revision: https://reviews.llvm.org/D103751
2021-06-08 15:28:20 +02:00
Michael Kruse
d123e983b3 [Polly] Move MatMul optimization into its own file. NFC.
Functions shared between generalized matrix-multiplication optimization
and other post-reschedule optimizations (tiling, prevect) are moved into
the schedule tree transformation utility ScheduleTreeTransform.
2021-06-04 23:22:30 -05:00
Michael Kruse
86008477a4 [Polly] Avoid compiler warning. NFC.
Avoid the warning

    /polly/lib/Support/RegisterPasses.cpp:833:3: warning: default label in switch which covers all enumeration values [-Wcovered-switch-default]
      default:
      ^

since all cases are now handled.

Thanks to Luke Benes for reporting.
2021-05-22 00:21:20 -05:00
Michael Kruse
ad568f4286 [Polly] Add support for -polly-dump-after(-file) with the NPM.
For the same reason as with -polly-dump-before, it is only supported
with -polly-position=early.
2021-05-17 22:20:47 -05:00
Michael Kruse
29bef8e4e3 [Polly] Add support for -polly-dump-before(-file) with the NPM.
Only supported with -polly-position=early. Unfortunately, the
extension point callpack for VectorizerStart only passes a
FunctionPassManager, making it impossible to add a module pass.
2021-05-17 20:58:37 -05:00
Michael Kruse
5aafcb2b44 [Polly] Add support for -polly-position=early with the NPM.
This required support for the canonicalization passes, inlcuding
porting RewriteByReferenceParams to the NPM.

For some reason, the legacy pass pipeline with -polly-position=early did
not run the CodePreparation pass. This was fixed as well.
2021-05-14 12:55:03 -05:00
Arthur Eubanks
34a8a437bf [NewPM] Hide pass manager debug logging behind -debug-pass-manager-verbose
Printing pass manager invocations is fairly verbose and not super
useful.

This allows us to remove DebugLogging from pass managers and PassBuilder
since all logging (aside from analysis managers) goes through
instrumentation now.

This has the downside of never being able to print the top level pass
manager via instrumentation, but that seems like a minor downside.

Reviewed By: ychen

Differential Revision: https://reviews.llvm.org/D101797
2021-05-07 21:51:47 -07:00
Fangrui Song
d8aba75a76 Internalize some cl::opt global variables or move them under namespace llvm 2021-05-07 11:15:43 -07:00
Bjorn Pettersson
3ee826594a Make dependency between certain analysis passes transitive (reapply)
LazyBlockFrequenceInfoPass, LazyBranchProbabilityInfoPass and
LoopAccessLegacyAnalysis all cache pointers to their nestled required
analysis passes. One need to use addRequiredTransitive to describe
that the nestled passes can't be freed until those analysis passes
no longer are used themselves.

There is still a bit of a mess considering the getLazyBPIAnalysisUsage
and getLazyBFIAnalysisUsage functions. Those functions are used from
both Transform, CodeGen and Analysis passes. I figure it is OK to
use addRequiredTransitive also when being used from Transform and
CodeGen passes. On the other hand, I figure we must do it when
used from other Analysis passes. So using addRequiredTransitive should
be more correct here. An alternative solution would be to add a
bool option in those functions to let the user tell if it is a
analysis pass or not. Since those lazy passes will be obsolete when
new PM has conquered the world I figure we can leave it like this
right now.

Intention with the patch is to fix PR49950. It at least solves the
problem for the reproducer in PR49950. However, that reproducer
need five passes in a specific order, so there are lots of various
"solutions" that could avoid the crash without actually fixing the
root cause.

This is a reapply of commit 3655f0757f, that was reverted in
33ff3c2049 due to problems with assertions in the polly
lit tests. That problem is supposed to be solved by also adjusting
ScopPass to explicitly preserve LazyBlockFrequencyInfo and
LazyBranchProbabilityInfo (it already preserved
OptimizationRemarkEmitter which depends on those lazy passes).

Differential Revision: https://reviews.llvm.org/D100958
2021-05-05 15:17:55 +02:00
Michael Kruse
286677870b [Polly][ManualOpt] Match interpretation of unroll metadata to LoopUnrolls's.
We previously had a different interpretation of unroll transformation
attributes than how LoopUnroll interpreted it. In particular,
llvm.loop.unroll.enable was needed explicitly to enable it and disabling
metadata was ignored.
Additionally, it required that either full unrolling or an unroll factor
to be specified or fail otherwise. An unroll factor is still required,
but the transformation is ignored with the hope that LoopUnroll is going
to apply the unrolling, since Polly currently does not implement an
heuristic.

Fixes llvm.org/PR50109
2021-04-24 04:30:19 -05:00
Krzysztof Parzyszek
a7f33d720b [Polly] Explicitly include all std headers
There were some recent header changes, and now some std classes
are no longer available in ScopDetection.cpp with the pre-existing
includes.
2021-04-21 12:52:11 -05:00
Michael Kruse
89b59345ee [PollyACC] Fix declaration/stub definition mismatch. NFC.
external.c defines stub functions that are never used because of how
Polly uses PPCG. Unfortunately, they are declared as functions without
return values or parameters which does not match their declarations.
Since they are never called, this was usually not a problem, but an LTO
build gets confused with differently declared functions, or in case of
pet_options_args, a global variable declaration that is defined as a
function

Resolve by including the declaring headers in external.c which forces
the declaration and definition to match at compile-time.

This fixes llvm.org/50021
2021-04-21 11:52:43 -05:00
Michael Kruse
6048d1d19c [PollyACC] Configure PollyPPCG only if needed.
The PollyPPCG library is only needed when POLLY_ENABLE_GPGPU_CODEGEN=ON.
If disabled, the library target is still created, but not linked against
anything.

This change does not add create the PollyPPCG build target if not
needed.

Motivated by llvm.org/PR50021
2021-04-21 01:08:01 -05:00
Michael Kruse
90e5ce0b0d [PollyACC] Fix implicit function definitions. NFC.
The isl_id_* have been in used without including the correspodning
isl/id.h header. According to rules in C, a function is defined
implicitly when first used with an assumed int return type (32 bits on
64 bit systems). But the implementation returns a pointer (64 bits on 64
bit systems). Is usually has no consequence because the return value is
stored in a registers that is 64 bits (RAX) and the optimizer does not
truncate its value before using it again as a pointer value. However,
LTO optimizers will be rightfull;y confused.

Fix by including <isl/id.h>

This fixes llvm.org/PR50021
2021-04-21 01:08:00 -05:00