dmitry-chirkov-dremio commented on code in PR #55506:
URL: https://github.com/apache/arrow/pull/55506#discussion_r4558631022


##########
cpp/src/gandiva/engine.cc:
##########
@@ -117,9 +117,44 @@
 
 namespace gandiva {
 
+// Oldest macOS release for each architecture. Used as a floor and as the 
fallback when
+// the Darwin kernel version is missing or can't be converted.
+constexpr unsigned kMinMacOSMajorArm64 = 11;  // first Apple Silicon release
+constexpr unsigned kMinMacOSMinorArm64 = 0;
+constexpr unsigned kMinMacOSMajorX86 = 10;
+constexpr unsigned kMinMacOSMinorX86 = 15;
+
 extern const unsigned char kPrecompiledBitcode[];
 extern const size_t kPrecompiledBitcodeSize;
 
+llvm::Triple NormalizeDarwinTriple(llvm::Triple triple) {
+  // LLVM's default host triple names the OS "darwin<kernel version>", but 
LLVM only
+  // enables macOS libcalls (e.g. __exp10 for llvm.exp10) for the "macosx" OS.
+  // clang's driver does this rewrite; the JIT does not, so do it here.
+  if (triple.getOS() != llvm::Triple::Darwin) {
+    return triple;
+  }
+
+  const llvm::VersionTuple min_version =
+      triple.isAArch64() ? llvm::VersionTuple(kMinMacOSMajorArm64, 
kMinMacOSMinorArm64)
+                         : llvm::VersionTuple(kMinMacOSMajorX86, 
kMinMacOSMinorX86);
+
+  // Only "at least macOS 10.9" matters for libcall selection, so an 
approximate
+  // kernel->macOS mapping is acceptable here.
+  llvm::VersionTuple version = min_version;
+  llvm::VersionTuple converted;
+  if (triple.getMacOSXVersion(converted) && converted >= min_version) {
+    version = converted;
+  }
+
+  // getMacOSXVersion() leaves the minor unset for darwin20+; print it as 
"11.0", not
+  // "11".
+  const unsigned minor = version.getMinor().value_or(0);

Review Comment:
   getMinor() returns llvm::Optional on LLVM 14, which has no value_or(). CMake 
still accepts those versions, and this function compiles on every platform. 
Let's use the portable form.
   
   ```c++
   const auto minor = version.getMinor();
   const unsigned minor_value = minor ? *minor : 0;
   ```



##########
cpp/src/gandiva/tests/decimal_test.cc:
##########
@@ -43,6 +43,23 @@ class TestDecimal : public ::testing::Test {
                                             int32_t scale);
 
  protected:
+  // Compiles round(float64, int32) through the Gandiva JIT and evaluates it 
on the

Review Comment:
   nit: One of my favorite things to do is test-only first commit that fails 
the CI however here I still don't know what runs on pull requests before the 
green light from the overseer 



##########
cpp/src/gandiva/engine.cc:
##########
@@ -117,9 +117,44 @@
 
 namespace gandiva {
 
+// Oldest macOS release for each architecture. Used as a floor and as the 
fallback when
+// the Darwin kernel version is missing or can't be converted.
+constexpr unsigned kMinMacOSMajorArm64 = 11;  // first Apple Silicon release
+constexpr unsigned kMinMacOSMinorArm64 = 0;
+constexpr unsigned kMinMacOSMajorX86 = 10;
+constexpr unsigned kMinMacOSMinorX86 = 15;
+
 extern const unsigned char kPrecompiledBitcode[];
 extern const size_t kPrecompiledBitcodeSize;
 
+llvm::Triple NormalizeDarwinTriple(llvm::Triple triple) {
+  // LLVM's default host triple names the OS "darwin<kernel version>", but 
LLVM only
+  // enables macOS libcalls (e.g. __exp10 for llvm.exp10) for the "macosx" OS.
+  // clang's driver does this rewrite; the JIT does not, so do it here.
+  if (triple.getOS() != llvm::Triple::Darwin) {
+    return triple;
+  }
+
+  const llvm::VersionTuple min_version =
+      triple.isAArch64() ? llvm::VersionTuple(kMinMacOSMajorArm64, 
kMinMacOSMinorArm64)
+                         : llvm::VersionTuple(kMinMacOSMajorX86, 
kMinMacOSMinorX86);
+
+  // Only "at least macOS 10.9" matters for libcall selection, so an 
approximate
+  // kernel->macOS mapping is acceptable here.
+  llvm::VersionTuple version = min_version;
+  llvm::VersionTuple converted;
+  if (triple.getMacOSXVersion(converted) && converted >= min_version) {

Review Comment:
   This conversion can advertise a newer macOS than the machine actually runs. 
With LLVM 21.1.8, darwin27.2.0 converts to macosx28.0 on my macOS 27.2.1 
machine. Although that enables exp10, the target version affects other libcall 
availability decisions too. Could we instead take the macOS OS/version 
component from Gandiva’s embedded bitcode target triple, after validating its 
platform and architecture? Clang already records that target. I tested that 
approach with LLVM 21.1.8, and it fixes the reported cases without the 
approximate kernel-version conversion.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to