[polly] r307579 - [IslAst] Print memory accesses in AST dump

Tobias Grosser via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 10 13:13:07 PDT 2017


Author: grosser
Date: Mon Jul 10 13:13:06 2017
New Revision: 307579

URL: http://llvm.org/viewvc/llvm-project?rev=307579&view=rev
Log:
[IslAst] Print memory accesses in AST dump

When providing the option "-polly-ast-print-accesses" Polly also prints the
memory accesses that are generated:

    #pragma known-parallel
    for (int c0 = 0; c0 <= 1023; c0 += 4)
      #pragma simd
      for (int c1 = c0; c1 <= c0 + 3; c1 += 1)
        Stmt_for_body(
          /* read  */ &MemRef_B[0]
          /* write */  MemRef_A[c1]
        );

This makes writing and debugging memory layout transformations easier.

Based on a patch contributed by Thomas Lang (ETH Zurich)

Added:
    polly/trunk/test/Isl/Ast/non_affine_access.ll
Modified:
    polly/trunk/lib/CodeGen/IslAst.cpp
    polly/trunk/test/Isl/Ast/single_loop_strip_mine.ll

Modified: polly/trunk/lib/CodeGen/IslAst.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/IslAst.cpp?rev=307579&r1=307578&r2=307579&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/IslAst.cpp (original)
+++ polly/trunk/lib/CodeGen/IslAst.cpp Mon Jul 10 13:13:06 2017
@@ -43,6 +43,8 @@
 #include "isl/set.h"
 #include "isl/union_map.h"
 
+#include <utility>
+
 #define DEBUG_TYPE "polly-ast"
 
 using namespace llvm;
@@ -55,6 +57,11 @@ static cl::opt<bool>
                   cl::desc("Generate thread parallel code (isl codegen only)"),
                   cl::init(false), cl::ZeroOrMore, cl::cat(PollyCategory));
 
+static cl::opt<bool> PrintAccesses("polly-ast-print-accesses",
+                                   cl::desc("Print memory access functions"),
+                                   cl::init(false), cl::ZeroOrMore,
+                                   cl::cat(PollyCategory));
+
 static cl::opt<bool> PollyParallelForce(
     "polly-parallel-force",
     cl::desc(
@@ -559,6 +566,55 @@ IslAstInfo IslAstAnalysis::run(Scop &S,
                  Dependences::AL_Statement)};
 }
 
