[compiler-rt] r276355 - [Profile] deprecate __llvm_profile_override_default_filename (part2)
Xinliang David Li via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 21 16:19:18 PDT 2016
Author: davidxl
Date: Thu Jul 21 18:19:18 2016
New Revision: 276355
URL: http://llvm.org/viewvc/llvm-project?rev=276355&view=rev
Log:
[Profile] deprecate __llvm_profile_override_default_filename (part2)
This eliminates unncessary calls and init functions.
Differential Revision: http://reviews.llvm.org/D22614
Modified:
compiler-rt/trunk/lib/profile/InstrProfData.inc
compiler-rt/trunk/lib/profile/InstrProfiling.c
compiler-rt/trunk/lib/profile/InstrProfiling.h
compiler-rt/trunk/lib/profile/InstrProfilingFile.c
compiler-rt/trunk/test/profile/instrprof-override-filename-then-reset-default.c
compiler-rt/trunk/test/profile/instrprof-override-filename-with-env.c
compiler-rt/trunk/test/profile/instrprof-override-filename.c
Modified: compiler-rt/trunk/lib/profile/InstrProfData.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfData.inc?rev=276355&r1=276354&r2=276355&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfData.inc (original)
+++ compiler-rt/trunk/lib/profile/InstrProfData.inc Thu Jul 21 18:19:18 2016
@@ -605,6 +605,10 @@ serializeValueProfDataFrom(ValueProfReco
#define VARIANT_MASK_IR_PROF (0x1ULL << 56)
#define IR_LEVEL_PROF_VERSION_VAR __llvm_profile_raw_version
+/* The variable that holds the name of the profile data
+ * specified via command line. */
+#define INSTR_PROF_PROFILE_NAME_VAR __llvm_profile_filename
+
/* Runtime section names and name strings. */
#define INSTR_PROF_DATA_SECT_NAME __llvm_prf_data
#define INSTR_PROF_NAME_SECT_NAME __llvm_prf_names
Modified: compiler-rt/trunk/lib/profile/InstrProfiling.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfiling.c?rev=276355&r1=276354&r2=276355&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfiling.c (original)
+++ compiler-rt/trunk/lib/profile/InstrProfiling.c Thu Jul 21 18:19:18 2016
@@ -20,6 +20,8 @@ COMPILER_RT_VISIBILITY char *(*GetEnvHoo
COMPILER_RT_WEAK uint64_t __llvm_profile_raw_version = INSTR_PROF_RAW_VERSION;
+COMPILER_RT_WEAK char INSTR_PROF_PROFILE_NAME_VAR[1] = {0};
+
COMPILER_RT_VISIBILITY uint64_t __llvm_profile_get_magic(void) {
return sizeof(void *) == sizeof(uint64_t) ? (INSTR_PROF_RAW_MAGIC_64)
: (INSTR_PROF_RAW_MAGIC_32);
Modified: compiler-rt/trunk/lib/profile/InstrProfiling.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfiling.h?rev=276355&r1=276354&r2=276355&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfiling.h (original)
+++ compiler-rt/trunk/lib/profile/InstrProfiling.h Thu Jul 21 18:19:18 2016
@@ -112,9 +112,8 @@ void INSTR_PROF_VALUE_PROF_FUNC(
* Writes to the file with the last name given to \a *
* __llvm_profile_set_filename(),
* or if it hasn't been called, the \c LLVM_PROFILE_FILE environment variable,
- * or if that's not set, the last name given to
- * \a __llvm_profile_override_default_filename(), or if that's not set,
- * \c "default.profraw".
+ * or if that's not set, the last name set to INSTR_PROF_PROFILE_NAME_VAR,
+ * or if that's not set, \c "default.profraw".
*/
int __llvm_profile_write_file(void);
@@ -129,19 +128,6 @@ int __llvm_profile_write_file(void);
*/
void __llvm_profile_set_filename(const char *Name);
-/*!
- * \brief Set the filename for writing instrumentation data, unless the
- * \c LLVM_PROFILE_FILE environment variable was set.
- *
- * Unless overridden, sets the filename to be used for subsequent calls to
- * \a __llvm_profile_write_file().
- *
- * \c Name is not copied, so it must remain valid. Passing NULL resets the
- * filename logic to the default behaviour (unless the \c LLVM_PROFILE_FILE
- * was set in which case it has no effect).
- */
-void __llvm_profile_override_default_filename(const char *Name);
-
/*! \brief Register to write instrumentation data to file at exit. */
int __llvm_profile_register_write_file_atexit(void);
@@ -191,4 +177,11 @@ COMPILER_RT_VISIBILITY extern int __llvm
*/
extern uint64_t __llvm_profile_raw_version;
+/*!
+ * This variable is a weak symbol defined in InstrProfiling.c. It allows
+ * compiler instrumentation to provide overriding definition with value
+ * from compiler command line. This variable has default visibility.
+ */
+extern char INSTR_PROF_PROFILE_NAME_VAR[1]; /* __llvm_profile_filename. */
+
#endif /* PROFILE_INSTRPROFILING_H_ */
Modified: compiler-rt/trunk/lib/profile/InstrProfilingFile.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingFile.c?rev=276355&r1=276354&r2=276355&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfilingFile.c (original)
+++ compiler-rt/trunk/lib/profile/InstrProfilingFile.c Thu Jul 21 18:19:18 2016
@@ -330,12 +330,6 @@ static void parseAndSetFilename(const ch
if (!FilenamePat)
FilenamePat = DefaultProfileName;
- /* When -fprofile-instr-generate=<path> is specified on the
- * command line, each module will be instrumented with runtime
- * init call to __llvm_profile_init function which calls
- * __llvm_profile_override_default_filename. In most of the cases,
- * the path will be identical, so bypass the parsing completely.
- */
if (OldFilenamePat && !strcmp(OldFilenamePat, FilenamePat)) {
lprofCurFilename.PNS = PNS;
return;
@@ -472,10 +466,24 @@ const char *__llvm_profile_get_path_pref
* environment variable can override this default value. */
COMPILER_RT_VISIBILITY
void __llvm_profile_initialize_file(void) {
- const char *FilenamePat;
+ const char *EnvFilenamePat;
+ const char *SelectedPat = NULL;
+ ProfileNameSpecifier PNS = PNS_unknown;
+ int hasCommandLineOverrider = (INSTR_PROF_PROFILE_NAME_VAR[0] != 0);
+
+ EnvFilenamePat = getFilenamePatFromEnv();
+ if (EnvFilenamePat) {
+ SelectedPat = EnvFilenamePat;
+ PNS = PNS_environment;
+ } else if (hasCommandLineOverrider) {
+ SelectedPat = INSTR_PROF_PROFILE_NAME_VAR;
+ PNS = PNS_command_line;
+ } else {
+ SelectedPat = NULL;
+ PNS = PNS_default;
+ }
- FilenamePat = getFilenamePatFromEnv();
- parseAndSetFilename(FilenamePat, FilenamePat ? PNS_environment : PNS_default);
+ parseAndSetFilename(SelectedPat, PNS);
}
/* This API is directly called by the user application code. It has the
@@ -487,17 +495,6 @@ void __llvm_profile_set_filename(const c
parseAndSetFilename(FilenamePat, PNS_runtime_api);
}
-/*
- * This API is invoked by the global initializers emitted by Clang/LLVM when
- * -fprofile-instr-generate=<..> is specified (vs -fprofile-instr-generate
- * without an argument). This option has lower precedence than the
- * LLVM_PROFILE_FILE environment variable.
- */
-COMPILER_RT_VISIBILITY
-void __llvm_profile_override_default_filename(const char *FilenamePat) {
- parseAndSetFilename(FilenamePat, PNS_command_line);
-}
-
/* The public API for writing profile data into the file with name
* set by previous calls to __llvm_profile_set_filename or
* __llvm_profile_override_default_filename or
Modified: compiler-rt/trunk/test/profile/instrprof-override-filename-then-reset-default.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/profile/instrprof-override-filename-then-reset-default.c?rev=276355&r1=276354&r2=276355&view=diff
==============================================================================
--- compiler-rt/trunk/test/profile/instrprof-override-filename-then-reset-default.c (original)
+++ compiler-rt/trunk/test/profile/instrprof-override-filename-then-reset-default.c Thu Jul 21 18:19:18 2016
@@ -7,13 +7,13 @@
// RUN: %clang_profuse=%t.d/default.profdata -o - -S -emit-llvm %s | FileCheck %s
-void __llvm_profile_override_default_filename(const char *);
+void __llvm_profile_set_filename(const char *);
int main(int argc, const char *argv[]) {
// CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof ![[PD1:[0-9]+]]
if (argc < 2)
return 1;
- __llvm_profile_override_default_filename(argv[1]);
- __llvm_profile_override_default_filename(0);
+ __llvm_profile_set_filename(argv[1]);
+ __llvm_profile_set_filename(0);
return 0;
}
// CHECK: ![[PD1]] = !{!"branch_weights", i32 1, i32 2}
Modified: compiler-rt/trunk/test/profile/instrprof-override-filename-with-env.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/profile/instrprof-override-filename-with-env.c?rev=276355&r1=276354&r2=276355&view=diff
==============================================================================
--- compiler-rt/trunk/test/profile/instrprof-override-filename-with-env.c (original)
+++ compiler-rt/trunk/test/profile/instrprof-override-filename-with-env.c Thu Jul 21 18:19:18 2016
@@ -1,14 +1,14 @@
-// RUN: %clang_profgen -o %t -O3 %s
+// RUN: %clang_profgen=%t.bad.profraw -o %t -O3 %s
// RUN: env LLVM_PROFILE_FILE=%t.good.profraw %run %t %t.bad.profraw
// RUN: llvm-profdata merge -o %t.profdata %t.good.profraw
// RUN: %clang_profuse=%t.profdata -o - -S -emit-llvm %s | FileCheck %s
-void __llvm_profile_override_default_filename(const char *);
+void bar () {}
int main(int argc, const char *argv[]) {
// CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof ![[PD1:[0-9]+]]
if (argc < 2)
return 1;
- __llvm_profile_override_default_filename(argv[1]);
+ bar();
return 0;
}
// CHECK: ![[PD1]] = !{!"branch_weights", i32 1, i32 2}
Modified: compiler-rt/trunk/test/profile/instrprof-override-filename.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/profile/instrprof-override-filename.c?rev=276355&r1=276354&r2=276355&view=diff
==============================================================================
--- compiler-rt/trunk/test/profile/instrprof-override-filename.c (original)
+++ compiler-rt/trunk/test/profile/instrprof-override-filename.c Thu Jul 21 18:19:18 2016
@@ -1,14 +1,14 @@
-// RUN: %clang_profgen -o %t -O3 %s
+// RUN: %clang_profgen=%t.profraw -o %t -O3 %s
// RUN: %run %t %t.profraw
// RUN: llvm-profdata merge -o %t.profdata %t.profraw
// RUN: %clang_profuse=%t.profdata -o - -S -emit-llvm %s | FileCheck %s
-void __llvm_profile_override_default_filename(const char *);
+void bar() {}
int main(int argc, const char *argv[]) {
// CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof ![[PD1:[0-9]+]]
if (argc < 2)
return 1;
- __llvm_profile_override_default_filename(argv[1]);
+ bar();
return 0;
}
// CHECK: ![[PD1]] = !{!"branch_weights", i32 1, i32 2}
More information about the llvm-commits
mailing list