--- utils/clflags.ml.orig Thu May 15 09:30:31 1997 +++ utils/clflags.ml Thu Jun 25 00:07:14 1998 @@ -24,6 +24,7 @@ and print_types = ref false (* -i *) and make_archive = ref false (* -a *) and debug = ref false (* -g *) +and profile = ref false (* -p *) and fast = ref false (* -unsafe *) and link_everything = ref false (* -linkall *) and custom_runtime = ref false (* -custom *) --- driver/optmain.ml.orig Tue Nov 18 12:14:54 1997 +++ driver/optmain.ml Thu Jun 25 00:12:55 1998 @@ -81,6 +81,8 @@ " Set output file name to (default a.out)"; "-output-obj", Arg.Unit(fun () -> output_c_object := true), "Output a C object file instead of an executable"; + "-p", Arg.Set profile, + "Make a profiled binary"; "-pp", Arg.String(fun s -> preprocessor := Some s), " Pipe sources through preprocessor "; "-S", Arg.Set keep_asm_file, " Keep intermediate assembly file"; --- asmcomp/i386/emit.mlp.orig Fri Nov 14 06:02:04 1997 +++ asmcomp/i386/emit.mlp Thu Jun 25 01:21:04 1998 @@ -28,6 +28,8 @@ let stack_offset = ref 0 +let profile_lbl = ref 0 + (* Layout of the stack frame *) let frame_size () = (* includes return address *) @@ -64,6 +66,9 @@ let emit_label lbl = emit_string label_prefix; emit_int lbl +let emit_profile_label () = + emit_string label_prefix; emit_string "P"; emit_int !profile_lbl + (* Some data directives have different names under Solaris *) let word_dir = @@ -725,6 +730,22 @@ emit_align 4; ` .globl {emit_symbol fundecl.fun_name}\n`; `{emit_symbol fundecl.fun_name}:\n`; + if !Clflags.profile then + begin + ` pushl %ebp;\n`; + ` movl %esp, %ebp\n`; + `.data\n`; + emit_align 4; + `{emit_profile_label ()}:\n`; + ` .long 0\n`; + `.text\n`; + ` pushl %edx\n`; + ` movl ${emit_profile_label ()},%edx\n`; + ` call mcount\n`; + ` popl %edx\n`; + ` popl %ebp\n`; + incr profile_lbl; + end; let n = frame_size() - 4 in if n > 0 then ` subl ${emit_int n}, %esp\n`; @@ -772,6 +793,7 @@ (* Beginning / end of an assembly file *) let begin_assembly() = + profile_lbl:=0; let lbl_begin = Compilenv.current_unit_name() ^ "_data_begin" in ` .data\n`; ` .globl {emit_symbol lbl_begin}\n`; --- asmcomp/asmlink.ml.orig Wed Jul 2 14:14:34 1997 +++ asmcomp/asmlink.ml Thu Jun 25 15:16:19 1998 @@ -171,7 +171,9 @@ close_out oc let call_linker file_list startup_file = - let libname = "libasmrun" ^ ext_lib in + let libname = + (if !Clflags.profile then "libasmprun" + else "libasmrun") ^ ext_lib in let runtime_lib = try find_in_path !load_path libname @@ -181,11 +183,12 @@ match Config.system with "win32" -> if not !Clflags.output_c_object then - Printf.sprintf "%s /Fe%s -I%s %s %s %s %s %s %s" + Printf.sprintf "%s /Fe%s -I%s %s %s %s %s %s %s %s" Config.native_c_compiler !Clflags.exec_name Config.standard_library (String.concat " " (List.rev !Clflags.ccopts)) + (if !Clflags.profile then "-pg" else "") startup_file (String.concat " " (List.rev file_list)) (String.concat " " (List.rev !Clflags.ccobjs)) @@ -199,11 +202,12 @@ (String.concat " " (List.rev file_list)) | _ -> if not !Clflags.output_c_object then - Printf.sprintf "%s -o %s -I%s %s %s %s -L%s %s %s %s" + Printf.sprintf "%s -o %s -I%s %s %s %s %s -L%s %s %s %s" Config.native_c_compiler !Clflags.exec_name Config.standard_library (String.concat " " (List.rev !Clflags.ccopts)) + (if !Clflags.profile then "-pg" else "") startup_file (String.concat " " (List.rev file_list)) Config.standard_library --- asmrun/Makefile.orig Mon Nov 17 05:38:16 1997 +++ asmrun/Makefile Fri Jul 17 18:50:03 1998 @@ -4,6 +4,9 @@ FLAGS=-I../byterun -DNATIVE_CODE -DTARGET_$(ARCH) -DSYS_$(SYSTEM) CFLAGS=$(FLAGS) -O $(NATIVECCCOMPOPTS) DFLAGS=$(FLAGS) -g -DDEBUG $(NATIVECCCOMPOPTS) +PFLAGS=$(FLAGS) -pg $(NATIVECCCOMPOPTS) + +ASPPPFLAGS=$(ASPPFLAGS) -DPROFILE COBJS=startup.o main.o fail.o roots.o signals.o \ misc.o freelist.o major_gc.o minor_gc.o memory.o alloc.o compare.o ints.o \ @@ -15,22 +18,28 @@ OBJS=$(COBJS) $(ASMOBJS) DOBJS=$(COBJS:.o=.d.o) $(ASMOBJS) +POBJS=$(COBJS:.o=.p.o) $(ARCH).p.o -all: libasmrun.a +all: libasmrun.a libasmprun.a libasmrun.a: $(OBJS) rm -f libasmrun.a ar rc libasmrun.a $(OBJS) $(RANLIB) libasmrun.a +libasmprun.a: $(POBJS) + rm -f libasmprun.a + ar rc libasmprun.a $(POBJS) + $(RANLIB) libasmprun.a + libasmrund.a: $(DOBJS) rm -f libasmrund.a ar rc libasmrund.a $(DOBJS) $(RANLIB) libasmrund.a install: - cp libasmrun.a $(LIBDIR) - cd $(LIBDIR); $(RANLIB) libasmrun.a + cp libasmrun.a libasmprun.a $(LIBDIR) + cd $(LIBDIR); $(RANLIB) libasmrun.a; $(RANLIB) libasmprun.a power.o: power-$(SYSTEM).o cp power-$(SYSTEM).o power.o @@ -98,16 +107,22 @@ clean:: rm -f $(LINKEDFILES) -.SUFFIXES: .S .d.o +.SUFFIXES: .S .d.o .p.o .S.o: $(ASPP) $(ASPPFLAGS) -o $*.o $*.S +.S.p.o: + $(ASPP) $(ASPPPFLAGS) -o $*.p.o $*.S + .c.d.o: @ if test -f $*.o; then mv $*.o $*.f.o; else :; fi $(CC) -c $(DFLAGS) $< mv $*.o $*.d.o @ if test -f $*.f.o; then mv $*.f.o $*.o; else :; fi + +.c.p.o: + $(CC) -c $(PFLAGS) -o $*.p.o $*.c clean:: rm -f *.o *.s *.a *~ --- asmrun/i386.S.orig Fri Jul 17 18:35:12 1998 +++ asmrun/i386.S Fri Jul 17 18:46:41 1998 @@ -41,7 +41,20 @@ leal 4(%esp), %eax movl %eax, G(caml_bottom_of_stack) /* Build array of registers, save it into caml_gc_regs */ -L105: pushl %ebp +.L105: + pushl %ebp +#ifdef PROFILE + movl %esp,%ebp +.data + .align 4 +.LP0: + .long 0 +.text + pushl %edx + movl $.LP0,%edx + call mcount + popl %edx +#endif /* PROFILE */ pushl %edi pushl %esi pushl %edx @@ -64,58 +77,114 @@ .align FUNCTION_ALIGN G(caml_alloc1): +#ifdef PROFILE + pushl %ebp + movl %esp,%ebp +.data + .align 4 +.LP1: + .long 0 +.text + pushl %edx + movl $.LP1,%edx + call mcount + popl %edx + popl %ebp +#endif /* PROFILE */ movl G(young_ptr), %eax subl $8, %eax movl %eax, G(young_ptr) cmpl G(young_limit), %eax - jb L100 + jb .L100 ret -L100: movl 0(%esp), %eax +.L100: movl 0(%esp), %eax movl %eax, G(caml_last_return_address) leal 4(%esp), %eax movl %eax, G(caml_bottom_of_stack) - call L105 + call .L105 jmp G(caml_alloc1) .align FUNCTION_ALIGN G(caml_alloc2): +#ifdef PROFILE + pushl %ebp + movl %esp,%ebp +.data + .align 4 +.LP2: + .long 0 +.text + pushl %edx + movl $.LP2,%edx + call mcount + popl %edx + popl %ebp +#endif /* PROFILE */ movl G(young_ptr), %eax subl $12, %eax movl %eax, G(young_ptr) cmpl G(young_limit), %eax - jb L101 + jb .L101 ret -L101: movl 0(%esp), %eax +.L101: movl 0(%esp), %eax movl %eax, G(caml_last_return_address) leal 4(%esp), %eax movl %eax, G(caml_bottom_of_stack) - call L105 + call .L105 jmp G(caml_alloc2) .align FUNCTION_ALIGN G(caml_alloc3): +#ifdef PROFILE + pushl %ebp + movl %esp,%ebp +.data + .align 4 +.LP3: + .long 0 +.text + pushl %edx + movl $.LP3,%edx + call mcount + popl %edx + popl %ebp +#endif /* PROFILE */ movl G(young_ptr), %eax subl $16, %eax movl %eax, G(young_ptr) cmpl G(young_limit), %eax - jb L102 + jb .L102 ret -L102: movl 0(%esp), %eax +.L102: movl 0(%esp), %eax movl %eax, G(caml_last_return_address) leal 4(%esp), %eax movl %eax, G(caml_bottom_of_stack) - call L105 + call .L105 jmp G(caml_alloc3) .align FUNCTION_ALIGN G(caml_alloc): +#ifdef PROFILE + pushl %ebp + movl %esp,%ebp +.data + .align 4 +.LP4: + .long 0 +.text + pushl %edx + movl $.LP4,%edx + call mcount + popl %edx + popl %ebp +#endif /* PROFILE */ subl G(young_ptr), %eax /* eax = size - young_ptr */ negl %eax /* eax = young_ptr - size */ cmpl G(young_limit), %eax - jb L103 + jb .L103 movl %eax, G(young_ptr) ret -L103: subl G(young_ptr), %eax /* eax = - size */ +.L103: subl G(young_ptr), %eax /* eax = - size */ negl %eax /* eax = size */ pushl %eax /* save desired size */ subl %eax, G(young_ptr) /* must update young_ptr */ @@ -123,7 +192,7 @@ movl %eax, G(caml_last_return_address) leal 8(%esp), %eax movl %eax, G(caml_bottom_of_stack) - call L105 + call .L105 popl %eax /* recover desired size */ jmp G(caml_alloc) @@ -132,6 +201,20 @@ .globl G(caml_c_call) .align FUNCTION_ALIGN G(caml_c_call): +#ifdef PROFILE + pushl %ebp + movl %esp,%ebp +.data + .align 4 +.LP5: + .long 0 +.text + pushl %edx + movl $.LP5,%edx + call mcount + popl %edx + popl %ebp +#endif /* PROFILE */ /* Record lowest stack address and return address */ movl (%esp), %edx movl %edx, G(caml_last_return_address) @@ -145,6 +228,20 @@ .globl G(caml_start_program) .align FUNCTION_ALIGN G(caml_start_program): +#ifdef PROFILE + pushl %ebp + movl %esp,%ebp +.data + .align 4 +.LP6: + .long 0 +.text + pushl %edx + movl $.LP6,%edx + call mcount + popl %edx + popl %ebp +#endif /* PROFILE */ /* Save callee-save registers */ pushl %ebx pushl %esi @@ -153,18 +250,18 @@ /* Initial entry point is caml_program */ movl $ G(caml_program), %esi /* Common code for caml_start_program and callback* */ -L106: +.L106: /* Build a callback link */ pushl G(caml_gc_regs) pushl G(caml_last_return_address) pushl G(caml_bottom_of_stack) /* Build an exception handler */ - pushl $L108 + pushl $.L108 pushl G(caml_exception_pointer) movl %esp, G(caml_exception_pointer) /* Call the Caml code */ call *%esi -L107: +.L107: /* Pop the exception handler */ popl G(caml_exception_pointer) popl %esi /* dummy register */ @@ -179,7 +276,7 @@ popl %ebx /* Return to caller. */ ret -L108: +.L108: /* Exception handler*/ /* Pop the callback link, restoring the global variables */ popl G(caml_bottom_of_stack) @@ -195,6 +292,20 @@ .globl G(raise_caml_exception) .align FUNCTION_ALIGN G(raise_caml_exception): +#ifdef PROFILE + pushl %ebp + movl %esp,%ebp +.data + .align 4 +.LP7: + .long 0 +.text + pushl %edx + movl $.LP7,%edx + call mcount + popl %edx + popl %ebp +#endif /* PROFILE */ movl 4(%esp), %eax movl G(caml_exception_pointer), %esp popl G(caml_exception_pointer) @@ -205,6 +316,20 @@ .globl G(callback) .align FUNCTION_ALIGN G(callback): +#ifdef PROFILE + pushl %ebp + movl %esp,%ebp +.data + .align 4 +.LP8: + .long 0 +.text + pushl %edx + movl $.LP8,%edx + call mcount + popl %edx + popl %ebp +#endif /* PROFILE */ /* Save callee-save registers */ pushl %ebx pushl %esi @@ -214,11 +339,25 @@ movl 20(%esp), %ebx /* closure */ movl 24(%esp), %eax /* argument */ movl 0(%ebx), %esi /* code pointer */ - jmp L106 + jmp .L106 .globl G(callback2) .align FUNCTION_ALIGN G(callback2): +#ifdef PROFILE + pushl %ebp + movl %esp,%ebp +.data + .align 4 +.LP9: + .long 0 +.text + pushl %edx + movl $.LP9,%edx + call mcount + popl %edx + popl %ebp +#endif /* PROFILE */ /* Save callee-save registers */ pushl %ebx pushl %esi @@ -229,11 +368,25 @@ movl 24(%esp), %eax /* first argument */ movl 28(%esp), %ebx /* second argument */ movl $ G(caml_apply2), %esi /* code pointer */ - jmp L106 + jmp .L106 .globl G(callback3) .align FUNCTION_ALIGN G(callback3): +#ifdef PROFILE + pushl %ebp + movl %esp,%ebp +.data + .align 4 +.LP10: + .long 0 +.text + pushl %edx + movl $.LP10,%edx + call mcount + popl %edx + popl %ebp +#endif /* PROFILE */ /* Save callee-save registers */ pushl %ebx pushl %esi @@ -245,13 +398,13 @@ movl 28(%esp), %ebx /* second argument */ movl 32(%esp), %ecx /* third argument */ movl $ G(caml_apply3), %esi /* code pointer */ - jmp L106 + jmp .L106 .data .globl G(system_frametable) G(system_frametable): .long 1 /* one descriptor */ - .long L107 /* return address into callback */ + .long .L107 /* return address into callback */ #ifndef SYS_solaris .word -1 /* negative frame size => use callback link */ .word 0 /* no roots here */