Add file containing extensions of the LLVM C API.
authorAndres Freund <andres@anarazel.de>
Thu, 22 Mar 2018 02:44:17 +0000 (19:44 -0700)
committerAndres Freund <andres@anarazel.de>
Thu, 22 Mar 2018 02:44:17 +0000 (19:44 -0700)
Author: Andres Freund
Discussion: https://postgr.es/m/20170901064131.tazjxwus3k2w3ybh@alap3.anarazel.de

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

index 856b94e12b4631a5306560f1888f3b0a2902a014..4b58a3450f3be568e5cdfb7a80d2fb3964a3c293 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..5d1a17c
--- /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/llvm/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_DECL_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..63b2fdfe5910403a801fa06948b14b4c67b8f81a 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_DECL_LLVMGETHOSTCPUNAME
+/** Get the host CPU as a string. The result needs to be disposed with
+  LLVMDisposeMessage. */
+extern 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