LLVMJIT: Add file containing extensions / polyfills of the LLVM C API.
authorAndres Freund <[email protected]>
Mon, 29 Jan 2018 08:07:47 +0000 (00:07 -0800)
committerAndres Freund <[email protected]>
Wed, 21 Mar 2018 02:34:24 +0000 (19:34 -0700)
Author: Andres Freund
Discussion: https://postgr.es/m/20170901064131[email protected]

src/backend/jit/llvm/Makefile
src/backend/jit/llvm/llvmjit_wrap.cpp [new file with mode: 0644]
src/include/jit/llvmjit.h

index 7d78460cc608e5839a68fb43b88062c6f52267a7..a2093798658869004ea3e028c01d021f859c35a3 100644 (file)
@@ -37,7 +37,7 @@ override COMPILER = $(CXX) $(CFLAGS)
 OBJS=$(WIN32RES)
 
 # Infrastructure
-OBJS += llvmjit.o llvmjit_error.o
+OBJS += llvmjit.o llvmjit_error.o llvmjit_wrap.o
 # Code generation
 OBJS +=
 
diff --git a/src/backend/jit/llvm/llvmjit_wrap.cpp b/src/backend/jit/llvm/llvmjit_wrap.cpp
new file mode 100644 (file)
index 0000000..efbdd06
--- /dev/null
@@ -0,0 +1,44 @@
+/*-------------------------------------------------------------------------
+ *
+ * llvmjit_wrap.cpp
+ *   Parts of the LLVM interface not (yet) exposed to C.
+ *
+ * Copyright (c) 2016-2018, PostgreSQL Global Development Group
+ *
+ * IDENTIFICATION
+ *   src/backend/lib/llvmjit_wrap.c
+ *
+ *-------------------------------------------------------------------------
+ */
+
+extern "C"
+{
+#include "postgres.h"
+}
+
+#include <llvm/MC/SubtargetFeature.h>
+#include <llvm/Support/Host.h>
+
+#include "jit/llvmjit.h"
+
+
+/*
+ * C-API extensions.
+ */
+#if defined(HAVE_DECL_LLVMGETHOSTCPUNAME) && !HAVE_LLVMGETHOSTCPUNAME
+char *LLVMGetHostCPUName(void) {
+   return strdup(llvm::sys::getHostCPUName().data());
+}
+#endif
+
+
+char *LLVMGetHostCPUFeatures(void) {
+   llvm::SubtargetFeatures Features;
+   llvm::StringMap<bool> HostFeatures;
+
+   if (llvm::sys::getHostCPUFeatures(HostFeatures))
+       for (auto &F : HostFeatures)
+           Features.AddFeature(F.first(), F.second);
+
+   return strdup(Features.getString().c_str());
+}
index 187ebe2c2a02c3ff4fa964397fc3a5ef09bf32e6..18ba7fd5745f008ab6b91d8366474b2fc8d7291e 100644 (file)
@@ -44,6 +44,23 @@ extern void llvm_assert_in_fatal_section(void);
 
 extern LLVMJitContext *llvm_create_context(int jitFlags);
 
+
+/*
+ ****************************************************************************
+ * Extensions / Backward compatibility section of the LLVM C API
+ * Error handling related functions.
+ ****************************************************************************
+ */
+#if defined(HAVE_DECL_LLVMGETHOSTCPUNAME) && !HAVE_LLVMGETHOSTCPUNAME
+/** Get the host CPU as a string. The result needs to be disposed with
+  LLVMDisposeMessage. */
+char      *LLVMGetHostCPUName(void);
+#endif
+
+/** Get the host CPU features as a string. The result needs to be disposed
+  with LLVMDisposeMessage. */
+extern char *LLVMGetHostCPUFeatures(void);
+
 #ifdef __cplusplus
 } /* extern "C" */
 #endif