Aot Lowering

lower NEWOBJDYNRANGE_PREF_IMM16_V8, JEQZ_IMM8, JEQZ_IMM16, JNEZ_IMM8, JNEZ_IMM16

issue:https://gitee.com/openharmony/ark_js_runtime/issues/I515NO

Signed-off-by: wanyanglan <wanyanglan1@huawei.com>
Change-Id: Ia8ebbb51f39cce5b3be69c1a39aa39a0cd74ad81
This commit is contained in:
wanyanglan 2022-04-01 14:33:39 +08:00
parent 111a44610f
commit e7342acada
10 changed files with 116 additions and 10 deletions

View File

@ -22,7 +22,7 @@ namespace panda::ecmascript {
#define ECMASCRIPT_ENABLE_DEBUG_MODE 0
#define ECMASCRIPT_ENABLE_ARK_CONTAINER 1
#define ECMASCRIPT_ENABLE_TS_AOT_PRINT 0
#define ECMASCRIPT_ENABLE_TS_AOT_PRINT 1
#define ECMASCRIPT_COMPILE_ASM_INTERPRETER 0
#define ECMASCRIPT_ENABLE_ASM_INTERPRETER_LOG 0

View File

@ -130,18 +130,15 @@ void BytecodeCircuitBuilder::CollectBytecodeBlockInfo(uint8_t *pc, std::vector<C
}
break;
case EcmaOpcode::RETURN_DYN:
case EcmaOpcode::RETURNUNDEFINED_PREF: {
bytecodeBlockInfos.emplace_back(pc, SplitKind::END, std::vector<uint8_t *>(1, pc));
break;
}
case EcmaOpcode::RETURNUNDEFINED_PREF:
case EcmaOpcode::THROWDYN_PREF:
case EcmaOpcode::THROWCONSTASSIGNMENT_PREF_V8:
case EcmaOpcode::THROWTHROWNOTEXISTS_PREF:
case EcmaOpcode::THROWPATTERNNONCOERCIBLE_PREF:
case EcmaOpcode::THROWDELETESUPERPROPERTY_PREF: {
bytecodeBlockInfos.emplace_back(pc, SplitKind::END, std::vector<uint8_t *>(1, pc));
}
break;
}
default:
break;
}
@ -1126,6 +1123,7 @@ BytecodeInfo BytecodeCircuitBuilder::GetBytecodeInfo(uint8_t *pc)
info.accOut = true;
info.offset = BytecodeOffset::FIVE;
info.inputs.emplace_back(Immediate(READ_INST_16_1()));
info.inputs.emplace_back(Immediate(firstArgRegIdx));
info.inputs.emplace_back(VirtualRegister(firstArgRegIdx));
info.inputs.emplace_back(VirtualRegister(firstArgRegIdx + 1));
break;
@ -2422,7 +2420,6 @@ void BytecodeCircuitBuilder::BuildCircuit(BytecodeGraph &byteCodeGraph)
#endif
}
size_t BytecodeCircuitBuilder::GetFunctionArgIndex(size_t currentVreg, size_t numVregs) const
{
return (currentVreg - numVregs + CommonArgIdx::NUM_OF_ARGS);

View File

@ -108,6 +108,7 @@ class Variable;
V(TruncInt64ToInt32, OpCode::TRUNC_TO_INT32) \
V(TruncPtrToInt32, OpCode::TRUNC_TO_INT32) \
V(TruncInt64ToInt1, OpCode::TRUNC_TO_INT1) \
V(TruncInt64ToInt16, OpCode::TRUNC_TO_INT16) \
V(TruncInt32ToInt1, OpCode::TRUNC_TO_INT1)
#define BINARY_LOGIC_METHOD_LIST_WITHOUT_BITWIDTH(V) \

View File

@ -131,6 +131,8 @@ Properties OpCode::GetProperties() const
return {I32, NO_STATE, NO_DEPEND, VALUE(ANYVALUE), NO_ROOT};
case TRUNC_TO_INT1:
return {I1, NO_STATE, NO_DEPEND, VALUE(ANYVALUE), NO_ROOT};
case TRUNC_TO_INT16:
return {I16, NO_STATE, NO_DEPEND, VALUE(ANYVALUE), NO_ROOT};
case REV:
return {FLEX, NO_STATE, NO_DEPEND, VALUE(FLEX), NO_ROOT};
case ADD:
@ -248,6 +250,7 @@ std::string OpCode::Str() const
{SEXT_TO_ARCH, "SEXT_TO_ARCH"},
{TRUNC_TO_INT32, "TRUNC_TO_INT32"},
{TRUNC_TO_INT1, "TRUNC_TO_INT1"},
{TRUNC_TO_INT16, "TRUNC_TO_INT16"},
{REV, "REV"},
{ADD, "ADD"},
{SUB, "SUB"},

View File

@ -114,6 +114,7 @@ public:
SEXT_TO_ARCH,
TRUNC_TO_INT32,
TRUNC_TO_INT1,
TRUNC_TO_INT16,
REV,
ADD,
SUB,

View File

@ -337,6 +337,7 @@ public:
}
DeleteGate(useIt);
};
void DeleteIn(UsesIterator &useIt);
void DeleteGate(UsesIterator &useIt);
private:

View File

@ -154,6 +154,7 @@ void LLVMIRBuilder::AssignHandleMap()
{OpCode::SEXT_TO_ARCH, &LLVMIRBuilder::HandleSExtInt},
{OpCode::TRUNC_TO_INT1, &LLVMIRBuilder::HandleCastIntXToIntY},
{OpCode::TRUNC_TO_INT32, &LLVMIRBuilder::HandleCastIntXToIntY},
{OpCode::TRUNC_TO_INT16, &LLVMIRBuilder::HandleCastIntXToIntY},
{OpCode::REV, &LLVMIRBuilder::HandleIntRev},
{OpCode::ADD, &LLVMIRBuilder::HandleAdd},
{OpCode::SUB, &LLVMIRBuilder::HandleSub},

View File

@ -24,7 +24,7 @@
namespace panda::ecmascript::kungfu {
bool PassManager::Compile(const std::string &fileName, const std::string &triple,
const std::string &outputFileName)
const std::string &outputFileName)
{
BytecodeTranslationInfo translationInfo;
[[maybe_unused]] EcmaHandleScope handleScope(vm_->GetJSThread());

View File

@ -452,6 +452,17 @@ void SlowPathLowering::Lower(GateRef gate, EcmaOpcode op)
case GETMODULENAMESPACE_PREF_ID32:
LowerGetModuleNamespace(gate, glue);
break;
case NEWOBJDYNRANGE_PREF_IMM16_V8:
LowerNewObjDynRange(gate, glue);
break;
case JEQZ_IMM8:
case JEQZ_IMM16:
LowerConditionJump(gate, true);
break;
case JNEZ_IMM8:
case JNEZ_IMM16:
LowerConditionJump(gate, false);
break;
case GETITERATORNEXT_PREF_V8_V8:
LowerGetIteratorNext(gate, glue);
break;
@ -553,8 +564,8 @@ void SlowPathLowering::LowerLexicalEnv(GateRef gate, GateRef glue)
void SlowPathLowering::LowerTryLdGlobalByName(GateRef gate, GateRef glue)
{
GateRef prop = GetValueFromConstStringTable(glue, gate, 0);
GateRef id = builder_.Int64(RTSTUB_ID(TryLdGlobalByName));
acc_.SetDep(gate, prop);
GateRef id = builder_.Int64(RTSTUB_ID(TryLdGlobalByName));
ASSERT(acc_.GetNumValueIn(gate) == 1);
GateRef newGate = builder_.RuntimeCall(glue, id, Circuit::GetCircuitRoot(OpCode(OpCode::DEPEND_ENTRY)), {prop});
LowerHirToCall(gate, newGate);
@ -563,8 +574,8 @@ void SlowPathLowering::LowerTryLdGlobalByName(GateRef gate, GateRef glue)
void SlowPathLowering::LowerStGlobalVar(GateRef gate, GateRef glue)
{
GateRef prop = GetValueFromConstStringTable(glue, gate, 0);
GateRef id = builder_.Int64(RTSTUB_ID(StGlobalVar));
acc_.SetDep(gate, prop);
GateRef id = builder_.Int64(RTSTUB_ID(StGlobalVar));
ASSERT(acc_.GetNumValueIn(gate) == 2); // 2: number of value inputs
GateRef newGate = builder_.RuntimeCall(glue, id, Circuit::GetCircuitRoot(OpCode(OpCode::DEPEND_ENTRY)),
{prop, acc_.GetValueIn(gate, 0)});
@ -1078,6 +1089,7 @@ void SlowPathLowering::LowerFastStrictEqual(GateRef gate, GateRef glue)
{acc_.GetValueIn(gate, 0), acc_.GetValueIn(gate, 1)});
LowerHirToFastCall(gate, newGate);
}
void SlowPathLowering::LowerCreateEmptyArray(GateRef gate, GateRef glue)
{
LabelManager lm(gate, circuit_);
@ -1308,4 +1320,92 @@ void SlowPathLowering::LowerIsTrueOrFalse(GateRef gate, GateRef glue, bool flag)
exceptionControl.emplace_back(Circuit::NullGate());
builder_.MergeMirCircuit<true>(gate, *result, successControl, exceptionControl);
}
void SlowPathLowering::LowerNewObjDynRange(GateRef gate, GateRef glue)
{
GateRef id = builder_.Int64(RTSTUB_ID(NewObjDynRange));
// 4: number of value inputs
ASSERT(acc_.GetNumValueIn(gate) == 4);
// 2 : 2 first argument offset
GateRef firstArgOffset = builder_.Int16(2);
GateRef firstArgRegIdx = acc_.GetValueIn(gate, 1);
GateRef firstArgIdx = builder_.Int16Add(builder_.TruncInt64ToInt16(firstArgRegIdx), firstArgOffset);
GateRef numArgs = acc_.GetValueIn(gate, 0);
GateRef length = builder_.Int16Sub(builder_.TruncInt64ToInt16(numArgs), firstArgOffset);
// 2 : 2 input value
GateRef ctor = acc_.GetValueIn(gate, 2);
// 3 : 3 input value
GateRef newTarget = acc_.GetValueIn(gate, 3);
GateRef newGate = builder_.RuntimeCall(glue, id,Circuit::GetCircuitRoot(OpCode(OpCode::DEPEND_ENTRY)),
{ctor, newTarget, firstArgIdx, length});
LowerHirToCall(gate, newGate);
}
void SlowPathLowering::LowerConditionJump(GateRef gate, bool isEqualJump)
{
std::vector<GateRef> trueState;
GateRef value = acc_.GetValueIn(gate, 0);
// GET_ACC() == JSTaggedValue::False()
GateRef condition = builder_.TaggedSpecialValueChecker(value, JSTaggedValue::VALUE_FALSE);
GateRef ifBranch = builder_.Branch(acc_.GetState(gate), condition);
GateRef ifTrue = builder_.IfTrue(ifBranch);
trueState.emplace_back(ifTrue);
GateRef ifFalse = builder_.IfFalse(ifBranch);
// (GET_ACC().IsInt() && GET_ACC().GetInt())
std::vector<GateRef> intFalseState;
ifBranch = builder_.Branch(ifFalse, builder_.TaggedIsInt(value));
GateRef isInt = builder_.IfTrue(ifBranch);
GateRef notInt = builder_.IfFalse(ifBranch);
intFalseState.emplace_back(notInt);
condition = builder_.Int32Equal(builder_.TaggedGetInt(value), builder_.Int32(0));
ifBranch = builder_.Branch(isInt, condition);
GateRef isZero = builder_.IfTrue(ifBranch);
trueState.emplace_back(isZero);
GateRef notZero = builder_.IfFalse(ifBranch);
if (isEqualJump) {
intFalseState.emplace_back(notZero);
} else {
intFalseState.emplace_back(isZero);
}
auto mergeIntState = builder_.Merge(intFalseState.data(), intFalseState.size());
// (GET_ACC().IsDouble() && GET_ACC().GetDouble() == 0)
std::vector<GateRef> doubleFalseState;
ifBranch = builder_.Branch(mergeIntState, builder_.TaggedIsDouble(value));
GateRef isDouble = builder_.IfTrue(ifBranch);
GateRef notDouble = builder_.IfFalse(ifBranch);
doubleFalseState.emplace_back(notDouble);
condition = builder_.DoubleEqual(builder_.TaggedCastToDouble(value), builder_.Double(0));
ifBranch = builder_.Branch(isDouble, condition);
GateRef isDoubleZero = builder_.IfTrue(ifBranch);
trueState.emplace_back(isDoubleZero);
GateRef notDoubleZero = builder_.IfFalse(ifBranch);
if (isEqualJump) {
doubleFalseState.emplace_back(notDoubleZero);
} else {
doubleFalseState.emplace_back(isDoubleZero);
}
auto mergeFalseState = builder_.Merge(doubleFalseState.data(), doubleFalseState.size());
GateRef mergeTrueState = builder_.Merge(trueState.data(), trueState.size());
auto uses = acc_.Uses(gate);
for (auto it = uses.begin(); it != uses.end(); it++) {
if (acc_.GetOpCode(*it) == OpCode::IF_TRUE) {
acc_.SetOpCode(*it, OpCode::ORDINARY_BLOCK);
acc_.ReplaceIn(it, mergeTrueState);
} else if (acc_.GetOpCode(*it) == OpCode::IF_FALSE) {
acc_.SetOpCode(*it, OpCode::ORDINARY_BLOCK);
acc_.ReplaceIn(it, mergeFalseState);
} else if (((acc_.GetOpCode(*it) == OpCode::DEPEND_SELECTOR) ||
(acc_.GetOpCode(*it) == OpCode::DEPEND_RELAY)) &&
(acc_.GetOpCode(acc_.GetIn(acc_.GetIn(*it, 0), it.GetIndex() - 1)) != OpCode::IF_EXCEPTION)) {
acc_.ReplaceIn(it, acc_.GetDep(gate));
} else {
abort();
}
}
// delete old gate
circuit_->DeleteGate(gate);
}
} // namespace panda::ecmascript

View File

@ -197,6 +197,8 @@ private:
void LowerSuperCall(GateRef gate, GateRef glue, GateRef newTarget);
void LowerSuperCallSpread(GateRef gate, GateRef glue, GateRef newTarget);
void LowerIsTrueOrFalse(GateRef gate, GateRef glue, bool flag);
void LowerNewObjDynRange(GateRef gate, GateRef glue);
void LowerConditionJump(GateRef gate, bool isEqualJump);
BytecodeCircuitBuilder *bcBuilder_;
Circuit *circuit_;