Path: blob/master/runtime/compiler/optimizer/IdiomRecognitionUtils.hpp
6000 views
/*******************************************************************************1* Copyright (c) 2000, 2019 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 IDIOM_RECOGNITION_UTILS_INCL23#define IDIOM_RECOGNITION_UTILS_INCL2425#include <stddef.h>26#include <stdint.h>27#include "il/DataTypes.hpp"28#include "il/ILOpCodes.hpp"2930class TR_BitVector;31class TR_CISCNode;32class TR_CISCTransformer;33class TR_PCISCGraph;34class TR_PCISCNode;35namespace TR { class SymbolReference; }36namespace TR { class Block; }37namespace TR { class Compilation; }38namespace TR { class Node; }39template <class T> class List;4041enum42{43CISCUtilCtl_64Bit = 1,44CISCUtilCtl_NoI2L = 2,45CISCUtilCtl_ChildDirectConnected = 4,46CISCUtilCtl_BigEndian = 8,47CISCUtilCtl_NoConversion = 16,48CISCUtilCtl_AllConversion = 3249};50TR_PCISCGraph *makeStrlen16Graph(TR::Compilation *c, int32_t ctrl);51TR_PCISCGraph *makePtrArraySetGraph(TR::Compilation *c, int32_t ctrl);52TR_PCISCGraph *makeMemSetGraph(TR::Compilation *c, int32_t ctrl);53TR_PCISCGraph *makeMixedMemSetGraph(TR::Compilation *c, int32_t ctrl);5455TR_PCISCGraph *makeTRTGraph(TR::Compilation *c, int32_t ctrl);56TR_PCISCGraph *makeTRTGraph2(TR::Compilation *c, int32_t ctrl);57TR_PCISCGraph *makeTRT4NestedArrayGraph(TR::Compilation *c, int32_t ctrl);58TR_PCISCGraph *makeTRT4NestedArrayIfGraph(TR::Compilation *c, int32_t ctrl);5960TR_PCISCGraph *makeTROTArrayGraph(TR::Compilation *c, int32_t ctrl);61TR_PCISCGraph *makeTRTOArrayGraph(TR::Compilation *c, int32_t ctrl);62TR_PCISCGraph *makeTRTOArrayGraphSpecial(TR::Compilation *c, int32_t ctrl);63TR_PCISCGraph *makeCopyingTROOSpecialGraph(TR::Compilation *c, int32_t ctrl);64TR_PCISCGraph *makeCopyingTROxGraph(TR::Compilation *c, int32_t ctrl, int pattern);65TR_PCISCGraph *makeCopyingTROTInduction1Graph(TR::Compilation *c, int32_t ctrl, int32_t pattern);66TR_PCISCGraph *makeCopyingTRTxGraph(TR::Compilation *c, int32_t ctrl, int pattern);67TR_PCISCGraph *makeCopyingTRTxThreeIfsGraph(TR::Compilation *c, int32_t ctrl);68TR_PCISCGraph *makeCopyingTRTOGraphSpecial(TR::Compilation *c, int32_t ctrl);69TR_PCISCGraph *makeCopyingTRTOInduction1Graph(TR::Compilation *c, int32_t ctrl, int32_t pattern);70TR_PCISCGraph *makeCopyingTRTTSpecialGraph(TR::Compilation *c, int32_t ctrl);7172TR_PCISCGraph *makeMemCmpGraph(TR::Compilation *c, int32_t ctrl);73TR_PCISCGraph *makeMemCmpSpecialGraph(TR::Compilation *c, int32_t ctrl);74TR_PCISCGraph *makeMemCmpIndexOfGraph(TR::Compilation *c, int32_t ctrl);7576TR_PCISCGraph *makeMemCpySpecialGraph(TR::Compilation *c, int32_t ctrl);77TR_PCISCGraph *makeMemCpyGraph(TR::Compilation *c, int32_t ctrl);78TR_PCISCGraph *makeMemCpyDecGraph(TR::Compilation *c, int32_t ctrl);79TR_PCISCGraph *makeMemCpyByteToCharGraph(TR::Compilation *c, int32_t ctrl);80TR_PCISCGraph *makeMemCpyByteToCharBndchkGraph(TR::Compilation *c, int32_t ctrl);81TR_PCISCGraph *makeMemCpyCharToByteGraph(TR::Compilation *c, int32_t ctrl);82TR_PCISCGraph *makeMEMCPYChar2ByteGraph2(TR::Compilation *c, int32_t ctrl);83TR_PCISCGraph *makeMEMCPYChar2ByteMixedGraph(TR::Compilation *c, int32_t ctrl);84// not active idioms85TR_PCISCGraph *makeMEMCPYByte2IntGraph(TR::Compilation *c, int32_t ctrl);86TR_PCISCGraph *makeMEMCPYInt2ByteGraph(TR::Compilation *c, int32_t ctrl);8788TR_PCISCGraph *makeBitOpMemGraph(TR::Compilation *c, int32_t ctrl);89TR_PCISCGraph *makeCountDecimalDigitLongGraph(TR::Compilation *c, int32_t ctrl, bool isDiv2Mul);90TR_PCISCGraph *makeCountDecimalDigitIntGraph(TR::Compilation *c, int32_t ctrl, bool isDiv2Mul);91TR_PCISCGraph *makeLongToStringGraph(TR::Compilation *c, int32_t ctrl);92TR_PCISCGraph *makeIntToStringGraph(TR::Compilation *c, int32_t ctrl, bool isDiv2Mul);93TR_PCISCNode *createIdiomIOP2VarInLoop(TR_PCISCGraph *tgt, int32_t ctrl, int dagId, TR_PCISCNode *pred, int opcode, TR_PCISCNode *v, TR_PCISCNode *subval);94TR_PCISCNode *createIdiomIOP2VarInLoop(TR_PCISCGraph *tgt, int32_t ctrl, int dagId, TR_PCISCNode *pred, int opcode, TR_PCISCNode *v, TR_PCISCNode *src1, TR_PCISCNode *subval);95TR_PCISCNode *createIdiomDecVarInLoop(TR_PCISCGraph *tgt, int32_t ctrl, int dagId, TR_PCISCNode *pred, TR_PCISCNode *v, TR_PCISCNode *src1, TR_PCISCNode *subval);96TR_PCISCNode *createIdiomIncVarInLoop(TR_PCISCGraph *tgt, int32_t ctrl, int dagId, TR_PCISCNode *pred, TR_PCISCNode *v, TR_PCISCNode *src1, TR_PCISCNode *subval);97TR_PCISCNode *createIdiomDecVarInLoop(TR_PCISCGraph *tgt, int32_t ctrl, int dagId, TR_PCISCNode *pred, TR_PCISCNode *v, TR_PCISCNode *subval);98TR_PCISCNode *createIdiomIncVarInLoop(TR_PCISCGraph *tgt, int32_t ctrl, int dagId, TR_PCISCNode *pred, TR_PCISCNode *v, TR_PCISCNode *subval);99TR_PCISCNode *createIdiomArrayRelatedConst(TR_PCISCGraph *tgt, int32_t ctrl, uint16_t id, int dagId, int32_t val);100TR_PCISCNode *createIdiomArrayHeaderConst(TR_PCISCGraph *tgt, int32_t ctrl, uint16_t id, int dagId, TR::Compilation *c);101TR_PCISCNode *createIdiomArrayAddressInLoop(TR_PCISCGraph *tgt, int32_t ctrl, int dagId, TR_PCISCNode *pred, TR_PCISCNode *base, TR_PCISCNode *indexTree);102TR_PCISCNode *createIdiomI2LIfNecessary(TR_PCISCGraph *tgt, int32_t ctrl, int dagId, TR_PCISCNode **pred, TR_PCISCNode *node);103TR_PCISCNode *createIdiomArrayAddressIndexTreeInLoop(TR_PCISCGraph *tgt, int32_t ctrl, int dagId, TR_PCISCNode *pred, TR_PCISCNode *index, TR_PCISCNode *cmah, TR_PCISCNode *const2);104TR_PCISCNode *createIdiomArrayAddressInLoop(TR_PCISCGraph *tgt, int32_t ctrl, int dagId, TR_PCISCNode *pred, TR_PCISCNode *base, TR_PCISCNode *index, TR_PCISCNode *cmah, TR_PCISCNode *const2);105TR_PCISCNode *createIdiomCharArrayLoadInLoop(TR_PCISCGraph *tgt, int32_t ctrl, int dagId, TR_PCISCNode *pred, TR_PCISCNode *base, TR_PCISCNode *index, TR_PCISCNode *cmah, TR_PCISCNode *const2);106TR_PCISCNode *createIdiomArrayLoadInLoop(TR_PCISCGraph *tgt, int32_t ctrl, int dagId, TR_PCISCNode *pred, int opcode, TR::DataType, TR_PCISCNode *base, TR_PCISCNode *index, TR_PCISCNode *cmah, TR_PCISCNode *mulconst);107TR_PCISCNode *createIdiomArrayStoreBodyInLoop(TR_PCISCGraph *tgt, int32_t ctrl, int dagId, TR_PCISCNode *pred, int opcode, TR_PCISCNode *addr, TR_PCISCNode *storeval);108TR_PCISCNode *createIdiomCharArrayStoreBodyInLoop(TR_PCISCGraph *tgt, int32_t ctrl, int dagId, TR_PCISCNode *pred, TR_PCISCNode *addr, TR_PCISCNode *storeval);109TR_PCISCNode *createIdiomCharArrayStoreInLoop(TR_PCISCGraph *tgt, int32_t ctrl, int dagId, TR_PCISCNode *pred, TR_PCISCNode *base, TR_PCISCNode *index, TR_PCISCNode *cmah, TR_PCISCNode *const2, TR_PCISCNode *storeval);110TR_PCISCNode *createIdiomArrayStoreInLoop(TR_PCISCGraph *tgt, int32_t ctrl, int dagId, TR_PCISCNode *pred, int opcode, TR::DataType, TR_PCISCNode *base, TR_PCISCNode *index, TR_PCISCNode *cmah, TR_PCISCNode *const2, TR_PCISCNode *storeval);111TR_PCISCNode *createIdiomByteDirectArrayLoadInLoop(TR_PCISCGraph *tgt, int32_t ctrl, int dagId, TR_PCISCNode *pred, TR_PCISCNode *base, TR_PCISCNode *index);112TR_PCISCNode *createIdiomIDiv10InLoop(TR_PCISCGraph *tgt, int32_t ctrl, bool isDiv2Mul, int dagId, TR_PCISCNode *pred, TR_PCISCNode *src1, TR_PCISCNode *src2, TR_PCISCNode *c2, TR_PCISCNode *c31);113bool searchNodeInBlock(TR_CISCNode *start, TR_CISCNode *target);114bool checkSuccsSet(TR_CISCTransformer *const trans, TR_CISCNode *t, TR_BitVector *const pBV);115bool getThreeNodesForArray(TR_CISCNode *top, TR_CISCNode **ixload, TR_CISCNode **aload, TR_CISCNode **iload, bool allowArrayIndex = false);116bool testExitIF(int opcode, bool *isDecrement = NULL, int32_t *modLength = NULL, int32_t *modStartIdx = NULL);117bool testIConst(TR_CISCNode *n, int idx, int32_t value);118TR::Node* createI2LIfNecessary(TR::Compilation *comp, bool is64bit, TR::Node *child);119TR::Node* createLoadWithI2LIfNecessary(TR::Compilation *comp, bool is64bit, TR::Node *indexNode);120TR::Node* createBytesFromElement(TR::Compilation *comp, bool is64bit, TR::Node *indexNode, int multiply);121TR::Node* createIndexOffsetTree(TR::Compilation *comp, bool is64bit, TR::Node *indexNode, int multiply);122TR::Node* createLoad(TR::Node *baseNode);123TR::Node* createArrayHeaderConst(TR::Compilation *comp, bool is64bit, TR::Node *baseNode);124TR::Node* createArrayTopAddressTree(TR::Compilation *comp, bool is64bit, TR::Node *baseNode);125TR::Node* createArrayAddressTree(TR::Compilation *comp, bool is64bit, TR::Node *baseNode, TR::Node *indexNode, int multiply = 1);126TR::Node* createArrayLoad(TR::Compilation *comp, bool is64bit, TR::Node *ixload, TR::Node *baseNode, TR::Node *indexNode, int multiply = 1);127TR::Node* replaceIndexInAddressTree(TR::Compilation *comp, TR::Node *tree, TR::SymbolReference *symRef, TR::Node *newNode);128TR::Node* createTableLoad(TR::Compilation *comp, TR::Node* repNode, uint8_t inputSize, uint8_t outputSize, void *array, bool dispTrace);129TR::Node* createOP2(TR::Compilation *comp, TR::ILOpCodes op2, TR::Node* ch1, TR::Node* ch2);130TR::Node* createStoreOP2(TR::Compilation *comp, TR::Node* storeNode, TR::ILOpCodes op2, TR::Node* ch1, TR::Node* ch2);131TR::Node* createStoreOP2(TR::Compilation *comp, TR::SymbolReference* store, TR::ILOpCodes op2, TR::SymbolReference* ch1, TR::Node* ch2, TR::Node *rep);132TR::Node* createStoreOP2(TR::Compilation *comp, TR::SymbolReference* store, TR::ILOpCodes op2, TR::SymbolReference* ch1, TR::SymbolReference* ch2, TR::Node *rep);133TR::Node* createStoreOP2(TR::Compilation *comp, TR::SymbolReference* store, TR::ILOpCodes op2, TR::SymbolReference* ch1, int ch2Const, TR::Node *rep);134TR::Node* createMin(TR::Compilation *comp, TR::Node* x, TR::Node* y);135TR::Node* createMax(TR::Compilation *comp, TR::Node* x, TR::Node* y);136TR::Node* convertStoreToLoadWithI2LIfNecessary(TR::Compilation *comp, bool is64bit, TR::Node *indexNode);137TR::Node* convertStoreToLoad(TR::Compilation *comp, TR::Node *indexNode);138TR::Node* modifyArrayHeaderConst(TR::Compilation *comp, TR::Node *tree, int32_t offset);139bool getMultiplier(TR_CISCTransformer *trans, TR_CISCNode *mulConst, TR::Node **multiplier, int *elementSize, TR::DataType srcNodeType);140void getP2TTrRepNodes(TR_CISCTransformer *trans, TR::Node** array, int count);141void getP2TTrRepNodes(TR_CISCTransformer *trans, TR::Node** n1, TR::Node** n2);142void getP2TTrRepNodes(TR_CISCTransformer *trans, TR::Node** n1, TR::Node** n2, TR::Node** n3);143void getP2TTrRepNodes(TR_CISCTransformer *trans, TR::Node** n1, TR::Node** n2, TR::Node** n3, TR::Node** n4);144void getP2TTrRepNodes(TR_CISCTransformer *trans, TR::Node** n1, TR::Node** n2, TR::Node** n3, TR::Node** n4, TR::Node** n5);145void getP2TTrRepNodes(TR_CISCTransformer *trans, TR::Node** n1, TR::Node** n2, TR::Node** n3, TR::Node** n4, TR::Node** n5, TR::Node** n6);146void getP2TTrRepNodes(TR_CISCTransformer *trans, TR::Node** n1, TR::Node** n2, TR::Node** n3, TR::Node** n4, TR::Node** n5, TR::Node** n6, TR::Node** n7);147bool isFitTRTFunctionTable(uint8_t *table);148TR::Node* createTableAlignmentCheck(TR::Compilation *comp, TR::Node *tableNode, bool isByteSource, bool isByteTarget, bool tableBackedByRawStorage);149List<TR_CISCNode>* sortList(List<TR_CISCNode>* input, List<TR_CISCNode>* output, List<TR_CISCNode>* order, bool reverse = false);150151void dump256Bytes(uint8_t *t, TR::Compilation * comp);152153bool isLoopPreheaderLastBlockInMethod(TR::Compilation *comp, TR::Block *block, TR::Block **predBlock = NULL);154bool findAndOrReplaceNodesWithMatchingSymRefNumber(TR::Node *curNode, TR::Node *targetNode, int32_t symRefNumberToBeMatched);155TR::Node *findLoadWithMatchingSymRefNumber(TR::Node *curNode, int32_t symRefNumberToBeMatched);156157#endif158159160