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