Commit 697b9fb0 authored by Nico Hartmann's avatar Nico Hartmann Committed by Commit Bot

[Torque] Implement Flatten() and EmitCCValue without std::tuple_cat

The implementation of Flatten() Torque generates for CSA struct types
and the current implementation of EmitCCValue make heavy use of
std::make_tuple and std::tuple_cat, which had a noticeable impact on
build times of generated files including these outputs.
This CL eliminates all uses of std::tuple_cat and most uses of
std::make_tuple.

Bug: v8:9861
Change-Id: Ib950b2c87983171b8c32c388fc115d2407087717
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2784563
Commit-Queue: Nico Hartmann <nicohartmann@chromium.org>
Reviewed-by: 's avatarSeth Brenith <seth.brenith@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#73660}
parent 5e39dac7
...@@ -472,33 +472,38 @@ void CCGenerator::EmitInstruction(const StoreBitFieldInstruction& instruction, ...@@ -472,33 +472,38 @@ void CCGenerator::EmitInstruction(const StoreBitFieldInstruction& instruction,
ReportError("Not supported in C++ output: StoreBitField"); ReportError("Not supported in C++ output: StoreBitField");
} }
// static namespace {
void CCGenerator::EmitCCValue(VisitResult result,
const Stack<std::string>& values, void CollectAllFields(const VisitResult& result,
std::ostream& out) { const Stack<std::string>& values,
std::vector<std::string>& all_fields) {
if (!result.IsOnStack()) { if (!result.IsOnStack()) {
out << result.constexpr_value(); all_fields.push_back(result.constexpr_value());
} else if (auto struct_type = result.type()->StructSupertype()) { } else if (auto struct_type = result.type()->StructSupertype()) {
out << "std::tuple_cat("; for (const Field& field : (*struct_type)->fields()) {
bool first = true; CollectAllFields(ProjectStructField(result, field.name_and_type.name),
for (auto& field : (*struct_type)->fields()) { values, all_fields);
if (!first) {
out << ", ";
}
first = false;
if (!field.name_and_type.type->IsStructType()) {
out << "std::make_tuple(";
}
EmitCCValue(ProjectStructField(result, field.name_and_type.name), values,
out);
if (!field.name_and_type.type->IsStructType()) {
out << ")";
}
} }
out << ")";
} else { } else {
DCHECK_EQ(1, result.stack_range().Size()); DCHECK_EQ(1, result.stack_range().Size());
out << values.Peek(result.stack_range().begin()); all_fields.push_back(values.Peek(result.stack_range().begin()));
}
}
} // namespace
// static
void CCGenerator::EmitCCValue(VisitResult result,
const Stack<std::string>& values,
std::ostream& out) {
std::vector<std::string> all_fields;
CollectAllFields(result, values, all_fields);
if (all_fields.size() == 1) {
out << all_fields[0];
} else {
out << "std::make_tuple(";
PrintCommaSeparatedList(out, all_fields);
out << ")";
} }
} }
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "src/torque/type-inference.h" #include "src/torque/type-inference.h"
#include "src/torque/type-visitor.h" #include "src/torque/type-visitor.h"
#include "src/torque/types.h" #include "src/torque/types.h"
#include "src/torque/utils.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
...@@ -5158,6 +5159,24 @@ void ImplementationVisitor::GenerateExportedMacrosAssembler( ...@@ -5158,6 +5159,24 @@ void ImplementationVisitor::GenerateExportedMacrosAssembler(
WriteFile(output_directory + "/" + file_name + ".cc", cc_contents.str()); WriteFile(output_directory + "/" + file_name + ".cc", cc_contents.str());
} }
namespace {
void CollectAllFields(const std::string& path, const Field& field,
std::vector<std::string>& result) {
if (field.name_and_type.type->StructSupertype()) {
std::string next_path = path + field.name_and_type.name + ".";
const StructType* struct_type =
StructType::DynamicCast(field.name_and_type.type);
for (const auto& inner_field : struct_type->fields()) {
CollectAllFields(next_path, inner_field, result);
}
} else {
result.push_back(path + field.name_and_type.name);
}
}
} // namespace
void ImplementationVisitor::GenerateCSATypes( void ImplementationVisitor::GenerateCSATypes(
const std::string& output_directory) { const std::string& output_directory) {
std::string file_name = "csa-types"; std::string file_name = "csa-types";
...@@ -5188,20 +5207,13 @@ void ImplementationVisitor::GenerateCSATypes( ...@@ -5188,20 +5207,13 @@ void ImplementationVisitor::GenerateCSATypes(
first = false; first = false;
h_contents << type->GetGeneratedTypeName(); h_contents << type->GetGeneratedTypeName();
} }
h_contents << "> Flatten() const {\n" std::vector<std::string> all_fields;
<< " return std::tuple_cat(";
first = true;
for (auto& field : struct_type->fields()) { for (auto& field : struct_type->fields()) {
if (!first) { CollectAllFields("", field, all_fields);
h_contents << ", ";
}
first = false;
if (field.name_and_type.type->StructSupertype()) {
h_contents << field.name_and_type.name << ".Flatten()";
} else {
h_contents << "std::make_tuple(" << field.name_and_type.name << ")";
}
} }
h_contents << "> Flatten() const {\n"
" return std::make_tuple(";
PrintCommaSeparatedList(h_contents, all_fields);
h_contents << ");\n"; h_contents << ");\n";
h_contents << " }\n"; h_contents << " }\n";
h_contents << "};\n"; h_contents << "};\n";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment