• 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 MAPLEBE_INCLUDE_CG_CG_OPTION_H
17 #define MAPLEBE_INCLUDE_CG_CG_OPTION_H
18 #include <vector>
19 #include <sys/stat.h>
20 #include "mempool.h"
21 #include "mempool_allocator.h"
22 #include "mir_module.h"
23 #include "types_def.h"
24 
25 namespace maplebe {
26 using namespace maple;
27 struct Range {
28     bool enable;
29     uint64 begin;
30     uint64 end;
31 };
32 
33 typedef uint8 *(*MemoryManagerAllocateDataSectionCallback)(void *codeSpace, uint32 size, uint32 alignment,
34                                                            const std::string &sectionName);
35 
36 typedef void (*MemoryManagerSaveFunc2AddressInfoCallback)(void *codeSpace, std::string funcName, uint32_t address);
37 
38 typedef void (*MemoryManagerSaveFunc2FPtoPrevSPDeltaCallback)(void *object, std::string funcName,
39                                                               int32_t fp2PrevSpDelta);
40 
41 typedef void (*MemoryManagerSaveFunc2CalleeOffsetInfoCallback)(void *object, std::string funcName,
42                                                                std::vector<std::pair<uint16_t, int32_t>> calleeRegInfo);
43 
44 typedef void (*MemoryManagerSavePC2DeoptInfoCallback)(void *object, uint64_t pc, std::vector<uint8_t> deoptInfo);
45 
46 typedef void (*MemoryManagerSavePC2CallSiteInfoCallback)(void *object, uint64_t pc, std::vector<uint8_t> callSiteInfo);
47 
48 class CGOptions {
49 public:
50     enum OptionEnum : uint64 {
51         kUndefined = 0ULL,
52         kDoCg = 1ULL << 0,
53         kDoLinearScanRegAlloc = 1ULL << 1,
54         kVerboseAsm = 1ULL << 6,
55         kGenInsertCall = 1ULL << 7,
56         kGenYieldPoint = 1ULL << 9,
57         kGenLocalRc = 1ULL << 10,
58         kVerboseCG = 1ULL << 12,
59         kDebugFriendly = 1ULL << 20,
60         kWithLoc = 1ULL << 21,
61         kWithDwarf = 1ULL << 22,
62         kWithMpl = 1ULL << 23,
63         kWithSrc = 1ULL << 24,
64         kWithAsm = 1ULL << 25,
65         kTailCallOpt = 1ULL << 36,
66         /* undocumented */
67         kDumpCFG = 1ULL << 61,
68         kDumpCgir = 1ULL << 62,
69         kSuppressFileInfo = 1ULL << 63,
70     };
71 
72     using OptionFlag = uint64;
73 
74     enum GenerateEnum : uint64 {
75         kGrootList = 1ULL << 2,
76         kPrimorList = 1ULL << 3,
77     };
78 
79     using GenerateFlag = uint64;
80 
81     enum OptimizeLevel : uint8 {
82         kLevel0 = 0,
83         kLevelLiteCG = 1,
84         kLevel1 = 2,
85         kLevel2 = 3,
86     };
87     struct EmitMemoryManager {
88         void *codeSpace;
89         MemoryManagerAllocateDataSectionCallback allocateDataSection;
90         MemoryManagerSaveFunc2AddressInfoCallback funcAddressSaver;
91         MemoryManagerSaveFunc2FPtoPrevSPDeltaCallback funcFpSPDeltaSaver;
92         MemoryManagerSaveFunc2CalleeOffsetInfoCallback funcCalleeOffsetSaver;
93         MemoryManagerSavePC2DeoptInfoCallback pc2DeoptInfoSaver;
94         MemoryManagerSavePC2CallSiteInfoCallback pc2CallSiteInfoSaver;
95     };
96     /*
97      * The default CG option values are:
98      * Don't BE_QUITE; verbose,
99      * DO CG and generate .s file as output,
100      * Generate EH,
101      * Use frame pointer,
102      * Generate CFI directives,
103      * DO peephole optimization,
104      * Generate position-independent executable,
105      * Don't insert debug comments in .s file,
106      * Don't insert a call to the named (instrumentation)
107      * function at each function entry.
108      */
109     static const OptionFlag kDefaultOptions = OptionFlag(
110 #if TARGAARCH64 || TARGARM32 || TARGRISCV64
111         kDoCg
112 #else
113         kDoCg
114 #endif
115     );
116 
117     /*
118      * The default metadata generation flags values are:
119      * Generate .macros.def for C preprocessors.
120      * Generate .groots.txt for GC.
121      * Generate .primordials.txt for GC.
122      * Generate yieldpoints for GC.
123      * Do not generate separate GCTIB file.
124      */
125     static const GenerateFlag kDefaultGflags = GenerateFlag(0);
126 
127 public:
128     static CGOptions &GetInstance();
129     virtual ~CGOptions() = default;
130     bool SolveOptions();
131     std::ostream& GetLogStream() const;
132     void DumpOptions();
GetSequence()133     std::vector<std::string> &GetSequence()
134     {
135         return phaseSequence;
136     }
137 
GetEmitMemoryManager()138     const EmitMemoryManager &GetEmitMemoryManager() const
139     {
140         return emitMemoryManager;
141     }
142 
SetupEmitMemoryManager(void * codeSpace,MemoryManagerAllocateDataSectionCallback allocateDataSection,MemoryManagerSaveFunc2AddressInfoCallback funcAddressSaver,MemoryManagerSaveFunc2FPtoPrevSPDeltaCallback funcFPSPDeltaSaver,MemoryManagerSaveFunc2CalleeOffsetInfoCallback funcCalleeOffsetSaver,MemoryManagerSavePC2DeoptInfoCallback pc2DeoptInfoSaver,MemoryManagerSavePC2CallSiteInfoCallback pc2CallSiteInfoSaver)143     void SetupEmitMemoryManager(void *codeSpace, MemoryManagerAllocateDataSectionCallback allocateDataSection,
144                                 MemoryManagerSaveFunc2AddressInfoCallback funcAddressSaver,
145                                 MemoryManagerSaveFunc2FPtoPrevSPDeltaCallback funcFPSPDeltaSaver,
146                                 MemoryManagerSaveFunc2CalleeOffsetInfoCallback funcCalleeOffsetSaver,
147                                 MemoryManagerSavePC2DeoptInfoCallback pc2DeoptInfoSaver,
148                                 MemoryManagerSavePC2CallSiteInfoCallback pc2CallSiteInfoSaver)
149     {
150         emitMemoryManager.codeSpace = codeSpace;
151         emitMemoryManager.allocateDataSection = allocateDataSection;
152         emitMemoryManager.funcAddressSaver = funcAddressSaver;
153         emitMemoryManager.funcFpSPDeltaSaver = funcFPSPDeltaSaver;
154         emitMemoryManager.funcCalleeOffsetSaver = funcCalleeOffsetSaver;
155         emitMemoryManager.pc2DeoptInfoSaver = pc2DeoptInfoSaver;
156         emitMemoryManager.pc2CallSiteInfoSaver = pc2CallSiteInfoSaver;
157     }
158 
159     template <class T>
SetOrClear(T & dest,uint64 flag,bool truth)160     void SetOrClear(T &dest, uint64 flag, bool truth) const
161     {
162         if (truth) {
163             dest |= flag;
164         } else {
165             dest &= ~flag;
166         }
167     }
168 
169 #ifdef ARK_LITECG_DEBUG
170     void EnableO0();
171     void EnableO1();
172     void EnableO2();
173 #endif
174     void EnableLiteCG();
175 
GenGrootList()176     bool GenGrootList() const
177     {
178         return generateFlag & kGrootList;
179     }
180 
GenPrimorList()181     bool GenPrimorList() const
182     {
183         return generateFlag & kPrimorList;
184     }
185 
GenYieldPoint()186     bool GenYieldPoint() const
187     {
188         return generateFlag & kGenYieldPoint;
189     }
190 
GenLocalRC()191     bool GenLocalRC() const
192     {
193         return (generateFlag & kGenLocalRc) && !gcOnly;
194     }
195 
DoEmitCode()196     bool DoEmitCode() const
197     {
198         return (options & kDoCg) != 0;
199     }
200 
GenerateExceptionHandlingCode()201     bool GenerateExceptionHandlingCode() const
202     {
203         return true;
204     }
205 
DoLinearScanRegisterAllocation()206     bool DoLinearScanRegisterAllocation() const
207     {
208         return (options & kDoLinearScanRegAlloc) != 0;
209     }
210 
GenerateVerboseAsm()211     bool GenerateVerboseAsm() const
212     {
213         return (options & kVerboseAsm) != 0;
214     }
215 
GenerateVerboseCG()216     bool GenerateVerboseCG() const
217     {
218         return (options & kVerboseCG) != 0;
219     }
220 
GenerateDebugFriendlyCode()221     bool GenerateDebugFriendlyCode() const
222     {
223         return true;
224     }
225 
WithLoc()226     bool WithLoc() const
227     {
228         return (options & kWithLoc) != 0;
229     }
230 
WithSrc()231     bool WithSrc() const
232     {
233         return (options & kWithSrc) != 0;
234     }
235 
WithMpl()236     bool WithMpl() const
237     {
238         return (options & kWithMpl) != 0;
239     }
240 
WithAsm()241     bool WithAsm() const
242     {
243         return (options & kWithAsm) != 0;
244     }
245 
DoTailCall()246     bool DoTailCall() const
247     {
248         return (options & kTailCallOpt) != 0;
249     }
250 
SuppressFileInfo()251     bool SuppressFileInfo() const
252     {
253         return (options & kSuppressFileInfo) != 0;
254     }
255 
DoDumpCFG()256     bool DoDumpCFG() const
257     {
258         return (options & kDumpCFG) != 0;
259     }
260 
261     void SetDefaultOptions(const MIRModule &mod);
262     static bool DumpPhase(const std::string &phase);
263     static bool FuncFilter(const std::string &name);
264     void SplitPhases(const std::string &str, std::unordered_set<std::string> &set);
265 #ifdef ARK_LITECG_DEBUG
266     void SetRange(const std::string &str, const std::string &cmd, Range &subRange);
267     void SetTargetMachine(const std::string &str);
268 #endif
269 
GetOptimizeLevel()270     int32 GetOptimizeLevel() const
271     {
272         return optimizeLevel;
273     }
274 
IsRunCG()275     bool IsRunCG() const
276     {
277         return runCGFlag;
278     }
279 
SetRunCGFlag(bool cgFlag)280     void SetRunCGFlag(bool cgFlag)
281     {
282         runCGFlag = cgFlag;
283     }
284 
IsAsmEmitterEnable()285     bool IsAsmEmitterEnable() const
286     {
287         return asmEmitterEnable;
288     }
289 
SetAsmEmitterEnable(bool flag)290     void SetAsmEmitterEnable(bool flag)
291     {
292         asmEmitterEnable = flag;
293     }
294 
SetParserOption(uint32 option)295     void SetParserOption(uint32 option)
296     {
297         parserOption |= option;
298     }
299 
GetParserOption()300     uint32 GetParserOption() const
301     {
302         return parserOption;
303     }
304 
GetGenerateFlags()305     GenerateFlag &GetGenerateFlags()
306     {
307         return generateFlag;
308     }
309 
GetGenerateFlags()310     const GenerateFlag &GetGenerateFlags() const
311     {
312         return generateFlag;
313     }
314 
SetGenerateFlags(GenerateFlag flag)315     void SetGenerateFlags(GenerateFlag flag)
316     {
317         generateFlag |= flag;
318     }
319 
SetOption(OptionFlag opFlag)320     void SetOption(OptionFlag opFlag)
321     {
322         options |= opFlag;
323     }
324 
ClearOption(OptionFlag opFlag)325     void ClearOption(OptionFlag opFlag)
326     {
327         options &= ~opFlag;
328     }
329 
SetEHExclusiveFile(const std::string & ehExclusive)330     void SetEHExclusiveFile(const std::string &ehExclusive)
331     {
332         ehExclusiveFile = ehExclusive;
333     }
334 
SetEmitAotCodeCommentFile(const std::string & aotCodeCommentFile)335     void SetEmitAotCodeCommentFile(const std::string &aotCodeCommentFile)
336     {
337         aotCodeCommentFilePath = aotCodeCommentFile;
338     }
339 
GetEmitAotCodeCommentFile()340     const std::string &GetEmitAotCodeCommentFile() const
341     {
342         return aotCodeCommentFilePath;
343     }
344 
GetDumpPhases()345     static std::unordered_set<std::string> &GetDumpPhases()
346     {
347         return dumpPhases;
348     }
349 
GetSkipPhases()350     static std::unordered_set<std::string> &GetSkipPhases()
351     {
352         return skipPhases;
353     }
354 
IsSkipPhase(const std::string & phaseName)355     static bool IsSkipPhase(const std::string &phaseName)
356     {
357         return !(skipPhases.find(phaseName) == skipPhases.end());
358     }
359 
GetEHExclusiveFunctionNameVec()360     const std::vector<std::string> &GetEHExclusiveFunctionNameVec() const
361     {
362         return ehExclusiveFunctionName;
363     }
364 
GetCyclePatternMap()365     static const std::unordered_map<std::string, std::vector<std::string>> &GetCyclePatternMap()
366     {
367         return cyclePatternMap;
368     }
369 
IsSkipFromPhase(const std::string & phaseName)370     static bool IsSkipFromPhase(const std::string &phaseName)
371     {
372         return skipFrom.compare(phaseName) == 0;
373     }
374 
GetSkipFromPhase()375     static const std::string GetSkipFromPhase()
376     {
377         return skipFrom;
378     }
379 
SetSkipFrom(const std::string & phaseName)380     static void SetSkipFrom(const std::string &phaseName)
381     {
382         skipFrom = phaseName;
383     }
384 
IsSkipAfterPhase(const std::string & phaseName)385     static bool IsSkipAfterPhase(const std::string &phaseName)
386     {
387         return skipAfter.compare(phaseName) == 0;
388     }
389 
GetSkipAfterPhase()390     static const std::string GetSkipAfterPhase()
391     {
392         return skipAfter;
393     }
394 
SetSkipAfter(const std::string & phaseName)395     static void SetSkipAfter(const std::string &phaseName)
396     {
397         skipAfter = phaseName;
398     }
399 
GetDumpFunc()400     static const std::string &GetDumpFunc()
401     {
402         return dumpFunc;
403     }
404 
IsDumpFunc(const std::string & func)405     static bool IsDumpFunc(const std::string &func)
406     {
407         return ((dumpFunc.compare("*") == 0) || (func.find(CGOptions::dumpFunc.c_str()) != std::string::npos));
408     }
409 
SetDumpFunc(const std::string & func)410     static void SetDumpFunc(const std::string &func)
411     {
412         dumpFunc = func;
413     }
FindIndexInProfileData(char data)414     static size_t FindIndexInProfileData(char data)
415     {
416         return profileData.find(data);
417     }
418 
SetProfileData(const std::string & path)419     static void SetProfileData(const std::string &path)
420     {
421         profileData = path;
422     }
423 
GetProfileData()424     static std::string &GetProfileData()
425     {
426         return profileData;
427     }
428 
GetProfileDataSubStr(size_t begin,size_t end)429     static const std::string GetProfileDataSubStr(size_t begin, size_t end)
430     {
431         return profileData.substr(begin, end);
432     }
433 
GetProfileDataSubStr(size_t position)434     static const std::string GetProfileDataSubStr(size_t position)
435     {
436         return profileData.substr(position);
437     }
438 
IsProfileDataEmpty()439     static bool IsProfileDataEmpty()
440     {
441         return profileData.empty();
442     }
443 
GetProfileFuncData()444     static const std::string &GetProfileFuncData()
445     {
446         return profileFuncData;
447     }
448 
IsProfileFuncDataEmpty()449     static bool IsProfileFuncDataEmpty()
450     {
451         return profileFuncData.empty();
452     }
453 
SetProfileFuncData(const std::string & data)454     static void SetProfileFuncData(const std::string &data)
455     {
456         profileFuncData = data;
457     }
458 
GetProfileClassData()459     static const std::string &GetProfileClassData()
460     {
461         return profileClassData;
462     }
463 
SetProfileClassData(const std::string & data)464     static void SetProfileClassData(const std::string &data)
465     {
466         profileClassData = data;
467     }
468 
GetDuplicateAsmFile()469     static const std::string &GetDuplicateAsmFile()
470     {
471         return duplicateAsmFile;
472     }
473 
IsDuplicateAsmFileEmpty()474     static bool IsDuplicateAsmFileEmpty()
475     {
476         if (duplicateAsmFile.empty()) {
477             return true;
478         }
479         struct stat buffer;
480         if (stat(duplicateAsmFile.c_str(), &buffer) != 0) {
481             return true;
482         }
483         return false;
484     }
485 
UseRange()486     static bool UseRange()
487     {
488         return range.enable;
489     }
490 
GetRange()491     static Range &GetRange()
492     {
493         return range;
494     }
495 
GetRangeBegin()496     static uint64 GetRangeBegin()
497     {
498         return range.begin;
499     }
500 
GetRangeEnd()501     static uint64 GetRangeEnd()
502     {
503         return range.end;
504     }
505 
GetSpillRanges()506     static Range &GetSpillRanges()
507     {
508         return spillRanges;
509     }
510 
GetSpillRangesBegin()511     static uint64 GetSpillRangesBegin()
512     {
513         return spillRanges.begin;
514     }
515 
GetSpillRangesEnd()516     static uint64 GetSpillRangesEnd()
517     {
518         return spillRanges.end;
519     }
520 
GetLSRABBOptSize()521     static uint64 GetLSRABBOptSize()
522     {
523         return lsraBBOptSize;
524     }
525 
SetLSRABBOptSize(uint64 size)526     static void SetLSRABBOptSize(uint64 size)
527     {
528         lsraBBOptSize = size;
529     }
530 
SetLSRAInsnOptSize(uint64 size)531     static void SetLSRAInsnOptSize(uint64 size)
532     {
533         lsraInsnOptSize = size;
534     }
535 
GetOverlapNum()536     static uint64 GetOverlapNum()
537     {
538         return overlapNum;
539     }
540 
SetOverlapNum(uint64 num)541     static void SetOverlapNum(uint64 num)
542     {
543         overlapNum = num;
544     }
545 
OptimizeForSize()546     static bool OptimizeForSize()
547     {
548         return optForSize;
549     }
550 
IsEnableTimePhases()551     static bool IsEnableTimePhases()
552     {
553         return timePhases;
554     }
555 
EnableTimePhases()556     static void EnableTimePhases()
557     {
558         timePhases = true;
559     }
560 
DisableTimePhases()561     static void DisableTimePhases()
562     {
563         timePhases = false;
564     }
565 
EnableInRange()566     static void EnableInRange()
567     {
568         inRange = true;
569     }
570 
DisableInRange()571     static void DisableInRange()
572     {
573         inRange = false;
574     }
575 
IsInRange()576     static bool IsInRange()
577     {
578         return inRange;
579     }
580 
DisableEBO()581     static void DisableEBO()
582     {
583         doEBO = false;
584     }
585 
DisableCGSSA()586     static void DisableCGSSA()
587     {
588         doCGSSA = false;
589     }
590 
EnableCGSSA()591     static void EnableCGSSA()
592     {
593         doCGSSA = true;
594     }
595 
EnableSupportFuncSymbol()596     static void EnableSupportFuncSymbol()
597     {
598         supportFuncSymbol = true;
599     }
600 
DisableSupportFuncSymbol()601     static void DisableSupportFuncSymbol()
602     {
603         supportFuncSymbol = false;
604     }
605 
addFuncSymbol()606     static bool addFuncSymbol()
607     {
608         return supportFuncSymbol;
609     }
610 
DoCGSSA()611     static bool DoCGSSA()
612     {
613         return doCGSSA;
614     }
615 
DisableLocalSchedule()616     static void DisableLocalSchedule()
617     {
618         doLocalSchedule = false;
619     }
620 
EnableLocalSchedule()621     static void EnableLocalSchedule()
622     {
623         doLocalSchedule = true;
624     }
625 
DoLocalSchedule()626     static bool DoLocalSchedule()
627     {
628         return doLocalSchedule;
629     }
630 
DoCGRegCoalecse()631     static bool DoCGRegCoalecse()
632     {
633         return doCGRegCoalesce;
634     }
635 
DisableIPARA()636     static void DisableIPARA()
637     {
638         doIPARA = false;
639     }
640 
DoIPARA()641     static bool DoIPARA()
642     {
643         return doIPARA;
644     }
645 
EnableCFGO()646     static void EnableCFGO()
647     {
648         doCFGO = true;
649     }
650 
DisableCFGO()651     static void DisableCFGO()
652     {
653         doCFGO = false;
654     }
655 
DoCFGO()656     static bool DoCFGO()
657     {
658         return doCFGO;
659     }
660 
SetUseJitCodeSign(bool isJitCodeSign)661     static void SetUseJitCodeSign(bool isJitCodeSign)
662     {
663         useJitCodeSign = isJitCodeSign;
664     }
665 
UseJitCodeSign()666     static bool UseJitCodeSign()
667     {
668         return useJitCodeSign;
669     }
670 
DisableICO()671     static void DisableICO()
672     {
673         doICO = false;
674     }
675 
EnableBigEndianInCG()676     static void EnableBigEndianInCG()
677     {
678         cgBigEndian = true;
679     }
680 
DisableBigEndianInCG()681     static void DisableBigEndianInCG()
682     {
683         cgBigEndian = false;
684     }
685 
IsBigEndian()686     static bool IsBigEndian()
687     {
688         return cgBigEndian;
689     }
690 
EnableArm64ilp32()691     static void EnableArm64ilp32()
692     {
693         arm64ilp32 = true;
694     }
695 
DisableArm64ilp32()696     static void DisableArm64ilp32()
697     {
698         arm64ilp32 = false;
699     }
700 
IsArm64ilp32()701     static bool IsArm64ilp32()
702     {
703         return arm64ilp32;
704     }
705 
IsTargetX86_64()706     static bool IsTargetX86_64()
707     {
708         return targetArch == "x86_64";
709     };
710 
IsTargetAArch64()711     static bool IsTargetAArch64()
712     {
713         return targetArch == "aarch64";
714     };
715 
DoPrePeephole()716     static bool DoPrePeephole()
717     {
718         return doPrePeephole;
719     }
720 
DoPeephole()721     static bool DoPeephole()
722     {
723         return doPeephole;
724     }
725 
DoPreSchedule()726     static bool DoPreSchedule()
727     {
728         return doPreSchedule;
729     }
730 
DisableSchedule()731     static void DisableSchedule()
732     {
733         doSchedule = false;
734     }
735 
EnableNoDupBB()736     static void EnableNoDupBB()
737     {
738         noDupBB = true;
739     }
740 
DisableNoDupBB()741     static void DisableNoDupBB()
742     {
743         noDupBB = false;
744     }
745 
IsNoDupBB()746     static bool IsNoDupBB()
747     {
748         return noDupBB;
749     }
750 
EnableNoCalleeCFI()751     static void EnableNoCalleeCFI()
752     {
753         noCalleeCFI = true;
754     }
755 
DisableNoCalleeCFI()756     static void DisableNoCalleeCFI()
757     {
758         noCalleeCFI = false;
759     }
760 
IsNoCalleeCFI()761     static bool IsNoCalleeCFI()
762     {
763         return noCalleeCFI;
764     }
765 
EnableGeneralRegOnly()766     static void EnableGeneralRegOnly()
767     {
768         generalRegOnly = true;
769     }
770 
DisableGeneralRegOnly()771     static void DisableGeneralRegOnly()
772     {
773         generalRegOnly = false;
774     }
775 
UseGeneralRegOnly()776     static bool UseGeneralRegOnly()
777     {
778         return generalRegOnly;
779     }
780 
GetGlobalVarProFile()781     static std::string &GetGlobalVarProFile()
782     {
783         return globalVarProfile;
784     }
785 
IsGlobalVarProFileEmpty()786     static bool IsGlobalVarProFileEmpty()
787     {
788         return globalVarProfile.empty();
789     }
790 
IsEmitBlockMarker()791     static bool IsEmitBlockMarker()
792     {
793         return emitBlockMarker;
794     }
795 
EnableLazyBinding()796     static void EnableLazyBinding()
797     {
798         lazyBinding = true;
799     }
800 
DisableLazyBinding()801     static void DisableLazyBinding()
802     {
803         lazyBinding = false;
804     }
805 
IsLazyBinding()806     static bool IsLazyBinding()
807     {
808         return lazyBinding;
809     }
810 
EnableHotFix()811     static void EnableHotFix()
812     {
813         hotFix = true;
814     }
815 
DisableHotFix()816     static void DisableHotFix()
817     {
818         hotFix = false;
819     }
820 
IsHotFix()821     static bool IsHotFix()
822     {
823         return hotFix;
824     }
825 
EnableFramePointer()826     static void EnableFramePointer()
827     {
828         useFramePointer = true;
829     }
830 
DisableFramePointer()831     static void DisableFramePointer()
832     {
833         useFramePointer = false;
834     }
835 
UseFramePointer()836     static bool UseFramePointer()
837     {
838         return useFramePointer;
839     }
840 
EnableGCOnly()841     static void EnableGCOnly()
842     {
843         gcOnly = true;
844     }
845 
DisableGCOnly()846     static void DisableGCOnly()
847     {
848         gcOnly = false;
849     }
850 
IsGCOnly()851     static bool IsGCOnly()
852     {
853         return gcOnly;
854     }
855 
GetOptionFlag()856     const OptionFlag &GetOptionFlag() const
857     {
858         return options;
859     }
860 
SetOptionFlag(const OptionFlag & flag)861     void SetOptionFlag(const OptionFlag &flag)
862     {
863         options = flag;
864     }
865 
SetFuncAlignPow(uint32 funcPow)866     static void SetFuncAlignPow(uint32 funcPow)
867     {
868         funcAlignPow = funcPow;
869     }
870 
GetFuncAlignPow()871     static uint32 GetFuncAlignPow()
872     {
873         return funcAlignPow;
874     }
875 
DoOptimizedFrameLayout()876     static bool DoOptimizedFrameLayout()
877     {
878         return doOptimizedFrameLayout;
879     }
880 
DoCGIRVerify()881     static bool DoCGIRVerify()
882     {
883         return doCgirVerify;
884     }
885 private:
886     std::vector<std::string> phaseSequence;
887     EmitMemoryManager emitMemoryManager;
888 
889     bool runCGFlag = true;
890     bool asmEmitterEnable = false;
891     uint32 parserOption = 0;
892     int32 optimizeLevel = 0;
893 
894     GenerateFlag generateFlag = 0;
895     OptionFlag options = kUndefined;
896 
897     std::string ehExclusiveFile;
898     /* we don't do exception handling in this list */
899     std::vector<std::string> ehExclusiveFunctionName;
900     std::string aotCodeCommentFilePath = "";
901 
902     static std::string targetArch;
903     static std::unordered_set<std::string> dumpPhases;
904     static std::unordered_set<std::string> skipPhases;
905     static std::unordered_map<std::string, std::vector<std::string>> cyclePatternMap;
906     static std::string skipFrom;
907     static std::string skipAfter;
908     static std::string dumpFunc;
909     static std::string duplicateAsmFile;
910     static bool optForSize;
911     static bool enableHotColdSplit;
912     static bool timePhases;
913     static bool cgBigEndian;
914     static bool doEBO;
915     static bool doCGSSA;
916     static bool doLocalSchedule;
917     static bool doCGRegCoalesce;
918     static bool doIPARA;
919     static bool doCFGO;
920     static bool doICO;
921     static bool doStoreLoadOpt;
922     static bool doGlobalOpt;
923     static bool doPrePeephole;
924     static bool doPeephole;
925     static bool doSchedule;
926     static bool doWriteRefFieldOpt;
927     static bool doRegSavesOpt;
928     static bool useSsaPreSave;
929     static bool useSsuPreRestore;
930     static bool checkArrayStore;
931     static bool noDupBB;
932     static bool noCalleeCFI;
933     static std::string globalVarProfile;
934     static bool nativeOpt;
935     static bool lazyBinding;
936     static bool arm64ilp32;
937     static bool hotFix;
938     static bool useJitCodeSign;
939     static bool useFramePointer;
940     static bool gcOnly;
941     static bool doPreSchedule;
942     static bool emitBlockMarker;
943     static Range range;
944     static bool inRange;
945     static std::string profileData;
946     static std::string profileFuncData;
947     static std::string profileClassData;
948     static Range spillRanges;
949     static uint64 lsraBBOptSize;
950     static uint64 lsraInsnOptSize;
951     static uint64 overlapNum;
952     static bool doPreLSRAOpt;
953     static bool generalRegOnly;
954     static std::string literalProfile;
955     static bool noCommon;
956     static uint32 funcAlignPow;
957     static bool doOptimizedFrameLayout;
958     static bool doCgirVerify;
959     static bool supportFuncSymbol;
960 };
961 } /* namespace maplebe */
962 
963 #define SET_FIND(SET, NAME) ((SET).find(NAME))
964 #define SET_END(SET) ((SET).end())
965 #define IS_STR_IN_SET(SET, NAME) (SET_FIND(SET, NAME) != SET_END(SET))
966 
967 #define CG_DEBUG_FUNC(f)                                                                              \
968     (!maplebe::CGOptions::GetDumpPhases().empty() && maplebe::CGOptions::IsDumpFunc((f).GetName()) && \
969      maplebe::CGOptions::GetDumpPhases().find(PhaseName()) != maplebe::CGOptions::GetDumpPhases().end())
970 #ifndef TRACE_PHASE
971 #define TRACE_PHASE (IS_STR_IN_SET(maplebe::CGOptions::GetDumpPhases(), PhaseName()))
972 #endif
973 
974 #endif /* MAPLEBE_INCLUDE_CG_CG_OPTION_H */
975