PGO AssertType

Issues: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I8AT6D?from=project-issue
Signed-off-by: liuzhijie <jay.lau2020.work@outlook.com>

Change-Id: I9595a32942956e9a38cf7c6f89b6631087195ec7
This commit is contained in:
liuzhijie 2023-10-25 15:42:55 +08:00
parent 1d5894abf4
commit e9ce337360
34 changed files with 1168 additions and 852 deletions

View File

@ -182,7 +182,10 @@ group("ark_runtime_host_unittest") {
deps = []
if (host_os != "mac") {
# js unittest
deps += [ ":ark_unittest" ]
deps += [
":ark_unittest",
"$js_root/test/typeinfer:ark_pgotypeinfer_test",
]
# js bytecode test
deps += [ "$js_root/test/moduletest:ark_js_moduletest" ]

View File

@ -443,4 +443,11 @@ JSTaggedValue BuiltinsArkTools::Gc([[maybe_unused]] EcmaRuntimeCallInfo *info)
LOG_ECMA(INFO) << "Enter Gc()";
return JSTaggedValue::Undefined();
}
} // namespace panda::ecmascript::builtins
// empty function for pgoAssertType
JSTaggedValue BuiltinsArkTools::PGOAssertType([[maybe_unused]] EcmaRuntimeCallInfo *info)
{
LOG_ECMA(INFO) << "Enter PGOAssertType";
return JSTaggedValue::Undefined();
}
} // namespace panda::ecmascript::builtins

View File

@ -37,6 +37,7 @@
V("isRegExpReplaceDetectorValid", IsRegExpReplaceDetectorValid, 0, INVALID) \
V("isSymbolIteratorDetectorValid", IsSymbolIteratorDetectorValid, 1, INVALID) \
V("isTSHClass", IsTSHClass, 1, INVALID) \
V("pgoAssertType", PGOAssertType, 2, INVALID) \
V("print", ObjectDump, 0, INVALID) \
V("removeAOTFlag", RemoveAOTFlag, 1, INVALID) \
V("timeInUs", TimeInUs, 0, INVALID)
@ -138,6 +139,8 @@ public:
static JSTaggedValue Gc(EcmaRuntimeCallInfo *info);
static JSTaggedValue PGOAssertType(EcmaRuntimeCallInfo *info);
static Span<const base::BuiltinFunctionEntry> GetArkToolsFunctions()
{
return Span<const base::BuiltinFunctionEntry>(ARK_TOOLS_FUNCTIONS);

View File

@ -106,7 +106,6 @@ ohos_source_set("libark_jsoptimizer_set") {
"later_elimination.cpp",
"lcr_circuit_builder.cpp",
"lcr_gate_meta_data.cpp",
"lcr_lowering.cpp",
"lexical_env_specialization.cpp",
"llvm_codegen.cpp",
"llvm_ir_builder.cpp",
@ -114,9 +113,10 @@ ohos_source_set("libark_jsoptimizer_set") {
"loop_peeling.cpp",
"mcr_circuit_builder.cpp",
"mcr_gate_meta_data.cpp",
"mcr_lowering.cpp",
"new_object_stub_builder.cpp",
"ntype_bytecode_lowering.cpp",
"ntype_hcr_lowering.cpp",
"ntype_mcr_lowering.cpp",
"number_speculative_lowering.cpp",
"number_speculative_retype.cpp",
"number_speculative_runner.cpp",
@ -143,16 +143,16 @@ ohos_source_set("libark_jsoptimizer_set") {
"trampoline/x64/optimized_fast_call.cpp",
"ts_class_analysis.cpp",
"ts_hclass_generator.cpp",
"ts_hcr_lowering.cpp",
"ts_hcr_opt_pass.cpp",
"ts_inline_lowering.cpp",
"type.cpp",
"type_bytecode_lowering.cpp",
"type_hcr_lowering.cpp",
"type_inference/global_type_infer.cpp",
"type_inference/initialization_analysis.cpp",
"type_inference/method_type_infer.cpp",
"type_inference/pgo_type_infer.cpp",
"type_inference/pgo_type_infer_helper.cpp",
"type_mcr_lowering.cpp",
"type_recorder.cpp",
"typed_array_stub_builder.cpp",
"value_numbering.cpp",

View File

@ -40,10 +40,10 @@ class BuiltinsStringStubBuilder;
class CompilationConfig;
class Environment;
class Label;
class NTypeHCRLowering;
class NTypeBytecodeLowering;
class SlowPathLowering;
class StubBuilder;
class TSHCRLowering;
class TypeBytecodeLowering;
class Variable;
#define BINARY_ARITHMETIC_METHOD_LIST_WITH_BITWIDTH(V) \
@ -696,8 +696,8 @@ private:
CompilationConfig *cmpCfg_ {nullptr};
friend StubBuilder;
friend BuiltinsStringStubBuilder;
friend TSHCRLowering;
friend NTypeHCRLowering;
friend TypeBytecodeLowering;
friend NTypeBytecodeLowering;
friend SlowPathLowering;
};

View File

@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ecmascript/compiler/lcr_lowering.h"
#include "ecmascript/compiler/mcr_lowering.h"
#include "ecmascript/compiler/bytecodes.h"
#include "ecmascript/compiler/share_gate_meta_data.h"
#include "ecmascript/global_env.h"
@ -21,7 +21,7 @@
namespace panda::ecmascript::kungfu {
GateRef LCRLowering::VisitGate(GateRef gate)
GateRef MCRLowering::VisitGate(GateRef gate)
{
auto op = acc_.GetOpCode(gate);
switch (op) {
@ -97,7 +97,7 @@ GateRef LCRLowering::VisitGate(GateRef gate)
return Circuit::NullGate();
}
void LCRLowering::LowerConvertHoleAsUndefined(GateRef gate)
void MCRLowering::LowerConvertHoleAsUndefined(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
@ -116,7 +116,7 @@ void LCRLowering::LowerConvertHoleAsUndefined(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), *result);
}
void LCRLowering::LowerLoadConstOffset(GateRef gate)
void MCRLowering::LowerLoadConstOffset(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
GateRef receiver = acc_.GetValueIn(gate, 0);
@ -126,7 +126,7 @@ void LCRLowering::LowerLoadConstOffset(GateRef gate)
acc_.ReplaceGate(gate, Circuit::NullGate(), builder_.GetDepend(), result);
}
void LCRLowering::LowerStoreConstOffset(GateRef gate)
void MCRLowering::LowerStoreConstOffset(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
@ -138,7 +138,7 @@ void LCRLowering::LowerStoreConstOffset(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), Circuit::NullGate());
}
void LCRLowering::LowerHeapObjectCheck(GateRef gate)
void MCRLowering::LowerHeapObjectCheck(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
GateRef frameState = acc_.GetFrameState(gate);
@ -150,7 +150,7 @@ void LCRLowering::LowerHeapObjectCheck(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), Circuit::NullGate());
}
void LCRLowering::LowerGetConstPool(GateRef gate)
void MCRLowering::LowerGetConstPool(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
GateRef jsFunc = acc_.GetValueIn(gate, 0); // 0: this object
@ -162,7 +162,7 @@ void LCRLowering::LowerGetConstPool(GateRef gate)
acc_.DeleteGate(gate);
}
void LCRLowering::DeleteStateSplit(GateRef gate)
void MCRLowering::DeleteStateSplit(GateRef gate)
{
auto depend = acc_.GetDep(gate);
auto frameState = acc_.GetFrameState(gate);
@ -170,7 +170,7 @@ void LCRLowering::DeleteStateSplit(GateRef gate)
acc_.ReplaceGate(gate, Circuit::NullGate(), depend, Circuit::NullGate());
}
void LCRLowering::LowerArrayGuardianCheck(GateRef gate)
void MCRLowering::LowerArrayGuardianCheck(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
@ -182,7 +182,7 @@ void LCRLowering::LowerArrayGuardianCheck(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), Circuit::NullGate());
}
void LCRLowering::LowerHClassStableArrayCheck(GateRef gate)
void MCRLowering::LowerHClassStableArrayCheck(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
GateRef frameState = acc_.GetFrameState(gate);
@ -210,7 +210,7 @@ void LCRLowering::LowerHClassStableArrayCheck(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), Circuit::NullGate());
}
StateDepend LCRLowering::LowerConvert(StateDepend stateDepend, GateRef gate)
StateDepend MCRLowering::LowerConvert(StateDepend stateDepend, GateRef gate)
{
Environment env(stateDepend.State(), stateDepend.Depend(), {}, circuit_, &builder_);
GateRef value = acc_.GetValueIn(gate);
@ -278,7 +278,7 @@ StateDepend LCRLowering::LowerConvert(StateDepend stateDepend, GateRef gate)
return builder_.GetStateDepend();
}
GateRef LCRLowering::ConvertTaggedNumberToBool(GateRef gate, Label *exit)
GateRef MCRLowering::ConvertTaggedNumberToBool(GateRef gate, Label *exit)
{
DEFVAlUE(result, (&builder_), VariableType::BOOL(), builder_.Boolean(false));
Label isInt(&builder_);
@ -301,7 +301,7 @@ GateRef LCRLowering::ConvertTaggedNumberToBool(GateRef gate, Label *exit)
return *result;
}
GateRef LCRLowering::ConvertTaggedNumberToInt32(GateRef gate, Label *exit)
GateRef MCRLowering::ConvertTaggedNumberToInt32(GateRef gate, Label *exit)
{
DEFVAlUE(result, (&builder_), VariableType::INT32(), builder_.Int32(0));
Label isInt(&builder_);
@ -318,7 +318,7 @@ GateRef LCRLowering::ConvertTaggedNumberToInt32(GateRef gate, Label *exit)
return *result;
}
GateRef LCRLowering::ConvertTaggedNumberToFloat64(GateRef gate, Label *exit)
GateRef MCRLowering::ConvertTaggedNumberToFloat64(GateRef gate, Label *exit)
{
DEFVAlUE(result, (&builder_), VariableType::FLOAT64(), builder_.Double(0));
Label isInt(&builder_);
@ -334,7 +334,7 @@ GateRef LCRLowering::ConvertTaggedNumberToFloat64(GateRef gate, Label *exit)
return *result;
}
void LCRLowering::LowerCheckAndConvert(GateRef gate)
void MCRLowering::LowerCheckAndConvert(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
GateRef frameState = acc_.GetFrameState(gate);
@ -370,7 +370,7 @@ void LCRLowering::LowerCheckAndConvert(GateRef gate)
}
}
void LCRLowering::LowerCheckUInt32AndConvert(GateRef gate, GateRef frameState)
void MCRLowering::LowerCheckUInt32AndConvert(GateRef gate, GateRef frameState)
{
GateRef value = acc_.GetValueIn(gate, 0);
GateRef upperBound = builder_.Int32(INT32_MAX);
@ -379,7 +379,7 @@ void LCRLowering::LowerCheckUInt32AndConvert(GateRef gate, GateRef frameState)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), value);
}
void LCRLowering::LowerCheckTaggedIntAndConvert(GateRef gate, GateRef frameState)
void MCRLowering::LowerCheckTaggedIntAndConvert(GateRef gate, GateRef frameState)
{
GateRef value = acc_.GetValueIn(gate, 0);
GateRef typeCheck = builder_.TaggedIsInt(value);
@ -395,7 +395,7 @@ void LCRLowering::LowerCheckTaggedIntAndConvert(GateRef gate, GateRef frameState
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), result);
}
void LCRLowering::LowerCheckTaggedDoubleAndConvert(GateRef gate, GateRef frameState, Label *exit)
void MCRLowering::LowerCheckTaggedDoubleAndConvert(GateRef gate, GateRef frameState, Label *exit)
{
GateRef value = acc_.GetValueIn(gate, 0);
GateRef typeCheck = builder_.TaggedIsDouble(value);
@ -411,7 +411,7 @@ void LCRLowering::LowerCheckTaggedDoubleAndConvert(GateRef gate, GateRef frameSt
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), result);
}
void LCRLowering::LowerCheckTaggedNumberAndConvert(GateRef gate, GateRef frameState, Label *exit)
void MCRLowering::LowerCheckTaggedNumberAndConvert(GateRef gate, GateRef frameState, Label *exit)
{
GateRef value = acc_.GetValueIn(gate, 0);
GateRef typeCheck = builder_.TaggedIsNumber(value);
@ -429,7 +429,7 @@ void LCRLowering::LowerCheckTaggedNumberAndConvert(GateRef gate, GateRef frameSt
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), result);
}
void LCRLowering::LowerCheckSupportAndConvert(GateRef gate, GateRef frameState)
void MCRLowering::LowerCheckSupportAndConvert(GateRef gate, GateRef frameState)
{
ValueType dstType = acc_.GetDstType(gate);
ASSERT(dstType == ValueType::INT32 || dstType == ValueType::FLOAT64);
@ -447,7 +447,7 @@ void LCRLowering::LowerCheckSupportAndConvert(GateRef gate, GateRef frameState)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), result);
}
void LCRLowering::LowerCheckTaggedBoolAndConvert(GateRef gate, GateRef frameState)
void MCRLowering::LowerCheckTaggedBoolAndConvert(GateRef gate, GateRef frameState)
{
GateRef value = acc_.GetValueIn(gate, 0);
GateRef typeCheck = builder_.TaggedIsBoolean(value);
@ -466,7 +466,7 @@ void LCRLowering::LowerCheckTaggedBoolAndConvert(GateRef gate, GateRef frameStat
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), result);
}
void LCRLowering::LowerCheckNullAndConvert(GateRef gate, GateRef frameState)
void MCRLowering::LowerCheckNullAndConvert(GateRef gate, GateRef frameState)
{
GateRef value = acc_.GetValueIn(gate, 0);
GateRef typeCheck = builder_.TaggedIsNull(value);
@ -484,7 +484,7 @@ void LCRLowering::LowerCheckNullAndConvert(GateRef gate, GateRef frameState)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), result);
}
void LCRLowering::LowerUndefinedAndConvert(GateRef gate, GateRef frameState)
void MCRLowering::LowerUndefinedAndConvert(GateRef gate, GateRef frameState)
{
GateRef value = acc_.GetValueIn(gate, 0);
GateRef typeCheck = builder_.TaggedIsUndefined(value);
@ -502,32 +502,32 @@ void LCRLowering::LowerUndefinedAndConvert(GateRef gate, GateRef frameState)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), result);
}
GateRef LCRLowering::ConvertTaggedBooleanToBool(GateRef value)
GateRef MCRLowering::ConvertTaggedBooleanToBool(GateRef value)
{
return builder_.TaggedIsTrue(value);
}
GateRef LCRLowering::ConvertBoolToTaggedBoolean(GateRef gate)
GateRef MCRLowering::ConvertBoolToTaggedBoolean(GateRef gate)
{
return builder_.BooleanToTaggedBooleanPtr(gate);
}
GateRef LCRLowering::ConvertInt32ToFloat64(GateRef gate)
GateRef MCRLowering::ConvertInt32ToFloat64(GateRef gate)
{
return builder_.ChangeInt32ToFloat64(gate);
}
GateRef LCRLowering::ConvertUInt32ToFloat64(GateRef gate)
GateRef MCRLowering::ConvertUInt32ToFloat64(GateRef gate)
{
return builder_.ChangeUInt32ToFloat64(gate);
}
GateRef LCRLowering::ConvertInt32ToTaggedInt(GateRef gate)
GateRef MCRLowering::ConvertInt32ToTaggedInt(GateRef gate)
{
return builder_.Int32ToTaggedPtr(gate);
}
GateRef LCRLowering::ConvertUInt32ToTaggedNumber(GateRef gate, Label *exit)
GateRef MCRLowering::ConvertUInt32ToTaggedNumber(GateRef gate, Label *exit)
{
Label isOverFlow(&builder_);
Label notOverFlow(&builder_);
@ -544,44 +544,44 @@ GateRef LCRLowering::ConvertUInt32ToTaggedNumber(GateRef gate, Label *exit)
return *taggedVal;
}
GateRef LCRLowering::ConvertFloat64ToInt32(GateRef gate, Label *exit)
GateRef MCRLowering::ConvertFloat64ToInt32(GateRef gate, Label *exit)
{
return builder_.DoubleToInt(gate, exit);
}
GateRef LCRLowering::ConvertFloat64ToBool(GateRef gate)
GateRef MCRLowering::ConvertFloat64ToBool(GateRef gate)
{
GateRef doubleNotZero = builder_.DoubleNotEqual(gate, builder_.Double(0.0));
GateRef doubleNotNAN = builder_.BoolNot(builder_.DoubleIsNAN(gate));
return builder_.BoolAnd(doubleNotZero, doubleNotNAN);
}
GateRef LCRLowering::ConvertFloat64ToTaggedDouble(GateRef gate)
GateRef MCRLowering::ConvertFloat64ToTaggedDouble(GateRef gate)
{
return builder_.DoubleToTaggedDoublePtr(gate);
}
GateRef LCRLowering::ConvertTaggedIntToInt32(GateRef gate)
GateRef MCRLowering::ConvertTaggedIntToInt32(GateRef gate)
{
return builder_.GetInt32OfTInt(gate);
}
GateRef LCRLowering::ConvertTaggedIntToFloat64(GateRef gate)
GateRef MCRLowering::ConvertTaggedIntToFloat64(GateRef gate)
{
return builder_.ChangeInt32ToFloat64(builder_.GetInt32OfTInt(gate));
}
GateRef LCRLowering::ConvertTaggedDoubleToInt32(GateRef gate, Label *exit)
GateRef MCRLowering::ConvertTaggedDoubleToInt32(GateRef gate, Label *exit)
{
return builder_.DoubleToInt(builder_.GetDoubleOfTDouble(gate), exit);
}
GateRef LCRLowering::ConvertTaggedDoubleToFloat64(GateRef gate)
GateRef MCRLowering::ConvertTaggedDoubleToFloat64(GateRef gate)
{
return builder_.GetDoubleOfTDouble(gate);
}
void LCRLowering::LowerGetGlobalEnv(GateRef gate)
void MCRLowering::LowerGetGlobalEnv(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
GateRef glueGlobalEnvOffset = builder_.IntPtr(JSThread::GlueData::GetGlueGlobalEnvOffset(false));
@ -589,7 +589,7 @@ void LCRLowering::LowerGetGlobalEnv(GateRef gate)
acc_.ReplaceGate(gate, Circuit::NullGate(), builder_.GetDepend(), glueGlobalEnv);
}
void LCRLowering::LowerGetGlobalEnvObj(GateRef gate)
void MCRLowering::LowerGetGlobalEnvObj(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
GateRef globalEnv = acc_.GetValueIn(gate, 0);
@ -599,7 +599,7 @@ void LCRLowering::LowerGetGlobalEnvObj(GateRef gate)
acc_.ReplaceGate(gate, Circuit::NullGate(), builder_.GetDepend(), object);
}
void LCRLowering::LowerGetGlobalEnvObjHClass(GateRef gate)
void MCRLowering::LowerGetGlobalEnvObjHClass(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
GateRef globalEnv = acc_.GetValueIn(gate, 0);
@ -611,7 +611,7 @@ void LCRLowering::LowerGetGlobalEnvObjHClass(GateRef gate)
acc_.ReplaceGate(gate, Circuit::NullGate(), builder_.GetDepend(), hclass);
}
void LCRLowering::LowerGetGlobalConstantValue(GateRef gate)
void MCRLowering::LowerGetGlobalConstantValue(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
size_t index = acc_.GetIndex(gate);
@ -622,7 +622,7 @@ void LCRLowering::LowerGetGlobalConstantValue(GateRef gate)
acc_.ReplaceGate(gate, Circuit::NullGate(), builder_.GetDepend(), result);
}
void LCRLowering::LowerHeapAllocate(GateRef gate)
void MCRLowering::LowerHeapAllocate(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
auto flag = acc_.TryGetValue(gate);
@ -636,7 +636,7 @@ void LCRLowering::LowerHeapAllocate(GateRef gate)
}
}
void LCRLowering::HeapAllocateInYoung(GateRef gate)
void MCRLowering::HeapAllocateInYoung(GateRef gate)
{
Label exit(&builder_);
GateRef size = acc_.GetValueIn(gate, 0);
@ -671,7 +671,7 @@ void LCRLowering::HeapAllocateInYoung(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), *result);
}
void LCRLowering::LowerInt32CheckRightIsZero(GateRef gate)
void MCRLowering::LowerInt32CheckRightIsZero(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
GateRef frameState = acc_.GetFrameState(gate);
@ -681,7 +681,7 @@ void LCRLowering::LowerInt32CheckRightIsZero(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), Circuit::NullGate());
}
void LCRLowering::LowerFloat64CheckRightIsZero(GateRef gate)
void MCRLowering::LowerFloat64CheckRightIsZero(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
GateRef frameState = acc_.GetFrameState(gate);
@ -691,7 +691,7 @@ void LCRLowering::LowerFloat64CheckRightIsZero(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), Circuit::NullGate());
}
void LCRLowering::LowerLexVarIsHoleCheck(GateRef gate)
void MCRLowering::LowerLexVarIsHoleCheck(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
GateRef frameState = acc_.GetFrameState(gate);
@ -701,7 +701,7 @@ void LCRLowering::LowerLexVarIsHoleCheck(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), Circuit::NullGate());
}
void LCRLowering::LowerValueCheckNegOverflow(GateRef gate)
void MCRLowering::LowerValueCheckNegOverflow(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
GateRef frameState = acc_.GetFrameState(gate);
@ -711,7 +711,7 @@ void LCRLowering::LowerValueCheckNegOverflow(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), Circuit::NullGate());
}
void LCRLowering::LowerOverflowCheck(GateRef gate)
void MCRLowering::LowerOverflowCheck(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
GateRef frameState = acc_.GetFrameState(gate);
@ -721,7 +721,7 @@ void LCRLowering::LowerOverflowCheck(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), Circuit::NullGate());
}
void LCRLowering::LowerInt32UnsignedUpperBoundCheck(GateRef gate)
void MCRLowering::LowerInt32UnsignedUpperBoundCheck(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
GateRef frameState = acc_.GetFrameState(gate);
@ -732,7 +732,7 @@ void LCRLowering::LowerInt32UnsignedUpperBoundCheck(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), Circuit::NullGate());
}
void LCRLowering::LowerInt32DivWithCheck(GateRef gate)
void MCRLowering::LowerInt32DivWithCheck(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
GateRef frameState = acc_.GetFrameState(gate);
@ -752,7 +752,7 @@ void LCRLowering::LowerInt32DivWithCheck(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), result);
}
void LCRLowering::LowerStoreMemory(GateRef gate)
void MCRLowering::LowerStoreMemory(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
GateRef receiver = acc_.GetValueIn(gate, 0);
@ -762,7 +762,7 @@ void LCRLowering::LowerStoreMemory(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), Circuit::NullGate());
}
void LCRLowering::InitializeWithSpeicalValue(Label *exit, GateRef object, GateRef glue,
void MCRLowering::InitializeWithSpeicalValue(Label *exit, GateRef object, GateRef glue,
GateRef value, GateRef start, GateRef end)
{
Label begin(&builder_);

View File

@ -13,8 +13,8 @@
* limitations under the License.
*/
#ifndef ECMASCRIPT_COMPILER_LCR_LOWERING_H
#define ECMASCRIPT_COMPILER_LCR_LOWERING_H
#ifndef ECMASCRIPT_COMPILER_MCR_LOWERING_H
#define ECMASCRIPT_COMPILER_MCR_LOWERING_H
#include "ecmascript/compiler/circuit.h"
#include "ecmascript/compiler/circuit_builder-inl.h"
@ -23,14 +23,14 @@
namespace panda::ecmascript::kungfu {
class LCRLowering : public PassVisitor {
class MCRLowering : public PassVisitor {
public:
LCRLowering(Circuit *circuit, RPOVisitor *visitor, CompilationConfig *cmpCfg, Chunk *chunk)
MCRLowering(Circuit *circuit, RPOVisitor *visitor, CompilationConfig *cmpCfg, Chunk *chunk)
: PassVisitor(circuit, chunk, visitor), circuit_(circuit), acc_(circuit),
builder_(circuit, cmpCfg), glue_(acc_.GetGlueFromArgList())
{
}
~LCRLowering() = default;
~MCRLowering() = default;
GateRef VisitGate(GateRef gate) override;
StateDepend LowerConvert(StateDepend stateDepend, GateRef gate);
@ -93,4 +93,4 @@ private:
GateRef glue_ {Circuit::NullGate()};
};
} // panda::ecmascript::kungfu
#endif // ECMASCRIPT_COMPILER_LCR_LOWERING_H
#endif // ECMASCRIPT_COMPILER_MCR_LOWERING_H

View File

@ -0,0 +1,304 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ecmascript/compiler/ntype_bytecode_lowering.h"
#include "ecmascript/compiler/circuit_builder-inl.h"
#include "ecmascript/dfx/vmstat/opt_code_profiler.h"
namespace panda::ecmascript::kungfu {
void NTypeBytecodeLowering::RunNTypeBytecodeLowering()
{
std::vector<GateRef> gateList;
circuit_->GetAllGates(gateList);
for (const auto &gate : gateList) {
auto op = acc_.GetOpCode(gate);
if (op == OpCode::JS_BYTECODE) {
Lower(gate);
}
}
if (IsLogEnabled()) {
LOG_COMPILER(INFO) << "";
LOG_COMPILER(INFO) << "\033[34m"
<< "===================="
<< " After NTypeBytecodeLowering "
<< "[" << GetMethodName() << "]"
<< "===================="
<< "\033[0m";
circuit_->PrintAllGatesWithBytecode();
LOG_COMPILER(INFO) << "\033[34m" << "========================= End ==========================" << "\033[0m";
}
}
void NTypeBytecodeLowering::Lower(GateRef gate)
{
EcmaOpcode ecmaOpcode = acc_.GetByteCodeOpcode(gate);
// initialize label manager
Environment env(gate, circuit_, &builder_);
switch (ecmaOpcode) {
case EcmaOpcode::CREATEEMPTYARRAY_IMM8:
case EcmaOpcode::CREATEEMPTYARRAY_IMM16:
LowerNTypedCreateEmptyArray(gate);
break;
case EcmaOpcode::CREATEARRAYWITHBUFFER_IMM8_ID16:
case EcmaOpcode::CREATEARRAYWITHBUFFER_IMM16_ID16:
LowerNTypedCreateArrayWithBuffer(gate);
break;
case EcmaOpcode::STOWNBYINDEX_IMM8_V8_IMM16:
case EcmaOpcode::STOWNBYINDEX_IMM16_V8_IMM16:
case EcmaOpcode::WIDE_STOWNBYINDEX_PREF_V8_IMM32:
LowerNTypedStownByIndex(gate);
break;
case EcmaOpcode::STOWNBYNAME_IMM8_ID16_V8:
case EcmaOpcode::STOWNBYNAME_IMM16_ID16_V8:
LowerNTypedStOwnByName(gate);
break;
case EcmaOpcode::THROW_UNDEFINEDIFHOLEWITHNAME_PREF_ID16:
LowerThrowUndefinedIfHoleWithName(gate);
break;
case EcmaOpcode::LDLEXVAR_IMM4_IMM4:
case EcmaOpcode::LDLEXVAR_IMM8_IMM8:
case EcmaOpcode::WIDE_LDLEXVAR_PREF_IMM16_IMM16:
LowerLdLexVar(gate);
break;
case EcmaOpcode::STLEXVAR_IMM4_IMM4:
case EcmaOpcode::STLEXVAR_IMM8_IMM8:
case EcmaOpcode::WIDE_STLEXVAR_PREF_IMM16_IMM16:
LowerStLexVar(gate);
break;
default:
break;
}
}
void NTypeBytecodeLowering::LowerThrowUndefinedIfHoleWithName(GateRef gate)
{
GateRef value = acc_.GetValueIn(gate, 1); // 1: the second parameter
builder_.LexVarIsHoleCheck(value);
acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), Circuit::NullGate());
}
void NTypeBytecodeLowering::LowerLdLexVar(GateRef gate)
{
AddProfiling(gate);
GateRef level = acc_.GetValueIn(gate, 0); // 0: first parameter
GateRef index = acc_.GetValueIn(gate, 1); // 1: the second parameter
GateRef currentEnv = acc_.GetValueIn(gate, 2); // 2: the third parameter
uint32_t levelValue = static_cast<uint32_t>(acc_.GetConstantValue(level));
uint32_t indexValue = static_cast<uint32_t>(acc_.GetConstantValue(index));
indexValue += LexicalEnv::RESERVED_ENV_LENGTH;
GateRef result = Circuit::NullGate();
if (levelValue == 0) {
result = builder_.LoadFromTaggedArray(currentEnv, indexValue);
} else if (levelValue == 1) { // 1: level 1
auto parentEnv = builder_.LoadFromTaggedArray(currentEnv, LexicalEnv::PARENT_ENV_INDEX);
result = builder_.LoadFromTaggedArray(parentEnv, indexValue);
} else {
// level > 1, go slowpath
return;
}
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), result);
}
void NTypeBytecodeLowering::LowerStLexVar(GateRef gate)
{
AddProfiling(gate);
GateRef level = acc_.GetValueIn(gate, 0); // 0: first parameter
GateRef index = acc_.GetValueIn(gate, 1); // 1: the second parameter
GateRef currentEnv = acc_.GetValueIn(gate, 2); // 2: the third parameter
GateRef value = acc_.GetValueIn(gate, 3); // 3: the fourth parameter
uint32_t levelValue = static_cast<uint32_t>(acc_.GetConstantValue(level));
uint32_t indexValue = static_cast<uint32_t>(acc_.GetConstantValue(index));
indexValue += LexicalEnv::RESERVED_ENV_LENGTH;
GateRef result = Circuit::NullGate();
if (levelValue == 0) {
result = builder_.StoreToTaggedArray(currentEnv, indexValue, value);
} else if (levelValue == 1) { // 1: level 1
auto parentEnv = builder_.LoadFromTaggedArray(currentEnv, LexicalEnv::PARENT_ENV_INDEX);
result = builder_.StoreToTaggedArray(parentEnv, indexValue, value);
} else {
// level > 1, go slowpath
return;
}
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), result);
}
void NTypeBytecodeLowering::LowerNTypedCreateEmptyArray(GateRef gate)
{
// in the future, the type of the elements in the array will be obtained through pgo,
// and the type will be used to determine whether to create a typed-array.
AddProfiling(gate);
auto thread = tsManager_->GetEcmaVM()->GetJSThread();
uint64_t bcAbsoluteOffset = GetBcAbsoluteOffset(gate);
ElementsKind kind = acc_.TryGetElementsKind(gate);
auto hclassIdx = thread->GetArrayHClassIndexMap().at(kind);
tsManager_->AddArrayTSConstantIndex(bcAbsoluteOffset, JSTaggedValue(static_cast<int64_t>(hclassIdx)));
GateRef array = builder_.CreateArray(kind, 0);
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), array);
}
void NTypeBytecodeLowering::LowerNTypedCreateArrayWithBuffer(GateRef gate)
{
// 1: number of value inputs
ASSERT(acc_.GetNumValueIn(gate) == 1);
GateRef index = acc_.GetValueIn(gate, 0);
auto thread = tsManager_->GetEcmaVM()->GetJSThread();
uint64_t bcAbsoluteOffset = GetBcAbsoluteOffset(gate);
uint32_t cpIdx = static_cast<uint32_t>(acc_.GetConstantValue(index));
JSHandle<ConstantPool> constpoolHandle(tsManager_->GetConstantPool());
JSTaggedValue arr = ConstantPool::GetLiteralFromCache<ConstPoolType::ARRAY_LITERAL>(
thread, constpoolHandle.GetTaggedValue(), cpIdx, recordName_);
JSHandle<JSArray> arrayHandle(thread, arr);
ElementsKind kind = acc_.TryGetElementsKind(gate);
auto hclassIdx = thread->GetArrayHClassIndexMap().at(kind);
GateType gateType = acc_.GetGateType(gate);
panda_file::File::EntityId id = ConstantPool::GetIdFromCache(constpoolHandle.GetTaggedValue(), cpIdx);
tsManager_->AddArrayTSConstantIndex(bcAbsoluteOffset, JSTaggedValue(static_cast<int64_t>(hclassIdx)));
tsManager_->AddArrayTSElements(id, arrayHandle->GetElements());
tsManager_->AddArrayTSElementsKind(id, JSTaggedValue(static_cast<int64_t>(kind)));
gateType = tsManager_->TryNarrowUnionType(gateType);
int elementIndex = -1;
if (tsManager_->IsArrayTypeKind(gateType)) {
elementIndex = tsManager_->GetElementsIndexByArrayType(gateType, id);
}
if (elementIndex == -1) { // slowpath
return;
}
AddProfiling(gate);
GateRef elementIndexGate = builder_.IntPtr(elementIndex);
GateRef array = builder_.CreateArrayWithBuffer(kind, ArrayMetaDataAccessor::Mode::CREATE, index, elementIndexGate);
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), array);
}
void NTypeBytecodeLowering::LowerNTypedStownByIndex(GateRef gate)
{
// 3: number of value inputs
ASSERT(acc_.GetNumValueIn(gate) == 3);
GateRef receiver = acc_.GetValueIn(gate, 0);
GateRef index = acc_.GetValueIn(gate, 1);
GateRef value = acc_.GetValueIn(gate, 2);
if (acc_.GetOpCode(receiver) != OpCode::CREATE_ARRAY &&
acc_.GetOpCode(receiver) != OpCode::CREATE_ARRAY_WITH_BUFFER) {
return;
}
builder_.COWArrayCheck(receiver);
AddProfiling(gate);
uint32_t indexValue = static_cast<uint32_t>(acc_.GetConstantValue(index));
uint32_t arraySize = acc_.GetArraySize(receiver);
if (indexValue > arraySize) {
acc_.TrySetElementsKind(receiver, ElementsKind::HOLE);
}
acc_.SetArraySize(receiver, std::max(arraySize, indexValue + 1));
index = builder_.Int32(indexValue);
builder_.StoreElement<TypedStoreOp::ARRAY_STORE_ELEMENT>(receiver, index, value);
acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), Circuit::NullGate());
}
void NTypeBytecodeLowering::LowerNTypedStOwnByName(GateRef gate)
{
// 3: number of value inputs
ASSERT(acc_.GetNumValueIn(gate) == 3);
auto constData = acc_.GetValueIn(gate, 0);
uint16_t propIndex = acc_.GetConstantValue(constData);
auto thread = tsManager_->GetEcmaVM()->GetJSThread();
auto propKey = tsManager_->GetStringFromConstantPool(propIndex);
GateRef receiver = acc_.GetValueIn(gate, 1);
GateRef value = acc_.GetValueIn(gate, 2);
GateType receiverType = acc_.GetGateType(receiver);
receiverType = tsManager_->TryNarrowUnionType(receiverType);
int hclassIndex = -1;
if (tsManager_->IsObjectTypeKind(receiverType)) {
hclassIndex = tsManager_->GetHClassIndexByObjectType(receiverType);
}
if (hclassIndex == -1) { // slowpath
return;
}
JSHClass *hclass = JSHClass::Cast(tsManager_->GetValueFromCache(hclassIndex).GetTaggedObject());
PropertyLookupResult plr = JSHClass::LookupPropertyInAotHClass(thread, hclass, propKey);
if (!plr.IsFound() || !plr.IsLocal() || plr.IsAccessor() || !plr.IsWritable()) { // slowpath
return;
}
AddProfiling(gate);
GateRef pfrGate = builder_.Int32(plr.GetData());
builder_.StoreProperty(receiver, pfrGate, value);
acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), Circuit::NullGate());
}
uint64_t NTypeBytecodeLowering::GetBcAbsoluteOffset(GateRef gate) const
{
uint64_t pcOffset = acc_.TryGetPcOffset(gate);
uint64_t pfOffset = reinterpret_cast<uint64_t>(jsPandaFile_->GetHeader());
uint64_t methodOffset = reinterpret_cast<uint64_t>(methodLiteral_->GetBytecodeArray());
uint64_t bcAbsoluteOffset = methodOffset - pfOffset + pcOffset;
return bcAbsoluteOffset;
}
void NTypeBytecodeLowering::AddProfiling(GateRef gate)
{
if (IsTraceBC()) {
// see stateSplit as a part of JSByteCode if exists
GateRef maybeStateSplit = acc_.GetDep(gate);
GateRef current = Circuit::NullGate();
if (acc_.GetOpCode(maybeStateSplit) == OpCode::STATE_SPLIT) {
current = maybeStateSplit;
} else {
current = gate;
}
EcmaOpcode ecmaOpcode = acc_.GetByteCodeOpcode(gate);
auto ecmaOpcodeGate = builder_.Int32(static_cast<uint32_t>(ecmaOpcode));
GateRef constOpcode = builder_.Int32ToTaggedInt(ecmaOpcodeGate);
GateRef typedPath = builder_.Int32ToTaggedInt(builder_.Int32(1));
GateRef traceGate = builder_.CallRuntime(glue_, RTSTUB_ID(DebugAOTPrint), acc_.GetDep(current),
{ constOpcode, typedPath }, gate);
acc_.SetDep(current, traceGate);
builder_.SetDepend(acc_.GetDep(gate)); // set gate depend: trace or STATE_SPLIT
}
if (IsProfiling()) {
// see stateSplit as a part of JSByteCode if exists
GateRef maybeStateSplit = acc_.GetDep(gate);
GateRef current = Circuit::NullGate();
if (acc_.GetOpCode(maybeStateSplit) == OpCode::STATE_SPLIT) {
current = maybeStateSplit;
} else {
current = gate;
}
EcmaOpcode ecmaOpcode = acc_.GetByteCodeOpcode(gate);
auto ecmaOpcodeGate = builder_.Int32(static_cast<uint32_t>(ecmaOpcode));
GateRef constOpcode = builder_.Int32ToTaggedInt(ecmaOpcodeGate);
GateRef mode =
builder_.Int32ToTaggedInt(builder_.Int32(static_cast<int32_t>(OptCodeProfiler::Mode::TYPED_PATH)));
GateRef profiling = builder_.CallRuntime(glue_, RTSTUB_ID(ProfileOptimizedCode), acc_.GetDep(current),
{ constOpcode, mode }, gate);
acc_.SetDep(current, profiling);
builder_.SetDepend(acc_.GetDep(gate)); // set gate depend: profiling or STATE_SPLIT
}
}
}

View File

@ -13,64 +13,80 @@
* limitations under the License.
*/
#ifndef ECMASCRIPT_COMPILER_NTYPE_MCR_LOWERING_H
#define ECMASCRIPT_COMPILER_NTYPE_MCR_LOWERING_H
#ifndef ECMASCRIPT_COMPILER_NTYPE_BYTECODE_LOWERING_H
#define ECMASCRIPT_COMPILER_NTYPE_BYTECODE_LOWERING_H
#include "ecmascript/compiler/argument_accessor.h"
#include "ecmascript/compiler/builtins/builtins_call_signature.h"
#include "ecmascript/compiler/bytecode_circuit_builder.h"
#include "ecmascript/compiler/circuit_builder-inl.h"
#include "ecmascript/compiler/combined_pass_visitor.h"
#include "ecmascript/compiler/pass_manager.h"
namespace panda::ecmascript::kungfu {
class NTypeMCRLowering : public PassVisitor {
class NTypeBytecodeLowering {
public:
NTypeMCRLowering(Circuit *circuit, RPOVisitor *visitor, PassContext *ctx, const CString &recordName, Chunk* chunk)
: PassVisitor(circuit, chunk, visitor),
circuit_(circuit),
NTypeBytecodeLowering(Circuit *circuit, PassContext *ctx, TSManager *tsManager, const MethodLiteral *methodLiteral,
const CString &recordName, bool enableLog, const std::string& name)
: circuit_(circuit),
acc_(circuit),
builder_(circuit, ctx->GetCompilerConfig()),
dependEntry_(circuit->GetDependRoot()),
tsManager_(ctx->GetTSManager()),
recordName_(recordName),
tsManager_(tsManager),
jsPandaFile_(ctx->GetJSPandaFile()),
methodLiteral_(methodLiteral),
enableLog_(enableLog),
profiling_(ctx->GetCompilerConfig()->IsProfiling()),
traceBc_(ctx->GetCompilerConfig()->IsTraceBC()),
methodName_(name),
glue_(acc_.GetGlueFromArgList()) {}
~NTypeMCRLowering() = default;
GateRef VisitGate(GateRef gate) override;
~NTypeBytecodeLowering() = default;
void RunNTypeBytecodeLowering();
private:
static constexpr int MAX_TAGGED_ARRAY_LENGTH = 50;
void Lower(GateRef gate);
void LowerCreateArray(GateRef gate, GateRef glue);
void LowerCreateArrayWithBuffer(GateRef gate, GateRef glue);
void LowerCreateEmptyArray(GateRef gate);
void LowerCreateArrayWithOwn(GateRef gate, GateRef glue);
void LowerStLexVar(GateRef gate);
void LowerNTypedCreateEmptyArray(GateRef gate);
void LowerNTypedCreateArrayWithBuffer(GateRef gate);
void LowerNTypedStownByIndex(GateRef gate);
void LowerNTypedStOwnByName(GateRef gate);
void LowerLdLexVar(GateRef gate);
void LowerStLexVar(GateRef gate);
void LowerThrowUndefinedIfHoleWithName(GateRef gate);
uint64_t GetBcAbsoluteOffset(GateRef gate) const;
GateRef LoadFromConstPool(GateRef jsFunc, size_t index);
GateRef NewJSArrayLiteral(GateRef gate, GateRef elements, GateRef length);
GateRef NewTaggedArray(size_t length);
GateRef CreateElementsWithLength(GateRef gate, GateRef glue, size_t arrayLength);
GateRef LowerCallRuntime(GateRef glue, GateRef hirGate, int index, const std::vector<GateRef> &args,
bool useLabel = false);
GateRef GetFrameState(GateRef gate) const
bool IsLogEnabled() const
{
return acc_.GetFrameState(gate);
return enableLog_;
}
bool IsProfiling() const
{
return profiling_;
}
bool IsTraceBC() const
{
return traceBc_;
}
const std::string& GetMethodName() const
{
return methodName_;
}
void AddProfiling(GateRef gate);
Circuit *circuit_ {nullptr};
GateAccessor acc_;
CircuitBuilder builder_;
GateRef dependEntry_;
TSManager *tsManager_ {nullptr};
const CString &recordName_;
panda_file::File::EntityId methodId_ {0};
TSManager *tsManager_ {nullptr};
const JSPandaFile *jsPandaFile_ {nullptr};
const MethodLiteral *methodLiteral_ {nullptr};
bool enableLog_ {false};
bool profiling_ {false};
bool traceBc_ {false};
std::string methodName_;
GateRef glue_ {Circuit::NullGate()};
};
} // panda::ecmascript::kungfu
#endif // ECMASCRIPT_COMPILER_NTYPE_MCR_LOWERING_H
#endif // ECMASCRIPT_COMPILER_NTYPE_BYTECODE_LOWERING_H

View File

@ -14,291 +14,186 @@
*/
#include "ecmascript/compiler/ntype_hcr_lowering.h"
#include "ecmascript/compiler/circuit_builder-inl.h"
#include "ecmascript/dfx/vmstat/opt_code_profiler.h"
#include "ecmascript/compiler/new_object_stub_builder.h"
namespace panda::ecmascript::kungfu {
void NTypeHCRLowering::RunNTypeHCRLowering()
GateRef NTypeHCRLowering::VisitGate(GateRef gate)
{
std::vector<GateRef> gateList;
circuit_->GetAllGates(gateList);
for (const auto &gate : gateList) {
auto op = acc_.GetOpCode(gate);
if (op == OpCode::JS_BYTECODE) {
Lower(gate);
}
}
if (IsLogEnabled()) {
LOG_COMPILER(INFO) << "";
LOG_COMPILER(INFO) << "\033[34m"
<< "===================="
<< " After NTypeHCRlowering "
<< "[" << GetMethodName() << "]"
<< "===================="
<< "\033[0m";
circuit_->PrintAllGatesWithBytecode();
LOG_COMPILER(INFO) << "\033[34m" << "========================= End ==========================" << "\033[0m";
}
}
void NTypeHCRLowering::Lower(GateRef gate)
{
EcmaOpcode ecmaOpcode = acc_.GetByteCodeOpcode(gate);
// initialize label manager
Environment env(gate, circuit_, &builder_);
switch (ecmaOpcode) {
case EcmaOpcode::CREATEEMPTYARRAY_IMM8:
case EcmaOpcode::CREATEEMPTYARRAY_IMM16:
LowerNTypedCreateEmptyArray(gate);
GateRef glue = acc_.GetGlueFromArgList();
auto op = acc_.GetOpCode(gate);
switch (op) {
case OpCode::CREATE_ARRAY:
LowerCreateArray(gate, glue);
break;
case EcmaOpcode::CREATEARRAYWITHBUFFER_IMM8_ID16:
case EcmaOpcode::CREATEARRAYWITHBUFFER_IMM16_ID16:
LowerNTypedCreateArrayWithBuffer(gate);
break;
case EcmaOpcode::STOWNBYINDEX_IMM8_V8_IMM16:
case EcmaOpcode::STOWNBYINDEX_IMM16_V8_IMM16:
case EcmaOpcode::WIDE_STOWNBYINDEX_PREF_V8_IMM32:
LowerNTypedStownByIndex(gate);
break;
case EcmaOpcode::STOWNBYNAME_IMM8_ID16_V8:
case EcmaOpcode::STOWNBYNAME_IMM16_ID16_V8:
LowerNTypedStOwnByName(gate);
break;
case EcmaOpcode::THROW_UNDEFINEDIFHOLEWITHNAME_PREF_ID16:
LowerThrowUndefinedIfHoleWithName(gate);
break;
case EcmaOpcode::LDLEXVAR_IMM4_IMM4:
case EcmaOpcode::LDLEXVAR_IMM8_IMM8:
case EcmaOpcode::WIDE_LDLEXVAR_PREF_IMM16_IMM16:
LowerLdLexVar(gate);
break;
case EcmaOpcode::STLEXVAR_IMM4_IMM4:
case EcmaOpcode::STLEXVAR_IMM8_IMM8:
case EcmaOpcode::WIDE_STLEXVAR_PREF_IMM16_IMM16:
LowerStLexVar(gate);
case OpCode::CREATE_ARRAY_WITH_BUFFER:
LowerCreateArrayWithBuffer(gate, glue);
break;
default:
break;
}
return Circuit::NullGate();
}
void NTypeHCRLowering::LowerThrowUndefinedIfHoleWithName(GateRef gate)
void NTypeHCRLowering::LowerCreateArray(GateRef gate, GateRef glue)
{
GateRef value = acc_.GetValueIn(gate, 1); // 1: the second parameter
builder_.LexVarIsHoleCheck(value);
acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), Circuit::NullGate());
}
void NTypeHCRLowering::LowerLdLexVar(GateRef gate)
{
AddProfiling(gate);
GateRef level = acc_.GetValueIn(gate, 0); // 0: first parameter
GateRef index = acc_.GetValueIn(gate, 1); // 1: the second parameter
GateRef currentEnv = acc_.GetValueIn(gate, 2); // 2: the third parameter
uint32_t levelValue = static_cast<uint32_t>(acc_.GetConstantValue(level));
uint32_t indexValue = static_cast<uint32_t>(acc_.GetConstantValue(index));
indexValue += LexicalEnv::RESERVED_ENV_LENGTH;
GateRef result = Circuit::NullGate();
if (levelValue == 0) {
result = builder_.LoadFromTaggedArray(currentEnv, indexValue);
} else if (levelValue == 1) { // 1: level 1
auto parentEnv = builder_.LoadFromTaggedArray(currentEnv, LexicalEnv::PARENT_ENV_INDEX);
result = builder_.LoadFromTaggedArray(parentEnv, indexValue);
Environment env(gate, circuit_, &builder_);
if (acc_.GetArraySize(gate) == 0) {
LowerCreateEmptyArray(gate);
} else {
// level > 1, go slowpath
return;
LowerCreateArrayWithOwn(gate, glue);
}
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), result);
}
void NTypeHCRLowering::LowerStLexVar(GateRef gate)
void NTypeHCRLowering::LowerCreateEmptyArray(GateRef gate)
{
AddProfiling(gate);
GateRef level = acc_.GetValueIn(gate, 0); // 0: first parameter
GateRef index = acc_.GetValueIn(gate, 1); // 1: the second parameter
GateRef currentEnv = acc_.GetValueIn(gate, 2); // 2: the third parameter
GateRef value = acc_.GetValueIn(gate, 3); // 3: the fourth parameter
GateRef length = builder_.Int32(0);
GateRef elements = builder_.GetGlobalConstantValue(ConstantIndex::EMPTY_ARRAY_OBJECT_INDEX);
uint32_t levelValue = static_cast<uint32_t>(acc_.GetConstantValue(level));
uint32_t indexValue = static_cast<uint32_t>(acc_.GetConstantValue(index));
indexValue += LexicalEnv::RESERVED_ENV_LENGTH;
GateRef result = Circuit::NullGate();
if (levelValue == 0) {
result = builder_.StoreToTaggedArray(currentEnv, indexValue, value);
} else if (levelValue == 1) { // 1: level 1
auto parentEnv = builder_.LoadFromTaggedArray(currentEnv, LexicalEnv::PARENT_ENV_INDEX);
result = builder_.StoreToTaggedArray(parentEnv, indexValue, value);
} else {
// level > 1, go slowpath
return;
}
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), result);
}
void NTypeHCRLowering::LowerNTypedCreateEmptyArray(GateRef gate)
{
// in the future, the type of the elements in the array will be obtained through pgo,
// and the type will be used to determine whether to create a typed-array.
AddProfiling(gate);
auto thread = tsManager_->GetEcmaVM()->GetJSThread();
uint64_t bcAbsoluteOffset = GetBcAbsoluteOffset(gate);
ElementsKind kind = acc_.TryGetElementsKind(gate);
auto hclassIdx = thread->GetArrayHClassIndexMap().at(kind);
tsManager_->AddArrayTSConstantIndex(bcAbsoluteOffset, JSTaggedValue(static_cast<int64_t>(hclassIdx)));
GateRef array = builder_.CreateArray(kind, 0);
auto array = NewJSArrayLiteral(gate, elements, length);
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), array);
}
void NTypeHCRLowering::LowerNTypedCreateArrayWithBuffer(GateRef gate)
void NTypeHCRLowering::LowerCreateArrayWithOwn(GateRef gate, GateRef glue)
{
// 1: number of value inputs
ASSERT(acc_.GetNumValueIn(gate) == 1);
uint32_t elementsLength = acc_.GetArraySize(gate);
GateRef length = builder_.IntPtr(elementsLength);
GateRef elements = CreateElementsWithLength(gate, glue, elementsLength);
auto array = NewJSArrayLiteral(gate, elements, length);
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), array);
}
void NTypeHCRLowering::LowerCreateArrayWithBuffer(GateRef gate, GateRef glue)
{
Environment env(gate, circuit_, &builder_);
// 2: number of value inputs
ASSERT(acc_.GetNumValueIn(gate) == 2);
GateRef index = acc_.GetValueIn(gate, 0);
GateRef aotElmIndex = acc_.GetValueIn(gate, 1);
auto elementIndex = acc_.GetConstantValue(aotElmIndex);
uint32_t constPoolIndex = static_cast<uint32_t>(acc_.GetConstantValue(index));
ArgumentAccessor argAcc(circuit_);
GateRef frameState = GetFrameState(gate);
GateRef jsFunc = argAcc.GetFrameArgsIn(frameState, FrameArgIdx::FUNC);
GateRef literialElements = LoadFromConstPool(jsFunc, elementIndex);
auto thread = tsManager_->GetEcmaVM()->GetJSThread();
uint64_t bcAbsoluteOffset = GetBcAbsoluteOffset(gate);
uint32_t cpIdx = static_cast<uint32_t>(acc_.GetConstantValue(index));
JSHandle<ConstantPool> constpoolHandle(tsManager_->GetConstantPool());
JSTaggedValue arr = ConstantPool::GetLiteralFromCache<ConstPoolType::ARRAY_LITERAL>(
thread, constpoolHandle.GetTaggedValue(), cpIdx, recordName_);
thread, constpoolHandle.GetTaggedValue(), constPoolIndex, recordName_);
JSHandle<JSArray> arrayHandle(thread, arr);
ElementsKind kind = acc_.TryGetElementsKind(gate);
auto hclassIdx = thread->GetArrayHClassIndexMap().at(kind);
GateType gateType = acc_.GetGateType(gate);
panda_file::File::EntityId id = ConstantPool::GetIdFromCache(constpoolHandle.GetTaggedValue(), cpIdx);
tsManager_->AddArrayTSConstantIndex(bcAbsoluteOffset, JSTaggedValue(static_cast<int64_t>(hclassIdx)));
tsManager_->AddArrayTSElements(id, arrayHandle->GetElements());
tsManager_->AddArrayTSElementsKind(id, JSTaggedValue(static_cast<int64_t>(kind)));
gateType = tsManager_->TryNarrowUnionType(gateType);
int elementIndex = -1;
if (tsManager_->IsArrayTypeKind(gateType)) {
elementIndex = tsManager_->GetElementsIndexByArrayType(gateType, id);
}
if (elementIndex == -1) { // slowpath
return;
TaggedArray *arrayLiteral = TaggedArray::Cast(arrayHandle->GetElements());
uint32_t literialLength = arrayLiteral->GetLength();
uint32_t arrayLength = acc_.GetArraySize(gate);
GateRef elements = Circuit::NullGate();
GateRef length = Circuit::NullGate();
if (arrayLength > literialLength) {
elements = CreateElementsWithLength(gate, glue, arrayLength);
for (uint32_t i = 0; i < literialLength; i++) {
GateRef value = builder_.LoadFromTaggedArray(literialElements, i);
builder_.StoreToTaggedArray(elements, i, value);
}
length = builder_.IntPtr(arrayLength);
} else {
elements = literialElements;
length = builder_.IntPtr(literialLength);
}
AddProfiling(gate);
GateRef elementIndexGate = builder_.IntPtr(elementIndex);
GateRef array = builder_.CreateArrayWithBuffer(kind, ArrayMetaDataAccessor::Mode::CREATE, index, elementIndexGate);
auto array = NewJSArrayLiteral(gate, elements, length);
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), array);
}
void NTypeHCRLowering::LowerNTypedStownByIndex(GateRef gate)
GateRef NTypeHCRLowering::LoadFromConstPool(GateRef jsFunc, size_t index)
{
// 3: number of value inputs
ASSERT(acc_.GetNumValueIn(gate) == 3);
GateRef receiver = acc_.GetValueIn(gate, 0);
GateRef index = acc_.GetValueIn(gate, 1);
GateRef value = acc_.GetValueIn(gate, 2);
if (acc_.GetOpCode(receiver) != OpCode::CREATE_ARRAY &&
acc_.GetOpCode(receiver) != OpCode::CREATE_ARRAY_WITH_BUFFER) {
return;
}
builder_.COWArrayCheck(receiver);
AddProfiling(gate);
uint32_t indexValue = static_cast<uint32_t>(acc_.GetConstantValue(index));
uint32_t arraySize = acc_.GetArraySize(receiver);
if (indexValue > arraySize) {
acc_.TrySetElementsKind(receiver, ElementsKind::HOLE);
}
acc_.SetArraySize(receiver, std::max(arraySize, indexValue + 1));
index = builder_.Int32(indexValue);
builder_.StoreElement<TypedStoreOp::ARRAY_STORE_ELEMENT>(receiver, index, value);
acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), Circuit::NullGate());
GateRef constPool = builder_.GetConstPool(jsFunc);
return builder_.LoadFromTaggedArray(constPool, index);
}
void NTypeHCRLowering::LowerNTypedStOwnByName(GateRef gate)
GateRef NTypeHCRLowering::CreateElementsWithLength(GateRef gate, GateRef glue, size_t arrayLength)
{
// 3: number of value inputs
ASSERT(acc_.GetNumValueIn(gate) == 3);
auto constData = acc_.GetValueIn(gate, 0);
uint16_t propIndex = acc_.GetConstantValue(constData);
auto thread = tsManager_->GetEcmaVM()->GetJSThread();
auto propKey = tsManager_->GetStringFromConstantPool(propIndex);
GateRef receiver = acc_.GetValueIn(gate, 1);
GateRef value = acc_.GetValueIn(gate, 2);
GateType receiverType = acc_.GetGateType(receiver);
receiverType = tsManager_->TryNarrowUnionType(receiverType);
int hclassIndex = -1;
if (tsManager_->IsObjectTypeKind(receiverType)) {
hclassIndex = tsManager_->GetHClassIndexByObjectType(receiverType);
GateRef elements = Circuit::NullGate();
GateRef length = builder_.IntPtr(arrayLength);
if (arrayLength < MAX_TAGGED_ARRAY_LENGTH) {
elements = NewTaggedArray(arrayLength);
} else {
elements = LowerCallRuntime(glue, gate, RTSTUB_ID(NewTaggedArray), { builder_.Int32ToTaggedInt(length) }, true);
}
if (hclassIndex == -1) { // slowpath
return;
}
JSHClass *hclass = JSHClass::Cast(tsManager_->GetValueFromCache(hclassIndex).GetTaggedObject());
PropertyLookupResult plr = JSHClass::LookupPropertyInAotHClass(thread, hclass, propKey);
if (!plr.IsFound() || !plr.IsLocal() || plr.IsAccessor() || !plr.IsWritable()) { // slowpath
return;
}
AddProfiling(gate);
GateRef pfrGate = builder_.Int32(plr.GetData());
builder_.StoreProperty(receiver, pfrGate, value);
acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), Circuit::NullGate());
return elements;
}
uint64_t NTypeHCRLowering::GetBcAbsoluteOffset(GateRef gate) const
GateRef NTypeHCRLowering::NewJSArrayLiteral(GateRef gate, GateRef elements, GateRef length)
{
uint64_t pcOffset = acc_.TryGetPcOffset(gate);
uint64_t pfOffset = reinterpret_cast<uint64_t>(jsPandaFile_->GetHeader());
uint64_t methodOffset = reinterpret_cast<uint64_t>(methodLiteral_->GetBytecodeArray());
uint64_t bcAbsoluteOffset = methodOffset - pfOffset + pcOffset;
return bcAbsoluteOffset;
ElementsKind kind = acc_.GetArrayMetaDataAccessor(gate).GetElementsKind();
GateRef hclass = Circuit::NullGate();
if (!Elements::IsGeneric(kind)) {
auto thread = tsManager_->GetEcmaVM()->GetJSThread();
auto hclassIndex = thread->GetArrayHClassIndexMap().at(kind);
hclass = builder_.GetGlobalConstantValue(hclassIndex);
} else {
GateRef globalEnv = builder_.GetGlobalEnv();
hclass = builder_.GetGlobalEnvObjHClass(globalEnv, GlobalEnv::ARRAY_FUNCTION_INDEX);
}
JSHandle<JSFunction> arrayFunc(tsManager_->GetEcmaVM()->GetGlobalEnv()->GetArrayFunction());
JSTaggedValue protoOrHClass = arrayFunc->GetProtoOrHClass();
JSHClass *arrayHC = JSHClass::Cast(protoOrHClass.GetTaggedObject());
size_t arraySize = arrayHC->GetObjectSize();
size_t lengthAccessorOffset = arrayHC->GetInlinedPropertiesOffset(JSArray::LENGTH_INLINE_PROPERTY_INDEX);
GateRef emptyArray = builder_.GetGlobalConstantValue(ConstantIndex::EMPTY_ARRAY_OBJECT_INDEX);
GateRef accessor = builder_.GetGlobalConstantValue(ConstantIndex::ARRAY_LENGTH_ACCESSOR);
GateRef size = builder_.IntPtr(arrayHC->GetObjectSize());
builder_.StartAllocate();
GateRef array = builder_.HeapAlloc(size, GateType::TaggedValue(), RegionSpaceFlag::IN_YOUNG_SPACE);
// initialization
for (size_t offset = JSArray::SIZE; offset < arraySize; offset += JSTaggedValue::TaggedTypeSize()) {
builder_.StoreConstOffset(VariableType::INT64(), array, offset, builder_.Undefined());
}
builder_.StoreConstOffset(VariableType::JS_POINTER(), array, 0, hclass);
builder_.StoreConstOffset(VariableType::INT64(), array, ECMAObject::HASH_OFFSET,
builder_.Int64(JSTaggedValue(0).GetRawData()));
builder_.StoreConstOffset(VariableType::JS_POINTER(), array, JSObject::PROPERTIES_OFFSET, emptyArray);
builder_.StoreConstOffset(VariableType::JS_POINTER(), array, JSObject::ELEMENTS_OFFSET, elements);
builder_.StoreConstOffset(VariableType::INT32(), array, JSArray::LENGTH_OFFSET, length);
builder_.StoreConstOffset(VariableType::JS_POINTER(), array, lengthAccessorOffset, accessor);
builder_.StoreConstOffset(VariableType::INT64(), array, JSArray::TRACK_INFO_OFFSET, builder_.Undefined());
builder_.FinishAllocate();
return array;
}
void NTypeHCRLowering::AddProfiling(GateRef gate)
GateRef NTypeHCRLowering::NewTaggedArray(size_t length)
{
if (IsTraceBC()) {
// see stateSplit as a part of JSByteCode if exists
GateRef maybeStateSplit = acc_.GetDep(gate);
GateRef current = Circuit::NullGate();
if (acc_.GetOpCode(maybeStateSplit) == OpCode::STATE_SPLIT) {
current = maybeStateSplit;
} else {
current = gate;
}
GateRef elementsHclass = builder_.GetGlobalConstantValue(ConstantIndex::ARRAY_CLASS_INDEX);
GateRef elementsSize = builder_.ComputeTaggedArraySize(builder_.IntPtr(length));
EcmaOpcode ecmaOpcode = acc_.GetByteCodeOpcode(gate);
auto ecmaOpcodeGate = builder_.Int32(static_cast<uint32_t>(ecmaOpcode));
GateRef constOpcode = builder_.Int32ToTaggedInt(ecmaOpcodeGate);
GateRef typedPath = builder_.Int32ToTaggedInt(builder_.Int32(1));
GateRef traceGate = builder_.CallRuntime(glue_, RTSTUB_ID(DebugAOTPrint), acc_.GetDep(current),
{ constOpcode, typedPath }, gate);
acc_.SetDep(current, traceGate);
builder_.SetDepend(acc_.GetDep(gate)); // set gate depend: trace or STATE_SPLIT
builder_.StartAllocate();
GateRef elements = builder_.HeapAlloc(elementsSize, GateType::TaggedValue(), RegionSpaceFlag::IN_YOUNG_SPACE);
builder_.StoreConstOffset(VariableType::JS_POINTER(), elements, 0, elementsHclass);
builder_.StoreConstOffset(VariableType::JS_ANY(), elements, TaggedArray::LENGTH_OFFSET,
builder_.Int32ToTaggedInt(builder_.IntPtr(length)));
size_t endOffset = TaggedArray::DATA_OFFSET + length * JSTaggedValue::TaggedTypeSize();
// initialization
for (size_t offset = TaggedArray::DATA_OFFSET; offset < endOffset; offset += JSTaggedValue::TaggedTypeSize()) {
builder_.StoreConstOffset(VariableType::INT64(), elements, offset, builder_.Hole());
}
builder_.FinishAllocate();
if (IsProfiling()) {
// see stateSplit as a part of JSByteCode if exists
GateRef maybeStateSplit = acc_.GetDep(gate);
GateRef current = Circuit::NullGate();
if (acc_.GetOpCode(maybeStateSplit) == OpCode::STATE_SPLIT) {
current = maybeStateSplit;
} else {
current = gate;
}
return elements;
}
EcmaOpcode ecmaOpcode = acc_.GetByteCodeOpcode(gate);
auto ecmaOpcodeGate = builder_.Int32(static_cast<uint32_t>(ecmaOpcode));
GateRef constOpcode = builder_.Int32ToTaggedInt(ecmaOpcodeGate);
GateRef mode =
builder_.Int32ToTaggedInt(builder_.Int32(static_cast<int32_t>(OptCodeProfiler::Mode::TYPED_PATH)));
GateRef profiling = builder_.CallRuntime(glue_, RTSTUB_ID(ProfileOptimizedCode), acc_.GetDep(current),
{ constOpcode, mode }, gate);
acc_.SetDep(current, profiling);
builder_.SetDepend(acc_.GetDep(gate)); // set gate depend: profiling or STATE_SPLIT
GateRef NTypeHCRLowering::LowerCallRuntime(GateRef glue, GateRef hirGate, int index, const std::vector<GateRef> &args,
bool useLabel)
{
if (useLabel) {
GateRef result = builder_.CallRuntime(glue, index, Gate::InvalidGateRef, args, hirGate);
return result;
} else {
const CallSignature *cs = RuntimeStubCSigns::Get(RTSTUB_ID(CallRuntime));
GateRef target = builder_.IntPtr(index);
GateRef result = builder_.Call(cs, glue, target, dependEntry_, args, hirGate);
return result;
}
}
}

View File

@ -20,72 +20,56 @@
#include "ecmascript/compiler/builtins/builtins_call_signature.h"
#include "ecmascript/compiler/bytecode_circuit_builder.h"
#include "ecmascript/compiler/circuit_builder-inl.h"
#include "ecmascript/compiler/combined_pass_visitor.h"
#include "ecmascript/compiler/pass_manager.h"
namespace panda::ecmascript::kungfu {
class NTypeHCRLowering {
class NTypeHCRLowering : public PassVisitor {
public:
NTypeHCRLowering(Circuit *circuit, PassContext *ctx, TSManager *tsManager, const MethodLiteral *methodLiteral,
const CString &recordName, bool enableLog, const std::string& name)
: circuit_(circuit),
NTypeHCRLowering(Circuit *circuit, RPOVisitor *visitor, PassContext *ctx, const CString &recordName, Chunk* chunk)
: PassVisitor(circuit, chunk, visitor),
circuit_(circuit),
acc_(circuit),
builder_(circuit, ctx->GetCompilerConfig()),
dependEntry_(circuit->GetDependRoot()),
tsManager_(ctx->GetTSManager()),
recordName_(recordName),
tsManager_(tsManager),
jsPandaFile_(ctx->GetJSPandaFile()),
methodLiteral_(methodLiteral),
enableLog_(enableLog),
profiling_(ctx->GetCompilerConfig()->IsProfiling()),
traceBc_(ctx->GetCompilerConfig()->IsTraceBC()),
methodName_(name),
glue_(acc_.GetGlueFromArgList()) {}
~NTypeHCRLowering() = default;
void RunNTypeHCRLowering();
GateRef VisitGate(GateRef gate) override;
private:
static constexpr int MAX_TAGGED_ARRAY_LENGTH = 50;
void Lower(GateRef gate);
void LowerNTypedCreateEmptyArray(GateRef gate);
void LowerNTypedCreateArrayWithBuffer(GateRef gate);
void LowerNTypedStownByIndex(GateRef gate);
void LowerNTypedStOwnByName(GateRef gate);
void LowerLdLexVar(GateRef gate);
void LowerCreateArray(GateRef gate, GateRef glue);
void LowerCreateArrayWithBuffer(GateRef gate, GateRef glue);
void LowerCreateEmptyArray(GateRef gate);
void LowerCreateArrayWithOwn(GateRef gate, GateRef glue);
void LowerStLexVar(GateRef gate);
void LowerThrowUndefinedIfHoleWithName(GateRef gate);
uint64_t GetBcAbsoluteOffset(GateRef gate) const;
void LowerLdLexVar(GateRef gate);
bool IsLogEnabled() const
GateRef LoadFromConstPool(GateRef jsFunc, size_t index);
GateRef NewJSArrayLiteral(GateRef gate, GateRef elements, GateRef length);
GateRef NewTaggedArray(size_t length);
GateRef CreateElementsWithLength(GateRef gate, GateRef glue, size_t arrayLength);
GateRef LowerCallRuntime(GateRef glue, GateRef hirGate, int index, const std::vector<GateRef> &args,
bool useLabel = false);
GateRef GetFrameState(GateRef gate) const
{
return enableLog_;
return acc_.GetFrameState(gate);
}
bool IsProfiling() const
{
return profiling_;
}
bool IsTraceBC() const
{
return traceBc_;
}
const std::string& GetMethodName() const
{
return methodName_;
}
void AddProfiling(GateRef gate);
Circuit *circuit_ {nullptr};
GateAccessor acc_;
CircuitBuilder builder_;
const CString &recordName_;
GateRef dependEntry_;
TSManager *tsManager_ {nullptr};
const JSPandaFile *jsPandaFile_ {nullptr};
const MethodLiteral *methodLiteral_ {nullptr};
bool enableLog_ {false};
const CString &recordName_;
panda_file::File::EntityId methodId_ {0};
bool profiling_ {false};
bool traceBc_ {false};
std::string methodName_;
GateRef glue_ {Circuit::NullGate()};
};
} // panda::ecmascript::kungfu

View File

@ -1,199 +0,0 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ecmascript/compiler/ntype_mcr_lowering.h"
#include "ecmascript/dfx/vmstat/opt_code_profiler.h"
#include "ecmascript/compiler/new_object_stub_builder.h"
namespace panda::ecmascript::kungfu {
GateRef NTypeMCRLowering::VisitGate(GateRef gate)
{
GateRef glue = acc_.GetGlueFromArgList();
auto op = acc_.GetOpCode(gate);
switch (op) {
case OpCode::CREATE_ARRAY:
LowerCreateArray(gate, glue);
break;
case OpCode::CREATE_ARRAY_WITH_BUFFER:
LowerCreateArrayWithBuffer(gate, glue);
break;
default:
break;
}
return Circuit::NullGate();
}
void NTypeMCRLowering::LowerCreateArray(GateRef gate, GateRef glue)
{
Environment env(gate, circuit_, &builder_);
if (acc_.GetArraySize(gate) == 0) {
LowerCreateEmptyArray(gate);
} else {
LowerCreateArrayWithOwn(gate, glue);
}
}
void NTypeMCRLowering::LowerCreateEmptyArray(GateRef gate)
{
GateRef length = builder_.Int32(0);
GateRef elements = builder_.GetGlobalConstantValue(ConstantIndex::EMPTY_ARRAY_OBJECT_INDEX);
auto array = NewJSArrayLiteral(gate, elements, length);
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), array);
}
void NTypeMCRLowering::LowerCreateArrayWithOwn(GateRef gate, GateRef glue)
{
uint32_t elementsLength = acc_.GetArraySize(gate);
GateRef length = builder_.IntPtr(elementsLength);
GateRef elements = CreateElementsWithLength(gate, glue, elementsLength);
auto array = NewJSArrayLiteral(gate, elements, length);
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), array);
}
void NTypeMCRLowering::LowerCreateArrayWithBuffer(GateRef gate, GateRef glue)
{
Environment env(gate, circuit_, &builder_);
// 2: number of value inputs
ASSERT(acc_.GetNumValueIn(gate) == 2);
GateRef index = acc_.GetValueIn(gate, 0);
GateRef aotElmIndex = acc_.GetValueIn(gate, 1);
auto elementIndex = acc_.GetConstantValue(aotElmIndex);
uint32_t constPoolIndex = static_cast<uint32_t>(acc_.GetConstantValue(index));
ArgumentAccessor argAcc(circuit_);
GateRef frameState = GetFrameState(gate);
GateRef jsFunc = argAcc.GetFrameArgsIn(frameState, FrameArgIdx::FUNC);
GateRef literialElements = LoadFromConstPool(jsFunc, elementIndex);
auto thread = tsManager_->GetEcmaVM()->GetJSThread();
JSHandle<ConstantPool> constpoolHandle(tsManager_->GetConstantPool());
JSTaggedValue arr = ConstantPool::GetLiteralFromCache<ConstPoolType::ARRAY_LITERAL>(
thread, constpoolHandle.GetTaggedValue(), constPoolIndex, recordName_);
JSHandle<JSArray> arrayHandle(thread, arr);
TaggedArray *arrayLiteral = TaggedArray::Cast(arrayHandle->GetElements());
uint32_t literialLength = arrayLiteral->GetLength();
uint32_t arrayLength = acc_.GetArraySize(gate);
GateRef elements = Circuit::NullGate();
GateRef length = Circuit::NullGate();
if (arrayLength > literialLength) {
elements = CreateElementsWithLength(gate, glue, arrayLength);
for (uint32_t i = 0; i < literialLength; i++) {
GateRef value = builder_.LoadFromTaggedArray(literialElements, i);
builder_.StoreToTaggedArray(elements, i, value);
}
length = builder_.IntPtr(arrayLength);
} else {
elements = literialElements;
length = builder_.IntPtr(literialLength);
}
auto array = NewJSArrayLiteral(gate, elements, length);
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), array);
}
GateRef NTypeMCRLowering::LoadFromConstPool(GateRef jsFunc, size_t index)
{
GateRef constPool = builder_.GetConstPool(jsFunc);
return builder_.LoadFromTaggedArray(constPool, index);
}
GateRef NTypeMCRLowering::CreateElementsWithLength(GateRef gate, GateRef glue, size_t arrayLength)
{
GateRef elements = Circuit::NullGate();
GateRef length = builder_.IntPtr(arrayLength);
if (arrayLength < MAX_TAGGED_ARRAY_LENGTH) {
elements = NewTaggedArray(arrayLength);
} else {
elements = LowerCallRuntime(glue, gate, RTSTUB_ID(NewTaggedArray), { builder_.Int32ToTaggedInt(length) }, true);
}
return elements;
}
GateRef NTypeMCRLowering::NewJSArrayLiteral(GateRef gate, GateRef elements, GateRef length)
{
ElementsKind kind = acc_.GetArrayMetaDataAccessor(gate).GetElementsKind();
GateRef hclass = Circuit::NullGate();
if (!Elements::IsGeneric(kind)) {
auto thread = tsManager_->GetEcmaVM()->GetJSThread();
auto hclassIndex = thread->GetArrayHClassIndexMap().at(kind);
hclass = builder_.GetGlobalConstantValue(hclassIndex);
} else {
GateRef globalEnv = builder_.GetGlobalEnv();
hclass = builder_.GetGlobalEnvObjHClass(globalEnv, GlobalEnv::ARRAY_FUNCTION_INDEX);
}
JSHandle<JSFunction> arrayFunc(tsManager_->GetEcmaVM()->GetGlobalEnv()->GetArrayFunction());
JSTaggedValue protoOrHClass = arrayFunc->GetProtoOrHClass();
JSHClass *arrayHC = JSHClass::Cast(protoOrHClass.GetTaggedObject());
size_t arraySize = arrayHC->GetObjectSize();
size_t lengthAccessorOffset = arrayHC->GetInlinedPropertiesOffset(JSArray::LENGTH_INLINE_PROPERTY_INDEX);
GateRef emptyArray = builder_.GetGlobalConstantValue(ConstantIndex::EMPTY_ARRAY_OBJECT_INDEX);
GateRef accessor = builder_.GetGlobalConstantValue(ConstantIndex::ARRAY_LENGTH_ACCESSOR);
GateRef size = builder_.IntPtr(arrayHC->GetObjectSize());
builder_.StartAllocate();
GateRef array = builder_.HeapAlloc(size, GateType::TaggedValue(), RegionSpaceFlag::IN_YOUNG_SPACE);
// initialization
for (size_t offset = JSArray::SIZE; offset < arraySize; offset += JSTaggedValue::TaggedTypeSize()) {
builder_.StoreConstOffset(VariableType::INT64(), array, offset, builder_.Undefined());
}
builder_.StoreConstOffset(VariableType::JS_POINTER(), array, 0, hclass);
builder_.StoreConstOffset(VariableType::INT64(), array, ECMAObject::HASH_OFFSET,
builder_.Int64(JSTaggedValue(0).GetRawData()));
builder_.StoreConstOffset(VariableType::JS_POINTER(), array, JSObject::PROPERTIES_OFFSET, emptyArray);
builder_.StoreConstOffset(VariableType::JS_POINTER(), array, JSObject::ELEMENTS_OFFSET, elements);
builder_.StoreConstOffset(VariableType::INT32(), array, JSArray::LENGTH_OFFSET, length);
builder_.StoreConstOffset(VariableType::JS_POINTER(), array, lengthAccessorOffset, accessor);
builder_.StoreConstOffset(VariableType::INT64(), array, JSArray::TRACK_INFO_OFFSET, builder_.Undefined());
builder_.FinishAllocate();
return array;
}
GateRef NTypeMCRLowering::NewTaggedArray(size_t length)
{
GateRef elementsHclass = builder_.GetGlobalConstantValue(ConstantIndex::ARRAY_CLASS_INDEX);
GateRef elementsSize = builder_.ComputeTaggedArraySize(builder_.IntPtr(length));
builder_.StartAllocate();
GateRef elements = builder_.HeapAlloc(elementsSize, GateType::TaggedValue(), RegionSpaceFlag::IN_YOUNG_SPACE);
builder_.StoreConstOffset(VariableType::JS_POINTER(), elements, 0, elementsHclass);
builder_.StoreConstOffset(VariableType::JS_ANY(), elements, TaggedArray::LENGTH_OFFSET,
builder_.Int32ToTaggedInt(builder_.IntPtr(length)));
size_t endOffset = TaggedArray::DATA_OFFSET + length * JSTaggedValue::TaggedTypeSize();
// initialization
for (size_t offset = TaggedArray::DATA_OFFSET; offset < endOffset; offset += JSTaggedValue::TaggedTypeSize()) {
builder_.StoreConstOffset(VariableType::INT64(), elements, offset, builder_.Hole());
}
builder_.FinishAllocate();
return elements;
}
GateRef NTypeMCRLowering::LowerCallRuntime(GateRef glue, GateRef hirGate, int index, const std::vector<GateRef> &args,
bool useLabel)
{
if (useLabel) {
GateRef result = builder_.CallRuntime(glue, index, Gate::InvalidGateRef, args, hirGate);
return result;
} else {
const CallSignature *cs = RuntimeStubCSigns::Get(RTSTUB_ID(CallRuntime));
GateRef target = builder_.IntPtr(index);
GateRef result = builder_.Call(cs, glue, target, dependEntry_, args, hirGate);
return result;
}
}
}

View File

@ -16,7 +16,7 @@
#include "ecmascript/compiler/share_gate_meta_data.h"
#include "ecmascript/compiler/number_gate_info.h"
#include "ecmascript/compiler/type.h"
#include "ecmascript/compiler/type_mcr_lowering.h"
#include "ecmascript/compiler/type_hcr_lowering.h"
#include "ecmascript/compiler/builtins_lowering.h"
#include "ecmascript/compiler/new_object_stub_builder.h"
#include "ecmascript/compiler/number_speculative_lowering.h"

View File

@ -52,7 +52,7 @@ private:
PropertyLookupResult plr_ {};
};
// An auxiliary class serving TSHCRLowering, used for named object property access,
// An auxiliary class serving TypeBytecodeLowering, used for named object property access,
// invoking TSManager and HClass.
class ObjectAccessHelper final {
public:

View File

@ -28,25 +28,25 @@
#include "ecmascript/compiler/graph_editor.h"
#include "ecmascript/compiler/graph_linearizer.h"
#include "ecmascript/compiler/later_elimination.h"
#include "ecmascript/compiler/lcr_lowering.h"
#include "ecmascript/compiler/mcr_lowering.h"
#include "ecmascript/compiler/lexical_env_specialization.h"
#include "ecmascript/compiler/llvm_codegen.h"
#include "ecmascript/compiler/loop_analysis.h"
#include "ecmascript/compiler/loop_peeling.h"
#include "ecmascript/compiler/ntype_bytecode_lowering.h"
#include "ecmascript/compiler/ntype_hcr_lowering.h"
#include "ecmascript/compiler/ntype_mcr_lowering.h"
#include "ecmascript/compiler/number_speculative_runner.h"
#include "ecmascript/compiler/scheduler.h"
#include "ecmascript/compiler/slowpath_lowering.h"
#include "ecmascript/compiler/state_split_linearizer.h"
#include "ecmascript/compiler/ts_class_analysis.h"
#include "ecmascript/compiler/ts_inline_lowering.h"
#include "ecmascript/compiler/ts_hcr_lowering.h"
#include "ecmascript/compiler/type_bytecode_lowering.h"
#include "ecmascript/compiler/ts_hcr_opt_pass.h"
#include "ecmascript/compiler/type_inference/global_type_infer.h"
#include "ecmascript/compiler/type_inference/initialization_analysis.h"
#include "ecmascript/compiler/type_inference/pgo_type_infer.h"
#include "ecmascript/compiler/type_mcr_lowering.h"
#include "ecmascript/compiler/type_hcr_lowering.h"
#include "ecmascript/compiler/value_numbering.h"
#include "ecmascript/compiler/verifier.h"
#include "ecmascript/js_runtime_options.h"
@ -285,7 +285,7 @@ public:
}
};
class TSHCRLoweringPass {
class TypeBytecodeLoweringPass {
public:
bool Run(PassData* data)
{
@ -293,12 +293,12 @@ public:
if (!passOptions->EnableTypeLowering()) {
return false;
}
TimeScope timescope("TSHCRLoweringPass", data->GetMethodName(), data->GetMethodOffset(), data->GetLog());
TimeScope timescope("TypeBytecodeLoweringPass", data->GetMethodName(), data->GetMethodOffset(), data->GetLog());
bool enableLog = data->GetLog()->EnableMethodCIRLog();
bool enableTypeLog = data->GetLog()->GetEnableMethodLog() && data->GetLog()->OutputType();
TSHCRLowering lowering(data->GetCircuit(), data->GetPassContext(),
TypeBytecodeLowering lowering(data->GetCircuit(), data->GetPassContext(),
enableLog, enableTypeLog, data->GetMethodName());
bool success = lowering.RunTSHCRLowering();
bool success = lowering.RunTypeBytecodeLowering();
if (!success) {
data->MarkAsTypeAbort();
}
@ -316,6 +316,50 @@ public:
}
};
class NTypeBytecodeLoweringPass {
public:
bool Run(PassData* data)
{
PassOptions *passOptions = data->GetPassOptions();
if (!passOptions->EnableTypeLowering()) {
return false;
}
TimeScope timescope("NTypeBytecodeLoweringPass", data->GetMethodName(), data->GetMethodOffset(), data->GetLog());
bool enableLog = data->GetLog()->EnableMethodCIRLog();
NTypeBytecodeLowering lowering(data->GetCircuit(), data->GetPassContext(), data->GetTSManager(),
data->GetMethodLiteral(), data->GetRecordName(), enableLog, data->GetMethodName());
lowering.RunNTypeBytecodeLowering();
Chunk chunk(data->GetNativeAreaAllocator());
CombinedPassVisitor visitor(data->GetCircuit(), enableLog, data->GetMethodName(), &chunk);
DeadCodeElimination deadCodeElimination(data->GetCircuit(), &visitor, &chunk);
visitor.AddPass(&deadCodeElimination);
visitor.VisitGraph();
return true;
}
};
class TypeHCRLoweringPass {
public:
bool Run(PassData* data)
{
PassOptions *passOptions = data->GetPassOptions();
if (!passOptions->EnableTypeLowering()) {
return false;
}
TimeScope timescope("TypeHCRLoweringPass", data->GetMethodName(), data->GetMethodOffset(), data->GetLog());
bool enableLog = data->GetLog()->EnableMethodCIRLog();
Chunk chunk(data->GetNativeAreaAllocator());
CombinedPassVisitor visitor(data->GetCircuit(), enableLog, data->GetMethodName(), &chunk);
TypeHCRLowering lowering(data->GetCircuit(), &visitor,
data->GetCompilerConfig(), data->GetTSManager(), &chunk,
data->GetPassOptions()->EnableOptOnHeapCheck());
visitor.AddPass(&lowering);
visitor.VisitGraph();
visitor.PrintLog("TypeHCRLowering");
return true;
}
};
class NTypeHCRLoweringPass {
public:
bool Run(PassData* data)
@ -326,57 +370,13 @@ public:
}
TimeScope timescope("NTypeHCRLoweringPass", data->GetMethodName(), data->GetMethodOffset(), data->GetLog());
bool enableLog = data->GetLog()->EnableMethodCIRLog();
NTypeHCRLowering lowering(data->GetCircuit(), data->GetPassContext(), data->GetTSManager(),
data->GetMethodLiteral(), data->GetRecordName(), enableLog, data->GetMethodName());
lowering.RunNTypeHCRLowering();
Chunk chunk(data->GetNativeAreaAllocator());
CombinedPassVisitor visitor(data->GetCircuit(), enableLog, data->GetMethodName(), &chunk);
DeadCodeElimination deadCodeElimination(data->GetCircuit(), &visitor, &chunk);
visitor.AddPass(&deadCodeElimination);
visitor.VisitGraph();
return true;
}
};
class TypeMCRLoweringPass {
public:
bool Run(PassData* data)
{
PassOptions *passOptions = data->GetPassOptions();
if (!passOptions->EnableTypeLowering()) {
return false;
}
TimeScope timescope("TypeMCRLoweringPass", data->GetMethodName(), data->GetMethodOffset(), data->GetLog());
bool enableLog = data->GetLog()->EnableMethodCIRLog();
Chunk chunk(data->GetNativeAreaAllocator());
CombinedPassVisitor visitor(data->GetCircuit(), enableLog, data->GetMethodName(), &chunk);
TypeMCRLowering lowering(data->GetCircuit(), &visitor,
data->GetCompilerConfig(), data->GetTSManager(), &chunk,
data->GetPassOptions()->EnableOptOnHeapCheck());
visitor.AddPass(&lowering);
visitor.VisitGraph();
visitor.PrintLog("TypeMCRLowering");
return true;
}
};
class NTypeMCRLoweringPass {
public:
bool Run(PassData* data)
{
PassOptions *passOptions = data->GetPassOptions();
if (!passOptions->EnableTypeLowering()) {
return false;
}
TimeScope timescope("NTypeMCRLoweringPass", data->GetMethodName(), data->GetMethodOffset(), data->GetLog());
bool enableLog = data->GetLog()->EnableMethodCIRLog();
Chunk chunk(data->GetNativeAreaAllocator());
CombinedPassVisitor visitor(data->GetCircuit(), enableLog, data->GetMethodName(), &chunk);
NTypeMCRLowering lowering(data->GetCircuit(), &visitor, data->GetPassContext(),
NTypeHCRLowering lowering(data->GetCircuit(), &visitor, data->GetPassContext(),
data->GetRecordName(), &chunk);
visitor.AddPass(&lowering);
visitor.VisitGraph();
visitor.PrintLog("NTypeMCRLowering");
visitor.PrintLog("NTypeHCRLowering");
return true;
}
};
@ -393,10 +393,10 @@ public:
bool enableLog = data->GetLog()->EnableMethodCIRLog();
Chunk chunk(data->GetNativeAreaAllocator());
CombinedPassVisitor visitor(data->GetCircuit(), enableLog, data->GetMethodName(), &chunk);
LCRLowering lowering(data->GetCircuit(), &visitor, data->GetCompilerConfig(), &chunk);
MCRLowering lowering(data->GetCircuit(), &visitor, data->GetCompilerConfig(), &chunk);
visitor.AddPass(&lowering);
visitor.VisitGraph();
visitor.PrintLog("LCRLowering");
visitor.PrintLog("MCRLowering");
return true;
}
};

