From 3dea38532f9312e6305e1b3b19400bb5b2a464b4 Mon Sep 17 00:00:00 2001 From: luobohua Date: Sun, 10 Aug 2025 10:35:46 +0800 Subject: [PATCH] use bitfield to save 8B for every CallExpression Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICS787 Change-Id: I8c9301a3bac2e41c31ddcc61d59ef41cf3d38f77 Signed-off-by: luobohua --- ets2panda/ir/expressions/callExpression.cpp | 34 ++++++++++----------- ets2panda/ir/expressions/callExpression.h | 28 ++++++++--------- 2 files changed, 30 insertions(+), 32 deletions(-) diff --git a/ets2panda/ir/expressions/callExpression.cpp b/ets2panda/ir/expressions/callExpression.cpp index c0619e941d..a265516733 100644 --- a/ets2panda/ir/expressions/callExpression.cpp +++ b/ets2panda/ir/expressions/callExpression.cpp @@ -41,10 +41,10 @@ void CallExpression::TransformChildren(const NodeTransformer &cb, std::string_vi } } - if (trailingLambdaInfo_.block != nullptr) { - if (auto *transformedNode = cb(trailingLambdaInfo_.block); trailingLambdaInfo_.block != transformedNode) { - trailingLambdaInfo_.block->SetTransformedNode(transformationName, transformedNode); - trailingLambdaInfo_.block = transformedNode->AsBlockStatement(); + if (trailingBlock_ != nullptr) { + if (auto *transformedNode = cb(trailingBlock_); trailingBlock_ != transformedNode) { + trailingBlock_->SetTransformedNode(transformationName, transformedNode); + trailingBlock_ = transformedNode->AsBlockStatement(); } } } @@ -61,8 +61,8 @@ void CallExpression::Iterate(const NodeTraverser &cb) const cb(it); } - if (trailingLambdaInfo_.block != nullptr) { - cb(trailingLambdaInfo_.block); + if (trailingBlock_ != nullptr) { + cb(trailingBlock_); } } @@ -96,11 +96,11 @@ void CallExpression::Dump(ir::SrcDumper *dumper) const } } dumper->Add(")"); - if (trailingLambdaInfo_.block != nullptr) { - if (trailingLambdaInfo_.isBlockInNewLine) { + if (trailingBlock_ != nullptr) { + if (callFlags_.isBlockInNewLine) { dumper->Endl(); } - trailingLambdaInfo_.block->Dump(dumper); + trailingBlock_->Dump(dumper); } } @@ -128,9 +128,8 @@ CallExpression::CallExpression(CallExpression const &other, ArenaAllocator *cons : MaybeOptionalExpression(static_cast(other)), arguments_(allocator->Adapter()), signature_(other.signature_), - trailingComma_(other.trailingComma_), - trailingLambdaInfo_({other.trailingLambdaInfo_.block, other.trailingLambdaInfo_.isBlockInNewLine, - other.trailingLambdaInfo_.isTrailingCall}) + trailingBlock_(nullptr), + callFlags_(other.callFlags_) { callee_ = other.callee_->Clone(allocator, this)->AsExpression(); typeParams_ = other.typeParams_ != nullptr ? other.typeParams_->Clone(allocator, this) : nullptr; @@ -139,9 +138,8 @@ CallExpression::CallExpression(CallExpression const &other, ArenaAllocator *cons arguments_.emplace_back(argument->Clone(allocator, this)->AsExpression()); } - trailingLambdaInfo_.block = other.trailingLambdaInfo_.block != nullptr - ? other.trailingLambdaInfo_.block->Clone(allocator, this)->AsBlockStatement() - : nullptr; + trailingBlock_ = + other.trailingBlock_ != nullptr ? other.trailingBlock_->Clone(allocator, this)->AsBlockStatement() : nullptr; } CallExpression *CallExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) @@ -166,9 +164,9 @@ void CallExpression::SetTypeParams(TSTypeParameterInstantiation *typeParams) noe void CallExpression::SetTrailingBlock(ir::BlockStatement *const block) noexcept { - trailingLambdaInfo_.block = block; - if (trailingLambdaInfo_.block != nullptr) { - trailingLambdaInfo_.block->SetParent(this); + trailingBlock_ = block; + if (trailingBlock_ != nullptr) { + trailingBlock_->SetParent(this); } } diff --git a/ets2panda/ir/expressions/callExpression.h b/ets2panda/ir/expressions/callExpression.h index 36d3e3be58..ba9b53b82f 100644 --- a/ets2panda/ir/expressions/callExpression.h +++ b/ets2panda/ir/expressions/callExpression.h @@ -50,7 +50,7 @@ public: callee_(callee), arguments_(std::move(arguments)), typeParams_(typeParams), - trailingComma_(trailingComma) + callFlags_ {trailingComma, false, false, 0} { } @@ -100,7 +100,7 @@ public: [[nodiscard]] bool HasTrailingComma() const noexcept { - return trailingComma_; + return callFlags_.trailingComma; } [[nodiscard]] checker::Signature *Signature() noexcept @@ -136,27 +136,27 @@ public: [[nodiscard]] ir::BlockStatement *TrailingBlock() const noexcept { - return trailingLambdaInfo_.block; + return trailingBlock_; } void SetIsTrailingBlockInNewLine(bool const isNewLine) noexcept { - trailingLambdaInfo_.isBlockInNewLine = isNewLine; + callFlags_.isBlockInNewLine = isNewLine; } [[nodiscard]] bool IsTrailingBlockInNewLine() const noexcept { - return trailingLambdaInfo_.isBlockInNewLine; + return callFlags_.isBlockInNewLine; } void SetIsTrailingCall(bool const isTrailingCall) noexcept { - trailingLambdaInfo_.isTrailingCall = isTrailingCall; + callFlags_.isTrailingCall = isTrailingCall; } [[nodiscard]] bool IsTrailingCall() const noexcept { - return trailingLambdaInfo_.isTrailingCall; + return callFlags_.isTrailingCall; } bool IsETSConstructorCall() const noexcept @@ -191,10 +191,11 @@ public: } private: - struct TrailingLambdaInfo { - ir::BlockStatement *block {nullptr}; - bool isTrailingCall {false}; - bool isBlockInNewLine {false}; + struct CallFlags { + bool trailingComma : 1; + bool isTrailingCall : 1; + bool isBlockInNewLine : 1; + unsigned reserved : 5; }; protected: @@ -203,10 +204,9 @@ protected: ArenaVector arguments_; TSTypeParameterInstantiation *typeParams_; checker::Signature *signature_ {}; - bool trailingComma_; - // for trailing lambda feature in ets - TrailingLambdaInfo trailingLambdaInfo_ {}; + ir::BlockStatement *trailingBlock_ = nullptr; checker::Type *uncheckedType_ {}; + CallFlags callFlags_ {}; // NOLINTEND(misc-non-private-member-variables-in-classes) }; } // namespace ark::es2panda::ir -- Gitee