Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/CodeGen/include/Luau/LoweringStats.h
2727 views
1
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
2
#pragma once
3
4
#include <algorithm>
5
#include <string>
6
#include <vector>
7
8
namespace Luau
9
{
10
namespace CodeGen
11
{
12
13
struct BlockLinearizationStats
14
{
15
unsigned int constPropInstructionCount = 0;
16
double timeSeconds = 0.0;
17
18
BlockLinearizationStats& operator+=(const BlockLinearizationStats& that)
19
{
20
this->constPropInstructionCount += that.constPropInstructionCount;
21
this->timeSeconds += that.timeSeconds;
22
23
return *this;
24
}
25
26
BlockLinearizationStats operator+(const BlockLinearizationStats& other) const
27
{
28
BlockLinearizationStats result(*this);
29
result += other;
30
return result;
31
}
32
};
33
34
enum FunctionStatsFlags
35
{
36
// Enable stats collection per function
37
FunctionStats_Enable = 1 << 0,
38
// Compute function bytecode summary
39
FunctionStats_BytecodeSummary = 1 << 1,
40
};
41
42
struct FunctionStats
43
{
44
std::string name;
45
int line = -1;
46
unsigned bcodeCount = 0;
47
unsigned irCount = 0;
48
unsigned asmCount = 0;
49
unsigned asmSize = 0;
50
std::vector<std::vector<unsigned>> bytecodeSummary;
51
};
52
53
struct LoweringStats
54
{
55
unsigned totalFunctions = 0;
56
unsigned skippedFunctions = 0;
57
int spillsToSlot = 0;
58
int spillsToRestore = 0;
59
unsigned maxSpillSlotsUsed = 0;
60
unsigned blocksPreOpt = 0;
61
unsigned blocksPostOpt = 0;
62
unsigned maxBlockInstructions = 0;
63
64
int regAllocErrors = 0;
65
int loweringErrors = 0;
66
67
BlockLinearizationStats blockLinearizationStats;
68
69
unsigned functionStatsFlags = 0;
70
std::vector<FunctionStats> functions;
71
72
LoweringStats operator+(const LoweringStats& other) const
73
{
74
LoweringStats result(*this);
75
result += other;
76
return result;
77
}
78
79
LoweringStats& operator+=(const LoweringStats& that)
80
{
81
this->totalFunctions += that.totalFunctions;
82
this->skippedFunctions += that.skippedFunctions;
83
this->spillsToSlot += that.spillsToSlot;
84
this->spillsToRestore += that.spillsToRestore;
85
this->maxSpillSlotsUsed = std::max(this->maxSpillSlotsUsed, that.maxSpillSlotsUsed);
86
this->blocksPreOpt += that.blocksPreOpt;
87
this->blocksPostOpt += that.blocksPostOpt;
88
this->maxBlockInstructions = std::max(this->maxBlockInstructions, that.maxBlockInstructions);
89
90
this->regAllocErrors += that.regAllocErrors;
91
this->loweringErrors += that.loweringErrors;
92
93
this->blockLinearizationStats += that.blockLinearizationStats;
94
95
if (this->functionStatsFlags & FunctionStats_Enable)
96
this->functions.insert(this->functions.end(), that.functions.begin(), that.functions.end());
97
98
return *this;
99
}
100
};
101
102
} // namespace CodeGen
103
} // namespace Luau
104
105