• 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_IR_INCLUDE_MIR_FUNCTION_H
17 #define MAPLE_IR_INCLUDE_MIR_FUNCTION_H
18 #include <string>
19 #include "mir_module.h"
20 #include "mir_const.h"
21 #include "mir_symbol.h"
22 #include "mir_preg.h"
23 #include "intrinsics.h"
24 #include "mir_nodes.h"
25 #include "mir_type.h"
26 #include "func_desc.h"
27 
28 #define DEBUGME true
29 
30 namespace maple {
31 enum PointerAttr : uint32_t { kPointerUndeiced = 0x1, kPointerNull = 0x2, kPointerNoNull = 0x3 };
32 
33 struct SaveInfo {
34     int offset;
35     bool shouldSave;
36     int idx;
37 };
38 
39 enum FuncAttrProp : uint32_t {
40     kNoThrowException = 0x1,
41     kNoRetNewlyAllocObj = 0x2,
42     kNoDefEffect = 0x4,
43     kNoDefArgEffect = 0x8,
44     kPureFunc = 0x10,
45     kIpaSeen = 0x20,
46     kUseEffect = 0x40,
47     kDefEffect = 0x80
48 };
49 
50 // file-layout is shared between maple compiler and runtime, thus not in namespace maplert
51 enum LayoutType : uint8_t {
52     kLayoutBootHot,
53     kLayoutBothHot,
54     kLayoutRunHot,
55     kLayoutStartupOnly,
56     kLayoutUsedOnce,
57     kLayoutExecuted,  // method excuted in some condition
58     kLayoutUnused,
59     kLayoutTypeCount
60 };
61 // this used for c string layout
62 static constexpr uint8_t kCStringShift = 1;
63 
64 // describe a formal definition in a function declaration
65 class FormalDef {
66 public:
67     GStrIdx formalStrIdx = GStrIdx(0);  // used when processing the prototype
68     MIRSymbol *formalSym = nullptr;     // used in the function definition
69     TyIdx formalTyIdx = TyIdx();
70     TypeAttrs formalAttrs = TypeAttrs();  // the formal's type attributes
71 
FormalDef()72     FormalDef() {};
~FormalDef()73     virtual ~FormalDef() {}
FormalDef(MIRSymbol * s,const TyIdx & tidx,const TypeAttrs & at)74     FormalDef(MIRSymbol *s, const TyIdx &tidx, const TypeAttrs &at) : formalSym(s), formalTyIdx(tidx), formalAttrs(at)
75     {
76     }
FormalDef(const GStrIdx & sidx,MIRSymbol * s,const TyIdx & tidx,const TypeAttrs & at)77     FormalDef(const GStrIdx &sidx, MIRSymbol *s, const TyIdx &tidx, const TypeAttrs &at)
78         : formalStrIdx(sidx), formalSym(s), formalTyIdx(tidx), formalAttrs(at)
79     {
80     }
81 };
82 
83 class MeFunction;         // circular dependency exists, no other choice
84 class EAConnectionGraph;  // circular dependency exists, no other choice
85 class MemReferenceTable;
86 class MIRFunction {
87 public:
MIRFunction(MIRModule * mod,StIdx idx)88     MIRFunction(MIRModule *mod, StIdx idx) : module(mod), symbolTableIdx(idx) {}
89 
90     ~MIRFunction() = default;
91 
92 #ifdef ARK_LITECG_DEBUG
93     void Dump(bool withoutBody = false);
94     void DumpUpFormal(int32 indent) const;
95     void DumpFrame(int32 indent) const;
96     void DumpFuncBody(int32 indent);
97 #endif
98 
99     const MIRSymbol *GetFuncSymbol() const;
100     MIRSymbol *GetFuncSymbol();
101 
SetMemPool(MemPool * memPool)102     void SetMemPool(MemPool *memPool)
103     {
104         SetCodeMemPool(memPool);
105         codeMemPoolAllocator.SetMemPool(codeMemPool);
106     }
107 
108     const std::string &GetName() const;
109 
110 #ifdef ARK_LITECG_DEBUG
111     GStrIdx GetNameStrIdx() const;
112 #endif
113 
114     const std::string &GetBaseClassName() const;
115 
116     const std::string &GetBaseFuncName() const;
117 
GetBaseClassNameStrIdx()118     GStrIdx GetBaseClassNameStrIdx() const
119     {
120         return baseClassStrIdx;
121     }
122 
GetBaseFuncNameStrIdx()123     GStrIdx GetBaseFuncNameStrIdx() const
124     {
125         return baseFuncStrIdx;
126     }
127 
GetBaseFuncNameWithTypeStrIdx()128     GStrIdx GetBaseFuncNameWithTypeStrIdx() const
129     {
130         return baseFuncWithTypeStrIdx;
131     }
132 
GetBaseFuncSigStrIdx()133     GStrIdx GetBaseFuncSigStrIdx() const
134     {
135         return baseFuncSigStrIdx;
136     }
137 
SetBaseClassNameStrIdx(GStrIdx id)138     void SetBaseClassNameStrIdx(GStrIdx id)
139     {
140         baseClassStrIdx = id;
141     }
142 
SetBaseFuncNameStrIdx(GStrIdx id)143     void SetBaseFuncNameStrIdx(GStrIdx id)
144     {
145         baseFuncStrIdx = id;
146     }
147 
SetBaseFuncNameWithTypeStrIdx(GStrIdx id)148     void SetBaseFuncNameWithTypeStrIdx(GStrIdx id)
149     {
150         baseFuncWithTypeStrIdx = id;
151     }
152 
153     const MIRType *GetReturnType() const;
154     MIRType *GetReturnType();
IsReturnVoid()155     bool IsReturnVoid() const
156     {
157         return GetReturnType()->GetPrimType() == PTY_void;
158     }
GetReturnTyIdx()159     TyIdx GetReturnTyIdx() const
160     {
161         CHECK_FATAL(funcType != nullptr, "funcType is nullptr");
162         return funcType->GetRetTyIdx();
163     }
SetReturnTyIdx(TyIdx tyidx)164     void SetReturnTyIdx(TyIdx tyidx)
165     {
166         CHECK_FATAL(funcType != nullptr, "funcType is nullptr");
167         funcType->SetRetTyIdx(tyidx);
168     }
169 
SetFrameTypeInfo(int offset,bool shouldSave,int idx)170     void SetFrameTypeInfo(int offset, bool shouldSave, int idx)
171     {
172         frameTypeInfo.offset = offset;
173         frameTypeInfo.shouldSave = shouldSave;
174         frameTypeInfo.idx = idx;
175     }
176 
SetFuncInfo(int offset,bool shouldSave,int idx)177     void SetFuncInfo(int offset, bool shouldSave, int idx)
178     {
179         funcIdxInfo.offset = offset;
180         funcIdxInfo.shouldSave = shouldSave;
181         funcIdxInfo.idx = idx;
182     }
183 
GetFrameTypeInfo()184     SaveInfo &GetFrameTypeInfo()
185     {
186         return frameTypeInfo;
187     }
188 
GetFuncInfo()189     SaveInfo &GetFuncInfo()
190     {
191         return funcIdxInfo;
192     }
193 
GetClassTyIdx()194     TyIdx GetClassTyIdx() const
195     {
196         return classTyIdx;
197     }
SetClassTyIdx(TyIdx tyIdx)198     void SetClassTyIdx(TyIdx tyIdx)
199     {
200         classTyIdx = tyIdx;
201     }
SetClassTyIdx(uint32 idx)202     void SetClassTyIdx(uint32 idx)
203     {
204         classTyIdx.reset(idx);
205     }
206 
AddArgument(MIRSymbol * st)207     void AddArgument(MIRSymbol *st)
208     {
209         DEBUG_ASSERT(st != nullptr, "null ptr check");
210         FormalDef formalDef(st->GetNameStrIdx(), st, st->GetTyIdx(), st->GetAttrs());
211         formalDefVec.push_back(formalDef);
212     }
213 
AddFormalDef(const FormalDef & formalDef)214     void AddFormalDef(const FormalDef &formalDef)
215     {
216         formalDefVec.push_back(formalDef);
217     }
218 
GetParamSize()219     size_t GetParamSize() const
220     {
221         CHECK_FATAL(funcType != nullptr, "funcType is nullptr");
222         return funcType->GetParamTypeList().size();
223     }
224 
GetParamTypes()225     auto &GetParamTypes() const
226     {
227         CHECK_FATAL(funcType != nullptr, "funcType is nullptr");
228         return funcType->GetParamTypeList();
229     }
230 
GetNthParamTyIdx(size_t i)231     TyIdx GetNthParamTyIdx(size_t i) const
232     {
233         DEBUG_ASSERT(i < funcType->GetParamTypeList().size(), "array index out of range");
234         return funcType->GetParamTypeList()[i];
235     }
236 
237     const MIRType *GetNthParamType(size_t i) const;
238     MIRType *GetNthParamType(size_t i);
239 
GetNthParamAttr(size_t i)240     const TypeAttrs &GetNthParamAttr(size_t i) const
241     {
242         DEBUG_ASSERT(i < formalDefVec.size(), "array index out of range");
243         DEBUG_ASSERT(formalDefVec[i].formalSym != nullptr, "null ptr check");
244         return formalDefVec[i].formalSym->GetAttrs();
245     }
246     void UpdateFuncTypeAndFormalsAndReturnType(const std::vector<MIRSymbol *> &symbols, const TyIdx &retTyIdx,
247                                                bool clearOldArgs = false);
248     LabelIdx GetOrCreateLableIdxFromName(const std::string &name);
GetLabelStringIndex(LabelIdx labelIdx)249     GStrIdx GetLabelStringIndex(LabelIdx labelIdx) const
250     {
251         CHECK_FATAL(labelTab != nullptr, "labelTab is nullptr");
252         DEBUG_ASSERT(labelIdx < labelTab->Size(), "index out of range in GetLabelStringIndex");
253         return labelTab->GetSymbolFromStIdx(labelIdx);
254     }
GetLabelName(LabelIdx labelIdx)255     const std::string &GetLabelName(LabelIdx labelIdx) const
256     {
257         GStrIdx strIdx = GetLabelStringIndex(labelIdx);
258         return GlobalTables::GetStrTable().GetStringFromStrIdx(strIdx);
259     }
260 
261     const MIRSymbol *GetLocalOrGlobalSymbol(const StIdx &idx, bool checkFirst = false) const;
262     MIRSymbol *GetLocalOrGlobalSymbol(const StIdx &idx, bool checkFirst = false);
263 
GetAttrs()264     const FuncAttrs &GetAttrs() const
265     {
266         return funcAttrs;
267     }
268 
SetAttrs(FuncAttrs attr)269     void SetAttrs(FuncAttrs attr)
270     {
271         funcAttrs = attr;
272     }
273 
GetAttr(FuncAttrKind attrKind)274     bool GetAttr(FuncAttrKind attrKind) const
275     {
276         return funcAttrs.GetAttr(attrKind);
277     }
278 
SetAttr(FuncAttrKind attrKind)279     void SetAttr(FuncAttrKind attrKind)
280     {
281         funcAttrs.SetAttr(attrKind);
282     }
283 
UnSetAttr(FuncAttrKind attrKind)284     void UnSetAttr(FuncAttrKind attrKind)
285     {
286         funcAttrs.SetAttr(attrKind, true);
287     }
288 
IsVarargs()289     bool IsVarargs() const
290     {
291         return funcAttrs.GetAttr(FUNCATTR_varargs);
292     }
293 
IsWeak()294     bool IsWeak() const
295     {
296         return funcAttrs.GetAttr(FUNCATTR_weak);
297     }
298 
IsStatic()299     bool IsStatic() const
300     {
301         return funcAttrs.GetAttr(FUNCATTR_static);
302     }
303 
IsInline()304     bool IsInline() const
305     {
306         return funcAttrs.GetAttr(FUNCATTR_inline);
307     }
308 
IsExtern()309     bool IsExtern() const
310     {
311         return funcAttrs.GetAttr(FUNCATTR_extern);
312     }
313 
IsNative()314     bool IsNative() const
315     {
316         return funcAttrs.GetAttr(FUNCATTR_native);
317     }
318 
IsFinal()319     bool IsFinal() const
320     {
321         return funcAttrs.GetAttr(FUNCATTR_final);
322     }
323 
IsAbstract()324     bool IsAbstract() const
325     {
326         return funcAttrs.GetAttr(FUNCATTR_abstract);
327     }
328 
IsPublic()329     bool IsPublic() const
330     {
331         return funcAttrs.GetAttr(FUNCATTR_public);
332     }
333 
IsPrivate()334     bool IsPrivate() const
335     {
336         return funcAttrs.GetAttr(FUNCATTR_private);
337     }
338 
IsProtected()339     bool IsProtected() const
340     {
341         return funcAttrs.GetAttr(FUNCATTR_protected);
342     }
343 
IsConstructor()344     bool IsConstructor() const
345     {
346         return funcAttrs.GetAttr(FUNCATTR_constructor);
347     }
348 
IsLocal()349     bool IsLocal() const
350     {
351         return funcAttrs.GetAttr(FUNCATTR_local);
352     }
353 
IsNoDefArgEffect()354     bool IsNoDefArgEffect() const
355     {
356         return funcAttrs.GetAttr(FUNCATTR_nodefargeffect);
357     }
358 
IsNoDefEffect()359     bool IsNoDefEffect() const
360     {
361         return funcAttrs.GetAttr(FUNCATTR_nodefeffect);
362     }
363 
IsNoRetGlobal()364     bool IsNoRetGlobal() const
365     {
366         return funcAttrs.GetAttr(FUNCATTR_noretglobal);
367     }
368 
IsNoThrowException()369     bool IsNoThrowException() const
370     {
371         return funcAttrs.GetAttr(FUNCATTR_nothrow_exception);
372     }
373 
IsNoRetArg()374     bool IsNoRetArg() const
375     {
376         return funcAttrs.GetAttr(FUNCATTR_noretarg);
377     }
378 
IsNoPrivateDefEffect()379     bool IsNoPrivateDefEffect() const
380     {
381         return funcAttrs.GetAttr(FUNCATTR_noprivate_defeffect);
382     }
383 
IsIpaSeen()384     bool IsIpaSeen() const
385     {
386         return funcAttrs.GetAttr(FUNCATTR_ipaseen);
387     }
388 
IsPure()389     bool IsPure() const
390     {
391         return funcAttrs.GetAttr(FUNCATTR_pure);
392     }
393 
IsFirstArgReturn()394     bool IsFirstArgReturn() const
395     {
396         return funcAttrs.GetAttr(FUNCATTR_firstarg_return);
397     }
398 
IsUnSafe()399     bool IsUnSafe() const
400     {
401         return !funcAttrs.GetAttr(FUNCATTR_safed) || funcAttrs.GetAttr(FUNCATTR_unsafed);
402     }
403 
IsSafe()404     bool IsSafe() const
405     {
406         return funcAttrs.GetAttr(FUNCATTR_safed);
407     }
408 
SetVarArgs()409     void SetVarArgs()
410     {
411         funcAttrs.SetAttr(FUNCATTR_varargs);
412     }
413 
SetNoDefArgEffect()414     void SetNoDefArgEffect()
415     {
416         funcAttrs.SetAttr(FUNCATTR_nodefargeffect);
417     }
418 
SetNoDefEffect()419     void SetNoDefEffect()
420     {
421         funcAttrs.SetAttr(FUNCATTR_nodefeffect);
422     }
423 
SetNoRetGlobal()424     void SetNoRetGlobal()
425     {
426         funcAttrs.SetAttr(FUNCATTR_noretglobal);
427     }
428 
SetNoThrowException()429     void SetNoThrowException()
430     {
431         funcAttrs.SetAttr(FUNCATTR_nothrow_exception);
432     }
433 
SetNoRetArg()434     void SetNoRetArg()
435     {
436         funcAttrs.SetAttr(FUNCATTR_noretarg);
437     }
438 
SetNoPrivateDefEffect()439     void SetNoPrivateDefEffect()
440     {
441         funcAttrs.SetAttr(FUNCATTR_noprivate_defeffect);
442     }
443 
SetIpaSeen()444     void SetIpaSeen()
445     {
446         funcAttrs.SetAttr(FUNCATTR_ipaseen);
447     }
448 
SetPure()449     void SetPure()
450     {
451         funcAttrs.SetAttr(FUNCATTR_pure);
452     }
453 
SetFirstArgReturn()454     void SetFirstArgReturn()
455     {
456         funcAttrs.SetAttr(FUNCATTR_firstarg_return);
457     }
458 
UnsetNoDefArgEffect()459     void UnsetNoDefArgEffect()
460     {
461         funcAttrs.SetAttr(FUNCATTR_nodefargeffect, true);
462     }
463 
UnsetNoDefEffect()464     void UnsetNoDefEffect()
465     {
466         funcAttrs.SetAttr(FUNCATTR_nodefeffect, true);
467     }
468 
UnsetNoRetGlobal()469     void UnsetNoRetGlobal()
470     {
471         funcAttrs.SetAttr(FUNCATTR_noretglobal, true);
472     }
473 
UnsetNoThrowException()474     void UnsetNoThrowException()
475     {
476         funcAttrs.SetAttr(FUNCATTR_nothrow_exception, true);
477     }
478 
UnsetPure()479     void UnsetPure()
480     {
481         funcAttrs.SetAttr(FUNCATTR_pure, true);
482     }
483 
UnsetNoRetArg()484     void UnsetNoRetArg()
485     {
486         funcAttrs.SetAttr(FUNCATTR_noretarg, true);
487     }
488 
UnsetNoPrivateDefEffect()489     void UnsetNoPrivateDefEffect()
490     {
491         funcAttrs.SetAttr(FUNCATTR_noprivate_defeffect, true);
492     }
493 
494     bool HasCall() const;
495     void SetHasCall();
496 
497 #ifdef ARK_LITECG_DEBUG
498     bool IsInfoPrinted() const;
499     void SetInfoPrinted();
500     void ResetInfoPrinted();
501 #endif
IsAFormal(const MIRSymbol * st)502     bool IsAFormal(const MIRSymbol *st) const
503     {
504         for (const auto &formalDef : formalDefVec) {
505             if (st == formalDef.formalSym) {
506                 return true;
507             }
508         }
509         return false;
510     }
511 
GetFormalIndex(const MIRSymbol * symbol)512     uint32 GetFormalIndex(const MIRSymbol *symbol) const
513     {
514         for (size_t i = 0; i < formalDefVec.size(); ++i) {
515             if (formalDefVec[i].formalSym == symbol) {
516                 return i;
517             }
518         }
519         return 0xffffffff;
520     }
521 
GetFormalDefFromMIRSymbol(const MIRSymbol * symbol)522     FormalDef &GetFormalDefFromMIRSymbol(const MIRSymbol *symbol)
523     {
524         for (auto &formalDef : formalDefVec) {
525             if (formalDef.formalSym == symbol) {
526                 return formalDef;
527             }
528         }
529         CHECK_FATAL(false, "Impossible.");
530     }
531 
IsAFormalName(const GStrIdx idx)532     bool IsAFormalName(const GStrIdx idx) const
533     {
534         for (const auto &formalDef : formalDefVec) {
535             if (idx == formalDef.formalStrIdx) {
536                 return true;
537             }
538         }
539         return false;
540     }
541 
GetFormalFromName(const GStrIdx idx)542     const FormalDef GetFormalFromName(const GStrIdx idx) const
543     {
544         for (size_t i = 0; i < formalDefVec.size(); ++i) {
545             if (formalDefVec[i].formalStrIdx == idx) {
546                 return formalDefVec[i];
547             }
548         }
549         return FormalDef();
550     }
551 
ReleaseMemory()552     void ReleaseMemory()
553     {
554         if (codeMemPoolTmp != nullptr) {
555             delete codeMemPoolTmp;
556             codeMemPoolTmp = nullptr;
557         }
558     }
559 
ReleaseCodeMemory()560     void ReleaseCodeMemory()
561     {
562         if (codeMemPool != nullptr) {
563             codeMemPoolAllocator.SetMemPool(nullptr);
564             delete codeMemPool;
565             codeMemPool = nullptr;
566             SetMemPool(nullptr);
567         }
568     }
569 
GetCodeMempool()570     MemPool *GetCodeMempool()
571     {
572         if (useTmpMemPool) {
573             if (codeMemPoolTmp == nullptr) {
574                 codeMemPoolTmp = new ThreadLocalMemPool(memPoolCtrler, "func code mempool");
575                 codeMemPoolTmpAllocator.SetMemPool(codeMemPoolTmp);
576             }
577             return codeMemPoolTmp;
578         }
579         if (codeMemPool == nullptr) {
580             codeMemPool = new ThreadLocalMemPool(memPoolCtrler, "func code mempool");
581             codeMemPoolAllocator.SetMemPool(codeMemPool);
582         }
583         return codeMemPool;
584     }
585 
GetCodeMemPoolAllocator()586     MapleAllocator &GetCodeMemPoolAllocator()
587     {
588         GetCodeMempool();
589         if (useTmpMemPool) {
590             return codeMemPoolTmpAllocator;
591         }
592         return codeMemPoolAllocator;
593     }
594 
GetCodeMempoolAllocator()595     MapleAllocator &GetCodeMempoolAllocator()
596     {
597         if (codeMemPool == nullptr) {
598             codeMemPool = new ThreadLocalMemPool(memPoolCtrler, "func code mempool");
599             codeMemPoolAllocator.SetMemPool(codeMemPool);
600         }
601         return codeMemPoolAllocator;
602     }
603 
604     void EnterFormals();
605     void NewBody();
606 
GetModule()607     MIRModule *GetModule()
608     {
609         return module;
610     }
611 
GetPuidx()612     PUIdx GetPuidx() const
613     {
614         return puIdx;
615     }
SetPuidx(PUIdx idx)616     void SetPuidx(PUIdx idx)
617     {
618         puIdx = idx;
619     }
620 
GetPuidxOrigin()621     PUIdx GetPuidxOrigin() const
622     {
623         return puIdxOrigin;
624     }
SetPuidxOrigin(PUIdx idx)625     void SetPuidxOrigin(PUIdx idx)
626     {
627         puIdxOrigin = idx;
628     }
629 
GetStIdx()630     StIdx GetStIdx() const
631     {
632         return symbolTableIdx;
633     }
SetStIdx(StIdx stIdx)634     void SetStIdx(StIdx stIdx)
635     {
636         symbolTableIdx = stIdx;
637     }
638 
GetSCCId()639     int32 GetSCCId() const
640     {
641         return sccID;
642     }
SetSCCId(int32 id)643     void SetSCCId(int32 id)
644     {
645         sccID = id;
646     }
647 
GetMIRFuncType()648     MIRFuncType *GetMIRFuncType()
649     {
650         return funcType;
651     }
SetMIRFuncType(MIRFuncType * type)652     void SetMIRFuncType(MIRFuncType *type)
653     {
654         funcType = type;
655     }
656 
GetInferredReturnTyIdx()657     TyIdx GetInferredReturnTyIdx() const
658     {
659         return inferredReturnTyIdx;
660     }
661 
SetInferredReturnTyIdx(TyIdx tyIdx)662     void SetInferredReturnTyIdx(TyIdx tyIdx)
663     {
664         inferredReturnTyIdx = tyIdx;
665     }
666 
GetTypeNameTab()667     MIRTypeNameTable *GetTypeNameTab() const
668     {
669         return typeNameTab;
670     }
671 
AllocTypeNameTab()672     void AllocTypeNameTab()
673     {
674         if (typeNameTab == nullptr) {
675             typeNameTab = module->GetMemPool()->New<MIRTypeNameTable>(module->GetMPAllocator());
676         }
677     }
HaveTypeNameTab()678     bool HaveTypeNameTab() const
679     {
680         return typeNameTab != nullptr;
681     }
GetGStrIdxToTyIdxMap()682     const MapleMap<GStrIdx, TyIdx> &GetGStrIdxToTyIdxMap() const
683     {
684         CHECK_FATAL(typeNameTab != nullptr, "typeNameTab is nullptr");
685         return typeNameTab->GetGStrIdxToTyIdxMap();
686     }
GetTyIdxFromGStrIdx(GStrIdx idx)687     TyIdx GetTyIdxFromGStrIdx(GStrIdx idx) const
688     {
689         CHECK_FATAL(typeNameTab != nullptr, "typeNameTab is nullptr");
690         return typeNameTab->GetTyIdxFromGStrIdx(idx);
691     }
SetGStrIdxToTyIdx(GStrIdx gStrIdx,TyIdx tyIdx)692     void SetGStrIdxToTyIdx(GStrIdx gStrIdx, TyIdx tyIdx)
693     {
694         CHECK_FATAL(typeNameTab != nullptr, "typeNameTab is nullptr");
695         typeNameTab->SetGStrIdxToTyIdx(gStrIdx, tyIdx);
696     }
697 
GetLabelTabItem(LabelIdx labelIdx)698     const std::string &GetLabelTabItem(LabelIdx labelIdx) const
699     {
700         CHECK_FATAL(labelTab != nullptr, "labelTab is nullptr");
701         return labelTab->GetName(labelIdx);
702     }
703 
AllocLabelTab()704     void AllocLabelTab()
705     {
706         if (labelTab == nullptr) {
707             labelTab = module->GetMemPool()->New<MIRLabelTable>(module->GetMPAllocator());
708         }
709     }
710 
GetPregTab()711     MIRPregTable *GetPregTab() const
712     {
713         return pregTab;
714     }
715 
SetPregTab(MIRPregTable * tab)716     void SetPregTab(MIRPregTable *tab)
717     {
718         pregTab = tab;
719     }
AllocPregTab()720     void AllocPregTab()
721     {
722         if (pregTab == nullptr) {
723             pregTab = module->GetMemPool()->New<MIRPregTable>(&module->GetMPAllocator());
724         }
725     }
GetPregItem(PregIdx idx)726     MIRPreg *GetPregItem(PregIdx idx)
727     {
728         return const_cast<MIRPreg *>(const_cast<const MIRFunction *>(this)->GetPregItem(idx));
729     }
GetPregItem(PregIdx idx)730     const MIRPreg *GetPregItem(PregIdx idx) const
731     {
732         return pregTab->PregFromPregIdx(idx);
733     }
734 
GetBody()735     BlockNode *GetBody()
736     {
737         return body;
738     }
GetBody()739     const BlockNode *GetBody() const
740     {
741         return body;
742     }
SetBody(BlockNode * node)743     void SetBody(BlockNode *node)
744     {
745         body = node;
746     }
747 
GetLastPosBody()748     BlockNode *GetLastPosBody()
749     {
750         return bodyLast;
751     }
GetLastPosBody()752     const BlockNode *GetLastPosBody() const
753     {
754         return bodyLast;
755     }
SetLastPosBody(BlockNode * node)756     void SetLastPosBody(BlockNode *node)
757     {
758         bodyLast = node;
759     }
760 
GetSrcPosition()761     SrcPosition &GetSrcPosition()
762     {
763         DEBUG_ASSERT(GetFuncSymbol() != nullptr, "null ptr check");
764         return GetFuncSymbol()->GetSrcPosition();
765     }
766 
SetSrcPosition(const SrcPosition & position)767     void SetSrcPosition(const SrcPosition &position)
768     {
769         DEBUG_ASSERT(GetFuncSymbol() != nullptr, "null ptr check");
770         GetFuncSymbol()->SetSrcPosition(position);
771     }
772 
GetFuncAttrs()773     const FuncAttrs &GetFuncAttrs() const
774     {
775         return funcAttrs;
776     }
GetFuncAttrs()777     FuncAttrs &GetFuncAttrs()
778     {
779         return funcAttrs;
780     }
781 
SetFuncAttrs(const FuncAttrs & attrs)782     void SetFuncAttrs(const FuncAttrs &attrs)
783     {
784         funcAttrs = attrs;
785     }
SetFuncAttrs(uint64 attrFlag)786     void SetFuncAttrs(uint64 attrFlag)
787     {
788         funcAttrs.SetAttrFlag(attrFlag);
789     }
790 
GetFlag()791     uint32 GetFlag() const
792     {
793         return flag;
794     }
SetFlag(uint32 newFlag)795     void SetFlag(uint32 newFlag)
796     {
797         flag = newFlag;
798     }
799 
GetHashCode()800     uint16 GetHashCode() const
801     {
802         return hashCode;
803     }
SetHashCode(uint16 newHashCode)804     void SetHashCode(uint16 newHashCode)
805     {
806         hashCode = newHashCode;
807     }
808 
SetFileIndex(uint32 newFileIndex)809     void SetFileIndex(uint32 newFileIndex)
810     {
811         fileIndex = newFileIndex;
812     }
813 
GetInfoVector()814     MIRInfoVector &GetInfoVector()
815     {
816         return info;
817     }
818 
GetInfoPair(size_t i)819     const MIRInfoPair &GetInfoPair(size_t i) const
820     {
821         return info.at(i);
822     }
823 
PushbackMIRInfo(const MIRInfoPair & pair)824     void PushbackMIRInfo(const MIRInfoPair &pair)
825     {
826         info.push_back(pair);
827     }
828 
SetMIRInfoNum(size_t idx,uint32 num)829     void SetMIRInfoNum(size_t idx, uint32 num)
830     {
831         info[idx].second = num;
832     }
833 
InfoIsString()834     MapleVector<bool> &InfoIsString()
835     {
836         return infoIsString;
837     }
838 
PushbackIsString(bool isString)839     void PushbackIsString(bool isString)
840     {
841         infoIsString.push_back(isString);
842     }
843 
HasVlaOrAlloca()844     bool HasVlaOrAlloca() const
845     {
846         return hasVlaOrAlloca;
847     }
SetVlaOrAlloca(bool has)848     void SetVlaOrAlloca(bool has)
849     {
850         hasVlaOrAlloca = has;
851     }
852 
853     // Default freq is the lastStmtFreq
HasFreqMap()854     bool HasFreqMap() const
855     {
856         return freqLastMap != nullptr;
857     }
858 
HasFirstFreqMap()859     bool HasFirstFreqMap() const
860     {
861         return freqFirstMap != nullptr;
862     }
863 
GetFirstFreqMap()864     const MapleMap<uint32, uint32> &GetFirstFreqMap() const
865     {
866         return *freqFirstMap;
867     }
868 
SetFirstFreqMap(uint32 stmtID,uint32 freq)869     void SetFirstFreqMap(uint32 stmtID, uint32 freq)
870     {
871         if (freqFirstMap == nullptr) {
872             freqFirstMap = module->GetMemPool()->New<MapleMap<uint32, uint32>>(module->GetMPAllocator().Adapter());
873         }
874         (*freqFirstMap)[stmtID] = freq;
875     }
876 
GetLastFreqMap()877     const MapleMap<uint32, uint32> &GetLastFreqMap() const
878     {
879         return *freqLastMap;
880     }
881 
GetFreqFromLastStmt(uint32 stmtId)882     int32 GetFreqFromLastStmt(uint32 stmtId)
883     {
884         if (freqLastMap == nullptr) {
885             return -1;
886         }
887         if ((*freqLastMap).find(stmtId) == (*freqLastMap).end()) {
888             return -1;
889         }
890         return static_cast<int32>((*freqLastMap)[stmtId]);
891     }
892 
GetFreqFromFirstStmt(uint32 stmtId)893     int32 GetFreqFromFirstStmt(uint32 stmtId)
894     {
895         if (freqFirstMap == nullptr) {
896             return -1;
897         }
898         if ((*freqFirstMap).find(stmtId) == (*freqFirstMap).end()) {
899             return -1;
900         }
901         return static_cast<int32>((*freqFirstMap)[stmtId]);
902     }
903 
SetLastFreqMap(uint32 stmtID,uint32 freq)904     void SetLastFreqMap(uint32 stmtID, uint32 freq)
905     {
906         if (freqLastMap == nullptr) {
907             freqLastMap = module->GetMemPool()->New<MapleMap<uint32, uint32>>(module->GetMPAllocator().Adapter());
908         }
909         (*freqLastMap)[stmtID] = freq;
910     }
911 
WithLocInfo()912     bool WithLocInfo() const
913     {
914         return withLocInfo;
915     }
SetWithLocInfo(bool withInfo)916     void SetWithLocInfo(bool withInfo)
917     {
918         withLocInfo = withInfo;
919     }
920 
IsDirty()921     bool IsDirty() const
922     {
923         return isDirty;
924     }
SetDirty(bool dirty)925     void SetDirty(bool dirty)
926     {
927         isDirty = dirty;
928     }
929 
IsFromMpltInline()930     bool IsFromMpltInline() const
931     {
932         return fromMpltInline;
933     }
SetFromMpltInline(bool isInline)934     void SetFromMpltInline(bool isInline)
935     {
936         fromMpltInline = isInline;
937     }
938 
GetLayoutType()939     uint8 GetLayoutType() const
940     {
941         return layoutType;
942     }
SetLayoutType(uint8 type)943     void SetLayoutType(uint8 type)
944     {
945         layoutType = type;
946     }
947 
GetCallTimes()948     uint32 GetCallTimes() const
949     {
950         return callTimes;
951     }
SetCallTimes(uint32 times)952     void SetCallTimes(uint32 times)
953     {
954         callTimes = times;
955     }
956 
GetFrameSize()957     uint32 GetFrameSize() const
958     {
959         return frameSize;
960     }
SetFrameSize(uint32 size)961     void SetFrameSize(uint32 size)
962     {
963         frameSize = size;
964     }
965 
GetUpFormalSize()966     uint32 GetUpFormalSize() const
967     {
968         return upFormalSize;
969     }
SetUpFormalSize(uint32 size)970     void SetUpFormalSize(uint32 size)
971     {
972         upFormalSize = size;
973     }
974 
GetOutParmSize()975     uint32 GetOutParmSize() const
976     {
977         return outParmSize;
978     }
SetOutParmSize(uint32 size)979     void SetOutParmSize(uint32 size)
980     {
981         outParmSize = size;
982     }
983 
GetModuleId()984     uint16 GetModuleId() const
985     {
986         return moduleID;
987     }
SetModuleID(uint16 id)988     void SetModuleID(uint16 id)
989     {
990         moduleID = id;
991     }
992 
GetFuncSize()993     uint32 GetFuncSize() const
994     {
995         return funcSize;
996     }
SetFuncSize(uint32 size)997     void SetFuncSize(uint32 size)
998     {
999         funcSize = size;
1000     }
1001 
GetTempCount()1002     uint32 GetTempCount() const
1003     {
1004         return tempCount;
1005     }
IncTempCount()1006     void IncTempCount()
1007     {
1008         ++tempCount;
1009     }
1010 
GetFormalWordsTypeTagged()1011     uint8 *GetFormalWordsTypeTagged() const
1012     {
1013         return formalWordsTypeTagged;
1014     }
SetFormalWordsTypeTagged(uint8 * tagged)1015     void SetFormalWordsTypeTagged(uint8 *tagged)
1016     {
1017         formalWordsTypeTagged = tagged;
1018     }
GetFwtAddress()1019     uint8 **GetFwtAddress()
1020     {
1021         return &formalWordsTypeTagged;
1022     }
1023 
GetLocalWordsTypeTagged()1024     uint8 *GetLocalWordsTypeTagged() const
1025     {
1026         return localWordsTypeTagged;
1027     }
SetLocalWordsTypeTagged(uint8 * tagged)1028     void SetLocalWordsTypeTagged(uint8 *tagged)
1029     {
1030         localWordsTypeTagged = tagged;
1031     }
GetLwtAddress()1032     uint8 **GetLwtAddress()
1033     {
1034         return &localWordsTypeTagged;
1035     }
1036 
GetFormalWordsRefCounted()1037     uint8 *GetFormalWordsRefCounted() const
1038     {
1039         return formalWordsRefCounted;
1040     }
SetFormalWordsRefCounted(uint8 * counted)1041     void SetFormalWordsRefCounted(uint8 *counted)
1042     {
1043         formalWordsRefCounted = counted;
1044     }
GetFwrAddress()1045     uint8 **GetFwrAddress()
1046     {
1047         return &formalWordsRefCounted;
1048     }
1049 
GetLocalWordsRefCounted()1050     uint8 *GetLocalWordsRefCounted() const
1051     {
1052         return localWordsRefCounted;
1053     }
SetLocalWordsRefCounted(uint8 * counted)1054     void SetLocalWordsRefCounted(uint8 *counted)
1055     {
1056         localWordsRefCounted = counted;
1057     }
1058 
GetMeFunc()1059     MeFunction *GetMeFunc()
1060     {
1061         return meFunc;
1062     }
1063 
SetMeFunc(MeFunction * func)1064     void SetMeFunc(MeFunction *func)
1065     {
1066         meFunc = func;
1067     }
1068 
GetEACG()1069     EAConnectionGraph *GetEACG()
1070     {
1071         return eacg;
1072     }
SetEACG(EAConnectionGraph * eacgVal)1073     void SetEACG(EAConnectionGraph *eacgVal)
1074     {
1075         eacg = eacgVal;
1076     }
1077 
SetFormalDefVec(const MapleVector<FormalDef> & currFormals)1078     void SetFormalDefVec(const MapleVector<FormalDef> &currFormals)
1079     {
1080         formalDefVec = currFormals;
1081     }
1082 
GetFormalDefVec()1083     MapleVector<FormalDef> &GetFormalDefVec()
1084     {
1085         return formalDefVec;
1086     }
1087 
GetFormalDefAt(size_t i)1088     const FormalDef &GetFormalDefAt(size_t i) const
1089     {
1090         return formalDefVec[i];
1091     }
1092 
GetFormalDefAt(size_t i)1093     FormalDef &GetFormalDefAt(size_t i)
1094     {
1095         return formalDefVec[i];
1096     }
1097 
GetFormal(size_t i)1098     const MIRSymbol *GetFormal(size_t i) const
1099     {
1100         return formalDefVec[i].formalSym;
1101     }
1102 
GetFormal(size_t i)1103     MIRSymbol *GetFormal(size_t i)
1104     {
1105         return formalDefVec[i].formalSym;
1106     }
1107 
GetFormalName(size_t i)1108     const std::string &GetFormalName(size_t i) const
1109     {
1110         auto *formal = formalDefVec[i].formalSym;
1111         if (formal != nullptr) {
1112             return formal->GetName();
1113         }
1114         return GlobalTables::GetStrTable().GetStringFromStrIdx(formalDefVec[i].formalStrIdx);
1115     }
1116 
GetFormalCount()1117     size_t GetFormalCount() const
1118     {
1119         return formalDefVec.size();
1120     }
1121 
ClearFormals()1122     void ClearFormals()
1123     {
1124         formalDefVec.clear();
1125     }
1126 
ClearArguments()1127     void ClearArguments()
1128     {
1129         formalDefVec.clear();
1130         funcType->GetParamTypeList().clear();
1131         funcType->GetParamAttrsList().clear();
1132     }
1133 
GetSymbolTabSize()1134     size_t GetSymbolTabSize() const
1135     {
1136         DEBUG_ASSERT(symTab != nullptr, "symTab is nullptr");
1137         return symTab->GetSymbolTableSize();
1138     }
1139     MIRSymbol *GetSymbolTabItem(uint32 idx, bool checkFirst = false) const
1140     {
1141         return symTab->GetSymbolFromStIdx(idx, checkFirst);
1142     }
GetSymTab()1143     const MIRSymbolTable *GetSymTab() const
1144     {
1145         return symTab;
1146     }
GetSymTab()1147     MIRSymbolTable *GetSymTab()
1148     {
1149         return symTab;
1150     }
AllocSymTab()1151     void AllocSymTab()
1152     {
1153         if (symTab == nullptr) {
1154             symTab = module->GetMemPool()->New<MIRSymbolTable>(module->GetMPAllocator());
1155         }
1156     }
GetLabelTab()1157     MIRLabelTable *GetLabelTab() const
1158     {
1159         CHECK_FATAL(labelTab != nullptr, "must be");
1160         return labelTab;
1161     }
GetLabelTab()1162     MIRLabelTable *GetLabelTab()
1163     {
1164         if (labelTab == nullptr) {
1165             labelTab = module->GetMemPool()->New<MIRLabelTable>(module->GetMPAllocator());
1166         }
1167         return labelTab;
1168     }
SetLabelTab(MIRLabelTable * currLabelTab)1169     void SetLabelTab(MIRLabelTable *currLabelTab)
1170     {
1171         labelTab = currLabelTab;
1172     }
1173 
GetRetRefSym()1174     const MapleSet<MIRSymbol *> &GetRetRefSym() const
1175     {
1176         return retRefSym;
1177     }
InsertMIRSymbol(MIRSymbol * sym)1178     void InsertMIRSymbol(MIRSymbol *sym)
1179     {
1180         (void)retRefSym.insert(sym);
1181     }
1182 
GetDataMemPool()1183     MemPool *GetDataMemPool() const
1184     {
1185         return module->GetMemPool();
1186     }
1187 
GetCodeMemPool()1188     MemPool *GetCodeMemPool()
1189     {
1190         if (codeMemPool == nullptr) {
1191             codeMemPool = new ThreadLocalMemPool(memPoolCtrler, "func code mempool");
1192             codeMemPoolAllocator.SetMemPool(codeMemPool);
1193         }
1194         return codeMemPool;
1195     }
1196 
SetCodeMemPool(MemPool * currCodeMemPool)1197     void SetCodeMemPool(MemPool *currCodeMemPool)
1198     {
1199         codeMemPool = currCodeMemPool;
1200     }
1201 
GetCodeMPAllocator()1202     MapleAllocator &GetCodeMPAllocator()
1203     {
1204         GetCodeMemPool();
1205         return codeMemPoolAllocator;
1206     }
1207 
AddFuncGenericDeclare(GenericDeclare * g)1208     void AddFuncGenericDeclare(GenericDeclare *g)
1209     {
1210         genericDeclare.push_back(g);
1211     }
1212 
AddFuncGenericArg(AnnotationType * a)1213     void AddFuncGenericArg(AnnotationType *a)
1214     {
1215         genericArg.push_back(a);
1216     }
1217 
AddFuncGenericRet(AnnotationType * r)1218     void AddFuncGenericRet(AnnotationType *r)
1219     {
1220         genericRet = r;
1221     }
1222 
AddFuncLocalGenericVar(const GStrIdx & str,AnnotationType * at)1223     void AddFuncLocalGenericVar(const GStrIdx &str, AnnotationType *at)
1224     {
1225         genericLocalVar[str] = at;
1226     }
1227 
GetFuncGenericDeclare()1228     MapleVector<GenericDeclare *> &GetFuncGenericDeclare()
1229     {
1230         return genericDeclare;
1231     }
1232 
GetFuncGenericArg()1233     MapleVector<AnnotationType *> &GetFuncGenericArg()
1234     {
1235         return genericArg;
1236     }
1237 
SetRetrunAttrKind(const PointerAttr kind)1238     void SetRetrunAttrKind(const PointerAttr kind)
1239     {
1240         returnKind = kind;
1241     }
1242 
GetRetrunAttrKind()1243     PointerAttr GetRetrunAttrKind() const
1244     {
1245         return returnKind;
1246     }
1247 
GetFuncGenericRet()1248     AnnotationType *GetFuncGenericRet()
1249     {
1250         return genericRet;
1251     }
1252 
GetFuncLocalGenericVar(const GStrIdx & str)1253     AnnotationType *GetFuncLocalGenericVar(const GStrIdx &str)
1254     {
1255         if (genericLocalVar.find(str) == genericLocalVar.end()) {
1256             return nullptr;
1257         }
1258         return genericLocalVar[str];
1259     }
1260 
GetCodeMemPoolTmp()1261     MemPool *GetCodeMemPoolTmp()
1262     {
1263         if (codeMemPoolTmp == nullptr) {
1264             codeMemPoolTmp = new ThreadLocalMemPool(memPoolCtrler, "func code mempool");
1265             codeMemPoolTmpAllocator.SetMemPool(codeMemPoolTmp);
1266         }
1267         return codeMemPoolTmp;
1268     }
1269 
CheckParamNullType(MIRSymbol * sym)1270     bool CheckParamNullType(MIRSymbol *sym)
1271     {
1272         return paramNonullTypeMap.find(sym) != paramNonullTypeMap.end();
1273     }
1274 
GetParamNonull(MIRSymbol * sym)1275     PointerAttr GetParamNonull(MIRSymbol *sym)
1276     {
1277         return paramNonullTypeMap[sym];
1278     }
1279 
SetParamNonull(MIRSymbol * sym,PointerAttr type)1280     void SetParamNonull(MIRSymbol *sym, PointerAttr type)
1281     {
1282         paramNonullTypeMap[sym] = type;
1283     }
1284 
CopyReferedRegs(std::set<uint32> regs)1285     void CopyReferedRegs(std::set<uint32> regs)
1286     {
1287         for (auto reg : regs) {
1288             referedPregs.insert(reg);
1289         }
1290     }
1291 
GetReferedRegs()1292     MapleSet<uint32> GetReferedRegs() const
1293     {
1294         return referedPregs;
1295     }
1296 
SetDerived2BaseRef(PregIdx deriveRef,PregIdx baseRef)1297     void SetDerived2BaseRef(PregIdx deriveRef, PregIdx baseRef)
1298     {
1299         CHECK_FATAL(derived2BaseRef.find(deriveRef) == derived2BaseRef.end(), "derived2BaseRef double set");
1300         derived2BaseRef[deriveRef] = baseRef;
1301     }
1302 
GetDerived2BaseRef()1303     const MapleUnorderedMap<PregIdx, PregIdx> &GetDerived2BaseRef() const
1304     {
1305         return derived2BaseRef;
1306     }
1307 
IsReferedRegsValid()1308     bool IsReferedRegsValid() const
1309     {
1310         return referedRegsValid;
1311     }
1312 
SetReferedRegsValid(bool val)1313     void SetReferedRegsValid(bool val)
1314     {
1315         referedRegsValid = val;
1316     }
1317 
GetFuncDesc()1318     FuncDesc &GetFuncDesc()
1319     {
1320         return funcDesc;
1321     }
1322 
SetFuncDesc(const FuncDesc & value)1323     void SetFuncDesc(const FuncDesc &value)
1324     {
1325         funcDesc = value;
1326     }
1327 
InitFuncDescToBest()1328     void InitFuncDescToBest()
1329     {
1330         funcDesc.InitToBest();
1331     }
1332 
GetFuncDesc()1333     const FuncDesc &GetFuncDesc() const
1334     {
1335         return funcDesc;
1336     }
1337 
IsVisited()1338     bool IsVisited() const
1339     {
1340         return isVisited;
1341     }
SetIsVisited()1342     void SetIsVisited()
1343     {
1344         isVisited = true;
1345     }
1346 
SetFuncProfData(GcovFuncInfo * data)1347     void SetFuncProfData(GcovFuncInfo *data)
1348     {
1349         funcProfData = data;
1350     }
GetFuncProfData()1351     GcovFuncInfo *GetFuncProfData()
1352     {
1353         return funcProfData;
1354     }
GetFuncProfData()1355     GcovFuncInfo *GetFuncProfData() const
1356     {
1357         return funcProfData;
1358     }
SetStmtFreq(uint32_t stmtID,uint64_t freq)1359     void SetStmtFreq(uint32_t stmtID, uint64_t freq)
1360     {
1361         DEBUG_ASSERT((funcProfData != nullptr && freq > 0), "nullptr check");
1362         funcProfData->SetStmtFreq(stmtID, static_cast<int64_t>(freq));
1363     }
1364 
SetWithSrc(bool var)1365     void SetWithSrc(bool var)
1366     {
1367         withSrc = var;
1368     }
1369 
GetWithSrc()1370     bool GetWithSrc() const
1371     {
1372         return withSrc;
1373     }
1374 
GetFrameReseverdSlot()1375     uint8 GetFrameReseverdSlot()
1376     {
1377         return funcAttrs.GetFrameResverdSlot();
1378     }
1379 
GetMemReferenceTable()1380     MemReferenceTable *GetMemReferenceTable()
1381     {
1382         return memReferenceTable;
1383     }
1384 
DiscardMemReferenceTable()1385     void DiscardMemReferenceTable()
1386     {
1387         memReferenceTable = nullptr;
1388     }
1389 
1390     void CreateMemReferenceTable();
1391 
1392     MemReferenceTable *GetOrCreateMemReferenceTable();
1393 
AddNewDebugComment(const std::string & dbgComment)1394     const MapleString* AddNewDebugComment(const std::string& dbgComment)
1395     {
1396         return &debugComments.emplace_back(dbgComment, module->GetMPAllocator().GetMemPool());
1397     }
1398 
SetIsDeoptFunc()1399     void SetIsDeoptFunc()
1400     {
1401         isDeoptFunc = true;
1402     }
1403 
IsDeoptFunc()1404     bool IsDeoptFunc() const
1405     {
1406         return isDeoptFunc;
1407     }
1408 private:
1409     MIRModule *module;      // the module that owns this function
1410     PUIdx puIdx = 0;        // the PU index of this function
1411     PUIdx puIdxOrigin = 0;  // the original puIdx when initial generation
1412     StIdx symbolTableIdx;   // the symbol table index of this function
1413     int32 sccID = -1;       // the scc id of this function, for mplipa
1414     MIRFuncType *funcType = nullptr;
1415     TyIdx inferredReturnTyIdx {0};  // the actual return type of of this function (may be a
1416                                     // subclass of the above). 0 means can not be inferred.
1417     TyIdx classTyIdx {0};           // class/interface type this function belongs to
1418     MapleVector<FormalDef> formalDefVec {module->GetMPAllocator().Adapter()};  // the formals in function definition
1419     MapleSet<MIRSymbol *> retRefSym {module->GetMPAllocator().Adapter()};
1420 
1421     MapleVector<GenericDeclare *> genericDeclare {module->GetMPAllocator().Adapter()};
1422     MapleVector<AnnotationType *> genericArg {module->GetMPAllocator().Adapter()};
1423     MapleMap<GStrIdx, AnnotationType *> genericLocalVar {module->GetMPAllocator().Adapter()};
1424     AnnotationType *genericRet = nullptr;
1425 
1426     MIRSymbolTable *symTab = nullptr;
1427     MIRTypeNameTable *typeNameTab = nullptr;
1428     MIRLabelTable *labelTab = nullptr;
1429     MIRPregTable *pregTab = nullptr;
1430     MemPool *codeMemPool = nullptr;
1431     MapleAllocator codeMemPoolAllocator {nullptr};
1432     uint32 callTimes = 0;
1433     BlockNode *body = nullptr;
1434     BlockNode *bodyLast = nullptr;
1435     FuncAttrs funcAttrs {};
1436     uint32 flag = 0;
1437     uint16 hashCode = 0;   // for methodmetadata order
1438     uint32 fileIndex = 0;  // this function belongs to which file, used by VM for plugin manager
1439     MIRInfoVector info {module->GetMPAllocator().Adapter()};
1440     MapleVector<bool> infoIsString {module->GetMPAllocator().Adapter()};  // tells if an entry has string value
1441     MapleMap<uint32, uint32> *freqFirstMap = nullptr;  // save bb frequency in its first_stmt, key is stmtId
1442     MapleMap<uint32, uint32> *freqLastMap = nullptr;   // save bb frequency in its last_stmt, key is stmtId
1443     MapleSet<uint32> referedPregs {module->GetMPAllocator().Adapter()};
1444     MapleUnorderedMap<PregIdx, PregIdx> derived2BaseRef {module->GetMPAllocator().Adapter()};
1445     bool referedRegsValid = false;
1446     bool hasVlaOrAlloca = false;
1447     bool withLocInfo = true;
1448     bool withSrc = true;
1449     bool isVisited = false;  // only used in inline phase.
1450     bool isDirty = false;
1451     bool fromMpltInline = false;  // Whether this function is imported from mplt_inline file or not.
1452     uint8_t layoutType = kLayoutUnused;
1453     uint32 frameSize = 0;
1454     uint32 upFormalSize = 0;
1455     uint32 outParmSize = 0;
1456     uint16 moduleID = 0;
1457     uint32 funcSize = 0;  // size of code in words
1458     uint32 tempCount = 0;
1459     uint8 *formalWordsTypeTagged = nullptr;  // bit vector where the Nth bit tells whether
1460     // the Nth word in the formal parameters area
1461     // addressed upward from %%FP (that means
1462     // the word at location (%%FP + N*4)) has
1463     // typetag; if yes, the typetag is the word
1464     // at (%%FP + N*4 + 4); the bitvector's size
1465     // is given by BlockSize2BitvectorSize(upFormalSize)
1466     uint8 *localWordsTypeTagged = nullptr;  // bit vector where the Nth bit tells whether
1467     // the Nth word in the local stack frame
1468     // addressed downward from %%FP (that means
1469     // the word at location (%%FP - N*4)) has
1470     // typetag; if yes, the typetag is the word
1471     // at (%%FP - N*4 + 4); the bitvector's size
1472     // is given by BlockSize2BitvectorSize(frameSize)
1473     uint8 *formalWordsRefCounted = nullptr;  // bit vector where the Nth bit tells whether
1474     // the Nth word in the formal parameters area
1475     // addressed upward from %%FP (that means
1476     // the word at location (%%FP + N*4)) points to
1477     // a dynamic memory block that needs reference
1478     // count; the bitvector's size is given by
1479     // BlockSize2BitvectorSize(upFormalSize)
1480     uint8 *localWordsRefCounted = nullptr;  // bit vector where the Nth bit tells whether
1481     // the Nth word in the local stack frame
1482     // addressed downward from %%FP (that means
1483     // the word at location (%%FP - N*4)) points to
1484     // a dynamic memory block that needs reference
1485     // count; the bitvector's size is given by
1486     // BlockSize2BitvectorSize(frameSize)
1487     // uint16 numlabels // removed. label table size
1488     // StmtNode **lbl2stmt // lbl2stmt table, removed
1489     // to hold unmangled class and function names
1490     MeFunction *meFunc = nullptr;
1491     EAConnectionGraph *eacg = nullptr;
1492     GStrIdx baseClassStrIdx {0};  // the string table index of base class name
1493     GStrIdx baseFuncStrIdx {0};   // the string table index of base function name
1494     // the string table index of base function name mangled with type info
1495     GStrIdx baseFuncWithTypeStrIdx {0};
1496     // funcname + types of args, no type of retv
1497     GStrIdx baseFuncSigStrIdx {0};
1498     GStrIdx signatureStrIdx {0};
1499     MemPool *codeMemPoolTmp {nullptr};
1500     MapleAllocator codeMemPoolTmpAllocator {nullptr};
1501     bool useTmpMemPool = false;
1502     PointerAttr returnKind = PointerAttr::kPointerUndeiced;
1503     MapleMap<MIRSymbol *, PointerAttr> paramNonullTypeMap {module->GetMPAllocator().Adapter()};
1504     FuncDesc funcDesc {};
1505     GcovFuncInfo *funcProfData = nullptr;
1506     MemReferenceTable *memReferenceTable = nullptr;
1507 #ifdef ARK_LITECG_DEBUG
1508     void DumpFlavorLoweredThanMmpl() const;
1509 #endif
1510     MIRFuncType *ReconstructFormals(const std::vector<MIRSymbol *> &symbols, bool clearOldArgs);
1511     SaveInfo frameTypeInfo {0, false, 0};
1512     SaveInfo funcIdxInfo {0, false, 0};
1513     MapleList<MapleString> debugComments {module->GetMPAllocator().Adapter()};
1514     bool isDeoptFunc = false;
1515 };
1516 }  // namespace maple
1517 #endif  // MAPLE_IR_INCLUDE_MIR_FUNCTION_H
1518