[llvm-commits] CVS: llvm/runtime/libprofile/BlockProfiling.c CommonProfiling.c FunctionProfiling.c Makefile Profiling.h exported_symbols.lst

Chris Lattner lattner at cs.uiuc.edu
Tue Oct 28 12:58:01 PST 2003


Changes in directory llvm/runtime/libprofile:

BlockProfiling.c added (r1.1)
CommonProfiling.c added (r1.1)
FunctionProfiling.c added (r1.1)
Makefile added (r1.1)
Profiling.h added (r1.1)
exported_symbols.lst added (r1.1)

---
Log message:

Initial checkin of function and block profiling runtime library


---
Diffs of the changes:  (+220 -0)

Index: llvm/runtime/libprofile/BlockProfiling.c
diff -c /dev/null llvm/runtime/libprofile/BlockProfiling.c:1.1
*** /dev/null	Tue Oct 28 12:57:01 2003
--- llvm/runtime/libprofile/BlockProfiling.c	Tue Oct 28 12:56:51 2003
***************
*** 0 ****
--- 1,43 ----
+ /*===-- BlockProfiling.c - Support library for block profiling ------------===*\
+ |*
+ |*                     The LLVM Compiler Infrastructure
+ |*
+ |* This file was developed by the LLVM research group and is distributed under
+ |* the University of Illinois Open Source License. See LICENSE.TXT for details.
+ |* 
+ |*===----------------------------------------------------------------------===*|
+ |* 
+ |* This file implements the call back routines for the block profiling
+ |* instrumentation pass.  This should be used with the -insert-block-profiling
+ |* LLVM pass.
+ |*
+ \*===----------------------------------------------------------------------===*/
+ 
+ #include "Profiling.h"
+ #include <stdlib.h>
+ 
+ static unsigned *ArrayStart;
+ static unsigned NumElements;
+ 
+ /* BlockProfAtExitHandler - When the program exits, just write out the profiling
+  * data.
+  */
+ static void BlockProfAtExitHandler() {
+   /* Note that if this were doing something more intellegent with the
+      instrumentation, that we could do some computation here to expand what we
+      collected into simple block profiles.  Since we directly count each block,
+   */
+   write_profiling_data(Block, ArrayStart, NumElements);
+ }
+ 
+ 
+ /* llvm_start_block_profiling - This is the main entry point of the block
+  * profiling library.  It is responsible for setting up the atexit handler.
+  */
+ void llvm_start_block_profiling(int argc, const char **argv,
+                                 unsigned *arrayStart, unsigned numElements) {
+   save_arguments(argc, argv);
+   ArrayStart = arrayStart;
+   NumElements = numElements;
+   atexit(BlockProfAtExitHandler);
+ }


Index: llvm/runtime/libprofile/CommonProfiling.c
diff -c /dev/null llvm/runtime/libprofile/CommonProfiling.c:1.1
*** /dev/null	Tue Oct 28 12:57:01 2003
--- llvm/runtime/libprofile/CommonProfiling.c	Tue Oct 28 12:56:51 2003
***************
*** 0 ****
--- 1,82 ----
+ /*===-- CommonProfiling.c - Profiling support library support -------------===*\
+ |*
+ |*                     The LLVM Compiler Infrastructure
+ |*
+ |* This file was developed by the LLVM research group and is distributed under
+ |* the University of Illinois Open Source License. See LICENSE.TXT for details.
+ |* 
+ |*===----------------------------------------------------------------------===*|
+ |* 
+ |* This file implements functions used by the various different types of
+ |* profiling implementations.
+ |*
+ \*===----------------------------------------------------------------------===*/
+ 
+ #include "Profiling.h"
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <fcntl.h>
+ #include <stdio.h>
+ #include <string.h>
+ #include <unistd.h>
+ 
+ static int SavedArgc = 0;
+ static const char **SavedArgv = 0;
+ 
+ /* save_arguments - Save argc and argv as passed into the program for the file
+  * we output.
+  */
+ void save_arguments(int argc, const char **argv) {
+   if (SavedArgv) return;  /* This can be called multiple times */
+ 
+   /* FIXME: this should copy the arguments out of argv into a string of our own,
+    * because the program might modify the arguments!
+    */
+   SavedArgc = argc;
+   SavedArgv = argv;
+ }
+ 
+ 
+ 
+ 
+ /* write_profiling_data - Write a raw block of profiling counters out to the
+  * llvmprof.out file.  Note that we allow programs to be instrumented with
+  * multiple different kinds of instrumentation.  For this reason, this function
+  * may be called more than once.
+  */
+ void write_profiling_data(enum ProfilingType PT, unsigned *Start,
+                           unsigned NumElements) {
+   static int OutFile = -1;
+   int PTy;
+   
+   /* If this is the first time this function is called, open the output file for
+    * appending, creating it if it does not already exist.
+    */
+   if (OutFile == -1) {
+     off_t Offset;
+     OutFile = open("llvmprof.out", O_CREAT | O_WRONLY | O_APPEND, 0666);
+     if (OutFile == -1) {
+       perror("LLVM profiling: while opening 'llvmprof.out'");
+       return;
+     }
+ 
+     /* Output the command line arguments to the file. */
+     {
+       const char *Args = "";
+       int PTy = Arguments;
+       int ArgLength = strlen(Args);
+       int Zeros = 0;
+       write(OutFile, &PTy, sizeof(int));
+       write(OutFile, &ArgLength, sizeof(int));
+       write(OutFile, Args, ArgLength);
+       /* Pad out to a multiple of four bytes */
+       if (ArgLength & 3)
+         write(OutFile, &Zeros, 4-(ArgLength&3));
+     }
+   }
+  
+   /* Write out this record! */
+   PTy = PT;
+   write(OutFile, &PTy, sizeof(int));
+   write(OutFile, Start, NumElements*sizeof(unsigned));
+ }


