summaryrefslogtreecommitdiff
path: root/polly/lib/CodeGen/IslNodeBuilder.cpp
AgeCommit message (Collapse)Author
2025-04-28[RemoveDI][Polly] Migrate to adapt to the new DebugRecord format in more ↵Karthika Devi C
areas (#135935) Some of the changes in the patch include: 1. Using iterators instead of instruction pointers when applicable. 2. Modifying Polly functions to accept iterators instead of inst pointers. 3. Updating API usages such as use begin instead of front.
2025-04-24[RemoveDI][Polly] Use iterators instead of instruction pointers to ↵Karthika Devi C
SetInsertPoint (#135336) As part of the effort to transition to using Debug Records instead of Debug intrinsics, some API/argument changes are necessary to achieve the desired behavior from Debug Records. This particular fix involves passing iterators instead of instruction pointers to the SetInsertPoint function. While this is crucial in certain areas, it may be more than needed in others, but it does not cause any harm.
2025-03-30[polly] Use DenseMap::insert_range (NFC) (#133657)Kazu Hirata
2025-03-29[polly] Use *Set::insert_range (NFC) (#133609)Kazu Hirata
2025-03-06[IR] Store Triple in Module (NFC) (#129868)Nikita Popov
The module currently stores the target triple as a string. This means that any code that wants to actually use the triple first has to instantiate a Triple, which is somewhat expensive. The change in #121652 caused a moderate compile-time regression due to this. While it would be easy enough to work around, I think that architecturally, it makes more sense to store the parsed Triple in the module, so that it can always be directly queried. For this change, I've opted not to add any magic conversions between std::string and Triple for backwards-compatibilty purses, and instead write out needed Triple()s or str()s explicitly. This is because I think a decent number of them should be changed to work on Triple as well, to avoid unnecessary conversions back and forth. The only interesting part in this patch is that the default triple is Triple("") instead of Triple() to preserve existing behavior. The former defaults to using the ELF object format instead of unknown object format. We should fix that as well.
2025-01-27[Polly] Ensure i1 preload conditionMichael Kruse
If the preload condition is a constant, ExprBuilder::create returns an integer of the native integer while an i1 is expected. Cast the result to i1 if that happens. Fixes #123932
2025-01-27[Polly] Fix typos discovered by codespell (#124545)Christian Clauss
Patch created using the following command line: ```bash codespell polly --skip="*.pdf,polly/lib/External/*" --write-changes \ --ignore-words-list=couter,createor,distribues,doble,identty,indention,indx,olt,ore,padd,sais,te,theses ```
2025-01-08[Polly] Switch DT/LI in RegionGenerator for parallel subfn (#120413)Karthika Devi C
The patch #102460 already implements separate DT/LI/SE for parallel sub function. Crashes have been reported while region generator tries using oringinal function's DT while creating new parallel sub function due to checks in #101198. This patch aims at fixing those cases by switching the DT/LI while generating parallel function using Region Generator. Fixes #117877
2024-10-16[polly] Avoid llvm::Type::getPointerTo() (NFC) (#112368)Youngsuk Kim
`llvm::Type::getPointerTo()` is to be deprecated & removed soon. Also, avoid pointercasts that are essentially no-ops.
2024-08-10[Polly] Use separate DT/LI/SE for outlined subfn. NFC. (#102460)Michael Kruse
DominatorTree, LoopInfo, and ScalarEvolution are function-level analyses that expect to be called only on instructions and basic blocks of the function they were original created for. When Polly outlined a parallel loop body into a separate function, it reused the same analyses seemed to work until new checks to be added in #101198. This patch creates new analyses for the subfunctions. GenDT, GenLI, and GenSE now refer to the analyses of the current region of code. Outside of an outlined function, they refer to the same analysis as used for the SCoP, but are substituted within an outlined function. Additionally to the cross-function queries of DT/LI/SE, we must not create SCEVs that refer to a mix of expressions for old and generated values. Currently, SCEVs themselves do not "remember" which ScalarEvolution analysis they were created for, but mixing them is just as unexpected as using DT/LI across function boundaries. Hence `SCEVLoopAddRecRewriter` was combined into `ScopExpander`. `SCEVLoopAddRecRewriter` only replaced induction variables but left SCEVUnknowns to reference the old function. `SCEVParameterRewriter` would have done so but its job was effectively superseded by `ScopExpander`, and now also `SCEVLoopAddRecRewriter`. Some issues persist put marked with a FIXME in the code. Changing them would possibly cause this patch to be not NFC anymore.
2024-03-19[NFC][RemoveDIs] Use iterators for insertion at various call-sites (#84736)Jeremy Morse
These are the last remaining "trivial" changes to passes that use Instruction pointers for insertion. All of this should be NFC, it's just changing the spelling of how we identify a position. In one or two locations, I'm also switching uses of getNextNode etc to using std::next with iterators. This too should be NFC. --------- Merged by: Stephen Tozer <stephen.tozer@sony.com>
2023-09-19Move CallInst::CreateFree to IRBuilderBaseKonrad Kleine
Similarly to D158861 I'm moving the `CreateFree` method from `CallInst` to `IRBuilderBase`. Differential Revision: https://reviews.llvm.org/D159418
2023-09-19[llvm] Move CallInst::CreateMalloc to IRBuilderBase::CreateMallocKonrad Kleine
This removes `CreateMalloc` from `CallInst` and adds it to the `IRBuilderBase` class. We no longer needed the `Instruction *InsertBefore` and `BasicBlock *InsertAtEnd` arguments of the `createMalloc` helper function because we're using `IRBuilder` now. That's why I we also don't need 4 `CreateMalloc` functions, but only two. Differential Revision: https://reviews.llvm.org/D158861
2023-03-15Use *{Map,Set}::contains (NFC)Kazu Hirata
2023-03-09[polly] Remove unused variable 'VectorLoops' in IslNodeBuilder.cpp (NFC)Jie Fu
/home/jiefu/llvm-project/polly/lib/CodeGen/IslNodeBuilder.cpp:80:11: error: unused variable 'VectorLoops' [-Werror,-Wunused-variable] STATISTIC(VectorLoops, "Number of generated vector for-loops"); ^ 1 error generated.
2023-03-08[Polly] Remove -polly-vectorizer=polly.Michael Kruse
Polly's internal vectorizer is not well maintained and is known to not work in some cases such as region ScopStmts. Unlike LLVM's LoopVectorize pass it also does not have a target-dependent cost heuristics, and we recommend using LoopVectorize instead of -polly-vectorizer=polly. In the future we hope that Polly can collaborate better with LoopVectorize, like Polly marking a loop is safe to vectorize with a specific simd width, instead of replicating its functionality. Reviewed By: grosser Differential Revision: https://reviews.llvm.org/D142640
2022-06-04Remove unneeded cl::ZeroOrMore for cl::opt optionsFangrui Song
Similar to 557efc9a8b68628c2c944678c6471dac30ed9e8e. This commit handles options where cl::ZeroOrMore is more than one line below cl::opt.
2022-05-17[Polly] Mark classes as final by default. NFC.Michael Kruse
This make is obivious that a class was not intended to be derived from. NPM analysis pass can unfortunately not marked as final because they are derived from a llvm::Checker<T> template internally by the NPM. Also normalize the use of classes/structs * NPM passes are structs * Legacy passes are classes * structs that have methods and are not a visitor pattern are classes * structs have public inheritance by default, remove "public" keyword * Use typedef'ed type instead of inline forward declaration
2022-02-16[polly] Match function definitions and header declarations. NFC.Michael Kruse
Ensure that function definitions match their declrations in header files, even if they have no effect on linking. This includes 1. Both have the same __isl_* annotations 2. Both use the same type alias 3. Remove unused declarations that have no definition 4. Use explicit polly namespace qualifier for definitions; generally, the .cpp file should use at most an anon namespace region since only symbols declared in the header file can be accessed from other translation units anyway. For defintions that have been declared in the header file, the explicit namespace qualifier ensures that both match.
2021-10-15[Polly] Remove checkIslAstExprInt and use RAII instead of manually freeing ↵Max Fan
Expr. NFC. Polly is trying to move towards using isl::ast_expr / isl-noexceptions.h (which implements RAII) where possible instead of manually managing memory. checkIslAstExprInt manually frees Expr, so it has been removed to be more idiomatic and consistent. Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D111769
2021-10-14[Polly] Remove support for code generated by gfortran+DragonEgg.Michael Kruse
DragonEgg is not maintained anymore, hence there is no need for this functionality. Fixes llvm.org/PR52173
2021-09-26[Polly] Use VirtualUse to determine references.Michael Kruse
VirtualUse ensures consistency over different source of values with Polly. In particular, this enables its use of instructions moved between Statement. Before the patch, the code wrongly assumed that the BB's instructions are also the ScopStmt's instructions. Reference are determined for OpenMP outlining and GPGPU kernel extraction. GPGPU CodeGen had some problems. For one, it generated GPU kernel parameters for constants. Second, it emitted GPU-side invariant loads which have already been loaded by the host. This has been partially fixed, it still generates a store for the invariant load result, but using the value that the host has already written. WARNING: I did not test the generated PollyACC code on an actual GPU. The improved consistency will be made use of in the next patch.
2021-09-20[Polly] Don't generate inter-iteration noalias metadata.Michael Kruse
This metadata was intended to mark all accesses within an iteration to be pairwise non-aliasing, in this case because every memory of a base pointer is touched (read or write) at most once. This is typical for 'sweeps' over all data. The stated motivation from D30606 is to ensure that unrolled iterations are considered non-aliasing. Rhe implemention had multiple issues: * The structure of the noalias metadata was malformed. D110026 added check in the verifier for this metadata, and the tests were failing since then. * This is not true for the outer loops of the BLIS matrix multiplication, where it was being inserted. Each element of A, B, C is accessed multiple times, as often as the loop not used as an index is iterating. * Scopes were added to SecondLevelOtherAliasScopeList (used for the !noalias scop list) on-the-fly when another SCEV was seen. This meant that previously visited instructions would not be updated with alias scopes that are only seen later, missing out those SCEVs they should not be aliasing with. * Since the !noalias scope list would ideally consists of all other SCEV for this base pointer, we might run quickly into scalability issues. Especially after unrolling there would probably at least once SCEV per instruction and unroll instance. * The inter-iteration noalias base pointer was not removed after leaving the loop marked with it, effectively marking everything after it to noalias as well. A solution I considered was to mark each instruction as non-aliasing with its own scope. The instruction itself would obviously alias itself, but such construction might also be considered invalid. Duplicating the instruction (e.g. due to speculation) would mark the instruction non-aliasing with its clone. I don't want to go into this territory, especially since the original motivation of determining unrolled instances as noalias based on SCEV is the what scev-aa does as well. This effectively reverts D30606 and D35761.
2021-08-16[Polly][Isl] Move to the new-polly-generator branch version of ↵Riccardo Mori
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 https://github.com/patacca/isl/commit/73f5ed1f4d1f72582f731590ef9e43d9ab1956ad No functional change intended. Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D107225
2021-07-17[OpaquePtr] Remove uses of CreateInBoundsGEP() without element typeNikita Popov
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-06-18[Polly][Isl] Refactoring IslAstInfo::getBuild() and ↵patacca
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-04-10[Polly] Partially refactoring of IslAstInfo and IslNodeBuilder to use isl++. ↵patacca
NFC. Polly use 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 following methods of class IslAstInfo - isParallel() isExecutedInParallel() isReductionParallel() getSchedule() getMinimalDependenceDistance() getBrokenReductions() - Refactoring the following methods of class IslNodeBuilder - getReferencesInSubtree() getScheduleForAstNode() - Refactoring function getBrokenReductionsStr() - Fixed the mismatching function declaration for getScheduleForAstNode() Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D99971
2021-03-16[Polly][CodeGen] Allow nesting of BandAttr mark without loop.Michael Kruse
BandAttr markers are added as parents of schedule tree bands. These also appear as markers its equivalent AST, but a band does not necessarily corresponds to a loop in this. Iterations may be peeled or the loop being unrolled (e.g. if it has just one iteration). In such cases it may happend that there is not loop between a BandAttr marker and the marker for a loop nested in the former parent band/loop. Handle the situation by giving priority to the inner marker over the outer. Fixes the polly-x86_64-linux-test-suite buildbot.
2021-03-15[Polly][Optimizer] Apply user-directed unrolling.Michael Kruse
Make Polly look for unrolling metadata (https://llvm.org/docs/TransformMetadata.html#loop-unrolling) that is usually only interpreted by the LoopUnroll pass and apply it to the SCoP's schedule. While not that useful by itself (there already is an unroll pass), it introduces mechanism to apply arbitrary loop transformation directives in arbitrary order to the schedule. Transformations are applied until no more directives are found. Since ISL's rescheduling would discard the manual transformations and it is assumed that when the user specifies the sequence of transformations, they do not want any other transformations to apply. Applying user-directed transformations can be controlled using the `-polly-pragma-based-opts` switch and is enabled by default. This does not influence the SCoP detection heuristic. As a consequence, loop that do not fulfill SCoP requirements or the initial profitability heuristic will be ignored. `-polly-process-unprofitable` can be used to disable the latter. Other than manually editing the IR, there is currently no way for the user to add loop transformations in an order other than the order in the default pipeline, or transformations other than the one supported by clang's LoopHint. See the `unroll_double.ll` test as example that clang currently is unable to emit. My own extension of `#pragma clang loop` allowing an arbitrary order and additional transformations is available here: https://github.com/meinersbur/llvm-project/tree/pragma-clang-loop. An effort to upstream this functionality as `#pragma clang transform` (because `#pragma clang loop` has an implicit transformation order defined by the loop pipeline) is D69088. Additional transformations from my downstream pragma-clang-loop branch are tiling, interchange, reversal, unroll-and-jam, thread-parallelization and array packing. Unroll was chosen because it uses already-defined metadata and does not require correctness checks. Reviewed By: sebastiankreutzer Differential Revision: https://reviews.llvm.org/D97977
2021-03-11[Polly] Remove uses of type-less CreateLoad() APIs (NFC)Nikita Popov
These are incompatible with opaque pointers and are going away. Explicitly specify the loaded type instead.
2021-03-11[OpaquePtrs] Remove some uses of type-less CreateLoad APIs (NFC)Nikita Popov
Explicitly pass loaded type when creating loads, in preparation for the deprecation of these APIs. There are still a couple of uses left.
2021-02-26[Polly] Refactoring IsInnermostParallel() in ISL to take the C++ wrapper ↵Kevin Zhou
object. NFC Currently, the IslAst library is a C library that would be incompatible with the rest of the LLVM because LLVM is written in C++. I took one function, IsInnermostParallel(), and refactored it so that it would take the C++ wrapper object instead of using reference counters with the C ISL library. As well, all the references that use IsInnermostParallel() will use manage_copy() since they are still expecting the C object. Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D97425
2021-02-10[Polly] Avoid "using namespace llvm" in public headers. NFC.Michael Kruse
"using namespace" pollutes the namespace of every file that includes such a header and universally considered a bad thing. Even the variant namespace polly { using namespace llvm; } (previously used by LoopGenerators.h) imports more symbols than the file is in control of. The header may include a fixed set of files from LLVM, but the header itself may by be included together with other headers from LLVM. For instance, LLVM's MemorySSA.h and Polly's ScopInfo.h both declare a class 'MemoryAccess' which may conflict. Instead of prefixing everything in Polly's header files, this patch adds 'using' statements to import only the symbols that are actually referenced in Polly. This approach is also used by MLIR to import commonly used symbols into the mlir namespace. This patch also puts the symbols declared in IslNodeBuilder.h into the Polly namespace to also be able to use the imported symbols.
2020-05-16AllocaInst should store Align instead of MaybeAlign.Eli Friedman
Along the lines of D77454 and D79968. Unlike loads and stores, the default alignment is getPrefTypeAlign, to match the existing handling in various places, including SelectionDAG and InstCombine. Differential Revision: https://reviews.llvm.org/D80044
2020-04-06[NFC] Modernize misc. uses of Align/MaybeAlign APIs.Eli Friedman
Use the current getAlign() APIs where it makes sense, and use Align instead of MaybeAlign when we know the value is non-zero.
2019-09-30[Alignment][NFC] Remove AllocaInst::setAlignment(unsigned)Guillaume Chatelet
Summary: This is patch is part of a series to introduce an Alignment type. See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html See this patch for the introduction of the type: https://reviews.llvm.org/D64790 Reviewers: courbet Subscribers: jholewinski, arsenm, jvesely, nhaehnle, eraman, hiraditya, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D68141 llvm-svn: 373207
2019-09-30[Alignment] Fix polly buildGuillaume Chatelet
llvm-svn: 373199
2019-09-17[CodeGen] Handle outlining of CopyStmts.Michael Kruse
Since the removal of extensions nodes from schedule trees in r362257 it is possible to emit parallel code for SCoPs containing matrix-multiplications. However, the code looking for references used in outlined statement was not prepared to handle CopyStmts introduced by the matrix-matrix multiplication detection. In this case, CopyStmts do not introduce references in addition to the ones captured by MemoryAccesses, i.e. we change the assertion to accept CopyStmts and add a regression test for this case. This fixes llvm.org/PR43164 llvm-svn: 372188
2019-03-28Apply include-what-you-use #include removal suggestions. NFC.Michael Kruse
This removes unused includes (and forward declarations) as suggested by include-what-you-use. If a transitive include of a removed include is required to compile a file, I added the required header (or forward declaration if suggested by include-what-you-use). This should reduce compilation time and reduce the number of iterative recompilations when a header was changed. llvm-svn: 357209
2019-03-19[CodeGen] LLVM OpenMP Backend.Michael Kruse
The ParallelLoopGenerator class is changed such that GNU OpenMP specific code was removed, allowing to use it as super class in a template-pattern. Therefore, the code has been reorganized and one may not use the ParallelLoopGenerator directly anymore, instead specific implementations have to be provided. These implementations contain the library-specific code. As such, the "GOMP" (code completely taken from the existing backend) and "KMP" variant were created. For "check-polly" all tests that involved "GOMP": equivalents were added that test the new functionalities, like static scheduling and different chunk sizes. "docs/UsingPollyWithClang.rst" shows how the alternative backend may be used. Patch by Michael Halkenhäuser <michaelhalk@web.de> Differential Revision: https://reviews.llvm.org/D59100 llvm-svn: 356434
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2018-07-31[CodeGen] Convert IslNodeBuilder::getNumberOfIterations to isl++. NFC.Michael Kruse
llvm-svn: 338451
2018-07-31[CodeGen] Convert IslNodeBuilder::createForSequential to isl++. NFC.Michael Kruse
llvm-svn: 338450
2018-07-31[CodeGen] Convert IslNodeBuilder::getUpperBound to isl++. NFC.Michael Kruse
llvm-svn: 338449
2018-07-17[IslNodeBuilder] Use isl++ to replace foreach_set with for loopTobias Grosser
llvm-svn: 337247
2018-04-29Remove the last uses of isl::give and isl::takeTobias Grosser
llvm-svn: 331126
2018-02-20Use isl::manage_copy to simplify calls to isl::manage(isl_.._copy())Tobias Grosser
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
2017-11-21[CodeGen] Detect empty domain because of parameters context.Michael Kruse
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-21Run polly-update-format. NFC.Michael Kruse
polly-check-format has been failing since at least r318517, due to more than one cause. llvm-svn: 318795
2017-11-19Port ScopInfo to the isl cpp bindingsPhilip Pfaffe
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