//===- Nodes.cpp ----------------------------------------------------------===// // // 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 // //===----------------------------------------------------------------------===// #include "mlir/Tools/PDLL/AST/Nodes.h" #include "mlir/Tools/PDLL/AST/Context.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/TypeSwitch.h" #include <optional> usingnamespacemlir; usingnamespacemlir::pdll::ast; /// Copy a string reference into the context with a null terminator. static StringRef copyStringWithNull(Context &ctx, StringRef str) { … } //===----------------------------------------------------------------------===// // Name //===----------------------------------------------------------------------===// const Name &Name::create(Context &ctx, StringRef name, SMRange location) { … } //===----------------------------------------------------------------------===// // Node //===----------------------------------------------------------------------===// namespace { class NodeVisitor { … }; } // namespace void Node::walk(function_ref<void(const Node *)> walkFn) const { … } //===----------------------------------------------------------------------===// // DeclScope //===----------------------------------------------------------------------===// void DeclScope::add(Decl *decl) { … } Decl *DeclScope::lookup(StringRef name) { … } //===----------------------------------------------------------------------===// // CompoundStmt //===----------------------------------------------------------------------===// CompoundStmt *CompoundStmt::create(Context &ctx, SMRange loc, ArrayRef<Stmt *> children) { … } //===----------------------------------------------------------------------===// // LetStmt //===----------------------------------------------------------------------===// LetStmt *LetStmt::create(Context &ctx, SMRange loc, VariableDecl *varDecl) { … } //===----------------------------------------------------------------------===// // OpRewriteStmt //===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===// // EraseStmt EraseStmt *EraseStmt::create(Context &ctx, SMRange loc, Expr *rootOp) { … } //===----------------------------------------------------------------------===// // ReplaceStmt ReplaceStmt *ReplaceStmt::create(Context &ctx, SMRange loc, Expr *rootOp, ArrayRef<Expr *> replExprs) { … } //===----------------------------------------------------------------------===// // RewriteStmt RewriteStmt *RewriteStmt::create(Context &ctx, SMRange loc, Expr *rootOp, CompoundStmt *rewriteBody) { … } //===----------------------------------------------------------------------===// // ReturnStmt //===----------------------------------------------------------------------===// ReturnStmt *ReturnStmt::create(Context &ctx, SMRange loc, Expr *resultExpr) { … } //===----------------------------------------------------------------------===// // AttributeExpr //===----------------------------------------------------------------------===// AttributeExpr *AttributeExpr::create(Context &ctx, SMRange loc, StringRef value) { … } //===----------------------------------------------------------------------===// // CallExpr //===----------------------------------------------------------------------===// CallExpr *CallExpr::create(Context &ctx, SMRange loc, Expr *callable, ArrayRef<Expr *> arguments, Type resultType, bool isNegated) { … } //===----------------------------------------------------------------------===// // DeclRefExpr //===----------------------------------------------------------------------===// DeclRefExpr *DeclRefExpr::create(Context &ctx, SMRange loc, Decl *decl, Type type) { … } //===----------------------------------------------------------------------===// // MemberAccessExpr //===----------------------------------------------------------------------===// MemberAccessExpr *MemberAccessExpr::create(Context &ctx, SMRange loc, const Expr *parentExpr, StringRef memberName, Type type) { … } //===----------------------------------------------------------------------===// // OperationExpr //===----------------------------------------------------------------------===// OperationExpr * OperationExpr::create(Context &ctx, SMRange loc, const ods::Operation *odsOp, const OpNameDecl *name, ArrayRef<Expr *> operands, ArrayRef<Expr *> resultTypes, ArrayRef<NamedAttributeDecl *> attributes) { … } std::optional<StringRef> OperationExpr::getName() const { … } //===----------------------------------------------------------------------===// // RangeExpr //===----------------------------------------------------------------------===// RangeExpr *RangeExpr::create(Context &ctx, SMRange loc, ArrayRef<Expr *> elements, RangeType type) { … } //===----------------------------------------------------------------------===// // TupleExpr //===----------------------------------------------------------------------===// TupleExpr *TupleExpr::create(Context &ctx, SMRange loc, ArrayRef<Expr *> elements, ArrayRef<StringRef> names) { … } //===----------------------------------------------------------------------===// // TypeExpr //===----------------------------------------------------------------------===// TypeExpr *TypeExpr::create(Context &ctx, SMRange loc, StringRef value) { … } //===----------------------------------------------------------------------===// // Decl //===----------------------------------------------------------------------===// void Decl::setDocComment(Context &ctx, StringRef comment) { … } //===----------------------------------------------------------------------===// // AttrConstraintDecl //===----------------------------------------------------------------------===// AttrConstraintDecl *AttrConstraintDecl::create(Context &ctx, SMRange loc, Expr *typeExpr) { … } //===----------------------------------------------------------------------===// // OpConstraintDecl //===----------------------------------------------------------------------===// OpConstraintDecl *OpConstraintDecl::create(Context &ctx, SMRange loc, const OpNameDecl *nameDecl) { … } std::optional<StringRef> OpConstraintDecl::getName() const { … } //===----------------------------------------------------------------------===// // TypeConstraintDecl //===----------------------------------------------------------------------===// TypeConstraintDecl *TypeConstraintDecl::create(Context &ctx, SMRange loc) { … } //===----------------------------------------------------------------------===// // TypeRangeConstraintDecl //===----------------------------------------------------------------------===// TypeRangeConstraintDecl *TypeRangeConstraintDecl::create(Context &ctx, SMRange loc) { … } //===----------------------------------------------------------------------===// // ValueConstraintDecl //===----------------------------------------------------------------------===// ValueConstraintDecl *ValueConstraintDecl::create(Context &ctx, SMRange loc, Expr *typeExpr) { … } //===----------------------------------------------------------------------===// // ValueRangeConstraintDecl //===----------------------------------------------------------------------===// ValueRangeConstraintDecl * ValueRangeConstraintDecl::create(Context &ctx, SMRange loc, Expr *typeExpr) { … } //===----------------------------------------------------------------------===// // UserConstraintDecl //===----------------------------------------------------------------------===// std::optional<StringRef> UserConstraintDecl::getNativeInputType(unsigned index) const { … } UserConstraintDecl *UserConstraintDecl::createImpl( Context &ctx, const Name &name, ArrayRef<VariableDecl *> inputs, ArrayRef<StringRef> nativeInputTypes, ArrayRef<VariableDecl *> results, std::optional<StringRef> codeBlock, const CompoundStmt *body, Type resultType) { … } //===----------------------------------------------------------------------===// // NamedAttributeDecl //===----------------------------------------------------------------------===// NamedAttributeDecl *NamedAttributeDecl::create(Context &ctx, const Name &name, Expr *value) { … } //===----------------------------------------------------------------------===// // OpNameDecl //===----------------------------------------------------------------------===// OpNameDecl *OpNameDecl::create(Context &ctx, const Name &name) { … } OpNameDecl *OpNameDecl::create(Context &ctx, SMRange loc) { … } //===----------------------------------------------------------------------===// // PatternDecl //===----------------------------------------------------------------------===// PatternDecl *PatternDecl::create(Context &ctx, SMRange loc, const Name *name, std::optional<uint16_t> benefit, bool hasBoundedRecursion, const CompoundStmt *body) { … } //===----------------------------------------------------------------------===// // UserRewriteDecl //===----------------------------------------------------------------------===// UserRewriteDecl *UserRewriteDecl::createImpl(Context &ctx, const Name &name, ArrayRef<VariableDecl *> inputs, ArrayRef<VariableDecl *> results, std::optional<StringRef> codeBlock, const CompoundStmt *body, Type resultType) { … } //===----------------------------------------------------------------------===// // VariableDecl //===----------------------------------------------------------------------===// VariableDecl *VariableDecl::create(Context &ctx, const Name &name, Type type, Expr *initExpr, ArrayRef<ConstraintRef> constraints) { … } //===----------------------------------------------------------------------===// // Module //===----------------------------------------------------------------------===// Module *Module::create(Context &ctx, SMLoc loc, ArrayRef<Decl *> children) { … }