From 5cb757a4741ccb3490ca24f49474492620c966c0 Mon Sep 17 00:00:00 2001
From: Thomas Lively <tlively@google.com>
Date: Thu, 10 Jan 2019 23:49:00 +0000
Subject: [WebAssembly] Add unimplemented-simd128 feature, gate builtins

Summary: Depends on D56501. Also adds a macro define
`__wasm_unimplemented_simd128__` for feature detection of
unimplemented SIMD builtins.

Reviewers: aheejin, dschuff

Subscribers: sbc100, jgravelle-google, sunfish, kristina, cfe-commits, rrwinterton

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@350909 91177308-0d34-0410-b5e6-96231b3b80d8
---
 include/clang/Basic/BuiltinsWebAssembly.def | 141 ++++++++++++++--------------
 1 file changed, 73 insertions(+), 68 deletions(-)

(limited to 'include/clang/Basic/BuiltinsWebAssembly.def')

diff --git a/include/clang/Basic/BuiltinsWebAssembly.def b/include/clang/Basic/BuiltinsWebAssembly.def
index e1e97fe26a..7b201dbf0e 100644
--- a/include/clang/Basic/BuiltinsWebAssembly.def
+++ b/include/clang/Basic/BuiltinsWebAssembly.def
@@ -16,6 +16,10 @@
 
 // The format of this database matches clang/Basic/Builtins.def.
 
+#if defined(BUILTIN) && !defined(TARGET_BUILTIN)
+#   define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE) BUILTIN(ID, TYPE, ATTRS)
+#endif
+
 // Query the current memory size, and increase the current memory size.
 // Note that memory.size is not "c" (readnone) because it must be sequenced
 // with respect to memory.grow calls.
@@ -30,9 +34,15 @@ BUILTIN(__builtin_wasm_mem_grow, "zIiz", "n")
 BUILTIN(__builtin_wasm_current_memory, "z", "n")
 BUILTIN(__builtin_wasm_grow_memory, "zz", "n")
 
+// Floating point min/max
+BUILTIN(__builtin_wasm_min_f32, "fff", "nc")
+BUILTIN(__builtin_wasm_max_f32, "fff", "nc")
+BUILTIN(__builtin_wasm_min_f64, "ddd", "nc")
+BUILTIN(__builtin_wasm_max_f64, "ddd", "nc")
+
 // Exception handling builtins.
-BUILTIN(__builtin_wasm_throw, "vUiv*", "r")
-BUILTIN(__builtin_wasm_rethrow, "v", "r")
+TARGET_BUILTIN(__builtin_wasm_throw, "vUiv*", "r", "exception-handling")
+TARGET_BUILTIN(__builtin_wasm_rethrow, "v", "r", "exception-handling")
 
 // Atomic wait and notify.
 BUILTIN(__builtin_wasm_atomic_wait_i32, "ii*iLLi", "n")
@@ -40,73 +50,68 @@ BUILTIN(__builtin_wasm_atomic_wait_i64, "iLLi*LLiLLi", "n")
 BUILTIN(__builtin_wasm_atomic_notify, "Uii*Ui", "n")
 
 // Saturating fp-to-int conversions
