1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef MAPLEBE_INCLUDE_X64_MPISEL_H 17 #define MAPLEBE_INCLUDE_X64_MPISEL_H 18 19 #include "isel.h" 20 #include "x64_call_conv.h" 21 22 namespace maplebe { 23 class X64MPIsel : public MPISel { 24 public: X64MPIsel(MemPool & mp,MapleAllocator & allocator,CGFunc & f)25 X64MPIsel(MemPool &mp, MapleAllocator &allocator, CGFunc &f) : MPISel(mp, allocator, f) {} 26 ~X64MPIsel() override = default; 27 void SelectReturn(NaryStmtNode &retNode, Operand &opnd) override; 28 void SelectReturn() override; 29 void SelectCall(CallNode &callNode) override; 30 void SelectIcall(IcallNode &icallNode) override; 31 Operand &ProcessReturnReg(PrimType primType, int32 sReg) override; 32 Operand &GetTargetRetOperand(PrimType primType, int32 sReg) override; 33 Operand *SelectFloatingConst(MIRConst &floatingConst, PrimType primType) const override; 34 void SelectGoto(GotoNode &stmt) override; 35 void SelectIntrinsicCall(IntrinsiccallNode &intrinsiccallNode) override; 36 void SelectRangeGoto(RangeGotoNode &rangeGotoNode, Operand &srcOpnd) override; 37 void SelectCondGoto(CondGotoNode &stmt, BaseNode &condNode, Operand &opnd0) override; 38 Operand *SelectDiv(BinaryNode &node, Operand &opnd0, Operand &opnd1, const BaseNode &parent) override; 39 Operand *SelectRem(BinaryNode &node, Operand &opnd0, Operand &opnd1, const BaseNode &parent) override; 40 Operand *SelectMpy(BinaryNode &node, Operand &opnd0, Operand &opnd1, const BaseNode &parent) override; 41 Operand *SelectCmpOp(CompareNode &node, Operand &opnd0, Operand &opnd1, const BaseNode &parent) override; 42 Operand *SelectLnot(const UnaryNode &node, Operand &opnd0, const BaseNode &parent) override; 43 /* Create the operand interface directly */ 44 MemOperand &CreateMemOpndOrNull(PrimType ptype, const BaseNode &parent, BaseNode &addrExpr, int64 offset = 0); 45 Operand *SelectCclz(IntrinsicopNode &node, Operand &opnd0, const BaseNode &parent) override; 46 Operand *SelectCctz(IntrinsicopNode &node, Operand &opnd0, const BaseNode &parent) override; 47 Operand *SelectSqrt(UnaryNode &node, Operand &opnd0, const BaseNode &parent) override; 48 49 private: 50 MemOperand &GetOrCreateMemOpndFromSymbol(const MIRSymbol &symbol, FieldID fieldId = 0) const override; 51 MemOperand &GetOrCreateMemOpndFromSymbol(const MIRSymbol &symbol, uint32 opndSize, int64 offset) const override; 52 Insn &AppendCall(x64::X64MOP_t mOp, Operand &targetOpnd, ListOperand ¶mOpnds, ListOperand &retOpnds); 53 void SelectCalleeReturn(MIRType *retType, ListOperand &retOpnds); 54 55 void SelectOverFlowCall(const IntrinsiccallNode &intrnNode); 56 void SelectParmList(StmtNode &naryNode, ListOperand &srcOpnds, uint32 &fpNum); 57 void SelectMpy(Operand &resOpnd, Operand &opnd0, Operand &opnd1, PrimType primType); 58 void SelectPureCall(const IntrinsiccallNode &intrnNode); 59 RegOperand &LoadOpndIntoPhysicalRegister(const IntrinsiccallNode &intrnNode, uint32 index); 60 /* lt/le in float is replaced by gt/ge on swaped operands */ 61 void SelectCmp(Operand &opnd0, Operand &opnd1, PrimType primType, bool isSwap = false); 62 void SelectCmpFloatEq(RegOperand &resOpnd, Operand &opnd0, Operand &opnd1, PrimType primResType, 63 PrimType primOpndType); 64 void SelectCmpResult(RegOperand &resOpnd, Opcode opCode, PrimType primType, PrimType primOpndType); 65 void SelectSelect(Operand &resOpnd, Operand &trueOpnd, Operand &falseOpnd, PrimType primType, Opcode cmpOpcode, 66 PrimType cmpPrimType); 67 68 Operand *SelectDivRem(RegOperand &opnd0, RegOperand &opnd1, PrimType primType, Opcode opcode); 69 RegOperand &GetTargetBasicPointer(PrimType primType) override; 70 void SelectMinOrMax(bool isMin, Operand &resOpnd, Operand &opnd0, Operand &opnd1, PrimType primType) override; 71 void SelectPseduoForReturn(std::vector<RegOperand *> &retRegs); 72 RegOperand &SelectSpecialRegread(PregIdx pregIdx, PrimType primType) override; 73 void SelectRetypeFloat(RegOperand &resOpnd, Operand &opnd0, PrimType toType, PrimType fromType) override; 74 75 /* save param pass by reg */ 76 std::vector<std::tuple<RegOperand *, Operand *, PrimType>> paramPassByReg; 77 }; 78 } // namespace maplebe 79 80 #endif /* MAPLEBE_INCLUDE_X64_MPISEL_H */ 81