[polly] r298197 - [CodeGen] Remove need for all parameters to be in scop context for load hoisting.

Tobias Grosser via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 18 16:12:50 PDT 2017


Author: grosser
Date: Sat Mar 18 18:12:49 2017
New Revision: 298197

URL: http://llvm.org/viewvc/llvm-project?rev=298197&view=rev
Log:
[CodeGen] Remove need for all parameters to be in scop context for load hoisting.

When not adding constraints on parameters using -polly-ignore-parameter-bounds,
the context may not necessarily list all parameter dimensions. To support code
generation in this situation, we now always iterate over the actual parameter
list, rather than relying on the context to list all parameter dimensions.

Added:
    polly/trunk/test/Isl/CodeGen/invariant_loads_ignore_parameter_bounds.ll
Modified:
    polly/trunk/include/polly/CodeGen/IslNodeBuilder.h
    polly/trunk/include/polly/ScopInfo.h
    polly/trunk/lib/CodeGen/IslNodeBuilder.cpp

Modified: polly/trunk/include/polly/CodeGen/IslNodeBuilder.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/CodeGen/IslNodeBuilder.h?rev=298197&r1=298196&r2=298197&view=diff
==============================================================================
--- polly/trunk/include/polly/CodeGen/IslNodeBuilder.h (original)
+++ polly/trunk/include/polly/CodeGen/IslNodeBuilder.h Sat Mar 18 18:12:49 2017
@@ -181,11 +181,13 @@ protected:
 
   /// Materialize parameters of @p Set.
   ///
-  /// @param All If not set only parameters referred to by the constraints in
-  ///            @p Set will be materialized, otherwise all.
+  /// @returns False, iff a problem occurred and the value was not materialized.
+  bool materializeParameters(__isl_take isl_set *Set);
+
+  /// Materialize all parameters in the current scop.
   ///
   /// @returns False, iff a problem occurred and the value was not materialized.
-  bool materializeParameters(__isl_take isl_set *Set, bool All);
+  bool materializeParameters();
 
   // Extract the upper bound of this loop
   //

Modified: polly/trunk/include/polly/ScopInfo.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/ScopInfo.h?rev=298197&r1=298196&r2=298197&view=diff
==============================================================================
--- polly/trunk/include/polly/ScopInfo.h (original)
+++ polly/trunk/include/polly/ScopInfo.h Sat Mar 18 18:12:49 2017
@@ -2105,6 +2105,11 @@ public:
   /// Take a list of parameters and add the new ones to the scop.
   void addParams(const ParameterSetTy &NewParameters);
 
+  /// Return an iterator range containing the scop parameters.
+  iterator_range<ParameterSetTy::iterator> parameters() const {
+    return make_range(Parameters.begin(), Parameters.end());
+  }
+
   /// Return whether this scop is empty, i.e. contains no statements that
   /// could be executed.
   bool isEmpty() const { return Stmts.empty(); }

Modified: polly/trunk/lib/CodeGen/IslNodeBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/IslNodeBuilder.cpp?rev=298197&r1=298196&r2=298197&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/IslNodeBuilder.cpp (original)
+++ polly/trunk/lib/CodeGen/IslNodeBuilder.cpp Sat Mar 18 18:12:49 2017
@@ -971,9 +971,9 @@ bool IslNodeBuilder::materializeValue(is
   return true;
 }
 
