| 
 | 1 | +//===- SMTExtensionOps.cpp - SMT extension for the Transform dialect ------===//  | 
 | 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 | +#include "mlir/Dialect/Transform/SMTExtension/SMTExtensionOps.h"  | 
 | 10 | +#include "mlir/Dialect/SMT/IR/SMTDialect.h"  | 
 | 11 | +#include "mlir/Dialect/Transform/IR/TransformOps.h"  | 
 | 12 | +#include "mlir/Dialect/Transform/SMTExtension/SMTExtension.h"  | 
 | 13 | + | 
 | 14 | +using namespace mlir;  | 
 | 15 | + | 
 | 16 | +#define GET_OP_CLASSES  | 
 | 17 | +#include "mlir/Dialect/Transform/SMTExtension/SMTExtensionOps.cpp.inc"  | 
 | 18 | + | 
 | 19 | +//===----------------------------------------------------------------------===//  | 
 | 20 | +// ConstrainParamsOp  | 
 | 21 | +//===----------------------------------------------------------------------===//  | 
 | 22 | + | 
 | 23 | +void transform::smt::ConstrainParamsOp::getEffects(  | 
 | 24 | +    SmallVectorImpl<MemoryEffects::EffectInstance> &effects) {  | 
 | 25 | +  onlyReadsHandle(getParamsMutable(), effects);  | 
 | 26 | +}  | 
 | 27 | + | 
 | 28 | +DiagnosedSilenceableFailure  | 
 | 29 | +transform::smt::ConstrainParamsOp::apply(transform::TransformRewriter &rewriter,  | 
 | 30 | +                                         transform::TransformResults &results,  | 
 | 31 | +                                         transform::TransformState &state) {  | 
 | 32 | +  // TODO: Proper operational semantics are to check the SMT problem in the body  | 
 | 33 | +  //       with a SMT solver with the arguments of the body constrained to the  | 
 | 34 | +  //       values passed into the op. Success or failure is then determined by  | 
 | 35 | +  //       the solver's result.  | 
 | 36 | +  //       One way to support this is to just promise the TransformOpInterface  | 
 | 37 | +  //       and allow for users to attach their own implementation, which would,  | 
 | 38 | +  //       e.g., translate the ops to SMTLIB and hand that over to the user's  | 
 | 39 | +  //       favourite solver. This requires changes to the dialect's verifier.  | 
 | 40 | +  return emitDefiniteFailure() << "op does not have interpreted semantics yet";  | 
 | 41 | +}  | 
 | 42 | + | 
 | 43 | +LogicalResult transform::smt::ConstrainParamsOp::verify() {  | 
 | 44 | +  if (getOperands().size() != getBody().getNumArguments())  | 
 | 45 | +    return emitOpError(  | 
 | 46 | +        "must have the same number of block arguments as operands");  | 
 | 47 | + | 
 | 48 | +  for (auto &op : getBody().getOps()) {  | 
 | 49 | +    if (!isa<mlir::smt::SMTDialect>(op.getDialect()))  | 
 | 50 | +      return emitOpError(  | 
 | 51 | +          "ops contained in region should belong to SMT-dialect");  | 
 | 52 | +  }  | 
 | 53 | + | 
 | 54 | +  return success();  | 
 | 55 | +}  | 
0 commit comments