Skip to content

Commit f8ffb4f

Browse files
committed
Add wide-arithmetic support to clang too
1 parent ff058da commit f8ffb4f

File tree

5 files changed

+33
-0
lines changed

5 files changed

+33
-0
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5098,6 +5098,8 @@ def msimd128 : Flag<["-"], "msimd128">, Group<m_wasm_Features_Group>;
50985098
def mno_simd128 : Flag<["-"], "mno-simd128">, Group<m_wasm_Features_Group>;
50995099
def mtail_call : Flag<["-"], "mtail-call">, Group<m_wasm_Features_Group>;
51005100
def mno_tail_call : Flag<["-"], "mno-tail-call">, Group<m_wasm_Features_Group>;
5101+
def mwide_arithmetic : Flag<["-"], "mwide-arithmetic">, Group<m_wasm_Features_Group>;
5102+
def mno_wide_arithmetic : Flag<["-"], "mno-wide-arithmetic">, Group<m_wasm_Features_Group>;
51015103
def mexec_model_EQ : Joined<["-"], "mexec-model=">, Group<m_wasm_Features_Driver_Group>,
51025104
Values<"command,reactor">,
51035105
HelpText<"Execution model (WebAssembly only)">,

clang/lib/Basic/Targets/WebAssembly.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ bool WebAssemblyTargetInfo::hasFeature(StringRef Feature) const {
5959
.Case("sign-ext", HasSignExt)
6060
.Case("simd128", SIMDLevel >= SIMD128)
6161
.Case("tail-call", HasTailCall)
62+
.Case("wide-arithmetic", HasWideArithmetic)
6263
.Default(false);
6364
}
6465

@@ -102,6 +103,8 @@ void WebAssemblyTargetInfo::getTargetDefines(const LangOptions &Opts,
102103
Builder.defineMacro("__wasm_simd128__");
103104
if (HasTailCall)
104105
Builder.defineMacro("__wasm_tail_call__");
106+
if (HasWideArithmetic)
107+
Builder.defineMacro("__wasm_wide_arithmetic__");
105108

106109
Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
107110
Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
@@ -166,6 +169,7 @@ bool WebAssemblyTargetInfo::initFeatureMap(
166169
Features["multimemory"] = true;
167170
Features["nontrapping-fptoint"] = true;
168171
Features["tail-call"] = true;
172+
Features["wide-arithmetic"] = true;
169173
setSIMDLevel(Features, RelaxedSIMD, true);
170174
};
171175
if (CPU == "generic") {
@@ -293,6 +297,14 @@ bool WebAssemblyTargetInfo::handleTargetFeatures(
293297
HasTailCall = false;
294298
continue;
295299
}
300+
if (Feature == "+wide-arithmetic") {
301+
HasWideArithmetic = true;
302+
continue;
303+
}
304+
if (Feature == "-wide-arithmetic") {
305+
HasWideArithmetic = false;
306+
continue;
307+
}
296308

297309
Diags.Report(diag::err_opt_not_valid_with_opt)
298310
<< Feature << "-target-feature";

clang/lib/Basic/Targets/WebAssembly.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo {
6565
bool HasReferenceTypes = false;
6666
bool HasSignExt = false;
6767
bool HasTailCall = false;
68+
bool HasWideArithmetic = false;
6869

6970
std::string ABI;
7071

clang/test/Driver/wasm-features.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,9 @@
9494

9595
// TAIL-CALL: "-target-feature" "+tail-call"
9696
// NO-TAIL-CALL: "-target-feature" "-tail-call"
97+
98+
// RUN: %clang --target=wasm32-unknown-unknown -### %s -mwide-arithmetic 2>&1 | FileCheck %s -check-prefix=WIDE-ARITH
99+
// RUN: %clang --target=wasm32-unknown-unknown -### %s -mno-wide-arithmetic 2>&1 | FileCheck %s -check-prefix=NO-WIDE-ARITH
100+
101+
// WIDE-ARITH: "-target-feature" "+wide-arithmetic"
102+
// NO-WIDE-ARITH: "-target-feature" "-wide-arithmetic"

clang/test/Preprocessor/wasm-target-features.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@
154154
// MVP-NOT: #define __wasm_sign_ext__ 1{{$}}
155155
// MVP-NOT: #define __wasm_simd128__ 1{{$}}
156156
// MVP-NOT: #define __wasm_tail_call__ 1{{$}}
157+
// MVP-NOT: #define __wasm_wide_arithmetic__ 1{{$}}
157158

158159
// RUN: %clang -E -dM %s -o - 2>&1 \
159160
// RUN: -target wasm32-unknown-unknown -mcpu=generic \
@@ -184,6 +185,7 @@
184185
// GENERIC-NOT: #define __wasm_relaxed_simd__ 1{{$}}
185186
// GENERIC-NOT: #define __wasm_simd128__ 1{{$}}
186187
// GENERIC-NOT: #define __wasm_tail_call__ 1{{$}}
188+
// GENERIC-NOT: #define __wasm_wide_arithmetic__ 1{{$}}
187189

188190
// RUN: %clang -E -dM %s -o - 2>&1 \
189191
// RUN: -target wasm32-unknown-unknown -mcpu=bleeding-edge \
@@ -206,6 +208,7 @@
206208
// BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_sign_ext__ 1{{$}}
207209
// BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_simd128__ 1{{$}}
208210
// BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_tail_call__ 1{{$}}
211+
// BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_wide_arithmetic__ 1{{$}}
209212

210213
// RUN: %clang -E -dM %s -o - 2>&1 \
211214
// RUN: -target wasm32-unknown-unknown -mcpu=bleeding-edge -mno-simd128 \
@@ -215,3 +218,12 @@
215218
// RUN: | FileCheck %s -check-prefix=BLEEDING-EDGE-NO-SIMD128
216219
//
217220
// BLEEDING-EDGE-NO-SIMD128-NOT: #define __wasm_simd128__ 1{{$}}
221+
222+
// RUN: %clang -E -dM %s -o - 2>&1 \
223+
// RUN: -target wasm32-unknown-unknown -mwide-arithmetic \
224+
// RUN: | FileCheck %s -check-prefix=WIDE-ARITHMETIC
225+
// RUN: %clang -E -dM %s -o - 2>&1 \
226+
// RUN: -target wasm64-unknown-unknown -mwide-arithmetic \
227+
// RUN: | FileCheck %s -check-prefix=WIDE-ARITHMETIC
228+
//
229+
// WIDE-ARITHMETIC: #define __wasm_wide_arithmetic__ 1{{$}}

0 commit comments

Comments
 (0)