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 #include "aarch64_live.h"
17 #include "aarch64_cg.h"
18
19 namespace maplebe {
GenerateReturnBBDefUse(BB & bb) const20 void AArch64LiveAnalysis::GenerateReturnBBDefUse(BB &bb) const
21 {
22 PrimType returnType = cgFunc->GetFunction().GetReturnType()->GetPrimType();
23 auto *aarchCGFunc = static_cast<AArch64CGFunc *>(cgFunc);
24 if (IsPrimitiveFloat(returnType)) {
25 Operand &phyOpnd =
26 aarchCGFunc->GetOrCreatePhysicalRegisterOperand(static_cast<AArch64reg>(V0), k64BitSize, kRegTyFloat);
27 CollectLiveInfo(bb, phyOpnd, false, true);
28 } else if (IsPrimitiveInteger(returnType)) {
29 Operand &phyOpnd =
30 aarchCGFunc->GetOrCreatePhysicalRegisterOperand(static_cast<AArch64reg>(R0), k64BitSize, kRegTyInt);
31 CollectLiveInfo(bb, phyOpnd, false, true);
32 }
33 }
34
CleanupBBIgnoreReg(regno_t reg)35 bool AArch64LiveAnalysis::CleanupBBIgnoreReg(regno_t reg)
36 {
37 regno_t regNO = reg + R0;
38 if (regNO < R8 || (RLR <= regNO && regNO <= RZR)) {
39 return true;
40 }
41 return false;
42 }
43
ProcessCallInsnParam(BB & bb,const Insn & insn) const44 void AArch64LiveAnalysis::ProcessCallInsnParam(BB &bb, const Insn &insn) const
45 {
46 /* R0 ~ R7(R0 + 0 ~ R0 + 7) and V0 ~ V7 (V0 + 0 ~ V0 + 7) is parameter register */
47 AArch64CGFunc *aarchCGFunc = static_cast<AArch64CGFunc *>(cgFunc);
48 auto *targetOpnd = insn.GetCallTargetOperand();
49 CHECK_FATAL(targetOpnd != nullptr, "target is null in Insn::IsCallToFunctionThatNeverReturns");
50 if (CGOptions::DoIPARA() && targetOpnd->IsFuncNameOpnd()) {
51 FuncNameOperand *target = static_cast<FuncNameOperand *>(targetOpnd);
52 const MIRSymbol *funcSt = target->GetFunctionSymbol();
53 DEBUG_ASSERT(funcSt->GetSKind() == kStFunc, "funcst must be a function name symbol");
54 MIRFunction *func = funcSt->GetFunction();
55 if (func != nullptr && func->IsReferedRegsValid()) {
56 for (auto preg : func->GetReferedRegs()) {
57 if (AArch64Abi::IsCalleeSavedReg(static_cast<AArch64reg>(preg))) {
58 continue;
59 }
60 RegOperand *opnd = &aarchCGFunc->GetOrCreatePhysicalRegisterOperand(
61 static_cast<AArch64reg>(preg), k64BitSize,
62 AArch64isa::IsFPSIMDRegister(static_cast<AArch64reg>(preg)) ? kRegTyFloat : kRegTyInt);
63 CollectLiveInfo(bb, *opnd, true, false);
64 }
65 return;
66 }
67 }
68 for (uint32 i = 0; i < 8; ++i) { // do with 8 reg (R0-R7, V0-V7)
69 Operand &phyOpndR =
70 aarchCGFunc->GetOrCreatePhysicalRegisterOperand(static_cast<AArch64reg>(R0 + i), k64BitSize, kRegTyInt);
71 CollectLiveInfo(bb, phyOpndR, true, false);
72 Operand &phyOpndV =
73 aarchCGFunc->GetOrCreatePhysicalRegisterOperand(static_cast<AArch64reg>(V0 + i), k64BitSize, kRegTyFloat);
74 CollectLiveInfo(bb, phyOpndV, true, false);
75 }
76 }
77
78 } /* namespace maplebe */
79