aboutsummaryrefslogtreecommitdiffhomepage
path: root/transform
AgeCommit message (Collapse)Author
2024-01-31Allow larger systems to have a larger max stack allocDamian Gryski
Fixes #3331
2023-10-14builder: refactor clang include headersAyke van Laethem
Set -resource-dir in a central place instead of passing the header path around everywhere and adding it using the `-I` flag. I believe this is closer to how Clang is intended to be used. This change was inspired by my attempt to add a Nix flake file to TinyGo.
2023-10-04all: use the new LLVM pass managerAyke van Laethem
The old LLVM pass manager is deprecated and should not be used anymore. Moreover, the pass manager builder (which we used to set up a pass pipeline) is actually removed from LLVM entirely in LLVM 17: https://reviews.llvm.org/D145387 https://reviews.llvm.org/D145835 The new pass manager does change the binary size in many cases: both growing and shrinking it. However, on average the binary size remains more or less the same. This is needed as a preparation for LLVM 17.
2023-10-01all: remove LLVM 14 supportAyke van Laethem
This is a big change: apart from removing LLVM 14 it also removes typed pointer support (which was only fully supported in LLVM up to version 14). This removes about 200 lines of code, but more importantly removes a ton of special cases for LLVM 14.
2023-09-23transform: fix bug in StringToBytes optimization passAyke van Laethem
Previously, this pass would convert any read-only use of a runtime.stringToBytes call to use the original string buffer instead. This is incorrect: if there are any writes to the resulting buffer, none of the slice buffer pointers can be converted to use the original read-only string buffer. This commit fixes that bug and adds a test to prove the new (correct) behavior.
2023-06-17wasm: remove i64 workaround, use BigInt insteadAyke van Laethem
Browsers previously didn't support the WebAssembly i64 type, so we had to work around that limitation by converting the LLVM i64 type to something else. Some people used a pair of i32 values, but we used a pointer to a stack allocated i64. Now however, all major browsers and Node.js do support WebAssembly BigInt integration so that i64 values can be passed back and forth between WebAssembly and JavaScript easily. Therefore, I think the time has come to drop support for this workaround. For more information: https://v8.dev/features/wasm-bigint (note that TinyGo has used a slightly different way of passing i64 values between JS and Wasm). For information on browser support: https://webassembly.org/roadmap/
2023-06-09compiler,transform: fix for pointer-to-pointer type switches from @aykevlDamian Gryski
2023-03-22compiler: add alloc attributes to runtime.allocAyke van Laethem
This gives a small improvement now, and is needed to be able to use the Heap2Stack transform that's available in the Attributor pass. This Heap2Stack transform could replace our custom OptimizeAllocs pass. Most of the changes are just IR that changed, the actual change is relatively small. To give an example of why this is useful, here is the code size before this change: $ tinygo build -o test -size=short ./testdata/stdlib.go code data bss | flash ram 95620 1812 968 | 97432 2780 $ tinygo build -o test -size=short ./testdata/stdlib.go code data bss | flash ram 95380 1812 968 | 97192 2780 That's a 0.25% reduction. Not a whole lot, but nice for such a small patch.
2023-03-19transform: fix OptimizeReflectImplements pass for new named elem offsetDamian Gryski
2023-03-16transform: update wasm-abi to use opaque pointersAyke van Laethem
2023-03-16transform: update stringtobytes test to opaque pointersAyke van Laethem
2023-03-16transform: update stringequal test to opaque pointersAyke van Laethem
2023-03-16transform: update stacksize test to opaque pointersAyke van Laethem
2023-03-16transform: update panic test to opaque pointersAyke van Laethem
2023-03-16transform: update maps test to opaque pointersAyke van Laethem
2023-03-16transform: update interrupt test to opaque pointersAyke van Laethem
2023-03-16transform: update interface test to opaque pointersAyke van Laethem
2023-03-16transform: update gc-stackslots test to opaque pointersAyke van Laethem
2023-03-16transform: update allocs test to opaque pointersAyke van Laethem
Also, rename most of the SSA values while we're at it.
2023-03-16transform: update reflect-implements test to opaque pointersAyke van Laethem
2023-03-08transform: add debug information to internal/task.stackSizeAyke van Laethem
This has two benefits: 1. It attributes these bytes to the internal/task package (in -size=full), instead of (unknown). 2. It makes it possible to print the stack sizes variable in GDB. This is what it might look like in GDB: (gdb) p 'internal/task.stackSizes' $13 = {344, 120, 80, 2048, 360, 112, 80, 120, 2048, 2048}
2023-03-02transform: fix non-determinism in the interface lowering passAyke van Laethem
This non-determinism was introduced in https://github.com/tinygo-org/tinygo/pull/2640. Non-determinism in the compiler is a bug because it makes it harder to find whether a compiler change actually affected the binary. Fixes https://github.com/tinygo-org/tinygo/issues/3504
2023-02-26builder: remove non-ThinLTO build modeAyke van Laethem
All targets now support ThinLTO so let's remove the old unused code.
2023-02-17all: refactor reflect packageAyke van Laethem
This is a big commit that changes the way runtime type information is stored in the binary. Instead of compressing it and storing it in a number of sidetables, it is stored similar to how the Go compiler toolchain stores it (but still more compactly). This has a number of advantages: * It is much easier to add new features to reflect support. They can simply be added to these structs without requiring massive changes (especially in the reflect lowering pass). * It removes the reflect lowering pass, which was a large amount of hard to understand and debug code. * The reflect lowering pass also required merging all LLVM IR into one module, which is terrible for performance especially when compiling large amounts of code. See issue 2870 for details. * It is (probably!) easier to reason about for the compiler. The downside is that it increases code size a bit, especially when reflect is involved. I hope to fix some of that in later patches.
2022-11-18transform: remove duplicate if in gc transformDamian Gryski
2022-11-18avr: support ThinLTOAyke van Laethem
ThinLTO results in a small code size reduction, which is nice (especially on these very small chips). It also brings us one step closer to using ThinLTO everywhere.
2022-11-18compiler: refactor some code for the next commitAyke van Laethem
This is a pure refactor, it doesn't change the behavior of anything. It's separate from the next commit so that the actual changes are easier to read.
2022-11-04wasm: remove -wasm-abi= flagAyke van Laethem
This flag controls whether to convert external i64 parameters for use in a browser-like environment. This flag was needed in the past because back then we only supported wasm on browsers but no WASI. Now, I can't think of a reason why anybody would want to change the default. For `-target=wasm` (used for browser-like environments), the wasm_exec.js file expects this i64-via-stack ABI. For WASI, there is no limitation on i64 values and `-wasm-abi=generic` is the default.
2022-10-19ci: add support for LLVM 15Ayke van Laethem
This commit switches to LLVM 15 everywhere by default, while still keeping LLVM 14 support.
2022-10-19transform: fix memory corruption issuesAyke van Laethem
There was a bug in the wasm ABI lowering pass (found using AddressSanitizer on LLVM 15) that resulted in a rather subtle memory corruption. This commit fixes this issues.
2022-10-19all: remove pointer ElementType callsAyke van Laethem
This is needed for opaque pointers, which are enabled by default in LLVM 15.
2022-10-19all: replace llvm.Const* calls with builder.Create* callsAyke van Laethem
A number of llvm.Const* functions (in particular extractvalue and insertvalue) were removed in LLVM 15, so we have to use a builder instead. This builder will create the same constant values, it simply uses a different API.
2022-10-19all: add type parameter to *GEP callsAyke van Laethem
This is necessary for LLVM 15.
2022-10-19all: add type parameter to CreateLoadAyke van Laethem
This is needed for LLVM 15.
2022-10-19all: add type parameter to CreateCallAyke van Laethem
This uses LLVMBuildCall2 in the background, which is the replacement for the deprecated LLVMBuildCall function.
2022-10-19wasm: fix GC scanning of allocasAyke van Laethem
Scanning of allocas was entirely broken on WebAssembly. The code intended to do this was never run. There were also no tests. Looking into this further, I found that it is actually not really necessary to do that: the C stack can be scanned conservatively and in fact this was already done for goroutine stacks (because they live on the heap and are always referenced). It wasn't done for the system stack however. With these fixes, I believe code should be both faster *and* more correct. I found this in my work to get opaque pointers supported in LLVM 15, because the code that was never reached now finally got run and was actually quite buggy.
2022-09-15all: add flag for setting the goroutine stack sizeAyke van Laethem
This is helpful in some cases where the default stack size isn't big enough.
2022-08-07all: update _test.go files for ioutil changesDamian Gryski
2022-08-04all: format code according to Go 1.19 rulesAyke van Laethem
Go 1.19 started reformatting code in a way that makes it more obvious how it will be rendered on pkg.go.dev. It gets it almost right, but not entirely. Therefore, I had to modify some of the comments so that they are formatted correctly.
2022-06-11fix: fixes tinygo test ./... syntax.José Carlos Chávez
2022-06-10transform (MakeGCStackSlots): do not move the stack chain pop earlierNia Waldvogel
Previously, the MakeGCStackSlots pass would attempt to pop the stack chain before a tail call. This resulted in use-after-free bugs when the tail call allocated memory and used a value allocated by its caller. Instead of trying to move the stack chain pop, remove the tail flag from the call.
2022-06-01gc: drop support for 'precise' globalsAyke van Laethem
Precise globals require a whole program optimization pass that is hard to support when building packages separately. This patch removes support for these globals by converting the last use (Linux) to use linker-defined symbols instead. For details, see: https://github.com/tinygo-org/tinygo/issues/2870
2022-05-30transform: run OptimizeMaps during package optimizationsAyke van Laethem
This shrinks transform.Optimize() a little bit, working towards the goal of https://github.com/tinygo-org/tinygo/issues/2870. I ran the smoke tests and there is no practical downside: one test got smaller (??) and one had a different .hex hash, but other than that there was no difference. This should also make TinyGo a liiitle bit faster but it's probably not even measurable.
2022-05-30builder: move some code to transform packageAyke van Laethem
The transform package is the more appropriate location for package-level optimizations, to match `transform.Optimize` for whole-program optimizations. This is just a refactor, to make later changes easier to read.
2022-05-30builder: free LLVM objects after useAyke van Laethem
This reduces the TinyGo memory consumption when running make tinygo-test from 5.8GB to around 2GB on my laptop.
2022-05-07all: remove support for LLVM 11 and LLVM 12Ayke van Laethem
This removes a lot of backwards compatibility cruft and makes it possible to start using features that need LLVM 13 or newer. For example: * https://github.com/tinygo-org/tinygo/pull/2637 * https://github.com/tinygo-org/tinygo/pull/2830
2022-04-15transform: fix poison value in heap-to-stack transformAyke van Laethem
In https://github.com/tinygo-org/tinygo/issues/2777, a poison value ended up in `runtime.alloc`. This shouldn't happen, especially not for well written code. So I'm not sure why it happens. But here is a fix anyway.
2022-04-07compiler: fix difference in aliases in interface methodsAyke van Laethem
There used to be a difference between `byte` and `uint8` in interface methods. These are aliases, so they should be treated the same. This patch introduces a custom serialization format for types, circumventing the `Type.String()` method that is slightly wrong for our purposes. This also fixes an issue with the `any` keyword in Go 1.18, which suffers from the same problem (but this time actually leads to a crash).
2022-03-12all: add support for ThinLTOAyke van Laethem
ThinLTO optimizes across LLVM modules at link time. This means that optimizations (such as inlining and const-propagation) are possible between C and Go. This makes this change especially useful for CGo, but not just for CGo. By doing some optimizations at link time, the linker can discard some unused functions and this leads to a size reduction on average. It does increase code size in some cases, but that's true for most optimizations. I've excluded a number of targets for now (wasm, avr, xtensa, windows, macos). They can probably be supported with some more work, but that should be done in separate PRs. Overall, this change results in an average 3.24% size reduction over all the tinygo.org/x/drivers smoke tests. TODO: this commit runs part of the pass pipeline twice. We should set the PrepareForThinLTO flag in the PassManagerBuilder for even further reduced code size (0.7%) and improved compilation speed.
2022-02-11compiler: move allocations > 256 bytes to the heapDamian Gryski