xref: /llvm-project/mlir/lib/Support/InterfaceSupport.cpp (revision 891fad0448fc560877e67c980754c1c4a5c83735)
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(TypeID interfaceId,void * conceptImpl)21 void detail::InterfaceMap::insert(TypeID interfaceId, void *conceptImpl) {
22   // Insert directly into the right position to keep the interfaces sorted.
23   auto *it =
24       llvm::lower_bound(interfaces, interfaceId, [](const auto &it, TypeID id) {
25         return compare(it.first, id);
26       });
27   if (it != interfaces.end() && it->first == interfaceId) {
28     LLVM_DEBUG(llvm::dbgs() << "Ignoring repeated interface registration\n");
29     free(conceptImpl);
30     return;
31   }
32   interfaces.insert(it, {interfaceId, conceptImpl});
33 }
34