Skip to content

Commit 31bc604

Browse files
committed
Add file containing extensions of the LLVM C API.
Author: Andres Freund Discussion: https://postgr.es/m/20170901064131.tazjxwus3k2w3ybh@alap3.anarazel.de
1 parent 432bb9e commit 31bc604

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

src/backend/jit/llvm/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ override COMPILER = $(CXX) $(CFLAGS)
3737
OBJS=$(WIN32RES)
3838

3939
# Infrastructure
40-
OBJS += llvmjit.o llvmjit_error.o
40+
OBJS += llvmjit.o llvmjit_error.o llvmjit_wrap.o
4141
# Code generation
4242
OBJS +=
4343

src/backend/jit/llvm/llvmjit_wrap.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* llvmjit_wrap.cpp
4+
* Parts of the LLVM interface not (yet) exposed to C.
5+
*
6+
* Copyright (c) 2016-2018, PostgreSQL Global Development Group
7+
*
8+
* IDENTIFICATION
9+
* src/backend/lib/llvm/llvmjit_wrap.c
10+
*
11+
*-------------------------------------------------------------------------
12+
*/
13+
14+
extern "C"
15+
{
16+
#include "postgres.h"
17+
}
18+
19+
#include <llvm/MC/SubtargetFeature.h>
20+
#include <llvm/Support/Host.h>
21+
22+
#include "jit/llvmjit.h"
23+
24+
25+
/*
26+
* C-API extensions.
27+
*/
28+
#if defined(HAVE_DECL_LLVMGETHOSTCPUNAME) && !HAVE_DECL_LLVMGETHOSTCPUNAME
29+
char *LLVMGetHostCPUName(void) {
30+
return strdup(llvm::sys::getHostCPUName().data());
31+
}
32+
#endif
33+
34+
35+
char *LLVMGetHostCPUFeatures(void) {
36+
llvm::SubtargetFeatures Features;
37+
llvm::StringMap<bool> HostFeatures;
38+
39+
if (llvm::sys::getHostCPUFeatures(HostFeatures))
40+
for (auto &F : HostFeatures)
41+
Features.AddFeature(F.first(), F.second);
42+
43+
return strdup(Features.getString().c_str());
44+
}

src/include/jit/llvmjit.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,23 @@ extern void llvm_assert_in_fatal_section(void);
4444

4545
extern LLVMJitContext *llvm_create_context(int jitFlags);
4646

47+
48+
/*
49+
****************************************************************************
50+
* Extensions / Backward compatibility section of the LLVM C API
51+
* Error handling related functions.
52+
****************************************************************************
53+
*/
54+
#if defined(HAVE_DECL_LLVMGETHOSTCPUNAME) && !HAVE_DECL_LLVMGETHOSTCPUNAME
55+
/** Get the host CPU as a string. The result needs to be disposed with
56+
LLVMDisposeMessage. */
57+
extern char *LLVMGetHostCPUName(void);
58+
#endif
59+
60+
/** Get the host CPU features as a string. The result needs to be disposed
61+
with LLVMDisposeMessage. */
62+
extern char *LLVMGetHostCPUFeatures(void);
63+
4764
#ifdef __cplusplus
4865
} /* extern "C" */
4966
#endif

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy