| Submitter | Tobias Burnus |
|---|---|
| Date | Dec. 31, 2012, 12:17 p.m. |
| Message ID | <50E18240.8040806@net-b.de> |
| Download | mbox | patch |
| Permalink | /patch/208850/ |
| State | New |
| Headers | show |
Comments
On Mon, Dec 31, 2012 at 01:17:04PM +0100, Tobias Burnus wrote: > The attached patch adds a new - internal only - intrinsic, STRIDE, which > returns the stride of an array with array descriptor; for an "integer :: > array(5,5)", the stride of dim=2 is 5. > > This new intrinsic is only internally available and will be used by the > finalization wrapper to handle noncontiguous arrays. > What is the plan for when J3 decides to add a STRIDE intrinsic to Fortran20xy, which may have different semantics to what your function does? At a minimum, please consider adding a leading underscore to the function. This will clearly never conflict with a future Fortran standard (unless J3 looses it collected mind).
Hi Steve, Steve Kargl: > On Mon, Dec 31, 2012 at 01:17:04PM +0100, Tobias Burnus wrote: >> This new intrinsic is only internally available and will be used by the >> finalization wrapper to handle noncontiguous arrays. > What is the plan for when J3 decides to add a > STRIDE intrinsic Well, we then add it. As written, this intrinsic is *only* *internally* available. Actually, I do hope that J3 will add a better access to Fortran's array descriptor. Currently, one can do a lot of manipulations from C (since ISO/IEC TS 29113:2012) but not from Fortran. The better access from Fortran also matches the wish of the UK's BSI Fortran Panel: ftp://ftp.nag.co.uk/sc22wg5/N1901-N1950/N1923.pdf (4th non-indent paragraph). > At a minimum, please consider adding a leading underscore to the function. If you had read the patch carefully, you had seen that the intrinsic is defined as GFC_PREFIX ("stride"), which expands on most systems to "_F._stride". However, even if I had named it "stride" it were not available as it is marked as "make_from_module();". The latter implies that gfc_find_function (name) won't find it. You have to use a symbol which has "sym->intmod_sym_id" set - which is not possible from the user code. The "make_from_module();" technique has been added for procedures like "c_sizeof" which should be handled via the normal intrinsic handling (intrinsic.c, check.c, iresolve.c, trans-intrinsic.c), but where the procedure should only be available after using "USE ISO_C_BINDING". By the way, the symbol also never appears in the tree / assembler as it is converted into the respective component access of the array descriptor, e.g. "variable.dim[i].stride". Tobias
On Mon, Dec 31, 2012 at 08:19:49PM +0100, Tobias Burnus wrote: > Hi Steve, > > Steve Kargl: > > On Mon, Dec 31, 2012 at 01:17:04PM +0100, Tobias Burnus wrote: > >> This new intrinsic is only internally available and will be used by the > >> finalization wrapper to handle noncontiguous arrays. > > What is the plan for when J3 decides to add a > > STRIDE intrinsic > > Well, we then add it. As written, this intrinsic is *only* *internally* > available. > > Actually, I do hope that J3 will add a better access to Fortran's array > descriptor. Currently, one can do a lot of manipulations from C (since > ISO/IEC TS 29113:2012) but not from Fortran. The better access from > Fortran also matches the wish of the UK's BSI Fortran Panel: > ftp://ftp.nag.co.uk/sc22wg5/N1901-N1950/N1923.pdf (4th non-indent > paragraph). > > > At a minimum, please consider adding a leading underscore to the function. > > If you had read the patch carefully, you had seen that the intrinsic is > defined as GFC_PREFIX ("stride"), which expands on most systems to > "_F._stride". > Ah, I did miss the GFC_PREFIX declaration. I was going off your (mis)description of what you were adding to the list of intrinsics. Namely, you stated you were adding a STRIDE intrinsic when in fact you are adding a GFC_PREFIX("stride") intrinsic.
Dear Tobias, This one is also OK for trunk. It does cross my mind, however, that we should offer STRIDE as a gcc extension, in anticipation of F201x. Cheers Paul On 31 December 2012 13:17, Tobias Burnus <burnus@net-b.de> wrote: > The attached patch adds a new - internal only - intrinsic, STRIDE, which > returns the stride of an array with array descriptor; for an "integer :: > array(5,5)", the stride of dim=2 is 5. > > This new intrinsic is only internally available and will be used by the > finalization wrapper to handle noncontiguous arrays. > > Build on x86-64-gnu-linux. > OK for the trunk? > > Tobias
Patch
2012-12-31 Tobias Burnus <burnus@net-b.de>
* intrinsic.c (add_functions): New internal intrinsic
function GFC_PREFIX ("stride").
* gfortran.h (gfc_isym_id): Add GFC_ISYM_STRIDE.
* intrinsic.h (gfc_resolve_stride): New prototypes.
* iresolve.c (gfc_resolve_stride): New function.
* trans-intrinsic.c (conv_intrinsic_stride): New static
function.
(gfc_conv_intrinsic_function): Use it.
diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index a419af3..027cab6 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -521,6 +521,7 @@ enum gfc_isym_id
GFC_ISYM_SR_KIND,
GFC_ISYM_STAT,
GFC_ISYM_STORAGE_SIZE,
+ GFC_ISYM_STRIDE,
GFC_ISYM_SUM,
GFC_ISYM_SYMLINK,
GFC_ISYM_SYMLNK,
diff --git a/gcc/fortran/intrinsic.c b/gcc/fortran/intrinsic.c
index 274c921..8328b9b 100644
--- a/gcc/fortran/intrinsic.c
+++ b/gcc/fortran/intrinsic.c
@@ -2640,6 +2640,14 @@ add_functions (void)
make_generic ("size", GFC_ISYM_SIZE, GFC_STD_F95);
+ /* Obtain the stride for a given dimensions; to be used only internally.
+ "make_from_module" makes inaccessible for external users. */
+ add_sym_2 (GFC_PREFIX ("stride"), GFC_ISYM_STRIDE, CLASS_INQUIRY, ACTUAL_NO,
+ BT_INTEGER, gfc_index_integer_kind, GFC_STD_GNU,
+ NULL, NULL, gfc_resolve_stride,
+ ar, BT_REAL, dr, REQUIRED, dm, BT_INTEGER, ii, OPTIONAL);
+ make_from_module();
+
add_sym_1 ("sizeof", GFC_ISYM_SIZEOF, CLASS_IMPURE, ACTUAL_NO, BT_INTEGER, ii,
GFC_STD_GNU, gfc_check_sizeof, NULL, NULL,
x, BT_UNKNOWN, 0, REQUIRED);
diff --git a/gcc/fortran/intrinsic.h b/gcc/fortran/intrinsic.h
index 2635ba6..4540ad8 100644
--- a/gcc/fortran/intrinsic.h
+++ b/gcc/fortran/intrinsic.h
@@ -546,6 +546,7 @@ void gfc_resolve_signal (gfc_expr *, gfc_expr *, gfc_expr *);
void gfc_resolve_sin (gfc_expr *, gfc_expr *);
void gfc_resolve_sinh (gfc_expr *, gfc_expr *);
void gfc_resolve_size (gfc_expr *, gfc_expr *, gfc_expr *, gfc_expr *);
+void gfc_resolve_stride (gfc_expr *, gfc_expr *, gfc_expr *);
void gfc_resolve_spacing (gfc_expr *, gfc_expr *);
void gfc_resolve_spread (gfc_expr *, gfc_expr *, gfc_expr *, gfc_expr *);
void gfc_resolve_sqrt (gfc_expr *, gfc_expr *);
diff --git a/gcc/fortran/iresolve.c b/gcc/fortran/iresolve.c
index 3f981d8..c884fc1 100644
--- a/gcc/fortran/iresolve.c
+++ b/gcc/fortran/iresolve.c
@@ -2314,6 +2314,15 @@ gfc_resolve_size (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED,
void
+gfc_resolve_stride (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED,
+ gfc_expr *dim ATTRIBUTE_UNUSED)
+{
+ f->ts.type = BT_INTEGER;
+ f->ts.kind = gfc_index_integer_kind;
+}
+
+
+void
gfc_resolve_spacing (gfc_expr *f, gfc_expr *x)
{
f->ts = x->ts;
diff --git a/gcc/fortran/trans-intrinsic.c b/gcc/fortran/trans-intrinsic.c
index 5a89be1..e0b5f11 100644
--- a/gcc/fortran/trans-intrinsic.c
+++ b/gcc/fortran/trans-intrinsic.c
@@ -1657,6 +1657,35 @@ conv_intrinsic_cobound (gfc_se * se, gfc_expr * expr)
static void
+conv_intrinsic_stride (gfc_se * se, gfc_expr * expr)
+{
+ gfc_actual_arglist *array_arg;
+ gfc_actual_arglist *dim_arg;
+ gfc_se argse;
+ tree desc, tmp;
+
+ array_arg = expr->value.function.actual;
+ dim_arg = array_arg->next;
+
+ gcc_assert (array_arg->expr->expr_type == EXPR_VARIABLE);
+
+ gfc_init_se (&argse, NULL);
+ gfc_conv_expr_descriptor (&argse, array_arg->expr);
+ gfc_add_block_to_block (&se->pre, &argse.pre);
+ gfc_add_block_to_block (&se->post, &argse.post);
+ desc = argse.expr;
+
+ gcc_assert (dim_arg->expr);
+ gfc_init_se (&argse, NULL);
+ gfc_conv_expr_type (&argse, dim_arg->expr, gfc_array_index_type);
+ gfc_add_block_to_block (&se->pre, &argse.pre);
+ tmp = fold_build2_loc (input_location, MINUS_EXPR, gfc_array_index_type,
+ argse.expr, gfc_index_one_node);
+ se->expr = gfc_conv_descriptor_stride_get (desc, tmp);
+}
+
+
+static void
gfc_conv_intrinsic_abs (gfc_se * se, gfc_expr * expr)
{
tree arg, cabs;
@@ -6806,6 +6835,10 @@ gfc_conv_intrinsic_function (gfc_se * se, gfc_expr * expr)
gfc_conv_intrinsic_spacing (se, expr);
break;
+ case GFC_ISYM_STRIDE:
+ conv_intrinsic_stride (se, expr);
+ break;
+
case GFC_ISYM_SUM:
gfc_conv_intrinsic_arith (se, expr, PLUS_EXPR, false);
break;