llvm/mlir/tools/mlir-tblgen/RewriterGen.cpp

//===- RewriterGen.cpp - MLIR pattern rewriter generator ------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
//
// RewriterGen uses pattern rewrite definitions to generate rewriter matchers.
//
//===----------------------------------------------------------------------===//

#include "mlir/Support/IndentedOstream.h"
#include "mlir/TableGen/Argument.h"
#include "mlir/TableGen/Attribute.h"
#include "mlir/TableGen/CodeGenHelpers.h"
#include "mlir/TableGen/Format.h"
#include "mlir/TableGen/GenInfo.h"
#include "mlir/TableGen/Operator.h"
#include "mlir/TableGen/Pattern.h"
#include "mlir/TableGen/Predicate.h"
#include "mlir/TableGen/Property.h"
#include "mlir/TableGen/Type.h"
#include "llvm/ADT/FunctionExtras.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/FormatAdapters.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Signals.h"
#include "llvm/TableGen/Error.h"
#include "llvm/TableGen/Main.h"
#include "llvm/TableGen/Record.h"
#include "llvm/TableGen/TableGenBackend.h"

usingnamespacemlir;
usingnamespacemlir::tblgen;

formatv;
Record;
RecordKeeper;

#define DEBUG_TYPE

namespace llvm {
template <>
struct format_provider<mlir::tblgen::Pattern::IdentifierLine> {};
} // namespace llvm

//===----------------------------------------------------------------------===//
// PatternEmitter
//===----------------------------------------------------------------------===//

namespace {

class StaticMatcherHelper;

class PatternEmitter {};

// Tracks DagNode's reference multiple times across patterns. Enables generating
// static matcher functions for DagNode's referenced multiple times rather than
// inlining them.
class StaticMatcherHelper {};

} // namespace

PatternEmitter::PatternEmitter(const Record *pat, RecordOperatorMap *mapper,
                               raw_ostream &os, StaticMatcherHelper &helper)
    :{}

std::string PatternEmitter::handleConstantAttr(Attribute attr,
                                               const Twine &value) {}

void PatternEmitter::emitStaticMatcher(DagNode tree, std::string funcName) {}

// Helper function to match patterns.
void PatternEmitter::emitMatch(DagNode tree, StringRef name, int depth) {}

void PatternEmitter::emitStaticMatchCall(DagNode tree, StringRef opName) {}

void PatternEmitter::emitStaticVerifierCall(StringRef funcName,
                                            StringRef opName, StringRef arg,
                                            StringRef failureStr) {}

// Helper function to match patterns.
void PatternEmitter::emitNativeCodeMatch(DagNode tree, StringRef opName,
                                         int depth) {}

// Helper function to match patterns.
void PatternEmitter::emitOpMatch(DagNode tree, StringRef opName, int depth) {}

void PatternEmitter::emitOperandMatch(DagNode tree, StringRef opName,
                                      StringRef operandName, int operandIndex,
                                      DagLeaf operandMatcher, StringRef argName,
                                      int argIndex,
                                      std::optional<int> variadicSubIndex) {}

void PatternEmitter::emitEitherOperandMatch(DagNode tree, DagNode eitherArgTree,
                                            StringRef opName, int argIndex,
                                            int &operandIndex, int depth) {}

void PatternEmitter::emitVariadicOperandMatch(DagNode tree,
                                              DagNode variadicArgTree,
                                              StringRef opName, int argIndex,
                                              int &operandIndex, int depth) {}

void PatternEmitter::emitAttributeMatch(DagNode tree, StringRef opName,
                                        int argIndex, int depth) {}

void PatternEmitter::emitMatchCheck(
    StringRef opName, const FmtObjectBase &matchFmt,
    const llvm::formatv_object_base &failureFmt) {}

void PatternEmitter::emitMatchCheck(StringRef opName,
                                    const std::string &matchStr,
                                    const std::string &failureStr) {}

void PatternEmitter::emitMatchLogic(DagNode tree, StringRef opName) {}

void PatternEmitter::collectOps(DagNode tree,
                                llvm::SmallPtrSetImpl<const Operator *> &ops) {}

void PatternEmitter::emit(StringRef rewriteName) {}

void PatternEmitter::emitRewriteLogic() {}

std::string PatternEmitter::getUniqueSymbol(const Operator *op) {}

std::string PatternEmitter::handleResultPattern(DagNode resultTree,
                                                int resultIndex, int depth) {}

std::string PatternEmitter::handleVariadic(DagNode tree, int depth) {}

StringRef PatternEmitter::handleReplaceWithValue(DagNode tree) {}

std::string PatternEmitter::handleLocationDirective(DagNode tree) {}

std::string PatternEmitter::handleReturnTypeArg(DagNode returnType, int i,
                                                int depth) {}

std::string PatternEmitter::handleOpArgument(DagLeaf leaf,
                                             StringRef patArgName) {}

std::string PatternEmitter::handleReplaceWithNativeCodeCall(DagNode tree,
                                                            int depth) {}

int PatternEmitter::getNodeValueCount(DagNode node) {}

PatternEmitter::TrailingDirectives
PatternEmitter::getTrailingDirectives(DagNode tree) {}

std::string
PatternEmitter::getLocation(PatternEmitter::TrailingDirectives &tail) {}

std::string PatternEmitter::handleOpCreation(DagNode tree, int resultIndex,
                                             int depth) {}

void PatternEmitter::createSeparateLocalVarsForOpArgs(
    DagNode node, ChildNodeIndexNameMap &childNodeNames) {}

void PatternEmitter::supplyValuesForOpArgs(
    DagNode node, const ChildNodeIndexNameMap &childNodeNames, int depth) {}

void PatternEmitter::createAggregateLocalVarsForOpArgs(
    DagNode node, const ChildNodeIndexNameMap &childNodeNames, int depth) {}

StaticMatcherHelper::StaticMatcherHelper(raw_ostream &os,
                                         const RecordKeeper &records,
                                         RecordOperatorMap &mapper)
    :{}

void StaticMatcherHelper::populateStaticMatchers(raw_ostream &os) {}

void StaticMatcherHelper::populateStaticConstraintFunctions(raw_ostream &os) {}

void StaticMatcherHelper::addPattern(const Record *record) {}

StringRef StaticMatcherHelper::getVerifierName(DagLeaf leaf) {}

static void emitRewriters(const RecordKeeper &records, raw_ostream &os) {}

static mlir::GenRegistration
    genRewriters("gen-rewriters", "Generate pattern rewriters",
                 [](const RecordKeeper &records, raw_ostream &os) {});