• 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 #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 
ProcessCallInsnParam(BB & bb,const Insn & insn) const35 void AArch64LiveAnalysis::ProcessCallInsnParam(BB &bb, const Insn &insn) const
36 {
37     /* R0 ~ R7(R0 + 0  ~ R0 + 7) and V0 ~ V7 (V0 + 0 ~ V0 + 7) is parameter register */
38     AArch64CGFunc *aarchCGFunc = static_cast<AArch64CGFunc *>(cgFunc);
39     auto *targetOpnd = insn.GetCallTargetOperand();
40     CHECK_FATAL(targetOpnd != nullptr, "target is null in Insn::IsCallToFunctionThatNeverReturns");
41     if (CGOptions::DoIPARA() && targetOpnd->IsFuncNameOpnd()) {
42         FuncNameOperand *target = static_cast<FuncNameOperand *>(targetOpnd);
43         const MIRSymbol *funcSt = target->GetFunctionSymbol();
44         DEBUG_ASSERT(funcSt->GetSKind() == kStFunc, "funcst must be a function name symbol");
45         MIRFunction *func = funcSt->GetFunction();
46         if (func != nullptr && func->IsReferedRegsValid()) {
47             for (auto preg : func->GetReferedRegs()) {
48                 if (AArch64Abi::IsCalleeSavedReg(static_cast<AArch64reg>(preg))) {
49                     continue;
50                 }
51                 RegOperand *opnd = &aarchCGFunc->GetOrCreatePhysicalRegisterOperand(
52                     static_cast<AArch64reg>(preg), k64BitSize,
53                     AArch64isa::IsFPSIMDRegister(static_cast<AArch64reg>(preg)) ? kRegTyFloat : kRegTyInt);
54                 CollectLiveInfo(bb, *opnd, true, false);
55             }
56             return;
57         }
58     }
59     for (uint32 i = 0; i < 8; ++i) { // do with 8 reg (R0-R7, V0-V7)
60         Operand &phyOpndR =
61             aarchCGFunc->GetOrCreatePhysicalRegisterOperand(static_cast<AArch64reg>(R0 + i), k64BitSize, kRegTyInt);
62         CollectLiveInfo(bb, phyOpndR, true, false);
63         Operand &phyOpndV =
64             aarchCGFunc->GetOrCreatePhysicalRegisterOperand(static_cast<AArch64reg>(V0 + i), k64BitSize, kRegTyFloat);
65         CollectLiveInfo(bb, phyOpndV, true, false);
66     }
67 }
68 
69 } /* namespace maplebe */
70