From 29c5b6bbfa034438b92846fd81be959f74aadb6c Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Mon, 20 Jul 2026 23:26:35 -0700 Subject: [PATCH] Cleanup shared-constants.h. NFC - Remove some unused shared constants. - For constants that are only used in a single file move them there - Be consistent about how static Names are initialized. --- src/asmjs/shared-constants.cpp | 21 ---------- src/asmjs/shared-constants.h | 21 ---------- src/passes/Asyncify.cpp | 30 +++++++------- src/passes/InstrumentBranchHints.cpp | 4 +- src/passes/InstrumentLocals.cpp | 30 +++++++------- src/passes/InstrumentMemory.cpp | 60 ++++++++++++++-------------- src/passes/LegalizeJSInterface.cpp | 8 ++-- src/passes/LogExecution.cpp | 2 +- src/passes/RemoveNonJSOps.cpp | 16 ++++++++ src/passes/TrapMode.cpp | 12 ++++-- src/shared-constants.h | 8 ---- src/wasm/wasm-emscripten.cpp | 2 + src/wasm/wasm.cpp | 7 ---- 13 files changed, 93 insertions(+), 128 deletions(-) diff --git a/src/asmjs/shared-constants.cpp b/src/asmjs/shared-constants.cpp index bd924f17943..31f8f619942 100644 --- a/src/asmjs/shared-constants.cpp +++ b/src/asmjs/shared-constants.cpp @@ -39,12 +39,8 @@ IString MAX("max"); IString F64_REM("f64-rem"); IString F64_TO_INT("f64-to-int"); IString F64_TO_UINT("f64-to-uint"); -IString F64_TO_INT64("f64-to-int64"); -IString F64_TO_UINT64("f64-to-uint64"); IString F32_TO_INT("f32-to-int"); IString F32_TO_UINT("f32-to-uint"); -IString F32_TO_INT64("f32-to-int64"); -IString F32_TO_UINT64("f32-to-uint64"); IString I32S_DIV("i32s-div"); IString I32U_DIV("i32u-div"); IString I32S_REM("i32s-rem"); @@ -72,27 +68,10 @@ IString MATH_TRUNC("Math_trunc"); IString MATH_SQRT("Math_sqrt"); IString MATH_MIN("Math_min"); IString MATH_MAX("Math_max"); -IString WASM_CTZ32("__wasm_ctz_i32"); -IString WASM_CTZ64("__wasm_ctz_i64"); -IString WASM_CLZ32("__wasm_clz_i32"); -IString WASM_CLZ64("__wasm_clz_i64"); -IString WASM_POPCNT32("__wasm_popcnt_i32"); -IString WASM_POPCNT64("__wasm_popcnt_i64"); -IString WASM_ROTL32("__wasm_rotl_i32"); -IString WASM_ROTL64("__wasm_rotl_i64"); -IString WASM_ROTR32("__wasm_rotr_i32"); -IString WASM_ROTR64("__wasm_rotr_i64"); IString WASM_MEMORY_GROW("__wasm_memory_grow"); IString WASM_MEMORY_SIZE("__wasm_memory_size"); IString WASM_FETCH_HIGH_BITS("__wasm_fetch_high_bits"); IString INT64_TO_32_HIGH_BITS("i64toi32_i32$HIGH_BITS"); -IString WASM_NEAREST_F32("__wasm_nearest_f32"); -IString WASM_NEAREST_F64("__wasm_nearest_f64"); -IString WASM_I64_MUL("__wasm_i64_mul"); -IString WASM_I64_SDIV("__wasm_i64_sdiv"); -IString WASM_I64_UDIV("__wasm_i64_udiv"); -IString WASM_I64_SREM("__wasm_i64_srem"); -IString WASM_I64_UREM("__wasm_i64_urem"); IString ASM_FUNC("asmFunc"); IString FUNCTION_TABLE("FUNCTION_TABLE"); diff --git a/src/asmjs/shared-constants.h b/src/asmjs/shared-constants.h index d48da560ec2..7fc501b4709 100644 --- a/src/asmjs/shared-constants.h +++ b/src/asmjs/shared-constants.h @@ -42,12 +42,8 @@ extern IString MAX; extern IString F64_REM; extern IString F64_TO_INT; extern IString F64_TO_UINT; -extern IString F64_TO_INT64; -extern IString F64_TO_UINT64; extern IString F32_TO_INT; extern IString F32_TO_UINT; -extern IString F32_TO_INT64; -extern IString F32_TO_UINT64; extern IString I32S_DIV; extern IString I32U_DIV; extern IString I32S_REM; @@ -75,27 +71,10 @@ extern IString MATH_TRUNC; extern IString MATH_SQRT; extern IString MATH_MIN; extern IString MATH_MAX; -extern IString WASM_CTZ32; -extern IString WASM_CTZ64; -extern IString WASM_CLZ32; -extern IString WASM_CLZ64; -extern IString WASM_POPCNT32; -extern IString WASM_POPCNT64; -extern IString WASM_ROTL32; -extern IString WASM_ROTL64; -extern IString WASM_ROTR32; -extern IString WASM_ROTR64; extern IString WASM_MEMORY_GROW; extern IString WASM_MEMORY_SIZE; extern IString WASM_FETCH_HIGH_BITS; extern IString INT64_TO_32_HIGH_BITS; -extern IString WASM_NEAREST_F32; -extern IString WASM_NEAREST_F64; -extern IString WASM_I64_MUL; -extern IString WASM_I64_SDIV; -extern IString WASM_I64_UDIV; -extern IString WASM_I64_SREM; -extern IString WASM_I64_UREM; // wasm2js constants extern IString ASM_FUNC; extern IString FUNCTION_TABLE; diff --git a/src/passes/Asyncify.cpp b/src/passes/Asyncify.cpp index c839f26c61d..94a3261d78a 100644 --- a/src/passes/Asyncify.cpp +++ b/src/passes/Asyncify.cpp @@ -363,21 +363,21 @@ namespace wasm { namespace { -static const Name ASYNCIFY_STATE = "__asyncify_state"; -static const Name ASYNCIFY_GET_STATE = "asyncify_get_state"; -static const Name ASYNCIFY_DATA = "__asyncify_data"; -static const Name ASYNCIFY_START_UNWIND = "asyncify_start_unwind"; -static const Name ASYNCIFY_STOP_UNWIND = "asyncify_stop_unwind"; -static const Name ASYNCIFY_START_REWIND = "asyncify_start_rewind"; -static const Name ASYNCIFY_STOP_REWIND = "asyncify_stop_rewind"; -static const Name ASYNCIFY_UNWIND = "__asyncify_unwind"; -static const Name ASYNCIFY = "asyncify"; -static const Name START_UNWIND = "start_unwind"; -static const Name STOP_UNWIND = "stop_unwind"; -static const Name START_REWIND = "start_rewind"; -static const Name STOP_REWIND = "stop_rewind"; -static const Name ASYNCIFY_GET_CALL_INDEX = "__asyncify_get_call_index"; -static const Name ASYNCIFY_CHECK_CALL_INDEX = "__asyncify_check_call_index"; +static const Name ASYNCIFY_STATE("__asyncify_state"); +static const Name ASYNCIFY_GET_STATE("asyncify_get_state"); +static const Name ASYNCIFY_DATA("__asyncify_data"); +static const Name ASYNCIFY_START_UNWIND("asyncify_start_unwind"); +static const Name ASYNCIFY_STOP_UNWIND("asyncify_stop_unwind"); +static const Name ASYNCIFY_START_REWIND("asyncify_start_rewind"); +static const Name ASYNCIFY_STOP_REWIND("asyncify_stop_rewind"); +static const Name ASYNCIFY_UNWIND("__asyncify_unwind"); +static const Name ASYNCIFY("asyncify"); +static const Name START_UNWIND("start_unwind"); +static const Name STOP_UNWIND("stop_unwind"); +static const Name START_REWIND("start_rewind"); +static const Name STOP_REWIND("stop_rewind"); +static const Name ASYNCIFY_GET_CALL_INDEX("__asyncify_get_call_index"); +static const Name ASYNCIFY_CHECK_CALL_INDEX("__asyncify_check_call_index"); // TODO: having just normal/unwind_or_rewind would decrease code // size, but make debugging harder diff --git a/src/passes/InstrumentBranchHints.cpp b/src/passes/InstrumentBranchHints.cpp index 9a80598877f..ef250a67af9 100644 --- a/src/passes/InstrumentBranchHints.cpp +++ b/src/passes/InstrumentBranchHints.cpp @@ -110,8 +110,8 @@ namespace wasm { namespace { // The module and base names of our import. -const Name MODULE = "fuzzing-support"; -const Name BASE = "log-branch"; +static const Name MODULE("fuzzing-support"); +static const Name BASE("log-branch"); // Finds our import, if it exists. Name getLogBranchImport(Module* module) { diff --git a/src/passes/InstrumentLocals.cpp b/src/passes/InstrumentLocals.cpp index 267e806916e..6f34cf7f8da 100644 --- a/src/passes/InstrumentLocals.cpp +++ b/src/passes/InstrumentLocals.cpp @@ -51,21 +51,21 @@ namespace wasm { -Name get_i32("get_i32"); -Name get_i64("get_i64"); -Name get_f32("get_f32"); -Name get_f64("get_f64"); -Name get_v128("get_v128"); -Name get_funcref("get_funcref"); -Name get_externref("get_externref"); - -Name set_i32("set_i32"); -Name set_i64("set_i64"); -Name set_f32("set_f32"); -Name set_f64("set_f64"); -Name set_v128("set_v128"); -Name set_funcref("set_funcref"); -Name set_externref("set_externref"); +static const Name get_i32("get_i32"); +static const Name get_i64("get_i64"); +static const Name get_f32("get_f32"); +static const Name get_f64("get_f64"); +static const Name get_v128("get_v128"); +static const Name get_funcref("get_funcref"); +static const Name get_externref("get_externref"); + +static const Name set_i32("set_i32"); +static const Name set_i64("set_i64"); +static const Name set_f32("set_f32"); +static const Name set_f64("set_f64"); +static const Name set_v128("set_v128"); +static const Name set_funcref("set_funcref"); +static const Name set_externref("set_externref"); struct InstrumentLocals : public WalkerPass> { // Adds calls to new imports. diff --git a/src/passes/InstrumentMemory.cpp b/src/passes/InstrumentMemory.cpp index ddbac6a1a69..f0869c94c58 100644 --- a/src/passes/InstrumentMemory.cpp +++ b/src/passes/InstrumentMemory.cpp @@ -66,36 +66,36 @@ namespace wasm { -static Name load_ptr("load_ptr"); -static Name load_val_i32("load_val_i32"); -static Name load_val_i64("load_val_i64"); -static Name load_val_f32("load_val_f32"); -static Name load_val_f64("load_val_f64"); -static Name store_ptr("store_ptr"); -static Name store_val_i32("store_val_i32"); -static Name store_val_i64("store_val_i64"); -static Name store_val_f32("store_val_f32"); -static Name store_val_f64("store_val_f64"); -static Name struct_get_val_i32("struct_get_val_i32"); -static Name struct_get_val_i64("struct_get_val_i64"); -static Name struct_get_val_f32("struct_get_val_f32"); -static Name struct_get_val_f64("struct_get_val_f64"); -static Name struct_set_val_i32("struct_set_val_i32"); -static Name struct_set_val_i64("struct_set_val_i64"); -static Name struct_set_val_f32("struct_set_val_f32"); -static Name struct_set_val_f64("struct_set_val_f64"); -static Name array_get_val_i32("array_get_val_i32"); -static Name array_get_val_i64("array_get_val_i64"); -static Name array_get_val_f32("array_get_val_f32"); -static Name array_get_val_f64("array_get_val_f64"); -static Name array_set_val_i32("array_set_val_i32"); -static Name array_set_val_i64("array_set_val_i64"); -static Name array_set_val_f32("array_set_val_f32"); -static Name array_set_val_f64("array_set_val_f64"); -static Name array_get_index("array_get_index"); -static Name array_set_index("array_set_index"); -static Name memory_grow_pre("memory_grow_pre"); -static Name memory_grow_post("memory_grow_post"); +static const Name load_ptr("load_ptr"); +static const Name load_val_i32("load_val_i32"); +static const Name load_val_i64("load_val_i64"); +static const Name load_val_f32("load_val_f32"); +static const Name load_val_f64("load_val_f64"); +static const Name store_ptr("store_ptr"); +static const Name store_val_i32("store_val_i32"); +static const Name store_val_i64("store_val_i64"); +static const Name store_val_f32("store_val_f32"); +static const Name store_val_f64("store_val_f64"); +static const Name struct_get_val_i32("struct_get_val_i32"); +static const Name struct_get_val_i64("struct_get_val_i64"); +static const Name struct_get_val_f32("struct_get_val_f32"); +static const Name struct_get_val_f64("struct_get_val_f64"); +static const Name struct_set_val_i32("struct_set_val_i32"); +static const Name struct_set_val_i64("struct_set_val_i64"); +static const Name struct_set_val_f32("struct_set_val_f32"); +static const Name struct_set_val_f64("struct_set_val_f64"); +static const Name array_get_val_i32("array_get_val_i32"); +static const Name array_get_val_i64("array_get_val_i64"); +static const Name array_get_val_f32("array_get_val_f32"); +static const Name array_get_val_f64("array_get_val_f64"); +static const Name array_set_val_i32("array_set_val_i32"); +static const Name array_set_val_i64("array_set_val_i64"); +static const Name array_set_val_f32("array_set_val_f32"); +static const Name array_set_val_f64("array_set_val_f64"); +static const Name array_get_index("array_get_index"); +static const Name array_set_index("array_set_index"); +static const Name memory_grow_pre("memory_grow_pre"); +static const Name memory_grow_post("memory_grow_post"); // TODO: Add support for atomicRMW/cmpxchg diff --git a/src/passes/LegalizeJSInterface.cpp b/src/passes/LegalizeJSInterface.cpp index ecf1adbc3be..4bb74918ff0 100644 --- a/src/passes/LegalizeJSInterface.cpp +++ b/src/passes/LegalizeJSInterface.cpp @@ -46,13 +46,13 @@ namespace { // These are aliases for getTempRet0/setTempRet0 which emscripten defines in // compiler-rt and exports under these names. -static Name GET_TEMP_RET_EXPORT("__get_temp_ret"); -static Name SET_TEMP_RET_EXPORT("__set_temp_ret"); +static const Name GET_TEMP_RET_EXPORT("__get_temp_ret"); +static const Name SET_TEMP_RET_EXPORT("__set_temp_ret"); // For non-emscripten module we expect the host to define these functions so // and we import them under these names. -static Name GET_TEMP_RET_IMPORT("getTempRet0"); -static Name SET_TEMP_RET_IMPORT("setTempRet0"); +static const Name GET_TEMP_RET_IMPORT("getTempRet0"); +static const Name SET_TEMP_RET_IMPORT("setTempRet0"); struct LegalizeJSInterface : public Pass { // Adds calls to new imports. diff --git a/src/passes/LogExecution.cpp b/src/passes/LogExecution.cpp index c194fdc5ac0..760f7990c25 100644 --- a/src/passes/LogExecution.cpp +++ b/src/passes/LogExecution.cpp @@ -36,7 +36,7 @@ namespace wasm { -Name LOGGER("log_execution"); +static const Name LOGGER("log_execution"); struct LogExecution : public WalkerPass> { // The module name the logger function is imported from. diff --git a/src/passes/RemoveNonJSOps.cpp b/src/passes/RemoveNonJSOps.cpp index e5a87f5e3a9..290eec7c8e5 100644 --- a/src/passes/RemoveNonJSOps.cpp +++ b/src/passes/RemoveNonJSOps.cpp @@ -49,6 +49,22 @@ namespace wasm { +static const Name WASM_CTZ32("__wasm_ctz_i32"); +static const Name WASM_CTZ64("__wasm_ctz_i64"); +static const Name WASM_POPCNT32("__wasm_popcnt_i32"); +static const Name WASM_POPCNT64("__wasm_popcnt_i64"); +static const Name WASM_ROTL32("__wasm_rotl_i32"); +static const Name WASM_ROTL64("__wasm_rotl_i64"); +static const Name WASM_ROTR32("__wasm_rotr_i32"); +static const Name WASM_ROTR64("__wasm_rotr_i64"); +static const Name WASM_NEAREST_F32("__wasm_nearest_f32"); +static const Name WASM_NEAREST_F64("__wasm_nearest_f64"); +static const Name WASM_I64_MUL("__wasm_i64_mul"); +static const Name WASM_I64_SDIV("__wasm_i64_sdiv"); +static const Name WASM_I64_UDIV("__wasm_i64_udiv"); +static const Name WASM_I64_SREM("__wasm_i64_srem"); +static const Name WASM_I64_UREM("__wasm_i64_urem"); + struct RemoveNonJSOpsPass : public WalkerPass> { std::unique_ptr builder; std::unordered_set neededIntrinsics; diff --git a/src/passes/TrapMode.cpp b/src/passes/TrapMode.cpp index 8438b7407df..18a016436eb 100644 --- a/src/passes/TrapMode.cpp +++ b/src/passes/TrapMode.cpp @@ -31,10 +31,14 @@ namespace wasm { -Name I64S_REM("i64s-rem"); -Name I64U_REM("i64u-rem"); -Name I64S_DIV("i64s-div"); -Name I64U_DIV("i64u-div"); +static const Name I64S_REM("i64s-rem"); +static const Name I64U_REM("i64u-rem"); +static const Name I64S_DIV("i64s-div"); +static const Name I64U_DIV("i64u-div"); +static const Name F64_TO_INT64("f64-to-int64"); +static const Name F64_TO_UINT64("f64-to-uint64"); +static const Name F32_TO_INT64("f32-to-int64"); +static const Name F32_TO_UINT64("f32-to-uint64"); static Expression* ensureDouble(Expression* expr, MixedArena& allocator) { if (expr->type == Type::f32) { diff --git a/src/shared-constants.h b/src/shared-constants.h index 528d09df581..4ad624d1ad7 100644 --- a/src/shared-constants.h +++ b/src/shared-constants.h @@ -21,7 +21,6 @@ namespace wasm { -extern Name STACK_POINTER; extern Name MODULE; extern Name START; extern Name FUNC; @@ -41,20 +40,13 @@ extern Name TYPE; extern Name REF; extern Name NULL_; extern Name CALL; -extern Name CALL_IMPORT; extern Name CALL_INDIRECT; extern Name BLOCK; -extern Name BR_IF; extern Name THEN; extern Name ELSE; -extern Name _NAN; -extern Name _INFINITY; -extern Name NEG_INFINITY; -extern Name NEG_NAN; extern Name CASE; extern Name BR; extern Name FUNCREF; -extern Name FAKE_RETURN; extern Name DELEGATE_CALLER_TARGET; extern Name MUT; extern Name SPECTEST; diff --git a/src/wasm/wasm-emscripten.cpp b/src/wasm/wasm-emscripten.cpp index 8c2c272c8b9..a810cc2bba8 100644 --- a/src/wasm/wasm-emscripten.cpp +++ b/src/wasm/wasm-emscripten.cpp @@ -33,6 +33,8 @@ namespace wasm { +static const Name STACK_POINTER("__stack_pointer"); + void addExportedFunction(Module& wasm, Function* function) { wasm.addFunction(function); wasm.addExport( diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp index 6aa8373cb69..89bb20e5bc7 100644 --- a/src/wasm/wasm.cpp +++ b/src/wasm/wasm.cpp @@ -95,7 +95,6 @@ const Name ToolchainInlineHint = "binaryen.inline"; } // namespace Annotations -Name STACK_POINTER("__stack_pointer"); Name MODULE("module"); Name START("start"); Name GLOBAL("global"); @@ -120,17 +119,11 @@ Name NULL_("null"); Name CALL("call"); Name CALL_INDIRECT("call_indirect"); Name BLOCK("block"); -Name BR_IF("br_if"); Name THEN("then"); Name ELSE("else"); -Name _NAN("NaN"); -Name _INFINITY("Infinity"); -Name NEG_INFINITY("-infinity"); -Name NEG_NAN("-nan"); Name CASE("case"); Name BR("br"); Name FUNCREF("funcref"); -Name FAKE_RETURN("__binaryen_fake_return"); Name DELEGATE_CALLER_TARGET("__binaryen_delegate_caller_target"); Name MUT("mut"); Name SPECTEST("spectest");