From 60682592c698e6b6e7a1c4e46d8a7ba7007757c9 Mon Sep 17 00:00:00 2001 From: Thomas Symalla Date: Tue, 17 Oct 2023 13:42:15 +0200 Subject: [PATCH] [OpMap] Fix GCC compiler warnings. GCC spotted the following warnings: a) Parenthesis usage around assert in complexSet is not correct in ExampleMain b) OpMap::m_dialectOps uses the anonymous namespace indirectly (-Wsubobject-linkage) --- example/ExampleMain.cpp | 4 +- include/llvm-dialects/Dialect/OpMap.h | 81 ++++++++++++--------------- 2 files changed, 38 insertions(+), 47 deletions(-) diff --git a/example/ExampleMain.cpp b/example/ExampleMain.cpp index cc3b97e..91203cc 100644 --- a/example/ExampleMain.cpp +++ b/example/ExampleMain.cpp @@ -191,9 +191,9 @@ template const Visitor &getExampleVisitor() { }); b.addSet(complexSet, [](VisitorNest &self, llvm::Instruction &op) { assert((op.getOpcode() == Instruction::Ret || - (isa)(&op) && + (isa(&op) && cast(&op)->getIntrinsicID() == - Intrinsic::umin) && + Intrinsic::umin)) && "Unexpected operation detected while visiting OpSet!"); if (op.getOpcode() == Instruction::Ret) { diff --git a/include/llvm-dialects/Dialect/OpMap.h b/include/llvm-dialects/Dialect/OpMap.h index 6eacb3f..8324a03 100644 --- a/include/llvm-dialects/Dialect/OpMap.h +++ b/include/llvm-dialects/Dialect/OpMap.h @@ -37,35 +37,6 @@ using namespace llvm; using namespace llvm_dialects; -namespace { - -using DialectOpKey = std::pair; - -class DialectOpKVUtils { -public: - static DialectOpKey getDialectMapKey(const OpDescription &desc) { - return {desc.getMnemonic(), - desc.getKind() == OpDescription::Kind::DialectWithOverloads}; - } -}; - -template struct DialectOpKV final { - DialectOpKey Key; - ValueT Value; - - bool operator==(const DialectOpKV &other) const { - return Key.first == other.Key.first && Key.second == other.Key.second && - Value == other.Value; - } - - bool operator==(const OpDescription &desc) const { - const bool isOverload = - desc.getKind() == OpDescription::Kind::DialectWithOverloads; - return Key.first == desc.getMnemonic() && Key.second == isOverload; - } -}; -} // namespace - namespace llvm_dialects { // Forward declarations. @@ -87,7 +58,23 @@ template class OpMap final { friend class OpMapIteratorBase; friend class OpMapIteratorBase; - using DialectOpKVT = DialectOpKV; + using DialectOpKey = std::pair; + + struct DialectOpKV final { + DialectOpKey Key; + ValueT Value; + + bool operator==(const DialectOpKV &other) const { + return Key.first == other.Key.first && Key.second == other.Key.second && + Value == other.Value; + } + + bool operator==(const OpDescription &desc) const { + const bool isOverload = + desc.getKind() == OpDescription::Kind::DialectWithOverloads; + return Key.first == desc.getMnemonic() && Key.second == isOverload; + } + }; public: using iterator = OpMapIteratorBase; @@ -159,7 +146,7 @@ template class OpMap final { (desc.isIntrinsic() && containsIntrinsic(op)); } - for (const DialectOpKVT &dialectOpKV : m_dialectOps) { + for (const DialectOpKV &dialectOpKV : m_dialectOps) { if (dialectOpKV == desc) return true; } @@ -247,7 +234,7 @@ template class OpMap final { // -------------------------------------------------------------------------- template std::pair try_emplace(const OpDescription &desc, - Ts &&... vals) { + Ts &&...vals) { auto found = find(const_cast(desc)); if (found) return {found, false}; @@ -271,7 +258,7 @@ template class OpMap final { // Find the iterator into the dialect ops. size_t Idx = 0; - for (DialectOpKVT &dialectOpKV : m_dialectOps) { + for (DialectOpKV &dialectOpKV : m_dialectOps) { if (dialectOpKV == desc) { auto it = m_dialectOps.begin(); std::advance(it, Idx); @@ -284,9 +271,9 @@ template class OpMap final { // If the entry doesn't exist, construct it and return an iterator to the // end of dialect ops. - auto it = m_dialectOps.insert( - m_dialectOps.end(), - {DialectOpKVUtils::getDialectMapKey(desc), std::forward(vals)...}); + auto it = + m_dialectOps.insert(m_dialectOps.end(), {getDialectMapKey(desc), + std::forward(vals)...}); return {makeIterator(it, OpDescription::Kind::Dialect, false), true}; } @@ -392,16 +379,21 @@ template class OpMap final { private: DenseMap m_coreOpcodes; DenseMap m_intrinsics; - SmallVector m_dialectOps; + SmallVector m_dialectOps; - template iterator makeIterator(Args &&... args) { + template iterator makeIterator(Args &&...args) { return iterator(this, std::forward(args)...); } template - const_iterator makeConstIterator(Args &&... args) const { + const_iterator makeConstIterator(Args &&...args) const { return const_iterator(this, std::forward(args)...); } + + static DialectOpKey getDialectMapKey(const OpDescription &desc) { + return {desc.getMnemonic(), + desc.getKind() == OpDescription::Kind::DialectWithOverloads}; + } }; /// A simple iterator operating on the internal data structures of the OpMap. It @@ -412,19 +404,18 @@ template class OpMap final { /// Note that iterating over an OpMap instance never guarantees the order of /// insertion. template class OpMapIteratorBase final { + using OpMapT = + std::conditional_t, OpMap>; using BaseIteratorT = std::conditional_t::const_iterator, typename DenseMap::iterator>; using DialectOpIteratorT = std::conditional_t< - isConst, typename SmallVectorImpl>::const_iterator, - typename SmallVectorImpl>::iterator>; + isConst, typename SmallVectorImpl::const_iterator, + typename SmallVectorImpl::iterator>; using InternalValueT = std::conditional_t; - using OpMapT = - std::conditional_t, OpMap>; - friend class OpMap; friend class OpMapIteratorBase; friend class OpMapIteratorBase; @@ -723,7 +714,7 @@ template class OpMapIteratorBase final { size_t idx = 0; bool found = false; for (auto &dialectOpKV : m_map->m_dialectOps) { - const DialectOpKey &key = dialectOpKV.Key; + const auto &key = dialectOpKV.Key; if (detail::isOperationDecl(funcName, key.second, key.first)) { m_desc = {key.second, key.first}; auto it = m_map->m_dialectOps.begin();