Index: llvm/runtime/libprofile/FunctionProfiling.c
diff -c /dev/null llvm/runtime/libprofile/FunctionProfiling.c:1.1
*** /dev/null	Tue Oct 28 12:57:01 2003
--- llvm/runtime/libprofile/FunctionProfiling.c	Tue Oct 28 12:56:51 2003
***************
*** 0 ****
--- 1,41 ----
+ /*===-- FunctionProfiling.c - Support library for function profiling ------===*\
+ |*
+ |*                     The LLVM Compiler Infrastructure
+ |*
+ |* This file was developed by the LLVM research group and is distributed under
+ |* the University of Illinois Open Source License. See LICENSE.TXT for details.
+ |* 
+ |*===----------------------------------------------------------------------===*|
+ |* 
+ |* This file implements the call back routines for the function profiling
+ |* instrumentation pass.  This should be used with the
+ |* -insert-function-profiling LLVM pass.
+ |*
+ \*===----------------------------------------------------------------------===*/
+ 
+ #include "Profiling.h"
+ #include <stdlib.h>
+ 
+ static unsigned *ArrayStart;
+ static unsigned NumElements;
+ 
+ /* FuncProfAtExitHandler - When the program exits, just write out the profiling
+  * data.
+  */
+ static void FuncProfAtExitHandler() {
+   /* Just write out the data we collected.
+    */
+   write_profiling_data(Function, ArrayStart, NumElements);
+ }
+ 
+ 
+ /* llvm_start_func_profiling - This is the main entry point of the function
+  * profiling library.  It is responsible for setting up the atexit handler.
+  */
+ void llvm_start_func_profiling(int argc, const char **argv,
+                                unsigned *arrayStart, unsigned numElements) {
+   save_arguments(argc, argv);
+   ArrayStart = arrayStart;
+   NumElements = numElements;
+   atexit(FuncProfAtExitHandler);
+ }


Index: llvm/runtime/libprofile/Makefile
diff -c /dev/null llvm/runtime/libprofile/Makefile:1.1
*** /dev/null	Tue Oct 28 12:57:01 2003
--- llvm/runtime/libprofile/Makefile	Tue Oct 28 12:56:51 2003
***************
*** 0 ****
--- 1,17 ----
+ ##===- runtime/libprofile/Makefile -------------------------*- Makefile -*-===##
+ # 
+ #                     The LLVM Compiler Infrastructure
+ #
+ # This file was developed by the LLVM research group and is distributed under
+ # the University of Illinois Open Source License. See LICENSE.TXT for details.
+ # 
+ ##===----------------------------------------------------------------------===##
+ LEVEL = ../..
+ BYTECODE_LIBRARY=1
+ SHARED_LIBRARY=1
+ #DONT_BUILD_RELINKED=1
+ LIBRARYNAME=profile_rt
+ EXPORTED_SYMBOL_FILE = $(SourceDir)/exported_symbols.lst
+ 
+ include $(LEVEL)/Makefile.common
+ 


Index: llvm/runtime/libprofile/Profiling.h
diff -c /dev/null llvm/runtime/libprofile/Profiling.h:1.1
*** /dev/null	Tue Oct 28 12:57:01 2003
--- llvm/runtime/libprofile/Profiling.h	Tue Oct 28 12:56:51 2003
***************
*** 0 ****
--- 1,34 ----
+ /*===-- Profiling.h - Profiling support library support routines --*- C -*-===*\
+ |*
+ |*                     The LLVM Compiler Infrastructure
+ |*
+ |* This file was developed by the LLVM research group and is distributed under
+ |* the University of Illinois Open Source License. See LICENSE.TXT for details.
+ |* 
+ |*===----------------------------------------------------------------------===*|
+ |* 
+ |* This file defines functions shared by the various different profiling
+ |* implementations.
+ |*
+ \*===----------------------------------------------------------------------===*/
+ 
+ #ifndef PROFILING_H
+ #define PROFILING_H
+ 
+ /* save_arguments - Save argc and argv as passed into the program for the file
+  * we output.
+  */
+ void save_arguments(int argc, const char **argv);
+ 
+ enum ProfilingType {
+   Arguments = 1,   /* The command line argument block */
+   Function  = 2,   /* Function profiling information  */
+   Block     = 3,   /* Block profiling information     */
+   Edge      = 4,   /* Edge profiling information      */
+   Path      = 5    /* Path profiling information      */
+ };
+ 
+ void write_profiling_data(enum ProfilingType PT, unsigned *Start,
+                           unsigned NumElements);
+ 
+ #endif


Index: llvm/runtime/libprofile/exported_symbols.lst
diff -c /dev/null llvm/runtime/libprofile/exported_symbols.lst:1.1
*** /dev/null	Tue Oct 28 12:57:01 2003
--- llvm/runtime/libprofile/exported_symbols.lst	Tue Oct 28 12:56:51 2003
***************
*** 0 ****
--- 1,3 ----
+ 
+ llvm_start_func_profiling
+ llvm_start_block_profiling





More information about the llvm-commits mailing list