annotate include/llvm/Transforms/Scalar/SimpleLoopUnswitch.h @ 148:63bd29f05246

merged
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 14 Aug 2019 19:46:37 +0900
parents c2174574ed3a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
1 //===- SimpleLoopUnswitch.h - Hoist loop-invariant control flow -*- C++ -*-===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
2 //
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
4 // See https://llvm.org/LICENSE.txt for license information.
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
6 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
7 //===----------------------------------------------------------------------===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
8
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
9 #ifndef LLVM_TRANSFORMS_SCALAR_SIMPLELOOPUNSWITCH_H
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
10 #define LLVM_TRANSFORMS_SCALAR_SIMPLELOOPUNSWITCH_H
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
11
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
12 #include "llvm/Analysis/LoopAnalysisManager.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
13 #include "llvm/Analysis/LoopInfo.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
14 #include "llvm/IR/PassManager.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
15 #include "llvm/Transforms/Scalar/LoopPassManager.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
16
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
17 namespace llvm {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
18
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
19 /// This pass transforms loops that contain branches or switches on loop-
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
20 /// invariant conditions to have multiple loops. For example, it turns the left
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
21 /// into the right code:
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
22 ///
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
23 /// for (...) if (lic)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
24 /// A for (...)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
25 /// if (lic) A; B; C
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
26 /// B else
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
27 /// C for (...)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
28 /// A; C
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
29 ///
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
30 /// This can increase the size of the code exponentially (doubling it every time
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
31 /// a loop is unswitched) so we only unswitch if the resultant code will be
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
32 /// smaller than a threshold.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
33 ///
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
34 /// This pass expects LICM to be run before it to hoist invariant conditions out
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
35 /// of the loop, to make the unswitching opportunity obvious.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
36 ///
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
37 /// There is a taxonomy of unswitching that we use to classify different forms
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
38 /// of this transformaiton:
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
39 ///
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
40 /// - Trival unswitching: this is when the condition can be unswitched without
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
41 /// cloning any code from inside the loop. A non-trivial unswitch requires
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
42 /// code duplication.
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
43 ///
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
44 /// - Full unswitching: this is when the branch or switch is completely moved
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
45 /// from inside the loop to outside the loop. Partial unswitching removes the
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
46 /// branch from the clone of the loop but must leave a (somewhat simplified)
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
47 /// branch in the original loop. While theoretically partial unswitching can
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
48 /// be done for switches, the requirements are extreme - we need the loop
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
49 /// invariant input to the switch to be sufficient to collapse to a single
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
50 /// successor in each clone.
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
51 ///
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
52 /// This pass always does trivial, full unswitching for both branches and
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
53 /// switches. For branches, it also always does trivial, partial unswitching.
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
54 ///
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
55 /// If enabled (via the constructor's `NonTrivial` parameter), this pass will
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
56 /// additionally do non-trivial, full unswitching for branches and switches, and
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
57 /// will do non-trivial, partial unswitching for branches.
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
58 ///
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
59 /// Because partial unswitching of switches is extremely unlikely to be possible
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
60 /// in practice and significantly complicates the implementation, this pass does
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
61 /// not currently implement that in any mode.
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
62 class SimpleLoopUnswitchPass : public PassInfoMixin<SimpleLoopUnswitchPass> {
134
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
63 bool NonTrivial;
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
64
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
65 public:
134
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
66 SimpleLoopUnswitchPass(bool NonTrivial = false) : NonTrivial(NonTrivial) {}
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
67
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
68 PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
69 LoopStandardAnalysisResults &AR, LPMUpdater &U);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
70 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
71
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
72 /// Create the legacy pass object for the simple loop unswitcher.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
73 ///
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
74 /// See the documentaion for `SimpleLoopUnswitchPass` for details.
134
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
75 Pass *createSimpleLoopUnswitchLegacyPass(bool NonTrivial = false);
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
76
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
77 } // end namespace llvm
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
78
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
79 #endif // LLVM_TRANSFORMS_SCALAR_SIMPLELOOPUNSWITCH_H