+static __isl_give isl_printer *cbPrintUser(__isl_take isl_printer *P,
+                                           __isl_take isl_ast_print_options *O,
+                                           __isl_keep isl_ast_node *Node,
+                                           void *User) {
+  isl::ast_node AstNode = isl::manage(isl_ast_node_copy(Node));
+  isl::ast_expr NodeExpr = AstNode.user_get_expr();
+  isl::ast_expr CallExpr = NodeExpr.get_op_arg(0);
+  isl::id CallExprId = CallExpr.get_id();
+  ScopStmt *AccessStmt = (ScopStmt *)CallExprId.get_user();
+
+  P = isl_printer_start_line(P);
+  P = isl_printer_print_str(P, AccessStmt->getBaseName());
+  P = isl_printer_print_str(P, "(");
+  P = isl_printer_end_line(P);
+  P = isl_printer_indent(P, 2);
+
+  for (MemoryAccess *MemAcc : *AccessStmt) {
+    P = isl_printer_start_line(P);
+
+    if (MemAcc->isRead())
+      P = isl_printer_print_str(P, "/* read  */ &");
+    else
+      P = isl_printer_print_str(P, "/* write */  ");
+
+    isl::ast_build Build =
+        isl::manage(isl_ast_build_copy(IslAstInfo::getBuild(Node)));
+    if (MemAcc->isAffine()) {
+      isl_pw_multi_aff *PwmaPtr =
+          MemAcc->applyScheduleToAccessRelation(Build.get_schedule().release());
+      isl::pw_multi_aff Pwma = isl::manage(PwmaPtr);
+      isl::ast_expr AccessExpr = Build.access_from(Pwma);
+      P = isl_printer_print_ast_expr(P, AccessExpr.get());
+    } else {
+      P = isl_printer_print_str(
+          P, MemAcc->getLatestScopArrayInfo()->getName().c_str());
+      P = isl_printer_print_str(P, "[*]");
+    }
+    P = isl_printer_end_line(P);
+  }
+
+  P = isl_printer_indent(P, -2);
+  P = isl_printer_start_line(P);
+  P = isl_printer_print_str(P, ");");
+  P = isl_printer_end_line(P);
+
+  isl_ast_print_options_free(O);
+  return P;
+}
+
 void IslAstInfo::print(raw_ostream &OS) {
   isl_ast_print_options *Options;
   isl_ast_node *RootNode = Ast.getAst();
@@ -580,6 +636,10 @@ void IslAstInfo::print(raw_ostream &OS)
   char *RtCStr, *AstStr;
 
   Options = isl_ast_print_options_alloc(S.getIslCtx());
+
+  if (PrintAccesses)
+    Options =
+        isl_ast_print_options_set_print_user(Options, cbPrintUser, nullptr);
   Options = isl_ast_print_options_set_print_for(Options, cbPrintFor, nullptr);
 
   isl_printer *P = isl_printer_to_str(S.getIslCtx());

Added: polly/trunk/test/Isl/Ast/non_affine_access.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/Ast/non_affine_access.ll?rev=307579&view=auto
==============================================================================
--- polly/trunk/test/Isl/Ast/non_affine_access.ll (added)
+++ polly/trunk/test/Isl/Ast/non_affine_access.ll Mon Jul 10 13:13:06 2017
@@ -0,0 +1,52 @@
+; RUN: opt %loadPolly -polly-ast -polly-ast-print-accesses -analyze \
+; RUN:   -polly-allow-nonaffine < %s \
+; RUN:   | FileCheck %s
+;
+;    void non_affine_access(float A[]) {
+;      for (long i = 0; i < 1024; i++)
+;        A[i * i] = 1;
+;    }
+
+; CHECK: for (int c0 = 0; c0 <= 1023; c0 += 1)
+; CHECK:   Stmt_bb3(
+; CHECK:     /* write */  MemRef_A[*]
+; CHECK:   );
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-linux-gnu"
+
+define void @non_affine_access(float* %A) {
+bb:
+  br label %bb1
+
+bb1:                                              ; preds = %bb6, %bb
+  %i.0 = phi i64 [ 0, %bb ], [ %tmp7, %bb6 ]
+  %exitcond = icmp ne i64 %i.0, 1024
+  br i1 %exitcond, label %bb3, label %bb2
+
+bb2:                                              ; preds = %bb1
+  br label %bb8
+
+bb3:                                              ; preds = %bb1
+  %prod = mul i64 %i.0, %i.0
+  %tmp5 = getelementptr inbounds float, float* %A, i64 %prod
+  store float 1.000000e+00, float* %tmp5, align 4, !tbaa !5
+  br label %bb6
+
+bb6:                                              ; preds = %bb3
+  %tmp7 = add nuw nsw i64 %i.0, 1
+  br label %bb1
+
+bb8:                                              ; preds = %bb2
+  ret void
+}
+
+!llvm.ident = !{!0}
+
+!0 = !{!"Ubuntu clang version 3.7.1-3ubuntu4 (tags/RELEASE_371/final) (based on LLVM 3.7.1)"}
+!1 = !{!2, !2, i64 0}
+!2 = !{!"long", !3, i64 0}
+!3 = !{!"omnipotent char", !4, i64 0}
+!4 = !{!"Simple C/C++ TBAA"}
+!5 = !{!6, !6, i64 0}
+!6 = !{!"float", !3, i64 0}

Modified: polly/trunk/test/Isl/Ast/single_loop_strip_mine.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/Ast/single_loop_strip_mine.ll?rev=307579&r1=307578&r2=307579&view=diff
==============================================================================
--- polly/trunk/test/Isl/Ast/single_loop_strip_mine.ll (original)
+++ polly/trunk/test/Isl/Ast/single_loop_strip_mine.ll Mon Jul 10 13:13:06 2017
@@ -1,5 +1,8 @@
 ; RUN: opt %loadPolly -basicaa -polly-ast -analyze < %s | FileCheck %s
-; RUN: opt %loadPolly -polly-import-jscop-dir=%S -basicaa -polly-import-jscop -polly-ast -polly-ast-detect-parallel -analyze < %s | FileCheck %s -check-prefix=CHECK-VECTOR
+; RUN: opt %loadPolly -polly-import-jscop-dir=%S -basicaa -polly-import-jscop \
+; RUN:   -polly-ast-print-accesses \
+; RUN:   -polly-ast -polly-ast-detect-parallel -analyze < %s | FileCheck %s \
+; RUN:   -check-prefix=CHECK-VECTOR
 
 ; for (i = 0; i < 1024; i++)
 ;   A[i] = B[i];
@@ -35,6 +38,8 @@ for.end:
 ; CHECK-VECTOR: for (int c0 = 0; c0 <= 1023; c0 += 4)
 ; CHECK-VECTOR:     #pragma simd
 ; CHECK-VECTOR:     for (int c1 = c0; c1 <= c0 + 3; c1 += 1)
-; CHECK-VECTOR:           Stmt_for_body(c1);
-
+; CHECK-VECTOR:       Stmt_for_body(
+; CHECK-VECTOR:         /* read  */ &MemRef_B[0]
+; CHECK-VECTOR:         /* write */  MemRef_A[c1]
+; CHECK-VECTOR:       );
 




More information about the llvm-commits mailing list