Created
August 18, 2023 23:59
-
-
Save j2kun/fe28ffce726bf9b391e2245a6f9994ff to your computer and use it in GitHub Desktop.
Poly ops generated code
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
/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ | |
|* *| | |
|* Op Definitions *| | |
|* *| | |
|* Automatically generated file, do not edit! *| | |
|* *| | |
\*===----------------------------------------------------------------------===*/ | |
#ifdef GET_OP_LIST | |
#undef GET_OP_LIST | |
::mlir::tutorial::poly::AddOp | |
#endif // GET_OP_LIST | |
#ifdef GET_OP_CLASSES | |
#undef GET_OP_CLASSES | |
//===----------------------------------------------------------------------===// | |
// Local Utility Method Definitions | |
//===----------------------------------------------------------------------===// | |
namespace mlir { | |
namespace tutorial { | |
namespace poly { | |
static ::mlir::LogicalResult __mlir_ods_local_type_constraint_PolyOps0( | |
::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, | |
unsigned valueIndex) { | |
if (!((::llvm::isa<::mlir::tutorial::poly::PolynomialType>(type)))) { | |
return op->emitOpError(valueKind) << " #" << valueIndex | |
<< " must be A polynomial with u32 coefficients, but got " << type; | |
} | |
return ::mlir::success(); | |
} | |
} // namespace poly | |
} // namespace tutorial | |
} // namespace mlir | |
namespace mlir { | |
namespace tutorial { | |
namespace poly { | |
//===----------------------------------------------------------------------===// | |
// ::mlir::tutorial::poly::AddOp definitions | |
//===----------------------------------------------------------------------===// | |
namespace detail { | |
AddOpGenericAdaptorBase::AddOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const ::mlir::EmptyProperties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) | |
odsOpName.emplace("poly.add", odsAttrs.getContext()); | |
} | |
std::pair<unsigned, unsigned> AddOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { | |
return {index, 1}; | |
} | |
::mlir::DictionaryAttr AddOpGenericAdaptorBase::getAttributes() { | |
return odsAttrs; | |
} | |
} // namespace detail | |
AddOpAdaptor::AddOpAdaptor(AddOp op) : AddOpAdaptor(op->getOperands(), op->getAttrDictionary(), op.getProperties(), op->getRegions()) {} | |
::mlir::LogicalResult AddOpAdaptor::verify(::mlir::Location loc) { | |
return ::mlir::success(); | |
} | |
std::pair<unsigned, unsigned> AddOp::getODSOperandIndexAndLength(unsigned index) { | |
return {index, 1}; | |
} | |
::mlir::Operation::operand_range AddOp::getODSOperands(unsigned index) { | |
auto valueRange = getODSOperandIndexAndLength(index); | |
return {std::next(getOperation()->operand_begin(), valueRange.first), | |
std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; | |
} | |
::mlir::TypedValue<::mlir::tutorial::poly::PolynomialType> AddOp::getLhs() { | |
return ::llvm::cast<::mlir::TypedValue<::mlir::tutorial::poly::PolynomialType>>(*getODSOperands(0).begin()); | |
} | |
::mlir::TypedValue<::mlir::tutorial::poly::PolynomialType> AddOp::getRhs() { | |
return ::llvm::cast<::mlir::TypedValue<::mlir::tutorial::poly::PolynomialType>>(*getODSOperands(1).begin()); | |
} | |
::mlir::MutableOperandRange AddOp::getLhsMutable() { | |
auto range = getODSOperandIndexAndLength(0); | |
auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); | |
return mutableRange; | |
} | |
::mlir::MutableOperandRange AddOp::getRhsMutable() { | |
auto range = getODSOperandIndexAndLength(1); | |
auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); | |
return mutableRange; | |
} | |
std::pair<unsigned, unsigned> AddOp::getODSResultIndexAndLength(unsigned index) { | |
return {index, 1}; | |
} | |
::mlir::Operation::result_range AddOp::getODSResults(unsigned index) { | |
auto valueRange = getODSResultIndexAndLength(index); | |
return {std::next(getOperation()->result_begin(), valueRange.first), | |
std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; | |
} | |
::mlir::TypedValue<::mlir::tutorial::poly::PolynomialType> AddOp::getOutput() { | |
return ::llvm::cast<::mlir::TypedValue<::mlir::tutorial::poly::PolynomialType>>(*getODSResults(0).begin()); | |
} | |
void AddOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type output, ::mlir::Value lhs, ::mlir::Value rhs) { | |
odsState.addOperands(lhs); | |
odsState.addOperands(rhs); | |
odsState.addTypes(output); | |
} | |
void AddOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value lhs, ::mlir::Value rhs) { | |
odsState.addOperands(lhs); | |
odsState.addOperands(rhs); | |
assert(resultTypes.size() == 1u && "mismatched number of results"); | |
odsState.addTypes(resultTypes); | |
} | |
void AddOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { | |
assert(operands.size() == 2u && "mismatched number of parameters"); | |
odsState.addOperands(operands); | |
odsState.addAttributes(attributes); | |
assert(resultTypes.size() == 1u && "mismatched number of return types"); | |
odsState.addTypes(resultTypes); | |
} | |
::mlir::LogicalResult AddOp::verifyInvariantsImpl() { | |
{ | |
unsigned index = 0; (void)index; | |
auto valueGroup0 = getODSOperands(0); | |
for (auto v : valueGroup0) { | |
if (::mlir::failed(__mlir_ods_local_type_constraint_PolyOps0(*this, v.getType(), "operand", index++))) | |
return ::mlir::failure(); | |
} | |
auto valueGroup1 = getODSOperands(1); | |
for (auto v : valueGroup1) { | |
if (::mlir::failed(__mlir_ods_local_type_constraint_PolyOps0(*this, v.getType(), "operand", index++))) | |
return ::mlir::failure(); | |
} | |
} | |
{ | |
unsigned index = 0; (void)index; | |
auto valueGroup0 = getODSResults(0); | |
for (auto v : valueGroup0) { | |
if (::mlir::failed(__mlir_ods_local_type_constraint_PolyOps0(*this, v.getType(), "result", index++))) | |
return ::mlir::failure(); | |
} | |
} | |
return ::mlir::success(); | |
} | |
::mlir::LogicalResult AddOp::verifyInvariants() { | |
return verifyInvariantsImpl(); | |
} | |
::mlir::ParseResult AddOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { | |
::mlir::OpAsmParser::UnresolvedOperand lhsRawOperands[1]; | |
::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> lhsOperands(lhsRawOperands); ::llvm::SMLoc lhsOperandsLoc; | |
(void)lhsOperandsLoc; | |
::mlir::OpAsmParser::UnresolvedOperand rhsRawOperands[1]; | |
::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> rhsOperands(rhsRawOperands); ::llvm::SMLoc rhsOperandsLoc; | |
(void)rhsOperandsLoc; | |
::mlir::Type lhsRawTypes[1]; | |
::llvm::ArrayRef<::mlir::Type> lhsTypes(lhsRawTypes); | |
::mlir::Type rhsRawTypes[1]; | |
::llvm::ArrayRef<::mlir::Type> rhsTypes(rhsRawTypes); | |
::mlir::Type outputRawTypes[1]; | |
::llvm::ArrayRef<::mlir::Type> outputTypes(outputRawTypes); | |
lhsOperandsLoc = parser.getCurrentLocation(); | |
if (parser.parseOperand(lhsRawOperands[0])) | |
return ::mlir::failure(); | |
if (parser.parseComma()) | |
return ::mlir::failure(); | |
rhsOperandsLoc = parser.getCurrentLocation(); | |
if (parser.parseOperand(rhsRawOperands[0])) | |
return ::mlir::failure(); | |
{ | |
auto loc = parser.getCurrentLocation();(void)loc; | |
if (parser.parseOptionalAttrDict(result.attributes)) | |
return ::mlir::failure(); | |
} | |
if (parser.parseColon()) | |
return ::mlir::failure(); | |
if (parser.parseLParen()) | |
return ::mlir::failure(); | |
{ | |
::mlir::tutorial::poly::PolynomialType type; | |
if (parser.parseCustomTypeWithFallback(type)) | |
return ::mlir::failure(); | |
lhsRawTypes[0] = type; | |
} | |
if (parser.parseComma()) | |
return ::mlir::failure(); | |
{ | |
::mlir::tutorial::poly::PolynomialType type; | |
if (parser.parseCustomTypeWithFallback(type)) | |
return ::mlir::failure(); | |
rhsRawTypes[0] = type; | |
} | |
if (parser.parseRParen()) | |
return ::mlir::failure(); | |
if (parser.parseArrow()) | |
return ::mlir::failure(); | |
{ | |
::mlir::tutorial::poly::PolynomialType type; | |
if (parser.parseCustomTypeWithFallback(type)) | |
return ::mlir::failure(); | |
outputRawTypes[0] = type; | |
} | |
result.addTypes(outputTypes); | |
if (parser.resolveOperands(lhsOperands, lhsTypes, lhsOperandsLoc, result.operands)) | |
return ::mlir::failure(); | |
if (parser.resolveOperands(rhsOperands, rhsTypes, rhsOperandsLoc, result.operands)) | |
return ::mlir::failure(); | |
return ::mlir::success(); | |
} | |
void AddOp::print(::mlir::OpAsmPrinter &_odsPrinter) { | |
_odsPrinter << ' '; | |
_odsPrinter << getLhs(); | |
_odsPrinter << ","; | |
_odsPrinter << ' '; | |
_odsPrinter << getRhs(); | |
::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; | |
_odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); | |
_odsPrinter << ' ' << ":"; | |
_odsPrinter << ' ' << "("; | |
{ | |
auto type = getLhs().getType(); | |
if (auto validType = ::llvm::dyn_cast<::mlir::tutorial::poly::PolynomialType>(type)) | |
_odsPrinter.printStrippedAttrOrType(validType); | |
else | |
_odsPrinter << type; | |
} | |
_odsPrinter << ","; | |
_odsPrinter << ' '; | |
{ | |
auto type = getRhs().getType(); | |
if (auto validType = ::llvm::dyn_cast<::mlir::tutorial::poly::PolynomialType>(type)) | |
_odsPrinter.printStrippedAttrOrType(validType); | |
else | |
_odsPrinter << type; | |
} | |
_odsPrinter << ")"; | |
_odsPrinter << ' ' << "->"; | |
_odsPrinter << ' '; | |
{ | |
auto type = getOutput().getType(); | |
if (auto validType = ::llvm::dyn_cast<::mlir::tutorial::poly::PolynomialType>(type)) | |
_odsPrinter.printStrippedAttrOrType(validType); | |
else | |
_odsPrinter << type; | |
} | |
} | |
} // namespace poly | |
} // namespace tutorial | |
} // namespace mlir | |
MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::tutorial::poly::AddOp) | |
#endif // GET_OP_CLASSES | |
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
/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ | |
|* *| | |
|* Op Declarations *| | |
|* *| | |
|* Automatically generated file, do not edit! *| | |
|* *| | |
\*===----------------------------------------------------------------------===*/ | |
#if defined(GET_OP_CLASSES) || defined(GET_OP_FWD_DEFINES) | |
#undef GET_OP_FWD_DEFINES | |
namespace mlir { | |
namespace tutorial { | |
namespace poly { | |
class AddOp; | |
} // namespace poly | |
} // namespace tutorial | |
} // namespace mlir | |
#endif | |
#ifdef GET_OP_CLASSES | |
#undef GET_OP_CLASSES | |
//===----------------------------------------------------------------------===// | |
// Local Utility Method Definitions | |
//===----------------------------------------------------------------------===// | |
namespace mlir { | |
namespace tutorial { | |
namespace poly { | |
//===----------------------------------------------------------------------===// | |
// ::mlir::tutorial::poly::AddOp declarations | |
//===----------------------------------------------------------------------===// | |
namespace detail { | |
class AddOpGenericAdaptorBase { | |
public: | |
protected: | |
::mlir::DictionaryAttr odsAttrs; | |
::std::optional<::mlir::OperationName> odsOpName; | |
::mlir::RegionRange odsRegions; | |
public: | |
AddOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}); | |
std::pair<unsigned, unsigned> getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); | |
::mlir::DictionaryAttr getAttributes(); | |
}; | |
} // namespace detail | |
template <typename RangeT> | |
class AddOpGenericAdaptor : public detail::AddOpGenericAdaptorBase { | |
using ValueT = ::llvm::detail::ValueOfRange<RangeT>; | |
using Base = detail::AddOpGenericAdaptorBase; | |
public: | |
AddOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} | |
AddOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : AddOpGenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() : ::mlir::EmptyProperties{}), regions) {} | |
std::pair<unsigned, unsigned> getODSOperandIndexAndLength(unsigned index) { | |
return Base::getODSOperandIndexAndLength(index, odsOperands.size()); | |
} | |
RangeT getODSOperands(unsigned index) { | |
auto valueRange = getODSOperandIndexAndLength(index); | |
return {std::next(odsOperands.begin(), valueRange.first), | |
std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; | |
} | |
ValueT getLhs() { | |
return (*getODSOperands(0).begin()); | |
} | |
ValueT getRhs() { | |
return (*getODSOperands(1).begin()); | |
} | |
RangeT getOperands() { | |
return odsOperands; | |
} | |
private: | |
RangeT odsOperands; | |
}; | |
class AddOpAdaptor : public AddOpGenericAdaptor<::mlir::ValueRange> { | |
public: | |
using AddOpGenericAdaptor::AddOpGenericAdaptor; | |
AddOpAdaptor(AddOp op); | |
::mlir::LogicalResult verify(::mlir::Location loc); | |
}; | |
class AddOp : public ::mlir::Op<AddOp, ::mlir::OpTrait::ZeroRegions, ::mlir::OpTrait::OneResult, ::mlir::OpTrait::OneTypedResult<::mlir::tutorial::poly::PolynomialType>::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::NOperands<2>::Impl, ::mlir::OpTrait::OpInvariants> { | |
public: | |
using Op::Op; | |
using Op::print; | |
using Adaptor = AddOpAdaptor; | |
template <typename RangeT> | |
using GenericAdaptor = AddOpGenericAdaptor<RangeT>; | |
using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; | |
static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { | |
return {}; | |
} | |
static constexpr ::llvm::StringLiteral getOperationName() { | |
return ::llvm::StringLiteral("poly.add"); | |
} | |
std::pair<unsigned, unsigned> getODSOperandIndexAndLength(unsigned index); | |
::mlir::Operation::operand_range getODSOperands(unsigned index); | |
::mlir::TypedValue<::mlir::tutorial::poly::PolynomialType> getLhs(); | |
::mlir::TypedValue<::mlir::tutorial::poly::PolynomialType> getRhs(); | |
::mlir::MutableOperandRange getLhsMutable(); | |
::mlir::MutableOperandRange getRhsMutable(); | |
std::pair<unsigned, unsigned> getODSResultIndexAndLength(unsigned index); | |
::mlir::Operation::result_range getODSResults(unsigned index); | |
::mlir::TypedValue<::mlir::tutorial::poly::PolynomialType> getOutput(); | |
static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type output, ::mlir::Value lhs, ::mlir::Value rhs); | |
static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value lhs, ::mlir::Value rhs); | |
static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); | |
::mlir::LogicalResult verifyInvariantsImpl(); | |
::mlir::LogicalResult verifyInvariants(); | |
static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); | |
void print(::mlir::OpAsmPrinter &_odsPrinter); | |
public: | |
}; | |
} // namespace poly | |
} // namespace tutorial | |
} // namespace mlir | |
MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::tutorial::poly::AddOp) | |
#endif // GET_OP_CLASSES | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment