diff options
author | Ayke van Laethem <[email protected]> | 2020-04-14 22:43:32 +0200 |
---|---|---|
committer | Ron Evans <[email protected]> | 2020-10-13 20:23:50 +0200 |
commit | b40f250530769330cec4a2ae0a9ba6e0c6ce058a (patch) | |
tree | 83736ddcb5df3c00ef0b95bb41482c9e77133c86 /transform | |
parent | 184175378f56e8ad03b6048fb40f5138e9710adb (diff) | |
download | tinygo-b40f250530769330cec4a2ae0a9ba6e0c6ce058a.tar.gz tinygo-b40f250530769330cec4a2ae0a9ba6e0c6ce058a.zip |
main: add initial support for (in-development) LLVM 11
This can be useful to test improvements in LLVM master and to make it
possible to support LLVM 11 for the most part already before the next
release. That also allows catching LLVM bugs early to fix them upstream.
Note that tests do not yet pass for this LLVM version, but the TinyGo
compiler can be built with the binaries from apt.llvm.org (at the time
of making this commit).
Diffstat (limited to 'transform')
-rw-r--r-- | transform/globals.go | 14 | ||||
-rw-r--r-- | transform/transform_test.go | 16 |
2 files changed, 28 insertions, 2 deletions
diff --git a/transform/globals.go b/transform/globals.go index 89386fd84..7a2968356 100644 --- a/transform/globals.go +++ b/transform/globals.go @@ -31,3 +31,17 @@ func NonConstGlobals(mod llvm.Module) { global = llvm.NextGlobal(global) } } + +// DisableTailCalls adds the "disable-tail-calls"="true" function attribute to +// all functions. This may be necessary, in particular to avoid an error with +// WebAssembly in LLVM 11. +func DisableTailCalls(mod llvm.Module) { + attribute := mod.Context().CreateStringAttribute("disable-tail-calls", "true") + llvmFn := mod.FirstFunction() + for !llvmFn.IsNil() { + if !llvmFn.IsDeclaration() { + llvmFn.AddFunctionAttr(attribute) + } + llvmFn = llvm.NextFunction(llvmFn) + } +} diff --git a/transform/transform_test.go b/transform/transform_test.go index 7a607f13b..28faf8681 100644 --- a/transform/transform_test.go +++ b/transform/transform_test.go @@ -61,6 +61,8 @@ func testTransform(t *testing.T, pathPrefix string, transform func(mod llvm.Modu } } +var alignRegexp = regexp.MustCompile(", align [0-9]+$") + // fuzzyEqualIR returns true if the two LLVM IR strings passed in are roughly // equal. That means, only relevant lines are compared (excluding comments // etc.). @@ -70,8 +72,18 @@ func fuzzyEqualIR(s1, s2 string) bool { if len(lines1) != len(lines2) { return false } - for i, line := range lines1 { - if line != lines2[i] { + for i, line1 := range lines1 { + line2 := lines2[i] + match1 := alignRegexp.MatchString(line1) + match2 := alignRegexp.MatchString(line2) + if match1 != match2 { + // Only one of the lines has the align keyword. Remove it. + // This is a change to make the test work in both LLVM 10 and LLVM + // 11 (LLVM 11 appears to automatically add alignment everywhere). + line1 = alignRegexp.ReplaceAllString(line1, "") + line2 = alignRegexp.ReplaceAllString(line2, "") + } + if line1 != line2 { return false } } |