hanchenye-llvm-project/polly
Michael Kruse 6744efa8d8 [ScopDetection] Only allow SCoP-wide available base pointers.
Simplify ScopDetection::isInvariant(). Essentially deny everything that
is defined within the SCoP and is not load-hoisted.

The previous understanding of "invariant" has a few holes:

- Expressions without side-effects with only invariant arguments, but
  are defined withing the SCoP's region with the exception of selects
  and PHIs. These should be part of the index expression derived by
  ScalarEvolution and not of the base pointer.

- Function calls with that are !mayHaveSideEffects() (typically
  functions with "readnone nounwind" attributes). An example is given
  below.

      @C = external global i32
      declare float* @getNextBasePtr(float*) readnone nounwind
      ...
      %ptr = call float* @getNextBasePtr(float* %A, float %B)

  The call might return:

  * %A, so %ptr aliases with it in the SCoP
  * %B, so %ptr aliases with it in the SCoP
  * @C, so %ptr aliases with it in the SCoP
  * a new pointer everytime it is called, such as malloc()
  * a pointer into the allocated block of one of the aforementioned
  * any of the above, at random at each call

  Hence and contrast to a comment in the base_pointer.ll regression
  test, %ptr is not necessarily the same all the time. It might also
  alias with anything and no AliasAnalysis can tell otherwise if the
  definition is external. It is hence not suitable in the role of a
  base pointer.

The practical problem with base pointers defined in SCoP statements is
that it is not available globally in the SCoP. The statement instance
must be executed first before the base pointer can be used. This is no
problem if the base pointer is transferred as a scalar value between
statements. Uses of MemoryAccess::setNewAccessRelation may add a use of
the base pointer anywhere in the array. setNewAccessRelation is used by
JSONImporter, DeLICM and D28518. Indeed, BlockGenerator currently
assumes that base pointers are available globally and generates invalid
code for new access relation (referring to the base pointer of the
original code) if not, even if the base pointer would be available in
the statement.

This could be fixed with some added complexity and restrictions. The
ExprBuilder must lookup the local BBMap and code that call
setNewAccessRelation must check whether the base pointer is available
first.

The code would still be incorrect in the presence of aliasing. There
is the switch -polly-ignore-aliasing to explicitly allow this, but
it is hardly a justification for the additional complexity. It would
still be mostly useless because in most cases either getNextBasePtr()
has external linkage in which case the readnone nounwind attributes
cannot be derived in the translation unit itself, or is defined in the
same translation unit and gets inlined.

Reviewed By: grosser

Differential Revision: https://reviews.llvm.org/D30695

llvm-svn: 297281
2017-03-08 15:14:46 +00:00
..
cmake [Cmake] Optionally use a system isl version. 2017-02-27 17:54:25 +00:00
docs Porting the example illustrating Polly from HTML to reStructuredText 2017-02-10 11:46:57 +00:00
include/polly [ScopDetection] Require LoadInst base pointers to be hoisted. 2017-03-07 20:28:43 +00:00
lib [ScopDetection] Only allow SCoP-wide available base pointers. 2017-03-08 15:14:46 +00:00
test [ScopDetection] Only allow SCoP-wide available base pointers. 2017-03-08 15:14:46 +00:00
tools GPURuntime: ensure compilation with C99 2016-09-11 07:32:50 +00:00
unittests [Support] Remove NonowningIslPtr. NFC. 2017-02-23 17:57:27 +00:00
utils
www Porting the example illustrating Polly from HTML to reStructuredText 2017-02-10 11:46:57 +00:00
.arcconfig Upgrade all the .arcconfigs to https. 2016-07-14 13:15:37 +00:00
.arclint [External] Move lib/JSON to lib/External/JSON. NFC. 2017-02-05 15:26:56 +00:00
.gitattributes
.gitignore Do not track the isl PDF manual in SVN 2017-01-16 11:48:03 +00:00
CMakeLists.txt [Cmake] Optionally use a system isl version. 2017-02-27 17:54:25 +00:00
CREDITS.txt
LICENSE.txt [External] Move lib/JSON to lib/External/JSON. NFC. 2017-02-05 15:26:56 +00:00
README

README

Polly - Polyhedral optimizations for LLVM
-----------------------------------------
http://polly.llvm.org/

Polly uses a mathematical representation, the polyhedral model, to represent and
transform loops and other control flow structures. Using an abstract
representation it is possible to reason about transformations in a more general
way and to use highly optimized linear programming libraries to figure out the
optimal loop structure. These transformations can be used to do constant
propagation through arrays, remove dead loop iterations, optimize loops for
cache locality, optimize arrays, apply advanced automatic parallelization, drive
vectorization, or they can be used to do software pipelining.