Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/Compiler/src/CostModel.h
2725 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 "Luau/Ast.h"
5
#include "Luau/DenseHash.h"
6
7
namespace Luau
8
{
9
namespace Compile
10
{
11
12
struct Constant;
13
14
// cost model: 8 bytes, where first byte is the baseline cost, and the next 7 bytes are discounts for when variable #i is constant
15
uint64_t modelCost(
16
AstNode* root,
17
AstLocal* const* vars,
18
size_t varCount,
19
const DenseHashMap<AstExprCall*, int>& builtins,
20
const DenseHashMap<AstExpr*, Constant>& constants
21
);
22
// when additional data is not available, used to test the cost model
23
uint64_t modelCost(AstNode* root, AstLocal* const* vars, size_t varCount);
24
25
// cost is computed as B - sum(Di * Ci), where B is baseline cost, Di is the discount for each variable and Ci is 1 when variable #i is constant
26
int computeCost(uint64_t model, const bool* varsConst, size_t varCount);
27
28
// get loop trip count or -1 if we can't compute it precisely
29
int getTripCount(double from, double to, double step);
30
31
} // namespace Compile
32
} // namespace Luau
33
34