Skip to content

Commit c878d03

Browse files
committed
[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.
1 parent cdb4fcf commit c878d03

File tree

3 files changed

+40
-16
lines changed

3 files changed

+40
-16
lines changed

mlir/include/mlir/Support/InterfaceSupport.h

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,8 @@
1616
#include "mlir/Support/TypeID.h"
1717
#include "llvm/ADT/ArrayRef.h"
1818
#include "llvm/ADT/DenseMap.h"
19-
#include "llvm/Support/Debug.h"
2019
#include "llvm/Support/TypeName.h"
2120

22-
#define DEBUG_TYPE "interfaces"
23-
2421
namespace mlir {
2522
namespace detail {
2623
//===----------------------------------------------------------------------===//
@@ -232,19 +229,7 @@ class InterfaceMap {
232229
std::pair<TypeID, void *> elements[] = {
233230
std::make_pair(IfaceModels::Interface::getInterfaceID(),
234231
new (malloc(sizeof(IfaceModels))) IfaceModels())...};
235-
// Insert directly into the right position to keep the interfaces sorted.
236-
for (auto &element : elements) {
237-
TypeID id = element.first;
238-
auto it =
239-
llvm::lower_bound(interfaces, id, [](const auto &it, TypeID id) {
240-
return compare(it.first, id);
241-
});
242-
if (it != interfaces.end() && it->first == id) {
243-
LLVM_DEBUG(llvm::dbgs() << "Ignoring repeated interface registration");
244-
continue;
245-
}
246-
interfaces.insert(it, element);
247-
}
232+
insert(elements);
248233
}
249234

250235
private:
@@ -255,6 +240,8 @@ class InterfaceMap {
255240

256241
InterfaceMap() = default;
257242

243+
void insert(ArrayRef<std::pair<TypeID, void *>> elements);
244+
258245
template <typename... Ts>
259246
static InterfaceMap getImpl(std::tuple<Ts...> *) {
260247
std::pair<TypeID, void *> elements[] = {std::make_pair(

mlir/lib/Support/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ set(LLVM_OPTIONAL_SOURCES
22
DebugCounter.cpp
33
FileUtilities.cpp
44
IndentedOstream.cpp
5+
InterfaceSupport.cpp
56
MlirOptMain.cpp
67
StorageUniquer.cpp
78
Timing.cpp
@@ -11,6 +12,7 @@ set(LLVM_OPTIONAL_SOURCES
1112
add_mlir_library(MLIRSupport
1213
DebugCounter.cpp
1314
FileUtilities.cpp
15+
InterfaceSupport.cpp
1416
StorageUniquer.cpp
1517
Timing.cpp
1618
ToolUtilities.cpp

mlir/lib/Support/InterfaceSupport.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//===- InterfaceSupport.cpp - MLIR Interface Support Classes --------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file defines several support classes for defining interfaces.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include "mlir/Support/InterfaceSupport.h"
14+
#include "llvm/Support/Debug.h"
15+
#include "llvm/Support/raw_ostream.h"
16+
17+
#define DEBUG_TYPE "interfaces"
18+
19+
using namespace mlir;
20+
21+
void detail::InterfaceMap::insert(
22+
ArrayRef<std::pair<TypeID, void *>> elements) {
23+
// Insert directly into the right position to keep the interfaces sorted.
24+
for (auto &element : elements) {
25+
TypeID id = element.first;
26+
auto *it = llvm::lower_bound(interfaces, id, [](const auto &it, TypeID id) {
27+
return compare(it.first, id);
28+
});
29+
if (it != interfaces.end() && it->first == id) {
30+
LLVM_DEBUG(llvm::dbgs() << "Ignoring repeated interface registration");
31+
continue;
32+
}
33+
interfaces.insert(it, element);
34+
}
35+
}

0 commit comments

Comments
 (0)