MLIR  18.0.0git
Classes | Functions | Variables
mlir::detail::pdl_function_builder Namespace Reference

Classes

struct  ProcessPDLValue
 This struct provides a convenient way to determine how to process a given type as either a PDL parameter, or a result value. More...
 
struct  ProcessPDLValueBasedOn
 This struct provides a simplified model for processing types that are based on another type, e.g. More...
 
struct  ProcessBuiltinPDLValue
 This struct provides a simplified model for processing types that have "builtin" PDLValue support: More...
 
struct  ProcessDerivedPDLValue
 This struct provides a simplified model for processing types that inherit from builtin PDLValue types. More...
 
struct  ProcessPDLValue< Attribute >
 
struct  ProcessPDLValue< T, std::enable_if_t< std::is_base_of< Attribute, T >::value > >
 
struct  ProcessPDLValue< StringRef >
 Handling for various Attribute value types. More...
 
struct  ProcessPDLValue< std::string >
 
struct  ProcessPDLValue< Operation * >
 
struct  ProcessPDLValue< T, std::enable_if_t< std::is_base_of< OpState, T >::value > >
 
struct  ProcessPDLValue< Type >
 
struct  ProcessPDLValue< T, std::enable_if_t< std::is_base_of< Type, T >::value > >
 
struct  ProcessPDLValue< TypeRange >
 
struct  ProcessPDLValue< ValueTypeRange< OperandRange > >
 
struct  ProcessPDLValue< ValueTypeRange< ResultRange > >
 
struct  ProcessPDLValue< SmallVector< Type, N > >
 
struct  ProcessPDLValue< Value >
 
struct  ProcessPDLValue< ValueRange >
 
struct  ProcessPDLValue< OperandRange >
 
struct  ProcessPDLValue< ResultRange >
 
struct  ProcessPDLValue< SmallVector< Value, N > >
 

Functions

template<typename PDLFnT , std::size_t... I>
LogicalResult verifyAsArgs (PatternRewriter &rewriter, ArrayRef< PDLValue > values, std::index_sequence< I... >)
 Validate the given PDLValues match the constraints defined by the argument types of the given function. More...
 
template<typename PDLFnT , std::size_t... I>
void assertArgs (PatternRewriter &rewriter, ArrayRef< PDLValue > values, std::index_sequence< I... >)
 Assert that the given PDLValues match the constraints defined by the arguments of the given function. More...
 
template<typename T >
static LogicalResult processResults (PatternRewriter &rewriter, PDLResultList &results, T &&value)
 Store a single result within the result list. More...
 
template<typename T1 , typename T2 >
static LogicalResult processResults (PatternRewriter &rewriter, PDLResultList &results, std::pair< T1, T2 > &&pair)
 Store a std::pair<> as individual results within the result list. More...
 
template<typename... Ts>
static LogicalResult processResults (PatternRewriter &rewriter, PDLResultList &results, std::tuple< Ts... > &&tuple)
 Store a std::tuple<> as individual results within the result list. More...
 
LogicalResult processResults (PatternRewriter &rewriter, PDLResultList &results, LogicalResult &&result)
 Handle LogicalResult propagation. More...
 
template<typename T >
static LogicalResult processResults (PatternRewriter &rewriter, PDLResultList &results, FailureOr< T > &&result)
 
template<typename PDLFnT , std::size_t... I, typename FnTraitsT = llvm::function_traits<PDLFnT>>
FnTraitsT::result_t processArgsAndInvokeConstraint (PDLFnT &fn, PatternRewriter &rewriter, ArrayRef< PDLValue > values, std::index_sequence< I... >)
 Process the arguments of a native constraint and invoke it. More...
 
template<typename ConstraintFnT >
std::enable_if_t< std::is_convertible< ConstraintFnT, PDLConstraintFunction >::value, PDLConstraintFunctionbuildConstraintFn (ConstraintFnT &&constraintFn)
 Build a constraint function from the given function ConstraintFnT. More...
 
template<typename ConstraintFnT >
std::enable_if_t< !std::is_convertible< ConstraintFnT, PDLConstraintFunction >::value, PDLConstraintFunctionbuildConstraintFn (ConstraintFnT &&constraintFn)
 Otherwise, we generate a wrapper that will unpack the PDLValues in the form we desire. More...
 
template<typename PDLFnT , std::size_t... I, typename FnTraitsT = llvm::function_traits<PDLFnT>>
std::enable_if_t< std::is_same< typename FnTraitsT::result_t, void >::value, LogicalResultprocessArgsAndInvokeRewrite (PDLFnT &fn, PatternRewriter &rewriter, PDLResultList &, ArrayRef< PDLValue > values, std::index_sequence< I... >)
 Process the arguments of a native rewrite and invoke it. More...
 
