blob: 3464b759280f6c7d911a42749c0046b5e7a1a70b [file] [log] [blame]
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +00001//===- MergedLoadStoreMotion.cpp - merge and hoist/sink load/stores -------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10//! \file
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000011//! This pass performs merges of loads and stores on both sides of a
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +000012// diamond (hammock). It hoists the loads and sinks the stores.
13//
14// The algorithm iteratively hoists two loads to the same address out of a
15// diamond (hammock) and merges them into a single load in the header. Similar
16// it sinks and merges two stores to the tail block (footer). The algorithm
17// iterates over the instructions of one side of the diamond and attempts to
18// find a matching load/store on the other side. It hoists / sinks when it
19// thinks it safe to do so. This optimization helps with eg. hiding load
20// latencies, triggering if-conversion, and reducing static code size.
21//
Daniel Berlin390dfde2017-01-24 19:55:36 +000022// NOTE: This code no longer performs load hoisting, it is subsumed by GVNHoist.
23//
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +000024//===----------------------------------------------------------------------===//
25//
26//
27// Example:
28// Diamond shaped code before merge:
29//
30// header:
31// br %cond, label %if.then, label %if.else
Gerolf Hoflehnerea96a3d2014-08-07 23:19:55 +000032// + +
33// + +
34// + +
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +000035// if.then: if.else:
36// %lt = load %addr_l %le = load %addr_l
37// <use %lt> <use %le>
38// <...> <...>
39// store %st, %addr_s store %se, %addr_s
40// br label %if.end br label %if.end
Gerolf Hoflehnerea96a3d2014-08-07 23:19:55 +000041// + +
42// + +
43// + +
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +000044// if.end ("footer"):
45// <...>
46//
47// Diamond shaped code after merge:
48//
49// header:
50// %l = load %addr_l
51// br %cond, label %if.then, label %if.else
Gerolf Hoflehnerea96a3d2014-08-07 23:19:55 +000052// + +
53// + +
54// + +
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +000055// if.then: if.else:
56// <use %l> <use %l>
57// <...> <...>
58// br label %if.end br label %if.end
Gerolf Hoflehnerea96a3d2014-08-07 23:19:55 +000059// + +
60// + +
61// + +
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +000062// if.end ("footer"):
63// %s.sink = phi [%st, if.then], [%se, if.else]
64// <...>
65// store %s.sink, %addr_s
66// <...>
67//
68//
69//===----------------------- TODO -----------------------------------------===//
70//
71// 1) Generalize to regions other than diamonds
72// 2) Be more aggressive merging memory operations
73// Note that both changes require register pressure control
74//
75//===----------------------------------------------------------------------===//
76
Davide Italianob49aa5c2016-06-17 19:10:09 +000077#include "llvm/Transforms/Scalar/MergedLoadStoreMotion.h"
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +000078#include "llvm/ADT/Statistic.h"
79#include "llvm/Analysis/AliasAnalysis.h"
80#include "llvm/Analysis/CFG.h"
Chandler Carruth7b560d42015-09-09 17:55:00 +000081#include "llvm/Analysis/GlobalsModRef.h"
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +000082#include "llvm/Analysis/Loads.h"
Eli Friedman9f8031c2016-06-12 02:11:20 +000083#include "llvm/Analysis/ValueTracking.h"
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +000084#include "llvm/IR/Metadata.h"
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +000085#include "llvm/Support/Debug.h"
Benjamin Kramerb85d3752015-03-23 18:45:56 +000086#include "llvm/Support/raw_ostream.h"
Mehdi Aminib550cb12016-04-18 09:17:29 +000087#include "llvm/Transforms/Scalar.h"
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +000088#include "llvm/Transforms/Utils/BasicBlockUtils.h"
Hans Wennborg083ca9b2015-10-06 23:24:35 +000089
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +000090using namespace llvm;
91
92#define DEBUG_TYPE "mldst-motion"
93
Benjamin Kramer4d098922016-07-10 11:28:51 +000094namespace {
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +000095//===----------------------------------------------------------------------===//
96// MergedLoadStoreMotion Pass
97//===----------------------------------------------------------------------===//
Davide Italianob49aa5c2016-06-17 19:10:09 +000098class MergedLoadStoreMotion {
Davide Italianob49aa5c2016-06-17 19:10:09 +000099 AliasAnalysis *AA = nullptr;
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000100
Davide Italianob49aa5c2016-06-17 19:10:09 +0000101 // The mergeLoad/Store algorithms could have Size0 * Size1 complexity,
102 // where Size0 and Size1 are the #instructions on the two sides of
103 // the diamond. The constant chosen here is arbitrary. Compiler Time
104 // Control is enforced by the check Size0 * Size1 < MagicCompileTimeControl.
105 const int MagicCompileTimeControl = 250;
Davide Italiano41315f72016-06-16 17:40:53 +0000106
107public:
Bjorn Steinbrink983d6c32018-02-23 10:41:57 +0000108 bool run(Function &F, AliasAnalysis &AA);
Davide Italiano41315f72016-06-16 17:40:53 +0000109
110private:
Davide Italiano41315f72016-06-16 17:40:53 +0000111 BasicBlock *getDiamondTail(BasicBlock *BB);
112 bool isDiamondHead(BasicBlock *BB);
Davide Italiano41315f72016-06-16 17:40:53 +0000113 // Routines for sinking stores
114 StoreInst *canSinkFromBlock(BasicBlock *BB, StoreInst *SI);
115 PHINode *getPHIOperand(BasicBlock *BB, StoreInst *S0, StoreInst *S1);
116 bool isStoreSinkBarrierInRange(const Instruction &Start,
117 const Instruction &End, MemoryLocation Loc);
118 bool sinkStore(BasicBlock *BB, StoreInst *SinkCand, StoreInst *ElseInst);
119 bool mergeStores(BasicBlock *BB);
Davide Italiano41315f72016-06-16 17:40:53 +0000120};
Benjamin Kramer4d098922016-07-10 11:28:51 +0000121} // end anonymous namespace
Davide Italiano41315f72016-06-16 17:40:53 +0000122
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000123///
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000124/// Return tail block of a diamond.
Davide Italiano41315f72016-06-16 17:40:53 +0000125///
126BasicBlock *MergedLoadStoreMotion::getDiamondTail(BasicBlock *BB) {
127 assert(isDiamondHead(BB) && "Basic block is not head of a diamond");
128 return BB->getTerminator()->getSuccessor(0)->getSingleSuccessor();
129}
130
131///
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000132/// True when BB is the head of a diamond (hammock)
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000133///
Davide Italiano41315f72016-06-16 17:40:53 +0000134bool MergedLoadStoreMotion::isDiamondHead(BasicBlock *BB) {
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000135 if (!BB)
136 return false;
David Majnemer8cce3332016-05-26 05:43:12 +0000137 auto *BI = dyn_cast<BranchInst>(BB->getTerminator());
138 if (!BI || !BI->isConditional())
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000139 return false;
140
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000141 BasicBlock *Succ0 = BI->getSuccessor(0);
142 BasicBlock *Succ1 = BI->getSuccessor(1);
143
David Majnemer8cce3332016-05-26 05:43:12 +0000144 if (!Succ0->getSinglePredecessor())
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000145 return false;
David Majnemer8cce3332016-05-26 05:43:12 +0000146 if (!Succ1->getSinglePredecessor())
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000147 return false;
148
David Majnemer8cce3332016-05-26 05:43:12 +0000149 BasicBlock *Succ0Succ = Succ0->getSingleSuccessor();
150 BasicBlock *Succ1Succ = Succ1->getSingleSuccessor();
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000151 // Ignore triangles.
David Majnemer8cce3332016-05-26 05:43:12 +0000152 if (!Succ0Succ || !Succ1Succ || Succ0Succ != Succ1Succ)
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000153 return false;
154 return true;
155}
156
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000157
158///
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000159/// True when instruction is a sink barrier for a store
Elena Demikhovskya5599bf2014-12-15 14:09:53 +0000160/// located in Loc
161///
162/// Whenever an instruction could possibly read or modify the
163/// value being stored or protect against the store from
164/// happening it is considered a sink barrier.
165///
Davide Italiano41315f72016-06-16 17:40:53 +0000166bool MergedLoadStoreMotion::isStoreSinkBarrierInRange(const Instruction &Start,
167 const Instruction &End,
168 MemoryLocation Loc) {
David Majnemer47451252016-05-26 07:11:09 +0000169 for (const Instruction &Inst :
170 make_range(Start.getIterator(), End.getIterator()))
171 if (Inst.mayThrow())
172 return true;
Alina Sbirlea193429f2017-12-07 22:41:34 +0000173 return AA->canInstructionRangeModRef(Start, End, Loc, ModRefInfo::ModRef);
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000174}
175
176///
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000177/// Check if \p BB contains a store to the same address as \p SI
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000178///
179/// \return The store in \p when it is safe to sink. Otherwise return Null.
180///
Davide Italiano41315f72016-06-16 17:40:53 +0000181StoreInst *MergedLoadStoreMotion::canSinkFromBlock(BasicBlock *BB1,
182 StoreInst *Store0) {
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000183 LLVM_DEBUG(dbgs() << "can Sink? : "; Store0->dump(); dbgs() << "\n");
Elena Demikhovskyef035bb2015-02-17 13:10:05 +0000184 BasicBlock *BB0 = Store0->getParent();
David Majnemerd7708772016-06-24 04:05:21 +0000185 for (Instruction &Inst : reverse(*BB1)) {
186 auto *Store1 = dyn_cast<StoreInst>(&Inst);
David Majnemer47451252016-05-26 07:11:09 +0000187 if (!Store1)
188 continue;
Elena Demikhovskya5599bf2014-12-15 14:09:53 +0000189
Chandler Carruthac80dc72015-06-17 07:18:54 +0000190 MemoryLocation Loc0 = MemoryLocation::get(Store0);
191 MemoryLocation Loc1 = MemoryLocation::get(Store1);
Elena Demikhovskya5599bf2014-12-15 14:09:53 +0000192 if (AA->isMustAlias(Loc0, Loc1) && Store0->isSameOperationAs(Store1) &&
Davide Italiano41315f72016-06-16 17:40:53 +0000193 !isStoreSinkBarrierInRange(*Store1->getNextNode(), BB1->back(), Loc1) &&
194 !isStoreSinkBarrierInRange(*Store0->getNextNode(), BB0->back(), Loc0)) {
Elena Demikhovskya5599bf2014-12-15 14:09:53 +0000195 return Store1;
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000196 }
197 }
Elena Demikhovskya5599bf2014-12-15 14:09:53 +0000198 return nullptr;
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000199}
200
201///
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000202/// Create a PHI node in BB for the operands of S0 and S1
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000203///
Davide Italiano41315f72016-06-16 17:40:53 +0000204PHINode *MergedLoadStoreMotion::getPHIOperand(BasicBlock *BB, StoreInst *S0,
205 StoreInst *S1) {
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000206 // Create a phi if the values mismatch.
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000207 Value *Opd1 = S0->getValueOperand();
208 Value *Opd2 = S1->getValueOperand();
David Majnemer8cce3332016-05-26 05:43:12 +0000209 if (Opd1 == Opd2)
210 return nullptr;
211
212 auto *NewPN = PHINode::Create(Opd1->getType(), 2, Opd2->getName() + ".sink",
213 &BB->front());
214 NewPN->addIncoming(Opd1, S0->getParent());
215 NewPN->addIncoming(Opd2, S1->getParent());
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000216 return NewPN;
217}
218
219///
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000220/// Merge two stores to same address and sink into \p BB
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000221///
222/// Also sinks GEP instruction computing the store address
223///
Davide Italiano41315f72016-06-16 17:40:53 +0000224bool MergedLoadStoreMotion::sinkStore(BasicBlock *BB, StoreInst *S0,
225 StoreInst *S1) {
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000226 // Only one definition?
David Majnemer8cce3332016-05-26 05:43:12 +0000227 auto *A0 = dyn_cast<Instruction>(S0->getPointerOperand());
228 auto *A1 = dyn_cast<Instruction>(S1->getPointerOperand());
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000229 if (A0 && A1 && A0->isIdenticalTo(A1) && A0->hasOneUse() &&
230 (A0->getParent() == S0->getParent()) && A1->hasOneUse() &&
231 (A1->getParent() == S1->getParent()) && isa<GetElementPtrInst>(A0)) {
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000232 LLVM_DEBUG(dbgs() << "Sink Instruction into BB \n"; BB->dump();
233 dbgs() << "Instruction Left\n"; S0->dump(); dbgs() << "\n";
234 dbgs() << "Instruction Right\n"; S1->dump(); dbgs() << "\n");
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000235 // Hoist the instruction.
236 BasicBlock::iterator InsertPt = BB->getFirstInsertionPt();
237 // Intersect optional metadata.
Peter Collingbourne8f1dd5c2016-09-07 23:39:04 +0000238 S0->andIRFlags(S1);
Adrian Prantlcbdfdb72015-08-20 22:00:30 +0000239 S0->dropUnknownNonDebugMetadata();
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000240
241 // Create the new store to be inserted at the join point.
David Majnemer8cce3332016-05-26 05:43:12 +0000242 StoreInst *SNew = cast<StoreInst>(S0->clone());
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000243 Instruction *ANew = A0->clone();
Duncan P. N. Exon Smithbe4d8cb2015-10-13 19:26:58 +0000244 SNew->insertBefore(&*InsertPt);
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000245 ANew->insertBefore(SNew);
246
247 assert(S0->getParent() == A0->getParent());
248 assert(S1->getParent() == A1->getParent());
249
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000250 // New PHI operand? Use it.
Davide Italiano41315f72016-06-16 17:40:53 +0000251 if (PHINode *NewPN = getPHIOperand(BB, S0, S1))
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000252 SNew->setOperand(0, NewPN);
Bjorn Steinbrink983d6c32018-02-23 10:41:57 +0000253 S0->eraseFromParent();
254 S1->eraseFromParent();
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000255 A0->replaceAllUsesWith(ANew);
Bjorn Steinbrink983d6c32018-02-23 10:41:57 +0000256 A0->eraseFromParent();
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000257 A1->replaceAllUsesWith(ANew);
Bjorn Steinbrink983d6c32018-02-23 10:41:57 +0000258 A1->eraseFromParent();
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000259 return true;
260 }
261 return false;
262}
263
264///
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000265/// True when two stores are equivalent and can sink into the footer
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000266///
267/// Starting from a diamond tail block, iterate over the instructions in one
268/// predecessor block and try to match a store in the second predecessor.
269///
Davide Italiano41315f72016-06-16 17:40:53 +0000270bool MergedLoadStoreMotion::mergeStores(BasicBlock *T) {
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000271
272 bool MergedStores = false;
273 assert(T && "Footer of a diamond cannot be empty");
274
275 pred_iterator PI = pred_begin(T), E = pred_end(T);
276 assert(PI != E);
277 BasicBlock *Pred0 = *PI;
278 ++PI;
279 BasicBlock *Pred1 = *PI;
280 ++PI;
281 // tail block of a diamond/hammock?
282 if (Pred0 == Pred1)
283 return false; // No.
284 if (PI != E)
285 return false; // No. More than 2 predecessors.
286
287 // #Instructions in Succ1 for Compile Time Control
Vedant Kumar5a0872c2018-05-16 23:20:42 +0000288 auto InstsNoDbg = Pred1->instructionsWithoutDebug();
289 int Size1 = std::distance(InstsNoDbg.begin(), InstsNoDbg.end());
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000290 int NStores = 0;
291
292 for (BasicBlock::reverse_iterator RBI = Pred0->rbegin(), RBE = Pred0->rend();
293 RBI != RBE;) {
294
295 Instruction *I = &*RBI;
296 ++RBI;
Elena Demikhovskya5599bf2014-12-15 14:09:53 +0000297
David Majnemer8cce3332016-05-26 05:43:12 +0000298 // Don't sink non-simple (atomic, volatile) stores.
299 auto *S0 = dyn_cast<StoreInst>(I);
300 if (!S0 || !S0->isSimple())
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000301 continue;
302
303 ++NStores;
304 if (NStores * Size1 >= MagicCompileTimeControl)
305 break;
Davide Italiano41315f72016-06-16 17:40:53 +0000306 if (StoreInst *S1 = canSinkFromBlock(Pred1, S0)) {
307 bool Res = sinkStore(T, S0, S1);
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000308 MergedStores |= Res;
309 // Don't attempt to sink below stores that had to stick around
310 // But after removal of a store and some of its feeding
311 // instruction search again from the beginning since the iterator
312 // is likely stale at this point.
313 if (!Res)
314 break;
David Majnemer8cce3332016-05-26 05:43:12 +0000315 RBI = Pred0->rbegin();
316 RBE = Pred0->rend();
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000317 LLVM_DEBUG(dbgs() << "Search again\n"; Instruction *I = &*RBI; I->dump());
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000318 }
319 }
320 return MergedStores;
321}
Hans Wennborg083ca9b2015-10-06 23:24:35 +0000322
Bjorn Steinbrink983d6c32018-02-23 10:41:57 +0000323bool MergedLoadStoreMotion::run(Function &F, AliasAnalysis &AA) {
Davide Italianob49aa5c2016-06-17 19:10:09 +0000324 this->AA = &AA;
Davide Italiano41315f72016-06-16 17:40:53 +0000325
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000326 bool Changed = false;
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000327 LLVM_DEBUG(dbgs() << "Instruction Merger\n");
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000328
329 // Merge unconditional branches, allowing PRE to catch more
330 // optimization opportunities.
331 for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE;) {
Duncan P. N. Exon Smithbe4d8cb2015-10-13 19:26:58 +0000332 BasicBlock *BB = &*FI++;
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000333
334 // Hoist equivalent loads and sink stores
335 // outside diamonds when possible
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000336 if (isDiamondHead(BB)) {
Davide Italiano41315f72016-06-16 17:40:53 +0000337 Changed |= mergeStores(getDiamondTail(BB));
Gerolf Hoflehnerf27ae6c2014-07-18 19:13:09 +0000338 }
339 }
340 return Changed;
341}
Davide Italianob49aa5c2016-06-17 19:10:09 +0000342
343namespace {
344class MergedLoadStoreMotionLegacyPass : public FunctionPass {
345public:
346 static char ID; // Pass identification, replacement for typeid
347 MergedLoadStoreMotionLegacyPass() : FunctionPass(ID) {
348 initializeMergedLoadStoreMotionLegacyPassPass(
349 *PassRegistry::getPassRegistry());
350 }
351
352 ///
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000353 /// Run the transformation for each function
Davide Italianob49aa5c2016-06-17 19:10:09 +0000354 ///
355 bool runOnFunction(Function &F) override {
356 if (skipFunction(F))
357 return false;
358 MergedLoadStoreMotion Impl;
Bjorn Steinbrink983d6c32018-02-23 10:41:57 +0000359 return Impl.run(F, getAnalysis<AAResultsWrapperPass>().getAAResults());
Davide Italianob49aa5c2016-06-17 19:10:09 +0000360 }
361
362private:
Davide Italianob49aa5c2016-06-17 19:10:09 +0000363 void getAnalysisUsage(AnalysisUsage &AU) const override {
364 AU.setPreservesCFG();
365 AU.addRequired<AAResultsWrapperPass>();
366 AU.addPreserved<GlobalsAAWrapperPass>();
Davide Italianob49aa5c2016-06-17 19:10:09 +0000367 }
368};
369
370char MergedLoadStoreMotionLegacyPass::ID = 0;
371} // anonymous namespace
372
373///
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000374/// createMergedLoadStoreMotionPass - The public interface to this file.
Davide Italianob49aa5c2016-06-17 19:10:09 +0000375///
376FunctionPass *llvm::createMergedLoadStoreMotionPass() {
377 return new MergedLoadStoreMotionLegacyPass();
378}
379
380INITIALIZE_PASS_BEGIN(MergedLoadStoreMotionLegacyPass, "mldst-motion",
381 "MergedLoadStoreMotion", false, false)
Davide Italianob49aa5c2016-06-17 19:10:09 +0000382INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
383INITIALIZE_PASS_END(MergedLoadStoreMotionLegacyPass, "mldst-motion",
384 "MergedLoadStoreMotion", false, false)
385
386PreservedAnalyses
Sean Silva36e0d012016-08-09 00:28:15 +0000387MergedLoadStoreMotionPass::run(Function &F, FunctionAnalysisManager &AM) {
Davide Italianob49aa5c2016-06-17 19:10:09 +0000388 MergedLoadStoreMotion Impl;
Davide Italianob49aa5c2016-06-17 19:10:09 +0000389 auto &AA = AM.getResult<AAManager>(F);
Bjorn Steinbrink983d6c32018-02-23 10:41:57 +0000390 if (!Impl.run(F, AA))
Davide Italianob49aa5c2016-06-17 19:10:09 +0000391 return PreservedAnalyses::all();
392
Davide Italianob49aa5c2016-06-17 19:10:09 +0000393 PreservedAnalyses PA;
Chandler Carruthca68a3e2017-01-15 06:32:49 +0000394 PA.preserveSet<CFGAnalyses>();
Davide Italianob49aa5c2016-06-17 19:10:09 +0000395 PA.preserve<GlobalsAA>();
Davide Italianob49aa5c2016-06-17 19:10:09 +0000396 return PA;
397}