Skip to content

Commit e938e02

Browse files
authored
[NFC][LLVM] Namespace cleanup in GVNSink (#163305)
1 parent 1394e39 commit e938e02

File tree

1 file changed

+23
-25
lines changed

1 file changed

+23
-25
lines changed

llvm/lib/Transforms/Scalar/GVNSink.cpp

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,17 @@
7373
#include <utility>
7474

7575
using namespace llvm;
76+
using namespace llvm::GVNExpression;
7677

7778
#define DEBUG_TYPE "gvn-sink"
7879

7980
STATISTIC(NumRemoved, "Number of instructions removed");
8081

81-
namespace llvm {
82-
namespace GVNExpression {
83-
8482
LLVM_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-
9487
static 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
@@ -290,15 +289,15 @@ using ModelledPHISet = DenseSet<ModelledPHI, DenseMapInfo<ModelledPHI>>;
290289
///
291290
/// This class also contains fields for discriminators used when determining
292291
/// equivalence of instructions with sideeffects.
293-
class InstructionUseExpr : public GVNExpression::BasicExpression {
292+
class InstructionUseExpr : public BasicExpression {
294293
unsigned MemoryUseOrder = -1;
295294
bool Volatile = false;
296295
ArrayRef<int> ShuffleMask;
297296

298297
public:
299298
InstructionUseExpr(Instruction *I, ArrayRecycler<Value *> &R,
300299
BumpPtrAllocator &A)
301-
: GVNExpression::BasicExpression(I->getNumUses()) {
300+
: BasicExpression(I->getNumUses()) {
302301
allocateOperands(R, A);
303302
setOpcode(I->getOpcode());
304303
setType(I->getType());
@@ -315,8 +314,8 @@ class InstructionUseExpr : public GVNExpression::BasicExpression {
315314
void setVolatile(bool V) { Volatile = V; }
316315

317316
hash_code getHashValue() const override {
318-
return hash_combine(GVNExpression::BasicExpression::getHashValue(),
319-
MemoryUseOrder, Volatile, ShuffleMask);
317+
return hash_combine(BasicExpression::getHashValue(), MemoryUseOrder,
318+
Volatile, ShuffleMask);
320319
}
321320

322321
template <typename Function> hash_code getHashValue(Function MapFn) {
@@ -332,7 +331,7 @@ using BasicBlocksSet = SmallPtrSet<const BasicBlock *, 32>;
332331

333332
class ValueTable {
334333
DenseMap<Value *, uint32_t> ValueNumbering;
335-
DenseMap<GVNExpression::Expression *, uint32_t> ExpressionNumbering;
334+
DenseMap<Expression *, uint32_t> ExpressionNumbering;
336335
DenseMap<size_t, uint32_t> HashNumbering;
337336
BumpPtrAllocator Allocator;
338337
ArrayRecycler<Value *> Recycler;
@@ -594,6 +593,7 @@ class GVNSink {
594593
}
595594
}
596595
};
596+
} // namespace
597597

598598
std::optional<SinkingInstructionCandidate>
599599
GVNSink::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-
856854
PreservedAnalyses GVNSinkPass::run(Function &F, FunctionAnalysisManager &AM) {
857855
GVNSink G;
858856
if (!G.run(F))

0 commit comments

Comments
 (0)