Verified Commit 7dfb4686 authored by Camil Staps's avatar Camil Staps
Browse files

Add -pg and -npg options to turn enable/disable callgraph profiling

parent 8c3cfeca
Loading
Loading
Loading
Loading
Loading
+2
Changes for clm.1: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -62,6 +62,8 @@ enable/disable optimizing uniqueness typing. (default: -ou)
enable/disable optimizing by fusion transformation. (default: -nfusion)
.IP -pt\ -npt
enable/disable the generation of code for time profiling. (default: -npt)
.IP -pg\ -npg
enable/disable the generation of code for callgraph profiling. (default: -npg)
.IP -desc
generate all descriptors.
.IP -exl
+44 −9
Changes for clm.c: 44 added lines, 9 removed lines.
Original line number Diff line number Diff line
@@ -164,6 +164,7 @@ extern char *getenv();
#define DEFAULT_STRICTNESS_ANALYSIS 	1
#define DEFAULT_LIST_TYPES				0
#define DEFAULT_LIST_ALL_TYPES			0
#define DEFAULT_CALLGRAPH_PROFILE		0

#define DEBUG_MASK					1
#define NO_REUSE_UNIQUE_NODES_MASK	2
@@ -176,11 +177,14 @@ extern char *getenv();
#define SYSTEM_MASK 				256
#define FUSION_MASK					512
#define A64_MASK					1024
#define DYNAMICS_MASK				2048
#define GENERIC_FUSION_MASK			4096
#define CALLGRAPH_PROFILE_MASK		8192

#define LIST_TYPES_MASK 			2048
#define LIST_ALL_TYPES_MASK 		4096
#define LIST_TYPES_MASK 			16384
#define LIST_ALL_TYPES_MASK 		32768

#define MEMORY_PROFILE				8192
#define MEMORY_PROFILE				65536
 
#define DEFAULT_OPTIONS \
	(DEFAULT_WARNING ? WARNING_MASK : 0)\
@@ -191,7 +195,8 @@ extern char *getenv();
	| (DEFAULT_NO_TIME_PROFILE ? NO_TIME_PROFILE_MASK : 0)\
	| (DEFAULT_STRICTNESS_ANALYSIS ? STRICTNESS_ANALYSIS_MASK : 0)\
	| (DEFAULT_LIST_TYPES ? LIST_TYPES_MASK : 0)\
	| (DEFAULT_LIST_ALL_TYPES ? LIST_ALL_TYPES_MASK : 0)
	| (DEFAULT_LIST_ALL_TYPES ? LIST_ALL_TYPES_MASK : 0)\
	| (DEFAULT_CALLGRAPH_PROFILE ? CALLGRAPH_PROFILE_MASK : 0)

