19#include "mlir/IR/Attributes.h"
20#include "mlir/IR/DialectImplementation.h"
21#include "mlir/Interfaces/ControlFlowInterfaces.h"
22#include "mlir/Interfaces/FunctionImplementation.h"
23#include "mlir/Support/LLVM.h"
25#include "clang/CIR/Dialect/IR/CIROpsDialect.cpp.inc"
26#include "clang/CIR/Dialect/IR/CIROpsEnums.cpp.inc"
28#include "llvm/ADT/SetOperations.h"
29#include "llvm/ADT/SmallSet.h"
30#include "llvm/Support/LogicalResult.h"
39struct CIROpAsmDialectInterface :
public OpAsmDialectInterface {
40 using OpAsmDialectInterface::OpAsmDialectInterface;
42 AliasResult getAlias(Type type, raw_ostream &os)
const final {
43 if (
auto recordType = dyn_cast<cir::RecordType>(type)) {
46 os <<
"rec_anon_" <<
recordType.getKindAsStr();
48 os <<
"rec_" << nameAttr.getValue();
49 return AliasResult::OverridableAlias;
51 if (
auto intType = dyn_cast<cir::IntType>(type)) {
54 unsigned width = intType.getWidth();
55 if (width < 8 || !llvm::isPowerOf2_32(width))
56 return AliasResult::NoAlias;
57 os << intType.getAlias();
58 return AliasResult::OverridableAlias;
60 if (
auto voidType = dyn_cast<cir::VoidType>(type)) {
61 os << voidType.getAlias();
62 return AliasResult::OverridableAlias;
65 return AliasResult::NoAlias;
68 AliasResult getAlias(Attribute attr, raw_ostream &os)
const final {
69 if (
auto boolAttr = mlir::dyn_cast<cir::BoolAttr>(attr)) {
70 os << (boolAttr.getValue() ?
"true" :
"false");
71 return AliasResult::FinalAlias;
73 if (
auto bitfield = mlir::dyn_cast<cir::BitfieldInfoAttr>(attr)) {
74 os <<
"bfi_" << bitfield.getName().str();
75 return AliasResult::FinalAlias;
77 if (
auto dynCastInfoAttr = mlir::dyn_cast<cir::DynamicCastInfoAttr>(attr)) {
78 os << dynCastInfoAttr.getAlias();
79 return AliasResult::FinalAlias;
81 return AliasResult::NoAlias;
86void cir::CIRDialect::initialize() {
91#include "clang/CIR/Dialect/IR/CIROps.cpp.inc"
93 addInterfaces<CIROpAsmDialectInterface>();
96Operation *cir::CIRDialect::materializeConstant(mlir::OpBuilder &builder,
97 mlir::Attribute value,
100 return cir::ConstantOp::create(builder, loc, type,
101 mlir::cast<mlir::TypedAttr>(value));
113 for (
auto en : llvm::enumerate(keywords)) {
114 if (succeeded(parser.parseOptionalKeyword(en.value())))
121template <
typename Ty>
struct EnumTraits {};
123#define REGISTER_ENUM_TYPE(Ty) \
124 template <> struct EnumTraits<cir::Ty> { \
125 static llvm::StringRef stringify(cir::Ty value) { \
126 return stringify##Ty(value); \
128 static unsigned getMaxEnumVal() { return cir::getMaxEnumValFor##Ty(); } \
139template <
typename EnumTy,
typename RetTy = EnumTy>
142 for (
unsigned i = 0, e = EnumTraits<EnumTy>::getMaxEnumVal(); i <= e; ++i)
143 names.push_back(EnumTraits<EnumTy>::stringify(
static_cast<EnumTy
>(i)));
147 return static_cast<RetTy
>(defaultValue);
148 return static_cast<RetTy
>(index);
152template <
typename EnumTy,
typename RetTy = EnumTy>
155 for (
unsigned i = 0, e = EnumTraits<EnumTy>::getMaxEnumVal(); i <= e; ++i)
156 names.push_back(EnumTraits<EnumTy>::stringify(
static_cast<EnumTy
>(i)));
161 result =
static_cast<RetTy
>(index);
169 Location eLoc = parser.getEncodedSourceLoc(parser.getCurrentLocation());
170 OpBuilder builder(parser.getBuilder().getContext());
175 builder.createBlock(®ion);
177 Block &block = region.back();
179 if (!block.empty() && block.back().hasTrait<OpTrait::IsTerminator>())
183 if (!region.hasOneBlock())
184 return parser.emitError(errLoc,
185 "multi-block region must not omit terminator");
188 builder.setInsertionPointToEnd(&block);
189 cir::YieldOp::create(builder, eLoc);
195 const auto singleNonEmptyBlock = r.hasOneBlock() && !r.back().empty();
196 const auto yieldsNothing = [&r]() {
197 auto y = dyn_cast<cir::YieldOp>(r.back().getTerminator());
198 return y && y.getArgs().empty();
200 return singleNonEmptyBlock && yieldsNothing();
204 cir::VisibilityAttr &visibility) {
205 switch (visibility.getValue()) {
206 case cir::VisibilityKind::Hidden:
209 case cir::VisibilityKind::Protected:
210 printer <<
"protected";
212 case cir::VisibilityKind::Default:
218 cir::VisibilityKind visibilityKind =
220 visibility = cir::VisibilityAttr::get(parser.getContext(), visibilityKind);
228 cir::InlineKindAttr &inlineKindAttr) {
230 static constexpr llvm::StringRef keywords[] = {
"no_inline",
"always_inline",
234 llvm::StringRef keyword;
235 if (parser.parseOptionalKeyword(&keyword, keywords).failed()) {
241 auto inlineKindResult = ::cir::symbolizeEnum<::cir::InlineKind>(keyword);
242 if (!inlineKindResult) {
243 return parser.emitError(parser.getCurrentLocation(),
"expected one of [")
245 <<
"] for inlineKind, got: " << keyword;
249 ::cir::InlineKindAttr::get(parser.getContext(), *inlineKindResult);
254 if (inlineKindAttr) {
255 p <<
" " << stringifyInlineKind(inlineKindAttr.getValue());
263 mlir::Region ®ion) {
264 auto regionLoc = parser.getCurrentLocation();
265 if (parser.parseRegion(region))
274 mlir::Region ®ion) {
275 printer.printRegion(region,
284void cir::AllocaOp::build(mlir::OpBuilder &odsBuilder,
285 mlir::OperationState &odsState, mlir::Type addr,
286 mlir::Type allocaType, llvm::StringRef name,
287 mlir::IntegerAttr alignment) {
288 odsState.addAttribute(getAllocaTypeAttrName(odsState.name),
289 mlir::TypeAttr::get(allocaType));
290 odsState.addAttribute(getNameAttrName(odsState.name),
291 odsBuilder.getStringAttr(name));
293 odsState.addAttribute(getAlignmentAttrName(odsState.name), alignment);
295 odsState.addTypes(addr);
302LogicalResult cir::BreakOp::verify() {
304 if (!getOperation()->getParentOfType<LoopOpInterface>() &&
305 !getOperation()->getParentOfType<SwitchOp>())
306 return emitOpError(
"must be within a loop");
318void cir::ConditionOp::getSuccessorRegions(
324 if (
auto loopOp = dyn_cast<LoopOpInterface>(getOperation()->getParentOp())) {
325 regions.emplace_back(&loopOp.getBody(), loopOp.getBody().getArguments());
326 regions.emplace_back(getOperation(), loopOp->getResults());
330 auto await = cast<AwaitOp>(getOperation()->getParentOp());
331 regions.emplace_back(&await.getResume(), await.getResume().getArguments());
332 regions.emplace_back(&await.getSuspend(), await.getSuspend().getArguments());
336cir::ConditionOp::getMutableSuccessorOperands(RegionSuccessor point) {
338 return MutableOperandRange(getOperation(), 0, 0);
341LogicalResult cir::ConditionOp::verify() {
342 if (!isa<LoopOpInterface, AwaitOp>(getOperation()->getParentOp()))
343 return emitOpError(
"condition must be within a conditional region");
352 mlir::Attribute attrType) {
353 if (isa<cir::ConstPtrAttr>(attrType)) {
354 if (!mlir::isa<cir::PointerType>(opType))
355 return op->emitOpError(
356 "pointer constant initializing a non-pointer type");
360 if (isa<cir::DataMemberAttr>(attrType)) {
366 if (isa<cir::ZeroAttr>(attrType)) {
367 if (isa<cir::RecordType, cir::ArrayType, cir::VectorType, cir::ComplexType>(
370 return op->emitOpError(
371 "zero expects struct, array, vector, or complex type");
374 if (mlir::isa<cir::UndefAttr>(attrType)) {
375 if (!mlir::isa<cir::VoidType>(opType))
377 return op->emitOpError(
"undef expects non-void type");
380 if (mlir::isa<cir::BoolAttr>(attrType)) {
381 if (!mlir::isa<cir::BoolType>(opType))
382 return op->emitOpError(
"result type (")
383 << opType <<
") must be '!cir.bool' for '" << attrType <<
"'";
387 if (mlir::isa<cir::IntAttr, cir::FPAttr>(attrType)) {
388 auto at = cast<TypedAttr>(attrType);
389 if (at.getType() != opType) {
390 return op->emitOpError(
"result type (")
391 << opType <<
") does not match value type (" << at.getType()
397 if (mlir::isa<cir::ConstArrayAttr, cir::ConstVectorAttr,
398 cir::ConstComplexAttr, cir::ConstRecordAttr,
399 cir::GlobalViewAttr, cir::PoisonAttr, cir::TypeInfoAttr,
400 cir::VTableAttr>(attrType))
403 assert(isa<TypedAttr>(attrType) &&
"What else could we be looking at here?");
404 return op->emitOpError(
"global with type ")
405 << cast<TypedAttr>(attrType).getType() <<
" not yet supported";
408LogicalResult cir::ConstantOp::verify() {
415OpFoldResult cir::ConstantOp::fold(FoldAdaptor ) {
423LogicalResult cir::ContinueOp::verify() {
424 if (!getOperation()->getParentOfType<LoopOpInterface>())
425 return emitOpError(
"must be within a loop");
433LogicalResult cir::CastOp::verify() {
434 mlir::Type resType =
getType();
435 mlir::Type srcType = getSrc().getType();
439 auto srcPtrTy = mlir::dyn_cast<cir::PointerType>(srcType);
440 auto resPtrTy = mlir::dyn_cast<cir::PointerType>(resType);
441 if (srcPtrTy && resPtrTy && (
getKind() != cir::CastKind::address_space))
442 if (srcPtrTy.getAddrSpace() != resPtrTy.getAddrSpace()) {
443 return emitOpError() <<
"result type address space does not match the "
444 "address space of the operand";
447 if (mlir::isa<cir::VectorType>(srcType) &&
448 mlir::isa<cir::VectorType>(resType)) {
451 srcType = mlir::dyn_cast<cir::VectorType>(srcType).getElementType();
452 resType = mlir::dyn_cast<cir::VectorType>(resType).getElementType();
456 case cir::CastKind::int_to_bool: {
457 if (!mlir::isa<cir::BoolType>(resType))
458 return emitOpError() <<
"requires !cir.bool type for result";
459 if (!mlir::isa<cir::IntType>(srcType))
460 return emitOpError() <<
"requires !cir.int type for source";
463 case cir::CastKind::ptr_to_bool: {
464 if (!mlir::isa<cir::BoolType>(resType))
465 return emitOpError() <<
"requires !cir.bool type for result";
466 if (!mlir::isa<cir::PointerType>(srcType))
467 return emitOpError() <<
"requires !cir.ptr type for source";
470 case cir::CastKind::integral: {
471 if (!mlir::isa<cir::IntType>(resType))
472 return emitOpError() <<
"requires !cir.int type for result";
473 if (!mlir::isa<cir::IntType>(srcType))
474 return emitOpError() <<
"requires !cir.int type for source";
477 case cir::CastKind::array_to_ptrdecay: {
478 const auto arrayPtrTy = mlir::dyn_cast<cir::PointerType>(srcType);
479 const auto flatPtrTy = mlir::dyn_cast<cir::PointerType>(resType);
480 if (!arrayPtrTy || !flatPtrTy)
481 return emitOpError() <<
"requires !cir.ptr type for source and result";
486 case cir::CastKind::bitcast: {
488 auto srcPtrTy = mlir::dyn_cast<cir::PointerType>(srcType);
489 auto resPtrTy = mlir::dyn_cast<cir::PointerType>(resType);
491 if (srcPtrTy && resPtrTy) {
497 case cir::CastKind::floating: {
498 if (!mlir::isa<cir::FPTypeInterface>(srcType) ||
499 !mlir::isa<cir::FPTypeInterface>(resType))
500 return emitOpError() <<
"requires !cir.float type for source and result";
503 case cir::CastKind::float_to_int: {
504 if (!mlir::isa<cir::FPTypeInterface>(srcType))
505 return emitOpError() <<
"requires !cir.float type for source";
506 if (!mlir::dyn_cast<cir::IntType>(resType))
507 return emitOpError() <<
"requires !cir.int type for result";
510 case cir::CastKind::int_to_ptr: {
511 if (!mlir::dyn_cast<cir::IntType>(srcType))
512 return emitOpError() <<
"requires !cir.int type for source";
513 if (!mlir::dyn_cast<cir::PointerType>(resType))
514 return emitOpError() <<
"requires !cir.ptr type for result";
517 case cir::CastKind::ptr_to_int: {
518 if (!mlir::dyn_cast<cir::PointerType>(srcType))
519 return emitOpError() <<
"requires !cir.ptr type for source";
520 if (!mlir::dyn_cast<cir::IntType>(resType))
521 return emitOpError() <<
"requires !cir.int type for result";
524 case cir::CastKind::float_to_bool: {
525 if (!mlir::isa<cir::FPTypeInterface>(srcType))
526 return emitOpError() <<
"requires !cir.float type for source";
527 if (!mlir::isa<cir::BoolType>(resType))
528 return emitOpError() <<
"requires !cir.bool type for result";
531 case cir::CastKind::bool_to_int: {
532 if (!mlir::isa<cir::BoolType>(srcType))
533 return emitOpError() <<
"requires !cir.bool type for source";
534 if (!mlir::isa<cir::IntType>(resType))
535 return emitOpError() <<
"requires !cir.int type for result";
538 case cir::CastKind::int_to_float: {
539 if (!mlir::isa<cir::IntType>(srcType))
540 return emitOpError() <<
"requires !cir.int type for source";
541 if (!mlir::isa<cir::FPTypeInterface>(resType))
542 return emitOpError() <<
"requires !cir.float type for result";
545 case cir::CastKind::bool_to_float: {
546 if (!mlir::isa<cir::BoolType>(srcType))
547 return emitOpError() <<
"requires !cir.bool type for source";
548 if (!mlir::isa<cir::FPTypeInterface>(resType))
549 return emitOpError() <<
"requires !cir.float type for result";
552 case cir::CastKind::address_space: {
553 auto srcPtrTy = mlir::dyn_cast<cir::PointerType>(srcType);
554 auto resPtrTy = mlir::dyn_cast<cir::PointerType>(resType);
555 if (!srcPtrTy || !resPtrTy)
556 return emitOpError() <<
"requires !cir.ptr type for source and result";
557 if (srcPtrTy.getPointee() != resPtrTy.getPointee())
558 return emitOpError() <<
"requires two types differ in addrspace only";
561 case cir::CastKind::float_to_complex: {
562 if (!mlir::isa<cir::FPTypeInterface>(srcType))
563 return emitOpError() <<
"requires !cir.float type for source";
564 auto resComplexTy = mlir::dyn_cast<cir::ComplexType>(resType);
566 return emitOpError() <<
"requires !cir.complex type for result";
567 if (srcType != resComplexTy.getElementType())
568 return emitOpError() <<
"requires source type match result element type";
571 case cir::CastKind::int_to_complex: {
572 if (!mlir::isa<cir::IntType>(srcType))
573 return emitOpError() <<
"requires !cir.int type for source";
574 auto resComplexTy = mlir::dyn_cast<cir::ComplexType>(resType);
576 return emitOpError() <<
"requires !cir.complex type for result";
577 if (srcType != resComplexTy.getElementType())
578 return emitOpError() <<
"requires source type match result element type";
581 case cir::CastKind::float_complex_to_real: {
582 auto srcComplexTy = mlir::dyn_cast<cir::ComplexType>(srcType);
584 return emitOpError() <<
"requires !cir.complex type for source";
585 if (!mlir::isa<cir::FPTypeInterface>(resType))
586 return emitOpError() <<
"requires !cir.float type for result";
587 if (srcComplexTy.getElementType() != resType)
588 return emitOpError() <<
"requires source element type match result type";
591 case cir::CastKind::int_complex_to_real: {
592 auto srcComplexTy = mlir::dyn_cast<cir::ComplexType>(srcType);
594 return emitOpError() <<
"requires !cir.complex type for source";
595 if (!mlir::isa<cir::IntType>(resType))
596 return emitOpError() <<
"requires !cir.int type for result";
597 if (srcComplexTy.getElementType() != resType)
598 return emitOpError() <<
"requires source element type match result type";
601 case cir::CastKind::float_complex_to_bool: {
602 auto srcComplexTy = mlir::dyn_cast<cir::ComplexType>(srcType);
603 if (!srcComplexTy || !srcComplexTy.isFloatingPointComplex())
605 <<
"requires floating point !cir.complex type for source";
606 if (!mlir::isa<cir::BoolType>(resType))
607 return emitOpError() <<
"requires !cir.bool type for result";
610 case cir::CastKind::int_complex_to_bool: {
611 auto srcComplexTy = mlir::dyn_cast<cir::ComplexType>(srcType);
612 if (!srcComplexTy || !srcComplexTy.isIntegerComplex())
614 <<
"requires floating point !cir.complex type for source";
615 if (!mlir::isa<cir::BoolType>(resType))
616 return emitOpError() <<
"requires !cir.bool type for result";
619 case cir::CastKind::float_complex: {
620 auto srcComplexTy = mlir::dyn_cast<cir::ComplexType>(srcType);
621 if (!srcComplexTy || !srcComplexTy.isFloatingPointComplex())
623 <<
"requires floating point !cir.complex type for source";
624 auto resComplexTy = mlir::dyn_cast<cir::ComplexType>(resType);
625 if (!resComplexTy || !resComplexTy.isFloatingPointComplex())
627 <<
"requires floating point !cir.complex type for result";
630 case cir::CastKind::float_complex_to_int_complex: {
631 auto srcComplexTy = mlir::dyn_cast<cir::ComplexType>(srcType);
632 if (!srcComplexTy || !srcComplexTy.isFloatingPointComplex())
634 <<
"requires floating point !cir.complex type for source";
635 auto resComplexTy = mlir::dyn_cast<cir::ComplexType>(resType);
636 if (!resComplexTy || !resComplexTy.isIntegerComplex())
637 return emitOpError() <<
"requires integer !cir.complex type for result";
640 case cir::CastKind::int_complex: {
641 auto srcComplexTy = mlir::dyn_cast<cir::ComplexType>(srcType);
642 if (!srcComplexTy || !srcComplexTy.isIntegerComplex())
643 return emitOpError() <<
"requires integer !cir.complex type for source";
644 auto resComplexTy = mlir::dyn_cast<cir::ComplexType>(resType);
645 if (!resComplexTy || !resComplexTy.isIntegerComplex())
646 return emitOpError() <<
"requires integer !cir.complex type for result";
649 case cir::CastKind::int_complex_to_float_complex: {
650 auto srcComplexTy = mlir::dyn_cast<cir::ComplexType>(srcType);
651 if (!srcComplexTy || !srcComplexTy.isIntegerComplex())
652 return emitOpError() <<
"requires integer !cir.complex type for source";
653 auto resComplexTy = mlir::dyn_cast<cir::ComplexType>(resType);
654 if (!resComplexTy || !resComplexTy.isFloatingPointComplex())
656 <<
"requires floating point !cir.complex type for result";
660 llvm_unreachable(
"Unknown CastOp kind?");
665 auto kind = op.getKind();
666 return kind == cir::CastKind::bool_to_int ||
667 kind == cir::CastKind::int_to_bool || kind == cir::CastKind::integral;
671 cir::CastOp head = op, tail = op;
677 op = head.getSrc().getDefiningOp<cir::CastOp>();
685 if (head.getKind() == cir::CastKind::bool_to_int &&
686 tail.getKind() == cir::CastKind::int_to_bool)
687 return head.getSrc();
692 if (head.getKind() == cir::CastKind::int_to_bool &&
693 tail.getKind() == cir::CastKind::int_to_bool)
694 return head.getResult();
699OpFoldResult cir::CastOp::fold(FoldAdaptor adaptor) {
700 if (mlir::isa_and_present<cir::PoisonAttr>(adaptor.getSrc())) {
702 return cir::PoisonAttr::get(getContext(),
getType());
707 case cir::CastKind::integral: {
711 auto foldOrder = getSrc().getDefiningOp()->fold(foldResults);
712 if (foldOrder.succeeded() && mlir::isa<mlir::Attribute>(foldResults[0]))
713 return mlir::cast<mlir::Attribute>(foldResults[0]);
716 case cir::CastKind::bitcast:
717 case cir::CastKind::address_space:
718 case cir::CastKind::float_complex:
719 case cir::CastKind::int_complex: {
733mlir::OperandRange cir::CallOp::getArgOperands() {
735 return getArgs().drop_front(1);
739mlir::MutableOperandRange cir::CallOp::getArgOperandsMutable() {
740 mlir::MutableOperandRange args = getArgsMutable();
742 return args.slice(1, args.size() - 1);
746mlir::Value cir::CallOp::getIndirectCall() {
747 assert(isIndirect());
748 return getOperand(0);
752Value cir::CallOp::getArgOperand(
unsigned i) {
755 return getOperand(i);
759unsigned cir::CallOp::getNumArgOperands() {
761 return this->getOperation()->getNumOperands() - 1;
762 return this->getOperation()->getNumOperands();
765static mlir::ParseResult
767 mlir::OperationState &result) {
768 mlir::Block *normalDestSuccessor;
769 if (parser.parseSuccessor(normalDestSuccessor))
770 return mlir::failure();
772 if (parser.parseComma())
773 return mlir::failure();
775 mlir::Block *unwindDestSuccessor;
776 if (parser.parseSuccessor(unwindDestSuccessor))
777 return mlir::failure();
779 result.addSuccessors(normalDestSuccessor);
780 result.addSuccessors(unwindDestSuccessor);
781 return mlir::success();
785 mlir::OperationState &result,
786 bool hasDestinationBlocks =
false) {
789 mlir::FlatSymbolRefAttr calleeAttr;
794 .parseOptionalAttribute(calleeAttr, CIRDialect::getCalleeAttrName(),
797 OpAsmParser::UnresolvedOperand indirectVal;
799 if (parser.parseOperand(indirectVal).failed())
801 ops.push_back(indirectVal);
804 if (parser.parseLParen())
805 return mlir::failure();
807 opsLoc = parser.getCurrentLocation();
808 if (parser.parseOperandList(ops))
809 return mlir::failure();
810 if (parser.parseRParen())
811 return mlir::failure();
813 if (hasDestinationBlocks &&
815 return ::mlir::failure();
818 if (parser.parseOptionalKeyword(
"nothrow").succeeded())
819 result.addAttribute(CIRDialect::getNoThrowAttrName(),
820 mlir::UnitAttr::get(parser.getContext()));
822 if (parser.parseOptionalKeyword(
"side_effect").succeeded()) {
823 if (parser.parseLParen().failed())
825 cir::SideEffect sideEffect;
828 if (parser.parseRParen().failed())
830 auto attr = cir::SideEffectAttr::get(parser.getContext(), sideEffect);
831 result.addAttribute(CIRDialect::getSideEffectAttrName(), attr);
834 if (parser.parseOptionalAttrDict(result.attributes))
835 return ::mlir::failure();
837 if (parser.parseColon())
838 return ::mlir::failure();
840 mlir::FunctionType opsFnTy;
841 if (parser.parseType(opsFnTy))
842 return mlir::failure();
844 allResultTypes = opsFnTy.getResults();
845 result.addTypes(allResultTypes);
847 if (parser.resolveOperands(ops, opsFnTy.getInputs(), opsLoc, result.operands))
848 return mlir::failure();
850 return mlir::success();
854 mlir::FlatSymbolRefAttr calleeSym,
855 mlir::Value indirectCallee,
856 mlir::OpAsmPrinter &printer,
bool isNothrow,
857 cir::SideEffect sideEffect,
858 mlir::Block *normalDest =
nullptr,
859 mlir::Block *unwindDest =
nullptr) {
862 auto callLikeOp = mlir::cast<cir::CIRCallOpInterface>(op);
863 auto ops = callLikeOp.getArgOperands();
867 printer.printAttributeWithoutType(calleeSym);
870 assert(indirectCallee);
871 printer << indirectCallee;
874 printer <<
"(" << ops <<
")";
877 assert(unwindDest &&
"expected two successors");
878 auto tryCall = cast<cir::TryCallOp>(op);
879 printer <<
' ' << tryCall.getNormalDest();
882 printer << tryCall.getUnwindDest();
886 printer <<
" nothrow";
888 if (sideEffect != cir::SideEffect::All) {
889 printer <<
" side_effect(";
890 printer << stringifySideEffect(sideEffect);
895 CIRDialect::getCalleeAttrName(), CIRDialect::getNoThrowAttrName(),
896 CIRDialect::getSideEffectAttrName(),
897 CIRDialect::getOperandSegmentSizesAttrName()};
898 printer.printOptionalAttrDict(op->getAttrs(), elidedAttrs);
900 printer.printFunctionalType(op->getOperands().getTypes(),
901 op->getResultTypes());
904mlir::ParseResult cir::CallOp::parse(mlir::OpAsmParser &parser,
905 mlir::OperationState &result) {
909void cir::CallOp::print(mlir::OpAsmPrinter &p) {
910 mlir::Value indirectCallee = isIndirect() ? getIndirectCall() :
nullptr;
911 cir::SideEffect sideEffect = getSideEffect();
912 printCallCommon(*
this, getCalleeAttr(), indirectCallee, p, getNothrow(),
918 SymbolTableCollection &symbolTable) {
920 op->getAttrOfType<FlatSymbolRefAttr>(CIRDialect::getCalleeAttrName());
923 return mlir::success();
926 auto fn = symbolTable.lookupNearestSymbolFrom<cir::FuncOp>(op, fnAttr);
928 return op->emitOpError() <<
"'" << fnAttr.getValue()
929 <<
"' does not reference a valid function";
931 auto callIf = dyn_cast<cir::CIRCallOpInterface>(op);
932 assert(callIf &&
"expected CIR call interface to be always available");
936 auto fnType = fn.getFunctionType();
937 if (!fn.getNoProto()) {
938 unsigned numCallOperands = callIf.getNumArgOperands();
939 unsigned numFnOpOperands = fnType.getNumInputs();
941 if (!fnType.isVarArg() && numCallOperands != numFnOpOperands)
942 return op->emitOpError(
"incorrect number of operands for callee");
943 if (fnType.isVarArg() && numCallOperands < numFnOpOperands)
944 return op->emitOpError(
"too few operands for callee");
946 for (
unsigned i = 0, e = numFnOpOperands; i != e; ++i)
947 if (callIf.getArgOperand(i).getType() != fnType.getInput(i))
948 return op->emitOpError(
"operand type mismatch: expected operand type ")
949 << fnType.getInput(i) <<
", but provided "
950 << op->getOperand(i).getType() <<
" for operand number " << i;
956 if (fnType.hasVoidReturn() && op->getNumResults() != 0)
957 return op->emitOpError(
"callee returns void but call has results");
960 if (!fnType.hasVoidReturn() && op->getNumResults() != 1)
961 return op->emitOpError(
"incorrect number of results for callee");
964 if (!fnType.hasVoidReturn() &&
965 op->getResultTypes().front() != fnType.getReturnType()) {
966 return op->emitOpError(
"result type mismatch: expected ")
967 << fnType.getReturnType() <<
", but provided "
968 << op->getResult(0).getType();
971 return mlir::success();
975cir::CallOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
983mlir::OperandRange cir::TryCallOp::getArgOperands() {
985 return getArgs().drop_front(1);
989mlir::MutableOperandRange cir::TryCallOp::getArgOperandsMutable() {
990 mlir::MutableOperandRange args = getArgsMutable();
992 return args.slice(1, args.size() - 1);
996mlir::Value cir::TryCallOp::getIndirectCall() {
997 assert(isIndirect());
998 return getOperand(0);
1002Value cir::TryCallOp::getArgOperand(
unsigned i) {
1005 return getOperand(i);
1009unsigned cir::TryCallOp::getNumArgOperands() {
1011 return this->getOperation()->getNumOperands() - 1;
1012 return this->getOperation()->getNumOperands();
1016cir::TryCallOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
1020mlir::ParseResult cir::TryCallOp::parse(mlir::OpAsmParser &parser,
1021 mlir::OperationState &result) {
1025void cir::TryCallOp::print(::mlir::OpAsmPrinter &p) {
1026 mlir::Value indirectCallee = isIndirect() ? getIndirectCall() :
nullptr;
1027 cir::SideEffect sideEffect = getSideEffect();
1028 printCallCommon(*
this, getCalleeAttr(), indirectCallee, p, getNothrow(),
1029 sideEffect, getNormalDest(), getUnwindDest());
1037 cir::FuncOp function) {
1039 if (op.getNumOperands() > 1)
1040 return op.emitOpError() <<
"expects at most 1 return operand";
1043 auto expectedTy = function.getFunctionType().getReturnType();
1045 (op.getNumOperands() == 0 ? cir::VoidType::get(op.getContext())
1046 : op.getOperand(0).getType());
1047 if (actualTy != expectedTy)
1048 return op.emitOpError() <<
"returns " << actualTy
1049 <<
" but enclosing function returns " << expectedTy;
1051 return mlir::success();
1054mlir::LogicalResult cir::ReturnOp::verify() {
1057 auto *fnOp = getOperation()->getParentOp();
1058 while (!isa<cir::FuncOp>(fnOp))
1059 fnOp = fnOp->getParentOp();
1072ParseResult cir::IfOp::parse(OpAsmParser &parser, OperationState &result) {
1074 result.regions.reserve(2);
1075 Region *thenRegion = result.addRegion();
1076 Region *elseRegion = result.addRegion();
1078 mlir::Builder &builder = parser.getBuilder();
1079 OpAsmParser::UnresolvedOperand cond;
1080 Type boolType = cir::BoolType::get(builder.getContext());
1082 if (parser.parseOperand(cond) ||
1083 parser.resolveOperand(cond, boolType, result.operands))
1087 mlir::SMLoc parseThenLoc = parser.getCurrentLocation();
1088 if (parser.parseRegion(*thenRegion, {}, {}))
1095 if (!parser.parseOptionalKeyword(
"else")) {
1096 mlir::SMLoc parseElseLoc = parser.getCurrentLocation();
1097 if (parser.parseRegion(*elseRegion, {}, {}))
1104 if (parser.parseOptionalAttrDict(result.attributes))
1109void cir::IfOp::print(OpAsmPrinter &p) {
1110 p <<
" " << getCondition() <<
" ";
1111 mlir::Region &thenRegion = this->getThenRegion();
1112 p.printRegion(thenRegion,
1117 mlir::Region &elseRegion = this->getElseRegion();
1118 if (!elseRegion.empty()) {
1120 p.printRegion(elseRegion,
1125 p.printOptionalAttrDict(getOperation()->getAttrs());
1131 cir::YieldOp::create(builder, loc);
1139void cir::IfOp::getSuccessorRegions(mlir::RegionBranchPoint point,
1140 SmallVectorImpl<RegionSuccessor> ®ions) {
1142 if (!point.isParent()) {
1144 RegionSuccessor(getOperation(), getOperation()->getResults()));
1149 Region *elseRegion = &this->getElseRegion();
1150 if (elseRegion->empty())
1151 elseRegion =
nullptr;
1154 regions.push_back(RegionSuccessor(&getThenRegion()));
1157 regions.push_back(RegionSuccessor(elseRegion));
1162void cir::IfOp::build(OpBuilder &builder, OperationState &result,
Value cond,
1165 assert(thenBuilder &&
"the builder callback for 'then' must be present");
1166 result.addOperands(cond);
1168 OpBuilder::InsertionGuard guard(builder);
1169 Region *thenRegion = result.addRegion();
1170 builder.createBlock(thenRegion);
1171 thenBuilder(builder, result.location);
1173 Region *elseRegion = result.addRegion();
1174 if (!withElseRegion)
1177 builder.createBlock(elseRegion);
1178 elseBuilder(builder, result.location);
1190void cir::ScopeOp::getSuccessorRegions(
1191 mlir::RegionBranchPoint point, SmallVectorImpl<RegionSuccessor> ®ions) {
1193 if (!point.isParent()) {
1194 regions.push_back(RegionSuccessor(getOperation(), getODSResults(0)));
1199 regions.push_back(RegionSuccessor(&getScopeRegion()));
1202void cir::ScopeOp::build(
1203 OpBuilder &builder, OperationState &result,
1204 function_ref<
void(OpBuilder &, Type &, Location)> scopeBuilder) {
1205 assert(scopeBuilder &&
"the builder callback for 'then' must be present");
1207 OpBuilder::InsertionGuard guard(builder);
1208 Region *scopeRegion = result.addRegion();
1209 builder.createBlock(scopeRegion);
1213 scopeBuilder(builder, yieldTy, result.location);
1216 result.addTypes(TypeRange{yieldTy});
1219void cir::ScopeOp::build(
1220 OpBuilder &builder, OperationState &result,
1221 function_ref<
void(OpBuilder &, Location)> scopeBuilder) {
1222 assert(scopeBuilder &&
"the builder callback for 'then' must be present");
1223 OpBuilder::InsertionGuard guard(builder);
1224 Region *scopeRegion = result.addRegion();
1225 builder.createBlock(scopeRegion);
1227 scopeBuilder(builder, result.location);
1230LogicalResult cir::ScopeOp::verify() {
1232 return emitOpError() <<
"cir.scope must not be empty since it should "
1233 "include at least an implicit cir.yield ";
1236 mlir::Block &lastBlock =
getRegion().back();
1237 if (lastBlock.empty() || !lastBlock.mightHaveTerminator() ||
1238 !lastBlock.getTerminator()->hasTrait<OpTrait::IsTerminator>())
1239 return emitOpError() <<
"last block of cir.scope must be terminated";
1247mlir::SuccessorOperands cir::BrOp::getSuccessorOperands(
unsigned index) {
1248 assert(index == 0 &&
"invalid successor index");
1249 return mlir::SuccessorOperands(getDestOperandsMutable());
1260mlir::SuccessorOperands
1261cir::IndirectBrOp::getSuccessorOperands(
unsigned index) {
1262 assert(index < getNumSuccessors() &&
"invalid successor index");
1263 return mlir::SuccessorOperands(getSuccOperandsMutable()[index]);
1267 OpAsmParser &parser, Type &flagType,
1268 SmallVectorImpl<Block *> &succOperandBlocks,
1271 if (failed(parser.parseCommaSeparatedList(
1272 OpAsmParser::Delimiter::Square,
1274 Block *destination = nullptr;
1275 SmallVector<OpAsmParser::UnresolvedOperand> operands;
1276 SmallVector<Type> operandTypes;
1278 if (parser.parseSuccessor(destination).failed())
1281 if (succeeded(parser.parseOptionalLParen())) {
1282 if (failed(parser.parseOperandList(
1283 operands, OpAsmParser::Delimiter::None)) ||
1284 failed(parser.parseColonTypeList(operandTypes)) ||
1285 failed(parser.parseRParen()))
1288 succOperandBlocks.push_back(destination);
1289 succOperands.emplace_back(operands);
1290 succOperandsTypes.emplace_back(operandTypes);
1293 "successor blocks")))
1299 Type flagType, SuccessorRange succs,
1300 OperandRangeRange succOperands,
1301 const TypeRangeRange &succOperandsTypes) {
1304 llvm::zip(succs, succOperands),
1307 p.printSuccessorAndUseList(std::get<0>(i), std::get<1>(i));
1310 if (!succOperands.empty())
1319mlir::SuccessorOperands cir::BrCondOp::getSuccessorOperands(
unsigned index) {
1320 assert(index < getNumSuccessors() &&
"invalid successor index");
1321 return SuccessorOperands(index == 0 ? getDestOperandsTrueMutable()
1322 : getDestOperandsFalseMutable());
1326 if (IntegerAttr condAttr = dyn_cast_if_present<IntegerAttr>(operands.front()))
1327 return condAttr.getValue().isOne() ? getDestTrue() : getDestFalse();
1335void cir::CaseOp::getSuccessorRegions(
1336 mlir::RegionBranchPoint point, SmallVectorImpl<RegionSuccessor> ®ions) {
1337 if (!point.isParent()) {
1339 RegionSuccessor(getOperation(), getOperation()->getResults()));
1342 regions.push_back(RegionSuccessor(&getCaseRegion()));
1345void cir::CaseOp::build(OpBuilder &builder, OperationState &result,
1346 ArrayAttr value, CaseOpKind kind,
1347 OpBuilder::InsertPoint &insertPoint) {
1348 OpBuilder::InsertionGuard guardSwitch(builder);
1349 result.addAttribute(
"value", value);
1350 result.getOrAddProperties<Properties>().kind =
1351 cir::CaseOpKindAttr::get(builder.getContext(), kind);
1352 Region *caseRegion = result.addRegion();
1353 builder.createBlock(caseRegion);
1355 insertPoint = builder.saveInsertionPoint();
1362void cir::SwitchOp::getSuccessorRegions(
1363 mlir::RegionBranchPoint point, SmallVectorImpl<RegionSuccessor> ®ion) {
1364 if (!point.isParent()) {
1366 RegionSuccessor(getOperation(), getOperation()->getResults()));
1370 region.push_back(RegionSuccessor(&getBody()));
1373void cir::SwitchOp::build(OpBuilder &builder, OperationState &result,
1375 assert(switchBuilder &&
"the builder callback for regions must be present");
1376 OpBuilder::InsertionGuard guardSwitch(builder);
1377 Region *switchRegion = result.addRegion();
1378 builder.createBlock(switchRegion);
1379 result.addOperands({cond});
1380 switchBuilder(builder, result.location, result);
1384 walk<mlir::WalkOrder::PreOrder>([&](mlir::Operation *op) {
1386 if (isa<cir::SwitchOp>(op) && op != *
this)
1387 return WalkResult::skip();
1389 if (
auto caseOp = dyn_cast<cir::CaseOp>(op))
1390 cases.push_back(caseOp);
1392 return WalkResult::advance();
1397 collectCases(cases);
1399 if (getBody().empty())
1402 if (!isa<YieldOp>(getBody().front().back()))
1405 if (!llvm::all_of(getBody().front(),
1406 [](Operation &op) {
return isa<CaseOp, YieldOp>(op); }))
1409 return llvm::all_of(cases, [
this](CaseOp op) {
1410 return op->getParentOfType<SwitchOp>() == *
this;
1418void cir::SwitchFlatOp::build(OpBuilder &builder, OperationState &result,
1419 Value value, Block *defaultDestination,
1420 ValueRange defaultOperands,
1422 BlockRange caseDestinations,
1425 std::vector<mlir::Attribute> caseValuesAttrs;
1426 for (
const APInt &val : caseValues)
1427 caseValuesAttrs.push_back(cir::IntAttr::get(value.getType(), val));
1428 mlir::ArrayAttr attrs = ArrayAttr::get(builder.getContext(), caseValuesAttrs);
1430 build(builder, result, value, defaultOperands, caseOperands, attrs,
1431 defaultDestination, caseDestinations);
1437 OpAsmParser &parser, Type flagType, mlir::ArrayAttr &caseValues,
1438 SmallVectorImpl<Block *> &caseDestinations,
1442 if (failed(parser.parseLSquare()))
1444 if (succeeded(parser.parseOptionalRSquare()))
1448 auto parseCase = [&]() {
1450 if (failed(parser.parseInteger(value)))
1453 values.push_back(cir::IntAttr::get(flagType, value));
1458 if (parser.parseColon() || parser.parseSuccessor(destination))
1460 if (!parser.parseOptionalLParen()) {
1461 if (parser.parseOperandList(operands, OpAsmParser::Delimiter::None,
1463 parser.parseColonTypeList(operandTypes) || parser.parseRParen())
1466 caseDestinations.push_back(destination);
1467 caseOperands.emplace_back(operands);
1468 caseOperandTypes.emplace_back(operandTypes);
1471 if (failed(parser.parseCommaSeparatedList(parseCase)))
1474 caseValues = ArrayAttr::get(flagType.getContext(), values);
1476 return parser.parseRSquare();
1480 Type flagType, mlir::ArrayAttr caseValues,
1481 SuccessorRange caseDestinations,
1482 OperandRangeRange caseOperands,
1483 const TypeRangeRange &caseOperandTypes) {
1493 llvm::zip(caseValues, caseDestinations),
1496 mlir::Attribute a = std::get<0>(i);
1497 p << mlir::cast<cir::IntAttr>(a).getValue();
1499 p.printSuccessorAndUseList(std::get<1>(i), caseOperands[index++]);
1514 mlir::Attribute &valueAttr) {
1516 return parser.parseAttribute(valueAttr,
"value", attr);
1520 p.printAttribute(value);
1523mlir::LogicalResult cir::GlobalOp::verify() {
1526 if (getInitialValue().has_value()) {
1538void cir::GlobalOp::build(
1539 OpBuilder &odsBuilder, OperationState &odsState, llvm::StringRef sym_name,
1540 mlir::Type sym_type,
bool isConstant, cir::GlobalLinkageKind linkage,
1541 function_ref<
void(OpBuilder &, Location)> ctorBuilder,
1542 function_ref<
void(OpBuilder &, Location)> dtorBuilder) {
1543 odsState.addAttribute(getSymNameAttrName(odsState.name),
1544 odsBuilder.getStringAttr(sym_name));
1545 odsState.addAttribute(getSymTypeAttrName(odsState.name),
1546 mlir::TypeAttr::get(sym_type));
1548 odsState.addAttribute(getConstantAttrName(odsState.name),
1549 odsBuilder.getUnitAttr());
1551 cir::GlobalLinkageKindAttr linkageAttr =
1552 cir::GlobalLinkageKindAttr::get(odsBuilder.getContext(), linkage);
1553 odsState.addAttribute(getLinkageAttrName(odsState.name), linkageAttr);
1555 Region *ctorRegion = odsState.addRegion();
1557 odsBuilder.createBlock(ctorRegion);
1558 ctorBuilder(odsBuilder, odsState.location);
1561 Region *dtorRegion = odsState.addRegion();
1563 odsBuilder.createBlock(dtorRegion);
1564 dtorBuilder(odsBuilder, odsState.location);
1567 odsState.addAttribute(getGlobalVisibilityAttrName(odsState.name),
1568 cir::VisibilityAttr::get(odsBuilder.getContext()));
1576void cir::GlobalOp::getSuccessorRegions(
1577 mlir::RegionBranchPoint point, SmallVectorImpl<RegionSuccessor> ®ions) {
1579 if (!point.isParent()) {
1581 RegionSuccessor(getOperation(), getOperation()->getResults()));
1586 Region *ctorRegion = &this->getCtorRegion();
1587 if (ctorRegion->empty())
1588 ctorRegion =
nullptr;
1591 Region *dtorRegion = &this->getCtorRegion();
1592 if (dtorRegion->empty())
1593 dtorRegion =
nullptr;
1597 regions.push_back(RegionSuccessor(ctorRegion));
1599 regions.push_back(RegionSuccessor(dtorRegion));
1603 TypeAttr type, Attribute initAttr,
1604 mlir::Region &ctorRegion,
1605 mlir::Region &dtorRegion) {
1606 auto printType = [&]() { p <<
": " << type; };
1607 if (!op.isDeclaration()) {
1609 if (!ctorRegion.empty()) {
1613 p.printRegion(ctorRegion,
1622 if (!dtorRegion.empty()) {
1624 p.printRegion(dtorRegion,
1635 Attribute &initialValueAttr,
1636 mlir::Region &ctorRegion,
1637 mlir::Region &dtorRegion) {
1639 if (parser.parseOptionalEqual().failed()) {
1642 if (parser.parseColonType(opTy))
1647 if (!parser.parseOptionalKeyword(
"ctor")) {
1648 if (parser.parseColonType(opTy))
1650 auto parseLoc = parser.getCurrentLocation();
1651 if (parser.parseRegion(ctorRegion, {}, {}))
1662 assert(mlir::isa<mlir::TypedAttr>(initialValueAttr) &&
1663 "Non-typed attrs shouldn't appear here.");
1664 auto typedAttr = mlir::cast<mlir::TypedAttr>(initialValueAttr);
1665 opTy = typedAttr.getType();
1670 if (!parser.parseOptionalKeyword(
"dtor")) {
1671 auto parseLoc = parser.getCurrentLocation();
1672 if (parser.parseRegion(dtorRegion, {}, {}))
1679 typeAttr = TypeAttr::get(opTy);
1688cir::GetGlobalOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
1691 mlir::Operation *op =
1692 symbolTable.lookupNearestSymbolFrom(*
this, getNameAttr());
1693 if (op ==
nullptr || !(isa<GlobalOp>(op) || isa<FuncOp>(op)))
1694 return emitOpError(
"'")
1696 <<
"' does not reference a valid cir.global or cir.func";
1699 if (
auto g = dyn_cast<GlobalOp>(op)) {
1700 symTy = g.getSymType();
1704 if (getTls() && !g.getTlsModel())
1705 return emitOpError(
"access to global not marked thread local");
1706 }
else if (
auto f = dyn_cast<FuncOp>(op)) {
1707 symTy = f.getFunctionType();
1709 llvm_unreachable(
"Unexpected operation for GetGlobalOp");
1712 auto resultType = dyn_cast<PointerType>(getAddr().
getType());
1713 if (!resultType || symTy != resultType.getPointee())
1714 return emitOpError(
"result type pointee type '")
1715 << resultType.getPointee() <<
"' does not match type " << symTy
1716 <<
" of the global @" <<
getName();
1726cir::VTableAddrPointOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
1732 symbolTable.lookupNearestSymbolFrom<cir::GlobalOp>(*
this, getNameAttr());
1734 return emitOpError(
"'")
1735 <<
name <<
"' does not reference a valid cir.global";
1736 std::optional<mlir::Attribute> init = op.getInitialValue();
1739 if (!isa<cir::VTableAttr>(*init))
1740 return emitOpError(
"Expected #cir.vtable in initializer for global '")
1750cir::VTTAddrPointOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
1759 symbolTable.lookupNearestSymbolFrom<cir::GlobalOp>(*
this, getNameAttr());
1761 return emitOpError(
"'")
1762 <<
name <<
"' does not reference a valid cir.global";
1763 std::optional<mlir::Attribute> init = op.getInitialValue();
1766 if (!isa<cir::ConstArrayAttr>(*init))
1768 "Expected constant array in initializer for global VTT '")
1773LogicalResult cir::VTTAddrPointOp::verify() {
1775 if (
getName() && getSymAddr())
1776 return emitOpError(
"should use either a symbol or value, but not both");
1782 mlir::Type resultType = getAddr().getType();
1783 mlir::Type resTy = cir::PointerType::get(
1784 cir::PointerType::get(cir::VoidType::get(getContext())));
1786 if (resultType != resTy)
1787 return emitOpError(
"result type must be ")
1788 << resTy <<
", but provided result type is " << resultType;
1800void cir::FuncOp::build(OpBuilder &builder, OperationState &result,
1801 StringRef name, FuncType type,
1802 GlobalLinkageKind linkage) {
1804 result.addAttribute(SymbolTable::getSymbolAttrName(),
1805 builder.getStringAttr(name));
1806 result.addAttribute(getFunctionTypeAttrName(result.name),
1807 TypeAttr::get(type));
1808 result.addAttribute(
1810 GlobalLinkageKindAttr::get(builder.getContext(), linkage));
1811 result.addAttribute(getGlobalVisibilityAttrName(result.name),
1812 cir::VisibilityAttr::get(builder.getContext()));
1815ParseResult cir::FuncOp::parse(OpAsmParser &parser, OperationState &state) {
1816 llvm::SMLoc loc = parser.getCurrentLocation();
1817 mlir::Builder &builder = parser.getBuilder();
1819 mlir::StringAttr builtinNameAttr = getBuiltinAttrName(state.name);
1820 mlir::StringAttr coroutineNameAttr = getCoroutineAttrName(state.name);
1821 mlir::StringAttr inlineKindNameAttr = getInlineKindAttrName(state.name);
1822 mlir::StringAttr lambdaNameAttr = getLambdaAttrName(state.name);
1823 mlir::StringAttr noProtoNameAttr = getNoProtoAttrName(state.name);
1824 mlir::StringAttr visNameAttr = getSymVisibilityAttrName(state.name);
1825 mlir::StringAttr visibilityNameAttr = getGlobalVisibilityAttrName(state.name);
1826 mlir::StringAttr dsoLocalNameAttr = getDsoLocalAttrName(state.name);
1827 mlir::StringAttr specialMemberAttr = getCxxSpecialMemberAttrName(state.name);
1829 if (::mlir::succeeded(parser.parseOptionalKeyword(builtinNameAttr.strref())))
1830 state.addAttribute(builtinNameAttr, parser.getBuilder().getUnitAttr());
1831 if (::mlir::succeeded(
1832 parser.parseOptionalKeyword(coroutineNameAttr.strref())))
1833 state.addAttribute(coroutineNameAttr, parser.getBuilder().getUnitAttr());
1836 cir::InlineKindAttr inlineKindAttr;
1840 state.addAttribute(inlineKindNameAttr, inlineKindAttr);
1842 if (::mlir::succeeded(parser.parseOptionalKeyword(lambdaNameAttr.strref())))
1843 state.addAttribute(lambdaNameAttr, parser.getBuilder().getUnitAttr());
1844 if (parser.parseOptionalKeyword(noProtoNameAttr).succeeded())
1845 state.addAttribute(noProtoNameAttr, parser.getBuilder().getUnitAttr());
1849 GlobalLinkageKindAttr::get(
1850 parser.getContext(),
1852 parser, GlobalLinkageKind::ExternalLinkage)));
1854 ::llvm::StringRef visAttrStr;
1855 if (parser.parseOptionalKeyword(&visAttrStr, {
"private",
"public",
"nested"})
1857 state.addAttribute(visNameAttr,
1858 parser.getBuilder().getStringAttr(visAttrStr));
1861 cir::VisibilityAttr cirVisibilityAttr;
1863 state.addAttribute(visibilityNameAttr, cirVisibilityAttr);
1865 if (parser.parseOptionalKeyword(dsoLocalNameAttr).succeeded())
1866 state.addAttribute(dsoLocalNameAttr, parser.getBuilder().getUnitAttr());
1868 StringAttr nameAttr;
1869 if (parser.parseSymbolName(nameAttr, SymbolTable::getSymbolAttrName(),
1875 bool isVariadic =
false;
1876 if (function_interface_impl::parseFunctionSignatureWithArguments(
1877 parser,
true, arguments, isVariadic, resultTypes,
1881 for (OpAsmParser::Argument &arg : arguments)
1882 argTypes.push_back(
arg.type);
1884 if (resultTypes.size() > 1) {
1885 return parser.emitError(
1886 loc,
"functions with multiple return types are not supported");
1889 mlir::Type returnType =
1890 (resultTypes.empty() ? cir::VoidType::get(builder.getContext())
1891 : resultTypes.front());
1893 cir::FuncType fnType = cir::FuncType::get(argTypes, returnType, isVariadic);
1896 state.addAttribute(getFunctionTypeAttrName(state.name),
1897 TypeAttr::get(fnType));
1899 bool hasAlias =
false;
1900 mlir::StringAttr aliaseeNameAttr = getAliaseeAttrName(state.name);
1901 if (parser.parseOptionalKeyword(
"alias").succeeded()) {
1902 if (parser.parseLParen().failed())
1904 mlir::StringAttr aliaseeAttr;
1905 if (parser.parseOptionalSymbolName(aliaseeAttr).failed())
1907 state.addAttribute(aliaseeNameAttr, FlatSymbolRefAttr::get(aliaseeAttr));
1908 if (parser.parseRParen().failed())
1913 mlir::StringAttr personalityNameAttr = getPersonalityAttrName(state.name);
1914 if (parser.parseOptionalKeyword(
"personality").succeeded()) {
1915 if (parser.parseLParen().failed())
1917 mlir::StringAttr personalityAttr;
1918 if (parser.parseOptionalSymbolName(personalityAttr).failed())
1920 state.addAttribute(personalityNameAttr,
1921 FlatSymbolRefAttr::get(personalityAttr));
1922 if (parser.parseRParen().failed())
1926 auto parseGlobalDtorCtor =
1927 [&](StringRef keyword,
1928 llvm::function_ref<void(std::optional<int> prio)> createAttr)
1929 -> mlir::LogicalResult {
1930 if (mlir::succeeded(parser.parseOptionalKeyword(keyword))) {
1931 std::optional<int> priority;
1932 if (mlir::succeeded(parser.parseOptionalLParen())) {
1933 auto parsedPriority = mlir::FieldParser<int>::parse(parser);
1934 if (mlir::failed(parsedPriority))
1935 return parser.emitError(parser.getCurrentLocation(),
1936 "failed to parse 'priority', of type 'int'");
1937 priority = parsedPriority.value_or(
int());
1939 if (parser.parseRParen())
1942 createAttr(priority);
1948 if (parser.parseOptionalKeyword(
"special_member").succeeded()) {
1949 cir::CXXCtorAttr ctorAttr;
1950 cir::CXXDtorAttr dtorAttr;
1951 cir::CXXAssignAttr assignAttr;
1952 if (parser.parseLess().failed())
1954 if (parser.parseOptionalAttribute(ctorAttr).has_value())
1955 state.addAttribute(specialMemberAttr, ctorAttr);
1956 else if (parser.parseOptionalAttribute(dtorAttr).has_value())
1957 state.addAttribute(specialMemberAttr, dtorAttr);
1958 else if (parser.parseOptionalAttribute(assignAttr).has_value())
1959 state.addAttribute(specialMemberAttr, assignAttr);
1960 if (parser.parseGreater().failed())
1964 if (parseGlobalDtorCtor(
"global_ctor", [&](std::optional<int> priority) {
1965 mlir::IntegerAttr globalCtorPriorityAttr =
1966 builder.getI32IntegerAttr(priority.value_or(65535));
1967 state.addAttribute(getGlobalCtorPriorityAttrName(state.name),
1968 globalCtorPriorityAttr);
1972 if (parseGlobalDtorCtor(
"global_dtor", [&](std::optional<int> priority) {
1973 mlir::IntegerAttr globalDtorPriorityAttr =
1974 builder.getI32IntegerAttr(priority.value_or(65535));
1975 state.addAttribute(getGlobalDtorPriorityAttrName(state.name),
1976 globalDtorPriorityAttr);
1981 NamedAttrList parsedAttrs;
1982 if (parser.parseOptionalAttrDictWithKeyword(parsedAttrs))
1985 for (StringRef disallowed : cir::FuncOp::getAttributeNames()) {
1986 if (parsedAttrs.get(disallowed))
1987 return parser.emitError(loc,
"attribute '")
1989 <<
"' should not be specified in the explicit attribute list";
1992 state.attributes.append(parsedAttrs);
1995 auto *body = state.addRegion();
1996 OptionalParseResult parseResult = parser.parseOptionalRegion(
1997 *body, arguments,
false);
1998 if (parseResult.has_value()) {
2000 return parser.emitError(loc,
"function alias shall not have a body");
2001 if (failed(*parseResult))
2005 return parser.emitError(loc,
"expected non-empty function body");
2014bool cir::FuncOp::isDeclaration() {
2017 std::optional<StringRef> aliasee = getAliasee();
2019 return getFunctionBody().empty();
2025bool cir::FuncOp::isCXXSpecialMemberFunction() {
2026 return getCxxSpecialMemberAttr() !=
nullptr;
2029bool cir::FuncOp::isCxxConstructor() {
2030 auto attr = getCxxSpecialMemberAttr();
2031 return attr && dyn_cast<CXXCtorAttr>(attr);
2034bool cir::FuncOp::isCxxDestructor() {
2035 auto attr = getCxxSpecialMemberAttr();
2036 return attr && dyn_cast<CXXDtorAttr>(attr);
2039bool cir::FuncOp::isCxxSpecialAssignment() {
2040 auto attr = getCxxSpecialMemberAttr();
2041 return attr && dyn_cast<CXXAssignAttr>(attr);
2044std::optional<CtorKind> cir::FuncOp::getCxxConstructorKind() {
2045 mlir::Attribute
attr = getCxxSpecialMemberAttr();
2047 if (
auto ctor = dyn_cast<CXXCtorAttr>(attr))
2048 return ctor.getCtorKind();
2050 return std::nullopt;
2053std::optional<AssignKind> cir::FuncOp::getCxxSpecialAssignKind() {
2054 mlir::Attribute
attr = getCxxSpecialMemberAttr();
2056 if (
auto assign = dyn_cast<CXXAssignAttr>(attr))
2057 return assign.getAssignKind();
2059 return std::nullopt;
2062bool cir::FuncOp::isCxxTrivialMemberFunction() {
2063 mlir::Attribute
attr = getCxxSpecialMemberAttr();
2065 if (
auto ctor = dyn_cast<CXXCtorAttr>(attr))
2066 return ctor.getIsTrivial();
2067 if (
auto dtor = dyn_cast<CXXDtorAttr>(attr))
2068 return dtor.getIsTrivial();
2069 if (
auto assign = dyn_cast<CXXAssignAttr>(attr))
2070 return assign.getIsTrivial();
2075mlir::Region *cir::FuncOp::getCallableRegion() {
2081void cir::FuncOp::print(OpAsmPrinter &p) {
2099 if (getLinkage() != GlobalLinkageKind::ExternalLinkage)
2100 p <<
' ' << stringifyGlobalLinkageKind(getLinkage());
2102 mlir::SymbolTable::Visibility vis = getVisibility();
2103 if (vis != mlir::SymbolTable::Visibility::Public)
2106 cir::VisibilityAttr cirVisibilityAttr = getGlobalVisibilityAttr();
2107 if (!cirVisibilityAttr.isDefault()) {
2116 p.printSymbolName(getSymName());
2117 cir::FuncType fnType = getFunctionType();
2118 function_interface_impl::printFunctionSignature(
2119 p, *
this, fnType.getInputs(), fnType.isVarArg(), fnType.getReturnTypes());
2121 if (std::optional<StringRef> aliaseeName = getAliasee()) {
2123 p.printSymbolName(*aliaseeName);
2127 if (std::optional<StringRef> personalityName = getPersonality()) {
2128 p <<
" personality(";
2129 p.printSymbolName(*personalityName);
2133 if (
auto specialMemberAttr = getCxxSpecialMember()) {
2134 p <<
" special_member<";
2135 p.printAttribute(*specialMemberAttr);
2139 if (
auto globalCtorPriority = getGlobalCtorPriority()) {
2140 p <<
" global_ctor";
2141 if (globalCtorPriority.value() != 65535)
2142 p <<
"(" << globalCtorPriority.value() <<
")";
2145 if (
auto globalDtorPriority = getGlobalDtorPriority()) {
2146 p <<
" global_dtor";
2147 if (globalDtorPriority.value() != 65535)
2148 p <<
"(" << globalDtorPriority.value() <<
")";
2151 function_interface_impl::printFunctionAttributes(
2152 p, *
this, cir::FuncOp::getAttributeNames());
2155 Region &body = getOperation()->getRegion(0);
2156 if (!body.empty()) {
2158 p.printRegion(body,
false,
2163mlir::LogicalResult cir::FuncOp::verify() {
2165 if (!isDeclaration() && getCoroutine()) {
2166 bool foundAwait =
false;
2167 this->walk([&](Operation *op) {
2168 if (
auto await = dyn_cast<AwaitOp>(op)) {
2174 return emitOpError()
2175 <<
"coroutine body must use at least one cir.await op";
2178 llvm::SmallSet<llvm::StringRef, 16> labels;
2179 llvm::SmallSet<llvm::StringRef, 16> gotos;
2180 llvm::SmallSet<llvm::StringRef, 16> blockAddresses;
2181 bool invalidBlockAddress =
false;
2182 getOperation()->walk([&](mlir::Operation *op) {
2183 if (
auto lab = dyn_cast<cir::LabelOp>(op)) {
2184 labels.insert(lab.getLabel());
2185 }
else if (
auto goTo = dyn_cast<cir::GotoOp>(op)) {
2186 gotos.insert(goTo.getLabel());
2187 }
else if (
auto blkAdd = dyn_cast<cir::BlockAddressOp>(op)) {
2188 if (blkAdd.getBlockAddrInfoAttr().getFunc().getAttr() != getSymName()) {
2190 invalidBlockAddress =
true;
2191 return mlir::WalkResult::interrupt();
2193 blockAddresses.insert(blkAdd.getBlockAddrInfoAttr().getLabel());
2195 return mlir::WalkResult::advance();
2198 if (invalidBlockAddress)
2199 return emitOpError() <<
"blockaddress references a different function";
2201 llvm::SmallSet<llvm::StringRef, 16> mismatched;
2202 if (!labels.empty() || !gotos.empty()) {
2203 mismatched = llvm::set_difference(gotos, labels);
2205 if (!mismatched.empty())
2206 return emitOpError() <<
"goto/label mismatch";
2211 if (!labels.empty() || !blockAddresses.empty()) {
2212 mismatched = llvm::set_difference(blockAddresses, labels);
2214 if (!mismatched.empty())
2215 return emitOpError()
2216 <<
"expects an existing label target in the referenced function";
2225LogicalResult cir::BinOp::verify() {
2226 bool noWrap = getNoUnsignedWrap() || getNoSignedWrap();
2227 bool saturated = getSaturated();
2229 if (!isa<cir::IntType>(
getType()) && noWrap)
2231 <<
"only operations on integer values may have nsw/nuw flags";
2233 bool noWrapOps =
getKind() == cir::BinOpKind::Add ||
2234 getKind() == cir::BinOpKind::Sub ||
2235 getKind() == cir::BinOpKind::Mul;
2238 getKind() == cir::BinOpKind::Add ||
getKind() == cir::BinOpKind::Sub;
2240 if (noWrap && !noWrapOps)
2241 return emitError() <<
"The nsw/nuw flags are applicable to opcodes: 'add', "
2243 if (saturated && !saturatedOps)
2244 return emitError() <<
"The saturated flag is applicable to opcodes: 'add' "
2246 if (noWrap && saturated)
2247 return emitError() <<
"The nsw/nuw flags and the saturated flag are "
2248 "mutually exclusive";
2250 return mlir::success();
2262void cir::TernaryOp::getSuccessorRegions(
2263 mlir::RegionBranchPoint point, SmallVectorImpl<RegionSuccessor> ®ions) {
2265 if (!point.isParent()) {
2266 regions.push_back(RegionSuccessor(getOperation(), this->getODSResults(0)));
2272 regions.push_back(RegionSuccessor(&getTrueRegion()));
2273 regions.push_back(RegionSuccessor(&getFalseRegion()));
2276void cir::TernaryOp::build(
2277 OpBuilder &builder, OperationState &result,
Value cond,
2278 function_ref<
void(OpBuilder &, Location)> trueBuilder,
2279 function_ref<
void(OpBuilder &, Location)> falseBuilder) {
2280 result.addOperands(cond);
2281 OpBuilder::InsertionGuard guard(builder);
2282 Region *trueRegion = result.addRegion();
2283 builder.createBlock(trueRegion);
2284 trueBuilder(builder, result.location);
2285 Region *falseRegion = result.addRegion();
2286 builder.createBlock(falseRegion);
2287 falseBuilder(builder, result.location);
2292 dyn_cast_or_null<cir::YieldOp>(trueRegion->back().getTerminator());
2294 yield = dyn_cast_or_null<cir::YieldOp>(falseRegion->back().getTerminator());
2296 assert((yield && yield.getNumOperands() <= 1) &&
2297 "expected zero or one result type");
2298 if (yield.getNumOperands() == 1)
2299 result.addTypes(TypeRange{yield.getOperandTypes().front()});
2306OpFoldResult cir::SelectOp::fold(FoldAdaptor adaptor) {
2307 mlir::Attribute condition = adaptor.getCondition();
2309 bool conditionValue = mlir::cast<cir::BoolAttr>(condition).getValue();
2310 return conditionValue ? getTrueValue() : getFalseValue();
2314 mlir::Attribute trueValue = adaptor.getTrueValue();
2315 mlir::Attribute falseValue = adaptor.getFalseValue();
2316 if (trueValue == falseValue)
2318 if (getTrueValue() == getFalseValue())
2319 return getTrueValue();
2324LogicalResult cir::SelectOp::verify() {
2326 auto condTy = dyn_cast<cir::VectorType>(getCondition().
getType());
2333 if (!isa<cir::VectorType>(getTrueValue().
getType()) ||
2334 !isa<cir::VectorType>(getFalseValue().
getType())) {
2335 return emitOpError()
2336 <<
"expected both true and false operands to be vector types "
2337 "when the condition is a vector boolean type";
2346LogicalResult cir::ShiftOp::verify() {
2347 mlir::Operation *op = getOperation();
2348 auto op0VecTy = mlir::dyn_cast<cir::VectorType>(op->getOperand(0).getType());
2349 auto op1VecTy = mlir::dyn_cast<cir::VectorType>(op->getOperand(1).getType());
2350 if (!op0VecTy ^ !op1VecTy)
2351 return emitOpError() <<
"input types cannot be one vector and one scalar";
2354 if (op0VecTy.getSize() != op1VecTy.getSize())
2355 return emitOpError() <<
"input vector types must have the same size";
2357 auto opResultTy = mlir::dyn_cast<cir::VectorType>(
getType());
2359 return emitOpError() <<
"the type of the result must be a vector "
2360 <<
"if it is vector shift";
2362 auto op0VecEleTy = mlir::cast<cir::IntType>(op0VecTy.getElementType());
2363 auto op1VecEleTy = mlir::cast<cir::IntType>(op1VecTy.getElementType());
2364 if (op0VecEleTy.getWidth() != op1VecEleTy.getWidth())
2365 return emitOpError()
2366 <<
"vector operands do not have the same elements sizes";
2368 auto resVecEleTy = mlir::cast<cir::IntType>(opResultTy.getElementType());
2369 if (op0VecEleTy.getWidth() != resVecEleTy.getWidth())
2370 return emitOpError() <<
"vector operands and result type do not have the "
2371 "same elements sizes";
2374 return mlir::success();
2381LogicalResult cir::LabelOp::verify() {
2382 mlir::Operation *op = getOperation();
2383 mlir::Block *blk = op->getBlock();
2384 if (&blk->front() != op)
2385 return emitError() <<
"must be the first operation in a block";
2387 return mlir::success();
2394LogicalResult cir::UnaryOp::verify() {
2396 case cir::UnaryOpKind::Inc:
2397 case cir::UnaryOpKind::Dec:
2398 case cir::UnaryOpKind::Plus:
2399 case cir::UnaryOpKind::Minus:
2400 case cir::UnaryOpKind::Not:
2405 llvm_unreachable(
"Unknown UnaryOp kind?");
2409 return isa<cir::BoolType>(op.getInput().getType()) &&
2410 op.getKind() == cir::UnaryOpKind::Not;
2422OpFoldResult cir::UnaryOp::fold(FoldAdaptor adaptor) {
2424 mlir::dyn_cast_if_present<cir::PoisonAttr>(adaptor.getInput())) {
2430 if (
auto previous = getInput().getDefiningOp<cir::UnaryOp>())
2432 return previous.getInput();
2440void cir::AwaitOp::build(OpBuilder &builder, OperationState &result,
2444 result.addAttribute(getKindAttrName(result.name),
2445 cir::AwaitKindAttr::get(builder.getContext(), kind));
2447 OpBuilder::InsertionGuard guard(builder);
2448 Region *readyRegion = result.addRegion();
2449 builder.createBlock(readyRegion);
2450 readyBuilder(builder, result.location);
2454 OpBuilder::InsertionGuard guard(builder);
2455 Region *suspendRegion = result.addRegion();
2456 builder.createBlock(suspendRegion);
2457 suspendBuilder(builder, result.location);
2461 OpBuilder::InsertionGuard guard(builder);
2462 Region *resumeRegion = result.addRegion();
2463 builder.createBlock(resumeRegion);
2464 resumeBuilder(builder, result.location);
2468void cir::AwaitOp::getSuccessorRegions(
2469 mlir::RegionBranchPoint point, SmallVectorImpl<RegionSuccessor> ®ions) {
2472 if (!point.isParent()) {
2474 RegionSuccessor(getOperation(), getOperation()->getResults()));
2481 regions.push_back(RegionSuccessor(&this->getReady()));
2482 regions.push_back(RegionSuccessor(&this->getSuspend()));
2483 regions.push_back(RegionSuccessor(&this->getResume()));
2486LogicalResult cir::AwaitOp::verify() {
2487 if (!isa<ConditionOp>(this->getReady().back().getTerminator()))
2488 return emitOpError(
"ready region must end with cir.condition");
2496LogicalResult cir::CopyOp::verify() {
2498 if (!
getType().getPointee().hasTrait<DataLayoutTypeInterface::Trait>())
2499 return emitError() <<
"missing data layout for pointee type";
2501 if (getSrc() == getDst())
2502 return emitError() <<
"source and destination are the same";
2504 return mlir::success();
2511LogicalResult cir::GetRuntimeMemberOp::verify() {
2512 auto recordTy = mlir::cast<RecordType>(getAddr().
getType().getPointee());
2513 cir::DataMemberType memberPtrTy = getMember().getType();
2515 if (recordTy != memberPtrTy.getClassTy())
2516 return emitError() <<
"record type does not match the member pointer type";
2517 if (
getType().getPointee() != memberPtrTy.getMemberTy())
2518 return emitError() <<
"result type does not match the member pointer type";
2519 return mlir::success();
2526LogicalResult cir::GetMemberOp::verify() {
2527 const auto recordTy = dyn_cast<RecordType>(getAddrTy().getPointee());
2529 return emitError() <<
"expected pointer to a record type";
2531 if (recordTy.getMembers().size() <=
getIndex())
2532 return emitError() <<
"member index out of bounds";
2535 return emitError() <<
"member type mismatch";
2537 return mlir::success();
2544OpFoldResult cir::VecCreateOp::fold(FoldAdaptor adaptor) {
2545 if (llvm::any_of(getElements(), [](mlir::Value value) {
2546 return !value.getDefiningOp<cir::ConstantOp>();
2550 return cir::ConstVectorAttr::get(
2551 getType(), mlir::ArrayAttr::get(getContext(), adaptor.getElements()));
2554LogicalResult cir::VecCreateOp::verify() {
2558 const cir::VectorType vecTy =
getType();
2559 if (getElements().size() != vecTy.getSize()) {
2560 return emitOpError() <<
"operand count of " << getElements().size()
2561 <<
" doesn't match vector type " << vecTy
2562 <<
" element count of " << vecTy.getSize();
2565 const mlir::Type elementType = vecTy.getElementType();
2566 for (
const mlir::Value element : getElements()) {
2567 if (element.getType() != elementType) {
2568 return emitOpError() <<
"operand type " << element.getType()
2569 <<
" doesn't match vector element type "
2581OpFoldResult cir::VecExtractOp::fold(FoldAdaptor adaptor) {
2582 const auto vectorAttr =
2583 llvm::dyn_cast_if_present<cir::ConstVectorAttr>(adaptor.getVec());
2587 const auto indexAttr =
2588 llvm::dyn_cast_if_present<cir::IntAttr>(adaptor.getIndex());
2592 const mlir::ArrayAttr elements = vectorAttr.getElts();
2593 const uint64_t index = indexAttr.getUInt();
2594 if (index >= elements.size())
2597 return elements[index];
2604OpFoldResult cir::VecCmpOp::fold(FoldAdaptor adaptor) {
2606 mlir::dyn_cast_if_present<cir::ConstVectorAttr>(adaptor.getLhs());
2608 mlir::dyn_cast_if_present<cir::ConstVectorAttr>(adaptor.getRhs());
2609 if (!lhsVecAttr || !rhsVecAttr)
2612 mlir::Type inputElemTy =
2613 mlir::cast<cir::VectorType>(lhsVecAttr.getType()).getElementType();
2614 if (!isAnyIntegerOrFloatingPointType(inputElemTy))
2617 cir::CmpOpKind opKind = adaptor.getKind();
2618 mlir::ArrayAttr lhsVecElhs = lhsVecAttr.getElts();
2619 mlir::ArrayAttr rhsVecElhs = rhsVecAttr.getElts();
2620 uint64_t vecSize = lhsVecElhs.size();
2623 bool isIntAttr = vecSize && mlir::isa<cir::IntAttr>(lhsVecElhs[0]);
2624 for (uint64_t i = 0; i < vecSize; i++) {
2625 mlir::Attribute lhsAttr = lhsVecElhs[i];
2626 mlir::Attribute rhsAttr = rhsVecElhs[i];
2629 case cir::CmpOpKind::lt: {
2631 cmpResult = mlir::cast<cir::IntAttr>(lhsAttr).getSInt() <
2632 mlir::cast<cir::IntAttr>(rhsAttr).getSInt();
2634 cmpResult = mlir::cast<cir::FPAttr>(lhsAttr).getValue() <
2635 mlir::cast<cir::FPAttr>(rhsAttr).getValue();
2639 case cir::CmpOpKind::le: {
2641 cmpResult = mlir::cast<cir::IntAttr>(lhsAttr).getSInt() <=
2642 mlir::cast<cir::IntAttr>(rhsAttr).getSInt();
2644 cmpResult = mlir::cast<cir::FPAttr>(lhsAttr).getValue() <=
2645 mlir::cast<cir::FPAttr>(rhsAttr).getValue();
2649 case cir::CmpOpKind::gt: {
2651 cmpResult = mlir::cast<cir::IntAttr>(lhsAttr).getSInt() >
2652 mlir::cast<cir::IntAttr>(rhsAttr).getSInt();
2654 cmpResult = mlir::cast<cir::FPAttr>(lhsAttr).getValue() >
2655 mlir::cast<cir::FPAttr>(rhsAttr).getValue();
2659 case cir::CmpOpKind::ge: {
2661 cmpResult = mlir::cast<cir::IntAttr>(lhsAttr).getSInt() >=
2662 mlir::cast<cir::IntAttr>(rhsAttr).getSInt();
2664 cmpResult = mlir::cast<cir::FPAttr>(lhsAttr).getValue() >=
2665 mlir::cast<cir::FPAttr>(rhsAttr).getValue();
2669 case cir::CmpOpKind::eq: {
2671 cmpResult = mlir::cast<cir::IntAttr>(lhsAttr).getSInt() ==
2672 mlir::cast<cir::IntAttr>(rhsAttr).getSInt();
2674 cmpResult = mlir::cast<cir::FPAttr>(lhsAttr).getValue() ==
2675 mlir::cast<cir::FPAttr>(rhsAttr).getValue();
2679 case cir::CmpOpKind::ne: {
2681 cmpResult = mlir::cast<cir::IntAttr>(lhsAttr).getSInt() !=
2682 mlir::cast<cir::IntAttr>(rhsAttr).getSInt();
2684 cmpResult = mlir::cast<cir::FPAttr>(lhsAttr).getValue() !=
2685 mlir::cast<cir::FPAttr>(rhsAttr).getValue();
2691 elements[i] = cir::IntAttr::get(
getType().getElementType(), cmpResult);
2694 return cir::ConstVectorAttr::get(
2695 getType(), mlir::ArrayAttr::get(getContext(), elements));
2702OpFoldResult cir::VecShuffleOp::fold(FoldAdaptor adaptor) {
2704 mlir::dyn_cast_if_present<cir::ConstVectorAttr>(adaptor.getVec1());
2706 mlir::dyn_cast_if_present<cir::ConstVectorAttr>(adaptor.getVec2());
2707 if (!vec1Attr || !vec2Attr)
2710 mlir::Type vec1ElemTy =
2711 mlir::cast<cir::VectorType>(vec1Attr.getType()).getElementType();
2713 mlir::ArrayAttr vec1Elts = vec1Attr.getElts();
2714 mlir::ArrayAttr vec2Elts = vec2Attr.getElts();
2715 mlir::ArrayAttr indicesElts = adaptor.getIndices();
2718 elements.reserve(indicesElts.size());
2720 uint64_t vec1Size = vec1Elts.size();
2721 for (
const auto &idxAttr : indicesElts.getAsRange<cir::IntAttr>()) {
2722 if (idxAttr.getSInt() == -1) {
2723 elements.push_back(cir::UndefAttr::get(vec1ElemTy));
2727 uint64_t idxValue = idxAttr.getUInt();
2728 elements.push_back(idxValue < vec1Size ? vec1Elts[idxValue]
2729 : vec2Elts[idxValue - vec1Size]);
2732 return cir::ConstVectorAttr::get(
2733 getType(), mlir::ArrayAttr::get(getContext(), elements));
2736LogicalResult cir::VecShuffleOp::verify() {
2739 if (getIndices().size() != getResult().
getType().getSize()) {
2740 return emitOpError() <<
": the number of elements in " << getIndices()
2741 <<
" and " << getResult().getType() <<
" don't match";
2746 if (getVec1().
getType().getElementType() !=
2747 getResult().
getType().getElementType()) {
2748 return emitOpError() <<
": element types of " << getVec1().getType()
2749 <<
" and " << getResult().getType() <<
" don't match";
2752 const uint64_t maxValidIndex =
2753 getVec1().getType().getSize() + getVec2().getType().getSize() - 1;
2755 getIndices().getAsRange<cir::IntAttr>(), [&](cir::IntAttr idxAttr) {
2756 return idxAttr.getSInt() != -1 && idxAttr.getUInt() > maxValidIndex;
2758 return emitOpError() <<
": index for __builtin_shufflevector must be "
2759 "less than the total number of vector elements";
2768OpFoldResult cir::VecShuffleDynamicOp::fold(FoldAdaptor adaptor) {
2769 mlir::Attribute vec = adaptor.getVec();
2770 mlir::Attribute indices = adaptor.getIndices();
2771 if (mlir::isa_and_nonnull<cir::ConstVectorAttr>(vec) &&
2772 mlir::isa_and_nonnull<cir::ConstVectorAttr>(indices)) {
2773 auto vecAttr = mlir::cast<cir::ConstVectorAttr>(vec);
2774 auto indicesAttr = mlir::cast<cir::ConstVectorAttr>(indices);
2776 mlir::ArrayAttr vecElts = vecAttr.getElts();
2777 mlir::ArrayAttr indicesElts = indicesAttr.getElts();
2779 const uint64_t numElements = vecElts.size();
2782 elements.reserve(numElements);
2784 const uint64_t maskBits = llvm::NextPowerOf2(numElements - 1) - 1;
2785 for (
const auto &idxAttr : indicesElts.getAsRange<cir::IntAttr>()) {
2786 uint64_t idxValue = idxAttr.getUInt();
2787 uint64_t newIdx = idxValue & maskBits;
2788 elements.push_back(vecElts[newIdx]);
2791 return cir::ConstVectorAttr::get(
2792 getType(), mlir::ArrayAttr::get(getContext(), elements));
2798LogicalResult cir::VecShuffleDynamicOp::verify() {
2800 if (getVec().
getType().getSize() !=
2801 mlir::cast<cir::VectorType>(getIndices().
getType()).getSize()) {
2802 return emitOpError() <<
": the number of elements in " << getVec().getType()
2803 <<
" and " << getIndices().getType() <<
" don't match";
2812LogicalResult cir::VecTernaryOp::verify() {
2817 if (getCond().
getType().getSize() != getLhs().
getType().getSize()) {
2818 return emitOpError() <<
": the number of elements in "
2819 << getCond().getType() <<
" and " << getLhs().getType()
2825OpFoldResult cir::VecTernaryOp::fold(FoldAdaptor adaptor) {
2826 mlir::Attribute cond = adaptor.getCond();
2827 mlir::Attribute lhs = adaptor.getLhs();
2828 mlir::Attribute rhs = adaptor.getRhs();
2830 if (!mlir::isa_and_nonnull<cir::ConstVectorAttr>(cond) ||
2831 !mlir::isa_and_nonnull<cir::ConstVectorAttr>(lhs) ||
2832 !mlir::isa_and_nonnull<cir::ConstVectorAttr>(rhs))
2834 auto condVec = mlir::cast<cir::ConstVectorAttr>(cond);
2835 auto lhsVec = mlir::cast<cir::ConstVectorAttr>(lhs);
2836 auto rhsVec = mlir::cast<cir::ConstVectorAttr>(rhs);
2838 mlir::ArrayAttr condElts = condVec.getElts();
2841 elements.reserve(condElts.size());
2843 for (
const auto &[idx, condAttr] :
2844 llvm::enumerate(condElts.getAsRange<cir::IntAttr>())) {
2845 if (condAttr.getSInt()) {
2846 elements.push_back(lhsVec.getElts()[idx]);
2848 elements.push_back(rhsVec.getElts()[idx]);
2852 cir::VectorType vecTy = getLhs().getType();
2853 return cir::ConstVectorAttr::get(
2854 vecTy, mlir::ArrayAttr::get(getContext(), elements));
2861LogicalResult cir::ComplexCreateOp::verify() {
2864 <<
"operand type of cir.complex.create does not match its result type";
2871OpFoldResult cir::ComplexCreateOp::fold(FoldAdaptor adaptor) {
2872 mlir::Attribute real = adaptor.getReal();
2873 mlir::Attribute imag = adaptor.getImag();
2879 auto realAttr = mlir::cast<mlir::TypedAttr>(real);
2880 auto imagAttr = mlir::cast<mlir::TypedAttr>(imag);
2881 return cir::ConstComplexAttr::get(realAttr, imagAttr);
2888LogicalResult cir::ComplexRealOp::verify() {
2889 mlir::Type operandTy = getOperand().getType();
2890 if (
auto complexOperandTy = mlir::dyn_cast<cir::ComplexType>(operandTy))
2891 operandTy = complexOperandTy.getElementType();
2894 emitOpError() <<
": result type does not match operand type";
2901OpFoldResult cir::ComplexRealOp::fold(FoldAdaptor adaptor) {
2902 if (!mlir::isa<cir::ComplexType>(getOperand().
getType()))
2905 if (
auto complexCreateOp = getOperand().getDefiningOp<cir::ComplexCreateOp>())
2906 return complexCreateOp.getOperand(0);
2909 mlir::cast_if_present<cir::ConstComplexAttr>(adaptor.getOperand());
2910 return complex ? complex.getReal() :
nullptr;
2917LogicalResult cir::ComplexImagOp::verify() {
2918 mlir::Type operandTy = getOperand().getType();
2919 if (
auto complexOperandTy = mlir::dyn_cast<cir::ComplexType>(operandTy))
2920 operandTy = complexOperandTy.getElementType();
2923 emitOpError() <<
": result type does not match operand type";
2930OpFoldResult cir::ComplexImagOp::fold(FoldAdaptor adaptor) {
2931 if (!mlir::isa<cir::ComplexType>(getOperand().
getType()))
2934 if (
auto complexCreateOp = getOperand().getDefiningOp<cir::ComplexCreateOp>())
2935 return complexCreateOp.getOperand(1);
2938 mlir::cast_if_present<cir::ConstComplexAttr>(adaptor.getOperand());
2939 return complex ? complex.getImag() :
nullptr;
2946LogicalResult cir::ComplexRealPtrOp::verify() {
2947 mlir::Type resultPointeeTy =
getType().getPointee();
2948 cir::PointerType operandPtrTy = getOperand().getType();
2949 auto operandPointeeTy =
2950 mlir::cast<cir::ComplexType>(operandPtrTy.getPointee());
2952 if (resultPointeeTy != operandPointeeTy.getElementType()) {
2953 return emitOpError() <<
": result type does not match operand type";
2963LogicalResult cir::ComplexImagPtrOp::verify() {
2964 mlir::Type resultPointeeTy =
getType().getPointee();
2965 cir::PointerType operandPtrTy = getOperand().getType();
2966 auto operandPointeeTy =
2967 mlir::cast<cir::ComplexType>(operandPtrTy.getPointee());
2969 if (resultPointeeTy != operandPointeeTy.getElementType()) {
2970 return emitOpError()
2971 <<
"cir.complex.imag_ptr result type does not match operand type";
2982 llvm::function_ref<llvm::APInt(
const llvm::APInt &)> func,
2983 bool poisonZero =
false) {
2984 if (mlir::isa_and_present<cir::PoisonAttr>(inputAttr)) {
2989 auto input = mlir::dyn_cast_if_present<IntAttr>(inputAttr);
2993 llvm::APInt inputValue = input.getValue();
2994 if (poisonZero && inputValue.isZero())
2995 return cir::PoisonAttr::get(input.getType());
2997 llvm::APInt resultValue = func(inputValue);
2998 return IntAttr::get(input.getType(), resultValue);
3001OpFoldResult BitClrsbOp::fold(FoldAdaptor adaptor) {
3002 return foldUnaryBitOp(adaptor.getInput(), [](
const llvm::APInt &inputValue) {
3003 unsigned resultValue =
3004 inputValue.getBitWidth() - inputValue.getSignificantBits();
3005 return llvm::APInt(inputValue.getBitWidth(), resultValue);
3009OpFoldResult BitClzOp::fold(FoldAdaptor adaptor) {
3012 [](
const llvm::APInt &inputValue) {
3013 unsigned resultValue = inputValue.countLeadingZeros();
3014 return llvm::APInt(inputValue.getBitWidth(), resultValue);
3019OpFoldResult BitCtzOp::fold(FoldAdaptor adaptor) {
3022 [](
const llvm::APInt &inputValue) {
3023 return llvm::APInt(inputValue.getBitWidth(),
3024 inputValue.countTrailingZeros());
3029OpFoldResult BitFfsOp::fold(FoldAdaptor adaptor) {
3030 return foldUnaryBitOp(adaptor.getInput(), [](
const llvm::APInt &inputValue) {
3031 unsigned trailingZeros = inputValue.countTrailingZeros();
3033 trailingZeros == inputValue.getBitWidth() ? 0 : trailingZeros + 1;
3034 return llvm::APInt(inputValue.getBitWidth(), result);
3038OpFoldResult BitParityOp::fold(FoldAdaptor adaptor) {
3039 return foldUnaryBitOp(adaptor.getInput(), [](
const llvm::APInt &inputValue) {
3040 return llvm::APInt(inputValue.getBitWidth(), inputValue.popcount() % 2);
3044OpFoldResult BitPopcountOp::fold(FoldAdaptor adaptor) {
3045 return foldUnaryBitOp(adaptor.getInput(), [](
const llvm::APInt &inputValue) {
3046 return llvm::APInt(inputValue.getBitWidth(), inputValue.popcount());
3050OpFoldResult BitReverseOp::fold(FoldAdaptor adaptor) {
3051 return foldUnaryBitOp(adaptor.getInput(), [](
const llvm::APInt &inputValue) {
3052 return inputValue.reverseBits();
3056OpFoldResult ByteSwapOp::fold(FoldAdaptor adaptor) {
3057 return foldUnaryBitOp(adaptor.getInput(), [](
const llvm::APInt &inputValue) {
3058 return inputValue.byteSwap();
3062OpFoldResult RotateOp::fold(FoldAdaptor adaptor) {
3063 if (mlir::isa_and_present<cir::PoisonAttr>(adaptor.getInput()) ||
3064 mlir::isa_and_present<cir::PoisonAttr>(adaptor.getAmount())) {
3066 return cir::PoisonAttr::get(
getType());
3069 auto input = mlir::dyn_cast_if_present<IntAttr>(adaptor.getInput());
3070 auto amount = mlir::dyn_cast_if_present<IntAttr>(adaptor.getAmount());
3071 if (!input && !amount)
3080 llvm::APInt inputValue;
3082 inputValue = input.getValue();
3083 if (inputValue.isZero() || inputValue.isAllOnes()) {
3089 uint64_t amountValue;
3091 amountValue = amount.getValue().urem(getInput().
getType().getWidth());
3092 if (amountValue == 0) {
3098 if (!input || !amount)
3101 assert(inputValue.getBitWidth() == getInput().
getType().getWidth() &&
3102 "input value must have the same bit width as the input type");
3104 llvm::APInt resultValue;
3106 resultValue = inputValue.rotl(amountValue);
3108 resultValue = inputValue.rotr(amountValue);
3110 return IntAttr::get(input.getContext(), input.getType(), resultValue);
3117void cir::InlineAsmOp::print(OpAsmPrinter &p) {
3118 p <<
'(' << getAsmFlavor() <<
", ";
3123 auto *nameIt = names.begin();
3124 auto *attrIt = getOperandAttrs().begin();
3126 for (mlir::OperandRange ops : getAsmOperands()) {
3127 p << *nameIt <<
" = ";
3130 llvm::interleaveComma(llvm::make_range(ops.begin(), ops.end()), p,
3132 p.printOperand(value);
3133 p <<
" : " << value.getType();
3135 p <<
" (maybe_memory)";
3144 p.printString(getAsmString());
3146 p.printString(getConstraints());
3150 if (getSideEffects())
3151 p <<
" side_effects";
3153 std::array elidedAttrs{
3154 llvm::StringRef(
"asm_flavor"), llvm::StringRef(
"asm_string"),
3155 llvm::StringRef(
"constraints"), llvm::StringRef(
"operand_attrs"),
3156 llvm::StringRef(
"operands_segments"), llvm::StringRef(
"side_effects")};
3157 p.printOptionalAttrDict(getOperation()->getAttrs(), elidedAttrs);
3159 if (
auto v = getRes())
3160 p <<
" -> " << v.getType();
3163void cir::InlineAsmOp::build(OpBuilder &odsBuilder, OperationState &odsState,
3165 StringRef asmString, StringRef constraints,
3166 bool sideEffects, cir::AsmFlavor asmFlavor,
3170 for (
auto operandRange : asmOperands) {
3171 segments.push_back(operandRange.size());
3172 odsState.addOperands(operandRange);
3175 odsState.addAttribute(
3176 "operands_segments",
3177 DenseI32ArrayAttr::get(odsBuilder.getContext(), segments));
3178 odsState.addAttribute(
"asm_string", odsBuilder.getStringAttr(asmString));
3179 odsState.addAttribute(
"constraints", odsBuilder.getStringAttr(constraints));
3180 odsState.addAttribute(
"asm_flavor",
3181 AsmFlavorAttr::get(odsBuilder.getContext(), asmFlavor));
3184 odsState.addAttribute(
"side_effects", odsBuilder.getUnitAttr());
3186 odsState.addAttribute(
"operand_attrs", odsBuilder.getArrayAttr(operandAttrs));
3189ParseResult cir::InlineAsmOp::parse(OpAsmParser &parser,
3190 OperationState &result) {
3193 std::string asmString, constraints;
3195 MLIRContext *ctxt = parser.getBuilder().getContext();
3197 auto error = [&](
const Twine &msg) -> LogicalResult {
3198 return parser.emitError(parser.getCurrentLocation(), msg);
3201 auto expected = [&](
const std::string &
c) {
3202 return error(
"expected '" +
c +
"'");
3205 if (parser.parseLParen().failed())
3206 return expected(
"(");
3208 auto flavor = FieldParser<AsmFlavor, AsmFlavor>::parse(parser);
3210 return error(
"Unknown AsmFlavor");
3212 if (parser.parseComma().failed())
3213 return expected(
",");
3215 auto parseValue = [&](
Value &v) {
3216 OpAsmParser::UnresolvedOperand op;
3218 if (parser.parseOperand(op) || parser.parseColon())
3219 return error(
"can't parse operand");
3222 if (parser.parseType(typ).failed())
3223 return error(
"can't parse operand type");
3225 if (parser.resolveOperand(op, typ, tmp))
3226 return error(
"can't resolve operand");
3228 return mlir::success();
3231 auto parseOperands = [&](llvm::StringRef
name) {
3232 if (parser.parseKeyword(name).failed())
3233 return error(
"expected " + name +
" operands here");
3234 if (parser.parseEqual().failed())
3235 return expected(
"=");
3236 if (parser.parseLSquare().failed())
3237 return expected(
"[");
3240 if (parser.parseOptionalRSquare().succeeded()) {
3241 operandsGroupSizes.push_back(size);
3242 if (parser.parseComma())
3243 return expected(
",");
3244 return mlir::success();
3247 auto parseOperand = [&]() {
3249 if (parseValue(val).succeeded()) {
3250 result.operands.push_back(val);
3253 if (parser.parseOptionalLParen().failed()) {
3254 operandAttrs.push_back(mlir::Attribute());
3255 return mlir::success();
3258 if (parser.parseKeyword(
"maybe_memory").succeeded()) {
3259 operandAttrs.push_back(mlir::UnitAttr::get(ctxt));
3260 if (parser.parseRParen())
3261 return expected(
")");
3262 return mlir::success();
3264 return expected(
"maybe_memory");
3267 return mlir::failure();
3270 if (parser.parseCommaSeparatedList(parseOperand).failed())
3271 return mlir::failure();
3273 if (parser.parseRSquare().failed() || parser.parseComma().failed())
3274 return expected(
"]");
3275 operandsGroupSizes.push_back(size);
3276 return mlir::success();
3279 if (parseOperands(
"out").failed() || parseOperands(
"in").failed() ||
3280 parseOperands(
"in_out").failed())
3281 return error(
"failed to parse operands");
3283 if (parser.parseLBrace())
3284 return expected(
"{");
3285 if (parser.parseString(&asmString))
3286 return error(
"asm string parsing failed");
3287 if (parser.parseString(&constraints))
3288 return error(
"constraints string parsing failed");
3289 if (parser.parseRBrace())
3290 return expected(
"}");
3291 if (parser.parseRParen())
3292 return expected(
")");
3294 if (parser.parseOptionalKeyword(
"side_effects").succeeded())
3295 result.attributes.set(
"side_effects", UnitAttr::get(ctxt));
3297 if (parser.parseOptionalArrow().succeeded() &&
3298 parser.parseType(resType).failed())
3299 return mlir::failure();
3301 if (parser.parseOptionalAttrDict(result.attributes).failed())
3302 return mlir::failure();
3304 result.attributes.set(
"asm_flavor", AsmFlavorAttr::get(ctxt, *flavor));
3305 result.attributes.set(
"asm_string", StringAttr::get(ctxt, asmString));
3306 result.attributes.set(
"constraints", StringAttr::get(ctxt, constraints));
3307 result.attributes.set(
"operand_attrs", ArrayAttr::get(ctxt, operandAttrs));
3308 result.getOrAddProperties<InlineAsmOp::Properties>().operands_segments =
3309 parser.getBuilder().getDenseI32ArrayAttr(operandsGroupSizes);
3311 result.addTypes(TypeRange{resType});
3313 return mlir::success();
3320mlir::LogicalResult cir::ThrowOp::verify() {
3325 if (getNumOperands() != 0) {
3328 return emitOpError() <<
"'type_info' symbol attribute missing";
3338LogicalResult cir::AtomicFetchOp::verify() {
3339 if (getBinop() != cir::AtomicFetchKind::Add &&
3340 getBinop() != cir::AtomicFetchKind::Sub &&
3341 getBinop() != cir::AtomicFetchKind::Max &&
3342 getBinop() != cir::AtomicFetchKind::Min &&
3343 !mlir::isa<cir::IntType>(getVal().
getType()))
3344 return emitError(
"only atomic add, sub, max, and min operation could "
3345 "operate on floating-point values");
3353LogicalResult cir::TypeInfoAttr::verify(
3354 ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError,
3355 ::mlir::Type type, ::mlir::ArrayAttr typeInfoData) {
3357 if (cir::ConstRecordAttr::verify(emitError, type, typeInfoData).failed())
3367void cir::TryOp::getSuccessorRegions(
3368 mlir::RegionBranchPoint point,
3371 if (!point.isParent()) {
3373 RegionSuccessor(getOperation(), getOperation()->getResults()));
3377 regions.push_back(mlir::RegionSuccessor(&getTryRegion()));
3381 for (mlir::Region &handlerRegion : this->getHandlerRegions())
3382 regions.push_back(mlir::RegionSuccessor(&handlerRegion));
3387 mlir::MutableArrayRef<mlir::Region> handlerRegions,
3388 mlir::ArrayAttr handlerTypes) {
3392 for (
const auto [typeIdx, typeAttr] : llvm::enumerate(handlerTypes)) {
3396 if (mlir::isa<cir::CatchAllAttr>(typeAttr)) {
3397 printer <<
"catch all ";
3398 }
else if (mlir::isa<cir::UnwindAttr>(typeAttr)) {
3399 printer <<
"unwind ";
3401 printer <<
"catch [type ";
3402 printer.printAttribute(typeAttr);
3406 printer.printRegion(handlerRegions[typeIdx],
3413 mlir::OpAsmParser &parser,
3415 mlir::ArrayAttr &handlerTypes) {
3417 auto parseCheckedCatcherRegion = [&]() -> mlir::ParseResult {
3418 handlerRegions.emplace_back(
new mlir::Region);
3420 mlir::Region &currRegion = *handlerRegions.back();
3421 mlir::SMLoc regionLoc = parser.getCurrentLocation();
3422 if (parser.parseRegion(currRegion)) {
3423 handlerRegions.clear();
3427 if (currRegion.empty())
3428 return parser.emitError(regionLoc,
"handler region shall not be empty");
3430 if (!(currRegion.back().mightHaveTerminator() &&
3431 currRegion.back().getTerminator()))
3432 return parser.emitError(
3433 regionLoc,
"blocks are expected to be explicitly terminated");
3438 bool hasCatchAll =
false;
3440 while (parser.parseOptionalKeyword(
"catch").succeeded()) {
3441 bool hasLSquare = parser.parseOptionalLSquare().succeeded();
3443 llvm::StringRef attrStr;
3444 if (parser.parseOptionalKeyword(&attrStr, {
"all",
"type"}).failed())
3445 return parser.emitError(parser.getCurrentLocation(),
3446 "expected 'all' or 'type' keyword");
3448 bool isCatchAll = attrStr ==
"all";
3451 return parser.emitError(parser.getCurrentLocation(),
3452 "can't have more than one catch all");
3456 mlir::Attribute exceptionRTTIAttr;
3457 if (!isCatchAll && parser.parseAttribute(exceptionRTTIAttr).failed())
3458 return parser.emitError(parser.getCurrentLocation(),
3459 "expected valid RTTI info attribute");
3461 catcherAttrs.push_back(isCatchAll
3462 ? cir::CatchAllAttr::get(parser.getContext())
3463 : exceptionRTTIAttr);
3465 if (hasLSquare && isCatchAll)
3466 return parser.emitError(parser.getCurrentLocation(),
3467 "catch all dosen't need RTTI info attribute");
3469 if (hasLSquare && parser.parseRSquare().failed())
3470 return parser.emitError(parser.getCurrentLocation(),
3471 "expected `]` after RTTI info attribute");
3473 if (parseCheckedCatcherRegion().failed())
3474 return mlir::failure();
3477 if (parser.parseOptionalKeyword(
"unwind").succeeded()) {
3479 return parser.emitError(parser.getCurrentLocation(),
3480 "unwind can't be used with catch all");
3482 catcherAttrs.push_back(cir::UnwindAttr::get(parser.getContext()));
3483 if (parseCheckedCatcherRegion().failed())
3484 return mlir::failure();
3487 handlerTypes = parser.getBuilder().getArrayAttr(catcherAttrs);
3488 return mlir::success();
3495#define GET_OP_CLASSES
3496#include "clang/CIR/Dialect/IR/CIROps.cpp.inc"
static const MemRegion * getRegion(const CallEvent &Call, const MutexDescriptor &Descriptor, bool IsLock)
static mlir::LogicalResult checkReturnAndFunction(cir::ReturnOp op, cir::FuncOp function)
static bool isBoolNot(cir::UnaryOp op)
static mlir::ParseResult parseCallCommon(mlir::OpAsmParser &parser, mlir::OperationState &result, bool hasDestinationBlocks=false)
static bool isIntOrBoolCast(cir::CastOp op)
static void printConstant(OpAsmPrinter &p, Attribute value)
static mlir::ParseResult parseOmittedTerminatorRegion(mlir::OpAsmParser &parser, mlir::Region ®ion)
ParseResult parseInlineKindAttr(OpAsmParser &parser, cir::InlineKindAttr &inlineKindAttr)
void printInlineKindAttr(OpAsmPrinter &p, cir::InlineKindAttr inlineKindAttr)
void printVisibilityAttr(OpAsmPrinter &printer, cir::VisibilityAttr &visibility)
static ParseResult parseSwitchFlatOpCases(OpAsmParser &parser, Type flagType, mlir::ArrayAttr &caseValues, SmallVectorImpl< Block * > &caseDestinations, SmallVectorImpl< llvm::SmallVector< OpAsmParser::UnresolvedOperand > > &caseOperands, SmallVectorImpl< llvm::SmallVector< Type > > &caseOperandTypes)
<cases> ::= [ (case (, case )* )?
static LogicalResult verifyCallCommInSymbolUses(mlir::Operation *op, SymbolTableCollection &symbolTable)
static LogicalResult ensureRegionTerm(OpAsmParser &parser, Region ®ion, SMLoc errLoc)
static ParseResult parseGlobalOpTypeAndInitialValue(OpAsmParser &parser, TypeAttr &typeAttr, Attribute &initialValueAttr, mlir::Region &ctorRegion, mlir::Region &dtorRegion)
void printIndirectBrOpSucessors(OpAsmPrinter &p, cir::IndirectBrOp op, Type flagType, SuccessorRange succs, OperandRangeRange succOperands, const TypeRangeRange &succOperandsTypes)
static OpFoldResult foldUnaryBitOp(mlir::Attribute inputAttr, llvm::function_ref< llvm::APInt(const llvm::APInt &)> func, bool poisonZero=false)
static llvm::StringRef getLinkageAttrNameString()
Returns the name used for the linkage attribute.
static RetTy parseOptionalCIRKeyword(AsmParser &parser, EnumTy defaultValue)
Parse an enum from the keyword, or default to the provided default value.
static void printSwitchFlatOpCases(OpAsmPrinter &p, cir::SwitchFlatOp op, Type flagType, mlir::ArrayAttr caseValues, SuccessorRange caseDestinations, OperandRangeRange caseOperands, const TypeRangeRange &caseOperandTypes)
static mlir::ParseResult parseTryCallDestinations(mlir::OpAsmParser &parser, mlir::OperationState &result)
static void printGlobalOpTypeAndInitialValue(OpAsmPrinter &p, cir::GlobalOp op, TypeAttr type, Attribute initAttr, mlir::Region &ctorRegion, mlir::Region &dtorRegion)
static ParseResult parseCIRKeyword(AsmParser &parser, RetTy &result)
Parse an enum from the keyword, return failure if the keyword is not found.
static Value tryFoldCastChain(cir::CastOp op)
void parseVisibilityAttr(OpAsmParser &parser, cir::VisibilityAttr &visibility)
static void printTryHandlerRegions(mlir::OpAsmPrinter &printer, cir::TryOp op, mlir::MutableArrayRef< mlir::Region > handlerRegions, mlir::ArrayAttr handlerTypes)
ParseResult parseIndirectBrOpSucessors(OpAsmParser &parser, Type &flagType, SmallVectorImpl< Block * > &succOperandBlocks, SmallVectorImpl< SmallVector< OpAsmParser::UnresolvedOperand > > &succOperands, SmallVectorImpl< SmallVector< Type > > &succOperandsTypes)
static bool omitRegionTerm(mlir::Region &r)
static void printCallCommon(mlir::Operation *op, mlir::FlatSymbolRefAttr calleeSym, mlir::Value indirectCallee, mlir::OpAsmPrinter &printer, bool isNothrow, cir::SideEffect sideEffect, mlir::Block *normalDest=nullptr, mlir::Block *unwindDest=nullptr)
static void printOmittedTerminatorRegion(mlir::OpAsmPrinter &printer, cir::ScopeOp &op, mlir::Region ®ion)
static ParseResult parseConstantValue(OpAsmParser &parser, mlir::Attribute &valueAttr)
static LogicalResult checkConstantTypes(mlir::Operation *op, mlir::Type opType, mlir::Attribute attrType)
static mlir::ParseResult parseTryHandlerRegions(mlir::OpAsmParser &parser, llvm::SmallVectorImpl< std::unique_ptr< mlir::Region > > &handlerRegions, mlir::ArrayAttr &handlerTypes)
#define REGISTER_ENUM_TYPE(Ty)
static int parseOptionalKeywordAlternative(AsmParser &parser, ArrayRef< llvm::StringRef > keywords)
llvm::function_ref< void(mlir::OpBuilder &, mlir::Location)> BuilderCallbackRef
llvm::function_ref< void( mlir::OpBuilder &, mlir::Location, mlir::OperationState &)> BuilderOpStateCallbackRef
static std::optional< NonLoc > getIndex(ProgramStateRef State, const ElementRegion *ER, CharKind CK)
static Decl::Kind getKind(const Decl *D)
__device__ __2f16 float c
void buildTerminatedBody(mlir::OpBuilder &builder, mlir::Location loc)
const internal::VariadicAllOfMatcher< Attr > attr
const AstTypeMatcher< RecordType > recordType
StringRef getName(const HeaderType T)
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
__DEVICE__ _Tp arg(const std::complex< _Tp > &__c)
static bool addressSpace()
static bool opCallCallConv()
static bool opScopeCleanupRegion()
static bool supportIFuncAttr()