Author: Sam Clegg Date: 2022-03-07T16:45:42-08:00 New Revision: c832edfd3fbccfac6d5212d6495f0dde851dbdde
URL: https://github.com/llvm/llvm-project/commit/c832edfd3fbccfac6d5212d6495f0dde851dbdde DIFF: https://github.com/llvm/llvm-project/commit/c832edfd3fbccfac6d5212d6495f0dde851dbdde.diff LOG: [WebAssembly] Add new target feature in support of 'extended-const' proposal We don't yet do anything when this feature is enabled, this change just lays the ground work by accepting that there is such a feature. See https://github.com/WebAssembly/extended-const Differential Revision: https://reviews.llvm.org/D121151 Added: Modified: clang/docs/ClangCommandLineReference.rst clang/include/clang/Driver/Options.td clang/lib/Basic/Targets/WebAssembly.cpp clang/lib/Basic/Targets/WebAssembly.h clang/test/Preprocessor/wasm-target-features.c llvm/lib/Target/WebAssembly/WebAssembly.td llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.td llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h Removed: ################################################################################ diff --git a/clang/docs/ClangCommandLineReference.rst b/clang/docs/ClangCommandLineReference.rst index 77c20d3646500..6815dca1f1529 100644 --- a/clang/docs/ClangCommandLineReference.rst +++ b/clang/docs/ClangCommandLineReference.rst @@ -3629,6 +3629,8 @@ WebAssembly .. option:: -mtail-call, -mno-tail-call +.. option:: -mextended-const, -mno-extended-const + WebAssembly Driver ------------------ .. option:: -mexec-model=<arg> diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 24e2069711be5..06802ae424f7a 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -3468,6 +3468,8 @@ def mtail_call : Flag<["-"], "mtail-call">, Group<m_wasm_Features_Group>; def mno_tail_call : Flag<["-"], "mno-tail-call">, Group<m_wasm_Features_Group>; def mreference_types : Flag<["-"], "mreference-types">, Group<m_wasm_Features_Group>; def mno_reference_types : Flag<["-"], "mno-reference-types">, Group<m_wasm_Features_Group>; +def mextended_const : Flag<["-"], "mextended-const">, Group<m_wasm_Features_Group>; +def mno_extended_const : Flag<["-"], "mno-extended-const">, Group<m_wasm_Features_Group>; def mexec_model_EQ : Joined<["-"], "mexec-model=">, Group<m_wasm_Features_Driver_Group>, Values<"command,reactor">, HelpText<"Execution model (WebAssembly only)">; diff --git a/clang/lib/Basic/Targets/WebAssembly.cpp b/clang/lib/Basic/Targets/WebAssembly.cpp index 18ff109bf2d39..b3b6c2be5c134 100644 --- a/clang/lib/Basic/Targets/WebAssembly.cpp +++ b/clang/lib/Basic/Targets/WebAssembly.cpp @@ -56,6 +56,7 @@ bool WebAssemblyTargetInfo::hasFeature(StringRef Feature) const { .Case("multivalue", HasMultivalue) .Case("tail-call", HasTailCall) .Case("reference-types", HasReferenceTypes) + .Case("extended-const", HasExtendedConst) .Default(false); } @@ -93,6 +94,8 @@ void WebAssemblyTargetInfo::getTargetDefines(const LangOptions &Opts, Builder.defineMacro("__wasm_tail_call__"); if (HasReferenceTypes) Builder.defineMacro("__wasm_reference_types__"); + if (HasExtendedConst) + Builder.defineMacro("__wasm_extended_const__"); } void WebAssemblyTargetInfo::setSIMDLevel(llvm::StringMap<bool> &Features, @@ -240,6 +243,14 @@ bool WebAssemblyTargetInfo::handleTargetFeatures( HasReferenceTypes = false; continue; } + if (Feature == "+extended-const") { + HasExtendedConst = true; + continue; + } + if (Feature == "-extended-const") { + HasExtendedConst = false; + continue; + } Diags.Report(diag::err_opt_not_valid_with_opt) << Feature << "-target-feature"; diff --git a/clang/lib/Basic/Targets/WebAssembly.h b/clang/lib/Basic/Targets/WebAssembly.h index 075486990558b..63418869d10ac 100644 --- a/clang/lib/Basic/Targets/WebAssembly.h +++ b/clang/lib/Basic/Targets/WebAssembly.h @@ -39,6 +39,7 @@ class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo { bool HasMultivalue = false; bool HasTailCall = false; bool HasReferenceTypes = false; + bool HasExtendedConst = false; std::string ABI; diff --git a/clang/test/Preprocessor/wasm-target-features.c b/clang/test/Preprocessor/wasm-target-features.c index 3c743142a3e38..c05b26a0c2278 100644 --- a/clang/test/Preprocessor/wasm-target-features.c +++ b/clang/test/Preprocessor/wasm-target-features.c @@ -105,6 +105,15 @@ // RUN: | FileCheck %s -check-prefix=REFERENCE-TYPES // // REFERENCE-TYPES:#define __wasm_reference_types__ 1{{$}} +// +// RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: -target wasm32-unknown-unknown -mextended-const \ +// RUN: | FileCheck %s -check-prefix=EXTENDED-CONST +// RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: -target wasm64-unknown-unknown -mextended-const \ +// RUN: | FileCheck %s -check-prefix=EXTENDED-CONST +// +// EXTENDED-CONST:#define __wasm_extended_const__ 1{{$}} // RUN: %clang -E -dM %s -o - 2>&1 \ // RUN: -target wasm32-unknown-unknown -mcpu=mvp \ @@ -123,6 +132,7 @@ // MVP-NOT:#define __wasm_multivalue__ // MVP-NOT:#define __wasm_tail_call__ // MVP-NOT:#define __wasm_reference_types__ +// MVP-NOT:#define __wasm_extended_const__ // RUN: %clang -E -dM %s -o - 2>&1 \ // RUN: -target wasm32-unknown-unknown -mcpu=bleeding-edge \ @@ -142,6 +152,7 @@ // BLEEDING-EDGE-NOT:#define __wasm_exception_handling__ 1{{$}} // BLEEDING-EDGE-NOT:#define __wasm_multivalue__ 1{{$}} // BLEEDING-EDGE-NOT:#define __wasm_reference_types__ 1{{$}} +// BLEEDING-EDGE-NOT:#define __wasm_extended_const__ 1{{$}} // RUN: %clang -E -dM %s -o - 2>&1 \ // RUN: -target wasm32-unknown-unknown -mcpu=bleeding-edge -mno-simd128 \ diff --git a/llvm/lib/Target/WebAssembly/WebAssembly.td b/llvm/lib/Target/WebAssembly/WebAssembly.td index a529c6217189a..b83dcf3a8e656 100644 --- a/llvm/lib/Target/WebAssembly/WebAssembly.td +++ b/llvm/lib/Target/WebAssembly/WebAssembly.td @@ -67,6 +67,10 @@ def FeatureReferenceTypes : SubtargetFeature<"reference-types", "HasReferenceTypes", "true", "Enable reference types">; +def FeatureExtendedConst : + SubtargetFeature<"extended-const", "HasExtendedConst", "true", + "Enable extended const expressions">; + //===----------------------------------------------------------------------===// // Architectures. //===----------------------------------------------------------------------===// diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.td b/llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.td index 3fb0af1d47a0c..d700fcbc1ff4e 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.td +++ b/llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.td @@ -66,6 +66,10 @@ def HasReferenceTypes : Predicate<"Subtarget->hasReferenceTypes()">, AssemblerPredicate<(all_of FeatureReferenceTypes), "reference-types">; +def HasExtendedConst : + Predicate<"Subtarget->hasExtendedConst()">, + AssemblerPredicate<(all_of FeatureExtendedConst), "extended-const">; + //===----------------------------------------------------------------------===// // WebAssembly-specific DAG Node Types. //===----------------------------------------------------------------------===// diff --git a/llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h b/llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h index b553c81506527..7806949805235 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h +++ b/llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h @@ -48,6 +48,7 @@ class WebAssemblySubtarget final : public WebAssemblyGenSubtargetInfo { bool HasMutableGlobals = false; bool HasTailCall = false; bool HasReferenceTypes = false; + bool HasExtendedConst = false; /// What processor and OS we're targeting. Triple TargetTriple; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits