Path: blob/master/runtime/compiler/x/codegen/X86HelperLinkage.hpp
6004 views
/*******************************************************************************1* Copyright (c) 2000, 2020 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* 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-exception20*******************************************************************************/2122#ifndef X86_HELPERLINKAGE_INCL23#define X86_HELPERLINKAGE_INCL2425#include "codegen/CodeGenerator.hpp"26#include "codegen/Linkage.hpp"27#include "env/jittypes.h"28#include "infra/Array.hpp"2930namespace TR { class CodeGenerator; }31namespace TR { class Instruction; }32namespace TR { class LabelSymbol; }33namespace TR { class Node; }34namespace TR { class RegisterDependencyConditions; }3536#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."3738// This class implements following calling conventions on different platforms:39// X86-32 Windows and Linux: fastcall40// X86-64 Windows : Microsoft x64 calling convention, an extension of fastcall41// X86-64 Linux : System V AMD64 ABI42// This initial version has following limitations:43// 1. Floating point parameters are not currently in-support.44// 2. Return value can only be at most pointer size, i.e. DWORD on X86-32 and QWORD on X86-64.45namespace J946{4748namespace X8649{5051class HelperCallSite52{53public:54HelperCallSite(TR::Node* callNode, TR::CodeGenerator* cg) :55_cg(cg),56_Node(callNode),57_ReturnType(callNode->getDataType()),58_SymRef(callNode->getSymbolReference()),59_Params(cg->trMemory())60{}61HelperCallSite(TR::Node* callNode, TR::DataType callReturnType, TR::SymbolReference* callSymRef, TR::CodeGenerator* cg) :62_cg(cg),63_Node(callNode),64_ReturnType(callReturnType),65_SymRef(callSymRef),66_Params(cg->trMemory())67{}68void AddParam(TR::Register* param)69{70TR_ASSERT(param->getKind() == TR_GPR, "HelperCallSite now only support GPR");71_Params.add(param);72}73TR::Register* BuildCall();74TR::CodeGenerator* cg() const75{76return _cg;77}78static const uint32_t PreservedRegisterMapForGC;79static const bool CalleeCleanup;80static const bool RegisterParameterShadowOnStack;81static const size_t StackSlotSize;82static const size_t NumberOfIntParamRegisters;83static const size_t StackIndexAdjustment;84static const TR::RealRegister::RegNum IntParamRegisters[];85static const TR::RealRegister::RegNum CallerSavedRegisters[];86static const TR::RealRegister::RegNum CalleeSavedRegisters[];8788private:89TR::CodeGenerator* _cg;90TR::Node* _Node;91TR::SymbolReference* _SymRef;92TR::DataType _ReturnType;93TR_Array<TR::Register*> _Params;94};9596class HelperLinkage : public TR::Linkage97{98public:99HelperLinkage(TR::CodeGenerator *cg) : TR::Linkage(cg) {}100const TR::X86LinkageProperties& getProperties() { return _Properties; }101virtual void createPrologue(TR::Instruction *cursor) { TR_ASSERT(false, IMCOMPLETELINKAGE); }102virtual void createEpilogue(TR::Instruction *cursor) { TR_ASSERT(false, IMCOMPLETELINKAGE); }103virtual TR::Register* buildIndirectDispatch(TR::Node *callNode) { TR_ASSERT(false, "Indirect dispatch is not currently supported"); return NULL; }104virtual TR::Register* buildDirectDispatch(TR::Node* callNode, bool spillFPRegs)105{106HelperCallSite CallSite(callNode, cg());107// Evaluate children108for (int i = 0; i < callNode->getNumChildren(); i++)109{110cg()->evaluate(callNode->getChild(i));111}112// Setup parameters113for (int i = callNode->getNumChildren() - 1; i >= 0; i--)114{115CallSite.AddParam(callNode->getChild(i)->getRegister());116}117// Supply VMThread as the first parameter if necessary118if (!callNode->getSymbol()->getMethodSymbol()->isSystemLinkageDispatch())119{120CallSite.AddParam(cg()->getVMThreadRegister());121}122TR::Register* ret = CallSite.BuildCall();123// Release children124for (int i = 0; i < callNode->getNumChildren(); i++)125{126cg()->decReferenceCount(callNode->getChild(i));127}128return ret;129}130131private:132TR::X86LinkageProperties _Properties;133};134135}136137}138139#endif140141142