• 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_AARCH64_AARCH64_CG_H
17 #define MAPLEBE_INCLUDE_CG_AARCH64_AARCH64_CG_H
18 
19 #include "cg.h"
20 #include "aarch64_cgfunc.h"
21 #include "aarch64_live.h"
22 #include "aarch64_args.h"
23 #include "aarch64_cfgo.h"
24 #include "aarch64_peep.h"
25 #include "aarch64_proepilog.h"
26 
27 namespace maplebe {
28 constexpr int64 kShortBRDistance = (8 * 1024);
29 constexpr int64 kNegativeImmLowerLimit = -4096;
30 constexpr int32 kIntRegTypeNum = 5;
31 constexpr uint32 kAlignPseudoSize = 3;
32 constexpr uint32 kInsnSize = 4;
33 constexpr uint32 kAlignMovedFlag = 31;
34 
35 /* sub Target info & implement */
36 class AArch64CG : public CG {
37 public:
AArch64CG(MIRModule & mod,const CGOptions & opts,const std::vector<std::string> & nameVec,const std::unordered_map<std::string,std::vector<std::string>> & patternMap)38     AArch64CG(MIRModule &mod, const CGOptions &opts, const std::vector<std::string> &nameVec,
39               const std::unordered_map<std::string, std::vector<std::string>> &patternMap)
40         : CG(mod, opts),
41           ehExclusiveNameVec(nameVec),
42           cyclePatternMap(patternMap),
43           keyPatternMap(allocator.Adapter()),
44           symbolPatternMap(allocator.Adapter())
45     {
46     }
47 
48     ~AArch64CG() override = default;
49 
CreateCGFunc(MIRModule & mod,MIRFunction & mirFunc,BECommon & bec,MemPool & memPool,StackMemPool & stackMp,MapleAllocator & mallocator,uint32 funcId)50     CGFunc *CreateCGFunc(MIRModule &mod, MIRFunction &mirFunc, BECommon &bec, MemPool &memPool, StackMemPool &stackMp,
51                          MapleAllocator &mallocator, uint32 funcId) override
52     {
53         return memPool.New<AArch64CGFunc>(mod, *this, mirFunc, bec, memPool, stackMp, mallocator, funcId);
54     }
55 
56     void EnrollTargetPhases(MaplePhaseManager *pm) const override;
57 
GetCyclePatternMap()58     const std::unordered_map<std::string, std::vector<std::string>> &GetCyclePatternMap() const
59     {
60         return cyclePatternMap;
61     }
62 
63     bool IsExclusiveFunc(MIRFunction &) override;
64 
65     void EmitGCTIBLabel(GCTIBKey *key, const std::string &gcTIBName, std::vector<uint64> &bitmapWords, uint32 rcHeader);
66 
67     void CreateRefSymForGlobalPtn(GCTIBPattern &ptn) const;
68 
69     PhiOperand &CreatePhiOperand(MemPool &mp, MapleAllocator &mAllocator) override;
70 
71 #ifdef ARK_LITECG_DEBUG
72     std::string FindGCTIBPatternName(const std::string &name) const override;
73 #endif
74 
CreateLiveAnalysis(MemPool & mp,CGFunc & f)75     LiveAnalysis *CreateLiveAnalysis(MemPool &mp, CGFunc &f) const override
76     {
77         return mp.New<AArch64LiveAnalysis>(f, mp);
78     }
79     GenProEpilog *CreateGenProEpilog(CGFunc &f, MemPool &mp, MemPool *tempMemPool = nullptr) const override
80     {
81         return mp.New<AArch64GenProEpilog>(f, *tempMemPool);
82     }
CreateCGPeepHole(MemPool & mp,CGFunc & f)83     CGPeepHole *CreateCGPeepHole(MemPool &mp, CGFunc &f) const override
84     {
85         return mp.New<AArch64CGPeepHole>(f, &mp);
86     }
CreateMoveRegArgs(MemPool & mp,CGFunc & f)87     MoveRegArgs *CreateMoveRegArgs(MemPool &mp, CGFunc &f) const override
88     {
89         return mp.New<AArch64MoveRegArgs>(f);
90     }
CreateCFGOptimizer(MemPool & mp,CGFunc & f,LoopAnalysis & loop)91     CFGOptimizer *CreateCFGOptimizer(MemPool &mp, CGFunc &f, LoopAnalysis &loop) const override
92     {
93         return mp.New<AArch64CFGOptimizer>(f, mp, loop);
94     }
95 
96     /* Return the copy operand id of reg1 if it is an insn who just do copy from reg1 to reg2.
97      * i. mov reg2, reg1
98      * ii. add/sub reg2, reg1, 0/zero register
99      * iii. mul reg2, reg1, 1
100      */
101     bool IsEffectiveCopy(Insn &insn) const final;
102     bool IsTargetInsn(MOperator mOp) const final;
103     bool IsClinitInsn(MOperator mOp) const final;
104     bool IsPseudoInsn(MOperator mOp) const final;
105     void DumpTargetOperand(Operand &opnd, const OpndDesc &opndDesc) const final;
GetTargetMd(MOperator mOp)106     const InsnDesc &GetTargetMd(MOperator mOp) const final
107     {
108         return kMd[mOp];
109     }
110 
111     static const InsnDesc kMd[kMopLast];
112     enum : uint8 { kR8List, kR16List, kR32List, kR64List, kV64List };
113     static std::array<std::array<const std::string, kAllRegNum>, kIntRegTypeNum> intRegNames;
114     static std::array<const std::string, kAllRegNum> vectorRegNames;
115 
116 private:
117     const std::vector<std::string> &ehExclusiveNameVec;
118     const std::unordered_map<std::string, std::vector<std::string>> &cyclePatternMap;
119     MapleUnorderedMap<GCTIBKey *, GCTIBPattern *, Hasher, EqualFn> keyPatternMap;
120     MapleUnorderedMap<std::string, GCTIBPattern *> symbolPatternMap;
121 };
122 } /* namespace maplebe */
123 
124 #endif /* MAPLEBE_INCLUDE_CG_AARCH64_AARCH64_CG_H */
125