Commit Graph

151 Commits

Author SHA1 Message Date
Michael Kruse 4c86a1d97b IR cleanup after CodeGeneration
Re-run canonicalization passes after Polly's code generation.

The set of passes currently added here are nearly all the passes between
--polly-position=early and --polly-position=before-vectorizer, i.e. all
passes that would usually run after Polly.

In order to run these only if Polly actually modified the code, we add a
function attribute "polly-optimzed" to a function that contains
generated code. The cleanup pass is skipped if the function does not
have this attribute.

There is no support by the (legacy) PassManager to run passes only under
some conditions. One could have wrapped all transformation passes to run
only when CodeGeneration changed the code, but the analyses would run
anyway. This patch creates an independent pass manager. The
disadvantages are that all analyses have to re-run even if preserved and
it does not honor compiler switches like the PassManagerBuilder does.

Differential Revision: http://reviews.llvm.org/D14333

llvm-svn: 254150
2015-11-26 12:36:25 +00:00
Johannes Doerfert 2af10e2eed Use parameter constraints provided via llvm.assume
If an llvm.assume dominates the SCoP entry block and the assumed condition
  can be expressed as an affine inequality we will now add it to the context.

Differential Revision: http://reviews.llvm.org/D14413

llvm-svn: 252851
2015-11-12 03:25:01 +00:00
Tobias Grosser e3d1f1c0b0 ScopDetection: Tighten the check for always executed 'error blocks'
Basic blocks that are always executed can not be error blocks as their execution
can not possibly be an unlikely event. In this commit we tighten the check
if an error block to basic blcoks that do not dominate the exit condition, but
that dominate all exiting blocks of the scop.

llvm-svn: 252726
2015-11-11 13:25:13 +00:00
Tobias Grosser b12b006c4b ScopDetection: Do not allow blocks to reference operands in error blocks
r252713 introduced a couple of regressions due to later basic blocks refering
to instructions defined in error blocks which have not yet been modeled.

This commit is currently just encoding limitations of our modeling and code
generation backends to ensure correctness. In theory, we should be able to
generate and optimize such regions, as everything that is dominated by an error
region is assumed to not be executed anyhow. We currently just lack the code
to make this happen in practice.

llvm-svn: 252725
2015-11-11 12:44:18 +00:00
Tobias Grosser b43cc62fe1 stringFromIslObj: Do not crash when printing 'null' objects
No test case, as this code path is currently only used for debugging.

llvm-svn: 252609
2015-11-10 15:09:44 +00:00
Duncan P. N. Exon Smith b8f58b53dd polly/ADT: Remove implicit ilist iterator conversions, NFC
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-06 22:56:54 +00:00
Johannes Doerfert 01978cfa0c Remove independent blocks pass
Polly can now be used as a analysis only tool as long as the code
  generation is disabled. However, we do not have an alternative to the
  independent blocks pass in place yet, though in the relevant cases
  this does not seem to impact the performance much. Nevertheless, a
  virtual alternative that allows the same transformations without
  changing the input region will follow shortly.

llvm-svn: 250652
2015-10-18 12:28:00 +00:00
Tobias Grosser d17183f20f Use EP_ModuleOptimizerEarly to run early polly passes,
instead of llvm::PassManagerBuilder::EP_EarlyAsPossible. This will allow us
to run actual module passes in Polly's canonicalization sequence, but should
otherwise have only little impact.

llvm-svn: 250091
2015-10-12 20:03:41 +00:00
Johannes Doerfert f363ed9804 [NFC] Move helper functions to ScopHelper
Helper functions in the BlockGenerators.h/cpp introduce dependences
  from the frontend to the backend of Polly. As they are used in
  ScopDetection, ScopInfo, etc. we move them to the ScopHelper file.

