//===- EmitC.cpp - EmitC Dialect ------------------------------------------===// // // 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/Dialect/EmitC/IR/EmitC.h" #include "mlir/Dialect/EmitC/IR/EmitCTraits.h" #include "mlir/IR/Builders.h" #include "mlir/IR/BuiltinAttributes.h" #include "mlir/IR/BuiltinTypes.h" #include "mlir/IR/DialectImplementation.h" #include "mlir/IR/IRMapping.h" #include "mlir/IR/Types.h" #include "mlir/Interfaces/FunctionImplementation.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/TypeSwitch.h" #include "llvm/Support/Casting.h" usingnamespacemlir; usingnamespacemlir::emitc; #include "mlir/Dialect/EmitC/IR/EmitCDialect.cpp.inc" //===----------------------------------------------------------------------===// // EmitCDialect //===----------------------------------------------------------------------===// void EmitCDialect::initialize() { … } /// Materialize a single constant operation from a given attribute value with /// the desired resultant type. Operation *EmitCDialect::materializeConstant(OpBuilder &builder, Attribute value, Type type, Location loc) { … } /// Default callback for builders of ops carrying a region. Inserts a yield /// without arguments. void mlir::emitc::buildTerminatedBody(OpBuilder &builder, Location loc) { … } bool mlir::emitc::isSupportedEmitCType(Type type) { … } bool mlir::emitc::isSupportedIntegerType(Type type) { … } bool mlir::emitc::isIntegerIndexOrOpaqueType(Type type) { … } bool mlir::emitc::isSupportedFloatType(Type type) { … } bool mlir::emitc::isPointerWideType(Type type) { … } /// Check that the type of the initial value is compatible with the operations /// result type. static LogicalResult verifyInitializationAttribute(Operation *op, Attribute value) { … } //===----------------------------------------------------------------------===// // AddOp //===----------------------------------------------------------------------===// LogicalResult AddOp::verify() { … } //===----------------------------------------------------------------------===// // ApplyOp //===----------------------------------------------------------------------===// LogicalResult ApplyOp::verify() { … } //===----------------------------------------------------------------------===// // AssignOp //===----------------------------------------------------------------------===// /// The assign op requires that the assigned value's type matches the /// assigned-to variable type. LogicalResult emitc::AssignOp::verify() { … } //===----------------------------------------------------------------------===// // CastOp //===----------------------------------------------------------------------===// bool CastOp::areCastCompatible(TypeRange inputs, TypeRange outputs) { … } //===----------------------------------------------------------------------===// // CallOpaqueOp //===----------------------------------------------------------------------===// LogicalResult emitc::CallOpaqueOp::verify() { … } //===----------------------------------------------------------------------===// // ConstantOp //===----------------------------------------------------------------------===// LogicalResult emitc::ConstantOp::verify() { … } OpFoldResult emitc::ConstantOp::fold(FoldAdaptor adaptor) { … } //===----------------------------------------------------------------------===// // ExpressionOp //===----------------------------------------------------------------------===// Operation *ExpressionOp::getRootOp() { … } LogicalResult ExpressionOp::verify() { … } //===----------------------------------------------------------------------===// // ForOp //===----------------------------------------------------------------------===// void ForOp::build(OpBuilder &builder, OperationState &result, Value lb, Value ub, Value step, BodyBuilderFn bodyBuilder) { … } void ForOp::getCanonicalizationPatterns(RewritePatternSet &, MLIRContext *) { … } ParseResult ForOp::parse(OpAsmParser &parser, OperationState &result) { … } void ForOp::print(OpAsmPrinter &p) { … } LogicalResult ForOp::verifyRegions() { … } //===----------------------------------------------------------------------===// // CallOp //===----------------------------------------------------------------------===// LogicalResult CallOp::verifySymbolUses(SymbolTableCollection &symbolTable) { … } FunctionType CallOp::getCalleeType() { … } //===----------------------------------------------------------------------===// // DeclareFuncOp //===----------------------------------------------------------------------===// LogicalResult DeclareFuncOp::verifySymbolUses(SymbolTableCollection &symbolTable) { … } //===----------------------------------------------------------------------===// // FuncOp //===----------------------------------------------------------------------===// void FuncOp::build(OpBuilder &builder, OperationState &state, StringRef name, FunctionType type, ArrayRef<NamedAttribute> attrs, ArrayRef<DictionaryAttr> argAttrs) { … } ParseResult FuncOp::parse(OpAsmParser &parser, OperationState &result) { … } void FuncOp::print(OpAsmPrinter &p) { … } LogicalResult FuncOp::verify() { … } //===----------------------------------------------------------------------===// // ReturnOp //===----------------------------------------------------------------------===// LogicalResult ReturnOp::verify() { … } //===----------------------------------------------------------------------===// // IfOp //===----------------------------------------------------------------------===// void IfOp::build(OpBuilder &builder, OperationState &result, Value cond, bool addThenBlock, bool addElseBlock) { … } void IfOp::build(OpBuilder &builder, OperationState &result, Value cond, bool withElseRegion) { … } void IfOp::build(OpBuilder &builder, OperationState &result, Value cond, function_ref<void(OpBuilder &, Location)> thenBuilder, function_ref<void(OpBuilder &, Location)> elseBuilder) { … } ParseResult IfOp::parse(OpAsmParser &parser, OperationState &result) { … } void IfOp::print(OpAsmPrinter &p) { … } /// Given the region at `index`, or the parent operation if `index` is None, /// return the successor regions. These are the regions that may be selected /// during the flow of control. `operands` is a set of optional attributes that /// correspond to a constant value for each operand, or null if that operand is /// not a constant. void IfOp::getSuccessorRegions(RegionBranchPoint point, SmallVectorImpl<RegionSuccessor> ®ions) { … } void IfOp::getEntrySuccessorRegions(ArrayRef<Attribute> operands, SmallVectorImpl<RegionSuccessor> ®ions) { … } void IfOp::getRegionInvocationBounds( ArrayRef<Attribute> operands, SmallVectorImpl<InvocationBounds> &invocationBounds) { … } //===----------------------------------------------------------------------===// // IncludeOp //===----------------------------------------------------------------------===// void IncludeOp::print(OpAsmPrinter &p) { … } ParseResult IncludeOp::parse(OpAsmParser &parser, OperationState &result) { … } //===----------------------------------------------------------------------===// // LiteralOp //===----------------------------------------------------------------------===// /// The literal op requires a non-empty value. LogicalResult emitc::LiteralOp::verify() { … } //===----------------------------------------------------------------------===// // SubOp //===----------------------------------------------------------------------===// LogicalResult SubOp::verify() { … } //===----------------------------------------------------------------------===// // VariableOp //===----------------------------------------------------------------------===// LogicalResult emitc::VariableOp::verify() { … } //===----------------------------------------------------------------------===// // YieldOp //===----------------------------------------------------------------------===// LogicalResult emitc::YieldOp::verify() { … } //===----------------------------------------------------------------------===// // SubscriptOp //===----------------------------------------------------------------------===// LogicalResult emitc::SubscriptOp::verify() { … } //===----------------------------------------------------------------------===// // EmitC Enums //===----------------------------------------------------------------------===// #include "mlir/Dialect/EmitC/IR/EmitCEnums.cpp.inc" //===----------------------------------------------------------------------===// // EmitC Attributes //===----------------------------------------------------------------------===// #define GET_ATTRDEF_CLASSES #include "mlir/Dialect/EmitC/IR/EmitCAttributes.cpp.inc" //===----------------------------------------------------------------------===// // EmitC Types //===----------------------------------------------------------------------===// #define GET_TYPEDEF_CLASSES #include "mlir/Dialect/EmitC/IR/EmitCTypes.cpp.inc" //===----------------------------------------------------------------------===// // ArrayType //===----------------------------------------------------------------------===// Type emitc::ArrayType::parse(AsmParser &parser) { … } void emitc::ArrayType::print(AsmPrinter &printer) const { … } LogicalResult emitc::ArrayType::verify( ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, ::llvm::ArrayRef<int64_t> shape, Type elementType) { … } emitc::ArrayType emitc::ArrayType::cloneWith(std::optional<ArrayRef<int64_t>> shape, Type elementType) const { … } //===----------------------------------------------------------------------===// // LValueType //===----------------------------------------------------------------------===// LogicalResult mlir::emitc::LValueType::verify( llvm::function_ref<mlir::InFlightDiagnostic()> emitError, mlir::Type value) { … } //===----------------------------------------------------------------------===// // OpaqueType //===----------------------------------------------------------------------===// LogicalResult mlir::emitc::OpaqueType::verify( llvm::function_ref<mlir::InFlightDiagnostic()> emitError, llvm::StringRef value) { … } //===----------------------------------------------------------------------===// // PointerType //===----------------------------------------------------------------------===// LogicalResult mlir::emitc::PointerType::verify( llvm::function_ref<mlir::InFlightDiagnostic()> emitError, Type value) { … } //===----------------------------------------------------------------------===// // GlobalOp //===----------------------------------------------------------------------===// static void printEmitCGlobalOpTypeAndInitialValue(OpAsmPrinter &p, GlobalOp op, TypeAttr type, Attribute initialValue) { … } static Type getInitializerTypeForGlobal(Type type) { … } static ParseResult parseEmitCGlobalOpTypeAndInitialValue(OpAsmParser &parser, TypeAttr &typeAttr, Attribute &initialValue) { … } LogicalResult GlobalOp::verify() { … } //===----------------------------------------------------------------------===// // GetGlobalOp //===----------------------------------------------------------------------===// LogicalResult GetGlobalOp::verifySymbolUses(SymbolTableCollection &symbolTable) { … } //===----------------------------------------------------------------------===// // SwitchOp //===----------------------------------------------------------------------===// /// Parse the case regions and values. static ParseResult parseSwitchCases(OpAsmParser &parser, DenseI64ArrayAttr &cases, SmallVectorImpl<std::unique_ptr<Region>> &caseRegions) { … } /// Print the case regions and values. static void printSwitchCases(OpAsmPrinter &p, Operation *op, DenseI64ArrayAttr cases, RegionRange caseRegions) { … } static LogicalResult verifyRegion(emitc::SwitchOp op, Region ®ion, const Twine &name) { … } LogicalResult emitc::SwitchOp::verify() { … } unsigned emitc::SwitchOp::getNumCases() { … } Block &emitc::SwitchOp::getDefaultBlock() { … } Block &emitc::SwitchOp::getCaseBlock(unsigned idx) { … } void SwitchOp::getSuccessorRegions( RegionBranchPoint point, SmallVectorImpl<RegionSuccessor> &successors) { … } void SwitchOp::getEntrySuccessorRegions( ArrayRef<Attribute> operands, SmallVectorImpl<RegionSuccessor> &successors) { … } void SwitchOp::getRegionInvocationBounds( ArrayRef<Attribute> operands, SmallVectorImpl<InvocationBounds> &bounds) { … } //===----------------------------------------------------------------------===// // TableGen'd op method definitions //===----------------------------------------------------------------------===// #define GET_OP_CLASSES #include "mlir/Dialect/EmitC/IR/EmitC.cpp.inc"