[llvm] 5e1ed67 - [GVN] Move `ValueTable` out of `GVN.h` (NFC) (#226233)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 29 02:07:38 PDT 2026
Author: Momchil Velikov
Date: 2026-09-29T10:07:27+01:00
New Revision: 5e1ed67dbadba1b2bc254411cf78e61db51687d1
URL: https://github.com/llvm/llvm-project/commit/5e1ed67dbadba1b2bc254411cf78e61db51687d1
DIFF: https://github.com/llvm/llvm-project/commit/5e1ed67dbadba1b2bc254411cf78e61db51687d1.diff
LOG: [GVN] Move `ValueTable` out of `GVN.h` (NFC) (#226233)
* Rename `GVNPass::ValueTable` to `GVNValueTable`, and move it out to
the `llvm` namespace and to its own file `GVNValueTable.h`.
* Move `GVNPass::Expression` into `llvm::GVNValueTable`.
* Move `GVNHoistPass` and `GVNSinkPass` to their own headers.
With these changes `GVHoist.cpp` and `GVNSink.cpp` no longer need to
include `GVN.h` or peek into `GVNPass` internals.
Added:
llvm/include/llvm/Transforms/Scalar/GVNHoist.h
llvm/include/llvm/Transforms/Scalar/GVNSink.h
llvm/include/llvm/Transforms/Scalar/GVNValueTable.h
Modified:
llvm/include/llvm/Transforms/Scalar/GVN.h
llvm/lib/Passes/PassBuilder.cpp
llvm/lib/Passes/PassBuilderPipelines.cpp
llvm/lib/Transforms/Scalar/GVN.cpp
llvm/lib/Transforms/Scalar/GVNHoist.cpp
llvm/lib/Transforms/Scalar/GVNSink.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Transforms/Scalar/GVN.h b/llvm/include/llvm/Transforms/Scalar/GVN.h
index 553b7fc245250..c59d830bb7016 100644
--- a/llvm/include/llvm/Transforms/Scalar/GVN.h
+++ b/llvm/include/llvm/Transforms/Scalar/GVN.h
@@ -26,6 +26,7 @@
#include "llvm/IR/ValueHandle.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/Compiler.h"
+#include "llvm/Transforms/Scalar/GVNValueTable.h"
#include <cstdint>
#include <optional>
#include <utility>
@@ -230,97 +231,6 @@ class GVNPass : public OptionalPassInfoMixin<GVNPass> {
LLVM_ABI bool isMemDepEnabled() const;
LLVM_ABI bool isMemorySSAEnabled() 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.
- class ValueTable {
- DenseMap<Value *, uint32_t> ValueNumbering;
- DenseMap<Expression, uint32_t> ExpressionNumbering;
-
- // Expressions is the vector of Expression. ExprIdx is the mapping from
- // value number to the index of Expression in Expressions. We use it
- // instead of a DenseMap because filling such mapping is faster than
- // filling a DenseMap and the compile time is a little better.
- uint32_t NextExprNumber = 0;
-
- std::vector<Expression> Expressions;
- std::vector<uint32_t> ExprIdx;
-
- // Value number to PHINode mapping. Used for phi-translate in scalarpre.
- DenseMap<uint32_t, PHINode *> NumberingPhi;
-
- // Value number to BasicBlock mapping. Used for phi-translate across
- // MemoryPhis.
- DenseMap<uint32_t, BasicBlock *> NumberingBB;
-
- // Cache for phi-translate in scalarpre.
- using PhiTranslateMap =
- DenseMap<std::pair<uint32_t, const BasicBlock *>, uint32_t>;
- PhiTranslateMap PhiTranslateTable;
-
- AAResults *AA = nullptr;
- MemoryDependenceResults *MD = nullptr;
- bool IsMDEnabled = false;
- MemorySSA *MSSA = nullptr;
- bool IsMSSAEnabled = false;
- DominatorTree *DT = nullptr;
-
- uint32_t NextValueNumber = 1;
-
- Expression createExpr(Instruction *I);
- Expression createCmpExpr(unsigned Opcode, CmpInst::Predicate Predicate,
- Value *LHS, Value *RHS);
- Expression createExtractValueExpr(ExtractValueInst *EI);
- Expression createGEPExpr(GetElementPtrInst *GEP);
- uint32_t lookupOrAddCall(CallInst *C);
- uint32_t computeLoadStoreVN(Instruction *I);
- uint32_t phiTranslateImpl(const BasicBlock *BB, const BasicBlock *PhiBlock,
- uint32_t Num, GVNLeaderMap &LeaderTable);
- bool areCallValsEqual(uint32_t Num, uint32_t NewNum, const BasicBlock *Pred,
- const BasicBlock *PhiBlock,
- GVNLeaderMap &LeaderTable);
- std::pair<uint32_t, bool> assignExpNewValueNum(Expression &Exp);
- bool areAllValsInBB(uint32_t Num, const BasicBlock *BB,
- GVNLeaderMap &LeaderTable);
- void addMemoryStateToExp(Instruction *I, Expression &Exp);
-
- public:
- LLVM_ABI ValueTable();
- LLVM_ABI ValueTable(const ValueTable &Arg);
- LLVM_ABI ValueTable(ValueTable &&Arg);
- LLVM_ABI ~ValueTable();
- LLVM_ABI ValueTable &operator=(const ValueTable &Arg);
-
- LLVM_ABI uint32_t lookupOrAdd(MemoryAccess *MA);
- LLVM_ABI uint32_t lookupOrAdd(Value *V);
- LLVM_ABI uint32_t lookup(Value *V, bool Verify = true) const;
- LLVM_ABI uint32_t lookupOrAddCmp(unsigned Opcode, CmpInst::Predicate Pred,
- Value *LHS, Value *RHS);
- LLVM_ABI uint32_t lookupPtrToInt(Value *Ptr, Type *Ty);
- LLVM_ABI uint32_t phiTranslate(const BasicBlock *BB,
- const BasicBlock *PhiBlock, uint32_t Num,
- GVNLeaderMap &LeaderTable);
- LLVM_ABI void eraseTranslateCacheEntry(uint32_t Num,
- const BasicBlock &CurrBlock);
- LLVM_ABI bool exists(Value *V) const;
- LLVM_ABI void add(Value *V, uint32_t Num);
- LLVM_ABI void clear();
- LLVM_ABI void erase(Value *V);
- void setAliasAnalysis(AAResults *A) { AA = A; }
- AAResults *getAliasAnalysis() const { return AA; }
- void setMemDep(MemoryDependenceResults *M, bool MDEnabled = true) {
- MD = M;
- IsMDEnabled = MDEnabled;
- }
- void setMemorySSA(MemorySSA *M, bool MSSAEnabled = false) {
- MSSA = M;
- IsMSSAEnabled = MSSAEnabled;
- }
- void setDomTree(DominatorTree *D) { DT = D; }
- uint32_t getNextUnusedValueNumber() { return NextValueNumber; }
- LLVM_ABI void verifyRemoved(const Value *) const;
- };
-
private:
friend class GVNLegacyPass;
friend struct DenseMapInfo<Expression>;
@@ -336,7 +246,7 @@ class GVNPass : public OptionalPassInfoMixin<GVNPass> {
AAResults *AA = nullptr;
MemorySSAUpdater *MSSAU = nullptr;
- ValueTable VN;
+ GVNValueTable VN;
GVNLeaderMap LeaderTable;
@@ -518,20 +428,6 @@ class GVNPass : public OptionalPassInfoMixin<GVNPass> {
LLVM_ABI FunctionPass *createGVNPass(bool ScalarPRE);
LLVM_ABI FunctionPass *createGVNPass();
-/// A simple and fast domtree-based GVN pass to hoist common expressions
-/// from sibling branches.
-struct GVNHoistPass : OptionalPassInfoMixin<GVNHoistPass> {
- /// Run the pass over the function.
- LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
-};
-
-/// Uses an "inverted" value numbering to decide the similarity of
-/// expressions and sinks similar expressions into successors.
-struct GVNSinkPass : OptionalPassInfoMixin<GVNSinkPass> {
- /// Run the pass over the function.
- LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
-};
-
} // end namespace llvm
#endif // LLVM_TRANSFORMS_SCALAR_GVN_H
diff --git a/llvm/include/llvm/Transforms/Scalar/GVNHoist.h b/llvm/include/llvm/Transforms/Scalar/GVNHoist.h
new file mode 100644
index 0000000000000..2ab562b13247a
--- /dev/null
+++ b/llvm/include/llvm/Transforms/Scalar/GVNHoist.h
@@ -0,0 +1,30 @@
+//===- GVNHoist.h - Hoist scalar and load expressions ---------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file provides the interface for the GVNHoist pass.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_TRANSFORMS_SCALAR_GVNHOIST_H
+#define LLVM_TRANSFORMS_SCALAR_GVNHOIST_H
+
+#include "llvm/IR/PassManager.h"
+
+namespace llvm {
+
+/// A simple and fast domtree-based GVN pass to hoist common expressions
+/// from sibling branches.
+struct GVNHoistPass : OptionalPassInfoMixin<GVNHoistPass> {
+ /// Run the pass over the function.
+ LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
+};
+
+} // namespace llvm
+
+#endif // LLVM_TRANSFORMS_SCALAR_GVNHOIST_H
diff --git a/llvm/include/llvm/Transforms/Scalar/GVNSink.h b/llvm/include/llvm/Transforms/Scalar/GVNSink.h
new file mode 100644
index 0000000000000..f8dafc87d716c
--- /dev/null
+++ b/llvm/include/llvm/Transforms/Scalar/GVNSink.h
@@ -0,0 +1,30 @@
+//===- GVNSink.h - Sink expressions into successors -----------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file provides the interface for the GVNSink pass.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_TRANSFORMS_SCALAR_GVNSINK_H
+#define LLVM_TRANSFORMS_SCALAR_GVNSINK_H
+
+#include "llvm/IR/PassManager.h"
+
+namespace llvm {
+
+/// Uses an "inverted" value numbering to decide the similarity of
+/// expressions and sinks similar expressions into successors.
+struct GVNSinkPass : OptionalPassInfoMixin<GVNSinkPass> {
+ /// Run the pass over the function.
+ LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
+};
+
+} // end namespace llvm
+
+#endif // LLVM_TRANSFORMS_SCALAR_GVNSINK_H
diff --git a/llvm/include/llvm/Transforms/Scalar/GVNValueTable.h b/llvm/include/llvm/Transforms/Scalar/GVNValueTable.h
new file mode 100644
index 0000000000000..3de7d45fed441
--- /dev/null
+++ b/llvm/include/llvm/Transforms/Scalar/GVNValueTable.h
@@ -0,0 +1,132 @@
+//===- GVNValueTable.h - Value table for GVN ------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file provides a data structure for mapping values and expressions to
+/// congruence class IDs.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_TRANSFORMS_SCALAR_GVNVALUETABLE_H
+#define LLVM_TRANSFORMS_SCALAR_GVNVALUETABLE_H
+
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/IR/InstrTypes.h"
+
+namespace llvm {
+
+class AAResults;
+class BasicBlock;
+class CallInst;
+class DominatorTree;
+class ExtractValueInst;
+class GVNLeaderMap;
+class Instruction;
+class GetElementPtrInst;
+class MemoryAccess;
+class MemoryDependenceResults;
+class MemorySSA;
+class PHINode;
+class Value;
+
+/// 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.
+class GVNValueTable {
+public:
+ struct Expression;
+
+private:
+ DenseMap<Value *, uint32_t> ValueNumbering;
+ DenseMap<Expression, uint32_t> ExpressionNumbering;
+
+ // Expressions is the vector of Expression. ExprIdx is the mapping from
+ // value number to the index of Expression in Expressions. We use it
+ // instead of a DenseMap because filling such mapping is faster than
+ // filling a DenseMap and the compile time is a little better.
+ uint32_t NextExprNumber = 0;
+
+ std::vector<Expression> Expressions;
+ std::vector<uint32_t> ExprIdx;
+
+ // Value number to PHINode mapping. Used for phi-translate in scalarpre.
+ DenseMap<uint32_t, PHINode *> NumberingPhi;
+
+ // Value number to BasicBlock mapping. Used for phi-translate across
+ // MemoryPhis.
+ DenseMap<uint32_t, BasicBlock *> NumberingBB;
+
+ // Cache for phi-translate in scalarpre.
+ using PhiTranslateMap =
+ DenseMap<std::pair<uint32_t, const BasicBlock *>, uint32_t>;
+ PhiTranslateMap PhiTranslateTable;
+
+ AAResults *AA = nullptr;
+ MemoryDependenceResults *MD = nullptr;
+ bool IsMDEnabled = false;
+ MemorySSA *MSSA = nullptr;
+ bool IsMSSAEnabled = false;
+ DominatorTree *DT = nullptr;
+
+ uint32_t NextValueNumber = 1;
+
+ Expression createExpr(Instruction *I);
+ Expression createCmpExpr(unsigned Opcode, CmpInst::Predicate Predicate,
+ Value *LHS, Value *RHS);
+ Expression createExtractValueExpr(ExtractValueInst *EI);
+ Expression createGEPExpr(GetElementPtrInst *GEP);
+ uint32_t lookupOrAddCall(CallInst *C);
+ uint32_t computeLoadStoreVN(Instruction *I);
+ uint32_t phiTranslateImpl(const BasicBlock *BB, const BasicBlock *PhiBlock,
+ uint32_t Num, GVNLeaderMap &LeaderTable);
+ bool areCallValsEqual(uint32_t Num, uint32_t NewNum, const BasicBlock *Pred,
+ const BasicBlock *PhiBlock, GVNLeaderMap &LeaderTable);
+ std::pair<uint32_t, bool> assignExpNewValueNum(Expression &Exp);
+ bool areAllValsInBB(uint32_t Num, const BasicBlock *BB,
+ GVNLeaderMap &LeaderTable);
+ void addMemoryStateToExp(Instruction *I, Expression &Exp);
+
+public:
+ LLVM_ABI GVNValueTable();
+ LLVM_ABI GVNValueTable(const GVNValueTable &Arg);
+ LLVM_ABI GVNValueTable(GVNValueTable &&Arg);
+ LLVM_ABI ~GVNValueTable();
+ LLVM_ABI GVNValueTable &operator=(const GVNValueTable &Arg);
+
+ LLVM_ABI uint32_t lookupOrAdd(MemoryAccess *MA);
+ LLVM_ABI uint32_t lookupOrAdd(Value *V);
+ LLVM_ABI uint32_t lookup(Value *V, bool Verify = true) const;
+ LLVM_ABI uint32_t lookupOrAddCmp(unsigned Opcode, CmpInst::Predicate Pred,
+ Value *LHS, Value *RHS);
+ LLVM_ABI uint32_t lookupPtrToInt(Value *Ptr, Type *Ty);
+ LLVM_ABI uint32_t phiTranslate(const BasicBlock *BB,
+ const BasicBlock *PhiBlock, uint32_t Num,
+ GVNLeaderMap &LeaderTable);
+ LLVM_ABI void eraseTranslateCacheEntry(uint32_t Num,
+ const BasicBlock &CurrBlock);
+ LLVM_ABI bool exists(Value *V) const;
+ LLVM_ABI void add(Value *V, uint32_t Num);
+ LLVM_ABI void clear();
+ LLVM_ABI void erase(Value *V);
+ void setAliasAnalysis(AAResults *A) { AA = A; }
+ AAResults *getAliasAnalysis() const { return AA; }
+ void setMemDep(MemoryDependenceResults *M, bool MDEnabled = true) {
+ MD = M;
+ IsMDEnabled = MDEnabled;
+ }
+ void setMemorySSA(MemorySSA *M, bool MSSAEnabled = false) {
+ MSSA = M;
+ IsMSSAEnabled = MSSAEnabled;
+ }
+ void setDomTree(DominatorTree *D) { DT = D; }
+ uint32_t getNextUnusedValueNumber() { return NextValueNumber; }
+ LLVM_ABI void verifyRemoved(const Value *) const;
+};
+
+} // namespace llvm
+#endif // LLVM_TRANSFORMS_SCALAR_GVNVALUETABLE_H
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index 172533cf66a24..30a6f75a1b86d 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -314,6 +314,8 @@
#include "llvm/Transforms/Scalar/FlattenCFG.h"
#include "llvm/Transforms/Scalar/Float2Int.h"
#include "llvm/Transforms/Scalar/GVN.h"
+#include "llvm/Transforms/Scalar/GVNHoist.h"
+#include "llvm/Transforms/Scalar/GVNSink.h"
#include "llvm/Transforms/Scalar/GuardWidening.h"
#include "llvm/Transforms/Scalar/IVUsersPrinter.h"
#include "llvm/Transforms/Scalar/IndVarSimplify.h"
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 8e532b5980e74..bd37fffc8e991 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -100,6 +100,8 @@
#include "llvm/Transforms/Scalar/ExpandMemCmp.h"
#include "llvm/Transforms/Scalar/Float2Int.h"
#include "llvm/Transforms/Scalar/GVN.h"
+#include "llvm/Transforms/Scalar/GVNHoist.h"
+#include "llvm/Transforms/Scalar/GVNSink.h"
#include "llvm/Transforms/Scalar/IndVarSimplify.h"
#include "llvm/Transforms/Scalar/InferAlignment.h"
#include "llvm/Transforms/Scalar/InstSimplifyPass.h"
diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp
index bf7115106fa6a..463520f2b32d7 100644
--- a/llvm/lib/Transforms/Scalar/GVN.cpp
+++ b/llvm/lib/Transforms/Scalar/GVN.cpp
@@ -151,7 +151,7 @@ static cl::opt<uint32_t> MaxNumInsnsPerBlock(
cl::desc("Max number of instructions to scan in each basic block in GVN "
"(default = 100)"));
-struct llvm::GVNPass::Expression {
+struct llvm::GVNValueTable::Expression {
uint32_t Opcode;
bool Commutative = false;
// The type is not necessarily the result type of the expression, it may be
@@ -184,15 +184,15 @@ struct llvm::GVNPass::Expression {
}
};
-template <> struct llvm::DenseMapInfo<GVNPass::Expression> {
- static unsigned getHashValue(const GVNPass::Expression &E) {
+template <> struct llvm::DenseMapInfo<GVNValueTable::Expression> {
+ static unsigned getHashValue(const GVNValueTable::Expression &E) {
using llvm::hash_value;
return static_cast<unsigned>(hash_value(E));
}
- static bool isEqual(const GVNPass::Expression &LHS,
- const GVNPass::Expression &RHS) {
+ static bool isEqual(const GVNValueTable::Expression &LHS,
+ const GVNValueTable::Expression &RHS) {
return LHS == RHS;
}
};
@@ -331,7 +331,7 @@ struct llvm::GVNPass::AvailableValueInBlock {
// ValueTable Internal Functions
//===----------------------------------------------------------------------===//
-GVNPass::Expression GVNPass::ValueTable::createExpr(Instruction *I) {
+GVNValueTable::Expression GVNValueTable::createExpr(Instruction *I) {
Expression E;
E.Ty = I->getType();
E.Opcode = I->getOpcode();
@@ -369,8 +369,9 @@ GVNPass::Expression GVNPass::ValueTable::createExpr(Instruction *I) {
return E;
}
-GVNPass::Expression GVNPass::ValueTable::createCmpExpr(
- unsigned Opcode, CmpInst::Predicate Predicate, Value *LHS, Value *RHS) {
+GVNValueTable::Expression
+GVNValueTable::createCmpExpr(unsigned Opcode, CmpInst::Predicate Predicate,
+ Value *LHS, Value *RHS) {
assert((Opcode == Instruction::ICmp || Opcode == Instruction::FCmp) &&
"Not a comparison!");
Expression E;
@@ -388,8 +389,8 @@ GVNPass::Expression GVNPass::ValueTable::createCmpExpr(
return E;
}
-GVNPass::Expression
-GVNPass::ValueTable::createExtractValueExpr(ExtractValueInst *EI) {
+GVNValueTable::Expression
+GVNValueTable::createExtractValueExpr(ExtractValueInst *EI) {
assert(EI && "Not an ExtractValueInst?");
Expression E;
E.Ty = EI->getType();
@@ -417,7 +418,7 @@ GVNPass::ValueTable::createExtractValueExpr(ExtractValueInst *EI) {
return E;
}
-GVNPass::Expression GVNPass::ValueTable::createGEPExpr(GetElementPtrInst *GEP) {
+GVNValueTable::Expression GVNValueTable::createGEPExpr(GetElementPtrInst *GEP) {
Expression E;
Type *PtrTy = GEP->getType()->getScalarType();
const DataLayout &DL = GEP->getDataLayout();
@@ -453,15 +454,14 @@ GVNPass::Expression GVNPass::ValueTable::createGEPExpr(GetElementPtrInst *GEP) {
// ValueTable External Functions
//===----------------------------------------------------------------------===//
-GVNPass::ValueTable::ValueTable() = default;
-GVNPass::ValueTable::ValueTable(const ValueTable &) = default;
-GVNPass::ValueTable::ValueTable(ValueTable &&) = default;
-GVNPass::ValueTable::~ValueTable() = default;
-GVNPass::ValueTable &
-GVNPass::ValueTable::operator=(const GVNPass::ValueTable &Arg) = default;
+GVNValueTable::GVNValueTable() = default;
+GVNValueTable::GVNValueTable(const GVNValueTable &) = default;
+GVNValueTable::GVNValueTable(GVNValueTable &&) = default;
+GVNValueTable::~GVNValueTable() = default;
+GVNValueTable &GVNValueTable::operator=(const GVNValueTable &Arg) = default;
/// add - Insert a value into the table with a specified value number.
-void GVNPass::ValueTable::add(Value *V, uint32_t Num) {
+void GVNValueTable::add(Value *V, uint32_t Num) {
ValueNumbering.insert(std::make_pair(V, Num));
if (PHINode *PN = dyn_cast<PHINode>(V))
NumberingPhi[Num] = PN;
@@ -473,14 +473,14 @@ void GVNPass::ValueTable::add(Value *V, uint32_t Num) {
/// * a MemoryPhi, add the value number of the basic block corresponding to that
/// MemoryPhi,
/// * a MemoryDef, add the value number of the memory setting instruction.
-void GVNPass::ValueTable::addMemoryStateToExp(Instruction *I, Expression &Exp) {
+void GVNValueTable::addMemoryStateToExp(Instruction *I, Expression &Exp) {
assert(MSSA && "addMemoryStateToExp should not be called without MemorySSA");
assert(MSSA->getMemoryAccess(I) && "Instruction does not access memory");
MemoryAccess *MA = MSSA->getSkipSelfWalker()->getClobberingMemoryAccess(I);
Exp.VarArgs.push_back(lookupOrAdd(MA));
}
-uint32_t GVNPass::ValueTable::lookupOrAddCall(CallInst *C) {
+uint32_t GVNValueTable::lookupOrAddCall(CallInst *C) {
// FIXME: Currently the calls which may access the thread id may
// be considered as not accessing the memory. But this is
// problematic for coroutines, since coroutines may resume in a
@@ -621,7 +621,7 @@ uint32_t GVNPass::ValueTable::lookupOrAddCall(CallInst *C) {
}
/// Returns the value number for the specified load or store instruction.
-uint32_t GVNPass::ValueTable::computeLoadStoreVN(Instruction *I) {
+uint32_t GVNValueTable::computeLoadStoreVN(Instruction *I) {
if (!MSSA || !IsMSSAEnabled) {
ValueNumbering[I] = NextValueNumber;
return NextValueNumber++;
@@ -640,11 +640,11 @@ uint32_t GVNPass::ValueTable::computeLoadStoreVN(Instruction *I) {
}
/// Returns true if a value number exists for the specified value.
-bool GVNPass::ValueTable::exists(Value *V) const {
+bool GVNValueTable::exists(Value *V) const {
return ValueNumbering.contains(V);
}
-uint32_t GVNPass::ValueTable::lookupOrAdd(MemoryAccess *MA) {
+uint32_t GVNValueTable::lookupOrAdd(MemoryAccess *MA) {
return MSSA->isLiveOnEntryDef(MA) || isa<MemoryPhi>(MA)
? lookupOrAdd(MA->getBlock())
: lookupOrAdd(cast<MemoryUseOrDef>(MA)->getMemoryInst());
@@ -652,7 +652,7 @@ uint32_t GVNPass::ValueTable::lookupOrAdd(MemoryAccess *MA) {
/// lookupOrAdd - Returns the value number for the specified value, assigning
/// it a new number if it did not have one before.
-uint32_t GVNPass::ValueTable::lookupOrAdd(Value *V) {
+uint32_t GVNValueTable::lookupOrAdd(Value *V) {
auto VI = ValueNumbering.find(V);
if (VI != ValueNumbering.end())
return VI->second;
@@ -740,7 +740,7 @@ uint32_t GVNPass::ValueTable::lookupOrAdd(Value *V) {
/// Returns the value number of the specified value. Fails if
/// the value has not yet been numbered.
-uint32_t GVNPass::ValueTable::lookup(Value *V, bool Verify) const {
+uint32_t GVNValueTable::lookup(Value *V, bool Verify) const {
auto VI = ValueNumbering.find(V);
if (Verify) {
assert(VI != ValueNumbering.end() && "Value not numbered?");
@@ -753,15 +753,15 @@ uint32_t GVNPass::ValueTable::lookup(Value *V, bool Verify) const {
/// assigning it a new number if it did not have one before. Useful when
/// we deduced the result of a comparison, but don't immediately have an
/// instruction realizing that comparison to hand.
-uint32_t GVNPass::ValueTable::lookupOrAddCmp(unsigned Opcode,
- CmpInst::Predicate Predicate,
- Value *LHS, Value *RHS) {
+uint32_t GVNValueTable::lookupOrAddCmp(unsigned Opcode,
+ CmpInst::Predicate Predicate, Value *LHS,
+ Value *RHS) {
Expression Exp = createCmpExpr(Opcode, Predicate, LHS, RHS);
return assignExpNewValueNum(Exp).first;
}
/// Returns the value number of ptrtoint \p Ptr to \Ty.
-uint32_t GVNPass::ValueTable::lookupPtrToInt(Value *Ptr, Type *Ty) {
+uint32_t GVNValueTable::lookupPtrToInt(Value *Ptr, Type *Ty) {
Expression Exp(Instruction::PtrToInt);
Exp.Ty = Ty;
Exp.VarArgs.push_back(lookupOrAdd(Ptr));
@@ -769,7 +769,7 @@ uint32_t GVNPass::ValueTable::lookupPtrToInt(Value *Ptr, Type *Ty) {
}
/// Remove all entries from the ValueTable.
-void GVNPass::ValueTable::clear() {
+void GVNValueTable::clear() {
ValueNumbering.clear();
ExpressionNumbering.clear();
NumberingPhi.clear();
@@ -782,7 +782,7 @@ void GVNPass::ValueTable::clear() {
}
/// Remove a value from the value numbering.
-void GVNPass::ValueTable::erase(Value *V) {
+void GVNValueTable::erase(Value *V) {
uint32_t Num = ValueNumbering.lookup(V);
ValueNumbering.erase(V);
// If V is PHINode, V <--> value number is an one-to-one mapping.
@@ -794,7 +794,7 @@ void GVNPass::ValueTable::erase(Value *V) {
/// verifyRemoved - Verify that the value is removed from all internal data
/// structures.
-void GVNPass::ValueTable::verifyRemoved(const Value *V) const {
+void GVNValueTable::verifyRemoved(const Value *V) const {
assert(!ValueNumbering.contains(V) &&
"Inst still occurs in value numbering map!");
}
@@ -2903,8 +2903,7 @@ bool GVNPass::processMaskedLoad(IntrinsicInst *I) {
/// Return a pair the first field showing the value number of \p Exp and the
/// second field showing whether it is a value number newly created.
-std::pair<uint32_t, bool>
-GVNPass::ValueTable::assignExpNewValueNum(Expression &Exp) {
+std::pair<uint32_t, bool> GVNValueTable::assignExpNewValueNum(Expression &Exp) {
uint32_t &E = ExpressionNumbering[Exp];
bool CreateNewValNum = !E;
if (CreateNewValNum) {
@@ -2919,18 +2918,17 @@ GVNPass::ValueTable::assignExpNewValueNum(Expression &Exp) {
/// Return whether all the values related with the same \p num are
/// defined in \p BB.
-bool GVNPass::ValueTable::areAllValsInBB(uint32_t Num, const BasicBlock *BB,
- GVNLeaderMap &LeaderTable) {
+bool GVNValueTable::areAllValsInBB(uint32_t Num, const BasicBlock *BB,
+ GVNLeaderMap &LeaderTable) {
return all_of(
LeaderTable.getLeaders(Num),
[=](const GVNLeaderMap::LeaderTableEntry &L) { return L.BB == BB; });
}
/// Wrap phiTranslateImpl to provide caching functionality.
-uint32_t GVNPass::ValueTable::phiTranslate(const BasicBlock *Pred,
- const BasicBlock *PhiBlock,
- uint32_t Num,
- GVNLeaderMap &LeaderTable) {
+uint32_t GVNValueTable::phiTranslate(const BasicBlock *Pred,
+ const BasicBlock *PhiBlock, uint32_t Num,
+ GVNLeaderMap &LeaderTable) {
auto FindRes = PhiTranslateTable.find({Num, Pred});
if (FindRes != PhiTranslateTable.end())
return FindRes->second;
@@ -2941,10 +2939,10 @@ uint32_t GVNPass::ValueTable::phiTranslate(const BasicBlock *Pred,
// Return true if the value number \p Num and NewNum have equal value.
// Return false if the result is unknown.
-bool GVNPass::ValueTable::areCallValsEqual(uint32_t Num, uint32_t NewNum,
- const BasicBlock *Pred,
- const BasicBlock *PhiBlock,
- GVNLeaderMap &LeaderTable) {
+bool GVNValueTable::areCallValsEqual(uint32_t Num, uint32_t NewNum,
+ const BasicBlock *Pred,
+ const BasicBlock *PhiBlock,
+ GVNLeaderMap &LeaderTable) {
CallInst *Call = nullptr;
auto Leaders = LeaderTable.getLeaders(Num);
for (const auto &Entry : Leaders) {
@@ -2976,10 +2974,10 @@ bool GVNPass::ValueTable::areCallValsEqual(uint32_t Num, uint32_t NewNum,
/// Translate value number \p Num using phis, so that it has the values of
/// the phis in BB.
-uint32_t GVNPass::ValueTable::phiTranslateImpl(const BasicBlock *Pred,
- const BasicBlock *PhiBlock,
- uint32_t Num,
- GVNLeaderMap &LeaderTable) {
+uint32_t GVNValueTable::phiTranslateImpl(const BasicBlock *Pred,
+ const BasicBlock *PhiBlock,
+ uint32_t Num,
+ GVNLeaderMap &LeaderTable) {
// See if we can refine the value number by looking at the PN incoming value
// for the given predecessor.
if (PHINode *PN = NumberingPhi[Num]) {
@@ -3060,8 +3058,8 @@ uint32_t GVNPass::ValueTable::phiTranslateImpl(const BasicBlock *Pred,
/// Erase stale entry from phiTranslate cache so phiTranslate can be computed
/// again.
-void GVNPass::ValueTable::eraseTranslateCacheEntry(
- uint32_t Num, const BasicBlock &CurrBlock) {
+void GVNValueTable::eraseTranslateCacheEntry(uint32_t Num,
+ const BasicBlock &CurrBlock) {
for (const BasicBlock *Pred : predecessors(&CurrBlock))
PhiTranslateTable.erase({Num, Pred});
}
diff --git a/llvm/lib/Transforms/Scalar/GVNHoist.cpp b/llvm/lib/Transforms/Scalar/GVNHoist.cpp
index 6bb6d6772fbfb..5556810c40cac 100644
--- a/llvm/lib/Transforms/Scalar/GVNHoist.cpp
+++ b/llvm/lib/Transforms/Scalar/GVNHoist.cpp
@@ -33,6 +33,7 @@
// 2. geps when corresponding load/store cannot be hoisted.
//===----------------------------------------------------------------------===//
+#include "llvm/Transforms/Scalar/GVNHoist.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/STLExtras.h"
@@ -65,7 +66,7 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
-#include "llvm/Transforms/Scalar/GVN.h"
+#include "llvm/Transforms/Scalar/GVNValueTable.h"
#include "llvm/Transforms/Utils/Local.h"
#include <algorithm>
#include <cassert>
@@ -162,7 +163,7 @@ class InsnInfo {
public:
// Inserts I and its value number in VNtoScalars.
- void insert(Instruction *I, GVNPass::ValueTable &VN) {
+ void insert(Instruction *I, GVNValueTable &VN) {
// Scalar instruction.
unsigned V = VN.lookupOrAdd(I);
VNtoScalars[{V, InvalidVN}].push_back(I);
@@ -177,7 +178,7 @@ class LoadInfo {
public:
// Insert Load and the value number of its memory address in VNtoLoads.
- void insert(LoadInst *Load, GVNPass::ValueTable &VN) {
+ void insert(LoadInst *Load, GVNValueTable &VN) {
if (Load->isSimple()) {
unsigned V = VN.lookupOrAdd(Load->getPointerOperand());
// With opaque pointers we may have loads from the same pointer with
@@ -196,7 +197,7 @@ class StoreInfo {
public:
// Insert the Store and a hash number of the store address and the stored
// value in VNtoStores.
- void insert(StoreInst *Store, GVNPass::ValueTable &VN) {
+ void insert(StoreInst *Store, GVNValueTable &VN) {
if (!Store->isSimple())
return;
// Hash the store address and the stored value.
@@ -216,7 +217,7 @@ class CallInfo {
public:
// Insert Call and its value numbering in one of the VNtoCalls* containers.
- void insert(CallInst *Call, GVNPass::ValueTable &VN) {
+ void insert(CallInst *Call, GVNValueTable &VN) {
// A call that doesNotAccessMemory is handled as a Scalar,
// onlyReadsMemory will be handled as a Load instruction,
// all other calls will be handled as stores.
@@ -259,7 +260,7 @@ class GVNHoist {
unsigned int rank(const Value *V) const;
private:
- GVNPass::ValueTable VN;
+ GVNValueTable VN;
DominatorTree *DT;
PostDominatorTree *PDT;
AliasAnalysis *AA;
diff --git a/llvm/lib/Transforms/Scalar/GVNSink.cpp b/llvm/lib/Transforms/Scalar/GVNSink.cpp
index eb7a9c68b5b61..045e2a3edc3f8 100644
--- a/llvm/lib/Transforms/Scalar/GVNSink.cpp
+++ b/llvm/lib/Transforms/Scalar/GVNSink.cpp
@@ -33,6 +33,7 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/Transforms/Scalar/GVNSink.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/Hashing.h"
@@ -61,7 +62,6 @@
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
-#include "llvm/Transforms/Scalar/GVN.h"
#include "llvm/Transforms/Scalar/GVNExpression.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/Local.h"
More information about the llvm-commits
mailing list