!2149 Implement re-layout of abc file items

Merge pull request !2149 from huyunhui/file_items
This commit is contained in:
openharmony_ci 2024-08-19 09:46:46 +00:00 committed by Gitee
commit e72547ff1c
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 53 additions and 0 deletions

View File

@ -1453,6 +1453,7 @@ bool AsmEmitter::EmitPrograms(const std::string &filename, const std::vector<Pro
}
}
items.ReLayout();
items.ComputeLayout();
for (const auto *prog : progs) {

View File

@ -406,6 +406,40 @@ void ItemContainer::DeduplicateItems(bool computeLayout)
DeduplicateAnnotations();
}
static bool Compare(const std::unique_ptr<BaseItem> &item1, const std::unique_ptr<BaseItem> &item2)
{
return item1->GetReLayoutRank() > item2->GetReLayoutRank();
}
void ItemContainer::ReLayout()
{
for (auto &item : items_) {
if (!item->NeedsEmit()) {
continue;
}
/* Because only class items and func_main_0 will be accessed in runtime's initialization,
* the items in abc will be arranged in following order to increase cache hit rate:
* class items -> string items(for field name) -> other items
*/
switch (item->GetItemType()) {
case ItemTypes::CLASS_ITEM: {
item->SetReLayoutRank(ItemRank::CLASS_ITEM_RANK);
break;
}
case ItemTypes::STRING_ITEM: {
item->SetReLayoutRank(ItemRank::STRING_ITEM_RANK);
break;
}
default: {
break;
}
}
}
items_.sort(Compare);
}
uint32_t ItemContainer::ComputeLayout()
{
uint32_t original_offset = 0;

View File

@ -104,6 +104,7 @@ public:
return ret;
}
void ReLayout();
uint32_t ComputeLayout();
bool Write(Writer *writer, bool deduplicateItems = true);

View File

@ -84,6 +84,12 @@ enum class FunctionKind : uint8_t {
SENDABLE_FUNCTION = 1 << 3
};
enum class ItemRank : uint8_t {
DEFAULT_RANK = 0x0,
STRING_ITEM_RANK = 0x1,
CLASS_ITEM_RANK = 0x2
};
bool IsDynamicLanguage(panda::panda_file::SourceLang lang);
std::optional<panda::panda_file::SourceLang> LanguageFromString(const std::string_view &lang);
const char *LanguageToString(panda::panda_file::SourceLang lang);
@ -273,6 +279,16 @@ public:
return original_rank_;
}
void SetReLayoutRank(ItemRank rank)
{
re_layout_rank_ = rank;
}
ItemRank GetReLayoutRank() const
{
return re_layout_rank_;
}
private:
bool needs_emit_ {true};
uint32_t offset_ {0};
@ -280,6 +296,7 @@ private:
std::list<IndexedItem *> index_deps_;
uint32_t pgo_rank_ {0};
uint32_t original_rank_ {0};
ItemRank re_layout_rank_ {ItemRank::DEFAULT_RANK};
};
class IndexedItem : public BaseItem {