[PATCH] D69137: [profile] Do not cache __llvm_profile_get_filename result

Vedant Kumar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 17 14:00:13 PDT 2019


vsk created this revision.
vsk added reviewers: tejohnson, davidxl.
Herald added a project: LLVM.

When the %m filename pattern is used, the filename is unique to each
image, so the cached value is wrong.

It struck me that the full filename isn't something that's recomputed
often, so perhaps it doesn't need to be cached at all.

rdar://55137071


https://reviews.llvm.org/D69137

Files:
  compiler-rt/lib/profile/InstrProfilingFile.c
  compiler-rt/test/profile/Inputs/instrprof-get-filename-dso.c
  compiler-rt/test/profile/instrprof-get-filename-merge-mode.c


Index: compiler-rt/test/profile/instrprof-get-filename-merge-mode.c
===================================================================
--- /dev/null
+++ compiler-rt/test/profile/instrprof-get-filename-merge-mode.c
@@ -0,0 +1,16 @@
+// Test __llvm_profile_get_filename when the on-line merging mode is enabled.
+//
+// RUN: %clang_pgogen -dynamiclib -o %t.dso %p/Inputs/instrprof-get-filename-dso.c
+// RUN: %clang_pgogen -o %t %s %t.dso
+// RUN: env LLVM_PROFILE_FILE="%t-%m.profraw" %run %t
+
+#include <string.h>
+
+const char *__llvm_profile_get_filename(void);
+extern const char *get_filename_from_DSO(void);
+
+int main(int argc, const char *argv[]) {
+  const char *filename1 = __llvm_profile_get_filename();
+  const char *filename2 = get_filename_from_DSO();
+  return strcmp(filename1, filename2) == 0;
+}
Index: compiler-rt/test/profile/Inputs/instrprof-get-filename-dso.c
===================================================================
--- /dev/null
+++ compiler-rt/test/profile/Inputs/instrprof-get-filename-dso.c
@@ -0,0 +1,5 @@
+const char *__llvm_profile_get_filename(void);
+
+const char *get_filename_from_DSO(void) {
+  return __llvm_profile_get_filename();
+}
Index: compiler-rt/lib/profile/InstrProfilingFile.c
===================================================================
--- compiler-rt/lib/profile/InstrProfilingFile.c
+++ compiler-rt/lib/profile/InstrProfilingFile.c
@@ -70,7 +70,6 @@
    * by runtime. */
   unsigned OwnsFilenamePat;
   const char *ProfilePathPrefix;
-  const char *Filename;
   char PidChars[MAX_PID_SIZE];
   char Hostname[COMPILER_RT_MAX_HOSTLEN];
   unsigned NumPids;
@@ -86,7 +85,7 @@
   ProfileNameSpecifier PNS;
 } lprofFilename;
 
-COMPILER_RT_WEAK lprofFilename lprofCurFilename = {0,   0, 0, 0, {0},
+COMPILER_RT_WEAK lprofFilename lprofCurFilename = {0,   0, 0, {0},
                                                    {0}, 0, 0, 0, PNS_unknown};
 
 static int ProfileMergeRequested = 0;
@@ -387,8 +386,6 @@
   /* Clean up cached prefix and filename.  */
   if (lprofCurFilename.ProfilePathPrefix)
     free((void *)lprofCurFilename.ProfilePathPrefix);
-  if (lprofCurFilename.Filename)
-    free((void *)lprofCurFilename.Filename);
 
   if (lprofCurFilename.FilenamePat && lprofCurFilename.OwnsFilenamePat) {
     free((void *)lprofCurFilename.FilenamePat);
@@ -602,9 +599,6 @@
   char *FilenameBuf;
   const char *Filename;
 
-  if (lprofCurFilename.Filename)
-    return lprofCurFilename.Filename;
-
   Length = getCurFilenameLength();
   FilenameBuf = (char *)malloc(Length + 1);
   if (!FilenameBuf) {
@@ -615,7 +609,6 @@
   if (!Filename)
     return "\0";
 
-  lprofCurFilename.Filename = FilenameBuf;
   return FilenameBuf;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69137.225513.patch
Type: text/x-patch
Size: 2702 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191017/9bbcb56b/attachment.bin>


More information about the llvm-commits mailing list