llvm-svn: 249919
2015-10-09 23:40:24 +00:00
Johannes Doerfert 08d90a3cee Treat conditionally executed non-pure calls as errors
This replaces the support for user defined error functions by a
  heuristic that tries to determine if a call to a non-pure function
  should be considered "an error". If so the block is assumed not to be
  executed at runtime. While treating all non-pure function calls as
  errors will allow a lot more regions to be analyzed, it will also
  cause us to dismiss a lot again due to an infeasible runtime context.
  This patch tries to limit that effect. A non-pure function call is
  considered an error if it is executed only in conditionally with
  regards to a cheap but simple heuristic.

llvm-svn: 249611
2015-10-07 20:32:43 +00:00
Johannes Doerfert 09e3697f44 Allow invariant loads in the SCoP description
This patch allows invariant loads to be used in the SCoP description,
  e.g., as loop bounds, conditions or in memory access functions.

  First we collect "required invariant loads" during SCoP detection that
  would otherwise make an expression we care about non-affine. To this
  end a new level of abstraction was introduced before
  SCEVValidator::isAffineExpr() namely ScopDetection::isAffine() and
  ScopDetection::onlyValidRequiredInvariantLoads(). Here we can decide
  if we want a load inside the region to be optimistically assumed
  invariant or not. If we do, it will be marked as required and in the
  SCoP generation we bail if it is actually not invariant. If we don't
  it will be a non-affine expression as before. At the moment we
  optimistically assume all "hoistable" (namely non-loop-carried) loads
  to be invariant. This causes us to expand some SCoPs and dismiss them
  later but it also allows us to detect a lot we would dismiss directly
  if we would ask e.g., AliasAnalysis::canBasicBlockModify(). We also
  allow potential aliases between optimistically assumed invariant loads
  and other pointers as our runtime alias checks are sound in case the
  loads are actually invariant. Together with the invariant checks this
  combination allows to handle a lot more than LICM can.

  The code generation of the invariant loads had to be extended as we
  can now have dependences between parameters and invariant (hoisted)
  loads as well as the other way around, e.g.,
    test/Isl/CodeGen/invariant_load_parameters_cyclic_dependence.ll
  First, it is important to note that we cannot have real cycles but
  only dependences from a hoisted load to a parameter and from another
  parameter to that hoisted load (and so on). To handle such cases we
  materialize llvm::Values for parameters that are referred by a hoisted
  load on demand and then materialize the remaining parameters. Second,
  there are new kinds of dependences between hoisted loads caused by the
  constraints on their execution. If a hoisted load is conditionally
  executed it might depend on the value of another hoisted load. To deal
  with such situations we sort them already in the ScopInfo such that
  they can be generated in the order they are listed in the
  Scop::InvariantAccesses list (see compareInvariantAccesses). The
  dependences between hoisted loads caused by indirect accesses are
  handled the same way as before.

llvm-svn: 249607
2015-10-07 20:17:36 +00:00
Tobias Grosser f4bb7a6a4d Consolidate the different ValueMapTypes we are using
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-10-04 10:18:32 +00:00
Johannes Doerfert f80f3b0449 Allow user defined error functions
The user can provide function names with
    -polly-error-functions=name1,name2,name3
  that will be treated as error functions. Any call to them is assumed
  not to be executed.

  This feature is mainly for developers to play around with the new
  "error block" feature.

llvm-svn: 249098
2015-10-01 23:45:51 +00:00
Johannes Doerfert 59984322c3 [FIX] Handle identity mappings in the ScopExpander
If the VMap in the ScopExpander contains identity mappings
  we now ignore the mapping.

Reported-by: Tobias Grosser <tobias@grosser.es>
llvm-svn: 248946
2015-09-30 21:12:12 +00:00
Johannes Doerfert c0729a3216 Move remapping functionality in the ScopExpander
Because we handle more than SCEV does it is not possible to rewrite an
  expression on the top-level using the SCEVParameterRewriter only. With
  this patch we will do the rewriting on demand only and also
  recursively, thus not only on the top-level.

