⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reload1.c

📁 gcc库的原代码,对编程有很大帮助.
💻 C
📖 第 1 页 / 共 5 页
字号:
	  something_changed = 1;	}      /* See if anything that happened changes which eliminations are valid.	 For example, on the Sparc, whether or not the frame pointer can	 be eliminated can depend on what registers have been used.  We need	 not check some conditions again (such as flag_omit_frame_pointer)	 since they can't have changed.  */      for (ep = reg_eliminate; ep < &reg_eliminate[NUM_ELIMINABLE_REGS]; ep++)	if ((ep->from == HARD_FRAME_POINTER_REGNUM && FRAME_POINTER_REQUIRED)#ifdef ELIMINABLE_REGS	    || ! CAN_ELIMINATE (ep->from, ep->to)#endif	    )	  ep->can_eliminate = 0;      /* Look for the case where we have discovered that we can't replace	 register A with register B and that means that we will now be	 trying to replace register A with register C.  This means we can	 no longer replace register C with register B and we need to disable	 such an elimination, if it exists.  This occurs often with A == ap,	 B == sp, and C == fp.  */      for (ep = reg_eliminate; ep < &reg_eliminate[NUM_ELIMINABLE_REGS]; ep++)	{	  struct elim_table *op;	  register int new_to = -1;	  if (! ep->can_eliminate && ep->can_eliminate_previous)	    {	      /* Find the current elimination for ep->from, if there is a		 new one.  */	      for (op = reg_eliminate;		   op < &reg_eliminate[NUM_ELIMINABLE_REGS]; op++)		if (op->from == ep->from && op->can_eliminate)		  {		    new_to = op->to;		    break;		  }	      /* See if there is an elimination of NEW_TO -> EP->TO.  If so,		 disable it.  */	      for (op = reg_eliminate;		   op < &reg_eliminate[NUM_ELIMINABLE_REGS]; op++)		if (op->from == new_to && op->to == ep->to)		  op->can_eliminate = 0;	    }	}      /* See if any registers that we thought we could eliminate the previous	 time are no longer eliminable.  If so, something has changed and we	 must spill the register.  Also, recompute the number of eliminable	 registers and see if the frame pointer is needed; it is if there is	 no elimination of the frame pointer that we can perform.  */      frame_pointer_needed = 1;      for (ep = reg_eliminate; ep < &reg_eliminate[NUM_ELIMINABLE_REGS]; ep++)	{	  if (ep->can_eliminate && ep->from == FRAME_POINTER_REGNUM	      && ep->to != HARD_FRAME_POINTER_REGNUM)	    frame_pointer_needed = 0;	  if (! ep->can_eliminate && ep->can_eliminate_previous)	    {	      ep->can_eliminate_previous = 0;	      spill_hard_reg (ep->from, global, dumpfile, 1);	      something_changed = 1;	      num_eliminable--;	    }	}#if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM      /* If we didn't need a frame pointer last time, but we do now, spill	 the hard frame pointer.  */      if (frame_pointer_needed && ! previous_frame_pointer_needed)	{	  spill_hard_reg (HARD_FRAME_POINTER_REGNUM, global, dumpfile, 1);	  something_changed = 1;	}#endif      /* If all needs are met, we win.  */      for (i = 0; i < N_REG_CLASSES; i++)	if (max_needs[i] > 0 || max_groups[i] > 0 || max_nongroups[i] > 0)	  break;      if (i == N_REG_CLASSES && !new_basic_block_needs && ! something_changed)	break;      /* Not all needs are met; must spill some hard regs.  */      /* Put all registers spilled so far back in potential_reload_regs, but	 put them at the front, since we've already spilled most of the	 pseudos in them (we might have left some pseudos unspilled if they	 were in a block that didn't need any spill registers of a conflicting	 class.  We used to try to mark off the need for those registers,	 but doing so properly is very complex and reallocating them is the	 simpler approach.  First, "pack" potential_reload_regs by pushing 	 any nonnegative entries towards the end.  That will leave room 	 for the registers we already spilled.	 Also, undo the marking of the spill registers from the last time	 around in FORBIDDEN_REGS since we will be probably be allocating	 them again below.	 ??? It is theoretically possible that we might end up not using one	 of our previously-spilled registers in this allocation, even though	 they are at the head of the list.  It's not clear what to do about	 this, but it was no better before, when we marked off the needs met	 by the previously-spilled registers.  With the current code, globals	 can be allocated into these registers, but locals cannot.  */      if (n_spills)	{	  for (i = j = FIRST_PSEUDO_REGISTER - 1; i >= 0; i--)	    if (potential_reload_regs[i] != -1)	      potential_reload_regs[j--] = potential_reload_regs[i];	  for (i = 0; i < n_spills; i++)	    {	      potential_reload_regs[i] = spill_regs[i];	      spill_reg_order[spill_regs[i]] = -1;	      CLEAR_HARD_REG_BIT (forbidden_regs, spill_regs[i]);	    }	  n_spills = 0;	}      /* Now find more reload regs to satisfy the remaining need	 Do it by ascending class number, since otherwise a reg	 might be spilled for a big class and might fail to count	 for a smaller class even though it belongs to that class.	 Count spilled regs in `spills', and add entries to	 `spill_regs' and `spill_reg_order'.	 ??? Note there is a problem here.	 When there is a need for a group in a high-numbered class,	 and also need for non-group regs that come from a lower class,	 the non-group regs are chosen first.  If there aren't many regs,	 they might leave no room for a group.	 This was happening on the 386.  To fix it, we added the code	 that calls possible_group_p, so that the lower class won't	 break up the last possible group.	 Really fixing the problem would require changes above	 in counting the regs already spilled, and in choose_reload_regs.	 It might be hard to avoid introducing bugs there.  */      CLEAR_HARD_REG_SET (counted_for_groups);      CLEAR_HARD_REG_SET (counted_for_nongroups);      for (class = 0; class < N_REG_CLASSES; class++)	{	  /* First get the groups of registers.	     If we got single registers first, we might fragment	     possible groups.  */	  while (max_groups[class] > 0)	    {	      /* If any single spilled regs happen to form groups,		 count them now.  Maybe we don't really need		 to spill another group.  */	      count_possible_groups (group_size, group_mode, max_groups,				     class);	      if (max_groups[class] <= 0)		break;	      /* Groups of size 2 (the only groups used on most machines)		 are treated specially.  */	      if (group_size[class] == 2)		{		  /* First, look for a register that will complete a group.  */		  for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)		    {		      int other;		      j = potential_reload_regs[i];		      if (j >= 0 && ! TEST_HARD_REG_BIT (bad_spill_regs, j)			  &&			  ((j > 0 && (other = j - 1, spill_reg_order[other] >= 0)			    && TEST_HARD_REG_BIT (reg_class_contents[class], j)			    && TEST_HARD_REG_BIT (reg_class_contents[class], other)			    && HARD_REGNO_MODE_OK (other, group_mode[class])			    && ! TEST_HARD_REG_BIT (counted_for_nongroups,						    other)			    /* We don't want one part of another group.			       We could get "two groups" that overlap!  */			    && ! TEST_HARD_REG_BIT (counted_for_groups, other))			   ||			   (j < FIRST_PSEUDO_REGISTER - 1			    && (other = j + 1, spill_reg_order[other] >= 0)			    && TEST_HARD_REG_BIT (reg_class_contents[class], j)			    && TEST_HARD_REG_BIT (reg_class_contents[class], other)			    && HARD_REGNO_MODE_OK (j, group_mode[class])			    && ! TEST_HARD_REG_BIT (counted_for_nongroups,						    other)			    && ! TEST_HARD_REG_BIT (counted_for_groups,						    other))))			{			  register enum reg_class *p;			  /* We have found one that will complete a group,			     so count off one group as provided.  */			  max_groups[class]--;			  p = reg_class_superclasses[class];			  while (*p != LIM_REG_CLASSES)			    {			      if (group_size [(int) *p] <= group_size [class])				max_groups[(int) *p]--;			      p++;			    }			  /* Indicate both these regs are part of a group.  */			  SET_HARD_REG_BIT (counted_for_groups, j);			  SET_HARD_REG_BIT (counted_for_groups, other);			  break;			}		    }		  /* We can't complete a group, so start one.  */#ifdef SMALL_REGISTER_CLASSES		  /* Look for a pair neither of which is explicitly used.  */		  if (i == FIRST_PSEUDO_REGISTER)		    for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)		      {			int k;			j = potential_reload_regs[i];			/* Verify that J+1 is a potential reload reg.  */			for (k = 0; k < FIRST_PSEUDO_REGISTER; k++)			  if (potential_reload_regs[k] == j + 1)			    break;			if (j >= 0 && j + 1 < FIRST_PSEUDO_REGISTER			    && k < FIRST_PSEUDO_REGISTER			    && spill_reg_order[j] < 0 && spill_reg_order[j + 1] < 0			    && TEST_HARD_REG_BIT (reg_class_contents[class], j)			    && TEST_HARD_REG_BIT (reg_class_contents[class], j + 1)			    && HARD_REGNO_MODE_OK (j, group_mode[class])			    && ! TEST_HARD_REG_BIT (counted_for_nongroups,						    j + 1)			    && ! TEST_HARD_REG_BIT (bad_spill_regs, j + 1)			    /* Reject J at this stage			       if J+1 was explicitly used.  */			    && ! regs_explicitly_used[j + 1])			  break;		      }#endif		  /* Now try any group at all		     whose registers are not in bad_spill_regs.  */		  if (i == FIRST_PSEUDO_REGISTER)		    for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)		      {			int k;			j = potential_reload_regs[i];			/* Verify that J+1 is a potential reload reg.  */			for (k = 0; k < FIRST_PSEUDO_REGISTER; k++)			  if (potential_reload_regs[k] == j + 1)			    break;			if (j >= 0 && j + 1 < FIRST_PSEUDO_REGISTER			    && k < FIRST_PSEUDO_REGISTER			    && spill_reg_order[j] < 0 && spill_reg_order[j + 1] < 0			    && TEST_HARD_REG_BIT (reg_class_contents[class], j)			    && TEST_HARD_REG_BIT (reg_class_contents[class], j + 1)			    && HARD_REGNO_MODE_OK (j, group_mode[class])			    && ! TEST_HARD_REG_BIT (counted_for_nongroups,						    j + 1)			    && ! TEST_HARD_REG_BIT (bad_spill_regs, j + 1))			  break;		      }		  /* I should be the index in potential_reload_regs		     of the new reload reg we have found.  */		  if (i >= FIRST_PSEUDO_REGISTER)		    {		      /* There are no groups left to spill.  */		      spill_failure (max_groups_insn[class]);		      failure = 1;		      goto failed;		    }		  else		    something_changed		      |= new_spill_reg (i, class, max_needs, NULL_PTR,					global, dumpfile);		}	      else		{		  /* For groups of more than 2 registers,		     look for a sufficient sequence of unspilled registers,		     and spill them all at once.  */		  for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)		    {		      int k;		      j = potential_reload_regs[i];		      if (j >= 0			  && j + group_size[class] <= FIRST_PSEUDO_REGISTER			  && HARD_REGNO_MODE_OK (j, group_mode[class]))			{			  /* Check each reg in the sequence.  */			  for (k = 0; k < group_size[class]; k++)			    if (! (spill_reg_order[j + k] < 0				   && ! TEST_HARD_REG_BIT (bad_spill_regs, j + k)				   && TEST_HARD_REG_BIT (reg_class_contents[class], j + k)))			      break;			  /* We got a full sequence, so spill them all.  */			  if (k == group_size[class])			    {			      register enum reg_class *p;			      for (k = 0; k < group_size[class]; k++)				{				  int idx;				  SET_HARD_REG_BIT (counted_for_groups, j + k);				  for (idx = 0; idx < FIRST_PSEUDO_REGISTER; idx++)				    if (potential_reload_regs[idx] == j + k)				      break;				  something_changed				    |= new_spill_reg (idx, class,						      max_needs, NULL_PTR,						      global, dumpfile);				}			      /* We have found one that will complete a group,				 so count off one group as provided.  */			      max_groups[class]--;			      p = reg_class_superclasses[class];			      while (*p != LIM_REG_CLASSES)				{				  if (group_size [(int) *p]				      <= group_size [class])				    max_groups[(int) *p]--;				  p++;				}			      break;			    }			}		    }		  /* We couldn't find any registers for this reload.		     Avoid going into an infinite loop.  */		  if (i >= FIRST_PSEUDO_REGISTER)		    {		      /* There are no groups left.  */		      spill_failure (max_groups_insn[class]);		      failure = 1;		      goto failed;		    }		}	    }	  /* Now similarly satisfy all need for single registers.  */	  while (max_needs[class] > 0 || max_nongroups[class] > 0)	    {#ifdef SMALL_REGISTER_CLASSES	      /* This should be right for all machines, but only the 386		 is known to need it, so this conditional plays safe.		 ??? For 2.5, try making this unconditional.  */	      /* If we spilled enough regs, but they weren't counted		 against the non-group need, see if we can count them now.		 If so, we can avoid some a

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -