Skip to content

Commit 27f4436

Browse files
committed
ci: add support for LLVM 15
This commit switches to LLVM 15 everywhere by default, while still keeping LLVM 14 support.
1 parent 05b3c51 commit 27f4436

File tree

22 files changed

+168
-55
lines changed

22 files changed

+168
-55
lines changed

.github/workflows/build-macos.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
uses: actions/cache@v3
4141
id: cache-llvm-source
4242
with:
43-
key: llvm-source-14-macos-v1
43+
key: llvm-source-15-macos-v1
4444
path: |
4545
llvm-project/clang/lib/Headers
4646
llvm-project/clang/include
@@ -54,7 +54,7 @@ jobs:
5454
uses: actions/cache@v3
5555
id: cache-llvm-build
5656
with:
57-
key: llvm-build-14-macos-v1
57+
key: llvm-build-15-macos-v1
5858
path: llvm-build
5959
- name: Build LLVM
6060
if: steps.cache-llvm-build.outputs.cache-hit != 'true'
@@ -108,7 +108,7 @@ jobs:
108108
- name: Install LLVM
109109
shell: bash
110110
run: |
111-
HOMEBREW_NO_AUTO_UPDATE=1 brew install llvm@14
111+
HOMEBREW_NO_AUTO_UPDATE=1 brew install llvm@15
112112
- name: Checkout
113113
uses: actions/checkout@v2
114114
- name: Install Go

.github/workflows/linux.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
uses: actions/cache@v3
4444
id: cache-llvm-source
4545
with:
46-
key: llvm-source-14-linux-alpine-v1
46+
key: llvm-source-15-linux-alpine-v1
4747
path: |
4848
llvm-project/clang/lib/Headers
4949
llvm-project/clang/include
@@ -57,7 +57,7 @@ jobs:
5757
uses: actions/cache@v3
5858
id: cache-llvm-build
5959
with:
60-
key: llvm-build-14-linux-alpine-v1
60+
key: llvm-build-15-linux-alpine-v1
6161
path: llvm-build
6262
- name: Build LLVM
6363
if: steps.cache-llvm-build.outputs.cache-hit != 'true'
@@ -185,7 +185,7 @@ jobs:
185185
uses: actions/cache@v3
186186
id: cache-llvm-source
187187
with:
188-
key: llvm-source-14-linux-asserts-v2
188+
key: llvm-source-15-linux-asserts-v1
189189
path: |
190190
llvm-project/clang/lib/Headers
191191
llvm-project/clang/include
@@ -199,7 +199,7 @@ jobs:
199199
uses: actions/cache@v3
200200
id: cache-llvm-build
201201
with:
202-
key: llvm-build-14-linux-asserts-v1
202+
key: llvm-build-15-linux-asserts-v1
203203
path: llvm-build
204204
- name: Build LLVM
205205
if: steps.cache-llvm-build.outputs.cache-hit != 'true'
@@ -277,7 +277,7 @@ jobs:
277277
uses: actions/cache@v3
278278
id: cache-llvm-source
279279
with:
280-
key: llvm-source-14-linux-v2
280+
key: llvm-source-15-linux-v1
281281
path: |
282282
llvm-project/clang/lib/Headers
283283
llvm-project/clang/include
@@ -291,7 +291,7 @@ jobs:
291291
uses: actions/cache@v3
292292
id: cache-llvm-build
293293
with:
294-
key: llvm-build-14-linux-arm-v1
294+
key: llvm-build-15-linux-arm-v1
295295
path: llvm-build
296296
- name: Build LLVM
297297
if: steps.cache-llvm-build.outputs.cache-hit != 'true'
@@ -377,7 +377,7 @@ jobs:
377377
uses: actions/cache@v3
378378
id: cache-llvm-source
379379
with:
380-
key: llvm-source-14-linux-v1
380+
key: llvm-source-15-linux-v1
381381
path: |
382382
llvm-project/clang/lib/Headers
383383
llvm-project/clang/include
@@ -391,7 +391,7 @@ jobs:
391391
uses: actions/cache@v3
392392
id: cache-llvm-build
393393
with:
394-
key: llvm-build-14-linux-arm64-v1
394+
key: llvm-build-15-linux-arm64-v1
395395
path: llvm-build
396396
- name: Build LLVM
397397
if: steps.cache-llvm-build.outputs.cache-hit != 'true'

.github/workflows/windows.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
uses: actions/cache@v3
3636
id: cache-llvm-source
3737
with:
38-
key: llvm-source-14-windows-v2
38+
key: llvm-source-15-windows-v1
3939
path: |
4040
llvm-project/clang/lib/Headers
4141
llvm-project/clang/include
@@ -49,7 +49,7 @@ jobs:
4949
uses: actions/cache@v3
5050
id: cache-llvm-build
5151
with:
52-
key: llvm-build-14-windows-v2
52+
key: llvm-build-15-windows-v1
5353
path: llvm-build
5454
- name: Build LLVM
5555
if: steps.cache-llvm-build.outputs.cache-hit != 'true'

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ endif
107107

108108
.PHONY: all tinygo test $(LLVM_BUILDDIR) llvm-source clean fmt gen-device gen-device-nrf gen-device-nxp gen-device-avr gen-device-rp
109109

110-
LLVM_COMPONENTS = all-targets analysis asmparser asmprinter bitreader bitwriter codegen core coroutines coverage debuginfodwarf debuginfopdb executionengine frontendopenmp instrumentation interpreter ipo irreader libdriver linker lto mc mcjit objcarcopts option profiledata scalaropts support target windowsmanifest
110+
LLVM_COMPONENTS = all-targets analysis asmparser asmprinter bitreader bitwriter codegen core coroutines coverage debuginfodwarf debuginfopdb executionengine frontendopenmp instrumentation interpreter ipo irreader libdriver linker lto mc mcjit objcarcopts option profiledata scalaropts support target windowsdriver windowsmanifest
111111

112112
ifeq ($(OS),Windows_NT)
113113
EXE = .exe
@@ -142,7 +142,7 @@ else
142142
endif
143143

144144
# Libraries that should be linked in for the statically linked Clang.
145-
CLANG_LIB_NAMES = clangAnalysis clangAST clangASTMatchers clangBasic clangCodeGen clangCrossTU clangDriver clangDynamicASTMatchers clangEdit clangFormat clangFrontend clangFrontendTool clangHandleCXX clangHandleLLVM clangIndex clangLex clangParse clangRewrite clangRewriteFrontend clangSema clangSerialization clangTooling clangToolingASTDiff clangToolingCore clangToolingInclusions
145+
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
146146
CLANG_LIBS = $(START_GROUP) $(addprefix -l,$(CLANG_LIB_NAMES)) $(END_GROUP) -lstdc++
147147

148148
# Libraries that should be linked in for the statically linked LLD.
@@ -230,7 +230,7 @@ gen-device-rp: build/gen-device-svd
230230

231231
# Get LLVM sources.
232232
$(LLVM_PROJECTDIR)/llvm:
233-
git clone -b xtensa_release_14.0.0-patched --depth=1 https://github.com/tinygo-org/llvm-project $(LLVM_PROJECTDIR)
233+
git clone -b xtensa_release_15.x --depth=1 https://github.com/espressif/llvm-project $(LLVM_PROJECTDIR)
234234
llvm-source: $(LLVM_PROJECTDIR)/llvm
235235

236236
# Configure LLVM.

builder/cc1as.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
101101

102102
// Target Options
103103
Opts.Triple = llvm::Triple::normalize(Args.getLastArgValue(OPT_triple));
104+
if (Arg *A = Args.getLastArg(options::OPT_darwin_target_variant_triple))
105+
Opts.DarwinTargetVariantTriple = llvm::Triple(A->getValue());
106+
104107
Opts.CPU = std::string(Args.getLastArgValue(OPT_target_cpu));
105108
Opts.Features = Args.getAllArgValues(OPT_target_feature);
106109

@@ -203,6 +206,14 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
203206
.Default(0);
204207
}
205208

209+
if (auto *A = Args.getLastArg(OPT_femit_dwarf_unwind_EQ)) {
210+
Opts.EmitDwarfUnwind =
211+
llvm::StringSwitch<EmitDwarfUnwindType>(A->getValue())
212+
.Case("always", EmitDwarfUnwindType::Always)
213+
.Case("no-compact-unwind", EmitDwarfUnwindType::NoCompactUnwind)
214+
.Case("default", EmitDwarfUnwindType::Default);
215+
}
216+
206217
return Success;
207218
}
208219

@@ -253,6 +264,8 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
253264
assert(MRI && "Unable to create target register info!");
254265

255266
MCTargetOptions MCOptions;
267+
MCOptions.EmitDwarfUnwind = Opts.EmitDwarfUnwind;
268+
256269
std::unique_ptr<MCAsmInfo> MAI(
257270
TheTarget->createMCAsmInfo(*MRI, Opts.Triple, MCOptions));
258271
assert(MAI && "Unable to create target asm info!");
@@ -299,6 +312,8 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
299312
// MCObjectFileInfo needs a MCContext reference in order to initialize itself.
300313
std::unique_ptr<MCObjectFileInfo> MOFI(
301314
TheTarget->createMCObjectFileInfo(Ctx, PIC));
315+
if (Opts.DarwinTargetVariantTriple)
316+
MOFI->setDarwinTargetVariantTriple(*Opts.DarwinTargetVariantTriple);
302317
Ctx.setObjectFileInfo(MOFI.get());
303318

304319
if (Opts.SaveTemporaryLabels)
@@ -347,7 +362,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
347362

348363
std::unique_ptr<MCCodeEmitter> CE;
349364
if (Opts.ShowEncoding)
350-
CE.reset(TheTarget->createMCCodeEmitter(*MCII, *MRI, Ctx));
365+
CE.reset(TheTarget->createMCCodeEmitter(*MCII, Ctx));
351366
std::unique_ptr<MCAsmBackend> MAB(
352367
TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions));
353368

@@ -367,7 +382,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
367382
}
368383

369384
std::unique_ptr<MCCodeEmitter> CE(
370-
TheTarget->createMCCodeEmitter(*MCII, *MRI, Ctx));
385+
TheTarget->createMCCodeEmitter(*MCII, Ctx));
371386
std::unique_ptr<MCAsmBackend> MAB(
372387
TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions));
373388
assert(MAB && "Unable to create asm backend!");
@@ -389,7 +404,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
389404
if (Opts.EmbedBitcode && Ctx.getObjectFileType() == MCContext::IsMachO) {
390405
MCSection *AsmLabel = Ctx.getMachOSection(
391406
"__LLVM", "__asm", MachO::S_REGULAR, 4, SectionKind::getReadOnly());
392-
Str.get()->SwitchSection(AsmLabel);
407+
Str.get()->switchSection(AsmLabel);
393408
Str.get()->emitZeros(1);
394409
}
395410

