Skip to content

Commit

Permalink
Add support for LLVM 15
Browse files Browse the repository at this point in the history
Also use LLVM 15 by default, because it's already supported on Linux
(apt.llvm.org) and MacOS (Homebrew).
  • Loading branch information
aykevl committed Sep 22, 2022
1 parent 4b5ad7f commit dcb078a
Show file tree
Hide file tree
Showing 15 changed files with 79 additions and 229 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ jobs:
- name: Test LLVM 14
run:
go test -v -tags=llvm14
test-macos-llvm-15:
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install LLVM
run: |
brew update
brew install llvm@15
- name: Test LLVM 15
run:
go test -v -tags=llvm15
- name: Test default LLVM
run:
go test -v
Expand All @@ -35,6 +47,20 @@ jobs:
- name: Test LLVM 14
run:
go test -v -tags=llvm14
test-linux-llvm-15:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install LLVM
run: |
echo 'deb http://apt.llvm.org/focal/ llvm-toolchain-focal-15 main' | sudo tee /etc/apt/sources.list.d/llvm.list
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt-get update
sudo apt-get install --no-install-recommends llvm-15-dev
- name: Test LLVM 15
run:
go test -v -tags=llvm15
- name: Test default LLVM
run:
go test -v
48 changes: 0 additions & 48 deletions InstrumentationBindings.cpp

This file was deleted.

37 changes: 0 additions & 37 deletions InstrumentationBindings.h

This file was deleted.

1 change: 0 additions & 1 deletion backports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Transforms/IPO.h"
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
#include "llvm/Transforms/Coroutines.h"
#include "llvm-c/DebugInfo.h"