llvm-svn: 248916
2015-09-30 16:52:03 +00:00
Johannes Doerfert 9a132f36c3 Allow switch instructions in SCoPs
This patch allows switch instructions with affine conditions in the
  SCoP. Also switch instructions in non-affine subregions are allowed.
  Both did not require much changes to the code, though there was some
  refactoring needed to integrate them without code duplication.

  In the llvm-test suite the number of profitable SCoPs increased from
  135 to 139 but more importantly we can handle more benchmarks and user
  inputs without preprocessing.

Differential Revision: http://reviews.llvm.org/D13200

llvm-svn: 248701
2015-09-28 09:33:22 +00:00
Tobias Grosser c2bb0cbe00 Sort includes using Chandler's sort_includes.py script
llvm-svn: 248568
2015-09-25 09:49:19 +00:00
Johannes Doerfert 6a72a2af13 Use <nsw> AddRecs in the affinator to avoid bounded assumptions
If we encounter a <nsw> tagged AddRec for a loop we know the trip count of
  that loop has to be bounded or the semantics is undefined anyway. Hence, we
  only need to add unbounded assumptions if no such AddRec is known.

llvm-svn: 248128
2015-09-20 16:59:23 +00:00
Johannes Doerfert 883f8c1d2f Use modulo semantic to generate non-integer-overflow assumptions
This will allow to generate non-wrap assumptions for integer expressions
  that are part of the SCoP. We compare the common isl representation of
  the expression with one computed with modulo semantic. For all parameter
  combinations they are not equal we can have integer overflows.

  The nsw flags are respected when the modulo representation is computed,
  nuw and nw flags are ignored for now.

  In order to not increase compile time to much, the non-wrap assumptions
  are collected in a separate boundary context instead of the assumed
  context. This helps compile time as the boundary context can become
  complex and it is therefor not advised to use it in other operations
  except runtime check generation. However, the assumed context is e.g.,
  used to tighten dependences. While the boundary context might help to
  tighten the assumed context it is doubtful that it will help in practice
  (it does not effect lnt much) as the boundary (or no-wrap assumptions)
  only restrict the very end of the possible value range of parameters.

  PET uses a different approach to compute the no-wrap context, though lnt runs
  have shown that this version performs slightly better for us.

llvm-svn: 247732
2015-09-15 22:52:53 +00:00
Johannes Doerfert cef616fe2d Use blocks instead of domains in SCEVAffinator
Due to the new domain generation, the SCoP keeps track of the domain
  for all blocks, thus the SCEVAffinator can now work with blocks to avoid
  duplication of the domains.

llvm-svn: 247731
2015-09-15 22:49:04 +00:00
Johannes Doerfert 36255eecd8 Revert r247278 "Disable support for modulo expressions"
This reverts commit 00c5b6ca8832439193036aadaaaee92a43236219.

  We can handle modulo expressions in the domain again.

llvm-svn: 247542
2015-09-14 11:14:23 +00:00
Johannes Doerfert 90db75ed24 Runtime error check elimination
Hoist runtime checks in the loop nest if they guard an "error" like event.
  Such events are recognized as blocks with an unreachable terminator or a call
  to the ubsan function that deals with out of bound accesses. Other "error"
  events can be added easily.

  We will ignore these blocks when we detect/model/optmize and code generate SCoPs
  but we will make sure that they would not have been executed using the assumption
  framework.

llvm-svn: 247310
2015-09-10 17:51:27 +00:00
Johannes Doerfert b68cffb5df Allow general loops with one latch
As we do not rely on ScalarEvolution any more we do not need to get
  the backedge taken count. Additionally, our domain generation handles
  everything that is affine and has one latch and our ScopDetection will
  over-approximate everything else.

  This change will therefor allow loops with:
    - one latch
    - exiting conditions that are affine

  Additionally, it will not check for structured control flow anymore.
  Hence, loops and conditionals are not necessarily single entry single
  exit regions any more.

