tint/writer/glsl: Simplify map keys with UnorderedKeyWrapper

And remove the unused DMAIntrinsic struct / field.

Change-Id: I641c066a7bc22dc903592b3928705be56d83392c
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/96145
Reviewed-by: Zhaoming Jiang <zhaoming.jiang@intel.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
Ben Clayton 2022-07-16 00:00:29 +00:00 committed by Dawn LUCI CQ
parent ac660c2794
commit 605b7fbadc
2 changed files with 41 additions and 68 deletions

View File

@ -502,7 +502,8 @@ bool GeneratorImpl::EmitFloatModulo(std::ostream& out, const ast::BinaryExpressi
auto* ret_ty = TypeOf(expr)->UnwrapRef();
auto* lhs_ty = TypeOf(expr->lhs)->UnwrapRef();
auto* rhs_ty = TypeOf(expr->rhs)->UnwrapRef();
fn = utils::GetOrCreate(float_modulo_funcs_, {lhs_ty, rhs_ty}, [&]() -> std::string {
fn = utils::GetOrCreate(float_modulo_funcs_, BinaryOperandType{{lhs_ty, rhs_ty}},
[&]() -> std::string {
TextBuffer b;
TINT_DEFER(helpers_.Append(b));
@ -510,21 +511,21 @@ bool GeneratorImpl::EmitFloatModulo(std::ostream& out, const ast::BinaryExpressi
std::vector<std::string> parameter_names;
{
auto decl = line(&b);
if (!EmitTypeAndName(decl, ret_ty, ast::StorageClass::kNone, ast::Access::kUndefined,
fn_name)) {
if (!EmitTypeAndName(decl, ret_ty, ast::StorageClass::kNone,
ast::Access::kUndefined, fn_name)) {
return "";
}
{
ScopedParen sp(decl);
const auto* ty = TypeOf(expr->lhs)->UnwrapRef();
if (!EmitTypeAndName(decl, ty, ast::StorageClass::kNone, ast::Access::kUndefined,
"lhs")) {
if (!EmitTypeAndName(decl, ty, ast::StorageClass::kNone,
ast::Access::kUndefined, "lhs")) {
return "";
}
decl << ", ";
ty = TypeOf(expr->rhs)->UnwrapRef();
if (!EmitTypeAndName(decl, ty, ast::StorageClass::kNone, ast::Access::kUndefined,
"rhs")) {
if (!EmitTypeAndName(decl, ty, ast::StorageClass::kNone,
ast::Access::kUndefined, "rhs")) {
return "";
}
}

View File

@ -16,6 +16,7 @@
#define SRC_TINT_WRITER_GLSL_GENERATOR_IMPL_H_
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
@ -478,36 +479,9 @@ class GeneratorImpl : public TextGenerator {
std::string var_name;
};
struct DMAIntrinsic {
transform::DecomposeMemoryAccess::Intrinsic::Op op;
transform::DecomposeMemoryAccess::Intrinsic::DataType type;
bool operator==(const DMAIntrinsic& rhs) const { return op == rhs.op && type == rhs.type; }
/// Hasher is a std::hash function for DMAIntrinsic
struct Hasher {
/// @param i the DMAIntrinsic to hash
/// @returns the hash of `i`
inline std::size_t operator()(const DMAIntrinsic& i) const {
return utils::Hash(i.op, i.type);
}
};
};
/// The structure holding both type of two operands for a binary operator.
struct BinaryOperandType {
const sem::Type* lhs_type;
const sem::Type* rhs_type;
bool operator==(const BinaryOperandType& rhs) const {
return lhs_type == rhs.lhs_type && rhs_type == rhs.rhs_type;
}
/// Hasher is a std::hash function for BinaryOperandType
struct Hasher {
/// @param i the BinaryOperandType to hash
/// @returns the hash of `i`
inline std::size_t operator()(const BinaryOperandType& i) const {
return utils::Hash(i.lhs_type, i.rhs_type);
}
};
};
/// The map key for two semantic types.
using BinaryOperandType =
utils::UnorderedKeyWrapper<std::tuple<const sem::Type*, const sem::Type*>>;
/// CallBuiltinHelper will call the builtin helper function, creating it
/// if it hasn't been built already. If the builtin needs to be built then
@ -535,12 +509,10 @@ class GeneratorImpl : public TextGenerator {
TextBuffer helpers_; // Helper functions emitted at the top of the output
std::function<bool()> emit_continuing_;
std::unordered_map<DMAIntrinsic, std::string, DMAIntrinsic::Hasher> dma_intrinsics_;
std::unordered_map<const sem::Builtin*, std::string> builtins_;
std::unordered_map<const sem::Vector*, std::string> dynamic_vector_write_;
std::unordered_map<const sem::Vector*, std::string> int_dot_funcs_;
std::unordered_map<BinaryOperandType, std::string, BinaryOperandType::Hasher>
float_modulo_funcs_;
std::unordered_map<BinaryOperandType, std::string> float_modulo_funcs_;
std::unordered_set<const sem::Struct*> emitted_structs_;
bool requires_oes_sample_variables_ = false;
bool requires_default_precision_qualifier_ = false;