Skip to content

Commit bea786d

Browse files
authored
[NFC][LLVM] Use namespace qualifier to define DenseMapInfo specializations (llvm#162683)
Use `llvm::DenseMapInfo` to define `DenseMapInfo` specializations instead of surrounding it with `namespace llvm {}`.
1 parent 0a21b06 commit bea786d

File tree

8 files changed

+32
-70
lines changed

8 files changed

+32
-70
lines changed

llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,19 +1033,17 @@ class IndexCallsiteContextGraph
10331033
};
10341034
} // namespace
10351035

1036-
namespace llvm {
10371036
template <>
1038-
struct DenseMapInfo<typename CallsiteContextGraph<
1037+
struct llvm::DenseMapInfo<typename CallsiteContextGraph<
10391038
ModuleCallsiteContextGraph, Function, Instruction *>::CallInfo>
10401039
: public DenseMapInfo<std::pair<Instruction *, unsigned>> {};
10411040
template <>
1042-
struct DenseMapInfo<typename CallsiteContextGraph<
1041+
struct llvm::DenseMapInfo<typename CallsiteContextGraph<
10431042
IndexCallsiteContextGraph, FunctionSummary, IndexCall>::CallInfo>
10441043
: public DenseMapInfo<std::pair<IndexCall, unsigned>> {};
10451044
template <>
1046-
struct DenseMapInfo<IndexCall>
1045+
struct llvm::DenseMapInfo<IndexCall>
10471046
: public DenseMapInfo<PointerUnion<CallsiteInfo *, AllocInfo *>> {};
1048-
} // end namespace llvm
10491047