Differential Version: http://reviews.llvm.org/D12758

llvm-svn: 247289
2015-09-10 15:27:46 +00:00
Michael Kruse d868b5d509 Merge TempScopInfo into ScopInfo
The TempScopInfo (-polly-analyze-ir) pass is removed and its work taken
over by ScopInfo (-polly-scops). Several tests depend on
-polly-analyze-ir and use -polly-scops instead which for the moment
prints the output of both passes. This again is not expected by some
other tests, especially those with negative searches, which have been
adapted.

Differential Version: http://reviews.llvm.org/D12694

llvm-svn: 247288
2015-09-10 15:25:24 +00:00
Johannes Doerfert 171f07ed71 Disable support for modulo expressions
The support for modulo expressions is not comlete and makes the new
  domain generation harder. As the currently broken domain generation
  needs to be replaced, we will first swap in the new, fixed domain
  generation and make it compatible with the modulo expressions later.

llvm-svn: 247278
2015-09-10 12:56:46 +00:00
Michael Kruse 7bf3944d23 Merge TempScopInfo.{cpp|h} into ScopInfo.{cpp|h}
This prepares for a series of patches that merges TempScopInfo into ScopInfo to
reduce Polly's code complexity. Only ScopInfo.{cpp|h} will be left thereafter.
Moving the code of TempScopInfo in one commit makes the mains diffs simpler to
understand.

In detail, merging the following classes is planned:
TempScopInfo into ScopInfo
TempScop into Scop
IRAccess into MemoryAccess

Only moving code, no functional changes intended.

Differential Version: http://reviews.llvm.org/D12693

llvm-svn: 247274
2015-09-10 12:46:52 +00:00
Michael Kruse d16550de92 Fix typo: zycle -> cycle [NFC]
llvm-svn: 247172
2015-09-09 18:20:31 +00:00
Johannes Doerfert 7ca8dc2d2d Disable support for pointer expressions
The support for pointer expressions is broken as it can only handle
  some patterns in the IslExprBuilder. We should to treat pointers in
  expressions the same as integers at some point and revert this patch.

llvm-svn: 247147
2015-09-09 14:19:04 +00:00
Johannes Doerfert b1e3bbb7c9 [FIX] Keep a copy of the Domain set in the SCEVAffinator
llvm-svn: 246397
2015-08-30 19:52:06 +00:00
Johannes Doerfert b409fdc0d7 [NFC] Make SCEVAffinator work without a statement
llvm-svn: 246290
2015-08-28 09:24:35 +00:00
Johannes Doerfert d020b77295 Use ISL to Determine Loop Trip Count
Use ISL to compute the loop trip count when scalar evolution is unable to do
  so.

Contributed-by: Matthew Simpson <mssimpso@codeaurora.org>

Differential Revision: http://reviews.llvm.org/D9444

llvm-svn: 246142
2015-08-27 06:53:52 +00:00
Johannes Doerfert e69e1141d9 Introduce the ScopExpander as a SCEVExpander replacement
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-08-18 11:56:00 +00:00
Tobias Grosser d46fd5ed95 Make the dimension sizes of in ScopArrayInfo available as isl_pw_affs
This makes it easier to reason about the size of an array dimension with isl.

llvm-svn: 244757
2015-08-12 15:27:16 +00:00
Johannes Doerfert 5451544a17 Remove identity operation from SCEVAffinator
llvm-svn: 244736
2015-08-12 10:58:01 +00:00
Johannes Doerfert 3f0a2a325f Add caching to the SCEVAffinator
While the compile time is not affected by this patch much it will
  allow us to look at all translated expressions after the SCoP is build
  in a convenient way. Additionally, bigger SCoPs or SCoPs with
  repeating complicated expressions might benefit from the cache later
  on.

