7373#include < utility>
7474
7575using namespace llvm ;
76+ using namespace llvm ::GVNExpression;
7677
7778#define DEBUG_TYPE " gvn-sink"
7879
7980STATISTIC (NumRemoved, " Number of instructions removed" );
8081
81- namespace llvm {
82- namespace GVNExpression {
83-
8482LLVM_DUMP_METHOD void Expression::dump () const {
8583 print (dbgs ());
8684 dbgs () << " \n " ;
8785}
8886
89- } // end namespace GVNExpression
90- } // end namespace llvm
91-
92- namespace {
93-
9487static bool isMemoryInst (const Instruction *I) {
9588 return isa<LoadInst>(I) || isa<StoreInst>(I) ||
9689 (isa<InvokeInst>(I) && !cast<InvokeInst>(I)->doesNotAccessMemory ()) ||
@@ -99,6 +92,8 @@ static bool isMemoryInst(const Instruction *I) {
9992
10093// ===----------------------------------------------------------------------===//
10194
95+ namespace {
96+
10297// / Candidate solution for sinking. There may be different ways to
10398// / sink instructions, differing in the number of instructions sunk,
10499// / the number of predecessors sunk from and the number of PHIs
@@ -125,14 +120,6 @@ struct SinkingInstructionCandidate {
125120 }
126121};
127122
128- #ifndef NDEBUG
129- raw_ostream &operator <<(raw_ostream &OS, const SinkingInstructionCandidate &C) {
130- OS << " <Candidate Cost=" << C.Cost << " #Blocks=" << C.NumBlocks
131- << " #Insts=" << C.NumInstructions << " #PHIs=" << C.NumPHIs << " >" ;
132- return OS;
133- }
134- #endif
135-
136123// ===----------------------------------------------------------------------===//
137124
138125// / Describes a PHI node that may or may not exist. These track the PHIs
@@ -256,8 +243,18 @@ class ModelledPHI {
256243 return Values == Other.Values && Blocks == Other.Blocks ;
257244 }
258245};
246+ } // namespace
259247
260- template <typename ModelledPHI> struct DenseMapInfo {
248+ #ifndef NDEBUG
249+ static raw_ostream &operator <<(raw_ostream &OS,
250+ const SinkingInstructionCandidate &C) {
251+ OS << " <Candidate Cost=" << C.Cost << " #Blocks=" << C.NumBlocks
252+ << " #Insts=" << C.NumInstructions << " #PHIs=" << C.NumPHIs << " >" ;
253+ return OS;
254+ }
255+ #endif
256+
257+ template <> struct llvm ::DenseMapInfo<ModelledPHI> {
261258 static inline ModelledPHI &getEmptyKey () {
262259 static ModelledPHI Dummy = ModelledPHI::createDummy (0 );
263260 return Dummy;
@@ -275,7 +272,9 @@ template <typename ModelledPHI> struct DenseMapInfo {
275272 }
276273};
277274
278- using ModelledPHISet = DenseSet<ModelledPHI, DenseMapInfo<ModelledPHI>>;
275+ using ModelledPHISet = DenseSet<ModelledPHI>;
276+
277+ namespace {
279278
280279// ===----------------------------------------------------------------------===//
281280// ValueTable
@@ -594,6 +593,7 @@ class GVNSink {
594593 }
595594 }
596595};
596+ } // namespace
597597
598598std::optional<SinkingInstructionCandidate>
599599GVNSink::analyzeInstructionForSinking (LockstepReverseIterator<false > &LRI,
@@ -851,8 +851,6 @@ void GVNSink::sinkLastInstruction(ArrayRef<BasicBlock *> Blocks,
851851 NumRemoved += Insts.size () - 1 ;
852852}
853853
854- } // end anonymous namespace
855-
856854PreservedAnalyses GVNSinkPass::run (Function &F, FunctionAnalysisManager &AM) {
857855 GVNSink G;
858856 if (!G.run (F))
0 commit comments