Skip to content

Commit

Permalink
More fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
sunfishcode committed Oct 14, 2024
1 parent 1f77f5e commit 2fa3ef0
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 11 deletions.
3 changes: 2 additions & 1 deletion clang/lib/Basic/Targets/WebAssembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ bool WebAssemblyTargetInfo::hasFeature(StringRef Feature) const {
.Case("atomics", HasAtomics)
.Case("bulk-memory", HasBulkMemory)
.Case("bulk-memory-opt", HasBulkMemoryOpt)
.Case("call-indirect-overlong", HasCallIndirectOverlong)
.Case("exception-handling", HasExceptionHandling)
.Case("extended-const", HasExtendedConst)
.Case("fp16", HasFP16)
Expand All @@ -56,7 +57,6 @@ bool WebAssemblyTargetInfo::hasFeature(StringRef Feature) const {
.Case("mutable-globals", HasMutableGlobals)
.Case("nontrapping-fptoint", HasNontrappingFPToInt)
.Case("reference-types", HasReferenceTypes)
.Case("call-indirect-overlong", HasCallIndirectOverlong)
.Case("relaxed-simd", SIMDLevel >= RelaxedSIMD)
.Case("sign-ext", HasSignExt)
.Case("simd128", SIMDLevel >= SIMD128)
Expand Down Expand Up @@ -175,6 +175,7 @@ bool WebAssemblyTargetInfo::initFeatureMap(
Features["atomics"] = true;
Features["bulk-memory"] = true;
Features["bulk-memory-opt"] = true;
Features["call-indirect-overlong"] = true;
Features["exception-handling"] = true;
Features["extended-const"] = true;
Features["fp16"] = true;
Expand Down
13 changes: 12 additions & 1 deletion llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,18 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
: MCTargetAsmParser(Options, STI, MII), Parser(Parser),
Lexer(Parser.getLexer()), Is64(STI.getTargetTriple().isArch64Bit()),
TC(Parser, MII, Is64), SkipTypeCheck(Options.MCNoTypeCheck) {
setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
FeatureBitset FBS = ComputeAvailableFeatures(STI.getFeatureBits());

// bulk-memory implies bulk-memory-opt
if (FBS.test(WebAssembly::FeatureBulkMemory)) {
FBS.set(WebAssembly::FeatureBulkMemoryOpt);
}
// reference-types implies call-indirect-overlong
if (FBS.test(WebAssembly::FeatureReferenceTypes)) {
FBS.set(WebAssembly::FeatureCallIndirectOverlong);
}

setAvailableFeatures(FBS);
// Don't type check if this is inline asm, since that is a naked sequence of
// instructions without a function/locals decl.
auto &SM = Parser.getSourceManager();
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/CodeGen/WebAssembly/call-indirect.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: llc < %s -asm-verbose=false -mattr=-reference-types -O2 | FileCheck --check-prefixes=CHECK,NOREF %s
; RUN: llc < %s -asm-verbose=false -mattr=+reference-types -O2 | FileCheck --check-prefixes=CHECK,REF %s
; RUN: llc < %s -asm-verbose=false -mattr=-reference-types,call-indirect-overlong -O2 | FileCheck --check-prefixes=CHECK,NOREF %s
; RUN: llc < %s -asm-verbose=false -mattr=+call-indirect-overlong -O2 | FileCheck --check-prefixes=CHECK,REF %s
; RUN: llc < %s -asm-verbose=false -O2 --filetype=obj | obj2yaml | FileCheck --check-prefix=OBJ %s

; Test that compilation units with call_indirect but without any
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/CodeGen/WebAssembly/function-pointer64.ll
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
; RUN: llc < %s -asm-verbose=false -mattr=-reference-types -O2 | FileCheck %s
; RUN: llc < %s -asm-verbose=false -mattr=-reference-types,-call-indirect-overlong -O2 | FileCheck %s
; RUN: llc < %s -asm-verbose=false -mattr=+reference-types -O2 | FileCheck --check-prefix=REF %s
; RUN: llc < %s -asm-verbose=false -mattr=-reference-types -O2 --filetype=obj | obj2yaml | FileCheck --check-prefix=YAML %s
; RUN: llc < %s -asm-verbose=false -mattr=-reference-types,-call-indirect-overlong -O2 --filetype=obj | obj2yaml | FileCheck --check-prefix=YAML %s

; This tests pointer features that may codegen differently in wasm64.

Expand Down
20 changes: 15 additions & 5 deletions llvm/test/CodeGen/WebAssembly/target-features-cpus.ll
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ target triple = "wasm32-unknown-unknown"
; mvp: should not contain the target features section
; MVP-NOT: .custom_section.target_features,"",@

; generic: +multivalue, +mutable-globals, +reference-types, +sign-ext
; generic: +call-indirect-overlong, +multivalue, +mutable-globals, +reference-types, +sign-ext
; GENERIC-LABEL: .custom_section.target_features,"",@
; GENERIC-NEXT: .int8 4
; GENERIC-NEXT: .int8 43
; GENERIC-NEXT: .int8 22
; GENERIC-NEXT: .ascii "call-indirect-overlong"
; GENERIC-NEXT: .int8 43
; GENERIC-NEXT: .int8 10
; GENERIC-NEXT: .ascii "multivalue"
; GENERIC-NEXT: .int8 43
Expand Down Expand Up @@ -53,10 +56,11 @@ target triple = "wasm32-unknown-unknown"
; TRAIL1-NEXT: .int8 8
; TRAIL1-NEXT: .ascii "sign-ext"

; bleeding-edge: +atomics, +bulk-memory, +exception-handling, +extended-const,
; +fp16, +multimemory, +multivalue, +mutable-globals,
; +nontrapping-fptoint, +relaxed-simd, +reference-types,
; +simd128, +sign-ext, +tail-call
; bleeding-edge: +atomics, +bulk-memory, +bulk-memory-opt,
; +call-indirect-overlong, +exception-handling,
; +extended-const, +fp16, +multimemory, +multivalue,
; +mutable-globals, +nontrapping-fptoint, +relaxed-simd,
; +reference-types, +simd128, +sign-ext, +tail-call
; BLEEDING-EDGE-LABEL: .section .custom_section.target_features,"",@
; BLEEDING-EDGE-NEXT: .int8 14
; BLEEDING-EDGE-NEXT: .int8 43
Expand All @@ -66,6 +70,12 @@ target triple = "wasm32-unknown-unknown"
; BLEEDING-EDGE-NEXT: .int8 11
; BLEEDING-EDGE-NEXT: .ascii "bulk-memory"
; BLEEDING-EDGE-NEXT: .int8 43
; BLEEDING-EDGE-NEXT: .int8 15
; BLEEDING-EDGE-NEXT: .ascii "bulk-memory-opt"
; BLEEDING-EDGE-NEXT: .int8 43
; BLEEDING-EDGE-NEXT: .int8 22
; BLEEDING-EDGE-NEXT: .ascii "call-indirect-overlong"
; BLEEDING-EDGE-NEXT: .int8 43
; BLEEDING-EDGE-NEXT: .int8 18
; BLEEDING-EDGE-NEXT: .ascii "exception-handling"
; BLEEDING-EDGE-NEXT: .int8 43
Expand Down

0 comments on commit 2fa3ef0

Please sign in to comment.