Skip to content

Commit 0983421

Browse files
committed
[WebAssembly] Add half-precision feature
This currently only defines a constant, but in the future will be used to gate builtins for experimenting and prototyping half-precision proposal (https://github.com/WebAssembly/half-precision).
1 parent 5a1d850 commit 0983421

File tree

6 files changed

+23
-0
lines changed

6 files changed

+23
-0
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4876,6 +4876,8 @@ def msimd128 : Flag<["-"], "msimd128">, Group<m_wasm_Features_Group>;
48764876
def mno_simd128 : Flag<["-"], "mno-simd128">, Group<m_wasm_Features_Group>;
48774877
def mrelaxed_simd : Flag<["-"], "mrelaxed-simd">, Group<m_wasm_Features_Group>;
48784878
def mno_relaxed_simd : Flag<["-"], "mno-relaxed-simd">, Group<m_wasm_Features_Group>;
4879+
def mhalf_precision : Flag<["-"], "mhalf-precision">, Group<m_wasm_Features_Group>;
4880+
def mno_half_precision : Flag<["-"], "mno-half-precision">, Group<m_wasm_Features_Group>;
48794881
def mnontrapping_fptoint : Flag<["-"], "mnontrapping-fptoint">, Group<m_wasm_Features_Group>;
48804882
def mno_nontrapping_fptoint : Flag<["-"], "mno-nontrapping-fptoint">, Group<m_wasm_Features_Group>;
48814883
def msign_ext : Flag<["-"], "msign-ext">, Group<m_wasm_Features_Group>;

clang/lib/Basic/Targets/WebAssembly.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ bool WebAssemblyTargetInfo::hasFeature(StringRef Feature) const {
4747
return llvm::StringSwitch<bool>(Feature)
4848
.Case("simd128", SIMDLevel >= SIMD128)
4949
.Case("relaxed-simd", SIMDLevel >= RelaxedSIMD)
50+
.Case("half-precision", HasHalfPrecision)
5051
.Case("nontrapping-fptoint", HasNontrappingFPToInt)
5152
.Case("sign-ext", HasSignExt)
5253
.Case("exception-handling", HasExceptionHandling)
@@ -156,6 +157,7 @@ bool WebAssemblyTargetInfo::initFeatureMap(
156157
Features["reference-types"] = true;
157158
Features["sign-ext"] = true;
158159
Features["tail-call"] = true;
160+
Features["half-precision"] = true;
159161
setSIMDLevel(Features, SIMD128, true);
160162
} else if (CPU == "generic") {
161163
Features["mutable-globals"] = true;
@@ -216,6 +218,15 @@ bool WebAssemblyTargetInfo::handleTargetFeatures(
216218
HasBulkMemory = false;
217219
continue;
218220
}
221+
if (Feature == "+half-precision") {
222+
SIMDLevel = std::max(SIMDLevel, SIMD128);
223+
HasHalfPrecision = true;
224+
continue;
225+
}
226+
if (Feature == "-half-precision") {
227+
HasHalfPrecision = false;
228+
continue;
229+
}
219230
if (Feature == "+atomics") {
220231
HasAtomics = true;
221232
continue;

clang/lib/Basic/Targets/WebAssembly.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo {
6464
bool HasReferenceTypes = false;
6565
bool HasExtendedConst = false;
6666
bool HasMultiMemory = false;
67+
bool HasHalfPrecision = false;
6768

6869
std::string ABI;
6970

llvm/lib/Target/WebAssembly/WebAssembly.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ def FeatureSIMD128 : SubtargetFeature<"simd128", "SIMDLevel", "SIMD128",
2828
def FeatureRelaxedSIMD : SubtargetFeature<"relaxed-simd", "SIMDLevel", "RelaxedSIMD",
2929
"Enable relaxed-simd instructions">;
3030

31+
def FeatureHalfPrecision : SubtargetFeature<"half-precision", "HasHalfPrecision", "true",
32+
"Enable half precision instructions">;
33+
3134
def FeatureAtomics : SubtargetFeature<"atomics", "HasAtomics", "true",
3235
"Enable Atomics">;
3336

llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ def HasRelaxedSIMD :
3030
Predicate<"Subtarget->hasRelaxedSIMD()">,
3131
AssemblerPredicate<(all_of FeatureRelaxedSIMD), "relaxed-simd">;
3232

33+
def HasHalfPrecision :
34+
Predicate<"Subtarget->hasHalfPrecision()">,
35+
AssemblerPredicate<(all_of FeatureHalfPrecision), "half-precision">;
36+
3337
def HasAtomics :
3438
Predicate<"Subtarget->hasAtomics()">,
3539
AssemblerPredicate<(all_of FeatureAtomics), "atomics">;

llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class WebAssemblySubtarget final : public WebAssemblyGenSubtargetInfo {
5050
bool HasReferenceTypes = false;
5151
bool HasExtendedConst = false;
5252
bool HasMultiMemory = false;
53+
bool HasHalfPrecision = false;
5354

5455
/// What processor and OS we're targeting.
5556
Triple TargetTriple;
@@ -93,6 +94,7 @@ class WebAssemblySubtarget final : public WebAssemblyGenSubtargetInfo {
9394
bool hasAddr64() const { return TargetTriple.isArch64Bit(); }
9495
bool hasSIMD128() const { return SIMDLevel >= SIMD128; }
9596
bool hasRelaxedSIMD() const { return SIMDLevel >= RelaxedSIMD; }
97+
bool hasHalfPrecision() const { return HasHalfPrecision; }
9698
bool hasAtomics() const { return HasAtomics; }
9799
bool hasNontrappingFPToInt() const { return HasNontrappingFPToInt; }
98100
bool hasSignExt() const { return HasSignExt; }

0 commit comments

Comments
 (0)