View File

@ -119,9 +119,9 @@ bool PassManager::Compile(JSPandaFile *jsPandaFile, const std::string &fileName,
data.AbortCompilation();
return;
}
pipeline.RunPass<TSHCRLoweringPass>();
pipeline.RunPass<TypeBytecodeLoweringPass>();
pipeline.RunPass<RedundantPhiEliminationPass>();
pipeline.RunPass<NTypeHCRLoweringPass>();
pipeline.RunPass<NTypeBytecodeLoweringPass>();
if (data.IsTypeAbort()) {
data.AbortCompilation();
return;
@ -132,8 +132,8 @@ bool PassManager::Compile(JSPandaFile *jsPandaFile, const std::string &fileName,
pipeline.RunPass<LaterEliminationPass>();
pipeline.RunPass<ValueNumberingPass>();
pipeline.RunPass<StateSplitLinearizerPass>();
pipeline.RunPass<NTypeMCRLoweringPass>();
pipeline.RunPass<TypeMCRLoweringPass>();
pipeline.RunPass<NTypeHCRLoweringPass>();
pipeline.RunPass<TypeHCRLoweringPass>();
pipeline.RunPass<LaterEliminationPass>();
pipeline.RunPass<EarlyEliminationPass>();
pipeline.RunPass<LCRLoweringPass>();

View File

@ -20,7 +20,7 @@
#include "ecmascript/compiler/circuit.h"
#include "ecmascript/compiler/gate_accessor.h"
#include "ecmascript/compiler/lcr_lowering.h"
#include "ecmascript/compiler/mcr_lowering.h"
#include "ecmascript/compiler/graph_linearizer.h"
#include "ecmascript/mem/chunk_containers.h"
@ -51,7 +51,7 @@ private:
std::string methodName_;
Circuit* circuit_ {nullptr};
GraphLinearizer graphLinearizer_;
LCRLowering lcrLowering_;
MCRLowering lcrLowering_;
friend class StateDependBuilder;
};
}; // namespace panda::ecmascript::kungfu

View File

@ -23,8 +23,8 @@
#include "ecmascript/compiler/type.h"
#include "ecmascript/compiler/variable_type.h"
#include "ecmascript/compiler/verifier.h"
#include "ecmascript/compiler/ts_hcr_lowering.h"
#include "ecmascript/compiler/type_mcr_lowering.h"
#include "ecmascript/compiler/type_bytecode_lowering.h"
#include "ecmascript/compiler/type_hcr_lowering.h"
#include "ecmascript/mem/chunk.h"
#include "ecmascript/mem/native_area_allocator.h"
#include "ecmascript/tests/test_helper.h"

View File

@ -18,8 +18,8 @@
#include "ecmascript/compiler/share_opcodes.h"
#include "ecmascript/compiler/value_numbering.h"
#include "ecmascript/compiler/verifier.h"
#include "ecmascript/compiler/ts_hcr_lowering.h"
#include "ecmascript/compiler/type_mcr_lowering.h"
#include "ecmascript/compiler/type_bytecode_lowering.h"
#include "ecmascript/compiler/type_hcr_lowering.h"
#include "ecmascript/elements.h"
#include "ecmascript/mem/concurrent_marker.h"
#include "ecmascript/mem/native_area_allocator.h"

View File

@ -24,8 +24,8 @@
#include "ecmascript/compiler/type.h"
#include "ecmascript/compiler/variable_type.h"
#include "ecmascript/compiler/verifier.h"
#include "ecmascript/compiler/ts_hcr_lowering.h"
#include "ecmascript/compiler/type_mcr_lowering.h"
#include "ecmascript/compiler/type_bytecode_lowering.h"
#include "ecmascript/compiler/type_hcr_lowering.h"
#include "ecmascript/mem/chunk.h"
#include "ecmascript/mem/native_area_allocator.h"
#include "ecmascript/tests/test_helper.h"

View File

@ -15,8 +15,8 @@
#include "ecmascript/compiler/gate_accessor.h"
#include "ecmascript/compiler/share_opcodes.h"
#include "ecmascript/compiler/verifier.h"
#include "ecmascript/compiler/ts_hcr_lowering.h"
#include "ecmascript/compiler/type_mcr_lowering.h"
#include "ecmascript/compiler/type_bytecode_lowering.h"
#include "ecmascript/compiler/type_hcr_lowering.h"
#include "ecmascript/elements.h"
#include "ecmascript/mem/concurrent_marker.h"
#include "ecmascript/mem/native_area_allocator.h"

View File

