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

📄 profile.c

📁 GCC编译器源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
      c[0] = c[1] = c[2] = c[3] = 0;      fwrite (c, sizeof (char), 4 - temp, bb_file);    }  /* Store another delimiter in the .bb file, just to make it easy to find the     end of the file name.  */  __write_long (delimiter, bb_file, 4);}/* Instrument and/or analyze program behavior based on program flow graph.   In either case, this function builds a flow graph for the function being   compiled.  The flow graph is stored in BB_GRAPH.   When FLAG_PROFILE_ARCS is nonzero, this function instruments the arcs in   the flow graph that are needed to reconstruct the dynamic behavior of the   flow graph.   When FLAG_BRANCH_PROBABILITIES is nonzero, this function reads auxiliary   information from a data file containing arc count information from previous   executions of the function being compiled.  In this case, the flow graph is   annotated with actual execution counts, which are later propagated into the   rtl for optimization purposes.   Main entry point of this file.  */voidbranch_prob (f, dump_file)     rtx f;     FILE *dump_file;{  int i, num_blocks;  int dest;  rtx insn;  struct adj_list *arcptr;  int num_arcs, changes, passes;  int total, prob;  int hist_br_prob[20], num_never_executed, num_branches;  /* Set to non-zero if we got bad count information.  */  int bad_counts = 0;  /* start of a function.  */  if (flag_test_coverage)    output_gcov_string (current_function_name, (long) -2);  /* Execute this only if doing arc profiling or branch probabilities.  */  if (! profile_arc_flag && ! flag_branch_probabilities      && ! flag_test_coverage)    abort ();  total_num_times_called++;  /* Create an array label_to_bb of ints of size max_label_num.  */  label_to_bb_size = max_label_num ();  label_to_bb = (int *) oballoc (label_to_bb_size * sizeof (int));  bzero ((char *) label_to_bb, label_to_bb_size * sizeof (int));  /* Scan the insns in the function, count the number of basic blocks     present.  When a code label is passed, set label_to_bb[label] = bb     number.  */  /* The first block found will be block 1, so that function entry can be     block 0.  */  {    register RTX_CODE prev_code = JUMP_INSN;    register RTX_CODE code;    register rtx insn;    register int i;    int block_separator_emitted = 0;    ignore_next_note = 0;    for (insn = NEXT_INSN (f), i = 0; insn; insn = NEXT_INSN (insn))      {	code = GET_CODE (insn);	if (code == BARRIER)	  ;	else if (code == CODE_LABEL)	  /* This label is part of the next block, but we can't increment	     block number yet since there might be multiple labels.  */	  label_to_bb[CODE_LABEL_NUMBER (insn)] = i + 1;	/* We make NOTE_INSN_SETJMP notes into a block of their own, so that	   they can be the target of the fake arc for the setjmp call.	   This avoids creating cycles of fake arcs, which would happen if	   the block after the setjmp call contained a call insn.  */	else if ((prev_code == JUMP_INSN || prev_code == CALL_INSN		  || prev_code == CODE_LABEL || prev_code == BARRIER)		 && (GET_RTX_CLASS (code) == 'i'		     || (code == NOTE			 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_SETJMP)))	  {	    i += 1;	    /* Emit the block separator if it hasn't already been emitted.  */	    if (flag_test_coverage && ! block_separator_emitted)	      {		/* Output a zero to the .bb file to indicate that a new		   block list is starting.  */		__write_long (0, bb_file, 4);	      }	    block_separator_emitted = 0;	  }	/* If flag_test_coverage is true, then we must add an entry to the	   .bb file for every note.  */	else if (code == NOTE && flag_test_coverage)	  {	    /* Must ignore the line number notes that immediately follow the	       end of an inline function to avoid counting it twice.  There	       is a note before the call, and one after the call.  */	    if (NOTE_LINE_NUMBER (insn) == NOTE_REPEATED_LINE_NUMBER)	      ignore_next_note = 1;	    else if (NOTE_LINE_NUMBER (insn) > 0)	      {		if (ignore_next_note)		  ignore_next_note = 0;		else		  {		    /* Emit a block separator here to ensure that a NOTE		       immediately following a JUMP_INSN or CALL_INSN will end		       up in the right basic block list.  */		    if ((prev_code == JUMP_INSN || prev_code == CALL_INSN			 || prev_code == CODE_LABEL || prev_code == BARRIER)			&& ! block_separator_emitted)		      {			/* Output a zero to the .bb file to indicate that			   a new block list is starting.  */			__write_long (0, bb_file, 4);			block_separator_emitted = 1;		      }		    		    /* If this is a new source file, then output the file's		       name to the .bb file.  */		    if (! last_bb_file_name			|| strcmp (NOTE_SOURCE_FILE (insn),				   last_bb_file_name))		      {			if (last_bb_file_name)			  free (last_bb_file_name);			last_bb_file_name			  = xmalloc (strlen (NOTE_SOURCE_FILE (insn)) + 1);			strcpy (last_bb_file_name, NOTE_SOURCE_FILE (insn));			output_gcov_string (NOTE_SOURCE_FILE (insn), (long)-1);		      }		    /* Output the line number to the .bb file.  Must be done		       after the output_bb_profile_data() call, and after the		       file name is written, to ensure that it is correctly		       handled by gcov.  */		    __write_long (NOTE_LINE_NUMBER (insn), bb_file, 4);		  }	      }	  }	if (code != NOTE)	  prev_code = code;	else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_SETJMP)	  prev_code = CALL_INSN;      }    /* Allocate last `normal' entry for bb_graph.  */    /* The last insn was a jump, call, or label.  In that case we have       a block at the end of the function with no insns.  */    if (prev_code == JUMP_INSN || prev_code == CALL_INSN	|| prev_code == CODE_LABEL || prev_code == BARRIER)      {	i++;	/* Emit the block separator if it hasn't already been emitted.  */	if (flag_test_coverage && ! block_separator_emitted)	  {	    /* Output a zero to the .bb file to indicate that a new	       block list is starting.  */	    __write_long (0, bb_file, 4);	  }      }    /* Create another block to stand for EXIT, and make all return insns, and       the last basic block point here.  Add one more to account for block       zero.  */    num_blocks = i + 2;  }  total_num_blocks += num_blocks;  if (dump_file)    fprintf (dump_file, "%d basic blocks\n", num_blocks);  /* If we are only doing test coverage here, then return now.  */  if (! profile_arc_flag && ! flag_branch_probabilities)    return;  /* Create and initialize the arrays that will hold bb_graph     and execution count info.  */  bb_graph = (struct bb_info *) alloca (num_blocks * sizeof (struct bb_info));  bzero ((char *) bb_graph, (sizeof (struct bb_info) * num_blocks));  {    /* Scan the insns again:       - at the entry to each basic block, increment the predecessor count       (and successor of previous block) if it is a fall through entry,       create adj_list entries for this and the previous block       - at each jump insn, increment predecessor/successor counts for       target/source basic blocks, add this insn to pred/succ lists.       This also cannot be broken out as a separate subroutine       because it uses `alloca'.  */    register RTX_CODE prev_code = JUMP_INSN;    register RTX_CODE code;    register rtx insn;    register int i;    int fall_through = 0;    struct adj_list *arcptr;    int dest;    /* Block 0 always falls through to block 1.  */    num_arcs = 0;    arcptr = (struct adj_list *) alloca (sizeof (struct adj_list));    init_arc (arcptr, 0, 1, 0);    arcptr->fall_through = 1;    num_arcs++;    /* Add a fake fall through arc from the last block to block 0, to make the       graph complete.  */    arcptr = (struct adj_list *) alloca (sizeof (struct adj_list));    init_arc (arcptr, num_blocks - 1, 0, 0);    arcptr->fake = 1;    num_arcs++;    /* Exit must be one node of the graph, and all exits from the function       must point there.  When see a return branch, must point the arc to the       exit node.  */    /* Must start scan with second insn in function as above.  */    for (insn = NEXT_INSN (f), i = 0; insn; insn = NEXT_INSN (insn))      {	code = GET_CODE (insn);	if (code == BARRIER)	  fall_through = 0;	else if (code == CODE_LABEL)	  ;	/* We make NOTE_INSN_SETJMP notes into a block of their own, so that	   they can be the target of the fake arc for the setjmp call.	   This avoids creating cycles of fake arcs, which would happen if	   the block after the setjmp call ended with a call.  */	else if ((prev_code == JUMP_INSN || prev_code == CALL_INSN		  || prev_code == CODE_LABEL || prev_code == BARRIER)		 && (GET_RTX_CLASS (code) == 'i'		     || (code == NOTE			 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_SETJMP)))	  {	    /* This is the first insn of the block.  */	    i += 1;	    if (fall_through)	      {		arcptr = (struct adj_list *) alloca (sizeof (struct adj_list));		init_arc (arcptr, i - 1, i, 0);		arcptr->fall_through = 1;		num_arcs++;	      }	    fall_through = 1;	    bb_graph[i].first_insn = insn;	  }	else if (code == NOTE)	  ;	if (code == CALL_INSN)	  {	    /* In the normal case, the call returns, and this is just like	       a branch fall through.  */	    fall_through = 1;	    /* Setjmp may return more times than called, so to make the graph	       solvable, add a fake arc from the function entrance to the	       next block.	       All other functions may return fewer times than called (if	       a descendent call longjmp or exit), so to make the graph	       solvable, add a fake arc to the function exit from the	       current block.	       Distinguish the cases by checking for a SETJUMP note.	       A call_insn can be the last ins of a function, so must check	       to see if next insn actually exists.  */	    arcptr = (struct adj_list *) alloca (sizeof (struct adj_list));	    if (NEXT_INSN (insn)		&& GET_CODE (NEXT_INSN (insn)) == NOTE		&& NOTE_LINE_NUMBER (NEXT_INSN (insn)) == NOTE_INSN_SETJMP)	      init_arc (arcptr, 0, i+1, insn);	    else	      init_arc (arcptr, i, num_blocks-1, insn);	    arcptr->fake = 1;	    num_arcs++;	  }	else if (code == JUMP_INSN)	  {	    rtx tem, pattern = PATTERN (insn);	    rtx tablejump = 0;	    /* If running without optimization, then jump label won't be valid,	       so we must search for the destination label in that case.	       We have to handle tablejumps and returns specially anyways, so	       we don't check the JUMP_LABEL at all here.  */	    if (GET_CODE (pattern) == PARALLEL)	      {		/* This assumes that PARALLEL jumps are tablejump entry		   jumps.  */		/* Make an arc from this jump to the label of the		   jump table.  This will instrument the number of		   times the switch statement is executed.  */		if (GET_CODE (XVECEXP (pattern, 0, 1)) == USE)		  {		    tem = XEXP (XVECEXP (pattern, 0, 1), 0);		    if (GET_CODE (tem) != LABEL_REF)		      abort ();		    dest = label_to_bb[CODE_LABEL_NUMBER (XEXP (tem, 0))];		  }		else if (GET_CODE (XVECEXP (pattern, 0, 0)) == SET			 && SET_DEST (XVECEXP (pattern, 0, 0)) == pc_rtx)		  {		    tem = SET_SRC (XVECEXP (pattern, 0, 0));		    if (GET_CODE (tem) == PLUS			&& GET_CODE (XEXP (tem, 1)) == LABEL_REF)		      {			tem = XEXP (tem, 1);			dest = label_to_bb [CODE_LABEL_NUMBER (XEXP (tem, 0))];		      }		  }		else		  abort ();	      }	    else if (GET_CODE (pattern) == ADDR_VEC		     || GET_CODE (pattern) == ADDR_DIFF_VEC)	      tablejump = pattern;	    else if (GET_CODE (pattern) == RETURN)	      dest = num_blocks - 1;	    else if ((tem = SET_SRC (pattern))		     && GET_CODE (tem) == LABEL_REF)	      dest = label_to_bb[CODE_LABEL_NUMBER (XEXP (tem, 0))];	    else	      {		rtx label_ref;		/* Must be an IF_THEN_ELSE branch.  */		if (GET_CODE (tem) != IF_THEN_ELSE)		  abort ();		if (XEXP (tem, 1) != pc_rtx)		  label_ref = XEXP (tem, 1);		else		  label_ref = XEXP (tem, 2);		dest = label_to_bb[CODE_LABEL_NUMBER (XEXP (label_ref, 0))];	      }	    if (tablejump)	      {		int diff_vec_p = GET_CODE (tablejump) == ADDR_DIFF_VEC;		int len = XVECLEN (tablejump, diff_vec_p);		int k;		for (k = 0; k < len; k++)		  {		    rtx tem = XEXP (XVECEXP (tablejump, diff_vec_p, k), 0);		    dest = label_to_bb[CODE_LABEL_NUMBER (tem)];		    arcptr = (struct adj_list *) alloca (sizeof(struct adj_list));		    init_arc (arcptr, i, dest, insn);		    num_arcs++;		  }	      }	    else	      {		arcptr = (struct adj_list *) alloca (sizeof (struct adj_list));		init_arc (arcptr, i, dest, insn);		num_arcs++;	      }	    /* Determine whether or not this jump will fall through.	       Unconditional jumps and returns are not always followed by	       barriers.  */	    pattern = PATTERN (insn);	    if (GET_CODE (pattern) == PARALLEL		|| GET_CODE (pattern) == RETURN)	      fall_through = 0;	    else if (GET_CODE (pattern) == ADDR_VEC		     || GET_CODE (pattern) == ADDR_DIFF_VEC)	      /* These aren't actually jump insns, but they never fall		 through, so...  */	      fall_through = 0;	    else	      {		if (GET_CODE (pattern) != SET || SET_DEST (pattern) != pc_rtx)		  abort ();		if (GET_CODE (SET_SRC (pattern)) != IF_THEN_ELSE)		  fall_through = 0;	      }	  }	if (code != NOTE)	  prev_code = code;	else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_SETJMP)	  prev_code = CALL_INSN;      }

⌨️ 快捷键说明

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