-BUILTIN(__builtin_wasm_trunc_saturate_s_i32_f32, "if", "nc")
-BUILTIN(__builtin_wasm_trunc_saturate_u_i32_f32, "if", "nc")
-BUILTIN(__builtin_wasm_trunc_saturate_s_i32_f64, "id", "nc")
-BUILTIN(__builtin_wasm_trunc_saturate_u_i32_f64, "id", "nc")
-BUILTIN(__builtin_wasm_trunc_saturate_s_i64_f32, "LLif", "nc")
-BUILTIN(__builtin_wasm_trunc_saturate_u_i64_f32, "LLif", "nc")
-BUILTIN(__builtin_wasm_trunc_saturate_s_i64_f64, "LLid", "nc")
-BUILTIN(__builtin_wasm_trunc_saturate_u_i64_f64, "LLid", "nc")
-
-// Floating point min/max
-BUILTIN(__builtin_wasm_min_f32, "fff", "nc")
-BUILTIN(__builtin_wasm_max_f32, "fff", "nc")
-BUILTIN(__builtin_wasm_min_f64, "ddd", "nc")
-BUILTIN(__builtin_wasm_max_f64, "ddd", "nc")
+TARGET_BUILTIN(__builtin_wasm_trunc_saturate_s_i32_f32, "if", "nc", "nontrapping-fptoint")
+TARGET_BUILTIN(__builtin_wasm_trunc_saturate_u_i32_f32, "if", "nc", "nontrapping-fptoint")
+TARGET_BUILTIN(__builtin_wasm_trunc_saturate_s_i32_f64, "id", "nc", "nontrapping-fptoint")
+TARGET_BUILTIN(__builtin_wasm_trunc_saturate_u_i32_f64, "id", "nc", "nontrapping-fptoint")
+TARGET_BUILTIN(__builtin_wasm_trunc_saturate_s_i64_f32, "LLif", "nc", "nontrapping-fptoint")
+TARGET_BUILTIN(__builtin_wasm_trunc_saturate_u_i64_f32, "LLif", "nc", "nontrapping-fptoint")
+TARGET_BUILTIN(__builtin_wasm_trunc_saturate_s_i64_f64, "LLid", "nc", "nontrapping-fptoint")
+TARGET_BUILTIN(__builtin_wasm_trunc_saturate_u_i64_f64, "LLid", "nc", "nontrapping-fptoint")
 
 // SIMD builtins
