Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WebAssembly] Sort target features (NFC) #90777

Merged
merged 2 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -4895,34 +4895,34 @@ def mharden_sls_EQ : Joined<["-"], "mharden-sls=">, Group<m_Group>,
" blr(ARM/AArch64), comdat(ARM/AArch64), nocomdat(ARM/AArch64),"
" return(X86), indirect-jmp(X86)">;

def msimd128 : Flag<["-"], "msimd128">, Group<m_wasm_Features_Group>;
def mno_simd128 : Flag<["-"], "mno-simd128">, Group<m_wasm_Features_Group>;
def mrelaxed_simd : Flag<["-"], "mrelaxed-simd">, Group<m_wasm_Features_Group>;
def mno_relaxed_simd : Flag<["-"], "mno-relaxed-simd">, Group<m_wasm_Features_Group>;
def mhalf_precision : Flag<["-"], "mhalf-precision">, Group<m_wasm_Features_Group>;
def mno_half_precision : Flag<["-"], "mno-half-precision">, Group<m_wasm_Features_Group>;
def mnontrapping_fptoint : Flag<["-"], "mnontrapping-fptoint">, Group<m_wasm_Features_Group>;
def mno_nontrapping_fptoint : Flag<["-"], "mno-nontrapping-fptoint">, Group<m_wasm_Features_Group>;
def msign_ext : Flag<["-"], "msign-ext">, Group<m_wasm_Features_Group>;
def mno_sign_ext : Flag<["-"], "mno-sign-ext">, Group<m_wasm_Features_Group>;
def mexception_handing : Flag<["-"], "mexception-handling">, Group<m_wasm_Features_Group>;
def mno_exception_handing : Flag<["-"], "mno-exception-handling">, Group<m_wasm_Features_Group>;
def matomics : Flag<["-"], "matomics">, Group<m_wasm_Features_Group>;
def mno_atomics : Flag<["-"], "mno-atomics">, Group<m_wasm_Features_Group>;
def mbulk_memory : Flag<["-"], "mbulk-memory">, Group<m_wasm_Features_Group>;
def mno_bulk_memory : Flag<["-"], "mno-bulk-memory">, Group<m_wasm_Features_Group>;
def mmutable_globals : Flag<["-"], "mmutable-globals">, Group<m_wasm_Features_Group>;
def mno_mutable_globals : Flag<["-"], "mno-mutable-globals">, Group<m_wasm_Features_Group>;
def mmultivalue : Flag<["-"], "mmultivalue">, Group<m_wasm_Features_Group>;
def mno_multivalue : Flag<["-"], "mno-multivalue">, Group<m_wasm_Features_Group>;
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 mexception_handing : Flag<["-"], "mexception-handling">, Group<m_wasm_Features_Group>;
def mno_exception_handing : Flag<["-"], "mno-exception-handling">, 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 mhalf_precision : Flag<["-"], "mhalf-precision">, Group<m_wasm_Features_Group>;
def mno_half_precision : Flag<["-"], "mno-half-precision">, Group<m_wasm_Features_Group>;
def mmultimemory : Flag<["-"], "mmultimemory">, Group<m_wasm_Features_Group>;
def mno_multimemory : Flag<["-"], "mno-multimemory">, Group<m_wasm_Features_Group>;
def mmultivalue : Flag<["-"], "mmultivalue">, Group<m_wasm_Features_Group>;
def mno_multivalue : Flag<["-"], "mno-multivalue">, Group<m_wasm_Features_Group>;
def mmutable_globals : Flag<["-"], "mmutable-globals">, Group<m_wasm_Features_Group>;
def mno_mutable_globals : Flag<["-"], "mno-mutable-globals">, Group<m_wasm_Features_Group>;
def mnontrapping_fptoint : Flag<["-"], "mnontrapping-fptoint">, Group<m_wasm_Features_Group>;
def mno_nontrapping_fptoint : Flag<["-"], "mno-nontrapping-fptoint">, 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 mrelaxed_simd : Flag<["-"], "mrelaxed-simd">, Group<m_wasm_Features_Group>;
def mno_relaxed_simd : Flag<["-"], "mno-relaxed-simd">, Group<m_wasm_Features_Group>;
def msign_ext : Flag<["-"], "msign-ext">, Group<m_wasm_Features_Group>;
def mno_sign_ext : Flag<["-"], "mno-sign-ext">, Group<m_wasm_Features_Group>;
def msimd128 : Flag<["-"], "msimd128">, Group<m_wasm_Features_Group>;
def mno_simd128 : Flag<["-"], "mno-simd128">, Group<m_wasm_Features_Group>;
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 mexec_model_EQ : Joined<["-"], "mexec-model=">, Group<m_wasm_Features_Driver_Group>,
Values<"command,reactor">,
HelpText<"Execution model (WebAssembly only)">,
Expand Down
166 changes: 83 additions & 83 deletions clang/lib/Basic/Targets/WebAssembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,20 @@ bool WebAssemblyTargetInfo::setABI(const std::string &Name) {

bool WebAssemblyTargetInfo::hasFeature(StringRef Feature) const {
return llvm::StringSwitch<bool>(Feature)
.Case("simd128", SIMDLevel >= SIMD128)
.Case("relaxed-simd", SIMDLevel >= RelaxedSIMD)
.Case("atomics", HasAtomics)
.Case("bulk-memory", HasBulkMemory)
.Case("exception-handling", HasExceptionHandling)
.Case("extended-const", HasExtendedConst)
.Case("half-precision", HasHalfPrecision)
.Case("multimemory", HasMultiMemory)
.Case("multivalue", HasMultivalue)
.Case("mutable-globals", HasMutableGlobals)
.Case("nontrapping-fptoint", HasNontrappingFPToInt)
.Case("reference-types", HasReferenceTypes)
.Case("relaxed-simd", SIMDLevel >= RelaxedSIMD)
.Case("sign-ext", HasSignExt)
.Case("exception-handling", HasExceptionHandling)
.Case("bulk-memory", HasBulkMemory)
.Case("atomics", HasAtomics)
.Case("mutable-globals", HasMutableGlobals)
.Case("multivalue", HasMultivalue)
.Case("simd128", SIMDLevel >= SIMD128)
.Case("tail-call", HasTailCall)
.Case("reference-types", HasReferenceTypes)
.Case("extended-const", HasExtendedConst)
.Case("multimemory", HasMultiMemory)
.Default(false);
}

Expand All @@ -74,34 +74,34 @@ void WebAssemblyTargetInfo::fillValidCPUList(
void WebAssemblyTargetInfo::getTargetDefines(const LangOptions &Opts,
MacroBuilder &Builder) const {
defineCPUMacros(Builder, "wasm", /*Tuning=*/false);
if (SIMDLevel >= SIMD128)
Builder.defineMacro("__wasm_simd128__");
if (SIMDLevel >= RelaxedSIMD)
Builder.defineMacro("__wasm_relaxed_simd__");
if (HasNontrappingFPToInt)
Builder.defineMacro("__wasm_nontrapping_fptoint__");
if (HasSignExt)
Builder.defineMacro("__wasm_sign_ext__");
if (HasExceptionHandling)
Builder.defineMacro("__wasm_exception_handling__");
if (HasBulkMemory)
Builder.defineMacro("__wasm_bulk_memory__");
if (HasAtomics)
Builder.defineMacro("__wasm_atomics__");
if (HasMutableGlobals)
Builder.defineMacro("__wasm_mutable_globals__");
if (HasMultivalue)
Builder.defineMacro("__wasm_multivalue__");
if (HasTailCall)
Builder.defineMacro("__wasm_tail_call__");
if (HasReferenceTypes)
Builder.defineMacro("__wasm_reference_types__");
if (HasBulkMemory)
Builder.defineMacro("__wasm_bulk_memory__");
if (HasExceptionHandling)
Builder.defineMacro("__wasm_exception_handling__");
if (HasExtendedConst)
Builder.defineMacro("__wasm_extended_const__");
if (HasMultiMemory)
Builder.defineMacro("__wasm_multimemory__");
if (HasHalfPrecision)
Builder.defineMacro("__wasm_half_precision__");
if (HasMultivalue)
Builder.defineMacro("__wasm_multivalue__");
if (HasMutableGlobals)
Builder.defineMacro("__wasm_mutable_globals__");
if (HasNontrappingFPToInt)
Builder.defineMacro("__wasm_nontrapping_fptoint__");
if (HasReferenceTypes)
Builder.defineMacro("__wasm_reference_types__");
if (SIMDLevel >= RelaxedSIMD)
Builder.defineMacro("__wasm_relaxed_simd__");
if (HasSignExt)
Builder.defineMacro("__wasm_sign_ext__");
if (SIMDLevel >= SIMD128)
Builder.defineMacro("__wasm_simd128__");
if (HasTailCall)
Builder.defineMacro("__wasm_tail_call__");

Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
Expand Down Expand Up @@ -160,10 +160,10 @@ bool WebAssemblyTargetInfo::initFeatureMap(
addGenericFeatures();
Features["atomics"] = true;
Features["bulk-memory"] = true;
Features["half-precision"] = true;
Features["multimemory"] = true;
Features["nontrapping-fptoint"] = true;
Features["tail-call"] = true;
Features["half-precision"] = true;
setSIMDLevel(Features, SIMD128, true);
};
if (CPU == "generic") {
Expand All @@ -178,36 +178,20 @@ bool WebAssemblyTargetInfo::initFeatureMap(
bool WebAssemblyTargetInfo::handleTargetFeatures(
std::vector<std::string> &Features, DiagnosticsEngine &Diags) {
for (const auto &Feature : Features) {
if (Feature == "+simd128") {
SIMDLevel = std::max(SIMDLevel, SIMD128);
continue;
}
if (Feature == "-simd128") {
SIMDLevel = std::min(SIMDLevel, SIMDEnum(SIMD128 - 1));
continue;
}
if (Feature == "+relaxed-simd") {
SIMDLevel = std::max(SIMDLevel, RelaxedSIMD);
continue;
}
if (Feature == "-relaxed-simd") {
SIMDLevel = std::min(SIMDLevel, SIMDEnum(RelaxedSIMD - 1));
continue;
}
if (Feature == "+nontrapping-fptoint") {
HasNontrappingFPToInt = true;
if (Feature == "+atomics") {
HasAtomics = true;
continue;
}
if (Feature == "-nontrapping-fptoint") {
HasNontrappingFPToInt = false;
if (Feature == "-atomics") {
HasAtomics = false;
continue;
}
if (Feature == "+sign-ext") {
HasSignExt = true;
if (Feature == "+bulk-memory") {
HasBulkMemory = true;
continue;
}
if (Feature == "-sign-ext") {
HasSignExt = false;
if (Feature == "-bulk-memory") {
HasBulkMemory = false;
continue;
}
if (Feature == "+exception-handling") {
Expand All @@ -218,12 +202,12 @@ bool WebAssemblyTargetInfo::handleTargetFeatures(
HasExceptionHandling = false;
continue;
}
if (Feature == "+bulk-memory") {
HasBulkMemory = true;
if (Feature == "+extended-const") {
HasExtendedConst = true;
continue;
}
if (Feature == "-bulk-memory") {
HasBulkMemory = false;
if (Feature == "-extended-const") {
HasExtendedConst = false;
continue;
}
if (Feature == "+half-precision") {
Expand All @@ -235,20 +219,12 @@ bool WebAssemblyTargetInfo::handleTargetFeatures(
HasHalfPrecision = false;
continue;
}
if (Feature == "+atomics") {
HasAtomics = true;
continue;
}
if (Feature == "-atomics") {
HasAtomics = false;
continue;
}
if (Feature == "+mutable-globals") {
HasMutableGlobals = true;
if (Feature == "+multimemory") {
HasMultiMemory = true;
continue;
}
if (Feature == "-mutable-globals") {
HasMutableGlobals = false;
if (Feature == "-multimemory") {
HasMultiMemory = false;
continue;
}
if (Feature == "+multivalue") {
Expand All @@ -259,12 +235,20 @@ bool WebAssemblyTargetInfo::handleTargetFeatures(
HasMultivalue = false;
continue;
}
if (Feature == "+tail-call") {
HasTailCall = true;
if (Feature == "+mutable-globals") {
HasMutableGlobals = true;
continue;
}
if (Feature == "-tail-call") {
HasTailCall = false;
if (Feature == "-mutable-globals") {
HasMutableGlobals = false;
continue;
}
if (Feature == "+nontrapping-fptoint") {
HasNontrappingFPToInt = true;
continue;
}
if (Feature == "-nontrapping-fptoint") {
HasNontrappingFPToInt = false;
continue;
}
if (Feature == "+reference-types") {
Expand All @@ -275,20 +259,36 @@ bool WebAssemblyTargetInfo::handleTargetFeatures(
HasReferenceTypes = false;
continue;
}
if (Feature == "+extended-const") {
HasExtendedConst = true;
if (Feature == "+relaxed-simd") {
SIMDLevel = std::max(SIMDLevel, RelaxedSIMD);
continue;
}
if (Feature == "-extended-const") {
HasExtendedConst = false;
if (Feature == "-relaxed-simd") {
SIMDLevel = std::min(SIMDLevel, SIMDEnum(RelaxedSIMD - 1));
continue;
}
if (Feature == "+multimemory") {
HasMultiMemory = true;
if (Feature == "+sign-ext") {
HasSignExt = true;
continue;
}
if (Feature == "-multimemory") {
HasMultiMemory = false;
if (Feature == "-sign-ext") {
HasSignExt = false;
continue;
}
if (Feature == "+simd128") {
SIMDLevel = std::max(SIMDLevel, SIMD128);
continue;
}
if (Feature == "-simd128") {
SIMDLevel = std::min(SIMDLevel, SIMDEnum(SIMD128 - 1));
continue;
}
if (Feature == "+tail-call") {
HasTailCall = true;
continue;
}
if (Feature == "-tail-call") {
HasTailCall = false;
continue;
}

Expand Down
18 changes: 9 additions & 9 deletions clang/lib/Basic/Targets/WebAssembly.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,18 @@ class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo {
RelaxedSIMD,
} SIMDLevel = NoSIMD;

bool HasNontrappingFPToInt = false;
bool HasSignExt = false;
bool HasExceptionHandling = false;
bool HasBulkMemory = false;
bool HasAtomics = false;
bool HasMutableGlobals = false;
bool HasMultivalue = false;
bool HasTailCall = false;
bool HasReferenceTypes = false;
bool HasBulkMemory = false;
bool HasExceptionHandling = false;
bool HasExtendedConst = false;
bool HasMultiMemory = false;
bool HasHalfPrecision = false;
bool HasMultiMemory = false;
bool HasMultivalue = false;
bool HasMutableGlobals = false;
bool HasNontrappingFPToInt = false;
bool HasReferenceTypes = false;
bool HasSignExt = false;
bool HasTailCall = false;

std::string ABI;

Expand Down
Loading
Loading