Skip to content

Instantly share code, notes, and snippets.

@bollu
Last active September 4, 2017 21:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bollu/999184bdb3d0f1569ee0fd0a351689e3 to your computer and use it in GitHub Desktop.
Save bollu/999184bdb3d0f1569ee0fd0a351689e3 to your computer and use it in GitHub Desktop.
How to create GIMPLE for function call?
diff --git a/fortran/trans-array.c b/fortran/trans-array.c
index c76cd11..d015465 100644
--- a/fortran/trans-array.c
+++ b/fortran/trans-array.c
@@ -2583,6 +2583,24 @@ gfc_conv_tmp_array_ref (gfc_se * se)
gfc_advance_se_ss_chain (se);
}
+// 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
@@ -2696,7 +2714,15 @@ gfc_conv_array_ref (gfc_se * se, gfc_array_ref * ar, gfc_symbol * sym,
/* Access the calculated element. */
tmp = gfc_conv_array_data (se->expr);
tmp = build_fold_indirect_ref (tmp);
+
+ printf("TIMSTAMP: %s - %s\n", __DATE__, __TIME__);
+ printf("======\n");
+
+
+ printf("# 1. index(new):\n");
+ call_polly_index(&se->pre, index, ar);
se->expr = gfc_build_array_ref (tmp, index, sym->backend_decl);
+ printf("======\n");
}
diff --git a/fortran/trans-decl.c b/fortran/trans-decl.c
index 5b5e788..3e11a69 100644
--- a/fortran/trans-decl.c
+++ b/fortran/trans-decl.c
@@ -85,6 +85,7 @@ tree gfc_static_ctors;
/* 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;
@@ -2934,6 +2935,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/fortran/trans.h b/fortran/trans.h
index 1536f2e..dc49e80 100644
--- a/fortran/trans.h
+++ b/fortran/trans.h
@@ -592,6 +592,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;
MODULE m
IMPLICIT NONE
REAL, ALLOCATABLE :: &
g_arr(:,:)
CONTAINS
SUBROUTINE f()
INTEGER :: &
i, j
REAL :: &
coeff
DO i=1, 3
DO j=1,3
g_arr(i, j) = 2
END DO
END DO
END SUBROUTINE f
END MODULE m
f ()
{
void * restrict D.1566;
integer(kind=4) i;
integer(kind=4) j;
i = 1;
if (i <= 3) goto <D.1560>; else goto <D.1561>;
<D.1560>:
<D.1562>:
{
logical(kind=4) D.1559;
j = 1;
if (j <= 3) goto <D.1563>; else goto <D.1564>;
<D.1563>:
<D.1565>:
{
logical(kind=4) D.1558;
{
integer(kind=8) pollyindex.0;
_gfortran_polly_array_index ();
D.1566 = g_arr.data;
MEM[(real(kind=4)[0:] *)D.1566][pollyindex.0] = 2.0e+0;
}
L.3:
D.1558 = j == 3;
j = j + 1;
if (D.1558 != 0) goto L.4; else goto <D.1567>;
<D.1567>:
}
goto <D.1565>;
<D.1564>:
L.4:
L.1:
D.1559 = i == 3;
i = i + 1;
if (D.1559 != 0) goto L.2; else goto <D.1568>;
<D.1568>:
}
goto <D.1562>;
<D.1561>:
L.2:
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment