Skip to content

Commit e19af50

Browse files
committed
Add gc target feature
1 parent dade3c6 commit e19af50

File tree

10 files changed

+45
-20
lines changed

10 files changed

+45
-20
lines changed

clang/include/clang/Basic/BuiltinsWebAssembly.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ TARGET_BUILTIN(__builtin_wasm_ref_null_func, "i", "nct", "reference-types")
203203
// to avoid "function signature mismatch" traps. Takes a function pointer, uses
204204
// table.get to look up the pointer in __indirect_function_table and then
205205
// ref.test to test the type.
206-
TARGET_BUILTIN(__builtin_wasm_test_function_pointer_signature, "i.", "nct", "reference-types")
206+
TARGET_BUILTIN(__builtin_wasm_test_function_pointer_signature, "i.", "nct", "gc")
207207

208208
// Table builtins
209209
TARGET_BUILTIN(__builtin_wasm_table_set, "viii", "t", "reference-types")

clang/lib/Basic/Targets/WebAssembly.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ bool WebAssemblyTargetInfo::hasFeature(StringRef Feature) const {
6464
.Case("mutable-globals", HasMutableGlobals)
6565
.Case("nontrapping-fptoint", HasNontrappingFPToInt)
6666
.Case("reference-types", HasReferenceTypes)
67+
.Case("gc", HasGC)
6768
.Case("relaxed-simd", SIMDLevel >= RelaxedSIMD)
6869
.Case("sign-ext", HasSignExt)
6970
.Case("simd128", SIMDLevel >= SIMD128)
@@ -106,6 +107,8 @@ void WebAssemblyTargetInfo::getTargetDefines(const LangOptions &Opts,
106107
Builder.defineMacro("__wasm_nontrapping_fptoint__");
107108
if (HasReferenceTypes)
108109
Builder.defineMacro("__wasm_reference_types__");
110+
if (HasGC)
111+
Builder.defineMacro("__wasm_gc__");
109112
if (SIMDLevel >= RelaxedSIMD)
110113
Builder.defineMacro("__wasm_relaxed_simd__");
111114
if (HasSignExt)
@@ -307,6 +310,14 @@ bool WebAssemblyTargetInfo::handleTargetFeatures(
307310
HasReferenceTypes = false;
308311
continue;
309312
}
313+
if (Feature == "+gc") {
314+
HasGC = true;
315+
continue;
316+
}
317+
if (Feature == "-gc") {
318+
HasGC = false;
319+
continue;
320+
}
310321
if (Feature == "+relaxed-simd") {
311322
SIMDLevel = std::max(SIMDLevel, RelaxedSIMD);
312323
continue;
@@ -353,6 +364,11 @@ bool WebAssemblyTargetInfo::handleTargetFeatures(
353364
return false;
354365
}
355366

367+
// gc implies reference-types
368+
if (HasGC) {
369+
HasReferenceTypes = true;
370+
}
371+
356372
// bulk-memory-opt is a subset of bulk-memory.
357373
if (HasBulkMemory) {
358374
HasBulkMemoryOpt = true;

clang/lib/Basic/Targets/WebAssembly.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo {
6969
bool HasMutableGlobals = false;
7070
bool HasNontrappingFPToInt = false;
7171
bool HasReferenceTypes = false;
72+
bool HasGC = false;
7273
bool HasSignExt = false;
7374
bool HasTailCall = false;
7475
bool HasWideArithmetic = false;

clang/test/CodeGen/builtins-wasm.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// RUN: %clang_cc1 -triple wasm32-unknown-unknown -target-feature +reference-types -target-feature +simd128 -target-feature +relaxed-simd -target-feature +nontrapping-fptoint -target-feature +exception-handling -target-feature +bulk-memory -target-feature +atomics -target-feature +fp16 -flax-vector-conversions=none -O3 -emit-llvm -o - %s | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY32
2-
// RUN: %clang_cc1 -triple wasm64-unknown-unknown -target-feature +reference-types -target-feature +simd128 -target-feature +relaxed-simd -target-feature +nontrapping-fptoint -target-feature +exception-handling -target-feature +bulk-memory -target-feature +atomics -target-feature +fp16 -flax-vector-conversions=none -O3 -emit-llvm -o - %s | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY64
3-
// RUN: not %clang_cc1 -triple wasm64-unknown-unknown -target-feature +reference-types -target-feature +nontrapping-fptoint -target-feature +exception-handling -target-feature +bulk-memory -target-feature +atomics -flax-vector-conversions=none -O3 -emit-llvm -o - %s 2>&1 | FileCheck %s -check-prefixes MISSING-SIMD
1+
// RUN: %clang_cc1 -triple wasm32-unknown-unknown -target-feature +reference-types -target-feature +simd128 -target-feature +relaxed-simd -target-feature +nontrapping-fptoint -target-feature +exception-handling -target-feature +bulk-memory -target-feature +atomics -target-feature +gc -target-feature +fp16 -flax-vector-conversions=none -O3 -emit-llvm -o - %s | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY32
2+
// RUN: %clang_cc1 -triple wasm64-unknown-unknown -target-feature +reference-types -target-feature +simd128 -target-feature +relaxed-simd -target-feature +nontrapping-fptoint -target-feature +exception-handling -target-feature +bulk-memory -target-feature +atomics -target-feature +gc -target-feature +fp16 -flax-vector-conversions=none -O3 -emit-llvm -o - %s | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY64
3+
// RUN: not %clang_cc1 -triple wasm64-unknown-unknown -target-feature +reference-types -target-feature +nontrapping-fptoint -target-feature +exception-handling -target-feature +bulk-memory -target-feature +atomics -target-feature +gc -flax-vector-conversions=none -O3 -emit-llvm -o - %s 2>&1 | FileCheck %s -check-prefixes MISSING-SIMD
44

55
// SIMD convenience types
66
typedef signed char i8x16 __attribute((vector_size(16)));

llvm/lib/Target/WebAssembly/WebAssembly.td

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def FeatureReferenceTypes :
7171
SubtargetFeature<"reference-types", "HasReferenceTypes", "true",
7272
"Enable reference types">;
7373

74+
def FeatureGC : SubtargetFeature<"gc", "HasGC", "true", "Enable wasm gc">;
7475
def FeatureRelaxedSIMD :
7576
SubtargetFeature<"relaxed-simd", "SIMDLevel", "RelaxedSIMD",
7677
"Enable relaxed-simd instructions">;
@@ -136,13 +137,13 @@ def : ProcessorModel<"lime1", NoSchedModel,
136137

137138
// Latest and greatest experimental version of WebAssembly. Bugs included!
138139
def : ProcessorModel<"bleeding-edge", NoSchedModel,
139-
[FeatureAtomics, FeatureBulkMemory, FeatureBulkMemoryOpt,
140-
FeatureCallIndirectOverlong, FeatureExceptionHandling,
141-
FeatureExtendedConst, FeatureFP16, FeatureMultiMemory,
142-
FeatureMultivalue, FeatureMutableGlobals,
143-
FeatureNontrappingFPToInt, FeatureRelaxedSIMD,
144-
FeatureReferenceTypes, FeatureSIMD128, FeatureSignExt,
145-
FeatureTailCall]>;
140+
[FeatureAtomics, FeatureBulkMemory, FeatureBulkMemoryOpt,
141+
FeatureCallIndirectOverlong, FeatureExceptionHandling,
142+
FeatureExtendedConst, FeatureFP16, FeatureMultiMemory,
143+
FeatureMultivalue, FeatureMutableGlobals,
144+
FeatureNontrappingFPToInt, FeatureRelaxedSIMD,
145+
FeatureReferenceTypes, FeatureGC, FeatureSIMD128,
146+
FeatureSignExt, FeatureTailCall]>;
146147

147148
//===----------------------------------------------------------------------===//
148149
// Target Declaration

llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ def HasReferenceTypes :
7676
Predicate<"Subtarget->hasReferenceTypes()">,
7777
AssemblerPredicate<(all_of FeatureReferenceTypes), "reference-types">;
7878

79+
def HasGC : Predicate<"Subtarget->hasGC()">,
80+
AssemblerPredicate<(all_of FeatureGC), "gc">;
81+
7982
def HasRelaxedSIMD :
8083
Predicate<"Subtarget->hasRelaxedSIMD()">,
8184
AssemblerPredicate<(all_of FeatureRelaxedSIMD), "relaxed-simd">;

llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,10 @@ multiclass REF_I<WebAssemblyRegClass rc, ValueType vt, string ht> {
3636
Requires<[HasReferenceTypes]>;
3737
}
3838

39-
defm REF_TEST_FUNCREF :
40-
I<(outs I32: $res),
41-
(ins TypeIndex:$type, FUNCREF: $ref),
42-
(outs),
43-
(ins TypeIndex:$type),
44-
[],
45-
"ref.test\t$type, $ref", "ref.test $type", 0xfb14>;
39+
defm REF_TEST_FUNCREF : I<(outs I32:$res), (ins TypeIndex:$type, FUNCREF:$ref),
40+
(outs), (ins TypeIndex:$type), [],
41+
"ref.test\t$type, $ref", "ref.test $type", 0xfb14>,
42+
Requires<[HasGC]>;
4643

4744
defm "" : REF_I<FUNCREF, funcref, "func">;
4845
defm "" : REF_I<EXTERNREF, externref, "extern">;

llvm/lib/Target/WebAssembly/WebAssemblySubtarget.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ WebAssemblySubtarget::initializeSubtargetDependencies(StringRef CPU,
4343
Bits.set(WebAssembly::FeatureBulkMemoryOpt);
4444
}
4545

46+
// gc implies reference-types
47+
if (HasGC) {
48+
HasReferenceTypes = true;
49+
}
50+
4651
// reference-types implies call-indirect-overlong
4752
if (HasReferenceTypes) {
4853
HasCallIndirectOverlong = true;

llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class WebAssemblySubtarget final : public WebAssemblyGenSubtargetInfo {
5151
bool HasMutableGlobals = false;
5252
bool HasNontrappingFPToInt = false;
5353
bool HasReferenceTypes = false;
54+
bool HasGC = false;
5455
bool HasSignExt = false;
5556
bool HasTailCall = false;
5657
bool HasWideArithmetic = false;
@@ -107,6 +108,7 @@ class WebAssemblySubtarget final : public WebAssemblyGenSubtargetInfo {
107108
bool hasMutableGlobals() const { return HasMutableGlobals; }
108109
bool hasNontrappingFPToInt() const { return HasNontrappingFPToInt; }
109110
bool hasReferenceTypes() const { return HasReferenceTypes; }
111+
bool hasGC() const { return HasGC; }
110112
bool hasRelaxedSIMD() const { return SIMDLevel >= RelaxedSIMD; }
111113
bool hasSignExt() const { return HasSignExt; }
112114
bool hasSIMD128() const { return SIMDLevel >= SIMD128; }

llvm/test/CodeGen/WebAssembly/ref-test-func.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2-
; RUN: llc < %s --mtriple=wasm32-unknown-unknown -mcpu=mvp -mattr=+reference-types | FileCheck --check-prefixes CHECK,CHK32 %s
3-
; RUN: llc < %s --mtriple=wasm64-unknown-unknown -mcpu=mvp -mattr=+reference-types | FileCheck --check-prefixes CHECK,CHK64 %s
2+
; RUN: llc < %s --mtriple=wasm32-unknown-unknown -mcpu=mvp -mattr=+reference-types -mattr=+gc | FileCheck --check-prefixes CHECK,CHK32 %s
3+
; RUN: llc < %s --mtriple=wasm64-unknown-unknown -mcpu=mvp -mattr=+reference-types -mattr=+gc | FileCheck --check-prefixes CHECK,CHK64 %s
44

55
define void @test_fpsig_void_void(ptr noundef %func) local_unnamed_addr #0 {
66
; CHECK-LABEL: test_fpsig_void_void:

0 commit comments

Comments
 (0)