00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00097 #ifndef CTRUMP_ANALYZER_LOOP_H
00098 #define CTRUMP_ANALYZER_LOOP_H
00099
00100 #include "ctrump/analyzer/var.h"
00101 #include "ctrump/analyzer/cfg.h"
00102 #include "ctrump/ast/expr-code.h"
00103
00104 #ifdef __cplusplus
00105 extern "C" {
00106 #endif
00107
00108 struct ctrump_expr;
00109 struct ctrump_stmt;
00110 struct ctrump_var;
00111
00115 enum ctrump_complicated_loop_reason_code {
00116 CTRUMP_COMPLICATED_LOOP_BREAK,
00117 CTRUMP_COMPLICATED_LOOP_GOTO,
00118 CTRUMP_COMPLICATED_LOOP_RETURN,
00119 CTRUMP_COMPLICATED_LOOP_HAVE_COMPLICATED_NEST,
00120 CTRUMP_COMPLICATED_LOOP_INVOKE_FUNC,
00121 CTRUMP_COMPLICATED_LOOP_NEST,
00122 CTRUMP_COMPLICATED_LOOP_HAS_MULTI_ENTRY
00123 };
00124
00128 struct ctrump_complicated_loop {
00129 enum ctrump_complicated_loop_reason_code reason;
00130 struct ctrump_stmt *stmt;
00131 };
00132
00137 struct ctrump_loop_iv {
00138 int iv_level;
00139 int incr;
00141 struct ctrump_var *var;
00142 struct ctrump_pdg_node *reach_at_loop_entry;
00143 };
00144
00148 struct ctrump_loop_pointer_inc {
00149 int iv_level;
00150 int incr;
00152
00153 };
00154
00159 struct ctrump_loop_array {
00160 struct ctrump_var *var;
00161 };
00162
00163
00170 struct ctrump_loop_subscript_constraint {
00171 enum ctrump_expr_code cmp_op;
00172 struct ctrump_expr *lhs;
00173 int rhs_coef;
00174 int rhs_off;
00175 struct ctrump_expr *rhs;
00176 };
00177
00180 enum ctrump_loop_index_code {
00181 CTRUMP_LOOP_INDEX_INDUCTIVE,
00182 CTRUMP_LOOP_INDEX_INVARIANT,
00183 CTRUMP_LOOP_INDEX_POINTER_INC
00184 };
00185
00188 struct ctrump_loop_index {
00189 enum ctrump_loop_index_code code;
00192 #define CTRUMP_LOOP_INDEX_NEGATIVE (1<<0)
00193
00197 int flags;
00198
00199 union {
00200 struct ctrump_loop_iv iv;
00201 struct ctrump_loop_pointer_inc ptrinc;
00202 struct ctrump_var *invariant;
00203 } u;
00204 };
00205
00209 struct ctrump_loop_subscript_record_member {
00210 const struct ctrump_symbol *member_name;
00211 struct ctrump_texpr *record_type;
00212 };
00213
00217 struct ctrump_loop_subscript_record_member_terminal {
00218 const struct ctrump_symbol *member_name;
00219 struct ctrump_texpr *record_type;
00220 struct ctrump_texpr *load_type;
00221 };
00222
00227 struct ctrump_loop_subscript_load_record {
00228 struct ctrump_texpr *load_type;
00229 };
00230
00234 enum ctrump_loop_subscript_code {
00235 CTRUMP_LOOP_SUBSCRIPT_COEF_TERMINAL,
00236 CTRUMP_LOOP_SUBSCRIPT_COEF_ARRAYSIZE,
00237 CTRUMP_LOOP_SUBSCRIPT_COEF_CONSTANT,
00238 CTRUMP_LOOP_SUBSCRIPT_RECORD_MEMBER,
00239 CTRUMP_LOOP_SUBSCRIPT_RECORD_MEMBER_TERMINAL,
00240 CTRUMP_LOOP_SUBSCRIPT_LOAD_RECORD,
00241 CTRUMP_LOOP_SUBSCRIPT_COEF_SCALE
00242 };
00243
00244
00248 struct ctrump_loop_subscript {
00249 int id;
00250 enum ctrump_loop_subscript_code code;
00252
00253
00254
00255
00256
00257
00258
00259
00260 int offset;
00261 int num_index;
00263 struct ctrump_loop_index *indices;
00268 union ctrump_loop_subscript_scale {
00269
00270
00271
00272 struct ctrump_var *scale_array_coef;
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282 int array_size_coef;
00283
00284
00285
00286
00287
00288 struct ctrump_loop_subscript_load_record load_record;
00289 struct ctrump_loop_subscript_record_member record_member;
00290 struct ctrump_loop_subscript_record_member_terminal record_member_terminal;
00291
00292 struct ctrump_texpr *load_type;
00293 } u;
00294 };
00295
00296
00303 CTRUMP_EXTDEF int
00304 ctrump_loop_subscript_equal(const struct ctrump_loop_subscript *s1,
00305 const struct ctrump_loop_subscript *s2);
00306
00313 CTRUMP_EXTDEF int
00314 ctrump_loop_index_equal(const struct ctrump_loop_index *i1,
00315 const struct ctrump_loop_index *i2);
00316
00322 CTRUMP_EXTDEF int
00323 ctrump_loop_subscript_hash(const struct ctrump_loop_subscript *s);
00324
00328 struct ctrump_loop_memory_access {
00329 int id;
00331 int num_subscript;
00332 struct ctrump_loop_subscript *subscripts;
00333 int num_constraint;
00334 struct ctrump_loop_subscript_constraint *constraints;
00336 struct ctrump_loop_array array;
00338 struct ctrump_stmt *at_stmt;
00339 struct ctrump_expr *at_expr;
00340 };
00341
00343 struct ctrump_array_access {
00344 struct ctrump_expr *array;
00346 int num_subscript;
00347 struct ctrump_subscript *subscripts;
00348 };
00349
00351 enum ctrump_random_access_code {
00352 CTRUMP_RANDOM_ACCESS_POINTER_NOT_INDUCTIVE,
00353 CTRUMP_RANDOM_ACCESS_COMPLICATED_POINTER,
00354 CTRUMP_RANDOM_ACCESS_ARRAY_NOT_INVARIANT,
00355 CTRUMP_RANDOM_ACCESS_SUBSCRIPT_NOT_INDUCTIVE,
00356 CTRUMP_RANDOM_ACCESS_COMPLICATED_ARRAY,
00357 CTRUMP_RANDOM_ACCESS_MULTIPLE_SCALED_INDEX,
00358 CTRUMP_RANDOM_ACCESS_COMPLICATED_SUBSCRIPT,
00359 CTRUMP_RANDOM_ACCESS_INDEX_VAR_NOT_INDUCTIVE
00360 };
00361
00367 struct ctrump_random_access_multiple_scaled_index {
00368 struct ctrump_expr *index0;
00369 struct ctrump_expr *index1;
00370 };
00371
00373 struct ctrump_random_access {
00374 enum ctrump_random_access_code code;
00375 struct ctrump_stmt *access_at_stmt;
00376 struct ctrump_expr *access_at_expr;
00378 union {
00379 struct ctrump_array_access arr_not_invariant;
00380 struct ctrump_array_access sub_not_inductive;
00381 struct ctrump_var *index_var_not_inductive;
00382 struct ctrump_array_access complicated_array;
00383 struct ctrump_random_access_multiple_scaled_index multiple_scaled_index;
00384 struct ctrump_expr *complicated_subscript;
00385 }u;
00386 };
00387
00389 enum ctrump_loop_count_code {
00390 CTRUMP_LOOP_COUNT_CONSTANT,
00391 CTRUMP_LOOP_COUNT_PREDICTABLE,
00392 CTRUMP_LOOP_COUNT_UNPREDICTABLE
00393 };
00394
00398 struct ctrump_loop_count_pred_info {
00399 enum ctrump_expr_code cmp_op;
00400 int incr;
00401 struct ctrump_var *inductive;
00402 struct ctrump_pdg_node *iv_loop_entry_value;
00403 struct ctrump_expr *bound;
00404 };
00405
00409 struct ctrump_loop_exit {
00410 enum ctrump_loop_count_code code;
00411 union {
00412 struct ctrump_loop_count_pred_info pred;
00413 int count;
00414 }u;
00415 };
00416
00420 struct ctrump_loop_info {
00421 int id;
00422 int nest_level;
00423
00424 struct ctrump_loop_info_node *root;
00425 };
00426
00427 #include "ctrump/analyzer/deptest.h"
00428
00432 struct ctrump_loop_info_node {
00433 int id;
00434
00435 struct ctrump_location loc;
00436 struct ctrump_loop_depinfo depinfo;
00448 int nest_level;
00449 int dfs_order;
00450 struct ctrump_loop_info_node *parent;
00451 struct ctrump_loop_cfg_info *cfg_info;
00453 int num_var;
00455 ctrump_bitmap_t inductive_var;
00456 ctrump_bitmap_t invariant_var;
00457 ctrump_bitmap_t modified_and_live_after_loop;
00458 ctrump_bitmap_t carry_dep;
00459 ctrump_bitmap_t modify;
00460 ctrump_bitmap_t use;
00462 int num_child;
00463 struct ctrump_loop_info_node **children;
00464 struct ctrump_loop_exit exit_info;
00466 int num_parallel_load;
00467 int num_parallel_store;
00468 int num_random_access;
00469 int num_ordered_loadstore;
00471 struct ctrump_loop_memory_access *parallel_loads;
00472 struct ctrump_loop_memory_access *parallel_stores;
00477 struct ctrump_ordered_memory_load_store_node *ordered_loadstore;
00478
00479 struct ctrump_random_access *random_accesses;
00481 int num_reduc_op;
00482 struct ctrump_loop_reduction *reductions;
00483 };
00484
00488 struct ctrump_loop_reduction {
00489 enum ctrump_reductive_expr_code op;
00490 struct ctrump_var *var;
00491 struct ctrump_stmt *at;
00492 };
00493
00497 enum ctrump_loop_code {
00498 CTRUMP_LOOP_UNANALYZED,
00499 CTRUMP_LOOP_COMPLICATED,
00500 CTRUMP_LOOP,
00501 };
00502
00515 struct ctrump_loop_cfg_info {
00516 int id;
00517 enum ctrump_loop_code code;
00519 struct ctrump_stmt *loop_stmt;
00521 struct ctrump_bb *loop_pred;
00522 struct ctrump_bb *cond_bb;
00523 struct ctrump_bb *body_start_bb;
00524 struct ctrump_bb *break_bb;
00526 struct ctrump_expr *exit_cond;
00527 union {
00528 struct ctrump_complicated_loop complicated;
00529 struct ctrump_loop_info_node *loop_info_node;
00530 } u;
00531 };
00532
00533 struct ctrump_abi;
00539 int ctrump_analyze_loop(struct ctrump_loop_info *dest,
00540 int *level_depth,
00541 struct ctrump_loop_info_node *loop_tree_node,
00542 struct ctrump_cfg *cfg,
00543 struct ctrump_intmap *var_info_map,
00544 const struct ctrump_abi *abi,
00545 struct ctrump_mempool *loop_alloc,
00546 int id);
00547
00548 #ifdef __cplusplus
00549 }
00550 #endif
00551 #endif