Skip to content

Commit

Permalink
WIP use LLVM 19
Browse files Browse the repository at this point in the history
  • Loading branch information
aykevl committed Aug 25, 2024
1 parent aaff3eb commit bd12051
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 38 deletions.
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
19 changes: 7 additions & 12 deletions dibuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,22 +610,17 @@ 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.LLVMDIBuilderInsertDbgValueRecordAtEnd(d.ref, v.C, diVarInfo.C, expr.C, loc, bb.C)

Check failure on line 618 in dibuilder.go

View workflow job for this annotation

GitHub Actions / test-macos (15)

could not determine kind of name for C.LLVMDIBuilderInsertDbgValueRecordAtEnd

Check failure on line 618 in dibuilder.go

View workflow job for this annotation

GitHub Actions / test-linux (14)

could not determine kind of name for C.LLVMDIBuilderInsertDbgValueRecordAtEnd

Check failure on line 618 in dibuilder.go

View workflow job for this annotation

GitHub Actions / test-linux (15)

could not determine kind of name for C.LLVMDIBuilderInsertDbgValueRecordAtEnd

Check failure on line 618 in dibuilder.go

View workflow job for this annotation

GitHub Actions / test-linux (16)

could not determine kind of name for C.LLVMDIBuilderInsertDbgValueRecordAtEnd

Check failure on line 618 in dibuilder.go

View workflow job for this annotation

GitHub Actions / test-linux (18)

could not determine kind of name for C.LLVMDIBuilderInsertDbgValueRecordAtEnd

Check failure on line 618 in dibuilder.go

View workflow job for this annotation

GitHub Actions / test-linux (17)

could not determine kind of name for C.LLVMDIBuilderInsertDbgValueRecordAtEnd

Check failure on line 618 in dibuilder.go

View workflow job for this annotation

GitHub Actions / test-linux (18)

could not determine kind of name for C.LLVMDIBuilderInsertDbgValueRecordAtEnd

Check failure on line 618 in dibuilder.go

View workflow job for this annotation

GitHub Actions / test-linux (15)

could not determine kind of name for C.LLVMDIBuilderInsertDbgValueRecordAtEnd

Check failure on line 618 in dibuilder.go

View workflow job for this annotation

GitHub Actions / test-linux (17)

could not determine kind of name for C.LLVMDIBuilderInsertDbgValueRecordAtEnd

Check failure on line 618 in dibuilder.go

View workflow job for this annotation

GitHub Actions / test-linux (16)

could not determine kind of name for C.LLVMDIBuilderInsertDbgValueRecordAtEnd

Check failure on line 618 in dibuilder.go

View workflow job for this annotation

GitHub Actions / test-macos (15)

could not determine kind of name for C.LLVMDIBuilderInsertDbgValueRecordAtEnd

Check failure on line 618 in dibuilder.go

View workflow job for this annotation

GitHub Actions / test-linux (14)

could not determine kind of name for C.LLVMDIBuilderInsertDbgValueRecordAtEnd
// 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.
// There was also a InsertDeclareAtEnd, it can easily be added back if other
// packages require that method.
}

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

0 comments on commit bd12051

Please sign in to comment.