-BUILTIN(__builtin_wasm_extract_lane_s_i8x16, "iV16cIi", "nc")
-BUILTIN(__builtin_wasm_extract_lane_u_i8x16, "iV16cIi", "nc")
-BUILTIN(__builtin_wasm_extract_lane_s_i16x8, "iV8sIi", "nc")
-BUILTIN(__builtin_wasm_extract_lane_u_i16x8, "iV8sIi", "nc")
-BUILTIN(__builtin_wasm_extract_lane_i32x4, "iV4iIi", "nc")
-BUILTIN(__builtin_wasm_extract_lane_i64x2, "LLiV2LLiIi", "nc")
-BUILTIN(__builtin_wasm_extract_lane_f32x4, "fV4fIi", "nc")
-BUILTIN(__builtin_wasm_extract_lane_f64x2, "dV2dIi", "nc")
-
-BUILTIN(__builtin_wasm_replace_lane_i8x16, "V16cV16cIii", "nc")
-BUILTIN(__builtin_wasm_replace_lane_i16x8, "V8sV8sIii", "nc")
-BUILTIN(__builtin_wasm_replace_lane_i32x4, "V4iV4iIii", "nc")
-BUILTIN(__builtin_wasm_replace_lane_i64x2, "V2LLiV2LLiIiLLi", "nc")
-BUILTIN(__builtin_wasm_replace_lane_f32x4, "V4fV4fIif", "nc")
-BUILTIN(__builtin_wasm_replace_lane_f64x2, "V2dV2dIid", "nc")
-
-BUILTIN(__builtin_wasm_add_saturate_s_i8x16, "V16cV16cV16c", "nc")
-BUILTIN(__builtin_wasm_add_saturate_u_i8x16, "V16cV16cV16c", "nc")
-BUILTIN(__builtin_wasm_add_saturate_s_i16x8, "V8sV8sV8s", "nc")
-BUILTIN(__builtin_wasm_add_saturate_u_i16x8, "V8sV8sV8s", "nc")
-
-BUILTIN(__builtin_wasm_sub_saturate_s_i8x16, "V16cV16cV16c", "nc")
-BUILTIN(__builtin_wasm_sub_saturate_u_i8x16, "V16cV16cV16c", "nc")
-BUILTIN(__builtin_wasm_sub_saturate_s_i16x8, "V8sV8sV8s", "nc")
-BUILTIN(__builtin_wasm_sub_saturate_u_i16x8, "V8sV8sV8s", "nc")
-
-BUILTIN(__builtin_wasm_bitselect, "V4iV4iV4iV4i", "nc")
-
-BUILTIN(__builtin_wasm_any_true_i8x16, "iV16c", "nc")
-BUILTIN(__builtin_wasm_any_true_i16x8, "iV8s", "nc")
-BUILTIN(__builtin_wasm_any_true_i32x4, "iV4i", "nc")
-BUILTIN(__builtin_wasm_any_true_i64x2, "iV2LLi", "nc")
-BUILTIN(__builtin_wasm_all_true_i8x16, "iV16c", "nc")
-BUILTIN(__builtin_wasm_all_true_i16x8, "iV8s", "nc")
-BUILTIN(__builtin_wasm_all_true_i32x4, "iV4i", "nc")
-BUILTIN(__builtin_wasm_all_true_i64x2, "iV2LLi", "nc")
-
-BUILTIN(__builtin_wasm_abs_f32x4, "V4fV4f", "nc")
-BUILTIN(__builtin_wasm_abs_f64x2, "V2dV2d", "nc")
-
-BUILTIN(__builtin_wasm_min_f32x4, "V4fV4fV4f", "nc")
-BUILTIN(__builtin_wasm_max_f32x4, "V4fV4fV4f", "nc")
-BUILTIN(__builtin_wasm_min_f64x2, "V2dV2dV2d", "nc")
-BUILTIN(__builtin_wasm_max_f64x2, "V2dV2dV2d", "nc")
-
-BUILTIN(__builtin_wasm_sqrt_f32x4, "V4fV4f", "nc")
-BUILTIN(__builtin_wasm_sqrt_f64x2, "V2dV2d", "nc")
-
-BUILTIN(__builtin_wasm_trunc_saturate_s_i32x4_f32x4, "V4iV4f", "nc")
-BUILTIN(__builtin_wasm_trunc_saturate_u_i32x4_f32x4, "V4iV4f", "nc")
-BUILTIN(__builtin_wasm_trunc_saturate_s_i64x2_f64x2, "V2LLiV2d", "nc")
-BUILTIN(__builtin_wasm_trunc_saturate_u_i64x2_f64x2, "V2LLiV2d", "nc")
+TARGET_BUILTIN(__builtin_wasm_extract_lane_s_i8x16, "iV16cIi", "nc", "simd128")
+TARGET_BUILTIN(__builtin_wasm_extract_lane_u_i8x16, "iV16cIi", "nc", "unimplemented-simd128")
+TARGET_BUILTIN(__builtin_wasm_extract_lane_s_i16x8, "iV8sIi", "nc", "simd128")
+TARGET_BUILTIN(__builtin_wasm_extract_lane_u_i16x8, "iV8sIi", "nc", "unimplemented-simd128")
+TARGET_BUILTIN(__builtin_wasm_extract_lane_i32x4, "iV4iIi", "nc", "simd128")
+TARGET_BUILTIN(__builtin_wasm_extract_lane_i64x2, "LLiV2LLiIi", "nc", "unimplemented-simd128")
+TARGET_BUILTIN(__builtin_wasm_extract_lane_f32x4, "fV4fIi", "nc", "simd128")
+TARGET_BUILTIN(__builtin_wasm_extract_lane_f64x2, "dV2dIi", "nc", "unimplemented-simd128")
+
+TARGET_BUILTIN(__builtin_wasm_replace_lane_i8x16, "V16cV16cIii", "nc", "simd128")
+TARGET_BUILTIN(__builtin_wasm_replace_lane_i16x8, "V8sV8sIii", "nc", "simd128")
+TARGET_BUILTIN(__builtin_wasm_replace_lane_i32x4, "V4iV4iIii", "nc", "simd128")
+TARGET_BUILTIN(__builtin_wasm_replace_lane_i64x2, "V2LLiV2LLiIiLLi", "nc", "unimplemented-simd128")
+TARGET_BUILTIN(__builtin_wasm_replace_lane_f32x4, "V4fV4fIif", "nc", "simd128")
+TARGET_BUILTIN(__builtin_wasm_replace_lane_f64x2, "V2dV2dIid", "nc", "unimplemented-simd128")
+
+TARGET_BUILTIN(__builtin_wasm_add_saturate_s_i8x16, "V16cV16cV16c", "nc", "simd128")
+TARGET_BUILTIN(__builtin_wasm_add_saturate_u_i8x16, "V16cV16cV16c", "nc", "simd128")
+TARGET_BUILTIN(__builtin_wasm_add_saturate_s_i16x8, "V8sV8sV8s", "nc", "simd128")
+TARGET_BUILTIN(__builtin_wasm_add_saturate_u_i16x8, "V8sV8sV8s", "nc", "simd128")
+
+TARGET_BUILTIN(__builtin_wasm_sub_saturate_s_i8x16, "V16cV16cV16c", "nc", "simd128")
+TARGET_BUILTIN(__builtin_wasm_sub_saturate_u_i8x16, "V16cV16cV16c", "nc", "simd128")
+TARGET_BUILTIN(__builtin_wasm_sub_saturate_s_i16x8, "V8sV8sV8s", "nc", "simd128")
+TARGET_BUILTIN(__builtin_wasm_sub_saturate_u_i16x8, "V8sV8sV8s", "nc", "simd128")
+
+TARGET_BUILTIN(__builtin_wasm_bitselect, "V4iV4iV4iV4i", "nc", "simd128")
+
+TARGET_BUILTIN(__builtin_wasm_any_true_i8x16, "iV16c", "nc", "simd128")
+TARGET_BUILTIN(__builtin_wasm_any_true_i16x8, "iV8s", "nc", "simd128")
+TARGET_BUILTIN(__builtin_wasm_any_true_i32x4, "iV4i", "nc", "simd128")
+TARGET_BUILTIN(__builtin_wasm_any_true_i64x2, "iV2LLi", "nc", "unimplemented-simd128")
+TARGET_BUILTIN(__builtin_wasm_all_true_i8x16, "iV16c", "nc", "simd128")
+TARGET_BUILTIN(__builtin_wasm_all_true_i16x8, "iV8s", "nc", "simd128")
+TARGET_BUILTIN(__builtin_wasm_all_true_i32x4, "iV4i", "nc", "simd128")
+TARGET_BUILTIN(__builtin_wasm_all_true_i64x2, "iV2LLi", "nc", "unimplemented-simd128")
+
+TARGET_BUILTIN(__builtin_wasm_abs_f32x4, "V4fV4f", "nc", "simd128")
+TARGET_BUILTIN(__builtin_wasm_abs_f64x2, "V2dV2d", "nc", "unimplemented-simd128")
+
+TARGET_BUILTIN(__builtin_wasm_min_f32x4, "V4fV4fV4f", "nc", "simd128")
+TARGET_BUILTIN(__builtin_wasm_max_f32x4, "V4fV4fV4f", "nc", "simd128")
+TARGET_BUILTIN(__builtin_wasm_min_f64x2, "V2dV2dV2d", "nc", "unimplemented-simd128")
+TARGET_BUILTIN(__builtin_wasm_max_f64x2, "V2dV2dV2d", "nc", "unimplemented-simd128")
+
+TARGET_BUILTIN(__builtin_wasm_sqrt_f32x4, "V4fV4f", "nc", "unimplemented-simd128")
+TARGET_BUILTIN(__builtin_wasm_sqrt_f64x2, "V2dV2d", "nc", "unimplemented-simd128")
+
+TARGET_BUILTIN(__builtin_wasm_trunc_saturate_s_i32x4_f32x4, "V4iV4f", "nc", "simd128")
+TARGET_BUILTIN(__builtin_wasm_trunc_saturate_u_i32x4_f32x4, "V4iV4f", "nc", "simd128")
+TARGET_BUILTIN(__builtin_wasm_trunc_saturate_s_i64x2_f64x2, "V2LLiV2d", "nc", "unimplemented-simd128")
+TARGET_BUILTIN(__builtin_wasm_trunc_saturate_u_i64x2_f64x2, "V2LLiV2d", "nc", "unimplemented-simd128")
 
 #undef BUILTIN
+#undef TARGET_BUILTIN
-- 
cgit v1.2.3

