LLVM  4.0.0
MergedLoadStoreMotion.cpp
Go to the documentation of this file.
1 //===- 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
11 //! \brief This pass performs merges of loads and stores on both sides of a
12 // 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 //
22 //===----------------------------------------------------------------------===//
23 //
24 //
25 // Example:
26 // Diamond shaped code before merge:
27 //
28 // header:
29 // br %cond, label %if.then, label %if.else
30 // + +
31 // + +
32 // + +
33 // if.then: if.else:
34 // %lt = load %addr_l %le = load %addr_l
35 // <use %lt> <use %le>
36 // <...> <...>
37 // store %st, %addr_s store %se, %addr_s
38 // br label %if.end br label %if.end
39 // + +
40 // + +
41 // + +
42 // if.end ("footer"):
43 // <...>
44 //
45 // Diamond shaped code after merge:
46 //
47 // header:
48 // %l = load %addr_l
49 // br %cond, label %if.then, label %if.else
50 // + +
51 // + +
52 // + +
53 // if.then: if.else:
54 // <use %l> <use %l>
55 // <...> <...>
56 // br label %if.end br label %if.end
57 // + +
58 // + +
59 // + +
60 // if.end ("footer"):
61 // %s.sink = phi [%st, if.then], [%se, if.else]
62 // <...>
63 // store %s.sink, %addr_s
64 // <...>
65 //
66 //
67 //===----------------------- TODO -----------------------------------------===//
68 //
69 // 1) Generalize to regions other than diamonds
70 // 2) Be more aggressive merging memory operations
71 // Note that both changes require register pressure control
72 //
73 //===----------------------------------------------------------------------===//
74 
76 #include "llvm/ADT/Statistic.h"
78 #include "llvm/Analysis/CFG.h"
80 #include "llvm/Analysis/Loads.h"
84 #include "llvm/IR/Metadata.h"
85 #include "llvm/IR/PatternMatch.h"
86 #include "llvm/Support/Debug.h"
88 #include "llvm/Transforms/Scalar.h"
91 
92 using namespace llvm;
93 
94 #define DEBUG_TYPE "mldst-motion"
95 
96 namespace {
97 //===----------------------------------------------------------------------===//
98 // MergedLoadStoreMotion Pass
99 //===----------------------------------------------------------------------===//
100 class MergedLoadStoreMotion {
101  MemoryDependenceResults *MD = nullptr;
102  AliasAnalysis *AA = nullptr;
103 
104  // The mergeLoad/Store algorithms could have Size0 * Size1 complexity,
105  // where Size0 and Size1 are the #instructions on the two sides of
106  // the diamond. The constant chosen here is arbitrary. Compiler Time
107  // Control is enforced by the check Size0 * Size1 < MagicCompileTimeControl.
108  const int MagicCompileTimeControl = 250;
109 
110 public:
111  bool run(Function &F, MemoryDependenceResults *MD, AliasAnalysis &AA);
112 
113 private:
114  ///
115  /// \brief Remove instruction from parent and update memory dependence
116  /// analysis.
117  ///
118  void removeInstruction(Instruction *Inst);
119  BasicBlock *getDiamondTail(BasicBlock *BB);
120  bool isDiamondHead(BasicBlock *BB);
121  // Routines for hoisting loads
122  bool isLoadHoistBarrierInRange(const Instruction &Start,
123  const Instruction &End, LoadInst *LI,
124  bool SafeToLoadUnconditionally);
125  LoadInst *canHoistFromBlock(BasicBlock *BB, LoadInst *LI);
126  void hoistInstruction(BasicBlock *BB, Instruction *HoistCand,
127  Instruction *ElseInst);
128  bool isSafeToHoist(Instruction *I) const;
129  bool hoistLoad(BasicBlock *BB, LoadInst *HoistCand, LoadInst *ElseInst);
130  bool mergeLoads(BasicBlock *BB);
131  // Routines for sinking stores
132  StoreInst *canSinkFromBlock(BasicBlock *BB, StoreInst *SI);
133  PHINode *getPHIOperand(BasicBlock *BB, StoreInst *S0, StoreInst *S1);
134  bool isStoreSinkBarrierInRange(const Instruction &Start,
135  const Instruction &End, MemoryLocation Loc);
136  bool sinkStore(BasicBlock *BB, StoreInst *SinkCand, StoreInst *ElseInst);
137  bool mergeStores(BasicBlock *BB);
138 };
139 } // end anonymous namespace
140 
141 ///
142 /// \brief Remove instruction from parent and update memory dependence analysis.
143 ///
144 void MergedLoadStoreMotion::removeInstruction(Instruction *Inst) {
145  // Notify the memory dependence analysis.
146  if (MD) {
147  MD->removeInstruction(Inst);
148  if (auto *LI = dyn_cast<LoadInst>(Inst))
149  MD->invalidateCachedPointerInfo(LI->getPointerOperand());
150  if (Inst->getType()->isPtrOrPtrVectorTy()) {
151  MD->invalidateCachedPointerInfo(Inst);
152  }
153  }
154  Inst->eraseFromParent();
155 }
156 
157 ///
158 /// \brief Return tail block of a diamond.
159 ///
160 BasicBlock *MergedLoadStoreMotion::getDiamondTail(BasicBlock *BB) {
161  assert(isDiamondHead(BB) && "Basic block is not head of a diamond");
162  return BB->getTerminator()->getSuccessor(0)->getSingleSuccessor();
163 }
164 
165 ///
166 /// \brief True when BB is the head of a diamond (hammock)
167 ///
168 bool MergedLoadStoreMotion::isDiamondHead(BasicBlock *BB) {
169  if (!BB)
170  return false;
171  auto *BI = dyn_cast<BranchInst>(BB->getTerminator());
172  if (!BI || !BI->isConditional())
173  return false;
174 
175  BasicBlock *Succ0 = BI->getSuccessor(0);
176  BasicBlock *Succ1 = BI->getSuccessor(1);
177 
178  if (!Succ0->getSinglePredecessor())
179  return false;
180  if (!Succ1->getSinglePredecessor())
181  return false;
182 
183  BasicBlock *Succ0Succ = Succ0->getSingleSuccessor();
184  BasicBlock *Succ1Succ = Succ1->getSingleSuccessor();
185  // Ignore triangles.
186  if (!Succ0Succ || !Succ1Succ || Succ0Succ != Succ1Succ)
187  return false;
188  return true;
189 }
190 
191 ///
192 /// \brief True when instruction is a hoist barrier for a load
193 ///
194 /// Whenever an instruction could possibly modify the value
195 /// being loaded or protect against the load from happening
196 /// it is considered a hoist barrier.
197 ///
198 bool MergedLoadStoreMotion::isLoadHoistBarrierInRange(
199  const Instruction &Start, const Instruction &End, LoadInst *LI,
200  bool SafeToLoadUnconditionally) {
201  if (!SafeToLoadUnconditionally)
202  for (const Instruction &Inst :
203  make_range(Start.getIterator(), End.getIterator()))
205  return true;
207  return AA->canInstructionRangeModRef(Start, End, Loc, MRI_Mod);
208 }
209 
210 ///
211 /// \brief Decide if a load can be hoisted
212 ///
213 /// When there is a load in \p BB to the same address as \p LI
214 /// and it can be hoisted from \p BB, return that load.
215 /// Otherwise return Null.
216 ///
217 LoadInst *MergedLoadStoreMotion::canHoistFromBlock(BasicBlock *BB1,
218  LoadInst *Load0) {
219  BasicBlock *BB0 = Load0->getParent();
220  BasicBlock *Head = BB0->getSinglePredecessor();
221  bool SafeToLoadUnconditionally = isSafeToLoadUnconditionally(
222  Load0->getPointerOperand(), Load0->getAlignment(),
223  Load0->getModule()->getDataLayout(),
224  /*ScanFrom=*/Head->getTerminator());
225  for (BasicBlock::iterator BBI = BB1->begin(), BBE = BB1->end(); BBI != BBE;
226  ++BBI) {
227  Instruction *Inst = &*BBI;
228 
229  // Only merge and hoist loads when their result in used only in BB
230  auto *Load1 = dyn_cast<LoadInst>(Inst);
231  if (!Load1 || Inst->isUsedOutsideOfBlock(BB1))
232  continue;
233 
234  MemoryLocation Loc0 = MemoryLocation::get(Load0);
235  MemoryLocation Loc1 = MemoryLocation::get(Load1);
236  if (Load0->isSameOperationAs(Load1) && AA->isMustAlias(Loc0, Loc1) &&
237  !isLoadHoistBarrierInRange(BB1->front(), *Load1, Load1,
238  SafeToLoadUnconditionally) &&
239  !isLoadHoistBarrierInRange(BB0->front(), *Load0, Load0,
240  SafeToLoadUnconditionally)) {
241  return Load1;
242  }
243  }
244  return nullptr;
245 }
246 
247 ///
248 /// \brief Merge two equivalent instructions \p HoistCand and \p ElseInst into
249 /// \p BB
250 ///
251 /// BB is the head of a diamond
252 ///
253 void MergedLoadStoreMotion::hoistInstruction(BasicBlock *BB,
254  Instruction *HoistCand,
255  Instruction *ElseInst) {
256  DEBUG(dbgs() << " Hoist Instruction into BB \n"; BB->dump();
257  dbgs() << "Instruction Left\n"; HoistCand->dump(); dbgs() << "\n";
258  dbgs() << "Instruction Right\n"; ElseInst->dump(); dbgs() << "\n");
259  // Hoist the instruction.
260  assert(HoistCand->getParent() != BB);
261 
262  // Intersect optional metadata.
263  HoistCand->andIRFlags(ElseInst);
264  HoistCand->dropUnknownNonDebugMetadata();
265 
266  // Prepend point for instruction insert
267  Instruction *HoistPt = BB->getTerminator();
268 
269  // Merged instruction
270  Instruction *HoistedInst = HoistCand->clone();
271 
272  // Hoist instruction.
273  HoistedInst->insertBefore(HoistPt);
274 
275  HoistCand->replaceAllUsesWith(HoistedInst);
276  removeInstruction(HoistCand);
277  // Replace the else block instruction.
278  ElseInst->replaceAllUsesWith(HoistedInst);
279  removeInstruction(ElseInst);
280 }
281 
282 ///
283 /// \brief Return true if no operand of \p I is defined in I's parent block
284 ///
285 bool MergedLoadStoreMotion::isSafeToHoist(Instruction *I) const {
286  BasicBlock *Parent = I->getParent();
287  for (Use &U : I->operands())
288  if (auto *Instr = dyn_cast<Instruction>(&U))
289  if (Instr->getParent() == Parent)
290  return false;
291  return true;
292 }
293 
294 ///
295 /// \brief Merge two equivalent loads and GEPs and hoist into diamond head
296 ///
297 bool MergedLoadStoreMotion::hoistLoad(BasicBlock *BB, LoadInst *L0,
298  LoadInst *L1) {
299  // Only one definition?
300  auto *A0 = dyn_cast<Instruction>(L0->getPointerOperand());
301  auto *A1 = dyn_cast<Instruction>(L1->getPointerOperand());
302  if (A0 && A1 && A0->isIdenticalTo(A1) && isSafeToHoist(A0) &&
303  A0->hasOneUse() && (A0->getParent() == L0->getParent()) &&
304  A1->hasOneUse() && (A1->getParent() == L1->getParent()) &&
305  isa<GetElementPtrInst>(A0)) {
306  DEBUG(dbgs() << "Hoist Instruction into BB \n"; BB->dump();
307  dbgs() << "Instruction Left\n"; L0->dump(); dbgs() << "\n";
308  dbgs() << "Instruction Right\n"; L1->dump(); dbgs() << "\n");
309  hoistInstruction(BB, A0, A1);
310  hoistInstruction(BB, L0, L1);
311  return true;
312  }
313  return false;
314 }
315 
316 ///
317 /// \brief Try to hoist two loads to same address into diamond header
318 ///
319 /// Starting from a diamond head block, iterate over the instructions in one
320 /// successor block and try to match a load in the second successor.
321 ///
322 bool MergedLoadStoreMotion::mergeLoads(BasicBlock *BB) {
323  bool MergedLoads = false;
324  assert(isDiamondHead(BB));
325  BranchInst *BI = cast<BranchInst>(BB->getTerminator());
326  BasicBlock *Succ0 = BI->getSuccessor(0);
327  BasicBlock *Succ1 = BI->getSuccessor(1);
328  // #Instructions in Succ1 for Compile Time Control
329  int Size1 = Succ1->size();
330  int NLoads = 0;
331  for (BasicBlock::iterator BBI = Succ0->begin(), BBE = Succ0->end();
332  BBI != BBE;) {
333  Instruction *I = &*BBI;
334  ++BBI;
335 
336  // Don't move non-simple (atomic, volatile) loads.
337  auto *L0 = dyn_cast<LoadInst>(I);
338  if (!L0 || !L0->isSimple() || L0->isUsedOutsideOfBlock(Succ0))
339  continue;
340 
341  ++NLoads;
342  if (NLoads * Size1 >= MagicCompileTimeControl)
343  break;
344  if (LoadInst *L1 = canHoistFromBlock(Succ1, L0)) {
345  bool Res = hoistLoad(BB, L0, L1);
346  MergedLoads |= Res;
347  // Don't attempt to hoist above loads that had not been hoisted.
348  if (!Res)
349  break;
350  }
351  }
352  return MergedLoads;
353 }
354 
355 ///
356 /// \brief True when instruction is a sink barrier for a store
357 /// located in Loc
358 ///
359 /// Whenever an instruction could possibly read or modify the
360 /// value being stored or protect against the store from
361 /// happening it is considered a sink barrier.
362 ///
363 bool MergedLoadStoreMotion::isStoreSinkBarrierInRange(const Instruction &Start,
364  const Instruction &End,
365  MemoryLocation Loc) {
366  for (const Instruction &Inst :
367  make_range(Start.getIterator(), End.getIterator()))
368  if (Inst.mayThrow())
369  return true;
370  return AA->canInstructionRangeModRef(Start, End, Loc, MRI_ModRef);
371 }
372 
373 ///
374 /// \brief Check if \p BB contains a store to the same address as \p SI
375 ///
376 /// \return The store in \p when it is safe to sink. Otherwise return Null.
377 ///
378 StoreInst *MergedLoadStoreMotion::canSinkFromBlock(BasicBlock *BB1,
379  StoreInst *Store0) {
380  DEBUG(dbgs() << "can Sink? : "; Store0->dump(); dbgs() << "\n");
381  BasicBlock *BB0 = Store0->getParent();
382  for (Instruction &Inst : reverse(*BB1)) {
383  auto *Store1 = dyn_cast<StoreInst>(&Inst);
384  if (!Store1)
385  continue;
386 
387  MemoryLocation Loc0 = MemoryLocation::get(Store0);
388  MemoryLocation Loc1 = MemoryLocation::get(Store1);
389  if (AA->isMustAlias(Loc0, Loc1) && Store0->isSameOperationAs(Store1) &&
390  !isStoreSinkBarrierInRange(*Store1->getNextNode(), BB1->back(), Loc1) &&
391  !isStoreSinkBarrierInRange(*Store0->getNextNode(), BB0->back(), Loc0)) {
392  return Store1;
393  }
394  }
395  return nullptr;
396 }
397 
398 ///
399 /// \brief Create a PHI node in BB for the operands of S0 and S1
400 ///
401 PHINode *MergedLoadStoreMotion::getPHIOperand(BasicBlock *BB, StoreInst *S0,
402  StoreInst *S1) {
403  // Create a phi if the values mismatch.
404  Value *Opd1 = S0->getValueOperand();
405  Value *Opd2 = S1->getValueOperand();
406  if (Opd1 == Opd2)
407  return nullptr;
408 
409  auto *NewPN = PHINode::Create(Opd1->getType(), 2, Opd2->getName() + ".sink",
410  &BB->front());
411  NewPN->addIncoming(Opd1, S0->getParent());
412  NewPN->addIncoming(Opd2, S1->getParent());
413  if (MD && NewPN->getType()->getScalarType()->isPointerTy())
414  MD->invalidateCachedPointerInfo(NewPN);
415  return NewPN;
416 }
417 
418 ///
419 /// \brief Merge two stores to same address and sink into \p BB
420 ///
421 /// Also sinks GEP instruction computing the store address
422 ///
423 bool MergedLoadStoreMotion::sinkStore(BasicBlock *BB, StoreInst *S0,
424  StoreInst *S1) {
425  // Only one definition?
426  auto *A0 = dyn_cast<Instruction>(S0->getPointerOperand());
427  auto *A1 = dyn_cast<Instruction>(S1->getPointerOperand());
428  if (A0 && A1 && A0->isIdenticalTo(A1) && A0->hasOneUse() &&
429  (A0->getParent() == S0->getParent()) && A1->hasOneUse() &&
430  (A1->getParent() == S1->getParent()) && isa<GetElementPtrInst>(A0)) {
431  DEBUG(dbgs() << "Sink Instruction into BB \n"; BB->dump();
432  dbgs() << "Instruction Left\n"; S0->dump(); dbgs() << "\n";
433  dbgs() << "Instruction Right\n"; S1->dump(); dbgs() << "\n");
434  // Hoist the instruction.
435  BasicBlock::iterator InsertPt = BB->getFirstInsertionPt();
436  // Intersect optional metadata.
437  S0->andIRFlags(S1);
439 
440  // Create the new store to be inserted at the join point.
441  StoreInst *SNew = cast<StoreInst>(S0->clone());
442  Instruction *ANew = A0->clone();
443  SNew->insertBefore(&*InsertPt);
444  ANew->insertBefore(SNew);
445 
446  assert(S0->getParent() == A0->getParent());
447  assert(S1->getParent() == A1->getParent());
448 
449  // New PHI operand? Use it.
450  if (PHINode *NewPN = getPHIOperand(BB, S0, S1))
451  SNew->setOperand(0, NewPN);
452  removeInstruction(S0);
453  removeInstruction(S1);
454  A0->replaceAllUsesWith(ANew);
455  removeInstruction(A0);
456  A1->replaceAllUsesWith(ANew);
457  removeInstruction(A1);
458  return true;
459  }
460  return false;
461 }
462 
463 ///
464 /// \brief True when two stores are equivalent and can sink into the footer
465 ///
466 /// Starting from a diamond tail block, iterate over the instructions in one
467 /// predecessor block and try to match a store in the second predecessor.
468 ///
469 bool MergedLoadStoreMotion::mergeStores(BasicBlock *T) {
470 
471  bool MergedStores = false;
472  assert(T && "Footer of a diamond cannot be empty");
473 
474  pred_iterator PI = pred_begin(T), E = pred_end(T);
475  assert(PI != E);
476  BasicBlock *Pred0 = *PI;
477  ++PI;
478  BasicBlock *Pred1 = *PI;
479  ++PI;
480  // tail block of a diamond/hammock?
481  if (Pred0 == Pred1)
482  return false; // No.
483  if (PI != E)
484  return false; // No. More than 2 predecessors.
485 
486  // #Instructions in Succ1 for Compile Time Control
487  int Size1 = Pred1->size();
488  int NStores = 0;
489 
490  for (BasicBlock::reverse_iterator RBI = Pred0->rbegin(), RBE = Pred0->rend();
491  RBI != RBE;) {
492 
493  Instruction *I = &*RBI;
494  ++RBI;
495 
496  // Don't sink non-simple (atomic, volatile) stores.
497  auto *S0 = dyn_cast<StoreInst>(I);
498  if (!S0 || !S0->isSimple())
499  continue;
500 
501  ++NStores;
502  if (NStores * Size1 >= MagicCompileTimeControl)
503  break;
504  if (StoreInst *S1 = canSinkFromBlock(Pred1, S0)) {
505  bool Res = sinkStore(T, S0, S1);
506  MergedStores |= Res;
507  // Don't attempt to sink below stores that had to stick around
508  // But after removal of a store and some of its feeding
509  // instruction search again from the beginning since the iterator
510  // is likely stale at this point.
511  if (!Res)
512  break;
513  RBI = Pred0->rbegin();
514  RBE = Pred0->rend();
515  DEBUG(dbgs() << "Search again\n"; Instruction *I = &*RBI; I->dump());
516  }
517  }
518  return MergedStores;
519 }
520 
521 bool MergedLoadStoreMotion::run(Function &F, MemoryDependenceResults *MD,
522  AliasAnalysis &AA) {
523  this->MD = MD;
524  this->AA = &AA;
525 
526  bool Changed = false;
527  DEBUG(dbgs() << "Instruction Merger\n");
528 
529  // Merge unconditional branches, allowing PRE to catch more
530  // optimization opportunities.
531  for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE;) {
532  BasicBlock *BB = &*FI++;
533 
534  // Hoist equivalent loads and sink stores
535  // outside diamonds when possible
536  if (isDiamondHead(BB)) {
537  Changed |= mergeLoads(BB);
538  Changed |= mergeStores(getDiamondTail(BB));
539  }
540  }
541  return Changed;
542 }
543 
544 namespace {
545 class MergedLoadStoreMotionLegacyPass : public FunctionPass {
546 public:
547  static char ID; // Pass identification, replacement for typeid
548  MergedLoadStoreMotionLegacyPass() : FunctionPass(ID) {
551  }
552 
553  ///
554  /// \brief Run the transformation for each function
555  ///
556  bool runOnFunction(Function &F) override {
557  if (skipFunction(F))
558  return false;
560  auto *MDWP = getAnalysisIfAvailable<MemoryDependenceWrapperPass>();
561  return Impl.run(F, MDWP ? &MDWP->getMemDep() : nullptr,
562  getAnalysis<AAResultsWrapperPass>().getAAResults());
563  }
564 
565 private:
566  void getAnalysisUsage(AnalysisUsage &AU) const override {
567  AU.setPreservesCFG();
571  }
572 };
573 
575 } // anonymous namespace
576 
577 ///
578 /// \brief createMergedLoadStoreMotionPass - The public interface to this file.
579 ///
581  return new MergedLoadStoreMotionLegacyPass();
582 }
583 
584 INITIALIZE_PASS_BEGIN(MergedLoadStoreMotionLegacyPass, "mldst-motion",
585  "MergedLoadStoreMotion", false, false)
588 INITIALIZE_PASS_END(MergedLoadStoreMotionLegacyPass, "mldst-motion",
589  "MergedLoadStoreMotion", false, false)
590 
593  MergedLoadStoreMotion Impl;
594  auto *MD = AM.getCachedResult<MemoryDependenceAnalysis>(F);
595  auto &AA = AM.getResult<AAManager>(F);
596  if (!Impl.run(F, MD, AA))
597  return PreservedAnalyses::all();
598 
599  // FIXME: This should also 'preserve the CFG'.
601  PA.preserve<GlobalsAA>();
603  return PA;
604 }
Legacy wrapper pass to provide the GlobalsAAResult object.
Value * getValueOperand()
Definition: Instructions.h:391
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
Definition: Instruction.cpp:76
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
Provides a lazy, caching interface for making common memory aliasing information queries, backed by LLVM's alias analysis passes.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
const Instruction & back() const
Definition: BasicBlock.h:242
NodeTy * getNextNode()
Get the next node, or nullptr for the list tail.
Definition: ilist_node.h:274
This is the interface for a simple mod/ref and alias analysis over globals.
void dropUnknownNonDebugMetadata(ArrayRef< unsigned > KnownIDs)
Drop all unknown metadata except for debug locations.
Definition: Metadata.cpp:1156
iterator end()
Definition: Function.h:537
bool isSimple() const
Definition: Instructions.h:384
This file contains the declarations for metadata subclasses.
bool isUsedOutsideOfBlock(const BasicBlock *BB) const
Return true if there are any uses of this instruction in blocks other than the specified block...
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
Definition: Type.h:216
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:100
const Instruction & front() const
Definition: BasicBlock.h:240
reverse_iterator rend()
Definition: BasicBlock.h:235
An instruction for reading from memory.
Definition: Instructions.h:164
reverse_iterator rbegin()
Definition: BasicBlock.h:233
bool isSimple() const
Definition: Instructions.h:263
bool isSafeToLoadUnconditionally(Value *V, unsigned Align, const DataLayout &DL, Instruction *ScanFrom=nullptr, const DominatorTree *DT=nullptr)
Return true if we know that executing a load from this value cannot trap.
Definition: Loads.cpp:191
The access modifies the value stored in memory.
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:191
iterator begin()
Instruction iterator methods.
Definition: BasicBlock.h:228
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:53
mldst false
mldst motion
A Use represents the edge between a Value definition and its users.
Definition: Use.h:56
mldst MergedLoadStoreMotion
An analysis that produces MemoryDependenceResults for a function.
Instruction * clone() const
Create a copy of 'this' instruction that is identical in all ways except the following: ...
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
Definition: STLExtras.h:241
#define F(x, y, z)
Definition: MD5.cpp:51
void andIRFlags(const Value *V)
Logical 'and' of any supported wrapping, exact, and fast-math flags of V and this instruction...
BasicBlock * getSuccessor(unsigned i) const
An instruction for storing to memory.
Definition: Instructions.h:300
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition: Value.cpp:401
iterator begin()
Definition: Function.h:535
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
static MemoryLocation get(const LoadInst *LI)
Return a location with information about the memory reference by the given instruction.
bool isGuaranteedToTransferExecutionToSuccessor(const Instruction *I)
Return true if this function can prove that the instruction I will always transfer execution to one o...
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:107
void insertBefore(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified instruction...
Definition: Instruction.cpp:82
LLVM Basic Block Representation.
Definition: BasicBlock.h:51
BasicBlock * getSuccessor(unsigned idx) const
Return the specified successor.
Definition: InstrTypes.h:79
Conditional or Unconditional Branch instruction.
A manager for alias analyses.
Interval::pred_iterator pred_begin(Interval *I)
pred_begin/pred_end - define methods so that Intervals may be used just like BasicBlocks can with the...
Definition: Interval.h:116
Represent the analysis usage information of a pass.
Analysis pass providing a never-invalidated alias analysis result.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE,"Assign register bank of generic virtual registers", false, false) RegBankSelect
static const unsigned End
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:298
Interval::pred_iterator pred_end(Interval *I)
Definition: Interval.h:119
op_range operands()
Definition: User.h:213
Value * getPointerOperand()
Definition: Instructions.h:270
self_iterator getIterator()
Definition: ilist_node.h:81
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:113
A wrapper analysis pass for the legacy pass manager that exposes a MemoryDepnedenceResults instance...
void dump() const
Support for debugging, callable in GDB: V->dump()
Definition: AsmWriter.cpp:3540
Representation for a specific memory location.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Iterator for intrusive lists based on ilist_node.
iterator end()
Definition: BasicBlock.h:230
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
Definition: Instruction.cpp:58
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:230
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition: Pass.cpp:276
void setOperand(unsigned i, Value *Val)
Definition: User.h:150
FunctionPass * createMergedLoadStoreMotionPass()
createMergedLoadStoreMotionPass - The public interface to this file.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
BasicBlock * getSingleSuccessor()
Return the successor of this block if it has a single successor.
Definition: BasicBlock.cpp:253
BasicBlock * getSinglePredecessor()
Return the predecessor of this block if it has a single predecessor block.
Definition: BasicBlock.cpp:226
INITIALIZE_PASS_BEGIN(MergedLoadStoreMotionLegacyPass,"mldst-motion","MergedLoadStoreMotion", false, false) INITIALIZE_PASS_END(MergedLoadStoreMotionLegacyPass
This pass performs merges of loads and stores on both sides of a.
bool mayThrow() const
Return true if this instruction may throw an exception.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Definition: Module.cpp:384
unsigned getAlignment() const
Return the alignment of the access that is being performed.
Definition: Instructions.h:227
The access both references and modifies the value stored in memory.
#define I(x, y, z)
Definition: MD5.cpp:54
TerminatorInst * getTerminator()
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
Definition: BasicBlock.cpp:124
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:287
void preserve()
Mark an analysis as preserved.
Definition: PassManager.h:120
size_t size() const
Definition: BasicBlock.h:238
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
Definition: Value.h:71
#define DEBUG(X)
Definition: Debug.h:100
A container for analyses that lazily runs them and caches their results.
bool isSameOperationAs(const Instruction *I, unsigned flags=0) const
This function determines if the specified instruction executes the same operation as the current one...
iterator getFirstInsertionPt()
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
Definition: BasicBlock.cpp:209
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object...
void initializeMergedLoadStoreMotionLegacyPassPass(PassRegistry &)
Value * getPointerOperand()
Definition: Instructions.h:394
const BasicBlock * getParent() const
Definition: Instruction.h:62