Path: blob/master/runtime/compiler/il/J9ILOps.hpp
6000 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#ifndef J9ILOPS_INCL23#define J9ILOPS_INCL2425#include "il/OMRILOps.hpp"2627namespace J9 {2829class ILOpCode : public OMR::ILOpCode30{3132public:3334ILOpCode() : OMR::ILOpCode() {}35ILOpCode(TR::ILOpCodes opCode) : OMR::ILOpCode(opCode) {}3637/**38* ILTypeProp, ILProp1, ILProp2, ILProp339*/40bool isFloatingPoint() const { return typeProperties().testAny(ILTypeProp::Floating_Point); }41bool isBCDLoadVar() const { return isLoadVar() && getType().isBCD(); }42bool isBCDLoad() const { return isLoad() && getType().isBCD(); }43bool isBCDStore() const { return isStore() && getType().isBCD(); }44bool isPackedConst() const { return isLoadConst() && getType().isAnyPacked(); }45bool isPackedStore() const { return isStore() && getType().isAnyPacked(); }46bool isPackedAdd() const { return isAdd() && getType().isAnyPacked(); }47bool isPackedSubtract() const { return isSub() && getType().isAnyPacked(); }48bool isPackedMultiply() const { return isMul() && getType().isAnyPacked(); }49bool isPackedDivide() const { return isDiv() && getType().isAnyPacked(); }50bool isPackedRemainder() const { return isRem() && getType().isAnyPacked(); }51bool isPackedShift() const { return isShift() && getType().isAnyPacked(); }52bool isPackedRightShift() const { return isRightShift() && getType().isAnyPacked(); }53bool isPackedLeftShift() const { return isLeftShift() && getType().isAnyPacked(); }54bool isBasicPackedArithmetic() const { return (isAdd() || isSub() || isMul() || isDiv() || isRem()) && getType().isAnyPacked(); }5556/**57* ILProp458*/59bool isSetSign() const { return properties4().testAny(ILProp4::SetSign); }60bool isSetSignOnNode() const { return properties4().testAny(ILProp4::SetSignOnNode); }61bool isModifyPrecision() const { return properties4().testAny(ILProp4::ModifyPrecision); }62bool isPackedModifyPrecision() const { return isModifyPrecision() && getType().isAnyPacked(); }63bool isConversionWithFraction() const { return properties4().testAny(ILProp4::ConversionHasFraction); }64bool isBinaryCodedDecimalOp() const { return properties4().testAny(ILProp4::BinaryCodedDecimalOp); }65bool isAnyBCDCompareOp() const { return isBinaryCodedDecimalOp() && isBooleanCompare(); } // isAnyBCDCompareOp is true for all BCD nodes that do some type of compare e.g. pdcmpxx66bool isBCDToNonBCDConversion() const { return isConversion() && isBinaryCodedDecimalOp() && !getType().isBCD(); }67bool isPackedArithmeticOverflowMessage() const { return properties4().testAny(ILProp4::PackedArithmeticOverflowMessage); }68bool isBasicOrSpecialPackedArithmetic() const { return isBasicPackedArithmetic() || isPackedArithmeticOverflowMessage(); }69bool isAnyBCDArithmetic() const { return isBasicOrSpecialPackedArithmetic(); }70bool trackLineNo() const { return properties4().testAny(ILProp4::TrackLineNo); }71bool canHavePaddingAddress() const { return properties4().testAny(ILProp4::CanHavePaddingAddress); }72bool canHaveStorageReferenceHint() const { return properties4().testAny(ILProp4::CanHaveStorageReferenceHint); }73bool canUseStoreAsAnAccumulator() const { return properties4().testAny(ILProp4::CanUseStoreAsAnAccumulator); }747576bool isSignlessBCDType() const {return (getDataType() == TR::UnicodeDecimal); }7778// i.e. a clean with no other side-effects79bool isSimpleBCDClean() const {return _opCode == TR::pdclean; }8081bool isSqrt()82{83return OMR::ILOpCode::isSqrt();84}8586static TR::ILOpCodes setSignOpCode(TR::DataType type)87{88switch (type)89{90case TR::PackedDecimal: return TR::pdSetSign;91default: TR_ASSERT(0, "no setSign opcode for this datatype");92}93return TR::BadILOp;94}9596// returns the index (0->numChild-1) for the sign value to be set or retrieved97static int32_t getSetSignValueIndex(TR::ILOpCodes op)98{99int32_t index = 0;100switch (op)101{102case TR::pdSetSign:103case TR::pd2zdslsSetSign:104case TR::pd2zdstsSetSign:105index = 1; // child 2106break;107case TR::pdshlSetSign:108index = 2; // child 3109break;110case TR::pdshrSetSign:111index = 3; // child 4112break;113default:114TR_ASSERT(false,"op is not a setSign operation\n");115}116return index;117}118119static TR::ILOpCodes setSignVersionOfOpCode(TR::ILOpCodes op)120{121switch(op)122{123case TR::pdshr: return TR::pdshrSetSign;124case TR::pdshl: return TR::pdshlSetSign;125case TR::pd2zdsls: return TR::pd2zdslsSetSign;126case TR::pd2zdsts: return TR::pd2zdstsSetSign;127default: return TR::BadILOp;128}129return TR::BadILOp;130}131132static TR::ILOpCodes reverseSetSignOpCode(TR::ILOpCodes op)133{134switch(op)135{136case TR::pdshrSetSign: return TR::pdshr;137case TR::pdshlSetSign: return TR::pdshl;138case TR::pd2zdslsSetSign: return TR::pd2zdsls;139case TR::pd2zdstsSetSign: return TR::pd2zdsts;140default: return TR::BadILOp;141}142return TR::BadILOp;143}144145static bool isZonedToZonedConversion(TR::ILOpCodes op)146{147switch (op)148{149case TR::zd2zdsle:150case TR::zdsle2zd:151return true;152default:153return false;154}155}156157static bool isPackedConversionToWiderType(TR::ILOpCodes op)158{159switch(op)160{161case TR::pd2zd:162case TR::pd2zdslsSetSign:163case TR::pd2zdstsSetSign:164return true;165default:166return false;167}168169}170171static TR::ILOpCodes getProperConversion(TR::DataType sourceDataType, TR::DataType targetDataType, bool needUnsignedConversion)172{173TR::ILOpCodes op = TR::DataType::getDataTypeConversion(sourceDataType, targetDataType);174if (!needUnsignedConversion) return op;175176switch (op)177{178case TR::i2pd: return TR::iu2pd;179case TR::l2pd: return TR::lu2pd;180case TR::pd2i: return TR::pd2iu;181case TR::pd2l: return TR::pd2lu;182183default: return OMR::ILOpCode::getProperConversion(sourceDataType, targetDataType, needUnsignedConversion);184}185}186187static bool isStrictlyLessThanCmp(TR::ILOpCodes op)188{189return OMR::ILOpCode::isStrictlyLessThanCmp(op);190}191192static bool isStrictlyGreaterThanCmp(TR::ILOpCodes op)193{194return OMR::ILOpCode::isStrictlyGreaterThanCmp(op);195}196197static bool isLessCmp(TR::ILOpCodes op)198{199return OMR::ILOpCode::isLessCmp(op);200}201202static bool isGreaterCmp(TR::ILOpCodes op)203{204return OMR::ILOpCode::isGreaterCmp(op);205}206207static bool isEqualCmp(TR::ILOpCodes op)208{209return OMR::ILOpCode::isEqualCmp(op);210}211212static bool isNotEqualCmp(TR::ILOpCodes op)213{214return OMR::ILOpCode::isNotEqualCmp(op);215}216217static TR::ILOpCodes cleanOpCode(TR::DataType type)218{219switch(type)220{221case TR::PackedDecimal: return TR::pdclean;222default: TR_ASSERT(0, "no clean opcode for this datatype");223}224return TR::BadILOp;225}226227static TR::ILOpCodes absOpCode(TR::DataType type)228{229switch(type)230{231case TR::PackedDecimal: return TR::pdabs;232default: return OMR::ILOpCode::absOpCode(type);233}234return TR::BadILOp;235}236237static TR::ILOpCodes addOpCode(TR::DataType type, bool is64Bit)238{239switch(type)240{241case TR::PackedDecimal: return TR::pdadd;242default: return OMR::ILOpCode::addOpCode(type, is64Bit);243}244return TR::BadILOp;245}246247static TR::ILOpCodes subtractOpCode(TR::DataType type)248{249switch(type)250{251case TR::PackedDecimal: return TR::pdsub;252default: return OMR::ILOpCode::subtractOpCode(type);253}254return TR::BadILOp;255}256257static TR::ILOpCodes multiplyOpCode(TR::DataType type)258{259switch(type)260{261case TR::PackedDecimal: return TR::pdmul;262default: return OMR::ILOpCode::multiplyOpCode(type);263}264return TR::BadILOp;265}266267static TR::ILOpCodes divideOpCode(TR::DataType type)268{269switch(type)270{271case TR::PackedDecimal: return TR::pddiv;272default: return OMR::ILOpCode::divideOpCode(type);273}274return TR::BadILOp;275}276277static TR::ILOpCodes remainderOpCode(TR::DataType type)278{279switch(type)280{281case TR::PackedDecimal: return TR::pdrem;282default: return OMR::ILOpCode::remainderOpCode(type);283}284return TR::BadILOp;285}286287static TR::ILOpCodes negateOpCode(TR::DataType type)288{289switch(type)290{291case TR::PackedDecimal: return TR::pdneg;292default: return OMR::ILOpCode::negateOpCode(type);293}294return TR::BadILOp;295}296297static TR::ILOpCodes modifyPrecisionOpCode(TR::DataType type)298{299switch (type)300{301case TR::PackedDecimal: return TR::pdModifyPrecision;302default: TR_ASSERT(0, "no modifyPrecision opcode for this datatype");303}304return TR::BadILOp;305}306307static TR::ILOpCodes shiftLeftOpCode(TR::DataType type)308{309return OMR::ILOpCode::shiftLeftOpCode(type);310}311312static TR::ILOpCodes shiftRightOpCode(TR::DataType type)313{314return OMR::ILOpCode::shiftRightOpCode(type);315}316317static TR::ILOpCodes ifcmpgeOpCode(TR::DataType type, bool isUnsigned)318{319return OMR::ILOpCode::ifcmpgeOpCode(type, isUnsigned);320}321322static TR::ILOpCodes ifcmpleOpCode(TR::DataType type, bool isUnsigned)323{324return OMR::ILOpCode::ifcmpleOpCode(type, isUnsigned);325}326327static TR::ILOpCodes ifcmpgtOpCode(TR::DataType type, bool isUnsigned)328{329return OMR::ILOpCode::ifcmpgtOpCode(type, isUnsigned);330}331332static TR::ILOpCodes ifcmpltOpCode(TR::DataType type, bool isUnsigned)333{334return OMR::ILOpCode::ifcmpltOpCode(type, isUnsigned);335}336337static TR::ILOpCodes ifcmpeqOpCode(TR::DataType type)338{339return OMR::ILOpCode::ifcmpeqOpCode(type);340}341342static TR::ILOpCodes ifcmpneOpCode(TR::DataType type)343{344return OMR::ILOpCode::ifcmpneOpCode(type);345}346347static TR::ILOpCodes cmpeqOpCode(TR::DataType type)348{349return OMR::ILOpCode::cmpeqOpCode(type);350}351352static TR::ILOpCodes constOpCode(TR::DataType type)353{354return OMR::ILOpCode::constOpCode(type);355}356357static TR::ILOpCodes returnOpCode(TR::DataType type)358{359return OMR::ILOpCode::returnOpCode(type);360}361362};363364}365366#endif367368369370