17#include "mlir/Support/LogicalResult.h"
19#include "clang/CIR/Dialect/IR/CIROpsDialect.cpp.inc"
28void cir::CIRDialect::initialize() {
33#include "clang/CIR/Dialect/IR/CIROps.cpp.inc"
42 mlir::Attribute attrType) {
43 if (isa<cir::ConstPtrAttr>(attrType)) {
44 if (!mlir::isa<cir::PointerType>(opType))
45 return op->emitOpError(
46 "pointer constant initializing a non-pointer type");
50 if (mlir::isa<cir::IntAttr, cir::FPAttr>(attrType)) {
51 auto at = cast<TypedAttr>(attrType);
52 if (at.getType() != opType) {
53 return op->emitOpError(
"result type (")
54 << opType <<
") does not match value type (" << at.getType()
60 assert(isa<TypedAttr>(attrType) &&
"What else could we be looking at here?");
61 return op->emitOpError(
"global with type ")
62 << cast<TypedAttr>(attrType).getType() <<
" not yet supported";
65LogicalResult cir::ConstantOp::verify() {
72OpFoldResult cir::ConstantOp::fold(FoldAdaptor ) {
81 mlir::Attribute &valueAttr) {
83 return parser.parseAttribute(valueAttr,
"value", attr);
87 p.printAttribute(value);
90mlir::LogicalResult cir::GlobalOp::verify() {
93 if (getInitialValue().has_value()) {
105void cir::GlobalOp::build(OpBuilder &odsBuilder, OperationState &odsState,
106 llvm::StringRef sym_name, mlir::Type sym_type) {
107 odsState.addAttribute(getSymNameAttrName(odsState.name),
108 odsBuilder.getStringAttr(sym_name));
109 odsState.addAttribute(getSymTypeAttrName(odsState.name),
110 mlir::TypeAttr::get(sym_type));
115 Attribute initAttr) {
116 if (!op.isDeclaration()) {
128 Attribute &initialValueAttr) {
130 if (parser.parseOptionalEqual().failed()) {
133 if (parser.parseColonType(opTy))
142 assert(mlir::isa<mlir::TypedAttr>(initialValueAttr) &&
143 "Non-typed attrs shouldn't appear here.");
144 auto typedAttr = mlir::cast<mlir::TypedAttr>(initialValueAttr);
145 opTy = typedAttr.getType();
148 typeAttr = TypeAttr::get(opTy);
156void cir::FuncOp::build(OpBuilder &builder, OperationState &result,
158 result.addAttribute(SymbolTable::getSymbolAttrName(),
159 builder.getStringAttr(name));
162ParseResult cir::FuncOp::parse(OpAsmParser &parser, OperationState &state) {
164 if (parser.parseSymbolName(nameAttr, SymbolTable::getSymbolAttrName(),
170void cir::FuncOp::print(OpAsmPrinter &p) {
173 p.printSymbolName(getSymName());
178mlir::LogicalResult cir::FuncOp::verify() {
return success(); }
184#define GET_OP_CLASSES
185#include "clang/CIR/Dialect/IR/CIROps.cpp.inc"
static void printGlobalOpTypeAndInitialValue(OpAsmPrinter &p, cir::GlobalOp op, TypeAttr type, Attribute initAttr)
static ParseResult parseGlobalOpTypeAndInitialValue(OpAsmParser &parser, TypeAttr &typeAttr, Attribute &initialValueAttr)
static void printConstant(OpAsmPrinter &p, Attribute value)
static ParseResult parseConstantValue(OpAsmParser &parser, mlir::Attribute &valueAttr)
static LogicalResult checkConstantTypes(mlir::Operation *op, mlir::Type opType, mlir::Attribute attrType)