Add EcmaOptCode range for typed bytecode lowering

Issue:https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I90JPR

Signed-off-by: h30044958 <herongpeng@huawei.com>
Change-Id: I3180268213a2d04fc4f6ef61f2cdfe105d45440d
This commit is contained in:
h30044958 2024-02-20 17:01:56 +08:00
parent 80d4e62825
commit cf4e2cc6b1
11 changed files with 250 additions and 118 deletions

View File

@ -151,7 +151,8 @@ int Main(const int argc, const char **argv)
cOptions.maxAotMethodSize_,
cOptions.maxMethodsInModule_,
profilerDecoder,
&passOptions);
&passOptions,
cOptions.optBCRange_);
bool isEnableLiteCG = runtimeOptions.IsCompilerEnableLiteCG();
AOTFileGenerator generator(&log, &logList, vm, cOptions.triple_, isEnableLiteCG);

View File

@ -61,6 +61,7 @@ CompilationOptions::CompilationOptions(EcmaVM *vm, JSRuntimeOptions &runtimeOpti
isEnableNativeInline_ = runtimeOptions.IsEnableNativeInline();
isEnableLoweringBuiltin_ = runtimeOptions.IsEnableLoweringBuiltin();
isEnableOptBranchProfiling_ = runtimeOptions.IsEnableBranchProfiling();
optBCRange_ = runtimeOptions.GetOptCodeRange();
}
bool AotCompilerPreprocessor::HandleTargetCompilerMode(CompilationOptions &cOptions)

View File

