luau/CodeGen/include/Luau/IrAnalysis.h

84 lines
1.8 KiB
C
Raw Normal View History

2023-01-28 05:28:45 +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 03:20:04 +08:00
#include <bitset>
2023-03-03 21:45:38 +08:00
#include <utility>
2023-03-11 03:20:04 +08:00
#include <vector>
2023-03-03 21:45:38 +08:00
#include <stdint.h>
2023-01-28 05:28:45 +08:00
namespace Luau
{
namespace CodeGen
{
2023-03-03 21:45:38 +08:00
struct IrBlock;
2023-01-28 05:28:45 +08:00
struct IrFunction;
2023-02-11 02:50:54 +08:00
void updateUseCounts(IrFunction& function);
void updateLastUseLocations(IrFunction& function);
2023-01-28 05:28:45 +08:00
2023-03-03 21:45:38 +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 03:20:04 +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;
};
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 22:59:30 +08:00
std::vector<RegisterSet> def;
2023-03-11 03:20:04 +08:00
std::vector<RegisterSet> out;
RegisterSet captured;
};
void computeCfgInfo(IrFunction& function);
struct BlockIteratorWrapper
{
2023-03-25 01:34:14 +08:00
const uint32_t* itBegin = nullptr;
const uint32_t* itEnd = nullptr;
2023-03-11 03:20:04 +08:00
bool empty() const
{
return itBegin == itEnd;
}
size_t size() const
{
return size_t(itEnd - itBegin);
}
2023-03-25 01:34:14 +08:00
const uint32_t* begin() const
2023-03-11 03:20:04 +08:00
{
return itBegin;
}
2023-03-25 01:34:14 +08:00
const uint32_t* end() const
2023-03-11 03:20:04 +08:00
{
return itEnd;
}
};
2023-03-25 01:34:14 +08:00
BlockIteratorWrapper predecessors(const CfgInfo& cfg, uint32_t blockIdx);
BlockIteratorWrapper successors(const CfgInfo& cfg, uint32_t blockIdx);
2023-03-11 03:20:04 +08:00
2023-01-28 05:28:45 +08:00
} // namespace CodeGen
} // namespace Luau