mirror of
https://github.com/luau-lang/luau.git
synced 2025-01-20 09:48:08 +00:00
51 lines
1 KiB
C++
51 lines
1 KiB
C++
|
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
||
|
#include "IrAnalysis.h"
|
||
|
|
||
|
#include "IrData.h"
|
||
|
#include "IrUtils.h"
|
||
|
|
||
|
#include <stddef.h>
|
||
|
|
||
|
namespace Luau
|
||
|
{
|
||
|
namespace CodeGen
|
||
|
{
|
||
|
|
||
|
static void recordUse(IrInst& inst, size_t index)
|
||
|
{
|
||
|
LUAU_ASSERT(inst.useCount < 0xffff);
|
||
|
|
||
|
inst.useCount++;
|
||
|
inst.lastUse = uint32_t(index);
|
||
|
}
|
||
|
|
||
|
void updateUseInfo(IrFunction& function)
|
||
|
{
|
||
|
std::vector<IrInst>& instructions = function.instructions;
|
||
|
|
||
|
for (IrInst& inst : instructions)
|
||
|
{
|
||
|
inst.useCount = 0;
|
||
|
inst.lastUse = 0;
|
||
|
}
|
||
|
|
||
|
for (size_t i = 0; i < instructions.size(); ++i)
|
||
|
{
|
||
|
IrInst& inst = instructions[i];
|
||
|
|
||
|
auto checkOp = [&instructions, i](IrOp op) {
|
||
|
if (op.kind == IrOpKind::Inst)
|
||
|
recordUse(instructions[op.index], i);
|
||
|
};
|
||
|
|
||
|
checkOp(inst.a);
|
||
|
checkOp(inst.b);
|
||
|
checkOp(inst.c);
|
||
|
checkOp(inst.d);
|
||
|
checkOp(inst.e);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
} // namespace CodeGen
|
||
|
} // namespace Luau
|