10501048
namespace {
10511049

llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,7 @@ struct VTableSlot {
372372

373373
} // end anonymous namespace
374374

375-
namespace llvm {
376-
377-
template <> struct DenseMapInfo<VTableSlot> {
375+
template <> struct llvm::DenseMapInfo<VTableSlot> {
378376
static VTableSlot getEmptyKey() {
379377
return {DenseMapInfo<Metadata *>::getEmptyKey(),
380378
DenseMapInfo<uint64_t>::getEmptyKey()};
@@ -393,7 +391,7 @@ template <> struct DenseMapInfo<VTableSlot> {
393391
}
394392
};
395393

396-
template <> struct DenseMapInfo<VTableSlotSummary> {
394+
template <> struct llvm::DenseMapInfo<VTableSlotSummary> {
397395
static VTableSlotSummary getEmptyKey() {
398396
return {DenseMapInfo<StringRef>::getEmptyKey(),
399397
DenseMapInfo<uint64_t>::getEmptyKey()};
@@ -412,8 +410,6 @@ template <> struct DenseMapInfo<VTableSlotSummary> {
412410
}
413411
};
414412

415-
} // end namespace llvm
416-
417413
// Returns true if the function must be unreachable based on ValueInfo.
418414
//
419415
// In particular, identifies a function as unreachable in the following

llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,27 +1069,22 @@ struct LoweredPHIRecord {
10691069
};
10701070
} // namespace
10711071

1072-
namespace llvm {
1073-
template<>
1074-
struct DenseMapInfo<LoweredPHIRecord> {
1075-
static inline LoweredPHIRecord getEmptyKey() {
1076-
return LoweredPHIRecord(nullptr, 0);
1077-
}
1078-
static inline LoweredPHIRecord getTombstoneKey() {
1079-
return LoweredPHIRecord(nullptr, 1);
1080-
}
1081-
static unsigned getHashValue(const LoweredPHIRecord &Val) {
1082-
return DenseMapInfo<PHINode*>::getHashValue(Val.PN) ^ (Val.Shift>>3) ^
1083-
(Val.Width>>3);
1084-
}
1085-
static bool isEqual(const LoweredPHIRecord &LHS,
1086-
const LoweredPHIRecord &RHS) {
1087-
return LHS.PN == RHS.PN && LHS.Shift == RHS.Shift &&
1088-
LHS.Width == RHS.Width;
1089-
}
1090-
};
1091-
} // namespace llvm
1092-
1072+
template <> struct llvm::DenseMapInfo<LoweredPHIRecord> {
1073+
static inline LoweredPHIRecord getEmptyKey() {
1074+
return LoweredPHIRecord(nullptr, 0);
1075+
}
1076+
static inline LoweredPHIRecord getTombstoneKey() {
1077+
return LoweredPHIRecord(nullptr, 1);
1078+
}
1079+
static unsigned getHashValue(const LoweredPHIRecord &Val) {
1080+
return DenseMapInfo<PHINode *>::getHashValue(Val.PN) ^ (Val.Shift >> 3) ^
1081+
(Val.Width >> 3);
1082+
}
1083+
static bool isEqual(const LoweredPHIRecord &LHS,
1084+
const LoweredPHIRecord &RHS) {
1085+
return LHS.PN == RHS.PN && LHS.Shift == RHS.Shift && LHS.Width == RHS.Width;
1086+
}
1087+
};
10931088

10941089
/// This is an integer PHI and we know that it has an illegal type: see if it is
10951090
/// only used by trunc or trunc(lshr) operations. If so, we split the PHI into

llvm/lib/Transforms/Scalar/EarlyCSE.cpp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ struct SimpleValue {
108108
// of instruction handled below (UnaryOperator, etc.).
109109
if (CallInst *CI = dyn_cast<CallInst>(Inst)) {
110110
if (Function *F = CI->getCalledFunction()) {
111-
switch ((Intrinsic::ID)F->getIntrinsicID()) {
111+
switch (F->getIntrinsicID()) {
112112
case Intrinsic::experimental_constrained_fadd:
113113
case Intrinsic::experimental_constrained_fsub:
114114
case Intrinsic::experimental_constrained_fmul:
@@ -154,9 +154,7 @@ struct SimpleValue {
154154

155155
} // end anonymous namespace
156156

157-
namespace llvm {
158-
159-
template <> struct DenseMapInfo<SimpleValue> {
157+
template <> struct llvm::DenseMapInfo<SimpleValue> {
160158
static inline SimpleValue getEmptyKey() {
161159
return DenseMapInfo<Instruction *>::getEmptyKey();
162160
}
@@ -169,8 +167,6 @@ template <> struct DenseMapInfo<SimpleValue> {
169167
static bool isEqual(SimpleValue LHS, SimpleValue RHS);
170168
};
171169

172-
} // end namespace llvm
173-
174170
/// Match a 'select' including an optional 'not's of the condition.
175171
static bool matchSelectWithOptionalNotCond(Value *V, Value *&Cond, Value *&A,
176172
Value *&B,
@@ -509,9 +505,7 @@ struct CallValue {
509505

510506
} // end anonymous namespace
511507

512-
namespace llvm {
513-
514-
template <> struct DenseMapInfo<CallValue> {
508+
template <> struct llvm::DenseMapInfo<CallValue> {
515509
static inline CallValue getEmptyKey() {
516510
return DenseMapInfo<Instruction *>::getEmptyKey();
517511
}
@@ -524,8 +518,6 @@ template <> struct DenseMapInfo<CallValue> {
524518
static bool isEqual(CallValue LHS, CallValue RHS);
525519
};
526520

527-
} // end namespace llvm
528-
529521
unsigned DenseMapInfo<CallValue>::getHashValue(CallValue Val) {
530522
Instruction *Inst = Val.Inst;
531523

@@ -580,9 +572,7 @@ struct GEPValue {
580572

581573
} // namespace
582574

583-
namespace llvm {
584-
585-
template <> struct DenseMapInfo<GEPValue> {
575+
template <> struct llvm::DenseMapInfo<GEPValue> {
586576
static inline GEPValue getEmptyKey() {
587577
return DenseMapInfo<Instruction *>::getEmptyKey();
588578
}
@@ -595,8 +585,6 @@ template <> struct DenseMapInfo<GEPValue> {
595585
static bool isEqual(const GEPValue &LHS, const GEPValue &RHS);
596586
};
597587

598-
} // end namespace llvm
599-
600588
unsigned DenseMapInfo<GEPValue>::getHashValue(const GEPValue &Val) {
601589
auto *GEP = cast<GetElementPtrInst>(Val.Inst);
602590
if (Val.ConstantOffset.has_value())

llvm/lib/Transforms/Scalar/GVN.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,7 @@ struct llvm::GVNPass::Expression {
170170
}
171171
};
172172

173-
namespace llvm {
174-
175-
template <> struct DenseMapInfo<GVNPass::Expression> {
173+
template <> struct llvm::DenseMapInfo<GVNPass::Expression> {
176174
static inline GVNPass::Expression getEmptyKey() { return ~0U; }
177175
static inline GVNPass::Expression getTombstoneKey() { return ~1U; }
178176

@@ -188,8 +186,6 @@ template <> struct DenseMapInfo<GVNPass::Expression> {
188186
}
189187
};
190188

191-
} // end namespace llvm
192-
193189
/// Represents a particular available value that we know how to materialize.
194190
/// Materialization of an AvailableValue never fails. An AvailableValue is
195191
/// implicitly associated with a rematerialization point which is the

llvm/lib/Transforms/Scalar/NewGVN.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -434,10 +434,6 @@ class CongruenceClass {
434434
int StoreCount = 0;
435435
};
436436

437-
} // end anonymous namespace
438-
439-
namespace llvm {
440-
441437
struct ExactEqualsExpression {
442438
const Expression &E;
443439

@@ -449,8 +445,9 @@ struct ExactEqualsExpression {
449445
return E.exactlyEquals(Other);
450446
}
451447
};
448+
} // end anonymous namespace
452449

453-
template <> struct DenseMapInfo<const Expression *> {
450+
template <> struct llvm::DenseMapInfo<const Expression *> {
454451
static const Expression *getEmptyKey() {
455452
auto Val = static_cast<uintptr_t>(-1);
456453
Val <<= PointerLikeTypeTraits<const Expression *>::NumLowBitsAvailable;
@@ -493,8 +490,6 @@ template <> struct DenseMapInfo<const Expression *> {
493490
}
494491
};
495492

496-
} // end namespace llvm
497-
498493
namespace {
499494

500495
class NewGVN {

llvm/lib/Transforms/Utils/CanonicalizeFreezeInLoops.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ class CanonicalizeFreezeInLoopsImpl {
8484
bool run();
8585
};
8686

87-
} // anonymous namespace
88-
89-
namespace llvm {
90-
9187
struct FrozenIndPHIInfo {
9288
// A freeze instruction that uses an induction phi
9389
FreezeInst *FI = nullptr;
@@ -103,7 +99,9 @@ struct FrozenIndPHIInfo {
10399
bool operator==(const FrozenIndPHIInfo &Other) { return FI == Other.FI; }
104100
};
105101

106-
template <> struct DenseMapInfo<FrozenIndPHIInfo> {
102+
} // namespace
103+
104+
template <> struct llvm::DenseMapInfo<FrozenIndPHIInfo> {
107105
static inline FrozenIndPHIInfo getEmptyKey() {
108106
return FrozenIndPHIInfo(DenseMapInfo<PHINode *>::getEmptyKey(),
109107
DenseMapInfo<BinaryOperator *>::getEmptyKey());
@@ -124,8 +122,6 @@ template <> struct DenseMapInfo<FrozenIndPHIInfo> {
124122
};
125123
};
126124

127-
} // end namespace llvm
128-
129125
// Given U = (value, user), replace value with freeze(value), and let
130126
// SCEV forget user. The inserted freeze is placed in the preheader.
131127
void CanonicalizeFreezeInLoopsImpl::InsertFreezeAndForgetFromSCEV(Use &U) {

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7740,8 +7740,7 @@ struct SwitchSuccWrapper {
77407740
DenseMap<PHINode *, SmallDenseMap<BasicBlock *, Value *, 8>> *PhiPredIVs;
77417741
};
77427742

7743-
namespace llvm {
7744-
template <> struct DenseMapInfo<const SwitchSuccWrapper *> {
7743+
template <> struct llvm::DenseMapInfo<const SwitchSuccWrapper *> {
77457744
static const SwitchSuccWrapper *getEmptyKey() {
77467745
return static_cast<SwitchSuccWrapper *>(
77477746
DenseMapInfo<void *>::getEmptyKey());
@@ -7809,7 +7808,6 @@ template <> struct DenseMapInfo<const SwitchSuccWrapper *> {
78097808
return true;
78107809
}
78117810
};
7812-
} // namespace llvm
78137811

78147812
bool SimplifyCFGOpt::simplifyDuplicateSwitchArms(SwitchInst *SI,
78157813
DomTreeUpdater *DTU) {

0 commit comments

Comments
 (0)