summaryrefslogtreecommitdiff
path: root/polly/lib/CodeGen/IslExprBuilder.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-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
2024-10-11[NFC] Rename `Intrinsic::getDeclaration` to `getOrInsertDeclaration` (#111752)Rahul Joshi
Rename the function to reflect its correct behavior and to be consistent with `Module::getOrInsertFunction`. This is also in preparation of adding a new `Intrinsic::getDeclaration` that will have behavior similar to `Module::getFunction` (i.e, just lookup, no creation).
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.
2023-03-17[Polly] Remove some bitcasts (NFC)Nikita Popov
No longer relevant with opaque pointers.
2022-06-05Remove unneeded cl::ZeroOrMore for cl::opt/cl::list optionsFangrui Song
2022-05-19[APInt] Remove all uses of zextOrSelf, sextOrSelf and truncOrSelfJay Foad
Most clients only used these methods because they wanted to be able to extend or truncate to the same bit width (which is a no-op). Now that the standard zext, sext and trunc allow this, there is no reason to use the OrSelf versions. The OrSelf versions additionally have the strange behaviour of allowing extending to a *smaller* width, or truncating to a *larger* width, which are also treated as no-ops. A small amount of client code relied on this (ConstantRange::castOp and MicrosoftCXXNameMangler::mangleNumber) and needed rewriting. Differential Revision: https://reviews.llvm.org/D125557
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-12-26Use static_assert instead of assert (NFC)Kazu Hirata
Identified with misc-static-assert.
2021-07-17[OpaquePtr] Remove uses of CreateGEP() without element typeNikita Popov
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-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.
2020-09-18[Polly] Update map passed to SCEVParameterReweriter.Florian Hahn
The type of the map the SCEVParameterRewriter takes has been changed in 4635f6050b10. Update the single use in polly to use SCEV* as type of the values.
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-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
2017-09-23[IslExprBuilder] Do not generate RTC with more than 64 bitTobias Grosser
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-07-24Move ScopArrayInfo::getFromAccessFunction and getFromId to isl++Tobias Grosser
llvm-svn: 308892
2017-06-08Fix a lot of typos. NFC.Michael Kruse
llvm-svn: 304974
2017-03-18[IslExprBuilder] Print accessed memory locations with RuntimeDebugBuilderTobias Grosser
After this change, enabling -polly-codegen-add-debug-printing in combination with -polly-codegen-generate-expressions allows us to instrument the compiled binaries to not only print the values stored and loaded to a given memory access, but also to print the accessed location with array name and per-dimension offset: MemRef_A[3][2] Store to 6299784: 5.000000 MemRef_A[3][3] Load from 6299788: 0.000000 MemRef_A[3][3] Store to 6299788: 6.000000 This can be very helpful for debugging. llvm-svn: 298194
2016-11-02[Polly CodeGen] Break critical edge from RTC to original loop.Eli Friedman
This makes polly generate a CFG which is closer to what we want in LLVM IR, with a loop preheader for the original loop. This is just a cleanup, but it exposes some fragile assumptions. I'm not completely happy with the changes related to expandCodeFor; RTCBB->getTerminator() is basically a random insertion point which happens to work due to the way we generate runtime checks. I'm not sure what the right answer looks like, though. Differential Revision: https://reviews.llvm.org/D26053 llvm-svn: 285864
2016-10-08Turn cl::values() (for enum) from a vararg function to using C++ variadic ↵Mehdi Amini
template The core of the change is supposed to be NFC, however it also fixes what I believe was an undefined behavior when calling: va_start(ValueArgs, Desc); with Desc being a StringRef. Differential Revision: https://reviews.llvm.org/D25342 llvm-svn: 283671
2016-09-02Drop '@brief' from doxygen commentsTobias Grosser
LLVM's coding guideline suggests to not use @brief for one-sentence doxygen comments to improve readability. Switch this once and for all to ensure people do not copy @brief comments from other parts of Polly, when writing new code. llvm-svn: 280468
2016-08-04GPGPU: Support scalars that are mapped to shared memoryTobias Grosser
llvm-svn: 277726
2016-07-21IslExprBuilder: allow to specify an external isl_id to ScopArrayInfo mappingTobias Grosser
This is useful for external users using IslExprBuilder, in case they cannot embed ScopArrayInfo data into their isl_ids, because the isl_ids either already carry other information or the isl_ids have been created and their user pointers cannot be updated any more. llvm-svn: 276268
2016-06-12Recommit: "Simplify min/max expression generation"Tobias Grosser
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-11This reverts recent expression type changesTobias Grosser
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-06Refactor division generation codeJohannes Doerfert
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-06Use minimal types for generated expressionsJohannes Doerfert
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-03Fix modulo compared to zero.Michael Kruse
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-02Temporarily promote values to i64 againJohannes Doerfert
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[NFC] Avoid unnecessary comparison for min/max expressionsJohannes Doerfert
llvm-svn: 271535
2016-06-02[NFC] Simplify min/max expression generationJohannes Doerfert
llvm-svn: 271514
2016-06-02Simplify the type adjustment in the IslExprBuilderJohannes Doerfert
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[FIX] Ensure wrapping checks for unary expressionsJohannes Doerfert
llvm-svn: 271512
2016-05-12Check overflows in RTCs and bail accordinglyJohannes Doerfert
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-04-10Allow pointer expressions in SCEVs again.Johannes Doerfert
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
2015-11-10ScopInfo: Make getDimensionSize better reflect which dimensions carry sizesTobias Grosser
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-07[FIX] Bail out if there is a dependence cycle between invariant loadsJohannes Doerfert
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-06polly/ADT: Remove implicit ilist iterator conversions, NFCDuncan P. N. Exon Smith
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-03[FIX] Use appropriately sized types for big constantsJohannes Doerfert
llvm-svn: 251869
2015-10-04Consolidate the different ValueMapTypes we are usingTobias Grosser
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-09-05OpenMP codegen: support generation of multi-dimensional access functionsTobias Grosser
When computing the index expressions for new, multi-dimensional memory accesses these new index expressions may reference original llvm::Values that are not transfered into the OpenMP subfunction. Using GlobalMap we now replace references to such values with the rewritten values that have e.g. been passed to the OpenMP subfunction. llvm-svn: 246923
2015-08-18Introduce the ScopExpander as a SCEVExpander replacementJohannes Doerfert
The SCEVExpander cannot deal with all SCEVs Polly allows in all kinds of expressions. To this end we introduce a ScopExpander that handles the additional expressions separatly and falls back to the SCEVExpander for everything else. Reviewers: grosser, Meinersbur Subscribers: #polly Differential Revision: http://reviews.llvm.org/D12066 llvm-svn: 245288
2015-06-04Mark sdivs as 'exact' instead of lowering them ourselvesTobias Grosser
LLVM's instcombine already translates power-of-two sdivs that are known to be exact to fast ashr instructions. Hence, there is no need to add this logic ourselves. Pointed-out-by: Johannes Doerfert llvm-svn: 239025
2015-06-03Lower signed-divisions without rounding to ashr instructionsTobias Grosser
llvm-svn: 238929
2015-06-03Only convert power-of-two floor-division with non-negative denominatorTobias Grosser
floord(a,b) === a ashr log_2 (b) holds for positive and negative a's, but shifting only makes sense for positive values of b. The previous patch did not consider this as isl currently always produces postive b's. To avoid future surprises, we check that b is positive and only then apply the optimization. We also now correctly check the return value of the dyn-cast. No additional test case, as isl currently does not produce negative denominators. Reported-by: David Majnemer <david.majnemer@gmail.com> llvm-svn: 238927
2015-06-03Translate power-of-two floor-division into ashrTobias Grosser
Power-of-two floor divisions can be translated into an arithmetic shift operation. This allows us to replace a complex lowering that requires division operations: %pexp.fdiv_q.0 = sub i64 %21, 128 %pexp.fdiv_q.1 = add i64 %pexp.fdiv_q.0, 1 %pexp.fdiv_q.2 = icmp slt i64 %21, 0 %pexp.fdiv_q.3 = select i1 %pexp.fdiv_q.2, i64 %pexp.fdiv_q.1, i64 %21 %pexp.fdiv_q.4 = sdiv i64 %pexp.fdiv_q.3, 128 with a simple ashr: %polly.fdiv_q.shr = ashr i64 %21, 7 llvm-svn: 238905
2015-05-29Exploit non-negative numeratorsTobias Grosser
isl marks known non-negative numerators in modulo (and soon also division) operations. We now exploit this by generating unsigned operations. This is beneficial as unsigned operations with power-of-two denominators will be translated by isl to fast bitshift or bitwise and operations. llvm-svn: 238577
2015-05-20Use base-pointer address space when creating new access functionsTobias Grosser
llvm-svn: 237785
2015-05-20Add printing and testing to ScopArrayInfoTobias Grosser
Being here, we extend the interface to return the element type and not a pointer to the element type. We also provide a function to get the size (in bytes) of the elements stored in this array. We currently still store the element size as an innermost dimension in ScopArrayInfo, which is somehow inconsistent and should be addressed in future patches. llvm-svn: 237779