void LLVMGlobalObjectAddMetadata(LLVMValueRef Global, unsigned KindID, LLVMMetadataRef MD) {
Expand Down
76 changes: 21 additions & 55 deletions ir.go
Original file line number Diff line number Diff line change
Expand Up @@ -911,37 +911,27 @@ func ConstVector(scalarConstVals []Value, packed bool) (v Value) {
}

// Constant expressions
func (v Value) Opcode() Opcode { return Opcode(C.LLVMGetConstOpcode(v.C)) }
func (v Value) InstructionOpcode() Opcode { return Opcode(C.LLVMGetInstructionOpcode(v.C)) }
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 ConstFNeg(v Value) (rv Value) { rv.C = C.LLVMConstFNeg(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 }
func ConstNUWAdd(lhs, rhs Value) (v Value) { v.C = C.LLVMConstNUWAdd(lhs.C, rhs.C); return }
func ConstFAdd(lhs, rhs Value) (v Value) { v.C = C.LLVMConstFAdd(lhs.C, rhs.C); return }
func ConstSub(lhs, rhs Value) (v Value) { v.C = C.LLVMConstSub(lhs.C, rhs.C); return }
func ConstNSWSub(lhs, rhs Value) (v Value) { v.C = C.LLVMConstNSWSub(lhs.C, rhs.C); return }
func ConstNUWSub(lhs, rhs Value) (v Value) { v.C = C.LLVMConstNUWSub(lhs.C, rhs.C); return }
func ConstFSub(lhs, rhs Value) (v Value) { v.C = C.LLVMConstFSub(lhs.C, rhs.C); return }
func ConstMul(lhs, rhs Value) (v Value) { v.C = C.LLVMConstMul(lhs.C, rhs.C); return }
func ConstNSWMul(lhs, rhs Value) (v Value) { v.C = C.LLVMConstNSWMul(lhs.C, rhs.C); return }
func ConstNUWMul(lhs, rhs Value) (v Value) { v.C = C.LLVMConstNUWMul(lhs.C, rhs.C); return }
func ConstFMul(lhs, rhs Value) (v Value) { v.C = C.LLVMConstFMul(lhs.C, rhs.C); return }
func ConstUDiv(lhs, rhs Value) (v Value) { v.C = C.LLVMConstUDiv(lhs.C, rhs.C); return }
func ConstSDiv(lhs, rhs Value) (v Value) { v.C = C.LLVMConstSDiv(lhs.C, rhs.C); return }
func ConstExactSDiv(lhs, rhs Value) (v Value) { v.C = C.LLVMConstExactSDiv(lhs.C, rhs.C); return }
func ConstFDiv(lhs, rhs Value) (v Value) { v.C = C.LLVMConstFDiv(lhs.C, rhs.C); return }
func ConstURem(lhs, rhs Value) (v Value) { v.C = C.LLVMConstURem(lhs.C, rhs.C); return }
func ConstSRem(lhs, rhs Value) (v Value) { v.C = C.LLVMConstSRem(lhs.C, rhs.C); return }
func ConstFRem(lhs, rhs Value) (v Value) { v.C = C.LLVMConstFRem(lhs.C, rhs.C); return }
func ConstAnd(lhs, rhs Value) (v Value) { v.C = C.LLVMConstAnd(lhs.C, rhs.C); return }
func ConstOr(lhs, rhs Value) (v Value) { v.C = C.LLVMConstOr(lhs.C, rhs.C); return }
func ConstXor(lhs, rhs Value) (v Value) { v.C = C.LLVMConstXor(lhs.C, rhs.C); return }
func (v Value) Opcode() Opcode { return Opcode(C.LLVMGetConstOpcode(v.C)) }
func (v Value) InstructionOpcode() Opcode { return Opcode(C.LLVMGetInstructionOpcode(v.C)) }
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 ConstFNeg(v Value) (rv Value) { rv.C = C.LLVMConstFNeg(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 }
func ConstNUWAdd(lhs, rhs Value) (v Value) { v.C = C.LLVMConstNUWAdd(lhs.C, rhs.C); return }
func ConstSub(lhs, rhs Value) (v Value) { v.C = C.LLVMConstSub(lhs.C, rhs.C); return }
func ConstNSWSub(lhs, rhs Value) (v Value) { v.C = C.LLVMConstNSWSub(lhs.C, rhs.C); return }
func ConstNUWSub(lhs, rhs Value) (v Value) { v.C = C.LLVMConstNUWSub(lhs.C, rhs.C); return }
func ConstMul(lhs, rhs Value) (v Value) { v.C = C.LLVMConstMul(lhs.C, rhs.C); return }
func ConstNSWMul(lhs, rhs Value) (v Value) { v.C = C.LLVMConstNSWMul(lhs.C, rhs.C); return }
func ConstNUWMul(lhs, rhs Value) (v Value) { v.C = C.LLVMConstNUWMul(lhs.C, rhs.C); return }
func ConstAnd(lhs, rhs Value) (v Value) { v.C = C.LLVMConstAnd(lhs.C, rhs.C); return }
func ConstOr(lhs, rhs Value) (v Value) { v.C = C.LLVMConstOr(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)
Expand Down Expand Up @@ -1013,30 +1003,6 @@ func ConstShuffleVector(veca, vecb, mask Value) (rv Value) {
return
}

//TODO
//LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
// unsigned NumIdx);

func ConstExtractValue(agg Value, indices []uint32) (rv Value) {
n := len(indices)
if n == 0 {
panic("one or more indices are required")
}
ptr := (*C.unsigned)(&indices[0])
rv.C = C.LLVMConstExtractValue(agg.C, ptr, C.unsigned(n))
return
}

func ConstInsertValue(agg, val Value, indices []uint32) (rv Value) {
n := len(indices)
if n == 0 {
panic("one or more indices are required")
}
ptr := (*C.unsigned)(&indices[0])
rv.C = C.LLVMConstInsertValue(agg.C, val.C, ptr, C.unsigned(n))
return
}

func BlockAddress(f Value, bb BasicBlock) (v Value) {
v.C = C.LLVMBlockAddress(f.C, bb.C)
return
Expand Down
11 changes: 1 addition & 10 deletions ir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,19 +140,10 @@ func TestSubtypes(t *testing.T) {
cont := NewContext()
defer cont.Dispose()

int_pointer := PointerType(cont.Int32Type(), 0)
int_inner := int_pointer.Subtypes()
if len(int_inner) != 1 {
t.Errorf("Got size %d, though wanted 1", len(int_inner))
}
if int_inner[0] != cont.Int32Type() {
t.Errorf("Expected int32 type")
}

st_pointer := cont.StructType([]Type{cont.Int32Type(), cont.Int8Type()}, false)
st_inner := st_pointer.Subtypes()
if len(st_inner) != 2 {
t.Errorf("Got size %d, though wanted 2", len(int_inner))
t.Errorf("Got size %d, though wanted 2", len(st_inner))
}
if st_inner[0] != cont.Int32Type() {
t.Errorf("Expected first struct field to be int32")
Expand Down
4 changes: 2 additions & 2 deletions llvm_config_darwin_llvm14.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build !byollvm && darwin
// +build !byollvm,darwin
//go:build !byollvm && darwin && llvm14
// +build !byollvm,darwin,llvm14

package llvm

Expand Down
16 changes: 16 additions & 0 deletions llvm_config_darwin_llvm15.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//go:build !byollvm && darwin && !llvm14
// +build !byollvm,darwin,!llvm14

package llvm

// Automatically generated by `make config BUILDDIR=`, do not edit.

// #cgo amd64 CPPFLAGS: -I/usr/local/opt/llvm@15/include -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
// #cgo amd64 CXXFLAGS: -std=c++14
// #cgo amd64 LDFLAGS: -L/usr/local/opt/llvm@15/lib -Wl,-search_paths_first -Wl,-headerpad_max_install_names -lLLVM -lz -lcurses -lm -lxml2 -L/usr/local/opt/libffi/lib -lffi
// #cgo arm64 CPPFLAGS: -I/opt/homebrew/opt/llvm@15/include -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
// #cgo arm64 CXXFLAGS: -std=c++14
// #cgo arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@15/lib -Wl,-search_paths_first -Wl,-headerpad_max_install_names -lLLVM -lz -lcurses -lm -lxml2 -L/opt/homebrew/opt/libffi/lib -lffi
import "C"

type run_build_sh int
4 changes: 2 additions & 2 deletions llvm_config_linux_llvm14.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build !byollvm && linux
// +build !byollvm,linux
//go:build !byollvm && linux && llvm14
// +build !byollvm,linux,llvm14

package llvm

Expand Down
11 changes: 11 additions & 0 deletions llvm_config_linux_llvm15.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//go:build !byollvm && linux && !llvm14
// +build !byollvm,linux,!llvm14

package llvm

// #cgo CPPFLAGS: -I/usr/lib/llvm-15/include -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
// #cgo CXXFLAGS: -std=c++14
// #cgo LDFLAGS: -L/usr/lib/llvm-15/lib -lLLVM-15
import "C"

type run_build_sh int
23 changes: 0 additions & 23 deletions transforms_coroutines.go

This file was deleted.

45 changes: 0 additions & 45 deletions transforms_instrumentation.go

This file was deleted.

1 change: 0 additions & 1 deletion transforms_ipo.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ func boolToUnsigned(b bool) C.unsigned {
return 0
}

func (pm PassManager) AddArgumentPromotionPass() { C.LLVMAddArgumentPromotionPass(pm.C) }
func (pm PassManager) AddConstantMergePass() { C.LLVMAddConstantMergePass(pm.C) }
func (pm PassManager) AddDeadArgEliminationPass() { C.LLVMAddDeadArgEliminationPass(pm.C) }
func (pm PassManager) AddFunctionAttrsPass() { C.LLVMAddFunctionAttrsPass(pm.C) }
Expand Down
4 changes: 0 additions & 4 deletions transforms_pmbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ func (pmb PassManagerBuilder) PopulateFunc(pm PassManager) {
C.LLVMPassManagerBuilderPopulateFunctionPassManager(pmb.C, pm.C)
}

func (pmb PassManagerBuilder) PopulateLTOPassManager(pm PassManager, internalize bool, runInliner bool) {
C.LLVMPassManagerBuilderPopulateLTOPassManager(pmb.C, pm.C, boolToLLVMBool(internalize), boolToLLVMBool(runInliner))
}

func (pmb PassManagerBuilder) Dispose() {
C.LLVMPassManagerBuilderDispose(pmb.C)
}
Expand Down
1 change: 0 additions & 1 deletion transforms_scalar.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ func (pm PassManager) AddLICMPass() { C.LLVMAddLICMPass(pm.C)
func (pm PassManager) AddLoopDeletionPass() { C.LLVMAddLoopDeletionPass(pm.C) }
func (pm PassManager) AddLoopRotatePass() { C.LLVMAddLoopRotatePass(pm.C) }
func (pm PassManager) AddLoopUnrollPass() { C.LLVMAddLoopUnrollPass(pm.C) }
func (pm PassManager) AddLoopUnswitchPass() { C.LLVMAddLoopUnswitchPass(pm.C) }
func (pm PassManager) AddMemCpyOptPass() { C.LLVMAddMemCpyOptPass(pm.C) }
func (pm PassManager) AddPromoteMemoryToRegisterPass() { C.LLVMAddPromoteMemoryToRegisterPass(pm.C) }
func (pm PassManager) AddReassociatePass() { C.LLVMAddReassociatePass(pm.C) }
Expand Down

0 comments on commit dcb078a

Please sign in to comment.