Reviewers: grosser, Meinersbur

Subscribers: #polly

Differential Revision: http://reviews.llvm.org/D11975

llvm-svn: 244734
2015-08-12 10:46:33 +00:00
Johannes Doerfert 574182d394 Expose the SCEVAffinator and make it a member of a SCoP.
This change has three major advantages:
    - The ScopInfo becomes smaller.
    - It allows to use the SCEVAffinator from outside the ScopInfo.
    - A member object allows state which in turn allows e.g., caching.

Differential Revision: http://reviews.llvm.org/D9099

llvm-svn: 244730
2015-08-12 10:19:50 +00:00
Michael Kruse 22370884c4 Revise the simplification of regions
The previous code had several problems:

For newly created BasicBlocks it did not (always) call RegionInfo::setRegionFor in order to update its analysis. At the moment RegionInfo does not verify its BBMap, but will in the future. This is fixed by determining the region new BBs belong to and set it accordingly. The new executeScopConditionally() requires accurate getRegionFor information. 

Which block is created by SplitEdge depends on the incoming and outgoing edges of the blocks it connects, which makes handling its output more difficult than it needs to be. Especially for finding which block has been created an to assign a region to it for the setRegionFor problem above. This patch uses an implementation for splitEdge that always creates a block between the predecessor and successor. simplifyRegion has also been simplified by using SplitBlockPredecessors instead of SplitEdge. Isolating the entries and exits have been refectored into individual functions.

Previously simplifyRegion did more than just ensuring that there is only one entering and one exiting edge. It ensured that the entering block had no other outgoing edge which was necessary for executeScopConditionally(). Now the latter uses the alternative splitEdge implementation which can handle this situation so simplifyRegion really only needs to simplify the region.

Also, executeScopConditionally assumed that there can be no PHI nodes in blocks with one incoming edge. This is wrong and LCSSA deliberately produces such edges. However, previous passes ensured that there can be no such PHIs in exit nodes, but which will no longer hold in the future.

The new code that the property that it preserves the identity of region block (the property that the memory address of the BasicBlock containing the instructions remains the same; new blocks only contain PHI nodes and a terminator), especially the entry block. As a result, there is no need to update the reference to the BasicBlock of ScopStmt that contain its instructions because they have been moved to other basic blocks.

Reviewers: grosser

Part of Differential Revision: http://reviews.llvm.org/D11867 

llvm-svn: 244606
2015-08-11 14:39:21 +00:00
Michael Kruse 23d0e83aa3 Introduce splitBlock and use it in splitEntryBlockForAlloca
RegionInfo::splitBlock did not update RegionInfo correctly. Specifically, it tried to make the new block the entry block if possible. This breaks for nested regions that have edges to the old block. 

We simply do not change the entry block. Updating RegionInfo becomes trivial as both block will always be in the same region.

splitEntryBlockForAlloca makes use of the new splitBlock.

Reviewers: grosser

Part of Differential Revision: http://reviews.llvm.org/D11867

llvm-svn: 244600
2015-08-11 14:04:06 +00:00
Tobias Grosser fbe7a2e841 Run ScopInfo after the ScopViewers
This change is required to see the detected scops even in cases where there is
no other ScopInfo user after the ScopViewers. Before this change, when
running with -polly-optimizer=none -polly-code-generator=none detected scops
have not been shown.

llvm-svn: 243971
2015-08-04 11:49:39 +00:00
Tobias Grosser 6213913244 Use the branch instruction to define the location of a PHI-node write
We use the branch instruction as the location at which a PHI-node write takes
place, instead of the PHI-node itself. This allows us to identify the
basic-block in a region statement which is on the incoming edge of the PHI-node
and for which the write access was originally introduced. As a result we can,
during code generation, avoid generating PHI-node write accesses for basic
blocks that do not preceed the PHI node without having to look at the IR
again.

