2023-01-28 06:28:31 +08:00
|
|
|
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
|
|
#pragma once
|
|
|
|
|
2023-03-11 04:21:07 +08:00
|
|
|
#include <bitset>
|
2023-03-04 04:21:14 +08:00
|
|
|
#include <utility>
|
2023-03-11 04:21:07 +08:00
|
|
|
#include <vector>
|
2023-03-04 04:21:14 +08:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2023-01-28 06:28:31 +08:00
|
|
|
namespace Luau
|
|
|
|
{
|
|
|
|
namespace CodeGen
|
|
|
|
{
|
|
|
|
|
2023-03-04 04:21:14 +08:00
|
|
|
struct IrBlock;
|
2023-01-28 06:28:31 +08:00
|
|
|
struct IrFunction;
|
|
|
|
|
2023-02-11 03:40:38 +08:00
|
|
|
void updateUseCounts(IrFunction& function);
|
|
|
|
|
|
|
|
void updateLastUseLocations(IrFunction& function);
|
2023-01-28 06:28:31 +08:00
|
|
|
|
2023-04-08 05:01:29 +08:00
|
|
|
uint32_t getNextInstUse(IrFunction& function, uint32_t targetInstIdx, uint32_t startInstIdx);
|
|
|
|
|
2023-03-04 04:21:14 +08:00
|
|
|
// Returns how many values are coming into the block (live in) and how many are coming out of the block (live out)
|
|
|
|
std::pair<uint32_t, uint32_t> getLiveInOutValueCount(IrFunction& function, IrBlock& block);
|
|
|
|
uint32_t getLiveInValueCount(IrFunction& function, IrBlock& block);
|
|
|
|
uint32_t getLiveOutValueCount(IrFunction& function, IrBlock& block);
|
|
|
|
|
2023-03-11 04:21:07 +08:00
|
|
|
struct RegisterSet
|
|
|
|
{
|
|
|
|
std::bitset<256> regs;
|
|
|
|
|
|
|
|
// If variadic sequence is active, we track register from which it starts
|
|
|
|
bool varargSeq = false;
|
|
|
|
uint8_t varargStart = 0;
|
|
|
|
};
|
|
|
|
|
2023-05-06 05:52:49 +08:00
|
|
|
void requireVariadicSequence(RegisterSet& sourceRs, const RegisterSet& defRs, uint8_t varargStart);
|
|
|
|
|
2023-03-11 04:21:07 +08:00
|
|
|
struct CfgInfo
|
|
|
|
{
|
|
|
|
std::vector<uint32_t> predecessors;
|
|
|
|
std::vector<uint32_t> predecessorsOffsets;
|
|
|
|
|
|
|
|
std::vector<uint32_t> successors;
|
|
|
|
std::vector<uint32_t> successorsOffsets;
|
|
|
|
|
2023-05-06 05:52:49 +08:00
|
|
|
// VM registers that are live when the block is entered
|
|
|
|
// Additionally, an active variadic sequence can exist at the entry of the block
|
2023-03-11 04:21:07 +08:00
|
|
|
std::vector<RegisterSet> in;
|
2023-05-06 05:52:49 +08:00
|
|
|
|
|
|
|
// VM registers that are defined inside the block
|
|
|
|
// It can also contain a variadic sequence definition if that hasn't been consumed inside the block
|
|
|
|
// Note that this means that checking 'def' set might not be enough to say that register has not been written to
|
2023-03-18 03:20:37 +08:00
|
|
|
std::vector<RegisterSet> def;
|
2023-05-06 05:52:49 +08:00
|
|
|
|
|
|
|
// VM registers that are coming out from the block
|
|
|
|
// These might be registers that are defined inside the block or have been defined at the entry of the block
|
|
|
|
// Additionally, an active variadic sequence can exist at the exit of the block
|
2023-03-11 04:21:07 +08:00
|
|
|
std::vector<RegisterSet> out;
|
|
|
|
|
2023-05-06 05:52:49 +08:00
|
|
|
// VM registers captured by nested closures
|
|
|
|
// This set can never have an active variadic sequence
|
2023-03-11 04:21:07 +08:00
|
|
|
RegisterSet captured;
|
|
|
|
};
|
|
|
|
|
|
|
|
void computeCfgInfo(IrFunction& function);
|
|
|
|
|
|
|
|
struct BlockIteratorWrapper
|
|
|
|
{
|
2023-03-25 02:03:04 +08:00
|
|
|
const uint32_t* itBegin = nullptr;
|
|
|
|
const uint32_t* itEnd = nullptr;
|
2023-03-11 04:21:07 +08:00
|
|
|
|
|
|
|
bool empty() const
|
|
|
|
{
|
|
|
|
return itBegin == itEnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t size() const
|
|
|
|
{
|
|
|
|
return size_t(itEnd - itBegin);
|
|
|
|
}
|
|
|
|
|
2023-03-25 02:03:04 +08:00
|
|
|
const uint32_t* begin() const
|
2023-03-11 04:21:07 +08:00
|
|
|
{
|
|
|
|
return itBegin;
|
|
|
|
}
|
|
|
|
|
2023-03-25 02:03:04 +08:00
|
|
|
const uint32_t* end() const
|
2023-03-11 04:21:07 +08:00
|
|
|
{
|
|
|
|
return itEnd;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-03-25 02:03:04 +08:00
|
|
|
BlockIteratorWrapper predecessors(const CfgInfo& cfg, uint32_t blockIdx);
|
|
|
|
BlockIteratorWrapper successors(const CfgInfo& cfg, uint32_t blockIdx);
|
2023-03-11 04:21:07 +08:00
|
|
|
|
2023-01-28 06:28:31 +08:00
|
|
|
} // namespace CodeGen
|
|
|
|
} // namespace Luau
|