-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
treewide: Introduce core function interface to avoid implicit symbol …
…from mlir::FunctionOpInterface.
- Loading branch information
Showing
37 changed files
with
1,719 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
include/vast/Dialect/Core/Interfaces/FunctionImplementation.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
//===- FunctionImplementation.h - Function-like Op utilities ----*- 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 provides utility functions for implementing function-like | ||
// operations, in particular, parsing, printing and verification components | ||
// common to function-like operations. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef VAST_DIALECT_CORE_FUNCTIONIMPLEMENTATION_HPP | ||
#define VAST_DIALECT_CORE_FUNCTIONIMPLEMENTATION_HPP | ||
|
||
#include "vast/Util/Warnings.hpp" | ||
|
||
VAST_RELAX_WARNINGS | ||
#include <mlir/IR/OpImplementation.h> | ||
VAST_UNRELAX_WARNINGS | ||
|
||
#include "vast/Dialect/Core/Interfaces/FunctionInterface.hpp" | ||
|
||
namespace vast::core { | ||
|
||
namespace function_interface_impl { | ||
|
||
/// A named class for passing around the variadic flag. | ||
class VariadicFlag { | ||
public: | ||
explicit VariadicFlag(bool variadic) : variadic(variadic) {} | ||
bool isVariadic() const { return variadic; } | ||
|
||
private: | ||
/// Underlying storage. | ||
bool variadic; | ||
}; | ||
|
||
/// Adds argument and result attributes, provided as `argAttrs` and | ||
/// `resultAttrs` arguments, to the list of operation attributes in `result`. | ||
/// Internally, argument and result attributes are stored as dict attributes | ||
/// with special names given by getResultAttrName, getArgumentAttrName. | ||
void addArgAndResultAttrs(::mlir::Builder &builder, ::mlir::OperationState &result, | ||
::mlir::ArrayRef<::mlir::DictionaryAttr> argAttrs, | ||
::mlir::ArrayRef<::mlir::DictionaryAttr> resultAttrs, | ||
::mlir::StringAttr argAttrsName, ::mlir::StringAttr resAttrsName); | ||
void addArgAndResultAttrs(::mlir::Builder &builder, ::mlir::OperationState &result, | ||
::mlir::ArrayRef<::mlir::OpAsmParser::Argument> args, | ||
::mlir::ArrayRef<::mlir::DictionaryAttr> resultAttrs, | ||
::mlir::StringAttr argAttrsName, ::mlir::StringAttr resAttrsName); | ||
|
||
/// Callback type for `parseFunctionOp`, the callback should produce the | ||
/// type that will be associated with a function-like operation from lists of | ||
/// function arguments and results, VariadicFlag indicates whether the function | ||
/// should have variadic arguments; in case of error, it may populate the last | ||
/// argument with a message. | ||
using FuncTypeBuilder = ::mlir::function_ref<::mlir::Type( | ||
::mlir::Builder &, ::mlir::ArrayRef<::mlir::Type>, ::mlir::ArrayRef<::mlir::Type>, VariadicFlag, std::string &)>; | ||
|
||
/// Parses a function signature using `parser`. The `allowVariadic` argument | ||
/// indicates whether functions with variadic arguments are supported. The | ||
/// trailing arguments are populated by this function with names, types, | ||
/// attributes and locations of the arguments and those of the results. | ||
::mlir::ParseResult | ||
parseFunctionSignature(::mlir::OpAsmParser &parser, bool allowVariadic, | ||
::mlir::SmallVectorImpl<::mlir::OpAsmParser::Argument> &arguments, | ||
bool &isVariadic, ::mlir::SmallVectorImpl<::mlir::Type> &resultTypes, | ||
::mlir::SmallVectorImpl<::mlir::DictionaryAttr> &resultAttrs); | ||
|
||
/// Parser implementation for function-like operations. Uses | ||
/// `funcTypeBuilder` to construct the custom function type given lists of | ||
/// input and output types. The parser sets the `typeAttrName` attribute to the | ||
/// resulting function type. If `allowVariadic` is set, the parser will accept | ||
/// trailing ellipsis in the function signature and indicate to the builder | ||
/// whether the function is variadic. If the builder returns a null type, | ||
/// `result` will not contain the `type` attribute. The caller can then add a | ||
/// type, report the error or delegate the reporting to the op's verifier. | ||
::mlir::ParseResult parseFunctionOp(::mlir::OpAsmParser &parser, ::mlir::OperationState &result, | ||
bool allowVariadic, ::mlir::StringAttr typeAttrName, | ||
FuncTypeBuilder funcTypeBuilder, | ||
::mlir::StringAttr argAttrsName, ::mlir::StringAttr resAttrsName); | ||
|
||
/// Printer implementation for function-like operations. | ||
void printFunctionOp(::mlir::OpAsmPrinter &p, FunctionOpInterface op, bool isVariadic, | ||
::mlir::StringRef typeAttrName, ::mlir::StringAttr argAttrsName, | ||
::mlir::StringAttr resAttrsName); | ||
|
||
/// Prints the signature of the function-like operation `op`. Assumes `op` has | ||
/// is a FunctionOpInterface and has passed verification. | ||
void printFunctionSignature(::mlir::OpAsmPrinter &p, FunctionOpInterface op, | ||
::mlir::ArrayRef<::mlir::Type> argTypes, bool isVariadic, | ||
::mlir::ArrayRef<::mlir::Type> resultTypes); | ||
|
||
/// Prints the list of function prefixed with the "attributes" keyword. The | ||
/// attributes with names listed in "elided" as well as those used by the | ||
/// function-like operation internally are not printed. Nothing is printed | ||
/// if all attributes are elided. Assumes `op` is a FunctionOpInterface and | ||
/// has passed verification. | ||
void printFunctionAttributes(::mlir::OpAsmPrinter &p, ::mlir::Operation *op, | ||
::mlir::ArrayRef<::mlir::StringRef> elided = {}); | ||
|
||
} // namespace function_interface_impl | ||
|
||
} // namespace vast::core | ||
|
||
#endif // VAST_DIALECT_CORE_FUNCTIONIMPLEMENTATION_HPP |
Oops, something went wrong.