2022-02-12 08:15:41 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ECMASCRIPT_COMPILER_GATE_ACCESSOR_H
|
|
|
|
#define ECMASCRIPT_COMPILER_GATE_ACCESSOR_H
|
|
|
|
|
2022-07-18 11:54:48 +00:00
|
|
|
#include "ecmascript/compiler/circuit.h"
|
2023-03-16 11:32:31 +00:00
|
|
|
#include "ecmascript/compiler/gate_meta_data.h"
|
2023-03-08 07:05:35 +00:00
|
|
|
#include "ecmascript/pgo_profiler/pgo_profiler_type.h"
|
2022-02-12 08:15:41 +00:00
|
|
|
|
|
|
|
namespace panda::ecmascript::kungfu {
|
2023-02-13 05:46:34 +00:00
|
|
|
|
|
|
|
class StateDepend {
|
|
|
|
public:
|
|
|
|
StateDepend()
|
|
|
|
: state_(Circuit::NullGate()), depend_(Circuit::NullGate()) {}
|
|
|
|
|
|
|
|
explicit StateDepend(GateRef state, GateRef depend)
|
|
|
|
: state_(state), depend_(depend) {}
|
|
|
|
|
|
|
|
GateRef State() const
|
|
|
|
{
|
|
|
|
return state_;
|
|
|
|
}
|
|
|
|
|
|
|
|
GateRef Depend() const
|
|
|
|
{
|
|
|
|
return depend_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetState(GateRef state)
|
|
|
|
{
|
|
|
|
state_ = state;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetDepend(GateRef depend)
|
|
|
|
{
|
|
|
|
depend_ = depend;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
GateRef state_;
|
|
|
|
GateRef depend_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Edge {
|
|
|
|
public:
|
|
|
|
explicit Edge(GateRef gate, size_t index) : gate_(gate), index_(static_cast<uint32_t>(index)) {}
|
|
|
|
|
|
|
|
GateRef GetGate() const
|
|
|
|
{
|
|
|
|
return gate_;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t GetIndex() const
|
|
|
|
{
|
|
|
|
return static_cast<size_t>(index_);
|
|
|
|
}
|
|
|
|
|
2023-02-20 09:33:41 +00:00
|
|
|
void SetIndex(size_t index)
|
|
|
|
{
|
|
|
|
index_ = static_cast<uint32_t>(index);
|
|
|
|
}
|
|
|
|
|
2023-02-13 05:46:34 +00:00
|
|
|
private:
|
|
|
|
GateRef gate_;
|
|
|
|
uint32_t index_;
|
|
|
|
};
|
|
|
|
|
2022-03-02 08:06:19 +00:00
|
|
|
class GateAccessor {
|
2022-02-16 10:54:54 +00:00
|
|
|
public:
|
2022-03-02 08:06:19 +00:00
|
|
|
// do not create new gate or modify self during iteration
|
2022-07-24 03:21:28 +00:00
|
|
|
struct ConstUseIterator {
|
2023-01-03 02:32:21 +00:00
|
|
|
ConstUseIterator(const Circuit* circuit, const Out* out) : circuit_(circuit), out_(out)
|
2022-03-02 08:06:19 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
GateRef operator*() const
|
|
|
|
{
|
2022-09-23 00:44:11 +00:00
|
|
|
if (out_ != nullptr) {
|
|
|
|
return circuit_->GetGateRef(out_->GetGateConst());
|
|
|
|
}
|
|
|
|
return 0;
|
2022-03-02 08:06:19 +00:00
|
|
|
}
|
|
|
|
|
2022-07-24 03:21:28 +00:00
|
|
|
const ConstUseIterator operator++()
|
2022-03-02 08:06:19 +00:00
|
|
|
{
|
2022-11-25 07:22:42 +00:00
|
|
|
ASSERT(out_ != nullptr);
|
2022-03-02 08:06:19 +00:00
|
|
|
if (!out_->IsNextOutNull()) {
|
|
|
|
out_ = out_->GetNextOutConst();
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
out_ = nullptr;
|
|
|
|
return *this;
|
|
|
|
}
|
2022-07-24 03:21:28 +00:00
|
|
|
const ConstUseIterator operator++(int)
|
2022-03-02 08:06:19 +00:00
|
|
|
{
|
2022-07-24 03:21:28 +00:00
|
|
|
ConstUseIterator tmp = *this;
|
2022-03-02 08:06:19 +00:00
|
|
|
++(*this);
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t GetIndex() const
|
|
|
|
{
|
|
|
|
ASSERT(out_ != nullptr);
|
|
|
|
return out_->GetIndex();
|
|
|
|
}
|
|
|
|
|
2022-03-07 02:58:13 +00:00
|
|
|
OpCode GetOpCode() const
|
|
|
|
{
|
|
|
|
ASSERT(out_ != nullptr);
|
|
|
|
return out_->GetGateConst()->GetOpCode();
|
|
|
|
}
|
|
|
|
|
2022-11-23 08:58:08 +00:00
|
|
|
friend bool operator == (const ConstUseIterator& a, const ConstUseIterator& b)
|
2022-03-02 08:06:19 +00:00
|
|
|
{
|
|
|
|
return a.out_ == b.out_;
|
|
|
|
};
|
2022-11-23 08:58:08 +00:00
|
|
|
friend bool operator != (const ConstUseIterator& a, const ConstUseIterator& b)
|
2022-03-02 08:06:19 +00:00
|
|
|
{
|
|
|
|
return a.out_ != b.out_;
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
const Circuit* circuit_;
|
|
|
|
const Out* out_;
|
|
|
|
};
|
|
|
|
|
|
|
|
// do not create new gate or modify self during iteration
|
2022-07-24 03:21:28 +00:00
|
|
|
struct UseIterator {
|
2023-01-03 02:32:21 +00:00
|
|
|
UseIterator(Circuit* circuit, Out* out) : circuit_(circuit), out_(out)
|
2022-03-04 14:14:59 +00:00
|
|
|
{
|
|
|
|
}
|
2022-03-02 08:06:19 +00:00
|
|
|
|
2022-05-31 11:20:56 +00:00
|
|
|
GateRef operator*() const
|
2022-03-02 08:06:19 +00:00
|
|
|
{
|
2022-09-23 00:44:11 +00:00
|
|
|
if (out_ != nullptr) {
|
|
|
|
return circuit_->GetGateRef(out_->GetGate());
|
|
|
|
}
|
|
|
|
return 0;
|
2022-03-02 08:06:19 +00:00
|
|
|
}
|
|
|
|
|
2022-07-24 03:21:28 +00:00
|
|
|
const UseIterator& operator++()
|
2022-03-02 08:06:19 +00:00
|
|
|
{
|
2022-11-25 07:22:42 +00:00
|
|
|
ASSERT(out_ != nullptr);
|
2022-07-24 03:21:28 +00:00
|
|
|
out_ = out_->IsNextOutNull() ? nullptr
|
|
|
|
: out_->GetNextOut();
|
2022-03-02 08:06:19 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2022-07-24 03:21:28 +00:00
|
|
|
UseIterator operator++(int)
|
2022-03-02 08:06:19 +00:00
|
|
|
{
|
2022-07-24 03:21:28 +00:00
|
|
|
UseIterator tmp = *this;
|
2022-03-02 08:06:19 +00:00
|
|
|
++(*this);
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t GetIndex() const
|
|
|
|
{
|
|
|
|
ASSERT(out_ != nullptr);
|
|
|
|
return out_->GetIndex();
|
|
|
|
}
|
|
|
|
|
2023-02-13 05:46:34 +00:00
|
|
|
Edge GetEdge()
|
|
|
|
{
|
|
|
|
ASSERT(out_ != nullptr);
|
|
|
|
UseIterator it = *this;
|
|
|
|
return Edge(*it, GetIndex());
|
|
|
|
}
|
|
|
|
|
2022-03-07 02:58:13 +00:00
|
|
|
OpCode GetOpCode() const
|
|
|
|
{
|
|
|
|
ASSERT(out_ != nullptr);
|
|
|
|
return out_->GetGateConst()->GetOpCode();
|
|
|
|
}
|
|
|
|
|
2022-11-23 08:58:08 +00:00
|
|
|
friend bool operator == (const UseIterator& a, const UseIterator& b)
|
2022-03-02 08:06:19 +00:00
|
|
|
{
|
|
|
|
return a.out_ == b.out_;
|
|
|
|
};
|
2022-11-23 08:58:08 +00:00
|
|
|
friend bool operator != (const UseIterator& a, const UseIterator& b)
|
2022-03-02 08:06:19 +00:00
|
|
|
{
|
|
|
|
return a.out_ != b.out_;
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2022-03-04 14:14:59 +00:00
|
|
|
Circuit* circuit_;
|
2022-03-02 08:06:19 +00:00
|
|
|
Out* out_;
|
|
|
|
};
|
2022-02-16 10:54:54 +00:00
|
|
|
|
2022-03-02 08:06:19 +00:00
|
|
|
struct ConstInsIterator {
|
2023-01-03 02:32:21 +00:00
|
|
|
ConstInsIterator(const Circuit* circuit, const In* in) : circuit_(circuit), in_(in)
|
2022-03-02 08:06:19 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
GateRef operator*() const
|
|
|
|
{
|
2022-07-18 11:54:48 +00:00
|
|
|
return circuit_->GetGateRef(in_->GetGateConst());
|
2022-03-02 08:06:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const ConstInsIterator& operator++()
|
|
|
|
{
|
|
|
|
in_++;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
ConstInsIterator operator++(int)
|
|
|
|
{
|
|
|
|
ConstInsIterator tmp = *this;
|
|
|
|
++(*this);
|
|
|
|
return tmp;
|
|
|
|
}
|
2022-03-07 02:58:13 +00:00
|
|
|
|
|
|
|
OpCode GetOpCode() const
|
|
|
|
{
|
|
|
|
ASSERT(in_ != nullptr);
|
|
|
|
return in_->GetGateConst()->GetOpCode();
|
|
|
|
}
|
|
|
|
|
2022-03-02 08:06:19 +00:00
|
|
|
friend bool operator== (const ConstInsIterator& a, const ConstInsIterator& b)
|
|
|
|
{
|
|
|
|
return a.in_ == b.in_;
|
|
|
|
};
|
|
|
|
friend bool operator!= (const ConstInsIterator& a, const ConstInsIterator& b)
|
|
|
|
{
|
|
|
|
return a.in_ != b.in_;
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
const Circuit* circuit_;
|
|
|
|
const In* in_;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct InsIterator {
|
2023-01-03 02:32:21 +00:00
|
|
|
InsIterator(const Circuit* circuit, In* in) : circuit_(circuit), in_(in)
|
2022-03-02 08:06:19 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
GateRef operator*()
|
|
|
|
{
|
2022-07-18 11:54:48 +00:00
|
|
|
return circuit_->GetGateRef(in_->GetGate());
|
2022-03-02 08:06:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const InsIterator& operator++()
|
|
|
|
{
|
|
|
|
in_++;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
InsIterator operator++(int)
|
|
|
|
{
|
|
|
|
InsIterator tmp = *this;
|
|
|
|
++(*this);
|
|
|
|
return tmp;
|
|
|
|
}
|
2022-03-07 02:58:13 +00:00
|
|
|
|
|
|
|
OpCode GetOpCode() const
|
|
|
|
{
|
|
|
|
ASSERT(in_ != nullptr);
|
|
|
|
return in_->GetGateConst()->GetOpCode();
|
|
|
|
}
|
|
|
|
|
2022-03-02 08:06:19 +00:00
|
|
|
friend bool operator== (const InsIterator& a, const InsIterator& b)
|
|
|
|
{
|
|
|
|
return a.in_ == b.in_;
|
|
|
|
};
|
|
|
|
friend bool operator!= (const InsIterator& a, const InsIterator& b)
|
|
|
|
{
|
|
|
|
return a.in_ != b.in_;
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
const Circuit* circuit_;
|
|
|
|
In* in_;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ConstUseWrapper {
|
2022-06-10 07:08:25 +00:00
|
|
|
Circuit* circuit;
|
2022-03-02 08:06:19 +00:00
|
|
|
GateRef gate;
|
|
|
|
auto begin()
|
|
|
|
{
|
2022-06-10 07:08:25 +00:00
|
|
|
return GateAccessor(circuit).ConstUseBegin(gate);
|
2022-03-02 08:06:19 +00:00
|
|
|
}
|
|
|
|
auto end()
|
|
|
|
{
|
2022-06-10 07:08:25 +00:00
|
|
|
return GateAccessor(circuit).ConstUseEnd();
|
2022-03-02 08:06:19 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct UseWrapper {
|
2022-06-10 07:08:25 +00:00
|
|
|
Circuit* circuit;
|
2022-03-02 08:06:19 +00:00
|
|
|
GateRef gate;
|
|
|
|
auto begin()
|
|
|
|
{
|
2022-06-10 07:08:25 +00:00
|
|
|
return GateAccessor(circuit).UseBegin(gate);
|
2022-03-02 08:06:19 +00:00
|
|
|
}
|
|
|
|
auto end()
|
|
|
|
{
|
2022-06-10 07:08:25 +00:00
|
|
|
return GateAccessor(circuit).UseEnd();
|
2022-03-02 08:06:19 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ConstInWrapper {
|
2022-06-10 07:08:25 +00:00
|
|
|
Circuit* circuit;
|
2022-03-02 08:06:19 +00:00
|
|
|
const GateRef gate;
|
|
|
|
auto begin()
|
|
|
|
{
|
2022-06-10 07:08:25 +00:00
|
|
|
return GateAccessor(circuit).ConstInBegin(gate);
|
2022-03-02 08:06:19 +00:00
|
|
|
}
|
|
|
|
auto end()
|
|
|
|
{
|
2022-06-10 07:08:25 +00:00
|
|
|
return GateAccessor(circuit).ConstInEnd(gate);
|
2022-03-02 08:06:19 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct InWrapper {
|
2022-06-10 07:08:25 +00:00
|
|
|
Circuit* circuit;
|
2022-03-02 08:06:19 +00:00
|
|
|
GateRef gate;
|
|
|
|
auto begin()
|
|
|
|
{
|
2022-06-10 07:08:25 +00:00
|
|
|
return GateAccessor(circuit).InBegin(gate);
|
2022-03-02 08:06:19 +00:00
|
|
|
}
|
|
|
|
auto end()
|
|
|
|
{
|
2022-06-10 07:08:25 +00:00
|
|
|
return GateAccessor(circuit).InEnd(gate);
|
2022-03-02 08:06:19 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-08-22 14:09:09 +00:00
|
|
|
ConstInWrapper ConstIns(GateRef gate) const
|
2022-02-16 10:54:54 +00:00
|
|
|
{
|
2022-06-10 07:08:25 +00:00
|
|
|
return { circuit_, gate };
|
2022-02-16 10:54:54 +00:00
|
|
|
}
|
|
|
|
|
2022-11-15 05:06:13 +00:00
|
|
|
InWrapper Ins(GateRef gate) const
|
2022-02-16 10:54:54 +00:00
|
|
|
{
|
2022-06-10 07:08:25 +00:00
|
|
|
return { circuit_, gate };
|
2022-02-16 10:54:54 +00:00
|
|
|
}
|
|
|
|
|
2022-11-29 09:25:20 +00:00
|
|
|
ConstUseWrapper ConstUses(GateRef gate) const
|
2022-02-16 10:54:54 +00:00
|
|
|
{
|
2022-06-10 07:08:25 +00:00
|
|
|
return { circuit_, gate };
|
2022-02-16 10:54:54 +00:00
|
|
|
}
|
|
|
|
|
2022-07-21 06:20:20 +00:00
|
|
|
UseWrapper Uses(GateRef gate)
|
2022-02-16 10:54:54 +00:00
|
|
|
{
|
2022-06-10 07:08:25 +00:00
|
|
|
return { circuit_, gate };
|
2022-02-16 10:54:54 +00:00
|
|
|
}
|
|
|
|
|
2022-03-02 08:06:19 +00:00
|
|
|
explicit GateAccessor(Circuit *circuit) : circuit_(circuit)
|
|
|
|
{
|
|
|
|
}
|
2022-06-10 07:08:25 +00:00
|
|
|
|
2022-03-28 13:29:37 +00:00
|
|
|
Circuit *GetCircuit() const
|
|
|
|
{
|
|
|
|
return circuit_;
|
|
|
|
}
|
2022-02-16 10:54:54 +00:00
|
|
|
|
2022-02-12 08:15:41 +00:00
|
|
|
~GateAccessor() = default;
|
2022-08-18 11:56:44 +00:00
|
|
|
void GetAllGates(std::vector<GateRef>& gates) const;
|
2022-07-19 12:44:46 +00:00
|
|
|
size_t GetNumIns(GateRef gate) const;
|
|
|
|
OpCode GetOpCode(GateRef gate) const;
|
2022-08-23 06:10:11 +00:00
|
|
|
bool IsGCRelated(GateRef gate) const;
|
2022-12-09 03:23:41 +00:00
|
|
|
uint64_t TryGetValue(GateRef gate) const;
|
|
|
|
ICmpCondition GetICmpCondition(GateRef gate) const;
|
|
|
|
FCmpCondition GetFCmpCondition(GateRef gate) const;
|
|
|
|
ConstDataId GetConstDataId(GateRef gate) const;
|
2023-03-31 06:54:43 +00:00
|
|
|
size_t GetOffset(GateRef gate) const;
|
2022-12-09 03:23:41 +00:00
|
|
|
size_t GetVirtualRegisterIndex(GateRef gate) const;
|
|
|
|
TypedLoadOp GetTypedLoadOp(GateRef gate) const;
|
|
|
|
TypedStoreOp GetTypedStoreOp(GateRef gate) const;
|
|
|
|
TypedBinOp GetTypedBinaryOp(GateRef gate) const;
|
2023-03-08 07:05:35 +00:00
|
|
|
PGOSampleType GetTypedBinaryType(GateRef gate) const;
|
|
|
|
bool HasNumberType(GateRef gate) const;
|
2022-12-09 03:23:41 +00:00
|
|
|
GateType GetParamGateType(GateRef gate) const;
|
2023-04-15 11:10:06 +00:00
|
|
|
TypedUnaryAccessor GetTypedUnAccessor(GateRef gate) const;
|
|
|
|
TypedJumpAccessor GetTypedJumpAccessor(GateRef gate) const;
|
2022-11-29 09:25:20 +00:00
|
|
|
uint64_t GetConstantValue(GateRef gate) const;
|
2023-01-06 10:04:16 +00:00
|
|
|
const ChunkVector<char>& GetConstantString(GateRef gate) const;
|
2023-03-27 08:51:45 +00:00
|
|
|
bool IsVtable(GateRef gate) const;
|
2023-03-17 07:02:11 +00:00
|
|
|
uint32_t TryGetPcOffset(GateRef gate) const;
|
2023-03-08 07:05:35 +00:00
|
|
|
PGOSampleType TryGetPGOType(GateRef gate) const;
|
|
|
|
void TrySetPGOType(GateRef gate, PGOSampleType type);
|
2022-11-09 02:05:55 +00:00
|
|
|
EcmaOpcode GetByteCodeOpcode(GateRef gate) const;
|
2022-05-29 23:22:55 +00:00
|
|
|
void Print(GateRef gate) const;
|
2022-09-22 15:53:58 +00:00
|
|
|
void ShortPrint(GateRef gate) const;
|
2022-07-19 12:44:46 +00:00
|
|
|
GateId GetId(GateRef gate) const;
|
|
|
|
GateRef GetValueIn(GateRef gate, size_t idx = 0) const;
|
|
|
|
size_t GetNumValueIn(GateRef gate) const;
|
|
|
|
GateRef GetIn(GateRef gate, size_t idx) const;
|
|
|
|
GateRef GetState(GateRef gate, size_t idx = 0) const;
|
|
|
|
GateRef GetDep(GateRef gate, size_t idx = 0) const;
|
|
|
|
size_t GetImmediateId(GateRef gate) const;
|
2022-02-16 10:54:54 +00:00
|
|
|
void SetDep(GateRef gate, GateRef depGate, size_t idx = 0);
|
2022-07-24 03:21:28 +00:00
|
|
|
UseIterator ReplaceIn(const UseIterator &useIt, GateRef replaceGate);
|
2022-03-03 08:27:02 +00:00
|
|
|
// Add for lowering
|
2022-07-19 12:44:46 +00:00
|
|
|
GateType GetGateType(GateRef gate) const;
|
2023-03-16 11:32:31 +00:00
|
|
|
ValueType GetSrcType(GateRef gate) const;
|
|
|
|
ValueType GetDstType(GateRef gate) const;
|
2022-05-26 04:54:21 +00:00
|
|
|
void SetGateType(GateRef gate, GateType gt);
|
2022-07-19 12:44:46 +00:00
|
|
|
void DeleteIn(GateRef gate, size_t idx);
|
2022-07-24 03:21:28 +00:00
|
|
|
UseIterator DeleteGate(const UseIterator &useIt);
|
|
|
|
void DecreaseIn(const UseIterator &useIt);
|
2022-10-11 13:04:50 +00:00
|
|
|
void DecreaseIn(GateRef gate, size_t index);
|
2022-06-10 07:22:21 +00:00
|
|
|
void NewIn(GateRef gate, size_t idx, GateRef in);
|
2022-07-19 12:44:46 +00:00
|
|
|
size_t GetStateCount(GateRef gate) const;
|
|
|
|
size_t GetDependCount(GateRef gate) const;
|
|
|
|
size_t GetInValueCount(GateRef gate) const;
|
2022-11-10 09:58:04 +00:00
|
|
|
size_t GetInValueStarts(GateRef gate) const;
|
2022-09-13 03:00:53 +00:00
|
|
|
void UpdateAllUses(GateRef gate, GateRef replaceValueIn);
|
2022-06-06 09:41:17 +00:00
|
|
|
void ReplaceIn(GateRef gate, size_t index, GateRef in);
|
|
|
|
void ReplaceStateIn(GateRef gate, GateRef in, size_t index = 0);
|
|
|
|
void ReplaceDependIn(GateRef gate, GateRef in, size_t index = 0);
|
|
|
|
void ReplaceValueIn(GateRef gate, GateRef in, size_t index = 0);
|
|
|
|
void DeleteGate(GateRef gate);
|
|
|
|
MachineType GetMachineType(GateRef gate) const;
|
2022-07-19 12:44:46 +00:00
|
|
|
void SetMachineType(GateRef gate, MachineType type);
|
2022-06-06 09:41:17 +00:00
|
|
|
GateRef GetConstantGate(MachineType bitValue, BitField bitfield, GateType type) const;
|
2023-03-27 09:23:59 +00:00
|
|
|
GateRef GetInitialEnvGate(GateRef jsFunc) const;
|
2023-03-16 11:32:31 +00:00
|
|
|
double GetFloat64FromConstant(GateRef gate) const;
|
|
|
|
int GetInt32FromConstant(GateRef gate) const;
|
2022-07-19 12:44:46 +00:00
|
|
|
bool IsInGateNull(GateRef gate, size_t idx) const;
|
|
|
|
bool IsSelector(GateRef g) const;
|
|
|
|
bool IsControlCase(GateRef gate) const;
|
|
|
|
bool IsLoopHead(GateRef gate) const;
|
2022-07-27 10:21:16 +00:00
|
|
|
bool IsLoopBack(GateRef gate) const;
|
|
|
|
bool IsState(GateRef gate) const;
|
2022-10-08 12:00:06 +00:00
|
|
|
bool IsConstant(GateRef gate) const;
|
2023-01-10 06:25:39 +00:00
|
|
|
bool IsDependSelector(GateRef gate) const;
|
2022-11-09 02:05:55 +00:00
|
|
|
bool IsConstantValue(GateRef gate, uint64_t value) const;
|
2023-03-16 11:32:31 +00:00
|
|
|
bool IsConstantUndefined(GateRef gate) const;
|
|
|
|
bool IsConstantNumber(GateRef gate) const;
|
2022-10-09 12:00:29 +00:00
|
|
|
bool IsTypedOperator(GateRef gate) const;
|
2022-12-30 08:37:07 +00:00
|
|
|
bool IsNotWrite(GateRef gate) const;
|
2023-01-06 10:04:16 +00:00
|
|
|
bool IsDead(GateRef gate) const;
|
2022-12-30 08:37:07 +00:00
|
|
|
bool IsCheckWithOneIn(GateRef gate) const;
|
|
|
|
bool IsCheckWithTwoIns(GateRef gate) const;
|
2022-07-27 10:21:16 +00:00
|
|
|
bool IsSchedulable(GateRef gate) const;
|
2022-07-21 06:20:20 +00:00
|
|
|
MarkCode GetMark(GateRef gate) const;
|
|
|
|
void SetMark(GateRef gate, MarkCode mark);
|
2022-07-27 10:21:16 +00:00
|
|
|
bool IsFinished(GateRef gate) const;
|
|
|
|
bool IsVisited(GateRef gate) const;
|
|
|
|
bool IsNotMarked(GateRef gate) const;
|
|
|
|
void SetFinished(GateRef gate);
|
|
|
|
void SetVisited(GateRef gate);
|
2022-09-13 03:00:53 +00:00
|
|
|
bool IsStateIn(const UseIterator &useIt) const;
|
2022-08-30 02:48:52 +00:00
|
|
|
bool IsDependIn(const UseIterator &useIt) const;
|
|
|
|
bool IsValueIn(const UseIterator &useIt) const;
|
2023-01-06 10:04:16 +00:00
|
|
|
bool IsFrameStateIn(const UseIterator &useIt) const;
|
2023-02-13 05:46:34 +00:00
|
|
|
bool IsStateIn(GateRef gate, size_t index) const;
|
2022-08-30 02:48:52 +00:00
|
|
|
bool IsDependIn(GateRef gate, size_t index) const;
|
2022-07-21 02:14:57 +00:00
|
|
|
bool IsValueIn(GateRef gate, size_t index) const;
|
2023-01-10 06:25:39 +00:00
|
|
|
void GetStateUses(GateRef gate, std::vector<GateRef>& stateUses);
|
|
|
|
void GetDependUses(GateRef gate, std::vector<GateRef>& dependUses);
|
2023-01-06 10:04:16 +00:00
|
|
|
bool IsFrameStateIn(GateRef gate, size_t index) const;
|
2022-12-30 08:37:07 +00:00
|
|
|
void DeleteStateSplitAndFrameState(GateRef gate);
|
2022-10-15 04:09:38 +00:00
|
|
|
void ReplaceGate(GateRef gate, GateRef state, GateRef depend, GateRef value);
|
2022-10-17 11:26:13 +00:00
|
|
|
GateType GetLeftType(GateRef gate) const;
|
|
|
|
GateType GetRightType(GateRef gate) const;
|
2022-11-10 09:58:04 +00:00
|
|
|
GateRef GetGlueFromArgList() const;
|
2022-11-28 01:26:23 +00:00
|
|
|
void GetArgsOuts(std::vector<GateRef>& outs) const;
|
|
|
|
void GetReturnOuts(std::vector<GateRef>& outs) const;
|
2022-12-01 08:50:20 +00:00
|
|
|
|
|
|
|
GateRef GetStateRoot() const
|
|
|
|
{
|
|
|
|
return GetRoot(OpCode::STATE_ENTRY);
|
|
|
|
}
|
|
|
|
|
|
|
|
GateRef GetDependRoot() const
|
|
|
|
{
|
|
|
|
return GetRoot(OpCode::DEPEND_ENTRY);
|
|
|
|
}
|
|
|
|
|
|
|
|
GateRef GetArgRoot() const
|
|
|
|
{
|
|
|
|
return GetRoot(OpCode::ARG_LIST);
|
|
|
|
}
|
|
|
|
|
|
|
|
GateRef GetReturnRoot() const
|
|
|
|
{
|
|
|
|
return GetRoot(OpCode::RETURN_LIST);
|
|
|
|
}
|
|
|
|
|
2023-01-06 10:04:16 +00:00
|
|
|
GateRef GetFrameState(GateRef gate) const;
|
|
|
|
void ReplaceFrameStateIn(GateRef gate, GateRef in);
|
|
|
|
bool HasFrameState(GateRef gate) const;
|
2022-11-29 09:25:20 +00:00
|
|
|
const GateMetaData *GetMetaData(GateRef gate) const;
|
|
|
|
void SetMetaData(GateRef gate, const GateMetaData* meta);
|
2022-04-06 07:17:04 +00:00
|
|
|
|
2023-02-13 05:46:34 +00:00
|
|
|
void ReplaceHirWithIfBranch(GateRef hirGate, StateDepend success,
|
|
|
|
StateDepend exception, GateRef value);
|
|
|
|
void ReplaceHirDirectly(GateRef hirGate, StateDepend replacement, GateRef value);
|
|
|
|
void ReplaceHirAndDeleteIfException(GateRef hirGate,
|
|
|
|
StateDepend replacement, GateRef value);
|
|
|
|
|
2022-02-12 08:15:41 +00:00
|
|
|
private:
|
2023-02-13 05:46:34 +00:00
|
|
|
UseIterator ReplaceHirIfSuccess(const UseIterator &useIt, GateRef state);
|
|
|
|
UseIterator ReplaceHirIfException(const UseIterator &useIt, StateDepend replacement);
|
|
|
|
void ExceptionReturn(GateRef state, GateRef depend);
|
|
|
|
|
2022-12-01 08:50:20 +00:00
|
|
|
GateRef GetRoot(OpCode opcode) const;
|
2022-07-24 03:21:28 +00:00
|
|
|
ConstUseIterator ConstUseBegin(GateRef gate) const
|
2022-03-02 08:06:19 +00:00
|
|
|
{
|
|
|
|
if (circuit_->LoadGatePtrConst(gate)->IsFirstOutNull()) {
|
2022-07-24 03:21:28 +00:00
|
|
|
return ConstUseIterator(circuit_, nullptr);
|
2022-03-02 08:06:19 +00:00
|
|
|
}
|
|
|
|
auto use = circuit_->LoadGatePtrConst(gate)->GetFirstOutConst();
|
2022-07-24 03:21:28 +00:00
|
|
|
return ConstUseIterator(circuit_, use);
|
2022-03-02 08:06:19 +00:00
|
|
|
}
|
|
|
|
|
2022-07-24 03:21:28 +00:00
|
|
|
ConstUseIterator ConstUseEnd() const
|
2022-03-02 08:06:19 +00:00
|
|
|
{
|
2022-07-24 03:21:28 +00:00
|
|
|
return ConstUseIterator(circuit_, nullptr);
|
2022-03-02 08:06:19 +00:00
|
|
|
}
|
|
|
|
|
2022-07-24 03:21:28 +00:00
|
|
|
UseIterator UseBegin(GateRef gate) const
|
2022-03-02 08:06:19 +00:00
|
|
|
{
|
|
|
|
if (circuit_->LoadGatePtrConst(gate)->IsFirstOutNull()) {
|
2022-07-24 03:21:28 +00:00
|
|
|
return UseIterator(circuit_, nullptr);
|
2022-03-02 08:06:19 +00:00
|
|
|
}
|
|
|
|
auto use = circuit_->LoadGatePtr(gate)->GetFirstOut();
|
2022-07-24 03:21:28 +00:00
|
|
|
return UseIterator(circuit_, use);
|
2022-03-02 08:06:19 +00:00
|
|
|
}
|
|
|
|
|
2022-07-24 03:21:28 +00:00
|
|
|
UseIterator UseEnd() const
|
2022-03-02 08:06:19 +00:00
|
|
|
{
|
2022-07-24 03:21:28 +00:00
|
|
|
return UseIterator(circuit_, nullptr);
|
2022-03-02 08:06:19 +00:00
|
|
|
}
|
|
|
|
|
2022-07-19 12:44:46 +00:00
|
|
|
ConstInsIterator ConstInBegin(GateRef gate) const
|
2022-03-02 08:06:19 +00:00
|
|
|
{
|
|
|
|
return ConstInsIterator(circuit_, &reinterpret_cast<const In *>(circuit_->LoadGatePtrConst(gate) + 1)[0]);
|
|
|
|
}
|
|
|
|
|
2022-07-19 12:44:46 +00:00
|
|
|
ConstInsIterator ConstInEnd(GateRef gate) const
|
2022-03-02 08:06:19 +00:00
|
|
|
{
|
|
|
|
auto endIndex = circuit_->LoadGatePtrConst(gate)->GetNumIns();
|
|
|
|
return ConstInsIterator(circuit_,
|
|
|
|
&reinterpret_cast<const In *>(circuit_->LoadGatePtrConst(gate) + 1)[endIndex]);
|
|
|
|
}
|
|
|
|
|
2022-07-19 12:44:46 +00:00
|
|
|
InsIterator InBegin(GateRef gate)
|
2022-03-02 08:06:19 +00:00
|
|
|
{
|
|
|
|
return InsIterator(circuit_, &reinterpret_cast<In *>(circuit_->LoadGatePtr(gate) + 1)[0]);
|
|
|
|
}
|
|
|
|
|
2022-07-19 12:44:46 +00:00
|
|
|
InsIterator InEnd(GateRef gate)
|
2022-03-02 08:06:19 +00:00
|
|
|
{
|
|
|
|
auto endIndex = circuit_->LoadGatePtrConst(gate)->GetNumIns();
|
|
|
|
return InsIterator(circuit_, &reinterpret_cast<In *>(circuit_->LoadGatePtr(gate) + 1)[endIndex]);
|
|
|
|
}
|
|
|
|
|
2022-11-15 05:06:13 +00:00
|
|
|
void GetIns(GateRef gate, std::vector<GateRef>& ins) const;
|
|
|
|
|
|
|
|
void GetOuts(GateRef gate, std::vector<GateRef>& outs) const;
|
|
|
|
|
2022-11-15 12:32:23 +00:00
|
|
|
void GetInStates(GateRef gate, std::vector<GateRef>& ins) const;
|
|
|
|
|
2022-11-15 05:06:13 +00:00
|
|
|
void GetOutStates(GateRef gate, std::vector<GateRef>& outStates) const;
|
|
|
|
|
2022-02-12 08:15:41 +00:00
|
|
|
Circuit *circuit_;
|
2022-11-15 05:06:13 +00:00
|
|
|
|
2022-12-01 08:50:20 +00:00
|
|
|
friend class Circuit;
|
2022-11-15 05:06:13 +00:00
|
|
|
friend class LLVMIRBuilder;
|
|
|
|
friend class Scheduler;
|
2023-01-10 06:25:39 +00:00
|
|
|
friend class EarlyElimination;
|
2022-11-15 05:06:13 +00:00
|
|
|
friend class ArgumentAccessor;
|
|
|
|
friend class BytecodeCircuitBuilder;
|
2023-03-13 06:37:22 +00:00
|
|
|
friend class TSInlineLowering;
|
2023-03-16 11:32:31 +00:00
|
|
|
friend class GraphVisitor;
|
2022-11-15 05:06:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ConstGateAccessor {
|
|
|
|
public:
|
|
|
|
struct ConstInsIterator {
|
2023-01-03 02:32:21 +00:00
|
|
|
ConstInsIterator(const Circuit* circuit, const In* in) : circuit_(circuit), in_(in)
|
2022-11-15 05:06:13 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
GateRef operator*() const
|
|
|
|
{
|
|
|
|
return circuit_->GetGateRef(in_->GetGateConst());
|
|
|
|
}
|
|
|
|
|
|
|
|
const ConstInsIterator& operator++()
|
|
|
|
{
|
|
|
|
in_++;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
ConstInsIterator operator++(int)
|
|
|
|
{
|
|
|
|
ConstInsIterator tmp = *this;
|
|
|
|
++(*this);
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
OpCode GetOpCode() const
|
|
|
|
{
|
|
|
|
ASSERT(in_ != nullptr);
|
|
|
|
return in_->GetGateConst()->GetOpCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
friend bool operator== (const ConstInsIterator& a, const ConstInsIterator& b)
|
|
|
|
{
|
|
|
|
return a.in_ == b.in_;
|
|
|
|
};
|
|
|
|
friend bool operator!= (const ConstInsIterator& a, const ConstInsIterator& b)
|
|
|
|
{
|
|
|
|
return a.in_ != b.in_;
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
const Circuit* circuit_;
|
|
|
|
const In* in_;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ConstInWrapper {
|
|
|
|
const Circuit* circuit;
|
|
|
|
const GateRef gate;
|
|
|
|
auto begin()
|
|
|
|
{
|
|
|
|
return ConstGateAccessor(circuit).ConstInBegin(gate);
|
|
|
|
}
|
|
|
|
auto end()
|
|
|
|
{
|
|
|
|
return ConstGateAccessor(circuit).ConstInEnd(gate);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ConstInWrapper Ins(GateRef gate) const
|
|
|
|
{
|
|
|
|
return { circuit_, gate };
|
|
|
|
}
|
|
|
|
|
|
|
|
explicit ConstGateAccessor(const Circuit *circuit) : circuit_(circuit)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~ConstGateAccessor() = default;
|
|
|
|
|
|
|
|
private:
|
|
|
|
ConstInsIterator ConstInBegin(GateRef gate) const
|
|
|
|
{
|
|
|
|
return ConstInsIterator(circuit_, &reinterpret_cast<const In *>(circuit_->LoadGatePtrConst(gate) + 1)[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
ConstInsIterator ConstInEnd(GateRef gate) const
|
|
|
|
{
|
|
|
|
auto endIndex = circuit_->LoadGatePtrConst(gate)->GetNumIns();
|
|
|
|
return ConstInsIterator(circuit_,
|
|
|
|
&reinterpret_cast<const In *>(circuit_->LoadGatePtrConst(gate) + 1)[endIndex]);
|
|
|
|
}
|
|
|
|
|
|
|
|
const Circuit *circuit_;
|
|
|
|
friend struct ConstInWrapper;
|
2022-02-12 08:15:41 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif // ECMASCRIPT_COMPILER_GATE_ACCESSOR_H
|