blob: 4498e1db521e807ce8e7e88077681a2da03aff55 [file] [log] [blame]
Devang Patelf42389f2007-04-07 01:25:15 +00001//===- LoopRotation.cpp - Loop Rotation Pass ------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Devang Patelf42389f2007-04-07 01:25:15 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements Loop Rotation Pass.
11//
12//===----------------------------------------------------------------------===//
13
Justin Bognerd0d23412016-05-03 22:02:31 +000014#include "llvm/Transforms/Scalar/LoopRotation.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000015#include "llvm/ADT/Statistic.h"
Chandler Carruth08eebe22015-07-23 09:34:01 +000016#include "llvm/Analysis/AliasAnalysis.h"
Chandler Carruth7b560d42015-09-09 17:55:00 +000017#include "llvm/Analysis/BasicAliasAnalysis.h"
Chandler Carruth66b31302015-01-04 12:03:27 +000018#include "llvm/Analysis/AssumptionCache.h"
Chris Lattner679572e2011-01-02 07:35:53 +000019#include "llvm/Analysis/CodeMetrics.h"
Chris Lattner8c5defd2011-01-08 08:24:46 +000020#include "llvm/Analysis/InstructionSimplify.h"
Chandler Carruth7b560d42015-09-09 17:55:00 +000021#include "llvm/Analysis/GlobalsModRef.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000022#include "llvm/Analysis/LoopPass.h"
Justin Bognerd0d23412016-05-03 22:02:31 +000023#include "llvm/Analysis/LoopPassManager.h"
Devang Patelfac4d1f2007-07-11 23:47:28 +000024#include "llvm/Analysis/ScalarEvolution.h"
Chandler Carruth7b560d42015-09-09 17:55:00 +000025#include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
Chandler Carruthbb9caa92013-01-21 13:04:33 +000026#include "llvm/Analysis/TargetTransformInfo.h"
Andrew Trick10cc4532012-02-14 00:00:23 +000027#include "llvm/Analysis/ValueTracking.h"
Chandler Carruth1305dc32014-03-04 11:45:46 +000028#include "llvm/IR/CFG.h"
Chandler Carruth5ad5f152014-01-13 09:26:24 +000029#include "llvm/IR/Dominators.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000030#include "llvm/IR/Function.h"
31#include "llvm/IR/IntrinsicInst.h"
Mehdi Aminia28d91d2015-03-10 02:37:25 +000032#include "llvm/IR/Module.h"
Owen Anderson115aa162014-05-26 08:58:51 +000033#include "llvm/Support/CommandLine.h"
Devang Patelf42389f2007-04-07 01:25:15 +000034#include "llvm/Support/Debug.h"
Benjamin Kramer799003b2015-03-23 19:32:43 +000035#include "llvm/Support/raw_ostream.h"
Justin Bognerd0d23412016-05-03 22:02:31 +000036#include "llvm/Transforms/Scalar.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000037#include "llvm/Transforms/Utils/BasicBlockUtils.h"
38#include "llvm/Transforms/Utils/Local.h"
Chandler Carruth31088a92016-02-19 10:45:18 +000039#include "llvm/Transforms/Utils/LoopUtils.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000040#include "llvm/Transforms/Utils/SSAUpdater.h"
41#include "llvm/Transforms/Utils/ValueMapper.h"
Devang Patelf42389f2007-04-07 01:25:15 +000042using namespace llvm;
43
Chandler Carruth964daaa2014-04-22 02:55:47 +000044#define DEBUG_TYPE "loop-rotate"
45
Sebastian Popdfb66a12016-06-14 14:44:05 +000046static cl::opt<unsigned> DefaultRotationThreshold(
47 "rotation-max-header-size", cl::init(16), cl::Hidden,
48 cl::desc("The default maximum header size for automatic loop rotation"));
Devang Patelf42389f2007-04-07 01:25:15 +000049
50STATISTIC(NumRotated, "Number of loops rotated");
Devang Patelf42389f2007-04-07 01:25:15 +000051
Benjamin Kramer4d098922016-07-10 11:28:51 +000052namespace {
Sebastian Popdfb66a12016-06-14 14:44:05 +000053/// A simple loop rotation transformation.
54class LoopRotate {
55 const unsigned MaxHeaderSize;
56 LoopInfo *LI;
57 const TargetTransformInfo *TTI;
58 AssumptionCache *AC;
59 DominatorTree *DT;
60 ScalarEvolution *SE;
61
62public:
63 LoopRotate(unsigned MaxHeaderSize, LoopInfo *LI,
64 const TargetTransformInfo *TTI, AssumptionCache *AC,
65 DominatorTree *DT, ScalarEvolution *SE)
66 : MaxHeaderSize(MaxHeaderSize), LI(LI), TTI(TTI), AC(AC), DT(DT), SE(SE) {
67 }
68 bool processLoop(Loop *L);
69
70private:
71 bool rotateLoop(Loop *L, bool SimplifiedLatch);
72 bool simplifyLoopLatch(Loop *L);
73};
Benjamin Kramer4d098922016-07-10 11:28:51 +000074} // end anonymous namespace
Sebastian Popdfb66a12016-06-14 14:44:05 +000075
Chris Lattner30f318e2011-01-08 19:26:33 +000076/// RewriteUsesOfClonedInstructions - We just cloned the instructions from the
77/// old header into the preheader. If there were uses of the values produced by
78/// these instruction that were outside of the loop, we have to insert PHI nodes
79/// to merge the two values. Do this now.
80static void RewriteUsesOfClonedInstructions(BasicBlock *OrigHeader,
81 BasicBlock *OrigPreheader,
82 ValueToValueMapTy &ValueMap) {
83 // Remove PHI node entries that are no longer live.
84 BasicBlock::iterator I, E = OrigHeader->end();
85 for (I = OrigHeader->begin(); PHINode *PN = dyn_cast<PHINode>(I); ++I)
86 PN->removeIncomingValue(PN->getBasicBlockIndex(OrigPreheader));
Andrew Tricka20f1982012-02-14 00:00:19 +000087
Chris Lattner30f318e2011-01-08 19:26:33 +000088 // Now fix up users of the instructions in OrigHeader, inserting PHI nodes
89 // as necessary.
90 SSAUpdater SSA;
91 for (I = OrigHeader->begin(); I != E; ++I) {
Duncan P. N. Exon Smithbe4d8cb2015-10-13 19:26:58 +000092 Value *OrigHeaderVal = &*I;
Andrew Tricka20f1982012-02-14 00:00:19 +000093
Chris Lattner30f318e2011-01-08 19:26:33 +000094 // If there are no uses of the value (e.g. because it returns void), there
95 // is nothing to rewrite.
96 if (OrigHeaderVal->use_empty())
97 continue;
Andrew Tricka20f1982012-02-14 00:00:19 +000098
Duncan P. N. Exon Smitha71301b2016-04-17 19:26:49 +000099 Value *OrigPreHeaderVal = ValueMap.lookup(OrigHeaderVal);
Chris Lattner30f318e2011-01-08 19:26:33 +0000100
101 // The value now exits in two versions: the initial value in the preheader
102 // and the loop "next" value in the original header.
103 SSA.Initialize(OrigHeaderVal->getType(), OrigHeaderVal->getName());
104 SSA.AddAvailableValue(OrigHeader, OrigHeaderVal);
105 SSA.AddAvailableValue(OrigPreheader, OrigPreHeaderVal);
Andrew Tricka20f1982012-02-14 00:00:19 +0000106
Chris Lattner30f318e2011-01-08 19:26:33 +0000107 // Visit each use of the OrigHeader instruction.
108 for (Value::use_iterator UI = OrigHeaderVal->use_begin(),
Sebastian Popdfb66a12016-06-14 14:44:05 +0000109 UE = OrigHeaderVal->use_end();
110 UI != UE;) {
Chris Lattner30f318e2011-01-08 19:26:33 +0000111 // Grab the use before incrementing the iterator.
Chandler Carruthcdf47882014-03-09 03:16:01 +0000112 Use &U = *UI;
Andrew Tricka20f1982012-02-14 00:00:19 +0000113
Chris Lattner30f318e2011-01-08 19:26:33 +0000114 // Increment the iterator before removing the use from the list.
115 ++UI;
Andrew Tricka20f1982012-02-14 00:00:19 +0000116
Chris Lattner30f318e2011-01-08 19:26:33 +0000117 // SSAUpdater can't handle a non-PHI use in the same block as an
118 // earlier def. We can easily handle those cases manually.
119 Instruction *UserInst = cast<Instruction>(U.getUser());
120 if (!isa<PHINode>(UserInst)) {
121 BasicBlock *UserBB = UserInst->getParent();
Andrew Tricka20f1982012-02-14 00:00:19 +0000122
Chris Lattner30f318e2011-01-08 19:26:33 +0000123 // The original users in the OrigHeader are already using the
124 // original definitions.
125 if (UserBB == OrigHeader)
126 continue;
Andrew Tricka20f1982012-02-14 00:00:19 +0000127
Chris Lattner30f318e2011-01-08 19:26:33 +0000128 // Users in the OrigPreHeader need to use the value to which the
129 // original definitions are mapped.
130 if (UserBB == OrigPreheader) {
131 U = OrigPreHeaderVal;
132 continue;
133 }
134 }
Andrew Tricka20f1982012-02-14 00:00:19 +0000135
Chris Lattner30f318e2011-01-08 19:26:33 +0000136 // Anything else can be handled by SSAUpdater.
137 SSA.RewriteUse(U);
138 }
Chuang-Yu Cheng175741d2016-05-10 09:45:44 +0000139
140 // Replace MetadataAsValue(ValueAsMetadata(OrigHeaderVal)) uses in debug
141 // intrinsics.
142 LLVMContext &C = OrigHeader->getContext();
143 if (auto *VAM = ValueAsMetadata::getIfExists(OrigHeaderVal)) {
144 if (auto *MAV = MetadataAsValue::getIfExists(C, VAM)) {
Sebastian Popdfb66a12016-06-14 14:44:05 +0000145 for (auto UI = MAV->use_begin(), E = MAV->use_end(); UI != E;) {
Chuang-Yu Cheng175741d2016-05-10 09:45:44 +0000146 // Grab the use before incrementing the iterator. Otherwise, altering
147 // the Use will invalidate the iterator.
148 Use &U = *UI++;
149 DbgInfoIntrinsic *UserInst = dyn_cast<DbgInfoIntrinsic>(U.getUser());
Sebastian Popdfb66a12016-06-14 14:44:05 +0000150 if (!UserInst)
151 continue;
Chuang-Yu Cheng175741d2016-05-10 09:45:44 +0000152
153 // The original users in the OrigHeader are already using the original
154 // definitions.
155 BasicBlock *UserBB = UserInst->getParent();
156 if (UserBB == OrigHeader)
157 continue;
158
159 // Users in the OrigPreHeader need to use the value to which the
160 // original definitions are mapped and anything else can be handled by
161 // the SSAUpdater. To avoid adding PHINodes, check if the value is
162 // available in UserBB, if not substitute undef.
163 Value *NewVal;
164 if (UserBB == OrigPreheader)
165 NewVal = OrigPreHeaderVal;
166 else if (SSA.HasValueForBlock(UserBB))
167 NewVal = SSA.GetValueInMiddleOfBlock(UserBB);
168 else
169 NewVal = UndefValue::get(OrigHeaderVal->getType());
170 U = MetadataAsValue::get(C, ValueAsMetadata::get(NewVal));
171 }
172 }
173 }
Chris Lattner30f318e2011-01-08 19:26:33 +0000174 }
Andrew Tricka20f1982012-02-14 00:00:19 +0000175}
Chris Lattner30f318e2011-01-08 19:26:33 +0000176
Dan Gohmanb5650eb2007-05-11 21:10:54 +0000177/// Rotate loop LP. Return true if the loop is rotated.
Andrew Trick9c72b072013-05-06 17:58:18 +0000178///
179/// \param SimplifiedLatch is true if the latch was just folded into the final
180/// loop exit. In this case we may want to rotate even though the new latch is
181/// now an exiting branch. This rotation would have happened had the latch not
182/// been simplified. However, if SimplifiedLatch is false, then we avoid
183/// rotating loops in which the latch exits to avoid excessive or endless
184/// rotation. LoopRotate should be repeatable and converge to a canonical
185/// form. This property is satisfied because simplifying the loop latch can only
186/// happen once across multiple invocations of the LoopRotate pass.
Sebastian Popdfb66a12016-06-14 14:44:05 +0000187bool LoopRotate::rotateLoop(Loop *L, bool SimplifiedLatch) {
Dan Gohman091e4402009-06-25 00:22:44 +0000188 // If the loop has only one block then there is not much to rotate.
Devang Patel88bc2c62007-04-09 16:11:48 +0000189 if (L->getBlocks().size() == 1)
Devang Patelf42389f2007-04-07 01:25:15 +0000190 return false;
Andrew Tricka20f1982012-02-14 00:00:19 +0000191
Chris Lattner7fab23b2011-01-08 18:06:22 +0000192 BasicBlock *OrigHeader = L->getHeader();
Benjamin Kramerafdfdb52012-08-30 15:39:42 +0000193 BasicBlock *OrigLatch = L->getLoopLatch();
Andrew Tricka20f1982012-02-14 00:00:19 +0000194
Chris Lattner7fab23b2011-01-08 18:06:22 +0000195 BranchInst *BI = dyn_cast<BranchInst>(OrigHeader->getTerminator());
Craig Topperf40110f2014-04-25 05:29:35 +0000196 if (!BI || BI->isUnconditional())
Chris Lattner7fab23b2011-01-08 18:06:22 +0000197 return false;
Andrew Tricka20f1982012-02-14 00:00:19 +0000198
Dan Gohman091e4402009-06-25 00:22:44 +0000199 // If the loop header is not one of the loop exiting blocks then
200 // either this loop is already rotated or it is not
Devang Patelf42389f2007-04-07 01:25:15 +0000201 // suitable for loop rotation transformations.
Dan Gohman8f4078b2009-10-24 23:34:26 +0000202 if (!L->isLoopExiting(OrigHeader))
Devang Patelf42389f2007-04-07 01:25:15 +0000203 return false;
204
Benjamin Kramerafdfdb52012-08-30 15:39:42 +0000205 // If the loop latch already contains a branch that leaves the loop then the
206 // loop is already rotated.
Craig Topperf40110f2014-04-25 05:29:35 +0000207 if (!OrigLatch)
Andrew Trick9c72b072013-05-06 17:58:18 +0000208 return false;
209
210 // Rotate if either the loop latch does *not* exit the loop, or if the loop
211 // latch was just simplified.
212 if (L->isLoopExiting(OrigLatch) && !SimplifiedLatch)
Devang Patelf42389f2007-04-07 01:25:15 +0000213 return false;
214
James Molloy4f6fb952012-12-20 16:04:27 +0000215 // Check size of original header and reject loop if it is very big or we can't
216 // duplicate blocks inside it.
Chris Lattner679572e2011-01-02 07:35:53 +0000217 {
Hal Finkel57f03dd2014-09-07 13:49:57 +0000218 SmallPtrSet<const Value *, 32> EphValues;
Chandler Carruth66b31302015-01-04 12:03:27 +0000219 CodeMetrics::collectEphemeralValues(L, AC, EphValues);
Hal Finkel57f03dd2014-09-07 13:49:57 +0000220
Chris Lattner679572e2011-01-02 07:35:53 +0000221 CodeMetrics Metrics;
Hal Finkel57f03dd2014-09-07 13:49:57 +0000222 Metrics.analyzeBasicBlock(OrigHeader, *TTI, EphValues);
James Molloy4f6fb952012-12-20 16:04:27 +0000223 if (Metrics.notDuplicatable) {
Alp Tokerf907b892013-12-05 05:44:44 +0000224 DEBUG(dbgs() << "LoopRotation: NOT rotating - contains non-duplicatable"
Sebastian Popdfb66a12016-06-14 14:44:05 +0000225 << " instructions: ";
226 L->dump());
James Molloy4f6fb952012-12-20 16:04:27 +0000227 return false;
228 }
Justin Lebardf04d2a2016-02-12 21:01:33 +0000229 if (Metrics.convergent) {
230 DEBUG(dbgs() << "LoopRotation: NOT rotating - contains convergent "
Sebastian Popdfb66a12016-06-14 14:44:05 +0000231 "instructions: ";
232 L->dump());
Justin Lebardf04d2a2016-02-12 21:01:33 +0000233 return false;
234 }
Owen Anderson115aa162014-05-26 08:58:51 +0000235 if (Metrics.NumInsts > MaxHeaderSize)
Chris Lattner679572e2011-01-02 07:35:53 +0000236 return false;
Devang Patelbab43b42009-03-06 03:51:30 +0000237 }
238
Devang Patelfac4d1f2007-07-11 23:47:28 +0000239 // Now, this loop is suitable for rotation.
Chris Lattner30f318e2011-01-08 19:26:33 +0000240 BasicBlock *OrigPreheader = L->getLoopPreheader();
Andrew Tricka20f1982012-02-14 00:00:19 +0000241
Chris Lattner88974f42011-04-09 07:25:58 +0000242 // If the loop could not be converted to canonical form, it must have an
243 // indirectbr in it, just give up.
Craig Topperf40110f2014-04-25 05:29:35 +0000244 if (!OrigPreheader)
Chris Lattner88974f42011-04-09 07:25:58 +0000245 return false;
Devang Patelfac4d1f2007-07-11 23:47:28 +0000246
Dan Gohmanfc20b672009-09-27 15:37:03 +0000247 // Anything ScalarEvolution may know about this loop or the PHI nodes
248 // in its header will soon be invalidated.
Justin Bogner6291b582015-12-14 23:22:48 +0000249 if (SE)
250 SE->forgetLoop(L);
Dan Gohmanfc20b672009-09-27 15:37:03 +0000251
Benjamin Kramerafdfdb52012-08-30 15:39:42 +0000252 DEBUG(dbgs() << "LoopRotation: rotating "; L->dump());
253
Devang Patelf42389f2007-04-07 01:25:15 +0000254 // Find new Loop header. NewHeader is a Header's one and only successor
Chris Lattner57cb4722009-01-26 01:57:01 +0000255 // that is inside loop. Header's other successor is outside the
256 // loop. Otherwise loop is not suitable for rotation.
Chris Lattner385f2ec2011-01-08 17:48:33 +0000257 BasicBlock *Exit = BI->getSuccessor(0);
258 BasicBlock *NewHeader = BI->getSuccessor(1);
Devang Patel88bc2c62007-04-09 16:11:48 +0000259 if (L->contains(Exit))
260 std::swap(Exit, NewHeader);
Chris Lattnerd67aaa62009-01-26 01:38:24 +0000261 assert(NewHeader && "Unable to determine new loop header");
Andrew Tricka20f1982012-02-14 00:00:19 +0000262 assert(L->contains(NewHeader) && !L->contains(Exit) &&
Devang Patel88bc2c62007-04-09 16:11:48 +0000263 "Unable to determine loop header and exit blocks");
Andrew Tricka20f1982012-02-14 00:00:19 +0000264
Dan Gohman091e4402009-06-25 00:22:44 +0000265 // This code assumes that the new header has exactly one predecessor.
266 // Remove any single-entry PHI nodes in it.
Chris Lattner7b6647c2009-01-26 02:11:30 +0000267 assert(NewHeader->getSinglePredecessor() &&
268 "New header doesn't have one pred!");
269 FoldSingleEntryPHINodes(NewHeader);
Devang Patelf42389f2007-04-07 01:25:15 +0000270
Dan Gohmanb9797942009-10-24 23:19:52 +0000271 // Begin by walking OrigHeader and populating ValueMap with an entry for
272 // each Instruction.
Devang Patel88bc2c62007-04-09 16:11:48 +0000273 BasicBlock::iterator I = OrigHeader->begin(), E = OrigHeader->end();
Chris Lattner2b3f20e2011-01-08 07:21:31 +0000274 ValueToValueMapTy ValueMap;
Devang Patelb9af5742007-04-09 19:04:21 +0000275
Dan Gohmanb9797942009-10-24 23:19:52 +0000276 // For PHI nodes, the value available in OldPreHeader is just the
277 // incoming value from OldPreHeader.
278 for (; PHINode *PN = dyn_cast<PHINode>(I); ++I)
Jay Foad372ad642011-06-20 14:18:48 +0000279 ValueMap[PN] = PN->getIncomingValueForBlock(OrigPreheader);
Devang Patelf42389f2007-04-07 01:25:15 +0000280
Mehdi Aminia28d91d2015-03-10 02:37:25 +0000281 const DataLayout &DL = L->getHeader()->getModule()->getDataLayout();
282
Chris Lattnerb01c24a2010-09-06 01:10:22 +0000283 // For the rest of the instructions, either hoist to the OrigPreheader if
284 // possible or create a clone in the OldPreHeader if not.
Chris Lattner30f318e2011-01-08 19:26:33 +0000285 TerminatorInst *LoopEntryBranch = OrigPreheader->getTerminator();
Chris Lattnerb01c24a2010-09-06 01:10:22 +0000286 while (I != E) {
Duncan P. N. Exon Smithbe4d8cb2015-10-13 19:26:58 +0000287 Instruction *Inst = &*I++;
Andrew Tricka20f1982012-02-14 00:00:19 +0000288
Chris Lattnerb01c24a2010-09-06 01:10:22 +0000289 // If the instruction's operands are invariant and it doesn't read or write
290 // memory, then it is safe to hoist. Doing this doesn't change the order of
291 // execution in the preheader, but does prevent the instruction from
292 // executing in each iteration of the loop. This means it is safe to hoist
293 // something that might trap, but isn't safe to hoist something that reads
294 // memory (without proving that the loop doesn't write).
Sebastian Popdfb66a12016-06-14 14:44:05 +0000295 if (L->hasLoopInvariantOperands(Inst) && !Inst->mayReadFromMemory() &&
296 !Inst->mayWriteToMemory() && !isa<TerminatorInst>(Inst) &&
297 !isa<DbgInfoIntrinsic>(Inst) && !isa<AllocaInst>(Inst)) {
Chris Lattnerb01c24a2010-09-06 01:10:22 +0000298 Inst->moveBefore(LoopEntryBranch);
299 continue;
300 }
Andrew Tricka20f1982012-02-14 00:00:19 +0000301
Chris Lattnerb01c24a2010-09-06 01:10:22 +0000302 // Otherwise, create a duplicate of the instruction.
303 Instruction *C = Inst->clone();
Andrew Tricka20f1982012-02-14 00:00:19 +0000304
Chris Lattner8c5defd2011-01-08 08:24:46 +0000305 // Eagerly remap the operands of the instruction.
306 RemapInstruction(C, ValueMap,
Duncan P. N. Exon Smithda68cbc2016-04-07 00:26:43 +0000307 RF_NoModuleLevelChanges | RF_IgnoreMissingLocals);
Andrew Tricka20f1982012-02-14 00:00:19 +0000308
Chris Lattner8c5defd2011-01-08 08:24:46 +0000309 // With the operands remapped, see if the instruction constant folds or is
310 // otherwise simplifyable. This commonly occurs because the entry from PHI
311 // nodes allows icmps and other instructions to fold.
Mehdi Aminia28d91d2015-03-10 02:37:25 +0000312 // FIXME: Provide TLI, DT, AC to SimplifyInstruction.
313 Value *V = SimplifyInstruction(C, DL);
Chris Lattner25ba40a2011-01-08 17:38:45 +0000314 if (V && LI->replacementPreservesLCSSAForm(C, V)) {
Chris Lattner8c5defd2011-01-08 08:24:46 +0000315 // If so, then delete the temporary instruction and stick the folded value
316 // in the map.
Chris Lattner8c5defd2011-01-08 08:24:46 +0000317 ValueMap[Inst] = V;
David Majnemerb8da3a22016-06-25 00:04:10 +0000318 if (!C->mayHaveSideEffects()) {
319 delete C;
320 C = nullptr;
321 }
Chris Lattner8c5defd2011-01-08 08:24:46 +0000322 } else {
David Majnemerb8da3a22016-06-25 00:04:10 +0000323 ValueMap[Inst] = C;
324 }
325 if (C) {
Chris Lattner8c5defd2011-01-08 08:24:46 +0000326 // Otherwise, stick the new instruction into the new block!
327 C->setName(Inst->getName());
328 C->insertBefore(LoopEntryBranch);
Chris Lattner8c5defd2011-01-08 08:24:46 +0000329 }
Devang Patelf42389f2007-04-07 01:25:15 +0000330 }
331
Dan Gohmanb9797942009-10-24 23:19:52 +0000332 // Along with all the other instructions, we just cloned OrigHeader's
333 // terminator into OrigPreHeader. Fix up the PHI nodes in each of OrigHeader's
334 // successors by duplicating their incoming values for OrigHeader.
335 TerminatorInst *TI = OrigHeader->getTerminator();
Pete Cooperebcd7482015-08-06 20:22:46 +0000336 for (BasicBlock *SuccBB : TI->successors())
337 for (BasicBlock::iterator BI = SuccBB->begin();
Dan Gohmanb9797942009-10-24 23:19:52 +0000338 PHINode *PN = dyn_cast<PHINode>(BI); ++BI)
Chris Lattner30f318e2011-01-08 19:26:33 +0000339 PN->addIncoming(PN->getIncomingValueForBlock(OrigHeader), OrigPreheader);
Devang Patelf42389f2007-04-07 01:25:15 +0000340
Dan Gohmanb9797942009-10-24 23:19:52 +0000341 // Now that OrigPreHeader has a clone of OrigHeader's terminator, remove
342 // OrigPreHeader's old terminator (the original branch into the loop), and
343 // remove the corresponding incoming values from the PHI nodes in OrigHeader.
344 LoopEntryBranch->eraseFromParent();
Devang Patelf42389f2007-04-07 01:25:15 +0000345
Chris Lattner30f318e2011-01-08 19:26:33 +0000346 // If there were any uses of instructions in the duplicated block outside the
347 // loop, update them, inserting PHI nodes as required
348 RewriteUsesOfClonedInstructions(OrigHeader, OrigPreheader, ValueMap);
Devang Patelf42389f2007-04-07 01:25:15 +0000349
Dan Gohmanb9797942009-10-24 23:19:52 +0000350 // NewHeader is now the header of the loop.
Devang Patelf42389f2007-04-07 01:25:15 +0000351 L->moveToHeader(NewHeader);
Chris Lattner26151302011-01-08 19:10:28 +0000352 assert(L->getHeader() == NewHeader && "Latch block is our new header");
Devang Patelf42389f2007-04-07 01:25:15 +0000353
Chris Lattner59c82f82011-01-08 19:59:06 +0000354 // At this point, we've finished our major CFG changes. As part of cloning
355 // the loop into the preheader we've simplified instructions and the
356 // duplicated conditional branch may now be branching on a constant. If it is
357 // branching on a constant and if that constant means that we enter the loop,
358 // then we fold away the cond branch to an uncond branch. This simplifies the
359 // loop in cases important for nested loops, and it also means we don't have
360 // to split as many edges.
361 BranchInst *PHBI = cast<BranchInst>(OrigPreheader->getTerminator());
362 assert(PHBI->isConditional() && "Should be clone of BI condbr!");
363 if (!isa<ConstantInt>(PHBI->getCondition()) ||
Sebastian Popdfb66a12016-06-14 14:44:05 +0000364 PHBI->getSuccessor(cast<ConstantInt>(PHBI->getCondition())->isZero()) !=
365 NewHeader) {
Chris Lattner59c82f82011-01-08 19:59:06 +0000366 // The conditional branch can't be folded, handle the general case.
367 // Update DominatorTree to reflect the CFG change we just made. Then split
368 // edges as necessary to preserve LoopSimplify form.
Chandler Carruth94209092015-01-18 02:08:05 +0000369 if (DT) {
Benjamin Kramerafdfdb52012-08-30 15:39:42 +0000370 // Everything that was dominated by the old loop header is now dominated
371 // by the original loop preheader. Conceptually the header was merged
372 // into the preheader, even though we reuse the actual block as a new
373 // loop latch.
Chandler Carruth94209092015-01-18 02:08:05 +0000374 DomTreeNode *OrigHeaderNode = DT->getNode(OrigHeader);
Benjamin Kramerafdfdb52012-08-30 15:39:42 +0000375 SmallVector<DomTreeNode *, 8> HeaderChildren(OrigHeaderNode->begin(),
376 OrigHeaderNode->end());
Chandler Carruth94209092015-01-18 02:08:05 +0000377 DomTreeNode *OrigPreheaderNode = DT->getNode(OrigPreheader);
Benjamin Kramerafdfdb52012-08-30 15:39:42 +0000378 for (unsigned I = 0, E = HeaderChildren.size(); I != E; ++I)
Chandler Carruth94209092015-01-18 02:08:05 +0000379 DT->changeImmediateDominator(HeaderChildren[I], OrigPreheaderNode);
Andrew Tricka20f1982012-02-14 00:00:19 +0000380
Chandler Carruth94209092015-01-18 02:08:05 +0000381 assert(DT->getNode(Exit)->getIDom() == OrigPreheaderNode);
382 assert(DT->getNode(NewHeader)->getIDom() == OrigPreheaderNode);
Benjamin Kramer3be6a482012-09-01 12:04:51 +0000383
Chris Lattner59c82f82011-01-08 19:59:06 +0000384 // Update OrigHeader to be dominated by the new header block.
Chandler Carruth94209092015-01-18 02:08:05 +0000385 DT->changeImmediateDominator(OrigHeader, OrigLatch);
Chris Lattner59c82f82011-01-08 19:59:06 +0000386 }
Andrew Tricka20f1982012-02-14 00:00:19 +0000387
Chris Lattner59c82f82011-01-08 19:59:06 +0000388 // Right now OrigPreHeader has two successors, NewHeader and ExitBlock, and
Nadav Rotem465834c2012-07-24 10:51:42 +0000389 // thus is not a preheader anymore.
390 // Split the edge to form a real preheader.
Chandler Carruth37df2cf2015-01-19 12:09:11 +0000391 BasicBlock *NewPH = SplitCriticalEdge(
392 OrigPreheader, NewHeader,
393 CriticalEdgeSplittingOptions(DT, LI).setPreserveLCSSA());
Chris Lattner59c82f82011-01-08 19:59:06 +0000394 NewPH->setName(NewHeader->getName() + ".lr.ph");
Andrew Tricka20f1982012-02-14 00:00:19 +0000395
Nadav Rotem465834c2012-07-24 10:51:42 +0000396 // Preserve canonical loop form, which means that 'Exit' should have only
Chandler Carruthd4be9dc2014-01-29 13:16:53 +0000397 // one predecessor. Note that Exit could be an exit block for multiple
398 // nested loops, causing both of the edges to now be critical and need to
399 // be split.
400 SmallVector<BasicBlock *, 4> ExitPreds(pred_begin(Exit), pred_end(Exit));
401 bool SplitLatchEdge = false;
Benjamin Kramer135f7352016-06-26 12:28:59 +0000402 for (BasicBlock *ExitPred : ExitPreds) {
Chandler Carruthd4be9dc2014-01-29 13:16:53 +0000403 // We only need to split loop exit edges.
Benjamin Kramer135f7352016-06-26 12:28:59 +0000404 Loop *PredLoop = LI->getLoopFor(ExitPred);
Chandler Carruthd4be9dc2014-01-29 13:16:53 +0000405 if (!PredLoop || PredLoop->contains(Exit))
406 continue;
Benjamin Kramer135f7352016-06-26 12:28:59 +0000407 if (isa<IndirectBrInst>(ExitPred->getTerminator()))
Benjamin Kramer911d5b32015-02-20 20:49:25 +0000408 continue;
Benjamin Kramer135f7352016-06-26 12:28:59 +0000409 SplitLatchEdge |= L->getLoopLatch() == ExitPred;
Chandler Carruth37df2cf2015-01-19 12:09:11 +0000410 BasicBlock *ExitSplit = SplitCriticalEdge(
Benjamin Kramer135f7352016-06-26 12:28:59 +0000411 ExitPred, Exit,
412 CriticalEdgeSplittingOptions(DT, LI).setPreserveLCSSA());
Chandler Carruthd4be9dc2014-01-29 13:16:53 +0000413 ExitSplit->moveBefore(Exit);
414 }
415 assert(SplitLatchEdge &&
416 "Despite splitting all preds, failed to split latch exit?");
Chris Lattner59c82f82011-01-08 19:59:06 +0000417 } else {
418 // We can fold the conditional branch in the preheader, this makes things
419 // simpler. The first step is to remove the extra edge to the Exit block.
420 Exit->removePredecessor(OrigPreheader, true /*preserve LCSSA*/);
Devang Patelc1f7c1d2011-04-29 20:38:55 +0000421 BranchInst *NewBI = BranchInst::Create(NewHeader, PHBI);
422 NewBI->setDebugLoc(PHBI->getDebugLoc());
Chris Lattner59c82f82011-01-08 19:59:06 +0000423 PHBI->eraseFromParent();
Andrew Tricka20f1982012-02-14 00:00:19 +0000424
Chris Lattner59c82f82011-01-08 19:59:06 +0000425 // With our CFG finalized, update DomTree if it is available.
Chandler Carruth94209092015-01-18 02:08:05 +0000426 if (DT) {
Chris Lattner59c82f82011-01-08 19:59:06 +0000427 // Update OrigHeader to be dominated by the new header block.
Chandler Carruth94209092015-01-18 02:08:05 +0000428 DT->changeImmediateDominator(NewHeader, OrigPreheader);
429 DT->changeImmediateDominator(OrigHeader, OrigLatch);
Benjamin Kramerafdfdb52012-08-30 15:39:42 +0000430
431 // Brute force incremental dominator tree update. Call
432 // findNearestCommonDominator on all CFG predecessors of each child of the
433 // original header.
Chandler Carruth94209092015-01-18 02:08:05 +0000434 DomTreeNode *OrigHeaderNode = DT->getNode(OrigHeader);
Benjamin Kramer599a4bb2012-09-02 11:57:22 +0000435 SmallVector<DomTreeNode *, 8> HeaderChildren(OrigHeaderNode->begin(),
436 OrigHeaderNode->end());
437 bool Changed;
438 do {
439 Changed = false;
440 for (unsigned I = 0, E = HeaderChildren.size(); I != E; ++I) {
441 DomTreeNode *Node = HeaderChildren[I];
442 BasicBlock *BB = Node->getBlock();
Benjamin Kramerafdfdb52012-08-30 15:39:42 +0000443
Benjamin Kramer599a4bb2012-09-02 11:57:22 +0000444 pred_iterator PI = pred_begin(BB);
445 BasicBlock *NearestDom = *PI;
446 for (pred_iterator PE = pred_end(BB); PI != PE; ++PI)
Chandler Carruth94209092015-01-18 02:08:05 +0000447 NearestDom = DT->findNearestCommonDominator(NearestDom, *PI);
Benjamin Kramer599a4bb2012-09-02 11:57:22 +0000448
449 // Remember if this changes the DomTree.
450 if (Node->getIDom()->getBlock() != NearestDom) {
Chandler Carruth94209092015-01-18 02:08:05 +0000451 DT->changeImmediateDominator(BB, NearestDom);
Benjamin Kramer599a4bb2012-09-02 11:57:22 +0000452 Changed = true;
Benjamin Kramerafdfdb52012-08-30 15:39:42 +0000453 }
Benjamin Kramerafdfdb52012-08-30 15:39:42 +0000454 }
455
Sebastian Popdfb66a12016-06-14 14:44:05 +0000456 // If the dominator changed, this may have an effect on other
457 // predecessors, continue until we reach a fixpoint.
Benjamin Kramer599a4bb2012-09-02 11:57:22 +0000458 } while (Changed);
Chris Lattner59c82f82011-01-08 19:59:06 +0000459 }
Devang Patelfac4d1f2007-07-11 23:47:28 +0000460 }
Andrew Tricka20f1982012-02-14 00:00:19 +0000461
Chris Lattner59c82f82011-01-08 19:59:06 +0000462 assert(L->getLoopPreheader() && "Invalid loop preheader after loop rotation");
Chris Lattner063dca02011-01-08 18:52:51 +0000463 assert(L->getLoopLatch() && "Invalid loop latch after loop rotation");
Chris Lattnerfee37c52011-01-08 18:55:50 +0000464
Chris Lattner63fe78d2011-01-11 07:47:59 +0000465 // Now that the CFG and DomTree are in a consistent state again, try to merge
466 // the OrigHeader block into OrigLatch. This will succeed if they are
467 // connected by an unconditional branch. This is just a cleanup so the
468 // emitted code isn't too gross in this common case.
Chandler Carruthb5c11532015-01-18 02:11:23 +0000469 MergeBlockIntoPredecessor(OrigHeader, DT, LI);
Andrew Tricka20f1982012-02-14 00:00:19 +0000470
Benjamin Kramerafdfdb52012-08-30 15:39:42 +0000471 DEBUG(dbgs() << "LoopRotation: into "; L->dump());
472
Chris Lattnerfee37c52011-01-08 18:55:50 +0000473 ++NumRotated;
474 return true;
Devang Patel85419782007-04-09 20:19:46 +0000475}
Justin Bognera7300452015-12-14 23:22:44 +0000476
477/// Determine whether the instructions in this range may be safely and cheaply
478/// speculated. This is not an important enough situation to develop complex
479/// heuristics. We handle a single arithmetic instruction along with any type
480/// conversions.
481static bool shouldSpeculateInstrs(BasicBlock::iterator Begin,
482 BasicBlock::iterator End, Loop *L) {
483 bool seenIncrement = false;
484 bool MultiExitLoop = false;
485
486 if (!L->getExitingBlock())
487 MultiExitLoop = true;
488
489 for (BasicBlock::iterator I = Begin; I != End; ++I) {
490
491 if (!isSafeToSpeculativelyExecute(&*I))
492 return false;
493
494 if (isa<DbgInfoIntrinsic>(I))
495 continue;
496
497 switch (I->getOpcode()) {
498 default:
499 return false;
500 case Instruction::GetElementPtr:
501 // GEPs are cheap if all indices are constant.
502 if (!cast<GEPOperator>(I)->hasAllConstantIndices())
503 return false;
Justin Bognerb03fd122016-08-17 05:10:15 +0000504 // fall-thru to increment case
505 LLVM_FALLTHROUGH;
Justin Bognera7300452015-12-14 23:22:44 +0000506 case Instruction::Add:
507 case Instruction::Sub:
508 case Instruction::And:
509 case Instruction::Or:
510 case Instruction::Xor:
511 case Instruction::Shl:
512 case Instruction::LShr:
513 case Instruction::AShr: {
Sebastian Popdfb66a12016-06-14 14:44:05 +0000514 Value *IVOpnd =
515 !isa<Constant>(I->getOperand(0))
516 ? I->getOperand(0)
517 : !isa<Constant>(I->getOperand(1)) ? I->getOperand(1) : nullptr;
Justin Bognera7300452015-12-14 23:22:44 +0000518 if (!IVOpnd)
519 return false;
520
521 // If increment operand is used outside of the loop, this speculation
522 // could cause extra live range interference.
523 if (MultiExitLoop) {
524 for (User *UseI : IVOpnd->users()) {
525 auto *UserInst = cast<Instruction>(UseI);
526 if (!L->contains(UserInst))
527 return false;
528 }
529 }
530
531 if (seenIncrement)
532 return false;
533 seenIncrement = true;
534 break;
535 }
536 case Instruction::Trunc:
537 case Instruction::ZExt:
538 case Instruction::SExt:
539 // ignore type conversions
540 break;
541 }
542 }
543 return true;
544}
545
546/// Fold the loop tail into the loop exit by speculating the loop tail
547/// instructions. Typically, this is a single post-increment. In the case of a
548/// simple 2-block loop, hoisting the increment can be much better than
549/// duplicating the entire loop header. In the case of loops with early exits,
550/// rotation will not work anyway, but simplifyLoopLatch will put the loop in
551/// canonical form so downstream passes can handle it.
552///
553/// I don't believe this invalidates SCEV.
Sebastian Popdfb66a12016-06-14 14:44:05 +0000554bool LoopRotate::simplifyLoopLatch(Loop *L) {
Justin Bognera7300452015-12-14 23:22:44 +0000555 BasicBlock *Latch = L->getLoopLatch();
556 if (!Latch || Latch->hasAddressTaken())
557 return false;
558
559 BranchInst *Jmp = dyn_cast<BranchInst>(Latch->getTerminator());
560 if (!Jmp || !Jmp->isUnconditional())
561 return false;
562
563 BasicBlock *LastExit = Latch->getSinglePredecessor();
564 if (!LastExit || !L->isLoopExiting(LastExit))
565 return false;
566
567 BranchInst *BI = dyn_cast<BranchInst>(LastExit->getTerminator());
568 if (!BI)
569 return false;
570
571 if (!shouldSpeculateInstrs(Latch->begin(), Jmp->getIterator(), L))
572 return false;
573
574 DEBUG(dbgs() << "Folding loop latch " << Latch->getName() << " into "
Sebastian Popdfb66a12016-06-14 14:44:05 +0000575 << LastExit->getName() << "\n");
Justin Bognera7300452015-12-14 23:22:44 +0000576
577 // Hoist the instructions from Latch into LastExit.
578 LastExit->getInstList().splice(BI->getIterator(), Latch->getInstList(),
579 Latch->begin(), Jmp->getIterator());
580
581 unsigned FallThruPath = BI->getSuccessor(0) == Latch ? 0 : 1;
582 BasicBlock *Header = Jmp->getSuccessor(0);
583 assert(Header == L->getHeader() && "expected a backward branch");
584
585 // Remove Latch from the CFG so that LastExit becomes the new Latch.
586 BI->setSuccessor(FallThruPath, Header);
587 Latch->replaceSuccessorsPhiUsesWith(LastExit);
588 Jmp->eraseFromParent();
589
590 // Nuke the Latch block.
591 assert(Latch->empty() && "unable to evacuate Latch");
592 LI->removeBlock(Latch);
593 if (DT)
594 DT->eraseNode(Latch);
595 Latch->eraseFromParent();
596 return true;
597}
598
Michael Zolotukhinb98294d2016-06-10 22:03:56 +0000599/// Rotate \c L, and return true if any modification was made.
Sebastian Popdfb66a12016-06-14 14:44:05 +0000600bool LoopRotate::processLoop(Loop *L) {
Justin Bognera7300452015-12-14 23:22:44 +0000601 // Save the loop metadata.
602 MDNode *LoopMD = L->getLoopID();
603
Justin Bognera7300452015-12-14 23:22:44 +0000604 // Simplify the loop latch before attempting to rotate the header
605 // upward. Rotation may not be needed if the loop tail can be folded into the
606 // loop exit.
Sebastian Popdfb66a12016-06-14 14:44:05 +0000607 bool SimplifiedLatch = simplifyLoopLatch(L);
Justin Bognera7300452015-12-14 23:22:44 +0000608
Sebastian Popdfb66a12016-06-14 14:44:05 +0000609 bool MadeChange = rotateLoop(L, SimplifiedLatch);
Michael Zolotukhinb98294d2016-06-10 22:03:56 +0000610 assert((!MadeChange || L->isLoopExiting(L->getLoopLatch())) &&
611 "Loop latch should be exiting after loop-rotate.");
Justin Bognera7300452015-12-14 23:22:44 +0000612
613 // Restore the loop metadata.
614 // NB! We presume LoopRotation DOESN'T ADD its own metadata.
615 if ((MadeChange || SimplifiedLatch) && LoopMD)
616 L->setLoopID(LoopMD);
617
618 return MadeChange;
619}
Justin Bogner6291b582015-12-14 23:22:48 +0000620
Sebastian Popdfb66a12016-06-14 14:44:05 +0000621LoopRotatePass::LoopRotatePass() {}
Justin Bognerd0d23412016-05-03 22:02:31 +0000622
Sean Silva0746f3b2016-08-09 00:28:52 +0000623PreservedAnalyses LoopRotatePass::run(Loop &L, LoopAnalysisManager &AM) {
Justin Bognerd0d23412016-05-03 22:02:31 +0000624 auto &FAM = AM.getResult<FunctionAnalysisManagerLoopProxy>(L).getManager();
625 Function *F = L.getHeader()->getParent();
626
627 auto *LI = FAM.getCachedResult<LoopAnalysis>(*F);
628 const auto *TTI = FAM.getCachedResult<TargetIRAnalysis>(*F);
629 auto *AC = FAM.getCachedResult<AssumptionAnalysis>(*F);
630 assert((LI && TTI && AC) && "Analyses for loop rotation not available");
631
632 // Optional analyses.
633 auto *DT = FAM.getCachedResult<DominatorTreeAnalysis>(*F);
634 auto *SE = FAM.getCachedResult<ScalarEvolutionAnalysis>(*F);
Sebastian Popdfb66a12016-06-14 14:44:05 +0000635 LoopRotate LR(DefaultRotationThreshold, LI, TTI, AC, DT, SE);
Justin Bognerd0d23412016-05-03 22:02:31 +0000636
Sebastian Popdfb66a12016-06-14 14:44:05 +0000637 bool Changed = LR.processLoop(&L);
Justin Bognerd0d23412016-05-03 22:02:31 +0000638 if (!Changed)
639 return PreservedAnalyses::all();
640 return getLoopPassPreservedAnalyses();
641}
642
Justin Bogner6291b582015-12-14 23:22:48 +0000643namespace {
644
Justin Bognerd0d23412016-05-03 22:02:31 +0000645class LoopRotateLegacyPass : public LoopPass {
Justin Bogner6291b582015-12-14 23:22:48 +0000646 unsigned MaxHeaderSize;
647
648public:
649 static char ID; // Pass ID, replacement for typeid
Justin Bognerd0d23412016-05-03 22:02:31 +0000650 LoopRotateLegacyPass(int SpecifiedMaxHeaderSize = -1) : LoopPass(ID) {
651 initializeLoopRotateLegacyPassPass(*PassRegistry::getPassRegistry());
Justin Bogner6291b582015-12-14 23:22:48 +0000652 if (SpecifiedMaxHeaderSize == -1)
653 MaxHeaderSize = DefaultRotationThreshold;
654 else
655 MaxHeaderSize = unsigned(SpecifiedMaxHeaderSize);
656 }
657
658 // LCSSA form makes instruction renaming easier.
659 void getAnalysisUsage(AnalysisUsage &AU) const override {
Justin Bogner6291b582015-12-14 23:22:48 +0000660 AU.addRequired<AssumptionCacheTracker>();
Justin Bogner6291b582015-12-14 23:22:48 +0000661 AU.addRequired<TargetTransformInfoWrapperPass>();
Chandler Carruth31088a92016-02-19 10:45:18 +0000662 getLoopAnalysisUsage(AU);
Justin Bogner6291b582015-12-14 23:22:48 +0000663 }
664
665 bool runOnLoop(Loop *L, LPPassManager &LPM) override {
Andrew Kayloraa641a52016-04-22 22:06:11 +0000666 if (skipLoop(L))
Justin Bogner6291b582015-12-14 23:22:48 +0000667 return false;
668 Function &F = *L->getHeader()->getParent();
669
670 auto *LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
671 const auto *TTI = &getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
672 auto *AC = &getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
673 auto *DTWP = getAnalysisIfAvailable<DominatorTreeWrapperPass>();
674 auto *DT = DTWP ? &DTWP->getDomTree() : nullptr;
675 auto *SEWP = getAnalysisIfAvailable<ScalarEvolutionWrapperPass>();
676 auto *SE = SEWP ? &SEWP->getSE() : nullptr;
Sebastian Popdfb66a12016-06-14 14:44:05 +0000677 LoopRotate LR(MaxHeaderSize, LI, TTI, AC, DT, SE);
678 return LR.processLoop(L);
Justin Bogner6291b582015-12-14 23:22:48 +0000679 }
680};
681}
682
Justin Bognerd0d23412016-05-03 22:02:31 +0000683char LoopRotateLegacyPass::ID = 0;
684INITIALIZE_PASS_BEGIN(LoopRotateLegacyPass, "loop-rotate", "Rotate Loops",
685 false, false)
Justin Bogner6291b582015-12-14 23:22:48 +0000686INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
Chandler Carruth31088a92016-02-19 10:45:18 +0000687INITIALIZE_PASS_DEPENDENCY(LoopPass)
688INITIALIZE_PASS_DEPENDENCY(TargetTransformInfoWrapperPass)
Sebastian Popdfb66a12016-06-14 14:44:05 +0000689INITIALIZE_PASS_END(LoopRotateLegacyPass, "loop-rotate", "Rotate Loops", false,
690 false)
Justin Bogner6291b582015-12-14 23:22:48 +0000691
692Pass *llvm::createLoopRotatePass(int MaxHeaderSize) {
Justin Bognerd0d23412016-05-03 22:02:31 +0000693 return new LoopRotateLegacyPass(MaxHeaderSize);
Justin Bogner6291b582015-12-14 23:22:48 +0000694}