• 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 MAPLE_ME_INCLUDE_PME_FUNCTION_H
17 #define MAPLE_ME_INCLUDE_PME_FUNCTION_H
18 #include "pme_mir_extension.h"
19 #include "me_ir.h"
20 
21 namespace maple {
22 class MeFunction;
23 
24 class PreMeWhileInfo {
25 public:
26     MIRSymbol *injectedIVSym = nullptr;  // the injected IV
27     OriginalSt *ivOst = nullptr;         // the primary IV
28     MeExpr *initExpr = nullptr;
29     int32 stepValue = 0;
30     MeExpr *tripCount = nullptr;
31     bool canConvertDoloop = false;
32 };
33 
34 class PreMeIfInfo {
35 public:
36     LabelIdx endLabel = 0;   // the label that is out of the if statement
37     LabelIdx elseLabel = 0;  // the label that is the begin of else branch
38 };
39 
40 class PreMeFunction {
41 public:
42     MemPool *pmemp;
43     MapleAllocator pmeAlloc;
44     MeFunction *meFunc;
45     // key is label at beginning of lowered while code sequence
46     MapleMap<LabelIdx, PreMeWhileInfo *> label2WhileInfo;
47     // key is target label of first conditional branch of lowered if code sequence
48     MapleMap<LabelIdx, PreMeIfInfo *> label2IfInfo;
49     // for the labels that were created by PreMe, we won't emit it
50     MapleSet<LabelIdx> pmeCreatedIfLabelSet;
51     MapleSet<LabelIdx> pmeCreatedWhileLabelSet;
52 
PreMeFunction(MemPool * mp,MeFunction * func)53     PreMeFunction(MemPool *mp, MeFunction *func)
54         : pmemp(mp),
55           pmeAlloc(mp),
56           meFunc(func),
57           label2WhileInfo(pmeAlloc.Adapter()),
58           label2IfInfo(pmeAlloc.Adapter()),
59           pmeCreatedIfLabelSet(pmeAlloc.Adapter()),
60           pmeCreatedWhileLabelSet(pmeAlloc.Adapter())
61     {
62     }
63     virtual ~PreMeFunction() = default;
64 
SetIfLabelCreatedByPreMe(LabelIdx lbidx)65     void SetIfLabelCreatedByPreMe(LabelIdx lbidx)
66     {
67         pmeCreatedIfLabelSet.insert(lbidx);
68     }
69 
IfLabelCreatedByPreMe(LabelIdx lbidx)70     bool IfLabelCreatedByPreMe(LabelIdx lbidx) const
71     {
72         return pmeCreatedIfLabelSet.count(lbidx) != 0;
73     }
74 
SetWhileLabelCreatedByPreMe(LabelIdx lbidx)75     void SetWhileLabelCreatedByPreMe(LabelIdx lbidx)
76     {
77         pmeCreatedWhileLabelSet.insert(lbidx);
78     }
79 
WhileLabelCreatedByPreMe(LabelIdx lbidx)80     bool WhileLabelCreatedByPreMe(LabelIdx lbidx) const
81     {
82         return pmeCreatedWhileLabelSet.count(lbidx) != 0;
83     }
84 };
85 }  // namespace maple
86 #endif  // MAPLE_ME_INCLUDE_PME_FUNCTION_H
87