2023-01-27 21:28:45 +00: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-10 19:20:04 +00:00
|
|
|
#include <bitset>
|
2023-03-03 13:45:38 +00:00
|
|
|
#include <utility>
|
2023-03-10 19:20:04 +00:00
|
|
|
#include <vector>
|
2023-03-03 13:45:38 +00:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2023-01-27 21:28:45 +00:00
|
|
|
namespace Luau
|
|
|
|
{
|
|
|
|
namespace CodeGen
|
|
|
|
{
|
|
|
|
|
2023-03-03 13:45:38 +00:00
|
|
|
struct IrBlock;
|
2023-01-27 21:28:45 +00:00
|
|
|
struct IrFunction;
|
|
|
|
|
2023-02-10 18:50:54 +00:00
|
|
|
void updateUseCounts(IrFunction& function);
|
|
|
|
|
|
|
|
void updateLastUseLocations(IrFunction& function);
|
2023-01-27 21:28:45 +00:00
|
|
|
|
2023-04-07 20:56:27 +01:00
|
|
|
uint32_t getNextInstUse(IrFunction& function, uint32_t targetInstIdx, uint32_t startInstIdx);
|
|
|
|
|
2023-03-03 13:45:38 +00: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-10 19:20:04 +00: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;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CfgInfo
|
|
|
|
{
|
|
|
|
std::vector<uint32_t> predecessors;
|
|
|
|
std::vector<uint32_t> predecessorsOffsets;
|
|
|
|
|
|
|
|
std::vector<uint32_t> successors;
|
|
|
|
std::vector<uint32_t> successorsOffsets;
|
|
|
|
|
|
|
|
std::vector<RegisterSet> in;
|
2023-03-17 14:59:30 +00:00
|
|
|
std::vector<RegisterSet> def;
|
2023-03-10 19:20:04 +00:00
|
|
|
std::vector<RegisterSet> out;
|
|
|
|
|
|
|
|
RegisterSet captured;
|
|
|
|
};
|
|
|
|
|
|
|
|
void computeCfgInfo(IrFunction& function);
|
|
|
|
|
|
|
|
struct BlockIteratorWrapper
|
|
|
|
{
|
2023-03-24 17:34:14 +00:00
|
|
|
const uint32_t* itBegin = nullptr;
|
|
|
|
const uint32_t* itEnd = nullptr;
|
2023-03-10 19:20:04 +00:00
|
|
|
|
|
|
|
bool empty() const
|
|
|
|
{
|
|
|
|
return itBegin == itEnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t size() const
|
|
|
|
{
|
|
|
|
return size_t(itEnd - itBegin);
|
|
|
|
}
|
|
|
|
|
2023-03-24 17:34:14 +00:00
|
|
|
const uint32_t* begin() const
|
2023-03-10 19:20:04 +00:00
|
|
|
{
|
|
|
|
return itBegin;
|
|
|
|
}
|
|
|
|
|
2023-03-24 17:34:14 +00:00
|
|
|
const uint32_t* end() const
|
2023-03-10 19:20:04 +00:00
|
|
|
{
|
|
|
|
return itEnd;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-03-24 17:34:14 +00:00
|
|
|
BlockIteratorWrapper predecessors(const CfgInfo& cfg, uint32_t blockIdx);
|
|
|
|
BlockIteratorWrapper successors(const CfgInfo& cfg, uint32_t blockIdx);
|
2023-03-10 19:20:04 +00:00
|
|
|
|
2023-01-27 21:28:45 +00:00
|
|
|
} // namespace CodeGen
|
|
|
|
} // namespace Luau
|