tree-data-ref.h

Go to the documentation of this file.
00001 /* Data references and dependences detectors. 
00002    Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
00003    Contributed by Sebastian Pop <pop@cri.ensmp.fr>
00004 
00005 This file is part of GCC.
00006 
00007 GCC is free software; you can redistribute it and/or modify it under
00008 the terms of the GNU General Public License as published by the Free
00009 Software Foundation; either version 2, or (at your option) any later
00010 version.
00011 
00012 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
00013 WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with GCC; see the file COPYING.  If not, write to the Free
00019 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
00020 02110-1301, USA.  */
00021 
00022 #ifndef GCC_TREE_DATA_REF_H
00023 #define GCC_TREE_DATA_REF_H
00024 
00025 #include "lambda.h"
00026 
00046 struct first_location_in_loop
00047 {
00048   tree base_address;
00049   tree offset;
00050   tree init;
00051   tree step;
00052   /* Access function related to first location in the loop.  */
00053   VEC(tree,heap) *access_fns;
00054 
00055 };
00056 
00057 struct base_object_info
00058 {
00059   /* The object.  */
00060   tree base_object;
00061   
00062   /* A list of chrecs.  Access functions related to BASE_OBJECT.  */
00063   VEC(tree,heap) *access_fns;
00064 };
00065 
00066 enum data_ref_type {
00067   ARRAY_REF_TYPE,
00068   POINTER_REF_TYPE
00069 };
00070 
00071 struct data_reference
00072 {
00073   /* A pointer to the statement that contains this DR.  */
00074   tree stmt;
00075   
00076   /* A pointer to the ARRAY_REF node.  */
00077   tree ref;
00078 
00079   /* Auxiliary info specific to a pass.  */
00080   int aux;
00081 
00082   /* True when the data reference is in RHS of a stmt.  */
00083   bool is_read;
00084 
00085   /* First location accessed by the data-ref in the loop.  */
00086   struct first_location_in_loop first_location;
00087 
00088   /* Base object related info.  */
00089   struct base_object_info object_info;
00090 
00091   /* Aliasing information.  This field represents the symbol that
00092      should be aliased by a pointer holding the address of this data
00093      reference.  If the original data reference was a pointer
00094      dereference, then this field contains the memory tag that should
00095      be used by the new vector-pointer.  */
00096   tree memtag;
00097   struct ptr_info_def *ptr_info;
00098   subvar_t subvars;
00099 
00100   /* Alignment information.  */ 
00101   /* The offset of the data-reference from its base in bytes.  */
00102   tree misalignment;
00103   /* The maximum data-ref's alignment.  */
00104   tree aligned_to;
00105 
00106   /* The type of the data-ref.  */
00107   enum data_ref_type type;
00108 };
00109 
00110 typedef struct data_reference *data_reference_p;
00111 DEF_VEC_P(data_reference_p);
00112 DEF_VEC_ALLOC_P (data_reference_p, heap);
00113 
00114 #define DR_STMT(DR)                (DR)->stmt
00115 #define DR_REF(DR)                 (DR)->ref
00116 #define DR_BASE_OBJECT(DR)         (DR)->object_info.base_object
00117 #define DR_TYPE(DR)                (DR)->type
00118 #define DR_ACCESS_FNS(DR)\
00119   (DR_TYPE(DR) == ARRAY_REF_TYPE ?  \
00120    (DR)->object_info.access_fns : (DR)->first_location.access_fns)
00121 #define DR_ACCESS_FN(DR, I)        VEC_index (tree, DR_ACCESS_FNS (DR), I)
00122 #define DR_NUM_DIMENSIONS(DR)      VEC_length (tree, DR_ACCESS_FNS (DR))  
00123 #define DR_IS_READ(DR)             (DR)->is_read
00124 #define DR_BASE_ADDRESS(DR)        (DR)->first_location.base_address
00125 #define DR_OFFSET(DR)              (DR)->first_location.offset
00126 #define DR_INIT(DR)                (DR)->first_location.init
00127 #define DR_STEP(DR)                (DR)->first_location.step
00128 #define DR_MEMTAG(DR)              (DR)->memtag
00129 #define DR_ALIGNED_TO(DR)          (DR)->aligned_to
00130 #define DR_OFFSET_MISALIGNMENT(DR) (DR)->misalignment
00131 #define DR_PTR_INFO(DR)            (DR)->ptr_info
00132 #define DR_SUBVARS(DR)             (DR)->subvars
00133 
00134 #define DR_ACCESS_FNS_ADDR(DR)       \
00135   (DR_TYPE(DR) == ARRAY_REF_TYPE ?   \
00136    &((DR)->object_info.access_fns) : &((DR)->first_location.access_fns))
00137 #define DR_SET_ACCESS_FNS(DR, ACC_FNS)         \
00138 {                                              \
00139   if (DR_TYPE(DR) == ARRAY_REF_TYPE)           \
00140     (DR)->object_info.access_fns = ACC_FNS;    \
00141   else                                         \
00142     (DR)->first_location.access_fns = ACC_FNS; \
00143 }
00144 #define DR_FREE_ACCESS_FNS(DR)                              \
00145 {                                                           \
00146   if (DR_TYPE(DR) == ARRAY_REF_TYPE)                        \
00147     VEC_free (tree, heap, (DR)->object_info.access_fns);    \
00148   else                                                      \
00149     VEC_free (tree, heap, (DR)->first_location.access_fns); \
00150 }
00151 
00152 enum data_dependence_direction {
00153   dir_positive, 
00154   dir_negative, 
00155   dir_equal, 
00156   dir_positive_or_negative,
00157   dir_positive_or_equal,
00158   dir_negative_or_equal,
00159   dir_star,
00160   dir_independent
00161 };
00162 
00163 /* What is a subscript?  Given two array accesses a subscript is the
00164    tuple composed of the access functions for a given dimension.
00165    Example: Given A[f1][f2][f3] and B[g1][g2][g3], there are three
00166    subscripts: (f1, g1), (f2, g2), (f3, g3).  These three subscripts
00167    are stored in the data_dependence_relation structure under the form
00168    of an array of subscripts.  */
00169 
00170 struct subscript
00171 {
00172   /* A description of the iterations for which the elements are
00173      accessed twice.  */
00174   tree conflicting_iterations_in_a;
00175   tree conflicting_iterations_in_b;
00176   
00177   /* This field stores the information about the iteration domain
00178      validity of the dependence relation.  */
00179   tree last_conflict;
00180   
00181   /* Distance from the iteration that access a conflicting element in
00182      A to the iteration that access this same conflicting element in
00183      B.  The distance is a tree scalar expression, i.e. a constant or a
00184      symbolic expression, but certainly not a chrec function.  */
00185   tree distance;
00186 };
00187 
00188 typedef struct subscript *subscript_p;
00189 DEF_VEC_P(subscript_p);
00190 DEF_VEC_ALLOC_P (subscript_p, heap);
00191 
00192 #define SUB_CONFLICTS_IN_A(SUB) SUB->conflicting_iterations_in_a
00193 #define SUB_CONFLICTS_IN_B(SUB) SUB->conflicting_iterations_in_b
00194 #define SUB_LAST_CONFLICT(SUB) SUB->last_conflict
00195 #define SUB_DISTANCE(SUB) SUB->distance
00196 
00197 typedef struct loop *loop_p;
00198 DEF_VEC_P(loop_p);
00199 DEF_VEC_ALLOC_P (loop_p, heap);
00200 
00201 /* A data_dependence_relation represents a relation between two
00202    data_references A and B.  */
00203 
00204 struct data_dependence_relation
00205 {
00206   
00207   struct data_reference *a;
00208   struct data_reference *b;
00209 
00210   /* When the dependence relation is affine, it can be represented by
00211      a distance vector.  */
00212   bool affine_p;
00213 
00214   /* A "yes/no/maybe" field for the dependence relation:
00215      
00216      - when "ARE_DEPENDENT == NULL_TREE", there exist a dependence
00217        relation between A and B, and the description of this relation
00218        is given in the SUBSCRIPTS array,
00219      
00220      - when "ARE_DEPENDENT == chrec_known", there is no dependence and
00221        SUBSCRIPTS is empty,
00222      
00223      - when "ARE_DEPENDENT == chrec_dont_know", there may be a dependence,
00224        but the analyzer cannot be more specific.  */
00225   tree are_dependent;
00226   
00227   /* For each subscript in the dependence test, there is an element in
00228      this array.  This is the attribute that labels the edge A->B of
00229      the data_dependence_relation.  */
00230   VEC (subscript_p, heap) *subscripts;
00231 
00232   /* The analyzed loop nest.  */
00233   VEC (loop_p, heap) *loop_nest;
00234 
00235   /* The classic direction vector.  */
00236   VEC (lambda_vector, heap) *dir_vects;
00237 
00238   /* The classic distance vector.  */
00239   VEC (lambda_vector, heap) *dist_vects;
00240 };
00241 
00242 typedef struct data_dependence_relation *ddr_p;
00243 DEF_VEC_P(ddr_p);
00244 DEF_VEC_ALLOC_P(ddr_p,heap);
00245 
00246 #define DDR_A(DDR) DDR->a
00247 #define DDR_B(DDR) DDR->b
00248 #define DDR_AFFINE_P(DDR) DDR->affine_p
00249 #define DDR_ARE_DEPENDENT(DDR) DDR->are_dependent
00250 #define DDR_SUBSCRIPTS(DDR) DDR->subscripts
00251 #define DDR_SUBSCRIPT(DDR, I) VEC_index (subscript_p, DDR_SUBSCRIPTS (DDR), I)
00252 #define DDR_NUM_SUBSCRIPTS(DDR) VEC_length (subscript_p, DDR_SUBSCRIPTS (DDR))
00253 
00254 #define DDR_LOOP_NEST(DDR) DDR->loop_nest
00255 /* The size of the direction/distance vectors: the number of loops in
00256    the loop nest.  */
00257 #define DDR_NB_LOOPS(DDR) (VEC_length (loop_p, DDR_LOOP_NEST (DDR)))
00258 
00259 #define DDR_DIST_VECTS(DDR) ((DDR)->dist_vects)
00260 #define DDR_DIR_VECTS(DDR) ((DDR)->dir_vects)
00261 #define DDR_NUM_DIST_VECTS(DDR) \
00262   (VEC_length (lambda_vector, DDR_DIST_VECTS (DDR)))
00263 #define DDR_NUM_DIR_VECTS(DDR) \
00264   (VEC_length (lambda_vector, DDR_DIR_VECTS (DDR)))
00265 #define DDR_DIR_VECT(DDR, I) \
00266   VEC_index (lambda_vector, DDR_DIR_VECTS (DDR), I)
00267 #define DDR_DIST_VECT(DDR, I) \
00268   VEC_index (lambda_vector, DDR_DIST_VECTS (DDR), I)
00269 
00270 
00271 
00272 extern tree find_data_references_in_loop (struct loop *,
00273                                           VEC (data_reference_p, heap) **);
00274 extern void compute_data_dependences_for_loop (struct loop *, bool,
00275                                                VEC (data_reference_p, heap) **,
00276                                                VEC (ddr_p, heap) **);
00277 extern void print_direction_vector (FILE *, lambda_vector, int);
00278 extern void print_dir_vectors (FILE *, VEC (lambda_vector, heap) *, int);
00279 extern void print_dist_vectors (FILE *, VEC (lambda_vector, heap) *, int);
00280 extern void dump_subscript (FILE *, struct subscript *);
00281 extern void dump_ddrs (FILE *, VEC (ddr_p, heap) *);
00282 extern void dump_dist_dir_vectors (FILE *, VEC (ddr_p, heap) *);
00283 extern void dump_data_reference (FILE *, struct data_reference *);
00284 extern void dump_data_references (FILE *, VEC (data_reference_p, heap) *);
00285 extern void debug_data_dependence_relation (struct data_dependence_relation *);
00286 extern void dump_data_dependence_relation (FILE *, 
00287                                            struct data_dependence_relation *);
00288 extern void dump_data_dependence_relations (FILE *, VEC (ddr_p, heap) *);
00289 extern void dump_data_dependence_direction (FILE *, 
00290                                             enum data_dependence_direction);
00291 extern void free_dependence_relation (struct data_dependence_relation *);
00292 extern void free_dependence_relations (VEC (ddr_p, heap) *);
00293 extern void free_data_refs (VEC (data_reference_p, heap) *);
00294 extern struct data_reference *analyze_array (tree, tree, bool);
00295 extern void estimate_iters_using_array (tree, tree);
00296 
00297 
00298 /* Return the index of the variable VAR in the LOOP_NEST array.  */
00299 
00300 static inline int
00301 index_in_loop_nest (int var, VEC (loop_p, heap) *loop_nest)
00302 {
00303   struct loop *loopi;
00304   int var_index;
00305 
00306   for (var_index = 0; VEC_iterate (loop_p, loop_nest, var_index, loopi);
00307        var_index++)
00308     if (loopi->num == var)
00309       break;
00310 
00311   return var_index;
00312 }
00313 
00314 /* In lambda-code.c  */
00315 bool lambda_transform_legal_p (lambda_trans_matrix, int, VEC (ddr_p, heap) *);
00316 
00317 #endif  /* GCC_TREE_DATA_REF_H  */

Generated on Sun Sep 17 18:03:28 2006 for Tree SSA by  doxygen 1.4.6