summaryrefslogtreecommitdiff
path: root/polly/lib/CodeGen/BlockGenerators.cpp
AgeCommit message (Collapse)Author
2016-08-04BlockGenerator: Assert that we do not get alloca of array accessTobias Grosser
llvm-svn: 277698
2016-08-03Fix a couple of spelling mistakesTobias Grosser
llvm-svn: 277569
2016-07-30Extend the jscop interface to allow the user to declare new arrays and to ↵Roman Gareev
reference these arrays from access expressions Extend the jscop interface to allow the user to export arrays. It is required that already existing arrays of the list of arrays correspond to arrays of the SCoP. Each array that is appended to the list will be newly created. Furthermore, we allow the user to modify access expressions to reference any array in case it has the same element type. Reviewed-by: Tobias Grosser <tobias@grosser.es> Differential Revision: https://reviews.llvm.org/D22828 llvm-svn: 277263
2016-07-21BlockGenerator: remove dead instructions in normal statementsTobias Grosser
This ensures that no trivially dead code is generated. This is not only cleaner, but also avoids troubles in case code is generated in a separate function and some of this dead code contains references to values that are not available. This issue may happen, in case the memory access functions have been updated and old getelementptr instructions remain in the code. With normal Polly, a test case is difficult to draft, but the upcoming GPU code generation can possibly trigger such problems. We will later extend this dead-code elimination to region and vector statements. llvm-svn: 276263
2016-05-29[Polly] Remove usage of the `apply` functionSanjoy Das
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-23Remove some unused local variables. NFC.Michael Kruse
Found by clang static analyzer (http://llvm.org/reports/scan-build/) and Visual Studio. llvm-svn: 270432
2016-05-23Use the SCoP directly for canSynthesize [NFC]Johannes Doerfert
llvm-svn: 270429
2016-05-23Duplicate part of the Region interface in the Scop class [NFC]Johannes Doerfert
This allows to use the SCoP directly for various queries, thus to hide the underlying region more often. llvm-svn: 270426
2016-05-23Add and use Scop::contains(Loop/BasicBlock/Instruction) [NFC]Johannes Doerfert
llvm-svn: 270424
2016-05-23Directly access information through the Scop class [NFC]Johannes Doerfert
llvm-svn: 270421
2016-05-23Simplify BlockGenerator::handleOutsideUsers interface [NFC]Johannes Doerfert
llvm-svn: 270411
2016-04-28BlockGenerator: Drop leftover debug statementTobias Grosser
llvm-svn: 267874
2016-04-25Check only loop control of loops that are part of the regionJohannes Doerfert
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-01[FIX] Adjust the insert point for non-affine region PHIsJohannes Doerfert
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-03-03[BlockGenerator] Fix PHI merges for MK_Arrays.Michael Kruse
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-01Fix non-synthesizable loop exit values.Michael Kruse
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-02-25Use inline local variable declaration. NFC.Michael Kruse
llvm-svn: 261876
2016-02-25Fix DomTree preservation for generated subregions.Michael Kruse
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-24Introduce ScopStmt::getEntryBlock(). NFC.Michael Kruse
This replaces an ungly inline ternary operator pattern. llvm-svn: 261792
2016-02-24Add assertions checking def dominates use. NFC.Michael Kruse
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-21BlockGenerator: Drop unnecessary return valueTobias Grosser
llvm-svn: 261473
2016-02-16Replace getLoopForInst by getLoopForStmtJohannes Doerfert
This patch was extracted from http://reviews.llvm.org/D13611. llvm-svn: 260958
2016-02-04Support accesses with differently sized types to the same arrayTobias Grosser
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-03Revert "Support loads with differently sized types from a single array"Tobias Grosser
This reverts commit (@259587). It needs some further discussions. llvm-svn: 259629
2016-02-02Support loads with differently sized types from a single arrayTobias Grosser
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-02Add const keyword to MemoryAccess argument [NFC]Johannes Doerfert
llvm-svn: 259504
2016-01-27Introduce MemAccInst helper class; NFCMichael Kruse
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-26Unique phi write accessesMichael Kruse
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-26BlockGenerators: Replace getNewScalarValue with getNewValueTobias Grosser
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-24BlockGenerators: Avoid redundant map lookup [NFC]Tobias Grosser
llvm-svn: 258660
2015-12-22Refactor canSynthesize in the BlockGenerators [NFC]Johannes Doerfert
llvm-svn: 256269
2015-12-22Treat inline assembly as a constant in the code generation.Johannes Doerfert
llvm-svn: 256267
2015-12-22Reduce indention in BlockGenerator::trySynthesizeNewValue [NFC]Johannes Doerfert
llvm-svn: 256266
2015-12-22BlockGenerators: Remove unnecessary const_castTobias Grosser
llvm-svn: 256227
2015-12-21Adjust formatting to clang-format changes in 256149Tobias Grosser
llvm-svn: 256151
2015-12-15BlockGenerator: Use getArrayAccessFor for vector code generationTobias Grosser
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-15VectorBlockGenerator: Generate scalar loads for vector statementsTobias Grosser
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-15ScopInfo: Look up first (and only) array accessTobias Grosser
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-14Fix typos; NFCMichael Kruse
llvm-svn: 255580
2015-12-14BlockGenerator: Do not use fast-path for external constantsTobias Grosser
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-14BlockGenerator: Drop unneeded const_castsTobias Grosser
llvm-svn: 255505
2015-12-13ScopInfo: Harmonize the different array kindsTobias Grosser
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-11-26Introduce origin/kind for exit PHI node accessesMichael Kruse
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-12RegionGenerator: Only introduce subregion.ivs for loops fully within a subregionTobias Grosser
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-09Fix non-affine generated entering node not being recognized as dominatingMichael Kruse
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-09Fix dominance when subregion exit is outside scopMichael Kruse
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-09Revert r252375 "Fix non-affine region dominance of implicitely stored values"Michael Kruse
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-09Revert "Fix non-affine generated entering node not being recognized as ↵Johannes Doerfert
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-09Fix non-affine generated entering node not being recognized as dominatingMichael Kruse
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[FIX] Initialize incoming scalar memory locations for PHIsJohannes Doerfert
llvm-svn: 252437