Consistent formatting for Dawn/Tint.
This CL updates the clang format files to have a single shared format
between Dawn and Tint. The major changes are tabs are 4 spaces, lines
are 100 columns and namespaces are not indented.
Bug: dawn:1339
Change-Id: I4208742c95643998d9fd14e77a9cc558071ded39
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/87603
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
diff --git a/src/tint/transform/calculate_array_length.cc b/src/tint/transform/calculate_array_length.cc
index b2ba299..c2128c7 100644
--- a/src/tint/transform/calculate_array_length.cc
+++ b/src/tint/transform/calculate_array_length.cc
@@ -31,8 +31,7 @@
#include "src/tint/utils/map.h"
TINT_INSTANTIATE_TYPEINFO(tint::transform::CalculateArrayLength);
-TINT_INSTANTIATE_TYPEINFO(
- tint::transform::CalculateArrayLength::BufferSizeIntrinsic);
+TINT_INSTANTIATE_TYPEINFO(tint::transform::CalculateArrayLength::BufferSizeIntrinsic);
namespace tint::transform {
@@ -41,201 +40,189 @@
/// ArrayUsage describes a runtime array usage.
/// It is used as a key by the array_length_by_usage map.
struct ArrayUsage {
- ast::BlockStatement const* const block;
- sem::Variable const* const buffer;
- bool operator==(const ArrayUsage& rhs) const {
- return block == rhs.block && buffer == rhs.buffer;
- }
- struct Hasher {
- inline std::size_t operator()(const ArrayUsage& u) const {
- return utils::Hash(u.block, u.buffer);
+ ast::BlockStatement const* const block;
+ sem::Variable const* const buffer;
+ bool operator==(const ArrayUsage& rhs) const {
+ return block == rhs.block && buffer == rhs.buffer;
}
- };
+ struct Hasher {
+ inline std::size_t operator()(const ArrayUsage& u) const {
+ return utils::Hash(u.block, u.buffer);
+ }
+ };
};
} // namespace
-CalculateArrayLength::BufferSizeIntrinsic::BufferSizeIntrinsic(ProgramID pid)
- : Base(pid) {}
+CalculateArrayLength::BufferSizeIntrinsic::BufferSizeIntrinsic(ProgramID pid) : Base(pid) {}
CalculateArrayLength::BufferSizeIntrinsic::~BufferSizeIntrinsic() = default;
std::string CalculateArrayLength::BufferSizeIntrinsic::InternalName() const {
- return "intrinsic_buffer_size";
+ return "intrinsic_buffer_size";
}
-const CalculateArrayLength::BufferSizeIntrinsic*
-CalculateArrayLength::BufferSizeIntrinsic::Clone(CloneContext* ctx) const {
- return ctx->dst->ASTNodes().Create<CalculateArrayLength::BufferSizeIntrinsic>(
- ctx->dst->ID());
+const CalculateArrayLength::BufferSizeIntrinsic* CalculateArrayLength::BufferSizeIntrinsic::Clone(
+ CloneContext* ctx) const {
+ return ctx->dst->ASTNodes().Create<CalculateArrayLength::BufferSizeIntrinsic>(ctx->dst->ID());
}
CalculateArrayLength::CalculateArrayLength() = default;
CalculateArrayLength::~CalculateArrayLength() = default;
-bool CalculateArrayLength::ShouldRun(const Program* program,
- const DataMap&) const {
- for (auto* fn : program->AST().Functions()) {
- if (auto* sem_fn = program->Sem().Get(fn)) {
- for (auto* builtin : sem_fn->DirectlyCalledBuiltins()) {
- if (builtin->Type() == sem::BuiltinType::kArrayLength) {
- return true;
+bool CalculateArrayLength::ShouldRun(const Program* program, const DataMap&) const {
+ for (auto* fn : program->AST().Functions()) {
+ if (auto* sem_fn = program->Sem().Get(fn)) {
+ for (auto* builtin : sem_fn->DirectlyCalledBuiltins()) {
+ if (builtin->Type() == sem::BuiltinType::kArrayLength) {
+ return true;
+ }
+ }
}
- }
}
- }
- return false;
+ return false;
}
-void CalculateArrayLength::Run(CloneContext& ctx,
- const DataMap&,
- DataMap&) const {
- auto& sem = ctx.src->Sem();
+void CalculateArrayLength::Run(CloneContext& ctx, const DataMap&, DataMap&) const {
+ auto& sem = ctx.src->Sem();
- // get_buffer_size_intrinsic() emits the function decorated with
- // BufferSizeIntrinsic that is transformed by the HLSL writer into a call to
- // [RW]ByteAddressBuffer.GetDimensions().
- std::unordered_map<const sem::Type*, Symbol> buffer_size_intrinsics;
- auto get_buffer_size_intrinsic = [&](const sem::Type* buffer_type) {
- return utils::GetOrCreate(buffer_size_intrinsics, buffer_type, [&] {
- auto name = ctx.dst->Sym();
- auto* type = CreateASTTypeFor(ctx, buffer_type);
- auto* disable_validation = ctx.dst->Disable(
- ast::DisabledValidation::kIgnoreConstructibleFunctionParameter);
- ctx.dst->AST().AddFunction(ctx.dst->create<ast::Function>(
- name,
- ast::VariableList{
- // Note: The buffer parameter requires the kStorage StorageClass
- // in order for HLSL to emit this as a ByteAddressBuffer.
- ctx.dst->create<ast::Variable>(
- ctx.dst->Sym("buffer"), ast::StorageClass::kStorage,
- ast::Access::kUndefined, type, true, false, nullptr,
- ast::AttributeList{disable_validation}),
- ctx.dst->Param("result",
- ctx.dst->ty.pointer(ctx.dst->ty.u32(),
- ast::StorageClass::kFunction)),
- },
- ctx.dst->ty.void_(), nullptr,
- ast::AttributeList{
- ctx.dst->ASTNodes().Create<BufferSizeIntrinsic>(ctx.dst->ID()),
- },
- ast::AttributeList{}));
+ // get_buffer_size_intrinsic() emits the function decorated with
+ // BufferSizeIntrinsic that is transformed by the HLSL writer into a call to
+ // [RW]ByteAddressBuffer.GetDimensions().
+ std::unordered_map<const sem::Type*, Symbol> buffer_size_intrinsics;
+ auto get_buffer_size_intrinsic = [&](const sem::Type* buffer_type) {
+ return utils::GetOrCreate(buffer_size_intrinsics, buffer_type, [&] {
+ auto name = ctx.dst->Sym();
+ auto* type = CreateASTTypeFor(ctx, buffer_type);
+ auto* disable_validation =
+ ctx.dst->Disable(ast::DisabledValidation::kIgnoreConstructibleFunctionParameter);
+ ctx.dst->AST().AddFunction(ctx.dst->create<ast::Function>(
+ name,
+ ast::VariableList{
+ // Note: The buffer parameter requires the kStorage StorageClass
+ // in order for HLSL to emit this as a ByteAddressBuffer.
+ ctx.dst->create<ast::Variable>(ctx.dst->Sym("buffer"),
+ ast::StorageClass::kStorage,
+ ast::Access::kUndefined, type, true, false,
+ nullptr, ast::AttributeList{disable_validation}),
+ ctx.dst->Param("result", ctx.dst->ty.pointer(ctx.dst->ty.u32(),
+ ast::StorageClass::kFunction)),
+ },
+ ctx.dst->ty.void_(), nullptr,
+ ast::AttributeList{
+ ctx.dst->ASTNodes().Create<BufferSizeIntrinsic>(ctx.dst->ID()),
+ },
+ ast::AttributeList{}));
- return name;
- });
- };
+ return name;
+ });
+ };
- std::unordered_map<ArrayUsage, Symbol, ArrayUsage::Hasher>
- array_length_by_usage;
+ std::unordered_map<ArrayUsage, Symbol, ArrayUsage::Hasher> array_length_by_usage;
- // Find all the arrayLength() calls...
- for (auto* node : ctx.src->ASTNodes().Objects()) {
- if (auto* call_expr = node->As<ast::CallExpression>()) {
- auto* call = sem.Get(call_expr);
- if (auto* builtin = call->Target()->As<sem::Builtin>()) {
- if (builtin->Type() == sem::BuiltinType::kArrayLength) {
- // We're dealing with an arrayLength() call
+ // Find all the arrayLength() calls...
+ for (auto* node : ctx.src->ASTNodes().Objects()) {
+ if (auto* call_expr = node->As<ast::CallExpression>()) {
+ auto* call = sem.Get(call_expr);
+ if (auto* builtin = call->Target()->As<sem::Builtin>()) {
+ if (builtin->Type() == sem::BuiltinType::kArrayLength) {
+ // We're dealing with an arrayLength() call
- // A runtime-sized array can only appear as the store type of a
- // variable, or the last element of a structure (which cannot itself
- // be nested). Given that we require SimplifyPointers, we can assume
- // that the arrayLength() call has one of two forms:
- // arrayLength(&struct_var.array_member)
- // arrayLength(&array_var)
- auto* arg = call_expr->args[0];
- auto* address_of = arg->As<ast::UnaryOpExpression>();
- if (!address_of || address_of->op != ast::UnaryOp::kAddressOf) {
- TINT_ICE(Transform, ctx.dst->Diagnostics())
- << "arrayLength() expected address-of, got "
- << arg->TypeInfo().name;
- }
- auto* storage_buffer_expr = address_of->expr;
- if (auto* accessor =
- storage_buffer_expr->As<ast::MemberAccessorExpression>()) {
- storage_buffer_expr = accessor->structure;
- }
- auto* storage_buffer_sem =
- sem.Get<sem::VariableUser>(storage_buffer_expr);
- if (!storage_buffer_sem) {
- TINT_ICE(Transform, ctx.dst->Diagnostics())
- << "expected form of arrayLength argument to be &array_var or "
- "&struct_var.array_member";
- break;
- }
- auto* storage_buffer_var = storage_buffer_sem->Variable();
- auto* storage_buffer_type = storage_buffer_sem->Type()->UnwrapRef();
+ // A runtime-sized array can only appear as the store type of a
+ // variable, or the last element of a structure (which cannot itself
+ // be nested). Given that we require SimplifyPointers, we can assume
+ // that the arrayLength() call has one of two forms:
+ // arrayLength(&struct_var.array_member)
+ // arrayLength(&array_var)
+ auto* arg = call_expr->args[0];
+ auto* address_of = arg->As<ast::UnaryOpExpression>();
+ if (!address_of || address_of->op != ast::UnaryOp::kAddressOf) {
+ TINT_ICE(Transform, ctx.dst->Diagnostics())
+ << "arrayLength() expected address-of, got " << arg->TypeInfo().name;
+ }
+ auto* storage_buffer_expr = address_of->expr;
+ if (auto* accessor = storage_buffer_expr->As<ast::MemberAccessorExpression>()) {
+ storage_buffer_expr = accessor->structure;
+ }
+ auto* storage_buffer_sem = sem.Get<sem::VariableUser>(storage_buffer_expr);
+ if (!storage_buffer_sem) {
+ TINT_ICE(Transform, ctx.dst->Diagnostics())
+ << "expected form of arrayLength argument to be &array_var or "
+ "&struct_var.array_member";
+ break;
+ }
+ auto* storage_buffer_var = storage_buffer_sem->Variable();
+ auto* storage_buffer_type = storage_buffer_sem->Type()->UnwrapRef();
- // Generate BufferSizeIntrinsic for this storage type if we haven't
- // already
- auto buffer_size = get_buffer_size_intrinsic(storage_buffer_type);
+ // Generate BufferSizeIntrinsic for this storage type if we haven't
+ // already
+ auto buffer_size = get_buffer_size_intrinsic(storage_buffer_type);
- // Find the current statement block
- auto* block = call->Stmt()->Block()->Declaration();
+ // Find the current statement block
+ auto* block = call->Stmt()->Block()->Declaration();
- auto array_length = utils::GetOrCreate(
- array_length_by_usage, {block, storage_buffer_var}, [&] {
- // First time this array length is used for this block.
- // Let's calculate it.
+ auto array_length =
+ utils::GetOrCreate(array_length_by_usage, {block, storage_buffer_var}, [&] {
+ // First time this array length is used for this block.
+ // Let's calculate it.
- // Construct the variable that'll hold the result of
- // RWByteAddressBuffer.GetDimensions()
- auto* buffer_size_result = ctx.dst->Decl(
- ctx.dst->Var(ctx.dst->Sym(), ctx.dst->ty.u32(),
- ast::StorageClass::kNone, ctx.dst->Expr(0u)));
+ // Construct the variable that'll hold the result of
+ // RWByteAddressBuffer.GetDimensions()
+ auto* buffer_size_result = ctx.dst->Decl(
+ ctx.dst->Var(ctx.dst->Sym(), ctx.dst->ty.u32(),
+ ast::StorageClass::kNone, ctx.dst->Expr(0u)));
- // Call storage_buffer.GetDimensions(&buffer_size_result)
- auto* call_get_dims = ctx.dst->CallStmt(ctx.dst->Call(
- // BufferSizeIntrinsic(X, ARGS...) is
- // translated to:
- // X.GetDimensions(ARGS..) by the writer
- buffer_size, ctx.Clone(storage_buffer_expr),
- ctx.dst->AddressOf(
- ctx.dst->Expr(buffer_size_result->variable->symbol))));
+ // Call storage_buffer.GetDimensions(&buffer_size_result)
+ auto* call_get_dims = ctx.dst->CallStmt(ctx.dst->Call(
+ // BufferSizeIntrinsic(X, ARGS...) is
+ // translated to:
+ // X.GetDimensions(ARGS..) by the writer
+ buffer_size, ctx.Clone(storage_buffer_expr),
+ ctx.dst->AddressOf(
+ ctx.dst->Expr(buffer_size_result->variable->symbol))));
- // Calculate actual array length
- // total_storage_buffer_size - array_offset
- // array_length = ----------------------------------------
- // array_stride
- auto name = ctx.dst->Sym();
- const ast::Expression* total_size =
- ctx.dst->Expr(buffer_size_result->variable);
- const sem::Array* array_type = nullptr;
- if (auto* str = storage_buffer_type->As<sem::Struct>()) {
- // The variable is a struct, so subtract the byte offset of
- // the array member.
- auto* array_member_sem = str->Members().back();
- array_type = array_member_sem->Type()->As<sem::Array>();
- total_size =
- ctx.dst->Sub(total_size, array_member_sem->Offset());
- } else if (auto* arr = storage_buffer_type->As<sem::Array>()) {
- array_type = arr;
- } else {
- TINT_ICE(Transform, ctx.dst->Diagnostics())
- << "expected form of arrayLength argument to be "
- "&array_var or &struct_var.array_member";
- return name;
+ // Calculate actual array length
+ // total_storage_buffer_size - array_offset
+ // array_length = ----------------------------------------
+ // array_stride
+ auto name = ctx.dst->Sym();
+ const ast::Expression* total_size =
+ ctx.dst->Expr(buffer_size_result->variable);
+ const sem::Array* array_type = nullptr;
+ if (auto* str = storage_buffer_type->As<sem::Struct>()) {
+ // The variable is a struct, so subtract the byte offset of
+ // the array member.
+ auto* array_member_sem = str->Members().back();
+ array_type = array_member_sem->Type()->As<sem::Array>();
+ total_size = ctx.dst->Sub(total_size, array_member_sem->Offset());
+ } else if (auto* arr = storage_buffer_type->As<sem::Array>()) {
+ array_type = arr;
+ } else {
+ TINT_ICE(Transform, ctx.dst->Diagnostics())
+ << "expected form of arrayLength argument to be "
+ "&array_var or &struct_var.array_member";
+ return name;
+ }
+ uint32_t array_stride = array_type->Size();
+ auto* array_length_var = ctx.dst->Decl(ctx.dst->Let(
+ name, ctx.dst->ty.u32(), ctx.dst->Div(total_size, array_stride)));
+
+ // Insert the array length calculations at the top of the block
+ ctx.InsertBefore(block->statements, block->statements[0],
+ buffer_size_result);
+ ctx.InsertBefore(block->statements, block->statements[0],
+ call_get_dims);
+ ctx.InsertBefore(block->statements, block->statements[0],
+ array_length_var);
+ return name;
+ });
+
+ // Replace the call to arrayLength() with the array length variable
+ ctx.Replace(call_expr, ctx.dst->Expr(array_length));
}
- uint32_t array_stride = array_type->Size();
- auto* array_length_var = ctx.dst->Decl(
- ctx.dst->Let(name, ctx.dst->ty.u32(),
- ctx.dst->Div(total_size, array_stride)));
-
- // Insert the array length calculations at the top of the block
- ctx.InsertBefore(block->statements, block->statements[0],
- buffer_size_result);
- ctx.InsertBefore(block->statements, block->statements[0],
- call_get_dims);
- ctx.InsertBefore(block->statements, block->statements[0],
- array_length_var);
- return name;
- });
-
- // Replace the call to arrayLength() with the array length variable
- ctx.Replace(call_expr, ctx.dst->Expr(array_length));
+ }
}
- }
}
- }
- ctx.Clone();
+ ctx.Clone();
}
} // namespace tint::transform