aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2024-05-18 12:55:35 +0200
committerRon Evans <[email protected]>2024-05-24 19:12:26 +0200
commit81ce7fb738142361afba119f1f531cf6ffddc6d1 (patch)
tree68559a44ba49457b5ef9a5f2381fab1eae0276ff
parentc2776dcf78125abb86e3e7b4a110bb0d07386d09 (diff)
downloadtinygo-81ce7fb738142361afba119f1f531cf6ffddc6d1.tar.gz
tinygo-81ce7fb738142361afba119f1f531cf6ffddc6d1.zip
LLVM 18 support
-rw-r--r--.circleci/config.yml12
-rw-r--r--.github/workflows/build-macos.yml10
-rw-r--r--.github/workflows/linux.yml12
-rw-r--r--.github/workflows/llvm.yml4
-rw-r--r--.github/workflows/nix.yml2
-rwxr-xr-x.github/workflows/sizediff-install-pkgs.sh10
-rw-r--r--.github/workflows/sizediff.yml2
-rw-r--r--.github/workflows/windows.yml4
-rw-r--r--GNUmakefile8
-rw-r--r--builder/build.go2
-rw-r--r--builder/builtins.go12
-rw-r--r--builder/cc1as.cpp15
-rw-r--r--builder/cc1as.h2
-rw-r--r--builder/sizes_test.go6
-rw-r--r--cgo/libclang_config_llvm17.go2
-rw-r--r--cgo/libclang_config_llvm18.go15
-rw-r--r--compileopts/target.go6
-rw-r--r--compiler/asserts.go4
-rw-r--r--compiler/intrinsics.go10
-rw-r--r--compiler/llvm.go8
-rw-r--r--compiler/llvmutil/llvm.go13
-rw-r--r--compiler/testdata/channel.ll4
-rw-r--r--compiler/testdata/defer-cortex-m-qemu.ll6
-rw-r--r--compiler/testdata/gc.ll18
-rw-r--r--compiler/testdata/slice.ll4
-rw-r--r--compiler/testdata/zeromap.ll8
-rw-r--r--flake.nix2
-rw-r--r--go.mod2
-rw-r--r--go.sum4
-rw-r--r--src/runtime/runtime.go8
-rw-r--r--targets/esp32c3.json2
-rw-r--r--targets/fe310.json2
-rw-r--r--targets/k210.json2
-rw-r--r--targets/riscv-qemu.json2
-rw-r--r--transform/optimizer.go10
35 files changed, 139 insertions, 94 deletions
diff --git a/.circleci/config.yml b/.circleci/config.yml
index c9c9d6504..a94040606 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -10,12 +10,12 @@ commands:
steps:
- restore_cache:
keys:
- - llvm-source-17-v1
+ - llvm-source-18-v1
- run:
name: "Fetch LLVM source"
command: make llvm-source
- save_cache:
- key: llvm-source-17-v1
+ key: llvm-source-18-v1
paths:
- llvm-project/clang/lib/Headers
- llvm-project/clang/include
@@ -105,12 +105,12 @@ jobs:
- test-linux:
llvm: "15"
resource_class: large
- test-llvm17-go122:
+ test-llvm18-go122:
docker:
- image: golang:1.22-bullseye
steps:
- test-linux:
- llvm: "17"
+ llvm: "18"
resource_class: large
workflows:
@@ -119,5 +119,5 @@ workflows:
# This tests our lowest supported versions of Go and LLVM, to make sure at
# least the smoke tests still pass.
- test-llvm15-go118
- # This tests LLVM 17 support when linking against system libraries.
- - test-llvm17-go122
+ # This tests LLVM 18 support when linking against system libraries.
+ - test-llvm18-go122
diff --git a/.github/workflows/build-macos.yml b/.github/workflows/build-macos.yml
index 1fefa27bf..7acd2e5b7 100644
--- a/.github/workflows/build-macos.yml
+++ b/.github/workflows/build-macos.yml
@@ -43,7 +43,7 @@ jobs:
uses: actions/cache/restore@v4
id: cache-llvm-source
with:
- key: llvm-source-17-${{ matrix.os }}-v2
+ key: llvm-source-18-${{ matrix.os }}-v2
path: |
llvm-project/clang/lib/Headers
llvm-project/clang/include
@@ -68,7 +68,7 @@ jobs:
uses: actions/cache/restore@v4
id: cache-llvm-build
with:
- key: llvm-build-17-${{ matrix.os }}-v2
+ key: llvm-build-18-${{ matrix.os }}-v2
path: llvm-build
- name: Build LLVM
if: steps.cache-llvm-build.outputs.cache-hit != 'true'
@@ -128,7 +128,7 @@ jobs:
runs-on: macos-latest
strategy:
matrix:
- version: [16, 17]
+ version: [16, 17, 18]
steps:
- name: Set up Homebrew
uses: Homebrew/actions/setup-homebrew@master
@@ -152,8 +152,8 @@ jobs:
- name: Check binary
run: tinygo version
- name: Build TinyGo (default LLVM)
- if: matrix.version == 17
+ if: matrix.version == 18
run: go install
- name: Check binary
- if: matrix.version == 17
+ if: matrix.version == 18
run: tinygo version
diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml
index c1529aa8a..38f0d92f5 100644
--- a/.github/workflows/linux.yml
+++ b/.github/workflows/linux.yml
@@ -43,7 +43,7 @@ jobs:
uses: actions/cache/restore@v4
id: cache-llvm-source
with:
- key: llvm-source-17-linux-alpine-v2
+ key: llvm-source-18-linux-alpine-v1
path: |
llvm-project/clang/lib/Headers
llvm-project/clang/include
@@ -68,7 +68,7 @@ jobs:
uses: actions/cache/restore@v4
id: cache-llvm-build
with:
- key: llvm-build-17-linux-alpine-v2
+ key: llvm-build-18-linux-alpine-v1
path: llvm-build
- name: Build LLVM
if: steps.cache-llvm-build.outputs.cache-hit != 'true'
@@ -196,7 +196,7 @@ jobs:
uses: actions/cache/restore@v4
id: cache-llvm-source
with:
- key: llvm-source-17-linux-asserts-v2
+ key: llvm-source-18-linux-asserts-v1
path: |
llvm-project/clang/lib/Headers
llvm-project/clang/include
@@ -221,7 +221,7 @@ jobs:
uses: actions/cache/restore@v4
id: cache-llvm-build
with:
- key: llvm-build-17-linux-asserts-v2
+ key: llvm-build-18-linux-asserts-v1
path: llvm-build
- name: Build LLVM
if: steps.cache-llvm-build.outputs.cache-hit != 'true'
@@ -309,7 +309,7 @@ jobs:
uses: actions/cache/restore@v4
id: cache-llvm-source
with:
- key: llvm-source-17-linux-v2
+ key: llvm-source-18-linux-v1
path: |
llvm-project/clang/lib/Headers
llvm-project/clang/include
@@ -334,7 +334,7 @@ jobs:
uses: actions/cache/restore@v4
id: cache-llvm-build
with:
- key: llvm-build-17-linux-${{ matrix.goarch }}-v2
+ key: llvm-build-18-linux-${{ matrix.goarch }}-v1
path: llvm-build
- name: Build LLVM
if: steps.cache-llvm-build.outputs.cache-hit != 'true'
diff --git a/.github/workflows/llvm.yml b/.github/workflows/llvm.yml
index d7fd574df..f97646f7b 100644
--- a/.github/workflows/llvm.yml
+++ b/.github/workflows/llvm.yml
@@ -35,8 +35,8 @@ jobs:
uses: docker/metadata-action@v5
with:
images: |
- tinygo/llvm-17
- ghcr.io/${{ github.repository_owner }}/llvm-17
+ tinygo/llvm-18
+ ghcr.io/${{ github.repository_owner }}/llvm-18
tags: |
type=sha,format=long
type=raw,value=latest
diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml
index 2eae94fc0..62da55672 100644
--- a/.github/workflows/nix.yml
+++ b/.github/workflows/nix.yml
@@ -24,7 +24,7 @@ jobs:
uses: actions/cache/restore@v4
id: cache-llvm-source
with:
- key: llvm-source-17-linux-nix-v2
+ key: llvm-source-18-linux-nix-v1
path: |
llvm-project/compiler-rt
- name: Download LLVM source
diff --git a/.github/workflows/sizediff-install-pkgs.sh b/.github/workflows/sizediff-install-pkgs.sh
index ce51d4d36..31edc5750 100755
--- a/.github/workflows/sizediff-install-pkgs.sh
+++ b/.github/workflows/sizediff-install-pkgs.sh
@@ -2,11 +2,11 @@
# still works after checking out the dev branch (that is, when going from LLVM
# 16 to LLVM 17 for example, both Clang 16 and Clang 17 are installed).
-echo 'deb https://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main' | sudo tee /etc/apt/sources.list.d/llvm.list
+echo 'deb https://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 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 -y \
- llvm-17-dev \
- clang-17 \
- libclang-17-dev \
- lld-17
+ llvm-18-dev \
+ clang-18 \
+ libclang-18-dev \
+ lld-18
diff --git a/.github/workflows/sizediff.yml b/.github/workflows/sizediff.yml
index 4146673ae..5dac15409 100644
--- a/.github/workflows/sizediff.yml
+++ b/.github/workflows/sizediff.yml
@@ -28,7 +28,7 @@ jobs:
uses: actions/cache@v4
id: cache-llvm-source
with:
- key: llvm-source-17-sizediff-v2
+ key: llvm-source-18-sizediff-v1
path: |
llvm-project/compiler-rt
- name: Download LLVM source
diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml
index 013ff1a27..5cfba9217 100644
--- a/.github/workflows/windows.yml
+++ b/.github/workflows/windows.yml
@@ -41,7 +41,7 @@ jobs:
uses: actions/cache/restore@v4
id: cache-llvm-source
with:
- key: llvm-source-17-windows-v2
+ key: llvm-source-18-windows-v1
path: |
llvm-project/clang/lib/Headers
llvm-project/clang/include
@@ -66,7 +66,7 @@ jobs:
uses: actions/cache/restore@v4
id: cache-llvm-build
with:
- key: llvm-build-17-windows-v2
+ key: llvm-build-18-windows-v1
path: llvm-build
- name: Build LLVM
if: steps.cache-llvm-build.outputs.cache-hit != 'true'
diff --git a/GNUmakefile b/GNUmakefile
index 5454896bf..ce833c656 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -10,7 +10,7 @@ LLD_SRC ?= $(LLVM_PROJECTDIR)/lld
# Try to autodetect LLVM build tools.
# Versions are listed here in descending priority order.
-LLVM_VERSIONS = 17 16 15
+LLVM_VERSIONS = 18 17 16 15
errifempty = $(if $(1),$(1),$(error $(2)))
detect = $(shell which $(call errifempty,$(firstword $(foreach p,$(2),$(shell command -v $(p) 2> /dev/null && echo $(p)))),failed to locate $(1) at any of: $(2)))
toolSearchPathsVersion = $(1)-$(2)
@@ -111,7 +111,7 @@ endif
.PHONY: all tinygo test $(LLVM_BUILDDIR) llvm-source clean fmt gen-device gen-device-nrf gen-device-nxp gen-device-avr gen-device-rp
-LLVM_COMPONENTS = all-targets analysis asmparser asmprinter bitreader bitwriter codegen core coroutines coverage debuginfodwarf debuginfopdb executionengine frontendhlsl frontendopenmp instrumentation interpreter ipo irreader libdriver linker lto mc mcjit objcarcopts option profiledata scalaropts support target windowsdriver windowsmanifest
+LLVM_COMPONENTS = all-targets analysis asmparser asmprinter bitreader bitwriter codegen core coroutines coverage debuginfodwarf debuginfopdb executionengine frontenddriver frontendhlsl frontendopenmp instrumentation interpreter ipo irreader libdriver linker lto mc mcjit objcarcopts option profiledata scalaropts support target windowsdriver windowsmanifest
ifeq ($(OS),Windows_NT)
EXE = .exe
@@ -147,7 +147,7 @@ endif
MD5SUM ?= md5sum
# Libraries that should be linked in for the statically linked Clang.
-CLANG_LIB_NAMES = clangAnalysis clangAST clangASTMatchers clangBasic clangCodeGen clangCrossTU clangDriver clangDynamicASTMatchers clangEdit clangExtractAPI clangFormat clangFrontend clangFrontendTool clangHandleCXX clangHandleLLVM clangIndex clangLex clangParse clangRewrite clangRewriteFrontend clangSema clangSerialization clangSupport clangTooling clangToolingASTDiff clangToolingCore clangToolingInclusions
+CLANG_LIB_NAMES = clangAnalysis clangAPINotes clangAST clangASTMatchers clangBasic clangCodeGen clangCrossTU clangDriver clangDynamicASTMatchers clangEdit clangExtractAPI clangFormat clangFrontend clangFrontendTool clangHandleCXX clangHandleLLVM clangIndex clangLex clangParse clangRewrite clangRewriteFrontend clangSema clangSerialization clangSupport clangTooling clangToolingASTDiff clangToolingCore clangToolingInclusions
CLANG_LIBS = $(START_GROUP) $(addprefix -l,$(CLANG_LIB_NAMES)) $(END_GROUP) -lstdc++
# Libraries that should be linked in for the statically linked LLD.
@@ -239,7 +239,7 @@ gen-device-renesas: build/gen-device-svd
# Get LLVM sources.
$(LLVM_PROJECTDIR)/llvm:
- git clone -b esp-17.0.1_20240419 --depth=1 https://github.com/espressif/llvm-project $(LLVM_PROJECTDIR)
+ git clone -b tinygo_xtensa_release_18.1.2 --depth=1 https://github.com/tinygo-org/llvm-project $(LLVM_PROJECTDIR)
llvm-source: $(LLVM_PROJECTDIR)/llvm
# Configure LLVM.
diff --git a/builder/build.go b/builder/build.go
index 5a6683ae6..940439667 100644
--- a/builder/build.go
+++ b/builder/build.go
@@ -773,7 +773,7 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe
if sizeLevel >= 2 {
// Workaround with roughly the same effect as
// https://reviews.llvm.org/D119342.
- // Can hopefully be removed in LLVM 18.
+ // Can hopefully be removed in LLVM 19.
ldflags = append(ldflags,
"-mllvm", "--rotation-max-header-size=0")
}
diff --git a/builder/builtins.go b/builder/builtins.go
index a1066b671..0dbfc42a0 100644
--- a/builder/builtins.go
+++ b/builder/builtins.go
@@ -8,14 +8,14 @@ import (
"github.com/tinygo-org/tinygo/goenv"
)
-// These are the GENERIC_SOURCES according to CMakeList.txt.
+// These are the GENERIC_SOURCES according to CMakeList.txt except for
+// divmodsi4.c and udivmodsi4.c.
var genericBuiltins = []string{
"absvdi2.c",
"absvsi2.c",
"absvti2.c",
"adddf3.c",
"addsf3.c",
- "addtf3.c",
"addvdi3.c",
"addvsi3.c",
"addvti3.c",
@@ -40,12 +40,12 @@ var genericBuiltins = []string{
"divdf3.c",
"divdi3.c",
"divmoddi4.c",
+ //"divmodsi4.c",
+ "divmodti4.c",
"divsc3.c",
"divsf3.c",
"divsi3.c",
- "divtc3.c",
"divti3.c",
- "divtf3.c",
"extendsfdf2.c",
"extendhfsf2.c",
"ffsdi2.c",
@@ -91,7 +91,6 @@ var genericBuiltins = []string{
"mulsc3.c",
"mulsf3.c",
"multi3.c",
- "multf3.c",
"mulvdi3.c",
"mulvsi3.c",
"mulvti3.c",
@@ -111,13 +110,11 @@ var genericBuiltins = []string{
"popcountti2.c",
"powidf2.c",
"powisf2.c",
- "powitf2.c",
"subdf3.c",
"subsf3.c",
"subvdi3.c",
"subvsi3.c",
"subvti3.c",
- "subtf3.c",
"trampoline_setup.c",
"truncdfhf2.c",
"truncdfsf2.c",
@@ -126,6 +123,7 @@ var genericBuiltins = []string{
"ucmpti2.c",
"udivdi3.c",
"udivmoddi4.c",
+ //"udivmodsi4.c",
"udivmodti4.c",
"udivsi3.c",
"udivti3.c",
diff --git a/builder/cc1as.cpp b/builder/cc1as.cpp
index 9f9e377fa..e489866ec 100644
--- a/builder/cc1as.cpp
+++ b/builder/cc1as.cpp
@@ -82,10 +82,10 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
// Parse the arguments.
const OptTable &OptTbl = getDriverOptTable();
- const unsigned IncludedFlagsBitmask = options::CC1AsOption;
+ llvm::opt::Visibility VisibilityMask(options::CC1AsOption);
unsigned MissingArgIndex, MissingArgCount;
- InputArgList Args = OptTbl.ParseArgs(Argv, MissingArgIndex, MissingArgCount,
- IncludedFlagsBitmask);
+ InputArgList Args =
+ OptTbl.ParseArgs(Argv, MissingArgIndex, MissingArgCount, VisibilityMask);
// Check for missing argument error.
if (MissingArgCount) {
@@ -98,7 +98,7 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
for (const Arg *A : Args.filtered(OPT_UNKNOWN)) {
auto ArgString = A->getAsString(Args);
std::string Nearest;
- if (OptTbl.findNearest(ArgString, Nearest, IncludedFlagsBitmask) > 1)
+ if (OptTbl.findNearest(ArgString, Nearest, VisibilityMask) > 1)
Diags.Report(diag::err_drv_unknown_argument) << ArgString;
else
Diags.Report(diag::err_drv_unknown_argument_with_suggestion)
@@ -521,9 +521,10 @@ int cc1as_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
if (Asm.ShowHelp) {
getDriverOptTable().printHelp(
llvm::outs(), "clang -cc1as [options] file...",
- "Clang Integrated Assembler",
- /*Include=*/driver::options::CC1AsOption, /*Exclude=*/0,
- /*ShowAllAliases=*/false);
+ "Clang Integrated Assembler", /*ShowHidden=*/false,
+ /*ShowAllAliases=*/false,
+ llvm::opt::Visibility(driver::options::CC1AsOption));
+
return 0;
}
diff --git a/builder/cc1as.h b/builder/cc1as.h
index 423a916a3..4b22fc3e8 100644
--- a/builder/cc1as.h
+++ b/builder/cc1as.h
@@ -93,7 +93,7 @@ struct AssemblerInvocation {
EmitDwarfUnwindType EmitDwarfUnwind;
// Whether to emit compact-unwind for non-canonical entries.
- // Note: may be overridden by other constraints.
+ // Note: maybe overriden by other constraints.
unsigned EmitCompactUnwindNonCanonical : 1;
/// The name of the relocation model to use.
diff --git a/builder/sizes_test.go b/builder/sizes_test.go
index 429e3f3e9..9755abe81 100644
--- a/builder/sizes_test.go
+++ b/builder/sizes_test.go
@@ -41,9 +41,9 @@ func TestBinarySize(t *testing.T) {
// This is a small number of very diverse targets that we want to test.
tests := []sizeTest{
// microcontrollers
- {"hifive1b", "examples/echo", 4476, 280, 0, 2252},
- {"microbit", "examples/serial", 2724, 388, 8, 2256},
- {"wioterminal", "examples/pininterrupt", 5996, 1484, 116, 6816},
+ {"hifive1b", "examples/echo", 4484, 280, 0, 2252},
+ {"microbit", "examples/serial", 2732, 388, 8, 2256},
+ {"wioterminal", "examples/pininterrupt", 6016, 1484, 116, 6816},
// TODO: also check wasm. Right now this is difficult, because
// wasm binaries are run through wasm-opt and therefore the
diff --git a/cgo/libclang_config_llvm17.go b/cgo/libclang_config_llvm17.go
index c17cca09b..6395d8a3a 100644
--- a/cgo/libclang_config_llvm17.go
+++ b/cgo/libclang_config_llvm17.go
@@ -1,4 +1,4 @@
-//go:build !byollvm && !llvm15 && !llvm16
+//go:build !byollvm && llvm17
package cgo
diff --git a/cgo/libclang_config_llvm18.go b/cgo/libclang_config_llvm18.go
new file mode 100644
index 000000000..3b769c622
--- /dev/null
+++ b/cgo/libclang_config_llvm18.go
@@ -0,0 +1,15 @@
+//go:build !byollvm && !llvm15 && !llvm16 && !llvm17
+
+package cgo
+
+/*
+#cgo linux CFLAGS: -I/usr/include/llvm-18 -I/usr/include/llvm-c-18 -I/usr/lib/llvm-18/include
+#cgo darwin,amd64 CFLAGS: -I/usr/local/opt/llvm@18/include
+#cgo darwin,arm64 CFLAGS: -I/opt/homebrew/opt/llvm@18/include
+#cgo freebsd CFLAGS: -I/usr/local/llvm18/include
+#cgo linux LDFLAGS: -L/usr/lib/llvm-18/lib -lclang
+#cgo darwin,amd64 LDFLAGS: -L/usr/local/opt/llvm@18/lib -lclang
+#cgo darwin,arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@18/lib -lclang
+#cgo freebsd LDFLAGS: -L/usr/local/llvm18/lib -lclang
+*/
+import "C"
diff --git a/compileopts/target.go b/compileopts/target.go
index da91cfa4f..9a7d550fa 100644
--- a/compileopts/target.go
+++ b/compileopts/target.go
@@ -319,11 +319,11 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) {
case "arm64":
spec.CPU = "generic"
if goos == "darwin" {
- spec.Features = "+neon"
+ spec.Features = "+fp-armv8,+neon"
} else if goos == "windows" {
- spec.Features = "+neon,-fmv"
+ spec.Features = "+fp-armv8,+neon,-fmv"
} else { // linux
- spec.Features = "+neon,-fmv,-outline-atomics"
+ spec.Features = "+fp-armv8,+neon,-fmv,-outline-atomics"
}
case "wasm":
spec.CPU = "generic"
diff --git a/compiler/asserts.go b/compiler/asserts.go
index 0fb112e0b..035fda616 100644
--- a/compiler/asserts.go
+++ b/compiler/asserts.go
@@ -135,7 +135,7 @@ func (b *builder) createChanBoundsCheck(elementSize uint64, bufSize llvm.Value,
// Calculate (^uintptr(0)) >> 1, which is the max value that fits in an
// uintptr if uintptrs were signed.
- maxBufSize := llvm.ConstLShr(llvm.ConstNot(llvm.ConstInt(b.uintptrType, 0, false)), llvm.ConstInt(b.uintptrType, 1, false))
+ maxBufSize := b.CreateLShr(llvm.ConstNot(llvm.ConstInt(b.uintptrType, 0, false)), llvm.ConstInt(b.uintptrType, 1, false), "")
if elementSize > maxBufSize.ZExtValue() {
b.addError(pos, fmt.Sprintf("channel element type is too big (%v bytes)", elementSize))
return
@@ -150,7 +150,7 @@ func (b *builder) createChanBoundsCheck(elementSize uint64, bufSize llvm.Value,
// Make sure maxBufSize has the same type as bufSize.
if maxBufSize.Type() != bufSize.Type() {
- maxBufSize = llvm.ConstZExt(maxBufSize, bufSize.Type())
+ maxBufSize = b.CreateZExt(maxBufSize, bufSize.Type(), "")
}
// Do the check for a too large (or negative) buffer size.
diff --git a/compiler/intrinsics.go b/compiler/intrinsics.go
index c1d05348b..3c7edd7c9 100644
--- a/compiler/intrinsics.go
+++ b/compiler/intrinsics.go
@@ -23,6 +23,8 @@ func (b *builder) defineIntrinsicFunction() {
b.createMemoryCopyImpl()
case name == "runtime.memzero":
b.createMemoryZeroImpl()
+ case name == "runtime.stacksave":
+ b.createStackSaveImpl()
case name == "runtime.KeepAlive":
b.createKeepAliveImpl()
case strings.HasPrefix(name, "runtime/volatile.Load"):
@@ -77,6 +79,14 @@ func (b *builder) createMemoryZeroImpl() {
b.CreateRetVoid()
}
+// createStackSaveImpl creates a call to llvm.stacksave.p0 to read the current
+// stack pointer.
+func (b *builder) createStackSaveImpl() {
+ b.createFunctionStart(true)
+ sp := b.readStackPointer()
+ b.CreateRet(sp)
+}
+
// Return the llvm.memset.p0.i8 function declaration.
func (c *compilerContext) getMemsetFunc() llvm.Value {
fnName := "llvm.memset.p0.i" + strconv.Itoa(c.uintptrType.IntTypeWidth())
diff --git a/compiler/llvm.go b/compiler/llvm.go
index 968d28b88..d693f6ed7 100644
--- a/compiler/llvm.go
+++ b/compiler/llvm.go
@@ -451,10 +451,14 @@ func (c *compilerContext) isThumb() bool {
// readStackPointer emits a LLVM intrinsic call that returns the current stack
// pointer as an *i8.
func (b *builder) readStackPointer() llvm.Value {
- stacksave := b.mod.NamedFunction("llvm.stacksave")
+ name := "llvm.stacksave.p0"
+ if llvmutil.Version() < 18 {
+ name = "llvm.stacksave" // backwards compatibility with LLVM 17 and below
+ }
+ stacksave := b.mod.NamedFunction(name)
if stacksave.IsNil() {
fnType := llvm.FunctionType(b.dataPtrType, nil, false)
- stacksave = llvm.AddFunction(b.mod, "llvm.stacksave", fnType)
+ stacksave = llvm.AddFunction(b.mod, name, fnType)
}
return b.CreateCall(stacksave.GlobalValueType(), stacksave, nil, "")
}
diff --git a/compiler/llvmutil/llvm.go b/compiler/llvmutil/llvm.go
index d4ceee3fb..48fddffbe 100644
--- a/compiler/llvmutil/llvm.go
+++ b/compiler/llvmutil/llvm.go
@@ -8,6 +8,9 @@
package llvmutil
import (
+ "strconv"
+ "strings"
+
"tinygo.org/x/go-llvm"
)
@@ -203,3 +206,13 @@ func AppendToGlobal(mod llvm.Module, globalName string, values ...llvm.Value) {
used.SetInitializer(usedInitializer)
used.SetLinkage(llvm.AppendingLinkage)
}
+
+// Return the LLVM major version.
+func Version() int {
+ majorStr := strings.Split(llvm.Version, ".")[0]
+ major, err := strconv.Atoi(majorStr)
+ if err != nil {
+ panic("unexpected error while parsing LLVM version: " + err.Error()) // should not happen
+ }
+ return major
+}
diff --git a/compiler/testdata/channel.ll b/compiler/testdata/channel.ll
index be769e859..65e18dea8 100644
--- a/compiler/testdata/channel.ll
+++ b/compiler/testdata/channel.ll
@@ -81,11 +81,11 @@ entry:
%select.send.value = alloca i32, align 4
store i32 1, ptr %select.send.value, align 4
call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %select.states.alloca)
- store ptr %ch1, ptr %select.states.alloca, align 8
+ store ptr %ch1, ptr %select.states.alloca, align 4
%select.states.alloca.repack1 = getelementptr inbounds %runtime.chanSelectState, ptr %select.states.alloca, i32 0, i32 1
store ptr %select.send.value, ptr %select.states.alloca.repack1, align 4
%0 = getelementptr inbounds [2 x %runtime.chanSelectState], ptr %select.states.alloca, i32 0, i32 1
- store ptr %ch2, ptr %0, align 8
+ store ptr %ch2, ptr %0, align 4
%.repack3 = getelementptr inbounds [2 x %runtime.chanSelectState], ptr %select.states.alloca, i32 0, i32 1, i32 1
store ptr null, ptr %.repack3, align 4
%select.result = call { i32, i1 } @runtime.tryChanSelect(ptr undef, ptr nonnull %select.states.alloca, i32 2, i32 2, ptr undef) #4
diff --git a/compiler/testdata/defer-cortex-m-qemu.ll b/compiler/testdata/defer-cortex-m-qemu.ll
index 32697ccd5..52a3bfbab 100644
--- a/compiler/testdata/defer-cortex-m-qemu.ll
+++ b/compiler/testdata/defer-cortex-m-qemu.ll
@@ -25,7 +25,7 @@ entry:
%deferPtr = alloca ptr, align 4
store ptr null, ptr %deferPtr, align 4
%deferframe.buf = alloca %runtime.deferFrame, align 4
- %0 = call ptr @llvm.stacksave()
+ %0 = call ptr @llvm.stacksave.p0()
call void @runtime.setupDeferFrame(ptr nonnull %deferframe.buf, ptr %0, ptr undef) #4
store i32 0, ptr %defer.alloca, align 4
%defer.alloca.repack15 = getelementptr inbounds { i32, ptr }, ptr %defer.alloca, i32 0, i32 1
@@ -113,7 +113,7 @@ rundefers.end3: ; preds = %rundefers.loophead6
}
; Function Attrs: nocallback nofree nosync nounwind willreturn
-declare ptr @llvm.stacksave() #3
+declare ptr @llvm.stacksave.p0() #3
declare void @runtime.setupDeferFrame(ptr dereferenceable_or_null(24), ptr, ptr) #2
@@ -136,7 +136,7 @@ entry:
%deferPtr = alloca ptr, align 4
store ptr null, ptr %deferPtr, align 4
%deferframe.buf = alloca %runtime.deferFrame, align 4
- %0 = call ptr @llvm.stacksave()
+ %0 = call ptr @llvm.stacksave.p0()
call void @runtime.setupDeferFrame(ptr nonnull %deferframe.buf, ptr %0, ptr undef) #4
store i32 0, ptr %defer.alloca, align 4
%defer.alloca.repack22 = getelementptr inbounds { i32, ptr }, ptr %defer.alloca, i32 0, i32 1
diff --git a/compiler/testdata/gc.ll b/compiler/testdata/gc.ll
index de638dad2..a696ee409 100644
--- a/compiler/testdata/gc.ll
+++ b/compiler/testdata/gc.ll
@@ -16,9 +16,9 @@ target triple = "wasm32-unknown-wasi"
@main.struct2 = hidden global ptr null, align 4
@main.struct3 = hidden global ptr null, align 4
@main.struct4 = hidden global ptr null, align 4
[email protected] = hidden global { ptr, i32, i32 } zeroinitializer, align 8
[email protected] = hidden global { ptr, i32, i32 } zeroinitializer, align 8
[email protected] = hidden global { ptr, i32, i32 } zeroinitializer, align 8
[email protected] = hidden global { ptr, i32, i32 } zeroinitializer, align 4
[email protected] = hidden global { ptr, i32, i32 } zeroinitializer, align 4
[email protected] = hidden global { ptr, i32, i32 } zeroinitializer, align 4
@"runtime/gc.layout:62-2000000000000001" = linkonce_odr unnamed_addr constant { i32, [8 x i8] } { i32 62, [8 x i8] c"\01\00\00\00\00\00\00 " }
@"runtime/gc.layout:62-0001" = linkonce_odr unnamed_addr constant { i32, [8 x i8] } { i32 62, [8 x i8] c"\01\00\00\00\00\00\00\00" }
@"reflect/types.type:basic:complex128" = linkonce_odr constant { i8, ptr } { i8 80, ptr @"reflect/types.type:pointer:basic:complex128" }, align 4
@@ -104,19 +104,19 @@ entry:
%stackalloc = alloca i8, align 1
%makeslice = call dereferenceable(5) ptr @runtime.alloc(i32 5, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #3
call void @runtime.trackPointer(ptr nonnull %makeslice, ptr nonnull %stackalloc, ptr undef) #3
- store ptr %makeslice, ptr @main.slice1, align 8
+ store ptr %makeslice, ptr @main.slice1, align 4
store i32 5, ptr getelementptr inbounds ({ ptr, i32, i32 }, ptr @main.slice1, i32 0, i32 1), align 4
- store i32 5, ptr getelementptr inbounds ({ ptr, i32, i32 }, ptr @main.slice1, i32 0, i32 2), align 8
+ store i32 5, ptr getelementptr inbounds ({ ptr, i32, i32 }, ptr @main.slice1, i32 0, i32 2), align 4
%makeslice1 = call dereferenceable(20) ptr @runtime.alloc(i32 20, ptr nonnull inttoptr (i32 67 to ptr), ptr undef) #3
call void @runtime.trackPointer(ptr nonnull %makeslice1, ptr nonnull %stackalloc, ptr undef) #3
- store ptr %makeslice1, ptr @main.slice2, align 8
+ store ptr %makeslice1, ptr @main.slice2, align 4
store i32 5, ptr getelementptr inbounds ({ ptr, i32, i32 }, ptr @main.slice2, i32 0, i32 1), align 4
- store i32 5, ptr getelementptr inbounds ({ ptr, i32, i32 }, ptr @main.slice2, i32 0, i32 2), align 8
+ store i32 5, ptr getelementptr inbounds ({ ptr, i32, i32 }, ptr @main.slice2, i32 0, i32 2), align 4
%makeslice3 = call dereferenceable(60) ptr @runtime.alloc(i32 60, ptr nonnull inttoptr (i32 71 to ptr), ptr undef) #3
call void @runtime.trackPointer(ptr nonnull %makeslice3, ptr nonnull %stackalloc, ptr undef) #3
- store ptr %makeslice3, ptr @main.slice3, align 8
+ store ptr %makeslice3, ptr @main.slice3, align 4
store i32 5, ptr getelementptr inbounds ({ ptr, i32, i32 }, ptr @main.slice3, i32 0, i32 1), align 4
- store i32 5, ptr getelementptr inbounds ({ ptr, i32, i32 }, ptr @main.slice3, i32 0, i32 2), align 8
+ store i32 5, ptr getelementptr inbounds ({ ptr, i32, i32 }, ptr @main.slice3, i32 0, i32 2), align 4
ret void
}
diff --git a/compiler/testdata/slice.ll b/compiler/testdata/slice.ll
index bc0198741..29d5ed8a4 100644
--- a/compiler/testdata/slice.ll
+++ b/compiler/testdata/slice.ll
@@ -122,7 +122,7 @@ entry:
br i1 %slice.maxcap, label %slice.throw, label %slice.next
slice.next: ; preds = %entry
- %makeslice.cap = shl i32 %len, 1
+ %makeslice.cap = shl nuw i32 %len, 1
%makeslice.buf = call ptr @runtime.alloc(i32 %makeslice.cap, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #3
%0 = insertvalue { ptr, i32, i32 } undef, ptr %makeslice.buf, 0
%1 = insertvalue { ptr, i32, i32 } %0, i32 %len, 1
@@ -164,7 +164,7 @@ entry:
br i1 %slice.maxcap, label %slice.throw, label %slice.next
slice.next: ; preds = %entry
- %makeslice.cap = shl i32 %len, 2
+ %makeslice.cap = shl nuw i32 %len, 2
%makeslice.buf = call ptr @runtime.alloc(i32 %makeslice.cap, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #3
%0 = insertvalue { ptr, i32, i32 } undef, ptr %makeslice.buf, 0
%1 = insertvalue { ptr, i32, i32 } %0, i32 %len, 1
diff --git a/compiler/testdata/zeromap.ll b/compiler/testdata/zeromap.ll
index 510010dbe..4ad263130 100644
--- a/compiler/testdata/zeromap.ll
+++ b/compiler/testdata/zeromap.ll
@@ -26,7 +26,7 @@ entry:
%2 = insertvalue %main.hasPadding %1, i1 %s.b2, 2
call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %hashmap.value)
call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %hashmap.key)
- store %main.hasPadding %2, ptr %hashmap.key, align 8
+ store %main.hasPadding %2, ptr %hashmap.key, align 4
%3 = getelementptr inbounds i8, ptr %hashmap.key, i32 1
call void @runtime.memzero(ptr nonnull %3, i32 3, ptr undef) #5
%4 = getelementptr inbounds i8, ptr %hashmap.key, i32 9
@@ -59,7 +59,7 @@ entry:
call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %hashmap.value)
store i32 5, ptr %hashmap.value, align 4
call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %hashmap.key)
- store %main.hasPadding %2, ptr %hashmap.key, align 8
+ store %main.hasPadding %2, ptr %hashmap.key, align 4
%3 = getelementptr inbounds i8, ptr %hashmap.key, i32 1
call void @runtime.memzero(ptr nonnull %3, i32 3, ptr undef) #5
%4 = getelementptr inbounds i8, ptr %hashmap.key, i32 9
@@ -80,7 +80,7 @@ entry:
call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %hashmap.value)
call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %hashmap.key)
%s.elt = extractvalue [2 x %main.hasPadding] %s, 0
- store %main.hasPadding %s.elt, ptr %hashmap.key, align 8
+ store %main.hasPadding %s.elt, ptr %hashmap.key, align 4
%hashmap.key.repack1 = getelementptr inbounds [2 x %main.hasPadding], ptr %hashmap.key, i32 0, i32 1
%s.elt2 = extractvalue [2 x %main.hasPadding] %s, 1
store %main.hasPadding %s.elt2, ptr %hashmap.key.repack1, align 4
@@ -108,7 +108,7 @@ entry:
store i32 5, ptr %hashmap.value, align 4
call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %hashmap.key)
%s.elt = extractvalue [2 x %main.hasPadding] %s, 0
- store %main.hasPadding %s.elt, ptr %hashmap.key, align 8
+ store %main.hasPadding %s.elt, ptr %hashmap.key, align 4
%hashmap.key.repack1 = getelementptr inbounds [2 x %main.hasPadding], ptr %hashmap.key, i32 0, i32 1
%s.elt2 = extractvalue [2 x %main.hasPadding] %s, 1
store %main.hasPadding %s.elt2, ptr %hashmap.key.repack1, align 4
diff --git a/flake.nix b/flake.nix
index 60c2b2534..9ba327840 100644
--- a/flake.nix
+++ b/flake.nix
@@ -77,7 +77,7 @@
export MD5SUM=md5sum
# Ugly hack to make the Clang resources directory available.
- export GOFLAGS="\"-ldflags=-X github.com/tinygo-org/tinygo/goenv.clangResourceDir=${llvmPackages_17.clang.cc.lib}/lib/clang/17"\"
+ export GOFLAGS="\"-ldflags=-X github.com/tinygo-org/tinygo/goenv.clangResourceDir=${llvmPackages_17.clang.cc.lib}/lib/clang/17\" -tags=llvm17"
'';
};
}
diff --git a/go.mod b/go.mod
index bf6d87ae6..6d40cd649 100644
--- a/go.mod
+++ b/go.mod
@@ -21,7 +21,7 @@ require (
golang.org/x/sys v0.16.0
golang.org/x/tools v0.17.0
gopkg.in/yaml.v2 v2.4.0
- tinygo.org/x/go-llvm v0.0.0-20240106122909-c2c543540318
+ tinygo.org/x/go-llvm v0.0.0-20240518103902-697964f2a9dc
)
require (
diff --git a/go.sum b/go.sum
index 7746bf7eb..59d33c94b 100644
--- a/go.sum
+++ b/go.sum
@@ -105,5 +105,5 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
-tinygo.org/x/go-llvm v0.0.0-20240106122909-c2c543540318 h1:4KjZvPtcN1UwobevcGbdzeinx0L1i8HDdJu84bu7NI8=
-tinygo.org/x/go-llvm v0.0.0-20240106122909-c2c543540318/go.mod h1:GFbusT2VTA4I+l4j80b17KFK+6whv69Wtny5U+T8RR0=
+tinygo.org/x/go-llvm v0.0.0-20240518103902-697964f2a9dc h1:TCzibFa4oLu+njEP3fnRUmZ+QQeb8BjtOwctgcjzL0k=
+tinygo.org/x/go-llvm v0.0.0-20240518103902-697964f2a9dc/go.mod h1:GFbusT2VTA4I+l4j80b17KFK+6whv69Wtny5U+T8RR0=
diff --git a/src/runtime/runtime.go b/src/runtime/runtime.go
index ac7cd25c9..a93260ba8 100644
--- a/src/runtime/runtime.go
+++ b/src/runtime/runtime.go
@@ -41,11 +41,9 @@ func memmove(dst, src unsafe.Pointer, size uintptr)
// like llvm.memset.p0.i32(ptr, 0, size, false).
func memzero(ptr unsafe.Pointer, size uintptr)
-// This intrinsic returns the current stack pointer.
-// It is normally used together with llvm.stackrestore but also works to get the
-// current stack pointer in a platform-independent way.
-//
-//export llvm.stacksave
+// Return the current stack pointer using the llvm.stacksave.p0 intrinsic.
+// It is normally used together with llvm.stackrestore.p0 but also works to get
+// the current stack pointer in a platform-independent way.
func stacksave() unsafe.Pointer
//export strlen
diff --git a/targets/esp32c3.json b/targets/esp32c3.json
index 5a1e70626..9d1c5cff7 100644
--- a/targets/esp32c3.json
+++ b/targets/esp32c3.json
@@ -1,6 +1,6 @@
{
"inherits": ["riscv32"],
- "features": "+32bit,+c,+m,-a,-d,-e,-experimental-smaia,-experimental-ssaia,-experimental-zacas,-experimental-zfa,-experimental-zfbfmin,-experimental-zicond,-experimental-zihintntl,-experimental-ztso,-experimental-zvbb,-experimental-zvbc,-experimental-zvfbfmin,-experimental-zvfbfwma,-experimental-zvkg,-experimental-zvkn,-experimental-zvknc,-experimental-zvkned,-experimental-zvkng,-experimental-zvknha,-experimental-zvknhb,-experimental-zvks,-experimental-zvksc,-experimental-zvksed,-experimental-zvksg,-experimental-zvksh,-experimental-zvkt,-f,-h,-relax,-save-restore,-svinval,-svnapot,-svpbmt,-v,-xcvbitmanip,-xcvmac,-xsfcie,-xsfvcp,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmp,-zcmt,-zdinx,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zicbom,-zicbop,-zicboz,-zicntr,-zicsr,-zifencei,-zihintpause,-zihpm,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-zmmul,-zve32f,-zve32x,-zve64d,-zve64f,-zve64x,-zvfh,-zvl1024b,-zvl128b,-zvl16384b,-zvl2048b,-zvl256b,-zvl32768b,-zvl32b,-zvl4096b,-zvl512b,-zvl64b,-zvl65536b,-zvl8192b",
+ "features": "+32bit,+c,+m,-a,-d,-e,-experimental-zacas,-experimental-zcmop,-experimental-zfbfmin,-experimental-zicfilp,-experimental-zicfiss,-experimental-zimop,-experimental-ztso,-experimental-zvfbfmin,-experimental-zvfbfwma,-f,-h,-relax,-smaia,-smepmp,-ssaia,-svinval,-svnapot,-svpbmt,-v,-xcvalu,-xcvbi,-xcvbitmanip,-xcvelw,-xcvmac,-xcvmem,-xcvsimd,-xsfvcp,-xsfvfnrclipxfqf,-xsfvfwmaccqqq,-xsfvqmaccdod,-xsfvqmaccqoq,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-za128rs,-za64rs,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmp,-zcmt,-zdinx,-zfa,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zic64b,-zicbom,-zicbop,-zicboz,-ziccamoa,-ziccif,-zicclsm,-ziccrse,-zicntr,-zicond,-zicsr,-zifencei,-zihintntl,-zihintpause,-zihpm,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-zmmul,-zvbb,-zvbc,-zve32f,-zve32x,-zve64d,-zve64f,-zve64x,-zvfh,-zvfhmin,-zvkb,-zvkg,-zvkn,-zvknc,-zvkned,-zvkng,-zvknha,-zvknhb,-zvks,-zvksc,-zvksed,-zvksg,-zvksh,-zvkt,-zvl1024b,-zvl128b,-zvl16384b,-zvl2048b,-zvl256b,-zvl32768b,-zvl32b,-zvl4096b,-zvl512b,-zvl64b,-zvl65536b,-zvl8192b",
"build-tags": ["esp32c3", "esp"],
"serial": "usb",
"rtlib": "compiler-rt",
diff --git a/targets/fe310.json b/targets/fe310.json
index a51488358..b96ae6d68 100644
--- a/targets/fe310.json
+++ b/targets/fe310.json
@@ -1,6 +1,6 @@
{
"inherits": ["riscv32"],
"cpu": "sifive-e31",
- "features": "+32bit,+a,+c,+m,-d,-e,-experimental-smaia,-experimental-ssaia,-experimental-zacas,-experimental-zfa,-experimental-zfbfmin,-experimental-zicond,-experimental-zihintntl,-experimental-ztso,-experimental-zvbb,-experimental-zvbc,-experimental-zvfbfmin,-experimental-zvfbfwma,-experimental-zvkg,-experimental-zvkn,-experimental-zvknc,-experimental-zvkned,-experimental-zvkng,-experimental-zvknha,-experimental-zvknhb,-experimental-zvks,-experimental-zvksc,-experimental-zvksed,-experimental-zvksg,-experimental-zvksh,-experimental-zvkt,-f,-h,-relax,-save-restore,-svinval,-svnapot,-svpbmt,-v,-xcvbitmanip,-xcvmac,-xsfcie,-xsfvcp,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmp,-zcmt,-zdinx,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zicbom,-zicbop,-zicboz,-zicntr,-zicsr,-zifencei,-zihintpause,-zihpm,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-zmmul,-zve32f,-zve32x,-zve64d,-zve64f,-zve64x,-zvfh,-zvl1024b,-zvl128b,-zvl16384b,-zvl2048b,-zvl256b,-zvl32768b,-zvl32b,-zvl4096b,-zvl512b,-zvl64b,-zvl65536b,-zvl8192b",
+ "features": "+32bit,+a,+c,+m,-d,-e,-experimental-zacas,-experimental-zcmop,-experimental-zfbfmin,-experimental-zicfilp,-experimental-zicfiss,-experimental-zimop,-experimental-ztso,-experimental-zvfbfmin,-experimental-zvfbfwma,-f,-h,-relax,-smaia,-smepmp,-ssaia,-svinval,-svnapot,-svpbmt,-v,-xcvalu,-xcvbi,-xcvbitmanip,-xcvelw,-xcvmac,-xcvmem,-xcvsimd,-xsfvcp,-xsfvfnrclipxfqf,-xsfvfwmaccqqq,-xsfvqmaccdod,-xsfvqmaccqoq,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-za128rs,-za64rs,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmp,-zcmt,-zdinx,-zfa,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zic64b,-zicbom,-zicbop,-zicboz,-ziccamoa,-ziccif,-zicclsm,-ziccrse,-zicntr,-zicond,-zicsr,-zifencei,-zihintntl,-zihintpause,-zihpm,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-zmmul,-zvbb,-zvbc,-zve32f,-zve32x,-zve64d,-zve64f,-zve64x,-zvfh,-zvfhmin,-zvkb,-zvkg,-zvkn,-zvknc,-zvkned,-zvkng,-zvknha,-zvknhb,-zvks,-zvksc,-zvksed,-zvksg,-zvksh,-zvkt,-zvl1024b,-zvl128b,-zvl16384b,-zvl2048b,-zvl256b,-zvl32768b,-zvl32b,-zvl4096b,-zvl512b,-zvl64b,-zvl65536b,-zvl8192b",
"build-tags": ["fe310", "sifive"]
}
diff --git a/targets/k210.json b/targets/k210.json
index 778e403c6..d95a6f511 100644
--- a/targets/k210.json
+++ b/targets/k210.json
@@ -1,6 +1,6 @@
{
"inherits": ["riscv64"],
- "features": "+64bit,+a,+c,+d,+f,+m,+zicsr,+zifencei,-e,-experimental-smaia,-experimental-ssaia,-experimental-zacas,-experimental-zfa,-experimental-zfbfmin,-experimental-zicond,-experimental-zihintntl,-experimental-ztso,-experimental-zvbb,-experimental-zvbc,-experimental-zvfbfmin,-experimental-zvfbfwma,-experimental-zvkg,-experimental-zvkn,-experimental-zvknc,-experimental-zvkned,-experimental-zvkng,-experimental-zvknha,-experimental-zvknhb,-experimental-zvks,-experimental-zvksc,-experimental-zvksed,-experimental-zvksg,-experimental-zvksh,-experimental-zvkt,-h,-relax,-save-restore,-svinval,-svnapot,-svpbmt,-v,-xcvbitmanip,-xcvmac,-xsfcie,-xsfvcp,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmp,-zcmt,-zdinx,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zicbom,-zicbop,-zicboz,-zicntr,-zihintpause,-zihpm,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-zmmul,-zve32f,-zve32x,-zve64d,-zve64f,-zve64x,-zvfh,-zvl1024b,-zvl128b,-zvl16384b,-zvl2048b,-zvl256b,-zvl32768b,-zvl32b,-zvl4096b,-zvl512b,-zvl64b,-zvl65536b,-zvl8192b",
+ "features": "+64bit,+a,+c,+d,+f,+m,+zicsr,+zifencei,-e,-experimental-zacas,-experimental-zcmop,-experimental-zfbfmin,-experimental-zicfilp,-experimental-zicfiss,-experimental-zimop,-experimental-ztso,-experimental-zvfbfmin,-experimental-zvfbfwma,-h,-relax,-smaia,-smepmp,-ssaia,-svinval,-svnapot,-svpbmt,-v,-xcvalu,-xcvbi,-xcvbitmanip,-xcvelw,-xcvmac,-xcvmem,-xcvsimd,-xsfvcp,-xsfvfnrclipxfqf,-xsfvfwmaccqqq,-xsfvqmaccdod,-xsfvqmaccqoq,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-za128rs,-za64rs,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmp,-zcmt,-zdinx,-zfa,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zic64b,-zicbom,-zicbop,-zicboz,-ziccamoa,-ziccif,-zicclsm,-ziccrse,-zicntr,-zicond,-zihintntl,-zihintpause,-zihpm,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-zmmul,-zvbb,-zvbc,-zve32f,-zve32x,-zve64d,-zve64f,-zve64x,-zvfh,-zvfhmin,-zvkb,-zvkg,-zvkn,-zvknc,-zvkned,-zvkng,-zvknha,-zvknhb,-zvks,-zvksc,-zvksed,-zvksg,-zvksh,-zvkt,-zvl1024b,-zvl128b,-zvl16384b,-zvl2048b,-zvl256b,-zvl32768b,-zvl32b,-zvl4096b,-zvl512b,-zvl64b,-zvl65536b,-zvl8192b",
"build-tags": ["k210", "kendryte"],
"code-model": "medium"
}
diff --git a/targets/riscv-qemu.json b/targets/riscv-qemu.json
index 7f9c5e395..cbe7d3c04 100644
--- a/targets/riscv-qemu.json
+++ b/targets/riscv-qemu.json
@@ -1,6 +1,6 @@
{
"inherits": ["riscv32"],
- "features": "+32bit,+a,+c,+m,-d,-e,-experimental-smaia,-experimental-ssaia,-experimental-zacas,-experimental-zfa,-experimental-zfbfmin,-experimental-zicond,-experimental-zihintntl,-experimental-ztso,-experimental-zvbb,-experimental-zvbc,-experimental-zvfbfmin,-experimental-zvfbfwma,-experimental-zvkg,-experimental-zvkn,-experimental-zvknc,-experimental-zvkned,-experimental-zvkng,-experimental-zvknha,-experimental-zvknhb,-experimental-zvks,-experimental-zvksc,-experimental-zvksed,-experimental-zvksg,-experimental-zvksh,-experimental-zvkt,-f,-h,-relax,-save-restore,-svinval,-svnapot,-svpbmt,-v,-xcvbitmanip,-xcvmac,-xsfcie,-xsfvcp,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmp,-zcmt,-zdinx,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zicbom,-zicbop,-zicboz,-zicntr,-zicsr,-zifencei,-zihintpause,-zihpm,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-zmmul,-zve32f,-zve32x,-zve64d,-zve64f,-zve64x,-zvfh,-zvl1024b,-zvl128b,-zvl16384b,-zvl2048b,-zvl256b,-zvl32768b,-zvl32b,-zvl4096b,-zvl512b,-zvl64b,-zvl65536b,-zvl8192b",
+ "features": "+32bit,+a,+c,+m,-d,-e,-experimental-zacas,-experimental-zcmop,-experimental-zfbfmin,-experimental-zicfilp,-experimental-zicfiss,-experimental-zimop,-experimental-ztso,-experimental-zvfbfmin,-experimental-zvfbfwma,-f,-h,-relax,-smaia,-smepmp,-ssaia,-svinval,-svnapot,-svpbmt,-v,-xcvalu,-xcvbi,-xcvbitmanip,-xcvelw,-xcvmac,-xcvmem,-xcvsimd,-xsfvcp,-xsfvfnrclipxfqf,-xsfvfwmaccqqq,-xsfvqmaccdod,-xsfvqmaccqoq,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-za128rs,-za64rs,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmp,-zcmt,-zdinx,-zfa,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zic64b,-zicbom,-zicbop,-zicboz,-ziccamoa,-ziccif,-zicclsm,-ziccrse,-zicntr,-zicond,-zicsr,-zifencei,-zihintntl,-zihintpause,-zihpm,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-zmmul,-zvbb,-zvbc,-zve32f,-zve32x,-zve64d,-zve64f,-zve64x,-zvfh,-zvfhmin,-zvkb,-zvkg,-zvkn,-zvknc,-zvkned,-zvkng,-zvknha,-zvknhb,-zvks,-zvksc,-zvksed,-zvksg,-zvksh,-zvkt,-zvl1024b,-zvl128b,-zvl16384b,-zvl2048b,-zvl256b,-zvl32768b,-zvl32b,-zvl4096b,-zvl512b,-zvl64b,-zvl65536b,-zvl8192b",
"build-tags": ["virt", "qemu"],
"default-stack-size": 4096,
"linkerscript": "targets/riscv-qemu.ld",
diff --git a/transform/optimizer.go b/transform/optimizer.go
index 4c0ccfc2e..05533b6a4 100644
--- a/transform/optimizer.go
+++ b/transform/optimizer.go
@@ -8,6 +8,7 @@ import (
"github.com/tinygo-org/tinygo/compileopts"
"github.com/tinygo-org/tinygo/compiler/ircheck"
+ "github.com/tinygo-org/tinygo/compiler/llvmutil"
"tinygo.org/x/go-llvm"
)
@@ -52,7 +53,12 @@ func Optimize(mod llvm.Module, config *compileopts.Config) []error {
// Run some preparatory passes for the Go optimizer.
po := llvm.NewPassBuilderOptions()
defer po.Dispose()
- err := mod.RunPasses("globaldce,globalopt,ipsccp,instcombine,adce,function-attrs", llvm.TargetMachine{}, po)
+ optPasses := "globaldce,globalopt,ipsccp,instcombine<no-verify-fixpoint>,adce,function-attrs"
+ if llvmutil.Version() < 18 {
+ // LLVM 17 doesn't have the no-verify-fixpoint flag.
+ optPasses = "globaldce,globalopt,ipsccp,instcombine,adce,function-attrs"
+ }
+ err := mod.RunPasses(optPasses, llvm.TargetMachine{}, po)
if err != nil {
return []error{fmt.Errorf("could not build pass pipeline: %w", err)}
}
@@ -75,7 +81,7 @@ func Optimize(mod llvm.Module, config *compileopts.Config) []error {
// After interfaces are lowered, there are many more opportunities for
// interprocedural optimizations. To get them to work, function
// attributes have to be updated first.
- err = mod.RunPasses("globaldce,globalopt,ipsccp,instcombine,adce,function-attrs", llvm.TargetMachine{}, po)
+ err = mod.RunPasses(optPasses, llvm.TargetMachine{}, po)
if err != nil {
return []error{fmt.Errorf("could not build pass pipeline: %w", err)}
}