Index: cfe/trunk/include/clang/Driver/Options.td =================================================================== --- cfe/trunk/include/clang/Driver/Options.td +++ cfe/trunk/include/clang/Driver/Options.td @@ -2185,6 +2185,10 @@ def mno_bulk_memory : Flag<["-"], "mno-bulk-memory">, Group; def mmutable_globals : Flag<["-"], "mmutable-globals">, Group; def mno_mutable_globals : Flag<["-"], "mno-mutable-globals">, Group; +def mmultivalue : Flag<["-"], "mmultivalue">, Group; +def mno_multivalue : Flag<["-"], "mno-multivalue">, Group; +def mtail_call : Flag<["-"], "mtail-call">, Group; +def mno_tail_call : Flag<["-"], "mno-tail-call">, Group; def mamdgpu_debugger_abi : Joined<["-"], "mamdgpu-debugger-abi=">, Flags<[HelpHidden]>, Index: cfe/trunk/lib/Basic/Targets/WebAssembly.h =================================================================== --- cfe/trunk/lib/Basic/Targets/WebAssembly.h +++ cfe/trunk/lib/Basic/Targets/WebAssembly.h @@ -36,6 +36,8 @@ bool HasBulkMemory = false; bool HasAtomics = false; bool HasMutableGlobals = false; + bool HasMultivalue = false; + bool HasTailCall = false; public: explicit WebAssemblyTargetInfo(const llvm::Triple &T, const TargetOptions &) Index: cfe/trunk/lib/Basic/Targets/WebAssembly.cpp =================================================================== --- cfe/trunk/lib/Basic/Targets/WebAssembly.cpp +++ cfe/trunk/lib/Basic/Targets/WebAssembly.cpp @@ -43,6 +43,8 @@ .Case("bulk-memory", HasBulkMemory) .Case("atomics", HasAtomics) .Case("mutable-globals", HasMutableGlobals) + .Case("multivalue", HasMultivalue) + .Case("tail-call", HasTailCall) .Default(false); } @@ -74,6 +76,10 @@ Builder.defineMacro("__wasm_atomics__"); if (HasMutableGlobals) Builder.defineMacro("__wasm_mutable_globals__"); + if (HasMultivalue) + Builder.defineMacro("__wasm_multivalue__"); + if (HasTailCall) + Builder.defineMacro("__wasm_tail_call__"); } void WebAssemblyTargetInfo::setSIMDLevel(llvm::StringMap &Features, @@ -116,6 +122,10 @@ Features["atomics"] = true; if (HasMutableGlobals) Features["mutable-globals"] = true; + if (HasMultivalue) + Features["multivalue"] = true; + if (HasTailCall) + Features["tail-call"] = true; return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec); } @@ -187,6 +197,22 @@ HasMutableGlobals = false; continue; } + if (Feature == "+multivalue") { + HasMultivalue = true; + continue; + } + if (Feature == "-multivalue") { + HasMultivalue = false; + continue; + } + if (Feature == "+tail-call") { + HasTailCall = true; + continue; + } + if (Feature == "-tail-call") { + HasTailCall = false; + continue; + } Diags.Report(diag::err_opt_not_valid_with_opt) << Feature << "-target-feature"; Index: cfe/trunk/test/Preprocessor/wasm-target-features.c =================================================================== --- cfe/trunk/test/Preprocessor/wasm-target-features.c +++ cfe/trunk/test/Preprocessor/wasm-target-features.c @@ -80,6 +80,24 @@ // MUTABLE-GLOBALS:#define __wasm_mutable_globals__ 1{{$}} // RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: -target wasm32-unknown-unknown -mmultivalue \ +// RUN: | FileCheck %s -check-prefix=MULTIVALUE +// RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: -target wasm64-unknown-unknown -mmultivalue \ +// RUN: | FileCheck %s -check-prefix=MULTIVALUE +// +// MULTIVALUE:#define __wasm_multivalue__ 1{{$}} + +// RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: -target wasm32-unknown-unknown -mtail-call \ +// RUN: | FileCheck %s -check-prefix=TAIL-CALL +// RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: -target wasm64-unknown-unknown -mtail-call \ +// RUN: | FileCheck %s -check-prefix=TAIL-CALL +// +// TAIL-CALL:#define __wasm_tail_call__ 1{{$}} + +// RUN: %clang -E -dM %s -o - 2>&1 \ // RUN: -target wasm32-unknown-unknown -mcpu=mvp \ // RUN: | FileCheck %s -check-prefix=MVP // RUN: %clang -E -dM %s -o - 2>&1 \ @@ -94,6 +112,8 @@ // MVP-NOT:#define __wasm_bulk_memory__ // MVP-NOT:#define __wasm_atomics__ // MVP-NOT:#define __wasm_mutable_globals__ +// MVP-NOT:#define __wasm_multivalue__ +// MVP-NOT:#define __wasm_tail_call__ // RUN: %clang -E -dM %s -o - 2>&1 \ // RUN: -target wasm32-unknown-unknown -mcpu=bleeding-edge \ @@ -108,6 +128,8 @@ // BLEEDING-EDGE-DAG:#define __wasm_atomics__ 1{{$}} // BLEEDING-EDGE-DAG:#define __wasm_mutable_globals__ 1{{$}} // BLEEDING-EDGE-NOT:#define __wasm_unimplemented_simd128__ 1{{$}} +// BLEEDING-EDGE-NOT:#define __wasm_multivalue__ 1{{$}} +// BLEEDING-EDGE-NOT:#define __wasm_tail_call__ 1{{$}} // RUN: %clang -E -dM %s -o - 2>&1 \ // RUN: -target wasm32-unknown-unknown -mcpu=bleeding-edge -mno-simd128 \ Index: llvm/trunk/lib/Target/WebAssembly/WebAssembly.td =================================================================== --- llvm/trunk/lib/Target/WebAssembly/WebAssembly.td +++ llvm/trunk/lib/Target/WebAssembly/WebAssembly.td @@ -33,6 +33,7 @@ def FeatureAtomics : SubtargetFeature<"atomics", "HasAtomics", "true", "Enable Atomics">; + def FeatureNontrappingFPToInt : SubtargetFeature<"nontrapping-fptoint", "HasNontrappingFPToInt", "true", @@ -43,6 +44,11 @@ "HasSignExt", "true", "Enable sign extension operators">; +def FeatureTailCall : + SubtargetFeature<"tail-call", + "HasTailCall", "true", + "Enable tail call instructions">; + def FeatureExceptionHandling : SubtargetFeature<"exception-handling", "HasExceptionHandling", "true", "Enable Wasm exception handling">; @@ -51,6 +57,11 @@ SubtargetFeature<"bulk-memory", "HasBulkMemory", "true", "Enable bulk memory operations">; +def FeatureMultivalue : + SubtargetFeature<"multivalue", + "HasMultivalue", "true", + "Enable multivalue blocks, instructions, and functions">; + def FeatureMutableGlobals : SubtargetFeature<"mutable-globals", "HasMutableGlobals", "true", "Enable mutable globals">; Index: llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrInfo.td =================================================================== --- llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrInfo.td +++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrInfo.td @@ -34,6 +34,10 @@ Predicate<"Subtarget->hasAtomics()">, AssemblerPredicate<"FeatureAtomics", "atomics">; +def HasMultivalue : + Predicate<"Subtarget->hasMultivalue()">, + AssemblerPredicate<"FeatureMultivalue", "multivalue">; + def HasNontrappingFPToInt : Predicate<"Subtarget->hasNontrappingFPToInt()">, AssemblerPredicate<"FeatureNontrappingFPToInt", "nontrapping-fptoint">; @@ -46,18 +50,14 @@ Predicate<"Subtarget->hasSignExt()">, AssemblerPredicate<"FeatureSignExt", "sign-ext">; -def NotHasSignExt : - Predicate<"!Subtarget->hasSignExt()">, - AssemblerPredicate<"!FeatureSignExt", "sign-ext">; +def HasTailCall : + Predicate<"Subtarget->hasTailCall()">, + AssemblerPredicate<"FeatureTailCall", "tail-call">; def HasExceptionHandling : Predicate<"Subtarget->hasExceptionHandling()">, AssemblerPredicate<"FeatureExceptionHandling", "exception-handling">; -def NotHasExceptionHandling : - Predicate<"!Subtarget->hasExceptionHandling()">, - AssemblerPredicate<"!FeatureExceptionHandling", "exception-handling">; - def HasBulkMemory : Predicate<"Subtarget->hasBulkMemory()">, AssemblerPredicate<"FeatureBulkMemory", "bulk-memory">; Index: llvm/trunk/lib/Target/WebAssembly/WebAssemblySubtarget.h =================================================================== --- llvm/trunk/lib/Target/WebAssembly/WebAssemblySubtarget.h +++ llvm/trunk/lib/Target/WebAssembly/WebAssemblySubtarget.h @@ -44,7 +44,9 @@ bool HasSignExt = false; bool HasExceptionHandling = false; bool HasBulkMemory = false; + bool HasMultivalue = false; bool HasMutableGlobals = false; + bool HasTailCall = false; /// String name of used CPU. std::string CPUString; @@ -98,7 +100,9 @@ bool hasSignExt() const { return HasSignExt; } bool hasExceptionHandling() const { return HasExceptionHandling; } bool hasBulkMemory() const { return HasBulkMemory; } + bool hasMultivalue() const { return HasMultivalue; } bool hasMutableGlobals() const { return HasMutableGlobals; } + bool hasTailCall() const { return HasTailCall; } /// Parses features string setting specified subtarget options. Definition of /// function is auto generated by tblgen. Index: llvm/trunk/test/CodeGen/WebAssembly/multivalue.ll =================================================================== --- llvm/trunk/test/CodeGen/WebAssembly/multivalue.ll +++ llvm/trunk/test/CodeGen/WebAssembly/multivalue.ll @@ -0,0 +1,28 @@ +; RUN: llc < %s -asm-verbose=false -verify-machineinstrs -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+multivalue | FileCheck %s + +; Test that the multivalue attribute is accepted +; TODO(tlively): implement multivalue + +target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" +target triple = "wasm32-unknown-unknown" + +%pair = type { i32, i32 } +%packed_pair = type <{ i32, i32 }> + +; CHECK-LABEL: sret: +; CHECK-NEXT: sret (i32, i32, i32) -> () +define %pair @sret(%pair %p) { + ret %pair %p +} + +; CHECK-LABEL: packed_sret: +; CHECK-NEXT: packed_sret (i32, i32, i32) -> () +define %packed_pair @packed_sret(%packed_pair %p) { + ret %packed_pair %p +} + +; CHECK-LABEL: .section .custom_section.target_features +; CHECK-NEXT: .int8 1 +; CHECK-NEXT: .int8 43 +; CHECK-NEXT: .int8 10 +; CHECK-NEXT: .ascii "multivalue" Index: llvm/trunk/test/CodeGen/WebAssembly/tailcall.ll =================================================================== --- llvm/trunk/test/CodeGen/WebAssembly/tailcall.ll +++ llvm/trunk/test/CodeGen/WebAssembly/tailcall.ll @@ -0,0 +1,21 @@ +; RUN: llc < %s -asm-verbose=false -verify-machineinstrs -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+tail-call | FileCheck %s + +; Test that the tail-call attribute is accepted +; TODO(tlively): implement tail call + +target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" +target triple = "wasm32-unknown-unknown" + +; CHECK-LABEL: recursive_tail: +; CHECK: i32.call $push[[L0:[0-9]+]]=, recursive_tail{{$}} +; CHECK-NEXT: return $pop[[L0]]{{$}} +define i32 @recursive_tail() { + %v = tail call i32 @recursive_tail() + ret i32 %v +} + +; CHECK-LABEL: .section .custom_section.target_features +; CHECK-NEXT: .int8 1 +; CHECK-NEXT: .int8 43 +; CHECK-NEXT: .int8 9 +; CHECK-NEXT: .ascii "tail-call"