• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2023-2024 Huawei Device Co., Ltd.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6# http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14module(
15    function(
16        lower-expect,               # Lower expect intrinsic
17        # Optimistically try to unswitch early before simplifycfg makes a lot of Selects out of branches
18        loop-mssa(
19            licm,
20            simple-loop-unswitch<nontrivial>
21        ),
22        simplifycfg,                # Simplify the CFG
23#       sroa,                       # SROA
24        early-cse                   # Early CSE
25    ),
26    function(
27        loop-simplify,              # Canonicalize natural loops
28        lcssa                       # Loop-Closed SSA Form Pass
29    ),
30    annotation2metadata,            # Annotation2Metadata
31#   forceattrs,                     # Force set function attributes
32
33    inferattrs,                     # Infer set function attributes
34    ipsccp,                         # Interprocedural Sparse Conditional Constant Propagation
35
36#   called-value-propagation,       # Called Value Propagation
37    globalopt,                      # Global Variable Optimizer
38#   mem2reg,                        # Promote Memory to Register
39    deadargelim,                    # Dead Argument Elimination
40
41    function(
42        instcombine,                # Combine redundant instructions
43        simplifycfg                 # Simplify the CFG
44    ),
45    # Adjust analysis for inliner
46    require<globals-aa>,
47    function(invalidate<aa>),
48    require<profile-summary>,
49    inline-prepare,
50    cgscc(
51        inline-devirt,                  # Run Inline+Devirt passes in loop
52        function-attrs,                 # Deduce function attributes
53        function(
54            propagate-lenarray,         # Propagate LenArray
55#           sroa,                       # SROA
56            early-cse<memssa>,          # Early CSE (with memory SSA)
57            infer-flags,                # Infer nsw flags
58#           wrap-speculative-execution, # Speculatively execute instructions if target has divergent branches
59            jump-threading,             # Jump Threading
60            correlated-propagation,     # Value Propagation
61            simplifycfg,                # Simplify the CFG
62            instcombine,                # Combine redundant instructions
63#           libcalls-shrinkwrap,        # Conditionally eliminate dead library calls
64#           pgo-memop-opt,              # PGOMemOPSize
65            tailcallelim,               # Tail Call Elimination
66            simplifycfg,                # Simplify the CFG
67            reassociate,                # Reassociate expressions
68            loop-simplify,              # Canonicalize natural loops
69            lcssa,                      # Loop-Closed SSA Form Pass
70            loop-mssa(
71                loop-instsimplify,
72                loop-simplifycfg,
73                licm,                   # Loop Invariant Code Motion
74                loop-rotate,            # Rotate Loops
75                licm,                   # Loop Invariant Code Motion
76                # Unswitch loops
77                simple-loop-unswitch<nontrivial>
78            ),
79            simplifycfg,                # Simplify the CFG
80            instcombine,                # Combine redundant instructions
81            loop-simplify,              # Canonicalize natural loops
82            lcssa,                      # Loop-Closed SSA Form Pass
83            loop-mssa(
84                loop-idiom,             # Recognize loop idioms
85                indvars,                # Induction Variable Simplification
86                loop-deletion           # Delete dead loops
87            ),
88            # Unroll loops
89            loop-unroll<O2;no-upperbound;peeling;partial>,
90#           sroa,                       # SROA
91            mldst-motion,               # MergedLoadStoreMotion
92            gvn,                        # Global Value Numbering
93            sccp,                       # Sparse Conditional Constant Propagation
94            bdce,                       # Bit-Tracking Dead Code Elimination
95            instcombine,                # Combine redundant instructions
96            jump-threading,             # Jump Threading
97            correlated-propagation,     # Value Propagation
98            adce,                       # Aggressive Dead Code Elimination
99            memcpyopt,                  # MemCpy Optimization
100            dse,                        # Dead Store Elimination
101            loop-simplify,              # Canonicalize natural loops
102            lcssa,                      # Loop-Closed SSA Form Pass
103            loop-mssa(
104                licm                    # Loop Invariant Code Motion
105            ),
106            # Simplify the CFG
107            simplifycfg<hoist-common-insts;sink-common-insts>,
108            instcombine                 # Combine redundant instructions
109        )
110    ),
111#   elim-avail-extern,              # Eliminate Available Externally Globals
112#   rpo-function-attrs,             # Deduce function attributes in RPO
113    globalopt,                      # Global Variable Optimizer
114    globaldce,                      # Dead Global Elimination
115#   float2int,                      # Float to int
116#   lower-constant-intrinsics,      # Lower constant intrinsics
117    discard-inline-module,          # Discard inline module
118
119    function(
120        loop-simplify,                  # Canonicalize natural loops
121        lcssa,                          # Loop-Closed SSA Form Pass
122        loop-rotate,                    # Rotate Loops
123        loop(ark-loop-peeling),         # Loop peeling
124        prune-deopt,                    # ARK Deopt Pruning
125        ark-gvn                         # ARK GVN
126    ),
127
128    # This sequence of passes from legacy function AddFunctionSimplificationPasses
129    function(
130#       sroa,                       # SROA
131        early-cse<memssa>,          # Early CSE (with memory SSA)
132#       wrap-speculative-execution, # Speculatively execute instructions if target has divergent branches
133        jump-threading,             # Jump Threading
134        correlated-propagation,     # Value Propagation
135        simplifycfg,                # Simplify the CFG
136        instcombine,                # Combine redundant instructions
137#       libcalls-shrinkwrap,        # Conditionally eliminate dead library calls
138#       pgo-memop-opt,              # PGOMemOPSize
139        tailcallelim,               # Tail Call Elimination
140        simplifycfg,                # Simplify the CFG
141        reassociate,                # Reassociate expressions
142        loop-mssa(
143            licm,                   # Loop Invariant Code Motion
144            loop-rotate,            # Rotate Loops
145            licm,                   # Loop Invariant Code Motion
146            # Unswitch loops
147            simple-loop-unswitch<nontrivial>
148        ),
149        simplifycfg,                # Simplify the CFG
150        instcombine,                # Combine redundant instructions
151        loop-mssa(
152            loop-idiom,             # Recognize loop idioms
153            indvars,                # Induction Variable Simplification
154            loop-deletion           # Delete dead loops
155        ),
156        loop-unroll,                # Unroll loops
157#       sroa,                       # SROA
158        mldst-motion,               # MergedLoadStoreMotion
159        gvn,                        # Global Value Numbering
160        sccp,                       # Sparse Conditional Constant Propagation
161        bdce,                       # Bit-Tracking Dead Code Elimination
162        instcombine,                # Combine redundant instructions
163        jump-threading,             # Jump Threading
164        correlated-propagation,     # Value Propagation
165        adce,                       # Aggressive Dead Code Elimination
166        memcpyopt,                  # MemCpy Optimization
167        dse,                        # Dead Store Elimination
168        loop-simplify,              # Canonicalize natural loops
169        lcssa,                      # Loop-Closed SSA Form Pass
170        loop-mssa(
171            licm                    # Loop Invariant Code Motion
172        ),
173        # Simplify the CFG
174        simplifycfg<
175            switch-to-lookup;
176            hoist-common-insts;
177            sink-common-insts
178        >,
179        instcombine                 # Combine redundant instructions
180    ),
181
182    # Continue default pipeline
183    function(
184        loop-simplify,              # Canonicalize natural loops
185        lcssa,                      # Loop-Closed SSA Form Pass
186        loop-mssa(
187            loop-rotate             # Rotate Loops
188        ),
189#       loop-distribute,            # Loop Distribution
190#       inject-tli-mappings,        # Inject TLI Mappings
191        loop-vectorize<
192            no-interleave-forced-only;
193            no-vectorize-forced-only
194        >,                          # Loop Vectorization
195        loop-simplify,              # Canonicalize natural loops
196#       loop-load-elim,             # LoopLoadEliminationPass
197        instcombine,                # Combine redundant instructions
198        simplifycfg<
199            forward-switch-cond;
200            switch-to-lookup;
201            no-keep-loops;
202            hoist-common-insts;
203            sink-common-insts
204        >,                          # Simplify the CFG
205        slp-vectorizer,             # Transform consecutive stores into vector-stores
206        vector-combine,             # Optimize scalar/vector ops
207        instcombine,                # Combine redundant instructions
208        loop-simplify,              # Canonicalize natural loops
209        lcssa,                      # Loop-Closed SSA Form Pass
210        loop-unroll,                # Unroll loops
211        instcombine,                # Combine redundant instructions
212        loop-simplify,              # Canonicalize natural loops
213        lcssa,                      # Loop-Closed SSA Form Pass
214        loop-mssa(
215            licm                    # Loop Invariant Code Motion
216        ),
217        transform-warning,          # Warn about non-applied transformations
218        alignment-from-assumptions  # Alignment from assumptions
219    ),
220    strip-dead-prototypes,          # Strip Unused Function Prototypes
221#   globaldce,                      # Dead Global Elimination
222    constmerge,                     # Merge Duplicate Global Constants
223    function(
224        loop-simplify,              # Canonicalize natural loops
225        lcssa,                      # Loop-Closed SSA Form Pass
226        loop-sink,                  # Loop Sink
227        instsimplify,               # Remove redundant instructions
228        div-rem-pairs,              # Hoist/decompose integer division and remainder
229        simplifycfg                 # Simplify the CFG
230    ),
231
232    function(
233        aarch64-fixup-sdiv,             # ARK Fixup SDiv and SRem instructions on AArch64
234        mem-barriers,                   # ARK Memory Barriers placement
235        intrinsics-lowering,            # ARK Intrinsics Lowering
236        runtime-calls-lowering,         # ARK Runtime Calls Lowering
237        insert-safepoints,              # ARK Insert Safepoints
238        gep-propagation,                # ARK GEP Propagation
239        gc-intrusion,                   # ARK GC Intrusion
240        gc-intrusion-check,             # ARK GC Intrusion Check
241        expand-atomics,                 # Expand atomics
242        fixup-poisons                   # ARK fixup poisons
243    )
244)
245