Skip to content

Commit

Permalink
[mono][llvm] More LLVM 14.x changes. (#69239)
Browse files Browse the repository at this point in the history
* Add a type to the 'sret' parameter attribute.
* Add helper functions for creating pointer types and pointer casts.
  • Loading branch information
vargaz committed May 14, 2022
1 parent 0aa3930 commit af2a48d
Show file tree
Hide file tree
Showing 3 changed files with 262 additions and 164 deletions.
47 changes: 47 additions & 0 deletions src/mono/mono/mini/mini-llvm-cpp.cpp
Expand Up @@ -497,6 +497,25 @@ mono_llvm_add_param_attr (LLVMValueRef param, AttrKind kind)
func->addParamAttr (n, convert_attr (kind));
}

void
mono_llvm_add_param_attr_with_type (LLVMValueRef param, AttrKind kind, LLVMTypeRef type)
{
Function *func = unwrap<Argument> (param)->getParent ();
int n = unwrap<Argument> (param)->getArgNo ();

switch (kind) {
case LLVM_ATTR_STRUCT_RET:
#if LLVM_API_VERSION >= 1400
func->addParamAttr (n, Attribute::getWithStructRetType (*unwrap (LLVMGetGlobalContext ()), unwrap (type)));
#else
func->addParamAttr (n, convert_attr (kind));
#endif
break;
default:
g_assert_not_reached ();
}
}

void
mono_llvm_add_param_byval_attr (LLVMValueRef param, LLVMTypeRef type)
{
Expand All @@ -515,6 +534,25 @@ mono_llvm_add_instr_attr (LLVMValueRef val, int index, AttrKind kind)
#endif
}

void
mono_llvm_add_instr_attr_with_type (LLVMValueRef val, int index, AttrKind kind, LLVMTypeRef type)
{
#if LLVM_API_VERSION >= 1400
Attribute attr;

switch (kind) {
case LLVM_ATTR_STRUCT_RET:
attr = Attribute::getWithStructRetType (*unwrap (LLVMGetGlobalContext ()), unwrap (type));
unwrap<CallBase> (val)->addParamAttr (index - 1, attr);
break;
default:
g_assert_not_reached ();
}
#else
unwrap<CallBase> (val)->addAttribute (index, convert_attr (kind));
#endif
}

void
mono_llvm_add_instr_byval_attr (LLVMValueRef val, int index, LLVMTypeRef type)
{
Expand Down Expand Up @@ -757,3 +795,12 @@ mono_llvm_inline_asm (LLVMBuilderRef builder, LLVMTypeRef type,
#endif
return LLVMBuildCall2 (builder, type, asmval, args, num_args, name);
}

#if LLVM_API_VERSION >= 1400
LLVMTypeRef
mono_llvm_get_ptr_type (void)
{
PointerType *t = PointerType::get (*unwrap (LLVMGetGlobalContext ()), 0);
return wrap (t);
}
#endif
9 changes: 9 additions & 0 deletions src/mono/mono/mini/mini-llvm-cpp.h
Expand Up @@ -152,12 +152,18 @@ mono_llvm_add_func_attr_nv (LLVMValueRef func, const char *attr_name, const char
void
mono_llvm_add_param_attr (LLVMValueRef param, AttrKind kind);

void
mono_llvm_add_param_attr_with_type (LLVMValueRef param, AttrKind kind, LLVMTypeRef type);

void
mono_llvm_add_param_byval_attr (LLVMValueRef param, LLVMTypeRef type);

void
mono_llvm_add_instr_attr (LLVMValueRef val, int index, AttrKind kind);

void
mono_llvm_add_instr_attr_with_type (LLVMValueRef val, int index, AttrKind kind, LLVMTypeRef type);

void
mono_llvm_add_instr_byval_attr (LLVMValueRef val, int index, LLVMTypeRef type);

Expand Down Expand Up @@ -227,6 +233,9 @@ mono_llvm_inline_asm (LLVMBuilderRef builder, LLVMTypeRef type,
MonoLLVMAsmFlags flags, LLVMValueRef *args, unsigned num_args,
const char *name);

LLVMTypeRef
mono_llvm_get_ptr_type (void);

G_END_DECLS

#endif /* __MONO_MINI_LLVM_CPP_H__ */

0 comments on commit af2a48d

Please sign in to comment.