diff options
Diffstat (limited to 'llvm/include/llvm/Transforms/Scalar/GVN.h')
-rw-r--r-- | llvm/include/llvm/Transforms/Scalar/GVN.h | 58 |
1 files changed, 53 insertions, 5 deletions
diff --git a/llvm/include/llvm/Transforms/Scalar/GVN.h b/llvm/include/llvm/Transforms/Scalar/GVN.h index 5a3d30de16a3..f2818c6b792e 100644 --- a/llvm/include/llvm/Transforms/Scalar/GVN.h +++ b/llvm/include/llvm/Transforms/Scalar/GVN.h @@ -20,7 +20,6 @@ #include "llvm/ADT/PostOrderIterator.h" #include "llvm/ADT/SetVector.h" #include "llvm/ADT/SmallVector.h" -#include "llvm/Analysis/AliasAnalysis.h" #include "llvm/Analysis/InstructionPrecedenceTracking.h" #include "llvm/Analysis/MemoryDependenceAnalysis.h" #include "llvm/IR/Dominators.h" @@ -35,6 +34,7 @@ namespace llvm { +class AAResults; class AssumptionCache; class BasicBlock; class BranchInst; @@ -61,14 +61,57 @@ class GVNLegacyPass; } // end namespace gvn +/// A set of parameters to control various transforms performed by GVN pass. +// Each of the optional boolean parameters can be set to: +/// true - enabling the transformation. +/// false - disabling the transformation. +/// None - relying on a global default. +/// Intended use is to create a default object, modify parameters with +/// additional setters and then pass it to GVN. +struct GVNOptions { + Optional<bool> AllowPRE = None; + Optional<bool> AllowLoadPRE = None; + Optional<bool> AllowLoadInLoopPRE = None; + Optional<bool> AllowMemDep = None; + + GVNOptions() = default; + + /// Enables or disables PRE in GVN. + GVNOptions &setPRE(bool PRE) { + AllowPRE = PRE; + return *this; + } + + /// Enables or disables PRE of loads in GVN. + GVNOptions &setLoadPRE(bool LoadPRE) { + AllowLoadPRE = LoadPRE; + return *this; + } + + GVNOptions &setLoadInLoopPRE(bool LoadInLoopPRE) { + AllowLoadInLoopPRE = LoadInLoopPRE; + return *this; + } + + /// Enables or disables use of MemDepAnalysis. + GVNOptions &setMemDep(bool MemDep) { + AllowMemDep = MemDep; + return *this; + } +}; + /// The core GVN pass object. /// /// FIXME: We should have a good summary of the GVN algorithm implemented by /// this particular pass here. class GVN : public PassInfoMixin<GVN> { + GVNOptions Options; + public: struct Expression; + GVN(GVNOptions Options = {}) : Options(Options) {} + /// Run the pass over the function. PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); @@ -80,9 +123,14 @@ public: } DominatorTree &getDominatorTree() const { return *DT; } - AliasAnalysis *getAliasAnalysis() const { return VN.getAliasAnalysis(); } + AAResults *getAliasAnalysis() const { return VN.getAliasAnalysis(); } MemoryDependenceResults &getMemDep() const { return *MD; } + bool isPREEnabled() const; + bool isLoadPREEnabled() const; + bool isLoadInLoopPREEnabled() const; + bool isMemDepEnabled() const; + /// This class holds the mapping between values and value numbers. It is used /// as an efficient mechanism to determine the expression-wise equivalence of /// two values. @@ -107,7 +155,7 @@ public: DenseMap<std::pair<uint32_t, const BasicBlock *>, uint32_t>; PhiTranslateMap PhiTranslateTable; - AliasAnalysis *AA = nullptr; + AAResults *AA = nullptr; MemoryDependenceResults *MD = nullptr; DominatorTree *DT = nullptr; @@ -143,8 +191,8 @@ public: void add(Value *V, uint32_t num); void clear(); void erase(Value *v); - void setAliasAnalysis(AliasAnalysis *A) { AA = A; } - AliasAnalysis *getAliasAnalysis() const { return AA; } + void setAliasAnalysis(AAResults *A) { AA = A; } + AAResults *getAliasAnalysis() const { return AA; } void setMemDep(MemoryDependenceResults *M) { MD = M; } void setDomTree(DominatorTree *D) { DT = D; } uint32_t getNextUnusedValueNumber() { return nextValueNumber; } |