[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: Seth Brenith <seth.brenith@microsoft.com> Cr-Commit-Position: refs/heads/master@{#73660}
This commit is contained in:
parent
5e39dac724
commit
697b9fb050
@ -472,33 +472,38 @@ void CCGenerator::EmitInstruction(const StoreBitFieldInstruction& instruction,
|
||||
ReportError("Not supported in C++ output: StoreBitField");
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
void CollectAllFields(const VisitResult& result,
|
||||
const Stack<std::string>& values,
|
||||
std::vector<std::string>& all_fields) {
|
||||
if (!result.IsOnStack()) {
|
||||
all_fields.push_back(result.constexpr_value());
|
||||
} else if (auto struct_type = result.type()->StructSupertype()) {
|
||||
for (const Field& field : (*struct_type)->fields()) {
|
||||
CollectAllFields(ProjectStructField(result, field.name_and_type.name),
|
||||
values, all_fields);
|
||||
}
|
||||
} else {
|
||||
DCHECK_EQ(1, result.stack_range().Size());
|
||||
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) {
|
||||
if (!result.IsOnStack()) {
|
||||
out << result.constexpr_value();
|
||||
} else if (auto struct_type = result.type()->StructSupertype()) {
|
||||
out << "std::tuple_cat(";
|
||||
bool first = true;
|
||||
for (auto& field : (*struct_type)->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 << ")";
|
||||
std::vector<std::string> all_fields;
|
||||
CollectAllFields(result, values, all_fields);
|
||||
if (all_fields.size() == 1) {
|
||||
out << all_fields[0];
|
||||
} else {
|
||||
DCHECK_EQ(1, result.stack_range().Size());
|
||||
out << values.Peek(result.stack_range().begin());
|
||||
out << "std::make_tuple(";
|
||||
PrintCommaSeparatedList(out, all_fields);
|
||||
out << ")";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "src/torque/type-inference.h"
|
||||
#include "src/torque/type-visitor.h"
|
||||
#include "src/torque/types.h"
|
||||
#include "src/torque/utils.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
@ -5158,6 +5159,24 @@ void ImplementationVisitor::GenerateExportedMacrosAssembler(
|
||||
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(
|
||||
const std::string& output_directory) {
|
||||
std::string file_name = "csa-types";
|
||||
@ -5188,20 +5207,13 @@ void ImplementationVisitor::GenerateCSATypes(
|
||||
first = false;
|
||||
h_contents << type->GetGeneratedTypeName();
|
||||
}
|
||||
h_contents << "> Flatten() const {\n"
|
||||
<< " return std::tuple_cat(";
|
||||
first = true;
|
||||
std::vector<std::string> all_fields;
|
||||
for (auto& field : struct_type->fields()) {
|
||||
if (!first) {
|
||||
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 << ")";
|
||||
}
|
||||
CollectAllFields("", field, all_fields);
|
||||
}
|
||||
h_contents << "> Flatten() const {\n"
|
||||
" return std::make_tuple(";
|
||||
PrintCommaSeparatedList(h_contents, all_fields);
|
||||
h_contents << ");\n";
|
||||
h_contents << " }\n";
|
||||
h_contents << "};\n";
|
||||
|
Loading…
Reference in New Issue
Block a user