forked from xgo-dev/llvm
-
Notifications
You must be signed in to change notification settings - Fork 0
llvm: sync complete upstream LLVM 22 support #5
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
63740cf
LLVM 21 support
aykevl 12a422f
Move the separate darwin/linux config files into one
aykevl 5ab4b69
add ExecutionEngine.NewJITCompiler()
1113dcf
fix compilation on freebsd and add ci
2e3bbdd
remove freebsd ci
00fb430
fix bad formatting
9bf73fc
Add paths for older LLVM versions on Fedora
aykevl 06c6725
Use LLVM 20 by default for now
aykevl ddd595b
Add LLVM 22 build support (#75)
dgryski acf1331
Merge remote-tracking branch 'tinygo/main' into xgo
zhouguangyuan0718 cb027fc
set llvm 19 as default
zhouguangyuan0718 caa39a9
Merge pull request #45 from zhouguangyuan0718/xgo
xushiwei 9958715
Merge xgo-dev/llvm xgo into coroutine bindings
cpunion bf5fb88
test: release LLVM resources in regression coverage
cpunion 5862354
ci: validate LLVM 20 bindings
cpunion File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package llvm | ||
|
|
||
| import ( | ||
| "strconv" | ||
| "strings" | ||
| "testing" | ||
| ) | ||
|
|
||
| // TestCapturesAttribute checks that the 'captures' parameter attribute | ||
| // (which replaced the boolean 'nocapture' enum attribute starting with | ||
| // LLVM 21) round-trips through the generic enum-attribute API, and that a | ||
| // value of 0 corresponds to CaptureInfo::none(), i.e. captures(none). | ||
| func TestCapturesAttribute(t *testing.T) { | ||
| majorVersion, _ := strconv.Atoi(strings.SplitN(Version, ".", 2)[0]) | ||
| if majorVersion < 21 { | ||
| t.Skip("not llvm 21") | ||
| } | ||
|
|
||
| ctx := NewContext() | ||
| defer ctx.Dispose() | ||
| mod := ctx.NewModule("") | ||
| defer mod.Dispose() | ||
|
|
||
| ptrType := PointerType(ctx.Int8Type(), 0) | ||
| ftyp := FunctionType(ctx.VoidType(), []Type{ptrType}, false) | ||
| fn := AddFunction(mod, "foo", ftyp) | ||
|
|
||
| kind := AttributeKindID("captures") | ||
| if kind == 0 { | ||
| t.Fatal("captures kind id not found") | ||
| } | ||
|
|
||
| attr := ctx.CreateEnumAttribute(kind, 0) | ||
| fn.AddAttributeAtIndex(1, attr) | ||
|
|
||
| got := fn.GetEnumAttributeAtIndex(1, kind) | ||
| if got.IsNil() { | ||
| t.Fatal("expected captures attribute on param 1, got nil") | ||
| } | ||
| if val := got.GetEnumValue(); val != 0 { | ||
| t.Errorf("expected captures value 0 (none), got %d", val) | ||
| } | ||
|
|
||
| text := mod.String() | ||
| if !strings.Contains(text, "captures(none)") { | ||
| t.Errorf("expected 'captures(none)' in output, got:\n%s", text) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| //go:build llvm22 | ||
|
|
||
| package llvm | ||
|
|
||
| /* | ||
| #include "llvm-c/Core.h" | ||
| */ | ||
| import "C" | ||
|
|
||
| // GetSwitchCaseValue obtains the case value for a successor of a switch | ||
| // instruction. i corresponds to the successor index; the first successor (0) | ||
| // is the default destination, so i must be greater than zero. | ||
| // | ||
| // LLVM 22 stopped exposing switch case values as regular instruction | ||
| // operands (only the condition and destination-block operands remain), so | ||
| // this is implemented via the new LLVMGetSwitchCaseValue C API added in the | ||
| // same release. | ||
| func (v Value) GetSwitchCaseValue(i int) (rv Value) { | ||
| rv.C = C.LLVMGetSwitchCaseValue(v.C, C.unsigned(i)) | ||
| return | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| //go:build !llvm22 | ||
|
|
||
| package llvm | ||
|
|
||
| // GetSwitchCaseValue obtains the case value for a successor of a switch | ||
| // instruction. i corresponds to the successor index; the first successor (0) | ||
| // is the default destination, so i must be greater than zero. | ||
| // | ||
| // Before LLVM 22, switch case values were stored as regular instruction | ||
| // operands (alternating with their destination blocks, after the leading | ||
| // condition/default-destination pair), so this is implemented via Operand | ||
| // access instead of the LLVM 22+-only LLVMGetSwitchCaseValue. | ||
| func (v Value) GetSwitchCaseValue(i int) Value { | ||
| return v.Operand(2 * i) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| package llvm | ||
|
|
||
| import ( | ||
| "os" | ||
| "testing" | ||
| ) | ||
|
|
||
| // TestSwitchCaseValue checks that GetSwitchCaseValue/SuccessorsCount/Successor | ||
| // correctly read a switch instruction's cases across LLVM versions. LLVM 22 | ||
| // stopped exposing case values as regular instruction operands (only the | ||
| // condition and destination-block operands remain), instead requiring the | ||
| // new LLVMGetSwitchCaseValue API; code that assumed the old operand layout | ||
| // silently reads a destination block where it expects a case value. | ||
| func TestSwitchCaseValue(t *testing.T) { | ||
| src := ` | ||
| define void @foo(i64 %callback) { | ||
| entry: | ||
| switch i64 %callback, label %default [ | ||
| i64 0, label %case0 | ||
| i64 5, label %case1 | ||
| ] | ||
| default: | ||
| ret void | ||
| case0: | ||
| ret void | ||
| case1: | ||
| ret void | ||
| } | ||
| ` | ||
| f, err := os.CreateTemp("", "switchcase-*.ll") | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| defer f.Close() | ||
| defer os.Remove(f.Name()) | ||
| if _, err := f.WriteString(src); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if err := f.Close(); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| ctx := NewContext() | ||
| defer ctx.Dispose() | ||
|
|
||
| buf, err := NewMemoryBufferFromFile(f.Name()) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| m, err := ctx.ParseIR(buf) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| defer m.Dispose() | ||
|
|
||
| fn := m.NamedFunction("foo") | ||
| sw := fn.EntryBasicBlock().FirstInstruction() | ||
|
|
||
| if n := sw.SuccessorsCount(); n != 3 { | ||
| t.Fatalf("expected 3 successors (default + 2 cases), got %d", n) | ||
| } | ||
| if got := sw.Successor(0).AsValue().Name(); got != "default" { | ||
| t.Errorf("expected default destination %q, got %q", "default", got) | ||
| } | ||
|
|
||
| wantCaseValues := []uint64{0, 5} | ||
| wantCaseDests := []string{"case0", "case1"} | ||
| for i, want := range wantCaseValues { | ||
| successor := i + 1 | ||
| val := sw.GetSwitchCaseValue(successor) | ||
| if got := val.ZExtValue(); got != want { | ||
| t.Errorf("case %d: expected value %d, got %d", i, want, got) | ||
| } | ||
| if got := sw.Successor(successor).AsValue().Name(); got != wantCaseDests[i] { | ||
| t.Errorf("case %d: expected destination %q, got %q", i, wantCaseDests[i], got) | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.