builder/cc1as.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,19 @@ struct AssemblerInvocation {
8585
unsigned IncrementalLinkerCompatible : 1;
8686
unsigned EmbedBitcode : 1;
8787

88+
/// Whether to emit DWARF unwind info.
89+
EmitDwarfUnwindType EmitDwarfUnwind;
90+
8891
/// The name of the relocation model to use.
8992
std::string RelocationModel;
9093

9194
/// The ABI targeted by the backend. Specified using -target-abi. Empty
9295
/// otherwise.
9396
std::string TargetABI;
9497

98+
/// Darwin target variant triple, the variant of the deployment target
99+
/// for which the code is being compiled.
100+
llvm::Optional<llvm::Triple> DarwinTargetVariantTriple;
95101
/// @}
96102

97103
public:
@@ -112,6 +118,7 @@ struct AssemblerInvocation {
112118
Dwarf64 = 0;
113119
DwarfVersion = 0;
114120
EmbedBitcode = 0;
121+
EmitDwarfUnwind = EmitDwarfUnwindType::Default;
115122
}
116123

117124
static bool CreateFromArgs(AssemblerInvocation &Res,

builder/musl.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import (
66
"os"
77
"path/filepath"
88
"regexp"
9+
"strconv"
910
"strings"
1011

1112
"github.com/tinygo-org/tinygo/compileopts"
1213
"github.com/tinygo-org/tinygo/goenv"
14+
"tinygo.org/x/go-llvm"
1315
)
1416

1517
var Musl = Library{
@@ -77,7 +79,7 @@ var Musl = Library{
7779
cflags: func(target, headerPath string) []string {
7880
arch := compileopts.MuslArchitecture(target)
7981
muslDir := filepath.Join(goenv.Get("TINYGOROOT"), "lib/musl")
80-
return []string{
82+
cflags := []string{
8183
"-std=c99", // same as in musl
8284
"-D_XOPEN_SOURCE=700", // same as in musl
8385
// Musl triggers some warnings and we don't want to show any
@@ -103,6 +105,12 @@ var Musl = Library{
103105
"-I" + muslDir + "/include",
104106
"-fno-stack-protector",
105107
}
108+
llvmMajor, _ := strconv.Atoi(strings.SplitN(llvm.Version, ".", 2)[0])
109+
if llvmMajor >= 15 {
110+
// This flag was added in Clang 15. It is not present in LLVM 14.
111+
cflags = append(cflags, "-Wno-deprecated-non-prototype")
112+
}
113+
return cflags
106114
},
107115
sourceDir: func() string { return filepath.Join(goenv.Get("TINYGOROOT"), "lib/musl/src") },
108116
librarySources: func(target string) []string {

cgo/libclang_config_llvm14.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//go:build !byollvm
2-
// +build !byollvm
1+
//go:build !byollvm && llvm14
2+
// +build !byollvm,llvm14
33

44
package cgo
55

cgo/libclang_config_llvm15.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//go:build !byollvm && !llvm14
2+
// +build !byollvm,!llvm14
3+
4+
package cgo
5+
6+
/*
7+
#cgo linux CFLAGS: -I/usr/lib/llvm-15/include
8+
#cgo darwin,amd64 CFLAGS: -I/usr/local/opt/llvm@15/include
9+
#cgo darwin,arm64 CFLAGS: -I/opt/homebrew/opt/llvm@15/include
10+
#cgo freebsd CFLAGS: -I/usr/local/llvm15/include
11+
#cgo linux LDFLAGS: -L/usr/lib/llvm-15/lib -lclang
12+
#cgo darwin,amd64 LDFLAGS: -L/usr/local/opt/llvm@15/lib -lclang -lffi
13+
#cgo darwin,arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@15/lib -lclang -lffi
14+
#cgo freebsd LDFLAGS: -L/usr/local/llvm15/lib -lclang
15+
*/
16+
import "C"

compiler/func.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,15 @@ func (b *builder) extractFuncContext(funcValue llvm.Value) llvm.Value {
5757
// value. This may be an expensive operation.
5858
func (b *builder) decodeFuncValue(funcValue llvm.Value, sig *types.Signature) (funcType llvm.Type, funcPtr, context llvm.Value) {
5959
context = b.CreateExtractValue(funcValue, 0, "")
60-
bitcast := b.CreateExtractValue(funcValue, 1, "")
61-
if !bitcast.IsAConstantExpr().IsNil() && bitcast.Opcode() == llvm.BitCast {
62-
funcPtr = bitcast.Operand(0)
63-
return
60+
funcPtr = b.CreateExtractValue(funcValue, 1, "")
61+
if !funcPtr.IsAConstantExpr().IsNil() && funcPtr.Opcode() == llvm.BitCast {
62+
funcPtr = funcPtr.Operand(0) // needed for LLVM 14 (no opaque pointers)
63+
}
64+
if sig != nil {
65+
funcType = b.getRawFuncType(sig)
66+
llvmSig := llvm.PointerType(funcType, b.funcPtrAddrSpace)
67+
funcPtr = b.CreateBitCast(funcPtr, llvmSig, "")
6468
}
65-
funcType = b.getRawFuncType(sig)
66-
llvmSig := llvm.PointerType(funcType, b.funcPtrAddrSpace)
67-
funcPtr = b.CreateBitCast(bitcast, llvmSig, "")
6869
return
6970
}
7071

0 commit comments

Comments
 (0)