79
79
#include " llvm/Analysis/GlobalsModRef.h"
80
80
#include " llvm/Analysis/Loads.h"
81
81
#include " llvm/Analysis/MemoryBuiltins.h"
82
- #include " llvm/Analysis/MemoryDependenceAnalysis.h"
83
82
#include " llvm/Analysis/ValueTracking.h"
84
83
#include " llvm/IR/Metadata.h"
85
84
#include " llvm/IR/PatternMatch.h"
@@ -98,7 +97,6 @@ namespace {
98
97
// MergedLoadStoreMotion Pass
99
98
// ===----------------------------------------------------------------------===//
100
99
class MergedLoadStoreMotion {
101
- MemoryDependenceResults *MD = nullptr ;
102
100
AliasAnalysis *AA = nullptr ;
103
101
104
102
// The mergeLoad/Store algorithms could have Size0 * Size1 complexity,
@@ -108,14 +106,9 @@ class MergedLoadStoreMotion {
108
106
const int MagicCompileTimeControl = 250 ;
109
107
110
108
public:
111
- bool run (Function &F, MemoryDependenceResults *MD, AliasAnalysis &AA);
109
+ bool run (Function &F, AliasAnalysis &AA);
112
110
113
111
private:
114
- // /
115
- // / \brief Remove instruction from parent and update memory dependence
116
- // / analysis.
117
- // /
118
- void removeInstruction (Instruction *Inst);
119
112
BasicBlock *getDiamondTail (BasicBlock *BB);
120
113
bool isDiamondHead (BasicBlock *BB);
121
114
// Routines for hoisting loads
@@ -138,22 +131,6 @@ class MergedLoadStoreMotion {
138
131
};
139
132
} // end anonymous namespace
140
133
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
134
// /
158
135
// / \brief Return tail block of a diamond.
159
136
// /
@@ -273,10 +250,10 @@ void MergedLoadStoreMotion::hoistInstruction(BasicBlock *BB,
273
250
HoistedInst->insertBefore (HoistPt);
274
251
275
252
HoistCand->replaceAllUsesWith (HoistedInst);
276
- removeInstruction ( HoistCand);
253
+ HoistCand-> eraseFromParent ( );
277
254
// Replace the else block instruction.
278
255
ElseInst->replaceAllUsesWith (HoistedInst);
279
- removeInstruction ( ElseInst);
256
+ ElseInst-> eraseFromParent ( );
280
257
}
281
258
282
259
// /
@@ -410,8 +387,6 @@ PHINode *MergedLoadStoreMotion::getPHIOperand(BasicBlock *BB, StoreInst *S0,
410
387
&BB->front ());
411
388
NewPN->addIncoming (Opd1, S0->getParent ());
412
389
NewPN->addIncoming (Opd2, S1->getParent ());
413
- if (MD && NewPN->getType ()->getScalarType ()->isPointerTy ())
414
- MD->invalidateCachedPointerInfo (NewPN);
415
390
return NewPN;
416
391
}
417
392
@@ -449,12 +424,12 @@ bool MergedLoadStoreMotion::sinkStore(BasicBlock *BB, StoreInst *S0,
449
424
// New PHI operand? Use it.
450
425
if (PHINode *NewPN = getPHIOperand (BB, S0, S1))
451
426
SNew->setOperand (0 , NewPN);
452
- removeInstruction (S0 );
453
- removeInstruction (S1 );
427
+ S0-> eraseFromParent ( );
428
+ S1-> eraseFromParent ( );
454
429
A0->replaceAllUsesWith (ANew);
455
- removeInstruction (A0 );
430
+ A0-> eraseFromParent ( );
456
431
A1->replaceAllUsesWith (ANew);
457
- removeInstruction (A1 );
432
+ A1-> eraseFromParent ( );
458
433
return true ;
459
434
}
460
435
return false ;
@@ -518,9 +493,7 @@ bool MergedLoadStoreMotion::mergeStores(BasicBlock *T) {
518
493
return MergedStores;
519
494
}
520
495
521
- bool MergedLoadStoreMotion::run (Function &F, MemoryDependenceResults *MD,
522
- AliasAnalysis &AA) {
523
- this ->MD = MD;
496
+ bool MergedLoadStoreMotion::run (Function &F, AliasAnalysis &AA) {
524
497
this ->AA = &AA;
525
498
526
499
bool Changed = false ;
@@ -557,17 +530,14 @@ class MergedLoadStoreMotionLegacyPass : public FunctionPass {
557
530
if (skipFunction (F))
558
531
return false ;
559
532
MergedLoadStoreMotion Impl;
560
- auto *MDWP = getAnalysisIfAvailable<MemoryDependenceWrapperPass>();
561
- return Impl.run (F, MDWP ? &MDWP->getMemDep () : nullptr ,
562
- getAnalysis<AAResultsWrapperPass>().getAAResults ());
533
+ return Impl.run (F, getAnalysis<AAResultsWrapperPass>().getAAResults ());
563
534
}
564
535
565
536
private:
566
537
void getAnalysisUsage (AnalysisUsage &AU) const override {
567
538
AU.setPreservesCFG ();
568
539
AU.addRequired <AAResultsWrapperPass>();
569
540
AU.addPreserved <GlobalsAAWrapperPass>();
570
- AU.addPreserved <MemoryDependenceWrapperPass>();
571
541
}
572
542
};
573
543
@@ -583,22 +553,19 @@ FunctionPass *llvm::createMergedLoadStoreMotionPass() {
583
553
584
554
INITIALIZE_PASS_BEGIN (MergedLoadStoreMotionLegacyPass, " mldst-motion" ,
585
555
" MergedLoadStoreMotion" , false , false )
586
- INITIALIZE_PASS_DEPENDENCY(MemoryDependenceWrapperPass)
587
556
INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
588
557
INITIALIZE_PASS_END(MergedLoadStoreMotionLegacyPass, " mldst-motion" ,
589
558
" MergedLoadStoreMotion" , false , false )
590
559
591
560
PreservedAnalyses
592
561
MergedLoadStoreMotionPass::run(Function &F, FunctionAnalysisManager &AM) {
593
562
MergedLoadStoreMotion Impl;
594
- auto *MD = AM.getCachedResult <MemoryDependenceAnalysis>(F);
595
563
auto &AA = AM.getResult <AAManager>(F);
596
- if (!Impl.run (F, MD, AA))
564
+ if (!Impl.run (F, AA))
597
565
return PreservedAnalyses::all ();
598
566
599
567
// FIXME: This should also 'preserve the CFG'.
600
568
PreservedAnalyses PA;
601
569
PA.preserve <GlobalsAA>();
602
- PA.preserve <MemoryDependenceAnalysis>();
603
570
return PA;
604
571
}
0 commit comments