80
80
#include " llvm/Analysis/CFG.h"
81
81
#include " llvm/Analysis/GlobalsModRef.h"
82
82
#include " llvm/Analysis/Loads.h"
83
- #include " llvm/Analysis/MemoryDependenceAnalysis.h"
84
83
#include " llvm/Analysis/ValueTracking.h"
85
84
#include " llvm/IR/Metadata.h"
86
85
#include " llvm/Support/Debug.h"
@@ -97,7 +96,6 @@ namespace {
97
96
// MergedLoadStoreMotion Pass
98
97
// ===----------------------------------------------------------------------===//
99
98
class MergedLoadStoreMotion {
100
- MemoryDependenceResults *MD = nullptr ;
101
99
AliasAnalysis *AA = nullptr ;
102
100
103
101
// The mergeLoad/Store algorithms could have Size0 * Size1 complexity,
@@ -107,14 +105,9 @@ class MergedLoadStoreMotion {
107
105
const int MagicCompileTimeControl = 250 ;
108
106
109
107
public:
110
- bool run (Function &F, MemoryDependenceResults *MD, AliasAnalysis &AA);
108
+ bool run (Function &F, AliasAnalysis &AA);
111
109
112
110
private:
113
- // /
114
- // / \brief Remove instruction from parent and update memory dependence
115
- // / analysis.
116
- // /
117
- void removeInstruction (Instruction *Inst);
118
111
BasicBlock *getDiamondTail (BasicBlock *BB);
119
112
bool isDiamondHead (BasicBlock *BB);
120
113
// Routines for sinking stores
@@ -127,22 +120,6 @@ class MergedLoadStoreMotion {
127
120
};
128
121
} // end anonymous namespace
129
122
130
- // /
131
- // / \brief Remove instruction from parent and update memory dependence analysis.
132
- // /
133
- void MergedLoadStoreMotion::removeInstruction (Instruction *Inst) {
134
- // Notify the memory dependence analysis.
135
- if (MD) {
136
- MD->removeInstruction (Inst);
137
- if (auto *LI = dyn_cast<LoadInst>(Inst))
138
- MD->invalidateCachedPointerInfo (LI->getPointerOperand ());
139
- if (Inst->getType ()->isPtrOrPtrVectorTy ()) {
140
- MD->invalidateCachedPointerInfo (Inst);
141
- }
142
- }
143
- Inst->eraseFromParent ();
144
- }
145
-
146
123
// /
147
124
// / \brief Return tail block of a diamond.
148
125
// /
@@ -236,8 +213,6 @@ PHINode *MergedLoadStoreMotion::getPHIOperand(BasicBlock *BB, StoreInst *S0,
236
213
&BB->front ());
237
214
NewPN->addIncoming (Opd1, S0->getParent ());
238
215
NewPN->addIncoming (Opd2, S1->getParent ());
239
- if (MD && NewPN->getType ()->isPtrOrPtrVectorTy ())
240
- MD->invalidateCachedPointerInfo (NewPN);
241
216
return NewPN;
242
217
}
243
218
@@ -275,12 +250,12 @@ bool MergedLoadStoreMotion::sinkStore(BasicBlock *BB, StoreInst *S0,
275
250
// New PHI operand? Use it.
276
251
if (PHINode *NewPN = getPHIOperand (BB, S0, S1))
277
252
SNew->setOperand (0 , NewPN);
278
- removeInstruction (S0 );
279
- removeInstruction (S1 );
253
+ S0-> eraseFromParent ( );
254
+ S1-> eraseFromParent ( );
280
255
A0->replaceAllUsesWith (ANew);
281
- removeInstruction (A0 );
256
+ A0-> eraseFromParent ( );
282
257
A1->replaceAllUsesWith (ANew);
283
- removeInstruction (A1 );
258
+ A1-> eraseFromParent ( );
284
259
return true ;
285
260
}
286
261
return false ;
@@ -344,9 +319,7 @@ bool MergedLoadStoreMotion::mergeStores(BasicBlock *T) {
344
319
return MergedStores;
345
320
}
346
321
347
- bool MergedLoadStoreMotion::run (Function &F, MemoryDependenceResults *MD,
348
- AliasAnalysis &AA) {
349
- this ->MD = MD;
322
+ bool MergedLoadStoreMotion::run (Function &F, AliasAnalysis &AA) {
350
323
this ->AA = &AA;
351
324
352
325
bool Changed = false ;
@@ -382,17 +355,14 @@ class MergedLoadStoreMotionLegacyPass : public FunctionPass {
382
355
if (skipFunction (F))
383
356
return false ;
384
357
MergedLoadStoreMotion Impl;
385
- auto *MDWP = getAnalysisIfAvailable<MemoryDependenceWrapperPass>();
386
- return Impl.run (F, MDWP ? &MDWP->getMemDep () : nullptr ,
387
- getAnalysis<AAResultsWrapperPass>().getAAResults ());
358
+ return Impl.run (F, getAnalysis<AAResultsWrapperPass>().getAAResults ());
388
359
}
389
360
390
361
private:
391
362
void getAnalysisUsage (AnalysisUsage &AU) const override {
392
363
AU.setPreservesCFG ();
393
364
AU.addRequired <AAResultsWrapperPass>();
394
365
AU.addPreserved <GlobalsAAWrapperPass>();
395
- AU.addPreserved <MemoryDependenceWrapperPass>();
396
366
}
397
367
};
398
368
@@ -408,22 +378,19 @@ FunctionPass *llvm::createMergedLoadStoreMotionPass() {
408
378
409
379
INITIALIZE_PASS_BEGIN (MergedLoadStoreMotionLegacyPass, " mldst-motion" ,
410
380
" MergedLoadStoreMotion" , false , false )
411
- INITIALIZE_PASS_DEPENDENCY(MemoryDependenceWrapperPass)
412
381
INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
413
382
INITIALIZE_PASS_END(MergedLoadStoreMotionLegacyPass, " mldst-motion" ,
414
383
" MergedLoadStoreMotion" , false , false )
415
384
416
385
PreservedAnalyses
417
386
MergedLoadStoreMotionPass::run(Function &F, FunctionAnalysisManager &AM) {
418
387
MergedLoadStoreMotion Impl;
419
- auto *MD = AM.getCachedResult <MemoryDependenceAnalysis>(F);
420
388
auto &AA = AM.getResult <AAManager>(F);
421
- if (!Impl.run (F, MD, AA))
389
+ if (!Impl.run (F, AA))
422
390
return PreservedAnalyses::all ();
423
391
424
392
PreservedAnalyses PA;
425
393
PA.preserveSet <CFGAnalyses>();
426
394
PA.preserve <GlobalsAA>();
427
- PA.preserve <MemoryDependenceAnalysis>();
428
395
return PA;
429
396
}
0 commit comments