在 2017年09月05日 14:14, Tobias Grosser 写道:
Hi Leslie,

I copied you in this thread as you currently worked quite a bit with
dragonegg and we are currently trying to generate metadata that makes it
easier to reason about multi-dimensional fortran arrays.

Best,
Tobias

On Mon, Sep 4, 2017, at 23:06, (IIIT) Siddharth Bhat wrote:
Hello,

I've been hacking on the Gfortran frontend to change array index
expressions to function calls, so that I can inspect them later on in the
pipeline. I go from Fortran -> LLVM IR (through dragonegg) where I will
look at the function call nodes.

However, I'm not able to generate correct IR for this. I can create
function call, but I am unable to assign the return value of a function
call to a variable here.

Here's a link to my experiments here: It includes a patch, a test file
and
the GIMPLE output
<https://gist.github.com/bollu/999184bdb3d0f1569ee0fd0a351689e3#file-m-gimple-L24>

I rebase the patch for GCC v8.x at first:


diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index 9efb531..73dad6e 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -3251,6 +3251,7 @@ gfc_conv_scalarized_array_ref (gfc_se * se, gfc_array_ref * ar)
   if (build_class_array_ref (se, tmp, index))
     return;

+  call_polly_index(&se->pre, index, ar);
   se->expr = gfc_build_array_ref (tmp, index, decl);
 }

@@ -3335,6 +3336,24 @@ build_array_ref (tree desc, tree offset, tree decl, tree vptr)
   return tmp;
 }

+// See: gfc_call_malloc
+static tree call_polly_index(stmtblock_t *parent_block, tree *original_index,
+        gfc_array_ref *ar) {
+  tree fncall, var, result;
+  stmtblock_t block;
+
+  var = gfc_create_var(gfc_array_index_type, "pollyindex");
+  gfc_init_block (&block);
+
+ fncall = build_call_expr_loc(input_location, gfor_fndecl_polly_array_index, 0);
+  gfc_add_modify(&block, var, fold_convert(gfc_array_index_type, fncall));
+  result = gfc_finish_block (&block);
+  gfc_add_expr_to_block(parent_block, result);
+  return var;
+
+  // return var;
+}
+

 /* Build an array reference.  se->expr already holds the array descriptor.
This should be either a variable, indirect variable reference or component
diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c
index 74d8606..28ddcfd 100644
--- a/gcc/fortran/trans-decl.c
+++ b/gcc/fortran/trans-decl.c
@@ -95,6 +95,7 @@ static int seen_ieee_symbol;

 /* Function declarations for builtin library functions.  */

+tree gfor_fndecl_polly_array_index;
 tree gfor_fndecl_pause_numeric;
 tree gfor_fndecl_pause_string;
 tree gfor_fndecl_stop_numeric;
@@ -3495,6 +3496,14 @@ gfc_build_builtin_function_decls (void)
   /* ERROR STOP doesn't return.  */
   TREE_THIS_VOLATILE (gfor_fndecl_error_stop_string) = 1;

+
+  printf("building polly_array_index function decl...\n");
+  gfor_fndecl_polly_array_index = gfc_build_library_function_decl (
+    get_identifier (PREFIX("polly_array_index")),
+    gfc_array_index_type, 0);
+  TREE_THIS_VOLATILE (gfor_fndecl_polly_array_index) = 1;
+  printf("built polly_array_index function decl...\n");
+
   gfor_fndecl_pause_numeric = gfc_build_library_function_decl (
     get_identifier (PREFIX("pause_numeric")),
     void_type_node, 1, gfc_int4_type_node);
diff --git a/gcc/fortran/trans.h b/gcc/fortran/trans.h
index d02f347..c8d24ec 100644
--- a/gcc/fortran/trans.h
+++ b/gcc/fortran/trans.h
@@ -781,6 +781,7 @@ struct gimplify_omp_ctx;
 void gfc_omp_firstprivatize_type_sizes (struct gimplify_omp_ctx *, tree);

 /* Runtime library function decls.  */
+extern GTY(()) tree gfor_fndecl_polly_array_index;
 extern GTY(()) tree gfor_fndecl_pause_numeric;
 extern GTY(()) tree gfor_fndecl_pause_string;
 extern GTY(()) tree gfor_fndecl_stop_numeric;


then I will rebuild GCC for investigation.


.

Help would be very much appreciated!

Thanks,
Siddharth.
--
Sending this from my phone, please excuse any typos!

--
Regards,
Leslie Zhai - https://reviews.llvm.org/p/xiangzhai/



Reply via email to