Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/compiler/aarch64/codegen/ARM64PrivateLinkage.hpp
6004 views
1
/*******************************************************************************
2
* Copyright (c) 2019, 2022 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 ARM64_PRIVATELINKAGE_INCL
24
#define ARM64_PRIVATELINKAGE_INCL
25
26
#include "codegen/Linkage.hpp"
27
#include "codegen/LinkageConventionsEnum.hpp"
28
#include "codegen/PrivateLinkage.hpp"
29
30
#include "infra/Assert.hpp"
31
32
class TR_ResolvedMethod;
33
34
namespace TR { class CodeGenerator; }
35
namespace TR { class Instruction; }
36
namespace TR { class Register; }
37
namespace TR { class ResolvedMethodSymbol; }
38
39
namespace J9
40
{
41
42
struct ARM64PICItem
43
{
44
TR_ALLOC(TR_Memory::Linkage);
45
46
ARM64PICItem(TR_OpaqueClassBlock *clazz, TR_ResolvedMethod *method, float freq) :
47
_clazz(clazz), _method(method), _frequency(freq) {}
48
49
TR_OpaqueClassBlock *_clazz;
50
TR_ResolvedMethod *_method;
51
float _frequency;
52
};
53
54
namespace ARM64
55
{
56
57
class PrivateLinkage : public J9::PrivateLinkage
58
{
59
protected:
60
61
TR::ARM64LinkageProperties _properties;
62
63
/**
64
* @brief Builds method arguments
65
* @param[in] node : caller node
66
* @param[in] dependencies : register dependency conditions
67
* @param[in] linkage : linkage type
68
*/
69
int32_t buildPrivateLinkageArgs(
70
TR::Node *callNode,
71
TR::RegisterDependencyConditions *dependencies,
72
TR_LinkageConventions linkage);
73
74
/**
75
* @brief Store informaiton of outgoing memory argument
76
* @param[in] argReg : argument register
77
* @param[in] offset : offset from Java SP
78
* @param[in] opCode : opcode for storing argument
79
* @param[in] memArg : MemoryArgument
80
*/
81
void pushOutgoingMemArgument(
82
TR::Register *argReg,
83
int32_t offset,
84
TR::InstOpCode::Mnemonic opCode,
85
TR::ARM64MemoryArgument &memArg);
86
87
public:
88
89
/**
90
* @brief Constructor
91
* @param[in] cg : CodeGenerator
92
*/
93
PrivateLinkage(TR::CodeGenerator *cg);
94
95
/**
96
* @brief Answers linkage properties
97
* @return linkage properties
98
*/
99
virtual TR::ARM64LinkageProperties& getProperties();
100
101
/**
102
* @brief Gets the RightToLeft flag
103
* @return RightToLeft flag
104
*/
105
virtual uint32_t getRightToLeft();
106
107
/**
108
* @brief Adjust stack index so that local references are aligned properly
109
* @param[in/out] stackIndex : index on stack
110
*/
111
virtual void alignLocalReferences(uint32_t &stackIndex);
112
/**
113
* @brief Maps symbols to locations on stack
114
* @param[in] method : method for which symbols are mapped on stack
115
*/
116
virtual void mapStack(TR::ResolvedMethodSymbol *method);
117
/**
118
* @brief Maps an automatic symbol to an index on stack
119
* @param[in] p : automatic symbol
120
* @param[in/out] stackIndex : index on stack
121
*/
122
virtual void mapSingleAutomatic(TR::AutomaticSymbol *p, uint32_t &stackIndex);
123
/**
124
* @brief Maps an automatic symbol to an index on stack
125
* @param[in] p : automatic symbol
126
* @param[in] size : size
127
* @param[in/out] stackIndex : index on stack
128
*/
129
virtual void mapSingleAutomatic(TR::AutomaticSymbol *p, uint32_t size, uint32_t &stackIndex);
130
131
/**
132
* @brief Initializes ARM64 RealRegister linkage
133
*/
134
virtual void initARM64RealRegisterLinkage();
135
136
/**
137
* @brief Calculates the amount of frame space required to save the
138
* preserved registers in this method.
139
*
140
* @param[out] registerSaveDescription : the bitmask of registers to preserve
141
* @param[out] numGPRsSaved : the number of GPRs saved
142
*
143
* @return : number of bytes required to reserve on the frame for
144
* preserved registers
145
*/
146
int32_t calculatePreservedRegisterSaveSize(
147
uint32_t &registerSaveDescription,
148
uint32_t &numGPRsSaved);
149
150
/**
151
* @brief Copy linkage register indices to parameter symbols
152
*
153
* @param[in] method : the resolved method symbol
154
*/
155
void setParameterLinkageRegisterIndex(TR::ResolvedMethodSymbol *method);
156
157
/**
158
* @brief Creates method prologue
159
* @param[in] cursor : instruction cursor
160
*/
161
virtual void createPrologue(TR::Instruction *cursor);
162
/**
163
* @brief Creates method epilogue
164
* @param[in] cursor : instruction cursor
165
*/
166
virtual void createEpilogue(TR::Instruction *cursor);
167
168
/**
169
* @brief Loads all parameters passed on the stack from the interpreter into
170
* the corresponding JITed method private linkage register.
171
*
172
* @param[in] cursor : the TR::Instruction to begin generating
173
* the load sequence at.
174
*
175
* @return : the instruction cursor after the load sequence
176
*/
177
virtual TR::Instruction *loadStackParametersToLinkageRegisters(TR::Instruction *cursor);
178
179
/**
180
* @brief Stores parameters passed in linkage registers to the stack. This method is used only in FSD mode.
181
*
182
* @param[in] cursor : the instruction cursor to begin inserting copy instructions
183
*
184
* @return The instruction cursor after copies inserted.
185
*/
186
virtual TR::Instruction *saveParametersToStack(TR::Instruction *cursor);
187
188
/**
189
* @brief Builds method arguments
190
* @param[in] node : caller node
191
* @param[in] dependencies : register dependency conditions
192
*/
193
virtual int32_t buildArgs(
194
TR::Node *callNode,
195
TR::RegisterDependencyConditions *dependencies);
196
197
/**
198
* @brief Builds direct dispatch to method
199
* @param[in] node : caller node
200
*/
201
virtual TR::Register *buildDirectDispatch(TR::Node *callNode);
202
203
/**
204
* @brief Builds direct call to method
205
* @param[in] node : caller node
206
* @param[in] callSymRef : target symbol reference
207
* @param[in] dependencies : register dependency conditions
208
* @param[in] pp : linkage properties
209
* @param[in] argSize : size of arguments
210
*/
211
void buildDirectCall(
212
TR::Node *callNode,
213
TR::SymbolReference *callSymRef,
214
TR::RegisterDependencyConditions *dependencies,
215
const TR::ARM64LinkageProperties &pp,
216
uint32_t argSize);
217
218
/**
219
* @brief Builds indirect dispatch to method
220
* @param[in] node : caller node
221
*/
222
virtual TR::Register *buildIndirectDispatch(TR::Node *callNode);
223
224
/**
225
* @brief Builds virtual dispatch to method
226
* @param[in] node : caller node
227
* @param[in] dependencies : register dependency conditions
228
* @param[in] argSize : size of arguments
229
*/
230
virtual void buildVirtualDispatch(
231
TR::Node *callNode,
232
TR::RegisterDependencyConditions *dependencies,
233
uint32_t argSize);
234
235
/**
236
* @brief J9 private linkage override of OMR function
237
*/
238
virtual intptr_t entryPointFromCompiledMethod();
239
240
/**
241
* @brief J9 private linkage override of OMR function
242
*/
243
virtual intptr_t entryPointFromInterpretedMethod();
244
245
/**
246
* J9 private linkage override of OMR function
247
*/
248
virtual void performPostBinaryEncoding();
249
250
/**
251
* @return Retrieve the interpretedMethodEntryPoint instruction
252
*/
253
TR::Instruction *getInterpretedMethodEntryPoint() { return _interpretedMethodEntryPoint; }
254
255
/**
256
* @brief Sets the interpreted method entry point instruction
257
* @param[in] ins : interpreted method entry point instruction
258
*/
259
void setInterpretedMethodEntryPoint(TR::Instruction *ins) { _interpretedMethodEntryPoint = ins; }
260
261
/**
262
* @return Retrieve the jittedMethodEntryPoint instruction
263
*/
264
TR::Instruction *getJittedMethodEntryPoint() { return _jittedMethodEntryPoint; }
265
266
/**
267
* @brief Sets the jitted method entry point instruction
268
* @param[in] ins : jitted method entry point instruction
269
*/
270
void setJittedMethodEntryPoint(TR::Instruction *ins) { _jittedMethodEntryPoint = ins; }
271
272
protected:
273
274
/**
275
* The first TR::Instruction of the method when called from an interpreted method.
276
*/
277
TR::Instruction *_interpretedMethodEntryPoint;
278
279
/**
280
* The first TR::Instruction of the method when called from a jitted method.
281
*/
282
TR::Instruction *_jittedMethodEntryPoint;
283
284
private:
285
286
// Tactical GRA
287
static uint32_t _globalRegisterNumberToRealRegisterMap[];
288
};
289
290
291
class HelperLinkage : public PrivateLinkage
292
{
293
public:
294
295
/**
296
* @brief Constructor
297
* @param[in] cg : CodeGenerator
298
* @param[in] helperLinkage : linkage convention
299
*/
300
HelperLinkage(TR::CodeGenerator *cg, TR_LinkageConventions helperLinkage) : _helperLinkage(helperLinkage), PrivateLinkage(cg)
301
{
302
TR_ASSERT(helperLinkage == TR_Helper || helperLinkage == TR_CHelper, "Unexpected helper linkage convention");
303
}
304
305
/**
306
* @brief Builds method arguments for helper call
307
* @param[in] node : caller node
308
* @param[in] dependencies : register dependency conditions
309
* @return total size that arguments occupy on Java stack
310
*/
311
virtual int32_t buildArgs(
312
TR::Node *callNode,
313
TR::RegisterDependencyConditions *dependencies);
314
protected:
315
316
TR_LinkageConventions _helperLinkage;
317
318
};
319
320
}
321
322
}
323
324
#endif
325
326