clang 20.0.0git
CIRDialect.cpp
Go to the documentation of this file.
1//===- CIRDialect.cpp - MLIR CIR ops implementation -----------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the CIR dialect and its operations.
10//
11//===----------------------------------------------------------------------===//
12
14
15#include "mlir/Support/LogicalResult.h"
16
17#include "clang/CIR/Dialect/IR/CIROpsDialect.cpp.inc"
18
19using namespace mlir;
20using namespace cir;
21
22//===----------------------------------------------------------------------===//
23// CIR Dialect
24//===----------------------------------------------------------------------===//
25
26void cir::CIRDialect::initialize() {
27 registerTypes();
28 registerAttributes();
29 addOperations<
30#define GET_OP_LIST
31#include "clang/CIR/Dialect/IR/CIROps.cpp.inc"
32 >();
33}
34
35//===----------------------------------------------------------------------===//
36// GlobalOp
37//===----------------------------------------------------------------------===//
38
39// TODO(CIR): The properties of global variables that require verification
40// haven't been implemented yet.
41mlir::LogicalResult cir::GlobalOp::verify() { return success(); }
42
43void cir::GlobalOp::build(OpBuilder &odsBuilder, OperationState &odsState,
44 llvm::StringRef sym_name, mlir::Type sym_type) {
45 odsState.addAttribute(getSymNameAttrName(odsState.name),
46 odsBuilder.getStringAttr(sym_name));
47 odsState.addAttribute(getSymTypeAttrName(odsState.name),
48 mlir::TypeAttr::get(sym_type));
49}
50
51//===----------------------------------------------------------------------===//
52// FuncOp
53//===----------------------------------------------------------------------===//
54
55void cir::FuncOp::build(OpBuilder &builder, OperationState &result,
56 StringRef name) {
57 result.addAttribute(SymbolTable::getSymbolAttrName(),
58 builder.getStringAttr(name));
59}
60
61ParseResult cir::FuncOp::parse(OpAsmParser &parser, OperationState &state) {
62 StringAttr nameAttr;
63 if (parser.parseSymbolName(nameAttr, SymbolTable::getSymbolAttrName(),
64 state.attributes))
65 return failure();
66 return success();
67}
68
69void cir::FuncOp::print(OpAsmPrinter &p) {
70 p << ' ';
71 // For now the only property a function has is its name
72 p.printSymbolName(getSymName());
73}
74
75// TODO(CIR): The properties of functions that require verification haven't
76// been implemented yet.
77mlir::LogicalResult cir::FuncOp::verify() { return success(); }
78
79//===----------------------------------------------------------------------===//
80// TableGen'd op method definitions
81//===----------------------------------------------------------------------===//
82
83#define GET_OP_CLASSES
84#include "clang/CIR/Dialect/IR/CIROps.cpp.inc"