10 #define LLVMJIT_EMIT_H
18 #include <llvm-c/Core.h>
26 static inline LLVMValueRef
27 l_ptr_const(
void *ptr, LLVMTypeRef
type)
29 LLVMValueRef
c = LLVMConstInt(
TypeSizeT, (uintptr_t) ptr,
false);
31 return LLVMConstIntToPtr(
c,
type);
37 static inline LLVMTypeRef
40 return LLVMPointerType(t, 0);
46 static inline LLVMValueRef
49 return LLVMConstInt(LLVMInt8Type(),
i,
false);
55 static inline LLVMValueRef
58 return LLVMConstInt(LLVMInt16Type(),
i,
false);
64 static inline LLVMValueRef
67 return LLVMConstInt(LLVMInt32Type(),
i,
false);
73 static inline LLVMValueRef
74 l_int64_const(int64
i)
76 return LLVMConstInt(LLVMInt64Type(),
i,
false);
82 static inline LLVMValueRef
83 l_sizet_const(
size_t i)
91 static inline LLVMValueRef
100 static inline LLVMValueRef
101 l_pbool_const(
bool i)
109 static inline LLVMValueRef
110 l_load_struct_gep(LLVMBuilderRef
b, LLVMValueRef v,
int32 idx,
const char *
name)
112 LLVMValueRef v_ptr = LLVMBuildStructGEP(
b, v,
idx,
"");
114 return LLVMBuildLoad(
b, v_ptr,
name);
120 static inline LLVMValueRef
121 l_load_gep1(LLVMBuilderRef
b, LLVMValueRef v, LLVMValueRef
idx,
const char *
name)
123 LLVMValueRef v_ptr = LLVMBuildGEP(
b, v, &
idx, 1,
"");
125 return LLVMBuildLoad(
b, v_ptr,
name);
129 static inline LLVMBasicBlockRef l_bb_before_v(LLVMBasicBlockRef r,
const char *
fmt,...)
pg_attribute_printf(2, 3);
135 static inline LLVMBasicBlockRef
136 l_bb_before_v(LLVMBasicBlockRef r, const
char *
fmt,...)
145 return LLVMInsertBasicBlock(r,
buf);
149 static inline LLVMBasicBlockRef l_bb_append_v(LLVMValueRef f,
const char *
fmt,...)
pg_attribute_printf(2, 3);
155 static inline LLVMBasicBlockRef
156 l_bb_append_v(LLVMValueRef f, const
char *
fmt,...)
165 return LLVMAppendBasicBlock(f,
buf);
172 l_callsite_ro(LLVMValueRef f)
174 const char argname[] =
"readonly";
175 LLVMAttributeRef ref;
177 ref = LLVMCreateStringAttribute(LLVMGetGlobalContext(),
182 LLVMAddCallSiteAttribute(f, LLVMAttributeFunctionIndex, ref);
189 l_callsite_alwaysinline(LLVMValueRef f)
191 const char argname[] =
"alwaysinline";
193 LLVMAttributeRef attr;
195 id = LLVMGetEnumAttributeKindForName(argname,
196 sizeof(argname) - 1);
197 attr = LLVMCreateEnumAttribute(LLVMGetGlobalContext(),
id, 0);
198 LLVMAddCallSiteAttribute(f, LLVMAttributeFunctionIndex, attr);
204 static inline LLVMValueRef
205 l_mcxt_switch(LLVMModuleRef mod, LLVMBuilderRef
b, LLVMValueRef nc)
207 const char *cmc =
"CurrentMemoryContext";
211 if (!(
cur = LLVMGetNamedGlobal(mod, cmc)))
213 ret = LLVMBuildLoad(
b,
cur, cmc);
214 LLVMBuildStore(
b, nc,
cur);
222 static inline LLVMValueRef
223 l_funcnullp(LLVMBuilderRef
b, LLVMValueRef v_fcinfo,
size_t argno)
228 v_args = LLVMBuildStructGEP(
b,
232 v_argn = LLVMBuildStructGEP(
b, v_args, argno,
"");
240 static inline LLVMValueRef
241 l_funcvaluep(LLVMBuilderRef
b, LLVMValueRef v_fcinfo,
size_t argno)
246 v_args = LLVMBuildStructGEP(
b,
250 v_argn = LLVMBuildStructGEP(
b, v_args, argno,
"");
258 static inline LLVMValueRef
259 l_funcnull(LLVMBuilderRef
b, LLVMValueRef v_fcinfo,
size_t argno)
261 return LLVMBuildLoad(
b, l_funcnullp(
b, v_fcinfo, argno),
"");
267 static inline LLVMValueRef
268 l_funcvalue(LLVMBuilderRef
b, LLVMValueRef v_fcinfo,
size_t argno)
270 return LLVMBuildLoad(
b, l_funcvaluep(
b, v_fcinfo, argno),
"");
Datum idx(PG_FUNCTION_ARGS)
#define pg_attribute_printf(f, a)
#define FIELDNO_FUNCTIONCALLINFODATA_ARGS
static void const char * fmt
LLVMTypeRef TypeParamBool
LLVMTypeRef StructMemoryContextData
LLVMTypeRef TypeStorageBool
#define FIELDNO_NULLABLE_DATUM_ISNULL
#define FIELDNO_NULLABLE_DATUM_DATUM