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 
insert(ArrayRef<std::pair<TypeID,void * >> elements)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       free(element.second);
32       continue;
33     }
34     interfaces.insert(it, element);
35   }
36 }
37