[K/N] LLVM: Add missing opaque pointer API

LLVMConstGEP2 and LLVMConstInBoundsGEP2 were forward declared in
LLVM-11, but not implemented until LLVM-14. This patch adds these along
with the missing LLVMAddAlias2. All three implementations are copied
from llvm branch release/14.x
This commit is contained in:
Troels Bjerre Lund
2023-11-06 14:41:28 +01:00
committed by Space Cloud
parent 61f825fbd4
commit c1f72de6e5
3 changed files with 75 additions and 3 deletions
@@ -0,0 +1,37 @@
#include "OpaquePointerAPI.h"
#include <llvm/IR/IntrinsicInst.h>
#include <llvm/IR/Module.h>
using namespace llvm;
/* These are the opaque pointer functions that are missing in llvm-11, which
must be removed upon upgrading LLVM version.
Copied from llvm release/14.x.
*/
LLVMValueRef LLVMAddAlias2(LLVMModuleRef M, LLVMTypeRef ValueTy,
unsigned AddrSpace, LLVMValueRef Aliasee,
const char *Name) {
return wrap(GlobalAlias::create(unwrap(ValueTy), AddrSpace,
GlobalValue::ExternalLinkage, Name,
unwrap<Constant>(Aliasee), unwrap(M)));
}
LLVMValueRef LLVMConstGEP2(LLVMTypeRef Ty, LLVMValueRef ConstantVal,
LLVMValueRef *ConstantIndices, unsigned NumIndices) {
ArrayRef<Constant *> IdxList(unwrap<Constant>(ConstantIndices, NumIndices),
NumIndices);
Constant *Val = unwrap<Constant>(ConstantVal);
return wrap(ConstantExpr::getGetElementPtr(unwrap(Ty), Val, IdxList));
}
LLVMValueRef LLVMConstInBoundsGEP2(LLVMTypeRef Ty, LLVMValueRef ConstantVal,
LLVMValueRef *ConstantIndices,
unsigned NumIndices) {
ArrayRef<Constant *> IdxList(unwrap<Constant>(ConstantIndices, NumIndices),
NumIndices);
Constant *Val = unwrap<Constant>(ConstantVal);
return wrap(ConstantExpr::getInBoundsGetElementPtr(unwrap(Ty), Val, IdxList));
}
@@ -0,0 +1,35 @@
#ifndef LIBLLVMEXT_OPAQUE_POINTER_API_H
#define LIBLLVMEXT_OPAQUE_POINTER_API_H
#include <llvm-c/Core.h>
#include <llvm-c/Target.h>
# ifdef __cplusplus
extern "C" {
# endif
/* These are the opaque pointer functions that are missing in llvm-11, which
must be removed upon upgrading LLVM version.
Copied from llvm release/14.x.
*/
// LLVMConstGEP2 and LLVMConstInBoundsGEP2 are already forward declared in Core.h
LLVMValueRef LLVMConstGEP2(LLVMTypeRef Ty, LLVMValueRef ConstantVal,
LLVMValueRef *ConstantIndices, unsigned NumIndices);
LLVMValueRef LLVMConstInBoundsGEP2(LLVMTypeRef Ty, LLVMValueRef ConstantVal,
LLVMValueRef *ConstantIndices,
unsigned NumIndices);
LLVMValueRef LLVMAddAlias2(LLVMModuleRef M, LLVMTypeRef ValueTy,
unsigned AddrSpace, LLVMValueRef Aliasee,
const char *Name);
# ifdef __cplusplus
}
# endif
#endif // LIBLLVMEXT_OPAQUE_POINTER_API_H