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

Classes

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
 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  ProcessPDLValue< Attribute >
 
struct  ProcessPDLValue< OperandRange >
 
struct  ProcessPDLValue< Operation * >
 
struct  ProcessPDLValue< ResultRange >
 
struct  ProcessPDLValue< std::string >
 
struct  ProcessPDLValue< StringRef >
 Handling for various Attribute value types. More...
 
struct  ProcessPDLValue< T, std::enable_if_t< std::is_base_of< Attribute, T >::value > >
 
struct  ProcessPDLValue< T, std::enable_if_t< std::is_base_of< OpState, T >::value > >
 
struct  ProcessPDLValue< T, std::enable_if_t< std::is_base_of< Type, T >::value > >
 
struct  ProcessPDLValue< Type >
 
struct  ProcessPDLValue< TypeRange >
 
struct  ProcessPDLValue< Value >
 
struct  ProcessPDLValue< ValueRange >
 
struct  ProcessPDLValue< ValueTypeRange< OperandRange > >
 
struct  ProcessPDLValue< ValueTypeRange< ResultRange > >
 
struct  ProcessPDLValueBasedOn
 This struct provides a simplified model for processing types that are based on another type, e.g. More...
 

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 void processResults (PatternRewriter &rewriter, PDLResultList &results, T &&value)
 Store a single result within the result list. More...
 
template<typename T1 , typename T2 >
static void 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 void processResults (PatternRewriter &rewriter, PDLResultList &results, std::tuple< Ts... > &&tuple)
 Store a std::tuple<> as individual results within the result list. More...
 
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 >::valueprocessArgsAndInvokeRewrite (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 >::valueprocessArgsAndInvokeRewrite (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 1092 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 1164 of file PatternMatch.h.

Referenced by mlir::PDLPatternModule::registerConstraintFunction(), and mlir::transform::TransformDialectExtension< DerivedTy, ExtraDialects >::registerPDLMatchConstraintFn().

◆ 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 1173 of file PatternMatch.h.

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

◆ 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 1225 of file PatternMatch.h.

References value.

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 1233 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 1145 of file PatternMatch.h.

References value.

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> 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 1195 of file PatternMatch.h.

References value.

◆ 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> 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 1207 of file PatternMatch.h.

References processResults(), and value.

Referenced by buildRewriteFn().

◆ processResults() [1/3]

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

Store a single result within the result list.

Definition at line 1113 of file PatternMatch.h.

References value.

◆ processResults() [2/3]

template<typename T1 , typename T2 >
static void 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 1121 of file PatternMatch.h.

References processResults().

◆ processResults() [3/3]

template<typename... Ts>
static void 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 1129 of file PatternMatch.h.

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 1075 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

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 827 of file PatternMatch.h.