• 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_yieldpoint.h"
17 #include "aarch64_cgfunc.h"
18 
19 namespace maplebe {
20 using namespace maple;
21 
Run()22 void AArch64YieldPointInsertion::Run()
23 {
24     InsertYieldPoint();
25 }
26 
InsertYieldPoint()27 void AArch64YieldPointInsertion::InsertYieldPoint()
28 {
29     AArch64CGFunc *aarchCGFunc = static_cast<AArch64CGFunc *>(cgFunc);
30 
31     /*
32      * do not insert yieldpoint in function that not saved X30 into stack,
33      * because X30 will be changed after yieldpoint is taken.
34      */
35     if (!aarchCGFunc->GetHasProEpilogue()) {
36         DEBUG_ASSERT(aarchCGFunc->GetYieldPointInsn() != nullptr, "the entry yield point has been inserted");
37         aarchCGFunc->GetYieldPointInsn()->GetBB()->RemoveInsn(*aarchCGFunc->GetYieldPointInsn());
38         return;
39     }
40     /* skip if no GetFirstbb(). */
41     if (aarchCGFunc->GetFirstBB() == nullptr) {
42         return;
43     }
44     /*
45      * The yield point in the entry of the GetFunction() is inserted just after the initialization
46      * of localrefvars in HandleRCCall.
47      * for BBs after firstbb.
48      */
49     for (BB *bb = aarchCGFunc->GetFirstBB()->GetNext(); bb != nullptr; bb = bb->GetNext()) {
50         // insert a yieldpoint at loop header bb
51         auto *loop = loopInfo.GetBBLoopParent(bb->GetId());
52         if (loop != nullptr && loop->GetHeader().GetId() == bb->GetId()) {
53             aarchCGFunc->GetDummyBB()->ClearInsns();
54             aarchCGFunc->GenerateYieldpoint(*aarchCGFunc->GetDummyBB());
55             bb->InsertAtBeginning(*aarchCGFunc->GetDummyBB());
56         }
57     }
58 }
59 } /* namespace maplebe */
60