template<typename PDLFnT , std::size_t... I, typename FnTraitsT = llvm::function_traits<PDLFnT>>
std::enable_if_t<!std::is_same< typename FnTraitsT::result_t, void >::value, LogicalResultprocessArgsAndInvokeRewrite (PDLFnT &fn, PatternRewriter &rewriter, PDLResultList &results, ArrayRef< PDLValue > values, std::index_sequence< I... >)
 This overload handles the case of return values, which need to be packaged into the result list. More...
 
template<typename RewriteFnT >
std::enable_if_t< std::is_convertible< RewriteFnT, PDLRewriteFunction >::value, PDLRewriteFunctionbuildRewriteFn (RewriteFnT &&rewriteFn)
 Build a rewrite function from the given function RewriteFnT. More...
 
template<typename RewriteFnT >
std::enable_if_t<!std::is_convertible< RewriteFnT, PDLRewriteFunction >::value, PDLRewriteFunctionbuildRewriteFn (RewriteFnT &&rewriteFn)
 Otherwise, we generate a wrapper that will unpack the PDLValues in the form we desire. More...
 

Variables

template<class... T>
constexpr bool always_false = false
 A utility variable that always resolves to false. More...
 

Function Documentation

◆ assertArgs()

template<typename PDLFnT , std::size_t... I>
void mlir::detail::pdl_function_builder::assertArgs ( PatternRewriter rewriter,
ArrayRef< PDLValue values,
std::index_sequence< I... >   
)

Assert that the given PDLValues match the constraints defined by the arguments of the given function.

In the case of failure, a fatal error is emitted.

Definition at line 1343 of file PatternMatch.h.

References mlir::succeeded().

◆ buildConstraintFn() [1/2]

template<typename ConstraintFnT >
std::enable_if_t< std::is_convertible<ConstraintFnT, PDLConstraintFunction>::value, PDLConstraintFunction> mlir::detail::pdl_function_builder::buildConstraintFn ( ConstraintFnT &&  constraintFn)

Build a constraint function from the given function ConstraintFnT.

This allows for enabling the user to define simpler, more direct constraint functions without needing to handle the low-level PDL goop.

If the constraint function is already in the correct form, we just forward it directly.

Definition at line 1437 of file PatternMatch.h.

Referenced by mlir::PDLPatternModule::registerConstraintFunction().

◆ buildConstraintFn() [2/2]

template<typename ConstraintFnT >
std::enable_if_t< !std::is_convertible<ConstraintFnT, PDLConstraintFunction>::value, PDLConstraintFunction> mlir::detail::pdl_function_builder::buildConstraintFn ( ConstraintFnT &&  constraintFn)

Otherwise, we generate a wrapper that will unpack the PDLValues in the form we desire.

Definition at line 1446 of file PatternMatch.h.

References mlir::failed(), mlir::failure(), and processArgsAndInvokeConstraint().

◆ buildRewriteFn() [1/2]

template<typename RewriteFnT >
std::enable_if_t<std::is_convertible<RewriteFnT, PDLRewriteFunction>::value, PDLRewriteFunction> mlir::detail::pdl_function_builder::buildRewriteFn ( RewriteFnT &&  rewriteFn)

Build a rewrite function from the given function RewriteFnT.

This allows for enabling the user to define simpler, more direct rewrite functions without needing to handle the low-level PDL goop.

If the rewrite function is already in the correct form, we just forward it directly.

Definition at line 1502 of file PatternMatch.h.

Referenced by mlir::PDLPatternModule::registerRewriteFunction().

◆ buildRewriteFn() [2/2]

template<typename RewriteFnT >
std::enable_if_t<!std::is_convertible<RewriteFnT, PDLRewriteFunction>::value, PDLRewriteFunction> mlir::detail::pdl_function_builder::buildRewriteFn ( RewriteFnT &&  rewriteFn)

Otherwise, we generate a wrapper that will unpack the PDLValues in the form we desire.

Definition at line 1510 of file PatternMatch.h.

References processArgsAndInvokeRewrite().

◆ processArgsAndInvokeConstraint()

template<typename PDLFnT , std::size_t... I, typename FnTraitsT = llvm::function_traits<PDLFnT>>
FnTraitsT::result_t mlir::detail::pdl_function_builder::processArgsAndInvokeConstraint ( PDLFnT &  fn,
PatternRewriter rewriter,
ArrayRef< PDLValue values,
std::index_sequence< I... >   
)

