Mercurial > hg > CbC > CbC_gcc
comparison gcc/df-problems.c @ 63:b7f97abdc517 gcc-4.6-20100522
update gcc from gcc-4.5.0 to gcc-4.6
author | ryoma <e075725@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 24 May 2010 12:47:05 +0900 |
parents | 77e2b8dfacca |
children | f6334be47118 |
comparison
equal
deleted
inserted
replaced
56:3c8a44c06a95 | 63:b7f97abdc517 |
---|---|
1 /* Standard problems for dataflow support routines. | 1 /* Standard problems for dataflow support routines. |
2 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, | 2 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
3 2008, 2009 Free Software Foundation, Inc. | 3 2008, 2009, 2010 Free Software Foundation, Inc. |
4 Originally contributed by Michael P. Hayes | 4 Originally contributed by Michael P. Hayes |
5 (m.hayes@elec.canterbury.ac.nz, mhayes@redhat.com) | 5 (m.hayes@elec.canterbury.ac.nz, mhayes@redhat.com) |
6 Major rewrite contributed by Danny Berlin (dberlin@dberlin.org) | 6 Major rewrite contributed by Danny Berlin (dberlin@dberlin.org) |
7 and Kenneth Zadeck (zadeck@naturalbridge.com). | 7 and Kenneth Zadeck (zadeck@naturalbridge.com). |
8 | 8 |
3401 } | 3401 } |
3402 | 3402 |
3403 return old; | 3403 return old; |
3404 } | 3404 } |
3405 | 3405 |
3406 /* Node of a linked list of uses of dead REGs in debug insns. */ | |
3407 struct dead_debug_use | |
3408 { | |
3409 df_ref use; | |
3410 struct dead_debug_use *next; | |
3411 }; | |
3412 | |
3413 /* Linked list of the above, with a bitmap of the REGs in the | |
3414 list. */ | |
3415 struct dead_debug | |
3416 { | |
3417 struct dead_debug_use *head; | |
3418 bitmap used; | |
3419 bitmap to_rescan; | |
3420 }; | |
3421 | |
3422 /* Initialize DEBUG to an empty list, and clear USED, if given. */ | |
3423 static inline void | |
3424 dead_debug_init (struct dead_debug *debug, bitmap used) | |
3425 { | |
3426 debug->head = NULL; | |
3427 debug->used = used; | |
3428 debug->to_rescan = NULL; | |
3429 if (used) | |
3430 bitmap_clear (used); | |
3431 } | |
3432 | |
3433 /* Reset all debug insns with pending uses. Release the bitmap in it, | |
3434 unless it is USED. USED must be the same bitmap passed to | |
3435 dead_debug_init. */ | |
3436 static inline void | |
3437 dead_debug_finish (struct dead_debug *debug, bitmap used) | |
3438 { | |
3439 struct dead_debug_use *head; | |
3440 rtx insn = NULL; | |
3441 | |
3442 if (debug->used != used) | |
3443 BITMAP_FREE (debug->used); | |
3444 | |
3445 while ((head = debug->head)) | |
3446 { | |
3447 insn = DF_REF_INSN (head->use); | |
3448 if (!head->next || DF_REF_INSN (head->next->use) != insn) | |
3449 { | |
3450 INSN_VAR_LOCATION_LOC (insn) = gen_rtx_UNKNOWN_VAR_LOC (); | |
3451 df_insn_rescan_debug_internal (insn); | |
3452 if (debug->to_rescan) | |
3453 bitmap_clear_bit (debug->to_rescan, INSN_UID (insn)); | |
3454 } | |
3455 debug->head = head->next; | |
3456 XDELETE (head); | |
3457 } | |
3458 | |
3459 if (debug->to_rescan) | |
3460 { | |
3461 bitmap_iterator bi; | |
3462 unsigned int uid; | |
3463 | |
3464 EXECUTE_IF_SET_IN_BITMAP (debug->to_rescan, 0, uid, bi) | |
3465 { | |
3466 struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid); | |
3467 if (insn_info) | |
3468 df_insn_rescan (insn_info->insn); | |
3469 } | |
3470 BITMAP_FREE (debug->to_rescan); | |
3471 } | |
3472 } | |
3473 | |
3474 /* Add USE to DEBUG. It must be a dead reference to UREGNO in a debug | |
3475 insn. Create a bitmap for DEBUG as needed. */ | |
3476 static inline void | |
3477 dead_debug_add (struct dead_debug *debug, df_ref use, unsigned int uregno) | |
3478 { | |
3479 struct dead_debug_use *newddu = XNEW (struct dead_debug_use); | |
3480 | |
3481 newddu->use = use; | |
3482 newddu->next = debug->head; | |
3483 debug->head = newddu; | |
3484 | |
3485 if (!debug->used) | |
3486 debug->used = BITMAP_ALLOC (NULL); | |
3487 | |
3488 bitmap_set_bit (debug->used, uregno); | |
3489 } | |
3490 | |
3491 /* If UREGNO is referenced by any entry in DEBUG, emit a debug insn | |
3492 before INSN that binds the REG to a debug temp, and replace all | |
3493 uses of UREGNO in DEBUG with uses of the debug temp. INSN must be | |
3494 the insn where UREGNO dies. */ | |
3495 static inline void | |
3496 dead_debug_insert_before (struct dead_debug *debug, unsigned int uregno, | |
3497 rtx insn) | |
3498 { | |
3499 struct dead_debug_use **tailp = &debug->head; | |
3500 struct dead_debug_use *cur; | |
3501 struct dead_debug_use *uses = NULL; | |
3502 struct dead_debug_use **usesp = &uses; | |
3503 rtx reg = NULL; | |
3504 rtx dval; | |
3505 rtx bind; | |
3506 | |
3507 if (!debug->used || !bitmap_clear_bit (debug->used, uregno)) | |
3508 return; | |
3509 | |
3510 /* Move all uses of uregno from debug->head to uses, setting mode to | |
3511 the widest referenced mode. */ | |
3512 while ((cur = *tailp)) | |
3513 { | |
3514 if (DF_REF_REGNO (cur->use) == uregno) | |
3515 { | |
3516 *usesp = cur; | |
3517 usesp = &cur->next; | |
3518 *tailp = cur->next; | |
3519 cur->next = NULL; | |
3520 if (!reg | |
3521 || (GET_MODE_BITSIZE (GET_MODE (reg)) | |
3522 < GET_MODE_BITSIZE (GET_MODE (*DF_REF_REAL_LOC (cur->use))))) | |
3523 reg = *DF_REF_REAL_LOC (cur->use); | |
3524 } | |
3525 else | |
3526 tailp = &(*tailp)->next; | |
3527 } | |
3528 | |
3529 gcc_assert (reg); | |
3530 | |
3531 /* Create DEBUG_EXPR (and DEBUG_EXPR_DECL). */ | |
3532 dval = make_debug_expr_from_rtl (reg); | |
3533 | |
3534 /* Emit a debug bind insn before the insn in which reg dies. */ | |
3535 bind = gen_rtx_VAR_LOCATION (GET_MODE (reg), | |
3536 DEBUG_EXPR_TREE_DECL (dval), reg, | |
3537 VAR_INIT_STATUS_INITIALIZED); | |
3538 | |
3539 bind = emit_debug_insn_before (bind, insn); | |
3540 df_insn_rescan (bind); | |
3541 | |
3542 /* Adjust all uses. */ | |
3543 while ((cur = uses)) | |
3544 { | |
3545 if (GET_MODE (*DF_REF_REAL_LOC (cur->use)) == GET_MODE (reg)) | |
3546 *DF_REF_REAL_LOC (cur->use) = dval; | |
3547 else | |
3548 *DF_REF_REAL_LOC (cur->use) | |
3549 = gen_lowpart_SUBREG (GET_MODE (*DF_REF_REAL_LOC (cur->use)), dval); | |
3550 /* ??? Should we simplify subreg of subreg? */ | |
3551 if (debug->to_rescan == NULL) | |
3552 debug->to_rescan = BITMAP_ALLOC (NULL); | |
3553 bitmap_set_bit (debug->to_rescan, INSN_UID (DF_REF_INSN (cur->use))); | |
3554 uses = cur->next; | |
3555 XDELETE (cur); | |
3556 } | |
3557 } | |
3406 | 3558 |
3407 /* Recompute the REG_DEAD and REG_UNUSED notes and compute register | 3559 /* Recompute the REG_DEAD and REG_UNUSED notes and compute register |
3408 info: lifetime, bb, and number of defs and uses for basic block | 3560 info: lifetime, bb, and number of defs and uses for basic block |
3409 BB. The three bitvectors are scratch regs used here. */ | 3561 BB. The three bitvectors are scratch regs used here. */ |
3410 | 3562 |
3414 { | 3566 { |
3415 basic_block bb = BASIC_BLOCK (bb_index); | 3567 basic_block bb = BASIC_BLOCK (bb_index); |
3416 rtx insn; | 3568 rtx insn; |
3417 df_ref *def_rec; | 3569 df_ref *def_rec; |
3418 df_ref *use_rec; | 3570 df_ref *use_rec; |
3571 struct dead_debug debug; | |
3572 | |
3573 dead_debug_init (&debug, NULL); | |
3419 | 3574 |
3420 bitmap_copy (live, df_get_live_out (bb)); | 3575 bitmap_copy (live, df_get_live_out (bb)); |
3421 bitmap_clear (artificial_uses); | 3576 bitmap_clear (artificial_uses); |
3422 | 3577 |
3423 #ifdef REG_DEAD_DEBUGGING | 3578 #ifdef REG_DEAD_DEBUGGING |
3590 #endif | 3745 #endif |
3591 if (!bitmap_bit_p (live, uregno)) | 3746 if (!bitmap_bit_p (live, uregno)) |
3592 { | 3747 { |
3593 if (debug_insn) | 3748 if (debug_insn) |
3594 { | 3749 { |
3595 debug_insn = -1; | 3750 if (debug_insn > 0) |
3751 { | |
3752 dead_debug_add (&debug, use, uregno); | |
3753 continue; | |
3754 } | |
3596 break; | 3755 break; |
3597 } | 3756 } |
3757 else | |
3758 dead_debug_insert_before (&debug, uregno, insn); | |
3598 | 3759 |
3599 if ( (!(DF_REF_FLAGS (use) & DF_REF_MW_HARDREG)) | 3760 if ( (!(DF_REF_FLAGS (use) & DF_REF_MW_HARDREG)) |
3600 && (!bitmap_bit_p (do_not_gen, uregno)) | 3761 && (!bitmap_bit_p (do_not_gen, uregno)) |
3601 && (!bitmap_bit_p (artificial_uses, uregno)) | 3762 && (!bitmap_bit_p (artificial_uses, uregno)) |
3602 && (!(DF_REF_FLAGS (use) & DF_REF_READ_WRITE)) | 3763 && (!(DF_REF_FLAGS (use) & DF_REF_READ_WRITE)) |
3634 registers with their definitions. */ | 3795 registers with their definitions. */ |
3635 INSN_VAR_LOCATION_LOC (insn) = gen_rtx_UNKNOWN_VAR_LOC (); | 3796 INSN_VAR_LOCATION_LOC (insn) = gen_rtx_UNKNOWN_VAR_LOC (); |
3636 df_insn_rescan_debug_internal (insn); | 3797 df_insn_rescan_debug_internal (insn); |
3637 } | 3798 } |
3638 } | 3799 } |
3800 | |
3801 dead_debug_finish (&debug, NULL); | |
3639 } | 3802 } |
3640 | 3803 |
3641 | 3804 |
3642 /* Compute register info: lifetime, bb, and number of defs and uses. */ | 3805 /* Compute register info: lifetime, bb, and number of defs and uses. */ |
3643 static void | 3806 static void |
3743 unsigned int uid = INSN_UID (insn); | 3906 unsigned int uid = INSN_UID (insn); |
3744 | 3907 |
3745 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++) | 3908 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++) |
3746 { | 3909 { |
3747 df_ref def = *def_rec; | 3910 df_ref def = *def_rec; |
3748 /* If the def is to only part of the reg, it does | 3911 bitmap_set_bit (defs, DF_REF_REGNO (def)); |
3749 not kill the other defs that reach here. */ | 3912 } |
3750 if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL))) | 3913 } |
3914 | |
3915 /* Find the set of real DEFs, which are not clobbers, for INSN. */ | |
3916 | |
3917 void | |
3918 df_simulate_find_noclobber_defs (rtx insn, bitmap defs) | |
3919 { | |
3920 df_ref *def_rec; | |
3921 unsigned int uid = INSN_UID (insn); | |
3922 | |
3923 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++) | |
3924 { | |
3925 df_ref def = *def_rec; | |
3926 if (!(DF_REF_FLAGS (def) & (DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER))) | |
3751 bitmap_set_bit (defs, DF_REF_REGNO (def)); | 3927 bitmap_set_bit (defs, DF_REF_REGNO (def)); |
3752 } | 3928 } |
3753 } | 3929 } |
3754 | 3930 |
3755 | 3931 |
3898 bitvector copyied from the DF_LIVE_IN or DF_LR_IN. Then | 4074 bitvector copyied from the DF_LIVE_IN or DF_LR_IN. Then |
3899 df_simulate_one_insn_forwards should be called for each insn in | 4075 df_simulate_one_insn_forwards should be called for each insn in |
3900 the block, starting with the first one. | 4076 the block, starting with the first one. |
3901 ----------------------------------------------------------------------------*/ | 4077 ----------------------------------------------------------------------------*/ |
3902 | 4078 |
3903 /* Apply the artificial uses and defs at the top of BB in a forwards | 4079 /* Initialize the LIVE bitmap, which should be copied from DF_LIVE_IN or |
3904 direction. ??? This is wrong; defs mark the point where a pseudo | 4080 DF_LR_IN for basic block BB, for forward scanning by marking artificial |
3905 becomes live when scanning forwards (unless a def is unused). Since | 4081 defs live. */ |
3906 there are no REG_UNUSED notes for artificial defs, passes that | |
3907 require artificial defs probably should not call this function | |
3908 unless (as is the case for fwprop) they are correct when liveness | |
3909 bitmaps are *under*estimated. */ | |
3910 | 4082 |
3911 void | 4083 void |
3912 df_simulate_initialize_forwards (basic_block bb, bitmap live) | 4084 df_simulate_initialize_forwards (basic_block bb, bitmap live) |
3913 { | 4085 { |
3914 df_ref *def_rec; | 4086 df_ref *def_rec; |
3916 | 4088 |
3917 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++) | 4089 for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++) |
3918 { | 4090 { |
3919 df_ref def = *def_rec; | 4091 df_ref def = *def_rec; |
3920 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP) | 4092 if (DF_REF_FLAGS (def) & DF_REF_AT_TOP) |
3921 bitmap_clear_bit (live, DF_REF_REGNO (def)); | 4093 bitmap_set_bit (live, DF_REF_REGNO (def)); |
3922 } | 4094 } |
3923 } | 4095 } |
3924 | 4096 |
3925 /* Simulate the forwards effects of INSN on the bitmap LIVE. */ | 4097 /* Simulate the forwards effects of INSN on the bitmap LIVE. */ |
3926 | 4098 |
3937 /* Note that this is the opposite as how the problem is defined, because | 4109 /* Note that this is the opposite as how the problem is defined, because |
3938 in the LR problem defs _kill_ liveness. However, they do so backwards, | 4110 in the LR problem defs _kill_ liveness. However, they do so backwards, |
3939 while here the scan is performed forwards! So, first assume that the | 4111 while here the scan is performed forwards! So, first assume that the |
3940 def is live, and if this is not true REG_UNUSED notes will rectify the | 4112 def is live, and if this is not true REG_UNUSED notes will rectify the |
3941 situation. */ | 4113 situation. */ |
3942 df_simulate_find_defs (insn, live); | 4114 df_simulate_find_noclobber_defs (insn, live); |
3943 | 4115 |
3944 /* Clear all of the registers that go dead. */ | 4116 /* Clear all of the registers that go dead. */ |
3945 for (link = REG_NOTES (insn); link; link = XEXP (link, 1)) | 4117 for (link = REG_NOTES (insn); link; link = XEXP (link, 1)) |
3946 { | 4118 { |
3947 switch (REG_NOTE_KIND (link)) | 4119 switch (REG_NOTE_KIND (link)) |