Move more defines to `utils/compiler.h` This CL moves the Dawn compiler defines, `DAWN_BUILTIN_UNREACHABLE`, `DAWN_LIKELY` and `DAWN_UNLIKELY` defines to `src/utils/compiler.h`. The `TINT_UNLIKELY` and `TINT_UNLIKELY` defines are removed and the Dawn defines used. Change-Id: I406fb19f249b8a09018b67d9f7d4eddaf57c2812 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/203814 Reviewed-by: James Price <jrprice@google.com> Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: dan sinclair <dsinclair@chromium.org>
diff --git a/src/dawn/common/Compiler.h b/src/dawn/common/Compiler.h index 2ccb57a..4b67ef6 100644 --- a/src/dawn/common/Compiler.h +++ b/src/dawn/common/Compiler.h
@@ -32,60 +32,6 @@ // Defines macros for compiler-specific functionality -// DAWN_COMPILER_IS(CLANG|GCC|MSVC): Compiler detection -// -// Note: clang masquerades as GCC on POSIX and as MSVC on Windows. It must be checked first. -#if defined(__clang__) -#define DAWN_COMPILER_IS_CLANG 1 -#define DAWN_COMPILER_IS_GCC 0 -#define DAWN_COMPILER_IS_MSVC 0 -#elif defined(__GNUC__) -#define DAWN_COMPILER_IS_CLANG 0 -#define DAWN_COMPILER_IS_GCC 1 -#define DAWN_COMPILER_IS_MSVC 0 -#elif defined(_MSC_VER) -#define DAWN_COMPILER_IS_CLANG 0 -#define DAWN_COMPILER_IS_GCC 0 -#define DAWN_COMPILER_IS_MSVC 1 -#else -#error "Unsupported compiler" -#endif - -// Use #if DAWN_COMPILER_IS(XXX) for compiler specific code. -// Do not use #ifdef or the naked macro DAWN_COMPILER_IS_XXX. -// This can help avoid common mistakes like not including "Compiler.h" and falling into unwanted -// code block as usage of undefined macro "function" will be blocked by the compiler. -#define DAWN_COMPILER_IS(X) (1 == DAWN_COMPILER_IS_##X) - -// DAWN_BUILTIN_UNREACHABLE() -// -// Hints the compiler that a code path is unreachable. -#if DAWN_COMPILER_IS(MSVC) -#define DAWN_BUILTIN_UNREACHABLE() __assume(false) -#else -#define DAWN_BUILTIN_UNREACHABLE() __builtin_unreachable() -#endif - -// DAWN_LIKELY(EXPR) -// -// Where available, hints the compiler that the expression will be true to help it generate code -// that leads to better branch prediction. -#if DAWN_COMPILER_IS(GCC) || DAWN_COMPILER_IS(CLANG) -#define DAWN_LIKELY(x) __builtin_expect(!!(x), 1) -#else -#define DAWN_LIKELY(x) (x) -#endif - -// DAWN_UNLIKELY(EXPR) -// -// Where available, hints the compiler that the expression will be false to help it generate code -// that leads to better branch prediction. -#if DAWN_COMPILER_IS(GCC) || DAWN_COMPILER_IS(CLANG) -#define DAWN_UNLIKELY(x) __builtin_expect(!!(x), 0) -#else -#define DAWN_UNLIKELY(x) (x) -#endif - // DAWN_NO_SANITIZE(instrumentation) // // Annotate a function or a global variable declaration to specify that a particular instrumentation
diff --git a/src/tint/lang/core/constant/eval.cc b/src/tint/lang/core/constant/eval.cc index 95ed95c..8462a3e 100644 --- a/src/tint/lang/core/constant/eval.cc +++ b/src/tint/lang/core/constant/eval.cc
@@ -442,7 +442,7 @@ pending.Push(ActionBuildComposite{el_count, convert->target_ty}); if (auto* str = convert->target_ty->As<core::type::Struct>()) { - if (TINT_UNLIKELY(str->Members().Length() != el_count)) { + if (DAWN_UNLIKELY(str->Members().Length() != el_count)) { TINT_ICE() << "const-eval conversion of structure has mismatched element counts"; } @@ -2058,7 +2058,7 @@ return Dispatch_ia_iu32(create, c0, c1); }; - if (TINT_UNLIKELY(!args[1]->Type()->DeepestElement()->Is<core::type::U32>())) { + if (DAWN_UNLIKELY(!args[1]->Type()->DeepestElement()->Is<core::type::U32>())) { TINT_ICE() << "Element type of rhs of ShiftLeft must be a u32"; } @@ -2123,7 +2123,7 @@ return Dispatch_ia_iu32(create, c0, c1); }; - if (TINT_UNLIKELY(!args[1]->Type()->DeepestElement()->Is<core::type::U32>())) { + if (DAWN_UNLIKELY(!args[1]->Type()->DeepestElement()->Is<core::type::U32>())) { TINT_ICE() << "Element type of rhs of ShiftLeft must be a u32"; }
diff --git a/src/tint/lang/core/constant/manager.cc b/src/tint/lang/core/constant/manager.cc index 5da3c44..5e0bc0c 100644 --- a/src/tint/lang/core/constant/manager.cc +++ b/src/tint/lang/core/constant/manager.cc
@@ -68,7 +68,7 @@ bool all_equal = true; auto* first = elements.Front(); for (auto* el : elements) { - if (TINT_UNLIKELY(!el)) { + if (DAWN_UNLIKELY(!el)) { return nullptr; } if (!any_zero && el->AnyZero()) {
diff --git a/src/tint/lang/core/intrinsic/table.cc b/src/tint/lang/core/intrinsic/table.cc index b422828..fb7aa90 100644 --- a/src/tint/lang/core/intrinsic/table.cc +++ b/src/tint/lang/core/intrinsic/table.cc
@@ -220,7 +220,7 @@ } // How many candidates matched? - if (TINT_UNLIKELY(num_matched == 0)) { + if (DAWN_UNLIKELY(num_matched == 0)) { // Perform the full scoring of each overload for (size_t overload_idx = 0; overload_idx < num_overloads; overload_idx++) { auto& overload = context.data[intrinsic.overloads + overload_idx]; @@ -245,7 +245,7 @@ } else { auto result = ResolveCandidate(context, std::move(candidates), intrinsic_name, template_args, args); - if (TINT_UNLIKELY(result != Success)) { + if (DAWN_UNLIKELY(result != Success)) { return result.Failure(); } match = result.Get(); @@ -258,7 +258,7 @@ return_type = context.Match(match.templates, *match.overload, matcher_indices, earliest_eval_stage) .Type(&any); - if (TINT_UNLIKELY(!return_type)) { + if (DAWN_UNLIKELY(!return_type)) { StyledText err; err << "MatchState.MatchState() returned null"; TINT_ICE() << err.Plain();
diff --git a/src/tint/lang/core/ir/binary/decode.cc b/src/tint/lang/core/ir/binary/decode.cc index 3b0c1cf..0f3e2a5 100644 --- a/src/tint/lang/core/ir/binary/decode.cc +++ b/src/tint/lang/core/ir/binary/decode.cc
@@ -169,7 +169,7 @@ /// @returns @p number if finite, otherwise 0. template <typename T> Number<T> CheckFinite(Number<T> number) { - if (TINT_UNLIKELY(!std::isfinite(number.value))) { + if (DAWN_UNLIKELY(!std::isfinite(number.value))) { Error() << "value must be finite"; return Number<T>{}; } @@ -255,7 +255,7 @@ Vector<FunctionParam*, 8> params_out; for (auto param_in : fn_in.parameters()) { auto* param_out = ValueAs<FunctionParam>(param_in); - if (TINT_LIKELY(param_out)) { + if (DAWN_LIKELY(param_out)) { params_out.Push(param_out); } } @@ -276,7 +276,7 @@ } ir::Function* Function(uint32_t id) { - if (TINT_UNLIKELY(id >= mod_out_.functions.Length())) { + if (DAWN_UNLIKELY(id >= mod_out_.functions.Length())) { Error() << "function id " << id << " out of range"; return nullptr; } @@ -311,7 +311,7 @@ Vector<ir::BlockParam*, 8> params; for (auto param_in : block_in.parameters()) { auto* param_out = ValueAs<BlockParam>(param_in); - if (TINT_LIKELY(param_out)) { + if (DAWN_LIKELY(param_out)) { params.Push(param_out); } } @@ -323,7 +323,7 @@ } ir::Block* Block(uint32_t id) { - if (TINT_UNLIKELY(id >= blocks_.Length())) { + if (DAWN_UNLIKELY(id >= blocks_.Length())) { Error() << "block id " << id << " out of range"; return b.Block(); } @@ -333,7 +333,7 @@ template <typename T> T* BlockAs(uint32_t id) { auto* block = Block(id); - if (auto cast = As<T>(block); TINT_LIKELY(cast)) { + if (auto cast = As<T>(block); DAWN_LIKELY(cast)) { return cast; } Error() << "block " << id << " is " << (block ? block->TypeInfo().name : "<null>") @@ -454,7 +454,7 @@ auto num_next_iter_values = inst_in.break_if().num_next_iter_values(); bool is_valid = inst_out->Operands().Length() >= num_next_iter_values + BreakIf::kArgsOperandOffset; - if (TINT_LIKELY(is_valid)) { + if (DAWN_LIKELY(is_valid)) { static_cast<BreakIf*>(inst_out)->SetNumNextIterValues( inst_in.break_if().num_next_iter_values()); } else { @@ -732,7 +732,7 @@ const type::Type* CreateTypeVector(const pb::TypeVector& vector_in) { const auto width = vector_in.width(); - if (TINT_UNLIKELY(width < 2 || width > 4)) { + if (DAWN_UNLIKELY(width < 2 || width > 4)) { Error() << "invalid vector width"; return mod_out_.Types().invalid(); } @@ -743,7 +743,7 @@ const type::Type* CreateTypeMatrix(const pb::TypeMatrix& matrix_in) { const auto rows = matrix_in.num_rows(); const auto cols = matrix_in.num_columns(); - if (TINT_UNLIKELY(rows < 2 || rows > 4 || cols < 2 || cols > 4)) { + if (DAWN_UNLIKELY(rows < 2 || rows > 4 || cols < 2 || cols > 4)) { Error() << "invalid matrix dimensions"; return mod_out_.Types().invalid(); } @@ -761,7 +761,7 @@ const type::Type* CreateTypeStruct(const pb::TypeStruct& struct_in) { auto struct_name = struct_in.name(); - if (TINT_UNLIKELY(struct_name.empty())) { + if (DAWN_UNLIKELY(struct_name.empty())) { Error() << "struct must have a name"; return mod_out_.Types().invalid(); } @@ -774,7 +774,7 @@ uint32_t offset = 0; for (auto& member_in : struct_in.member()) { auto member_name = member_in.name(); - if (TINT_UNLIKELY(member_name.empty())) { + if (DAWN_UNLIKELY(member_name.empty())) { Error() << "struct member must have a name"; return mod_out_.Types().invalid(); } @@ -783,11 +783,11 @@ auto index = static_cast<uint32_t>(members_out.Length()); auto align = member_in.align(); auto size = member_in.size(); - if (TINT_UNLIKELY(align == 0)) { + if (DAWN_UNLIKELY(align == 0)) { Error() << "struct member must have non-zero alignment"; align = 1; } - if (TINT_UNLIKELY(size == 0)) { + if (DAWN_UNLIKELY(size == 0)) { Error() << "struct member must have non-zero size"; size = 1; } @@ -818,7 +818,7 @@ offset += size; members_out.Push(member_out); } - if (TINT_UNLIKELY(members_out.IsEmpty())) { + if (DAWN_UNLIKELY(members_out.IsEmpty())) { Error() << "struct requires at least one member"; return mod_out_.Types().invalid(); } @@ -912,7 +912,7 @@ } const type::Type* Type(size_t id) { - if (TINT_UNLIKELY(id >= types_.Length())) { + if (DAWN_UNLIKELY(id >= types_.Length())) { Error() << "type id " << id << " out of range"; return mod_out_.Types().invalid(); } @@ -1006,7 +1006,7 @@ ir::Constant* Constant(uint32_t value_id) { return b.Constant(ConstantValue(value_id)); } ir::Value* Value(uint32_t id) { - if (TINT_UNLIKELY(id > values_.Length())) { + if (DAWN_UNLIKELY(id > values_.Length())) { Error() << "value id " << id << " out of range"; return nullptr; } @@ -1016,7 +1016,7 @@ template <typename T> T* ValueAs(uint32_t id) { auto* value = Value(id); - if (auto cast = As<T>(value); TINT_LIKELY(cast)) { + if (auto cast = As<T>(value); DAWN_LIKELY(cast)) { return cast; } Error() << "value " << id << " is " << (value ? value->TypeInfo().name : "<null>") @@ -1066,11 +1066,11 @@ auto* type = Type(composite_in.type()); auto type_elements = type->Elements(); size_t num_values = static_cast<size_t>(composite_in.elements().size()); - if (TINT_UNLIKELY(type_elements.count == 0)) { + if (DAWN_UNLIKELY(type_elements.count == 0)) { Error() << "cannot create a composite of type " << type->FriendlyName(); return b.InvalidConstant()->Value(); } - if (TINT_UNLIKELY(type_elements.count != num_values)) { + if (DAWN_UNLIKELY(type_elements.count != num_values)) { Error() << "constant composite type " << type->FriendlyName() << " expects " << type_elements.count << " elements, but " << num_values << " values encoded"; return b.InvalidConstant()->Value(); @@ -1079,7 +1079,7 @@ for (auto element_id : composite_in.elements()) { uint32_t i = static_cast<uint32_t>(elements_out.Length()); auto* value = ConstantValue(element_id); - if (auto* el_type = type->Element(i); TINT_UNLIKELY(value->Type() != el_type)) { + if (auto* el_type = type->Element(i); DAWN_UNLIKELY(value->Type() != el_type)) { Error() << "constant composite element value type " << value->Type()->FriendlyName() << " does not match element type " << el_type->FriendlyName(); return b.InvalidConstant()->Value(); @@ -1092,14 +1092,14 @@ const core::constant::Value* CreateConstantSplat(const pb::ConstantValueSplat& splat_in) { auto* type = Type(splat_in.type()); uint32_t num_elements = type->Elements().count; - if (TINT_UNLIKELY(num_elements == 0)) { + if (DAWN_UNLIKELY(num_elements == 0)) { Error() << "cannot create a splat of type " << type->FriendlyName(); return b.InvalidConstant()->Value(); } auto* value = ConstantValue(splat_in.elements()); for (uint32_t i = 0; i < num_elements; i++) { auto* el_type = type->Element(i); - if (TINT_UNLIKELY(el_type != value->Type())) { + if (DAWN_UNLIKELY(el_type != value->Type())) { Error() << "constant splat element value type " << value->Type()->FriendlyName() << " does not match element " << i << " type " << el_type->FriendlyName(); return b.InvalidConstant()->Value(); @@ -1109,7 +1109,7 @@ } const core::constant::Value* ConstantValue(uint32_t id) { - if (TINT_UNLIKELY(id >= constant_values_.Length())) { + if (DAWN_UNLIKELY(id >= constant_values_.Length())) { Error() << "constant value id " << id << " out of range"; return b.InvalidConstant()->Value(); }
diff --git a/src/tint/lang/core/ir/builder.cc b/src/tint/lang/core/ir/builder.cc index cb220b9..658cda0 100644 --- a/src/tint/lang/core/ir/builder.cc +++ b/src/tint/lang/core/ir/builder.cc
@@ -146,10 +146,10 @@ const core::type::Type* Builder::VectorPtrElementType(const core::type::Type* type) { auto* vec_ptr_ty = type->As<core::type::Pointer>(); TINT_ASSERT(vec_ptr_ty); - if (TINT_LIKELY(vec_ptr_ty)) { + if (DAWN_LIKELY(vec_ptr_ty)) { auto* vec_ty = vec_ptr_ty->StoreType()->As<core::type::Vector>(); TINT_ASSERT(vec_ty); - if (TINT_LIKELY(vec_ty)) { + if (DAWN_LIKELY(vec_ty)) { return vec_ty->Type(); } }
diff --git a/src/tint/lang/core/ir/builder.h b/src/tint/lang/core/ir/builder.h index 9e963c0..5e052df 100644 --- a/src/tint/lang/core/ir/builder.h +++ b/src/tint/lang/core/ir/builder.h
@@ -1295,7 +1295,7 @@ !traits::IsTypeOrDerived<std::remove_pointer_t<std::decay_t<VALUE>>, core::type::Type>>> ir::Var* Var(std::string_view name, VALUE&& init) { auto* val = Value(std::forward<VALUE>(init)); - if (TINT_UNLIKELY(!val)) { + if (DAWN_UNLIKELY(!val)) { TINT_ASSERT(val); return nullptr; } @@ -1350,7 +1350,7 @@ template <typename VALUE> ir::Let* Let(std::string_view name, VALUE&& value) { auto* val = Value(std::forward<VALUE>(value)); - if (TINT_UNLIKELY(!val)) { + if (DAWN_UNLIKELY(!val)) { TINT_ASSERT(val); return nullptr; }
diff --git a/src/tint/lang/core/ir/transform/multiplanar_external_texture.cc b/src/tint/lang/core/ir/transform/multiplanar_external_texture.cc index ef72b44..15a5dc5 100644 --- a/src/tint/lang/core/ir/transform/multiplanar_external_texture.cc +++ b/src/tint/lang/core/ir/transform/multiplanar_external_texture.cc
@@ -87,7 +87,7 @@ } auto* ptr = var->Result(0)->Type()->As<core::type::Pointer>(); if (ptr->StoreType()->Is<core::type::ExternalTexture>()) { - if (auto res = ReplaceVar(var); TINT_UNLIKELY(res != Success)) { + if (auto res = ReplaceVar(var); DAWN_UNLIKELY(res != Success)) { return res.Failure(); } to_remove.Push(var); @@ -123,7 +123,7 @@ auto name = ir.NameOf(old_var); auto bp = old_var->BindingPoint(); auto itr = multiplanar_map.find(bp.value()); - if (TINT_UNLIKELY(itr == multiplanar_map.end())) { + if (DAWN_UNLIKELY(itr == multiplanar_map.end())) { std::stringstream err; err << "ExternalTextureOptions missing binding entry for " << bp.value(); return Failure{err.str()};
diff --git a/src/tint/lang/core/ir/validator.cc b/src/tint/lang/core/ir/validator.cc index 11d471e..12a2759 100644 --- a/src/tint/lang/core/ir/validator.cc +++ b/src/tint/lang/core/ir/validator.cc
@@ -874,12 +874,12 @@ bool Validator::CheckResult(const Instruction* inst, size_t idx) { auto* result = inst->Result(idx); - if (TINT_UNLIKELY(result == nullptr)) { + if (DAWN_UNLIKELY(result == nullptr)) { AddResultError(inst, idx) << "result is undefined"; return false; } - if (TINT_UNLIKELY(result->Type() == nullptr)) { + if (DAWN_UNLIKELY(result->Type() == nullptr)) { AddResultError(inst, idx) << "result type is undefined"; return false; } @@ -889,7 +889,7 @@ bool Validator::CheckResults(const ir::Instruction* inst, std::optional<size_t> count = {}) { if (count.has_value()) { - if (TINT_UNLIKELY(inst->Results().Length() != count.value())) { + if (DAWN_UNLIKELY(inst->Results().Length() != count.value())) { AddError(inst) << "expected exactly " << count.value() << " results, got " << inst->Results().Length(); return false; @@ -898,7 +898,7 @@ bool passed = true; for (size_t i = 0; i < inst->Results().Length(); i++) { - if (TINT_UNLIKELY(!CheckResult(inst, i))) { + if (DAWN_UNLIKELY(!CheckResult(inst, i))) { passed = false; } } @@ -907,20 +907,20 @@ bool Validator::CheckOperand(const Instruction* inst, size_t idx) { auto* operand = inst->Operand(idx); - if (TINT_UNLIKELY(operand == nullptr)) { + if (DAWN_UNLIKELY(operand == nullptr)) { AddError(inst, idx) << "operand is undefined"; return false; } // ir::Unused is a internal value used by some transforms to track unused entries, and is // removed as part of generating an output shader. - if (TINT_UNLIKELY(operand->Is<ir::Unused>())) { + if (DAWN_UNLIKELY(operand->Is<ir::Unused>())) { return true; } // ir::Function does not have a meaningful type, so does not override the default Type() // behaviour. - if (TINT_UNLIKELY(!operand->Is<ir::Function>() && operand->Type() == nullptr)) { + if (DAWN_UNLIKELY(!operand->Is<ir::Function>() && operand->Type() == nullptr)) { AddError(inst, idx) << "operand type is undefined"; return false; } @@ -931,7 +931,7 @@ bool Validator::CheckOperands(const ir::Instruction* inst, size_t min_count, std::optional<size_t> max_count) { - if (TINT_UNLIKELY(inst->Operands().Length() < min_count)) { + if (DAWN_UNLIKELY(inst->Operands().Length() < min_count)) { if (max_count.has_value()) { AddError(inst) << "expected between " << min_count << " and " << max_count.value() << " operands, got " << inst->Operands().Length(); @@ -942,7 +942,7 @@ return false; } - if (TINT_UNLIKELY(max_count.has_value() && inst->Operands().Length() > max_count.value())) { + if (DAWN_UNLIKELY(max_count.has_value() && inst->Operands().Length() > max_count.value())) { AddError(inst) << "expected between " << min_count << " and " << max_count.value() << " operands, got " << inst->Operands().Length(); return false; @@ -950,7 +950,7 @@ bool passed = true; for (size_t i = 0; i < inst->Operands().Length(); i++) { - if (TINT_UNLIKELY(!CheckOperand(inst, i))) { + if (DAWN_UNLIKELY(!CheckOperand(inst, i))) { passed = false; } } @@ -959,7 +959,7 @@ bool Validator::CheckOperands(const ir::Instruction* inst, std::optional<size_t> count = {}) { if (count.has_value()) { - if (TINT_UNLIKELY(inst->Operands().Length() != count.value())) { + if (DAWN_UNLIKELY(inst->Operands().Length() != count.value())) { AddError(inst) << "expected exactly " << count.value() << " operands, got " << inst->Operands().Length(); return false; @@ -968,7 +968,7 @@ bool passed = true; for (size_t i = 0; i < inst->Operands().Length(); i++) { - if (TINT_UNLIKELY(!CheckOperand(inst, i))) { + if (DAWN_UNLIKELY(!CheckOperand(inst, i))) { passed = false; } } @@ -1146,7 +1146,7 @@ } if (func->Stage() == Function::PipelineStage::kCompute) { - if (TINT_UNLIKELY(!func->WorkgroupSize().has_value())) { + if (DAWN_UNLIKELY(!func->WorkgroupSize().has_value())) { AddError(func) << "compute entry point requires workgroup size attribute"; } } @@ -1157,20 +1157,20 @@ Capabilities{Capability::kAllowRefTypes}); if (func->Stage() != Function::PipelineStage::kUndefined) { - if (TINT_UNLIKELY(mod_.NameOf(func).Name().empty())) { + if (DAWN_UNLIKELY(mod_.NameOf(func).Name().empty())) { AddError(func) << "entry points must have names"; } } // void needs to be filtered out, since it isn't constructible, but used in the IR when no // return is specified. - if (TINT_UNLIKELY(!func->ReturnType()->Is<core::type::Void>() && + if (DAWN_UNLIKELY(!func->ReturnType()->Is<core::type::Void>() && !func->ReturnType()->IsConstructible())) { AddError(func) << "function return type must be constructible"; } if (func->Stage() != Function::PipelineStage::kFragment) { - if (TINT_UNLIKELY(func->ReturnBuiltin().has_value() && + if (DAWN_UNLIKELY(func->ReturnBuiltin().has_value() && func->ReturnBuiltin().value() == BuiltinValue::kFragDepth)) { AddError(func) << "frag_depth can only be declared for fragment entry points"; } @@ -1596,7 +1596,7 @@ }; auto* index = a->Indices()[i]; - if (TINT_UNLIKELY(!index->Type()->IsIntegerScalar())) { + if (DAWN_UNLIKELY(!index->Type()->IsIntegerScalar())) { err() << "index must be integer, got " << index->Type()->FriendlyName(); return; } @@ -1614,7 +1614,7 @@ // index is a signed integer scalar. Check that the index isn't negative. // If the index is unsigned, we can skip this. auto idx = value->ValueAs<AInt>(); - if (TINT_UNLIKELY(idx < 0)) { + if (DAWN_UNLIKELY(idx < 0)) { err() << "constant index must be positive, got " << idx; return; } @@ -1622,7 +1622,7 @@ auto idx = value->ValueAs<uint32_t>(); auto* el = ty->Element(idx); - if (TINT_UNLIKELY(!el)) { + if (DAWN_UNLIKELY(!el)) { // Is index in bounds? if (auto el_count = ty->Elements().count; el_count != 0 && idx >= el_count) { err() << "index out of bounds for type " << desc_of(in_kind, ty); @@ -1635,7 +1635,7 @@ ty = el; } else { auto* el = ty->Elements().type; - if (TINT_UNLIKELY(!el)) { + if (DAWN_UNLIKELY(!el)) { err() << "type " << desc_of(in_kind, ty) << " cannot be dynamically indexed"; return; } @@ -1659,7 +1659,7 @@ // Otherwise, result types should exactly match. ok = ty == want; } - if (TINT_UNLIKELY(!ok)) { + if (DAWN_UNLIKELY(!ok)) { AddError(a) << "result of access chain is type " << desc_of(in_kind, ty) << " but instruction type is " << style::Type(want->FriendlyName()); } @@ -2166,19 +2166,19 @@ const core::type::Type* Validator::GetVectorPtrElementType(const Instruction* inst, size_t idx) { auto* operand = inst->Operands()[idx]; - if (TINT_UNLIKELY(!operand)) { + if (DAWN_UNLIKELY(!operand)) { return nullptr; } auto* type = operand->Type(); - if (TINT_UNLIKELY(!type)) { + if (DAWN_UNLIKELY(!type)) { return nullptr; } auto* memory_view_ty = type->As<core::type::MemoryView>(); - if (TINT_LIKELY(memory_view_ty)) { + if (DAWN_LIKELY(memory_view_ty)) { auto* vec_ty = memory_view_ty->StoreType()->As<core::type::Vector>(); - if (TINT_LIKELY(vec_ty)) { + if (DAWN_LIKELY(vec_ty)) { return vec_ty->Type(); } }
diff --git a/src/tint/lang/core/type/manager.cc b/src/tint/lang/core/type/manager.cc index 621e5c6..84b5483 100644 --- a/src/tint/lang/core/type/manager.cc +++ b/src/tint/lang/core/type/manager.cc
@@ -236,7 +236,7 @@ } core::type::Struct* Manager::Struct(Symbol name, VectorRef<const StructMember*> members) { - if (auto* existing = Find<type::Struct>(name); TINT_UNLIKELY(existing)) { + if (auto* existing = Find<type::Struct>(name); DAWN_UNLIKELY(existing)) { TINT_ICE() << "attempting to construct two structs named " << name.NameView(); } @@ -250,7 +250,7 @@ } core::type::Struct* Manager::Struct(Symbol name, VectorRef<StructMemberDesc> md) { - if (auto* existing = Find<type::Struct>(name); TINT_UNLIKELY(existing)) { + if (auto* existing = Find<type::Struct>(name); DAWN_UNLIKELY(existing)) { TINT_ICE() << "attempting to construct two structs named " << name.NameView(); }
diff --git a/src/tint/lang/glsl/writer/ast_printer/ast_printer.cc b/src/tint/lang/glsl/writer/ast_printer/ast_printer.cc index a04f7b7d..4f6884e 100644 --- a/src/tint/lang/glsl/writer/ast_printer/ast_printer.cc +++ b/src/tint/lang/glsl/writer/ast_printer/ast_printer.cc
@@ -619,7 +619,7 @@ // Emit operator. if (expr->op == core::BinaryOp::kAnd) { out << " & "; - } else if (TINT_LIKELY(expr->op == core::BinaryOp::kOr)) { + } else if (DAWN_LIKELY(expr->op == core::BinaryOp::kOr)) { out << " | "; } else { TINT_ICE() << "unexpected binary op: " << expr->op; @@ -1356,7 +1356,7 @@ }; auto* texture = arg(Usage::kTexture); - if (TINT_UNLIKELY(!texture)) { + if (DAWN_UNLIKELY(!texture)) { TINT_ICE() << "missing texture argument"; } @@ -1541,7 +1541,7 @@ out << ", "; auto* param_coords = arg(Usage::kCoords); - if (TINT_UNLIKELY(!param_coords)) { + if (DAWN_UNLIKELY(!param_coords)) { TINT_ICE() << "missing coords argument"; } @@ -1630,7 +1630,7 @@ out << "xyz"[i]; } } - if (TINT_UNLIKELY(wgsl_ret_width > glsl_ret_width)) { + if (DAWN_UNLIKELY(wgsl_ret_width > glsl_ret_width)) { TINT_ICE() << "WGSL return width (" << wgsl_ret_width << ") is wider than GLSL return width (" << glsl_ret_width << ") for " << builtin->Fn(); @@ -1939,7 +1939,7 @@ void ASTPrinter::EmitUniformVariable(const ast::Var* var, const sem::GlobalVariable* sem) { auto* type = sem->Type()->UnwrapRef(); auto* str = type->As<core::type::Struct>(); - if (TINT_UNLIKELY(!str)) { + if (DAWN_UNLIKELY(!str)) { TINT_ICE() << "storage variable must be of struct type"; } auto bp = *sem->Attributes().binding_point; @@ -1957,7 +1957,7 @@ void ASTPrinter::EmitStorageVariable(const ast::Var* var, const sem::GlobalVariable* sem) { auto* type = sem->Type()->UnwrapRef(); auto* str = type->As<core::type::Struct>(); - if (TINT_UNLIKELY(!str)) { + if (DAWN_UNLIKELY(!str)) { TINT_ICE() << "storage variable must be of struct type"; } auto bp = *sem->Attributes().binding_point; @@ -2207,7 +2207,7 @@ for (auto* var : func->params) { auto* sem = builder_.Sem().Get(var); auto* type = sem->Type(); - if (TINT_UNLIKELY(!type->Is<core::type::Struct>())) { + if (DAWN_UNLIKELY(!type->Is<core::type::Struct>())) { // ICE likely indicates that the CanonicalizeEntryPointIO transform was // not run, or a builtin parameter was added after it was run. TINT_ICE() << "Unsupported non-struct entry point parameter"; @@ -2716,14 +2716,14 @@ if (mat->Rows() != mat->Columns()) { out << "x" << mat->Rows(); } - } else if (TINT_UNLIKELY(type->Is<core::type::Pointer>())) { + } else if (DAWN_UNLIKELY(type->Is<core::type::Pointer>())) { TINT_ICE() << "Attempting to emit pointer type. These should have been removed with the " "SimplifyPointers transform"; } else if (type->Is<core::type::Sampler>()) { } else if (auto* str = type->As<core::type::Struct>()) { out << StructName(str); } else if (auto* tex = type->As<core::type::Texture>()) { - if (TINT_UNLIKELY(tex->Is<core::type::ExternalTexture>())) { + if (DAWN_UNLIKELY(tex->Is<core::type::ExternalTexture>())) { TINT_ICE() << "Multiplanar external texture transform was not run."; } @@ -2771,7 +2771,7 @@ if (!subtype || subtype->Is<core::type::F32>()) { } else if (subtype->Is<core::type::I32>()) { out << "i"; - } else if (TINT_LIKELY(subtype->Is<core::type::U32>())) { + } else if (DAWN_LIKELY(subtype->Is<core::type::U32>())) { out << "u"; } else { TINT_ICE() << "Unsupported texture type";
diff --git a/src/tint/lang/glsl/writer/ast_raise/texture_builtins_from_uniform.cc b/src/tint/lang/glsl/writer/ast_raise/texture_builtins_from_uniform.cc index 450499a..4eb5b55 100644 --- a/src/tint/lang/glsl/writer/ast_raise/texture_builtins_from_uniform.cc +++ b/src/tint/lang/glsl/writer/ast_raise/texture_builtins_from_uniform.cc
@@ -331,7 +331,7 @@ auto* ty = global_sem->Type()->UnwrapRef(); auto* str = ty->As<sem::Struct>(); - if (TINT_UNLIKELY(!str)) { + if (DAWN_UNLIKELY(!str)) { TINT_ICE() << "existing ubo binding " << cfg->ubo_binding << " is not a struct."; }
diff --git a/src/tint/lang/hlsl/writer/ast_printer/ast_printer.cc b/src/tint/lang/hlsl/writer/ast_printer/ast_printer.cc index ce29693..a22cd99 100644 --- a/src/tint/lang/hlsl/writer/ast_printer/ast_printer.cc +++ b/src/tint/lang/hlsl/writer/ast_printer/ast_printer.cc
@@ -900,7 +900,7 @@ bool ASTPrinter::EmitAssign(const ast::AssignmentStatement* stmt) { if (auto* lhs_access = stmt->lhs->As<ast::IndexAccessorExpression>()) { auto validate_obj_not_pointer = [&](const core::type::Type* object_ty) { - if (TINT_UNLIKELY(object_ty->Is<core::type::Pointer>())) { + if (DAWN_UNLIKELY(object_ty->Is<core::type::Pointer>())) { TINT_ICE() << "lhs of index accessor should not be a pointer. These should have " "been removed by transforms such as SimplifyPointers, " "DecomposeMemoryAccess, and DirectVariableAccess"; @@ -2675,7 +2675,7 @@ }; auto* texture = arg(Usage::kTexture); - if (TINT_UNLIKELY(!texture)) { + if (DAWN_UNLIKELY(!texture)) { TINT_ICE() << "missing texture argument"; } @@ -2790,7 +2790,7 @@ } } - if (TINT_UNLIKELY(num_dimensions > 4)) { + if (DAWN_UNLIKELY(num_dimensions > 4)) { TINT_ICE() << "Texture query builtin temporary vector has " << num_dimensions << " dimensions"; } @@ -2823,7 +2823,7 @@ pre << dims; } else { static constexpr char xyzw[] = {'x', 'y', 'z', 'w'}; - if (TINT_UNLIKELY(num_dimensions < 0 || num_dimensions > 4)) { + if (DAWN_UNLIKELY(num_dimensions < 0 || num_dimensions > 4)) { TINT_ICE() << "vector dimensions are " << num_dimensions; } for (int i = 0; i < num_dimensions; i++) { @@ -2931,7 +2931,7 @@ } auto* param_coords = arg(Usage::kCoords); - if (TINT_UNLIKELY(!param_coords)) { + if (DAWN_UNLIKELY(!param_coords)) { TINT_ICE() << "missing coords argument"; } @@ -3016,7 +3016,7 @@ out << "xyz"[i]; } } - if (TINT_UNLIKELY(wgsl_ret_width > hlsl_ret_width)) { + if (DAWN_UNLIKELY(wgsl_ret_width > hlsl_ret_width)) { TINT_ICE() << "WGSL return width (" << wgsl_ret_width << ") is wider than HLSL return width (" << hlsl_ret_width << ") for " << builtin->Fn(); @@ -3524,7 +3524,7 @@ } out << "RasterizerOrderedTexture2D"; auto* component = ImageFormatToRWtextureType(storage->TexelFormat()); - if (TINT_UNLIKELY(!component)) { + if (DAWN_UNLIKELY(!component)) { TINT_ICE() << "Unsupported StorageTexture TexelFormat: " << static_cast<int>(storage->TexelFormat()); } @@ -3712,7 +3712,7 @@ for (auto* var : func->params) { auto* sem = builder_.Sem().Get(var); auto* type = sem->Type(); - if (TINT_UNLIKELY(!type->Is<core::type::Struct>())) { + if (DAWN_UNLIKELY(!type->Is<core::type::Struct>())) { // ICE likely indicates that the CanonicalizeEntryPointIO transform was // not run, or a builtin parameter was added after it was run. TINT_ICE() << "Unsupported non-struct entry point parameter"; @@ -4398,7 +4398,7 @@ const core::type::Type* base_type = ary; std::vector<uint32_t> sizes; while (auto* arr = base_type->As<core::type::Array>()) { - if (TINT_UNLIKELY(arr->Count()->Is<core::type::RuntimeArrayCount>())) { + if (DAWN_UNLIKELY(arr->Count()->Is<core::type::RuntimeArrayCount>())) { TINT_ICE() << "runtime arrays may only exist in storage buffers, which should have " "been transformed into a ByteAddressBuffer"; @@ -4482,7 +4482,7 @@ return true; }, [&](const core::type::Texture* tex) { - if (TINT_UNLIKELY(tex->Is<core::type::ExternalTexture>())) { + if (DAWN_UNLIKELY(tex->Is<core::type::ExternalTexture>())) { TINT_ICE() << "Multiplanar external texture transform was not run."; } @@ -4521,7 +4521,7 @@ if (storage) { auto* component = ImageFormatToRWtextureType(storage->TexelFormat()); - if (TINT_UNLIKELY(!component)) { + if (DAWN_UNLIKELY(!component)) { TINT_ICE() << "Unsupported StorageTexture TexelFormat: " << static_cast<int>(storage->TexelFormat()); } @@ -4535,7 +4535,7 @@ out << "float4"; } else if (subtype->Is<core::type::I32>()) { out << "int4"; - } else if (TINT_LIKELY(subtype->Is<core::type::U32>())) { + } else if (DAWN_LIKELY(subtype->Is<core::type::U32>())) { out << "uint4"; } else { TINT_ICE() << "Unsupported multisampled texture type"; @@ -4620,7 +4620,7 @@ if (auto location = attributes.location) { auto& pipeline_stage_uses = str->PipelineStageUses(); - if (TINT_UNLIKELY(pipeline_stage_uses.Count() != 1)) { + if (DAWN_UNLIKELY(pipeline_stage_uses.Count() != 1)) { TINT_ICE() << "invalid entry point IO struct uses"; } if (pipeline_stage_uses.Contains(core::type::PipelineStageUsage::kVertexInput)) { @@ -4631,7 +4631,7 @@ } else if (pipeline_stage_uses.Contains( core::type::PipelineStageUsage::kFragmentInput)) { post += " : TEXCOORD" + std::to_string(location.value()); - } else if (TINT_LIKELY(pipeline_stage_uses.Contains( + } else if (DAWN_LIKELY(pipeline_stage_uses.Contains( core::type::PipelineStageUsage::kFragmentOutput))) { if (auto blend_src = attributes.blend_src) { post +=
diff --git a/src/tint/lang/hlsl/writer/ast_raise/calculate_array_length.cc b/src/tint/lang/hlsl/writer/ast_raise/calculate_array_length.cc index f3763a8..4f37291 100644 --- a/src/tint/lang/hlsl/writer/ast_raise/calculate_array_length.cc +++ b/src/tint/lang/hlsl/writer/ast_raise/calculate_array_length.cc
@@ -164,7 +164,7 @@ // arrayLength(&array_var) auto* arg = call_expr->args[0]; auto* address_of = arg->As<ast::UnaryOpExpression>(); - if (TINT_UNLIKELY(!address_of || address_of->op != core::UnaryOp::kAddressOf)) { + if (DAWN_UNLIKELY(!address_of || address_of->op != core::UnaryOp::kAddressOf)) { TINT_ICE() << "arrayLength() expected address-of, got " << arg->TypeInfo().name; } @@ -173,11 +173,11 @@ storage_buffer_expr = accessor->object; } auto* storage_buffer_sem = sem.Get<sem::VariableUser>(storage_buffer_expr); - if (TINT_UNLIKELY(!storage_buffer_sem)) { + if (DAWN_UNLIKELY(!storage_buffer_sem)) { TINT_ICE() << "expected form of arrayLength argument to be &array_var or " "&struct_var.array_member"; } - if (TINT_UNLIKELY(storage_buffer_sem->Type()->Is<core::type::Pointer>())) { + if (DAWN_UNLIKELY(storage_buffer_sem->Type()->Is<core::type::Pointer>())) { TINT_ICE() << "storage buffer variable should not be a pointer. These should have " "been removed by the SimplifyPointers transform"; @@ -229,7 +229,7 @@ }, [&](const core::type::Array* arr) { return arr; }); - if (TINT_UNLIKELY(!array_type)) { + if (DAWN_UNLIKELY(!array_type)) { TINT_ICE() << "expected form of arrayLength argument to be " "&array_var or &struct_var.array_member"; }
diff --git a/src/tint/lang/hlsl/writer/ast_raise/decompose_memory_access.cc b/src/tint/lang/hlsl/writer/ast_raise/decompose_memory_access.cc index 48b28d9..41a9c59 100644 --- a/src/tint/lang/hlsl/writer/ast_raise/decompose_memory_access.cc +++ b/src/tint/lang/hlsl/writer/ast_raise/decompose_memory_access.cc
@@ -506,7 +506,7 @@ auto* i = b.Var(b.Symbols().New("i"), b.Expr(0_u)); auto* for_init = b.Decl(i); auto arr_cnt = arr_ty->ConstantCount(); - if (TINT_UNLIKELY(!arr_cnt)) { + if (DAWN_UNLIKELY(!arr_cnt)) { // Non-constant counts should not be possible: // * Override-expression counts can only be applied to workgroup arrays, and // this method only handles storage and uniform. @@ -591,7 +591,7 @@ auto* i = b.Var(b.Symbols().New("i"), b.Expr(0_u)); auto* for_init = b.Decl(i); auto arr_cnt = arr_ty->ConstantCount(); - if (TINT_UNLIKELY(!arr_cnt)) { + if (DAWN_UNLIKELY(!arr_cnt)) { // Non-constant counts should not be possible: // * Override-expression counts can only be applied to workgroup // arrays, and this method only handles storage and uniform. @@ -663,7 +663,7 @@ } auto* atomic = IntrinsicAtomicFor(ctx.dst, fn, el_ty, buffer); - if (TINT_UNLIKELY(!atomic)) { + if (DAWN_UNLIKELY(!atomic)) { TINT_ICE() << "IntrinsicAtomicFor() returned nullptr for fn " << fn << " and type " << el_ty->TypeInfo().name; }
diff --git a/src/tint/lang/hlsl/writer/ast_raise/localize_struct_array_assignment.cc b/src/tint/lang/hlsl/writer/ast_raise/localize_struct_array_assignment.cc index c01539c..dd03321 100644 --- a/src/tint/lang/hlsl/writer/ast_raise/localize_struct_array_assignment.cc +++ b/src/tint/lang/hlsl/writer/ast_raise/localize_struct_array_assignment.cc
@@ -184,7 +184,7 @@ // Indexing a member access expr? if (auto* ma = ia->object->As<ast::MemberAccessorExpression>()) { const auto* ma_ty = src.TypeOf(ma); - if (TINT_UNLIKELY(ma_ty->Is<core::type::Pointer>())) { + if (DAWN_UNLIKELY(ma_ty->Is<core::type::Pointer>())) { TINT_ICE() << "lhs of index accessor expression should not be a pointer. These " "should have been removed by the SimplifyPointers transform"; @@ -208,7 +208,7 @@ std::pair<const core::type::Type*, core::AddressSpace> GetOriginatingTypeAndAddressSpace( const ast::AssignmentStatement* assign_stmt) { auto* root_ident = src.Sem().GetVal(assign_stmt->lhs)->RootIdentifier(); - if (TINT_UNLIKELY(!root_ident)) { + if (DAWN_UNLIKELY(!root_ident)) { TINT_ICE() << "Unable to determine originating variable for lhs of assignment " "statement"; }
diff --git a/src/tint/lang/hlsl/writer/ast_raise/pixel_local.cc b/src/tint/lang/hlsl/writer/ast_raise/pixel_local.cc index 128cfef..eebce4e 100644 --- a/src/tint/lang/hlsl/writer/ast_raise/pixel_local.cc +++ b/src/tint/lang/hlsl/writer/ast_raise/pixel_local.cc
@@ -326,7 +326,7 @@ [&](const core::type::F32*) { return core::TexelFormat::kR32Float; }, TINT_ICE_ON_NO_MATCH); auto rov_format = ROVTexelFormat(member->Index()); - if (TINT_UNLIKELY(rov_format != Success)) { + if (DAWN_UNLIKELY(rov_format != Success)) { return rov_format.Failure(); } auto rov_type = b.ty.storage_texture(core::type::TextureDimension::k2d, @@ -464,7 +464,7 @@ /// @param field_index the pixel local field index uint32_t ROVRegisterIndex(uint32_t field_index) { auto idx = cfg.pls_member_to_rov_reg.Get(field_index); - if (TINT_UNLIKELY(!idx)) { + if (DAWN_UNLIKELY(!idx)) { b.Diagnostics().AddError(Source{}) << "PixelLocal::Config::attachments missing entry for field " << field_index; return 0; @@ -476,7 +476,7 @@ /// @param field_index the pixel local field index Result<core::TexelFormat> ROVTexelFormat(uint32_t field_index) { auto format = cfg.pls_member_to_rov_format.Get(field_index); - if (TINT_UNLIKELY(!format)) { + if (DAWN_UNLIKELY(!format)) { diag::Diagnostic err; err.severity = diag::Severity::Error; err.message << "PixelLocal::Config::attachments missing entry for field "
diff --git a/src/tint/lang/hlsl/writer/ast_raise/truncate_interstage_variables.cc b/src/tint/lang/hlsl/writer/ast_raise/truncate_interstage_variables.cc index 9918e7e..605136e 100644 --- a/src/tint/lang/hlsl/writer/ast_raise/truncate_interstage_variables.cc +++ b/src/tint/lang/hlsl/writer/ast_raise/truncate_interstage_variables.cc
@@ -100,7 +100,7 @@ // This transform is run after CanonicalizeEntryPointIO transform, // So it is guaranteed that entry point inputs are already grouped in a struct. - if (TINT_UNLIKELY(!str)) { + if (DAWN_UNLIKELY(!str)) { TINT_ICE() << "Entrypoint function return type is non-struct.\n" << "TruncateInterstageVariables transform needs to run after " "CanonicalizeEntryPointIO transform.";
diff --git a/src/tint/lang/hlsl/writer/printer/printer.cc b/src/tint/lang/hlsl/writer/printer/printer.cc index 69b2c29..78b73b3 100644 --- a/src/tint/lang/hlsl/writer/printer/printer.cc +++ b/src/tint/lang/hlsl/writer/printer/printer.cc
@@ -1317,7 +1317,7 @@ const core::type::Type* base_type = ary; std::vector<uint32_t> sizes; while (auto* arr = base_type->As<core::type::Array>()) { - if (TINT_UNLIKELY(arr->Count()->Is<core::type::RuntimeArrayCount>())) { + if (DAWN_UNLIKELY(arr->Count()->Is<core::type::RuntimeArrayCount>())) { TINT_ICE() << "runtime arrays may only exist in storage buffers, which " "should have " "been transformed into a ByteAddressBuffer"; @@ -1382,7 +1382,7 @@ } void EmitTextureType(StringStream& out, const core::type::Texture* tex) { - if (TINT_UNLIKELY(tex->Is<core::type::ExternalTexture>())) { + if (DAWN_UNLIKELY(tex->Is<core::type::ExternalTexture>())) { TINT_ICE() << "Multiplanar external texture transform was not run."; } @@ -1421,7 +1421,7 @@ if (storage) { auto* component = ImageFormatToRWtextureType(storage->TexelFormat()); - if (TINT_UNLIKELY(!component)) { + if (DAWN_UNLIKELY(!component)) { TINT_ICE() << "Unsupported StorageTexture TexelFormat: " << static_cast<int>(storage->TexelFormat()); } @@ -1435,7 +1435,7 @@ out << "float4"; } else if (subtype->Is<core::type::I32>()) { out << "int4"; - } else if (TINT_LIKELY(subtype->Is<core::type::U32>())) { + } else if (DAWN_LIKELY(subtype->Is<core::type::U32>())) { out << "uint4"; } else { TINT_ICE() << "Unsupported multisampled texture type"; @@ -1472,7 +1472,7 @@ std::string post; if (auto location = attributes.location) { auto& pipeline_stage_uses = str->PipelineStageUses(); - if (TINT_UNLIKELY(pipeline_stage_uses.Count() != 1)) { + if (DAWN_UNLIKELY(pipeline_stage_uses.Count() != 1)) { TINT_ICE() << "invalid entry point IO struct uses"; } if (pipeline_stage_uses.Contains( @@ -1484,7 +1484,7 @@ } else if (pipeline_stage_uses.Contains( core::type::PipelineStageUsage::kFragmentInput)) { post += " : TEXCOORD" + std::to_string(location.value()); - } else if (TINT_LIKELY(pipeline_stage_uses.Contains( + } else if (DAWN_LIKELY(pipeline_stage_uses.Contains( core::type::PipelineStageUsage::kFragmentOutput))) { if (auto blend_src = attributes.blend_src) { post += " : SV_Target" +
diff --git a/src/tint/lang/msl/writer/ast_printer/ast_printer.cc b/src/tint/lang/msl/writer/ast_printer/ast_printer.cc index 6c46559..e474114 100644 --- a/src/tint/lang/msl/writer/ast_printer/ast_printer.cc +++ b/src/tint/lang/msl/writer/ast_printer/ast_printer.cc
@@ -1239,7 +1239,7 @@ }; auto* texture = arg(Usage::kTexture)->Declaration(); - if (TINT_UNLIKELY(!texture)) { + if (DAWN_UNLIKELY(!texture)) { TINT_ICE() << "missing texture arg"; } @@ -2183,12 +2183,12 @@ // attribute have a value of zero. const uint32_t kInvalidBindingIndex = std::numeric_limits<uint32_t>::max(); auto get_binding_index = [&](const ast::Parameter* param) -> uint32_t { - if (TINT_UNLIKELY(!param->HasBindingPoint())) { + if (DAWN_UNLIKELY(!param->HasBindingPoint())) { TINT_ICE() << "missing binding attributes for entry point parameter"; } auto* param_sem = builder_.Sem().Get(param); auto bp = param_sem->Attributes().binding_point; - if (TINT_UNLIKELY(bp->group != 0)) { + if (DAWN_UNLIKELY(bp->group != 0)) { TINT_ICE() << "encountered non-zero resource group index (use BindingRemapper to fix)"; } return bp->binding; @@ -2290,7 +2290,7 @@ out << " [[" << name << "]]"; } - if (TINT_UNLIKELY(!builtin_found)) { + if (DAWN_UNLIKELY(!builtin_found)) { TINT_ICE() << "Unsupported entry point parameter"; } return true; @@ -2723,7 +2723,7 @@ out << "atomic_int"; return true; } - if (TINT_LIKELY(atomic->Type()->Is<core::type::U32>())) { + if (DAWN_LIKELY(atomic->Type()->Is<core::type::U32>())) { out << "atomic_uint"; return true; } @@ -2804,7 +2804,7 @@ return true; }, [&](const core::type::Texture* tex) { - if (TINT_UNLIKELY(tex->Is<core::type::ExternalTexture>())) { + if (DAWN_UNLIKELY(tex->Is<core::type::ExternalTexture>())) { TINT_ICE() << "Multiplanar external texture transform was not run."; } @@ -2979,7 +2979,7 @@ auto wgsl_offset = mem->Offset(); if (is_host_shareable) { - if (TINT_UNLIKELY(wgsl_offset < msl_offset)) { + if (DAWN_UNLIKELY(wgsl_offset < msl_offset)) { // Unimplementable layout TINT_ICE() << "Structure member WGSL offset (" << wgsl_offset << ") is behind MSL offset (" << msl_offset << ")"; @@ -3009,7 +3009,7 @@ // Emit `[[clip_distance]]` as a C-style f32 array if (builtin == core::BuiltinValue::kClipDistances) { const auto* arrayType = mem->Type()->As<core::type::Array>(); - if (TINT_UNLIKELY(arrayType == nullptr || + if (DAWN_UNLIKELY(arrayType == nullptr || !arrayType->ConstantCount().has_value())) { TINT_ICE() << "The type of `clip_distances` is not a sized array"; } else { @@ -3032,7 +3032,7 @@ if (auto location = attributes.location) { auto& pipeline_stage_uses = str->PipelineStageUses(); - if (TINT_UNLIKELY(pipeline_stage_uses.Count() != 1)) { + if (DAWN_UNLIKELY(pipeline_stage_uses.Count() != 1)) { TINT_ICE() << "invalid entry point IO struct uses for " << str->Name().NameView(); } @@ -3044,7 +3044,7 @@ } else if (pipeline_stage_uses.Contains( core::type::PipelineStageUsage::kFragmentInput)) { out << " [[user(locn" + std::to_string(location.value()) + ")]]"; - } else if (TINT_LIKELY(pipeline_stage_uses.Contains( + } else if (DAWN_LIKELY(pipeline_stage_uses.Contains( core::type::PipelineStageUsage::kFragmentOutput))) { if (auto blend_src = attributes.blend_src) { out << " [[color(" + std::to_string(location.value()) + ") index(" + @@ -3080,7 +3080,7 @@ if (is_host_shareable) { // Calculate new MSL offset auto size_align = MslPackedTypeSizeAndAlign(ty); - if (TINT_UNLIKELY(msl_offset % size_align.align)) { + if (DAWN_UNLIKELY(msl_offset % size_align.align)) { TINT_ICE() << "Misaligned MSL structure member " << ty->FriendlyName() << " " << mem_name; }
diff --git a/src/tint/lang/msl/writer/ast_raise/pixel_local.cc b/src/tint/lang/msl/writer/ast_raise/pixel_local.cc index 63c58b2..572939b 100644 --- a/src/tint/lang/msl/writer/ast_raise/pixel_local.cc +++ b/src/tint/lang/msl/writer/ast_raise/pixel_local.cc
@@ -247,7 +247,7 @@ /// @param field_index the pixel local field index uint32_t AttachmentIndex(uint32_t field_index) { auto idx = cfg.attachments.Get(field_index); - if (TINT_UNLIKELY(!idx)) { + if (DAWN_UNLIKELY(!idx)) { b.Diagnostics().AddError(Source{}) << "PixelLocal::Config::attachments missing entry for field " << field_index; return 0;
diff --git a/src/tint/lang/msl/writer/common/printer_support.cc b/src/tint/lang/msl/writer/common/printer_support.cc index 9f563c8..a303738 100644 --- a/src/tint/lang/msl/writer/common/printer_support.cc +++ b/src/tint/lang/msl/writer/common/printer_support.cc
@@ -206,7 +206,7 @@ }, [&](const core::type::Array* arr) { - if (TINT_UNLIKELY(!arr->IsStrideImplicit())) { + if (DAWN_UNLIKELY(!arr->IsStrideImplicit())) { TINT_ICE() << "arrays with explicit strides should not exist past the SPIR-V reader"; }
diff --git a/src/tint/lang/msl/writer/printer/printer.cc b/src/tint/lang/msl/writer/printer/printer.cc index cc7eb25..c5a18b2 100644 --- a/src/tint/lang/msl/writer/printer/printer.cc +++ b/src/tint/lang/msl/writer/printer/printer.cc
@@ -1264,7 +1264,7 @@ out << "atomic_int"; return; } - if (TINT_LIKELY(atomic->Type()->Is<core::type::U32>())) { + if (DAWN_LIKELY(atomic->Type()->Is<core::type::U32>())) { out << "atomic_uint"; return; } @@ -1313,7 +1313,7 @@ /// @param out the output stream /// @param tex the texture to emit void EmitTextureType(StringStream& out, const core::type::Texture* tex) { - if (TINT_UNLIKELY(tex->Is<core::type::ExternalTexture>())) { + if (DAWN_UNLIKELY(tex->Is<core::type::ExternalTexture>())) { TINT_IR_ICE(ir_) << "Multiplanar external texture transform was not run."; } @@ -1425,7 +1425,7 @@ auto ir_offset = mem->Offset(); if (is_host_shareable) { - if (TINT_UNLIKELY(ir_offset < msl_offset)) { + if (DAWN_UNLIKELY(ir_offset < msl_offset)) { // Unimplementable layout TINT_IR_ICE(ir_) << "Structure member offset (" << ir_offset << ") is behind MSL offset (" << msl_offset << ")"; @@ -1458,7 +1458,7 @@ if (auto location = attributes.location) { auto& pipeline_stage_uses = str->PipelineStageUses(); - if (TINT_UNLIKELY(pipeline_stage_uses.Count() != 1)) { + if (DAWN_UNLIKELY(pipeline_stage_uses.Count() != 1)) { TINT_IR_ICE(ir_) << "invalid entry point IO struct uses"; } @@ -1470,7 +1470,7 @@ } else if (pipeline_stage_uses.Contains( core::type::PipelineStageUsage::kFragmentInput)) { out << " [[user(locn" << location.value() << ")]]"; - } else if (TINT_LIKELY(pipeline_stage_uses.Contains( + } else if (DAWN_LIKELY(pipeline_stage_uses.Contains( core::type::PipelineStageUsage::kFragmentOutput))) { out << " [[color(" << location.value() << ")]]"; if (auto blend_src = attributes.blend_src) { @@ -1518,7 +1518,7 @@ if (is_host_shareable) { // Calculate new MSL offset auto size_align = MslPackedTypeSizeAndAlign(ty); - if (TINT_UNLIKELY(msl_offset % size_align.align)) { + if (DAWN_UNLIKELY(msl_offset % size_align.align)) { TINT_IR_ICE(ir_) << "Misaligned MSL structure member " << mem_name << " : " << ty->FriendlyName() << " offset: " << msl_offset << " align: " << size_align.align;
diff --git a/src/tint/lang/spirv/reader/ast_lower/decompose_strided_array.cc b/src/tint/lang/spirv/reader/ast_lower/decompose_strided_array.cc index 4262a41..0d1bcdb 100644 --- a/src/tint/lang/spirv/reader/ast_lower/decompose_strided_array.cc +++ b/src/tint/lang/spirv/reader/ast_lower/decompose_strided_array.cc
@@ -143,7 +143,7 @@ // Example: `arr[i]` -> `arr[i].el` ctx.ReplaceAll([&](const ast::IndexAccessorExpression* idx) -> const ast::Expression* { if (auto* ty = src.TypeOf(idx->object)) { - if (TINT_UNLIKELY(ty->Is<core::type::Pointer>())) { + if (DAWN_UNLIKELY(ty->Is<core::type::Pointer>())) { TINT_ICE() << "lhs of index accessor expression should not be a pointer. These " "should have been removed by the SimplifyPointers transform"; }
diff --git a/src/tint/lang/wgsl/ast/builder.cc b/src/tint/lang/wgsl/ast/builder.cc index f1640f1..2a29caf 100644 --- a/src/tint/lang/wgsl/ast/builder.cc +++ b/src/tint/lang/wgsl/ast/builder.cc
@@ -75,7 +75,7 @@ } void Builder::AssertNotMoved() const { - if (TINT_UNLIKELY(moved_)) { + if (DAWN_UNLIKELY(moved_)) { TINT_ICE() << "Attempting to use Builder after it has been moved"; } }
diff --git a/src/tint/lang/wgsl/ast/builder.h b/src/tint/lang/wgsl/ast/builder.h index f622c84..cf09f0a 100644 --- a/src/tint/lang/wgsl/ast/builder.h +++ b/src/tint/lang/wgsl/ast/builder.h
@@ -658,7 +658,7 @@ /// @param rows number of rows for the matrix /// @return a matrix of @p type ast::Type mat(const Source& source, ast::Type type, uint32_t columns, uint32_t rows) const { - if (TINT_LIKELY(columns >= 2 && columns <= 4 && rows >= 2 && rows <= 4)) { + if (DAWN_LIKELY(columns >= 2 && columns <= 4 && rows >= 2 && rows <= 4)) { static constexpr const char* names[] = { "mat2x2", "mat2x3", "mat2x4", // "mat3x2", "mat3x3", "mat3x4", //
diff --git a/src/tint/lang/wgsl/ast/clone_context.h b/src/tint/lang/wgsl/ast/clone_context.h index deb1012..82d2490 100644 --- a/src/tint/lang/wgsl/ast/clone_context.h +++ b/src/tint/lang/wgsl/ast/clone_context.h
@@ -289,7 +289,7 @@ for (auto& transform : transforms_) { bool already_registered = transform.typeinfo->Is(&tint::TypeInfo::Of<T>()) || tint::TypeInfo::Of<T>().Is(transform.typeinfo); - if (TINT_UNLIKELY(already_registered)) { + if (DAWN_UNLIKELY(already_registered)) { TINT_ICE() << "ReplaceAll() called with a handler for type " << TypeInfo::Of<T>().name << " that is already handled by a handler for type " @@ -314,7 +314,7 @@ /// register a SymbolTransform more than once will result in an ICE. /// @returns this CloneContext so calls can be chained CloneContext& ReplaceAll(const SymbolTransform& replacer) { - if (TINT_UNLIKELY(symbol_transform_)) { + if (DAWN_UNLIKELY(symbol_transform_)) { TINT_ICE() << "ReplaceAll(const SymbolTransform&) called multiple times on the same " "CloneContext"; } @@ -370,7 +370,7 @@ template <typename T, size_t N, typename OBJECT> CloneContext& Remove(const Vector<T, N>& vector, OBJECT* object) { TINT_ASSERT_GENERATION_IDS_EQUAL_IF_VALID(src_id, object); - if (TINT_UNLIKELY((std::find(vector.begin(), vector.end(), object) == vector.end()))) { + if (DAWN_UNLIKELY((std::find(vector.begin(), vector.end(), object) == vector.end()))) { TINT_ICE() << "CloneContext::Remove() vector does not contain object"; return *this; } @@ -436,7 +436,7 @@ const OBJECT* object) { TINT_ASSERT_GENERATION_IDS_EQUAL_IF_VALID(src_id, before); TINT_ASSERT_GENERATION_IDS_EQUAL_IF_VALID(dst, object); - if (TINT_UNLIKELY((std::find(vector.begin(), vector.end(), before) == vector.end()))) { + if (DAWN_UNLIKELY((std::find(vector.begin(), vector.end(), before) == vector.end()))) { TINT_ICE() << "CloneContext::InsertBefore() vector does not contain before"; return *this; } @@ -477,7 +477,7 @@ const OBJECT* object) { TINT_ASSERT_GENERATION_IDS_EQUAL_IF_VALID(src_id, after); TINT_ASSERT_GENERATION_IDS_EQUAL_IF_VALID(dst, object); - if (TINT_UNLIKELY((std::find(vector.begin(), vector.end(), after) == vector.end()))) { + if (DAWN_UNLIKELY((std::find(vector.begin(), vector.end(), after) == vector.end()))) { TINT_ICE() << "CloneContext::InsertAfter() vector does not contain after"; return *this; } @@ -563,7 +563,7 @@ return nullptr; } const TO* cast = obj->template As<TO>(); - if (TINT_LIKELY(cast)) { + if (DAWN_LIKELY(cast)) { return cast; } CheckedCastFailure(obj, tint::TypeInfo::Of<TO>());
diff --git a/src/tint/lang/wgsl/ast/module.cc b/src/tint/lang/wgsl/ast/module.cc index 269bdc0..7dcde59 100644 --- a/src/tint/lang/wgsl/ast/module.cc +++ b/src/tint/lang/wgsl/ast/module.cc
@@ -176,7 +176,7 @@ diagnostic_directives_.Clear(); for (auto* decl : global_declarations_) { - if (TINT_UNLIKELY(!decl)) { + if (DAWN_UNLIKELY(!decl)) { TINT_ICE() << "src global declaration was nullptr"; } BinGlobalDeclaration(decl);
diff --git a/src/tint/lang/wgsl/ast/transform/array_length_from_uniform.cc b/src/tint/lang/wgsl/ast/transform/array_length_from_uniform.cc index c95cec9..cea6a86 100644 --- a/src/tint/lang/wgsl/ast/transform/array_length_from_uniform.cc +++ b/src/tint/lang/wgsl/ast/transform/array_length_from_uniform.cc
@@ -220,7 +220,7 @@ // array_length = ---------------------------------------- // array_stride const Expression* total_size = total_storage_buffer_size; - if (TINT_UNLIKELY(global->Type()->Is<core::type::Pointer>())) { + if (DAWN_UNLIKELY(global->Type()->Is<core::type::Pointer>())) { TINT_ICE() << "storage buffer variable should not be a pointer. " "These should have been removed by the SimplifyPointers transform"; }
diff --git a/src/tint/lang/wgsl/ast/transform/builtin_polyfill.cc b/src/tint/lang/wgsl/ast/transform/builtin_polyfill.cc index 0891c85..bf323ba 100644 --- a/src/tint/lang/wgsl/ast/transform/builtin_polyfill.cc +++ b/src/tint/lang/wgsl/ast/transform/builtin_polyfill.cc
@@ -612,7 +612,7 @@ uint32_t width = WidthOf(ty); // Currently in WGSL parameters of insertBits must be i32, u32, vecN<i32> or vecN<u32> - if (TINT_UNLIKELY(((!ty->DeepestElement()->IsAnyOf<core::type::I32, core::type::U32>())))) { + if (DAWN_UNLIKELY(((!ty->DeepestElement()->IsAnyOf<core::type::I32, core::type::U32>())))) { TINT_ICE() << "insertBits polyfill only support i32, u32, and vector of i32 or u32, got " << ty->FriendlyName();
diff --git a/src/tint/lang/wgsl/ast/transform/canonicalize_entry_point_io.cc b/src/tint/lang/wgsl/ast/transform/canonicalize_entry_point_io.cc index 4b81a97..b3717bf 100644 --- a/src/tint/lang/wgsl/ast/transform/canonicalize_entry_point_io.cc +++ b/src/tint/lang/wgsl/ast/transform/canonicalize_entry_point_io.cc
@@ -415,7 +415,7 @@ func_ast->PipelineStage() == PipelineStage::kVertex && builtin_attr == core::BuiltinValue::kClipDistances) { const auto* arrayType = type->As<core::type::Array>(); - if (TINT_UNLIKELY(arrayType == nullptr || !arrayType->ConstantCount().has_value())) { + if (DAWN_UNLIKELY(arrayType == nullptr || !arrayType->ConstantCount().has_value())) { TINT_ICE() << "The type of `clip_distances` is not a sized array"; } else { clip_distances_size = *arrayType->ConstantCount(); @@ -509,7 +509,7 @@ // list to pass them through to the inner function. tint::Vector<const Expression*, 8> inner_struct_values; for (auto* member : str->Members()) { - if (TINT_UNLIKELY(member->Type()->Is<core::type::Struct>())) { + if (DAWN_UNLIKELY(member->Type()->Is<core::type::Struct>())) { TINT_ICE() << "nested IO struct"; } @@ -542,7 +542,7 @@ bool do_interpolate = func_ast->PipelineStage() != PipelineStage::kFragment; if (auto* str = inner_ret_type->As<sem::Struct>()) { for (auto* member : str->Members()) { - if (TINT_UNLIKELY(member->Type()->Is<core::type::Struct>())) { + if (DAWN_UNLIKELY(member->Type()->Is<core::type::Struct>())) { TINT_ICE() << "nested IO struct"; }
diff --git a/src/tint/lang/wgsl/ast/transform/direct_variable_access.cc b/src/tint/lang/wgsl/ast/transform/direct_variable_access.cc index 9fd64bb..0918238 100644 --- a/src/tint/lang/wgsl/ast/transform/direct_variable_access.cc +++ b/src/tint/lang/wgsl/ast/transform/direct_variable_access.cc
@@ -1104,7 +1104,7 @@ } auto* member = std::get_if<Symbol>(&op); - if (TINT_LIKELY(member)) { + if (DAWN_LIKELY(member)) { ss << member->Name(); continue; } @@ -1151,7 +1151,7 @@ } auto* member = std::get_if<Symbol>(&access); - if (TINT_LIKELY(member)) { + if (DAWN_LIKELY(member)) { /// The access is a member access. return b.MemberAccessor(expr, ctx.Clone(*member)); }
diff --git a/src/tint/lang/wgsl/ast/transform/hoist_to_decl_before.cc b/src/tint/lang/wgsl/ast/transform/hoist_to_decl_before.cc index fd763a1..1a506ec 100644 --- a/src/tint/lang/wgsl/ast/transform/hoist_to_decl_before.cc +++ b/src/tint/lang/wgsl/ast/transform/hoist_to_decl_before.cc
@@ -379,7 +379,7 @@ } auto* fl = parent->As<sem::ForLoopStatement>(); - if (TINT_LIKELY(fl)) { + if (DAWN_LIKELY(fl)) { // Insertion point is a for-loop initializer or continuing statement. // These require special care. if (fl->Declaration()->initializer == ip) { @@ -395,7 +395,7 @@ return true; } - if (TINT_LIKELY(fl->Declaration()->continuing == ip)) { + if (DAWN_LIKELY(fl->Declaration()->continuing == ip)) { // Insertion point is a for-loop continuing statement. // For-loop needs to be decomposed to a loop.
diff --git a/src/tint/lang/wgsl/ast/transform/multiplanar_external_texture.cc b/src/tint/lang/wgsl/ast/transform/multiplanar_external_texture.cc index 2190cbc..36136fe 100644 --- a/src/tint/lang/wgsl/ast/transform/multiplanar_external_texture.cc +++ b/src/tint/lang/wgsl/ast/transform/multiplanar_external_texture.cc
@@ -471,7 +471,7 @@ NewBindingSymbols syms) { const Expression* plane_0_binding_param = ctx.Clone(expr->args[0]); - if (TINT_UNLIKELY(expr->args.Length() != 3)) { + if (DAWN_UNLIKELY(expr->args.Length() != 3)) { TINT_ICE() << "expected textureSampleBaseClampToEdge call with a " "texture_external to have 3 parameters, found " << expr->args.Length() << " parameters"; @@ -515,7 +515,7 @@ /// @param syms the expanded symbols to be used in the new call /// @returns a call expression to textureLoadExternal const CallExpression* createTextureLoad(const sem::Call* call, NewBindingSymbols syms) { - if (TINT_UNLIKELY(call->Arguments().Length() != 2)) { + if (DAWN_UNLIKELY(call->Arguments().Length() != 2)) { TINT_ICE() << "expected textureLoad call with a texture_external to have 2 arguments, found " << call->Arguments().Length() << " arguments"; @@ -561,7 +561,7 @@ /// @param syms the expanded symbols to be used in the new call /// @returns a load of params.visibleSize const Expression* createTextureDimensions(const sem::Call* call, NewBindingSymbols syms) { - if (TINT_UNLIKELY(call->Arguments().Length() != 1)) { + if (DAWN_UNLIKELY(call->Arguments().Length() != 1)) { TINT_ICE() << "expected textureDimensions call with a texture_external to have 1 " "arguments, found " << call->Arguments().Length() << " arguments";
diff --git a/src/tint/lang/wgsl/ast/transform/push_constant_helper.cc b/src/tint/lang/wgsl/ast/transform/push_constant_helper.cc index 6b72964..7f442af 100644 --- a/src/tint/lang/wgsl/ast/transform/push_constant_helper.cc +++ b/src/tint/lang/wgsl/ast/transform/push_constant_helper.cc
@@ -47,7 +47,7 @@ if (v->AddressSpace() == core::AddressSpace::kPushConstant) { push_constants_var = var; auto* str = v->Type()->UnwrapRef()->As<sem::Struct>(); - if (TINT_UNLIKELY(!str)) { + if (DAWN_UNLIKELY(!str)) { TINT_ICE() << "expected var<push_constant> type to be struct. Was " "AddBlockAttribute run?"; } @@ -63,7 +63,7 @@ void PushConstantHelper::InsertMember(const char* name, ast::Type type, uint32_t offset) { auto& member = member_map[offset]; - if (TINT_UNLIKELY(member != nullptr)) { + if (DAWN_UNLIKELY(member != nullptr)) { ctx.dst->Diagnostics().AddError(Source{}) << "struct member offset collision"; } member = ctx.dst->Member(name, type, Vector{ctx.dst->MemberOffset(core::AInt(offset))});
diff --git a/src/tint/lang/wgsl/ast/transform/std140.cc b/src/tint/lang/wgsl/ast/transform/std140.cc index ea7f5fe..5884d87 100644 --- a/src/tint/lang/wgsl/ast/transform/std140.cc +++ b/src/tint/lang/wgsl/ast/transform/std140.cc
@@ -430,7 +430,7 @@ attrs.Push(b.create<StrideAttribute>(arr->Stride())); } auto count = arr->ConstantCount(); - if (TINT_UNLIKELY(!count)) { + if (DAWN_UNLIKELY(!count)) { // Non-constant counts should not be possible: // * Override-expression counts can only be applied to workgroup arrays, and // this method only handles types transitively used as uniform buffers. @@ -517,7 +517,7 @@ access.indices.Push(UniformVariable{}); return Action::kStop; } - if (TINT_LIKELY(user->Variable()->Type()->Is<core::type::Pointer>())) { + if (DAWN_LIKELY(user->Variable()->Type()->Is<core::type::Pointer>())) { // Found a pointer. As the root identifier is a uniform buffer variable, // this must be a pointer-let. Continue traversing from the let // initializer. @@ -626,7 +626,7 @@ [&](const core::type::Struct* str) { return str->Name().Name(); }, [&](const core::type::Array* arr) { auto count = arr->ConstantCount(); - if (TINT_UNLIKELY(!count)) { + if (DAWN_UNLIKELY(!count)) { // Non-constant counts should not be possible: // * Override-expression counts can only be applied to workgroup arrays, and // this method only handles types transitively used as uniform buffers. @@ -705,7 +705,7 @@ [&](const core::type::Matrix* mat) { // Reassemble a std140 matrix from the structure of column vector members. auto std140_mat = std140_mats.Get(mat); - if (TINT_LIKELY(std140_mat)) { + if (DAWN_LIKELY(std140_mat)) { tint::Vector<const Expression*, 8> args; // std140 decomposed matrix. Reassemble. auto mat_ty = CreateASTTypeFor(ctx, mat); @@ -727,7 +727,7 @@ auto* dst_el = b.IndexAccessor(var, i); auto* src_el = Convert(arr->ElemType(), b.IndexAccessor(param, i)); auto count = arr->ConstantCount(); - if (TINT_UNLIKELY(!count)) { + if (DAWN_UNLIKELY(!count)) { // Non-constant counts should not be possible: // * Override-expression counts can only be applied to workgroup arrays, and // this method only handles types transitively used as uniform buffers.
diff --git a/src/tint/lang/wgsl/ast/transform/transform.cc b/src/tint/lang/wgsl/ast/transform/transform.cc index 1e0bf1e..97e8a7b 100644 --- a/src/tint/lang/wgsl/ast/transform/transform.cc +++ b/src/tint/lang/wgsl/ast/transform/transform.cc
@@ -74,7 +74,7 @@ ctx.Remove(block->Declaration()->statements, stmt); return; } - if (TINT_LIKELY(tint::Is<sem::ForLoopStatement>(sem->Parent()))) { + if (DAWN_LIKELY(tint::Is<sem::ForLoopStatement>(sem->Parent()))) { ctx.Replace(stmt, static_cast<Expression*>(nullptr)); return; } @@ -144,7 +144,7 @@ return ctx.dst->ty.array(el, count, std::move(attrs)); } auto count = a->ConstantCount(); - if (TINT_UNLIKELY(!count)) { + if (DAWN_UNLIKELY(!count)) { TINT_ICE() << core::type::Array::kErrExpectedConstantCount; } return ctx.dst->ty.array(el, u32(count.value()), std::move(attrs));
diff --git a/src/tint/lang/wgsl/ast/transform/vectorize_scalar_matrix_initializers.cc b/src/tint/lang/wgsl/ast/transform/vectorize_scalar_matrix_initializers.cc index f1b5a19..18e4ff7 100644 --- a/src/tint/lang/wgsl/ast/transform/vectorize_scalar_matrix_initializers.cc +++ b/src/tint/lang/wgsl/ast/transform/vectorize_scalar_matrix_initializers.cc
@@ -144,7 +144,7 @@ return b.Call(fn, ctx.Clone(args[0]->Declaration())); } - if (TINT_LIKELY(args.Length() == mat_type->Columns() * mat_type->Rows())) { + if (DAWN_LIKELY(args.Length() == mat_type->Columns() * mat_type->Rows())) { return build_mat([&](uint32_t c, uint32_t r) { return ctx.Clone(args[c * mat_type->Rows() + r]->Declaration()); });
diff --git a/src/tint/lang/wgsl/ast/transform/vertex_pulling.cc b/src/tint/lang/wgsl/ast/transform/vertex_pulling.cc index aca164d..dd4a308 100644 --- a/src/tint/lang/wgsl/ast/transform/vertex_pulling.cc +++ b/src/tint/lang/wgsl/ast/transform/vertex_pulling.cc
@@ -786,13 +786,13 @@ auto* sem = src.Sem().Get(param); info.type = sem->Type(); - if (TINT_UNLIKELY(!sem->Attributes().location.has_value())) { + if (DAWN_UNLIKELY(!sem->Attributes().location.has_value())) { TINT_ICE() << "Location missing value"; } location_info[sem->Attributes().location.value()] = info; } else { auto* builtin_attr = GetAttribute<BuiltinAttribute>(param->attributes); - if (TINT_UNLIKELY(!builtin_attr)) { + if (DAWN_UNLIKELY(!builtin_attr)) { TINT_ICE() << "Invalid entry point parameter"; } auto builtin = builtin_attr->builtin; @@ -845,7 +845,7 @@ has_locations = true; } else { auto* builtin_attr = GetAttribute<BuiltinAttribute>(member->attributes); - if (TINT_UNLIKELY(!builtin_attr)) { + if (DAWN_UNLIKELY(!builtin_attr)) { TINT_ICE() << "Invalid entry point parameter"; } auto builtin = builtin_attr->builtin;
diff --git a/src/tint/lang/wgsl/inspector/inspector.cc b/src/tint/lang/wgsl/inspector/inspector.cc index f3c68ee..efa9d37 100644 --- a/src/tint/lang/wgsl/inspector/inspector.cc +++ b/src/tint/lang/wgsl/inspector/inspector.cc
@@ -1008,7 +1008,7 @@ template <size_t N, typename F> void Inspector::GetOriginatingResources(std::array<const ast::Expression*, N> exprs, F&& callback) { - if (TINT_UNLIKELY(!program_.IsValid())) { + if (DAWN_UNLIKELY(!program_.IsValid())) { TINT_ICE() << "attempting to get originating resources in invalid program"; return; }
diff --git a/src/tint/lang/wgsl/program/program_builder.cc b/src/tint/lang/wgsl/program/program_builder.cc index 7f68f22..b8ae5ac 100644 --- a/src/tint/lang/wgsl/program/program_builder.cc +++ b/src/tint/lang/wgsl/program/program_builder.cc
@@ -73,7 +73,7 @@ } void ProgramBuilder::AssertNotMoved() const { - if (TINT_UNLIKELY(moved_)) { + if (DAWN_UNLIKELY(moved_)) { TINT_ICE() << "Attempting to use ProgramBuilder after it has been moved"; } }
diff --git a/src/tint/lang/wgsl/reader/parser/parser.cc b/src/tint/lang/wgsl/reader/parser/parser.cc index 4a5660a..df57014 100644 --- a/src/tint/lang/wgsl/reader/parser/parser.cc +++ b/src/tint/lang/wgsl/reader/parser/parser.cc
@@ -309,13 +309,13 @@ } void Parser::split_token(Token::Type lhs, Token::Type rhs) { - if (TINT_UNLIKELY(next_token_idx_ == 0)) { + if (DAWN_UNLIKELY(next_token_idx_ == 0)) { TINT_ICE() << "attempt to update placeholder at beginning of tokens"; } - if (TINT_UNLIKELY(next_token_idx_ >= tokens_.size())) { + if (DAWN_UNLIKELY(next_token_idx_ >= tokens_.size())) { TINT_ICE() << "attempt to update placeholder past end of tokens"; } - if (TINT_UNLIKELY(!tokens_[next_token_idx_].IsPlaceholder())) { + if (DAWN_UNLIKELY(!tokens_[next_token_idx_].IsPlaceholder())) { TINT_ICE() << "attempt to update non-placeholder token"; } tokens_[next_token_idx_ - 1].SetType(lhs); @@ -3466,7 +3466,7 @@ auto result = body(); --parse_depth_; - if (TINT_UNLIKELY(sync_tokens_.back() != tok)) { + if (DAWN_UNLIKELY(sync_tokens_.back() != tok)) { TINT_ICE() << "sync_tokens is out of sync"; } sync_tokens_.pop_back();
diff --git a/src/tint/lang/wgsl/reader/program_to_ir/program_to_ir.cc b/src/tint/lang/wgsl/reader/program_to_ir/program_to_ir.cc index 47644a7..ac630c6 100644 --- a/src/tint/lang/wgsl/reader/program_to_ir/program_to_ir.cc +++ b/src/tint/lang/wgsl/reader/program_to_ir/program_to_ir.cc
@@ -1004,7 +1004,7 @@ void EmitIdentifier(const ast::IdentifierExpression* i) { auto* v = impl.scopes_.Get(i->identifier->symbol); - if (TINT_UNLIKELY(!v)) { + if (DAWN_UNLIKELY(!v)) { impl.AddError(i->source) << "unable to find identifier " << i->identifier->symbol.Name(); return;
diff --git a/src/tint/lang/wgsl/reader/reader.cc b/src/tint/lang/wgsl/reader/reader.cc index a51fa32..186e1b6 100644 --- a/src/tint/lang/wgsl/reader/reader.cc +++ b/src/tint/lang/wgsl/reader/reader.cc
@@ -38,7 +38,7 @@ namespace tint::wgsl::reader { Program Parse(const Source::File* file, const Options& options) { - if (TINT_UNLIKELY(file->content.data.size() > + if (DAWN_UNLIKELY(file->content.data.size() > static_cast<size_t>(std::numeric_limits<uint32_t>::max()))) { ProgramBuilder b; b.Diagnostics().AddError(tint::Source{}) << "WGSL source must be 0xffffffff bytes or fewer";
diff --git a/src/tint/lang/wgsl/resolver/dependency_graph.cc b/src/tint/lang/wgsl/resolver/dependency_graph.cc index 97a01b3..0817005 100644 --- a/src/tint/lang/wgsl/resolver/dependency_graph.cc +++ b/src/tint/lang/wgsl/resolver/dependency_graph.cc
@@ -706,7 +706,7 @@ sorted_.Add(global->node); - if (TINT_UNLIKELY(!stack.IsEmpty())) { + if (DAWN_UNLIKELY(!stack.IsEmpty())) { // Each stack.push() must have a corresponding stack.pop_back(). TINT_ICE() << "stack not empty after returning from TraverseDependencies()"; } @@ -718,7 +718,7 @@ /// @note will raise an ICE if the edge is not found. DependencyInfo DepInfoFor(const Global* from, const Global* to) const { auto info = dependency_edges_.Get(DependencyEdge{from, to}); - if (TINT_LIKELY(info)) { + if (DAWN_LIKELY(info)) { return *info; } TINT_ICE() << "failed to find dependency info for edge: '" << NameOf(from->node) << "' -> '"
diff --git a/src/tint/lang/wgsl/resolver/resolver.cc b/src/tint/lang/wgsl/resolver/resolver.cc index 8903fe0..8fcc5ca 100644 --- a/src/tint/lang/wgsl/resolver/resolver.cc +++ b/src/tint/lang/wgsl/resolver/resolver.cc
@@ -168,7 +168,7 @@ bool result = ResolveInternal(); - if (TINT_UNLIKELY(!result && !diagnostics_.ContainsErrors())) { + if (DAWN_UNLIKELY(!result && !diagnostics_.ContainsErrors())) { TINT_ICE() << "resolving failed, but no error was raised"; } @@ -238,7 +238,7 @@ bool result = true; for (auto* node : b.ASTNodes().Objects()) { - if (TINT_UNLIKELY(!marked_[node->node_id.value])) { + if (DAWN_UNLIKELY(!marked_[node->node_id.value])) { ICE(node->source) << "AST node '" << node->TypeInfo().name << "' was not reached by the resolver\n" << "Pointer: " << node; @@ -268,7 +268,7 @@ // If the variable has a declared type, resolve it. if (v->type) { auto* ty = Type(v->type); - if (TINT_UNLIKELY(!ty)) { + if (DAWN_UNLIKELY(!ty)) { return nullptr; } sem->SetType(ty); @@ -289,13 +289,13 @@ } } - if (TINT_UNLIKELY(!v->initializer)) { + if (DAWN_UNLIKELY(!v->initializer)) { AddError(v->source) << style::Keyword("let") << " declaration must have an initializer"; return nullptr; } auto* rhs = Load(Materialize(ValueExpression(v->initializer), sem->Type())); - if (TINT_UNLIKELY(!rhs)) { + if (DAWN_UNLIKELY(!rhs)) { return nullptr; } sem->SetInitializer(rhs); @@ -305,7 +305,7 @@ sem->SetType(rhs->Type()->UnwrapRef()); // Implicit load of RHS } - if (TINT_UNLIKELY(rhs && !validator_.VariableInitializer(v, sem->Type(), rhs))) { + if (DAWN_UNLIKELY(rhs && !validator_.VariableInitializer(v, sem->Type(), rhs))) { return nullptr; } @@ -349,7 +349,7 @@ "override initializer"}; TINT_SCOPED_ASSIGNMENT(expr_eval_stage_constraint_, constraint); init = Materialize(ValueExpression(v->initializer), ty); - if (TINT_UNLIKELY(!init)) { + if (DAWN_UNLIKELY(!init)) { return nullptr; } sem->SetInitializer(init); @@ -453,7 +453,7 @@ } } - if (TINT_UNLIKELY(!c->initializer)) { + if (DAWN_UNLIKELY(!c->initializer)) { AddError(c->source) << "'const' declaration must have an initializer"; return nullptr; } @@ -461,7 +461,7 @@ ExprEvalStageConstraint constraint{core::EvaluationStage::kConstant, "const initializer"}; TINT_SCOPED_ASSIGNMENT(expr_eval_stage_constraint_, constraint); const auto* init = ValueExpression(c->initializer); - if (TINT_UNLIKELY(!init)) { + if (DAWN_UNLIKELY(!init)) { return nullptr; } @@ -472,7 +472,7 @@ const core::type::Type* ty = nullptr; if (c->type) { ty = Type(c->type); - if (TINT_UNLIKELY(!ty)) { + if (DAWN_UNLIKELY(!ty)) { return nullptr; } } @@ -480,7 +480,7 @@ if (ty) { // If an explicit type was specified, materialize to that type init = Materialize(init, ty); - if (TINT_UNLIKELY(!init)) { + if (DAWN_UNLIKELY(!init)) { return nullptr; } } else { @@ -535,7 +535,7 @@ const core::type::Type* storage_ty = nullptr; if (auto ty = var->type) { storage_ty = Type(ty); - if (TINT_UNLIKELY(!storage_ty)) { + if (DAWN_UNLIKELY(!storage_ty)) { return nullptr; } } @@ -549,7 +549,7 @@ TINT_SCOPED_ASSIGNMENT(expr_eval_stage_constraint_, constraint); auto* init = Load(Materialize(ValueExpression(var->initializer), storage_ty)); - if (TINT_UNLIKELY(!init)) { + if (DAWN_UNLIKELY(!init)) { return nullptr; } sem->SetInitializer(init); @@ -567,7 +567,7 @@ if (var->declared_address_space) { auto space = AddressSpaceExpression(var->declared_address_space); - if (TINT_UNLIKELY(!space)) { + if (DAWN_UNLIKELY(!space)) { return nullptr; } sem->SetAddressSpace(space->Value()); @@ -767,7 +767,7 @@ attribute, // [&](const ast::LocationAttribute* attr) { auto value = LocationAttribute(attr); - if (TINT_UNLIKELY(value != Success)) { + if (DAWN_UNLIKELY(value != Success)) { return false; } sem->Attributes().location = value.Get(); @@ -775,7 +775,7 @@ }, [&](const ast::ColorAttribute* attr) { auto value = ColorAttribute(attr); - if (TINT_UNLIKELY(value != Success)) { + if (DAWN_UNLIKELY(value != Success)) { return false; } sem->Attributes().color = value.Get(); @@ -794,7 +794,7 @@ return false; } auto value = GroupAttribute(attr); - if (TINT_UNLIKELY(value != Success)) { + if (DAWN_UNLIKELY(value != Success)) { return false; } group = value.Get(); @@ -807,7 +807,7 @@ return false; } auto value = BindingAttribute(attr); - if (TINT_UNLIKELY(value != Success)) { + if (DAWN_UNLIKELY(value != Success)) { return false; } binding = value.Get(); @@ -851,7 +851,7 @@ } core::type::Type* ty = Type(param->type); - if (TINT_UNLIKELY(!ty)) { + if (DAWN_UNLIKELY(!ty)) { return nullptr; } sem->SetType(ty); @@ -943,7 +943,7 @@ void Resolver::SetShadows() { for (auto& it : dependencies_.shadows) { CastableBase* shadowed = sem_.Get(it.value); - if (TINT_UNLIKELY(!shadowed)) { + if (DAWN_UNLIKELY(!shadowed)) { ICE(it.value->source) << "AST node '" << it.value->TypeInfo().name << "' had no semantic info\n" << "Pointer: " << it.value; @@ -1199,7 +1199,7 @@ if (decl->body) { Mark(decl->body); - if (TINT_UNLIKELY(current_compound_statement_)) { + if (DAWN_UNLIKELY(current_compound_statement_)) { ICE(decl->body->source) << "Resolver::Function() called with a current compound statement"; } @@ -1631,12 +1631,12 @@ TINT_DEFER(on_transitively_reference_global_.Pop()); auto* type_expr = TypeExpression(ast); - if (TINT_UNLIKELY(!type_expr)) { + if (DAWN_UNLIKELY(!type_expr)) { return nullptr; } auto* type = const_cast<core::type::Type*>(type_expr->Type()); - if (TINT_UNLIKELY(!type)) { + if (DAWN_UNLIKELY(!type)) { return nullptr; } @@ -1652,10 +1652,10 @@ sem::BuiltinEnumExpression<core::AddressSpace>* Resolver::AddressSpaceExpression( const ast::Expression* expr) { auto address_space_expr = sem_.AsAddressSpace(Expression(expr)); - if (TINT_UNLIKELY(!address_space_expr)) { + if (DAWN_UNLIKELY(!address_space_expr)) { return nullptr; } - if (TINT_UNLIKELY( + if (DAWN_UNLIKELY( address_space_expr->Value() == core::AddressSpace::kPixelLocal && !enabled_extensions_.Contains(wgsl::Extension::kChromiumExperimentalPixelLocal))) { AddError(expr->source) << "'pixel_local' address space requires the '" @@ -1896,7 +1896,7 @@ const core::constant::Value* materialized_val = nullptr; if (!not_evaluated_.Contains(decl)) { auto expr_val = expr->ConstantValue(); - if (TINT_UNLIKELY(!expr_val)) { + if (DAWN_UNLIKELY(!expr_val)) { ICE(decl->source) << "Materialize(" << decl->TypeInfo().name << ") called on expression with no constant value"; } @@ -1907,7 +1907,7 @@ return nullptr; } materialized_val = val.Get(); - if (TINT_UNLIKELY(!materialized_val)) { + if (DAWN_UNLIKELY(!materialized_val)) { ICE(decl->source) << "ConvertValue(" << expr_val->Type()->FriendlyName() << " -> " << concrete_ty->FriendlyName() << ") returned invalid value"; } @@ -2075,7 +2075,7 @@ // * A value constructor. // * A value conversion. auto* target = sem_.Get(expr->target); - if (TINT_UNLIKELY(!target)) { + if (DAWN_UNLIKELY(!target)) { return nullptr; } @@ -2229,11 +2229,11 @@ return b.create<sem::ValueConstructor>(arr, std::move(params), args_stage); }); - if (TINT_UNLIKELY(!MaybeMaterializeAndLoadArguments(args, call_target))) { + if (DAWN_UNLIKELY(!MaybeMaterializeAndLoadArguments(args, call_target))) { return nullptr; } - if (TINT_UNLIKELY(!validator_.ArrayConstructor(expr, arr))) { + if (DAWN_UNLIKELY(!validator_.ArrayConstructor(expr, arr))) { return nullptr; } @@ -2254,11 +2254,11 @@ return b.create<sem::ValueConstructor>(str, std::move(params), args_stage); }); - if (TINT_UNLIKELY(!MaybeMaterializeAndLoadArguments(args, call_target))) { + if (DAWN_UNLIKELY(!MaybeMaterializeAndLoadArguments(args, call_target))) { return nullptr; } - if (TINT_UNLIKELY(!validator_.StructureInitializer(expr, str))) { + if (DAWN_UNLIKELY(!validator_.StructureInitializer(expr, str))) { return nullptr; } @@ -2304,7 +2304,7 @@ auto arg_tys = tint::Transform(args, [](auto* arg) { return arg->Type()->UnwrapRef(); }); auto el_ty = core::type::Type::Common(arg_tys); - if (TINT_UNLIKELY(!el_ty)) { + if (DAWN_UNLIKELY(!el_ty)) { AddError(expr->source) << "cannot infer common array element type from constructor arguments"; Hashset<const core::type::Type*, 8> types; @@ -2319,7 +2319,7 @@ } auto* arr = Array(expr->source, expr->source, expr->source, el_ty, el_count, /* explicit_stride */ 0); - if (TINT_UNLIKELY(!arr)) { + if (DAWN_UNLIKELY(!arr)) { return nullptr; } return ty_init_or_conv(arr); @@ -2341,7 +2341,7 @@ ty_expr->Type(), // [&](const IncompleteType* t) -> sem::Call* { auto* ctor = incomplete_type(t); - if (TINT_UNLIKELY(!ctor)) { + if (DAWN_UNLIKELY(!ctor)) { return nullptr; } // Replace incomplete type with resolved type @@ -2378,7 +2378,7 @@ if (auto* tmpl = expr->target->identifier->As<ast::TemplatedIdentifier>()) { for (auto* arg : tmpl->arguments) { auto* arg_ty = sem_.AsTypeExpression(sem_.Get(arg)); - if (TINT_UNLIKELY(!arg_ty)) { + if (DAWN_UNLIKELY(!arg_ty)) { return nullptr; } tmpl_args.Push(arg_ty->Type()); @@ -2597,7 +2597,7 @@ core::type::Type* Resolver::BuiltinType(core::BuiltinType builtin_ty, const ast::Identifier* ident) { auto check_no_tmpl_args = [&](core::type::Type* ty) -> core::type::Type* { - return TINT_LIKELY(CheckNotTemplated("type", ident)) ? ty : nullptr; + return DAWN_LIKELY(CheckNotTemplated("type", ident)) ? ty : nullptr; }; switch (builtin_ty) { @@ -2830,10 +2830,10 @@ } core::type::Vector* Resolver::Vec(const ast::Identifier* ident, core::type::Type* el, uint32_t n) { - if (TINT_UNLIKELY(!el)) { + if (DAWN_UNLIKELY(!el)) { return nullptr; } - if (TINT_UNLIKELY(!validator_.Vector(el, ident->source))) { + if (DAWN_UNLIKELY(!validator_.Vector(el, ident->source))) { return nullptr; } return b.create<core::type::Vector>(el, n); @@ -2848,12 +2848,12 @@ return b.create<IncompleteType>(builtin); } - if (TINT_UNLIKELY(!CheckTemplatedIdentifierArgs(tmpl_ident, 1))) { + if (DAWN_UNLIKELY(!CheckTemplatedIdentifierArgs(tmpl_ident, 1))) { return nullptr; } auto* ty = sem_.GetType(tmpl_ident->arguments[0]); - if (TINT_UNLIKELY(!ty)) { + if (DAWN_UNLIKELY(!ty)) { return nullptr; } @@ -2864,10 +2864,10 @@ core::type::Type* el, uint32_t num_columns, uint32_t num_rows) { - if (TINT_UNLIKELY(!el)) { + if (DAWN_UNLIKELY(!el)) { return nullptr; } - if (TINT_UNLIKELY(!validator_.Matrix(el, ident->source))) { + if (DAWN_UNLIKELY(!validator_.Matrix(el, ident->source))) { return nullptr; } auto* column = Vec(ident, el, num_rows); @@ -2887,12 +2887,12 @@ return b.create<IncompleteType>(builtin); } - if (TINT_UNLIKELY(!CheckTemplatedIdentifierArgs(tmpl_ident, 1))) { + if (DAWN_UNLIKELY(!CheckTemplatedIdentifierArgs(tmpl_ident, 1))) { return nullptr; } auto* el_ty = sem_.GetType(tmpl_ident->arguments[0]); - if (TINT_UNLIKELY(!el_ty)) { + if (DAWN_UNLIKELY(!el_ty)) { return nullptr; } @@ -2906,7 +2906,7 @@ return b.create<IncompleteType>(core::BuiltinType::kArray); } - if (TINT_UNLIKELY(!CheckTemplatedIdentifierArgs(tmpl_ident, 1, 2))) { + if (DAWN_UNLIKELY(!CheckTemplatedIdentifierArgs(tmpl_ident, 1, 2))) { return nullptr; } auto* ast_el_ty = tmpl_ident->arguments[0]; @@ -2950,17 +2950,17 @@ core::type::Atomic* Resolver::Atomic(const ast::Identifier* ident) { auto* tmpl_ident = TemplatedIdentifier(ident, 1); // atomic<type> - if (TINT_UNLIKELY(!tmpl_ident)) { + if (DAWN_UNLIKELY(!tmpl_ident)) { return nullptr; } auto* el_ty = sem_.GetType(tmpl_ident->arguments[0]); - if (TINT_UNLIKELY(!el_ty)) { + if (DAWN_UNLIKELY(!el_ty)) { return nullptr; } auto* out = b.create<core::type::Atomic>(el_ty); - if (TINT_UNLIKELY(!validator_.Atomic(tmpl_ident, out))) { + if (DAWN_UNLIKELY(!validator_.Atomic(tmpl_ident, out))) { return nullptr; } return out; @@ -2968,24 +2968,24 @@ core::type::Pointer* Resolver::Ptr(const ast::Identifier* ident) { auto* tmpl_ident = TemplatedIdentifier(ident, 2, 3); // ptr<address, type [, access]> - if (TINT_UNLIKELY(!tmpl_ident)) { + if (DAWN_UNLIKELY(!tmpl_ident)) { return nullptr; } auto address_space = sem_.GetAddressSpace(tmpl_ident->arguments[0]); - if (TINT_UNLIKELY(address_space == core::AddressSpace::kUndefined)) { + if (DAWN_UNLIKELY(address_space == core::AddressSpace::kUndefined)) { return nullptr; } auto* store_ty = const_cast<core::type::Type*>(sem_.GetType(tmpl_ident->arguments[1])); - if (TINT_UNLIKELY(!store_ty)) { + if (DAWN_UNLIKELY(!store_ty)) { return nullptr; } core::Access access = core::Access::kUndefined; if (tmpl_ident->arguments.Length() > 2) { access = sem_.GetAccess(tmpl_ident->arguments[2]); - if (TINT_UNLIKELY(access == core::Access::kUndefined)) { + if (DAWN_UNLIKELY(access == core::Access::kUndefined)) { return nullptr; } } else { @@ -2993,7 +2993,7 @@ } auto* out = b.create<core::type::Pointer>(address_space, store_ty, access); - if (TINT_UNLIKELY(!validator_.Pointer(tmpl_ident, out))) { + if (DAWN_UNLIKELY(!validator_.Pointer(tmpl_ident, out))) { return nullptr; } @@ -3007,12 +3007,12 @@ core::type::SampledTexture* Resolver::SampledTexture(const ast::Identifier* ident, core::type::TextureDimension dim) { auto* tmpl_ident = TemplatedIdentifier(ident, 1); - if (TINT_UNLIKELY(!tmpl_ident)) { + if (DAWN_UNLIKELY(!tmpl_ident)) { return nullptr; } auto* ty_expr = sem_.GetType(tmpl_ident->arguments[0]); - if (TINT_UNLIKELY(!ty_expr)) { + if (DAWN_UNLIKELY(!ty_expr)) { return nullptr; } @@ -3023,12 +3023,12 @@ core::type::MultisampledTexture* Resolver::MultisampledTexture(const ast::Identifier* ident, core::type::TextureDimension dim) { auto* tmpl_ident = TemplatedIdentifier(ident, 1); - if (TINT_UNLIKELY(!tmpl_ident)) { + if (DAWN_UNLIKELY(!tmpl_ident)) { return nullptr; } auto* ty_expr = sem_.GetType(tmpl_ident->arguments[0]); - if (TINT_UNLIKELY(!ty_expr)) { + if (DAWN_UNLIKELY(!ty_expr)) { return nullptr; } @@ -3039,17 +3039,17 @@ core::type::StorageTexture* Resolver::StorageTexture(const ast::Identifier* ident, core::type::TextureDimension dim) { auto* tmpl_ident = TemplatedIdentifier(ident, 2); - if (TINT_UNLIKELY(!tmpl_ident)) { + if (DAWN_UNLIKELY(!tmpl_ident)) { return nullptr; } auto format = sem_.GetTexelFormat(tmpl_ident->arguments[0]); - if (TINT_UNLIKELY(format == core::TexelFormat::kUndefined)) { + if (DAWN_UNLIKELY(format == core::TexelFormat::kUndefined)) { return nullptr; } auto access = sem_.GetAccess(tmpl_ident->arguments[1]); - if (TINT_UNLIKELY(access == core::Access::kUndefined)) { + if (DAWN_UNLIKELY(access == core::Access::kUndefined)) { return nullptr; } @@ -3064,12 +3064,12 @@ core::type::InputAttachment* Resolver::InputAttachment(const ast::Identifier* ident) { auto* tmpl_ident = TemplatedIdentifier(ident, 1); - if (TINT_UNLIKELY(!tmpl_ident)) { + if (DAWN_UNLIKELY(!tmpl_ident)) { return nullptr; } auto* ty_expr = sem_.GetType(tmpl_ident->arguments[0]); - if (TINT_UNLIKELY(!ty_expr)) { + if (DAWN_UNLIKELY(!ty_expr)) { return nullptr; } @@ -3079,16 +3079,16 @@ core::type::Vector* Resolver::PackedVec3T(const ast::Identifier* ident) { auto* tmpl_ident = TemplatedIdentifier(ident, 1); - if (TINT_UNLIKELY(!tmpl_ident)) { + if (DAWN_UNLIKELY(!tmpl_ident)) { return nullptr; } auto* el_ty = sem_.GetType(tmpl_ident->arguments[0]); - if (TINT_UNLIKELY(!el_ty)) { + if (DAWN_UNLIKELY(!el_ty)) { return nullptr; } - if (TINT_UNLIKELY(!validator_.Vector(el_ty, ident->source))) { + if (DAWN_UNLIKELY(!validator_.Vector(el_ty, ident->source))) { return nullptr; } return b.create<core::type::Vector>(el_ty, 3u, true); @@ -3099,7 +3099,7 @@ size_t max_args /* = use min 0 */) { auto* tmpl_ident = ident->As<ast::TemplatedIdentifier>(); if (!tmpl_ident) { - if (TINT_UNLIKELY(min_args != 0)) { + if (DAWN_UNLIKELY(min_args != 0)) { AddError(Source{ident->source.range.end}) << "expected " << style::Code("<") << " for " << style::Code(ident->symbol.NameView()); } @@ -3115,18 +3115,18 @@ max_args = min_args; } if (min_args == max_args) { - if (TINT_UNLIKELY(ident->arguments.Length() != min_args)) { + if (DAWN_UNLIKELY(ident->arguments.Length() != min_args)) { AddError(ident->source) << style::Code(ident->symbol.NameView()) << " requires " << min_args << " template arguments"; return false; } } else { - if (TINT_UNLIKELY(ident->arguments.Length() < min_args)) { + if (DAWN_UNLIKELY(ident->arguments.Length() < min_args)) { AddError(ident->source) << style::Code(ident->symbol.NameView()) << " requires at least " << min_args << " template arguments"; return false; } - if (TINT_UNLIKELY(ident->arguments.Length() > max_args)) { + if (DAWN_UNLIKELY(ident->arguments.Length() > max_args)) { AddError(ident->source) << style::Code(ident->symbol.NameView()) << " requires at most " << max_args << " template arguments"; return false; @@ -3159,7 +3159,7 @@ // Collect a texture/sampler pair for this builtin. const auto& signature = builtin->Signature(); int texture_index = signature.IndexOf(core::ParameterUsage::kTexture); - if (TINT_UNLIKELY(texture_index == -1)) { + if (DAWN_UNLIKELY(texture_index == -1)) { TINT_ICE() << "texture builtin without texture parameter"; } if (auto* user = @@ -3335,7 +3335,7 @@ return Switch( resolved_node, // [&](sem::Variable* variable) -> sem::VariableUser* { - if (!TINT_LIKELY(CheckNotTemplated("variable", ident))) { + if (!DAWN_LIKELY(CheckNotTemplated("variable", ident))) { return nullptr; } @@ -3402,7 +3402,7 @@ }, [&](const core::type::Type* ty) -> sem::TypeExpression* { // User declared types cannot be templated. - if (!TINT_LIKELY(CheckNotTemplated("type", ident))) { + if (!DAWN_LIKELY(CheckNotTemplated("type", ident))) { return nullptr; } @@ -3418,7 +3418,7 @@ return b.create<sem::TypeExpression>(expr, current_statement_, ty); }, [&](const sem::Function* fn) -> sem::FunctionExpression* { - if (!TINT_LIKELY(CheckNotTemplated("function", ident))) { + if (!DAWN_LIKELY(CheckNotTemplated("function", ident))) { return nullptr; } return b.create<sem::FunctionExpression>(expr, current_statement_, fn); @@ -4299,10 +4299,10 @@ core::type::Type* Resolver::Alias(const ast::Alias* alias) { auto* ty = Type(alias->type); - if (TINT_UNLIKELY(!ty)) { + if (DAWN_UNLIKELY(!ty)) { return nullptr; } - if (TINT_UNLIKELY(!validator_.Alias(alias))) { + if (DAWN_UNLIKELY(!validator_.Alias(alias))) { return nullptr; } return ty; @@ -4590,7 +4590,7 @@ << ") must not exceed 0xffffffff bytes"; return nullptr; } - if (TINT_UNLIKELY(struct_align > std::numeric_limits<uint32_t>::max())) { + if (DAWN_UNLIKELY(struct_align > std::numeric_limits<uint32_t>::max())) { ICE(str->source) << "calculated struct stride exceeds uint32"; } @@ -5054,11 +5054,11 @@ } bool Resolver::Mark(const ast::Node* node) { - if (TINT_UNLIKELY(node == nullptr)) { + if (DAWN_UNLIKELY(node == nullptr)) { TINT_ICE() << "Resolver::Mark() called with nullptr"; } auto marked_bit_ref = marked_[node->node_id.value]; - if (TINT_LIKELY(!marked_bit_ref)) { + if (DAWN_LIKELY(!marked_bit_ref)) { marked_bit_ref = true; return true; } @@ -5075,7 +5075,7 @@ } bool Resolver::CheckNotTemplated(const char* use, const ast::Identifier* ident) { - if (TINT_UNLIKELY(ident->Is<ast::TemplatedIdentifier>())) { + if (DAWN_UNLIKELY(ident->Is<ast::TemplatedIdentifier>())) { AddError(ident->source) << use << " " << style::Code(ident->symbol.NameView()) << " does not take template arguments"; if (auto resolved = dependencies_.resolved_identifiers.Get(ident)) {
diff --git a/src/tint/lang/wgsl/resolver/sem_helper.cc b/src/tint/lang/wgsl/resolver/sem_helper.cc index 4d8bd9a..81d16e5 100644 --- a/src/tint/lang/wgsl/resolver/sem_helper.cc +++ b/src/tint/lang/wgsl/resolver/sem_helper.cc
@@ -58,18 +58,18 @@ } sem::TypeExpression* SemHelper::AsTypeExpression(sem::Expression* expr) const { - if (TINT_UNLIKELY(!expr)) { + if (DAWN_UNLIKELY(!expr)) { return nullptr; } auto* ty_expr = expr->As<sem::TypeExpression>(); - if (TINT_UNLIKELY(!ty_expr)) { + if (DAWN_UNLIKELY(!ty_expr)) { ErrorUnexpectedExprKind(expr, "type"); return nullptr; } auto* type = ty_expr->Type(); - if (auto* incomplete = type->As<IncompleteType>(); TINT_UNLIKELY(incomplete)) { + if (auto* incomplete = type->As<IncompleteType>(); DAWN_UNLIKELY(incomplete)) { AddError(expr->Declaration()->source.End()) << "expected " << style::Code("<") << " for " << style::Type(incomplete->builtin); return nullptr;
diff --git a/src/tint/lang/wgsl/resolver/sem_helper.h b/src/tint/lang/wgsl/resolver/sem_helper.h index f79eefa..d48fdf7 100644 --- a/src/tint/lang/wgsl/resolver/sem_helper.h +++ b/src/tint/lang/wgsl/resolver/sem_helper.h
@@ -59,7 +59,7 @@ auto* Get(const AST* ast) const { using T = sem::Info::GetResultType<SEM, AST>; auto* sem = builder_->Sem().Get(ast); - if (TINT_UNLIKELY(!sem)) { + if (DAWN_UNLIKELY(!sem)) { TINT_ICE() << "AST node '" << ast->TypeInfo().name << "' had no semantic info\n" << "At: " << ast->source << "\n" << "Pointer: " << ast; @@ -81,8 +81,8 @@ /// @returns nullptr if @p expr is nullptr, or @p expr cast to sem::ValueExpression if the cast /// is successful, otherwise an error diagnostic is raised. sem::ValueExpression* AsValueExpression(sem::Expression* expr) const { - if (TINT_LIKELY(expr)) { - if (auto* val_expr = expr->As<sem::ValueExpression>(); TINT_LIKELY(val_expr)) { + if (DAWN_LIKELY(expr)) { + if (auto* val_expr = expr->As<sem::ValueExpression>(); DAWN_LIKELY(val_expr)) { return val_expr; } ErrorExpectedValueExpr(expr); @@ -102,7 +102,7 @@ /// @returns the sem node for @p ast const core::type::Type* GetType(const ast::Expression* ast) const { auto* expr = AsTypeExpression(Get(ast)); - if (TINT_LIKELY(expr)) { + if (DAWN_LIKELY(expr)) { return expr->Type(); } return nullptr; @@ -112,9 +112,9 @@ /// @returns nullptr if @p expr is nullptr, or @p expr cast to sem::Function if the cast is /// successful, otherwise an error diagnostic is raised. sem::FunctionExpression* AsFunctionExpression(sem::Expression* expr) const { - if (TINT_LIKELY(expr)) { + if (DAWN_LIKELY(expr)) { auto* fn_expr = expr->As<sem::FunctionExpression>(); - if (TINT_LIKELY(fn_expr)) { + if (DAWN_LIKELY(fn_expr)) { return fn_expr; } ErrorUnexpectedExprKind(expr, "function"); @@ -127,9 +127,9 @@ /// sem::BuiltinEnumExpression<core::AddressSpace> if the cast is successful, otherwise an /// error diagnostic is raised. sem::BuiltinEnumExpression<core::AddressSpace>* AsAddressSpace(sem::Expression* expr) const { - if (TINT_LIKELY(expr)) { + if (DAWN_LIKELY(expr)) { auto* enum_expr = expr->As<sem::BuiltinEnumExpression<core::AddressSpace>>(); - if (TINT_LIKELY(enum_expr)) { + if (DAWN_LIKELY(enum_expr)) { return enum_expr; } ErrorUnexpectedExprKind(expr, "address space", core::kAddressSpaceStrings); @@ -144,7 +144,7 @@ /// @returns the sem node for @p ast core::AddressSpace GetAddressSpace(const ast::Expression* ast) const { auto* expr = AsAddressSpace(Get(ast)); - if (TINT_LIKELY(expr)) { + if (DAWN_LIKELY(expr)) { return expr->Value(); } return core::AddressSpace::kUndefined; @@ -155,9 +155,9 @@ /// sem::BuiltinEnumExpression<core::type::TexelFormat> if the cast is successful, otherwise an /// error diagnostic is raised. sem::BuiltinEnumExpression<core::TexelFormat>* AsTexelFormat(sem::Expression* expr) const { - if (TINT_LIKELY(expr)) { + if (DAWN_LIKELY(expr)) { auto* enum_expr = expr->As<sem::BuiltinEnumExpression<core::TexelFormat>>(); - if (TINT_LIKELY(enum_expr)) { + if (DAWN_LIKELY(enum_expr)) { return enum_expr; } ErrorUnexpectedExprKind(expr, "texel format", core::kTexelFormatStrings); @@ -172,7 +172,7 @@ /// @returns the sem node for @p ast core::TexelFormat GetTexelFormat(const ast::Expression* ast) const { auto* expr = AsTexelFormat(Get(ast)); - if (TINT_LIKELY(expr)) { + if (DAWN_LIKELY(expr)) { return expr->Value(); } return core::TexelFormat::kUndefined; @@ -183,9 +183,9 @@ /// sem::BuiltinEnumExpression<core::Access> if the cast is successful, otherwise an error /// diagnostic is raised. sem::BuiltinEnumExpression<core::Access>* AsAccess(sem::Expression* expr) const { - if (TINT_LIKELY(expr)) { + if (DAWN_LIKELY(expr)) { auto* enum_expr = expr->As<sem::BuiltinEnumExpression<core::Access>>(); - if (TINT_LIKELY(enum_expr)) { + if (DAWN_LIKELY(enum_expr)) { return enum_expr; } ErrorUnexpectedExprKind(expr, "access", core::kAccessStrings); @@ -200,7 +200,7 @@ /// @returns the sem node for @p ast core::Access GetAccess(const ast::Expression* ast) const { auto* expr = AsAccess(Get(ast)); - if (TINT_LIKELY(expr)) { + if (DAWN_LIKELY(expr)) { return expr->Value(); } return core::Access::kUndefined;
diff --git a/src/tint/lang/wgsl/resolver/validator.cc b/src/tint/lang/wgsl/resolver/validator.cc index 9056664..5745ee6 100644 --- a/src/tint/lang/wgsl/resolver/validator.cc +++ b/src/tint/lang/wgsl/resolver/validator.cc
@@ -430,7 +430,7 @@ return false; } - if (TINT_UNLIKELY(t->TexelFormat() == core::TexelFormat::kR8Unorm && + if (DAWN_UNLIKELY(t->TexelFormat() == core::TexelFormat::kR8Unorm && !enabled_extensions_.Contains(wgsl::Extension::kChromiumInternalGraphite))) { AddError(source) << style::Enum(core::TexelFormat::kR8Unorm) << " requires the " << style::Code(wgsl::Extension::kChromiumInternalGraphite) << " extension"; @@ -1173,7 +1173,7 @@ auto i_type = attr->interpolation.type; auto i_sampling = attr->interpolation.sampling; - if (TINT_UNLIKELY(i_type == core::InterpolationType::kUndefined)) { + if (DAWN_UNLIKELY(i_type == core::InterpolationType::kUndefined)) { return false; } @@ -1293,7 +1293,7 @@ AddError(end_source) << "missing return at end of function"; return false; } - } else if (TINT_UNLIKELY(IsValidationEnabled( + } else if (DAWN_UNLIKELY(IsValidationEnabled( decl->attributes, ast::DisabledValidation::kFunctionHasNoBody))) { TINT_ICE() << "function " << decl->name->symbol.NameView() << " has no body"; } @@ -1307,7 +1307,7 @@ // https://www.w3.org/TR/WGSL/#behaviors-rules // a function behavior is always one of {}, or {Next}. - if (TINT_UNLIKELY(func->Behaviors() != sem::Behaviors{} && + if (DAWN_UNLIKELY(func->Behaviors() != sem::Behaviors{} && func->Behaviors() != sem::Behavior::kNext)) { auto name = decl->name->symbol.NameView(); TINT_ICE() << "function '" << name << "' behaviors are: " << func->Behaviors(); @@ -1393,7 +1393,7 @@ } pipeline_io_attribute = attr; - if (TINT_UNLIKELY(!location.has_value())) { + if (DAWN_UNLIKELY(!location.has_value())) { TINT_ICE() << "@location has no value"; } @@ -1402,7 +1402,7 @@ [&](const ast::BlendSrcAttribute* blend_src_attr) { blend_src_attribute = blend_src_attr; - if (TINT_UNLIKELY(!blend_src.has_value())) { + if (DAWN_UNLIKELY(!blend_src.has_value())) { TINT_ICE() << "@blend_src has no value"; } @@ -1422,7 +1422,7 @@ bool is_input = param_or_ret == ParamOrRetType::kParameter; - if (TINT_UNLIKELY(!color.has_value())) { + if (DAWN_UNLIKELY(!color.has_value())) { TINT_ICE() << "@color has no value"; } @@ -2266,7 +2266,7 @@ return false; } - if (TINT_UNLIKELY(!c->Is<core::type::ConstantArrayCount>())) { + if (DAWN_UNLIKELY(!c->Is<core::type::ConstantArrayCount>())) { TINT_ICE() << "Invalid ArrayCount found"; } @@ -3072,7 +3072,7 @@ if (auto* str = store_ty->As<sem::Struct>()) { for (auto* member : str->Members()) { using Allowed = std::tuple<core::type::I32, core::type::U32, core::type::F32>; - if (TINT_UNLIKELY(!member->Type()->TypeInfo().IsAnyOfTuple<Allowed>())) { + if (DAWN_UNLIKELY(!member->Type()->TypeInfo().IsAnyOfTuple<Allowed>())) { AddError(member->Declaration()->source) << style::Keyword("struct") << " members used in the " << style::Enum("pixel_local") @@ -3084,14 +3084,14 @@ return false; } } - } else if (TINT_UNLIKELY(!store_ty->TypeInfo().Is<core::type::Struct>())) { + } else if (DAWN_UNLIKELY(!store_ty->TypeInfo().Is<core::type::Struct>())) { AddError(source) << style::Enum("pixel_local") << " variable only support struct storage types"; return false; } break; case core::AddressSpace::kPushConstant: - if (TINT_UNLIKELY(!enabled_extensions_.Contains( + if (DAWN_UNLIKELY(!enabled_extensions_.Contains( wgsl::Extension::kChromiumExperimentalPushConstant) && IsValidationEnabled(attributes, ast::DisabledValidation::kIgnoreAddressSpace))) { @@ -3102,7 +3102,7 @@ } break; case core::AddressSpace::kStorage: - if (TINT_UNLIKELY(access == core::Access::kWrite)) { + if (DAWN_UNLIKELY(access == core::Access::kWrite)) { // The access mode for the storage address space can only be 'read' or 'read_write'. AddError(source) << "access mode " << style::Enum("write") << " is not valid for the " << style::Enum("storage") @@ -3134,7 +3134,7 @@ auto check_sub_atomics = [&] { if (auto atomic_use = atomic_composite_info_.Get(store_ty)) { - if (TINT_UNLIKELY(atomic_error())) { + if (DAWN_UNLIKELY(atomic_error())) { AddNote(**atomic_use) << "atomic sub-type of " << style::Type(sem_.TypeNameOf(store_ty)) << " is declared here"; @@ -3147,7 +3147,7 @@ return Switch( store_ty, // [&](const core::type::Atomic*) { - if (TINT_UNLIKELY(atomic_error())) { + if (DAWN_UNLIKELY(atomic_error())) { return false; } return true;
diff --git a/src/tint/lang/wgsl/writer/ir_to_program/ir_to_program.cc b/src/tint/lang/wgsl/writer/ir_to_program/ir_to_program.cc index a10c5f5..95914e3 100644 --- a/src/tint/lang/wgsl/writer/ir_to_program/ir_to_program.cc +++ b/src/tint/lang/wgsl/writer/ir_to_program/ir_to_program.cc
@@ -767,7 +767,7 @@ auto* vec = Expr(s->Object()); Vector<char, 4> components; for (uint32_t i : s->Indices()) { - if (TINT_UNLIKELY(i >= 4)) { + if (DAWN_UNLIKELY(i >= 4)) { TINT_ICE() << "invalid swizzle index: " << i; } components.Push("xyzw"[i]); @@ -857,7 +857,7 @@ [&](const core::ir::Constant* c) { return Constant(c); }, [&](Default) -> const ast::Expression* { auto lookup = bindings_.Get(value); - if (TINT_UNLIKELY(!lookup)) { + if (DAWN_UNLIKELY(!lookup)) { TINT_ICE() << "Expr(" << (value ? value->TypeInfo().name : "null") << ") value has no expression"; } @@ -991,7 +991,7 @@ return b.ty.array(el, std::move(attrs)); } auto count = a->ConstantCount(); - if (TINT_UNLIKELY(!count)) { + if (DAWN_UNLIKELY(!count)) { TINT_ICE() << core::type::Array::kErrExpectedConstantCount; } return b.ty.array(el, u32(count.value()), std::move(attrs)); @@ -1121,7 +1121,7 @@ TINT_ASSERT(value); if (value->IsUsed()) { // Value will be inlined at its place of usage. - if (TINT_UNLIKELY(!bindings_.Add(value, InlinedValue{expr}))) { + if (DAWN_UNLIKELY(!bindings_.Add(value, InlinedValue{expr}))) { TINT_ICE() << "Bind(" << value->TypeInfo().name << ") called twice for same value"; } } else { @@ -1133,7 +1133,7 @@ /// name. void Bind(const core::ir::Value* value, Symbol name) { TINT_ASSERT(value); - if (TINT_UNLIKELY(!bindings_.Add(value, VariableValue{name}))) { + if (DAWN_UNLIKELY(!bindings_.Add(value, VariableValue{name}))) { TINT_ICE() << "Bind(" << value->TypeInfo().name << ") called twice for same value"; } }
diff --git a/src/tint/lang/wgsl/writer/ir_to_program/ir_to_program_test.h b/src/tint/lang/wgsl/writer/ir_to_program/ir_to_program_test.h index 92cbdd8..fbe946f 100644 --- a/src/tint/lang/wgsl/writer/ir_to_program/ir_to_program_test.h +++ b/src/tint/lang/wgsl/writer/ir_to_program/ir_to_program_test.h
@@ -67,7 +67,7 @@ !traits::IsTypeOrDerived<std::remove_pointer_t<std::decay_t<VALUE>>, core::type::Type>>> core::ir::Var* Var(std::string_view name, VALUE&& init) { auto* val = b.Value(std::forward<VALUE>(init)); - if (TINT_UNLIKELY(!val)) { + if (DAWN_UNLIKELY(!val)) { TINT_ASSERT(val); return nullptr; }
diff --git a/src/tint/utils/containers/hashmap_base.h b/src/tint/utils/containers/hashmap_base.h index ba78fd0..869a667 100644 --- a/src/tint/utils/containers/hashmap_base.h +++ b/src/tint/utils/containers/hashmap_base.h
@@ -651,7 +651,7 @@ constexpr size_t kAllocationSize = RoundUp(alignof(Node), sizeof(Allocation)); auto* memory = reinterpret_cast<std::byte*>(malloc(kAllocationSize + sizeof(Node) * count)); - if (TINT_UNLIKELY(!memory)) { + if (DAWN_UNLIKELY(!memory)) { TINT_ICE() << "out of memory"; return; }
diff --git a/src/tint/utils/containers/scope_stack.h b/src/tint/utils/containers/scope_stack.h index 066d367..b98b047 100644 --- a/src/tint/utils/containers/scope_stack.h +++ b/src/tint/utils/containers/scope_stack.h
@@ -45,7 +45,7 @@ /// Push a new scope on to the stack void Push() { depth_++; - if (TINT_LIKELY(stack_.Length() >= depth_)) { + if (DAWN_LIKELY(stack_.Length() >= depth_)) { Top().Clear(); } else { stack_.Push({});
diff --git a/src/tint/utils/generator/text_generator.cc b/src/tint/utils/generator/text_generator.cc index 00e022d..58251a4 100644 --- a/src/tint/utils/generator/text_generator.cc +++ b/src/tint/utils/generator/text_generator.cc
@@ -68,7 +68,7 @@ } void TextGenerator::TextBuffer::Insert(const std::string& line, size_t before, uint32_t indent) { - if (TINT_UNLIKELY(before > lines.size())) { + if (DAWN_UNLIKELY(before > lines.size())) { TINT_ICE() << "TextBuffer::Insert() called with before > lines.size()\n" << " before:" << before << "\n" << " lines.size(): " << lines.size(); @@ -85,7 +85,7 @@ } void TextGenerator::TextBuffer::Insert(const TextBuffer& tb, size_t before, uint32_t indent) { - if (TINT_UNLIKELY(before > lines.size())) { + if (DAWN_UNLIKELY(before > lines.size())) { TINT_ICE() << "TextBuffer::Insert() called with before > lines.size()\n" << " before:" << before << "\n" << " lines.size(): " << lines.size();
diff --git a/src/tint/utils/ice/ice.h b/src/tint/utils/ice/ice.h index 96087bc..b260aed 100644 --- a/src/tint/utils/ice/ice.h +++ b/src/tint/utils/ice/ice.h
@@ -112,7 +112,7 @@ /// The ICE message contains the callsite's file and line. #define TINT_ASSERT(condition) \ do { \ - if (TINT_UNLIKELY(!(condition))) { \ + if (DAWN_UNLIKELY(!(condition))) { \ TINT_ICE() << "TINT_ASSERT(" #condition ")"; \ } \ } while (false)
diff --git a/src/tint/utils/macros/compiler.h b/src/tint/utils/macros/compiler.h index e7ef1c3..6c06bed 100644 --- a/src/tint/utils/macros/compiler.h +++ b/src/tint/utils/macros/compiler.h
@@ -83,9 +83,6 @@ __pragma(warning(push)) TINT_DISABLE_WARNING_UNUSED_PARAMETER TINT_REQUIRE_SEMICOLON #define TINT_END_DISABLE_PROTOBUF_WARNINGS() __pragma(warning(pop)) TINT_REQUIRE_SEMICOLON -#define TINT_UNLIKELY(x) x /* currently no-op */ -#define TINT_LIKELY(x) x /* currently no-op */ - #if defined(__SANITIZE_ADDRESS__) #define TINT_ASAN_ENABLED #endif @@ -166,9 +163,6 @@ TINT_REQUIRE_SEMICOLON // clang-format on -#define TINT_UNLIKELY(x) __builtin_expect(!!(x), false) -#define TINT_LIKELY(x) __builtin_expect(!!(x), true) - #if __has_feature(address_sanitizer) #define TINT_ASAN_ENABLED #endif @@ -241,9 +235,6 @@ TINT_REQUIRE_SEMICOLON // clang-format on -#define TINT_UNLIKELY(x) __builtin_expect(!!(x), false) -#define TINT_LIKELY(x) __builtin_expect(!!(x), true) - #if defined(__SANITIZE_ADDRESS__) #define TINT_ASAN_ENABLED #endif @@ -260,8 +251,6 @@ #define TINT_END_DISABLE_WARNING(name) TINT_REQUIRE_SEMICOLON #define TINT_BEGIN_DISABLE_PROTOBUF_WARNINGS() TINT_REQUIRE_SEMICOLON #define TINT_END_DISABLE_PROTOBUF_WARNINGS() TINT_REQUIRE_SEMICOLON -#define TINT_UNLIKELY(x) x -#define TINT_LIKELY(x) x #endif
diff --git a/src/tint/utils/memory/bump_allocator.h b/src/tint/utils/memory/bump_allocator.h index 30875a5..019034b 100644 --- a/src/tint/utils/memory/bump_allocator.h +++ b/src/tint/utils/memory/bump_allocator.h
@@ -80,7 +80,7 @@ /// @param size_in_bytes the number of bytes to allocate /// @returns the pointer to the allocated memory or `nullptr` if the memory can not be allocated std::byte* Allocate(size_t size_in_bytes) { - if (TINT_UNLIKELY(data.current_offset + size_in_bytes < size_in_bytes)) { + if (DAWN_UNLIKELY(data.current_offset + size_in_bytes < size_in_bytes)) { return nullptr; // integer overflow } if (data.current_offset + size_in_bytes > data.current_data_size) { @@ -89,7 +89,7 @@ size_t data_size = std::max(size_in_bytes, kDefaultBlockDataSize); data.current = Bitcast<BlockHeader*>(new (std::nothrow) std::byte[sizeof(BlockHeader) + data_size]); - if (TINT_UNLIKELY(!data.current)) { + if (DAWN_UNLIKELY(!data.current)) { return nullptr; // out of memory } data.current->next = nullptr;
diff --git a/src/utils/compiler.h b/src/utils/compiler.h index e20bdb9..637e68a 100644 --- a/src/utils/compiler.h +++ b/src/utils/compiler.h
@@ -28,6 +28,31 @@ #ifndef SRC_UTILS_COMPILER_H_ #define SRC_UTILS_COMPILER_H_ +// DAWN_COMPILER_IS(CLANG|GCC|MSVC): Compiler detection +// +// Note: clang masquerades as GCC on POSIX and as MSVC on Windows. It must be checked first. +#if defined(__clang__) +#define DAWN_COMPILER_IS_CLANG 1 +#define DAWN_COMPILER_IS_GCC 0 +#define DAWN_COMPILER_IS_MSVC 0 +#elif defined(__GNUC__) +#define DAWN_COMPILER_IS_CLANG 0 +#define DAWN_COMPILER_IS_GCC 1 +#define DAWN_COMPILER_IS_MSVC 0 +#elif defined(_MSC_VER) +#define DAWN_COMPILER_IS_CLANG 0 +#define DAWN_COMPILER_IS_GCC 0 +#define DAWN_COMPILER_IS_MSVC 1 +#else +#error "Unsupported compiler" +#endif + +// Use #if DAWN_COMPILER_IS(XXX) for compiler specific code. +// Do not use #ifdef or the naked macro DAWN_COMPILER_IS_XXX. +// This can help avoid common mistakes like not including "compiler.h" and falling into unwanted +// code block as usage of undefined macro "function" will be blocked by the compiler. +#define DAWN_COMPILER_IS(X) (1 == DAWN_COMPILER_IS_##X) + // DAWN_HAS_ATTRIBUTE // // A wrapper around `__has_attribute`. This test whether its operand is recognized by the compiler. @@ -47,4 +72,33 @@ #define DAWN_HAS_CPP_ATTRIBUTE(x) 0 #endif +// DAWN_BUILTIN_UNREACHABLE() +// +// Hints the compiler that a code path is unreachable. +#if DAWN_COMPILER_IS(MSVC) +#define DAWN_BUILTIN_UNREACHABLE() __assume(false) +#else +#define DAWN_BUILTIN_UNREACHABLE() __builtin_unreachable() +#endif + +// DAWN_LIKELY(EXPR) +// +// Where available, hints the compiler that the expression will be true to help it generate code +// that leads to better branch prediction. +#if DAWN_COMPILER_IS(GCC) || DAWN_COMPILER_IS(CLANG) +#define DAWN_LIKELY(x) __builtin_expect(!!(x), 1) +#else +#define DAWN_LIKELY(x) (x) +#endif + +// DAWN_UNLIKELY(EXPR) +// +// Where available, hints the compiler that the expression will be false to help it generate code +// that leads to better branch prediction. +#if DAWN_COMPILER_IS(GCC) || DAWN_COMPILER_IS(CLANG) +#define DAWN_UNLIKELY(x) __builtin_expect(!!(x), 0) +#else +#define DAWN_UNLIKELY(x) (x) +#endif + #endif // SRC_UTILS_COMPILER_H_