Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for LLVM 15 and opaque pointers #326

Merged
merged 17 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
strategy:
fail-fast: false
matrix:
branch: ['release-1.7', 'release-1.8', 'release-1.9', 'master']
branch: ['release-1.7', 'release-1.8', 'release-1.9', 'master', 'vc/upgrade_llvm15']
os: [ubuntu-latest, macOS-latest]
arch: [x64]
steps:
Expand Down
4 changes: 2 additions & 2 deletions COVERAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LLVM API coverage

Find functions in `lib` not mentioned in this document:
```
for f in $(grep -ohR "function \w*" lib | cut -d ' ' -f 2)
for f in $(grep -ohR "function \w*" lib | cut -d ' ' -f 2)
do
grep -q $f COVERAGE.md || echo $f
done
Expand Down Expand Up @@ -585,7 +585,7 @@ Function parameters:
- [ ] LLVMRemoveAttribute
- [ ] LLVMGetAttribute
- [ ] LLVMSetParamAlignment


### Metadata

Expand Down
5 changes: 4 additions & 1 deletion deps/LLVMExtra/include/LLVMExtra.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ LLVMCreateFunctionPass2(const char *Name, LLVMPassCallback Callback, void *Data)
// Various missing functions
unsigned int LLVMGetDebugMDVersion(void);

LLVMContextRef LLVMGetBuilderContext(LLVMBuilderRef B);
LLVMContextRef LLVMGetValueContext(LLVMValueRef V);
void LLVMAddTargetLibraryInfoByTriple(const char *T, LLVMPassManagerRef PM);
void LLVMAddInternalizePassWithExportList(
Expand Down Expand Up @@ -82,6 +83,8 @@ void LLVMExtraGetNamedMetadataOperands2(LLVMNamedMDNodeRef NMD, LLVMMetadataRef

void LLVMExtraAddNamedMetadataOperand2(LLVMNamedMDNodeRef NMD, LLVMMetadataRef Val);

LLVMTypeRef LLVMGetFunctionType(LLVMValueRef Fn);

#if LLVM_VERSION_MAJOR >= 12
void LLVMAddCFGSimplificationPass2(LLVMPassManagerRef PM,
int BonusInstThreshold,
Expand Down Expand Up @@ -158,7 +161,7 @@ LLVMValueRef LLVMMetadataAsValue2(LLVMContextRef C, LLVMMetadataRef Metadata);
void LLVMReplaceAllMetadataUsesWith(LLVMValueRef Old, LLVMValueRef New);
void LLVMReplaceMDNodeOperandWith(LLVMMetadataRef MD, unsigned I, LLVMMetadataRef New);

#if LLVM_VERSION_MAJOR >= 12
#if LLVM_VERSION_MAJOR >= 13
LLVMBool LLVMContextSupportsTypedPointers(LLVMContextRef C);
#endif

Expand Down
13 changes: 12 additions & 1 deletion deps/LLVMExtra/lib/llvm-api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ LLVMContextRef LLVMGetValueContext(LLVMValueRef V)
return wrap(&unwrap(V)->getContext());
}

LLVMContextRef LLVMGetBuilderContext(LLVMBuilderRef B)
{
return wrap(&unwrap(B)->getContext());
}

void LLVMAddTargetLibraryInfoByTriple(const char *T, LLVMPassManagerRef PM)
{
unwrap(PM)->add(new TargetLibraryInfoWrapperPass(Triple(T)));
Expand Down Expand Up @@ -551,7 +556,7 @@ void LLVMReplaceMDNodeOperandWith(LLVMMetadataRef MD, unsigned I, LLVMMetadataRe
unwrap<MDNode>(MD)->replaceOperandWith(I, unwrap(New));
}

#if LLVM_VERSION_MAJOR > 12
#if LLVM_VERSION_MAJOR >= 13
LLVMBool LLVMContextSupportsTypedPointers(LLVMContextRef C) {
return unwrap(C)->supportsTypedPointers();
}
Expand All @@ -561,3 +566,9 @@ LLVMValueRef LLVMConstDataArray(LLVMTypeRef ElementTy, const void *Data, unsigne
StringRef S((const char *)Data, NumElements * unwrap(ElementTy)->getPrimitiveSizeInBits() / 8);
return wrap(ConstantDataArray::getRaw(S, NumElements, unwrap(ElementTy)));
}

LLVMTypeRef LLVMGetFunctionType(LLVMValueRef Fn) {
auto Ftype = unwrap<Function>(Fn)->getFunctionType();
return wrap(Ftype);
}

8 changes: 4 additions & 4 deletions examples/Kaleidoscope/codegen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ end
function codegen(cg::CodeGen, expr::VariableExprAST)
V = get(current_scope(cg), expr.name, nothing)
V == nothing && error("did not find variable $(expr.name)")
return LLVM.load!(cg.builder, V, expr.name)
return LLVM.load!(cg.builder, LLVM.DoubleType(cg.ctx), V, expr.name)
end

function codegen(cg::CodeGen, expr::BinaryExprAST)
Expand Down Expand Up @@ -94,8 +94,8 @@ function codegen(cg::CodeGen, expr::CallExprAST)
for v in expr.args
push!(args, codegen(cg, v))
end

return LLVM.call!(cg.builder, func, args, "calltmp")
ft = LLVM.function_type(func)
return LLVM.call!(cg.builder, ft, func, args, "calltmp")
end

function codegen(cg::CodeGen, expr::PrototypeAST)
Expand Down Expand Up @@ -190,7 +190,7 @@ function codegen(cg::CodeGen, expr::ForExprAST)
step = codegen(cg, expr.step)
endd = codegen(cg, expr.endd)

curvar = LLVM.load!(cg.builder, alloc, expr.varname)
curvar = LLVM.load!(cg.builder, LLVM.DoubleType(cg.ctx), alloc, expr.varname)
nextvar = LLVM.fadd!(cg.builder, curvar, step, "nextvar")
LLVM.store!(cg.builder, nextvar, alloc)

Expand Down
4 changes: 2 additions & 2 deletions examples/constrained.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ meta(::Type{FPExceptStrict}) = "fpexcept.strict"
mod = LLVM.parent(llvm_f)
intrinsic = Intrinsic("llvm.experimental.constrained.$(func(F))")
intrinsic_fun = LLVM.Function(mod, intrinsic, [typ])

ftype = LLVM.FunctionType(intrinsic,[typ])
# generate IR
@dispose builder=Builder(ctx) begin
entry = BasicBlock(llvm_f, "entry"; ctx)
position!(builder, entry)
val = call!(builder, intrinsic_fun,
val = call!(builder, ftype, intrinsic_fun,
[parameters(llvm_f)..., Value(mround; ctx), Value(mfpexcept; ctx)])
ret!(builder, val)
end
Expand Down
4 changes: 2 additions & 2 deletions examples/generated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ end

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

ptr = gep!(builder, ptr, [parameters(llvmf)[2]])
val = load!(builder, ptr)
ptr = gep!(builder, eltyp, ptr, [parameters(llvmf)[2]])
val = load!(builder, eltyp, ptr)
ret!(builder, val)
end

Expand Down
4 changes: 2 additions & 2 deletions lib/13/libLLVM_h.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4746,8 +4746,8 @@ function LLVMBuildCall(arg1, Fn, Args, NumArgs, Name)
ccall((:LLVMBuildCall, libllvm), LLVMValueRef, (LLVMBuilderRef, LLVMValueRef, Ptr{LLVMValueRef}, Cuint, Cstring), arg1, Fn, Args, NumArgs, Name)
end

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

function LLVMBuildSelect(arg1, If, Then, Else, Name)
Expand Down
Loading