Skip to content

Commit 8dd9199

Browse files
authored
[WebAssembly] Add gc target feature to addBleedingEdgeFeatures (#151294)
Also alphebetize feature list, add `-mgc` and `-mno-gc` flags, and add some missing feature tests. Reland of #151107. #150201 (comment)
1 parent 90aed4d commit 8dd9199

File tree

9 files changed

+44
-22
lines changed

9 files changed

+44
-22
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5312,6 +5312,8 @@ def mextended_const : Flag<["-"], "mextended-const">, Group<m_wasm_Features_Grou
53125312
def mno_extended_const : Flag<["-"], "mno-extended-const">, Group<m_wasm_Features_Group>;
53135313
def mfp16 : Flag<["-"], "mfp16">, Group<m_wasm_Features_Group>;
53145314
def mno_fp16 : Flag<["-"], "mno-fp16">, Group<m_wasm_Features_Group>;
5315+
def mgc : Flag<["-"], "mgc">, Group<m_wasm_Features_Group>;
5316+
def mno_gc : Flag<["-"], "mno-gc">, Group<m_wasm_Features_Group>;
53155317
def mmultimemory : Flag<["-"], "mmultimemory">, Group<m_wasm_Features_Group>;
53165318
def mno_multimemory : Flag<["-"], "mno-multimemory">, Group<m_wasm_Features_Group>;
53175319
def mmultivalue : Flag<["-"], "mmultivalue">, Group<m_wasm_Features_Group>;

clang/lib/Basic/Targets/WebAssembly.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ bool WebAssemblyTargetInfo::hasFeature(StringRef Feature) const {
5959
.Case("exception-handling", HasExceptionHandling)
6060
.Case("extended-const", HasExtendedConst)
6161
.Case("fp16", HasFP16)
62+
.Case("gc", HasGC)
6263
.Case("multimemory", HasMultiMemory)
6364
.Case("multivalue", HasMultivalue)
6465
.Case("mutable-globals", HasMutableGlobals)
6566
.Case("nontrapping-fptoint", HasNontrappingFPToInt)
6667
.Case("reference-types", HasReferenceTypes)
67-
.Case("gc", HasGC)
6868
.Case("relaxed-simd", SIMDLevel >= RelaxedSIMD)
6969
.Case("sign-ext", HasSignExt)
7070
.Case("simd128", SIMDLevel >= SIMD128)
@@ -99,6 +99,8 @@ void WebAssemblyTargetInfo::getTargetDefines(const LangOptions &Opts,
9999
Builder.defineMacro("__wasm_multimemory__");
100100
if (HasFP16)
101101
Builder.defineMacro("__wasm_fp16__");
102+
if (HasGC)
103+
Builder.defineMacro("__wasm_gc__");
102104
if (HasMultivalue)
103105
Builder.defineMacro("__wasm_multivalue__");
104106
if (HasMutableGlobals)
@@ -107,8 +109,6 @@ void WebAssemblyTargetInfo::getTargetDefines(const LangOptions &Opts,
107109
Builder.defineMacro("__wasm_nontrapping_fptoint__");
108110
if (HasReferenceTypes)
109111
Builder.defineMacro("__wasm_reference_types__");
110-
if (HasGC)
111-
Builder.defineMacro("__wasm_gc__");
112112
if (SIMDLevel >= RelaxedSIMD)
113113
Builder.defineMacro("__wasm_relaxed_simd__");
114114
if (HasSignExt)
@@ -194,6 +194,7 @@ bool WebAssemblyTargetInfo::initFeatureMap(
194194
Features["exception-handling"] = true;
195195
Features["extended-const"] = true;
196196
Features["fp16"] = true;
197+
Features["gc"] = true;
197198
Features["multimemory"] = true;
198199
Features["tail-call"] = true;
199200
Features["wide-arithmetic"] = true;
@@ -270,6 +271,14 @@ bool WebAssemblyTargetInfo::handleTargetFeatures(
270271
HasFP16 = false;
271272
continue;
272273
}
274+
if (Feature == "+gc") {
275+
HasGC = true;
276+
continue;
277+
}
278+
if (Feature == "-gc") {
279+
HasGC = false;
280+
continue;
281+
}
273282
if (Feature == "+multimemory") {
274283
HasMultiMemory = true;
275284
continue;
@@ -310,14 +319,6 @@ bool WebAssemblyTargetInfo::handleTargetFeatures(
310319
HasReferenceTypes = false;
311320
continue;
312321
}
313-
if (Feature == "+gc") {
314-
HasGC = true;
315-
continue;
316-
}
317-
if (Feature == "-gc") {
318-
HasGC = false;
319-
continue;
320-
}
321322
if (Feature == "+relaxed-simd") {
322323
SIMDLevel = std::max(SIMDLevel, RelaxedSIMD);
323324
continue;

clang/lib/Basic/Targets/WebAssembly.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo {
6464
bool HasExceptionHandling = false;
6565
bool HasExtendedConst = false;
6666
bool HasFP16 = false;
67+
bool HasGC = false;
6768
bool HasMultiMemory = false;
6869
bool HasMultivalue = false;
6970
bool HasMutableGlobals = false;
7071
bool HasNontrappingFPToInt = false;
7172
bool HasReferenceTypes = false;
72-
bool HasGC = false;
7373
bool HasSignExt = false;
7474
bool HasTailCall = false;
7575
bool HasWideArithmetic = false;

clang/test/Driver/wasm-features.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@
4141
// HALF-PRECISION: "-target-feature" "+fp16"
4242
// NO-HALF-PRECISION: "-target-feature" "-fp16"
4343

44+
// RUN: %clang --target=wasm32-unknown-unknown -### %s -mgc 2>&1 | FileCheck %s -check-prefix=GC
45+
// RUN: %clang --target=wasm32-unknown-unknown -### %s -mno-gc 2>&1 | FileCheck %s -check-prefix=NO-GC
46+
47+
// GC: "-target-feature" "+gc"
48+
// NO-GC: "-target-feature" "-gc"
49+
4450
// RUN: %clang --target=wasm32-unknown-unknown -### %s -mmultimemory 2>&1 | FileCheck %s -check-prefix=MULTIMEMORY
4551
// RUN: %clang --target=wasm32-unknown-unknown -### %s -mno-multimemory 2>&1 | FileCheck %s -check-prefix=NO-MULTIMEMORY
4652

clang/test/Preprocessor/wasm-target-features.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@
5252
//
5353
// FP16: #define __wasm_fp16__ 1{{$}}
5454

55+
// RUN: %clang -E -dM %s -o - 2>&1 \
56+
// RUN: -target wasm32-unknown-unknown -mgc \
57+
// RUN: | FileCheck %s -check-prefix=GC
58+
// RUN: %clang -E -dM %s -o - 2>&1 \
59+
// RUN: -target wasm64-unknown-unknown -mgc \
60+
// RUN: | FileCheck %s -check-prefix=GC
61+
//
62+
// GC: #define __wasm_gc__ 1{{$}}
63+
5564
// RUN: %clang -E -dM %s -o - 2>&1 \
5665
// RUN: -target wasm32-unknown-unknown -mmultimemory \
5766
// RUN: | FileCheck %s -check-prefix=MULTIMEMORY
@@ -145,6 +154,7 @@
145154
// MVP-NOT: #define __wasm_exception_handling__ 1{{$}}
146155
// MVP-NOT: #define __wasm_extended_const__ 1{{$}}
147156
// MVP-NOT: #define __wasm_fp16__ 1{{$}}
157+
// MVP-NOT: #define __wasm_gc__ 1{{$}}
148158
// MVP-NOT: #define __wasm_multimemory__ 1{{$}}
149159
// MVP-NOT: #define __wasm_multivalue__ 1{{$}}
150160
// MVP-NOT: #define __wasm_mutable_globals__ 1{{$}}
@@ -181,6 +191,7 @@
181191
// GENERIC-NOT: #define __wasm_exception_handling__ 1{{$}}
182192
// GENERIC-NOT: #define __wasm_extended_const__ 1{{$}}
183193
// GENERIC-NOT: #define __wasm__fp16__ 1{{$}}
194+
// GENERIC-NOT: #define __wasm_gc__ 1{{$}}
184195
// GENERIC-NOT: #define __wasm_multimemory__ 1{{$}}
185196
// GENERIC-NOT: #define __wasm_relaxed_simd__ 1{{$}}
186197
// GENERIC-NOT: #define __wasm_simd128__ 1{{$}}
@@ -199,6 +210,7 @@
199210
// BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_exception_handling__ 1{{$}}
200211
// BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_extended_const__ 1{{$}}
201212
// BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_fp16__ 1{{$}}
213+
// BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_gc__ 1{{$}}
202214
// BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_multimemory__ 1{{$}}
203215
// BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_multivalue__ 1{{$}}
204216
// BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_mutable_globals__ 1{{$}}

llvm/lib/Target/WebAssembly/WebAssembly.td

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ def FeatureFP16 :
4949
SubtargetFeature<"fp16", "HasFP16", "true",
5050
"Enable FP16 instructions">;
5151

52+
def FeatureGC : SubtargetFeature<"gc", "HasGC", "true", "Enable wasm gc">;
53+
5254
def FeatureMultiMemory :
5355
SubtargetFeature<"multimemory", "HasMultiMemory", "true",
5456
"Enable multiple memories">;
@@ -71,7 +73,6 @@ def FeatureReferenceTypes :
7173
SubtargetFeature<"reference-types", "HasReferenceTypes", "true",
7274
"Enable reference types">;
7375

74-
def FeatureGC : SubtargetFeature<"gc", "HasGC", "true", "Enable wasm gc">;
7576
def FeatureRelaxedSIMD :
7677
SubtargetFeature<"relaxed-simd", "SIMDLevel", "RelaxedSIMD",
7778
"Enable relaxed-simd instructions">;
@@ -139,10 +140,10 @@ def : ProcessorModel<"lime1", NoSchedModel,
139140
def : ProcessorModel<"bleeding-edge", NoSchedModel,
140141
[FeatureAtomics, FeatureBulkMemory, FeatureBulkMemoryOpt,
141142
FeatureCallIndirectOverlong, FeatureExceptionHandling,
142-
FeatureExtendedConst, FeatureFP16, FeatureMultiMemory,
143-
FeatureMultivalue, FeatureMutableGlobals,
143+
FeatureExtendedConst, FeatureFP16, FeatureGC,
144+
FeatureMultiMemory, FeatureMultivalue, FeatureMutableGlobals,
144145
FeatureNontrappingFPToInt, FeatureRelaxedSIMD,
145-
FeatureReferenceTypes, FeatureGC, FeatureSIMD128,
146+
FeatureReferenceTypes, FeatureSIMD128,
146147
FeatureSignExt, FeatureTailCall]>;
147148

148149
//===----------------------------------------------------------------------===//

llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ def HasFP16 :
5050
Predicate<"Subtarget->hasFP16()">,
5151
AssemblerPredicate<(all_of FeatureFP16), "fp16">;
5252

53+
def HasGC : Predicate<"Subtarget->hasGC()">,
54+
AssemblerPredicate<(all_of FeatureGC), "gc">;
55+
5356
def HasMultiMemory :
5457
Predicate<"Subtarget->hasMultiMemory()">,
5558
AssemblerPredicate<(all_of FeatureMultiMemory), "multimemory">;
@@ -76,9 +79,6 @@ def HasReferenceTypes :
7679
Predicate<"Subtarget->hasReferenceTypes()">,
7780
AssemblerPredicate<(all_of FeatureReferenceTypes), "reference-types">;
7881

79-
def HasGC : Predicate<"Subtarget->hasGC()">,
80-
AssemblerPredicate<(all_of FeatureGC), "gc">;
81-
8282
def HasRelaxedSIMD :
8383
Predicate<"Subtarget->hasRelaxedSIMD()">,
8484
AssemblerPredicate<(all_of FeatureRelaxedSIMD), "relaxed-simd">;

llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ class WebAssemblySubtarget final : public WebAssemblyGenSubtargetInfo {
4646
bool HasExceptionHandling = false;
4747
bool HasExtendedConst = false;
4848
bool HasFP16 = false;
49+
bool HasGC = false;
4950
bool HasMultiMemory = false;
5051
bool HasMultivalue = false;
5152
bool HasMutableGlobals = false;
5253
bool HasNontrappingFPToInt = false;
5354
bool HasReferenceTypes = false;
54-
bool HasGC = false;
5555
bool HasSignExt = false;
5656
bool HasTailCall = false;
5757
bool HasWideArithmetic = false;

llvm/test/CodeGen/WebAssembly/target-features-cpus.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ target triple = "wasm32-unknown-unknown"
6868

6969
; bleeding-edge: +atomics, +bulk-memory, +bulk-memory-opt,
7070
; +call-indirect-overlong, +exception-handling,
71-
; +extended-const, +fp16, +multimemory, +multivalue,
71+
; +extended-const, +fp16, +gc, +multimemory, +multivalue,
7272
; +mutable-globals, +nontrapping-fptoint, +relaxed-simd,
73-
; +reference-types, +simd128, +sign-ext, +tail-call, +gc
73+
; +reference-types, +simd128, +sign-ext, +tail-call
7474
; BLEEDING-EDGE-LABEL: .section .custom_section.target_features,"",@
7575
; BLEEDING-EDGE-NEXT: .int8 17
7676
; BLEEDING-EDGE-NEXT: .int8 43

0 commit comments

Comments
 (0)