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 #if MIR_JAVA 113 static bool skipVirtualMethod; 114 #endif 115 // Ready to be deleted. 116 static bool noRC; 117 static bool analyzeCtor; 118 static bool strictNaiveRC; 119 static bool gcOnly; 120 static bool bigEndian; 121 static bool rcOpt1; 122 static std::string classMetaProFile; 123 static std::string methodMetaProfile; 124 static std::string fieldMetaProFile; 125 static std::string reflectStringProFile; 126 static bool nativeOpt; 127 static bool optForSize; 128 static bool O2; 129 static bool noDot; 130 static std::string criticalNativeFile; 131 static std::string fastNativeFile; 132 static bool barrier; 133 static std::string nativeFuncPropertyFile; 134 static bool mapleLinkerTransformLocal; 135 static uint32 buildApp; 136 static bool partialAot; 137 static uint32 decoupleInit; 138 static std::string sourceMuid; 139 static bool decoupleSuper; 140 static bool deferredVisit; 141 static bool deferredVisit2; 142 static bool genVtabAndItabForDecouple; 143 static bool profileFunc; 144 static uint32 parserOpt; 145 static std::string dumpDevirtualList; 146 static std::string readDevirtualList; 147 static bool usePreloadedClass; 148 static std::string profile; 149 static bool profileGen; 150 static bool profileUse; 151 static std::string appPackageName; 152 static std::string proFileData; 153 static std::string proFileFuncData; 154 static std::string proFileClassData; 155 static bool profileStaticFields; 156 static bool genIRProfile; 157 static bool profileTest; 158 static std::string classLoaderInvocationList; 159 static bool dumpClassLoaderInvocation; 160 static unsigned int warningLevel; 161 static bool lazyBinding; 162 static bool hotFix; 163 static bool compactMeta; 164 static bool genPGOReport; 165 static bool verify; 166 static uint32 inlineCache; 167 static bool checkArrayStore; 168 static bool noComment; 169 static bool rmNoUseFunc; 170 static bool sideEffect; 171 static bool dumpIPA; 172 static bool wpaa; 173 static bool genLMBC; 174 175 private: 176 void DecideMpl2MplRealLevel() const; 177 std::vector<std::string> phaseSeq; 178 }; 179 } // namespace maple 180 #ifndef TRACE_PHASE 181 #define TRACE_PHASE (Options::dumpPhase.compare(PhaseName()) == 0) 182 #endif 183 184 #ifndef TRACE_MAPLE_PHASE 185 #define TRACE_MAPLE_PHASE (Options::dumpPhase.compare(PhaseName()) == 0) 186 #endif 187 #endif // MAPLE_IR_INCLUDE_OPTION_H 188