[Mlir-commits] [mlir] c878d03 - [mlir] Split things dependent on LLVM_DEBUG into a .cpp file
Benjamin Kramer
llvmlistbot at llvm.org
Thu Jun 17 06:08:33 PDT 2021
Author: Benjamin Kramer
Date: 2021-06-17T15:06:40+02:00
New Revision: c878d03d60fc91ecad661f4435ce70bf276f3bdb
URL: https://github.com/llvm/llvm-project/commit/c878d03d60fc91ecad661f4435ce70bf276f3bdb
DIFF: https://github.com/llvm/llvm-project/commit/c878d03d60fc91ecad661f4435ce70bf276f3bdb.diff
LOG: [mlir] Split things dependent on LLVM_DEBUG into a .cpp file
LLVM_DEBUG in headers is awkward, better avoid it. DEBUG_TYPE in a
header results in a lot of macro redefinition warnings.
Added:
mlir/lib/Support/InterfaceSupport.cpp
Modified:
mlir/include/mlir/Support/InterfaceSupport.h
mlir/lib/Support/CMakeLists.txt
Removed:
################################################################################
diff --git a/mlir/include/mlir/Support/InterfaceSupport.h b/mlir/include/mlir/Support/InterfaceSupport.h
index 8e794ed52d918..e5d526b1ae515 100644
--- a/mlir/include/mlir/Support/InterfaceSupport.h
+++ b/mlir/include/mlir/Support/InterfaceSupport.h
@@ -16,11 +16,8 @@
#include "mlir/Support/TypeID.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
-#include "llvm/Support/Debug.h"
#include "llvm/Support/TypeName.h"
-#define DEBUG_TYPE "interfaces"
-
namespace mlir {
namespace detail {
//===----------------------------------------------------------------------===//
@@ -232,19 +229,7 @@ class InterfaceMap {
std::pair<TypeID, void *> elements[] = {
std::make_pair(IfaceModels::Interface::getInterfaceID(),
new (malloc(sizeof(IfaceModels))) IfaceModels())...};
- // Insert directly into the right position to keep the interfaces sorted.
- for (auto &element : elements) {
- TypeID id = element.first;
- auto it =
- llvm::lower_bound(interfaces, id, [](const auto &it, TypeID id) {
- return compare(it.first, id);
- });
- if (it != interfaces.end() && it->first == id) {
- LLVM_DEBUG(llvm::dbgs() << "Ignoring repeated interface registration");
- continue;
- }
- interfaces.insert(it, element);
- }
+ insert(elements);
}
private:
@@ -255,6 +240,8 @@ class InterfaceMap {
InterfaceMap() = default;
+ void insert(ArrayRef<std::pair<TypeID, void *>> elements);
+
template <typename... Ts>
static InterfaceMap getImpl(std::tuple<Ts...> *) {
std::pair<TypeID, void *> elements[] = {std::make_pair(
diff --git a/mlir/lib/Support/CMakeLists.txt b/mlir/lib/Support/CMakeLists.txt
index 4572423ab6b7c..633c4c82146b9 100644
--- a/mlir/lib/Support/CMakeLists.txt
+++ b/mlir/lib/Support/CMakeLists.txt
@@ -2,6 +2,7 @@ set(LLVM_OPTIONAL_SOURCES
DebugCounter.cpp
FileUtilities.cpp
IndentedOstream.cpp
+ InterfaceSupport.cpp
MlirOptMain.cpp
StorageUniquer.cpp
Timing.cpp
@@ -11,6 +12,7 @@ set(LLVM_OPTIONAL_SOURCES
add_mlir_library(MLIRSupport
DebugCounter.cpp
FileUtilities.cpp
+ InterfaceSupport.cpp
StorageUniquer.cpp
Timing.cpp
ToolUtilities.cpp
diff --git a/mlir/lib/Support/InterfaceSupport.cpp b/mlir/lib/Support/InterfaceSupport.cpp
new file mode 100644
index 0000000000000..b282121b30644
--- /dev/null
+++ b/mlir/lib/Support/InterfaceSupport.cpp
@@ -0,0 +1,35 @@
+//===- InterfaceSupport.cpp - MLIR Interface Support Classes --------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines several support classes for defining interfaces.
+//
+//===----------------------------------------------------------------------===//
+
+#include "mlir/Support/InterfaceSupport.h"
+#include "llvm/Support/Debug.h"
+#include "llvm/Support/raw_ostream.h"
+
+#define DEBUG_TYPE "interfaces"
+
+using namespace mlir;
+
+void detail::InterfaceMap::insert(
+ ArrayRef<std::pair<TypeID, void *>> elements) {
+ // Insert directly into the right position to keep the interfaces sorted.
+ for (auto &element : elements) {
+ TypeID id = element.first;
+ auto *it = llvm::lower_bound(interfaces, id, [](const auto &it, TypeID id) {
+ return compare(it.first, id);
+ });
+ if (it != interfaces.end() && it->first == id) {
+ LLVM_DEBUG(llvm::dbgs() << "Ignoring repeated interface registration");
+ continue;
+ }
+ interfaces.insert(it, element);
+ }
+}
More information about the Mlir-commits
mailing list