Process the arguments of a native constraint and invoke it.

Definition at line 1418 of file PatternMatch.h.

Referenced by buildConstraintFn().

◆ processArgsAndInvokeRewrite() [1/2]

template<typename PDLFnT , std::size_t... I, typename FnTraitsT = llvm::function_traits<PDLFnT>>
std::enable_if_t<std::is_same<typename FnTraitsT::result_t, void>::value, LogicalResult> mlir::detail::pdl_function_builder::processArgsAndInvokeRewrite ( PDLFnT &  fn,
PatternRewriter rewriter,
PDLResultList ,
ArrayRef< PDLValue values,
std::index_sequence< I... >   
)

Process the arguments of a native rewrite and invoke it.

This overload handles the case of no return values.

Definition at line 1469 of file PatternMatch.h.

References mlir::success().

Referenced by buildRewriteFn().

◆ processArgsAndInvokeRewrite() [2/2]

template<typename PDLFnT , std::size_t... I, typename FnTraitsT = llvm::function_traits<PDLFnT>>
std::enable_if_t<!std::is_same<typename FnTraitsT::result_t, void>::value, LogicalResult> mlir::detail::pdl_function_builder::processArgsAndInvokeRewrite ( PDLFnT &  fn,
PatternRewriter rewriter,
PDLResultList results,
ArrayRef< PDLValue values,
std::index_sequence< I... >   
)

This overload handles the case of return values, which need to be packaged into the result list.

Definition at line 1483 of file PatternMatch.h.

References processResults().

◆ processResults() [1/5]

template<typename T >
static LogicalResult mlir::detail::pdl_function_builder::processResults ( PatternRewriter rewriter,
PDLResultList results,
FailureOr< T > &&  result 
)
static

Definition at line 1402 of file PatternMatch.h.

References mlir::failed(), mlir::failure(), and processResults().

◆ processResults() [2/5]

LogicalResult mlir::detail::pdl_function_builder::processResults ( PatternRewriter rewriter,
PDLResultList results,
LogicalResult &&  result 
)
inline

Handle LogicalResult propagation.

Definition at line 1396 of file PatternMatch.h.

◆ processResults() [3/5]

template<typename T1 , typename T2 >
static LogicalResult mlir::detail::pdl_function_builder::processResults ( PatternRewriter rewriter,
PDLResultList results,
std::pair< T1, T2 > &&  pair 
)
static

Store a std::pair<> as individual results within the result list.

Definition at line 1374 of file PatternMatch.h.

References mlir::failed(), mlir::failure(), processResults(), and mlir::success().

◆ processResults() [4/5]

template<typename... Ts>
static LogicalResult mlir::detail::pdl_function_builder::processResults ( PatternRewriter rewriter,
PDLResultList results,
std::tuple< Ts... > &&  tuple 
)
static

Store a std::tuple<> as individual results within the result list.

Definition at line 1385 of file PatternMatch.h.

References processResults(), mlir::succeeded(), and mlir::success().

◆ processResults() [5/5]

template<typename T >
static LogicalResult mlir::detail::pdl_function_builder::processResults ( PatternRewriter rewriter,
PDLResultList results,
T &&  value 
)
static

Store a single result within the result list.

Definition at line 1365 of file PatternMatch.h.

References mlir::success().

Referenced by processArgsAndInvokeRewrite(), and processResults().

◆ verifyAsArgs()

template<typename PDLFnT , std::size_t... I>
LogicalResult mlir::detail::pdl_function_builder::verifyAsArgs ( PatternRewriter rewriter,
ArrayRef< PDLValue values,
std::index_sequence< I... >   
)

Validate the given PDLValues match the constraints defined by the argument types of the given function.

In the case of failure, a match failure diagnostic is emitted. FIXME: This should be completely removed in favor of assertArgs, but PDL does not currently preserve Constraint application ordering.

Definition at line 1326 of file PatternMatch.h.

References mlir::Builder::getUnknownLoc(), mlir::RewriterBase::notifyMatchFailure(), mlir::succeeded(), and mlir::success().

Variable Documentation

◆ always_false

template<class... T>
constexpr bool mlir::detail::pdl_function_builder::always_false = false
constexpr

A utility variable that always resolves to false.

This is useful for static asserts that are always false, but only should fire in certain templated constructs. For example, if a templated function should never be called, the function could be defined as:

template <typename T> void foo() { static_assert(always_false<T>, "This function should never be called"); }

Definition at line 1064 of file PatternMatch.h.