MLIR 23.0.0git
UBMatchers.h
Go to the documentation of this file.
1//===- UBMatchers.h - UB Dialect matchers -----------------------*- C++ -*-===//
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 provides matchers for the UB dialect, in particular for matching
10// poison values and attributes.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef MLIR_DIALECT_UB_IR_UBMATCHERS_H
15#define MLIR_DIALECT_UB_IR_UBMATCHERS_H
16
18#include "mlir/IR/Matchers.h"
19
20namespace mlir::ub {
21namespace detail {
22
23/// Matches a poison attribute (any attribute implementing PoisonAttrInterface).
24/// Supports matching against both Attribute and Operation* (via constant
25/// folding).
27 bool match(Attribute attr) { return isa<PoisonAttrInterface>(attr); }
28
29 bool match(Operation *op) {
30 Attribute attr;
32 return false;
33 return match(attr);
34 }
35};
36
37} // namespace detail
38
39/// Matches a poison constant (any attribute implementing PoisonAttrInterface).
40/// Works with `matchPattern` on Value, Operation*, and Attribute.
41///
42/// Examples:
43/// matchPattern(value, ub::m_Poison()) // Matches ub.poison op via Value.
44/// matchPattern(op, ub::m_Poison()) // Matches ub.poison op directly.
45/// matchPattern(attr, ub::m_Poison()) // Matches PoisonAttr(Interface).
49
50} // namespace mlir::ub
51
52#endif // MLIR_DIALECT_UB_IR_UBMATCHERS_H
Attributes are known-constant values of operations.
Definition Attributes.h:25
Operation is the basic unit of execution within MLIR.
Definition Operation.h:88
detail::poison_attr_matcher m_Poison()
Matches a poison constant (any attribute implementing PoisonAttrInterface).
Definition UBMatchers.h:46
The matcher that matches operations that have the ConstantLike trait, and binds the folded attribute ...
Definition Matchers.h:76
Matches a poison attribute (any attribute implementing PoisonAttrInterface).
Definition UBMatchers.h:26