• 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_local_schedule.h"
17 #include "aarch64_cg.h"
18 
19 namespace maplebe {
FinishScheduling(CDGNode & cdgNode)20 void AArch64LocalSchedule::FinishScheduling(CDGNode &cdgNode)
21 {
22     BB *curBB = cdgNode.GetBB();
23     CHECK_FATAL(curBB != nullptr, "get bb from cdgNode failed");
24     curBB->ClearInsns();
25 
26     const Insn *prevLocInsn = (curBB->GetPrev() != nullptr ? curBB->GetPrev()->GetLastLoc() : nullptr);
27     MapleVector<DepNode *> schedResults = commonSchedInfo->GetSchedResults();
28     for (auto depNode : schedResults) {
29         Insn *curInsn = depNode->GetInsn();
30         CHECK_FATAL(curInsn != nullptr, "get insn from depNode failed");
31 
32         // Append comments
33         for (auto comment : depNode->GetComments()) {
34             if (comment->GetPrev() != nullptr && comment->GetPrev()->IsDbgInsn()) {
35                 curBB->AppendInsn(*comment->GetPrev());
36             }
37             curBB->AppendInsn(*comment);
38         }
39 
40         // Append clinit insns
41         if (!depNode->GetClinitInsns().empty()) {
42             for (auto clinitInsn : depNode->GetClinitInsns()) {
43                 curBB->AppendInsn(*clinitInsn);
44             }
45         } else {
46             // Append debug insns
47             if (curInsn->GetPrev() != nullptr && curInsn->GetPrev()->IsDbgInsn()) {
48                 curBB->AppendInsn(*curInsn->GetPrev());
49             }
50             // Append insn
51             curBB->AppendInsn(*curInsn);
52         }
53     }
54 
55     curBB->SetLastLoc(prevLocInsn);
56     for (auto lastComment : cdgNode.GetLastComments()) {
57         curBB->AppendInsn(*lastComment);
58     }
59     cdgNode.ClearLastComments();
60     DEBUG_ASSERT(curBB->NumInsn() >= static_cast<int32>(cdgNode.GetInsnNum()),
61                  "The number of instructions after local-scheduling is unexpected");
62 
63     commonSchedInfo = nullptr;
64 }
65 } /* namespace maplebe */
66