Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/compiler/x/codegen/X86HelperLinkage.hpp
6004 views
1
/*******************************************************************************
2
* Copyright (c) 2000, 2020 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 X86_HELPERLINKAGE_INCL
24
#define X86_HELPERLINKAGE_INCL
25
26
#include "codegen/CodeGenerator.hpp"
27
#include "codegen/Linkage.hpp"
28
#include "env/jittypes.h"
29
#include "infra/Array.hpp"
30
31
namespace TR { class CodeGenerator; }
32
namespace TR { class Instruction; }
33
namespace TR { class LabelSymbol; }
34
namespace TR { class Node; }
35
namespace TR { class RegisterDependencyConditions; }
36
37
#define IMCOMPLETELINKAGE "This class is only used to generate call-out sequence but no call-in sequence, so it is not used as a complete linkage."
38
39
// This class implements following calling conventions on different platforms:
40
// X86-32 Windows and Linux: fastcall
41
// X86-64 Windows : Microsoft x64 calling convention, an extension of fastcall
42
// X86-64 Linux : System V AMD64 ABI
43
// This initial version has following limitations:
44
// 1. Floating point parameters are not currently in-support.
45
// 2. Return value can only be at most pointer size, i.e. DWORD on X86-32 and QWORD on X86-64.
46
namespace J9
47
{
48
49
namespace X86
50
{
51
52
class HelperCallSite
53
{
54
public:
55
HelperCallSite(TR::Node* callNode, TR::CodeGenerator* cg) :
56
_cg(cg),
57
_Node(callNode),
58
_ReturnType(callNode->getDataType()),
59
_SymRef(callNode->getSymbolReference()),
60
_Params(cg->trMemory())
61
{}
62
HelperCallSite(TR::Node* callNode, TR::DataType callReturnType, TR::SymbolReference* callSymRef, TR::CodeGenerator* cg) :
63
_cg(cg),
64
_Node(callNode),
65
_ReturnType(callReturnType),
66
_SymRef(callSymRef),
67
_Params(cg->trMemory())
68
{}
69
void AddParam(TR::Register* param)
70
{
71
TR_ASSERT(param->getKind() == TR_GPR, "HelperCallSite now only support GPR");
72
_Params.add(param);
73
}
74
TR::Register* BuildCall();
75
TR::CodeGenerator* cg() const
76
{
77
return _cg;
78
}
79
static const uint32_t PreservedRegisterMapForGC;
80
static const bool CalleeCleanup;
81
static const bool RegisterParameterShadowOnStack;
82
static const size_t StackSlotSize;
83
static const size_t NumberOfIntParamRegisters;
84
static const size_t StackIndexAdjustment;
85
static const TR::RealRegister::RegNum IntParamRegisters[];
86
static const TR::RealRegister::RegNum CallerSavedRegisters[];
87
static const TR::RealRegister::RegNum CalleeSavedRegisters[];
88
89
private:
90
TR::CodeGenerator* _cg;
91
TR::Node* _Node;
92
TR::SymbolReference* _SymRef;
93
TR::DataType _ReturnType;
94
TR_Array<TR::Register*> _Params;
95
};
96
97
class HelperLinkage : public TR::Linkage
98
{
99
public:
100
HelperLinkage(TR::CodeGenerator *cg) : TR::Linkage(cg) {}
101
const TR::X86LinkageProperties& getProperties() { return _Properties; }
102
virtual void createPrologue(TR::Instruction *cursor) { TR_ASSERT(false, IMCOMPLETELINKAGE); }
103
virtual void createEpilogue(TR::Instruction *cursor) { TR_ASSERT(false, IMCOMPLETELINKAGE); }
104
virtual TR::Register* buildIndirectDispatch(TR::Node *callNode) { TR_ASSERT(false, "Indirect dispatch is not currently supported"); return NULL; }
105
virtual TR::Register* buildDirectDispatch(TR::Node* callNode, bool spillFPRegs)
106
{
107
HelperCallSite CallSite(callNode, cg());
108
// Evaluate children
109
for (int i = 0; i < callNode->getNumChildren(); i++)
110
{
111
cg()->evaluate(callNode->getChild(i));
112
}
113
// Setup parameters
114
for (int i = callNode->getNumChildren() - 1; i >= 0; i--)
115
{
116
CallSite.AddParam(callNode->getChild(i)->getRegister());
117
}
118
// Supply VMThread as the first parameter if necessary
119
if (!callNode->getSymbol()->getMethodSymbol()->isSystemLinkageDispatch())
120
{
121
CallSite.AddParam(cg()->getVMThreadRegister());
122
}
123
TR::Register* ret = CallSite.BuildCall();
124
// Release children
125
for (int i = 0; i < callNode->getNumChildren(); i++)
126
{
127
cg()->decReferenceCount(callNode->getChild(i));
128
}
129
return ret;
130
}
131
132
private:
133
TR::X86LinkageProperties _Properties;
134
};
135
136
}
137
138
}
139
140
#endif
141
142