Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/compiler/optimizer/EstimateCodeSize.hpp
6000 views
1
/*******************************************************************************
2
* Copyright (c) 2000, 2021 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
21
*******************************************************************************/
22
23
#ifndef ESTIMATECS_INCL
24
#define ESTIMATECS_INCL
25
26
#include <stddef.h>
27
#include <stdint.h>
28
#include "env/TRMemory.hpp"
29
#include "infra/Flags.hpp"
30
#include "optimizer/Inliner.hpp"
31
32
class TR_CallStack;
33
namespace TR { class Compilation; }
34
struct TR_CallSite;
35
struct TR_CallTarget;
36
37
#define MAX_ECS_RECURSION_DEPTH 30
38
39
enum EcsCleanupErrorStates {
40
ECS_NORMAL = 0,
41
ECS_RECURSION_DEPTH_THRESHOLD_EXCEEDED,
42
ECS_OPTIMISTIC_SIZE_THRESHOLD_EXCEEDED,
43
ECS_VISITED_COUNT_THRESHOLD_EXCEEDED,
44
ECS_REAL_SIZE_THRESHOLD_EXCEEDED,
45
ECS_ARGUMENTS_INCOMPATIBLE,
46
ECS_CALLSITES_CREATION_FAILED
47
};
48
49
class TR_EstimateCodeSize
50
{
51
public:
52
53
void * operator new (size_t size, TR::Allocator allocator) { return allocator.allocate(size); }
54
void operator delete (void *, TR::Allocator allocator) {}
55
56
// {
57
// TR_EstimateCodeSize::raiiWrapper lexicalScopeObject(....);
58
// TR_EstimateCodeSize *ecs = lexicalScopeObject->getCodeEstimator();
59
// ... do whatever you gotta do
60
// } // estimator will be automatically freed by lexicalScopeObject regardless of how scope is exited
61
class raiiWrapper
62
{
63
public:
64
raiiWrapper(TR_InlinerBase *inliner, TR_InlinerTracer *tracer, int32_t sizeThreshold)
65
{
66
_estimator = TR_EstimateCodeSize::get(inliner, tracer, sizeThreshold);
67
}
68
69
~raiiWrapper()
70
{
71
TR_EstimateCodeSize::release(_estimator);
72
}
73
74
TR_EstimateCodeSize *getCodeEstimator()
75
{
76
return _estimator;
77
}
78
79
private:
80
TR_EstimateCodeSize *_estimator;
81
};
82
83
TR_EstimateCodeSize() { }
84
85
static TR_EstimateCodeSize *get(TR_InlinerBase *inliner, TR_InlinerTracer *tracer, int32_t sizeThreshold);
86
static void release(TR_EstimateCodeSize *estimator);
87
88
bool calculateCodeSize(TR_CallTarget *, TR_CallStack *, bool recurseDown = true);
89
90
int32_t getSize() { return _realSize; }
91
virtual int32_t getOptimisticSize() { return 0; } // override in subclasses that support partial inlining
92
const char *getError();
93
int32_t getSizeThreshold() { return _sizeThreshold; }
94
bool aggressivelyInlineThrows() { return _aggressivelyInlineThrows; }
95
bool recursedTooDeep() { return _recursedTooDeep; }
96
bool isLeaf() { return _isLeaf; }
97
98
int32_t getNumOfEstimatedCalls() { return _numOfEstimatedCalls; }
99
/*
100
* \brief
101
* tell whether this callsite has inlineable target
102
*/
103
bool isInlineable(TR_CallStack *, TR_CallSite *callsite);
104
105
TR::Compilation *comp() { return _inliner->comp(); }
106
TR_InlinerTracer *tracer() { return _tracer; }
107
TR_InlinerBase* getInliner() { return _inliner; }
108
109
protected:
110
111
virtual bool estimateCodeSize(TR_CallTarget *, TR_CallStack * , bool recurseDown = true) = 0;
112
113
114
/*
115
* \brief common tasks requiring completion before returning from estimation
116
*
117
* \param errorState
118
* an unique state used to identify where estimate code size bailed out
119
*/
120
bool returnCleanup(EcsCleanupErrorStates errorState);
121
122
/* Fields */
123
124
bool _isLeaf;
125
bool _foundThrow;
126
bool _hasExceptionHandlers;
127
bool _mayHaveVirtualCallProfileInfo;
128
bool _aggressivelyInlineThrows;
129
int32_t _throwCount;
130
131
int32_t _recursionDepth;
132
bool _recursedTooDeep;
133
134
int32_t _sizeThreshold;
135
int32_t _realSize; // size once we know if we're doing a partial inline or not
136
EcsCleanupErrorStates _error;
137
138
int32_t _totalBCSize; // Pure accumulation of the bytecode size. Used by HW-based inlining.
139
140
TR_InlinerBase * _inliner;
141
TR_InlinerTracer *_tracer;
142
143
int32_t _numOfEstimatedCalls;
144
bool _hasNonColdCalls;
145
};
146
147
#endif
148
149