• 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_ALIGNMENT_H
17 #define MAPLEBE_INCLUDE_CG_AARCH64_AARCH64_ALIGNMENT_H
18 
19 #include "alignment.h"
20 #include "aarch64_cgfunc.h"
21 
22 namespace maplebe {
23 constexpr uint32 kAlignRegionPower = 4;
24 constexpr uint32 kAlignInsnLength = 4;
25 constexpr uint32 kAlignMaxNopNum = 1;
26 
27 struct AArch64AlignInfo {
28     /* if bb size in (16byte, 96byte) , the bb need align */
29     uint32 alignMinBBSize = 16;
30     uint32 alignMaxBBSize = 96;
31     /* default loop & jump align power, related to the target machine.  eg. 2^5 */
32     uint32 loopAlign = 4;
33     uint32 jumpAlign = 5;
34     /* record func_align_power in CGFunc */
35 };
36 
37 class AArch64AlignAnalysis : public AlignAnalysis {
38 public:
AArch64AlignAnalysis(CGFunc & func,MemPool & memPool,LoopAnalysis & loop)39     AArch64AlignAnalysis(CGFunc &func, MemPool &memPool, LoopAnalysis &loop) : AlignAnalysis(func, memPool, loop)
40     {
41         aarFunc = static_cast<AArch64CGFunc *>(&func);
42     }
43     ~AArch64AlignAnalysis() override = default;
44 
45     void FindLoopHeader() override;
46     void FindJumpTarget() override;
47     void ComputeLoopAlign() override;
48     void ComputeJumpAlign() override;
49     void ComputeCondBranchAlign() override;
50     bool MarkShortBranchSplit();
51     void UpdateInsnId();
52     uint32 GetAlignRange(uint32 alignedVal, uint32 addr) const;
53 
54     /* filter condition */
55     bool IsIncludeCall(BB &bb) override;
56     bool IsInSizeRange(BB &bb) override;
57     bool HasFallthruEdge(BB &bb) override;
58     bool IsInSameAlignedRegion(uint32 addr1, uint32 addr2, uint32 alignedRegionSize) const;
59 
60 private:
61     AArch64CGFunc *aarFunc = nullptr;
62 };
63 } /* namespace maplebe */
64 
65 #endif /* MAPLEBE_INCLUDE_CG_AARCH64_AARCH64_ALIGNMENT_H */
66