@ -15,8 +15,8 @@
#include "ecmascript/compiler/gate_accessor.h"
#include "ecmascript/compiler/type.h"
#include "ecmascript/compiler/verifier.h"
#include "ecmascript/compiler/ts_hcr_lowering.h"
#include "ecmascript/compiler/type_mcr_lowering.h"
#include "ecmascript/compiler/type_bytecode_lowering.h"
#include "ecmascript/compiler/type_hcr_lowering.h"
#include "ecmascript/mem/chunk.h"
#include "ecmascript/mem/native_area_allocator.h"
#include "ecmascript/tests/test_helper.h"
@ -35,7 +35,7 @@ using ecmascript::kungfu::CircuitBuilder;
using ecmascript::kungfu::Verifier;
using ecmascript::kungfu::Environment;
using ecmascript::kungfu::CombinedPassVisitor;
using ecmascript::kungfu::TypeMCRLowering;
using ecmascript::kungfu::TypeHCRLowering;
HWTEST_F_L0(TypedArrayLoweringTests, LoadTypedArrayLength)
{
// construct a circuit
@ -55,7 +55,7 @@ HWTEST_F_L0(TypedArrayLoweringTests, LoadTypedArrayLength)
builder.Return(convert);
EXPECT_TRUE(Verifier::Run(&circuit));
CombinedPassVisitor visitor(&circuit, false, "LoadTypedArrayLength", &chunk);
TypeMCRLowering lowering(&circuit, &visitor, nullptr, nullptr, &chunk, false);
TypeHCRLowering lowering(&circuit, &visitor, nullptr, nullptr, &chunk, false);
visitor.AddPass(&lowering);
visitor.VisitGraph();
EXPECT_TRUE(Verifier::Run(&circuit));
@ -85,7 +85,7 @@ HWTEST_F_L0(TypedArrayLoweringTests, Int32ArrayLoadElement)
builder.Return(convert);
EXPECT_TRUE(Verifier::Run(&circuit));
CombinedPassVisitor visitor(&circuit, false, "Int32ArrayLoadElement", &chunk);
TypeMCRLowering lowering(&circuit, &visitor, nullptr, nullptr, &chunk, false);
TypeHCRLowering lowering(&circuit, &visitor, nullptr, nullptr, &chunk, false);
visitor.AddPass(&lowering);
visitor.VisitGraph();
EXPECT_TRUE(Verifier::Run(&circuit));
@ -121,7 +121,7 @@ HWTEST_F_L0(TypedArrayLoweringTests, Int32OnHeapArrayLoadElement)
builder.Return(convert);
EXPECT_TRUE(Verifier::Run(&circuit));
CombinedPassVisitor visitor(&circuit, false, "Int32OnHeapArrayLoadElement", &chunk);
TypeMCRLowering lowering(&circuit, &visitor, nullptr, nullptr, &chunk, true);
TypeHCRLowering lowering(&circuit, &visitor, nullptr, nullptr, &chunk, true);
visitor.AddPass(&lowering);
visitor.VisitGraph();
EXPECT_TRUE(Verifier::Run(&circuit));
@ -152,7 +152,7 @@ HWTEST_F_L0(TypedArrayLoweringTests, Float64OnHeapArrayLoadElement)
builder.Return(convert);
EXPECT_TRUE(Verifier::Run(&circuit));
CombinedPassVisitor visitor(&circuit, false, "Float64OnHeapArrayLoadElement", &chunk);
TypeMCRLowering lowering(&circuit, &visitor, nullptr, nullptr, &chunk, true);
TypeHCRLowering lowering(&circuit, &visitor, nullptr, nullptr, &chunk, true);
visitor.AddPass(&lowering);
visitor.VisitGraph();
EXPECT_TRUE(Verifier::Run(&circuit));
@ -183,7 +183,7 @@ HWTEST_F_L0(TypedArrayLoweringTests, FLOAT32OnHeapArrayLoadElement)
builder.Return(convert);
EXPECT_TRUE(Verifier::Run(&circuit));
CombinedPassVisitor visitor(&circuit, false, "FLOAT32OnHeapArrayLoadElement", &chunk);
TypeMCRLowering lowering(&circuit, &visitor, nullptr, nullptr, &chunk, true);
TypeHCRLowering lowering(&circuit, &visitor, nullptr, nullptr, &chunk, true);
visitor.AddPass(&lowering);
visitor.VisitGraph();
EXPECT_TRUE(Verifier::Run(&circuit));
@ -217,7 +217,7 @@ HWTEST_F_L0(TypedArrayLoweringTests, Int8OnHeapArrayLoadElement)
builder.Return(convert);
EXPECT_TRUE(Verifier::Run(&circuit));
CombinedPassVisitor visitor(&circuit, false, "Int8OnHeapArrayLoadElement", &chunk);
TypeMCRLowering lowering(&circuit, &visitor, nullptr, nullptr, &chunk, true);
TypeHCRLowering lowering(&circuit, &visitor, nullptr, nullptr, &chunk, true);
visitor.AddPass(&lowering);
visitor.VisitGraph();
EXPECT_TRUE(Verifier::Run(&circuit));
@ -251,7 +251,7 @@ HWTEST_F_L0(TypedArrayLoweringTests, UInt8OnHeapArrayLoadElement)
builder.Return(convert);
EXPECT_TRUE(Verifier::Run(&circuit));
CombinedPassVisitor visitor(&circuit, false, "UInt8OnHeapArrayLoadElement", &chunk);
TypeMCRLowering lowering(&circuit, &visitor, nullptr, nullptr, &chunk, true);
TypeHCRLowering lowering(&circuit, &visitor, nullptr, nullptr, &chunk, true);
visitor.AddPass(&lowering);
visitor.VisitGraph();
EXPECT_TRUE(Verifier::Run(&circuit));
@ -285,7 +285,7 @@ HWTEST_F_L0(TypedArrayLoweringTests, Int16OnHeapArrayLoadElement)
builder.Return(convert);
EXPECT_TRUE(Verifier::Run(&circuit));
CombinedPassVisitor visitor(&circuit, false, "Int16OnHeapArrayLoadElement", &chunk);
TypeMCRLowering lowering(&circuit, &visitor, nullptr, nullptr, &chunk, true);
TypeHCRLowering lowering(&circuit, &visitor, nullptr, nullptr, &chunk, true);
visitor.AddPass(&lowering);
visitor.VisitGraph();
EXPECT_TRUE(Verifier::Run(&circuit));
@ -319,7 +319,7 @@ HWTEST_F_L0(TypedArrayLoweringTests, UInt16OnHeapArrayLoadElement)
builder.Return(convert);
EXPECT_TRUE(Verifier::Run(&circuit));
CombinedPassVisitor visitor(&circuit, false, "UInt16OnHeapArrayLoadElement", &chunk);
TypeMCRLowering lowering(&circuit, &visitor, nullptr, nullptr, &chunk, true);
TypeHCRLowering lowering(&circuit, &visitor, nullptr, nullptr, &chunk, true);
visitor.AddPass(&lowering);
visitor.VisitGraph();
EXPECT_TRUE(Verifier::Run(&circuit));
@ -353,7 +353,7 @@ HWTEST_F_L0(TypedArrayLoweringTests, Int32ArrayStoreElement)
auto ret = builder.Return(builder.Undefined());
EXPECT_TRUE(Verifier::Run(&circuit));
CombinedPassVisitor visitor(&circuit, false, "Int32ArrayStoreElement", &chunk);
TypeMCRLowering lowering(&circuit, &visitor, nullptr, nullptr, &chunk, false);
TypeHCRLowering lowering(&circuit, &visitor, nullptr, nullptr, &chunk, false);
visitor.AddPass(&lowering);
visitor.VisitGraph();
EXPECT_TRUE(Verifier::Run(&circuit));
@ -389,7 +389,7 @@ HWTEST_F_L0(TypedArrayLoweringTests, Int32OnHeapArrayStoreElement)
auto ret = builder.Return(builder.Undefined());
EXPECT_TRUE(Verifier::Run(&circuit));
CombinedPassVisitor visitor(&circuit, false, "Int32OnHeapArrayStoreElement", &chunk);
TypeMCRLowering lowering(&circuit, &visitor, nullptr, nullptr, &chunk, true);
TypeHCRLowering lowering(&circuit, &visitor, nullptr, nullptr, &chunk, true);
visitor.AddPass(&lowering);
visitor.VisitGraph();
EXPECT_TRUE(Verifier::Run(&circuit));
@ -420,7 +420,7 @@ HWTEST_F_L0(TypedArrayLoweringTests, Float64OnHeapArrayStoreElement)
auto ret = builder.Return(builder.Undefined());
EXPECT_TRUE(Verifier::Run(&circuit));
CombinedPassVisitor visitor(&circuit, false, "Float64OnHeapArrayStoreElement", &chunk);
TypeMCRLowering lowering(&circuit, &visitor, nullptr, nullptr, &chunk, true);
TypeHCRLowering lowering(&circuit, &visitor, nullptr, nullptr, &chunk, true);
visitor.AddPass(&lowering);
visitor.VisitGraph();
EXPECT_TRUE(Verifier::Run(&circuit));
@ -451,7 +451,7 @@ HWTEST_F_L0(TypedArrayLoweringTests, Int8OnHeapArrayStoreElement)
auto ret = builder.Return(builder.Undefined());
EXPECT_TRUE(Verifier::Run(&circuit));
CombinedPassVisitor visitor(&circuit, false, "Int8OnHeapArrayStoreElement", &chunk);
TypeMCRLowering lowering(&circuit, &visitor, nullptr, nullptr, &chunk, true);
TypeHCRLowering lowering(&circuit, &visitor, nullptr, nullptr, &chunk, true);
visitor.AddPass(&lowering);
visitor.VisitGraph();
EXPECT_TRUE(Verifier::Run(&circuit));
@ -484,7 +484,7 @@ HWTEST_F_L0(TypedArrayLoweringTests, UInt8OnHeapArrayStoreElement)
auto ret = builder.Return(builder.Undefined());
EXPECT_TRUE(Verifier::Run(&circuit));
CombinedPassVisitor visitor(&circuit, false, "UInt8OnHeapArrayStoreElement", &chunk);
TypeMCRLowering lowering(&circuit, &visitor, nullptr, nullptr, &chunk, true);
TypeHCRLowering lowering(&circuit, &visitor, nullptr, nullptr, &chunk, true);
visitor.AddPass(&lowering);
visitor.VisitGraph();
EXPECT_TRUE(Verifier::Run(&circuit));
@ -517,7 +517,7 @@ HWTEST_F_L0(TypedArrayLoweringTests, Int16OnHeapArrayStoreElement)
auto ret = builder.Return(builder.Undefined());
EXPECT_TRUE(Verifier::Run(&circuit));
CombinedPassVisitor visitor(&circuit, false, "Int16OnHeapArrayStoreElement", &chunk);
TypeMCRLowering lowering(&circuit, &visitor, nullptr, nullptr, &chunk, true);
TypeHCRLowering lowering(&circuit, &visitor, nullptr, nullptr, &chunk, true);
visitor.AddPass(&lowering);
visitor.VisitGraph();
EXPECT_TRUE(Verifier::Run(&circuit));
@ -550,7 +550,7 @@ HWTEST_F_L0(TypedArrayLoweringTests, UInt16OnHeapArrayStoreElement)
auto ret = builder.Return(builder.Undefined());
EXPECT_TRUE(Verifier::Run(&circuit));
CombinedPassVisitor visitor(&circuit, false, "UInt16OnHeapArrayStoreElement", &chunk);
TypeMCRLowering lowering(&circuit, &visitor, nullptr, nullptr, &chunk, true);
TypeHCRLowering lowering(&circuit, &visitor, nullptr, nullptr, &chunk, true);
visitor.AddPass(&lowering);
visitor.VisitGraph();
EXPECT_TRUE(Verifier::Run(&circuit));
@ -583,7 +583,7 @@ HWTEST_F_L0(TypedArrayLoweringTests, Float32OnHeapArrayStoreElement)
auto ret = builder.Return(builder.Undefined());
EXPECT_TRUE(Verifier::Run(&circuit));
CombinedPassVisitor visitor(&circuit, false, "Float32OnHeapArrayStoreElement", &chunk);
TypeMCRLowering lowering(&circuit, &visitor, nullptr, nullptr, &chunk, true);
TypeHCRLowering lowering(&circuit, &visitor, nullptr, nullptr, &chunk, true);
visitor.AddPass(&lowering);
visitor.VisitGraph();
EXPECT_TRUE(Verifier::Run(&circuit));

View File

@ -13,7 +13,7 @@
* limitations under the License.
*/
#include "ecmascript/compiler/ts_hcr_lowering.h"
#include "ecmascript/compiler/type_bytecode_lowering.h"
#include "ecmascript/compiler/bytecodes.h"
#include "ecmascript/compiler/builtins_lowering.h"
#include "ecmascript/compiler/circuit.h"
@ -23,7 +23,7 @@
namespace panda::ecmascript::kungfu {
using PGONativeFunctionId = pgo::DumpUtils::PGONativeFunctionId;
bool TSHCRLowering::RunTSHCRLowering()
bool TypeBytecodeLowering::RunTypeBytecodeLowering()
{
std::vector<GateRef> gateList;
circuit_->GetAllGates(gateList);
@ -54,7 +54,7 @@ bool TSHCRLowering::RunTSHCRLowering()
LOG_COMPILER(INFO) << "";
LOG_COMPILER(INFO) << "\033[34m"
<< "===================="
<< " After TSHCRlowering "
<< " After TypeBytecodeLowering "
<< "[" << GetMethodName() << "]"
<< "===================="
<< "\033[0m";
@ -83,7 +83,7 @@ bool TSHCRLowering::RunTSHCRLowering()
return success;
}
bool TSHCRLowering::IsTrustedType(GateRef gate) const
bool TypeBytecodeLowering::IsTrustedType(GateRef gate) const
{
if (acc_.IsConstant(gate)) {
return true;
@ -123,7 +123,7 @@ bool TSHCRLowering::IsTrustedType(GateRef gate) const
return false;
}
bool TSHCRLowering::IsTrustedStringType(GateRef gate) const
bool TypeBytecodeLowering::IsTrustedStringType(GateRef gate) const
{
auto op = acc_.GetOpCode(gate);
if (op == OpCode::LOAD_ELEMENT) {
@ -149,7 +149,7 @@ bool TSHCRLowering::IsTrustedStringType(GateRef gate) const
return false;
}
void TSHCRLowering::Lower(GateRef gate)
void TypeBytecodeLowering::Lower(GateRef gate)
{
EcmaOpcode ecmaOpcode = acc_.GetByteCodeOpcode(gate);
// initialize label manager
@ -332,7 +332,7 @@ void TSHCRLowering::Lower(GateRef gate)
}
template<TypedBinOp Op>
void TSHCRLowering::LowerTypedBinOp(GateRef gate, bool convertNumberType)
void TypeBytecodeLowering::LowerTypedBinOp(GateRef gate, bool convertNumberType)
{
GateRef left = acc_.GetValueIn(gate, 0);
GateRef right = acc_.GetValueIn(gate, 1);
@ -344,7 +344,7 @@ void TSHCRLowering::LowerTypedBinOp(GateRef gate, bool convertNumberType)
}
template<TypedUnOp Op>
void TSHCRLowering::LowerTypedUnOp(GateRef gate)
void TypeBytecodeLowering::LowerTypedUnOp(GateRef gate)
{
GateRef value = acc_.GetValueIn(gate, 0);
if (HasNumberType(gate, value)) {
@ -352,7 +352,7 @@ void TSHCRLowering::LowerTypedUnOp(GateRef gate)
}
}
void TSHCRLowering::LowerTypedStrictEq(GateRef gate)
void TypeBytecodeLowering::LowerTypedStrictEq(GateRef gate)
{
GateRef left = acc_.GetValueIn(gate, 0);
GateRef right = acc_.GetValueIn(gate, 1);
@ -367,7 +367,7 @@ void TSHCRLowering::LowerTypedStrictEq(GateRef gate)
}
}
bool TSHCRLowering::HasNumberType(GateRef gate, GateRef value) const
bool TypeBytecodeLowering::HasNumberType(GateRef gate, GateRef value) const
{
GateType valueType = acc_.GetGateType(value);
PGOSampleType sampleType = acc_.TryGetPGOType(gate);
@ -378,7 +378,7 @@ bool TSHCRLowering::HasNumberType(GateRef gate, GateRef value) const
return false;
}
bool TSHCRLowering::HasNumberType(GateRef gate, GateRef left, GateRef right, bool convertNumberType) const
bool TypeBytecodeLowering::HasNumberType(GateRef gate, GateRef left, GateRef right, bool convertNumberType) const
{
GateType leftType = acc_.GetGateType(left);
GateType rightType = acc_.GetGateType(right);
@ -397,7 +397,7 @@ bool TSHCRLowering::HasNumberType(GateRef gate, GateRef left, GateRef right, boo
return false;
}
bool TSHCRLowering::HasStringType([[maybe_unused]] GateRef gate, GateRef left, GateRef right) const
bool TypeBytecodeLowering::HasStringType([[maybe_unused]] GateRef gate, GateRef left, GateRef right) const
{
GateType leftType = acc_.GetGateType(left);
GateType rightType = acc_.GetGateType(right);
@ -409,7 +409,7 @@ bool TSHCRLowering::HasStringType([[maybe_unused]] GateRef gate, GateRef left, G
}
template<TypedBinOp Op>
void TSHCRLowering::SpeculateStrings(GateRef gate)
void TypeBytecodeLowering::SpeculateStrings(GateRef gate)
{
if (Op == TypedBinOp::TYPED_EQ) {
AddProfiling(gate);
@ -433,7 +433,7 @@ void TSHCRLowering::SpeculateStrings(GateRef gate)
}
template<TypedBinOp Op>
void TSHCRLowering::SpeculateNumbers(GateRef gate)
void TypeBytecodeLowering::SpeculateNumbers(GateRef gate)
{
AddProfiling(gate);
GateRef left = acc_.GetValueIn(gate, 0);
@ -449,7 +449,7 @@ void TSHCRLowering::SpeculateNumbers(GateRef gate)
}
template<TypedUnOp Op>
void TSHCRLowering::SpeculateNumber(GateRef gate)
void TypeBytecodeLowering::SpeculateNumber(GateRef gate)
{
AddProfiling(gate);
GateRef value = acc_.GetValueIn(gate, 0);
@ -474,7 +474,7 @@ void TSHCRLowering::SpeculateNumber(GateRef gate)
acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), result);
}
void TSHCRLowering::LowerTypeToNumeric(GateRef gate)
void TypeBytecodeLowering::LowerTypeToNumeric(GateRef gate)
{
GateRef src = acc_.GetValueIn(gate, 0);
if (HasNumberType(gate, src)) {
@ -483,7 +483,7 @@ void TSHCRLowering::LowerTypeToNumeric(GateRef gate)
}
}
void TSHCRLowering::LowerPrimitiveTypeToNumber(GateRef gate)
void TypeBytecodeLowering::LowerPrimitiveTypeToNumber(GateRef gate)
{
GateRef src = acc_.GetValueIn(gate, 0);
GateType srcType = acc_.GetGateType(src);
@ -493,7 +493,7 @@ void TSHCRLowering::LowerPrimitiveTypeToNumber(GateRef gate)
acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), result);
}
void TSHCRLowering::LowerConditionJump(GateRef gate, bool flag)
void TypeBytecodeLowering::LowerConditionJump(GateRef gate, bool flag)
{
GateRef condition = acc_.GetValueIn(gate, 0);
GateType conditionType = acc_.GetGateType(condition);
@ -503,7 +503,7 @@ void TSHCRLowering::LowerConditionJump(GateRef gate, bool flag)
}
}
void TSHCRLowering::SpeculateConditionJump(GateRef gate, bool flag)
void TypeBytecodeLowering::SpeculateConditionJump(GateRef gate, bool flag)
{
GateRef value = acc_.GetValueIn(gate, 0);
GateType valueType = acc_.GetGateType(value);
@ -517,7 +517,7 @@ void TSHCRLowering::SpeculateConditionJump(GateRef gate, bool flag)
acc_.ReplaceGate(gate, jump, jump, Circuit::NullGate());
}
void TSHCRLowering::DeleteConstDataIfNoUser(GateRef gate)
void TypeBytecodeLowering::DeleteConstDataIfNoUser(GateRef gate)
{
auto uses = acc_.Uses(gate);
if (uses.begin() == uses.end()) {
@ -526,7 +526,7 @@ void TSHCRLowering::DeleteConstDataIfNoUser(GateRef gate)
}
}
void TSHCRLowering::LowerTypedLdObjByName(GateRef gate)
void TypeBytecodeLowering::LowerTypedLdObjByName(GateRef gate)
{
DISALLOW_GARBAGE_COLLECTION;
auto constData = acc_.GetValueIn(gate, 1); // 1: valueIn 1
@ -540,7 +540,7 @@ void TSHCRLowering::LowerTypedLdObjByName(GateRef gate)
DeleteConstDataIfNoUser(constData);
}
void TSHCRLowering::LowerTypedStObjByName(GateRef gate, bool isThis)
void TypeBytecodeLowering::LowerTypedStObjByName(GateRef gate, bool isThis)
{
DISALLOW_GARBAGE_COLLECTION;
auto constData = acc_.GetValueIn(gate, 1); // 1: valueIn 1
@ -564,7 +564,7 @@ void TSHCRLowering::LowerTypedStObjByName(GateRef gate, bool isThis)
DeleteConstDataIfNoUser(constData);
}
void TSHCRLowering::LowerNamedAccess(GateRef gate, GateRef receiver, AccessMode accessMode, JSTaggedValue key,
void TypeBytecodeLowering::LowerNamedAccess(GateRef gate, GateRef receiver, AccessMode accessMode, JSTaggedValue key,
GateRef value)
{
DISALLOW_GARBAGE_COLLECTION;
@ -649,7 +649,7 @@ void TSHCRLowering::LowerNamedAccess(GateRef gate, GateRef receiver, AccessMode
acc_.ReplaceHirAndDeleteIfException(gate, StateDepend(mergeState, dependSelector), result);
}
GateRef TSHCRLowering::BuildNamedPropertyAccess(GateRef hir, ObjectAccessHelper accessHelper, PropertyLookupResult plr)
GateRef TypeBytecodeLowering::BuildNamedPropertyAccess(GateRef hir, ObjectAccessHelper accessHelper, PropertyLookupResult plr)
{
GateRef receiver = accessHelper.GetReceiver();
GateRef plrGate = builder_.Int32(plr.GetData());
@ -687,7 +687,7 @@ GateRef TSHCRLowering::BuildNamedPropertyAccess(GateRef hir, ObjectAccessHelper
return result;
}
void TSHCRLowering::BuildNamedPropertyAccessVerifier(GateRef gate, GateRef receiver, AccessMode mode, GateRef value)
void TypeBytecodeLowering::BuildNamedPropertyAccessVerifier(GateRef gate, GateRef receiver, AccessMode mode, GateRef value)
{
GateRef constData = acc_.GetValueIn(gate, 1);
uint16_t keyIndex = acc_.GetConstantValue(constData);
@ -698,7 +698,7 @@ void TSHCRLowering::BuildNamedPropertyAccessVerifier(GateRef gate, GateRef recei
builder_.CallRuntime(glue_, stubId, builder_.GetDepend(), { receiver, key, value }, gate);
}
bool TSHCRLowering::TryLowerTypedLdObjByNameForBuiltin(GateRef gate, GateType receiverType, JSTaggedValue key)
bool TypeBytecodeLowering::TryLowerTypedLdObjByNameForBuiltin(GateRef gate, GateType receiverType, JSTaggedValue key)
{
// String: primitive string type only
// e.g. let s1 = "ABC"; // OK
@ -727,7 +727,7 @@ bool TSHCRLowering::TryLowerTypedLdObjByNameForBuiltin(GateRef gate, GateType re
return false; // No lowering performed
}
bool TSHCRLowering::TryLowerTypedLdObjByNameForBuiltin(GateRef gate, JSTaggedValue key, BuiltinTypeId type)
bool TypeBytecodeLowering::TryLowerTypedLdObjByNameForBuiltin(GateRef gate, JSTaggedValue key, BuiltinTypeId type)
{
EcmaString *propString = EcmaString::Cast(key.GetTaggedObject());
// (1) get length
@ -750,7 +750,7 @@ bool TSHCRLowering::TryLowerTypedLdObjByNameForBuiltin(GateRef gate, JSTaggedVal
return TryLowerTypedLdObjByNameForBuiltinMethod(gate, key, type);
}
bool TSHCRLowering::IsCreateArray(GateRef gate)
bool TypeBytecodeLowering::IsCreateArray(GateRef gate)
{
if (acc_.GetOpCode(gate) != OpCode::JS_BYTECODE) {
return false;
@ -769,7 +769,7 @@ bool TSHCRLowering::IsCreateArray(GateRef gate)
return false;
}
void TSHCRLowering::LowerTypedLdArrayLength(GateRef gate)
void TypeBytecodeLowering::LowerTypedLdArrayLength(GateRef gate)
{
AddProfiling(gate);
GateRef array = acc_.GetValueIn(gate, 2);
@ -784,7 +784,7 @@ void TSHCRLowering::LowerTypedLdArrayLength(GateRef gate)
acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), result);
}
void TSHCRLowering::LowerTypedLdTypedArrayLength(GateRef gate)
void TypeBytecodeLowering::LowerTypedLdTypedArrayLength(GateRef gate)
{
AddProfiling(gate);
GateRef array = acc_.GetValueIn(gate, 2);
@ -797,7 +797,7 @@ void TSHCRLowering::LowerTypedLdTypedArrayLength(GateRef gate)
acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), result);
}
void TSHCRLowering::LowerTypedLdStringLength(GateRef gate)
void TypeBytecodeLowering::LowerTypedLdStringLength(GateRef gate)
{
AddProfiling(gate);
GateRef str = acc_.GetValueIn(gate, 2);
@ -808,7 +808,7 @@ void TSHCRLowering::LowerTypedLdStringLength(GateRef gate)
acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), result);
}
bool TSHCRLowering::TryLowerTypedLdObjByNameForBuiltinMethod(GateRef gate, JSTaggedValue key, BuiltinTypeId type)
bool TypeBytecodeLowering::TryLowerTypedLdObjByNameForBuiltinMethod(GateRef gate, JSTaggedValue key, BuiltinTypeId type)
{
std::optional<GlobalEnvField> protoField = ToGlobelEnvPrototypeField(type);
if (!protoField.has_value()) {
@ -842,7 +842,7 @@ bool TSHCRLowering::TryLowerTypedLdObjByNameForBuiltinMethod(GateRef gate, JSTag
return true;
}
void TSHCRLowering::LowerTypedLdObjByIndex(GateRef gate)
void TypeBytecodeLowering::LowerTypedLdObjByIndex(GateRef gate)
{
// 2: number of value inputs
ASSERT(acc_.GetNumValueIn(gate) == 2);
@ -862,7 +862,7 @@ void TSHCRLowering::LowerTypedLdObjByIndex(GateRef gate)
acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), result);
}
void TSHCRLowering::LowerTypedStObjByIndex(GateRef gate)
void TypeBytecodeLowering::LowerTypedStObjByIndex(GateRef gate)
{
// 3: number of value inputs
ASSERT(acc_.GetNumValueIn(gate) == 3);
@ -904,7 +904,7 @@ void TSHCRLowering::LowerTypedStObjByIndex(GateRef gate)
acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), Circuit::NullGate());
}
void TSHCRLowering::LowerTypedLdObjByValue(GateRef gate, bool isThis)
void TypeBytecodeLowering::LowerTypedLdObjByValue(GateRef gate, bool isThis)
{
GateRef receiver = Circuit::NullGate();
GateRef propKey = Circuit::NullGate();
@ -943,7 +943,7 @@ void TSHCRLowering::LowerTypedLdObjByValue(GateRef gate, bool isThis)
acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), result);
}
GateRef TSHCRLowering::LoadStringByIndex(GateRef receiver, GateRef propKey)
GateRef TypeBytecodeLowering::LoadStringByIndex(GateRef receiver, GateRef propKey)
{
if (!Uncheck()) {
GateType receiverType = acc_.GetGateType(receiver);
@ -956,7 +956,7 @@ GateRef TSHCRLowering::LoadStringByIndex(GateRef receiver, GateRef propKey)
return builder_.LoadElement<TypedLoadOp::STRING_LOAD_ELEMENT>(receiver, propKey);
}
GateRef TSHCRLowering::LoadJSArrayByIndex(GateRef receiver, GateRef propKey, ElementsKind kind)
GateRef TypeBytecodeLowering::LoadJSArrayByIndex(GateRef receiver, GateRef propKey, ElementsKind kind)
{
if (!Uncheck()) {
GateType receiverType = acc_.GetGateType(receiver);
@ -983,7 +983,7 @@ GateRef TSHCRLowering::LoadJSArrayByIndex(GateRef receiver, GateRef propKey, Ele
return result;
}
GateRef TSHCRLowering::LoadTypedArrayByIndex(GateRef receiver, GateRef propKey)
GateRef TypeBytecodeLowering::LoadTypedArrayByIndex(GateRef receiver, GateRef propKey)
{
GateType receiverType = acc_.GetGateType(receiver);
receiverType = tsManager_->TryNarrowUnionType(receiverType);
@ -1020,7 +1020,7 @@ GateRef TSHCRLowering::LoadTypedArrayByIndex(GateRef receiver, GateRef propKey)
return Circuit::NullGate();
}
void TSHCRLowering::StoreJSArrayByIndex(GateRef receiver, GateRef propKey, GateRef value, ElementsKind kind)
void TypeBytecodeLowering::StoreJSArrayByIndex(GateRef receiver, GateRef propKey, GateRef value, ElementsKind kind)
{
if (!Uncheck()) {
GateType receiverType = acc_.GetGateType(receiver);
@ -1041,7 +1041,7 @@ void TSHCRLowering::StoreJSArrayByIndex(GateRef receiver, GateRef propKey, GateR
}
void TSHCRLowering::StoreTypedArrayByIndex(GateRef receiver, GateRef propKey, GateRef value)
void TypeBytecodeLowering::StoreTypedArrayByIndex(GateRef receiver, GateRef propKey, GateRef value)
{
GateType receiverType = acc_.GetGateType(receiver);
receiverType = tsManager_->TryNarrowUnionType(receiverType);
@ -1086,7 +1086,7 @@ void TSHCRLowering::StoreTypedArrayByIndex(GateRef receiver, GateRef propKey, Ga
}
}
void TSHCRLowering::LowerTypedStObjByValue(GateRef gate)
void TypeBytecodeLowering::LowerTypedStObjByValue(GateRef gate)
{
ASSERT(acc_.GetNumValueIn(gate) == 4); // 4: num of value ins
GateRef receiver = acc_.GetValueIn(gate, 1); // 1: receiver
@ -1113,7 +1113,7 @@ void TSHCRLowering::LowerTypedStObjByValue(GateRef gate)
acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), Circuit::NullGate());
}
void TSHCRLowering::LowerTypedIsTrueOrFalse(GateRef gate, bool flag)
void TypeBytecodeLowering::LowerTypedIsTrueOrFalse(GateRef gate, bool flag)
{
ASSERT(acc_.GetNumValueIn(gate) == 1);
auto value = acc_.GetValueIn(gate, 0);
@ -1133,7 +1133,7 @@ void TSHCRLowering::LowerTypedIsTrueOrFalse(GateRef gate, bool flag)
acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), result);
}
void TSHCRLowering::LowerTypedNewObjRange(GateRef gate)
void TypeBytecodeLowering::LowerTypedNewObjRange(GateRef gate)
{
GateRef ctor = acc_.GetValueIn(gate, 0);
GateType ctorType = acc_.GetGateType(ctor);
@ -1160,7 +1160,7 @@ void TSHCRLowering::LowerTypedNewObjRange(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), constructGate);
}
void TSHCRLowering::LowerTypedSuperCall(GateRef gate)
void TypeBytecodeLowering::LowerTypedSuperCall(GateRef gate)
{
GateRef ctor = argAcc_.GetFrameArgsIn(gate, FrameArgIdx::FUNC);
GateType ctorType = acc_.GetGateType(ctor); // ldfunction in derived constructor get function type
@ -1190,7 +1190,7 @@ void TSHCRLowering::LowerTypedSuperCall(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), constructGate);
}
void TSHCRLowering::SpeculateCallBuiltin(GateRef gate, GateRef func, const std::vector<GateRef> &args,
void TypeBytecodeLowering::SpeculateCallBuiltin(GateRef gate, GateRef func, const std::vector<GateRef> &args,
BuiltinsStubCSigns::ID id, bool isThrow)
{
if (!Uncheck()) {
@ -1206,7 +1206,7 @@ void TSHCRLowering::SpeculateCallBuiltin(GateRef gate, GateRef func, const std::
}
}
bool TSHCRLowering::TrySpeculateCallThis0Native(GateRef gate, GateRef func, GateRef thisObj)
bool TypeBytecodeLowering::TrySpeculateCallThis0Native(GateRef gate, GateRef func, GateRef thisObj)
{
PGOSampleType sampleType = acc_.TryGetPGOType(gate);
if (sampleType.IsNone()) {
@ -1228,7 +1228,7 @@ bool TSHCRLowering::TrySpeculateCallThis0Native(GateRef gate, GateRef func, Gate
return true;
}
BuiltinsStubCSigns::ID TSHCRLowering::GetBuiltinId(BuiltinTypeId id, GateRef func)
BuiltinsStubCSigns::ID TypeBytecodeLowering::GetBuiltinId(BuiltinTypeId id, GateRef func)
{
GateType funcType = acc_.GetGateType(func);
if (!tsManager_->IsBuiltinObjectMethod(id, funcType)) {
@ -1239,7 +1239,7 @@ BuiltinsStubCSigns::ID TSHCRLowering::GetBuiltinId(BuiltinTypeId id, GateRef fun
return stubId;
}
void TSHCRLowering::CheckCallTargetFromDefineFuncAndLowerCall(GateRef gate, GateRef func, GlobalTSTypeRef funcGt,
void TypeBytecodeLowering::CheckCallTargetFromDefineFuncAndLowerCall(GateRef gate, GateRef func, GlobalTSTypeRef funcGt,
GateType funcType, const std::vector<GateRef> &args, const std::vector<GateRef> &argsFastCall, bool isNoGC)
{
if (!Uncheck()) {
@ -1252,7 +1252,7 @@ void TSHCRLowering::CheckCallTargetFromDefineFuncAndLowerCall(GateRef gate, Gate
}
}
void TSHCRLowering::LowerFastCall(GateRef gate, GateRef func,
void TypeBytecodeLowering::LowerFastCall(GateRef gate, GateRef func,
const std::vector<GateRef> &argsFastCall, bool isNoGC)
{
builder_.StartCallTimer(glue_, gate, {glue_, func, builder_.True()}, true);
@ -1261,7 +1261,7 @@ void TSHCRLowering::LowerFastCall(GateRef gate, GateRef func,
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), result);
}
void TSHCRLowering::LowerCall(GateRef gate, GateRef func,
void TypeBytecodeLowering::LowerCall(GateRef gate, GateRef func,
const std::vector<GateRef> &args, bool isNoGC)
{
builder_.StartCallTimer(glue_, gate, {glue_, func, builder_.True()}, true);
@ -1270,7 +1270,7 @@ void TSHCRLowering::LowerCall(GateRef gate, GateRef func,
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), result);
}
void TSHCRLowering::CheckCallTargetAndLowerCall(GateRef gate, GateRef func, GlobalTSTypeRef funcGt,
void TypeBytecodeLowering::CheckCallTargetAndLowerCall(GateRef gate, GateRef func, GlobalTSTypeRef funcGt,
GateType funcType, const std::vector<GateRef> &args, const std::vector<GateRef> &argsFastCall)
{
if (IsLoadVtable(func)) {
@ -1306,7 +1306,7 @@ void TSHCRLowering::CheckCallTargetAndLowerCall(GateRef gate, GateRef func, Glob
}
}
void TSHCRLowering::LowerTypedCallArg0(GateRef gate)
void TypeBytecodeLowering::LowerTypedCallArg0(GateRef gate)
{
GateRef func = acc_.GetValueIn(gate, 0);
GateType funcType = acc_.GetGateType(func);
@ -1318,7 +1318,7 @@ void TSHCRLowering::LowerTypedCallArg0(GateRef gate)
LowerTypedCall(gate, func, actualArgc, funcType, 0);
}
void TSHCRLowering::LowerTypedCallArg1(GateRef gate)
void TypeBytecodeLowering::LowerTypedCallArg1(GateRef gate)
{
GateRef func = acc_.GetValueIn(gate, 1);
GateType funcType = acc_.GetGateType(func);
@ -1338,7 +1338,7 @@ void TSHCRLowering::LowerTypedCallArg1(GateRef gate)
}
}
void TSHCRLowering::LowerTypedCallArg2(GateRef gate)
void TypeBytecodeLowering::LowerTypedCallArg2(GateRef gate)
{
GateRef func = acc_.GetValueIn(gate, 2); // 2:function
GateType funcType = acc_.GetGateType(func);
@ -1350,7 +1350,7 @@ void TSHCRLowering::LowerTypedCallArg2(GateRef gate)
LowerTypedCall(gate, func, actualArgc, funcType, 2); // 2: 2 params
}
void TSHCRLowering::LowerTypedCallArg3(GateRef gate)
void TypeBytecodeLowering::LowerTypedCallArg3(GateRef gate)
{
GateRef func = acc_.GetValueIn(gate, 3); // 3:function
GateType funcType = acc_.GetGateType(func);
@ -1362,7 +1362,7 @@ void TSHCRLowering::LowerTypedCallArg3(GateRef gate)
LowerTypedCall(gate, func, actualArgc, funcType, 3); // 3: 3 params
}
void TSHCRLowering::LowerTypedCallrange(GateRef gate)
void TypeBytecodeLowering::LowerTypedCallrange(GateRef gate)
{
std::vector<GateRef> vec;
std::vector<GateRef> vec1;
@ -1379,7 +1379,7 @@ void TSHCRLowering::LowerTypedCallrange(GateRef gate)
LowerTypedCall(gate, func, actualArgc, funcType, argc);
}
void TSHCRLowering::LowerTypedCall(GateRef gate, GateRef func, GateRef actualArgc, GateType funcType, uint32_t argc)
void TypeBytecodeLowering::LowerTypedCall(GateRef gate, GateRef func, GateRef actualArgc, GateType funcType, uint32_t argc)
{
GlobalTSTypeRef funcGt = funcType.GetGTRef();
if (!tsManager_->IsHotnessFunc(funcGt)) {
@ -1402,7 +1402,7 @@ void TSHCRLowering::LowerTypedCall(GateRef gate, GateRef func, GateRef actualArg
CheckCallTargetAndLowerCall(gate, func, funcGt, funcType, args, argsFastCall);
}
bool TSHCRLowering::IsLoadVtable(GateRef func)
bool TypeBytecodeLowering::IsLoadVtable(GateRef func)
{
auto op = acc_.GetOpCode(func);
if (op != OpCode::LOAD_PROPERTY || !acc_.IsVtable(func)) {
@ -1411,7 +1411,7 @@ bool TSHCRLowering::IsLoadVtable(GateRef func)
return true;
}
bool TSHCRLowering::CanOptimizeAsFastCall(GateRef func)
bool TypeBytecodeLowering::CanOptimizeAsFastCall(GateRef func)
{
GateType funcType = acc_.GetGateType(func);
if (!tsManager_->IsFunctionTypeKind(funcType)) {
@ -1424,7 +1424,7 @@ bool TSHCRLowering::CanOptimizeAsFastCall(GateRef func)
return true;
}
void TSHCRLowering::CheckFastCallThisCallTarget(GateRef gate, GateRef func, GlobalTSTypeRef funcGt,
void TypeBytecodeLowering::CheckFastCallThisCallTarget(GateRef gate, GateRef func, GlobalTSTypeRef funcGt,
GateType funcType, bool isNoGC)
{
if (noCheck_) {
@ -1440,7 +1440,7 @@ void TSHCRLowering::CheckFastCallThisCallTarget(GateRef gate, GateRef func, Glob
}
}
void TSHCRLowering::CheckCallThisCallTarget(GateRef gate, GateRef func, GlobalTSTypeRef funcGt,
void TypeBytecodeLowering::CheckCallThisCallTarget(GateRef gate, GateRef func, GlobalTSTypeRef funcGt,
GateType funcType, bool isNoGC)
{
if (noCheck_) {
@ -1456,7 +1456,7 @@ void TSHCRLowering::CheckCallThisCallTarget(GateRef gate, GateRef func, GlobalTS
}
}
void TSHCRLowering::CheckThisCallTargetAndLowerCall(GateRef gate, GateRef func, GlobalTSTypeRef funcGt,
void TypeBytecodeLowering::CheckThisCallTargetAndLowerCall(GateRef gate, GateRef func, GlobalTSTypeRef funcGt,
GateType funcType, const std::vector<GateRef> &args, const std::vector<GateRef> &argsFastCall)
{
if (!tsManager_->FastCallFlagIsVaild(funcGt)) {
@ -1472,7 +1472,7 @@ void TSHCRLowering::CheckThisCallTargetAndLowerCall(GateRef gate, GateRef func,
}
}
void TSHCRLowering::LowerTypedCallthis0(GateRef gate)
void TypeBytecodeLowering::LowerTypedCallthis0(GateRef gate)
{
// 2: number of value inputs
ASSERT(acc_.GetNumValueIn(gate) == 2);
@ -1495,7 +1495,7 @@ void TSHCRLowering::LowerTypedCallthis0(GateRef gate)
LowerTypedThisCall(gate, func, actualArgc, 0);
}
void TSHCRLowering::LowerTypedCallthis1(GateRef gate)
void TypeBytecodeLowering::LowerTypedCallthis1(GateRef gate)
{
// 3: number of value inputs
ASSERT(acc_.GetNumValueIn(gate) == 3);
@ -1523,7 +1523,7 @@ void TSHCRLowering::LowerTypedCallthis1(GateRef gate)
LowerTypedThisCall(gate, func, actualArgc, 1);
}
void TSHCRLowering::LowerTypedCallthis2(GateRef gate)
void TypeBytecodeLowering::LowerTypedCallthis2(GateRef gate)
{
// 4: number of value inputs
ASSERT(acc_.GetNumValueIn(gate) == 4);
@ -1536,7 +1536,7 @@ void TSHCRLowering::LowerTypedCallthis2(GateRef gate)
LowerTypedThisCall(gate, func, actualArgc, 2); // 2: 2 params
}
void TSHCRLowering::LowerTypedCallthis3(GateRef gate)
void TypeBytecodeLowering::LowerTypedCallthis3(GateRef gate)
{
// 5: number of value inputs
ASSERT(acc_.GetNumValueIn(gate) == 5);
@ -1560,7 +1560,7 @@ void TSHCRLowering::LowerTypedCallthis3(GateRef gate)
LowerTypedThisCall(gate, func, actualArgc, 3); // 3: 3 params
}
void TSHCRLowering::LowerTypedThisCall(GateRef gate, GateRef func, GateRef actualArgc, uint32_t argc)
void TypeBytecodeLowering::LowerTypedThisCall(GateRef gate, GateRef func, GateRef actualArgc, uint32_t argc)
{
GateType funcType = acc_.GetGateType(func);
GlobalTSTypeRef funcGt = funcType.GetGTRef();
@ -1582,7 +1582,7 @@ void TSHCRLowering::LowerTypedThisCall(GateRef gate, GateRef func, GateRef actua
}
void TSHCRLowering::LowerTypedCallthisrange(GateRef gate)
void TypeBytecodeLowering::LowerTypedCallthisrange(GateRef gate)
{
// this
size_t fixedInputsNum = 1;
@ -1598,7 +1598,7 @@ void TSHCRLowering::LowerTypedCallthisrange(GateRef gate)
LowerTypedThisCall(gate, func, actualArgc, numIns - callTargetIndex - fixedInputsNum);
}
void TSHCRLowering::AddProfiling(GateRef gate)
void TypeBytecodeLowering::AddProfiling(GateRef gate)
{
hitTypedOpCount_++;
AddHitBytecodeCount();
@ -1644,7 +1644,7 @@ void TSHCRLowering::AddProfiling(GateRef gate)
}
}
void TSHCRLowering::AddBytecodeCount(EcmaOpcode op)
void TypeBytecodeLowering::AddBytecodeCount(EcmaOpcode op)
{
currentOp_ = op;
if (bytecodeMap_.find(op) != bytecodeMap_.end()) {
@ -1654,12 +1654,12 @@ void TSHCRLowering::AddBytecodeCount(EcmaOpcode op)
}
}
void TSHCRLowering::DeleteBytecodeCount(EcmaOpcode op)
void TypeBytecodeLowering::DeleteBytecodeCount(EcmaOpcode op)
{
bytecodeMap_.erase(op);
}
void TSHCRLowering::AddHitBytecodeCount()
void TypeBytecodeLowering::AddHitBytecodeCount()
{
if (bytecodeHitTimeMap_.find(currentOp_) != bytecodeHitTimeMap_.end()) {
bytecodeHitTimeMap_[currentOp_]++;
@ -1669,7 +1669,7 @@ void TSHCRLowering::AddHitBytecodeCount()
}
void TSHCRLowering::LowerTypedTypeOf(GateRef gate)
void TypeBytecodeLowering::LowerTypedTypeOf(GateRef gate)
{
// 1: number of value inputs
ASSERT(acc_.GetNumValueIn(gate) == 1);
@ -1690,7 +1690,7 @@ void TSHCRLowering::LowerTypedTypeOf(GateRef gate)
acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), result);
}
void TSHCRLowering::LowerGetIterator(GateRef gate)
void TypeBytecodeLowering::LowerGetIterator(GateRef gate)
{
PGOSampleType sampleType = acc_.TryGetPGOType(gate);
if (sampleType.IsNone()) {

View File

@ -13,8 +13,8 @@
* limitations under the License.
*/
#ifndef ECMASCRIPT_COMPILER_TS_HCR_LOWERING_H
#define ECMASCRIPT_COMPILER_TS_HCR_LOWERING_H
#ifndef ECMASCRIPT_COMPILER_TYPE_BYTECODE_LOWERING_H
#define ECMASCRIPT_COMPILER_TYPE_BYTECODE_LOWERING_H
#include "ecmascript/compiler/argument_accessor.h"
#include "ecmascript/compiler/builtins/builtins_call_signature.h"
@ -24,9 +24,9 @@
#include "ecmascript/compiler/pass_manager.h"
namespace panda::ecmascript::kungfu {
class TSHCRLowering {
class TypeBytecodeLowering {
public:
TSHCRLowering(Circuit *circuit, PassContext *ctx,
TypeBytecodeLowering(Circuit *circuit, PassContext *ctx,
bool enableLog, bool enableTypeLog,
const std::string& name)
: circuit_(circuit),
@ -46,9 +46,9 @@ public:
noCheck_(ctx->GetEcmaVM()->GetJSOptions().IsCompilerNoCheck()),
thread_(ctx->GetEcmaVM()->GetJSThread()) {}
~TSHCRLowering() = default;
~TypeBytecodeLowering() = default;
bool RunTSHCRLowering();
bool RunTypeBytecodeLowering();
private:
bool IsLogEnabled() const
@ -203,4 +203,4 @@ private:
const JSThread *thread_ {nullptr};
};
} // panda::ecmascript::kungfu
#endif // ECMASCRIPT_COMPILER_TS_HCR_LOWERING_H
#endif // ECMASCRIPT_COMPILER_TYPE_BYTECODE_LOWERING_H

View File

@ -13,7 +13,7 @@
* limitations under the License.
*/
#include "ecmascript/compiler/type_mcr_lowering.h"
#include "ecmascript/compiler/type_hcr_lowering.h"
#include "ecmascript/compiler/builtins_lowering.h"
#include "ecmascript/compiler/share_gate_meta_data.h"
#include "ecmascript/compiler/new_object_stub_builder.h"
@ -25,7 +25,7 @@
#include "ecmascript/message_string.h"
namespace panda::ecmascript::kungfu {
using PGONativeFunctionId = panda::ecmascript::pgo::DumpUtils::PGONativeFunctionId;
GateRef TypeMCRLowering::VisitGate(GateRef gate)
GateRef TypeHCRLowering::VisitGate(GateRef gate)
{
GateRef glue = acc_.GetGlueFromArgList();
auto op = acc_.GetOpCode(gate);
@ -151,7 +151,7 @@ GateRef TypeMCRLowering::VisitGate(GateRef gate)
return Circuit::NullGate();
}
void TypeMCRLowering::LowerJSCallTargetCheck(GateRef gate)
void TypeHCRLowering::LowerJSCallTargetCheck(GateRef gate)
{
TypedCallTargetCheckOp Op = acc_.GetTypedCallTargetCheckOp(gate);
switch (Op) {
@ -189,7 +189,7 @@ void TypeMCRLowering::LowerJSCallTargetCheck(GateRef gate)
}
}
void TypeMCRLowering::LowerPrimitiveTypeCheck(GateRef gate)
void TypeHCRLowering::LowerPrimitiveTypeCheck(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
auto type = acc_.GetParamGateType(gate);
@ -207,7 +207,7 @@ void TypeMCRLowering::LowerPrimitiveTypeCheck(GateRef gate)
}
}
void TypeMCRLowering::LowerIntCheck(GateRef gate)
void TypeHCRLowering::LowerIntCheck(GateRef gate)
{
GateRef frameState = GetFrameState(gate);
@ -218,7 +218,7 @@ void TypeMCRLowering::LowerIntCheck(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), Circuit::NullGate());
}
void TypeMCRLowering::LowerDoubleCheck(GateRef gate)
void TypeHCRLowering::LowerDoubleCheck(GateRef gate)
{
GateRef frameState = GetFrameState(gate);
@ -229,7 +229,7 @@ void TypeMCRLowering::LowerDoubleCheck(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), Circuit::NullGate());
}
void TypeMCRLowering::LowerNumberCheck(GateRef gate)
void TypeHCRLowering::LowerNumberCheck(GateRef gate)
{
GateRef frameState = GetFrameState(gate);
@ -240,7 +240,7 @@ void TypeMCRLowering::LowerNumberCheck(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), Circuit::NullGate());
}
void TypeMCRLowering::LowerBooleanCheck(GateRef gate)
void TypeHCRLowering::LowerBooleanCheck(GateRef gate)
{
GateRef frameState = GetFrameState(gate);
@ -251,7 +251,7 @@ void TypeMCRLowering::LowerBooleanCheck(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), Circuit::NullGate());
}
void TypeMCRLowering::LowerStableArrayCheck(GateRef gate)
void TypeHCRLowering::LowerStableArrayCheck(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
GateRef frameState = GetFrameState(gate);
@ -268,7 +268,7 @@ void TypeMCRLowering::LowerStableArrayCheck(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), Circuit::NullGate());
}
void TypeMCRLowering::SetDeoptTypeInfo(BuiltinTypeId id, DeoptType &type, size_t &funcIndex)
void TypeHCRLowering::SetDeoptTypeInfo(BuiltinTypeId id, DeoptType &type, size_t &funcIndex)
{
type = DeoptType::NOTARRAY;
switch (id) {
@ -311,7 +311,7 @@ void TypeMCRLowering::SetDeoptTypeInfo(BuiltinTypeId id, DeoptType &type, size_t
}
}
void TypeMCRLowering::LowerTypedArrayCheck(GateRef gate)
void TypeHCRLowering::LowerTypedArrayCheck(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
auto type = acc_.GetParamGateType(gate);
@ -337,7 +337,7 @@ void TypeMCRLowering::LowerTypedArrayCheck(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), Circuit::NullGate());
}
void TypeMCRLowering::LowerEcmaStringCheck(GateRef gate)
void TypeHCRLowering::LowerEcmaStringCheck(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
GateRef frameState = GetFrameState(gate);
@ -349,7 +349,7 @@ void TypeMCRLowering::LowerEcmaStringCheck(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), Circuit::NullGate());
}
void TypeMCRLowering::LowerFlattenTreeStringCheck(GateRef gate, GateRef glue)
void TypeHCRLowering::LowerFlattenTreeStringCheck(GateRef gate, GateRef glue)
{
Environment env(gate, circuit_, &builder_);
GateRef str = acc_.GetValueIn(gate, 0);
@ -379,14 +379,14 @@ void TypeMCRLowering::LowerFlattenTreeStringCheck(GateRef gate, GateRef glue)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), *result);
}
GateRef TypeMCRLowering::GetLengthFromString(GateRef gate)
GateRef TypeHCRLowering::GetLengthFromString(GateRef gate)
{
GateRef shiftCount = builder_.Int32(EcmaString::STRING_LENGTH_SHIFT_COUNT);
return builder_.Int32LSR(
builder_.LoadConstOffset(VariableType::INT32(), gate, EcmaString::MIX_LENGTH_OFFSET), shiftCount);
}
void TypeMCRLowering::LowerStringLength(GateRef gate)
void TypeHCRLowering::LowerStringLength(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
GateRef receiver = acc_.GetValueIn(gate, 0);
@ -395,7 +395,7 @@ void TypeMCRLowering::LowerStringLength(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), length);
}
void TypeMCRLowering::LowerLoadTypedArrayLength(GateRef gate)
void TypeHCRLowering::LowerLoadTypedArrayLength(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
GateRef receiver = acc_.GetValueIn(gate, 0);
@ -403,7 +403,7 @@ void TypeMCRLowering::LowerLoadTypedArrayLength(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), length);
}
void TypeMCRLowering::LowerObjectTypeCheck(GateRef gate)
void TypeHCRLowering::LowerObjectTypeCheck(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
GateType type = acc_.GetObjectTypeAccessor(gate).GetType();
@ -418,7 +418,7 @@ void TypeMCRLowering::LowerObjectTypeCheck(GateRef gate)
}
}
void TypeMCRLowering::LowerTSSubtypingCheck(GateRef gate)
void TypeHCRLowering::LowerTSSubtypingCheck(GateRef gate)
{
GateRef frameState = GetFrameState(gate);
Label levelValid(&builder_);
@ -428,7 +428,7 @@ void TypeMCRLowering::LowerTSSubtypingCheck(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), Circuit::NullGate());
}
void TypeMCRLowering::LowerSimpleHClassCheck(GateRef gate)
void TypeHCRLowering::LowerSimpleHClassCheck(GateRef gate)
{
GateRef frameState = GetFrameState(gate);
GateRef compare = BuildCompareHClass(gate, frameState);
@ -436,7 +436,7 @@ void TypeMCRLowering::LowerSimpleHClassCheck(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), Circuit::NullGate());
}
void TypeMCRLowering::LowerObjectTypeCompare(GateRef gate)
void TypeHCRLowering::LowerObjectTypeCompare(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
auto type = acc_.GetObjectTypeAccessor(gate).GetType();
@ -451,14 +451,14 @@ void TypeMCRLowering::LowerObjectTypeCompare(GateRef gate)
}
}
void TypeMCRLowering::LowerSimpleHClassCompare(GateRef gate)
void TypeHCRLowering::LowerSimpleHClassCompare(GateRef gate)
{
GateRef frameState = GetFrameState(gate);
GateRef compare = BuildCompareHClass(gate, frameState) ;
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), compare);
}
void TypeMCRLowering::LowerTSSubtypingCompare(GateRef gate)
void TypeHCRLowering::LowerTSSubtypingCompare(GateRef gate)
{
GateRef frameState = GetFrameState(gate);
Label levelValid(&builder_);
@ -467,7 +467,7 @@ void TypeMCRLowering::LowerTSSubtypingCompare(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), compare);
}
GateRef TypeMCRLowering::BuildCompareSubTyping(GateRef gate, GateRef frameState, Label *levelValid, Label *exit)
GateRef TypeHCRLowering::BuildCompareSubTyping(GateRef gate, GateRef frameState, Label *levelValid, Label *exit)
{
GateRef receiver = acc_.GetValueIn(gate, 0);
bool isHeapObject = acc_.GetObjectTypeAccessor(gate).IsHeapObject();
@ -510,7 +510,7 @@ GateRef TypeMCRLowering::BuildCompareSubTyping(GateRef gate, GateRef frameState,
return *check;
}
GateRef TypeMCRLowering::BuildCompareHClass(GateRef gate, GateRef frameState)
GateRef TypeHCRLowering::BuildCompareHClass(GateRef gate, GateRef frameState)
{
GateRef receiver = acc_.GetValueIn(gate, 0);
bool isHeapObject = acc_.GetObjectTypeAccessor(gate).IsHeapObject();
@ -528,7 +528,7 @@ GateRef TypeMCRLowering::BuildCompareHClass(GateRef gate, GateRef frameState)
return builder_.Equal(aotHCGate, receiverHClass, "checkHClass");
}
void TypeMCRLowering::LowerRangeCheckPredicate(GateRef gate)
void TypeHCRLowering::LowerRangeCheckPredicate(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
auto deoptType = DeoptType::NOTARRAY;
@ -560,7 +560,7 @@ void TypeMCRLowering::LowerRangeCheckPredicate(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), Circuit::NullGate());
}
void TypeMCRLowering::LowerBuiltinPrototypeHClassCheck(GateRef gate)
void TypeHCRLowering::LowerBuiltinPrototypeHClassCheck(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
BuiltinPrototypeHClassAccessor accessor = acc_.GetBuiltinHClassAccessor(gate);
@ -587,7 +587,7 @@ void TypeMCRLowering::LowerBuiltinPrototypeHClassCheck(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), Circuit::NullGate());
}
void TypeMCRLowering::LowerIndexCheck(GateRef gate)
void TypeHCRLowering::LowerIndexCheck(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
auto deoptType = DeoptType::NOTLEGALIDX;
@ -602,7 +602,7 @@ void TypeMCRLowering::LowerIndexCheck(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), index);
}
GateRef TypeMCRLowering::LowerCallRuntime(GateRef glue, GateRef hirGate, int index, const std::vector<GateRef> &args,
GateRef TypeHCRLowering::LowerCallRuntime(GateRef glue, GateRef hirGate, int index, const std::vector<GateRef> &args,
bool useLabel)
{
if (useLabel) {
@ -616,7 +616,7 @@ GateRef TypeMCRLowering::LowerCallRuntime(GateRef glue, GateRef hirGate, int ind
}
}
void TypeMCRLowering::LowerTypeConvert(GateRef gate)
void TypeHCRLowering::LowerTypeConvert(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
auto leftType = acc_.GetLeftType(gate);
@ -630,7 +630,7 @@ void TypeMCRLowering::LowerTypeConvert(GateRef gate)
}
}
void TypeMCRLowering::LowerPrimitiveToNumber(GateRef dst, GateRef src, GateType srcType)
void TypeHCRLowering::LowerPrimitiveToNumber(GateRef dst, GateRef src, GateType srcType)
{
DEFVAlUE(result, (&builder_), VariableType::JS_ANY(), builder_.HoleConstant());
if (srcType.IsBooleanType()) {
@ -662,19 +662,19 @@ void TypeMCRLowering::LowerPrimitiveToNumber(GateRef dst, GateRef src, GateType
acc_.ReplaceGate(dst, builder_.GetState(), builder_.GetDepend(), *result);
}
GateRef TypeMCRLowering::LoadFromConstPool(GateRef jsFunc, size_t index)
GateRef TypeHCRLowering::LoadFromConstPool(GateRef jsFunc, size_t index)
{
GateRef constPool = builder_.GetConstPool(jsFunc);
return builder_.LoadFromTaggedArray(constPool, index);
}
GateRef TypeMCRLowering::GetObjectFromConstPool(GateRef jsFunc, GateRef index)
GateRef TypeHCRLowering::GetObjectFromConstPool(GateRef jsFunc, GateRef index)
{
GateRef constPool = builder_.GetConstPool(jsFunc);
return builder_.GetValueFromTaggedArray(constPool, index);
}
void TypeMCRLowering::LowerLoadProperty(GateRef gate)
void TypeHCRLowering::LowerLoadProperty(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
ASSERT(acc_.GetNumValueIn(gate) == 2); // 2: receiver, plr
@ -697,7 +697,7 @@ void TypeMCRLowering::LowerLoadProperty(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), result);
}
void TypeMCRLowering::LowerCallGetter(GateRef gate, GateRef glue)
void TypeHCRLowering::LowerCallGetter(GateRef gate, GateRef glue)
{
Environment env(gate, circuit_, &builder_);
ASSERT(acc_.GetNumValueIn(gate) == 2); // 2: receiver, plr
@ -722,7 +722,7 @@ void TypeMCRLowering::LowerCallGetter(GateRef gate, GateRef glue)
ReplaceHirWithPendingException(gate, glue, builder_.GetState(), builder_.GetDepend(), *result);
}
void TypeMCRLowering::LowerStoreProperty(GateRef gate)
void TypeHCRLowering::LowerStoreProperty(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
ASSERT(acc_.GetNumValueIn(gate) == 3); // 3: receiver, plr, value
@ -742,7 +742,7 @@ void TypeMCRLowering::LowerStoreProperty(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), Circuit::NullGate());
}
void TypeMCRLowering::LowerCallSetter(GateRef gate, GateRef glue)
void TypeHCRLowering::LowerCallSetter(GateRef gate, GateRef glue)
{
Environment env(gate, circuit_, &builder_);
ASSERT(acc_.GetNumValueIn(gate) == 3); // 3: receiver, plr, value
@ -767,7 +767,7 @@ void TypeMCRLowering::LowerCallSetter(GateRef gate, GateRef glue)
ReplaceHirWithPendingException(gate, glue, builder_.GetState(), builder_.GetDepend(), Circuit::NullGate());
}
void TypeMCRLowering::LowerLoadArrayLength(GateRef gate)
void TypeHCRLowering::LowerLoadArrayLength(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
GateRef array = acc_.GetValueIn(gate, 0);
@ -776,7 +776,7 @@ void TypeMCRLowering::LowerLoadArrayLength(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), result);
}
GateRef TypeMCRLowering::GetElementSize(BuiltinTypeId id)
GateRef TypeHCRLowering::GetElementSize(BuiltinTypeId id)
{
GateRef elementSize = Circuit::NullGate();
switch (id) {
@ -804,7 +804,7 @@ GateRef TypeMCRLowering::GetElementSize(BuiltinTypeId id)
return elementSize;
}
VariableType TypeMCRLowering::GetVariableType(BuiltinTypeId id)
VariableType TypeHCRLowering::GetVariableType(BuiltinTypeId id)
{
VariableType type = VariableType::JS_ANY();
switch (id) {
@ -834,7 +834,7 @@ VariableType TypeMCRLowering::GetVariableType(BuiltinTypeId id)
return type;
}
void TypeMCRLowering::LowerLoadElement(GateRef gate)
void TypeHCRLowering::LowerLoadElement(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
auto op = acc_.GetTypedLoadOp(gate);
@ -884,7 +884,7 @@ void TypeMCRLowering::LowerLoadElement(GateRef gate)
}
}
void TypeMCRLowering::LowerCowArrayCheck(GateRef gate, GateRef glue)
void TypeHCRLowering::LowerCowArrayCheck(GateRef gate, GateRef glue)
{
Environment env(gate, circuit_, &builder_);
GateRef receiver = acc_.GetValueIn(gate, 0);
@ -902,7 +902,7 @@ void TypeMCRLowering::LowerCowArrayCheck(GateRef gate, GateRef glue)
}
// for JSArray
void TypeMCRLowering::LowerArrayLoadElement(GateRef gate, ArrayState arrayState)
void TypeHCRLowering::LowerArrayLoadElement(GateRef gate, ArrayState arrayState)
{
Environment env(gate, circuit_, &builder_);
GateRef receiver = acc_.GetValueIn(gate, 0);
@ -915,7 +915,7 @@ void TypeMCRLowering::LowerArrayLoadElement(GateRef gate, ArrayState arrayState)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), result);
}
void TypeMCRLowering::LowerTypedArrayLoadElement(GateRef gate, BuiltinTypeId id)
void TypeHCRLowering::LowerTypedArrayLoadElement(GateRef gate, BuiltinTypeId id)
{
Environment env(gate, circuit_, &builder_);
GateRef receiver = acc_.GetValueIn(gate, 0);
@ -957,7 +957,7 @@ void TypeMCRLowering::LowerTypedArrayLoadElement(GateRef gate, BuiltinTypeId id)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), result);
}
GateRef TypeMCRLowering::BuildOnHeapTypedArrayLoadElement(GateRef receiver, GateRef offset, VariableType type)
GateRef TypeHCRLowering::BuildOnHeapTypedArrayLoadElement(GateRef receiver, GateRef offset, VariableType type)
{
GateRef arrbuffer =
builder_.LoadConstOffset(VariableType::JS_POINTER(), receiver, JSTypedArray::VIEWED_ARRAY_BUFFER_OFFSET);
@ -966,7 +966,7 @@ GateRef TypeMCRLowering::BuildOnHeapTypedArrayLoadElement(GateRef receiver, Gate
return result;
}
GateRef TypeMCRLowering::BuildTypedArrayLoadElement(GateRef receiver, GateRef offset, VariableType type,
GateRef TypeHCRLowering::BuildTypedArrayLoadElement(GateRef receiver, GateRef offset, VariableType type,
Label *isByteArray, Label *isArrayBuffer, Label *exit)
{
GateRef byteArrayOrArraybuffer =
@ -997,7 +997,7 @@ GateRef TypeMCRLowering::BuildTypedArrayLoadElement(GateRef receiver, GateRef of
return *result;
}
void TypeMCRLowering::LowerStringLoadElement(GateRef gate)
void TypeHCRLowering::LowerStringLoadElement(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
GateRef glue = acc_.GetGlueFromArgList();
@ -1009,7 +1009,7 @@ void TypeMCRLowering::LowerStringLoadElement(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), result);
}
void TypeMCRLowering::LowerStoreElement(GateRef gate, GateRef glue)
void TypeHCRLowering::LowerStoreElement(GateRef gate, GateRef glue)
{
Environment env(gate, circuit_, &builder_);
auto op = acc_.GetTypedStoreOp(gate);
@ -1051,7 +1051,7 @@ void TypeMCRLowering::LowerStoreElement(GateRef gate, GateRef glue)
}
// for JSArray
void TypeMCRLowering::LowerArrayStoreElement(GateRef gate, GateRef glue)
void TypeHCRLowering::LowerArrayStoreElement(GateRef gate, GateRef glue)
{
Environment env(gate, circuit_, &builder_);
GateRef receiver = acc_.GetValueIn(gate, 0); // 0: receiver
@ -1065,7 +1065,7 @@ void TypeMCRLowering::LowerArrayStoreElement(GateRef gate, GateRef glue)
}
// for JSTypedArray
void TypeMCRLowering::LowerTypedArrayStoreElement(GateRef gate, BuiltinTypeId id)
void TypeHCRLowering::LowerTypedArrayStoreElement(GateRef gate, BuiltinTypeId id)
{
Environment env(gate, circuit_, &builder_);
GateRef receiver = acc_.GetValueIn(gate, 0);
@ -1102,7 +1102,7 @@ void TypeMCRLowering::LowerTypedArrayStoreElement(GateRef gate, BuiltinTypeId id
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), Circuit::NullGate());
}
void TypeMCRLowering::BuildOnHeapTypedArrayStoreElement(GateRef receiver, GateRef offset, GateRef value)
void TypeHCRLowering::BuildOnHeapTypedArrayStoreElement(GateRef receiver, GateRef offset, GateRef value)
{
GateRef arrbuffer = builder_.LoadConstOffset(VariableType::JS_POINTER(), receiver,
JSTypedArray::VIEWED_ARRAY_BUFFER_OFFSET);
@ -1111,7 +1111,7 @@ void TypeMCRLowering::BuildOnHeapTypedArrayStoreElement(GateRef receiver, GateRe
builder_.StoreMemory(MemoryType::ELEMENT_TYPE, VariableType::VOID(), data, offset, value);
}
void TypeMCRLowering::BuildTypedArrayStoreElement(GateRef receiver, GateRef offset, GateRef value,
void TypeHCRLowering::BuildTypedArrayStoreElement(GateRef receiver, GateRef offset, GateRef value,
Label *isByteArray, Label *isArrayBuffer, Label *exit)
{
GateRef byteArrayOrArraybuffer = builder_.LoadConstOffset(VariableType::JS_POINTER(), receiver,
@ -1140,7 +1140,7 @@ void TypeMCRLowering::BuildTypedArrayStoreElement(GateRef receiver, GateRef offs
}
// for UInt8ClampedArray
void TypeMCRLowering::LowerUInt8ClampedArrayStoreElement(GateRef gate)
void TypeHCRLowering::LowerUInt8ClampedArrayStoreElement(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
@ -1184,34 +1184,34 @@ void TypeMCRLowering::LowerUInt8ClampedArrayStoreElement(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), Circuit::NullGate());
}
GateRef TypeMCRLowering::DoubleToTaggedDoublePtr(GateRef gate)
GateRef TypeHCRLowering::DoubleToTaggedDoublePtr(GateRef gate)
{
return builder_.DoubleToTaggedDoublePtr(gate);
}
GateRef TypeMCRLowering::ChangeInt32ToFloat64(GateRef gate)
GateRef TypeHCRLowering::ChangeInt32ToFloat64(GateRef gate)
{
return builder_.ChangeInt32ToFloat64(gate);
}
GateRef TypeMCRLowering::TruncDoubleToInt(GateRef gate)
GateRef TypeHCRLowering::TruncDoubleToInt(GateRef gate)
{
return builder_.TruncInt64ToInt32(builder_.TruncFloatToInt64(gate));
}
GateRef TypeMCRLowering::IntToTaggedIntPtr(GateRef x)
GateRef TypeHCRLowering::IntToTaggedIntPtr(GateRef x)
{
GateRef val = builder_.SExtInt32ToInt64(x);
return builder_.ToTaggedIntPtr(val);
}
void TypeMCRLowering::LowerTypedCallBuitin(GateRef gate)
void TypeHCRLowering::LowerTypedCallBuitin(GateRef gate)
{
BuiltinLowering lowering(circuit_);
lowering.LowerTypedCallBuitin(gate);
}
void TypeMCRLowering::LowerJSCallTargetFromDefineFuncCheck(GateRef gate)
void TypeHCRLowering::LowerJSCallTargetFromDefineFuncCheck(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
auto type = acc_.GetParamGateType(gate);
@ -1227,7 +1227,7 @@ void TypeMCRLowering::LowerJSCallTargetFromDefineFuncCheck(GateRef gate)
}
}
void TypeMCRLowering::LowerJSCallTargetTypeCheck(GateRef gate)
void TypeHCRLowering::LowerJSCallTargetTypeCheck(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
auto type = acc_.GetParamGateType(gate);
@ -1251,7 +1251,7 @@ void TypeMCRLowering::LowerJSCallTargetTypeCheck(GateRef gate)
}
}
void TypeMCRLowering::LowerJSFastCallTargetTypeCheck(GateRef gate)
void TypeHCRLowering::LowerJSFastCallTargetTypeCheck(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
auto type = acc_.GetParamGateType(gate);
@ -1275,7 +1275,7 @@ void TypeMCRLowering::LowerJSFastCallTargetTypeCheck(GateRef gate)
}
}
void TypeMCRLowering::LowerJSCallThisTargetTypeCheck(GateRef gate)
void TypeHCRLowering::LowerJSCallThisTargetTypeCheck(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
auto type = acc_.GetParamGateType(gate);
@ -1293,7 +1293,7 @@ void TypeMCRLowering::LowerJSCallThisTargetTypeCheck(GateRef gate)
}
}
void TypeMCRLowering::LowerJSNoGCCallThisTargetTypeCheck(GateRef gate)
void TypeHCRLowering::LowerJSNoGCCallThisTargetTypeCheck(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
auto type = acc_.GetParamGateType(gate);
@ -1313,7 +1313,7 @@ void TypeMCRLowering::LowerJSNoGCCallThisTargetTypeCheck(GateRef gate)
}
}
void TypeMCRLowering::LowerJSFastCallThisTargetTypeCheck(GateRef gate)
void TypeHCRLowering::LowerJSFastCallThisTargetTypeCheck(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
auto type = acc_.GetParamGateType(gate);
@ -1331,7 +1331,7 @@ void TypeMCRLowering::LowerJSFastCallThisTargetTypeCheck(GateRef gate)
}
}
void TypeMCRLowering::LowerJSNoGCFastCallThisTargetTypeCheck(GateRef gate)
void TypeHCRLowering::LowerJSNoGCFastCallThisTargetTypeCheck(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
auto type = acc_.GetParamGateType(gate);
@ -1351,7 +1351,7 @@ void TypeMCRLowering::LowerJSNoGCFastCallThisTargetTypeCheck(GateRef gate)
}
}
void TypeMCRLowering::LowerCallTargetCheck(GateRef gate)
void TypeHCRLowering::LowerCallTargetCheck(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
GateRef frameState = GetFrameState(gate);
@ -1369,7 +1369,7 @@ void TypeMCRLowering::LowerCallTargetCheck(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), Circuit::NullGate());
}
void TypeMCRLowering::LowerJSInlineTargetTypeCheck(GateRef gate)
void TypeHCRLowering::LowerJSInlineTargetTypeCheck(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
GateRef frameState = GetFrameState(gate);
@ -1383,7 +1383,7 @@ void TypeMCRLowering::LowerJSInlineTargetTypeCheck(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), Circuit::NullGate());
}
void TypeMCRLowering::LowerTypedNewAllocateThis(GateRef gate, GateRef glue)
void TypeHCRLowering::LowerTypedNewAllocateThis(GateRef gate, GateRef glue)
{
Environment env(gate, circuit_, &builder_);
ArgumentAccessor argAcc(circuit_);
@ -1416,7 +1416,7 @@ void TypeMCRLowering::LowerTypedNewAllocateThis(GateRef gate, GateRef glue)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), *thisObj);
}
void TypeMCRLowering::LowerTypedSuperAllocateThis(GateRef gate, GateRef glue)
void TypeHCRLowering::LowerTypedSuperAllocateThis(GateRef gate, GateRef glue)
{
Environment env(gate, circuit_, &builder_);
GateRef superCtor = acc_.GetValueIn(gate, 0);
@ -1443,7 +1443,7 @@ void TypeMCRLowering::LowerTypedSuperAllocateThis(GateRef gate, GateRef glue)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), *thisObj);
}
void TypeMCRLowering::LowerGetSuperConstructor(GateRef gate)
void TypeHCRLowering::LowerGetSuperConstructor(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
GateRef ctor = acc_.GetValueIn(gate, 0);
@ -1452,7 +1452,7 @@ void TypeMCRLowering::LowerGetSuperConstructor(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), superCtor);
}
GateRef TypeMCRLowering::LoadFromVTable(GateRef receiver, size_t index)
GateRef TypeHCRLowering::LoadFromVTable(GateRef receiver, size_t index)
{
GateRef hclass = builder_.LoadConstOffset(
VariableType::JS_POINTER(), receiver, TaggedObject::HCLASS_OFFSET);
@ -1464,7 +1464,7 @@ GateRef TypeMCRLowering::LoadFromVTable(GateRef receiver, size_t index)
return builder_.Load(VariableType::JS_ANY(), itemOwner, builder_.TaggedGetInt(itemOffset));
}
VariableType TypeMCRLowering::GetVarType(PropertyLookupResult plr)
VariableType TypeHCRLowering::GetVarType(PropertyLookupResult plr)
{
if (plr.GetRepresentation() == Representation::DOUBLE) {
return kungfu::VariableType::FLOAT64();
@ -1475,23 +1475,23 @@ VariableType TypeMCRLowering::GetVarType(PropertyLookupResult plr)
}
}
GateRef TypeMCRLowering::LoadSupers(GateRef hclass)
GateRef TypeHCRLowering::LoadSupers(GateRef hclass)
{
return builder_.LoadConstOffset(VariableType::JS_ANY(), hclass, JSHClass::SUPERS_OFFSET);
}
GateRef TypeMCRLowering::GetLengthFromSupers(GateRef supers)
GateRef TypeHCRLowering::GetLengthFromSupers(GateRef supers)
{
return builder_.LoadConstOffset(VariableType::INT32(), supers, TaggedArray::EXTRACT_LENGTH_OFFSET);
}
GateRef TypeMCRLowering::GetValueFromSupers(GateRef supers, size_t index)
GateRef TypeHCRLowering::GetValueFromSupers(GateRef supers, size_t index)
{
GateRef val = builder_.LoadFromTaggedArray(supers, index);
return builder_.LoadObjectFromWeakRef(val);
}
GateRef TypeMCRLowering::CallAccessor(GateRef glue, GateRef gate, GateRef function, GateRef receiver,
GateRef TypeHCRLowering::CallAccessor(GateRef glue, GateRef gate, GateRef function, GateRef receiver,
AccessorMode mode, GateRef value)
{
const CallSignature *cs = RuntimeStubCSigns::Get(RTSTUB_ID(JSCall));
@ -1506,7 +1506,7 @@ GateRef TypeMCRLowering::CallAccessor(GateRef glue, GateRef gate, GateRef functi
return builder_.Call(cs, glue, target, builder_.GetDepend(), args, gate);
}
void TypeMCRLowering::ReplaceHirWithPendingException(GateRef hirGate, GateRef glue, GateRef state, GateRef depend,
void TypeHCRLowering::ReplaceHirWithPendingException(GateRef hirGate, GateRef glue, GateRef state, GateRef depend,
GateRef value)
{
auto condition = builder_.HasPendingException(glue);
@ -1521,7 +1521,7 @@ void TypeMCRLowering::ReplaceHirWithPendingException(GateRef hirGate, GateRef gl
acc_.ReplaceHirWithIfBranch(hirGate, success, exception, value);
}
void TypeMCRLowering::LowerLoadGetter(GateRef gate)
void TypeHCRLowering::LowerLoadGetter(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
ASSERT(acc_.GetNumValueIn(gate) == 2); // 2: receiver, plr
@ -1536,7 +1536,7 @@ void TypeMCRLowering::LowerLoadGetter(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), getter);
}
void TypeMCRLowering::LowerLoadSetter(GateRef gate)
void TypeHCRLowering::LowerLoadSetter(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
ASSERT(acc_.GetNumValueIn(gate) == 2); // 2: receiver, plr
@ -1552,7 +1552,7 @@ void TypeMCRLowering::LowerLoadSetter(GateRef gate)
}
// subtyping check and hclss check
void TypeMCRLowering::LowerInlineAccessorCheck(GateRef gate)
void TypeHCRLowering::LowerInlineAccessorCheck(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
GateRef receiver = acc_.GetValueIn(gate, 0);
@ -1602,7 +1602,7 @@ void TypeMCRLowering::LowerInlineAccessorCheck(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), Circuit::NullGate());
}
void TypeMCRLowering::LowerStringEqual(GateRef gate, GateRef glue)
void TypeHCRLowering::LowerStringEqual(GateRef gate, GateRef glue)
{
Environment env(gate, circuit_, &builder_);
GateRef left = acc_.GetValueIn(gate, 0);
@ -1623,7 +1623,7 @@ void TypeMCRLowering::LowerStringEqual(GateRef gate, GateRef glue)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), *result);
}
void TypeMCRLowering::LowerTypeOfCheck(GateRef gate)
void TypeHCRLowering::LowerTypeOfCheck(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
GateRef frameState = GetFrameState(gate);
@ -1658,7 +1658,7 @@ void TypeMCRLowering::LowerTypeOfCheck(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), Circuit::NullGate());
}
void TypeMCRLowering::LowerTypeOf(GateRef gate, GateRef glue)
void TypeHCRLowering::LowerTypeOf(GateRef gate, GateRef glue)
{
Environment env(gate, circuit_, &builder_);
GateType type = acc_.GetParamGateType(gate);
@ -1693,7 +1693,7 @@ void TypeMCRLowering::LowerTypeOf(GateRef gate, GateRef glue)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), result);
}
void TypeMCRLowering::LowerIteratorFunctionCheck(GateRef gate, GateRef glue)
void TypeHCRLowering::LowerIteratorFunctionCheck(GateRef gate, GateRef glue)
{
Environment env(gate, circuit_, &builder_);
GateRef frameState = GetFrameState(gate);
@ -1730,7 +1730,7 @@ void TypeMCRLowering::LowerIteratorFunctionCheck(GateRef gate, GateRef glue)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), Circuit::NullGate());
}
void TypeMCRLowering::LowerGetFixedIterator(GateRef gate, GateRef glue)
void TypeHCRLowering::LowerGetFixedIterator(GateRef gate, GateRef glue)
{
Environment env(gate, circuit_, &builder_);
GateRef obj = acc_.GetValueIn(gate, 0);
@ -1764,7 +1764,7 @@ void TypeMCRLowering::LowerGetFixedIterator(GateRef gate, GateRef glue)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), result);
}
void TypeMCRLowering::LowerNativeCallTargetCheck(GateRef gate)
void TypeHCRLowering::LowerNativeCallTargetCheck(GateRef gate)
{
Environment env(gate, circuit_, &builder_);
GateRef frameState = GetFrameState(gate);
@ -1799,7 +1799,7 @@ void TypeMCRLowering::LowerNativeCallTargetCheck(GateRef gate)
acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), Circuit::NullGate());
}
void TypeMCRLowering::LowerTypedCallNative(GateRef gate, GateRef glue)
void TypeHCRLowering::LowerTypedCallNative(GateRef gate, GateRef glue)
{
Environment env(gate, circuit_, &builder_);
GateRef thisObj = acc_.GetValueIn(gate, 0);

View File

@ -13,8 +13,8 @@
* limitations under the License.
*/
#ifndef ECMASCRIPT_COMPILER_TYPE_MCR_LOWERING_H
#define ECMASCRIPT_COMPILER_TYPE_MCR_LOWERING_H
#ifndef ECMASCRIPT_COMPILER_TYPE_HCR_LOWERING_H
#define ECMASCRIPT_COMPILER_TYPE_HCR_LOWERING_H
#include "ecmascript/compiler/argument_accessor.h"
#include "ecmascript/compiler/bytecode_circuit_builder.h"
@ -22,7 +22,7 @@
#include "ecmascript/compiler/combined_pass_visitor.h"
namespace panda::ecmascript::kungfu {
// TypeMCRLowering Process
// TypeHCRLowering Process
// SW: state wire, DW: depend wire, VW: value wire
// Before Type Lowering:
// SW DW VW
@ -96,14 +96,14 @@ namespace panda::ecmascript::kungfu {
// | JS_BYTECODE |
// +------------------------+
class TypeMCRLowering : public PassVisitor {
class TypeHCRLowering : public PassVisitor {
public:
TypeMCRLowering(Circuit *circuit, RPOVisitor *visitor,
TypeHCRLowering(Circuit *circuit, RPOVisitor *visitor,
CompilationConfig *cmpCfg, TSManager *tsManager, Chunk *chunk, bool onHeapCheck)
: PassVisitor(circuit, chunk, visitor), circuit_(circuit), acc_(circuit), builder_(circuit, cmpCfg),
dependEntry_(circuit->GetDependRoot()), tsManager_(tsManager), onHeapCheck_(onHeapCheck) {}
~TypeMCRLowering() = default;
~TypeHCRLowering() = default;
GateRef VisitGate(GateRef gate) override;
@ -236,4 +236,4 @@ private:
bool onHeapCheck_ {false};
};
} // panda::ecmascript::kungfu
#endif // ECMASCRIPT_COMPILER_TYPE_MCR_LOWERING_H
#endif // ECMASCRIPT_COMPILER_TYPE_HCR_LOWERING_H

View File

@ -1412,6 +1412,7 @@ void MethodTypeInfer::Verify() const
for (const auto &gate : gateList) {
if (IsByteCodeGate(gate)) {
TypeCheck(gate);
PGOTypeCheck(gate);
}
}
}
@ -1451,7 +1452,7 @@ void MethodTypeInfer::TypeCheck(GateRef gate) const
const std::string &sourceFileName = debugExtractor->GetSourceFile(methodId);
const std::string functionName = MethodLiteral::ParseFunctionName(jsPandaFile, methodId);
std::string log = CollectGateTypeLogInfo(valueGate, debugExtractor, "[TypeAssertion] ");
std::string log = CollectGateTypeLogInfo(valueGate, debugExtractor, "[TypeAssertion] ", false);
log += "[TypeAssertion] but expected type: " + expectedTypeStr + "\n";
LOG_COMPILER(ERROR) << "[TypeAssertion] [" << sourceFileName << ":" << functionName << "] begin:";
@ -1460,8 +1461,67 @@ void MethodTypeInfer::TypeCheck(GateRef gate) const
}
}
void MethodTypeInfer::PGOTypeCheck(GateRef gate) const
{
auto &info = GetByteCodeInfo(gate);
if (!info.IsBc(EcmaOpcode::CALLTHIS2_IMM8_V8_V8_V8)) { // ArkTools.pgoAssertType
return ;
}
// 1. thisObj
auto thisObj = gateAccessor_.GetValueIn(gate, 0);
if (!IsByteCodeGate(thisObj)) {
return ;
}
auto &thisObjInfo = GetByteCodeInfo(thisObj);
if (!thisObjInfo.IsBc(EcmaOpcode::TRYLDGLOBALBYNAME_IMM8_ID16) &&
!thisObjInfo.IsBc(EcmaOpcode::TRYLDGLOBALBYNAME_IMM16_ID16)) {
return;
}
auto thisObjName = gateAccessor_.GetValueIn(thisObj, 1);
uint16_t thisObjNameStrId = gateAccessor_.GetConstantValue(thisObjName);
auto thisObjNameString = tsManager_->GetStdStringFromConstantPool(thisObjNameStrId);
// 2. funcName
auto func = gateAccessor_.GetValueIn(gate, 3);
if (!IsByteCodeGate(func)) {
return ;
}
auto &funcInfo = GetByteCodeInfo(func);
if (!funcInfo.IsBc(EcmaOpcode::LDOBJBYNAME_IMM8_ID16)) {
return;
}
auto funcName = gateAccessor_.GetValueIn(func, 1);
uint16_t funcNameStrId = gateAccessor_.GetConstantValue(funcName);
auto funcNameString = tsManager_->GetStdStringFromConstantPool(funcNameStrId);
// 3. check whether it is ArkTools.pgoAssertType()
if (thisObjNameString == "ArkTools" && funcNameString == "pgoAssertType") {
// 4. expected type
GateRef expectedGate = gateAccessor_.GetValueIn(gate, 2);
GateRef constId = gateAccessor_.GetValueIn(expectedGate, 0);
uint16_t strId = gateAccessor_.GetConstantValue(constId);
auto expectedTypeStr = tsManager_->GetStdStringFromConstantPool(strId); // expected type
// 5. pgo type
GateRef valueGate = gateAccessor_.GetValueIn(gate, 1);
PGOSampleType pgoType = gateAccessor_.TryGetPGOType(valueGate); // pgo type
auto pgoTypeStr = pgoType.ToString();
// 6. compare expected type and pgo type
if (expectedTypeStr != pgoTypeStr) {
const JSPandaFile *jsPandaFile = builder_->GetJSPandaFile();
EntityId methodId = builder_->GetMethod()->GetMethodId();
DebugInfoExtractor *debugExtractor = JSPandaFileManager::GetInstance()->GetJSPtExtractor(jsPandaFile);
const std::string &sourceFileName = debugExtractor->GetSourceFile(methodId);
const std::string functionName = MethodLiteral::ParseFunctionName(jsPandaFile, methodId);
std::string log = CollectGateTypeLogInfo(valueGate, debugExtractor, "[PGOTypeAssertion] ", true);
log += "[PGOTypeAssertion] but expected type: " + expectedTypeStr + "\n";
LOG_COMPILER(ERROR) << "[PGOTypeAssertion] [" << sourceFileName << ":" << functionName << "] begin:";
LOG_COMPILER(FATAL) << log << "[compiler] [PGOTypeAssertion] end";
}
}
}
std::string MethodTypeInfer::CollectGateTypeLogInfo(GateRef gate, DebugInfoExtractor *debugExtractor,
const std::string &logPreFix) const
const std::string &logPreFix, bool isPGO) const
{
std::string log(logPreFix);
log += "gate id: "+ std::to_string(gateAccessor_.GetId(gate)) + ", ";
@ -1495,12 +1555,17 @@ std::string MethodTypeInfer::CollectGateTypeLogInfo(GateRef gate, DebugInfoExtra
}
}
GateType type = gateAccessor_.GetGateType(gate);
log += "type: " + tsManager_->GetTypeStr(type) + ", ";
if (!tsManager_->IsPrimitiveTypeKind(type)) {
GlobalTSTypeRef gt = type.GetGTRef();
log += "[moduleId: " + std::to_string(gt.GetModuleId()) + ", ";
log += "localId: " + std::to_string(gt.GetLocalId()) + "], ";
if (!isPGO) {
GateType type = gateAccessor_.GetGateType(gate);
log += "type: " + tsManager_->GetTypeStr(type) + ", ";
if (!tsManager_->IsPrimitiveTypeKind(type)) {
GlobalTSTypeRef gt = type.GetGTRef();
log += "[moduleId: " + std::to_string(gt.GetModuleId()) + ", ";
log += "localId: " + std::to_string(gt.GetLocalId()) + "], ";
}
} else {
PGOSampleType pgoType = gateAccessor_.TryGetPGOType(gate); // pgo type
log += "pgoType: " + pgoType.ToString() + ", ";
}
log += "\n[compiler] ";
@ -1533,4 +1598,4 @@ void MethodTypeInfer::VerifyTypePercent()
}
}
}
} // namespace panda::ecmascript
} // namespace panda::ecmascript