@ -46,6 +46,7 @@ struct CompilationOptions {
size_t maxMethodsInModule_;
uint32_t hotnessThreshold_;
std::string profilerIn_;
std::string optBCRange_;
bool needMerge_ {false};
bool isEnableArrayBoundsCheckElimination_;
bool isEnableTypeLowering_;

View File

@ -17,6 +17,7 @@
#include <map>
#include <string>
#include <vector>
namespace panda::ecmascript::kungfu {
@ -63,6 +64,7 @@ namespace panda::ecmascript::kungfu {
V(NEWOBJAPPLY_IMM16_V8) \
V(NEWOBJRANGE_IMM8_IMM8_V8) \
V(NEWOBJRANGE_IMM16_IMM8_V8) \
V(WIDE_NEWOBJRANGE_PREF_IMM16_V8) \
V(NEWLEXENV_IMM8) \
V(NEWLEXENVWITHNAME_IMM8_ID16) \
V(ADD2_IMM8_V8) \
@ -99,6 +101,7 @@ namespace panda::ecmascript::kungfu {
V(ISFALSE) \
V(CALLTHIS3_IMM8_V8_V8_V8_V8) \
V(CALLTHISRANGE_IMM8_IMM8_V8) \
V(WIDE_SUPERCALLTHISRANGE_PREF_IMM16_V8) \
V(SUPERCALLTHISRANGE_IMM8_IMM8_V8) \
V(SUPERCALLARROWRANGE_IMM8_IMM8_V8) \
V(DEFINEFUNC_IMM8_ID16_IMM8) \
@ -113,12 +116,19 @@ namespace panda::ecmascript::kungfu {
V(CALLRANGE_IMM8_IMM8_V8) \
V(LDEXTERNALMODULEVAR_IMM8) \
V(LDTHISBYNAME_IMM8_ID16) \
V(DEFINEGETTERSETTERBYVALUE_V8_V8_V8_V8) \
V(LDTHISBYNAME_IMM16_ID16) \
V(LDOBJBYNAME_IMM8_ID16) \
V(LDOBJBYNAME_IMM16_ID16) \
V(DEFINEGETTERSETTERBYVALUE_V8_V8_V8_V8) \
V(STTHISBYNAME_IMM8_ID16) \
V(STTHISBYNAME_IMM16_ID16) \
V(STOBJBYNAME_IMM8_ID16_V8) \
V(STOBJBYNAME_IMM16_ID16_V8) \
V(DEFINEFIELDBYNAME_IMM8_ID16_V8) \
V(LDTHISBYVALUE_IMM8) \
V(LDTHISBYVALUE_IMM16) \
V(LDOBJBYVALUE_IMM8_V8) \
V(LDOBJBYVALUE_IMM16_V8) \
V(STTHISBYVALUE_IMM8_V8) \
V(STTHISBYVALUE_IMM16_V8) \
V(DYNAMICIMPORT) \
@ -131,6 +141,7 @@ namespace panda::ecmascript::kungfu {
V(GETNEXTPROPNAME_V8) \
V(JEQZ_IMM8) \
V(JEQZ_IMM16) \
V(JEQZ_IMM32) \
V(SETOBJECTWITHPROTO_IMM8_V8) \
V(DELOBJPROP_V8) \
V(SUSPENDGENERATOR_V8) \
@ -138,8 +149,6 @@ namespace panda::ecmascript::kungfu {
V(COPYDATAPROPERTIES_V8) \
V(STARRAYSPREAD_V8_V8) \
V(SETOBJECTWITHPROTO_IMM16_V8) \
V(LDOBJBYVALUE_IMM8_V8) \
V(LDOBJBYVALUE_IMM16_V8) \
V(STOBJBYVALUE_IMM8_V8_V8) \
V(STOBJBYVALUE_IMM16_V8_V8) \
V(STOWNBYVALUE_IMM8_V8_V8) \
@ -150,8 +159,10 @@ namespace panda::ecmascript::kungfu {
V(STSUPERBYVALUE_IMM16_V8_V8) \
V(LDOBJBYINDEX_IMM8_IMM16) \
V(LDOBJBYINDEX_IMM16_IMM16) \
V(WIDE_LDOBJBYINDEX_PREF_IMM32) \
V(STOBJBYINDEX_IMM8_V8_IMM16) \
V(STOBJBYINDEX_IMM16_V8_IMM16) \
V(WIDE_STOBJBYINDEX_PREF_V8_IMM32) \
V(STOWNBYINDEX_IMM8_V8_IMM16) \
V(STOWNBYINDEX_IMM16_V8_IMM16) \
V(ASYNCFUNCTIONRESOLVE_V8) \
@ -167,10 +178,6 @@ namespace panda::ecmascript::kungfu {
V(TRYSTGLOBALBYNAME_IMM16_ID16) \
V(LDGLOBALVAR_IMM16_ID16) \
V(STGLOBALVAR_IMM16_ID16) \
V(LDOBJBYNAME_IMM8_ID16) \
V(LDOBJBYNAME_IMM16_ID16) \
V(STOBJBYNAME_IMM8_ID16_V8) \
V(STOBJBYNAME_IMM16_ID16_V8) \
V(STOWNBYNAME_IMM8_ID16_V8) \
V(STOWNBYNAME_IMM16_ID16_V8) \
V(LDSUPERBYNAME_IMM8_ID16) \
@ -180,7 +187,6 @@ namespace panda::ecmascript::kungfu {
V(LDLOCALMODULEVAR_IMM8) \
V(STCONSTTOGLOBALRECORD_IMM16_ID16) \
V(STTOGLOBALRECORD_IMM16_ID16) \
V(JEQZ_IMM32) \
V(JNEZ_IMM8) \
V(JNEZ_IMM16) \
V(JNEZ_IMM32) \
@ -244,7 +250,6 @@ namespace panda::ecmascript::kungfu {
V(WIDE_CREATEOBJECTWITHEXCLUDEDKEYS_PREF_IMM16_V8_V8) \
V(THROW_PREF_NONE) \
V(DEPRECATED_POPLEXENV_PREF_NONE) \
V(WIDE_NEWOBJRANGE_PREF_IMM16_V8) \
V(THROW_NOTEXISTS_PREF_NONE) \
V(DEPRECATED_GETITERATORNEXT_PREF_V8_V8) \
V(WIDE_NEWLEXENV_PREF_IMM16) \
@ -259,17 +264,14 @@ namespace panda::ecmascript::kungfu {
V(WIDE_CALLTHISRANGE_PREF_IMM16_V8) \
V(THROW_IFNOTOBJECT_PREF_V8) \
V(DEPRECATED_TONUMERIC_PREF_V8) \
V(WIDE_SUPERCALLTHISRANGE_PREF_IMM16_V8) \
V(THROW_UNDEFINEDIFHOLE_PREF_V8_V8) \
V(THROW_UNDEFINEDIFHOLEWITHNAME_PREF_ID16) \
V(DEPRECATED_NEG_PREF_V8) \
V(WIDE_SUPERCALLARROWRANGE_PREF_IMM16_V8) \
V(THROW_IFSUPERNOTCORRECTCALL_PREF_IMM8) \
V(DEPRECATED_NOT_PREF_V8) \
V(WIDE_LDOBJBYINDEX_PREF_IMM32) \
V(THROW_IFSUPERNOTCORRECTCALL_PREF_IMM16) \
V(DEPRECATED_INC_PREF_V8) \
V(WIDE_STOBJBYINDEX_PREF_V8_IMM32) \
V(DEPRECATED_DEC_PREF_V8) \
V(WIDE_STOWNBYINDEX_PREF_V8_IMM32) \
V(DEPRECATED_CALLARG0_PREF_V8) \
@ -317,7 +319,6 @@ namespace panda::ecmascript::kungfu {
V(DEPRECATED_CREATEOBJECTHAVINGMETHOD_PREF_IMM16) \
V(DEPRECATED_DYNAMICIMPORT_PREF_V8) \
V(CALLRUNTIME_NOTIFYCONCURRENTRESULT_PREF_NONE) \
V(DEFINEFIELDBYNAME_IMM8_ID16_V8) \
V(CALLRUNTIME_DEFINEFIELDBYVALUE_PREF_IMM8_V8_V8) \
V(CALLRUNTIME_DEFINEFIELDBYINDEX_PREF_IMM8_IMM32_V8) \
V(CALLRUNTIME_TOPROPERTYKEY_PREF_NONE) \
@ -340,5 +341,27 @@ inline std::string GetEcmaOpcodeStr(EcmaOpcode opcode)
return "bytecode-" + std::to_string(static_cast<uint16_t>(opcode));
}
inline std::vector<EcmaOpcode> GetEcmaCodeListForRange()
{
std::vector<EcmaOpcode> lorwingOpCodeList = {
#define BYTECODE_NAME_VECTOR(name) EcmaOpcode::name,
ECMA_OPCODE_LIST(BYTECODE_NAME_VECTOR)
#undef BYTECODE_NAME_VECTOR
};
return lorwingOpCodeList;
}
inline std::string GetHelpForEcmaCodeListForRange()
{
int32_t i = 0;
std::vector<EcmaOpcode> lorwingOpCodeList = GetEcmaCodeListForRange();
std::string optBCRangeStr;
optBCRangeStr.append(" bytecode for list: \n");
for (auto ecmaOpCode : lorwingOpCodeList) {
optBCRangeStr.append(" index:" + std::to_string(i) + " ecmaOpCode:" + GetEcmaOpcodeStr(ecmaOpCode) + "\n");
i++;
}
return optBCRangeStr;
}
} // namespace panda::ecmascript::kungfu
#endif // ECMASCRIPT_COMPILER_ECMA_OPCODE_DES_H_

View File

@ -69,10 +69,12 @@ public:
std::string methodName, MethodInfo *methodInfo = nullptr, bool hasTypes = false,
const CString &recordName = "", MethodLiteral *methodLiteral = nullptr,
uint32_t methodOffset = 0, NativeAreaAllocator *allocator = nullptr,
PGOProfilerDecoder *decoder = nullptr, PassOptions *passOptions = nullptr)
PGOProfilerDecoder *decoder = nullptr, PassOptions *passOptions = nullptr,
std::string optBCRange = "")
: builder_(builder), circuit_(circuit), ctx_(ctx), log_(log), methodName_(methodName),
methodInfo_(methodInfo), hasTypes_(hasTypes), recordName_(recordName), methodLiteral_(methodLiteral),
methodOffset_(methodOffset), allocator_(allocator), decoder_(decoder), passOptions_(passOptions)
methodOffset_(methodOffset), allocator_(allocator), decoder_(decoder), passOptions_(passOptions),
optBCRange_(optBCRange)
{
}
@ -183,6 +185,11 @@ public:
return passOptions_;
}
std::string GetOptBCRange() const
{
return optBCRange_;
}
bool IsTypeAbort() const
{
if (hasTypes_) {
@ -233,6 +240,7 @@ private:
NativeAreaAllocator *allocator_ {nullptr};
PGOProfilerDecoder *decoder_ {nullptr};
PassOptions *passOptions_ {nullptr};
std::string optBCRange_;
};
template<typename T1>
@ -312,7 +320,8 @@ public:
enableTypeLog,
data->GetMethodName(),
passOptions->EnableLoweringBuiltin(),
data->GetRecordName());
data->GetRecordName(),
data->GetOptBCRange());
bool success = lowering.RunTypedBytecodeLowering();
if (!success) {
data->MarkAsTypeAbort();

View File

@ -257,7 +257,8 @@ bool PassManager::Compile(JSPandaFile *jsPandaFile, const std::string &fileName,
}
PassData data(&builder, &circuit, &ctx, log_, fullName, &methodInfo, hasTypes, recordName,
methodLiteral, methodOffset, vm_->GetNativeAreaAllocator(), decoder, passOptions_);
methodLiteral, methodOffset, vm_->GetNativeAreaAllocator(), decoder, passOptions_,
optBCRange_);
PassRunner<PassData> pipeline(&data);
if (data.GetMethodLiteral()->HasDebuggerStmt()) {
data.AbortCompilation();

View File

@ -142,10 +142,10 @@ class PassManager {
public:
explicit PassManager(EcmaVM* vm, std::string &triple, size_t optLevel, size_t relocMode,
CompilerLog *log, AotMethodLogList *logList, size_t maxAotMethodSize, size_t maxMethodsInModule,
PGOProfilerDecoder &profilerDecoder, PassOptions *passOptions)
PGOProfilerDecoder &profilerDecoder, PassOptions *passOptions, std::string optBCRange)
: vm_(vm), triple_(triple), optLevel_(optLevel), relocMode_(relocMode), log_(log),
logList_(logList), maxAotMethodSize_(maxAotMethodSize), maxMethodsInModule_(maxMethodsInModule),
profilerDecoder_(profilerDecoder), passOptions_(passOptions) {
profilerDecoder_(profilerDecoder), passOptions_(passOptions), optBCRange_(optBCRange) {
enableJITLog_ = vm_->GetJSOptions().GetTraceJIT();
};
@ -165,6 +165,7 @@ protected:
size_t maxMethodsInModule_ {0};
PGOProfilerDecoder &profilerDecoder_;
PassOptions *passOptions_ {nullptr};
std::string optBCRange_ {};
bool enableJITLog_ {false};
};
@ -173,7 +174,7 @@ public:
JitPassManager(EcmaVM* vm, std::string &triple, size_t optLevel, size_t relocMode,
CompilerLog *log, AotMethodLogList *logList,
PGOProfilerDecoder &profilerDecoder, PassOptions *passOptions)
: PassManager(vm, triple, optLevel, relocMode, log, logList, 1, 1, profilerDecoder, passOptions) { };
: PassManager(vm, triple, optLevel, relocMode, log, logList, 1, 1, profilerDecoder, passOptions, "") { };
bool Compile(JSHandle<JSFunction> &jsFunction, AOTFileGenerator &gen);
bool RunCg();

View File

@ -13,6 +13,10 @@
* limitations under the License.
*/
#include <string>
#include <cstring>
#include <cstdlib>
#include "ecmascript/compiler/typed_bytecode_lowering.h"
#include "ecmascript/builtin_entries.h"
#include "ecmascript/compiler/builtins_lowering.h"
@ -23,12 +27,14 @@
#include "ecmascript/js_tagged_value.h"
#include "ecmascript/jspandafile/program_object.h"
#include "ecmascript/stackmap/llvm/llvm_stackmap_parser.h"
#include "ecmascript/base/string_helper.h"
namespace panda::ecmascript::kungfu {
bool TypedBytecodeLowering::RunTypedBytecodeLowering()
{
std::vector<GateRef> gateList;
circuit_->GetAllGates(gateList);
ParseOptBytecodeRange();
for (const auto &gate : gateList) {
auto op = acc_.GetOpCode(gate);
if (op == OpCode::JS_BYTECODE) {
@ -85,13 +91,74 @@ bool TypedBytecodeLowering::RunTypedBytecodeLowering()
return success;
}
void TypedBytecodeLowering::ParseOptBytecodeRange()
{
std::vector<std::string> splitStrs = base::StringHelper::SplitString(optBCRange_, ",");
for (const auto &optBCRange : splitStrs) {
std::vector<std::string> splitRange = base::StringHelper::SplitString(optBCRange, ":");
if (splitRange.size() == 2) {
std::vector<int32_t> range;
std::string start = splitRange[0];
std::string end = splitRange[1];
uint32_t startNumber = std::strtoull(start.c_str(), nullptr, 10);
uint32_t endNumber = std::strtoull(end.c_str(), nullptr, 10);
range.push_back(static_cast<int32_t>(startNumber));
range.push_back(static_cast<int32_t>(endNumber));
optBCRangeList_.push_back(range);
}
}
}
bool TypedBytecodeLowering::CheckIsInOptBCIgnoreRange(int32_t index, EcmaOpcode ecmaOpcode)
{
for (std::vector<int32_t> range : optBCRangeList_) {
if (index >= range[0] && index <= range[1]) {
LOG_COMPILER(INFO) << "TypedBytecodeLowering ignore opcode:" << GetEcmaOpcodeStr(ecmaOpcode);
return true;
}
}
return false;
}
void TypedBytecodeLowering::Lower(GateRef gate)
{
EcmaOpcode ecmaOpcode = acc_.GetByteCodeOpcode(gate);
// initialize label manager
Environment env(gate, circuit_, &builder_);
AddBytecodeCount(ecmaOpcode);
// The order in the switch is referred to in ecmascript/compiler/ecma_opcode_des.h
int32_t index = GetEcmaOpCodeListIndex(ecmaOpcode);
if (optBCRangeList_.size() > 0 && CheckIsInOptBCIgnoreRange(index, ecmaOpcode)) {
DeleteBytecodeCount(ecmaOpcode);
allNonTypedOpCount_++;
return;
}
switch (ecmaOpcode) {
case EcmaOpcode::GETITERATOR_IMM8:
case EcmaOpcode::GETITERATOR_IMM16:
LowerGetIterator(gate);
break;
case EcmaOpcode::CREATEEMPTYOBJECT:
LowerCreateEmptyObject(gate);
break;
case EcmaOpcode::CALLTHIS0_IMM8_V8:
LowerTypedCallthis0(gate);
break;
case EcmaOpcode::CALLTHIS1_IMM8_V8_V8:
LowerTypedCallthis1(gate);
break;
case EcmaOpcode::CALLTHIS2_IMM8_V8_V8_V8:
LowerTypedCallthis2(gate);
break;
case EcmaOpcode::CREATEOBJECTWITHBUFFER_IMM8_ID16:
case EcmaOpcode::CREATEOBJECTWITHBUFFER_IMM16_ID16:
LowerCreateObjectWithBuffer(gate);
break;
case EcmaOpcode::NEWOBJRANGE_IMM8_IMM8_V8:
case EcmaOpcode::NEWOBJRANGE_IMM16_IMM8_V8:
case EcmaOpcode::WIDE_NEWOBJRANGE_PREF_IMM16_V8:
LowerTypedNewObjRange(gate);
break;
case EcmaOpcode::ADD2_IMM8_V8:
LowerTypedBinOp<TypedBinOp::TYPED_ADD>(gate);
break;
@ -107,6 +174,12 @@ void TypedBytecodeLowering::Lower(GateRef gate)
case EcmaOpcode::MOD2_IMM8_V8:
LowerTypedBinOp<TypedBinOp::TYPED_MOD>(gate);
break;
case EcmaOpcode::EQ_IMM8_V8:
LowerTypedEqOrNotEq<TypedBinOp::TYPED_EQ>(gate);
break;
case EcmaOpcode::NOTEQ_IMM8_V8:
LowerTypedEqOrNotEq<TypedBinOp::TYPED_NOTEQ>(gate);
break;
case EcmaOpcode::LESS_IMM8_V8:
LowerTypedBinOp<TypedBinOp::TYPED_LESS>(gate);
break;
@ -119,18 +192,6 @@ void TypedBytecodeLowering::Lower(GateRef gate)
case EcmaOpcode::GREATEREQ_IMM8_V8:
LowerTypedBinOp<TypedBinOp::TYPED_GREATEREQ>(gate);
break;
case EcmaOpcode::EQ_IMM8_V8:
LowerTypedEqOrNotEq<TypedBinOp::TYPED_EQ>(gate);
break;
case EcmaOpcode::STRICTEQ_IMM8_V8:
LowerTypedEqOrNotEq<TypedBinOp::TYPED_STRICTEQ>(gate);
break;
case EcmaOpcode::NOTEQ_IMM8_V8:
LowerTypedEqOrNotEq<TypedBinOp::TYPED_NOTEQ>(gate);
break;
case EcmaOpcode::STRICTNOTEQ_IMM8_V8:
LowerTypedEqOrNotEq<TypedBinOp::TYPED_STRICTNOTEQ>(gate);
break;
case EcmaOpcode::SHL2_IMM8_V8:
LowerTypedBinOp<TypedBinOp::TYPED_SHL>(gate);
break;
@ -149,6 +210,10 @@ void TypedBytecodeLowering::Lower(GateRef gate)
case EcmaOpcode::XOR2_IMM8_V8:
LowerTypedBinOp<TypedBinOp::TYPED_XOR>(gate);
break;
case EcmaOpcode::TYPEOF_IMM8:
case EcmaOpcode::TYPEOF_IMM16:
LowerTypedTypeOf(gate);
break;
case EcmaOpcode::TONUMERIC_IMM8:
LowerTypeToNumeric(gate);
break;
@ -164,21 +229,42 @@ void TypedBytecodeLowering::Lower(GateRef gate)
case EcmaOpcode::DEC_IMM8:
LowerTypedUnOp<TypedUnOp::TYPED_DEC>(gate);
break;
case EcmaOpcode::INSTANCEOF_IMM8_V8:
LowerInstanceOf(gate);
break;
case EcmaOpcode::STRICTNOTEQ_IMM8_V8:
LowerTypedEqOrNotEq<TypedBinOp::TYPED_STRICTNOTEQ>(gate);
break;
case EcmaOpcode::STRICTEQ_IMM8_V8:
LowerTypedEqOrNotEq<TypedBinOp::TYPED_STRICTEQ>(gate);
break;
case EcmaOpcode::ISTRUE:
LowerTypedIsTrueOrFalse(gate, true);
break;
case EcmaOpcode::ISFALSE:
LowerTypedIsTrueOrFalse(gate, false);
break;
case EcmaOpcode::JEQZ_IMM8:
case EcmaOpcode::JEQZ_IMM16:
case EcmaOpcode::JEQZ_IMM32:
LowerConditionJump(gate, false);
case EcmaOpcode::CALLTHIS3_IMM8_V8_V8_V8_V8:
LowerTypedCallthis3(gate);
break;
case EcmaOpcode::JNEZ_IMM8:
case EcmaOpcode::JNEZ_IMM16:
case EcmaOpcode::JNEZ_IMM32:
LowerConditionJump(gate, true);
case EcmaOpcode::CALLTHISRANGE_IMM8_IMM8_V8:
LowerTypedCallthisrange(gate);
break;
case EcmaOpcode::SUPERCALLTHISRANGE_IMM8_IMM8_V8:
case EcmaOpcode::WIDE_SUPERCALLTHISRANGE_PREF_IMM16_V8:
LowerTypedSuperCall(gate);
break;
case EcmaOpcode::CALLARG0_IMM8:
LowerTypedCallArg0(gate);
break;
case EcmaOpcode::CALLARGS2_IMM8_V8_V8:
LowerTypedCallArg2(gate);
break;
case EcmaOpcode::CALLARGS3_IMM8_V8_V8_V8:
LowerTypedCallArg3(gate);
break;
case EcmaOpcode::CALLRANGE_IMM8_IMM8_V8:
LowerTypedCallrange(gate);
break;
case EcmaOpcode::LDOBJBYNAME_IMM8_ID16:
case EcmaOpcode::LDOBJBYNAME_IMM16_ID16:
@ -193,9 +279,24 @@ void TypedBytecodeLowering::Lower(GateRef gate)
case EcmaOpcode::DEFINEFIELDBYNAME_IMM8_ID16_V8:
LowerTypedStObjByName(gate);
break;
case EcmaOpcode::STOWNBYNAME_IMM8_ID16_V8:
case EcmaOpcode::STOWNBYNAME_IMM16_ID16_V8:
LowerTypedStOwnByName(gate);
case EcmaOpcode::LDOBJBYVALUE_IMM8_V8:
case EcmaOpcode::LDOBJBYVALUE_IMM16_V8:
case EcmaOpcode::LDTHISBYVALUE_IMM8:
case EcmaOpcode::LDTHISBYVALUE_IMM16:
LowerTypedLdObjByValue(gate);
break;
case EcmaOpcode::JEQZ_IMM8:
case EcmaOpcode::JEQZ_IMM16:
case EcmaOpcode::JEQZ_IMM32:
LowerConditionJump(gate, false);
break;
case EcmaOpcode::STOBJBYVALUE_IMM8_V8_V8:
case EcmaOpcode::STOBJBYVALUE_IMM16_V8_V8:
LowerTypedStObjByValue(gate);
break;
case EcmaOpcode::STOWNBYVALUE_IMM8_V8_V8:
case EcmaOpcode::STOWNBYVALUE_IMM16_V8_V8:
LowerTypedStOwnByValue(gate);
break;
case EcmaOpcode::LDOBJBYINDEX_IMM8_IMM16:
case EcmaOpcode::LDOBJBYINDEX_IMM16_IMM16:
@ -207,83 +308,24 @@ void TypedBytecodeLowering::Lower(GateRef gate)
case EcmaOpcode::WIDE_STOBJBYINDEX_PREF_V8_IMM32:
LowerTypedStObjByIndex(gate);
break;
case EcmaOpcode::LDOBJBYVALUE_IMM8_V8:
case EcmaOpcode::LDOBJBYVALUE_IMM16_V8:
case EcmaOpcode::LDTHISBYVALUE_IMM8:
case EcmaOpcode::LDTHISBYVALUE_IMM16:
LowerTypedLdObjByValue(gate);
break;
case EcmaOpcode::STOBJBYVALUE_IMM8_V8_V8:
case EcmaOpcode::STOBJBYVALUE_IMM16_V8_V8:
LowerTypedStObjByValue(gate);
break;
case EcmaOpcode::STOWNBYVALUE_IMM8_V8_V8:
case EcmaOpcode::STOWNBYVALUE_IMM16_V8_V8:
LowerTypedStOwnByValue(gate);
break;
case EcmaOpcode::NEWOBJRANGE_IMM8_IMM8_V8:
case EcmaOpcode::NEWOBJRANGE_IMM16_IMM8_V8:
case EcmaOpcode::WIDE_NEWOBJRANGE_PREF_IMM16_V8:
LowerTypedNewObjRange(gate);
break;
case EcmaOpcode::SUPERCALLTHISRANGE_IMM8_IMM8_V8:
case EcmaOpcode::WIDE_SUPERCALLTHISRANGE_PREF_IMM16_V8:
LowerTypedSuperCall(gate);
break;
case EcmaOpcode::CALLARG0_IMM8:
LowerTypedCallArg0(gate);
break;
case EcmaOpcode::CALLARG1_IMM8_V8:
LowerTypedCallArg1(gate);
break;
case EcmaOpcode::CALLARGS2_IMM8_V8_V8:
LowerTypedCallArg2(gate);
break;
case EcmaOpcode::CALLARGS3_IMM8_V8_V8_V8:
LowerTypedCallArg3(gate);
break;
case EcmaOpcode::CALLRANGE_IMM8_IMM8_V8:
LowerTypedCallrange(gate);
break;
case EcmaOpcode::CALLTHIS0_IMM8_V8:
LowerTypedCallthis0(gate);
break;
case EcmaOpcode::CALLTHIS1_IMM8_V8_V8:
LowerTypedCallthis1(gate);
break;
case EcmaOpcode::CALLTHIS2_IMM8_V8_V8_V8:
LowerTypedCallthis2(gate);
break;
case EcmaOpcode::CALLTHIS3_IMM8_V8_V8_V8_V8:
LowerTypedCallthis3(gate);
break;
case EcmaOpcode::CALLTHISRANGE_IMM8_IMM8_V8:
LowerTypedCallthisrange(gate);
break;
case EcmaOpcode::CALLRUNTIME_CALLINIT_PREF_IMM8_V8:
LowerTypedCallInit(gate);
break;
case EcmaOpcode::TYPEOF_IMM8:
case EcmaOpcode::TYPEOF_IMM16:
LowerTypedTypeOf(gate);
break;
case EcmaOpcode::GETITERATOR_IMM8:
case EcmaOpcode::GETITERATOR_IMM16:
LowerGetIterator(gate);
break;
case EcmaOpcode::TRYLDGLOBALBYNAME_IMM8_ID16:
case EcmaOpcode::TRYLDGLOBALBYNAME_IMM16_ID16:
LowerTypedTryLdGlobalByName(gate);
break;
case EcmaOpcode::INSTANCEOF_IMM8_V8:
LowerInstanceOf(gate);
case EcmaOpcode::STOWNBYNAME_IMM8_ID16_V8:
case EcmaOpcode::STOWNBYNAME_IMM16_ID16_V8:
LowerTypedStOwnByName(gate);
break;
case EcmaOpcode::CREATEEMPTYOBJECT:
LowerCreateEmptyObject(gate);
case EcmaOpcode::JNEZ_IMM8:
case EcmaOpcode::JNEZ_IMM16:
case EcmaOpcode::JNEZ_IMM32:
LowerConditionJump(gate, true);
break;
case EcmaOpcode::CREATEOBJECTWITHBUFFER_IMM8_ID16:
case EcmaOpcode::CREATEOBJECTWITHBUFFER_IMM16_ID16:
LowerCreateObjectWithBuffer(gate);
case EcmaOpcode::CALLARG1_IMM8_V8:
LowerTypedCallArg1(gate);
break;
case EcmaOpcode::CALLRUNTIME_CALLINIT_PREF_IMM8_V8:
LowerTypedCallInit(gate);
break;
default:
DeleteBytecodeCount(ecmaOpcode);
@ -292,6 +334,24 @@ void TypedBytecodeLowering::Lower(GateRef gate)
}
}
int32_t TypedBytecodeLowering::GetEcmaOpCodeListIndex(EcmaOpcode ecmaOpCode)
{
std::vector<EcmaOpcode> opcodeList = GetEcmaCodeListForRange();
int32_t index = opcodeList.size();
int32_t size = static_cast<int32_t>(opcodeList.size());
for (int32_t i = 0; i < size; i++) {
if (opcodeList[i] == ecmaOpCode) {
index = i;
break;
}
}
if (index != size) {
return index;
} else {
return -1;
}
}
template<TypedBinOp Op>
void TypedBytecodeLowering::LowerTypedBinOp(GateRef gate, bool convertNumberType)
{

View File

@ -37,7 +37,8 @@ public:
bool enableTypeLog,
const std::string& name,
bool enableLoweringBuiltin,
const CString& recordName)
const CString& recordName,
const std::string optBCRange)
: circuit_(circuit),
acc_(circuit),
builder_(circuit, ctx->GetCompilerConfig()),
@ -56,7 +57,8 @@ public:
noCheck_(ctx->GetEcmaVM()->GetJSOptions().IsCompilerNoCheck()),
thread_(ctx->GetEcmaVM()->GetJSThread()),
enableLoweringBuiltin_(enableLoweringBuiltin),
recordName_(recordName)
recordName_(recordName),
optBCRange_(optBCRange)
{
}
@ -204,7 +206,9 @@ private:
void DeleteConstDataIfNoUser(GateRef gate);
bool TryLowerNewBuiltinConstructor(GateRef gate);
bool TryLowerTypedLdobjBynameFromGloablBuiltin(GateRef gate);
bool CheckIsInOptBCIgnoreRange(int32_t index, EcmaOpcode ecmaOpcode);
int32_t GetEcmaOpCodeListIndex(EcmaOpcode ecmaOpCode);
void ParseOptBytecodeRange();
void AddProfiling(GateRef gate);
bool Uncheck() const
@ -237,6 +241,8 @@ private:
const JSThread *thread_ {nullptr};
bool enableLoweringBuiltin_ {false};
const CString &recordName_;
std::string optBCRange_;
std::vector<std::vector<int32_t>> optBCRangeList_;
};
} // panda::ecmascript::kungfu
#endif // ECMASCRIPT_COMPILER_TYPED_BYTECODE_LOWERING_H

View File

@ -22,6 +22,7 @@
#include "ecmascript/compiler/aot_file/an_file_data_manager.h"
#include "ecmascript/mem/mem_common.h"
#include "ecmascript/compiler/ecma_opcode_des.h"
namespace panda::ecmascript {
const std::string PUBLIC_API COMMON_HELP_HEAD_MSG =
@ -75,6 +76,8 @@ const std::string PUBLIC_API HELP_OPTION_MSG =
"--compiler-deopt-threshold: Set max count which aot function can occur deoptimization. Default: '10'\n"
"--compiler-stress-deopt: Enable stress deopt for aot compiler. Default: 'false'\n"
"--compiler-opt-code-profiler: Enable opt code Bytecode Statistics for aot runtime. Default: 'false'\n"
"--compiler-opt-bc-range: Range list for EcmaOpCode range Example '1:2,5:8'\n"
"--compiler-opt-bc-range-help: Range list for EcmaOpCode range help. Default: 'false''\n"
"--enable-force-gc: Enable force gc when allocating object. Default: 'true'\n"
"--enable-ic: Switch of inline cache. Default: 'true'\n"
"--enable-runtime-stat: Enable statistics of runtime state. Default: 'false'\n"
@ -198,6 +201,8 @@ bool JSRuntimeOptions::ParseCommand(const int argc, const char **argv)
{"compiler-deopt-threshold", required_argument, nullptr, OPTION_COMPILER_DEOPT_THRESHOLD},
{"compiler-stress-deopt", required_argument, nullptr, OPTION_COMPILER_STRESS_DEOPT},
{"compiler-opt-code-profiler", required_argument, nullptr, OPTION_COMPILER_OPT_CODE_PROFILER},
{"compiler-opt-bc-range", required_argument, nullptr, OPTION_COMPILER_OPT_BC_RANGE},
{"compiler-opt-bc-range-help", required_argument, nullptr, OPTION_COMPILER_OPT_BC_RANGE_HELP},
{"enable-force-gc", required_argument, nullptr, OPTION_ENABLE_FORCE_GC},
{"enable-ic", required_argument, nullptr, OPTION_ENABLE_IC},
{"enable-runtime-stat", required_argument, nullptr, OPTION_ENABLE_RUNTIME_STAT},
@ -466,6 +471,17 @@ bool JSRuntimeOptions::ParseCommand(const int argc, const char **argv)
return false;
}
break;
case OPTION_COMPILER_OPT_BC_RANGE:
SetOptCodeRange(optarg);
break;
case OPTION_COMPILER_OPT_BC_RANGE_HELP:
ret = ParseBoolParam(&argBool);
if (ret) {
std::string helpInfo = kungfu::GetHelpForEcmaCodeListForRange();
LOG_COMPILER(ERROR) << helpInfo.c_str();
exit(1);
}
break;
case OPTION_ENABLE_FORCE_GC:
ret = ParseBoolParam(&argBool);
if (ret) {

View File

@ -103,6 +103,7 @@ enum CommandValues {
OPTION_COMPILER_DEOPT_THRESHOLD,
OPTION_COMPILER_STRESS_DEOPT,
OPTION_COMPILER_OPT_CODE_PROFILER,
OPTION_COMPILER_OPT_BC_RANGE,
OPTION_LOG_LEVEL,
OPTION_LOG_DEBUG,
OPTION_LOG_INFO,
@ -166,6 +167,7 @@ enum CommandValues {
OPTION_TEST_ASSERT,
OPTION_COMPILER_METHODS_RANGE,
OPTION_COMPILER_CODEGEN_OPT,
OPTION_COMPILER_OPT_BC_RANGE_HELP,
};
class PUBLIC_API JSRuntimeOptions {
@ -1484,6 +1486,16 @@ public:
{
return compileCodegenOption_;
}
void SetOptCodeRange(std::string value)
{
optBCRange_ = std::move(value);
}
std::string GetOptCodeRange() const
{
return optBCRange_;
}
private:
static bool StartsWith(const std::string &haystack, const std::string &needle)
{
@ -1591,6 +1603,7 @@ private:
std::string hapPath_ {""};
uint32_t hapAbcOffset_ {0};
uint32_t hapAbcSize_ {0};
std::string optBCRange_ {""};
bool compilerNoCheck_ {false};
bool fastAOTCompileMode_ {false};
bool enableOptLoopPeeling_ {true};