#include "ByteCode.h"
#include "mlir/Analysis/Liveness.h"
#include "mlir/Dialect/PDL/IR/PDLTypes.h"
#include "mlir/Dialect/PDLInterp/IR/PDLInterp.h"
#include "mlir/IR/BuiltinOps.h"
#include "mlir/IR/RegionGraphTraits.h"
#include "llvm/ADT/IntervalMap.h"
#include "llvm/ADT/PostOrderIterator.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/FormatVariadic.h"
#include <numeric>
#include <optional>
#define DEBUG_TYPE …
usingnamespacemlir;
usingnamespacemlir::detail;
PDLByteCodePattern PDLByteCodePattern::create(pdl_interp::RecordMatchOp matchOp,
PDLPatternConfigSet *configSet,
ByteCodeAddr rewriterAddr) { … }
void PDLByteCodeMutableState::updatePatternBenefit(unsigned patternIndex,
PatternBenefit benefit) { … }
void PDLByteCodeMutableState::cleanupAfterMatchAndRewrite() { … }
namespace {
enum OpCode : ByteCodeField { … };
}
static constexpr ByteCodeField kInferTypesMarker = …;
namespace {
struct ByteCodeLiveRange;
struct ByteCodeWriter;
has_pointer_traits;
class Generator { … };
struct ByteCodeWriter { … };
struct ByteCodeLiveRange { … };
}
void Generator::generate(ModuleOp module) { … }
void Generator::allocateMemoryIndices(pdl_interp::FuncOp matcherFunc,
ModuleOp rewriterModule) { … }
void Generator::generate(Region *region, ByteCodeWriter &writer) { … }
void Generator::generate(Operation *op, ByteCodeWriter &writer) { … }
void Generator::generate(pdl_interp::ApplyConstraintOp op,
ByteCodeWriter &writer) { … }
void Generator::generate(pdl_interp::ApplyRewriteOp op,
ByteCodeWriter &writer) { … }
void Generator::generate(pdl_interp::AreEqualOp op, ByteCodeWriter &writer) { … }
void Generator::generate(pdl_interp::BranchOp op, ByteCodeWriter &writer) { … }
void Generator::generate(pdl_interp::CheckAttributeOp op,
ByteCodeWriter &writer) { … }
void Generator::generate(pdl_interp::CheckOperandCountOp op,
ByteCodeWriter &writer) { … }
void Generator::generate(pdl_interp::CheckOperationNameOp op,
ByteCodeWriter &writer) { … }
void Generator::generate(pdl_interp::CheckResultCountOp op,
ByteCodeWriter &writer) { … }
void Generator::generate(pdl_interp::CheckTypeOp op, ByteCodeWriter &writer) { … }
void Generator::generate(pdl_interp::CheckTypesOp op, ByteCodeWriter &writer) { … }
void Generator::generate(pdl_interp::ContinueOp op, ByteCodeWriter &writer) { … }
void Generator::generate(pdl_interp::CreateAttributeOp op,
ByteCodeWriter &writer) { … }
void Generator::generate(pdl_interp::CreateOperationOp op,
ByteCodeWriter &writer) { … }
void Generator::generate(pdl_interp::CreateRangeOp op, ByteCodeWriter &writer) { … }
void Generator::generate(pdl_interp::CreateTypeOp op, ByteCodeWriter &writer) { … }
void Generator::generate(pdl_interp::CreateTypesOp op, ByteCodeWriter &writer) { … }
void Generator::generate(pdl_interp::EraseOp op, ByteCodeWriter &writer) { … }
void Generator::generate(pdl_interp::ExtractOp op, ByteCodeWriter &writer) { … }
void Generator::generate(pdl_interp::FinalizeOp op, ByteCodeWriter &writer) { … }
void Generator::generate(pdl_interp::ForEachOp op, ByteCodeWriter &writer) { … }
void Generator::generate(pdl_interp::GetAttributeOp op,
ByteCodeWriter &writer) { … }
void Generator::generate(pdl_interp::GetAttributeTypeOp op,
ByteCodeWriter &writer) { … }
void Generator::generate(pdl_interp::GetDefiningOpOp op,
ByteCodeWriter &writer) { … }
void Generator::generate(pdl_interp::GetOperandOp op, ByteCodeWriter &writer) { … }
void Generator::generate(pdl_interp::GetOperandsOp op, ByteCodeWriter &writer) { … }
void Generator::generate(pdl_interp::GetResultOp op, ByteCodeWriter &writer) { … }
void Generator::generate(pdl_interp::GetResultsOp op, ByteCodeWriter &writer) { … }
void Generator::generate(pdl_interp::GetUsersOp op, ByteCodeWriter &writer) { … }
void Generator::generate(pdl_interp::GetValueTypeOp op,
ByteCodeWriter &writer) { … }
void Generator::generate(pdl_interp::IsNotNullOp op, ByteCodeWriter &writer) { … }
void Generator::generate(pdl_interp::RecordMatchOp op, ByteCodeWriter &writer) { … }
void Generator::generate(pdl_interp::ReplaceOp op, ByteCodeWriter &writer) { … }
void Generator::generate(pdl_interp::SwitchAttributeOp op,
ByteCodeWriter &writer) { … }
void Generator::generate(pdl_interp::SwitchOperandCountOp op,
ByteCodeWriter &writer) { … }
void Generator::generate(pdl_interp::SwitchOperationNameOp op,
ByteCodeWriter &writer) { … }
void Generator::generate(pdl_interp::SwitchResultCountOp op,
ByteCodeWriter &writer) { … }
void Generator::generate(pdl_interp::SwitchTypeOp op, ByteCodeWriter &writer) { … }
void Generator::generate(pdl_interp::SwitchTypesOp op, ByteCodeWriter &writer) { … }
PDLByteCode::PDLByteCode(
ModuleOp module, SmallVector<std::unique_ptr<PDLPatternConfigSet>> configs,
const DenseMap<Operation *, PDLPatternConfigSet *> &configMap,
llvm::StringMap<PDLConstraintFunction> constraintFns,
llvm::StringMap<PDLRewriteFunction> rewriteFns)
: … { … }
void PDLByteCode::initializeMutableState(PDLByteCodeMutableState &state) const { … }
namespace {
class ByteCodeRewriteResultList : public PDLResultList { … };
class ByteCodeExecutor { … };
}
void ByteCodeExecutor::executeApplyConstraint(PatternRewriter &rewriter) { … }
LogicalResult ByteCodeExecutor::executeApplyRewrite(PatternRewriter &rewriter) { … }
void ByteCodeExecutor::processNativeFunResults(
ByteCodeRewriteResultList &results, unsigned numResults,
LogicalResult &rewriteResult) { … }
void ByteCodeExecutor::executeAreEqual() { … }
void ByteCodeExecutor::executeAreRangesEqual() { … }
void ByteCodeExecutor::executeBranch() { … }
void ByteCodeExecutor::executeCheckOperandCount() { … }
void ByteCodeExecutor::executeCheckOperationName() { … }
void ByteCodeExecutor::executeCheckResultCount() { … }
void ByteCodeExecutor::executeCheckTypes() { … }
void ByteCodeExecutor::executeContinue() { … }
void ByteCodeExecutor::executeCreateConstantTypeRange() { … }
void ByteCodeExecutor::executeCreateOperation(PatternRewriter &rewriter,
Location mainRewriteLoc) { … }
template <typename T>
void ByteCodeExecutor::executeDynamicCreateRange(StringRef type) { … }
void ByteCodeExecutor::executeEraseOp(PatternRewriter &rewriter) { … }
template <typename T, typename Range, PDLValue::Kind kind>
void ByteCodeExecutor::executeExtract() { … }
void ByteCodeExecutor::executeFinalize() { … }
void ByteCodeExecutor::executeForEach() { … }
void ByteCodeExecutor::executeGetAttribute() { … }
void ByteCodeExecutor::executeGetAttributeType() { … }
void ByteCodeExecutor::executeGetDefiningOp() { … }
void ByteCodeExecutor::executeGetOperand(unsigned index) { … }
template <template <typename> class AttrSizedSegmentsT, typename RangeT>
static void *
executeGetOperandsResults(RangeT values, Operation *op, unsigned index,
ByteCodeField rangeIndex, StringRef attrSizedSegments,
MutableArrayRef<ValueRange> valueRangeMemory) { … }
void ByteCodeExecutor::executeGetOperands() { … }
void ByteCodeExecutor::executeGetResult(unsigned index) { … }
void ByteCodeExecutor::executeGetResults() { … }
void ByteCodeExecutor::executeGetUsers() { … }
void ByteCodeExecutor::executeGetValueType() { … }
void ByteCodeExecutor::executeGetValueRangeTypes() { … }
void ByteCodeExecutor::executeIsNotNull() { … }
void ByteCodeExecutor::executeRecordMatch(
PatternRewriter &rewriter,
SmallVectorImpl<PDLByteCode::MatchResult> &matches) { … }
void ByteCodeExecutor::executeReplaceOp(PatternRewriter &rewriter) { … }
void ByteCodeExecutor::executeSwitchAttribute() { … }
void ByteCodeExecutor::executeSwitchOperandCount() { … }
void ByteCodeExecutor::executeSwitchOperationName() { … }
void ByteCodeExecutor::executeSwitchResultCount() { … }
void ByteCodeExecutor::executeSwitchType() { … }
void ByteCodeExecutor::executeSwitchTypes() { … }
LogicalResult
ByteCodeExecutor::execute(PatternRewriter &rewriter,
SmallVectorImpl<PDLByteCode::MatchResult> *matches,
std::optional<Location> mainRewriteLoc) { … }
void PDLByteCode::match(Operation *op, PatternRewriter &rewriter,
SmallVectorImpl<MatchResult> &matches,
PDLByteCodeMutableState &state) const { … }
LogicalResult PDLByteCode::rewrite(PatternRewriter &rewriter,
const MatchResult &match,
PDLByteCodeMutableState &state) const { … }