• 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 /* sub Target info & implement */
17 #ifndef MAPLEBE_INCLUDE_CG_X86_64_CG_H
18 #define MAPLEBE_INCLUDE_CG_X86_64_CG_H
19 
20 #include "cg.h"
21 #include "x64_isa.h"
22 #include "x64_live.h"
23 #include "x64_MPISel.h"
24 #include "x64_standardize.h"
25 #include "x64_args.h"
26 #include "x64_cfgo.h"
27 #include "x64_peep.h"
28 #include "x64_proepilog.h"
29 
30 namespace maplebe {
31 class X64CG : public CG {
32 public:
X64CG(MIRModule & mod,const CGOptions & opts,const std::vector<std::string> & nameVec,const std::unordered_map<std::string,std::vector<std::string>> & patternMap)33     X64CG(MIRModule &mod, const CGOptions &opts, const std::vector<std::string> &nameVec,
34           const std::unordered_map<std::string, std::vector<std::string>> &patternMap)
35         : CG(mod, opts),
36         ehExclusiveNameVec(nameVec),
37         cyclePatternMap(patternMap),
38         keyPatternMap(allocator.Adapter()),
39         symbolPatternMap(allocator.Adapter()) {}
40 
41     static const InsnDesc kMd[x64::kMopLast];
42     void EnrollTargetPhases(MaplePhaseManager *pm) const override;
43     /* Init SubTarget phase */
CreateLiveAnalysis(MemPool & mp,CGFunc & f)44     LiveAnalysis *CreateLiveAnalysis(MemPool &mp, CGFunc &f) const override
45     {
46         return mp.New<X64LiveAnalysis>(f, mp);
47     }
CreateCGPeepHole(MemPool & mp,CGFunc & f)48     CGPeepHole *CreateCGPeepHole(MemPool &mp, CGFunc &f) const override
49     {
50         return mp.New<X64CGPeepHole>(f, &mp);
51     }
52     virtual GenProEpilog *CreateGenProEpilog(CGFunc &f, MemPool &mp, MemPool *tempMemPool = nullptr) const override
53     {
54         return mp.New<X64GenProEpilog>(f);
55     }
CreateMoveRegArgs(MemPool & mp,CGFunc & f)56     MoveRegArgs *CreateMoveRegArgs(MemPool &mp, CGFunc &f) const override
57     {
58         return mp.New<X64MoveRegArgs>(f);
59     }
60 
CreateMPIsel(MemPool & mp,MapleAllocator & allocator,CGFunc & f)61     MPISel *CreateMPIsel(MemPool &mp, MapleAllocator &allocator, CGFunc &f) const override
62     {
63         return mp.New<X64MPIsel>(mp, allocator, f);
64     }
65 
CreateStandardize(MemPool & mp,CGFunc & f)66     Standardize *CreateStandardize(MemPool &mp, CGFunc &f) const override
67     {
68         return mp.New<X64Standardize>(f);
69     }
70 
CreateCFGOptimizer(MemPool & mp,CGFunc & f,LoopAnalysis & loop)71     CFGOptimizer *CreateCFGOptimizer(MemPool &mp, CGFunc &f, LoopAnalysis &loop) const override
72     {
73         return mp.New<X64CFGOptimizer>(f, mp, loop);
74     }
75 
76     PhiOperand &CreatePhiOperand(MemPool &mp, MapleAllocator &mAllocator) override;
77 
78     CGFunc *CreateCGFunc(MIRModule &mod, MIRFunction &mirFunc, BECommon &bec, MemPool &memPool, StackMemPool &stackMp,
79                          MapleAllocator &mallocator, uint32 funcId) override;
80 
81     bool IsExclusiveFunc(MIRFunction &mirFunc) override;
82 
DoNothing()83     void DoNothing()
84     {
85         (void)ehExclusiveNameVec;
86         (void)cyclePatternMap;
87         (void)keyPatternMap;
88         (void)symbolPatternMap;
89     }
90 
91 #ifdef ARK_LITECG_DEBUG
92     /* Used for GCTIB pattern merging */
93     std::string FindGCTIBPatternName(const std::string &name) const override;
94 #endif
95     enum : uint8 { kR8LowList, kR8HighList, kR16List, kR32List, kR64List, kR128List };
96     bool IsEffectiveCopy(Insn &insn) const final;
97     bool IsTargetInsn(MOperator mOp) const final;
98     bool IsClinitInsn(MOperator mOp) const final;
99     bool IsPseudoInsn(MOperator mOp) const final;
100     void DumpTargetOperand(Operand &opnd, const OpndDesc &opndDesc) const final;
GetTargetMd(MOperator mOp)101     const InsnDesc &GetTargetMd(MOperator mOp) const final
102     {
103         return kMd[mOp];
104     }
105 private:
106 	const std::vector<std::string> &ehExclusiveNameVec;
107     const std::unordered_map<std::string, std::vector<std::string>> &cyclePatternMap;
108     MapleUnorderedMap<GCTIBKey*, GCTIBPattern*, Hasher, EqualFn> keyPatternMap;
109     MapleUnorderedMap<std::string, GCTIBPattern*> symbolPatternMap;
110 };
111 }  // namespace maplebe
112 #endif /* MAPLEBE_INCLUDE_CG_X86_64_CG_H */
113