static int clean_options=DEFAULT_OPTIONS;
static int clean_options_mask=0;
@@ -967,7 +972,7 @@ static int get_version_and_options_of_abc_file (P_NODE project_node,int *version
							last_char=getc (abc_file);
						}

						while (digit_n<11 && (last_char & 0xfe)=='0'){
						while (digit_n<14 && (last_char & 0xfe)=='0'){
							options |= ((last_char & 1)<<digit_n);
							last_char=getc (abc_file);
							++digit_n;
@@ -1152,7 +1157,7 @@ static int project_node_is_abc_up_to_date (P_NODE project_node)
			return 0;
		}

		if ((NO_TIME_PROFILE_MASK & (clean_options ^ abc_options))!=0){
		if (((NO_TIME_PROFILE_MASK | CALLGRAPH_PROFILE_MASK) & (clean_options ^ abc_options))!=0){
			if (verbose)
 				warning_s ("(%s.icl is compiled with different time profile options)",project_node->pro_fname);
			close_abc_file();
@@ -1188,13 +1193,14 @@ static int project_node_is_abc_up_to_date (P_NODE project_node)
			return 0;
		}
	} else {
		if ((NO_TIME_PROFILE_MASK & (clean_options ^ abc_options))!=0){
		if (((NO_TIME_PROFILE_MASK | CALLGRAPH_PROFILE_MASK) & (clean_options ^ abc_options))!=0){
			if (verbose)
 				warning_s ("(%s.icl is compiled with different time profile options)",project_node->pro_fname);
			close_abc_file();

			if (comp_options_position>=0){
				FILE *f;
				char c;

				f=fopen (abc_file_name,"r+");
				if (f==NULL)
@@ -1208,11 +1214,25 @@ static int project_node_is_abc_up_to_date (P_NODE project_node)
				else
					fputc ('1',f);

				if (fseek (f,comp_options_position+13,SEEK_SET)!=0)
					error_s ("Could not write to file %s\n",abc_file_name);

				c=fgetc (f);
				if (c=='0' || c=='1'){
					ungetc (c,f);

					if (clean_options & CALLGRAPH_PROFILE_MASK)
						fputc ('1',f);
					else
						fputc ('0',f);
				} else if (clean_options & CALLGRAPH_PROFILE_MASK)
					error_s ("Failed to patch %s for callgraph profiling",abc_file_name);
	
				if (fclose (f)!=0)
					error_s ("Could not write to file %s\n",abc_file_name);
			
				project_node->pro_options &= ~NO_TIME_PROFILE_MASK;
				project_node->pro_options |= clean_options & NO_TIME_PROFILE_MASK;
				project_node->pro_options &= ~(NO_TIME_PROFILE_MASK | CALLGRAPH_PROFILE_MASK);
				project_node->pro_options |= clean_options & (NO_TIME_PROFILE_MASK | CALLGRAPH_PROFILE_MASK);
				project_node->pro_valid_abc_time=0;

				return 1;
@@ -1996,6 +2016,8 @@ static int compile_project_node (P_NODE project_node)
		*arg++="-pm";
	if ((clean_options & NO_TIME_PROFILE_MASK)==0)
		*arg++="-pt";
	if ((clean_options & CALLGRAPH_PROFILE_MASK)!=0)
		*arg++="-pg";
	if ((clean_options & FUSION_MASK)!=0)
		*arg++="-fusion";
	if (dynamics)
@@ -3289,6 +3311,8 @@ static int link_project (P_NODE first_project_node,char *options_file_name,char
		need_file ("_startup",OBJECT_FILE_EXTENSION,start_up_file_name);
	} else if (stack_trace)
		need_file ("_startupTrace",OBJECT_FILE_EXTENSION,start_up_file_name);
	else if ((clean_options & CALLGRAPH_PROFILE_MASK)!=0)
		need_file ("_startupProfileGraph",OBJECT_FILE_EXTENSION,start_up_file_name);
	else
		need_file ("_startupProfile",OBJECT_FILE_EXTENSION,start_up_file_name);
	*arg++=start_up_file_name;
@@ -3521,6 +3545,8 @@ static int link_project (P_NODE first_project_node,char *options_file_name,char
		need_file ("_startup",OBJECT_FILE_EXTENSION,start_up_file_name);
	else if (stack_trace)
		need_file ("_startupTrace",OBJECT_FILE_EXTENSION,start_up_file_name);
	else if ((clean_options & CALLGRAPH_PROFILE_MASK)!=0)
		need_file ("_startupProfileGraph",OBJECT_FILE_EXTENSION,start_up_file_name);
	else
		need_file ("_startupProfile",OBJECT_FILE_EXTENSION,start_up_file_name);
	*arg++=start_up_file_name;
@@ -3777,6 +3803,8 @@ static void argument_error (void)
	printf ("                (default: -nfusion)\n");
	printf ("  -pt -npt      Enable/disable the generation of code for time profiling\n");
	printf ("                (default: -npt)\n");
	printf ("  -pg -npg      Enable/disable the generation of code for callgraph profiling\n");
	printf ("                (default: -npg)\n");
	printf ("  -desc         Generate all descriptors\n");
	printf ("  -exl          Export local labels\n");
	printf ("  -tst          Generate code for stack tracing\n");
@@ -4278,6 +4306,13 @@ int main (int argc,char **argv)
        } else if (!strcmp (s,"npm")){
            option_off (MEMORY_PROFILE);
*/
        } else if (!strcmp (s,"pg")){
            option_on (CALLGRAPH_PROFILE_MASK);
            option_off (NO_TIME_PROFILE_MASK);
			stack_trace=0;
        } else if (!strcmp (s,"npg")){
            option_off (CALLGRAPH_PROFILE_MASK);
            option_on (NO_TIME_PROFILE_MASK);
        } else if (!strcmp (s,"pt")){
            option_off (NO_TIME_PROFILE_MASK);
			stack_trace=0;