Files
clang-p2996/mlir/lib/Tools/PDLL/ODS/Dialect.cpp
River Riddle 1c2edb026e [mlir:PDLL] Rework the C++ generation of native Constraint/Rewrite arguments and results
The current translation uses the old "ugly"/"raw" form which used PDLValue for the arguments
and results. This commit updates the C++ generation to use the recently added sugar that
allows for directly using the desired types for the arguments and result of PDL functions.
In addition, this commit also properly imports the C++ class for ODS operations, constraints,
and interfaces. This allows for a much more convienent C++ API than previously granted
with the raw/low-level types.

Differential Revision: https://reviews.llvm.org/D124817
2022-05-30 17:35:34 -07:00

41 lines
1.6 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,
StringRef nativeClassName,
bool supportsResultTypeInferrence, 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, nativeClassName,
supportsResultTypeInferrence, 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;
}