View File

@ -18,6 +18,7 @@
#include "ecmascript/compiler/argument_accessor.h"
#include "ecmascript/compiler/bytecode_circuit_builder.h"
#include "ecmascript/compiler/compiler_log.h"
#include "ecmascript/compiler/circuit.h"
#include "ecmascript/compiler/gate_accessor.h"
#include "ecmascript/compiler/pass_manager.h"
@ -146,9 +147,10 @@ private:
void Verify() const;
void VerifyTypePercent();
void TypeCheck(GateRef gate) const;
void PGOTypeCheck(GateRef gate) const;
std::string CollectGateTypeLogInfo(GateRef gate, DebugInfoExtractor *debugExtractor,
const std::string &logPreFix) const;
const std::string &logPreFix, bool isPGO) const;
const BytecodeInfo &GetByteCodeInfo(const GateRef gate) const
{

View File

@ -220,6 +220,50 @@ public:
}
}
std::string ToString() const
{
if (type_.index() == 0) {
auto type = std::get<Type>(type_);
switch (type) {
case Type::NONE:
return "none";
case Type::INT:
return "int";
case Type::INT_OVERFLOW:
return "int_overflow";
case Type::DOUBLE:
return "double";
case Type::NUMBER:
return "number";
case Type::NUMBER1:
return "number1";
case Type::BOOLEAN:
return "boolean";
case Type::UNDEFINED_OR_NULL:
return "undefined_or_null";
case Type::SPECIAL:
return "special";
case Type::BOOLEAN_OR_SPECIAL:
return "boolean_or_special";
case Type::STRING:
return "string";
case Type::BIG_INT:
return "big_int";
case Type::HEAP_OBJECT:
return "heap_object";
case Type::HEAP_OR_UNDEFINED_OR_NULL:
return "heap_or_undefined_or_null";
case Type::ANY:
return "any";
default:
LOG_ECMA(FATAL) << "this branch is unreachable";
UNREACHABLE();
}
}
LOG_ECMA(FATAL) << "this branch is unreachable";
UNREACHABLE();
}
bool IsProfileType() const
{
return type_.index() == 1;

View File

@ -1022,7 +1022,7 @@ private:
double typeThreshold_ {-1};
// when the passmanager iterates each method, the curCP_ and curCPID_ should be updated
// so that subsequent passes (type_infer, ts_hcr_lowering) can obtain the correct constpool.
// so that subsequent passes (type_infer, type_bytecode_lowering) can obtain the correct constpool.
JSTaggedValue curCP_ {JSTaggedValue::Hole()};
int32_t curCPID_ {0};

View File

@ -1284,6 +1284,156 @@ template("host_typeinfer_test_action") {
}
}
template("host_pgotypeinfer_test_action") {
_target_name_ = "${target_name}"
_deps_ = invoker.deps
_test_ts_path_ = "./${_target_name_}.js"
_test_aot_arg_ = "$target_out_dir/${_target_name_}"
_host_aot_target_ =
"$js_root/ecmascript/compiler:ark_aot_compiler(${host_toolchain})"
_test_es2abc_abc_path_ = "$target_out_dir/es2abc/${_target_name_}.abc"
if (defined(invoker.is_common_js) && invoker.is_common_js) {
extra_args = [ "--commonjs" ]
} else {
extra_args = [ "--module" ]
}
extra_args += [ "--merge-abc" ]
es2abc_gen_abc("es2abc_gen_${_target_name_}_abc") {
extra_visibility = [ ":*" ] # Only targets in this file can depend on this.
extra_dependencies = _deps_
if (defined(invoker.is_multi_file_tests) && invoker.is_multi_file_tests) {
_test_es2abc_ts_path_ = "."
} else {
_test_es2abc_ts_path_ = _test_ts_path_
}
src_js = rebase_path(_test_es2abc_ts_path_)
dst_file = rebase_path(_test_es2abc_abc_path_)
in_puts = [ _test_ts_path_ ]
out_puts = [ _test_es2abc_abc_path_ ]
}
_script_args_ = rebase_path(_test_es2abc_abc_path_)
action("${_target_name_}PgoExecute") {
testonly = true
_host_jsvm_target_ = "//arkcompiler/ets_runtime/ecmascript/js_vm:ark_js_vm(${host_toolchain})"
_root_out_dir_ = get_label_info(_host_jsvm_target_, "root_out_dir")
deps = [
":es2abc_gen_${_target_name_}_abc",
_host_jsvm_target_,
]
deps += _deps_
script = "//arkcompiler/ets_runtime/script/run_ark_executable.py"
_aot_run_options_ =
" --asm-interpreter=true" + " --entry-point=${_target_name_}" +
" --enable-pgo-profiler=true" + " --compiler-pgo-profiler-path=" +
rebase_path(_test_aot_arg_) + "/modules.ap"
if (defined(invoker.is_enable_enableArkTools) &&
invoker.is_enable_enableArkTools) {
_aot_run_options_ += " --enable-ark-tools=true"
_aot_run_options_ += " --enable-force-gc=false"
}
if (defined(invoker.log_option)) {
_aot_run_options_ += invoker.log_option
}
args = [
"--script-file",
rebase_path(_root_out_dir_) + "/arkcompiler/ets_runtime/ark_js_vm",
"--script-options",
_aot_run_options_,
"--script-args",
_script_args_,
"--expect-output",
"0",
"--env-path",
rebase_path(_root_out_dir_) + "/arkcompiler/ets_runtime:" +
rebase_path(_root_out_dir_) + "/${_icu_path_}:" +
rebase_path(_root_out_dir_) + "/thirdparty/zlib:" +
rebase_path(_root_out_dir_) + "/resourceschedule/frame_aware_sched:" +
rebase_path(_root_out_dir_) + "/hiviewdfx/hilog:" +
rebase_path(_root_out_dir_) +
"/thirdparty/bounds_checking_function:" +
rebase_path("//prebuilts/clang/ohos/linux-x86_64/llvm/lib/"),
]
inputs = [ _test_es2abc_abc_path_ ]
outputs = [ "$target_out_dir/${_target_name_}/pgo" ]
}
action("${_target_name_}Es2abcAotTypeInferAction") {
testonly = true
_script_args_ = rebase_path(_test_es2abc_abc_path_)
_root_out_dir_ = get_label_info(_host_aot_target_, "root_out_dir")
deps = [
":es2abc_gen_${_target_name_}_abc",
_host_aot_target_,
]
deps += _deps_
# Pgo Execute
deps += [ ":${_target_name_}PgoExecute" ]
script = "//arkcompiler/ets_runtime/script/run_ark_executable.py"
_aot_compile_options_ = " --compiler-assert-types=true" +
" --compiler-opt-type-lowering=false" +
" --compiler-opt-loop-peeling=false"
# Pgo Option
_aot_compile_options_ += " --compiler-pgo-profiler-path=" +
rebase_path(_test_aot_arg_) + "/modules.ap"
if (defined(invoker.is_enable_builtins_dts) &&
invoker.is_enable_builtins_dts) {
deps += [ "//arkcompiler/ets_runtime:es2abc_gen_builtins_d_abc" ]
_aot_compile_options_ += " --builtins-dts=" + rebase_path(root_out_dir) + "/obj/arkcompiler/ets_runtime/lib_ark_builtins/es2abc/lib_ark_builtins.d.abc"
}
if (defined(invoker.is_enable_global_typeinfer) &&
invoker.is_enable_global_typeinfer) {
_aot_compile_options_ += " --compiler-opt-global-typeinfer=true"
}
args = [
"--script-file",
rebase_path(_root_out_dir_) + "/arkcompiler/ets_runtime/ark_aot_compiler",
"--script-options",
_aot_compile_options_,
"--script-args",
_script_args_,
"--expect-output",
"0",
"--env-path",
rebase_path(_root_out_dir_) + "/arkcompiler/ets_runtime:" +
rebase_path(_root_out_dir_) + "/${_icu_path_}:" +
rebase_path(_root_out_dir_) + "/thirdparty/zlib:" +
rebase_path(_root_out_dir_) + "/resourceschedule/frame_aware_sched:" +
rebase_path(_root_out_dir_) + "/hiviewdfx/hilog:" +
rebase_path(_root_out_dir_) +
"/thirdparty/bounds_checking_function:" +
rebase_path("//prebuilts/clang/ohos/linux-x86_64/llvm/lib/"),
]
inputs = [ _test_es2abc_abc_path_ ]
outputs = [ "$target_out_dir/${_target_name_}/es2abc/" ]
}
}
template("host_quickfix_test_action") {
_target_name_ = "${target_name}"

View File

@ -36,6 +36,17 @@ if (is_enable_typeinfer_automatedcases) {
}
}
group("ark_pgotypeinfer_test") {
testonly = true
test_list = [ "add" ]
deps = []
foreach(test, test_list) {
deps += [ "${test}:${test}Es2abcAotTypeInferAction" ]
}
}
group("ark_typeinfer_test") {
testonly = true

View File

@ -0,0 +1,18 @@
# Copyright (c) 2023 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//arkcompiler/ets_runtime/test/test_helper.gni")
host_pgotypeinfer_test_action("add") {
deps = []
}

13
test/typeinfer/add/add.js Normal file
View File

@ -0,0 +1,13 @@
let x = 0
let y = 3.14
let z = x + y
ArkTools.pgoAssertType(z, "number"); // int + int -> int
y = 0
z = x + y
ArkTools.pgoAssertType(z, "int");
x = 3.14
y = 3.14
z = x + y
ArkTools.pgoAssertType(z, "double");