• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 *SelectAddrof(AddrofNode &expr, const BaseNode &parent) override;
34     Operand *SelectAddrofFunc(AddroffuncNode &expr, const BaseNode &parent) override;
35     Operand *SelectAddrofLabel(AddroflabelNode &expr, const BaseNode &parent) override;
36     Operand *SelectFloatingConst(MIRConst &floatingConst, PrimType primType) const override;
37     void SelectGoto(GotoNode &stmt) override;
38     void SelectIntrinsicCall(IntrinsiccallNode &intrinsiccallNode) override;
39     void SelectAggIassign(IassignNode &stmt, Operand &AddrOpnd, Operand &opndRhs) override;
40     void SelectAggDassign(maplebe::MirTypeInfo &lhsInfo, MemOperand &symbolMem, Operand &opndRhs) override;
41     void SelectAggCopy(MemOperand &lhs, MemOperand &rhs, uint32 copySize) override;
42     void SelectRangeGoto(RangeGotoNode &rangeGotoNode, Operand &srcOpnd) override;
43     void SelectCondGoto(CondGotoNode &stmt, BaseNode &condNode, Operand &opnd0) override;
44     void SelectIgoto(Operand &opnd0) override;
45     Operand *SelectDiv(BinaryNode &node, Operand &opnd0, Operand &opnd1, const BaseNode &parent) override;
46     Operand *SelectRem(BinaryNode &node, Operand &opnd0, Operand &opnd1, const BaseNode &parent) override;
47     Operand *SelectMpy(BinaryNode &node, Operand &opnd0, Operand &opnd1, const BaseNode &parent) override;
48     Operand *SelectCmpOp(CompareNode &node, Operand &opnd0, Operand &opnd1, const BaseNode &parent) override;
49     Operand *SelectLnot(const UnaryNode &node, Operand &opnd0, const BaseNode &parent) override;
50     Operand *SelectSelect(TernaryNode &expr, Operand &cond, Operand &trueOpnd, Operand &falseOpnd,
51                           const BaseNode &parent) override;
52     Operand *SelectStrLiteral(ConststrNode &constStr) override;
53     void SelectIntAggCopyReturn(MemOperand &symbolMem, uint64 aggSize) override;
54     /* Create the operand interface directly */
55     MemOperand &CreateMemOpndOrNull(PrimType ptype, const BaseNode &parent, BaseNode &addrExpr, int64 offset = 0);
56     Operand *SelectBswap(IntrinsicopNode &node, Operand &opnd0, const BaseNode &parent) override;
57     Operand *SelectCclz(IntrinsicopNode &node, Operand &opnd0, const BaseNode &parent) override;
58     Operand *SelectCctz(IntrinsicopNode &node, Operand &opnd0, const BaseNode &parent) override;
59     Operand *SelectCexp(IntrinsicopNode &node, Operand &opnd0, const BaseNode &parent) override;
60     void SelectAsm(AsmNode &node) override;
61     Operand *SelectSqrt(UnaryNode &node, Operand &opnd0, const BaseNode &parent) override;
62 
63 private:
64     MemOperand &GetOrCreateMemOpndFromSymbol(const MIRSymbol &symbol, FieldID fieldId = 0) const override;
65     MemOperand &GetOrCreateMemOpndFromSymbol(const MIRSymbol &symbol, uint32 opndSize, int64 offset) const override;
66     Insn &AppendCall(x64::X64MOP_t mOp, Operand &targetOpnd, ListOperand &paramOpnds, ListOperand &retOpnds);
67     void SelectCalleeReturn(MIRType *retType, ListOperand &retOpnds);
68 
69     /* Inline function implementation of va_start */
70     void GenCVaStartIntrin(RegOperand &opnd, uint32 stkSize);
71 
72     /* Subclass private instruction selector function */
73     void SelectCVaStart(const IntrinsiccallNode &intrnNode);
74     void SelectOverFlowCall(const IntrinsiccallNode &intrnNode);
75     void SelectParmList(StmtNode &naryNode, ListOperand &srcOpnds, uint32 &fpNum);
76     void SelectMpy(Operand &resOpnd, Operand &opnd0, Operand &opnd1, PrimType primType);
77 
78     /* lt/le in float is replaced by gt/ge on swaped operands */
79     void SelectCmp(Operand &opnd0, Operand &opnd1, PrimType primType, bool isSwap = false);
80     void SelectCmpFloatEq(RegOperand &resOpnd, Operand &opnd0, Operand &opnd1, PrimType primResType,
81                           PrimType primOpndType);
82     void SelectCmpResult(RegOperand &resOpnd, Opcode opCode, PrimType primType, PrimType primOpndType);
83     void SelectSelect(Operand &resOpnd, Operand &trueOpnd, Operand &falseOpnd, PrimType primType, Opcode cmpOpcode,
84                       PrimType cmpPrimType);
85 
86     Operand *SelectDivRem(RegOperand &opnd0, RegOperand &opnd1, PrimType primType, Opcode opcode);
87     RegOperand &GetTargetStackPointer(PrimType primType) override;
88     RegOperand &GetTargetBasicPointer(PrimType primType) override;
89     std::tuple<Operand *, size_t, MIRType *> GetMemOpndInfoFromAggregateNode(BaseNode &argExpr);
90     void SelectParmListForAggregate(BaseNode &argExpr, X64CallConvImpl &parmLocator, bool isArgUnused);
91     void CreateCallStructParamPassByReg(MemOperand &memOpnd, regno_t regNo, uint32 parmNum);
92     void CreateCallStructParamPassByStack(MemOperand &addrOpnd, int32 symSize, int32 baseOffset);
93     void SelectAggCopyReturn(const MIRSymbol &symbol, MIRType &symbolType, uint64 symbolSize);
94     bool IsParamStructCopy(const MIRSymbol &symbol);
95     void SelectMinOrMax(bool isMin, Operand &resOpnd, Operand &opnd0, Operand &opnd1, PrimType primType) override;
96     void SelectLibCall(const std::string &funcName, std::vector<Operand *> &opndVec, PrimType primType,
97                        Operand *retOpnd, PrimType retType);
98     void SelectLibCallNArg(const std::string &funcName, std::vector<Operand *> &opndVec, std::vector<PrimType> pt,
99                            Operand *retOpnd, PrimType retType);
100     void SelectPseduoForReturn(std::vector<RegOperand *> &retRegs);
101     RegOperand *PrepareMemcpyParm(MemOperand &memOperand, MOperator mOp);
102     RegOperand *PrepareMemcpyParm(uint64 copySize);
103     RegOperand &SelectSpecialRegread(PregIdx pregIdx, PrimType primType) override;
104     void SelectRetypeFloat(RegOperand &resOpnd, Operand &opnd0, PrimType toType, PrimType fromType) override;
105 
106     /* save param pass by reg */
107     std::vector<std::tuple<RegOperand *, Operand *, PrimType>> paramPassByReg;
108 };
109 }  // namespace maplebe
110 
111 #endif /* MAPLEBE_INCLUDE_X64_MPISEL_H */
112