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_OPTION_H
17 #define MAPLE_IR_INCLUDE_OPTION_H
18 #include <string>
19 #include <vector>
20 
21 #include "mempool.h"
22 #include "mempool_allocator.h"
23 #include "types_def.h"
24 
25 namespace maple {
26 // option bits passed into ParseMIR
27 enum ParserOptions : uint8 {
28     kInvalidOption = 0x0,
29     kWithDbgInfo = 0x1,  // collect dbginfo
30     kKeepFirst = 0x2,    // ignore second type def, not emit error
31     kWithProfileInfo = 0x4,
32     kParseOptFunc = 0x08,        // parse optimized function mpl file
33     kParseInlineFuncBody = 0x10  // parse to-be-inlined function bodies
34 };
35 
36 class Options {
37 public:
38     static Options &GetInstance();
39 
40     ~Options() = default;
41 
42     void DumpOptions() const;
GetSequence() const43     const std::vector<std::string> &GetSequence() const
44     {
45         return phaseSeq;
46     }
47 
LastPhaseName() const48     std::string LastPhaseName() const
49     {
50         return phaseSeq.empty() ? "noopt" : phaseSeq[phaseSeq.size() - 1];
51     }
52 
53     enum Level { kMpl2MplLevelZero = 0, kMpl2MplLevelOne = 1, kMpl2MplLevelTwo = 2 };
54     enum DecoupleLevel { kNoDecouple = 0, kConservativeDecouple = 1, kAggressiveDecouple = 2, kDecoupleAndLazy = 3 };
55 
DumpPhase(const std::string &phase)56     static bool DumpPhase(const std::string &phase)
57     {
58         if (phase == "") {
59             return false;
60         }
61         return dumpPhase == "*" || dumpPhase == phase;
62     }
63 
IsSkipPhase(const std::string &phaseName)64     static bool IsSkipPhase(const std::string &phaseName)
65     {
66         return skipPhase == phaseName;
67     }
68 
DumpFunc()69     static bool DumpFunc()
70     {
71         return dumpFunc != "*" && dumpFunc != "";
72     }
IsBigEndian()73     static bool IsBigEndian()
74     {
75         return bigEndian;
76     }
77 
78     static bool dumpBefore;
79     static bool dumpAfter;
80     static std::string dumpPhase;
81     static std::string skipPhase;
82     static std::string skipFrom;
83     static std::string skipAfter;
84     static std::string dumpFunc;
85     static bool quiet;
86     static bool regNativeFunc;
87     static bool regNativeDynamicOnly;
88     static bool nativeWrapper;
89     static bool inlineWithProfile;
90     static bool useInline;
91     static bool enableIPAClone;
92     static std::string noInlineFuncList;
93     static std::string importFileList;
94     static bool useCrossModuleInline;
95     static uint32 numOfCloneVersions;
96     static uint32 numOfImpExprLowBound;
97     static uint32 numOfImpExprHighBound;
98     static uint32 numOfCallSiteLowBound;
99     static uint32 numOfCallSiteUpBound;
100     static uint32 numOfConstpropValue;
101     static uint32 inlineSmallFunctionThreshold;
102     static uint32 inlineHotFunctionThreshold;
103     static uint32 inlineRecursiveFunctionThreshold;
104     static uint32 inlineDepth;
105     static uint32 inlineModuleGrowth;
106     static uint32 inlineColdFunctionThreshold;
107     static uint32 profileHotCount;
108     static uint32 profileColdCount;
109     static bool profileHotCountSeted;
110     static bool profileColdCountSeted;
111     static uint32 profileHotRate;
112     static uint32 profileColdRate;
113     static std::string staticBindingList;
114     static bool usePreg;
115     static bool mapleLinker;
116     static bool dumpMuidFile;
117     static bool emitVtableImpl;
118     // Ready to be deleted.
119     static bool noRC;
120     static bool analyzeCtor;
121     static bool strictNaiveRC;
122     static bool gcOnly;
123     static bool bigEndian;
124     static bool rcOpt1;
125     static std::string classMetaProFile;
126     static std::string methodMetaProfile;
127     static std::string fieldMetaProFile;
128     static std::string reflectStringProFile;
129     static bool nativeOpt;
130     static bool optForSize;
131     static bool O2;
132     static bool noDot;
133     static std::string criticalNativeFile;
134     static std::string fastNativeFile;
135     static bool barrier;
136     static std::string nativeFuncPropertyFile;
137     static bool mapleLinkerTransformLocal;
138     static uint32 buildApp;
139     static bool partialAot;
140     static uint32 decoupleInit;
141     static std::string sourceMuid;
142     static bool decoupleSuper;
143     static bool deferredVisit;
144     static bool deferredVisit2;
145     static bool genVtabAndItabForDecouple;
146     static bool profileFunc;
147     static uint32 parserOpt;
148     static std::string dumpDevirtualList;
149     static std::string readDevirtualList;
150     static bool usePreloadedClass;
151     static std::string profile;
152     static bool profileGen;
153     static bool profileUse;
154     static std::string appPackageName;
155     static std::string proFileData;
156     static std::string proFileFuncData;
157     static std::string proFileClassData;
158     static bool profileStaticFields;
159     static bool genIRProfile;
160     static bool profileTest;
161     static std::string classLoaderInvocationList;
162     static bool dumpClassLoaderInvocation;
163     static unsigned int warningLevel;
164     static bool lazyBinding;
165     static bool hotFix;
166     static bool compactMeta;
167     static bool genPGOReport;
168     static bool verify;
169     static uint32 inlineCache;
170     static bool checkArrayStore;
171     static bool noComment;
172     static bool rmNoUseFunc;
173     static bool sideEffect;
174     static bool dumpIPA;
175     static bool wpaa;
176     static bool genLMBC;
177 
178 private:
179     std::vector<std::string> phaseSeq;
180 };
181 }  // namespace maple
182 #ifndef TRACE_PHASE
183 #define TRACE_PHASE (Options::dumpPhase.compare(PhaseName()) == 0)
184 #endif
185 
186 #ifndef TRACE_MAPLE_PHASE
187 #define TRACE_MAPLE_PHASE (Options::dumpPhase.compare(PhaseName()) == 0)
188 #endif
189 #endif  // MAPLE_IR_INCLUDE_OPTION_H
190