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