Roll back es2abc memory optimization

Issue: #IB4U6V

Signed-off-by: renguangxuan <renguangxuan@huawei.com>
Change-Id: I906027892e984b9b5b080cbfa64c59cfdbc55c40
This commit is contained in:
renguangxuan 2024-11-16 19:46:21 +08:00
parent a11fdfc43a
commit a9f4fe7394
11 changed files with 42 additions and 74 deletions

View File

@ -112,6 +112,7 @@ pandasm::Ins PandasmDumperUtils::DeepCopyIns(const pandasm::Ins &input)
auto &debug_ins = res.ins_debug;
debug_ins.line_number = input.ins_debug.line_number;
debug_ins.column_number = input.ins_debug.column_number;
debug_ins.whole_line = input.ins_debug.whole_line;
debug_ins.bound_left = input.ins_debug.bound_left;
debug_ins.bound_right = input.ins_debug.bound_right;
return res;

View File

@ -54,13 +54,10 @@ std::set<std::string> Abc2ProgramTestUtils::helloworld_expected_program_strings_
"toString",
"varA",
"x"};
std::vector<std::string> Abc2ProgramTestUtils::helloworld_expected_record_names_ = {
"_ESConcurrentModuleRequestsAnnotation",
"_ESModuleRecord",
"_ESSlotNumberAnnotation",
"_ESScopeNamesRecord",
"_GLOBAL"
};
std::vector<std::string> Abc2ProgramTestUtils::helloworld_expected_record_names_ = {"_ESModuleRecord",
"_ESSlotNumberAnnotation",
"_ESScopeNamesRecord",
"_GLOBAL"};
std::vector<std::string> Abc2ProgramTestUtils::helloworld_expected_literal_array_keys_ = {"_ESModuleRecord",
"_ESScopeNamesRecord",
"_GLOBAL",

View File

@ -26,10 +26,6 @@ _GLOBAL_1799 { 10 [ tag_value:2, i32:2, tag_value:5, string:"4newTarget", tag_va
# ====================
# RECORDS
.record _ESConcurrentModuleRequestsAnnotation {
}
.record.source_file
.record _ESModuleRecord {
u32 arkcompiler/runtime_core/abc2program/tests/ts/HelloWorld.ts _ESModuleRecord_3278
}

View File

@ -24,10 +24,6 @@ _GLOBAL_1584 { 10 [ tag_value:5, string:"NestedLiteralArray", tag_value:6, metho
# ====================
# RECORDS
.record _ESConcurrentModuleRequestsAnnotation {
}
.record.source_file
.record _ESModuleRecord {
u32 arkcompiler/runtime_core/abc2program/tests/ts/HelloWorld.ts _ESModuleRecord_1466
}

View File

@ -23,6 +23,7 @@ namespace panda::pandasm::debuginfo {
struct Ins {
size_t line_number = 0;
uint32_t column_number = 0;
std::string whole_line = ""; // TODO(mbolshov): redundant given file and line_number
size_t bound_left = 0;
size_t bound_right = 0;
@ -38,7 +39,7 @@ struct Ins {
Ins() = default;
Ins(size_t l_n, std::string &f_c, size_t b_l, size_t b_r)
: line_number(l_n), bound_left(b_l), bound_right(b_r)
: line_number(l_n), whole_line(std::move(f_c)), bound_left(b_l), bound_right(b_r)
{
}
};

View File

@ -1189,11 +1189,9 @@ bool AsmEmitter::AddMethodAndParamsAnnotations(ItemContainer *items, const Progr
auto &param_items = method->GetParams();
for (size_t proto_idx = 0; proto_idx < param_items.size(); proto_idx++) {
size_t param_idx = method->IsStatic() ? proto_idx : proto_idx + 1;
auto &param = func.params[param_idx];
auto &param_item = param_items[proto_idx];
// The ArkTs language does not collect this metadata data information.
// Thereore, this parameter is set to the default value to ensure code consistency and compatibility.
auto metadata = extensions::MetadataExtension::CreateParamMetadata(pandasm::extensions::Language::ECMASCRIPT);
if (!AddAnnotations(&param_item, items, *metadata, program, entities)) {
if (!AddAnnotations(&param_item, items, *param.metadata, program, entities)) {
SetLastError("Cannot emit annotations for parameter a" + std::to_string(param_idx) + "of function " +
func.name + ": " + GetLastError());
return false;
@ -1360,7 +1358,7 @@ bool AsmEmitter::MakeItemsForSingleProgram(ItemContainer *items, const Program &
}
// temp plan for ic slot number, should be deleted after method refactoring
void MakeSlotNumberRecord(Program *prog)
static void MakeSlotNumberRecord(Program *prog)
{
static const std::string SLOT_NUMBER = "_ESSlotNumberAnnotation";
pandasm::Record record(SLOT_NUMBER, pandasm::extensions::Language::ECMASCRIPT);
@ -1369,7 +1367,7 @@ void MakeSlotNumberRecord(Program *prog)
}
// temp plan for ic slot number, should be deleted after method refactoring
void MakeSlotNumberAnnotation(Program *prog)
static void MakeSlotNumberAnnotation(Program *prog)
{
static const std::string SLOT_NUMBER = "_ESSlotNumberAnnotation";
static const std::string ELEMENT_NAME = "SlotNumber";
@ -1389,7 +1387,7 @@ void MakeSlotNumberAnnotation(Program *prog)
}
}
void MakeConcurrentModuleRequestsRecord(Program *prog)
static void MakeConcurrentModuleRequestsRecord(Program *prog)
{
static const std::string CONCURRENT_MODULE_REQUESTS = "_ESConcurrentModuleRequestsAnnotation";
pandasm::Record record(CONCURRENT_MODULE_REQUESTS, pandasm::extensions::Language::ECMASCRIPT);
@ -1397,7 +1395,7 @@ void MakeConcurrentModuleRequestsRecord(Program *prog)
prog->record_table.emplace(CONCURRENT_MODULE_REQUESTS, std::move(record));
}
void MakeConcurrentModuleRequestsAnnotation(Program *prog)
static void MakeConcurrentModuleRequestsAnnotation(Program *prog)
{
static const std::string CONCURRENT_MODULE_REQUESTS = "_ESConcurrentModuleRequestsAnnotation";
static const std::string ELEMENT_NAME = "ConcurrentModuleRequest";
@ -1425,11 +1423,16 @@ void MakeConcurrentModuleRequestsAnnotation(Program *prog)
}
}
// The function releases the data in progs in advance for the sake of the peak memory at compiler time.
bool AsmEmitter::EmitPrograms(const std::string &filename, const std::vector<Program *> &progs, bool emit_debug_info,
uint8_t api, std::string subApi)
{
ASSERT(!progs.empty());
for (auto *prog : progs) {
MakeSlotNumberRecord(prog);
MakeSlotNumberAnnotation(prog);
MakeConcurrentModuleRequestsRecord(prog);
MakeConcurrentModuleRequestsAnnotation(prog);
}
ItemContainer::SetApi(api);
ItemContainer::SetSubApi(subApi);
@ -1438,31 +1441,25 @@ bool AsmEmitter::EmitPrograms(const std::string &filename, const std::vector<Pro
auto entities = AsmEmitter::AsmEntityCollections {};
SetLastError("");
for (auto *prog : progs) {
for (const auto *prog : progs) {
if (!MakeItemsForSingleProgram(&items, *prog, emit_debug_info, entities, primitive_types)) {
return false;
}
prog->strings.clear();
prog->literalarray_table.clear();
prog->array_types.clear();
}
for (auto *prog : progs) {
for (const auto *prog : progs) {
if (!MakeFunctionDebugInfoAndAnnotations(&items, *prog, entities, emit_debug_info)) {
return false;
}
prog->function_synonyms.clear();
}
items.ReLayout();
items.ComputeLayout();
for (auto *prog : progs) {
for (const auto *prog : progs) {
if (!EmitFunctions(&items, *prog, entities, emit_debug_info)) {
return false;
}
prog->function_table.clear();
prog->record_table.clear();
}
auto writer = FileWriter(filename);
@ -1478,6 +1475,8 @@ bool AsmEmitter::EmitPrograms(const std::string &filename, const std::vector<Pro
bool AsmEmitter::Emit(ItemContainer *items, const Program &program, PandaFileToPandaAsmMaps *maps, bool emit_debug_info,
panda::panda_file::pgo::ProfileOptimizer *profile_opt)
{
MakeSlotNumberRecord(const_cast<Program *>(&program));
MakeSlotNumberAnnotation(const_cast<Program *>(&program));
auto primitive_types = CreatePrimitiveTypes(items);
auto entities = AsmEmitter::AsmEntityCollections {};

View File

@ -31,12 +31,6 @@
#include "pgo.h"
namespace panda::pandasm {
void MakeConcurrentModuleRequestsAnnotation(Program *prog);
void MakeConcurrentModuleRequestsRecord(Program *prog);
void MakeSlotNumberAnnotation(Program *prog);
void MakeSlotNumberRecord(Program *prog);
class AsmEmitter {
public:
struct PandaFileToPandaAsmMaps {

View File

@ -61,9 +61,10 @@ struct Function {
struct Parameter {
Type type;
std::unique_ptr<ParamMetadata> metadata;
Parameter(Type t, panda::panda_file::SourceLang lang)
: type(std::move(t))
: type(std::move(t)), metadata(extensions::MetadataExtension::CreateParamMetadata(lang))
{
}
};

View File

@ -680,7 +680,7 @@ void Parser::ParseResetFunctionLabelsAndParams()
const auto &debug = curr_func_->ins[v.first - 1].ins_debug;
context_.err =
Error("Register width mismatch.", debug.line_number, Error::ErrorType::ERR_BAD_NAME_REG, "",
debug.bound_left, debug.bound_right, "");
debug.bound_left, debug.bound_right, debug.whole_line);
SetError();
break;
}
@ -714,7 +714,7 @@ void Parser::ParseResetFunctionTable()
const auto &debug = insn_it->ins_debug;
context_.err = Error("Unable to resolve ambiguous function call", debug.line_number,
Error::ErrorType::ERR_FUNCTION_MULTIPLE_ALTERNATIVES, "", debug.bound_left,
debug.bound_right, "");
debug.bound_right, debug.whole_line);
SetError();
break;
} else {
@ -731,7 +731,7 @@ void Parser::ParseResetFunctionTable()
const auto &debug = insn_it->ins_debug;
context_.err = Error("Function argument mismatch.", debug.line_number,
Error::ErrorType::ERR_FUNCTION_ARGUMENT_MISMATCH, "", debug.bound_left,
debug.bound_right, "");
debug.bound_right, debug.whole_line);
SetError();
}
}
@ -2077,6 +2077,7 @@ void Parser::SetOperationInformation()
context_.ins_number = curr_func_->ins.size();
auto &curr_debug = curr_func_->ins.back().ins_debug;
curr_debug.line_number = line_stric_;
curr_debug.whole_line = context_.tokens[context_.number - 1].whole_line;
curr_debug.bound_left = context_.tokens[context_.number - 1].bound_left;
curr_debug.bound_right = context_.tokens[context_.number - 1].bound_right;
}
@ -2147,6 +2148,7 @@ bool Parser::ParseFunctionArg()
++context_;
Function::Parameter parameter(type, program_.lang);
metadata_ = parameter.metadata.get();
if (*context_ == Token::Type::DEL_LT && !ParseMetaDef()) {
return false;

View File

@ -1009,7 +1009,6 @@ HWTEST_F(AssemblyEmitterTest, assembly_emitter_test_015, TestSize.Level1)
ScalarValue insn_order_anno(ScalarValue::Create<panda::pandasm::Value::Type::ANNOTATION>(annotation));
panda::pandasm::MakeSlotNumberRecord(&program.Value());
program.Value().record_table.at("R").field_list[0].metadata->SetValue(insn_order_anno);
auto pf4 = AsmEmitter::Emit(program.Value());
EXPECT_NE(pf4, nullptr);
@ -1199,15 +1198,14 @@ HWTEST_F(AssemblyEmitterTest, assembly_emitter_test_021, TestSize.Level1)
auto source = R"(
.function any foo(any a0) <noimpl>
)";
auto res = p.Parse(source);
EXPECT_EQ(p.ShowError().err, Error::ErrorType::ERR_NONE);
std::vector<Program *> progs;
progs.push_back(&res.Value());
// api 11
{
auto res = p.Parse(source);
EXPECT_EQ(p.ShowError().err, Error::ErrorType::ERR_NONE);
std::vector<Program *> progs;
progs.push_back(&res.Value());
std::string descriptor;
const std::string filename_api11 = "source_021_api11.abc";
auto is_emitted = AsmEmitter::EmitPrograms(filename_api11, progs, false, 11);
@ -1234,12 +1232,6 @@ HWTEST_F(AssemblyEmitterTest, assembly_emitter_test_021, TestSize.Level1)
// api 12
{
auto res = p.Parse(source);
EXPECT_EQ(p.ShowError().err, Error::ErrorType::ERR_NONE);
std::vector<Program *> progs;
progs.push_back(&res.Value());
std::string descriptor;
const std::string filename_api12 = "source_021_api12.abc";
auto is_emitted = AsmEmitter::EmitPrograms(filename_api12, progs, false, 12);

View File

@ -428,14 +428,8 @@ HWTEST_F(CodegenTest, codegen_test_012, TestSize.Level1)
BytecodeOptimizerRuntimeAdapter runtime_adapter(*pfile.get());
RuntimeInterface::MethodPtr caller = nullptr;
auto class_id = pfile->GetClassId(utf::CStringAsMutf8("L_GLOBAL;"));
EXPECT_TRUE(class_id.IsValid());
panda_file::ClassDataAccessor cda(*pfile.get(), class_id);
cda.EnumerateMethods([&](panda_file::MethodDataAccessor &mda) {
BytecodeOptimizerRuntimeAdapter::MethodId id = mda.GetMethodId().GetOffset();
EXPECT_EQ(runtime_adapter.GetMethodArgumentsCount(caller, id), 0);
});
BytecodeOptimizerRuntimeAdapter::MethodId id = 178; // foo method_id
EXPECT_EQ(runtime_adapter.GetMethodArgumentsCount(caller, id), 0);
}
/**
@ -456,16 +450,11 @@ HWTEST_F(CodegenTest, codegen_test_013, TestSize.Level1)
std::unique_ptr<const panda_file::File> pfile = ParseAndEmit(source);
BytecodeOptimizerRuntimeAdapter runtime_adapter(*pfile.get());
auto class_id = pfile->GetClassId(utf::CStringAsMutf8("L_GLOBAL;"));
EXPECT_TRUE(class_id.IsValid());
panda_file::ClassDataAccessor cda(*pfile.get(), class_id);
int f = 178; // foo method_id
RuntimeInterface::MethodPtr method;
method=(void*)(long)f;
cda.EnumerateMethods([&](panda_file::MethodDataAccessor &mda) {
BytecodeOptimizerRuntimeAdapter::MethodId id = mda.GetMethodId().GetOffset();
RuntimeInterface::MethodPtr method;
method=(void*)(long)id;
EXPECT_EQ(runtime_adapter.GetMethodFullName(method, false), "L_GLOBAL;::foo");
});
EXPECT_EQ(runtime_adapter.GetMethodFullName(method, false), "L_GLOBAL;::foo");
}
/**