description: Add constant gates caching mechanism for Circuit IR

Signed-off-by: Mingliang Zeng <zengmingliang1@huawei.com>
This commit is contained in:
Mingliang Zeng 2022-02-18 16:56:13 +08:00
parent 877b24e726
commit 245286cf1c
2 changed files with 15 additions and 0 deletions

View File

@ -448,4 +448,16 @@ void Circuit::SetFrameType(panda::ecmascript::FrameType type)
{
frameType_ = type;
}
GateRef Circuit::GetConstantGate(MachineType bitValue, BitField bitfield,
GateType type)
{
if (constantCache_.count({bitValue, bitfield, type})) {
return constantCache_.at({bitValue, bitfield, type});
}
auto gate = NewGate(OpCode(OpCode::CONSTANT), bitValue, bitfield,
{GetCircuitRoot(OpCode(OpCode::CONSTANT_LIST))}, type);
constantCache_[{bitValue, bitfield, type}] = gate;
return gate;
}
} // namespace panda::ecmascript::kungfu

View File

@ -95,6 +95,8 @@ public:
void SetSpaceDataSize(size_t sz);
panda::ecmascript::FrameType GetFrameType() const;
void SetFrameType(panda::ecmascript::FrameType type);
GateRef GetConstantGate(MachineType bitValue, BitField bitfield,
GateType type);
private:
uint8_t *AllocateSpace(size_t gateSize);
@ -106,6 +108,7 @@ private:
size_t gateCount_;
TimeStamp time_;
std::vector<uint8_t> dataSection_ {};
std::map<std::tuple<MachineType, BitField, GateType>, GateRef> constantCache_ {};
panda::ecmascript::FrameType frameType_ {panda::ecmascript::FrameType::OPTIMIZED_FRAME};
};
} // namespace panda::ecmascript::kungfu