Skip to content

Commit 1205905

Browse files
gbaraldimaleadt
andauthored
Support for LLVM 15 and opaque pointers (#326)
Co-authored-by: Tim Besard <tim.besard@gmail.com>
1 parent ba3d82d commit 1205905

31 files changed

+6892
-972
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jobs:
6767
strategy:
6868
fail-fast: false
6969
matrix:
70-
branch: ['release-1.7', 'release-1.8', 'release-1.9', 'master']
70+
branch: ['release-1.7', 'release-1.8', 'release-1.9', 'master', 'vc/upgrade_llvm15']
7171
os: [ubuntu-latest, macOS-latest]
7272
arch: [x64]
7373
steps:

COVERAGE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LLVM API coverage
55
66
Find functions in `lib` not mentioned in this document:
77
```
8-
for f in $(grep -ohR "function \w*" lib | cut -d ' ' -f 2)
8+
for f in $(grep -ohR "function \w*" lib | cut -d ' ' -f 2)
99
do
1010
grep -q $f COVERAGE.md || echo $f
1111
done
@@ -585,7 +585,7 @@ Function parameters:
585585
- [ ] LLVMRemoveAttribute
586586
- [ ] LLVMGetAttribute
587587
- [ ] LLVMSetParamAlignment
588-
588+
589589

590590
### Metadata
591591

deps/LLVMExtra/include/LLVMExtra.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ LLVMCreateFunctionPass2(const char *Name, LLVMPassCallback Callback, void *Data)
5151
// Various missing functions
5252
unsigned int LLVMGetDebugMDVersion(void);
5353

54+
LLVMContextRef LLVMGetBuilderContext(LLVMBuilderRef B);
5455
LLVMContextRef LLVMGetValueContext(LLVMValueRef V);
5556
void LLVMAddTargetLibraryInfoByTriple(const char *T, LLVMPassManagerRef PM);
5657
void LLVMAddInternalizePassWithExportList(
@@ -82,6 +83,8 @@ void LLVMExtraGetNamedMetadataOperands2(LLVMNamedMDNodeRef NMD, LLVMMetadataRef
8283

8384
void LLVMExtraAddNamedMetadataOperand2(LLVMNamedMDNodeRef NMD, LLVMMetadataRef Val);
8485

86+
LLVMTypeRef LLVMGetFunctionType(LLVMValueRef Fn);
87+
8588
#if LLVM_VERSION_MAJOR >= 12
8689
void LLVMAddCFGSimplificationPass2(LLVMPassManagerRef PM,
8790
int BonusInstThreshold,
@@ -158,7 +161,7 @@ LLVMValueRef LLVMMetadataAsValue2(LLVMContextRef C, LLVMMetadataRef Metadata);
158161
void LLVMReplaceAllMetadataUsesWith(LLVMValueRef Old, LLVMValueRef New);
159162
void LLVMReplaceMDNodeOperandWith(LLVMMetadataRef MD, unsigned I, LLVMMetadataRef New);
160163

161-
#if LLVM_VERSION_MAJOR >= 12
164+
#if LLVM_VERSION_MAJOR >= 13
162165
LLVMBool LLVMContextSupportsTypedPointers(LLVMContextRef C);
163166
#endif
164167

deps/LLVMExtra/lib/llvm-api.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ LLVMContextRef LLVMGetValueContext(LLVMValueRef V)
203203
return wrap(&unwrap(V)->getContext());
204204
}
205205

206+
LLVMContextRef LLVMGetBuilderContext(LLVMBuilderRef B)
207+
{
208+
return wrap(&unwrap(B)->getContext());
209+
}
210+
206211
void LLVMAddTargetLibraryInfoByTriple(const char *T, LLVMPassManagerRef PM)
207212
{
208213
unwrap(PM)->add(new TargetLibraryInfoWrapperPass(Triple(T)));
@@ -551,7 +556,7 @@ void LLVMReplaceMDNodeOperandWith(LLVMMetadataRef MD, unsigned I, LLVMMetadataRe
551556
unwrap<MDNode>(MD)->replaceOperandWith(I, unwrap(New));
552557
}
553558

554-
#if LLVM_VERSION_MAJOR > 12
559+
#if LLVM_VERSION_MAJOR >= 13
555560
LLVMBool LLVMContextSupportsTypedPointers(LLVMContextRef C) {
556561
return unwrap(C)->supportsTypedPointers();
557562
}
@@ -561,3 +566,9 @@ LLVMValueRef LLVMConstDataArray(LLVMTypeRef ElementTy, const void *Data, unsigne
561566
StringRef S((const char *)Data, NumElements * unwrap(ElementTy)->getPrimitiveSizeInBits() / 8);
562567
return wrap(ConstantDataArray::getRaw(S, NumElements, unwrap(ElementTy)));
563568
}
569+
570+
LLVMTypeRef LLVMGetFunctionType(LLVMValueRef Fn) {
571+
auto Ftype = unwrap<Function>(Fn)->getFunctionType();
572+
return wrap(Ftype);
573+
}
574+

examples/Kaleidoscope/codegen.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ end
4343
function codegen(cg::CodeGen, expr::VariableExprAST)
4444
V = get(current_scope(cg), expr.name, nothing)
4545
V == nothing && error("did not find variable $(expr.name)")
46-
return LLVM.load!(cg.builder, V, expr.name)
46+
return LLVM.load!(cg.builder, LLVM.DoubleType(cg.ctx), V, expr.name)
4747
end
4848

4949
function codegen(cg::CodeGen, expr::BinaryExprAST)
@@ -94,8 +94,8 @@ function codegen(cg::CodeGen, expr::CallExprAST)
9494
for v in expr.args
9595
push!(args, codegen(cg, v))
9696
end
97-
98-
return LLVM.call!(cg.builder, func, args, "calltmp")
97+
ft = LLVM.function_type(func)
98+
return LLVM.call!(cg.builder, ft, func, args, "calltmp")
9999
end
100100

101101
function codegen(cg::CodeGen, expr::PrototypeAST)
@@ -190,7 +190,7 @@ function codegen(cg::CodeGen, expr::ForExprAST)
190190
step = codegen(cg, expr.step)
191191
endd = codegen(cg, expr.endd)
192192

193-
curvar = LLVM.load!(cg.builder, alloc, expr.varname)
193+
curvar = LLVM.load!(cg.builder, LLVM.DoubleType(cg.ctx), alloc, expr.varname)
194194
nextvar = LLVM.fadd!(cg.builder, curvar, step, "nextvar")
195195
LLVM.store!(cg.builder, nextvar, alloc)
196196

examples/constrained.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ meta(::Type{FPExceptStrict}) = "fpexcept.strict"
4343
mod = LLVM.parent(llvm_f)
4444
intrinsic = Intrinsic("llvm.experimental.constrained.$(func(F))")
4545
intrinsic_fun = LLVM.Function(mod, intrinsic, [typ])
46-
46+
ftype = LLVM.FunctionType(intrinsic,[typ])
4747
# generate IR
4848
@dispose builder=Builder(ctx) begin
4949
entry = BasicBlock(llvm_f, "entry"; ctx)
5050
position!(builder, entry)
51-
val = call!(builder, intrinsic_fun,
51+
val = call!(builder, ftype, intrinsic_fun,
5252
[parameters(llvm_f)..., Value(mround; ctx), Value(mfpexcept; ctx)])
5353
ret!(builder, val)
5454
end

examples/generated.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ end
2727

2828
ptr = inttoptr!(builder, parameters(llvmf)[1], T_ptr)
2929

30-
ptr = gep!(builder, ptr, [parameters(llvmf)[2]])
31-
val = load!(builder, ptr)
30+
ptr = gep!(builder, eltyp, ptr, [parameters(llvmf)[2]])
31+
val = load!(builder, eltyp, ptr)
3232
ret!(builder, val)
3333
end
3434

lib/13/libLLVM_h.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4746,8 +4746,8 @@ function LLVMBuildCall(arg1, Fn, Args, NumArgs, Name)
47464746
ccall((:LLVMBuildCall, libllvm), LLVMValueRef, (LLVMBuilderRef, LLVMValueRef, Ptr{LLVMValueRef}, Cuint, Cstring), arg1, Fn, Args, NumArgs, Name)
47474747
end
47484748

4749-
function LLVMBuildCall2(arg1, arg2, Fn, Args, NumArgs, Name)
4750-
ccall((:LLVMBuildCall2, libllvm), LLVMValueRef, (LLVMBuilderRef, LLVMTypeRef, LLVMValueRef, Ptr{LLVMValueRef}, Cuint, Cstring), arg1, arg2, Fn, Args, NumArgs, Name)
4749+
function LLVMBuildCall2(arg1, Ty, Fn, Args, NumArgs, Name)
4750+
ccall((:LLVMBuildCall2, libllvm), LLVMValueRef, (LLVMBuilderRef, LLVMTypeRef, LLVMValueRef, Ptr{LLVMValueRef}, Cuint, Cstring), arg1, Ty, Fn, Args, NumArgs, Name)
47514751
end
47524752

47534753
function LLVMBuildSelect(arg1, If, Then, Else, Name)

0 commit comments

Comments
 (0)