//===- ByteCode.h - Pattern byte-code interpreter ---------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file declares a byte-code and interpreter for pattern rewrites in MLIR. // The byte-code is constructed from the PDL Interpreter dialect. // //===----------------------------------------------------------------------===// #ifndef MLIR_REWRITE_BYTECODE_H_ #define MLIR_REWRITE_BYTECODE_H_ #include "mlir/IR/PatternMatch.h" #if MLIR_ENABLE_PDL_IN_PATTERNMATCH namespace mlir { namespace pdl_interp { class RecordMatchOp; } // namespace pdl_interp namespace detail { class PDLByteCode; /// Use generic bytecode types. ByteCodeField refers to the actual bytecode /// entries. ByteCodeAddr refers to size of indices into the bytecode. ByteCodeField; ByteCodeAddr; OwningOpRange; //===----------------------------------------------------------------------===// // PDLByteCodePattern //===----------------------------------------------------------------------===// /// All of the data pertaining to a specific pattern within the bytecode. class PDLByteCodePattern : public Pattern { … }; //===----------------------------------------------------------------------===// // PDLByteCodeMutableState //===----------------------------------------------------------------------===// /// This class contains the mutable state of a bytecode instance. This allows /// for a bytecode instance to be cached and reused across various different /// threads/drivers. class PDLByteCodeMutableState { … }; //===----------------------------------------------------------------------===// // PDLByteCode //===----------------------------------------------------------------------===// /// The bytecode class is also the interpreter. Contains the bytecode itself, /// the static info, addresses of the rewriter functions, the interpreter /// memory buffer, and the execution context. class PDLByteCode { … }; } // namespace detail } // namespace mlir #else namespace mlir::detail { class PDLByteCodeMutableState { public: void cleanupAfterMatchAndRewrite() {} void updatePatternBenefit(unsigned patternIndex, PatternBenefit benefit) {} }; class PDLByteCodePattern : public Pattern {}; class PDLByteCode { public: struct MatchResult { const PDLByteCodePattern *pattern = nullptr; PatternBenefit benefit; }; void initializeMutableState(PDLByteCodeMutableState &state) const {} void match(Operation *op, PatternRewriter &rewriter, SmallVectorImpl<MatchResult> &matches, PDLByteCodeMutableState &state) const {} LogicalResult rewrite(PatternRewriter &rewriter, const MatchResult &match, PDLByteCodeMutableState &state) const { return failure(); } ArrayRef<PDLByteCodePattern> getPatterns() const { return {}; } }; } // namespace mlir::detail #endif // MLIR_ENABLE_PDL_IN_PATTERNMATCH #endif // MLIR_REWRITE_BYTECODE_H_