public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-3782] Fortran: Add gfc_simple_for_loop aux function
@ 2021-09-22  9:11 Tobias Burnus
  0 siblings, 0 replies; only message in thread
From: Tobias Burnus @ 2021-09-22  9:11 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:424a4a463ac5932830a83560cf929f9c2f4564d8

commit r12-3782-g424a4a463ac5932830a83560cf929f9c2f4564d8
Author: Tobias Burnus <tobias@codesourcery.com>
Date:   Wed Sep 22 11:11:00 2021 +0200

    Fortran: Add gfc_simple_for_loop aux function
    
    Function to generate a simple loop (to be used internally).
    Callers will be added in follow-up commits.
    
    gcc/fortran/
            * trans-expr.c (gfc_simple_for_loop): New.
            * trans.h (gfc_simple_for_loop): New prototype.

Diff:
---
 gcc/fortran/trans-expr.c | 34 ++++++++++++++++++++++++++++++++++
 gcc/fortran/trans.h      |  2 ++
 2 files changed, 36 insertions(+)

diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c
index 4a81f4695d9..41d5452aecf 100644
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -11728,3 +11728,37 @@ gfc_trans_assign (gfc_code * code)
 {
   return gfc_trans_assignment (code->expr1, code->expr2, false, true);
 }
+
+/* Generate a simple loop for internal use of the form
+   for (var = begin; var <cond> end; var += step)
+      body;  */
+void
+gfc_simple_for_loop (stmtblock_t *block, tree var, tree begin, tree end,
+		     enum tree_code cond, tree step, tree body)
+{
+  tree tmp;
+
+  /* var = begin. */
+  gfc_add_modify (block, var, begin);
+
+  /* Loop: for (var = begin; var <cond> end; var += step).  */
+  tree label_loop = gfc_build_label_decl (NULL_TREE);
+  tree label_cond = gfc_build_label_decl (NULL_TREE);
+  TREE_USED (label_loop) = 1;
+  TREE_USED (label_cond) = 1;
+
+  gfc_add_expr_to_block (block, build1_v (GOTO_EXPR, label_cond));
+  gfc_add_expr_to_block (block, build1_v (LABEL_EXPR, label_loop));
+
+  /* Loop body.  */
+  gfc_add_expr_to_block (block, body);
+
+  /* End of loop body.  */
+  tmp = fold_build2_loc (input_location, PLUS_EXPR, TREE_TYPE (var), var, step);
+  gfc_add_modify (block, var, tmp);
+  gfc_add_expr_to_block (block, build1_v (LABEL_EXPR, label_cond));
+  tmp = fold_build2_loc (input_location, cond, boolean_type_node, var, end);
+  tmp = build3_v (COND_EXPR, tmp, build1_v (GOTO_EXPR, label_loop),
+		  build_empty_stmt (input_location));
+  gfc_add_expr_to_block (block, tmp);
+}
diff --git a/gcc/fortran/trans.h b/gcc/fortran/trans.h
index 78578cfd732..4d29834dc52 100644
--- a/gcc/fortran/trans.h
+++ b/gcc/fortran/trans.h
@@ -518,6 +518,8 @@ tree gfc_string_to_single_character (tree len, tree str, int kind);
 tree gfc_get_tree_for_caf_expr (gfc_expr *);
 void gfc_get_caf_token_offset (gfc_se*, tree *, tree *, tree, tree, gfc_expr *);
 tree gfc_caf_get_image_index (stmtblock_t *, gfc_expr *, tree);
+void gfc_simple_for_loop (stmtblock_t *, tree, tree, tree, enum tree_code, tree,
+			  tree);
 
 /* Find the decl containing the auxiliary variables for assigned variables.  */
 void gfc_conv_label_variable (gfc_se * se, gfc_expr * expr);


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-09-22  9:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-22  9:11 [gcc r12-3782] Fortran: Add gfc_simple_for_loop aux function Tobias Burnus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).