[pkg-d-commits] [ldc] 135/149: Fix LLVM 5.0 build and update profile-rt (#2039)

Matthias Klumpp mak at moszumanska.debian.org
Sun Apr 23 22:37:06 UTC 2017


This is an automated email from the git hooks/post-receive script.

mak pushed a commit to annotated tag v1.2.0
in repository ldc.

commit e21634e19d4d02460460ef55717193ff66d3fc01
Author: Johan Engelen <jbc.engelen at gmail.com>
Date:   Sat Mar 18 20:58:10 2017 +0100

    Fix LLVM 5.0 build and update profile-rt (#2039)
    
    * Update profile-rt (LLVM 5.0)
    
    * Fix LLVM 5.0 compile.
    
    "less-precise-fpmad" is now always set to "false".
---
 gen/functions.cpp                                  | 11 +++++++-
 runtime/profile-rt/profile-rt-50/InstrProfData.inc | 17 ++++++++++++-
 .../profile-rt/profile-rt-50/InstrProfilingFile.c  |  9 +++++++
 .../profile-rt/profile-rt-50/InstrProfilingUtil.c  | 23 +++++++++++++++++
 .../profile-rt/profile-rt-50/InstrProfilingUtil.h  |  8 ++++++
 .../profile-rt/profile-rt-50/InstrProfilingValue.c | 29 ++++++++++++++++++++++
 6 files changed, 95 insertions(+), 2 deletions(-)

diff --git a/gen/functions.cpp b/gen/functions.cpp
index bb1fe29..e2235e2 100644
--- a/gen/functions.cpp
+++ b/gen/functions.cpp
@@ -446,8 +446,17 @@ void applyTargetMachineAttributes(llvm::Function &func,
 
   // Floating point settings
   func.addFnAttr("unsafe-fp-math", TO.UnsafeFPMath ? "true" : "false");
+  const bool lessPreciseFPMADOption =
+#if LDC_LLVM_VER >= 500
+      // This option was removed from llvm::TargetOptions in LLVM 5.0.
+      // Clang sets this to true when `-cl-mad-enable` is passed (OpenCL only).
+      // TODO: implement interface for this option.
+      false;
+#else
+      TO.LessPreciseFPMADOption;
+#endif
   func.addFnAttr("less-precise-fpmad",
-                 TO.LessPreciseFPMADOption ? "true" : "false");
+                 lessPreciseFPMADOption ? "true" : "false");
   func.addFnAttr("no-infs-fp-math", TO.NoInfsFPMath ? "true" : "false");
   func.addFnAttr("no-nans-fp-math", TO.NoNaNsFPMath ? "true" : "false");
 #if LDC_LLVM_VER < 307
diff --git a/runtime/profile-rt/profile-rt-50/InstrProfData.inc b/runtime/profile-rt/profile-rt-50/InstrProfData.inc
index f7c22d1..6ef1625 100644
--- a/runtime/profile-rt/profile-rt-50/InstrProfData.inc
+++ b/runtime/profile-rt/profile-rt-50/InstrProfData.inc
@@ -153,7 +153,17 @@ INSTR_PROF_RAW_HEADER(uint64_t, ValueKindLast, IPVK_Last)
 VALUE_PROF_FUNC_PARAM(uint64_t, TargetValue, Type::getInt64Ty(Ctx)) \
                       INSTR_PROF_COMMA
 VALUE_PROF_FUNC_PARAM(void *, Data, Type::getInt8PtrTy(Ctx)) INSTR_PROF_COMMA
+#ifndef VALUE_RANGE_PROF
 VALUE_PROF_FUNC_PARAM(uint32_t, CounterIndex, Type::getInt32Ty(Ctx))
+#else /* VALUE_RANGE_PROF */
+VALUE_PROF_FUNC_PARAM(uint32_t, CounterIndex, Type::getInt32Ty(Ctx)) \
+                      INSTR_PROF_COMMA
+VALUE_PROF_FUNC_PARAM(uint64_t, PreciseRangeStart, Type::getInt64Ty(Ctx)) \
+                      INSTR_PROF_COMMA
+VALUE_PROF_FUNC_PARAM(uint64_t, PreciseRangeLast, Type::getInt64Ty(Ctx)) \
+                      INSTR_PROF_COMMA
+VALUE_PROF_FUNC_PARAM(uint64_t, LargeValue, Type::getInt64Ty(Ctx))
+#endif /*VALUE_RANGE_PROF */
 #undef VALUE_PROF_FUNC_PARAM
 #undef INSTR_PROF_COMMA
 /* VALUE_PROF_FUNC_PARAM end */
@@ -174,13 +184,15 @@ VALUE_PROF_FUNC_PARAM(uint32_t, CounterIndex, Type::getInt32Ty(Ctx))
  * name hash and the function address.
  */
 VALUE_PROF_KIND(IPVK_IndirectCallTarget, 0)
+/* For memory intrinsic functions size profiling. */
+VALUE_PROF_KIND(IPVK_MemOPSize, 1)
 /* These two kinds must be the last to be
  * declared. This is to make sure the string
  * array created with the template can be
  * indexed with the kind value.
  */
 VALUE_PROF_KIND(IPVK_First, IPVK_IndirectCallTarget)
-VALUE_PROF_KIND(IPVK_Last, IPVK_IndirectCallTarget)
+VALUE_PROF_KIND(IPVK_Last, IPVK_MemOPSize)
 
 #undef VALUE_PROF_KIND
 /* VALUE_PROF_KIND end */
@@ -649,6 +661,9 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
 #define INSTR_PROF_VALUE_PROF_FUNC __llvm_profile_instrument_target
 #define INSTR_PROF_VALUE_PROF_FUNC_STR \
         INSTR_PROF_QUOTE(INSTR_PROF_VALUE_PROF_FUNC)
+#define INSTR_PROF_VALUE_RANGE_PROF_FUNC __llvm_profile_instrument_range
+#define INSTR_PROF_VALUE_RANGE_PROF_FUNC_STR \
+        INSTR_PROF_QUOTE(INSTR_PROF_VALUE_RANGE_PROF_FUNC)
 
 /* InstrProfile per-function control data alignment.  */
 #define INSTR_PROF_DATA_ALIGNMENT 8
diff --git a/runtime/profile-rt/profile-rt-50/InstrProfilingFile.c b/runtime/profile-rt/profile-rt-50/InstrProfilingFile.c
index cd3590e..dfcbe52 100644
--- a/runtime/profile-rt/profile-rt-50/InstrProfilingFile.c
+++ b/runtime/profile-rt/profile-rt-50/InstrProfilingFile.c
@@ -530,6 +530,7 @@ int __llvm_profile_write_file(void) {
   int rc, Length;
   const char *Filename;
   char *FilenameBuf;
+  int PDeathSig = 0;
 
   if (lprofProfileDumped()) {
     PROF_NOTE("Profile data not written to file: %s.\n", 
@@ -556,10 +557,18 @@ int __llvm_profile_write_file(void) {
     return -1;
   }
 
+  // Temporarily suspend getting SIGKILL when the parent exits.
+  PDeathSig = lprofSuspendSigKill();
+
   /* Write profile data to the file. */
   rc = writeFile(Filename);
   if (rc)
     PROF_ERR("Failed to write file \"%s\": %s\n", Filename, strerror(errno));
+
+  // Restore SIGKILL.
+  if (PDeathSig == 1)
+    lprofRestoreSigKill();
+
   return rc;
 }
 
diff --git a/runtime/profile-rt/profile-rt-50/InstrProfilingUtil.c b/runtime/profile-rt/profile-rt-50/InstrProfilingUtil.c
index 321c719..fb68f30 100644
--- a/runtime/profile-rt/profile-rt-50/InstrProfilingUtil.c
+++ b/runtime/profile-rt/profile-rt-50/InstrProfilingUtil.c
@@ -29,6 +29,11 @@
 #include <stdlib.h>
 #include <string.h>
 
+#if defined(__linux__)
+#include <signal.h>
+#include <sys/prctl.h>
+#endif
+
 COMPILER_RT_VISIBILITY
 void __llvm_profile_recursive_mkdir(char *path) {
   int i;
@@ -219,3 +224,21 @@ COMPILER_RT_VISIBILITY const char *lprofFindLastDirSeparator(const char *Path) {
 #endif
   return Sep;
 }
+
+COMPILER_RT_VISIBILITY int lprofSuspendSigKill() {
+#if defined(__linux__)
+  int PDeachSig = 0;
+  /* Temporarily suspend getting SIGKILL upon exit of the parent process. */
+  if (prctl(PR_GET_PDEATHSIG, &PDeachSig) == 0 && PDeachSig == SIGKILL)
+    prctl(PR_SET_PDEATHSIG, 0);
+  return (PDeachSig == SIGKILL);
+#else
+  return 0;
+#endif
+}
+
+COMPILER_RT_VISIBILITY void lprofRestoreSigKill() {
+#if defined(__linux__)
+  prctl(PR_SET_PDEATHSIG, SIGKILL);
+#endif
+}
diff --git a/runtime/profile-rt/profile-rt-50/InstrProfilingUtil.h b/runtime/profile-rt/profile-rt-50/InstrProfilingUtil.h
index a80fde7..9698599 100644
--- a/runtime/profile-rt/profile-rt-50/InstrProfilingUtil.h
+++ b/runtime/profile-rt/profile-rt-50/InstrProfilingUtil.h
@@ -51,4 +51,12 @@ int lprofGetHostName(char *Name, int Len);
 unsigned lprofBoolCmpXchg(void **Ptr, void *OldV, void *NewV);
 void *lprofPtrFetchAdd(void **Mem, long ByteIncr);
 
+/* Temporarily suspend SIGKILL. Return value of 1 means a restore is needed.
+ * Other return values mean no restore is needed.
+ */
+int lprofSuspendSigKill();
+
+/* Restore previously suspended SIGKILL. */
+void lprofRestoreSigKill();
+
 #endif /* PROFILE_INSTRPROFILINGUTIL_H */
diff --git a/runtime/profile-rt/profile-rt-50/InstrProfilingValue.c b/runtime/profile-rt/profile-rt-50/InstrProfilingValue.c
index 6648f89..44263da 100644
--- a/runtime/profile-rt/profile-rt-50/InstrProfilingValue.c
+++ b/runtime/profile-rt/profile-rt-50/InstrProfilingValue.c
@@ -220,6 +220,35 @@ __llvm_profile_instrument_target(uint64_t TargetValue, void *Data,
 }
 
 /*
+ * The target values are partitioned into multiple regions/ranges. There is one
+ * contiguous region which is precise -- every value in the range is tracked
+ * individually. A value outside the precise region will be collapsed into one
+ * value depending on the region it falls in.
+ *
+ * There are three regions:
+ * 1. (-inf, PreciseRangeStart) and (PreciseRangeLast, LargeRangeValue) belong
+ * to one region -- all values here should be mapped to one value of
+ * "PreciseRangeLast + 1".
+ * 2. [PreciseRangeStart, PreciseRangeLast]
+ * 3. Large values: [LargeValue, +inf) maps to one value of LargeValue.
+ *
+ * The range for large values is optional. The default value of INT64_MIN
+ * indicates it is not specified.
+ */
+COMPILER_RT_VISIBILITY void __llvm_profile_instrument_range(
+    uint64_t TargetValue, void *Data, uint32_t CounterIndex,
+    int64_t PreciseRangeStart, int64_t PreciseRangeLast, int64_t LargeValue) {
+
+  if (LargeValue != INT64_MIN && (int64_t)TargetValue >= LargeValue)
+    TargetValue = LargeValue;
+  else if ((int64_t)TargetValue < PreciseRangeStart ||
+           (int64_t)TargetValue > PreciseRangeLast)
+    TargetValue = PreciseRangeLast + 1;
+
+  __llvm_profile_instrument_target(TargetValue, Data, CounterIndex);
+}
+
+/*
  * A wrapper struct that represents value profile runtime data.
  * Like InstrProfRecord class which is used by profiling host tools,
  * ValueProfRuntimeRecord also implements the abstract intefaces defined in

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-d/ldc.git



More information about the pkg-d-commits mailing list