-bool IslNodeBuilder::materializeParameters(isl_set *Set, bool All) {
+bool IslNodeBuilder::materializeParameters(isl_set *Set) {
   for (unsigned i = 0, e = isl_set_dim(Set, isl_dim_param); i < e; ++i) {
-    if (!All && !isl_set_involves_dims(Set, isl_dim_param, i, 1))
+    if (!isl_set_involves_dims(Set, isl_dim_param, i, 1))
       continue;
     isl_id *Id = isl_set_get_dim_id(Set, isl_dim_param, i);
     if (!materializeValue(Id))
@@ -982,6 +982,15 @@ bool IslNodeBuilder::materializeParamete
   return true;
 }
 
+bool IslNodeBuilder::materializeParameters() {
+  for (const SCEV *Param : S.parameters()) {
+    isl_id *Id = S.getIdForParam(Param);
+    if (!materializeValue(Id))
+      return false;
+  }
+  return true;
+}
+
 /// Add the number of dimensions in @p BS to @p U.
 static isl_stat countTotalDims(__isl_take isl_basic_set *BS, void *U) {
   unsigned *NumTotalDim = static_cast<unsigned *>(U);
@@ -1034,7 +1043,7 @@ Value *IslNodeBuilder::preloadInvariantL
   isl_set *AccessRange = isl_map_range(MA.getAddressFunction());
   AccessRange = isl_set_gist_params(AccessRange, S.getContext());
 
-  if (!materializeParameters(AccessRange, false)) {
+  if (!materializeParameters(AccessRange)) {
     isl_set_free(AccessRange);
     isl_set_free(Domain);
     return nullptr;
@@ -1056,7 +1065,7 @@ Value *IslNodeBuilder::preloadInvariantL
     return PreloadVal;
   }
 
-  if (!materializeParameters(Domain, false)) {
+  if (!materializeParameters(Domain)) {
     isl_ast_build_free(Build);
     isl_set_free(AccessRange);
     isl_set_free(Domain);
@@ -1291,9 +1300,8 @@ bool IslNodeBuilder::preloadInvariantLoa
 }
 
 void IslNodeBuilder::addParameters(__isl_take isl_set *Context) {
-
   // Materialize values for the parameters of the SCoP.
-  materializeParameters(Context, /* all */ true);
+  materializeParameters();
 
   // Generate values for the current loop iteration for all surrounding loops.
   //

Added: polly/trunk/test/Isl/CodeGen/invariant_loads_ignore_parameter_bounds.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/invariant_loads_ignore_parameter_bounds.ll?rev=298197&view=auto
==============================================================================
--- polly/trunk/test/Isl/CodeGen/invariant_loads_ignore_parameter_bounds.ll (added)
+++ polly/trunk/test/Isl/CodeGen/invariant_loads_ignore_parameter_bounds.ll Sat Mar 18 18:12:49 2017
@@ -0,0 +1,36 @@
+; RUN: opt %loadPolly -polly-codegen -polly-invariant-load-hoisting \
+; RUN:     -polly-ignore-parameter-bounds -S < %s | FileCheck %s
+
+; CHECK: polly.preload.begin:
+; CHECK-NEXT: %global.load = load i32, i32* @global, align 4, !alias.scope !0, !noalias !2
+; CHECK-NEXT: store i32 %global.load, i32* %tmp24.preload.s2a
+
+target datalayout = "e-p:64:64:64-S128-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f16:16:16-f32:32:32-f64:64:64-f128:128:128-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+
+ at global = external global i32
+
+define void @hoge() {
+bb:
+  %tmp = alloca [4 x double], align 8
+  br label %bb18
+
+bb18:                                             ; preds = %bb16
+  %tmp19 = load i32, i32* @global, align 4
+  br label %bb20
+
+bb20:                                             ; preds = %bb21, %bb18
+  %tmp22 = icmp eq i32 0, %tmp19
+  br i1 %tmp22, label %bb23, label %bb20
+
+bb23:                                             ; preds = %bb21
+  %tmp24 = load i32, i32* @global, align 4
+  %tmp25 = add i32 %tmp24, 1
+  %tmp26 = sext i32 %tmp25 to i64
+  %tmp27 = add nsw i64 %tmp26, -1
+  %tmp28 = getelementptr [4 x double], [4 x double]* %tmp, i64 0, i64 %tmp27
+  store double undef, double* %tmp28
+  br label %bb29
+
+bb29:                                             ; preds = %bb23
+  ret void
+}




More information about the llvm-commits mailing list