This change fixes a bug which was introduced in r243420, when we started to
explicitly model PHI-node reads and writes, but dropped some additional checks
that where still necessary during code generation to not emit PHI-node writes
for basic-blocks that are not on incoming edges of the original PHI node.
Compared to the code before r243420 the new code does not need to inspect the IR
any more and we also do not generate multiple redundant writes.

llvm-svn: 243852
2015-08-02 16:17:41 +00:00
Michael Kruse 75b6b0c5bd Always execute polly::CodePreparation before Polly
ScopDetection does not allow scops to begin with the entry block, were
allocas are added at code generation.

llvm-svn: 243036
2015-07-23 20:00:20 +00:00
Chandler Carruth e677f7217b [PM/AA] Update to reflect the new LLVM API which no longer requires an
AliasAnalysis pointer.

llvm-svn: 242897
2015-07-22 12:15:33 +00:00
Tobias Grosser d783a98303 Add option to choose where in the pass pipeline polly is run
These options are useful to play with the location of Polly within LLVM's
pass manager.

llvm-svn: 242390
2015-07-16 08:28:09 +00:00
Tobias Grosser 16c4403a91 Make non-affine statement names isl compatible
Named isl sets can generally have any name if they remain within Polly, but only
certain strings can be parsed by isl. The new names we create ensure that we
can always copy-past isl strings from Polly to other isl tools, e.g. for
debugging.

llvm-svn: 241787
2015-07-09 07:31:45 +00:00
Tobias Grosser 50165ffdee Add support for srem instruction
Remainder operations with constant divisor can be modeled as quasi-affine
expression. This patch adds support for detecting and modeling them. We also
add a test that ensures they are correctly code generated.

This patch was extracted from a larger patch contributed by Johannes Doerfert
in http://reviews.llvm.org/D5293

llvm-svn: 240518
2015-06-24 04:13:29 +00:00
Tobias Grosser 09d3069740 Rename IslCodeGeneration to CodeGeneration
Besides class, function and file names, we also change the command line option
from -polly-codegen-isl to just -polly-codegen. The isl postfix is a leftover
from the times when we still had the CLooG based -polly-codegen. Today it is
just redundant and we drop it.

llvm-svn: 237099
2015-05-12 07:45:52 +00:00
Tobias Grosser ba0d09227c Sort include directives
Upcoming revisions of isl require us to include header files explicitly, which
have previously been already transitively included. Before we add them, we sort
the existing includes.

Thanks to Chandler for sort_includes.py. A simple, but very convenient script.

llvm-svn: 236930
2015-05-09 09:13:42 +00:00
Johannes Doerfert 8983031b5e [FIX] Invalid recognition of multidimensional access
In the lnt benchmark MultiSource/Benchmarks/MallocBench/gs/gs with
  scalar and PHI modeling we detected the multidimensional accesses
  with sizes variant in the SCoP. This will check the sizes for validity.

llvm-svn: 236395
2015-05-03 16:03:01 +00:00
Tobias Grosser a63b7cee66 Adding debug location information to Polly's JSCOP and dot exports
This change adds location information for the detected regions in Polly when the
required debug information is available.

The JSCOP output format is extended with a "location" field which contains the
information in the format "source.c:start-end"

The dot output is extended to contain the location information for each nested
region in the analyzed function.

As part of this change, the existing getDebugLocation function has been moved
into lib/Support/ScopLocation.cpp to avoid having to include
polly/ScopDetectionDiagnostics.h.

Differential Revision: http://reviews.llvm.org/D9431

Contributed-by: Roal Jordans <r.jordans@tue.nl>
llvm-svn: 236393
2015-05-03 05:21:36 +00:00
Tobias Grosser 8fd2390053 Do not expose code generator choice in the header
There is no need for other passes to access the code-generator command-line
option. Hence, drop it from the header to simplify the interface.

llvm-svn: 235866
2015-04-27 12:02:33 +00:00