Supplement the full-path to the header files

issues:https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I5HWSN

Change-Id: I7aa0ccee74320e79a7219e12e1d8d6fb0ce7ea45
This commit is contained in:
lvfuqing 2022-07-25 09:53:14 +08:00
commit 2916498dbb
37 changed files with 734 additions and 583 deletions

View File

@ -15,6 +15,8 @@
#include "ecmascript/builtins/builtins_math.h"
#include <random>
#include "ecmascript/ecma_runtime_call_info.h"
#include "ecmascript/js_tagged_number.h"

View File

@ -63,6 +63,7 @@ source_set("libark_jsoptimizer_set") {
"llvm_ir_builder.cpp",
"rt_call_signature.cpp",
"scheduler.cpp",
"stub.cpp",
"stub_builder.cpp",
"test_stubs.cpp",
"test_stubs_signature.cpp",

View File

@ -132,9 +132,11 @@ void AsyncFunctionLowering::RebuildGeneratorCfg(GateRef resumeGate, GateRef rest
// Find the node with LOOP_BEGIN as State input and modify its
// state input to the newly created IF_FALSE node.
auto uses = accessor_.Uses(stateInGate);
for (auto useIt = uses.begin(); useIt != uses.end(); useIt++) {
for (auto useIt = uses.begin(); useIt != uses.end();) {
if (accessor_.GetOpCode(*useIt).IsState() && *useIt != ifBranch) {
accessor_.ReplaceIn(useIt, ifFalse);
useIt = accessor_.ReplaceIn(useIt, ifFalse);
} else {
useIt++;
}
}

View File

@ -31,10 +31,10 @@ void BytecodeStubCSigns::Initialize()
callSigns_[name].SetID(ID_##name); \
callSigns_[name].SetName(#name); \
callSigns_[name].SetConstructor( \
[](void* ciruit) { \
[](void* env) { \
return static_cast<void*>( \
new name##StubBuilder(&callSigns_[name], \
static_cast<Circuit*>(ciruit))); \
static_cast<Environment*>(env))); \
});
INTERPRETER_BC_STUB_LIST(INIT_SIGNATURES)
#undef INIT_SIGNATURES
@ -45,9 +45,9 @@ void BytecodeStubCSigns::Initialize()
callSigns_[name].SetName(#name); \
callSigns_[name].SetTargetKind(CallSignature::TargetKind::BYTECODE_HELPER_HANDLER); \
callSigns_[name].SetConstructor( \
[](void* ciruit) { \
[](void* env) { \
return static_cast<void*>( \
new name##StubBuilder(&callSigns_[name], static_cast<Circuit*>(ciruit))); \
new name##StubBuilder(&callSigns_[name], static_cast<Environment*>(env))); \
});
ASM_INTERPRETER_BC_HELPER_STUB_LIST(INIT_HELPER_SIGNATURES)
#undef INIT_HELPER_SIGNATURES

View File

@ -673,10 +673,10 @@ GateRef Label::LabelImpl::ReadVariableRecursive(Variable *var)
// only loopheader gate will be not sealed
int valueCounts = static_cast<int>(this->predecessors_.size()) + 1;
if (MachineType == MachineType::NOVALUE) {
val = env_->GetBulder()->Selector(OpCode(OpCode::DEPEND_SELECTOR),
val = env_->GetBuilder()->Selector(OpCode(OpCode::DEPEND_SELECTOR),
predeControl_, {}, valueCounts, var->Type());
} else {
val = env_->GetBulder()->Selector(OpCode(OpCode::VALUE_SELECTOR),
val = env_->GetBuilder()->Selector(OpCode(OpCode::VALUE_SELECTOR),
MachineType, predeControl_, {}, valueCounts, var->Type());
}
env_->AddSelectorToLabel(val, Label(this));
@ -685,10 +685,10 @@ GateRef Label::LabelImpl::ReadVariableRecursive(Variable *var)
val = predecessors_[0]->ReadVariable(var);
} else {
if (MachineType == MachineType::NOVALUE) {
val = env_->GetBulder()->Selector(OpCode(OpCode::DEPEND_SELECTOR),
val = env_->GetBuilder()->Selector(OpCode(OpCode::DEPEND_SELECTOR),
predeControl_, {}, this->predecessors_.size(), var->Type());
} else {
val = env_->GetBulder()->Selector(OpCode(OpCode::VALUE_SELECTOR), MachineType,
val = env_->GetBuilder()->Selector(OpCode(OpCode::VALUE_SELECTOR), MachineType,
predeControl_, {}, this->predecessors_.size(), var->Type());
}
env_->AddSelectorToLabel(val, Label(this));
@ -704,7 +704,7 @@ void Label::LabelImpl::Bind()
ASSERT(!predecessors_.empty());
if (IsLoopHead()) {
// 2 means input number of depend selector gate
loopDepend_ = env_->GetBulder()->Selector(OpCode(OpCode::DEPEND_SELECTOR), predeControl_, {}, 2);
loopDepend_ = env_->GetBuilder()->Selector(OpCode(OpCode::DEPEND_SELECTOR), predeControl_, {}, 2);
GateAccessor(env_->GetCircuit()).NewIn(loopDepend_, 1, predecessors_[0]->GetDepend());
depend_ = loopDepend_;
}
@ -738,7 +738,7 @@ void Label::LabelImpl::MergeAllControl()
inGates[i++] = in;
}
GateRef merge = env_->GetBulder()->Merge(inGates.data(), inGates.size());
GateRef merge = env_->GetBuilder()->Merge(inGates.data(), inGates.size());
predeControl_ = merge;
control_ = merge;
}
@ -748,13 +748,13 @@ void Label::LabelImpl::MergeAllDepend()
if (IsControlCase()) {
// Add depend_relay to current label
auto denpendEntry = Circuit::GetCircuitRoot(OpCode(OpCode::DEPEND_ENTRY));
dependRelay_ = env_->GetBulder()->DependRelay(predeControl_, denpendEntry);
dependRelay_ = env_->GetBuilder()->DependRelay(predeControl_, denpendEntry);
}
if (predecessors_.size() < 2) { // 2 : Loop Head only support two predecessors_
depend_ = predecessors_[0]->GetDepend();
if (dependRelay_ != -1) {
depend_ = env_->GetBulder()->DependAnd({depend_, dependRelay_});
depend_ = env_->GetBuilder()->DependAnd({depend_, dependRelay_});
}
return;
}
@ -772,7 +772,7 @@ void Label::LabelImpl::MergeAllDepend()
for (auto prede : this->GetPredecessors()) {
dependsList.push_back(prede->GetDepend());
}
depend_ = env_->GetBulder()->Selector(OpCode(OpCode::DEPEND_SELECTOR),
depend_ = env_->GetBuilder()->Selector(OpCode(OpCode::DEPEND_SELECTOR),
predeControl_, dependsList, dependsList.size());
}
@ -837,17 +837,19 @@ GateRef Variable::TryRemoveTrivialPhi(GateRef phi)
if (same == Gate::InvalidGateRef) {
// the phi is unreachable or in the start block
GateType type = acc.GetGateType(phi);
same = env_->GetBulder()->UndefineConstant(type);
same = env_->GetBuilder()->UndefineConstant(type);
}
// remove the trivial phi
// get all users of phi except self
std::vector<GateRef> outs;
auto uses = acc.Uses(phi);
for (auto use = uses.begin(); use != uses.end(); use++) {
for (auto use = uses.begin(); use != uses.end();) {
GateRef u = *use;
if (u != phi) {
outs.push_back(u);
acc.ReplaceIn(use, same);
use = acc.ReplaceIn(use, same);
} else {
use++;
}
}
acc.DeleteGate(phi);

View File

@ -536,7 +536,7 @@ public:
{
currentLabel_ = label;
}
CircuitBuilder *GetBulder() const
CircuitBuilder *GetBuilder() const
{
return circuitBuilder_;
}

View File

@ -26,9 +26,8 @@
namespace panda::ecmascript::kungfu {
using namespace panda::ecmascript;
void AddStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
void AddStubBuilder::GenerateCircuit()
{
StubBuilder::GenerateCircuit(cfg);
GateRef glue = PtrArgument(0);
(void)glue;
GateRef x = TaggedArgument(1);
@ -36,9 +35,8 @@ void AddStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
Return(FastAdd(x, y));
}
void SubStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
void SubStubBuilder::GenerateCircuit()
{
StubBuilder::GenerateCircuit(cfg);
GateRef glue = PtrArgument(0);
(void)glue;
GateRef x = TaggedArgument(1);
@ -46,9 +44,8 @@ void SubStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
Return(FastSub(x, y));
}
void MulStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
void MulStubBuilder::GenerateCircuit()
{
StubBuilder::GenerateCircuit(cfg);
GateRef glue = PtrArgument(0);
(void)glue;
GateRef x = TaggedArgument(1);
@ -56,9 +53,8 @@ void MulStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
Return(FastMul(x, y));
}
void DivStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
void DivStubBuilder::GenerateCircuit()
{
StubBuilder::GenerateCircuit(cfg);
GateRef glue = PtrArgument(0);
(void)glue;
GateRef x = TaggedArgument(1);
@ -66,26 +62,23 @@ void DivStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
Return(FastDiv(x, y));
}
void ModStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
void ModStubBuilder::GenerateCircuit()
{
StubBuilder::GenerateCircuit(cfg);
GateRef glue = PtrArgument(0);
GateRef x = TaggedArgument(1);
GateRef y = TaggedArgument(2); // 2: 3rd argument
Return(FastMod(glue, x, y));
}
void TypeOfStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
void TypeOfStubBuilder::GenerateCircuit()
{
StubBuilder::GenerateCircuit(cfg);
GateRef glue = PtrArgument(0);
GateRef obj = TaggedArgument(1);
Return(FastTypeOf(glue, obj));
}
void EqualStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
void EqualStubBuilder::GenerateCircuit()
{
StubBuilder::GenerateCircuit(cfg);
GateRef glue = PtrArgument(0);
(void)glue;
GateRef x = TaggedArgument(1);
@ -93,18 +86,16 @@ void EqualStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
Return(FastEqual(x, y));
}
void GetPropertyByIndexStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
void GetPropertyByIndexStubBuilder::GenerateCircuit()
{
StubBuilder::GenerateCircuit(cfg);
GateRef glue = PtrArgument(0);
GateRef receiver = TaggedArgument(1);
GateRef index = Int32Argument(2); /* 2 : 3rd parameter is index */
Return(GetPropertyByIndex(glue, receiver, index));
}
void SetPropertyByIndexStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
void SetPropertyByIndexStubBuilder::GenerateCircuit()
{
StubBuilder::GenerateCircuit(cfg);
GateRef glue = PtrArgument(0);
GateRef receiver = TaggedArgument(1);
GateRef index = Int32Argument(2); /* 2 : 3rd parameter is index */
@ -112,9 +103,8 @@ void SetPropertyByIndexStubBuilder::GenerateCircuit(const CompilationConfig *cfg
Return(SetPropertyByIndex(glue, receiver, index, value, false));
}
void SetPropertyByIndexWithOwnStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
void SetPropertyByIndexWithOwnStubBuilder::GenerateCircuit()
{
StubBuilder::GenerateCircuit(cfg);
GateRef glue = PtrArgument(0);
GateRef receiver = TaggedArgument(1);
GateRef index = Int32Argument(2); /* 2 : 3rd parameter is index */
@ -122,18 +112,16 @@ void SetPropertyByIndexWithOwnStubBuilder::GenerateCircuit(const CompilationConf
Return(SetPropertyByIndex(glue, receiver, index, value, true));
}
void GetPropertyByNameStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
void GetPropertyByNameStubBuilder::GenerateCircuit()
{
StubBuilder::GenerateCircuit(cfg);
GateRef glue = PtrArgument(0);
GateRef receiver = TaggedArgument(1);
GateRef key = TaggedArgument(2); // 2 : 3rd para
Return(GetPropertyByName(glue, receiver, key));
}
void SetPropertyByNameStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
void SetPropertyByNameStubBuilder::GenerateCircuit()
{
StubBuilder::GenerateCircuit(cfg);
GateRef glue = PtrArgument(0);
GateRef receiver = TaggedArgument(1);
GateRef key = TaggedArgument(2); // 2 : 3rd para
@ -141,9 +129,8 @@ void SetPropertyByNameStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
Return(SetPropertyByName(glue, receiver, key, value, false));
}
void SetPropertyByNameWithOwnStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
void SetPropertyByNameWithOwnStubBuilder::GenerateCircuit()
{
StubBuilder::GenerateCircuit(cfg);
GateRef glue = PtrArgument(0);
GateRef receiver = TaggedArgument(1);
GateRef key = TaggedArgument(2); // 2 : 3rd para
@ -151,18 +138,16 @@ void SetPropertyByNameWithOwnStubBuilder::GenerateCircuit(const CompilationConfi
Return(SetPropertyByName(glue, receiver, key, value, true));
}
void GetPropertyByValueStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
void GetPropertyByValueStubBuilder::GenerateCircuit()
{
StubBuilder::GenerateCircuit(cfg);
GateRef glue = PtrArgument(0);
GateRef receiver = TaggedArgument(1);
GateRef key = TaggedArgument(2); // 2 : 3rd para
Return(GetPropertyByValue(glue, receiver, key));
}
void SetPropertyByValueStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
void SetPropertyByValueStubBuilder::GenerateCircuit()
{
StubBuilder::GenerateCircuit(cfg);
GateRef glue = PtrArgument(0);
GateRef receiver = TaggedArgument(1);
GateRef key = TaggedArgument(2); /* 2 : 3rd parameter is key */
@ -170,9 +155,8 @@ void SetPropertyByValueStubBuilder::GenerateCircuit(const CompilationConfig *cfg
Return(SetPropertyByValue(glue, receiver, key, value, false));
}
void SetPropertyByValueWithOwnStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
void SetPropertyByValueWithOwnStubBuilder::GenerateCircuit()
{
StubBuilder::GenerateCircuit(cfg);
GateRef glue = PtrArgument(0);
GateRef receiver = TaggedArgument(1);
GateRef key = TaggedArgument(2); /* 2 : 3rd parameter is key */
@ -180,9 +164,8 @@ void SetPropertyByValueWithOwnStubBuilder::GenerateCircuit(const CompilationConf
Return(SetPropertyByValue(glue, receiver, key, value, true));
}
void TryLoadICByNameStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
void TryLoadICByNameStubBuilder::GenerateCircuit()
{
StubBuilder::GenerateCircuit(cfg);
auto env = GetEnvironment();
GateRef glue = PtrArgument(0);
GateRef receiver = TaggedArgument(1);
@ -220,9 +203,8 @@ void TryLoadICByNameStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
}
}
void TryLoadICByValueStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
void TryLoadICByValueStubBuilder::GenerateCircuit()
{
StubBuilder::GenerateCircuit(cfg);
auto env = GetEnvironment();
GateRef glue = PtrArgument(0);
GateRef receiver = TaggedArgument(1);
@ -260,9 +242,8 @@ void TryLoadICByValueStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
Return(Hole());
}
void TryStoreICByNameStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
void TryStoreICByNameStubBuilder::GenerateCircuit()
{
StubBuilder::GenerateCircuit(cfg);
auto env = GetEnvironment();
GateRef glue = PtrArgument(0);
GateRef receiver = TaggedArgument(1);
@ -298,9 +279,8 @@ void TryStoreICByNameStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
Return(Hole(VariableType::INT64()));
}
void TryStoreICByValueStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
void TryStoreICByValueStubBuilder::GenerateCircuit()
{
StubBuilder::GenerateCircuit(cfg);
auto env = GetEnvironment();
GateRef glue = PtrArgument(0);
GateRef receiver = TaggedArgument(1);
@ -338,9 +318,8 @@ void TryStoreICByValueStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
Return(Hole(VariableType::INT64()));
}
void SetValueWithBarrierStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
void SetValueWithBarrierStubBuilder::GenerateCircuit()
{
StubBuilder::GenerateCircuit(cfg);
GateRef glue = PtrArgument(0);
GateRef obj = TaggedArgument(1);
GateRef offset = PtrArgument(2); // 2 : 3rd para
@ -349,9 +328,8 @@ void SetValueWithBarrierStubBuilder::GenerateCircuit(const CompilationConfig *cf
Return();
}
void JsProxyCallInternalStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
void JsProxyCallInternalStubBuilder::GenerateCircuit()
{
StubBuilder::GenerateCircuit(cfg);
auto env = GetEnvironment();
Label exit(env);
Label isNull(env);
@ -410,13 +388,13 @@ CallSignature CommonStubCSigns::callSigns_[CommonStubCSigns::NUM_OF_STUBS];
void CommonStubCSigns::Initialize()
{
#define INIT_SIGNATURES(name) \
name##CallSignature::Initialize(&callSigns_[name]); \
callSigns_[name].SetID(name); \
callSigns_[name].SetConstructor( \
[](void* ciruit) { \
return static_cast<void*>( \
new name##StubBuilder(&callSigns_[name], static_cast<Circuit*>(ciruit))); \
#define INIT_SIGNATURES(name) \
name##CallSignature::Initialize(&callSigns_[name]); \
callSigns_[name].SetID(name); \
callSigns_[name].SetConstructor( \
[](void* env) { \
return static_cast<void*>( \
new name##StubBuilder(&callSigns_[name], static_cast<Environment*>(env))); \
});
COMMON_STUB_ID_LIST(INIT_SIGNATURES)

View File

@ -51,12 +51,12 @@ namespace panda::ecmascript::kungfu {
#define DECLARE_STUB_CLASS(name) \
class name##StubBuilder : public StubBuilder { \
public: \
explicit name##StubBuilder(CallSignature *callSignature, Circuit *circuit) \
: StubBuilder(callSignature, circuit) {} \
explicit name##StubBuilder(CallSignature *callSignature, Environment *env) \
: StubBuilder(callSignature, env) {} \
~name##StubBuilder() = default; \
NO_MOVE_SEMANTIC(name##StubBuilder); \
NO_COPY_SEMANTIC(name##StubBuilder); \
void GenerateCircuit(const CompilationConfig *cfg) override; \
void GenerateCircuit() override; \
};
COMMON_STUB_LIST(DECLARE_STUB_CLASS)
#undef DECLARE_STUB_CLASS

View File

@ -16,6 +16,8 @@
#include "ecmascript/compiler/gate_accessor.h"
namespace panda::ecmascript::kungfu {
using UseIterator = GateAccessor::UseIterator;
size_t GateAccessor::GetNumIns(GateRef gate) const
{
Gate *gatePtr = circuit_->LoadGatePtr(gate);
@ -154,7 +156,7 @@ size_t GateAccessor::GetImmediateId(GateRef gate) const
return imm;
}
bool GateAccessor::IsDependIn(const UsesIterator &useIt) const
bool GateAccessor::IsDependIn(const UseIterator &useIt) const
{
Gate *gatePtr = circuit_->LoadGatePtr(*useIt);
size_t dependStartIndex = gatePtr->GetStateCount();
@ -171,12 +173,14 @@ void GateAccessor::SetDep(GateRef gate, GateRef depGate, size_t idx)
gatePtr->ModifyIn(dependIndex + idx, circuit_->LoadGatePtr(depGate));
}
void GateAccessor::ReplaceIn(UsesIterator &useIt, GateRef replaceGate)
UseIterator GateAccessor::ReplaceIn(const UseIterator &useIt, GateRef replaceGate)
{
UseIterator next = useIt;
next++;
Gate *curGatePtr = circuit_->LoadGatePtr(*useIt);
Gate *replaceGatePtr = circuit_->LoadGatePtr(replaceGate);
curGatePtr->ModifyIn(useIt.GetIndex(), replaceGatePtr);
useIt.SetChanged();
return next;
}
GateType GateAccessor::GetGateType(GateRef gate) const
@ -189,8 +193,10 @@ void GateAccessor::SetGateType(GateRef gate, GateType gt)
circuit_->LoadGatePtr(gate)->SetGateType(gt);
}
void GateAccessor::DeleteExceptionDep(UsesIterator &useIt)
UseIterator GateAccessor::DeleteExceptionDep(const UseIterator &useIt)
{
auto next = useIt;
next++;
ASSERT(GetOpCode(*useIt) == OpCode::RETURN || GetOpCode(*useIt) == OpCode::DEPEND_SELECTOR);
if (GetOpCode(*useIt) == OpCode::RETURN) {
// 0 : the index of CONSTANT
@ -208,27 +214,21 @@ void GateAccessor::DeleteExceptionDep(UsesIterator &useIt)
}
DecreaseIn(useIt);
}
return next;
}
void GateAccessor::DeleteIn(UsesIterator &useIt)
{
size_t idx = useIt.GetIndex();
Gate *curGatePtr = circuit_->LoadGatePtr(*useIt);
curGatePtr->DeleteIn(idx);
useIt.SetChanged();
}
void GateAccessor::DeleteGate(UsesIterator &useIt)
UseIterator GateAccessor::DeleteGate(const UseIterator &useIt)
{
auto next = useIt;
next++;
circuit_->DeleteGate(*useIt);
useIt.SetChanged();
return next;
}
void GateAccessor::DecreaseIn(UsesIterator &useIt)
void GateAccessor::DecreaseIn(const UseIterator &useIt)
{
size_t idx = useIt.GetIndex();
circuit_->DecreaseIn(*useIt, idx);
useIt.SetChanged();
}
void GateAccessor::NewIn(GateRef gate, size_t idx, GateRef in)

View File

@ -23,8 +23,8 @@ namespace panda::ecmascript::kungfu {
class GateAccessor {
public:
// do not create new gate or modify self during iteration
struct ConstUsesIterator {
explicit ConstUsesIterator(const Circuit* circuit, const Out* out) : circuit_(circuit), out_(out)
struct ConstUseIterator {
explicit ConstUseIterator(const Circuit* circuit, const Out* out) : circuit_(circuit), out_(out)
{
}
@ -33,7 +33,7 @@ public:
return circuit_->GetGateRef(out_->GetGateConst());
}
const ConstUsesIterator operator++()
const ConstUseIterator operator++()
{
if (!out_->IsNextOutNull()) {
out_ = out_->GetNextOutConst();
@ -42,9 +42,9 @@ public:
out_ = nullptr;
return *this;
}
const ConstUsesIterator operator++(int)
const ConstUseIterator operator++(int)
{
ConstUsesIterator tmp = *this;
ConstUseIterator tmp = *this;
++(*this);
return tmp;
}
@ -61,11 +61,11 @@ public:
return out_->GetGateConst()->GetOpCode();
}
friend bool operator== (const ConstUsesIterator& a, const ConstUsesIterator& b)
friend bool operator== (const ConstUseIterator& a, const ConstUseIterator& b)
{
return a.out_ == b.out_;
};
friend bool operator!= (const ConstUsesIterator& a, const ConstUsesIterator& b)
friend bool operator!= (const ConstUseIterator& a, const ConstUseIterator& b)
{
return a.out_ != b.out_;
};
@ -76,44 +76,26 @@ public:
};
// do not create new gate or modify self during iteration
struct UsesIterator {
explicit UsesIterator(Circuit* circuit, Out* out, GateRef gate) : circuit_(circuit), out_(out), gate_(gate)
struct UseIterator {
explicit UseIterator(Circuit* circuit, Out* out) : circuit_(circuit), out_(out)
{
}
void SetChanged()
{
changed_ = true;
}
GateRef operator*() const
{
return circuit_->GetGateRef(out_->GetGate());
}
const UsesIterator& operator++()
const UseIterator& operator++()
{
if (changed_) {
if (circuit_->LoadGatePtrConst(gate_)->IsFirstOutNull()) {
out_ = nullptr;
gate_ = 0;
} else {
out_ = circuit_->LoadGatePtr(gate_)->GetFirstOut();
}
changed_ = false;
return *this;
}
if (out_->IsNextOutNull()) {
out_ = nullptr;
return *this;
}
out_ = out_->GetNextOut();
out_ = out_->IsNextOutNull() ? nullptr
: out_->GetNextOut();
return *this;
}
UsesIterator operator++(int)
UseIterator operator++(int)
{
UsesIterator tmp = *this;
UseIterator tmp = *this;
++(*this);
return tmp;
}
@ -130,11 +112,11 @@ public:
return out_->GetGateConst()->GetOpCode();
}
friend bool operator== (const UsesIterator& a, const UsesIterator& b)
friend bool operator== (const UseIterator& a, const UseIterator& b)
{
return a.out_ == b.out_;
};
friend bool operator!= (const UsesIterator& a, const UsesIterator& b)
friend bool operator!= (const UseIterator& a, const UseIterator& b)
{
return a.out_ != b.out_;
};
@ -142,8 +124,6 @@ public:
private:
Circuit* circuit_;
Out* out_;
GateRef gate_;
bool changed_ {false};
};
struct ConstInsIterator {
@ -328,17 +308,16 @@ public:
GateRef GetState(GateRef gate, size_t idx = 0) const;
GateRef GetDep(GateRef gate, size_t idx = 0) const;
size_t GetImmediateId(GateRef gate) const;
bool IsDependIn(const UsesIterator &useIt) const;
bool IsDependIn(const UseIterator &useIt) const;
void SetDep(GateRef gate, GateRef depGate, size_t idx = 0);
void ReplaceIn(UsesIterator &useIt, GateRef replaceGate);
UseIterator ReplaceIn(const UseIterator &useIt, GateRef replaceGate);
// Add for lowering
GateType GetGateType(GateRef gate) const;
void SetGateType(GateRef gate, GateType gt);
void DeleteExceptionDep(UsesIterator &useIt);
void DeleteIn(UsesIterator &useIt);
UseIterator DeleteExceptionDep(const UseIterator &useIt);
void DeleteIn(GateRef gate, size_t idx);
void DeleteGate(UsesIterator &useIt);
void DecreaseIn(UsesIterator &useIt);
UseIterator DeleteGate(const UseIterator &useIt);
void DecreaseIn(const UseIterator &useIt);
void NewIn(GateRef gate, size_t idx, GateRef in);
size_t GetStateCount(GateRef gate) const;
size_t GetDependCount(GateRef gate) const;
@ -360,32 +339,32 @@ public:
void SetMark(GateRef gate, MarkCode mark);
private:
ConstUsesIterator ConstUseBegin(GateRef gate) const
ConstUseIterator ConstUseBegin(GateRef gate) const
{
if (circuit_->LoadGatePtrConst(gate)->IsFirstOutNull()) {
return ConstUsesIterator(circuit_, nullptr);
return ConstUseIterator(circuit_, nullptr);
}
auto use = circuit_->LoadGatePtrConst(gate)->GetFirstOutConst();
return ConstUsesIterator(circuit_, use);
return ConstUseIterator(circuit_, use);
}
ConstUsesIterator ConstUseEnd() const
ConstUseIterator ConstUseEnd() const
{
return ConstUsesIterator(circuit_, nullptr);
return ConstUseIterator(circuit_, nullptr);
}
UsesIterator UseBegin(GateRef gate) const
UseIterator UseBegin(GateRef gate) const
{
if (circuit_->LoadGatePtrConst(gate)->IsFirstOutNull()) {
return UsesIterator(circuit_, nullptr, 0);
return UseIterator(circuit_, nullptr);
}
auto use = circuit_->LoadGatePtr(gate)->GetFirstOut();
return UsesIterator(circuit_, use, gate);
return UseIterator(circuit_, use);
}
UsesIterator UseEnd() const
UseIterator UseEnd() const
{
return UsesIterator(circuit_, nullptr, 0);
return UseIterator(circuit_, nullptr);
}
ConstInsIterator ConstInBegin(GateRef gate) const

View File

@ -104,14 +104,14 @@ GateRef InterpreterStubBuilder::ReadInst4_3(GateRef pc)
GateRef InterpreterStubBuilder::ReadInstSigned8_0(GateRef pc)
{
GateRef x = Load(VariableType::INT8(), pc, IntPtr(1)); // 1 : skip 1 byte of bytecode
return GetEnvironment()->GetBulder()->UnaryArithmetic(OpCode(OpCode::SEXT_TO_INT32), x);
return GetEnvironment()->GetBuilder()->UnaryArithmetic(OpCode(OpCode::SEXT_TO_INT32), x);
}
GateRef InterpreterStubBuilder::ReadInstSigned16_0(GateRef pc)
{
/* 2 : skip 8 bits of opcode and 8 bits of low bits */
GateRef currentInst = Load(VariableType::INT8(), pc, IntPtr(2));
GateRef currentInst1 = GetEnvironment()->GetBulder()->UnaryArithmetic(
GateRef currentInst1 = GetEnvironment()->GetBuilder()->UnaryArithmetic(
OpCode(OpCode::SEXT_TO_INT32), currentInst);
GateRef currentInst2 = Int32LSL(currentInst1, Int32(8)); // 8 : set as high 8 bits
return Int32Add(currentInst2, ZExtInt8ToInt32(ReadInst8_0(pc)));
@ -121,7 +121,7 @@ GateRef InterpreterStubBuilder::ReadInstSigned32_0(GateRef pc)
{
/* 4 : skip 8 bits of opcode and 24 bits of low bits */
GateRef x = Load(VariableType::INT8(), pc, IntPtr(4));
GateRef currentInst = GetEnvironment()->GetBulder()->UnaryArithmetic(OpCode(OpCode::SEXT_TO_INT32), x);
GateRef currentInst = GetEnvironment()->GetBuilder()->UnaryArithmetic(OpCode(OpCode::SEXT_TO_INT32), x);
GateRef currentInst1 = Int32LSL(currentInst, Int32(8)); // 8 : set as high 8 bits
GateRef currentInst2 = Int32Add(currentInst1, ZExtInt8ToInt32(ReadInst8_2(pc)));
GateRef currentInst3 = Int32LSL(currentInst2, Int32(8)); // 8 : set as high 8 bits
@ -467,7 +467,7 @@ GateRef InterpreterStubBuilder::ReadInst64_0(GateRef pc)
template<typename... Args>
void InterpreterStubBuilder::DispatchBase(GateRef target, GateRef glue, Args... args)
{
GetEnvironment()->GetBulder()->CallBCHandler(glue, target, {glue, args...});
GetEnvironment()->GetBuilder()->CallBCHandler(glue, target, {glue, args...});
}
void InterpreterStubBuilder::Dispatch(GateRef glue, GateRef sp, GateRef pc, GateRef constpool, GateRef profileTypeInfo,
@ -494,7 +494,7 @@ void InterpreterStubBuilder::DispatchDebugger(GateRef glue, GateRef sp, GateRef
GateRef opcode = Load(VariableType::INT8(), pc);
GateRef target = PtrMul(ChangeInt32ToIntPtr(ZExtInt8ToInt32(opcode)), IntPtrSize());
auto args = { glue, sp, pc, constpool, profileTypeInfo, acc, hotnessCounter };
GetEnvironment()->GetBulder()->CallBCDebugger(glue, target, args);
GetEnvironment()->GetBuilder()->CallBCDebugger(glue, target, args);
Return();
}
@ -503,7 +503,7 @@ void InterpreterStubBuilder::DispatchDebuggerLast(GateRef glue, GateRef sp, Gate
{
GateRef target = PtrMul(IntPtr(BytecodeStubCSigns::ID_ExceptionHandler), IntPtrSize());
auto args = { glue, sp, pc, constpool, profileTypeInfo, acc, hotnessCounter };
GetEnvironment()->GetBulder()->CallBCDebugger(glue, target, args);
GetEnvironment()->GetBuilder()->CallBCDebugger(glue, target, args);
Return();
}
@ -528,13 +528,13 @@ GateRef InterpreterStubBuilder::GetHotnessCounterFromMethod(GateRef method)
auto env = GetEnvironment();
GateRef x = Load(VariableType::INT16(), method,
IntPtr(JSMethod::GetHotnessCounterOffset(env->IsArch32Bit())));
return GetEnvironment()->GetBulder()->UnaryArithmetic(OpCode(OpCode::SEXT_TO_INT32), x);
return GetEnvironment()->GetBuilder()->UnaryArithmetic(OpCode(OpCode::SEXT_TO_INT32), x);
}
void InterpreterStubBuilder::SetHotnessCounter(GateRef glue, GateRef method, GateRef value)
{
auto env = GetEnvironment();
GateRef newValue = env->GetBulder()->UnaryArithmetic(OpCode(OpCode::TRUNC_TO_INT16), value);
GateRef newValue = env->GetBuilder()->UnaryArithmetic(OpCode(OpCode::TRUNC_TO_INT16), value);
Store(VariableType::INT16(), glue, method,
IntPtr(JSMethod::GetHotnessCounterOffset(env->IsArch32Bit())), newValue);
}

View File

@ -34,9 +34,8 @@
namespace panda::ecmascript::kungfu {
#if ECMASCRIPT_ENABLE_ASM_INTERPRETER_LOG
#define DECLARE_ASM_HANDLER(name) \
void name##StubBuilder::GenerateCircuit(const CompilationConfig *cfg) \
void name##StubBuilder::GenerateCircuit() \
{ \
StubBuilder::GenerateCircuit(cfg); \
GateRef glue = PtrArgument(static_cast<size_t>(InterpreterHandlerInputs::GLUE)); \
GateRef sp = PtrArgument(static_cast<size_t>(InterpreterHandlerInputs::SP)); \
GateRef pc = PtrArgument(static_cast<size_t>(InterpreterHandlerInputs::PC)); \
@ -55,9 +54,8 @@ void name##StubBuilder::GenerateCircuitImpl(GateRef glue, GateRef sp, GateRef pc
GateRef acc, GateRef hotnessCounter)
#else
#define DECLARE_ASM_HANDLER(name) \
void name##StubBuilder::GenerateCircuit(const CompilationConfig *cfg) \
void name##StubBuilder::GenerateCircuit() \
{ \
StubBuilder::GenerateCircuit(cfg); \
GateRef glue = PtrArgument(static_cast<size_t>(InterpreterHandlerInputs::GLUE)); \
GateRef sp = PtrArgument(static_cast<size_t>(InterpreterHandlerInputs::SP)); \
GateRef pc = PtrArgument(static_cast<size_t>(InterpreterHandlerInputs::PC)); \
@ -3640,46 +3638,30 @@ DECLARE_ASM_HANDLER(HandleDefineClassWithBufferPrefId16Imm16Imm16V8V8)
DEFVARIABLE(varAcc, VariableType::JS_ANY(), acc);
GateRef methodId = ReadInst16_1(pc);
GateRef literalId = ReadInst16_3(pc);
GateRef length = ReadInst16_5(pc);
GateRef v0 = ReadInst8_7(pc);
GateRef v1 = ReadInst8_8(pc);
GateRef classTemplate = GetObjectFromConstPool(constpool, ZExtInt16ToInt32(methodId));
GateRef literalBuffer = GetObjectFromConstPool(constpool, ZExtInt16ToInt32(literalId));
GateRef lexicalEnv = GetVregValue(sp, ZExtInt8ToPtr(v0));
GateRef proto = GetVregValue(sp, ZExtInt8ToPtr(v1));
DEFVARIABLE(res, VariableType::JS_ANY(), Undefined());
GateRef res = CallRuntime(glue, RTSTUB_ID(CloneClassFromTemplate), { classTemplate, proto, lexicalEnv, constpool });
Label isResolved(env);
Label isNotResolved(env);
Label afterCheckResolved(env);
Branch(FunctionIsResolved(classTemplate), &isResolved, &isNotResolved);
Bind(&isResolved);
{
res = CallRuntime(glue, RTSTUB_ID(CloneClassFromTemplate), { classTemplate, proto, lexicalEnv, constpool });
Jump(&afterCheckResolved);
}
Bind(&isNotResolved);
{
res = CallRuntime(glue, RTSTUB_ID(ResolveClass),
{ classTemplate, literalBuffer, proto, lexicalEnv, constpool });
Jump(&afterCheckResolved);
}
Bind(&afterCheckResolved);
Label isException(env);
Label isNotException(env);
Branch(TaggedIsException(*res), &isException, &isNotException);
Branch(TaggedIsException(res), &isException, &isNotException);
Bind(&isException);
{
DISPATCH_LAST_WITH_ACC();
}
Bind(&isNotException);
GateRef newLexicalEnv = GetVregValue(sp, ZExtInt8ToPtr(v0)); // slow runtime may gc
SetLexicalEnvToFunction(glue, *res, newLexicalEnv);
CallRuntime(glue, RTSTUB_ID(SetClassConstructorLength), { *res, Int16ToTaggedTypeNGC(length) });
varAcc = *res;
SetLexicalEnvToFunction(glue, res, newLexicalEnv);
GateRef currentFunc = GetFunctionFromFrame(GetFrame(sp));
SetModuleToFunction(glue, res, GetModuleFromFunction(currentFunc));
CallRuntime(glue, RTSTUB_ID(SetClassConstructorLength), { res, Int16ToTaggedTypeNGC(length) });
varAcc = res;
DISPATCH_WITH_ACC(PREF_ID16_IMM16_IMM16_V8_V8);
}

View File

@ -24,12 +24,12 @@
namespace panda::ecmascript::kungfu {
class InterpreterStubBuilder : public StubBuilder {
public:
InterpreterStubBuilder(CallSignature *callSignature, Circuit *circuit)
: StubBuilder(callSignature, circuit) {}
InterpreterStubBuilder(CallSignature *callSignature, Environment *env)
: StubBuilder(callSignature, env) {}
~InterpreterStubBuilder() = default;
NO_MOVE_SEMANTIC(InterpreterStubBuilder);
NO_COPY_SEMANTIC(InterpreterStubBuilder);
virtual void GenerateCircuit(const CompilationConfig *cfg) = 0;
virtual void GenerateCircuit() = 0;
inline void SetVregValue(GateRef glue, GateRef sp, GateRef idx, GateRef val);
inline GateRef GetVregValue(GateRef sp, GateRef idx);
@ -116,15 +116,15 @@ private:
#define DECLARE_HANDLE_STUB_CLASS(name) \
class name##StubBuilder : public InterpreterStubBuilder { \
public: \
explicit name##StubBuilder(CallSignature *callSignature, Circuit *circuit) \
: InterpreterStubBuilder(callSignature, circuit) \
explicit name##StubBuilder(CallSignature *callSignature, Environment *env) \
: InterpreterStubBuilder(callSignature, env) \
{ \
circuit->SetFrameType(FrameType::INTERPRETER_FRAME); \
env->GetCircuit()->SetFrameType(FrameType::INTERPRETER_FRAME); \
} \
~name##StubBuilder() = default; \
NO_MOVE_SEMANTIC(name##StubBuilder); \
NO_COPY_SEMANTIC(name##StubBuilder); \
void GenerateCircuit(const CompilationConfig *cfg) override; \
void GenerateCircuit() override; \
\
private: \
void GenerateCircuitImpl(GateRef glue, GateRef sp, GateRef pc, GateRef constpool, \

View File

@ -16,6 +16,8 @@
#include "ecmascript/compiler/slowpath_lowering.h"
namespace panda::ecmascript::kungfu {
using UseIterator = GateAccessor::UseIterator;
#define CREATE_DOUBLE_EXIT(SuccessLabel, FailLabel) \
std::vector<GateRef> successControl; \
std::vector<GateRef> failControl; \
@ -57,14 +59,15 @@ int32_t SlowPathLowering::ComputeCallArgc(GateRef gate, EcmaOpcode op)
return acc_.GetNumValueIn(gate) + NUM_MANDATORY_JSFUNC_ARGS - 2; // 2: calltarget and bcoffset
}
void SlowPathLowering::ReplaceHirControlGate(GateAccessor::UsesIterator &useIt, GateRef newGate, bool noThrow)
UseIterator SlowPathLowering::ReplaceHirControlGate(const UseIterator &useIt, GateRef newGate, bool noThrow)
{
ASSERT(acc_.GetOpCode(*useIt) == OpCode::IF_SUCCESS || acc_.GetOpCode(*useIt) == OpCode::IF_EXCEPTION);
if (!noThrow) {
auto firstUse = acc_.Uses(*useIt).begin();
acc_.ReplaceIn(*firstUse, firstUse.GetIndex(), newGate);
}
acc_.DeleteGate(useIt);
auto next = acc_.DeleteGate(useIt);
return next;
}
// depends on the construction of JSgates in BytecodeCircuitBuilder
@ -80,40 +83,43 @@ void SlowPathLowering::ReplaceHirToSubCfg(GateRef hir, GateRef outir,
}
}
auto uses = acc_.Uses(hir);
for (auto useIt = uses.begin(); useIt != uses.end(); useIt++) {
for (auto useIt = uses.begin(); useIt != uses.end();) {
const OpCode op = acc_.GetOpCode(*useIt);
// replace HIR:IF_SUCCESS/IF_EXCEPTION with control flow in Label successExit/failExit of MIR Circuit
if (acc_.GetOpCode(*useIt) == OpCode::IF_SUCCESS) {
ReplaceHirControlGate(useIt, successControl[0]);
} else if (acc_.GetOpCode(*useIt) == OpCode::IF_EXCEPTION) {
ReplaceHirControlGate(useIt, exceptionControl[0], noThrow);
if (op == OpCode::IF_SUCCESS) {
useIt = ReplaceHirControlGate(useIt, successControl[0]);
} else if (op == OpCode::IF_EXCEPTION) {
useIt = ReplaceHirControlGate(useIt, exceptionControl[0], noThrow);
// change depend flow in catch block from HIR:JS_BYTECODE to depend flow in MIR Circuit
} else if (acc_.GetOpCode(*useIt) == OpCode::DEPEND_SELECTOR) {
} else if (op == OpCode::DEPEND_SELECTOR) {
if (acc_.GetOpCode(acc_.GetIn(acc_.GetIn(*useIt, 0), useIt.GetIndex() - 1)) == OpCode::IF_EXCEPTION) {
noThrow ? acc_.DeleteExceptionDep(useIt) : acc_.ReplaceIn(useIt, exceptionControl[1]);
useIt = noThrow ? acc_.DeleteExceptionDep(useIt)
: acc_.ReplaceIn(useIt, exceptionControl[1]);
} else {
acc_.ReplaceIn(useIt, successControl[1]);
useIt = acc_.ReplaceIn(useIt, successControl[1]);
}
} else if (acc_.GetOpCode(*useIt) == OpCode::DEPEND_RELAY) {
} else if (op == OpCode::DEPEND_RELAY) {
if (acc_.GetOpCode(acc_.GetIn(*useIt, 0)) == OpCode::IF_EXCEPTION) {
acc_.ReplaceIn(useIt, exceptionControl[1]);
useIt = acc_.ReplaceIn(useIt, exceptionControl[1]);
} else {
acc_.ReplaceIn(useIt, successControl[1]);
useIt = acc_.ReplaceIn(useIt, successControl[1]);
}
// replace normal depend
} else if ((acc_.GetOpCode(*useIt) == OpCode::JS_BYTECODE) && useIt.GetIndex() == 1) {
acc_.ReplaceIn(useIt, successControl[1]);
} else if ((acc_.GetOpCode(*useIt) == OpCode::RUNTIME_CALL) && useIt.GetIndex() == 0) {
acc_.ReplaceIn(useIt, successControl[1]);
} else if (op == OpCode::JS_BYTECODE && useIt.GetIndex() == 1) {
useIt = acc_.ReplaceIn(useIt, successControl[1]);
} else if (op == OpCode::RUNTIME_CALL && useIt.GetIndex() == 0) {
useIt = acc_.ReplaceIn(useIt, successControl[1]);
// if no catch block, just throw exception(RETURN)
} else if ((acc_.GetOpCode(*useIt) == OpCode::RETURN) &&
acc_.GetOpCode(acc_.GetIn(*useIt, 0)) == OpCode::IF_EXCEPTION) {
noThrow ? acc_.DeleteExceptionDep(useIt) : acc_.ReplaceIn(useIt, exceptionControl[1]);
} else if (op == OpCode::RETURN &&
acc_.GetOpCode(acc_.GetIn(*useIt, 0)) == OpCode::IF_EXCEPTION) {
useIt = noThrow ? acc_.DeleteExceptionDep(useIt)
: acc_.ReplaceIn(useIt, exceptionControl[1]);
// if hir isThrow
} else if (acc_.GetOpCode(*useIt) != OpCode::VALUE_SELECTOR && useIt.GetIndex() == 1) {
acc_.ReplaceIn(useIt, successControl[1]);
} else if (op != OpCode::VALUE_SELECTOR && useIt.GetIndex() == 1) {
useIt = acc_.ReplaceIn(useIt, successControl[1]);
// replace data flow with data output in label successExit(incluing JSgates and phigates)
} else {
acc_.ReplaceIn(useIt, outir);
useIt = acc_.ReplaceIn(useIt, outir);
}
}
acc_.DeleteGate(hir);
@ -133,16 +139,16 @@ void SlowPathLowering::ReplaceHirToJSCall(GateRef hirGate, GateRef callGate, Gat
GateRef ifBranch = builder_.Branch(stateInGate, equal);
auto uses = acc_.Uses(hirGate);
for (auto it = uses.begin(); it != uses.end(); it++) {
for (auto it = uses.begin(); it != uses.end();) {
if (acc_.GetOpCode(*it) == OpCode::IF_SUCCESS) {
acc_.SetOpCode(*it, OpCode::IF_FALSE);
acc_.ReplaceIn(it, ifBranch);
it = acc_.ReplaceIn(it, ifBranch);
} else {
if (acc_.GetOpCode(*it) == OpCode::IF_EXCEPTION) {
acc_.SetOpCode(*it, OpCode::IF_TRUE);
acc_.ReplaceIn(it, ifBranch);
it = acc_.ReplaceIn(it, ifBranch);
} else {
acc_.ReplaceIn(it, callGate);
it = acc_.ReplaceIn(it, callGate);
}
}
}
@ -183,16 +189,16 @@ void SlowPathLowering::ReplaceHirToCall(GateRef hirGate, GateRef callGate, bool
}
auto uses = acc_.Uses(hirGate);
for (auto it = uses.begin(); it != uses.end(); it++) {
for (auto it = uses.begin(); it != uses.end();) {
if (acc_.GetOpCode(*it) == OpCode::IF_SUCCESS) {
acc_.SetOpCode(*it, OpCode::IF_FALSE);
acc_.ReplaceIn(it, ifBranch);
it = acc_.ReplaceIn(it, ifBranch);
} else {
if (acc_.GetOpCode(*it) == OpCode::IF_EXCEPTION) {
acc_.SetOpCode(*it, OpCode::IF_TRUE);
acc_.ReplaceIn(it, ifBranch);
it = acc_.ReplaceIn(it, ifBranch);
} else {
acc_.ReplaceIn(it, callGate);
it = acc_.ReplaceIn(it, callGate);
}
}
}
@ -215,16 +221,16 @@ void SlowPathLowering::ReplaceHirToThrowCall(GateRef hirGate, GateRef callGate)
GateRef ifBranch = builder_.Branch(stateInGate, builder_.Boolean(true));
auto uses = acc_.Uses(hirGate);
for (auto it = uses.begin(); it != uses.end(); it++) {
for (auto it = uses.begin(); it != uses.end();) {
if (acc_.GetOpCode(*it) == OpCode::IF_SUCCESS) {
acc_.SetOpCode(*it, OpCode::IF_FALSE);
acc_.ReplaceIn(it, ifBranch);
it = acc_.ReplaceIn(it, ifBranch);
} else {
if (acc_.GetOpCode(*it) == OpCode::IF_EXCEPTION) {
acc_.SetOpCode(*it, OpCode::IF_TRUE);
acc_.ReplaceIn(it, ifBranch);
it = acc_.ReplaceIn(it, ifBranch);
} else {
acc_.ReplaceIn(it, callGate);
it = acc_.ReplaceIn(it, callGate);
}
}
}
@ -1143,11 +1149,11 @@ void SlowPathLowering::LowerExceptionHandler(GateRef hirGate)
GateRef clearException = circuit_->NewGate(OpCode(OpCode::STORE), 0,
{ loadException, holeCst, val }, VariableType::INT64().GetGateType());
auto uses = acc_.Uses(hirGate);
for (auto it = uses.begin(); it != uses.end(); it++) {
for (auto it = uses.begin(); it != uses.end();) {
if (acc_.GetOpCode(*it) != OpCode::VALUE_SELECTOR && acc_.IsDependIn(it)) {
acc_.ReplaceIn(it, clearException);
it = acc_.ReplaceIn(it, clearException);
} else {
acc_.ReplaceIn(it, loadException);
it = acc_.ReplaceIn(it, loadException);
}
}
acc_.DeleteGate(hirGate);
@ -1711,17 +1717,17 @@ void SlowPathLowering::LowerConditionJump(GateRef gate, bool isEqualJump)
GateRef mergeTrueState = builder_.Merge(trueState.data(), trueState.size());
auto uses = acc_.Uses(gate);
for (auto it = uses.begin(); it != uses.end(); it++) {
for (auto it = uses.begin(); it != uses.end();) {
if (acc_.GetOpCode(*it) == OpCode::IF_TRUE) {
acc_.SetOpCode(*it, OpCode::ORDINARY_BLOCK);
acc_.ReplaceIn(it, mergeTrueState);
it = acc_.ReplaceIn(it, mergeTrueState);
} else if (acc_.GetOpCode(*it) == OpCode::IF_FALSE) {
acc_.SetOpCode(*it, OpCode::ORDINARY_BLOCK);
acc_.ReplaceIn(it, mergeFalseState);
it = 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));
it = acc_.ReplaceIn(it, acc_.GetDep(gate));
} else {
UNREACHABLE();
}
@ -2993,11 +2999,13 @@ void SlowPathLowering::LowerResumeGenerator(GateRef gate)
auto indexOffset = builder_.Int32(index);
GateRef value = GetValueFromTaggedArray(arrayGate, indexOffset);
auto uses = acc_.Uses(item);
for (auto use = uses.begin(); use != uses.end(); use++) {
for (auto use = uses.begin(); use != uses.end();) {
size_t valueStartIndex = acc_.GetStateCount(*use) + acc_.GetDependCount(*use);
size_t valueEndIndex = valueStartIndex + acc_.GetInValueCount(*use);
if (use.GetIndex() >= valueStartIndex && use.GetIndex() < valueEndIndex) {
acc_.ReplaceIn(use, value);
use = acc_.ReplaceIn(use, value);
} else {
use++;
}
}
acc_.DeleteGate(item);

View File

@ -125,7 +125,8 @@ public:
}
private:
void ReplaceHirControlGate(GateAccessor::UsesIterator &useIt, GateRef newGate, bool noThrow = false);
GateAccessor::UseIterator ReplaceHirControlGate(const GateAccessor::UseIterator &useIt, GateRef newGate,
bool noThrow = false);
void ReplaceHirToSubCfg(GateRef hir, GateRef outir,
const std::vector<GateRef> &successControl,
const std::vector<GateRef> &exceptionControl,

View File

@ -0,0 +1,48 @@
/*
* Copyright (c) 2021 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/stub.h"
#include "ecmascript/compiler/stub_builder.h"
#include "ecmascript/compiler/call_signature.h"
namespace panda::ecmascript::kungfu {
Stub::Stub(const CallSignature *callSignature, Circuit *circuit)
: callSignature_(callSignature), builder_(circuit),
acc_(circuit), env_(callSignature->GetParametersCount(), &builder_)
{
}
void Stub::InitializeArguments()
{
auto argLength = callSignature_->GetParametersCount();
auto paramsType = callSignature_->GetParametersType();
for (size_t i = 0; i < argLength; i++) {
GateRef argument = env_.GetArgument(i);
if (paramsType[i] == VariableType::NATIVE_POINTER()) {
auto type = env_.IsArch64Bit() ? MachineType::I64 : MachineType::I32;
acc_.SetMachineType(argument, type);
} else {
acc_.SetMachineType(argument, paramsType[i].GetMachineType());
}
acc_.SetGateType(argument, paramsType[i].GetGateType());
}
}
void Stub::GenerateCircuit(const CompilationConfig *cfg)
{
env_.SetCompilationConfig(cfg);
InitializeArguments();
stubBuilder_->GenerateCircuit();
}
} // namespace panda::ecmascript::kungfu

View File

@ -0,0 +1,57 @@
/*
* Copyright (c) 2022 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.
*/
#ifndef ECMASCRIPT_COMPILER_STUB_H
#define ECMASCRIPT_COMPILER_STUB_H
#include "ecmascript/compiler/circuit_builder-inl.h"
#include "ecmascript/compiler/variable_type.h"
#include "ecmascript/compiler/call_signature.h"
namespace panda::ecmascript::kungfu {
class StubBuilder;
class Stub {
public:
explicit Stub(const CallSignature *callSignature, Circuit *circuit);
NO_MOVE_SEMANTIC(Stub);
NO_COPY_SEMANTIC(Stub);
Environment *GetEnvironment()
{
return &env_;
}
const CallSignature *GetCallSignature() const
{
return callSignature_;
}
void SetStubBuilder(StubBuilder *stubBuilder)
{
stubBuilder_ = stubBuilder;
}
const std::string &GetMethodName() const
{
return callSignature_->GetName();
}
void GenerateCircuit(const CompilationConfig *cfg);
private:
void InitializeArguments();
const CallSignature *callSignature_;
CircuitBuilder builder_;
GateAccessor acc_;
Environment env_;
StubBuilder *stubBuilder_ {nullptr};
};
} // namespace panda::ecmascript::kungfu
#endif // ECMASCRIPT_COMPILER_STUB_H

View File

@ -1,6 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 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
@ -23,6 +22,7 @@
#include "ecmascript/base/number_helper.h"
#include "ecmascript/compiler/bc_call_signature.h"
#include "ecmascript/global_dictionary.h"
#include "ecmascript/global_env_constants.h"
#include "ecmascript/ic/ic_handler.h"
#include "ecmascript/ic/proto_change_details.h"
#include "ecmascript/js_array.h"
@ -41,32 +41,32 @@ using PropertyBox = panda::ecmascript::PropertyBox;
inline GateRef StubBuilder::Int8(int8_t value)
{
return env_.GetBulder()->Int8(value);
return env_->GetBuilder()->Int8(value);
}
inline GateRef StubBuilder::Int16(int16_t value)
{
return env_.GetBulder()->Int16(value);
return env_->GetBuilder()->Int16(value);
}
inline GateRef StubBuilder::Int32(int32_t value)
{
return env_.GetBulder()->Int32(value);
return env_->GetBuilder()->Int32(value);
};
inline GateRef StubBuilder::Int64(int64_t value)
{
return env_.GetBulder()->Int64(value);
return env_->GetBuilder()->Int64(value);
}
inline GateRef StubBuilder::IntPtr(int64_t value)
{
return env_.Is32Bit() ? Int32(value) : Int64(value);
return env_->Is32Bit() ? Int32(value) : Int64(value);
};
inline GateRef StubBuilder::IntPtrSize()
{
return env_.Is32Bit() ? Int32(sizeof(uint32_t)) : Int64(sizeof(uint64_t));
return env_->Is32Bit() ? Int32(sizeof(uint32_t)) : Int64(sizeof(uint64_t));
}
inline GateRef StubBuilder::True()
@ -81,37 +81,37 @@ inline GateRef StubBuilder::False()
inline GateRef StubBuilder::Boolean(bool value)
{
return env_.GetBulder()->Boolean(value);
return env_->GetBuilder()->Boolean(value);
}
inline GateRef StubBuilder::Double(double value)
{
return env_.GetBulder()->Double(value);
return env_->GetBuilder()->Double(value);
}
inline GateRef StubBuilder::Undefined(VariableType type)
{
return env_.GetBulder()->UndefineConstant(type.GetGateType());
return env_->GetBuilder()->UndefineConstant(type.GetGateType());
}
inline GateRef StubBuilder::Hole(VariableType type)
{
return env_.GetBulder()->HoleConstant(type.GetGateType());
return env_->GetBuilder()->HoleConstant(type.GetGateType());
}
inline GateRef StubBuilder::Null(VariableType type)
{
return env_.GetBulder()->NullConstant(type.GetGateType());
return env_->GetBuilder()->NullConstant(type.GetGateType());
}
inline GateRef StubBuilder::Exception(VariableType type)
{
return env_.GetBulder()->ExceptionConstant(type.GetGateType());
return env_->GetBuilder()->ExceptionConstant(type.GetGateType());
}
inline GateRef StubBuilder::PtrMul(GateRef x, GateRef y)
{
if (env_.Is32Bit()) {
if (env_->Is32Bit()) {
return Int32Mul(x, y);
} else {
return Int64Mul(x, y);
@ -120,13 +120,13 @@ inline GateRef StubBuilder::PtrMul(GateRef x, GateRef y)
inline GateRef StubBuilder::RelocatableData(uint64_t value)
{
return env_.GetBulder()->RelocatableData(value);
return env_->GetBuilder()->RelocatableData(value);
}
// parameter
inline GateRef StubBuilder::Argument(size_t index)
{
return env_.GetArgument(index);
return env_->GetArgument(index);
}
inline GateRef StubBuilder::Int1Argument(size_t index)
@ -171,58 +171,58 @@ inline GateRef StubBuilder::Float64Argument(size_t index)
inline GateRef StubBuilder::Alloca(int size)
{
return env_.GetBulder()->Alloca(size);
return env_->GetBuilder()->Alloca(size);
}
inline GateRef StubBuilder::Return(GateRef value)
{
auto control = env_.GetCurrentLabel()->GetControl();
auto depend = env_.GetCurrentLabel()->GetDepend();
return env_.GetBulder()->Return(control, depend, value);
auto control = env_->GetCurrentLabel()->GetControl();
auto depend = env_->GetCurrentLabel()->GetDepend();
return env_->GetBuilder()->Return(control, depend, value);
}
inline GateRef StubBuilder::Return()
{
auto control = env_.GetCurrentLabel()->GetControl();
auto depend = env_.GetCurrentLabel()->GetDepend();
return env_.GetBulder()->ReturnVoid(control, depend);
auto control = env_->GetCurrentLabel()->GetControl();
auto depend = env_->GetCurrentLabel()->GetDepend();
return env_->GetBuilder()->ReturnVoid(control, depend);
}
inline void StubBuilder::Bind(Label *label)
{
label->Bind();
env_.SetCurrentLabel(label);
env_->SetCurrentLabel(label);
}
inline GateRef StubBuilder::CallRuntime(GateRef glue, int index, const std::initializer_list<GateRef>& args)
{
SavePcIfNeeded(glue);
GateRef result = env_.GetBulder()->CallRuntime(glue, index, Gate::InvalidGateRef, args);
GateRef result = env_->GetBuilder()->CallRuntime(glue, index, Gate::InvalidGateRef, args);
return result;
}
inline GateRef StubBuilder::CallRuntime(GateRef glue, int index, GateRef argc, GateRef argv)
{
SavePcIfNeeded(glue);
GateRef result = env_.GetBulder()->CallRuntimeVarargs(glue, index, argc, argv);
GateRef result = env_->GetBuilder()->CallRuntimeVarargs(glue, index, argc, argv);
return result;
}
inline GateRef StubBuilder::CallNGCRuntime(GateRef glue, int index, const std::initializer_list<GateRef>& args)
{
GateRef result = env_.GetBulder()->CallNGCRuntime(glue, index, Gate::InvalidGateRef, args);
GateRef result = env_->GetBuilder()->CallNGCRuntime(glue, index, Gate::InvalidGateRef, args);
return result;
}
inline GateRef StubBuilder::UpdateLeaveFrameAndCallNGCRuntime(GateRef glue, int index,
const std::initializer_list<GateRef>& args)
{
if (env_.IsAsmInterp()) {
if (env_->IsAsmInterp()) {
// CpuProfiler will get the latest leaveFrame_ in thread to up frames.
// So it's necessary to update leaveFrame_ if the program enters the c++ environment.
// We use the latest asm interpreter frame to update it when CallNGCRuntime.
GateRef sp = Argument(static_cast<size_t>(InterpreterHandlerInputs::SP));
GateRef spOffset = IntPtr(JSThread::GlueData::GetLeaveFrameOffset(env_.Is32Bit()));
GateRef spOffset = IntPtr(JSThread::GlueData::GetLeaveFrameOffset(env_->Is32Bit()));
Store(VariableType::NATIVE_POINTER(), glue, glue, spOffset, sp);
}
GateRef result = CallNGCRuntime(glue, index, args);
@ -232,7 +232,7 @@ inline GateRef StubBuilder::UpdateLeaveFrameAndCallNGCRuntime(GateRef glue, int
inline GateRef StubBuilder::CallStub(GateRef glue, int index, const std::initializer_list<GateRef>& args)
{
SavePcIfNeeded(glue);
GateRef result = GetBuilder()->CallStub(glue, index, args);
GateRef result = env_->GetBuilder()->CallStub(glue, index, args);
return result;
}
@ -248,7 +248,7 @@ inline void StubBuilder::FatalPrint(GateRef glue, std::initializer_list<GateRef>
void StubBuilder::SavePcIfNeeded(GateRef glue)
{
if (env_.IsAsmInterp()) {
if (env_->IsAsmInterp()) {
GateRef sp = Argument(static_cast<size_t>(InterpreterHandlerInputs::SP));
GateRef pc = Argument(static_cast<size_t>(InterpreterHandlerInputs::PC));
GateRef frame = PtrSub(sp,
@ -262,9 +262,9 @@ void StubBuilder::SavePcIfNeeded(GateRef glue)
inline GateRef StubBuilder::Load(VariableType type, GateRef base, GateRef offset)
{
if (type == VariableType::NATIVE_POINTER()) {
type = env_.IsArch64Bit() ? VariableType::INT64() : VariableType::INT32();
type = env_->IsArch64Bit() ? VariableType::INT64() : VariableType::INT32();
}
return builder_.Load(type, base, offset);
return env_->GetBuilder()->Load(type, base, offset);
}
inline GateRef StubBuilder::Load(VariableType type, GateRef base)
@ -275,27 +275,27 @@ inline GateRef StubBuilder::Load(VariableType type, GateRef base)
// arithmetic
inline GateRef StubBuilder::Int16Add(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryArithmetic(OpCode(OpCode::ADD), MachineType::I16, x, y);
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::ADD), MachineType::I16, x, y);
}
inline GateRef StubBuilder::Int32Add(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryArithmetic(OpCode(OpCode::ADD), MachineType::I32, x, y);
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::ADD), MachineType::I32, x, y);
}
inline GateRef StubBuilder::Int64Add(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryArithmetic(OpCode(OpCode::ADD), MachineType::I64, x, y);
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::ADD), MachineType::I64, x, y);
}
inline GateRef StubBuilder::DoubleAdd(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryArithmetic(OpCode(OpCode::ADD), MachineType::F64, x, y);
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::ADD), MachineType::F64, x, y);
}
inline GateRef StubBuilder::PtrAdd(GateRef x, GateRef y)
{
if (env_.Is32Bit()) {
if (env_->Is32Bit()) {
return Int32Add(x, y);
}
return Int64Add(x, y);
@ -303,12 +303,12 @@ inline GateRef StubBuilder::PtrAdd(GateRef x, GateRef y)
inline GateRef StubBuilder::IntPtrAnd(GateRef x, GateRef y)
{
return env_.Is32Bit() ? Int32And(x, y) : Int64And(x, y);
return env_->Is32Bit() ? Int32And(x, y) : Int64And(x, y);
}
inline GateRef StubBuilder::IntPtrEqual(GateRef x, GateRef y)
{
if (env_.Is32Bit()) {
if (env_->Is32Bit()) {
return Int32Equal(x, y);
}
return Int64Equal(x, y);
@ -316,7 +316,7 @@ inline GateRef StubBuilder::IntPtrEqual(GateRef x, GateRef y)
inline GateRef StubBuilder::PtrSub(GateRef x, GateRef y)
{
if (env_.Is32Bit()) {
if (env_->Is32Bit()) {
return Int32Sub(x, y);
}
return Int64Sub(x, y);
@ -324,192 +324,192 @@ inline GateRef StubBuilder::PtrSub(GateRef x, GateRef y)
inline GateRef StubBuilder::PointerSub(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryArithmetic(OpCode(OpCode::SUB), MachineType::ARCH, x, y);
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::SUB), MachineType::ARCH, x, y);
}
inline GateRef StubBuilder::Int16Sub(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryArithmetic(OpCode(OpCode::SUB), MachineType::I16, x, y);
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::SUB), MachineType::I16, x, y);
}
inline GateRef StubBuilder::Int32Sub(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryArithmetic(OpCode(OpCode::SUB), MachineType::I32, x, y);
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::SUB), MachineType::I32, x, y);
}
inline GateRef StubBuilder::Int64Sub(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryArithmetic(OpCode(OpCode::SUB), MachineType::I64, x, y);
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::SUB), MachineType::I64, x, y);
}
inline GateRef StubBuilder::DoubleSub(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryArithmetic(OpCode(OpCode::SUB), MachineType::F64, x, y);
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::SUB), MachineType::F64, x, y);
}
inline GateRef StubBuilder::Int32Mul(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryArithmetic(OpCode(OpCode::MUL), MachineType::I32, x, y);
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::MUL), MachineType::I32, x, y);
}
inline GateRef StubBuilder::Int64Mul(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryArithmetic(OpCode(OpCode::MUL), MachineType::I64, x, y);
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::MUL), MachineType::I64, x, y);
}
inline GateRef StubBuilder::DoubleMul(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryArithmetic(OpCode(OpCode::MUL), MachineType::F64, x, y);
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::MUL), MachineType::F64, x, y);
}
inline GateRef StubBuilder::DoubleDiv(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryArithmetic(OpCode(OpCode::FDIV), MachineType::F64, x, y);
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::FDIV), MachineType::F64, x, y);
}
inline GateRef StubBuilder::Int32Div(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryArithmetic(OpCode(OpCode::SDIV), MachineType::I32, x, y);
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::SDIV), MachineType::I32, x, y);
}
inline GateRef StubBuilder::Int64Div(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryArithmetic(OpCode(OpCode::SDIV), MachineType::I64, x, y);
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::SDIV), MachineType::I64, x, y);
}
inline GateRef StubBuilder::IntPtrDiv(GateRef x, GateRef y)
{
return env_.Is32Bit() ? Int32Div(x, y) : Int64Div(x, y);
return env_->Is32Bit() ? Int32Div(x, y) : Int64Div(x, y);
}
inline GateRef StubBuilder::Int32Mod(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryArithmetic(OpCode(OpCode::SMOD), MachineType::I32, x, y);
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::SMOD), MachineType::I32, x, y);
}
inline GateRef StubBuilder::DoubleMod(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryArithmetic(OpCode(OpCode::SMOD), MachineType::F64, x, y);
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::SMOD), MachineType::F64, x, y);
}
// bit operation
inline GateRef StubBuilder::Int32Or(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryArithmetic(OpCode(OpCode::OR), MachineType::I32, x, y);
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::OR), MachineType::I32, x, y);
}
inline GateRef StubBuilder::Int8And(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryArithmetic(OpCode(OpCode::AND), MachineType::I8, x, y);
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::AND), MachineType::I8, x, y);
}
inline GateRef StubBuilder::Int32And(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryArithmetic(OpCode(OpCode::AND), MachineType::I32, x, y);
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::AND), MachineType::I32, x, y);
}
inline GateRef StubBuilder::BoolAnd(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryArithmetic(OpCode(OpCode::AND), MachineType::I1, x, y);
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::AND), MachineType::I1, x, y);
}
inline GateRef StubBuilder::BoolOr(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryArithmetic(OpCode(OpCode::OR), MachineType::I1, x, y);
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::OR), MachineType::I1, x, y);
}
inline GateRef StubBuilder::Int32Not(GateRef x)
{
return env_.GetBulder()->UnaryArithmetic(OpCode(OpCode::REV), MachineType::I32, x);
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::REV), MachineType::I32, x);
}
inline GateRef StubBuilder::BoolNot(GateRef x)
{
return env_.GetBulder()->UnaryArithmetic(OpCode(OpCode::REV), MachineType::I1, x);
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::REV), MachineType::I1, x);
}
inline GateRef StubBuilder::Int64Or(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryArithmetic(OpCode(OpCode::OR), MachineType::I64, x, y);
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::OR), MachineType::I64, x, y);
}
inline GateRef StubBuilder::IntPtrOr(GateRef x, GateRef y)
{
auto ptrsize = env_.Is32Bit() ? MachineType::I32 : MachineType::I64;
return env_.GetBulder()->BinaryArithmetic(OpCode(OpCode::OR), ptrsize, x, y);
auto ptrsize = env_->Is32Bit() ? MachineType::I32 : MachineType::I64;
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::OR), ptrsize, x, y);
}
inline GateRef StubBuilder::Int64And(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryArithmetic(OpCode(OpCode::AND), MachineType::I64, x, y);
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::AND), MachineType::I64, x, y);
}
inline GateRef StubBuilder::Int16LSL(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryArithmetic(OpCode(OpCode::LSL), MachineType::I16, x, y);
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::LSL), MachineType::I16, x, y);
}
inline GateRef StubBuilder::Int64Xor(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryArithmetic(OpCode(OpCode::XOR), MachineType::I64, x, y);
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::XOR), MachineType::I64, x, y);
}
inline GateRef StubBuilder::Int32Xor(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryArithmetic(OpCode(OpCode::XOR), MachineType::I32, x, y);
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::XOR), MachineType::I32, x, y);
}
inline GateRef StubBuilder::Int8LSR(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryArithmetic(OpCode(OpCode::LSR), MachineType::I8, x, y);
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::LSR), MachineType::I8, x, y);
}
inline GateRef StubBuilder::Int64Not(GateRef x)
{
return env_.GetBulder()->UnaryArithmetic(OpCode(OpCode::REV), MachineType::I64, x);
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::REV), MachineType::I64, x);
}
inline GateRef StubBuilder::Int32LSL(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryArithmetic(OpCode(OpCode::LSL), MachineType::I32, x, y);
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::LSL), MachineType::I32, x, y);
}
inline GateRef StubBuilder::Int64LSL(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryArithmetic(OpCode(OpCode::LSL), MachineType::I64, x, y);
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::LSL), MachineType::I64, x, y);
}
inline GateRef StubBuilder::IntPtrLSL(GateRef x, GateRef y)
{
auto ptrSize = env_.Is32Bit() ? MachineType::I32 : MachineType::I64;
return env_.GetBulder()->BinaryArithmetic(OpCode(OpCode::LSL), ptrSize, x, y);
auto ptrSize = env_->Is32Bit() ? MachineType::I32 : MachineType::I64;
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::LSL), ptrSize, x, y);
}
inline GateRef StubBuilder::Int32ASR(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryArithmetic(OpCode(OpCode::ASR), MachineType::I32, x, y);
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::ASR), MachineType::I32, x, y);
}
inline GateRef StubBuilder::Int32LSR(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryArithmetic(OpCode(OpCode::LSR), MachineType::I32, x, y);
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::LSR), MachineType::I32, x, y);
}
inline GateRef StubBuilder::Int64LSR(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryArithmetic(OpCode(OpCode::LSR), MachineType::I64, x, y);
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::LSR), MachineType::I64, x, y);
}
inline GateRef StubBuilder::IntPtrLSR(GateRef x, GateRef y)
{
auto ptrSize = env_.Is32Bit() ? MachineType::I32 : MachineType::I64;
return env_.GetBulder()->BinaryArithmetic(OpCode(OpCode::LSR), ptrSize, x, y);
auto ptrSize = env_->Is32Bit() ? MachineType::I32 : MachineType::I64;
return env_->GetBuilder()->BinaryArithmetic(OpCode(OpCode::LSR), ptrSize, x, y);
}
template<OpCode::Op Op, MachineType Type>
inline GateRef StubBuilder::BinaryOp(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryArithmetic(OpCode(Op), Type, x, y);
return env_->GetBuilder()->BinaryArithmetic(OpCode(Op), Type, x, y);
}
inline GateRef StubBuilder::TaggedIsInt(GateRef x)
@ -698,7 +698,7 @@ inline GateRef StubBuilder::DoubleBuildTaggedTypeWithNoGC(GateRef x)
inline GateRef StubBuilder::CastDoubleToInt64(GateRef x)
{
return env_.GetBulder()->UnaryArithmetic(OpCode(OpCode::BITCAST), MachineType::I64, x);
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::BITCAST), MachineType::I64, x);
}
inline GateRef StubBuilder::TaggedTrue()
@ -714,128 +714,128 @@ inline GateRef StubBuilder::TaggedFalse()
// compare operation
inline GateRef StubBuilder::Int8Equal(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryLogic(OpCode(OpCode::EQ), x, y);
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::EQ), x, y);
}
inline GateRef StubBuilder::Int32Equal(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryLogic(OpCode(OpCode::EQ), x, y);
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::EQ), x, y);
}
inline GateRef StubBuilder::Int32NotEqual(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryLogic(OpCode(OpCode::NE), x, y);
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::NE), x, y);
}
inline GateRef StubBuilder::Int64Equal(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryLogic(OpCode(OpCode::EQ), x, y);
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::EQ), x, y);
}
inline GateRef StubBuilder::DoubleEqual(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryLogic(OpCode(OpCode::EQ), x, y);
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::EQ), x, y);
}
inline GateRef StubBuilder::DoubleLessThan(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryLogic(OpCode(OpCode::SLT), x, y);
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::SLT), x, y);
}
inline GateRef StubBuilder::DoubleLessThanOrEqual(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryLogic(OpCode(OpCode::SLE), x, y);
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::SLE), x, y);
}
inline GateRef StubBuilder::DoubleGreaterThan(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryLogic(OpCode(OpCode::SGT), x, y);
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::SGT), x, y);
}
inline GateRef StubBuilder::DoubleGreaterThanOrEqual(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryLogic(OpCode(OpCode::SGE), x, y);
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::SGE), x, y);
}
inline GateRef StubBuilder::Int64NotEqual(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryLogic(OpCode(OpCode::NE), x, y);
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::NE), x, y);
}
inline GateRef StubBuilder::Int32GreaterThan(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryLogic(OpCode(OpCode::SGT), x, y);
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::SGT), x, y);
}
inline GateRef StubBuilder::Int32LessThan(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryLogic(OpCode(OpCode::SLT), x, y);
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::SLT), x, y);
}
inline GateRef StubBuilder::Int32GreaterThanOrEqual(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryLogic(OpCode(OpCode::SGE), x, y);
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::SGE), x, y);
}
inline GateRef StubBuilder::Int32LessThanOrEqual(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryLogic(OpCode(OpCode::SLE), x, y);
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::SLE), x, y);
}
inline GateRef StubBuilder::Int32UnsignedGreaterThan(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryLogic(OpCode(OpCode::UGT), x, y);
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::UGT), x, y);
}
inline GateRef StubBuilder::Int32UnsignedLessThan(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryLogic(OpCode(OpCode::ULT), x, y);
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::ULT), x, y);
}
inline GateRef StubBuilder::Int32UnsignedGreaterThanOrEqual(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryLogic(OpCode(OpCode::UGE), x, y);
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::UGE), x, y);
}
inline GateRef StubBuilder::Int64GreaterThan(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryLogic(OpCode(OpCode::SGT), x, y);
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::SGT), x, y);
}
inline GateRef StubBuilder::Int64LessThan(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryLogic(OpCode(OpCode::SLT), x, y);
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::SLT), x, y);
}
inline GateRef StubBuilder::Int64LessThanOrEqual(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryLogic(OpCode(OpCode::SLE), x, y);
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::SLE), x, y);
}
inline GateRef StubBuilder::Int64GreaterThanOrEqual(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryLogic(OpCode(OpCode::SGE), x, y);
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::SGE), x, y);
}
inline GateRef StubBuilder::Int64UnsignedLessThanOrEqual(GateRef x, GateRef y)
{
return env_.GetBulder()->BinaryLogic(OpCode(OpCode::ULE), x, y);
return env_->GetBuilder()->BinaryLogic(OpCode(OpCode::ULE), x, y);
}
inline GateRef StubBuilder::IntPtrGreaterThan(GateRef x, GateRef y)
{
return env_.Is32Bit() ? Int32GreaterThan(x, y) : Int64GreaterThan(x, y);
return env_->Is32Bit() ? Int32GreaterThan(x, y) : Int64GreaterThan(x, y);
}
// cast operation
inline GateRef StubBuilder::ChangeInt64ToInt32(GateRef val)
{
return env_.GetBulder()->UnaryArithmetic(OpCode(OpCode::TRUNC_TO_INT32), val);
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::TRUNC_TO_INT32), val);
}
inline GateRef StubBuilder::ChangeInt64ToIntPtr(GateRef val)
{
if (env_.IsArch32Bit()) {
if (env_->IsArch32Bit()) {
return ChangeInt64ToInt32(val);
}
return val;
@ -843,7 +843,7 @@ inline GateRef StubBuilder::ChangeInt64ToIntPtr(GateRef val)
inline GateRef StubBuilder::ChangeInt32ToIntPtr(GateRef val)
{
if (env_.IsArch32Bit()) {
if (env_->IsArch32Bit()) {
return val;
}
return ZExtInt32ToInt64(val);
@ -851,7 +851,7 @@ inline GateRef StubBuilder::ChangeInt32ToIntPtr(GateRef val)
inline GateRef StubBuilder::ChangeIntPtrToInt32(GateRef val)
{
if (env_.IsArch32Bit()) {
if (env_->IsArch32Bit()) {
return val;
}
return ChangeInt64ToInt32(val);
@ -1514,7 +1514,7 @@ inline GateRef StubBuilder::TaggedCastToInt32(GateRef x)
inline GateRef StubBuilder::TaggedCastToIntPtr(GateRef x)
{
return env_.Is32Bit() ? ChangeInt64ToInt32(TaggedCastToInt64(x)) : TaggedCastToInt64(x);
return env_->Is32Bit() ? ChangeInt64ToInt32(TaggedCastToInt64(x)) : TaggedCastToInt64(x);
}
inline GateRef StubBuilder::TaggedCastToDouble(GateRef x)
@ -1532,131 +1532,131 @@ inline GateRef StubBuilder::TaggedCastToWeakReferentUnChecked(GateRef x)
inline GateRef StubBuilder::ChangeInt32ToFloat64(GateRef x)
{
return env_.GetBulder()->UnaryArithmetic(OpCode(OpCode::SIGNED_INT_TO_FLOAT), MachineType::F64, x);
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::SIGNED_INT_TO_FLOAT), MachineType::F64, x);
}
inline GateRef StubBuilder::ChangeUInt32ToFloat64(GateRef x)
{
return env_.GetBulder()->UnaryArithmetic(OpCode(OpCode::UNSIGNED_INT_TO_FLOAT), MachineType::F64, x);
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::UNSIGNED_INT_TO_FLOAT), MachineType::F64, x);
}
inline GateRef StubBuilder::ChangeFloat64ToInt32(GateRef x)
{
return env_.GetBulder()->UnaryArithmetic(OpCode(OpCode::FLOAT_TO_SIGNED_INT), MachineType::I32, x);
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::FLOAT_TO_SIGNED_INT), MachineType::I32, x);
}
inline GateRef StubBuilder::ChangeTaggedPointerToInt64(GateRef x)
{
return env_.GetBulder()->UnaryArithmetic(OpCode(OpCode::TAGGED_TO_INT64), x);
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::TAGGED_TO_INT64), x);
}
inline GateRef StubBuilder::ChangeInt64ToTagged(GateRef x)
{
return env_.GetBulder()->TaggedNumber(OpCode(OpCode::INT64_TO_TAGGED), x);
return env_->GetBuilder()->TaggedNumber(OpCode(OpCode::INT64_TO_TAGGED), x);
}
inline GateRef StubBuilder::CastInt64ToFloat64(GateRef x)
{
return env_.GetBulder()->UnaryArithmetic(OpCode(OpCode::BITCAST), MachineType::F64, x);
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::BITCAST), MachineType::F64, x);
}
inline GateRef StubBuilder::SExtInt32ToInt64(GateRef x)
{
return env_.GetBulder()->UnaryArithmetic(OpCode(OpCode::SEXT_TO_INT64), x);
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::SEXT_TO_INT64), x);
}
inline GateRef StubBuilder::SExtInt16ToInt64(GateRef x)
{
return env_.GetBulder()->UnaryArithmetic(OpCode(OpCode::SEXT_TO_INT64), x);
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::SEXT_TO_INT64), x);
}
inline GateRef StubBuilder::SExtInt8ToInt64(GateRef x)
{
return env_.GetBulder()->UnaryArithmetic(OpCode(OpCode::SEXT_TO_INT64), x);
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::SEXT_TO_INT64), x);
}
inline GateRef StubBuilder::SExtInt1ToInt64(GateRef x)
{
return env_.GetBulder()->UnaryArithmetic(OpCode(OpCode::SEXT_TO_INT64), x);
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::SEXT_TO_INT64), x);
}
inline GateRef StubBuilder::SExtInt1ToInt32(GateRef x)
{
return env_.GetBulder()->UnaryArithmetic(OpCode(OpCode::SEXT_TO_INT32), x);
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::SEXT_TO_INT32), x);
}
inline GateRef StubBuilder::ZExtInt8ToInt16(GateRef x)
{
return env_.GetBulder()->UnaryArithmetic(OpCode(OpCode::ZEXT_TO_INT16), x);
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::ZEXT_TO_INT16), x);
}
inline GateRef StubBuilder::ZExtInt32ToInt64(GateRef x)
{
return env_.GetBulder()->UnaryArithmetic(OpCode(OpCode::ZEXT_TO_INT64), x);
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::ZEXT_TO_INT64), x);
}
inline GateRef StubBuilder::ZExtInt1ToInt64(GateRef x)
{
return env_.GetBulder()->UnaryArithmetic(OpCode(OpCode::ZEXT_TO_INT64), x);
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::ZEXT_TO_INT64), x);
}
inline GateRef StubBuilder::ZExtInt1ToInt32(GateRef x)
{
return env_.GetBulder()->UnaryArithmetic(OpCode(OpCode::ZEXT_TO_INT32), x);
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::ZEXT_TO_INT32), x);
}
inline GateRef StubBuilder::ZExtInt8ToInt32(GateRef x)
{
return env_.GetBulder()->UnaryArithmetic(OpCode(OpCode::ZEXT_TO_INT32), x);
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::ZEXT_TO_INT32), x);
}
inline GateRef StubBuilder::ZExtInt8ToInt64(GateRef x)
{
return env_.GetBulder()->UnaryArithmetic(OpCode(OpCode::ZEXT_TO_INT64), x);
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::ZEXT_TO_INT64), x);
}
inline GateRef StubBuilder::ZExtInt8ToPtr(GateRef x)
{
if (env_.IsArch32Bit()) {
return env_.GetBulder()->UnaryArithmetic(OpCode(OpCode::ZEXT_TO_INT32), x);
if (env_->IsArch32Bit()) {
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::ZEXT_TO_INT32), x);
}
return env_.GetBulder()->UnaryArithmetic(OpCode(OpCode::ZEXT_TO_INT64), x);
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::ZEXT_TO_INT64), x);
}
inline GateRef StubBuilder::ZExtInt16ToPtr(GateRef x)
{
if (env_.IsArch32Bit()) {
return env_.GetBulder()->UnaryArithmetic(OpCode(OpCode::ZEXT_TO_INT32), x);
if (env_->IsArch32Bit()) {
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::ZEXT_TO_INT32), x);
}
return env_.GetBulder()->UnaryArithmetic(OpCode(OpCode::ZEXT_TO_INT64), x);
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::ZEXT_TO_INT64), x);
}
inline GateRef StubBuilder::SExtInt32ToPtr(GateRef x)
{
if (env_.IsArch32Bit()) {
if (env_->IsArch32Bit()) {
return x;
}
return env_.GetBulder()->UnaryArithmetic(OpCode(OpCode::SEXT_TO_INT64), x);
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::SEXT_TO_INT64), x);
}
inline GateRef StubBuilder::ZExtInt16ToInt32(GateRef x)
{
return env_.GetBulder()->UnaryArithmetic(OpCode(OpCode::ZEXT_TO_INT32), x);
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::ZEXT_TO_INT32), x);
}
inline GateRef StubBuilder::ZExtInt16ToInt64(GateRef x)
{
return env_.GetBulder()->UnaryArithmetic(OpCode(OpCode::ZEXT_TO_INT64), x);
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::ZEXT_TO_INT64), x);
}
inline GateRef StubBuilder::TruncInt64ToInt32(GateRef x)
{
return env_.GetBulder()->UnaryArithmetic(OpCode(OpCode::TRUNC_TO_INT32), x);
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::TRUNC_TO_INT32), x);
}
inline GateRef StubBuilder::TruncPtrToInt32(GateRef x)
{
if (env_.Is32Bit()) {
if (env_->Is32Bit()) {
return x;
}
return TruncInt64ToInt32(x);
@ -1664,12 +1664,12 @@ inline GateRef StubBuilder::TruncPtrToInt32(GateRef x)
inline GateRef StubBuilder::TruncInt64ToInt1(GateRef x)
{
return env_.GetBulder()->UnaryArithmetic(OpCode(OpCode::TRUNC_TO_INT1), x);
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::TRUNC_TO_INT1), x);
}
inline GateRef StubBuilder::TruncInt32ToInt1(GateRef x)
{
return env_.GetBulder()->UnaryArithmetic(OpCode(OpCode::TRUNC_TO_INT1), x);
return env_->GetBuilder()->UnaryArithmetic(OpCode(OpCode::TRUNC_TO_INT1), x);
}
inline GateRef StubBuilder::GetGlobalConstantAddr(GateRef index)
@ -1679,7 +1679,7 @@ inline GateRef StubBuilder::GetGlobalConstantAddr(GateRef index)
inline GateRef StubBuilder::GetGlobalConstantString(ConstantIndex index)
{
if (env_.Is32Bit()) {
if (env_->Is32Bit()) {
return Int32Mul(Int32(sizeof(JSTaggedValue)), Int32(static_cast<int>(index)));
} else {
return Int64Mul(Int64(sizeof(JSTaggedValue)), Int64(static_cast<int>(index)));
@ -1745,7 +1745,7 @@ inline void StubBuilder::SetHasConstructorToHClass(GateRef glue, GateRef hClass,
inline GateRef StubBuilder::IntPtrEuqal(GateRef x, GateRef y)
{
return env_.Is32Bit() ? Int32Equal(x, y) : Int64Equal(x, y);
return env_->Is32Bit() ? Int32Equal(x, y) : Int64Equal(x, y);
}
inline GateRef StubBuilder::GetBitMask(GateRef bitoffset)
@ -1765,10 +1765,10 @@ inline GateRef StubBuilder::ObjectAddressToRange(GateRef x)
inline GateRef StubBuilder::InYoungGeneration(GateRef region)
{
auto offset = Region::PackedData::GetFlagOffset(env_.Is32Bit());
auto offset = Region::PackedData::GetFlagOffset(env_->Is32Bit());
GateRef x = Load(VariableType::NATIVE_POINTER(), PtrAdd(IntPtr(offset), region),
IntPtr(0));
if (env_.Is32Bit()) {
if (env_->Is32Bit()) {
return Int32Equal(Int32And(x,
Int32(RegionSpaceFlag::VALID_SPACE_MASK)), Int32(RegionSpaceFlag::IN_YOUNG_SPACE));
} else {
@ -1836,7 +1836,7 @@ inline GateRef StubBuilder::GetMethodFromJSFunction(GateRef object)
inline GateRef StubBuilder::GetCallFieldFromMethod(GateRef method)
{
GateRef callFieldOffset = IntPtr(JSMethod::GetCallFieldOffset(env_.IsArch32Bit()));
GateRef callFieldOffset = IntPtr(JSMethod::GetCallFieldOffset(env_->IsArch32Bit()));
return Load(VariableType::INT64(), method, callFieldOffset);
}
@ -1848,7 +1848,7 @@ inline void StubBuilder::SetLexicalEnvToFunction(GateRef glue, GateRef object, G
inline GateRef StubBuilder::GetGlobalObject(GateRef glue)
{
GateRef offset = IntPtr(JSThread::GlueData::GetGlobalObjOffset(env_.Is32Bit()));
GateRef offset = IntPtr(JSThread::GlueData::GetGlobalObjOffset(env_->Is32Bit()));
return Load(VariableType::JS_ANY(), glue, offset);
}
@ -1896,7 +1896,7 @@ inline GateRef StubBuilder::IsBoundFunction(GateRef obj)
inline GateRef StubBuilder::IsNativeMethod(GateRef method)
{
GateRef callFieldOffset = IntPtr(JSMethod::GetCallFieldOffset(env_.Is32Bit()));
GateRef callFieldOffset = IntPtr(JSMethod::GetCallFieldOffset(env_->Is32Bit()));
GateRef callfield = Load(VariableType::INT64(), method, callFieldOffset);
return Int64NotEqual(
Int64And(
@ -1907,7 +1907,7 @@ inline GateRef StubBuilder::IsNativeMethod(GateRef method)
inline GateRef StubBuilder::HasAotCode(GateRef method)
{
GateRef callFieldOffset = IntPtr(JSMethod::GetCallFieldOffset(env_.Is32Bit()));
GateRef callFieldOffset = IntPtr(JSMethod::GetCallFieldOffset(env_->Is32Bit()));
GateRef callfield = Load(VariableType::INT64(), method, callFieldOffset);
return Int64NotEqual(
Int64And(
@ -1918,7 +1918,7 @@ inline GateRef StubBuilder::HasAotCode(GateRef method)
inline GateRef StubBuilder::GetExpectedNumOfArgs(GateRef method)
{
GateRef callFieldOffset = IntPtr(JSMethod::GetCallFieldOffset(env_.Is32Bit()));
GateRef callFieldOffset = IntPtr(JSMethod::GetCallFieldOffset(env_->Is32Bit()));
GateRef callfield = Load(VariableType::INT64(), method, callFieldOffset);
return TruncInt64ToInt32(Int64And(
Int64LSR(callfield, Int32(JSMethod::NumArgsBits::START_BIT)),
@ -1951,14 +1951,14 @@ inline GateRef StubBuilder::ComputeTaggedArraySize(GateRef length)
inline GateRef StubBuilder::GetGlobalConstantValue(VariableType type, GateRef glue, ConstantIndex index)
{
GateRef gConstAddr = PtrAdd(glue,
IntPtr(JSThread::GlueData::GetGlobalConstOffset(env_.Is32Bit())));
IntPtr(JSThread::GlueData::GetGlobalConstOffset(env_->Is32Bit())));
auto constantIndex = IntPtr(JSTaggedValue::TaggedTypeSize() * static_cast<size_t>(index));
return Load(type, gConstAddr, constantIndex);
}
inline GateRef StubBuilder::HasPendingException(GateRef glue)
{
GateRef exceptionOffset = IntPtr(JSThread::GlueData::GetExceptionOffset(env_.IsArch32Bit()));
GateRef exceptionOffset = IntPtr(JSThread::GlueData::GetExceptionOffset(env_->IsArch32Bit()));
GateRef exception = Load(VariableType::JS_ANY(), glue, exceptionOffset);
return Int64NotEqual(exception, Int64(JSTaggedValue::VALUE_HOLE));
}

View File

@ -13,11 +13,10 @@
* limitations under the License.
*/
#include "ecmascript/compiler/stub_builder.h"
#include "ecmascript/compiler/stub_builder-inl.h"
#include "ecmascript/compiler/llvm_ir_builder.h"
#include "ecmascript/compiler/rt_call_signature.h"
#include "ecmascript/compiler/stub_builder-inl.h"
#include "ecmascript/js_api/js_api_arraylist.h"
#include "ecmascript/js_api/js_api_vector.h"
#include "ecmascript/js_object.h"
@ -29,99 +28,77 @@
#include "libpandabase/macros.h"
namespace panda::ecmascript::kungfu {
StubBuilder::StubBuilder(CallSignature *callSignature, Circuit *circuit)
: callSignature_(callSignature), builder_(circuit),
acc_(circuit), env_(callSignature->GetParametersCount(), &builder_)
{
}
void StubBuilder::InitializeArguments()
{
auto argLength = callSignature_->GetParametersCount();
auto paramsType = callSignature_->GetParametersType();
for (size_t i = 0; i < argLength; i++) {
GateRef argument = Argument(i);
if (paramsType[i] == VariableType::NATIVE_POINTER()) {
auto type = env_.IsArch64Bit() ? MachineType::I64 : MachineType::I32;
acc_.SetMachineType(argument, type);
} else {
acc_.SetMachineType(argument, paramsType[i].GetMachineType());
}
acc_.SetGateType(argument, paramsType[i].GetGateType());
}
}
void StubBuilder::Jump(Label *label)
{
ASSERT(label);
auto currentLabel = env_.GetCurrentLabel();
auto currentLabel = env_->GetCurrentLabel();
auto currentControl = currentLabel->GetControl();
auto jump = env_.GetBulder()->Goto(currentControl);
auto jump = env_->GetBuilder()->Goto(currentControl);
currentLabel->SetControl(jump);
label->AppendPredecessor(currentLabel);
label->MergeControl(currentLabel->GetControl());
env_.SetCurrentLabel(nullptr);
env_->SetCurrentLabel(nullptr);
}
void StubBuilder::Branch(GateRef condition, Label *trueLabel, Label *falseLabel)
{
auto currentLabel = env_.GetCurrentLabel();
auto currentLabel = env_->GetCurrentLabel();
auto currentControl = currentLabel->GetControl();
GateRef ifBranch = env_.GetBulder()->Branch(currentControl, condition);
GateRef ifBranch = env_->GetBuilder()->Branch(currentControl, condition);
currentLabel->SetControl(ifBranch);
GateRef ifTrue = env_.GetBulder()->IfTrue(ifBranch);
trueLabel->AppendPredecessor(env_.GetCurrentLabel());
GateRef ifTrue = env_->GetBuilder()->IfTrue(ifBranch);
trueLabel->AppendPredecessor(env_->GetCurrentLabel());
trueLabel->MergeControl(ifTrue);
GateRef ifFalse = env_.GetBulder()->IfFalse(ifBranch);
falseLabel->AppendPredecessor(env_.GetCurrentLabel());
GateRef ifFalse = env_->GetBuilder()->IfFalse(ifBranch);
falseLabel->AppendPredecessor(env_->GetCurrentLabel());
falseLabel->MergeControl(ifFalse);
env_.SetCurrentLabel(nullptr);
env_->SetCurrentLabel(nullptr);
}
void StubBuilder::Switch(GateRef index, Label *defaultLabel, int64_t *keysValue, Label *keysLabel, int numberOfKeys)
{
auto currentLabel = env_.GetCurrentLabel();
auto currentLabel = env_->GetCurrentLabel();
auto currentControl = currentLabel->GetControl();
GateRef switchBranch = env_.GetBulder()->SwitchBranch(currentControl, index, numberOfKeys);
GateRef switchBranch = env_->GetBuilder()->SwitchBranch(currentControl, index, numberOfKeys);
currentLabel->SetControl(switchBranch);
for (int i = 0; i < numberOfKeys; i++) {
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
GateRef switchCase = env_.GetBulder()->SwitchCase(switchBranch, keysValue[i]);
GateRef switchCase = env_->GetBuilder()->SwitchCase(switchBranch, keysValue[i]);
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
keysLabel[i].AppendPredecessor(currentLabel);
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
keysLabel[i].MergeControl(switchCase);
}
GateRef defaultCase = env_.GetBulder()->DefaultCase(switchBranch);
GateRef defaultCase = env_->GetBuilder()->DefaultCase(switchBranch);
defaultLabel->AppendPredecessor(currentLabel);
defaultLabel->MergeControl(defaultCase);
env_.SetCurrentLabel(nullptr);
env_->SetCurrentLabel(nullptr);
}
void StubBuilder::LoopBegin(Label *loopHead)
{
ASSERT(loopHead);
auto loopControl = env_.GetBulder()->LoopBegin(loopHead->GetControl());
auto loopControl = env_->GetBuilder()->LoopBegin(loopHead->GetControl());
loopHead->SetControl(loopControl);
loopHead->SetPreControl(loopControl);
loopHead->Bind();
env_.SetCurrentLabel(loopHead);
env_->SetCurrentLabel(loopHead);
}
void StubBuilder::LoopEnd(Label *loopHead)
{
ASSERT(loopHead);
auto currentLabel = env_.GetCurrentLabel();
auto currentLabel = env_->GetCurrentLabel();
auto currentControl = currentLabel->GetControl();
auto loopend = env_.GetBulder()->LoopEnd(currentControl);
auto loopend = env_->GetBuilder()->LoopEnd(currentControl);
currentLabel->SetControl(loopend);
loopHead->AppendPredecessor(currentLabel);
loopHead->MergeControl(loopend);
loopHead->Seal();
loopHead->MergeAllControl();
loopHead->MergeAllDepend();
env_.SetCurrentLabel(nullptr);
env_->SetCurrentLabel(nullptr);
}
// FindElementWithCache in ecmascript/layout_info-inl.h
@ -745,7 +722,7 @@ void StubBuilder::JSHClassAddProperty(GateRef glue, GateRef receiver, GateRef ke
GateRef StubBuilder::SetHasConstructorCondition(GateRef glue, GateRef receiver, GateRef key)
{
GateRef gConstOffset = PtrAdd(glue,
IntPtr(JSThread::GlueData::GetGlobalConstOffset(env_.Is32Bit())));
IntPtr(JSThread::GlueData::GetGlobalConstOffset(env_->Is32Bit())));
GateRef gCtorStr = Load(VariableType::JS_ANY(),
gConstOffset,
Int64Mul(Int64(sizeof(JSTaggedValue)),
@ -931,22 +908,22 @@ GateRef StubBuilder::TaggedToRepresentation(GateRef value)
void StubBuilder::Store(VariableType type, GateRef glue, GateRef base, GateRef offset, GateRef value)
{
auto depend = env_.GetCurrentLabel()->GetDepend();
auto depend = env_->GetCurrentLabel()->GetDepend();
GateRef result;
if (env_.IsArch64Bit()) {
if (env_->IsArch64Bit()) {
GateRef ptr = Int64Add(base, offset);
if (type == VariableType::NATIVE_POINTER()) {
type = VariableType::INT64();
}
result = env_.GetCircuit()->NewGate(OpCode(OpCode::STORE), 0, { depend, value, ptr }, type.GetGateType());
env_.GetCurrentLabel()->SetDepend(result);
} else if (env_.IsArch32Bit()) {
result = env_->GetCircuit()->NewGate(OpCode(OpCode::STORE), 0, { depend, value, ptr }, type.GetGateType());
env_->GetCurrentLabel()->SetDepend(result);
} else if (env_->IsArch32Bit()) {
if (type == VariableType::NATIVE_POINTER()) {
type = VariableType::INT32();
}
GateRef ptr = Int32Add(base, offset);
result = env_.GetCircuit()->NewGate(OpCode(OpCode::STORE), 0, { depend, value, ptr }, type.GetGateType());
env_.GetCurrentLabel()->SetDepend(result);
result = env_->GetCircuit()->NewGate(OpCode(OpCode::STORE), 0, { depend, value, ptr }, type.GetGateType());
env_->GetCurrentLabel()->SetDepend(result);
} else {
UNREACHABLE();
}
@ -977,7 +954,7 @@ void StubBuilder::SetValueWithBarrier(GateRef glue, GateRef obj, GateRef offset,
Branch(BoolAnd(objectNotInYoung, valueRegionInYoung), &isVailedIndex, &notValidIndex);
Bind(&isVailedIndex);
{
GateRef loadOffset = IntPtr(Region::PackedData::GetOldToNewSetOffset(env_.Is32Bit()));
GateRef loadOffset = IntPtr(Region::PackedData::GetOldToNewSetOffset(env_->Is32Bit()));
auto oldToNewSet = Load(VariableType::NATIVE_POINTER(), objectRegion, loadOffset);
Label isNullPtr(env);
Label notNullPtr(env);
@ -4092,7 +4069,7 @@ GateRef StubBuilder::JSCallDispatch(GateRef glue, GateRef func, GateRef actualNu
{
GateRef newTarget = Undefined();
GateRef thisValue = Undefined();
GateRef lexEnv = builder_.GetLexicalEnv(func);
GateRef lexEnv = env_->GetBuilder()->GetLexicalEnv(func);
GateRef realNumArgs = Int64Add(ZExtInt32ToInt64(actualNumArgs), Int64(NUM_MANDATORY_JSFUNC_ARGS));
switch (mode) {
case JSCallMode::CALL_ARG0:

View File

@ -13,14 +13,13 @@
* limitations under the License.
*/
#ifndef ECMASCRIPT_COMPILER_STUB_H
#define ECMASCRIPT_COMPILER_STUB_H
#ifndef ECMASCRIPT_COMPILER_STUB_BUILDER_H
#define ECMASCRIPT_COMPILER_STUB_BUILDER_H
#include "ecmascript/compiler/circuit_builder-inl.h"
#include "ecmascript/compiler/call_signature.h"
#include "ecmascript/compiler/gate.h"
#include "ecmascript/compiler/circuit_builder-inl.h"
#include "ecmascript/compiler/variable_type.h"
#include "ecmascript/global_env_constants.h"
//#include "ecmascript/global_env_constants.h"
namespace panda::ecmascript::kungfu {
using namespace panda::ecmascript;
@ -29,22 +28,15 @@ using namespace panda::ecmascript;
class StubBuilder {
public:
explicit StubBuilder(CallSignature *callSignature, Circuit *circuit);
explicit StubBuilder(CallSignature *callSignature, Environment *env)
: callSignature_(callSignature), env_(env) {}
virtual ~StubBuilder() = default;
NO_MOVE_SEMANTIC(StubBuilder);
NO_COPY_SEMANTIC(StubBuilder);
virtual void GenerateCircuit(const CompilationConfig *cfg)
virtual void GenerateCircuit() = 0;
Environment *GetEnvironment() const
{
env_.SetCompilationConfig(cfg);
InitializeArguments();
}
CircuitBuilder* GetBuilder()
{
return &builder_;
}
Environment *GetEnvironment()
{
return &env_;
return env_;
}
CallSignature *GetCallSignature() const
{
@ -52,11 +44,7 @@ public:
}
int NextVariableId()
{
return env_.NextVariableId();
}
const std::string &GetMethodName() const
{
return callSignature_->GetName();
return env_->NextVariableId();
}
// constant
GateRef Int8(int8_t value);
@ -481,9 +469,7 @@ private:
const BinaryOperation& intOp, const BinaryOperation& floatOp);
void InitializeArguments();
CallSignature *callSignature_;
CircuitBuilder builder_;
GateAccessor acc_;
Environment env_;
Environment *env_;
};
} // namespace panda::ecmascript::kungfu
#endif // ECMASCRIPT_COMPILER_STUB_H
#endif // ECMASCRIPT_COMPILER_STUB_BUILDER_H

View File

@ -22,6 +22,7 @@
#include "ecmascript/compiler/llvm_codegen.h"
#include "ecmascript/compiler/pass.h"
#include "ecmascript/compiler/scheduler.h"
#include "ecmascript/compiler/stub.h"
#include "ecmascript/compiler/stub_builder-inl.h"
#include "ecmascript/compiler/verifier.h"
#include "ecmascript/napi/include/jsnapi.h"
@ -33,8 +34,8 @@
namespace panda::ecmascript::kungfu {
class StubPassData : public PassData {
public:
explicit StubPassData(StubBuilder *stubBuilder, LLVMModule *module)
: PassData(nullptr), module_(module), stubBuilder_(stubBuilder) {}
explicit StubPassData(Stub *stub, LLVMModule *module)
: PassData(nullptr), module_(module), stub_(stub) {}
~StubPassData() = default;
const CompilationConfig *GetCompilationConfig() const
@ -44,7 +45,7 @@ public:
Circuit *GetCircuit() const
{
return stubBuilder_->GetEnvironment()->GetCircuit();
return stub_->GetEnvironment()->GetCircuit();
}
LLVMModule *GetStubModule() const
@ -52,21 +53,21 @@ public:
return module_;
}
StubBuilder *GetStubBuilder() const
Stub *GetStub() const
{
return stubBuilder_;
return stub_;
}
private:
LLVMModule *module_;
StubBuilder *stubBuilder_;
Stub *stub_;
};
class StubBuildCircuitPass {
public:
bool Run(StubPassData *data, [[maybe_unused]] bool enableLog)
{
auto stub = data->GetStubBuilder();
auto stub = data->GetStub();
LOG_COMPILER(INFO) << "Stub Name: " << stub->GetMethodName();
stub->GenerateCircuit(data->GetCompilationConfig());
return true;
@ -99,14 +100,17 @@ void StubCompiler::RunPipeline(LLVMModule *module) const
for (size_t i = 0; i < callSigns.size(); i++) {
Circuit circuit;
Stub stub(callSigns[i], &circuit);
ASSERT(callSigns[i]->HasConstructor());
StubBuilder* stubBuilder = static_cast<StubBuilder*>(callSigns[i]->GetConstructor()(reinterpret_cast<void*>(&circuit)));
StubBuilder* stubBuilder = static_cast<StubBuilder*>(
callSigns[i]->GetConstructor()(reinterpret_cast<void*>(stub.GetEnvironment())));
stub.SetStubBuilder(stubBuilder);
if (!log->IsAlwaysEnabled() && !log->IsAlwaysDisabled()) { // neither "all" nor "none"
enableLog = log->IncludesMethod(stubBuilder->GetMethodName());
enableLog = log->IncludesMethod(stub.GetMethodName());
}
StubPassData data(stubBuilder, module);
StubPassData data(&stub, module);
PassRunner<StubPassData> pipeline(&data, enableLog);
pipeline.RunPass<StubBuildCircuitPass>();
pipeline.RunPass<VerifierPass>();

View File

@ -23,9 +23,8 @@
namespace panda::ecmascript::kungfu {
using namespace panda::ecmascript;
#ifndef NDEBUG
void FooAOTStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
void FooAOTStubBuilder::GenerateCircuit()
{
StubBuilder::GenerateCircuit(cfg);
GateRef glue = PtrArgument(0);
GateRef env = TaggedArgument(1);
GateRef argc = Int64Argument(2);
@ -44,9 +43,8 @@ void FooAOTStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
Return(result);
}
void BarAOTStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
void BarAOTStubBuilder::GenerateCircuit()
{
StubBuilder::GenerateCircuit(cfg);
GateRef glue = PtrArgument(0);
[[maybe_unused]] GateRef env = TaggedArgument(1);
[[maybe_unused]] GateRef argc = Int64Argument(2);
@ -59,9 +57,8 @@ void BarAOTStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
Return(result);
}
void Foo1AOTStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
void Foo1AOTStubBuilder::GenerateCircuit()
{
StubBuilder::GenerateCircuit(cfg);
GateRef glue = PtrArgument(0);
GateRef env = TaggedArgument(1);
GateRef argc = Int64Argument(2);
@ -80,9 +77,8 @@ void Foo1AOTStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
Return(result);
}
void Bar1AOTStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
void Bar1AOTStubBuilder::GenerateCircuit()
{
StubBuilder::GenerateCircuit(cfg);
GateRef glue = PtrArgument(0);
GateRef env = TaggedArgument(1);
GateRef argc = Int64Argument(2);
@ -102,9 +98,8 @@ void Bar1AOTStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
Return(result2);
}
void Foo2AOTStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
void Foo2AOTStubBuilder::GenerateCircuit()
{
StubBuilder::GenerateCircuit(cfg);
GateRef glue = PtrArgument(0);
GateRef env = TaggedArgument(1);
GateRef argc = Int64Argument(2);
@ -124,9 +119,8 @@ void Foo2AOTStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
Return(result);
}
void FooNativeAOTStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
void FooNativeAOTStubBuilder::GenerateCircuit()
{
StubBuilder::GenerateCircuit(cfg);
GateRef glue = PtrArgument(0);
GateRef env = TaggedArgument(1);
GateRef argc = Int64Argument(2);
@ -144,9 +138,8 @@ void FooNativeAOTStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
Return(result);
}
void FooBoundAOTStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
void FooBoundAOTStubBuilder::GenerateCircuit()
{
StubBuilder::GenerateCircuit(cfg);
GateRef glue = PtrArgument(0);
GateRef env = TaggedArgument(1);
GateRef argc = Int64Argument(2);
@ -169,9 +162,8 @@ void FooBoundAOTStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
Return(result);
}
void FooProxyAOTStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
void FooProxyAOTStubBuilder::GenerateCircuit()
{
StubBuilder::GenerateCircuit(cfg);
GateRef glue = PtrArgument(0);
GateRef env = TaggedArgument(1);
GateRef argc = Int64Argument(2);
@ -192,9 +184,8 @@ void FooProxyAOTStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
Return(result);
}
void FooProxy2AOTStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
void FooProxy2AOTStubBuilder::GenerateCircuit()
{
StubBuilder::GenerateCircuit(cfg);
GateRef glue = PtrArgument(0);
GateRef env = TaggedArgument(1);
GateRef argc = Int64Argument(2);
@ -216,9 +207,8 @@ void FooProxy2AOTStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
Return(result);
}
void Bar2AOTStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
void Bar2AOTStubBuilder::GenerateCircuit()
{
StubBuilder::GenerateCircuit(cfg);
[[maybe_unused]] GateRef glue = PtrArgument(0);
[[maybe_unused]] GateRef env = TaggedArgument(1);
[[maybe_unused]] GateRef argc = Int64Argument(2);
@ -229,9 +219,8 @@ void Bar2AOTStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
Return(thisObj);
}
void TestAbsoluteAddressRelocationStubBuilder::GenerateCircuit(const CompilationConfig *cfg)
void TestAbsoluteAddressRelocationStubBuilder::GenerateCircuit()
{
StubBuilder::GenerateCircuit(cfg);
auto env = GetEnvironment();
GateRef a = Int64Argument(0);
Label start(env);

View File

@ -17,23 +17,23 @@
#define ECMASCRIPT_COMPILER_TEST_STUBS_H
#include "ecmascript/compiler/stub_builder.h"
#include "test_stubs_signature.h"
#include "ecmascript/compiler/test_stubs_signature.h"
namespace panda::ecmascript::kungfu {
#ifndef NDEBUG
#define DECLARE_STUB_CLASS(name) \
class name##StubBuilder : public StubBuilder { \
public: \
explicit name##StubBuilder(CallSignature *callSignature, Circuit *circuit) \
: StubBuilder(callSignature, circuit) {} \
~name##StubBuilder() = default; \
NO_MOVE_SEMANTIC(name##StubBuilder); \
NO_COPY_SEMANTIC(name##StubBuilder); \
void GenerateCircuit(const CompilationConfig *cfg) override; \
#define DECLARE_STUB_CLASS(name) \
class name##StubBuilder : public StubBuilder { \
public: \
explicit name##StubBuilder(CallSignature *callSignature, Environment *env) \
: StubBuilder(callSignature, env) {} \
~name##StubBuilder() = default; \
NO_MOVE_SEMANTIC(name##StubBuilder); \
NO_COPY_SEMANTIC(name##StubBuilder); \
void GenerateCircuit() override; \
};
TEST_STUB_SIGNATRUE_LIST(DECLARE_STUB_CLASS)
#undef DECLARE_STUB_CLASS
#endif
}
#endif
#endif

View File

@ -25,6 +25,7 @@
#include "ecmascript/compiler/gate_accessor.h"
#include "ecmascript/compiler/llvm_codegen.h"
#include "ecmascript/compiler/llvm_ir_builder.h"
#include "ecmascript/compiler/stub.h"
#include "ecmascript/compiler/scheduler.h"
#include "ecmascript/compiler/verifier.h"
#include "ecmascript/ecma_vm.h"
@ -106,8 +107,10 @@ HWTEST_F_L0(StubTest, FastAddTest)
Circuit netOfGates;
CallSignature callSignature;
AddCallSignature::Initialize(&callSignature);
AddStubBuilder optimizer(&callSignature, &netOfGates);
optimizer.GenerateCircuit(stubModule.GetCompilationConfig());
Stub stub(&callSignature, &netOfGates);
AddStubBuilder optimizer(&callSignature, stub.GetEnvironment());
stub.SetStubBuilder(&optimizer);
stub.GenerateCircuit(stubModule.GetCompilationConfig());
netOfGates.PrintAllGates();
auto cfg = Scheduler::Run(&netOfGates);
PrintCircuitByBasicBlock(cfg, netOfGates);
@ -145,8 +148,10 @@ HWTEST_F_L0(StubTest, FastSubTest)
Circuit netOfGates;
CallSignature callSignature;
SubCallSignature::Initialize(&callSignature);
SubStubBuilder optimizer(&callSignature, &netOfGates);
optimizer.GenerateCircuit(stubModule.GetCompilationConfig());
Stub stub(&callSignature, &netOfGates);
SubStubBuilder optimizer(&callSignature, stub.GetEnvironment());
stub.SetStubBuilder(&optimizer);
stub.GenerateCircuit(stubModule.GetCompilationConfig());
netOfGates.PrintAllGates();
auto cfg = Scheduler::Run(&netOfGates);
PrintCircuitByBasicBlock(cfg, netOfGates);
@ -180,8 +185,10 @@ HWTEST_F_L0(StubTest, FastMulTest)
Circuit netOfGates;
CallSignature callSignature;
MulCallSignature::Initialize(&callSignature);
MulStubBuilder optimizer(&callSignature, &netOfGates);
optimizer.GenerateCircuit(stubModule.GetCompilationConfig());
Stub stub(&callSignature, &netOfGates);
MulStubBuilder optimizer(&callSignature, stub.GetEnvironment());
stub.SetStubBuilder(&optimizer);
stub.GenerateCircuit(stubModule.GetCompilationConfig());
netOfGates.PrintAllGates();
auto cfg = Scheduler::Run(&netOfGates);
PrintCircuitByBasicBlock(cfg, netOfGates);
@ -234,8 +241,10 @@ HWTEST_F_L0(StubTest, FastDivTest)
Circuit netOfGates;
CallSignature callSignature;
DivCallSignature::Initialize(&callSignature);
DivStubBuilder optimizer(&callSignature, &netOfGates);
optimizer.GenerateCircuit(stubModule.GetCompilationConfig());
Stub stub(&callSignature, &netOfGates);
DivStubBuilder optimizer(&callSignature, stub.GetEnvironment());
stub.SetStubBuilder(&optimizer);
stub.GenerateCircuit(stubModule.GetCompilationConfig());
netOfGates.PrintAllGates();
auto cfg = Scheduler::Run(&netOfGates);
PrintCircuitByBasicBlock(cfg, netOfGates);
@ -281,8 +290,10 @@ HWTEST_F_L0(StubTest, FastModTest)
Circuit netOfGates;
CallSignature callSignature;
ModCallSignature::Initialize(&callSignature);
ModStubBuilder optimizer(&callSignature, &netOfGates);
optimizer.GenerateCircuit(stubModule.GetCompilationConfig());
Stub stub(&callSignature, &netOfGates);
ModStubBuilder optimizer(&callSignature, stub.GetEnvironment());
stub.SetStubBuilder(&optimizer);
stub.GenerateCircuit(stubModule.GetCompilationConfig());
netOfGates.PrintAllGates();
auto cfg = Scheduler::Run(&netOfGates);
PrintCircuitByBasicBlock(cfg, netOfGates);
@ -347,8 +358,10 @@ HWTEST_F_L0(StubTest, TryLoadICByName)
Circuit netOfGates;
CallSignature callSignature;
TryLoadICByNameCallSignature::Initialize(&callSignature);
TryLoadICByNameStubBuilder optimizer(&callSignature, &netOfGates);
optimizer.GenerateCircuit(stubModule.GetCompilationConfig());
Stub stub(&callSignature, &netOfGates);
TryLoadICByNameStubBuilder optimizer(&callSignature, stub.GetEnvironment());
stub.SetStubBuilder(&optimizer);
stub.GenerateCircuit(stubModule.GetCompilationConfig());
netOfGates.PrintAllGates();
auto cfg = Scheduler::Run(&netOfGates);
PrintCircuitByBasicBlock(cfg, netOfGates);
@ -366,8 +379,10 @@ HWTEST_F_L0(StubTest, TryLoadICByValue)
Circuit netOfGates;
CallSignature callSignature;
TryLoadICByValueCallSignature::Initialize(&callSignature);
TryLoadICByValueStubBuilder optimizer(&callSignature, &netOfGates);
optimizer.GenerateCircuit(stubModule.GetCompilationConfig());
Stub stub(&callSignature, &netOfGates);
TryLoadICByValueStubBuilder optimizer(&callSignature, stub.GetEnvironment());
stub.SetStubBuilder(&optimizer);
stub.GenerateCircuit(stubModule.GetCompilationConfig());
netOfGates.PrintAllGates();
auto cfg = Scheduler::Run(&netOfGates);
PrintCircuitByBasicBlock(cfg, netOfGates);
@ -385,8 +400,10 @@ HWTEST_F_L0(StubTest, TryStoreICByName)
Circuit netOfGates;
CallSignature callSignature;
TryStoreICByNameCallSignature::Initialize(&callSignature);
TryStoreICByNameStubBuilder optimizer(&callSignature, &netOfGates);
optimizer.GenerateCircuit(stubModule.GetCompilationConfig());
Stub stub(&callSignature, &netOfGates);
TryStoreICByNameStubBuilder optimizer(&callSignature, stub.GetEnvironment());
stub.SetStubBuilder(&optimizer);
stub.GenerateCircuit(stubModule.GetCompilationConfig());
netOfGates.PrintAllGates();
auto cfg = Scheduler::Run(&netOfGates);
PrintCircuitByBasicBlock(cfg, netOfGates);
@ -404,8 +421,10 @@ HWTEST_F_L0(StubTest, TryStoreICByValue)
Circuit netOfGates;
CallSignature callSignature;
TryStoreICByValueCallSignature::Initialize(&callSignature);
TryStoreICByValueStubBuilder optimizer(&callSignature, &netOfGates);
optimizer.GenerateCircuit(stubModule.GetCompilationConfig());
Stub stub(&callSignature, &netOfGates);
TryStoreICByValueStubBuilder optimizer(&callSignature, stub.GetEnvironment());
stub.SetStubBuilder(&optimizer);
stub.GenerateCircuit(stubModule.GetCompilationConfig());
netOfGates.PrintAllGates();
auto cfg = Scheduler::Run(&netOfGates);
PrintCircuitByBasicBlock(cfg, netOfGates);
@ -869,8 +888,10 @@ HWTEST_F_L0(StubTest, GetPropertyByIndexStub)
Circuit netOfGates;
CallSignature callSignature;
GetPropertyByIndexCallSignature::Initialize(&callSignature);
GetPropertyByIndexStubBuilder optimizer(&callSignature, &netOfGates);
optimizer.GenerateCircuit(stubModule.GetCompilationConfig());
Stub stub(&callSignature, &netOfGates);
GetPropertyByIndexStubBuilder optimizer(&callSignature, stub.GetEnvironment());
stub.SetStubBuilder(&optimizer);
stub.GenerateCircuit(stubModule.GetCompilationConfig());
netOfGates.PrintAllGates();
auto cfg = Scheduler::Run(&netOfGates);
PrintCircuitByBasicBlock(cfg, netOfGates);
@ -901,8 +922,10 @@ HWTEST_F_L0(StubTest, SetPropertyByIndexStub)
Circuit netOfGates;
CallSignature callSignature;
SetPropertyByIndexCallSignature::Initialize(&callSignature);
SetPropertyByIndexStubBuilder optimizer(&callSignature, &netOfGates);
optimizer.GenerateCircuit(stubModule.GetCompilationConfig());
Stub stub(&callSignature, &netOfGates);
SetPropertyByIndexStubBuilder optimizer(&callSignature, stub.GetEnvironment());
stub.SetStubBuilder(&optimizer);
stub.GenerateCircuit(stubModule.GetCompilationConfig());
netOfGates.PrintAllGates();
bool result = Verifier::Run(&netOfGates);
ASSERT_TRUE(result);
@ -937,8 +960,10 @@ HWTEST_F_L0(StubTest, GetPropertyByNameStub)
Circuit netOfGates;
CallSignature callSignature;
GetPropertyByNameCallSignature::Initialize(&callSignature);
GetPropertyByNameStubBuilder optimizer(&callSignature, &netOfGates);
optimizer.GenerateCircuit(stubModule.GetCompilationConfig());
Stub stub(&callSignature, &netOfGates);
GetPropertyByNameStubBuilder optimizer(&callSignature, stub.GetEnvironment());
stub.SetStubBuilder(&optimizer);
stub.GenerateCircuit(stubModule.GetCompilationConfig());
netOfGates.PrintAllGates();
bool result = Verifier::Run(&netOfGates);
ASSERT_TRUE(result);
@ -975,8 +1000,10 @@ HWTEST_F_L0(StubTest, SetPropertyByNameStub)
Circuit netOfGates;
CallSignature callSignature;
SetPropertyByNameCallSignature::Initialize(&callSignature);
SetPropertyByNameStubBuilder optimizer(&callSignature, &netOfGates);
optimizer.GenerateCircuit(stubModule.GetCompilationConfig());
Stub stub(&callSignature, &netOfGates);
SetPropertyByNameStubBuilder optimizer(&callSignature, stub.GetEnvironment());
stub.SetStubBuilder(&optimizer);
stub.GenerateCircuit(stubModule.GetCompilationConfig());
netOfGates.PrintAllGates();
auto cfg = Scheduler::Run(&netOfGates);
PrintCircuitByBasicBlock(cfg, netOfGates);
@ -1010,8 +1037,10 @@ HWTEST_F_L0(StubTest, GetPropertyByValueStub)
Circuit netOfGates2;
CallSignature callSignature;
GetPropertyByIndexCallSignature::Initialize(&callSignature);
GetPropertyByIndexStubBuilder getPropertyByIndexStub(&callSignature, &netOfGates2);
getPropertyByIndexStub.GenerateCircuit(stubModule.GetCompilationConfig());
Stub stub(&callSignature, &netOfGates2);
GetPropertyByIndexStubBuilder optimizer(&callSignature, stub.GetEnvironment());
stub.SetStubBuilder(&optimizer);
stub.GenerateCircuit(stubModule.GetCompilationConfig());
netOfGates2.PrintAllGates();
auto cfg2 = Scheduler::Run(&netOfGates2);
LLVMIRBuilder llvmBuilder2(&cfg2, &netOfGates2, &stubModule, getPropertyByIndexfunction,
@ -1022,8 +1051,10 @@ HWTEST_F_L0(StubTest, GetPropertyByValueStub)
Circuit netOfGates1;
CallSignature callSignature1;
GetPropertyByNameCallSignature::Initialize(&callSignature1);
GetPropertyByNameStubBuilder getPropertyByNameStub(&callSignature1, &netOfGates1);
getPropertyByNameStub.GenerateCircuit(stubModule.GetCompilationConfig());
Stub stub1(&callSignature1, &netOfGates1);
GetPropertyByNameStubBuilder getPropertyByNameStub(&callSignature, stub1.GetEnvironment());
stub1.SetStubBuilder(&getPropertyByNameStub);
stub1.GenerateCircuit(stubModule.GetCompilationConfig());
bool result = Verifier::Run(&netOfGates1);
ASSERT_TRUE(result);
auto cfg1 = Scheduler::Run(&netOfGates1);
@ -1035,8 +1066,10 @@ HWTEST_F_L0(StubTest, GetPropertyByValueStub)
Circuit netOfGates;
CallSignature callSignature2;
GetPropertyByValueCallSignature::Initialize(&callSignature2);
GetPropertyByValueStubBuilder optimizer(&callSignature2, &netOfGates);
optimizer.GenerateCircuit(stubModule.GetCompilationConfig());
Stub stub2(&callSignature2, &netOfGates);
GetPropertyByValueStubBuilder getPropertyByValueStub(&callSignature, stub2.GetEnvironment());
stub2.SetStubBuilder(&getPropertyByValueStub);
stub2.GenerateCircuit(stubModule.GetCompilationConfig());
netOfGates.PrintAllGates();
result = Verifier::Run(&netOfGates);
ASSERT_TRUE(result);
@ -1104,8 +1137,10 @@ HWTEST_F_L0(StubTest, FastTypeOfTest)
Circuit netOfGates;
CallSignature callSignature;
TypeOfCallSignature::Initialize(&callSignature);
TypeOfStubBuilder optimizer(&callSignature, &netOfGates);
optimizer.GenerateCircuit(stubModule.GetCompilationConfig());
Stub stub(&callSignature, &netOfGates);
TypeOfStubBuilder optimizer(&callSignature, stub.GetEnvironment());
stub.SetStubBuilder(&optimizer);
stub.GenerateCircuit(stubModule.GetCompilationConfig());
netOfGates.PrintAllGates();
bool verRes = Verifier::Run(&netOfGates);
ASSERT_TRUE(verRes);
@ -1192,8 +1227,10 @@ HWTEST_F_L0(StubTest, FastEqualTest)
Circuit netOfGates;
CallSignature callSignature;
EqualCallSignature::Initialize(&callSignature);
EqualStubBuilder optimizer(&callSignature, &netOfGates);
optimizer.GenerateCircuit(stubModule.GetCompilationConfig());
Stub stub(&callSignature, &netOfGates);
EqualStubBuilder optimizer(&callSignature, stub.GetEnvironment());
stub.SetStubBuilder(&optimizer);
stub.GenerateCircuit(stubModule.GetCompilationConfig());
netOfGates.PrintAllGates();
auto cfg = Scheduler::Run(&netOfGates);
PrintCircuitByBasicBlock(cfg, netOfGates);
@ -1425,8 +1462,10 @@ HWTEST_F_L0(StubTest, RelocateTest)
Circuit netOfGates;
CallSignature callSignature;
TestAbsoluteAddressRelocationCallSignature::Initialize(&callSignature);
TestAbsoluteAddressRelocationStubBuilder optimizer(&callSignature, &netOfGates);
optimizer.GenerateCircuit(stubModule.GetCompilationConfig());
Stub stub(&callSignature, &netOfGates);
TestAbsoluteAddressRelocationStubBuilder optimizer(&callSignature, stub.GetEnvironment());
stub.SetStubBuilder(&optimizer);
stub.GenerateCircuit(stubModule.GetCompilationConfig());
netOfGates.PrintAllGates();
bool verRes = Verifier::Run(&netOfGates);
ASSERT_TRUE(verRes);

View File

@ -70,16 +70,16 @@ void TypeLowering::ReplaceHirToCall(GateRef hirGate, GateRef callGate, bool noTh
}
auto uses = acc_.Uses(hirGate);
for (auto it = uses.begin(); it != uses.end(); it++) {
for (auto it = uses.begin(); it != uses.end();) {
if (acc_.GetOpCode(*it) == OpCode::IF_SUCCESS) {
acc_.SetOpCode(*it, OpCode::IF_FALSE);
acc_.ReplaceIn(it, ifBranch);
it = acc_.ReplaceIn(it, ifBranch);
} else {
if (acc_.GetOpCode(*it) == OpCode::IF_EXCEPTION) {
acc_.SetOpCode(*it, OpCode::IF_TRUE);
acc_.ReplaceIn(it, ifBranch);
it = acc_.ReplaceIn(it, ifBranch);
} else {
acc_.ReplaceIn(it, callGate);
it = acc_.ReplaceIn(it, callGate);
}
}
}

View File

@ -19,6 +19,7 @@
#include "ecmascript/containers/containers_private.h"
#include "ecmascript/ecma_runtime_call_info.h"
#include "ecmascript/global_env.h"
#include "ecmascript/js_api/js_api_lightweightset_iterator.h"
#include "ecmascript/js_handle.h"
#include "ecmascript/js_tagged_value-inl.h"

View File

@ -3276,29 +3276,21 @@ void InterpreterAssembly::HandleDefineClassWithBufferPrefId16Imm16Imm16V8V8(
JSTaggedValue acc, int32_t hotnessCounter)
{
uint16_t methodId = READ_INST_16_1();
uint16_t imm = READ_INST_16_3();
uint16_t length = READ_INST_16_5();
uint16_t v0 = READ_INST_8_7();
uint16_t v1 = READ_INST_8_8();
LOG_INST() << "intrinsics::defineclasswithbuffer"
<< " method id:" << methodId << " literal id:" << imm << " lexenv: v" << v0 << " parent: v" << v1;
<< " method id:" << methodId << " lexenv: v" << v0 << " parent: v" << v1;
JSFunction *classTemplate = JSFunction::Cast(
ConstantPool::Cast(constpool.GetTaggedObject())->GetObjectFromCache(methodId).GetTaggedObject());
ASSERT(classTemplate != nullptr);
TaggedArray *literalBuffer = TaggedArray::Cast(
ConstantPool::Cast(constpool.GetTaggedObject())->GetObjectFromCache(imm).GetTaggedObject());
JSTaggedValue lexenv = GET_VREG_VALUE(v0);
JSTaggedValue proto = GET_VREG_VALUE(v1);
JSTaggedValue res;
if (LIKELY(!classTemplate->GetResolved())) {
res = SlowRuntimeStub::ResolveClass(thread, JSTaggedValue(classTemplate), literalBuffer,
proto, lexenv, ConstantPool::Cast(constpool.GetTaggedObject()));
} else {
res = SlowRuntimeStub::CloneClassFromTemplate(thread, JSTaggedValue(classTemplate),
proto, lexenv, ConstantPool::Cast(constpool.GetTaggedObject()));
}
SAVE_PC();
JSTaggedValue res = SlowRuntimeStub::CloneClassFromTemplate(thread, JSTaggedValue(classTemplate),
proto, lexenv, ConstantPool::Cast(constpool.GetTaggedObject()));
INTERPRETER_RETURN_IF_ABRUPT(res);
ASSERT(res.IsClassConstructor());

View File

@ -13,7 +13,6 @@
* limitations under the License.
*/
#include "ecmascript/js_api/js_api_arraylist_iterator.h"
#include "ecmascript/builtins/builtins_errors.h"
@ -21,7 +20,6 @@
#include "ecmascript/base/typed_array_helper.h"
#include "ecmascript/global_env.h"
#include "ecmascript/js_api/js_api_arraylist.h"
#include "ecmascript/object_factory.h"
namespace panda::ecmascript {

View File

@ -18,13 +18,13 @@
#include "ecmascript/base/builtins_base.h"
#include "ecmascript/global_env_constants-inl.h"
#include "ecmascript/js_api/js_api_deque.h"
#include "ecmascript/js_handle.h"
#include "ecmascript/js_iterator.h"
#include "ecmascript/js_handle.h"
#include "ecmascript/js_tagged_value-inl.h"
#include "ecmascript/js_thread.h"
#include "ecmascript/tagged_array.h"
namespace panda::ecmascript {
using BuiltinsBase = base::BuiltinsBase;
// DequeIteratorPrototype%.next ( )

View File

@ -21,7 +21,6 @@
#include "ecmascript/object_factory.h"
#include "ecmascript/tagged_tree.h"
namespace panda::ecmascript {
using BuiltinsBase = base::BuiltinsBase;
JSTaggedValue JSAPITreeSetIterator::Next(EcmaRuntimeCallInfo *argv)

View File

@ -626,10 +626,6 @@ JSTaggedValue RuntimeStubs::RuntimeCloneClassFromTemplate(JSThread *thread, cons
JSHandle<JSObject> clsPrototype(thread, ctor->GetFunctionPrototype());
bool canShareHClass = false;
if (ctor->GetClass()->GetProto() == base.GetTaggedValue()) {
canShareHClass = true;
}
JSHandle<JSFunction> cloneClass = factory->CloneClassCtor(ctor, lexenv, canShareHClass);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<JSObject> cloneClassPrototype = factory->CloneObjectLiteral(JSHandle<JSObject>(clsPrototype), lexenv,

View File

@ -14,7 +14,6 @@
*/
#include "ecmascript/stubs/runtime_stubs-inl.h"
#include "ecmascript/accessor_data.h"
#include "ecmascript/base/number_helper.h"
#include "ecmascript/compiler/call_signature.h"
@ -41,7 +40,6 @@
#include "ecmascript/object_factory.h"
#include "ecmascript/tagged_dictionary.h"
#include "ecmascript/ts_types/ts_loader.h"
#include "libpandabase/utils/string_helpers.h"
namespace panda::ecmascript {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 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
@ -13,22 +13,11 @@
* limitations under the License.
*/
#include "ecmascript/ecma_string.h"
#include "ecmascript/js_function.h"
#include "ecmascript/js_hclass.h"
#include "ecmascript/js_object-inl.h"
#include "ecmascript/js_tagged_value-inl.h"
#include "ecmascript/object_factory.h"
#include "ecmascript/js_symbol.h"
#include "ecmascript/tests/test_helper.h"
using JSSymbol = panda::ecmascript::JSSymbol;
using JSTaggedValue = panda::ecmascript::JSTaggedValue;
using LexicalEnv = panda::ecmascript::LexicalEnv;
using JSHClass = panda::ecmascript::JSHClass;
using ObjectFactory = panda::ecmascript::ObjectFactory;
template<typename T>
using JSHandle = panda::ecmascript::JSHandle<T>;
using namespace panda;
using namespace panda::ecmascript;
namespace panda::test {
class JSSymbolTest : public testing::Test {
@ -57,4 +46,46 @@ public:
ecmascript::EcmaHandleScope *scope {nullptr};
JSThread *thread {nullptr};
};
HWTEST_F_L0(JSSymbolTest, SymbolCreate)
{
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
JSHandle<JSSymbol> normallSymbol = factory->NewJSSymbol();
EXPECT_TRUE(*normallSymbol != nullptr);
EXPECT_TRUE(normallSymbol->GetDescription().IsUndefined());
JSHandle<JSSymbol> privateSymbol = factory->NewPrivateSymbol();
EXPECT_TRUE(*privateSymbol != nullptr);
EXPECT_TRUE(privateSymbol->IsPrivate());
EXPECT_TRUE(privateSymbol->GetDescription().IsUndefined());
JSHandle<JSTaggedValue> symbolName(factory->NewFromASCII("hello world"));
JSHandle<JSSymbol> privateNameSymbol = factory->NewPrivateNameSymbol(symbolName);
EXPECT_TRUE(*privateNameSymbol != nullptr);
EXPECT_TRUE(privateNameSymbol->IsPrivateNameSymbol());
EXPECT_FALSE(privateNameSymbol->GetDescription().IsUndefined());
JSHandle<JSSymbol> wellKnowSymbol = factory->NewWellKnownSymbol(symbolName);
EXPECT_TRUE(*wellKnowSymbol != nullptr);
EXPECT_TRUE(wellKnowSymbol->IsWellKnownSymbol());
EXPECT_FALSE(wellKnowSymbol->GetDescription().IsUndefined());
}
HWTEST_F_L0(JSSymbolTest, SymbolEqual)
{
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
JSHandle<JSTaggedValue> helloWord(factory->NewFromASCII("hello world"));
JSHandle<JSTaggedValue> hiWord(factory->NewFromASCII("hi world"));
JSHandle<JSTaggedValue> helloWord1SymbolVal(factory->NewPrivateNameSymbol(helloWord));
JSHandle<JSTaggedValue> helloWord2SymbolVal(factory->NewPrivateNameSymbol(helloWord));
JSHandle<JSTaggedValue> hiWordSymbolVal(factory->NewPrivateNameSymbol(hiWord));
JSSymbol *helloWord1Symbol = JSSymbol::Cast(helloWord1SymbolVal->GetTaggedObject());
JSSymbol *helloWord2Symbol = JSSymbol::Cast(helloWord2SymbolVal->GetTaggedObject());
JSSymbol *hiWordSymbol = JSSymbol::Cast(hiWordSymbolVal->GetTaggedObject());
EXPECT_TRUE(JSSymbol::Equal(*helloWord1Symbol, *helloWord2Symbol));
helloWord2Symbol->SetFlags(1);
EXPECT_FALSE(JSSymbol::Equal(*helloWord1Symbol, *helloWord2Symbol));
EXPECT_FALSE(JSSymbol::Equal(*helloWord1Symbol, *hiWordSymbol));
}
} // namespace panda::test

View File

@ -52,6 +52,7 @@ group("ark_js_moduletest") {
"trycatch:trycatchAction",
"typearray:typearrayAction",
"watch:watchAction",
"wrapperclassfunc:wrapperclassfuncAction",
"yieldstar:yieldstarAction",
]
if (!is_debug) {
@ -98,6 +99,7 @@ group("ark_asm_test") {
"throwdyn:throwdynAsmAction",
"trycatch:trycatchAsmAction",
"watch:watchAsmAction",
"wrapperclassfunc:wrapperclassfuncAsmAction",
"yieldstar:yieldstarAsmAction",
]
if (!is_debug) {

View File

@ -0,0 +1,22 @@
# Copyright (c) 2021 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_moduletest_action("wrapperclassfunc") {
extra_modules = [
"wrapperclassfunc",
"wrapperclassfunc",
]
deps = []
}

View File

@ -0,0 +1,19 @@
# Copyright (c) 2021 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.
wrapper call
raw function
wrapper call
raw function
wrapper call
raw function

View File

@ -0,0 +1,38 @@
/*
* Copyright (c) 2021 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.
*/
(() => {
function WrapperFunc(propertyDesc) {
const method = propertyDesc.value
propertyDesc.value = () => {
print("wrapper call")
method()
}
}
function decorate(obj, key) {
var method = Object.getOwnPropertyDescriptor(obj, key)
WrapperFunc(method)
Object.defineProperty(obj, key, method)
}
class RawClass {
printString() {
print("raw function")
}
}
decorate(RawClass.prototype, "printString")
globalThis.cls = new RawClass()
globalThis.cls.printString()
})()