Skip to content

Commit e0c2e79

Browse files
d0kkiranchandramohan
authored andcommitted
[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 ef203f5 commit e0c2e79

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
@@ -15,11 +15,8 @@
1515

1616
#include "mlir/Support/TypeID.h"
1717
#include "llvm/ADT/DenseMap.h"
18-
#include "llvm/Support/Debug.h"
1918
#include "llvm/Support/TypeName.h"
2019

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

249234
private:
@@ -254,6 +239,8 @@ class InterfaceMap {
254239

255240
InterfaceMap() = default;
256241

242+
void insert(ArrayRef<std::pair<TypeID, void *>> elements);
243+
257244
template <typename... Ts>
258245
static InterfaceMap getImpl(std::tuple<Ts...> *) {
259246
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)