Skip to content

Commit

Permalink
[mono][llvm] Refactor code to make it easier to support LLVM 13.x in … (
Browse files Browse the repository at this point in the history
#67692)

* [mono][llvm] Refactor code to make it easier to support LLVM 13.x in the future

* Remove some c++ functions which can be implemented using the C API.
* Use call_intrins in more places.

* Use the const_int32 ()/const_int64 () helper functions in more places.

* Use opaque pointer type APIs.

LLVM is transitioning to using opaque pointer types, i.e. pointer
types with no element type. Transition the LLVM backend to do
the same.

* Add an 'Address' structure which represents a pointer value and
  its element type, use it in places where the element type of
  a pointer is not locally available, like for globals.
* Use LLVMBuildCall2/BuildInvoke2 functions where possible.

* Fix the build.
  • Loading branch information
vargaz authored Apr 14, 2022
1 parent 5385962 commit 84b664a
Show file tree
Hide file tree
Showing 3 changed files with 423 additions and 433 deletions.
42 changes: 18 additions & 24 deletions src/mono/mono/mini/mini-llvm-cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,6 @@ mono_llvm_build_alloca (LLVMBuilderRef builder, LLVMTypeRef Ty, LLVMValueRef Arr
return wrap (ins);
}

LLVMValueRef
mono_llvm_build_load (LLVMBuilderRef builder, LLVMValueRef PointerVal,
const char *Name, gboolean is_volatile)
{
LoadInst *ins = unwrap(builder)->CreateLoad(unwrap(PointerVal), is_volatile, Name);

return wrap(ins);
}

LLVMValueRef
mono_llvm_build_atomic_load (LLVMBuilderRef builder, LLVMValueRef PointerVal,
const char *Name, gboolean is_volatile, int alignment, BarrierKind barrier)
Expand Down Expand Up @@ -150,10 +141,25 @@ mono_llvm_build_aligned_load (LLVMBuilderRef builder, LLVMValueRef PointerVal,
}

LLVMValueRef
mono_llvm_build_store (LLVMBuilderRef builder, LLVMValueRef Val, LLVMValueRef PointerVal,
gboolean is_volatile, BarrierKind barrier)
mono_llvm_build_aligned_store (LLVMBuilderRef builder, LLVMValueRef Val, LLVMValueRef PointerVal,
gboolean is_volatile, int alignment)
{
StoreInst *ins;

ins = unwrap(builder)->CreateStore(unwrap(Val), unwrap(PointerVal), is_volatile);
ins->setAlignment (to_align (alignment));

return wrap (ins);
}

LLVMValueRef
mono_llvm_build_atomic_store (LLVMBuilderRef builder, LLVMValueRef Val, LLVMValueRef PointerVal,
BarrierKind barrier, int alignment)
{
StoreInst *ins = unwrap(builder)->CreateStore(unwrap(Val), unwrap(PointerVal), is_volatile);
StoreInst *ins;

ins = unwrap(builder)->CreateStore(unwrap(Val), unwrap(PointerVal), false);
ins->setAlignment (to_align (alignment));

switch (barrier) {
case LLVM_BARRIER_NONE:
Expand All @@ -169,18 +175,6 @@ mono_llvm_build_store (LLVMBuilderRef builder, LLVMValueRef Val, LLVMValueRef Po
break;
}

return wrap(ins);
}

LLVMValueRef
mono_llvm_build_aligned_store (LLVMBuilderRef builder, LLVMValueRef Val, LLVMValueRef PointerVal,
gboolean is_volatile, int alignment)
{
StoreInst *ins;

ins = unwrap(builder)->CreateStore(unwrap(Val), unwrap(PointerVal), is_volatile);
ins->setAlignment (to_align (alignment));

return wrap (ins);
}

Expand Down
12 changes: 4 additions & 8 deletions src/mono/mono/mini/mini-llvm-cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ mono_llvm_build_alloca (LLVMBuilderRef builder, LLVMTypeRef Ty,
LLVMValueRef ArraySize,
int alignment, const char *Name);

LLVMValueRef
mono_llvm_build_load (LLVMBuilderRef builder, LLVMValueRef PointerVal,
const char *Name, gboolean is_volatile);

LLVMValueRef
mono_llvm_build_atomic_load (LLVMBuilderRef builder, LLVMValueRef PointerVal,
const char *Name, gboolean is_volatile, int alignment, BarrierKind barrier);
Expand All @@ -79,14 +75,14 @@ LLVMValueRef
mono_llvm_build_aligned_load (LLVMBuilderRef builder, LLVMValueRef PointerVal,
const char *Name, gboolean is_volatile, int alignment);

LLVMValueRef
mono_llvm_build_store (LLVMBuilderRef builder, LLVMValueRef Val, LLVMValueRef PointerVal,
gboolean is_volatile, BarrierKind kind);

LLVMValueRef
mono_llvm_build_aligned_store (LLVMBuilderRef builder, LLVMValueRef Val, LLVMValueRef PointerVal,
gboolean is_volatile, int alignment);

LLVMValueRef
mono_llvm_build_atomic_store (LLVMBuilderRef builder, LLVMValueRef Val, LLVMValueRef PointerVal,
BarrierKind barrier, int alignment);

LLVMValueRef
mono_llvm_build_atomic_rmw (LLVMBuilderRef builder, AtomicRMWOp op, LLVMValueRef ptr, LLVMValueRef val);

Expand Down
Loading

0 comments on commit 84b664a

Please sign in to comment.