This commit adds support for processing tablegen include files, and importing various information from ODS. This includes operations, attribute+type constraints, attribute/operation/type interfaces, etc. This will allow for much more robust tooling, and also allows for referencing ODS constructs directly within PDLL (imported interfaces can be used as constraints, operation result names can be used for member access, etc). Differential Revision: https://reviews.llvm.org/D119900
40 lines
1.5 KiB
C++
40 lines
1.5 KiB
C++
//===- Dialect.cpp --------------------------------------------------------===//
|
|
//
|
|
// 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "mlir/Tools/PDLL/ODS/Dialect.h"
|
|
#include "mlir/Tools/PDLL/ODS/Constraint.h"
|
|
#include "mlir/Tools/PDLL/ODS/Operation.h"
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
using namespace mlir;
|
|
using namespace mlir::pdll::ods;
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// Dialect
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
Dialect::Dialect(StringRef name) : name(name.str()) {}
|
|
Dialect::~Dialect() = default;
|
|
|
|
std::pair<Operation *, bool> Dialect::insertOperation(StringRef name,
|
|
StringRef summary,
|
|
StringRef desc,
|
|
llvm::SMLoc loc) {
|
|
std::unique_ptr<Operation> &operation = operations[name];
|
|
if (operation)
|
|
return std::make_pair(&*operation, /*wasInserted*/ false);
|
|
|
|
operation.reset(new Operation(name, summary, desc, loc));
|
|
return std::make_pair(&*operation, /*wasInserted*/ true);
|
|
}
|
|
|
|
Operation *Dialect::lookupOperation(StringRef name) const {
|
|
auto it = operations.find(name);
|
|
return it != operations.end() ? it->second.get() : nullptr;
|
|
}
|