Path: blob/master/runtime/compiler/x/codegen/J9X86Instruction.cpp
6004 views
/*******************************************************************************1* Copyright (c) 2000, 2021 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#include <algorithm>23#include "codegen/J9X86Instruction.hpp"24#include "env/OMRMemory.hpp"25#include "il/Node.hpp"26#include "il/Node_inlines.hpp"27#include "codegen/MemoryReference.hpp"28#include "codegen/UnresolvedDataSnippet.hpp"29#include "codegen/RegisterConstants.hpp"30#include "codegen/CodeGenerator.hpp"31#include "codegen/X86Instruction.hpp"32#include "codegen/Snippet.hpp"33#include "x/codegen/X86Instruction.hpp"34#include "codegen/InstOpCode.hpp"3536////////////////////////////////////////////////////////////////////////////////37// TR::X86MemImmSnippetInstruction:: member functions38////////////////////////////////////////////////////////////////////////////////3940TR::X86MemImmSnippetInstruction::X86MemImmSnippetInstruction(TR::InstOpCode::Mnemonic op,41TR::Node *node,42TR::MemoryReference *mr,43int32_t imm,44TR::UnresolvedDataSnippet *us,45TR::CodeGenerator *cg)46: TR::X86MemImmInstruction(imm, mr, node, op, cg), _unresolvedSnippet(us)47{48}4950TR::X86MemImmSnippetInstruction::X86MemImmSnippetInstruction(TR::Instruction *precedingInstruction,51TR::InstOpCode::Mnemonic op,52TR::MemoryReference *mr,53int32_t imm,54TR::UnresolvedDataSnippet *us,55TR::CodeGenerator *cg)56: TR::X86MemImmInstruction(imm, mr, op, precedingInstruction, cg), _unresolvedSnippet(us)57{58}5960TR::Snippet *TR::X86MemImmSnippetInstruction::getSnippetForGC()61{62if (getUnresolvedSnippet() != NULL)63{64return getUnresolvedSnippet();65}6667return getMemoryReference()->getUnresolvedDataSnippet();68}6970void TR::X86MemImmSnippetInstruction::assignRegisters(TR_RegisterKinds kindsToBeAssigned)71{72TR::X86MemImmInstruction::assignRegisters(kindsToBeAssigned);73if (kindsToBeAssigned & (TR_X87_Mask | TR_FPR_Mask))74{75TR::UnresolvedDataSnippet *snippet = getMemoryReference()->getUnresolvedDataSnippet();76if (snippet)77{78if (kindsToBeAssigned & TR_X87_Mask)79snippet->setNumLiveX87Registers(cg()->machine()->fpGetNumberOfLiveFPRs());8081if (kindsToBeAssigned & TR_FPR_Mask)82snippet->setHasLiveXMMRegisters((cg()->machine()->fpGetNumberOfLiveXMMRs() > 0) ? true : false);83}84}85}8687uint8_t *TR::X86MemImmSnippetInstruction::generateBinaryEncoding()88{89uint8_t *instructionStart = cg()->getBinaryBufferCursor();90uint8_t *cursor = instructionStart;9192setBinaryEncoding(instructionStart);9394cursor = getOpCode().binary(cursor, rexBits());95cursor = getMemoryReference()->generateBinaryEncoding(cursor - 1, this, cg());96if (cursor)97{98if (getOpCode().hasIntImmediate())99{100if (std::find(cg()->comp()->getStaticHCRPICSites()->begin(), cg()->comp()->getStaticHCRPICSites()->end(), this) != cg()->comp()->getStaticHCRPICSites()->end())101{102cg()->jitAdd32BitPicToPatchOnClassRedefinition(((void *)(uintptr_t)getSourceImmediateAsAddress()), (void *) cursor);103}104*(int32_t *)cursor = (int32_t)getSourceImmediate();105if (getUnresolvedSnippet() != NULL)106{107getUnresolvedSnippet()->setAddressOfDataReference(cursor);108}109cursor += 4;110}111else if (getOpCode().hasByteImmediate() || getOpCode().hasSignExtendImmediate())112{113*(int8_t *)cursor = (int8_t)getSourceImmediate();114cursor += 1;115}116else117{118*(int16_t *)cursor = (int16_t)getSourceImmediate();119cursor += 2;120}121setBinaryLength(cursor - getBinaryEncoding());122cg()->addAccumulatedInstructionLengthError(getEstimatedBinaryLength() - getBinaryLength());123return cursor;124}125else126{127// Memref changed during binary encoding; re-generate current instruction.128return generateBinaryEncoding();129}130}131132133134TR::X86CheckAsyncMessagesMemImmInstruction::X86CheckAsyncMessagesMemImmInstruction(135TR::Node *node,136TR::InstOpCode::Mnemonic op,137TR::MemoryReference *mr,138int32_t value,139TR::CodeGenerator *cg) :140TR::X86MemImmInstruction(value, mr, node, op, cg)141{142}143144TR::X86CheckAsyncMessagesMemRegInstruction::X86CheckAsyncMessagesMemRegInstruction(145TR::Node *node,146TR::InstOpCode::Mnemonic op,147TR::MemoryReference *mr,148TR::Register *valueReg,149TR::CodeGenerator *cg) :150TR::X86MemRegInstruction(valueReg, mr, node, op, cg)151{152}153154155TR::X86StackOverflowCheckInstruction::X86StackOverflowCheckInstruction(156TR::Instruction *precedingInstruction,157TR::InstOpCode::Mnemonic op,158TR::Register *cmpRegister,159TR::MemoryReference *mr,160TR::CodeGenerator *cg) :161TR::X86RegMemInstruction(mr, cmpRegister, op, precedingInstruction, cg)162{163}164165uint8_t *TR::X86StackOverflowCheckInstruction::generateBinaryEncoding()166{167uint8_t *cursor = TR::X86RegMemInstruction::generateBinaryEncoding();168return cursor;169};170171172173174TR::X86StackOverflowCheckInstruction *generateStackOverflowCheckInstruction(175TR::Instruction *precedingInstruction,176TR::InstOpCode::Mnemonic op,177TR::Register *cmpRegister,178TR::MemoryReference *mr,179TR::CodeGenerator *cg)180{181return new (cg->trHeapMemory()) TR::X86StackOverflowCheckInstruction(precedingInstruction, op, cmpRegister, mr, cg);182}183184TR::X86CheckAsyncMessagesMemImmInstruction *generateCheckAsyncMessagesInstruction(185TR::Node *node,186TR::InstOpCode::Mnemonic op,187TR::MemoryReference *mr,188int32_t value,189TR::CodeGenerator *cg)190{191return new (cg->trHeapMemory()) TR::X86CheckAsyncMessagesMemImmInstruction(node, op, mr, value, cg);192}193194TR::X86CheckAsyncMessagesMemRegInstruction *generateCheckAsyncMessagesInstruction(195TR::Node *node,196TR::InstOpCode::Mnemonic op,197TR::MemoryReference *mr,198TR::Register *reg,199TR::CodeGenerator *cg)200{201return new (cg->trHeapMemory()) TR::X86CheckAsyncMessagesMemRegInstruction(node, op, mr, reg, cg);202}203204uint8_t *TR::X86CheckAsyncMessagesMemImmInstruction::generateBinaryEncoding()205{206uint8_t *cursor = TR::X86MemImmInstruction::generateBinaryEncoding();207return cursor;208};209210uint8_t *TR::X86CheckAsyncMessagesMemRegInstruction::generateBinaryEncoding()211{212uint8_t *cursor = TR::X86MemRegInstruction::generateBinaryEncoding();213return cursor;214};215216TR::X86MemImmSnippetInstruction *217generateMemImmSnippetInstruction(TR::InstOpCode::Mnemonic op, TR::Node * node, TR::MemoryReference * mr, int32_t imm, TR::UnresolvedDataSnippet * snippet, TR::CodeGenerator *cg)218{219return new (cg->trHeapMemory()) TR::X86MemImmSnippetInstruction(op, node, mr, imm, snippet, cg);220}221222223224