72
72
//
73
73
// ===----------------------------------------------------------------------===//
74
74
75
+ #include " llvm/Transforms/Scalar/MergedLoadStoreMotion.h"
75
76
#include " llvm/ADT/Statistic.h"
76
77
#include " llvm/Analysis/AliasAnalysis.h"
77
78
#include " llvm/Analysis/CFG.h"
@@ -96,52 +97,12 @@ using namespace llvm;
96
97
// MergedLoadStoreMotion Pass
97
98
// ===----------------------------------------------------------------------===//
98
99
99
- namespace {
100
- class MergedLoadStoreMotion : public FunctionPass {
101
- AliasAnalysis *AA;
102
- MemoryDependenceResults *MD;
103
-
104
- public:
105
- static char ID; // Pass identification, replacement for typeid
106
- MergedLoadStoreMotion () : FunctionPass(ID), MD(nullptr ) {
107
- initializeMergedLoadStoreMotionPass (*PassRegistry::getPassRegistry ());
108
- }
109
-
110
- bool runOnFunction (Function &F) override ;
111
-
112
- private:
113
- // This transformation requires dominator postdominator info
114
- void getAnalysisUsage (AnalysisUsage &AU) const override {
115
- AU.setPreservesCFG ();
116
- AU.addRequired <AAResultsWrapperPass>();
117
- AU.addPreserved <GlobalsAAWrapperPass>();
118
- AU.addPreserved <MemoryDependenceWrapperPass>();
119
- }
120
- };
121
-
122
- char MergedLoadStoreMotion::ID = 0 ;
123
- } // anonymous namespace
124
-
125
100
// The mergeLoad/Store algorithms could have Size0 * Size1 complexity,
126
101
// where Size0 and Size1 are the #instructions on the two sides of
127
102
// the diamond. The constant chosen here is arbitrary. Compiler Time
128
103
// Control is enforced by the check Size0 * Size1 < MagicCompileTimeControl.
129
104
const int MagicCompileTimeControl = 250 ;
130
105
131
- // /
132
- // / \brief createMergedLoadStoreMotionPass - The public interface to this file.
133
- // /
134
- FunctionPass *llvm::createMergedLoadStoreMotionPass () {
135
- return new MergedLoadStoreMotion ();
136
- }
137
-
138
- INITIALIZE_PASS_BEGIN (MergedLoadStoreMotion, " mldst-motion" ,
139
- " MergedLoadStoreMotion" , false , false )
140
- INITIALIZE_PASS_DEPENDENCY(MemoryDependenceWrapperPass)
141
- INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
142
- INITIALIZE_PASS_END(MergedLoadStoreMotion, " mldst-motion" ,
143
- " MergedLoadStoreMotion" , false , false )
144
-
145
106
// /
146
107
// / \brief Remove instruction from parent and update memory dependence analysis.
147
108
// /
@@ -533,14 +494,8 @@ static bool mergeStores(BasicBlock *T, AliasAnalysis *AA,
533
494
// /
534
495
// / \brief Run the transformation for each function
535
496
// /
536
- bool MergedLoadStoreMotion::runOnFunction (Function &F) {
537
- if (skipFunction (F))
538
- return false ;
539
-
540
- auto *MDWP = getAnalysisIfAvailable<MemoryDependenceWrapperPass>();
541
- MD = MDWP ? &MDWP->getMemDep () : nullptr ;
542
- AA = &getAnalysis<AAResultsWrapperPass>().getAAResults ();
543
-
497
+ static bool runMergedLoadStoreMotion (Function &F, AliasAnalysis *AA,
498
+ MemoryDependenceResults *MD) {
544
499
bool Changed = false ;
545
500
DEBUG (dbgs () << " Instruction Merger\n " );
546
501
@@ -558,3 +513,61 @@ bool MergedLoadStoreMotion::runOnFunction(Function &F) {
558
513
}
559
514
return Changed;
560
515
}
516
+
517
+ PreservedAnalyses
518
+ MergedLoadStoreMotionPass::run (Function &F, AnalysisManager<Function> &AM) {
519
+ auto &AA = AM.getResult <AAManager>(F);
520
+ auto *MD = AM.getCachedResult <MemoryDependenceAnalysis>(F);
521
+ if (!runMergedLoadStoreMotion (F, &AA, MD))
522
+ return PreservedAnalyses::all ();
523
+ return PreservedAnalyses::none ();
524
+ }
525
+
526
+ namespace {
527
+ class MergedLoadStoreMotionLegacyPass : public FunctionPass {
528
+ AliasAnalysis *AA;
529
+ MemoryDependenceResults *MD;
530
+
531
+ public:
532
+ static char ID; // Pass identification, replacement for typeid
533
+ MergedLoadStoreMotionLegacyPass () : FunctionPass(ID), MD(nullptr ) {
534
+ initializeMergedLoadStoreMotionLegacyPassPass (
535
+ *PassRegistry::getPassRegistry ());
536
+ }
537
+
538
+ bool runOnFunction (Function &F) override {
539
+ if (skipFunction (F))
540
+ return false ;
541
+
542
+ AA = &getAnalysis<AAResultsWrapperPass>().getAAResults ();
543
+ auto *MDWP = getAnalysisIfAvailable<MemoryDependenceWrapperPass>();
544
+ MD = MDWP ? &MDWP->getMemDep () : nullptr ;
545
+ return runMergedLoadStoreMotion (F, AA, MD);
546
+ }
547
+
548
+ private:
549
+ // This transformation requires dominator postdominator info
550
+ void getAnalysisUsage (AnalysisUsage &AU) const override {
551
+ AU.setPreservesCFG ();
552
+ AU.addRequired <AAResultsWrapperPass>();
553
+ AU.addPreserved <GlobalsAAWrapperPass>();
554
+ AU.addPreserved <MemoryDependenceWrapperPass>();
555
+ }
556
+ };
557
+
558
+ char MergedLoadStoreMotionLegacyPass::ID = 0 ;
559
+ } // anonymous namespace
560
+
561
+ // /
562
+ // / \brief createMergedLoadStoreMotionPass - The public interface to this file.
563
+ // /
564
+ FunctionPass *llvm::createMergedLoadStoreMotionPass () {
565
+ return new MergedLoadStoreMotionLegacyPass ();
566
+ }
567
+
568
+ INITIALIZE_PASS_BEGIN (MergedLoadStoreMotionLegacyPass, " mldst-motion" ,
569
+ " MergedLoadStoreMotion" , false , false )
570
+ INITIALIZE_PASS_DEPENDENCY(MemoryDependenceWrapperPass)
571
+ INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
572
+ INITIALIZE_PASS_END(MergedLoadStoreMotionLegacyPass, " mldst-motion" ,
573
+ " MergedLoadStoreMotion" , false , false )
0 commit comments