MLIR  22.0.0git
TuneExtensionOps.cpp
Go to the documentation of this file.
1 //===- TuneExtensionOps.cpp - Tune 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 
10 #include "llvm/Support/Debug.h"
11 
13 
14 using namespace mlir;
15 
16 #define GET_OP_CLASSES
17 #include "mlir/Dialect/Transform/TuneExtension/TuneExtensionOps.cpp.inc"
18 
19 #define DEBUG_TYPE "transform-tune"
20 #define DBGS() (llvm::dbgs() << "[" DEBUG_TYPE "] ")
21 
22 //===----------------------------------------------------------------------===//
23 // KnobOp
24 //===----------------------------------------------------------------------===//
25 
26 void transform::tune::KnobOp::getEffects(
28  producesHandle(getOperation()->getOpResults(), effects);
29  onlyReadsPayload(effects);
30 }
31 
33 transform::tune::KnobOp::apply(transform::TransformRewriter &rewriter,
36  if (getSelected()) {
37  results.setParams(llvm::cast<OpResult>(getResult()), *getSelected());
39  }
40 
41  return emitDefiniteFailure()
42  << "non-deterministic choice " << getName()
43  << " is only resolved through providing a `selected` attr";
44 }
45 
46 LogicalResult transform::tune::KnobOp::verify() {
47  if (auto selected = getSelected()) {
48  if (auto optionsArray = dyn_cast<ArrayAttr>(getOptions())) {
49  if (!llvm::is_contained(optionsArray, selected))
50  return emitOpError("provided `selected` attribute is not an element of "
51  "`options` array of attributes");
52  } else
53  LLVM_DEBUG(DBGS() << "cannot verify `selected` attribute " << selected
54  << " is an element of `options` attribute "
55  << getOptions());
56  }
57 
58  return success();
59 }
#define DBGS()
The result of a transform IR operation application.
static DiagnosedSilenceableFailure success()
Constructs a DiagnosedSilenceableFailure in the success state.
Local mapping between values defined by a specific op implementing the TransformOpInterface and the p...
void setParams(OpResult value, ArrayRef< TransformState::Param > params)
Indicates that the result of the transform IR op at the given position corresponds to the given list ...
This is a special rewriter to be used in transform op implementations, providing additional helper fu...
The state maintained across applications of various ops implementing the TransformOpInterface.
void onlyReadsPayload(SmallVectorImpl< MemoryEffects::EffectInstance > &effects)
void producesHandle(ResultRange handles, SmallVectorImpl< MemoryEffects::EffectInstance > &effects)
Include the generated interface declarations.
DiagnosedDefiniteFailure emitDefiniteFailure(Location loc, const Twine &message={})
Emits a definite failure with the given message.
LogicalResult verify(Operation *op, bool verifyRecursively=true)
Perform (potentially expensive) checks of invariants, used to detect compiler bugs,...
Definition: Verifier.cpp:423