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

WIP use LLVM 19 #65

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
runs-on: ubuntu-20.04
strategy:
matrix:
llvm: [14, 15, 16, 17, 18]
llvm: [14, 15, 16, 17, 18, 19]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -52,6 +52,6 @@ jobs:
run:
go test -v -tags=llvm${{ matrix.llvm }}
- name: Test default LLVM
if: matrix.llvm == 18
if: matrix.llvm == 19
run:
go test -v
10 changes: 5 additions & 5 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ This library provides bindings to a system-installed LLVM.

Currently supported:

* LLVM 17, 16, 15 and 14 from [apt.llvm.org](http://apt.llvm.org/) on Debian/Ubuntu.
* LLVM 17, 16, 15 and 14 from Homebrew on macOS.
* LLVM 15 with a manually built LLVM through the `byollvm` build tag. You
* LLVM 19, 18, 17, 16, 15 and 14 from [apt.llvm.org](http://apt.llvm.org/) on Debian/Ubuntu.
* LLVM 18, 17, 16, 15 and 14 from Homebrew on macOS.
* LLVM 19 with a manually built LLVM through the `byollvm` build tag. You
need to set up `CFLAGS`/`LDFLAGS` etc yourself in this case.

You can select the LLVM version using a build tag, for example `-tags=llvm14`
to use LLVM 14.
You can select the LLVM version using a build tag, for example `-tags=llvm17`
to use LLVM 17.

## Usage

Expand Down
14 changes: 14 additions & 0 deletions backports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,17 @@ LLVMMemoryBufferRef LLVMGoWriteThinLTOBitcodeToMemoryBuffer(LLVMModuleRef M) {
#endif
return llvm::wrap(llvm::MemoryBuffer::getMemBufferCopy(OS.str()).release());
}

void LLVMGoDIBuilderInsertDbgValueRecordAtEnd(
LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo,
LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block) {
#if LLVM_VERSION_MAJOR >= 19
// Note: this returns a LLVMDbgRecordRef. Previously, InsertValueAtEnd would
// return a Value. But since the type changed, and I'd like to keep the API
// consistent across LLVM versions, I decided to drop the return value.
LLVMDIBuilderInsertDbgValueRecordAtEnd(Builder, Val, VarInfo, Expr, DebugLoc, Block);
#else
// Old llvm.dbg.* API.
LLVMDIBuilderInsertDbgValueAtEnd(Builder, Val, VarInfo, Expr, DebugLoc, Block);
#endif
}
5 changes: 3 additions & 2 deletions backports.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ void LLVMGlobalObjectAddMetadata(LLVMValueRef objValue, unsigned KindID, LLVMMet

LLVMMemoryBufferRef LLVMGoWriteThinLTOBitcodeToMemoryBuffer(LLVMModuleRef M);

LLVMMetadataRef LLVMGoDIBuilderCreateExpression(LLVMDIBuilderRef Builder,
uint64_t *Addr, size_t Length);
void LLVMGoDIBuilderInsertDbgValueRecordAtEnd(
LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo,
LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block);

#ifdef __cplusplus
}
Expand Down
14 changes: 2 additions & 12 deletions dibuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,22 +610,12 @@ func (d *DIBuilder) CreateExpression(addr []uint64) Metadata {
return Metadata{C: result}
}

// InsertDeclareAtEnd inserts a call to llvm.dbg.declare at the end of the
// specified basic block for the given value and associated debug metadata.
func (d *DIBuilder) InsertDeclareAtEnd(v Value, diVarInfo, expr Metadata, l DebugLoc, bb BasicBlock) Value {
loc := C.LLVMDIBuilderCreateDebugLocation(
d.m.Context().C, C.uint(l.Line), C.uint(l.Col), l.Scope.C, l.InlinedAt.C)
result := C.LLVMDIBuilderInsertDeclareAtEnd(d.ref, v.C, diVarInfo.C, expr.C, loc, bb.C)
return Value{C: result}
}

// InsertValueAtEnd inserts a call to llvm.dbg.value at the end of the
// specified basic block for the given value and associated debug metadata.
func (d *DIBuilder) InsertValueAtEnd(v Value, diVarInfo, expr Metadata, l DebugLoc, bb BasicBlock) Value {
func (d *DIBuilder) InsertValueAtEnd(v Value, diVarInfo, expr Metadata, l DebugLoc, bb BasicBlock) {
loc := C.LLVMDIBuilderCreateDebugLocation(
d.m.Context().C, C.uint(l.Line), C.uint(l.Col), l.Scope.C, l.InlinedAt.C)
result := C.LLVMDIBuilderInsertDbgValueAtEnd(d.ref, v.C, diVarInfo.C, expr.C, loc, bb.C)
return Value{C: result}
C.LLVMGoDIBuilderInsertDbgValueRecordAtEnd(d.ref, v.C, diVarInfo.C, expr.C, loc, bb.C)
}

func (v Value) SetSubprogram(sp Metadata) {
Expand Down
18 changes: 0 additions & 18 deletions ir.go
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,6 @@ func AlignOf(t Type) (v Value) { v.C = C.LLVMAlignOf(t.C); return }
func SizeOf(t Type) (v Value) { v.C = C.LLVMSizeOf(t.C); return }
func ConstNeg(v Value) (rv Value) { rv.C = C.LLVMConstNeg(v.C); return }
func ConstNSWNeg(v Value) (rv Value) { rv.C = C.LLVMConstNSWNeg(v.C); return }
func ConstNUWNeg(v Value) (rv Value) { rv.C = C.LLVMConstNUWNeg(v.C); return }
func ConstNot(v Value) (rv Value) { rv.C = C.LLVMConstNot(v.C); return }
func ConstAdd(lhs, rhs Value) (v Value) { v.C = C.LLVMConstAdd(lhs.C, rhs.C); return }
func ConstNSWAdd(lhs, rhs Value) (v Value) { v.C = C.LLVMConstNSWAdd(lhs.C, rhs.C); return }
Expand All @@ -934,17 +933,6 @@ func ConstNSWMul(lhs, rhs Value) (v Value) { v.C = C.LLVMConstNSWMul(lhs.C, rhs.
func ConstNUWMul(lhs, rhs Value) (v Value) { v.C = C.LLVMConstNUWMul(lhs.C, rhs.C); return }
func ConstXor(lhs, rhs Value) (v Value) { v.C = C.LLVMConstXor(lhs.C, rhs.C); return }

func ConstICmp(pred IntPredicate, lhs, rhs Value) (v Value) {
v.C = C.LLVMConstICmp(C.LLVMIntPredicate(pred), lhs.C, rhs.C)
return
}
func ConstFCmp(pred FloatPredicate, lhs, rhs Value) (v Value) {
v.C = C.LLVMConstFCmp(C.LLVMRealPredicate(pred), lhs.C, rhs.C)
return
}

func ConstShl(lhs, rhs Value) (v Value) { v.C = C.LLVMConstShl(lhs.C, rhs.C); return }

func ConstGEP(t Type, v Value, indices []Value) (rv Value) {
ptr, nvals := llvmValueRefs(indices)
rv.C = C.LLVMConstGEP2(t.C, v.C, ptr, nvals)
Expand Down Expand Up @@ -1660,12 +1648,6 @@ func (b Builder) CreateNSWNeg(v Value, name string) (rv Value) {
rv.C = C.LLVMBuildNSWNeg(b.C, v.C, cname)
return
}
func (b Builder) CreateNUWNeg(v Value, name string) (rv Value) {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
rv.C = C.LLVMBuildNUWNeg(b.C, v.C, cname)
return
}
func (b Builder) CreateFNeg(v Value, name string) (rv Value) {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
Expand Down
2 changes: 1 addition & 1 deletion llvm_config_linux_llvm18.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !byollvm && linux && !llvm14 && !llvm15 && !llvm16 && !llvm17
//go:build !byollvm && linux && llvm18

package llvm

Expand Down
10 changes: 10 additions & 0 deletions llvm_config_linux_llvm19.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//go:build !byollvm && linux && !llvm14 && !llvm15 && !llvm16 && !llvm17 && !llvm18

package llvm

// #cgo CPPFLAGS: -I/usr/include/llvm-19 -I/usr/include/llvm-c-19 -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
// #cgo CXXFLAGS: -std=c++17
// #cgo LDFLAGS: /usr/lib/llvm-19/lib/libLLVM.so
import "C"

type run_build_sh int
Loading