Skip to content

Commit 9e2ad76

Browse files
authored
Remove using namespace (#74)
Using namespace in headers is prone to generate conflicts, so specify the namespace explicitly.
1 parent a901f39 commit 9e2ad76

File tree

2 files changed

+45
-43
lines changed

2 files changed

+45
-43
lines changed

include/llvm-dialects/Dialect/OpMap.h

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@
3434
#include <tuple>
3535
#include <type_traits>
3636

37-
using namespace llvm;
38-
using namespace llvm_dialects;
39-
4037
namespace llvm_dialects {
4138

4239
// Forward declarations.
@@ -58,7 +55,7 @@ template <typename ValueT> class OpMap final {
5855
friend class OpMapIteratorBase<ValueT, true>;
5956
friend class OpMapIteratorBase<ValueT, false>;
6057

61-
using DialectOpKey = std::pair<StringRef, bool>;
58+
using DialectOpKey = std::pair<llvm::StringRef, bool>;
6259

6360
struct DialectOpKV final {
6461
DialectOpKey Key;
@@ -179,10 +176,10 @@ template <typename ValueT> class OpMap final {
179176

180177
FIND_OVERLOAD(OpDescription)
181178
FIND_CONST_OVERLOAD(OpDescription)
182-
FIND_OVERLOAD(Function)
183-
FIND_CONST_OVERLOAD(Function)
184-
FIND_OVERLOAD(Instruction)
185-
FIND_CONST_OVERLOAD(Instruction)
179+
FIND_OVERLOAD(llvm::Function)
180+
FIND_CONST_OVERLOAD(llvm::Function)
181+
FIND_OVERLOAD(llvm::Instruction)
182+
FIND_CONST_OVERLOAD(llvm::Instruction)
186183

187184
#undef FIND_CONST_OVERLOAD
188185
#undef FIND_OVERLOAD
@@ -207,7 +204,7 @@ template <typename ValueT> class OpMap final {
207204

208205
// Try to lookup a function which is either the callee of an intrinsic call
209206
// or a dialect operation.
210-
ValueT lookup(const Function &func) const {
207+
ValueT lookup(const llvm::Function &func) const {
211208
auto it = find(func);
212209
if (auto val = it.val(); val)
213210
return *val;
@@ -217,7 +214,7 @@ template <typename ValueT> class OpMap final {
217214

218215
// Try to lookup an instruction which is either an intrinsic instruction,
219216
// a dialect operation or a core instruction.
220-
ValueT lookup(const Instruction &inst) const {
217+
ValueT lookup(const llvm::Instruction &inst) const {
221218
auto it = find(inst);
222219
if (auto val = it.val(); val)
223220
return *val;
@@ -377,9 +374,9 @@ template <typename ValueT> class OpMap final {
377374
#undef GENERATE_ITERATOR_BODY
378375

379376
private:
380-
DenseMap<unsigned, ValueT> m_coreOpcodes;
381-
DenseMap<unsigned, ValueT> m_intrinsics;
382-
SmallVector<DialectOpKV, 1> m_dialectOps;
377+
llvm::DenseMap<unsigned, ValueT> m_coreOpcodes;
378+
llvm::DenseMap<unsigned, ValueT> m_intrinsics;
379+
llvm::SmallVector<DialectOpKV, 1> m_dialectOps;
383380

384381
template <typename... Args> iterator makeIterator(Args &&...args) {
385382
return iterator(this, std::forward<Args>(args)...);
@@ -406,13 +403,14 @@ template <typename ValueT> class OpMap final {
406403
template <typename ValueT, bool isConst> class OpMapIteratorBase final {
407404
using OpMapT =
408405
std::conditional_t<isConst, const OpMap<ValueT>, OpMap<ValueT>>;
409-
using BaseIteratorT =
410-
std::conditional_t<isConst,
411-
typename DenseMap<unsigned, ValueT>::const_iterator,
412-
typename DenseMap<unsigned, ValueT>::iterator>;
406+
using BaseIteratorT = std::conditional_t<
407+
isConst, typename llvm::DenseMap<unsigned, ValueT>::const_iterator,
408+
typename llvm::DenseMap<unsigned, ValueT>::iterator>;
413409
using DialectOpIteratorT = std::conditional_t<
414-
isConst, typename SmallVectorImpl<typename OpMapT::DialectOpKV>::const_iterator,
415-
typename SmallVectorImpl<typename OpMapT::DialectOpKV>::iterator>;
410+
isConst,
411+
typename llvm::SmallVectorImpl<
412+
typename OpMapT::DialectOpKV>::const_iterator,
413+
typename llvm::SmallVectorImpl<typename OpMapT::DialectOpKV>::iterator>;
416414

417415
using InternalValueT = std::conditional_t<isConst, const ValueT, ValueT>;
418416

@@ -598,15 +596,15 @@ template <typename ValueT, bool isConst> class OpMapIteratorBase final {
598596
}
599597
}
600598

601-
OpMapIteratorBase(OpMapT *map, const Function &func) : m_map{map} {
599+
OpMapIteratorBase(OpMapT *map, const llvm::Function &func) : m_map{map} {
602600
createFromFunc(func);
603601
}
604602

605603
// Do a lookup for a given instruction. Mark the iterator as invalid
606604
// if the instruction is a call-like core instruction.
607-
OpMapIteratorBase(OpMapT *map, const Instruction &inst) : m_map{map} {
608-
if (auto *CI = dyn_cast<CallInst>(&inst)) {
609-
const Function *callee = CI->getCalledFunction();
605+
OpMapIteratorBase(OpMapT *map, const llvm::Instruction &inst) : m_map{map} {
606+
if (auto *CI = llvm::dyn_cast<llvm::CallInst>(&inst)) {
607+
const llvm::Function *callee = CI->getCalledFunction();
610608
if (callee) {
611609
createFromFunc(*callee);
612610
return;
@@ -616,7 +614,7 @@ template <typename ValueT, bool isConst> class OpMapIteratorBase final {
616614
const unsigned op = inst.getOpcode();
617615

618616
// Construct an invalid iterator.
619-
if (op == Instruction::Call || op == Instruction::CallBr) {
617+
if (op == llvm::Instruction::Call || op == llvm::Instruction::CallBr) {
620618
invalidate();
621619
return;
622620
}
@@ -697,7 +695,7 @@ template <typename ValueT, bool isConst> class OpMapIteratorBase final {
697695
private:
698696
void invalidate() { m_isInvalid = true; }
699697

700-
void createFromFunc(const Function &func) {
698+
void createFromFunc(const llvm::Function &func) {
701699
if (func.isIntrinsic()) {
702700
m_iterator = m_map->m_intrinsics.find(func.getIntrinsicID());
703701

@@ -710,7 +708,7 @@ template <typename ValueT, bool isConst> class OpMapIteratorBase final {
710708
createFromDialectOp(func.getName());
711709
}
712710

713-
void createFromDialectOp(StringRef funcName) {
711+
void createFromDialectOp(llvm::StringRef funcName) {
714712
size_t idx = 0;
715713
bool found = false;
716714
for (auto &dialectOpKV : m_map->m_dialectOps) {

include/llvm-dialects/Dialect/OpSet.h

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,10 @@
3232
#include "llvm/IR/Instruction.h"
3333
#include "llvm/IR/Instructions.h"
3434

35-
using namespace llvm;
36-
3735
namespace llvm_dialects {
3836

3937
struct DialectOpPair final {
40-
StringRef mnemonic;
38+
llvm::StringRef mnemonic;
4139
bool isOverload;
4240

4341
// Checks whether the current pair is comparable to an OpDescription
@@ -63,7 +61,7 @@ class OpSet final {
6361
// -------------------------------------------------------------
6462

6563
// Construct an OpSet from a set of core opcodes.
66-
static OpSet fromCoreOpcodes(ArrayRef<unsigned> ops) {
64+
static OpSet fromCoreOpcodes(llvm::ArrayRef<unsigned> ops) {
6765
OpSet set;
6866
for (const unsigned op : ops)
6967
set.m_coreOpcodes.insert(op);
@@ -72,7 +70,7 @@ class OpSet final {
7270
}
7371

7472
// Construct an OpSet from a set of intrinsics.
75-
static OpSet fromIntrinsicIDs(ArrayRef<unsigned> intrinsicIDs) {
73+
static OpSet fromIntrinsicIDs(llvm::ArrayRef<unsigned> intrinsicIDs) {
7674
OpSet set;
7775
for (const unsigned intrinsicID : intrinsicIDs)
7876
set.m_intrinsicIDs.insert(intrinsicID);
@@ -81,7 +79,7 @@ class OpSet final {
8179
}
8280

8381
// Construct an OpSet from a set of OpDescriptions.
84-
static OpSet fromOpDescriptions(ArrayRef<OpDescription> descs) {
82+
static OpSet fromOpDescriptions(llvm::ArrayRef<OpDescription> descs) {
8583
OpSet set;
8684
for (const OpDescription &desc : descs)
8785
set.tryInsertOp(desc);
@@ -132,12 +130,12 @@ class OpSet final {
132130
}
133131

134132
// Checks if `inst` belongs to the OpSet.
135-
bool contains(const Instruction &inst) const {
133+
bool contains(const llvm::Instruction &inst) const {
136134
if (containsCoreOp(inst.getOpcode()))
137135
return true;
138136

139-
if (auto *CI = dyn_cast<CallInst>(&inst)) {
140-
const Function *Callee = CI->getCalledFunction();
137+
if (auto *CI = llvm::dyn_cast<llvm::CallInst>(&inst)) {
138+
const llvm::Function *Callee = CI->getCalledFunction();
141139
if (!Callee)
142140
return false;
143141

@@ -148,7 +146,7 @@ class OpSet final {
148146
}
149147

150148
// Checks if `func` belongs to the OpSet.
151-
bool contains(const Function &func) const {
149+
bool contains(const llvm::Function &func) const {
152150
if (func.isIntrinsic() && containsIntrinsicID(func.getIntrinsicID()))
153151
return true;
154152

@@ -158,11 +156,17 @@ class OpSet final {
158156
// -------------------------------------------------------------
159157
// Convenience getters to access the internal data structures.
160158
// -------------------------------------------------------------
161-
const DenseSet<unsigned> &getCoreOpcodes() const { return m_coreOpcodes; }
159+
const llvm::DenseSet<unsigned> &getCoreOpcodes() const {
160+
return m_coreOpcodes;
161+
}
162162

163-
const DenseSet<unsigned> &getIntrinsicIDs() const { return m_intrinsicIDs; }
163+
const llvm::DenseSet<unsigned> &getIntrinsicIDs() const {
164+
return m_intrinsicIDs;
165+
}
164166

165-
const ArrayRef<DialectOpPair> getDialectOps() const { return m_dialectOps; }
167+
const llvm::ArrayRef<DialectOpPair> getDialectOps() const {
168+
return m_dialectOps;
169+
}
166170

167171
private:
168172
// Generates an `OpDescription` for a given `OpT`, extracts the
@@ -176,7 +180,7 @@ class OpSet final {
176180

177181
// Checks if `mnemonic` can be described by any of the stored dialect
178182
// operations.
179-
bool isMatchingDialectOp(StringRef mnemonic) const {
183+
bool isMatchingDialectOp(llvm::StringRef mnemonic) const {
180184
for (const auto &dialectOp : m_dialectOps) {
181185
if (detail::isOperationDecl(mnemonic, dialectOp.isOverload,
182186
dialectOp.mnemonic))
@@ -211,8 +215,8 @@ class OpSet final {
211215
return desc.getKind() == OpDescription::Kind::DialectWithOverloads;
212216
}
213217

214-
DenseSet<unsigned> m_coreOpcodes;
215-
DenseSet<unsigned> m_intrinsicIDs;
216-
SmallVector<DialectOpPair, 1> m_dialectOps;
218+
llvm::DenseSet<unsigned> m_coreOpcodes;
219+
llvm::DenseSet<unsigned> m_intrinsicIDs;
220+
llvm::SmallVector<DialectOpPair, 1> m_dialectOps;
217221
};
218222
} // namespace llvm_dialects

0 commit comments

Comments
 (0)