19#include "mlir/IR/Attributes.h"
20#include "mlir/IR/DialectImplementation.h"
21#include "mlir/IR/PatternMatch.h"
22#include "mlir/Interfaces/ControlFlowInterfaces.h"
23#include "mlir/Interfaces/FunctionImplementation.h"
24#include "mlir/Support/LLVM.h"
26#include "clang/CIR/Dialect/IR/CIROpsDialect.cpp.inc"
27#include "clang/CIR/Dialect/IR/CIROpsEnums.cpp.inc"
29#include "llvm/ADT/SetOperations.h"
30#include "llvm/ADT/SmallSet.h"
31#include "llvm/ADT/TypeSwitch.h"
32#include "llvm/Support/LogicalResult.h"
41struct CIROpAsmDialectInterface :
public OpAsmDialectInterface {
42 using OpAsmDialectInterface::OpAsmDialectInterface;
44 AliasResult getAlias(Type type, raw_ostream &os)
const final {
45 if (
auto recordType = dyn_cast<cir::RecordType>(type)) {
48 os <<
"rec_anon_" <<
recordType.getKindAsStr();
50 os <<
"rec_" << nameAttr.getValue();
51 return AliasResult::OverridableAlias;
53 if (
auto intType = dyn_cast<cir::IntType>(type)) {
56 unsigned width = intType.getWidth();
57 if (width < 8 || !llvm::isPowerOf2_32(width))
58 return AliasResult::NoAlias;
59 os << intType.getAlias();
60 return AliasResult::OverridableAlias;
62 if (
auto voidType = dyn_cast<cir::VoidType>(type)) {
63 os << voidType.getAlias();
64 return AliasResult::OverridableAlias;
67 return AliasResult::NoAlias;
70 AliasResult getAlias(Attribute attr, raw_ostream &os)
const final {
71 if (
auto boolAttr = mlir::dyn_cast<cir::BoolAttr>(attr)) {
72 os << (boolAttr.getValue() ?
"true" :
"false");
73 return AliasResult::FinalAlias;
75 if (
auto bitfield = mlir::dyn_cast<cir::BitfieldInfoAttr>(attr)) {
76 os <<
"bfi_" << bitfield.getName().str();
77 return AliasResult::FinalAlias;
79 if (
auto dynCastInfoAttr = mlir::dyn_cast<cir::DynamicCastInfoAttr>(attr)) {
80 os << dynCastInfoAttr.getAlias();
81 return AliasResult::FinalAlias;
83 if (
auto cmpThreeWayInfoAttr =
84 mlir::dyn_cast<cir::CmpThreeWayInfoAttr>(attr)) {
85 os << cmpThreeWayInfoAttr.getAlias();
86 return AliasResult::FinalAlias;
88 return AliasResult::NoAlias;
93void cir::CIRDialect::initialize() {
98#include "clang/CIR/Dialect/IR/CIROps.cpp.inc"
100 addInterfaces<CIROpAsmDialectInterface>();
103Operation *cir::CIRDialect::materializeConstant(mlir::OpBuilder &builder,
104 mlir::Attribute value,
106 mlir::Location loc) {
107 return cir::ConstantOp::create(builder, loc, type,
108 mlir::cast<mlir::TypedAttr>(value));
120 for (
auto en : llvm::enumerate(keywords)) {
121 if (succeeded(parser.parseOptionalKeyword(en.value())))
128template <
typename Ty>
struct EnumTraits {};
130#define REGISTER_ENUM_TYPE(Ty) \
131 template <> struct EnumTraits<cir::Ty> { \
132 static llvm::StringRef stringify(cir::Ty value) { \
133 return stringify##Ty(value); \
135 static unsigned getMaxEnumVal() { return cir::getMaxEnumValFor##Ty(); } \
146template <
typename EnumTy,
typename RetTy = EnumTy>
149 for (
unsigned i = 0, e = EnumTraits<EnumTy>::getMaxEnumVal(); i <= e; ++i)
150 names.push_back(EnumTraits<EnumTy>::stringify(
static_cast<EnumTy
>(i)));
154 return static_cast<RetTy
>(defaultValue);
155 return static_cast<RetTy
>(index);
159template <
typename EnumTy,
typename RetTy = EnumTy>
162 for (
unsigned i = 0, e = EnumTraits<EnumTy>::getMaxEnumVal(); i <= e; ++i)
163 names.push_back(EnumTraits<EnumTy>::stringify(
static_cast<EnumTy
>(i)));
168 result =
static_cast<RetTy
>(index);
176 Location eLoc = parser.getEncodedSourceLoc(parser.getCurrentLocation());
177 OpBuilder builder(parser.getBuilder().getContext());
182 builder.createBlock(®ion);
184 Block &block = region.back();
186 if (!block.empty() && block.back().hasTrait<OpTrait::IsTerminator>())
190 if (!region.hasOneBlock())
191 return parser.emitError(errLoc,
192 "multi-block region must not omit terminator");
195 builder.setInsertionPointToEnd(&block);
196 cir::YieldOp::create(builder, eLoc);
202 const auto singleNonEmptyBlock = r.hasOneBlock() && !r.back().empty();
203 const auto yieldsNothing = [&r]() {
204 auto y = dyn_cast<cir::YieldOp>(r.back().getTerminator());
205 return y && y.getArgs().empty();
207 return singleNonEmptyBlock && yieldsNothing();
215 cir::InlineKindAttr &inlineKindAttr) {
217 static constexpr llvm::StringRef keywords[] = {
"no_inline",
"always_inline",
221 llvm::StringRef keyword;
222 if (parser.parseOptionalKeyword(&keyword, keywords).failed()) {
228 auto inlineKindResult = ::cir::symbolizeEnum<::cir::InlineKind>(keyword);
229 if (!inlineKindResult) {
230 return parser.emitError(parser.getCurrentLocation(),
"expected one of [")
232 <<
"] for inlineKind, got: " << keyword;
236 ::cir::InlineKindAttr::get(parser.getContext(), *inlineKindResult);
241 if (inlineKindAttr) {
242 p <<
" " << stringifyInlineKind(inlineKindAttr.getValue());
250 mlir::Region ®ion) {
251 auto regionLoc = parser.getCurrentLocation();
252 if (parser.parseRegion(region))
261 mlir::Region ®ion) {
262 printer.printRegion(region,
267mlir::OptionalParseResult
269 mlir::ptr::MemorySpaceAttrInterface &attr);
272 mlir::ptr::MemorySpaceAttrInterface attr);
278void cir::AllocaOp::build(mlir::OpBuilder &odsBuilder,
279 mlir::OperationState &odsState, mlir::Type addr,
280 mlir::Type allocaType, llvm::StringRef name,
281 mlir::IntegerAttr alignment) {
282 odsState.addAttribute(getAllocaTypeAttrName(odsState.name),
283 mlir::TypeAttr::get(allocaType));
284 odsState.addAttribute(getNameAttrName(odsState.name),
285 odsBuilder.getStringAttr(name));
287 odsState.addAttribute(getAlignmentAttrName(odsState.name), alignment);
289 odsState.addTypes(addr);
297 auto ptrTy = mlir::cast<cir::PointerType>(op.getAddr().getType());
298 mlir::Type pointeeTy = ptrTy.getPointee();
300 mlir::Block &body = op.getBody().front();
301 if (body.getNumArguments() != 1)
302 return op.emitOpError(
"body must have exactly one block argument");
304 auto expectedEltPtrTy =
305 mlir::dyn_cast<cir::PointerType>(body.getArgument(0).getType());
306 if (!expectedEltPtrTy)
307 return op.emitOpError(
"block argument must be a !cir.ptr type");
309 if (op.getNumElements()) {
310 auto recTy = mlir::dyn_cast<cir::RecordType>(pointeeTy);
312 return op.emitOpError(
313 "when 'num_elements' is present, 'addr' must be a pointer to a "
316 if (expectedEltPtrTy != ptrTy)
317 return op.emitOpError(
"when 'num_elements' is present, 'addr' type must "
318 "match the block argument type");
320 auto arrayTy = mlir::dyn_cast<cir::ArrayType>(pointeeTy);
322 return op.emitOpError(
323 "when 'num_elements' is absent, 'addr' must be a pointer to a "
326 mlir::Type innerEltTy = arrayTy.getElementType();
327 while (
auto nested = mlir::dyn_cast<cir::ArrayType>(innerEltTy))
328 innerEltTy = nested.getElementType();
330 auto recTy = mlir::dyn_cast<cir::RecordType>(innerEltTy);
332 return op.emitOpError(
333 "the block argument type must be a pointer to a !cir.record type");
335 if (expectedEltPtrTy.getPointee() != innerEltTy)
336 return op.emitOpError(
337 "block argument pointee type must match the innermost array "
344LogicalResult cir::ArrayCtor::verify() {
348 mlir::Region &partialDtor = getPartialDtor();
349 if (!partialDtor.empty()) {
350 mlir::Block &dtorBlock = partialDtor.front();
351 if (dtorBlock.getNumArguments() != 1)
352 return emitOpError(
"partial_dtor must have exactly one block argument");
354 auto bodyArgTy = getBody().front().getArgument(0).getType();
355 if (dtorBlock.getArgument(0).getType() != bodyArgTy)
356 return emitOpError(
"partial_dtor block argument type must match "
357 "the body block argument type");
367LogicalResult cir::BreakOp::verify() {
368 if (!getOperation()->getParentOfType<LoopOpInterface>() &&
369 !getOperation()->getParentOfType<SwitchOp>())
370 return emitOpError(
"must be within a loop");
382void cir::ConditionOp::getSuccessorRegions(
388 if (
auto loopOp = dyn_cast<LoopOpInterface>(getOperation()->getParentOp())) {
389 regions.emplace_back(&loopOp.getBody());
390 regions.push_back(RegionSuccessor::parent());
394 auto await = cast<AwaitOp>(getOperation()->getParentOp());
395 regions.emplace_back(&await.getResume());
396 regions.emplace_back(&await.getSuspend());
400cir::ConditionOp::getMutableSuccessorOperands(RegionSuccessor point) {
402 return MutableOperandRange(getOperation(), 0, 0);
406cir::ResumeOp::getMutableSuccessorOperands(RegionSuccessor point) {
408 return MutableOperandRange(getOperation(), 0, 0);
411LogicalResult cir::ConditionOp::verify() {
412 if (!isa<LoopOpInterface, AwaitOp>(getOperation()->getParentOp()))
413 return emitOpError(
"condition must be within a conditional region");
422 mlir::Attribute attrType) {
423 if (isa<cir::ConstPtrAttr>(attrType)) {
424 if (!mlir::isa<cir::PointerType>(opType))
425 return op->emitOpError(
426 "pointer constant initializing a non-pointer type");
430 if (isa<cir::DataMemberAttr, cir::MethodAttr>(attrType)) {
436 if (isa<cir::ZeroAttr>(attrType)) {
437 if (isa<cir::RecordType, cir::ArrayType, cir::VectorType, cir::ComplexType>(
440 return op->emitOpError(
441 "zero expects struct, array, vector, or complex type");
444 if (mlir::isa<cir::UndefAttr>(attrType)) {
445 if (!mlir::isa<cir::VoidType>(opType))
447 return op->emitOpError(
"undef expects non-void type");
450 if (mlir::isa<cir::BoolAttr>(attrType)) {
451 if (!mlir::isa<cir::BoolType>(opType))
452 return op->emitOpError(
"result type (")
453 << opType <<
") must be '!cir.bool' for '" << attrType <<
"'";
457 if (mlir::isa<cir::IntAttr, cir::FPAttr>(attrType)) {
458 auto at = cast<TypedAttr>(attrType);
459 if (at.getType() != opType) {
460 return op->emitOpError(
"result type (")
461 << opType <<
") does not match value type (" << at.getType()
467 if (mlir::isa<cir::ConstArrayAttr, cir::ConstVectorAttr,
468 cir::ConstComplexAttr, cir::ConstRecordAttr,
469 cir::GlobalViewAttr, cir::PoisonAttr, cir::TypeInfoAttr,
470 cir::VTableAttr>(attrType))
473 assert(isa<TypedAttr>(attrType) &&
"What else could we be looking at here?");
474 return op->emitOpError(
"global with type ")
475 << cast<TypedAttr>(attrType).getType() <<
" not yet supported";
478LogicalResult cir::ConstantOp::verify() {
485OpFoldResult cir::ConstantOp::fold(FoldAdaptor ) {
493LogicalResult cir::ContinueOp::verify() {
494 if (!getOperation()->getParentOfType<LoopOpInterface>())
495 return emitOpError(
"must be within a loop");
503LogicalResult cir::CastOp::verify() {
504 mlir::Type resType =
getType();
505 mlir::Type srcType = getSrc().getType();
509 auto srcPtrTy = mlir::dyn_cast<cir::PointerType>(srcType);
510 auto resPtrTy = mlir::dyn_cast<cir::PointerType>(resType);
511 if (srcPtrTy && resPtrTy && (
getKind() != cir::CastKind::address_space))
512 if (srcPtrTy.getAddrSpace() != resPtrTy.getAddrSpace()) {
513 return emitOpError() <<
"result type address space does not match the "
514 "address space of the operand";
517 if (mlir::isa<cir::VectorType>(srcType) &&
518 mlir::isa<cir::VectorType>(resType)) {
521 srcType = mlir::dyn_cast<cir::VectorType>(srcType).getElementType();
522 resType = mlir::dyn_cast<cir::VectorType>(resType).getElementType();
526 case cir::CastKind::int_to_bool: {
527 if (!mlir::isa<cir::BoolType>(resType))
528 return emitOpError() <<
"requires !cir.bool type for result";
529 if (!mlir::isa<cir::IntType>(srcType))
530 return emitOpError() <<
"requires !cir.int type for source";
533 case cir::CastKind::ptr_to_bool: {
534 if (!mlir::isa<cir::BoolType>(resType))
535 return emitOpError() <<
"requires !cir.bool type for result";
536 if (!mlir::isa<cir::PointerType>(srcType))
537 return emitOpError() <<
"requires !cir.ptr type for source";
540 case cir::CastKind::integral: {
541 if (!mlir::isa<cir::IntType>(resType))
542 return emitOpError() <<
"requires !cir.int type for result";
543 if (!mlir::isa<cir::IntType>(srcType))
544 return emitOpError() <<
"requires !cir.int type for source";
547 case cir::CastKind::array_to_ptrdecay: {
548 const auto arrayPtrTy = mlir::dyn_cast<cir::PointerType>(srcType);
549 const auto flatPtrTy = mlir::dyn_cast<cir::PointerType>(resType);
550 if (!arrayPtrTy || !flatPtrTy)
551 return emitOpError() <<
"requires !cir.ptr type for source and result";
556 case cir::CastKind::bitcast: {
558 auto srcPtrTy = mlir::dyn_cast<cir::PointerType>(srcType);
559 auto resPtrTy = mlir::dyn_cast<cir::PointerType>(resType);
561 if (srcPtrTy && resPtrTy) {
567 case cir::CastKind::floating: {
568 if (!mlir::isa<cir::FPTypeInterface>(srcType) ||
569 !mlir::isa<cir::FPTypeInterface>(resType))
570 return emitOpError() <<
"requires !cir.float type for source and result";
573 case cir::CastKind::float_to_int: {
574 if (!mlir::isa<cir::FPTypeInterface>(srcType))
575 return emitOpError() <<
"requires !cir.float type for source";
576 if (!mlir::dyn_cast<cir::IntType>(resType))
577 return emitOpError() <<
"requires !cir.int type for result";
580 case cir::CastKind::int_to_ptr: {
581 if (!mlir::dyn_cast<cir::IntType>(srcType))
582 return emitOpError() <<
"requires !cir.int type for source";
583 if (!mlir::dyn_cast<cir::PointerType>(resType))
584 return emitOpError() <<
"requires !cir.ptr type for result";
587 case cir::CastKind::ptr_to_int: {
588 if (!mlir::dyn_cast<cir::PointerType>(srcType))
589 return emitOpError() <<
"requires !cir.ptr type for source";
590 if (!mlir::dyn_cast<cir::IntType>(resType))
591 return emitOpError() <<
"requires !cir.int type for result";
594 case cir::CastKind::float_to_bool: {
595 if (!mlir::isa<cir::FPTypeInterface>(srcType))
596 return emitOpError() <<
"requires !cir.float type for source";
597 if (!mlir::isa<cir::BoolType>(resType))
598 return emitOpError() <<
"requires !cir.bool type for result";
601 case cir::CastKind::bool_to_int: {
602 if (!mlir::isa<cir::BoolType>(srcType))
603 return emitOpError() <<
"requires !cir.bool type for source";
604 if (!mlir::isa<cir::IntType>(resType))
605 return emitOpError() <<
"requires !cir.int type for result";
608 case cir::CastKind::int_to_float: {
609 if (!mlir::isa<cir::IntType>(srcType))
610 return emitOpError() <<
"requires !cir.int type for source";
611 if (!mlir::isa<cir::FPTypeInterface>(resType))
612 return emitOpError() <<
"requires !cir.float type for result";
615 case cir::CastKind::bool_to_float: {
616 if (!mlir::isa<cir::BoolType>(srcType))
617 return emitOpError() <<
"requires !cir.bool type for source";
618 if (!mlir::isa<cir::FPTypeInterface>(resType))
619 return emitOpError() <<
"requires !cir.float type for result";
622 case cir::CastKind::address_space: {
623 auto srcPtrTy = mlir::dyn_cast<cir::PointerType>(srcType);
624 auto resPtrTy = mlir::dyn_cast<cir::PointerType>(resType);
625 if (!srcPtrTy || !resPtrTy)
626 return emitOpError() <<
"requires !cir.ptr type for source and result";
627 if (srcPtrTy.getPointee() != resPtrTy.getPointee())
628 return emitOpError() <<
"requires two types differ in addrspace only";
631 case cir::CastKind::float_to_complex: {
632 if (!mlir::isa<cir::FPTypeInterface>(srcType))
633 return emitOpError() <<
"requires !cir.float type for source";
634 auto resComplexTy = mlir::dyn_cast<cir::ComplexType>(resType);
636 return emitOpError() <<
"requires !cir.complex type for result";
637 if (srcType != resComplexTy.getElementType())
638 return emitOpError() <<
"requires source type match result element type";
641 case cir::CastKind::int_to_complex: {
642 if (!mlir::isa<cir::IntType>(srcType))
643 return emitOpError() <<
"requires !cir.int type for source";
644 auto resComplexTy = mlir::dyn_cast<cir::ComplexType>(resType);
646 return emitOpError() <<
"requires !cir.complex type for result";
647 if (srcType != resComplexTy.getElementType())
648 return emitOpError() <<
"requires source type match result element type";
651 case cir::CastKind::float_complex_to_real: {
652 auto srcComplexTy = mlir::dyn_cast<cir::ComplexType>(srcType);
654 return emitOpError() <<
"requires !cir.complex type for source";
655 if (!mlir::isa<cir::FPTypeInterface>(resType))
656 return emitOpError() <<
"requires !cir.float type for result";
657 if (srcComplexTy.getElementType() != resType)
658 return emitOpError() <<
"requires source element type match result type";
661 case cir::CastKind::int_complex_to_real: {
662 auto srcComplexTy = mlir::dyn_cast<cir::ComplexType>(srcType);
664 return emitOpError() <<
"requires !cir.complex type for source";
665 if (!mlir::isa<cir::IntType>(resType))
666 return emitOpError() <<
"requires !cir.int type for result";
667 if (srcComplexTy.getElementType() != resType)
668 return emitOpError() <<
"requires source element type match result type";
671 case cir::CastKind::float_complex_to_bool: {
672 auto srcComplexTy = mlir::dyn_cast<cir::ComplexType>(srcType);
673 if (!srcComplexTy || !srcComplexTy.isFloatingPointComplex())
675 <<
"requires floating point !cir.complex type for source";
676 if (!mlir::isa<cir::BoolType>(resType))
677 return emitOpError() <<
"requires !cir.bool type for result";
680 case cir::CastKind::int_complex_to_bool: {
681 auto srcComplexTy = mlir::dyn_cast<cir::ComplexType>(srcType);
682 if (!srcComplexTy || !srcComplexTy.isIntegerComplex())
684 <<
"requires floating point !cir.complex type for source";
685 if (!mlir::isa<cir::BoolType>(resType))
686 return emitOpError() <<
"requires !cir.bool type for result";
689 case cir::CastKind::float_complex: {
690 auto srcComplexTy = mlir::dyn_cast<cir::ComplexType>(srcType);
691 if (!srcComplexTy || !srcComplexTy.isFloatingPointComplex())
693 <<
"requires floating point !cir.complex type for source";
694 auto resComplexTy = mlir::dyn_cast<cir::ComplexType>(resType);
695 if (!resComplexTy || !resComplexTy.isFloatingPointComplex())
697 <<
"requires floating point !cir.complex type for result";
700 case cir::CastKind::float_complex_to_int_complex: {
701 auto srcComplexTy = mlir::dyn_cast<cir::ComplexType>(srcType);
702 if (!srcComplexTy || !srcComplexTy.isFloatingPointComplex())
704 <<
"requires floating point !cir.complex type for source";
705 auto resComplexTy = mlir::dyn_cast<cir::ComplexType>(resType);
706 if (!resComplexTy || !resComplexTy.isIntegerComplex())
707 return emitOpError() <<
"requires integer !cir.complex type for result";
710 case cir::CastKind::int_complex: {
711 auto srcComplexTy = mlir::dyn_cast<cir::ComplexType>(srcType);
712 if (!srcComplexTy || !srcComplexTy.isIntegerComplex())
713 return emitOpError() <<
"requires integer !cir.complex type for source";
714 auto resComplexTy = mlir::dyn_cast<cir::ComplexType>(resType);
715 if (!resComplexTy || !resComplexTy.isIntegerComplex())
716 return emitOpError() <<
"requires integer !cir.complex type for result";
719 case cir::CastKind::int_complex_to_float_complex: {
720 auto srcComplexTy = mlir::dyn_cast<cir::ComplexType>(srcType);
721 if (!srcComplexTy || !srcComplexTy.isIntegerComplex())
722 return emitOpError() <<
"requires integer !cir.complex type for source";
723 auto resComplexTy = mlir::dyn_cast<cir::ComplexType>(resType);
724 if (!resComplexTy || !resComplexTy.isFloatingPointComplex())
726 <<
"requires floating point !cir.complex type for result";
729 case cir::CastKind::member_ptr_to_bool: {
730 if (!mlir::isa<cir::DataMemberType, cir::MethodType>(srcType))
732 <<
"requires !cir.data_member or !cir.method type for source";
733 if (!mlir::isa<cir::BoolType>(resType))
734 return emitOpError() <<
"requires !cir.bool type for result";
738 llvm_unreachable(
"Unknown CastOp kind?");
742 auto kind = op.getKind();
743 return kind == cir::CastKind::bool_to_int ||
744 kind == cir::CastKind::int_to_bool ||
kind == cir::CastKind::integral;
748 cir::CastOp head = op, tail = op;
754 op = head.getSrc().getDefiningOp<cir::CastOp>();
762 if (head.getKind() == cir::CastKind::bool_to_int &&
763 tail.getKind() == cir::CastKind::int_to_bool)
764 return head.getSrc();
769 if (head.getKind() == cir::CastKind::int_to_bool &&
770 tail.getKind() == cir::CastKind::int_to_bool)
771 return head.getResult();
776OpFoldResult cir::CastOp::fold(FoldAdaptor adaptor) {
777 if (mlir::isa_and_present<cir::PoisonAttr>(adaptor.getSrc())) {
779 return cir::PoisonAttr::get(getContext(),
getType());
784 case cir::CastKind::integral: {
786 auto foldOrder = getSrc().getDefiningOp()->fold(foldResults);
787 if (foldOrder.succeeded() && mlir::isa<mlir::Attribute>(foldResults[0]))
788 return mlir::cast<mlir::Attribute>(foldResults[0]);
791 case cir::CastKind::bitcast:
792 case cir::CastKind::address_space:
793 case cir::CastKind::float_complex:
794 case cir::CastKind::int_complex: {
808 if (
auto srcConst = getSrc().getDefiningOp<cir::ConstantOp>()) {
810 case cir::CastKind::integral: {
811 mlir::Type srcTy = getSrc().getType();
813 assert(mlir::isa<cir::VectorType>(srcTy) ==
814 mlir::isa<cir::VectorType>(
getType()));
815 if (mlir::isa<cir::VectorType>(srcTy))
818 auto srcIntTy = mlir::cast<cir::IntType>(srcTy);
819 auto dstIntTy = mlir::cast<cir::IntType>(
getType());
822 ? srcConst.getIntValue().sextOrTrunc(dstIntTy.getWidth())
823 : srcConst.getIntValue().zextOrTrunc(dstIntTy.getWidth());
824 return cir::IntAttr::get(dstIntTy, newVal);
837mlir::OperandRange cir::CallOp::getArgOperands() {
839 return getArgs().drop_front(1);
843mlir::MutableOperandRange cir::CallOp::getArgOperandsMutable() {
844 mlir::MutableOperandRange args = getArgsMutable();
846 return args.slice(1, args.size() - 1);
850mlir::Value cir::CallOp::getIndirectCall() {
851 assert(isIndirect());
852 return getOperand(0);
856Value cir::CallOp::getArgOperand(
unsigned i) {
859 return getOperand(i);
863unsigned cir::CallOp::getNumArgOperands() {
865 return this->getOperation()->getNumOperands() - 1;
866 return this->getOperation()->getNumOperands();
869static mlir::ParseResult
871 mlir::OperationState &result) {
872 mlir::Block *normalDestSuccessor;
873 if (parser.parseSuccessor(normalDestSuccessor))
874 return mlir::failure();
876 if (parser.parseComma())
877 return mlir::failure();
879 mlir::Block *unwindDestSuccessor;
880 if (parser.parseSuccessor(unwindDestSuccessor))
881 return mlir::failure();
883 result.addSuccessors(normalDestSuccessor);
884 result.addSuccessors(unwindDestSuccessor);
885 return mlir::success();
889 mlir::OperationState &result,
890 bool hasDestinationBlocks =
false) {
893 mlir::FlatSymbolRefAttr calleeAttr;
897 .parseOptionalAttribute(calleeAttr, CIRDialect::getCalleeAttrName(),
900 OpAsmParser::UnresolvedOperand indirectVal;
902 if (parser.parseOperand(indirectVal).failed())
904 ops.push_back(indirectVal);
907 if (parser.parseLParen())
908 return mlir::failure();
910 opsLoc = parser.getCurrentLocation();
911 if (parser.parseOperandList(ops))
912 return mlir::failure();
913 if (parser.parseRParen())
914 return mlir::failure();
916 if (hasDestinationBlocks &&
918 return ::mlir::failure();
921 if (parser.parseOptionalKeyword(
"musttail").succeeded())
922 result.addAttribute(CIRDialect::getMustTailAttrName(),
923 mlir::UnitAttr::get(parser.getContext()));
925 if (parser.parseOptionalKeyword(
"nothrow").succeeded())
926 result.addAttribute(CIRDialect::getNoThrowAttrName(),
927 mlir::UnitAttr::get(parser.getContext()));
929 if (parser.parseOptionalKeyword(
"side_effect").succeeded()) {
930 if (parser.parseLParen().failed())
932 cir::SideEffect sideEffect;
935 if (parser.parseRParen().failed())
937 auto attr = cir::SideEffectAttr::get(parser.getContext(), sideEffect);
938 result.addAttribute(CIRDialect::getSideEffectAttrName(), attr);
941 if (parser.parseOptionalAttrDict(result.attributes))
942 return ::mlir::failure();
944 if (parser.parseColon())
945 return ::mlir::failure();
951 if (call_interface_impl::parseFunctionSignature(parser, argTypes, argAttrs,
952 resultTypes, resultAttrs))
953 return mlir::failure();
955 if (resultTypes.size() > 1 || resultAttrs.size() > 1)
956 return parser.emitError(
957 parser.getCurrentLocation(),
958 "functions with multiple return types are not supported");
960 result.addTypes(resultTypes);
962 if (parser.resolveOperands(ops, argTypes, opsLoc, result.operands))
963 return mlir::failure();
965 if (!resultAttrs.empty() && resultAttrs[0])
967 CIRDialect::getResAttrsAttrName(),
968 mlir::ArrayAttr::get(parser.getContext(), {resultAttrs[0]}));
973 bool argAttrsEmpty =
true;
975 llvm::transform(argAttrs, std::back_inserter(convertedArgAttrs),
976 [&](DictionaryAttr da) -> mlir::Attribute {
978 argAttrsEmpty =
false;
982 if (!argAttrsEmpty) {
987 argAttrsRef = argAttrsRef.drop_front();
989 result.addAttribute(CIRDialect::getArgAttrsAttrName(),
990 mlir::ArrayAttr::get(parser.getContext(), argAttrsRef));
993 return mlir::success();
998 mlir::Value indirectCallee, mlir::OpAsmPrinter &printer,
999 bool isNothrow, cir::SideEffect sideEffect, ArrayAttr argAttrs,
1000 ArrayAttr resAttrs, mlir::Block *normalDest =
nullptr,
1001 mlir::Block *unwindDest =
nullptr) {
1004 auto callLikeOp = mlir::cast<cir::CIRCallOpInterface>(op);
1005 auto ops = callLikeOp.getArgOperands();
1009 printer.printAttributeWithoutType(calleeSym);
1012 assert(indirectCallee);
1013 printer << indirectCallee;
1016 printer <<
"(" << ops <<
")";
1019 assert(unwindDest &&
"expected two successors");
1020 auto tryCall = cast<cir::TryCallOp>(op);
1021 printer <<
' ' << tryCall.getNormalDest();
1024 printer << tryCall.getUnwindDest();
1027 if (op->hasAttr(CIRDialect::getMustTailAttrName()))
1028 printer <<
" musttail";
1031 printer <<
" nothrow";
1033 if (sideEffect != cir::SideEffect::All) {
1034 printer <<
" side_effect(";
1035 printer << stringifySideEffect(sideEffect);
1040 CIRDialect::getCalleeAttrName(),
1041 CIRDialect::getMustTailAttrName(),
1042 CIRDialect::getNoThrowAttrName(),
1043 CIRDialect::getSideEffectAttrName(),
1044 CIRDialect::getOperandSegmentSizesAttrName(),
1045 llvm::StringRef(
"res_attrs"),
1046 llvm::StringRef(
"arg_attrs")};
1047 printer.printOptionalAttrDict(op->getAttrs(), elidedAttrs);
1049 if (calleeSym || !argAttrs) {
1050 call_interface_impl::printFunctionSignature(
1051 printer, op->getOperands().getTypes(), argAttrs,
1052 false, op->getResultTypes(), resAttrs);
1060 shimmedArgAttrs.push_back(mlir::DictionaryAttr::get(op->getContext(), {}));
1061 shimmedArgAttrs.append(argAttrs.begin(), argAttrs.end());
1062 call_interface_impl::printFunctionSignature(
1063 printer, op->getOperands().getTypes(),
1064 mlir::ArrayAttr::get(op->getContext(), shimmedArgAttrs),
1065 false, op->getResultTypes(), resAttrs);
1069mlir::ParseResult cir::CallOp::parse(mlir::OpAsmParser &parser,
1070 mlir::OperationState &result) {
1074void cir::CallOp::print(mlir::OpAsmPrinter &p) {
1075 mlir::Value indirectCallee = isIndirect() ? getIndirectCall() :
nullptr;
1076 cir::SideEffect sideEffect = getSideEffect();
1077 printCallCommon(*
this, getCalleeAttr(), indirectCallee, p, getNothrow(),
1078 sideEffect, getArgAttrsAttr(), getResAttrsAttr());
1083 SymbolTableCollection &symbolTable) {
1085 op->getAttrOfType<FlatSymbolRefAttr>(CIRDialect::getCalleeAttrName());
1088 return mlir::success();
1091 auto fn = symbolTable.lookupNearestSymbolFrom<cir::FuncOp>(op, fnAttr);
1093 return op->emitOpError() <<
"'" << fnAttr.getValue()
1094 <<
"' does not reference a valid function";
1096 auto callIf = dyn_cast<cir::CIRCallOpInterface>(op);
1097 assert(callIf &&
"expected CIR call interface to be always available");
1101 auto fnType = fn.getFunctionType();
1102 if (!fn.getNoProto()) {
1103 unsigned numCallOperands = callIf.getNumArgOperands();
1104 unsigned numFnOpOperands = fnType.getNumInputs();
1106 if (!fnType.isVarArg() && numCallOperands != numFnOpOperands)
1107 return op->emitOpError(
"incorrect number of operands for callee");
1108 if (fnType.isVarArg() && numCallOperands < numFnOpOperands)
1109 return op->emitOpError(
"too few operands for callee");
1111 for (
unsigned i = 0, e = numFnOpOperands; i != e; ++i)
1112 if (callIf.getArgOperand(i).getType() != fnType.getInput(i))
1113 return op->emitOpError(
"operand type mismatch: expected operand type ")
1114 << fnType.getInput(i) <<
", but provided "
1115 << op->getOperand(i).getType() <<
" for operand number " << i;
1121 if (fnType.hasVoidReturn() && op->getNumResults() != 0)
1122 return op->emitOpError(
"callee returns void but call has results");
1125 if (!fnType.hasVoidReturn() && op->getNumResults() != 1)
1126 return op->emitOpError(
"incorrect number of results for callee");
1129 if (!fnType.hasVoidReturn() &&
1130 op->getResultTypes().front() != fnType.getReturnType()) {
1131 return op->emitOpError(
"result type mismatch: expected ")
1132 << fnType.getReturnType() <<
", but provided "
1133 << op->getResult(0).getType();
1136 return mlir::success();
1140cir::CallOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
1148mlir::OperandRange cir::TryCallOp::getArgOperands() {
1150 return getArgs().drop_front(1);
1154mlir::MutableOperandRange cir::TryCallOp::getArgOperandsMutable() {
1155 mlir::MutableOperandRange args = getArgsMutable();
1157 return args.slice(1, args.size() - 1);
1161mlir::Value cir::TryCallOp::getIndirectCall() {
1162 assert(isIndirect());
1163 return getOperand(0);
1167Value cir::TryCallOp::getArgOperand(
unsigned i) {
1170 return getOperand(i);
1174unsigned cir::TryCallOp::getNumArgOperands() {
1176 return this->getOperation()->getNumOperands() - 1;
1177 return this->getOperation()->getNumOperands();
1181cir::TryCallOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
1185mlir::ParseResult cir::TryCallOp::parse(mlir::OpAsmParser &parser,
1186 mlir::OperationState &result) {
1190void cir::TryCallOp::print(::mlir::OpAsmPrinter &p) {
1191 mlir::Value indirectCallee = isIndirect() ? getIndirectCall() :
nullptr;
1192 cir::SideEffect sideEffect = getSideEffect();
1193 printCallCommon(*
this, getCalleeAttr(), indirectCallee, p, getNothrow(),
1194 sideEffect, getArgAttrsAttr(), getResAttrsAttr(),
1195 getNormalDest(), getUnwindDest());
1203 cir::FuncOp function) {
1205 if (op.getNumOperands() > 1)
1206 return op.emitOpError() <<
"expects at most 1 return operand";
1209 auto expectedTy = function.getFunctionType().getReturnType();
1211 (op.getNumOperands() == 0 ? cir::VoidType::get(op.getContext())
1212 : op.getOperand(0).getType());
1213 if (actualTy != expectedTy)
1214 return op.emitOpError() <<
"returns " << actualTy
1215 <<
" but enclosing function returns " << expectedTy;
1217 return mlir::success();
1220mlir::LogicalResult cir::ReturnOp::verify() {
1223 auto *fnOp = getOperation()->getParentOp();
1224 while (!isa<cir::FuncOp>(fnOp))
1225 fnOp = fnOp->getParentOp();
1238ParseResult cir::IfOp::parse(OpAsmParser &parser, OperationState &result) {
1240 result.regions.reserve(2);
1241 Region *thenRegion = result.addRegion();
1242 Region *elseRegion = result.addRegion();
1244 mlir::Builder &builder = parser.getBuilder();
1245 OpAsmParser::UnresolvedOperand cond;
1246 Type boolType = cir::BoolType::get(builder.getContext());
1248 if (parser.parseOperand(cond) ||
1249 parser.resolveOperand(cond, boolType, result.operands))
1253 mlir::SMLoc parseThenLoc = parser.getCurrentLocation();
1254 if (parser.parseRegion(*thenRegion, {}, {}))
1261 if (!parser.parseOptionalKeyword(
"else")) {
1262 mlir::SMLoc parseElseLoc = parser.getCurrentLocation();
1263 if (parser.parseRegion(*elseRegion, {}, {}))
1270 if (parser.parseOptionalAttrDict(result.attributes))
1275void cir::IfOp::print(OpAsmPrinter &p) {
1276 p <<
" " << getCondition() <<
" ";
1277 mlir::Region &thenRegion = this->getThenRegion();
1278 p.printRegion(thenRegion,
1283 mlir::Region &elseRegion = this->getElseRegion();
1284 if (!elseRegion.empty()) {
1286 p.printRegion(elseRegion,
1291 p.printOptionalAttrDict(getOperation()->getAttrs());
1297 cir::YieldOp::create(builder, loc);
1305void cir::IfOp::getSuccessorRegions(mlir::RegionBranchPoint point,
1306 SmallVectorImpl<RegionSuccessor> ®ions) {
1308 if (!point.isParent()) {
1309 regions.push_back(RegionSuccessor::parent());
1314 Region *elseRegion = &this->getElseRegion();
1315 if (elseRegion->empty())
1316 elseRegion =
nullptr;
1319 regions.push_back(RegionSuccessor(&getThenRegion()));
1322 regions.push_back(RegionSuccessor(elseRegion));
1327mlir::ValueRange cir::IfOp::getSuccessorInputs(RegionSuccessor successor) {
1328 return successor.isParent() ? ValueRange(getOperation()->getResults())
1332void cir::IfOp::build(OpBuilder &builder, OperationState &result,
Value cond,
1335 assert(thenBuilder &&
"the builder callback for 'then' must be present");
1336 result.addOperands(cond);
1338 OpBuilder::InsertionGuard guard(builder);
1339 Region *thenRegion = result.addRegion();
1340 builder.createBlock(thenRegion);
1341 thenBuilder(builder, result.location);
1343 Region *elseRegion = result.addRegion();
1344 if (!withElseRegion)
1347 builder.createBlock(elseRegion);
1348 elseBuilder(builder, result.location);
1360void cir::ScopeOp::getSuccessorRegions(
1361 mlir::RegionBranchPoint point, SmallVectorImpl<RegionSuccessor> ®ions) {
1363 if (!point.isParent()) {
1364 regions.push_back(RegionSuccessor::parent());
1369 regions.push_back(RegionSuccessor(&getScopeRegion()));
1372mlir::ValueRange cir::ScopeOp::getSuccessorInputs(RegionSuccessor successor) {
1373 return successor.isParent() ? ValueRange(getOperation()->getResults())
1377void cir::ScopeOp::build(
1378 OpBuilder &builder, OperationState &result,
1379 function_ref<
void(OpBuilder &, Type &, Location)> scopeBuilder) {
1380 assert(scopeBuilder &&
"the builder callback for 'then' must be present");
1382 OpBuilder::InsertionGuard guard(builder);
1383 Region *scopeRegion = result.addRegion();
1384 builder.createBlock(scopeRegion);
1388 scopeBuilder(builder, yieldTy, result.location);
1391 result.addTypes(TypeRange{yieldTy});
1394void cir::ScopeOp::build(
1395 OpBuilder &builder, OperationState &result,
1396 function_ref<
void(OpBuilder &, Location)> scopeBuilder) {
1397 assert(scopeBuilder &&
"the builder callback for 'then' must be present");
1398 OpBuilder::InsertionGuard guard(builder);
1399 Region *scopeRegion = result.addRegion();
1400 builder.createBlock(scopeRegion);
1402 scopeBuilder(builder, result.location);
1405LogicalResult cir::ScopeOp::verify() {
1407 return emitOpError() <<
"cir.scope must not be empty since it should "
1408 "include at least an implicit cir.yield ";
1411 mlir::Block &lastBlock =
getRegion().back();
1412 if (lastBlock.empty() || !lastBlock.mightHaveTerminator() ||
1413 !lastBlock.getTerminator()->hasTrait<OpTrait::IsTerminator>())
1414 return emitOpError() <<
"last block of cir.scope must be terminated";
1418LogicalResult cir::ScopeOp::fold(FoldAdaptor ,
1419 SmallVectorImpl<OpFoldResult> &results) {
1424 if (block.getOperations().size() != 1)
1427 auto yield = dyn_cast<cir::YieldOp>(block.front());
1432 if (getNumResults() != 1 || yield.getNumOperands() != 1)
1435 results.push_back(yield.getOperand(0));
1443void cir::CleanupScopeOp::getSuccessorRegions(
1444 mlir::RegionBranchPoint point, SmallVectorImpl<RegionSuccessor> ®ions) {
1445 if (!point.isParent()) {
1446 regions.push_back(RegionSuccessor::parent());
1451 regions.push_back(RegionSuccessor(&getBodyRegion()));
1452 regions.push_back(RegionSuccessor(&getCleanupRegion()));
1456cir::CleanupScopeOp::getSuccessorInputs(RegionSuccessor successor) {
1457 return ValueRange();
1460LogicalResult cir::CleanupScopeOp::canonicalize(CleanupScopeOp op,
1461 PatternRewriter &rewriter) {
1462 auto isRegionTrivial = [](Region ®ion) {
1463 assert(!region.empty() &&
"CleanupScopeOp regions must not be empty");
1464 if (!region.hasOneBlock())
1466 Block &block = llvm::getSingleElement(region);
1467 return llvm::hasSingleElement(block) &&
1468 isa<cir::YieldOp>(llvm::getSingleElement(block));
1471 Region &body = op.getBodyRegion();
1472 Region &
cleanup = op.getCleanupRegion();
1476 if (op.getCleanupKind() == CleanupKind::EH && isRegionTrivial(body)) {
1477 rewriter.eraseOp(op);
1483 if (!isRegionTrivial(
cleanup) || !body.hasOneBlock())
1486 Block &bodyBlock = body.front();
1487 if (!isa<cir::YieldOp>(bodyBlock.getTerminator()))
1490 Operation *yield = bodyBlock.getTerminator();
1491 rewriter.inlineBlockBefore(&bodyBlock, op);
1492 rewriter.eraseOp(yield);
1493 rewriter.eraseOp(op);
1497void cir::CleanupScopeOp::build(
1498 OpBuilder &builder, OperationState &result, CleanupKind cleanupKind,
1499 function_ref<
void(OpBuilder &, Location)> bodyBuilder,
1500 function_ref<
void(OpBuilder &, Location)> cleanupBuilder) {
1501 result.addAttribute(getCleanupKindAttrName(result.name),
1502 CleanupKindAttr::get(builder.getContext(), cleanupKind));
1504 OpBuilder::InsertionGuard guard(builder);
1507 Region *bodyRegion = result.addRegion();
1508 builder.createBlock(bodyRegion);
1510 bodyBuilder(builder, result.location);
1513 Region *cleanupRegion = result.addRegion();
1514 builder.createBlock(cleanupRegion);
1516 cleanupBuilder(builder, result.location);
1531LogicalResult cir::BrOp::canonicalize(BrOp op, PatternRewriter &rewriter) {
1532 Block *src = op->getBlock();
1533 Block *dst = op.getDest();
1540 if (src->getNumSuccessors() != 1 || dst->getSinglePredecessor() != src)
1545 if (isa<cir::LabelOp, cir::IndirectBrOp>(dst->front()))
1548 auto operands = op.getDestOperands();
1549 rewriter.eraseOp(op);
1550 rewriter.mergeBlocks(dst, src, operands);
1554mlir::SuccessorOperands cir::BrOp::getSuccessorOperands(
unsigned index) {
1555 assert(index == 0 &&
"invalid successor index");
1556 return mlir::SuccessorOperands(getDestOperandsMutable());
1567mlir::SuccessorOperands
1568cir::IndirectBrOp::getSuccessorOperands(
unsigned index) {
1569 assert(index < getNumSuccessors() &&
"invalid successor index");
1570 return mlir::SuccessorOperands(getSuccOperandsMutable()[index]);
1574 OpAsmParser &parser, Type &flagType,
1575 SmallVectorImpl<Block *> &succOperandBlocks,
1578 if (failed(parser.parseCommaSeparatedList(
1579 OpAsmParser::Delimiter::Square,
1581 Block *destination = nullptr;
1582 SmallVector<OpAsmParser::UnresolvedOperand> operands;
1583 SmallVector<Type> operandTypes;
1585 if (parser.parseSuccessor(destination).failed())
1588 if (succeeded(parser.parseOptionalLParen())) {
1589 if (failed(parser.parseOperandList(
1590 operands, OpAsmParser::Delimiter::None)) ||
1591 failed(parser.parseColonTypeList(operandTypes)) ||
1592 failed(parser.parseRParen()))
1595 succOperandBlocks.push_back(destination);
1596 succOperands.emplace_back(operands);
1597 succOperandsTypes.emplace_back(operandTypes);
1600 "successor blocks")))
1606 Type flagType, SuccessorRange succs,
1607 OperandRangeRange succOperands,
1608 const TypeRangeRange &succOperandsTypes) {
1611 llvm::zip(succs, succOperands),
1614 p.printSuccessorAndUseList(std::get<0>(i), std::get<1>(i));
1617 if (!succOperands.empty())
1626mlir::SuccessorOperands cir::BrCondOp::getSuccessorOperands(
unsigned index) {
1627 assert(index < getNumSuccessors() &&
"invalid successor index");
1628 return SuccessorOperands(index == 0 ? getDestOperandsTrueMutable()
1629 : getDestOperandsFalseMutable());
1633 if (IntegerAttr condAttr = dyn_cast_if_present<IntegerAttr>(operands.front()))
1634 return condAttr.getValue().isOne() ? getDestTrue() : getDestFalse();
1642void cir::CaseOp::getSuccessorRegions(
1643 mlir::RegionBranchPoint point, SmallVectorImpl<RegionSuccessor> ®ions) {
1644 if (!point.isParent()) {
1645 regions.push_back(RegionSuccessor::parent());
1648 regions.push_back(RegionSuccessor(&getCaseRegion()));
1651mlir::ValueRange cir::CaseOp::getSuccessorInputs(RegionSuccessor successor) {
1652 return successor.isParent() ? ValueRange(getOperation()->getResults())
1656void cir::CaseOp::build(OpBuilder &builder, OperationState &result,
1657 ArrayAttr value, CaseOpKind
kind,
1658 OpBuilder::InsertPoint &insertPoint) {
1659 OpBuilder::InsertionGuard guardSwitch(builder);
1660 result.addAttribute(
"value", value);
1661 result.getOrAddProperties<Properties>().
kind =
1662 cir::CaseOpKindAttr::get(builder.getContext(),
kind);
1663 Region *caseRegion = result.addRegion();
1664 builder.createBlock(caseRegion);
1666 insertPoint = builder.saveInsertionPoint();
1673void cir::SwitchOp::getSuccessorRegions(
1674 mlir::RegionBranchPoint point, SmallVectorImpl<RegionSuccessor> ®ion) {
1675 if (!point.isParent()) {
1676 region.push_back(RegionSuccessor::parent());
1680 region.push_back(RegionSuccessor(&getBody()));
1683mlir::ValueRange cir::SwitchOp::getSuccessorInputs(RegionSuccessor successor) {
1684 return successor.isParent() ? ValueRange(getOperation()->getResults())
1688void cir::SwitchOp::build(OpBuilder &builder, OperationState &result,
1690 assert(switchBuilder &&
"the builder callback for regions must be present");
1691 OpBuilder::InsertionGuard guardSwitch(builder);
1692 Region *switchRegion = result.addRegion();
1693 builder.createBlock(switchRegion);
1694 result.addOperands({cond});
1695 switchBuilder(builder, result.location, result);
1699 walk<mlir::WalkOrder::PreOrder>([&](mlir::Operation *op) {
1701 if (isa<cir::SwitchOp>(op) && op != *
this)
1702 return WalkResult::skip();
1704 if (
auto caseOp = dyn_cast<cir::CaseOp>(op))
1705 cases.push_back(caseOp);
1707 return WalkResult::advance();
1712 collectCases(cases);
1714 if (getBody().empty())
1717 if (!isa<YieldOp>(getBody().front().back()))
1720 if (!llvm::all_of(getBody().front(),
1721 [](Operation &op) {
return isa<CaseOp, YieldOp>(op); }))
1724 return llvm::all_of(cases, [
this](CaseOp op) {
1725 return op->getParentOfType<SwitchOp>() == *
this;
1733void cir::SwitchFlatOp::build(OpBuilder &builder, OperationState &result,
1734 Value value, Block *defaultDestination,
1735 ValueRange defaultOperands,
1737 BlockRange caseDestinations,
1740 std::vector<mlir::Attribute> caseValuesAttrs;
1741 for (
const APInt &val : caseValues)
1742 caseValuesAttrs.push_back(cir::IntAttr::get(value.getType(), val));
1743 mlir::ArrayAttr attrs = ArrayAttr::get(builder.getContext(), caseValuesAttrs);
1745 build(builder, result, value, defaultOperands, caseOperands, attrs,
1746 defaultDestination, caseDestinations);
1752 OpAsmParser &parser, Type flagType, mlir::ArrayAttr &caseValues,
1753 SmallVectorImpl<Block *> &caseDestinations,
1757 if (failed(parser.parseLSquare()))
1759 if (succeeded(parser.parseOptionalRSquare()))
1763 auto parseCase = [&]() {
1765 if (failed(parser.parseInteger(value)))
1768 values.push_back(cir::IntAttr::get(flagType, value));
1773 if (parser.parseColon() || parser.parseSuccessor(destination))
1775 if (!parser.parseOptionalLParen()) {
1776 if (parser.parseOperandList(operands, OpAsmParser::Delimiter::None,
1778 parser.parseColonTypeList(operandTypes) || parser.parseRParen())
1781 caseDestinations.push_back(destination);
1782 caseOperands.emplace_back(operands);
1783 caseOperandTypes.emplace_back(operandTypes);
1786 if (failed(parser.parseCommaSeparatedList(parseCase)))
1789 caseValues = ArrayAttr::get(flagType.getContext(), values);
1791 return parser.parseRSquare();
1795 Type flagType, mlir::ArrayAttr caseValues,
1796 SuccessorRange caseDestinations,
1797 OperandRangeRange caseOperands,
1798 const TypeRangeRange &caseOperandTypes) {
1808 llvm::zip(caseValues, caseDestinations),
1811 mlir::Attribute a = std::get<0>(i);
1812 p << mlir::cast<cir::IntAttr>(a).getValue();
1814 p.printSuccessorAndUseList(std::get<1>(i), caseOperands[index++]);
1829 mlir::Attribute &valueAttr) {
1831 return parser.parseAttribute(valueAttr,
"value", attr);
1835 p.printAttribute(value);
1838mlir::LogicalResult cir::GlobalOp::verify() {
1841 if (getInitialValue().has_value()) {
1853void cir::GlobalOp::build(
1854 OpBuilder &odsBuilder, OperationState &odsState, llvm::StringRef sym_name,
1855 mlir::Type sym_type,
bool isConstant,
1856 mlir::ptr::MemorySpaceAttrInterface addrSpace,
1857 cir::GlobalLinkageKind linkage,
1858 function_ref<
void(OpBuilder &, Location)> ctorBuilder,
1859 function_ref<
void(OpBuilder &, Location)> dtorBuilder) {
1860 odsState.addAttribute(getSymNameAttrName(odsState.name),
1861 odsBuilder.getStringAttr(sym_name));
1862 odsState.addAttribute(getSymTypeAttrName(odsState.name),
1863 mlir::TypeAttr::get(sym_type));
1864 auto &properties = odsState.getOrAddProperties<cir::GlobalOp::Properties>();
1865 properties.setConstant(isConstant);
1869 odsState.addAttribute(getAddrSpaceAttrName(odsState.name), addrSpace);
1871 cir::GlobalLinkageKindAttr linkageAttr =
1872 cir::GlobalLinkageKindAttr::get(odsBuilder.getContext(), linkage);
1873 odsState.addAttribute(getLinkageAttrName(odsState.name), linkageAttr);
1875 Region *ctorRegion = odsState.addRegion();
1877 odsBuilder.createBlock(ctorRegion);
1878 ctorBuilder(odsBuilder, odsState.location);
1881 Region *dtorRegion = odsState.addRegion();
1883 odsBuilder.createBlock(dtorRegion);
1884 dtorBuilder(odsBuilder, odsState.location);
1893void cir::GlobalOp::getSuccessorRegions(
1894 mlir::RegionBranchPoint point, SmallVectorImpl<RegionSuccessor> ®ions) {
1896 if (!point.isParent()) {
1897 regions.push_back(RegionSuccessor::parent());
1902 Region *ctorRegion = &this->getCtorRegion();
1903 if (ctorRegion->empty())
1904 ctorRegion =
nullptr;
1907 Region *dtorRegion = &this->getDtorRegion();
1908 if (dtorRegion->empty())
1909 dtorRegion =
nullptr;
1913 regions.push_back(RegionSuccessor(ctorRegion));
1915 regions.push_back(RegionSuccessor(dtorRegion));
1918mlir::ValueRange cir::GlobalOp::getSuccessorInputs(RegionSuccessor successor) {
1919 return successor.isParent() ? ValueRange(getOperation()->getResults())
1924 TypeAttr type, Attribute initAttr,
1925 mlir::Region &ctorRegion,
1926 mlir::Region &dtorRegion) {
1927 auto printType = [&]() { p <<
": " << type; };
1928 if (!op.isDeclaration()) {
1930 if (!ctorRegion.empty()) {
1934 p.printRegion(ctorRegion,
1943 if (!dtorRegion.empty()) {
1945 p.printRegion(dtorRegion,
1956 Attribute &initialValueAttr,
1957 mlir::Region &ctorRegion,
1958 mlir::Region &dtorRegion) {
1960 if (parser.parseOptionalEqual().failed()) {
1963 if (parser.parseColonType(opTy))
1968 if (!parser.parseOptionalKeyword(
"ctor")) {
1969 if (parser.parseColonType(opTy))
1971 auto parseLoc = parser.getCurrentLocation();
1972 if (parser.parseRegion(ctorRegion, {}, {}))
1983 assert(mlir::isa<mlir::TypedAttr>(initialValueAttr) &&
1984 "Non-typed attrs shouldn't appear here.");
1985 auto typedAttr = mlir::cast<mlir::TypedAttr>(initialValueAttr);
1986 opTy = typedAttr.getType();
1991 if (!parser.parseOptionalKeyword(
"dtor")) {
1992 auto parseLoc = parser.getCurrentLocation();
1993 if (parser.parseRegion(dtorRegion, {}, {}))
2000 typeAttr = TypeAttr::get(opTy);
2009cir::GetGlobalOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
2012 mlir::Operation *op =
2013 symbolTable.lookupNearestSymbolFrom(*
this, getNameAttr());
2014 if (op ==
nullptr || !(isa<GlobalOp>(op) || isa<FuncOp>(op)))
2015 return emitOpError(
"'")
2017 <<
"' does not reference a valid cir.global or cir.func";
2020 mlir::ptr::MemorySpaceAttrInterface symAddrSpaceAttr{};
2021 if (
auto g = dyn_cast<GlobalOp>(op)) {
2022 symTy = g.getSymType();
2023 symAddrSpaceAttr = g.getAddrSpaceAttr();
2026 if (getTls() && !g.getTlsModel())
2027 return emitOpError(
"access to global not marked thread local");
2032 bool getGlobalIsStaticLocal = getStaticLocal();
2033 bool globalIsStaticLocal = g.getStaticLocalGuard().has_value();
2034 if (getGlobalIsStaticLocal != globalIsStaticLocal &&
2035 !getOperation()->getParentOfType<cir::GlobalOp>())
2036 return emitOpError(
"static_local attribute mismatch");
2037 }
else if (
auto f = dyn_cast<FuncOp>(op)) {
2038 symTy = f.getFunctionType();
2040 llvm_unreachable(
"Unexpected operation for GetGlobalOp");
2043 auto resultType = dyn_cast<PointerType>(getAddr().
getType());
2044 if (!resultType || symTy != resultType.getPointee())
2045 return emitOpError(
"result type pointee type '")
2046 << resultType.getPointee() <<
"' does not match type " << symTy
2047 <<
" of the global @" <<
getName();
2049 if (symAddrSpaceAttr != resultType.getAddrSpace()) {
2050 return emitOpError()
2051 <<
"result type address space does not match the address "
2052 "space of the global @"
2064cir::VTableAddrPointOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
2070 symbolTable.lookupNearestSymbolFrom<cir::GlobalOp>(*
this, getNameAttr());
2072 return emitOpError(
"'")
2073 <<
name <<
"' does not reference a valid cir.global";
2074 std::optional<mlir::Attribute> init = op.getInitialValue();
2077 if (!isa<cir::VTableAttr>(*init))
2078 return emitOpError(
"Expected #cir.vtable in initializer for global '")
2088cir::VTTAddrPointOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
2097 symbolTable.lookupNearestSymbolFrom<cir::GlobalOp>(*
this, getNameAttr());
2099 return emitOpError(
"'")
2100 <<
name <<
"' does not reference a valid cir.global";
2101 std::optional<mlir::Attribute> init = op.getInitialValue();
2104 if (!isa<cir::ConstArrayAttr>(*init))
2106 "Expected constant array in initializer for global VTT '")
2111LogicalResult cir::VTTAddrPointOp::verify() {
2113 if (
getName() && getSymAddr())
2114 return emitOpError(
"should use either a symbol or value, but not both");
2120 mlir::Type resultType = getAddr().getType();
2121 mlir::Type resTy = cir::PointerType::get(
2122 cir::PointerType::get(cir::VoidType::get(getContext())));
2124 if (resultType != resTy)
2125 return emitOpError(
"result type must be ")
2126 << resTy <<
", but provided result type is " << resultType;
2138void cir::FuncOp::build(OpBuilder &builder, OperationState &result,
2139 StringRef name, FuncType type,
2140 GlobalLinkageKind linkage) {
2142 result.addAttribute(SymbolTable::getSymbolAttrName(),
2143 builder.getStringAttr(name));
2144 result.addAttribute(getFunctionTypeAttrName(result.name),
2145 TypeAttr::get(type));
2146 result.addAttribute(
2148 GlobalLinkageKindAttr::get(builder.getContext(), linkage));
2151ParseResult cir::FuncOp::parse(OpAsmParser &parser, OperationState &state) {
2152 llvm::SMLoc loc = parser.getCurrentLocation();
2153 mlir::Builder &builder = parser.getBuilder();
2155 mlir::StringAttr builtinNameAttr = getBuiltinAttrName(state.name);
2156 mlir::StringAttr coroutineNameAttr = getCoroutineAttrName(state.name);
2157 mlir::StringAttr inlineKindNameAttr = getInlineKindAttrName(state.name);
2158 mlir::StringAttr lambdaNameAttr = getLambdaAttrName(state.name);
2159 mlir::StringAttr noProtoNameAttr = getNoProtoAttrName(state.name);
2160 mlir::StringAttr comdatNameAttr = getComdatAttrName(state.name);
2161 mlir::StringAttr visNameAttr = getSymVisibilityAttrName(state.name);
2162 mlir::StringAttr dsoLocalNameAttr = getDsoLocalAttrName(state.name);
2163 mlir::StringAttr specialMemberAttr = getCxxSpecialMemberAttrName(state.name);
2165 if (::mlir::succeeded(parser.parseOptionalKeyword(builtinNameAttr.strref())))
2166 state.addAttribute(builtinNameAttr, parser.getBuilder().getUnitAttr());
2167 if (::mlir::succeeded(
2168 parser.parseOptionalKeyword(coroutineNameAttr.strref())))
2169 state.addAttribute(coroutineNameAttr, parser.getBuilder().getUnitAttr());
2172 cir::InlineKindAttr inlineKindAttr;
2176 state.addAttribute(inlineKindNameAttr, inlineKindAttr);
2178 if (::mlir::succeeded(parser.parseOptionalKeyword(lambdaNameAttr.strref())))
2179 state.addAttribute(lambdaNameAttr, parser.getBuilder().getUnitAttr());
2180 if (parser.parseOptionalKeyword(noProtoNameAttr).succeeded())
2181 state.addAttribute(noProtoNameAttr, parser.getBuilder().getUnitAttr());
2183 if (parser.parseOptionalKeyword(comdatNameAttr).succeeded())
2184 state.addAttribute(comdatNameAttr, parser.getBuilder().getUnitAttr());
2188 GlobalLinkageKindAttr::get(
2189 parser.getContext(),
2191 parser, GlobalLinkageKind::ExternalLinkage)));
2193 ::llvm::StringRef visAttrStr;
2194 if (parser.parseOptionalKeyword(&visAttrStr, {
"private",
"public",
"nested"})
2196 state.addAttribute(visNameAttr,
2197 parser.getBuilder().getStringAttr(visAttrStr));
2200 state.getOrAddProperties<cir::FuncOp::Properties>().global_visibility =
2203 if (parser.parseOptionalKeyword(dsoLocalNameAttr).succeeded())
2204 state.addAttribute(dsoLocalNameAttr, parser.getBuilder().getUnitAttr());
2206 StringAttr nameAttr;
2207 if (parser.parseSymbolName(nameAttr, SymbolTable::getSymbolAttrName(),
2213 bool isVariadic =
false;
2214 if (function_interface_impl::parseFunctionSignatureWithArguments(
2215 parser,
true, arguments, isVariadic, resultTypes,
2220 bool argAttrsEmpty =
true;
2221 for (OpAsmParser::Argument &arg : arguments) {
2222 argTypes.push_back(
arg.type);
2226 argAttrs.push_back(
arg.attrs);
2228 argAttrsEmpty =
false;
2232 if (resultTypes.size() > 1 || resultAttrs.size() > 1)
2233 return parser.emitError(
2234 loc,
"functions with multiple return types are not supported");
2236 mlir::Type returnType =
2237 (resultTypes.empty() ? cir::VoidType::get(builder.getContext())
2238 : resultTypes.front());
2240 cir::FuncType fnType = cir::FuncType::get(argTypes, returnType, isVariadic);
2244 state.addAttribute(getFunctionTypeAttrName(state.name),
2245 TypeAttr::get(fnType));
2247 if (!resultAttrs.empty() && resultAttrs[0])
2249 getResAttrsAttrName(state.name),
2250 mlir::ArrayAttr::get(parser.getContext(), {resultAttrs[0]}));
2253 state.addAttribute(getArgAttrsAttrName(state.name),
2254 mlir::ArrayAttr::get(parser.getContext(), argAttrs));
2256 bool hasAlias =
false;
2257 mlir::StringAttr aliaseeNameAttr = getAliaseeAttrName(state.name);
2258 if (parser.parseOptionalKeyword(
"alias").succeeded()) {
2259 if (parser.parseLParen().failed())
2261 mlir::StringAttr aliaseeAttr;
2262 if (parser.parseOptionalSymbolName(aliaseeAttr).failed())
2264 state.addAttribute(aliaseeNameAttr, FlatSymbolRefAttr::get(aliaseeAttr));
2265 if (parser.parseRParen().failed())
2270 mlir::StringAttr personalityNameAttr = getPersonalityAttrName(state.name);
2271 if (parser.parseOptionalKeyword(
"personality").succeeded()) {
2272 if (parser.parseLParen().failed())
2274 mlir::StringAttr personalityAttr;
2275 if (parser.parseOptionalSymbolName(personalityAttr).failed())
2277 state.addAttribute(personalityNameAttr,
2278 FlatSymbolRefAttr::get(personalityAttr));
2279 if (parser.parseRParen().failed())
2283 auto parseGlobalDtorCtor =
2284 [&](StringRef keyword,
2285 llvm::function_ref<void(std::optional<int> prio)> createAttr)
2286 -> mlir::LogicalResult {
2287 if (mlir::succeeded(parser.parseOptionalKeyword(keyword))) {
2288 std::optional<int> priority;
2289 if (mlir::succeeded(parser.parseOptionalLParen())) {
2290 auto parsedPriority = mlir::FieldParser<int>::parse(parser);
2291 if (mlir::failed(parsedPriority))
2292 return parser.emitError(parser.getCurrentLocation(),
2293 "failed to parse 'priority', of type 'int'");
2294 priority = parsedPriority.value_or(
int());
2296 if (parser.parseRParen())
2299 createAttr(priority);
2305 if (parser.parseOptionalKeyword(
"special_member").succeeded()) {
2306 if (parser.parseLess().failed())
2309 mlir::Attribute
attr;
2310 if (parser.parseAttribute(attr).failed())
2312 if (!mlir::isa<cir::CXXCtorAttr, cir::CXXDtorAttr, cir::CXXAssignAttr>(
2314 return parser.emitError(parser.getCurrentLocation(),
2315 "expected a C++ special member attribute");
2316 state.addAttribute(specialMemberAttr, attr);
2318 if (parser.parseGreater().failed())
2322 if (parseGlobalDtorCtor(
"global_ctor", [&](std::optional<int> priority) {
2323 mlir::IntegerAttr globalCtorPriorityAttr =
2324 builder.getI32IntegerAttr(priority.value_or(65535));
2325 state.addAttribute(getGlobalCtorPriorityAttrName(state.name),
2326 globalCtorPriorityAttr);
2330 if (parseGlobalDtorCtor(
"global_dtor", [&](std::optional<int> priority) {
2331 mlir::IntegerAttr globalDtorPriorityAttr =
2332 builder.getI32IntegerAttr(priority.value_or(65535));
2333 state.addAttribute(getGlobalDtorPriorityAttrName(state.name),
2334 globalDtorPriorityAttr);
2338 if (parser.parseOptionalKeyword(
"side_effect").succeeded()) {
2339 cir::SideEffect sideEffect;
2341 if (parser.parseLParen().failed() ||
2343 parser.parseRParen().failed())
2346 auto attr = cir::SideEffectAttr::get(parser.getContext(), sideEffect);
2347 state.addAttribute(CIRDialect::getSideEffectAttrName(), attr);
2351 NamedAttrList parsedAttrs;
2352 if (parser.parseOptionalAttrDictWithKeyword(parsedAttrs))
2355 for (StringRef disallowed : cir::FuncOp::getAttributeNames()) {
2356 if (parsedAttrs.get(disallowed))
2357 return parser.emitError(loc,
"attribute '")
2359 <<
"' should not be specified in the explicit attribute list";
2362 state.attributes.append(parsedAttrs);
2365 auto *body = state.addRegion();
2366 OptionalParseResult parseResult = parser.parseOptionalRegion(
2367 *body, arguments,
false);
2368 if (parseResult.has_value()) {
2370 return parser.emitError(loc,
"function alias shall not have a body");
2371 if (failed(*parseResult))
2375 return parser.emitError(loc,
"expected non-empty function body");
2384bool cir::FuncOp::isDeclaration() {
2387 std::optional<StringRef> aliasee = getAliasee();
2389 return getFunctionBody().empty();
2395bool cir::FuncOp::isCXXSpecialMemberFunction() {
2396 return getCxxSpecialMemberAttr() !=
nullptr;
2399bool cir::FuncOp::isCxxConstructor() {
2400 auto attr = getCxxSpecialMemberAttr();
2401 return attr && dyn_cast<CXXCtorAttr>(attr);
2404bool cir::FuncOp::isCxxDestructor() {
2405 auto attr = getCxxSpecialMemberAttr();
2406 return attr && dyn_cast<CXXDtorAttr>(attr);
2409bool cir::FuncOp::isCxxSpecialAssignment() {
2410 auto attr = getCxxSpecialMemberAttr();
2411 return attr && dyn_cast<CXXAssignAttr>(attr);
2414std::optional<CtorKind> cir::FuncOp::getCxxConstructorKind() {
2415 mlir::Attribute
attr = getCxxSpecialMemberAttr();
2417 if (
auto ctor = dyn_cast<CXXCtorAttr>(attr))
2418 return ctor.getCtorKind();
2420 return std::nullopt;
2423std::optional<AssignKind> cir::FuncOp::getCxxSpecialAssignKind() {
2424 mlir::Attribute
attr = getCxxSpecialMemberAttr();
2426 if (
auto assign = dyn_cast<CXXAssignAttr>(attr))
2427 return assign.getAssignKind();
2429 return std::nullopt;
2432bool cir::FuncOp::isCxxTrivialMemberFunction() {
2433 mlir::Attribute
attr = getCxxSpecialMemberAttr();
2435 if (
auto ctor = dyn_cast<CXXCtorAttr>(attr))
2436 return ctor.getIsTrivial();
2437 if (
auto dtor = dyn_cast<CXXDtorAttr>(attr))
2438 return dtor.getIsTrivial();
2439 if (
auto assign = dyn_cast<CXXAssignAttr>(attr))
2440 return assign.getIsTrivial();
2445mlir::Region *cir::FuncOp::getCallableRegion() {
2451void cir::FuncOp::print(OpAsmPrinter &p) {
2469 if (getLinkage() != GlobalLinkageKind::ExternalLinkage)
2470 p <<
' ' << stringifyGlobalLinkageKind(getLinkage());
2472 mlir::SymbolTable::Visibility vis = getVisibility();
2473 if (vis != mlir::SymbolTable::Visibility::Public)
2476 if (getGlobalVisibility() != cir::VisibilityKind::Default)
2477 p <<
' ' << stringifyVisibilityKind(getGlobalVisibility());
2483 p.printSymbolName(getSymName());
2484 cir::FuncType fnType = getFunctionType();
2485 function_interface_impl::printFunctionSignature(
2486 p, *
this, fnType.getInputs(), fnType.isVarArg(), fnType.getReturnTypes());
2488 if (std::optional<StringRef> aliaseeName = getAliasee()) {
2490 p.printSymbolName(*aliaseeName);
2494 if (std::optional<StringRef> personalityName = getPersonality()) {
2495 p <<
" personality(";
2496 p.printSymbolName(*personalityName);
2500 if (
auto specialMemberAttr = getCxxSpecialMember()) {
2501 p <<
" special_member<";
2502 p.printAttribute(*specialMemberAttr);
2506 if (
auto globalCtorPriority = getGlobalCtorPriority()) {
2507 p <<
" global_ctor";
2508 if (globalCtorPriority.value() != 65535)
2509 p <<
"(" << globalCtorPriority.value() <<
")";
2512 if (
auto globalDtorPriority = getGlobalDtorPriority()) {
2513 p <<
" global_dtor";
2514 if (globalDtorPriority.value() != 65535)
2515 p <<
"(" << globalDtorPriority.value() <<
")";
2518 if (std::optional<cir::SideEffect> sideEffect = getSideEffect();
2519 sideEffect && *sideEffect != cir::SideEffect::All) {
2520 p <<
" side_effect(";
2521 p << stringifySideEffect(*sideEffect);
2525 function_interface_impl::printFunctionAttributes(
2526 p, *
this, cir::FuncOp::getAttributeNames());
2529 Region &body = getOperation()->getRegion(0);
2530 if (!body.empty()) {
2532 p.printRegion(body,
false,
2537mlir::LogicalResult cir::FuncOp::verify() {
2539 if (!isDeclaration() && getCoroutine()) {
2540 bool foundAwait =
false;
2541 this->walk([&](Operation *op) {
2542 if (
auto await = dyn_cast<AwaitOp>(op)) {
2548 return emitOpError()
2549 <<
"coroutine body must use at least one cir.await op";
2552 llvm::SmallSet<llvm::StringRef, 16> labels;
2553 llvm::SmallSet<llvm::StringRef, 16> gotos;
2554 llvm::SmallSet<llvm::StringRef, 16> blockAddresses;
2555 bool invalidBlockAddress =
false;
2556 getOperation()->walk([&](mlir::Operation *op) {
2557 if (
auto lab = dyn_cast<cir::LabelOp>(op)) {
2558 labels.insert(lab.getLabel());
2559 }
else if (
auto goTo = dyn_cast<cir::GotoOp>(op)) {
2560 gotos.insert(goTo.getLabel());
2561 }
else if (
auto blkAdd = dyn_cast<cir::BlockAddressOp>(op)) {
2562 if (blkAdd.getBlockAddrInfoAttr().getFunc().getAttr() != getSymName()) {
2564 invalidBlockAddress =
true;
2565 return mlir::WalkResult::interrupt();
2567 blockAddresses.insert(blkAdd.getBlockAddrInfoAttr().getLabel());
2569 return mlir::WalkResult::advance();
2572 if (invalidBlockAddress)
2573 return emitOpError() <<
"blockaddress references a different function";
2575 llvm::SmallSet<llvm::StringRef, 16> mismatched;
2576 if (!labels.empty() || !gotos.empty()) {
2577 mismatched = llvm::set_difference(gotos, labels);
2579 if (!mismatched.empty())
2580 return emitOpError() <<
"goto/label mismatch";
2585 if (!labels.empty() || !blockAddresses.empty()) {
2586 mismatched = llvm::set_difference(blockAddresses, labels);
2588 if (!mismatched.empty())
2589 return emitOpError()
2590 <<
"expects an existing label target in the referenced function";
2602 bool noUnsignedWrap,
bool saturated,
2604 bool noWrap = noSignedWrap || noUnsignedWrap;
2605 if (!isa<cir::IntType>(op->getResultTypes()[0]) && noWrap)
2606 return op->emitError()
2607 <<
"only operations on integer values may have nsw/nuw flags";
2608 if (hasSat && saturated && !isa<cir::IntType>(op->getResultTypes()[0]))
2609 return op->emitError()
2610 <<
"only operations on integer values may have sat flag";
2611 if (hasSat && noWrap && saturated)
2612 return op->emitError()
2613 <<
"the nsw/nuw flags and the saturated flag are mutually exclusive";
2614 return mlir::success();
2617LogicalResult cir::AddOp::verify() {
2619 getNoUnsignedWrap(), getSaturated(),
2623LogicalResult cir::SubOp::verify() {
2625 getNoUnsignedWrap(), getSaturated(),
2629LogicalResult cir::MulOp::verify() {
2631 getNoUnsignedWrap(),
false,
2644void cir::TernaryOp::getSuccessorRegions(
2645 mlir::RegionBranchPoint point, SmallVectorImpl<RegionSuccessor> ®ions) {
2647 if (!point.isParent()) {
2648 regions.push_back(RegionSuccessor::parent());
2654 regions.push_back(RegionSuccessor(&getTrueRegion()));
2655 regions.push_back(RegionSuccessor(&getFalseRegion()));
2658mlir::ValueRange cir::TernaryOp::getSuccessorInputs(RegionSuccessor successor) {
2659 return successor.isParent() ? ValueRange(getOperation()->getResults())
2663void cir::TernaryOp::build(
2664 OpBuilder &builder, OperationState &result,
Value cond,
2665 function_ref<
void(OpBuilder &, Location)> trueBuilder,
2666 function_ref<
void(OpBuilder &, Location)> falseBuilder) {
2667 result.addOperands(cond);
2668 OpBuilder::InsertionGuard guard(builder);
2669 Region *trueRegion = result.addRegion();
2670 builder.createBlock(trueRegion);
2671 trueBuilder(builder, result.location);
2672 Region *falseRegion = result.addRegion();
2673 builder.createBlock(falseRegion);
2674 falseBuilder(builder, result.location);
2679 if (trueRegion->back().mightHaveTerminator())
2680 yield = dyn_cast_or_null<cir::YieldOp>(trueRegion->back().getTerminator());
2681 if (!yield && falseRegion->back().mightHaveTerminator())
2682 yield = dyn_cast_or_null<cir::YieldOp>(falseRegion->back().getTerminator());
2684 assert((!yield || yield.getNumOperands() <= 1) &&
2685 "expected zero or one result type");
2686 if (yield && yield.getNumOperands() == 1)
2687 result.addTypes(TypeRange{yield.getOperandTypes().front()});
2694OpFoldResult cir::SelectOp::fold(FoldAdaptor adaptor) {
2695 mlir::Attribute
condition = adaptor.getCondition();
2697 bool conditionValue = mlir::cast<cir::BoolAttr>(
condition).getValue();
2698 return conditionValue ? getTrueValue() : getFalseValue();
2702 mlir::Attribute trueValue = adaptor.getTrueValue();
2703 mlir::Attribute falseValue = adaptor.getFalseValue();
2704 if (trueValue == falseValue)
2706 if (getTrueValue() == getFalseValue())
2707 return getTrueValue();
2712LogicalResult cir::SelectOp::verify() {
2714 auto condTy = dyn_cast<cir::VectorType>(getCondition().
getType());
2721 if (!isa<cir::VectorType>(getTrueValue().
getType()) ||
2722 !isa<cir::VectorType>(getFalseValue().
getType())) {
2723 return emitOpError()
2724 <<
"expected both true and false operands to be vector types "
2725 "when the condition is a vector boolean type";
2734LogicalResult cir::ShiftOp::verify() {
2735 mlir::Operation *op = getOperation();
2736 auto op0VecTy = mlir::dyn_cast<cir::VectorType>(op->getOperand(0).getType());
2737 auto op1VecTy = mlir::dyn_cast<cir::VectorType>(op->getOperand(1).getType());
2738 if (!op0VecTy ^ !op1VecTy)
2739 return emitOpError() <<
"input types cannot be one vector and one scalar";
2742 if (op0VecTy.getSize() != op1VecTy.getSize())
2743 return emitOpError() <<
"input vector types must have the same size";
2745 auto opResultTy = mlir::dyn_cast<cir::VectorType>(
getType());
2747 return emitOpError() <<
"the type of the result must be a vector "
2748 <<
"if it is vector shift";
2750 auto op0VecEleTy = mlir::cast<cir::IntType>(op0VecTy.getElementType());
2751 auto op1VecEleTy = mlir::cast<cir::IntType>(op1VecTy.getElementType());
2752 if (op0VecEleTy.getWidth() != op1VecEleTy.getWidth())
2753 return emitOpError()
2754 <<
"vector operands do not have the same elements sizes";
2756 auto resVecEleTy = mlir::cast<cir::IntType>(opResultTy.getElementType());
2757 if (op0VecEleTy.getWidth() != resVecEleTy.getWidth())
2758 return emitOpError() <<
"vector operands and result type do not have the "
2759 "same elements sizes";
2762 return mlir::success();
2769LogicalResult cir::LabelOp::verify() {
2770 mlir::Operation *op = getOperation();
2771 mlir::Block *blk = op->getBlock();
2772 if (&blk->front() != op)
2773 return emitError() <<
"must be the first operation in a block";
2775 return mlir::success();
2782OpFoldResult cir::IncOp::fold(FoldAdaptor adaptor) {
2783 if (mlir::isa_and_present<cir::PoisonAttr>(adaptor.getInput()))
2784 return adaptor.getInput();
2792OpFoldResult cir::DecOp::fold(FoldAdaptor adaptor) {
2793 if (mlir::isa_and_present<cir::PoisonAttr>(adaptor.getInput()))
2794 return adaptor.getInput();
2802OpFoldResult cir::MinusOp::fold(FoldAdaptor adaptor) {
2803 if (mlir::isa_and_present<cir::PoisonAttr>(adaptor.getInput()))
2804 return adaptor.getInput();
2807 if (
auto srcConst = getInput().getDefiningOp<cir::ConstantOp>())
2808 if (mlir::isa<cir::BoolType>(srcConst.getType()))
2809 return srcConst.getResult();
2812 if (mlir::Attribute attr = adaptor.getInput()) {
2813 if (
auto intAttr = mlir::dyn_cast<cir::IntAttr>(attr)) {
2814 APInt val = intAttr.getValue();
2816 return cir::IntAttr::get(
getType(), val);
2818 if (
auto fpAttr = mlir::dyn_cast<cir::FPAttr>(attr)) {
2819 APFloat val = fpAttr.getValue();
2821 return cir::FPAttr::get(
getType(), val);
2832OpFoldResult cir::NotOp::fold(FoldAdaptor adaptor) {
2833 if (mlir::isa_and_present<cir::PoisonAttr>(adaptor.getInput()))
2834 return adaptor.getInput();
2839 if (mlir::Attribute attr = adaptor.getInput()) {
2840 if (
auto intAttr = mlir::dyn_cast<cir::IntAttr>(attr)) {
2841 APInt val = intAttr.getValue();
2843 return cir::IntAttr::get(
getType(), val);
2845 if (
auto boolAttr = mlir::dyn_cast<cir::BoolAttr>(attr))
2846 return cir::BoolAttr::get(getContext(), !boolAttr.getValue());
2857 mlir::Type resultTy) {
2860 mlir::Type inputMemberTy;
2861 mlir::Type resultMemberTy;
2862 if (mlir::isa<cir::DataMemberType>(src.getType())) {
2864 mlir::cast<cir::DataMemberType>(src.getType()).getMemberTy();
2865 resultMemberTy = mlir::cast<cir::DataMemberType>(resultTy).getMemberTy();
2868 if (inputMemberTy != resultMemberTy)
2869 return op->emitOpError()
2870 <<
"member types of the operand and the result do not match";
2872 return mlir::success();
2875LogicalResult cir::BaseDataMemberOp::verify() {
2879LogicalResult cir::DerivedDataMemberOp::verify() {
2887LogicalResult cir::BaseMethodOp::verify() {
2891LogicalResult cir::DerivedMethodOp::verify() {
2899void cir::AwaitOp::build(OpBuilder &builder, OperationState &result,
2903 result.addAttribute(getKindAttrName(result.name),
2904 cir::AwaitKindAttr::get(builder.getContext(),
kind));
2906 OpBuilder::InsertionGuard guard(builder);
2907 Region *readyRegion = result.addRegion();
2908 builder.createBlock(readyRegion);
2909 readyBuilder(builder, result.location);
2913 OpBuilder::InsertionGuard guard(builder);
2914 Region *suspendRegion = result.addRegion();
2915 builder.createBlock(suspendRegion);
2916 suspendBuilder(builder, result.location);
2920 OpBuilder::InsertionGuard guard(builder);
2921 Region *resumeRegion = result.addRegion();
2922 builder.createBlock(resumeRegion);
2923 resumeBuilder(builder, result.location);
2927void cir::AwaitOp::getSuccessorRegions(
2928 mlir::RegionBranchPoint point, SmallVectorImpl<RegionSuccessor> ®ions) {
2931 if (!point.isParent()) {
2932 regions.push_back(RegionSuccessor::parent());
2939 regions.push_back(RegionSuccessor(&this->getReady()));
2940 regions.push_back(RegionSuccessor(&this->getSuspend()));
2941 regions.push_back(RegionSuccessor(&this->getResume()));
2944mlir::ValueRange cir::AwaitOp::getSuccessorInputs(RegionSuccessor successor) {
2945 if (successor.isParent())
2946 return getOperation()->getResults();
2947 if (successor == &getReady())
2948 return getReady().getArguments();
2949 if (successor == &getSuspend())
2950 return getSuspend().getArguments();
2951 if (successor == &getResume())
2952 return getResume().getArguments();
2953 llvm_unreachable(
"invalid region successor");
2956LogicalResult cir::AwaitOp::verify() {
2957 if (!isa<ConditionOp>(this->getReady().back().getTerminator()))
2958 return emitOpError(
"ready region must end with cir.condition");
2966LogicalResult cir::CopyOp::verify() {
2968 if (!
getType().getPointee().hasTrait<DataLayoutTypeInterface::Trait>())
2969 return emitError() <<
"missing data layout for pointee type";
2971 if (getSrc() == getDst())
2972 return emitError() <<
"source and destination are the same";
2974 if (getSkipTailPadding() &&
2975 !mlir::isa<cir::RecordType>(
getType().getPointee()))
2977 <<
"skip_tail_padding is only valid for record pointee types";
2979 return mlir::success();
2986LogicalResult cir::GetRuntimeMemberOp::verify() {
2987 auto recordTy = mlir::cast<RecordType>(getAddr().
getType().getPointee());
2988 cir::DataMemberType memberPtrTy = getMember().getType();
2990 if (recordTy != memberPtrTy.getClassTy())
2991 return emitError() <<
"record type does not match the member pointer type";
2992 if (
getType().getPointee() != memberPtrTy.getMemberTy())
2993 return emitError() <<
"result type does not match the member pointer type";
2994 return mlir::success();
3001LogicalResult cir::GetMethodOp::verify() {
3002 cir::MethodType methodTy = getMethod().getType();
3005 cir::PointerType objectPtrTy = getObject().getType();
3006 mlir::Type objectTy = objectPtrTy.getPointee();
3008 if (methodTy.getClassTy() != objectTy)
3009 return emitError() <<
"method class type and object type do not match";
3012 auto calleeTy = mlir::cast<cir::FuncType>(getCallee().
getType().getPointee());
3013 cir::FuncType methodFuncTy = methodTy.getMemberFuncTy();
3020 if (methodFuncTy.getReturnType() != calleeTy.getReturnType())
3022 <<
"method return type and callee return type do not match";
3027 if (calleeArgsTy.empty())
3028 return emitError() <<
"callee parameter list lacks receiver object ptr";
3030 auto calleeThisArgPtrTy = mlir::dyn_cast<cir::PointerType>(calleeArgsTy[0]);
3031 if (!calleeThisArgPtrTy ||
3032 !mlir::isa<cir::VoidType>(calleeThisArgPtrTy.getPointee())) {
3034 <<
"the first parameter of callee must be a void pointer";
3037 if (calleeArgsTy.slice(1) != methodFuncArgsTy)
3039 <<
"callee parameters and method parameters do not match";
3041 return mlir::success();
3048LogicalResult cir::GetMemberOp::verify() {
3049 const auto recordTy = dyn_cast<RecordType>(getAddrTy().getPointee());
3051 return emitError() <<
"expected pointer to a record type";
3053 if (recordTy.getMembers().size() <=
getIndex())
3054 return emitError() <<
"member index out of bounds";
3057 return emitError() <<
"member type mismatch";
3059 return mlir::success();
3066LogicalResult cir::ExtractMemberOp::verify() {
3067 auto recordTy = mlir::cast<cir::RecordType>(getRecord().
getType());
3068 if (recordTy.getKind() == cir::RecordType::Union)
3070 <<
"cir.extract_member currently does not support unions";
3071 if (recordTy.getMembers().size() <=
getIndex())
3072 return emitError() <<
"member index out of bounds";
3074 return emitError() <<
"member type mismatch";
3075 return mlir::success();
3082LogicalResult cir::InsertMemberOp::verify() {
3083 auto recordTy = mlir::cast<cir::RecordType>(getRecord().
getType());
3084 if (recordTy.getKind() == cir::RecordType::Union)
3085 return emitError() <<
"cir.insert_member currently does not support unions";
3086 if (recordTy.getMembers().size() <=
getIndex())
3087 return emitError() <<
"member index out of bounds";
3089 return emitError() <<
"member type mismatch";
3091 return mlir::success();
3098OpFoldResult cir::VecCreateOp::fold(FoldAdaptor adaptor) {
3099 if (llvm::any_of(getElements(), [](mlir::Value value) {
3100 return !value.getDefiningOp<cir::ConstantOp>();
3104 return cir::ConstVectorAttr::get(
3105 getType(), mlir::ArrayAttr::get(getContext(), adaptor.getElements()));
3108LogicalResult cir::VecCreateOp::verify() {
3112 const cir::VectorType vecTy =
getType();
3113 if (getElements().size() != vecTy.getSize()) {
3114 return emitOpError() <<
"operand count of " << getElements().size()
3115 <<
" doesn't match vector type " << vecTy
3116 <<
" element count of " << vecTy.getSize();
3119 const mlir::Type elementType = vecTy.getElementType();
3120 for (
const mlir::Value element : getElements()) {
3121 if (element.getType() != elementType) {
3122 return emitOpError() <<
"operand type " << element.getType()
3123 <<
" doesn't match vector element type "
3135OpFoldResult cir::VecExtractOp::fold(FoldAdaptor adaptor) {
3136 const auto vectorAttr =
3137 llvm::dyn_cast_if_present<cir::ConstVectorAttr>(adaptor.getVec());
3141 const auto indexAttr =
3142 llvm::dyn_cast_if_present<cir::IntAttr>(adaptor.getIndex());
3146 const mlir::ArrayAttr elements = vectorAttr.getElts();
3147 const uint64_t index = indexAttr.getUInt();
3148 if (index >= elements.size())
3151 return elements[index];
3158OpFoldResult cir::VecCmpOp::fold(FoldAdaptor adaptor) {
3160 mlir::dyn_cast_if_present<cir::ConstVectorAttr>(adaptor.getLhs());
3162 mlir::dyn_cast_if_present<cir::ConstVectorAttr>(adaptor.getRhs());
3163 if (!lhsVecAttr || !rhsVecAttr)
3166 mlir::Type inputElemTy =
3167 mlir::cast<cir::VectorType>(lhsVecAttr.getType()).getElementType();
3168 if (!isAnyIntegerOrFloatingPointType(inputElemTy))
3171 cir::CmpOpKind opKind = adaptor.getKind();
3172 mlir::ArrayAttr lhsVecElhs = lhsVecAttr.getElts();
3173 mlir::ArrayAttr rhsVecElhs = rhsVecAttr.getElts();
3174 uint64_t vecSize = lhsVecElhs.size();
3177 bool isIntAttr = vecSize && mlir::isa<cir::IntAttr>(lhsVecElhs[0]);
3178 for (uint64_t i = 0; i < vecSize; i++) {
3179 mlir::Attribute lhsAttr = lhsVecElhs[i];
3180 mlir::Attribute rhsAttr = rhsVecElhs[i];
3183 case cir::CmpOpKind::lt: {
3185 cmpResult = mlir::cast<cir::IntAttr>(lhsAttr).getSInt() <
3186 mlir::cast<cir::IntAttr>(rhsAttr).getSInt();
3188 cmpResult = mlir::cast<cir::FPAttr>(lhsAttr).getValue() <
3189 mlir::cast<cir::FPAttr>(rhsAttr).getValue();
3193 case cir::CmpOpKind::le: {
3195 cmpResult = mlir::cast<cir::IntAttr>(lhsAttr).getSInt() <=
3196 mlir::cast<cir::IntAttr>(rhsAttr).getSInt();
3198 cmpResult = mlir::cast<cir::FPAttr>(lhsAttr).getValue() <=
3199 mlir::cast<cir::FPAttr>(rhsAttr).getValue();
3203 case cir::CmpOpKind::gt: {
3205 cmpResult = mlir::cast<cir::IntAttr>(lhsAttr).getSInt() >
3206 mlir::cast<cir::IntAttr>(rhsAttr).getSInt();
3208 cmpResult = mlir::cast<cir::FPAttr>(lhsAttr).getValue() >
3209 mlir::cast<cir::FPAttr>(rhsAttr).getValue();
3213 case cir::CmpOpKind::ge: {
3215 cmpResult = mlir::cast<cir::IntAttr>(lhsAttr).getSInt() >=
3216 mlir::cast<cir::IntAttr>(rhsAttr).getSInt();
3218 cmpResult = mlir::cast<cir::FPAttr>(lhsAttr).getValue() >=
3219 mlir::cast<cir::FPAttr>(rhsAttr).getValue();
3223 case cir::CmpOpKind::eq: {
3225 cmpResult = mlir::cast<cir::IntAttr>(lhsAttr).getSInt() ==
3226 mlir::cast<cir::IntAttr>(rhsAttr).getSInt();
3228 cmpResult = mlir::cast<cir::FPAttr>(lhsAttr).getValue() ==
3229 mlir::cast<cir::FPAttr>(rhsAttr).getValue();
3233 case cir::CmpOpKind::ne: {
3235 cmpResult = mlir::cast<cir::IntAttr>(lhsAttr).getSInt() !=
3236 mlir::cast<cir::IntAttr>(rhsAttr).getSInt();
3238 cmpResult = mlir::cast<cir::FPAttr>(lhsAttr).getValue() !=
3239 mlir::cast<cir::FPAttr>(rhsAttr).getValue();
3245 elements[i] = cir::IntAttr::get(
getType().getElementType(), cmpResult);
3248 return cir::ConstVectorAttr::get(
3249 getType(), mlir::ArrayAttr::get(getContext(), elements));
3256OpFoldResult cir::VecShuffleOp::fold(FoldAdaptor adaptor) {
3258 mlir::dyn_cast_if_present<cir::ConstVectorAttr>(adaptor.getVec1());
3260 mlir::dyn_cast_if_present<cir::ConstVectorAttr>(adaptor.getVec2());
3261 if (!vec1Attr || !vec2Attr)
3264 mlir::Type vec1ElemTy =
3265 mlir::cast<cir::VectorType>(vec1Attr.getType()).getElementType();
3267 mlir::ArrayAttr vec1Elts = vec1Attr.getElts();
3268 mlir::ArrayAttr vec2Elts = vec2Attr.getElts();
3269 mlir::ArrayAttr indicesElts = adaptor.getIndices();
3272 elements.reserve(indicesElts.size());
3274 uint64_t vec1Size = vec1Elts.size();
3275 for (
const auto &idxAttr : indicesElts.getAsRange<cir::IntAttr>()) {
3276 if (idxAttr.getSInt() == -1) {
3277 elements.push_back(cir::UndefAttr::get(vec1ElemTy));
3281 uint64_t idxValue = idxAttr.getUInt();
3282 elements.push_back(idxValue < vec1Size ? vec1Elts[idxValue]
3283 : vec2Elts[idxValue - vec1Size]);
3286 return cir::ConstVectorAttr::get(
3287 getType(), mlir::ArrayAttr::get(getContext(), elements));
3290LogicalResult cir::VecShuffleOp::verify() {
3293 if (getIndices().size() != getResult().
getType().getSize()) {
3294 return emitOpError() <<
": the number of elements in " << getIndices()
3295 <<
" and " << getResult().getType() <<
" don't match";
3300 if (getVec1().
getType().getElementType() !=
3301 getResult().
getType().getElementType()) {
3302 return emitOpError() <<
": element types of " << getVec1().getType()
3303 <<
" and " << getResult().getType() <<
" don't match";
3306 const uint64_t maxValidIndex =
3307 getVec1().getType().getSize() + getVec2().getType().getSize() - 1;
3309 getIndices().getAsRange<cir::IntAttr>(), [&](cir::IntAttr idxAttr) {
3310 return idxAttr.getSInt() != -1 && idxAttr.getUInt() > maxValidIndex;
3312 return emitOpError() <<
": index for __builtin_shufflevector must be "
3313 "less than the total number of vector elements";
3322OpFoldResult cir::VecShuffleDynamicOp::fold(FoldAdaptor adaptor) {
3323 mlir::Attribute vec = adaptor.getVec();
3324 mlir::Attribute indices = adaptor.getIndices();
3325 if (mlir::isa_and_nonnull<cir::ConstVectorAttr>(vec) &&
3326 mlir::isa_and_nonnull<cir::ConstVectorAttr>(indices)) {
3327 auto vecAttr = mlir::cast<cir::ConstVectorAttr>(vec);
3328 auto indicesAttr = mlir::cast<cir::ConstVectorAttr>(indices);
3330 mlir::ArrayAttr vecElts = vecAttr.getElts();
3331 mlir::ArrayAttr indicesElts = indicesAttr.getElts();
3333 const uint64_t numElements = vecElts.size();
3336 elements.reserve(numElements);
3338 const uint64_t maskBits = llvm::NextPowerOf2(numElements - 1) - 1;
3339 for (
const auto &idxAttr : indicesElts.getAsRange<cir::IntAttr>()) {
3340 uint64_t idxValue = idxAttr.getUInt();
3341 uint64_t newIdx = idxValue & maskBits;
3342 elements.push_back(vecElts[newIdx]);
3345 return cir::ConstVectorAttr::get(
3346 getType(), mlir::ArrayAttr::get(getContext(), elements));
3352LogicalResult cir::VecShuffleDynamicOp::verify() {
3354 if (getVec().
getType().getSize() !=
3355 mlir::cast<cir::VectorType>(getIndices().
getType()).getSize()) {
3356 return emitOpError() <<
": the number of elements in " << getVec().getType()
3357 <<
" and " << getIndices().getType() <<
" don't match";
3366LogicalResult cir::VecTernaryOp::verify() {
3371 if (getCond().
getType().getSize() != getLhs().
getType().getSize()) {
3372 return emitOpError() <<
": the number of elements in "
3373 << getCond().getType() <<
" and " << getLhs().getType()
3379OpFoldResult cir::VecTernaryOp::fold(FoldAdaptor adaptor) {
3380 mlir::Attribute cond = adaptor.getCond();
3381 mlir::Attribute lhs = adaptor.getLhs();
3382 mlir::Attribute rhs = adaptor.getRhs();
3384 if (!mlir::isa_and_nonnull<cir::ConstVectorAttr>(cond) ||
3385 !mlir::isa_and_nonnull<cir::ConstVectorAttr>(lhs) ||
3386 !mlir::isa_and_nonnull<cir::ConstVectorAttr>(rhs))
3388 auto condVec = mlir::cast<cir::ConstVectorAttr>(cond);
3389 auto lhsVec = mlir::cast<cir::ConstVectorAttr>(lhs);
3390 auto rhsVec = mlir::cast<cir::ConstVectorAttr>(rhs);
3392 mlir::ArrayAttr condElts = condVec.getElts();
3395 elements.reserve(condElts.size());
3397 for (
const auto &[idx, condAttr] :
3398 llvm::enumerate(condElts.getAsRange<cir::IntAttr>())) {
3399 if (condAttr.getSInt()) {
3400 elements.push_back(lhsVec.getElts()[idx]);
3402 elements.push_back(rhsVec.getElts()[idx]);
3406 cir::VectorType vecTy = getLhs().getType();
3407 return cir::ConstVectorAttr::get(
3408 vecTy, mlir::ArrayAttr::get(getContext(), elements));
3415LogicalResult cir::ComplexCreateOp::verify() {
3418 <<
"operand type of cir.complex.create does not match its result type";
3425OpFoldResult cir::ComplexCreateOp::fold(FoldAdaptor adaptor) {
3426 mlir::Attribute real = adaptor.getReal();
3427 mlir::Attribute imag = adaptor.getImag();
3433 auto realAttr = mlir::cast<mlir::TypedAttr>(real);
3434 auto imagAttr = mlir::cast<mlir::TypedAttr>(imag);
3435 return cir::ConstComplexAttr::get(realAttr, imagAttr);
3442LogicalResult cir::ComplexRealOp::verify() {
3443 mlir::Type operandTy = getOperand().getType();
3444 if (
auto complexOperandTy = mlir::dyn_cast<cir::ComplexType>(operandTy))
3445 operandTy = complexOperandTy.getElementType();
3448 emitOpError() <<
": result type does not match operand type";
3455OpFoldResult cir::ComplexRealOp::fold(FoldAdaptor adaptor) {
3456 if (!mlir::isa<cir::ComplexType>(getOperand().
getType()))
3459 if (
auto complexCreateOp = getOperand().getDefiningOp<cir::ComplexCreateOp>())
3460 return complexCreateOp.getOperand(0);
3463 mlir::cast_if_present<cir::ConstComplexAttr>(adaptor.getOperand());
3464 return complex ? complex.getReal() :
nullptr;
3471LogicalResult cir::ComplexImagOp::verify() {
3472 mlir::Type operandTy = getOperand().getType();
3473 if (
auto complexOperandTy = mlir::dyn_cast<cir::ComplexType>(operandTy))
3474 operandTy = complexOperandTy.getElementType();
3477 emitOpError() <<
": result type does not match operand type";
3484OpFoldResult cir::ComplexImagOp::fold(FoldAdaptor adaptor) {
3485 if (!mlir::isa<cir::ComplexType>(getOperand().
getType()))
3488 if (
auto complexCreateOp = getOperand().getDefiningOp<cir::ComplexCreateOp>())
3489 return complexCreateOp.getOperand(1);
3492 mlir::cast_if_present<cir::ConstComplexAttr>(adaptor.getOperand());
3493 return complex ? complex.getImag() :
nullptr;
3500LogicalResult cir::ComplexRealPtrOp::verify() {
3501 mlir::Type resultPointeeTy =
getType().getPointee();
3502 cir::PointerType operandPtrTy = getOperand().getType();
3503 auto operandPointeeTy =
3504 mlir::cast<cir::ComplexType>(operandPtrTy.getPointee());
3506 if (resultPointeeTy != operandPointeeTy.getElementType()) {
3507 return emitOpError() <<
": result type does not match operand type";
3517LogicalResult cir::ComplexImagPtrOp::verify() {
3518 mlir::Type resultPointeeTy =
getType().getPointee();
3519 cir::PointerType operandPtrTy = getOperand().getType();
3520 auto operandPointeeTy =
3521 mlir::cast<cir::ComplexType>(operandPtrTy.getPointee());
3523 if (resultPointeeTy != operandPointeeTy.getElementType()) {
3524 return emitOpError()
3525 <<
"cir.complex.imag_ptr result type does not match operand type";
3536 llvm::function_ref<llvm::APInt(
const llvm::APInt &)> func,
3537 bool poisonZero =
false) {
3538 if (mlir::isa_and_present<cir::PoisonAttr>(inputAttr)) {
3543 auto input = mlir::dyn_cast_if_present<IntAttr>(inputAttr);
3547 llvm::APInt inputValue = input.getValue();
3548 if (poisonZero && inputValue.isZero())
3549 return cir::PoisonAttr::get(input.getType());
3551 llvm::APInt resultValue = func(inputValue);
3552 return IntAttr::get(input.getType(), resultValue);
3555OpFoldResult BitClrsbOp::fold(FoldAdaptor adaptor) {
3556 return foldUnaryBitOp(adaptor.getInput(), [](
const llvm::APInt &inputValue) {
3557 unsigned resultValue =
3558 inputValue.getBitWidth() - inputValue.getSignificantBits();
3559 return llvm::APInt(inputValue.getBitWidth(), resultValue);
3563OpFoldResult BitClzOp::fold(FoldAdaptor adaptor) {
3566 [](
const llvm::APInt &inputValue) {
3567 unsigned resultValue = inputValue.countLeadingZeros();
3568 return llvm::APInt(inputValue.getBitWidth(), resultValue);
3573OpFoldResult BitCtzOp::fold(FoldAdaptor adaptor) {
3576 [](
const llvm::APInt &inputValue) {
3577 return llvm::APInt(inputValue.getBitWidth(),
3578 inputValue.countTrailingZeros());
3583OpFoldResult BitFfsOp::fold(FoldAdaptor adaptor) {
3584 return foldUnaryBitOp(adaptor.getInput(), [](
const llvm::APInt &inputValue) {
3585 unsigned trailingZeros = inputValue.countTrailingZeros();
3587 trailingZeros == inputValue.getBitWidth() ? 0 : trailingZeros + 1;
3588 return llvm::APInt(inputValue.getBitWidth(), result);
3592OpFoldResult BitParityOp::fold(FoldAdaptor adaptor) {
3593 return foldUnaryBitOp(adaptor.getInput(), [](
const llvm::APInt &inputValue) {
3594 return llvm::APInt(inputValue.getBitWidth(), inputValue.popcount() % 2);
3598OpFoldResult BitPopcountOp::fold(FoldAdaptor adaptor) {
3599 return foldUnaryBitOp(adaptor.getInput(), [](
const llvm::APInt &inputValue) {
3600 return llvm::APInt(inputValue.getBitWidth(), inputValue.popcount());
3604OpFoldResult BitReverseOp::fold(FoldAdaptor adaptor) {
3605 return foldUnaryBitOp(adaptor.getInput(), [](
const llvm::APInt &inputValue) {
3606 return inputValue.reverseBits();
3610OpFoldResult ByteSwapOp::fold(FoldAdaptor adaptor) {
3611 return foldUnaryBitOp(adaptor.getInput(), [](
const llvm::APInt &inputValue) {
3612 return inputValue.byteSwap();
3616OpFoldResult RotateOp::fold(FoldAdaptor adaptor) {
3617 if (mlir::isa_and_present<cir::PoisonAttr>(adaptor.getInput()) ||
3618 mlir::isa_and_present<cir::PoisonAttr>(adaptor.getAmount())) {
3620 return cir::PoisonAttr::get(
getType());
3623 auto input = mlir::dyn_cast_if_present<IntAttr>(adaptor.getInput());
3624 auto amount = mlir::dyn_cast_if_present<IntAttr>(adaptor.getAmount());
3625 if (!input && !amount)
3634 llvm::APInt inputValue;
3636 inputValue = input.getValue();
3637 if (inputValue.isZero() || inputValue.isAllOnes()) {
3643 uint64_t amountValue;
3645 amountValue = amount.getValue().urem(getInput().
getType().getWidth());
3646 if (amountValue == 0) {
3652 if (!input || !amount)
3655 assert(inputValue.getBitWidth() == getInput().
getType().getWidth() &&
3656 "input value must have the same bit width as the input type");
3658 llvm::APInt resultValue;
3660 resultValue = inputValue.rotl(amountValue);
3662 resultValue = inputValue.rotr(amountValue);
3664 return IntAttr::get(input.getContext(), input.getType(), resultValue);
3671void cir::InlineAsmOp::print(OpAsmPrinter &p) {
3672 p <<
'(' << getAsmFlavor() <<
", ";
3677 auto *nameIt = names.begin();
3678 auto *attrIt = getOperandAttrs().begin();
3680 for (mlir::OperandRange ops : getAsmOperands()) {
3681 p << *nameIt <<
" = ";
3684 llvm::interleaveComma(llvm::make_range(ops.begin(), ops.end()), p,
3686 p.printOperand(value);
3687 p <<
" : " << value.getType();
3688 if (mlir::isa<mlir::UnitAttr>(*attrIt))
3689 p <<
" (maybe_memory)";
3698 p.printString(getAsmString());
3700 p.printString(getConstraints());
3704 if (getSideEffects())
3705 p <<
" side_effects";
3707 std::array elidedAttrs{
3708 llvm::StringRef(
"asm_flavor"), llvm::StringRef(
"asm_string"),
3709 llvm::StringRef(
"constraints"), llvm::StringRef(
"operand_attrs"),
3710 llvm::StringRef(
"operands_segments"), llvm::StringRef(
"side_effects")};
3711 p.printOptionalAttrDict(getOperation()->getAttrs(), elidedAttrs);
3713 if (
auto v = getRes())
3714 p <<
" -> " << v.getType();
3717void cir::InlineAsmOp::build(OpBuilder &odsBuilder, OperationState &odsState,
3719 StringRef asmString, StringRef constraints,
3720 bool sideEffects, cir::AsmFlavor asmFlavor,
3724 for (
auto operandRange : asmOperands) {
3725 segments.push_back(operandRange.size());
3726 odsState.addOperands(operandRange);
3729 odsState.addAttribute(
3730 "operands_segments",
3731 DenseI32ArrayAttr::get(odsBuilder.getContext(), segments));
3732 odsState.addAttribute(
"asm_string", odsBuilder.getStringAttr(asmString));
3733 odsState.addAttribute(
"constraints", odsBuilder.getStringAttr(constraints));
3734 odsState.addAttribute(
"asm_flavor",
3735 AsmFlavorAttr::get(odsBuilder.getContext(), asmFlavor));
3738 odsState.addAttribute(
"side_effects", odsBuilder.getUnitAttr());
3740 odsState.addAttribute(
"operand_attrs", odsBuilder.getArrayAttr(operandAttrs));
3743ParseResult cir::InlineAsmOp::parse(OpAsmParser &parser,
3744 OperationState &result) {
3747 std::string asmString, constraints;
3749 MLIRContext *ctxt = parser.getBuilder().getContext();
3751 auto error = [&](
const Twine &msg) -> LogicalResult {
3752 return parser.emitError(parser.getCurrentLocation(), msg);
3755 auto expected = [&](
const std::string &
c) {
3756 return error(
"expected '" +
c +
"'");
3759 if (parser.parseLParen().failed())
3760 return expected(
"(");
3762 auto flavor = FieldParser<AsmFlavor, AsmFlavor>::parse(parser);
3764 return error(
"Unknown AsmFlavor");
3766 if (parser.parseComma().failed())
3767 return expected(
",");
3769 auto parseValue = [&](
Value &v) {
3770 OpAsmParser::UnresolvedOperand op;
3772 if (parser.parseOperand(op) || parser.parseColon())
3773 return error(
"can't parse operand");
3776 if (parser.parseType(typ).failed())
3777 return error(
"can't parse operand type");
3779 if (parser.resolveOperand(op, typ, tmp))
3780 return error(
"can't resolve operand");
3782 return mlir::success();
3785 auto parseOperands = [&](llvm::StringRef
name) {
3786 if (parser.parseKeyword(name).failed())
3787 return error(
"expected " + name +
" operands here");
3788 if (parser.parseEqual().failed())
3789 return expected(
"=");
3790 if (parser.parseLSquare().failed())
3791 return expected(
"[");
3794 if (parser.parseOptionalRSquare().succeeded()) {
3795 operandsGroupSizes.push_back(size);
3796 if (parser.parseComma())
3797 return expected(
",");
3798 return mlir::success();
3801 auto parseOperand = [&]() {
3803 if (parseValue(val).succeeded()) {
3804 result.operands.push_back(val);
3807 if (parser.parseOptionalLParen().failed()) {
3808 operandAttrs.push_back(mlir::DictionaryAttr::get(ctxt));
3809 return mlir::success();
3812 if (parser.parseKeyword(
"maybe_memory").succeeded()) {
3813 operandAttrs.push_back(mlir::UnitAttr::get(ctxt));
3814 if (parser.parseRParen())
3815 return expected(
")");
3816 return mlir::success();
3818 return expected(
"maybe_memory");
3821 return mlir::failure();
3824 if (parser.parseCommaSeparatedList(parseOperand).failed())
3825 return mlir::failure();
3827 if (parser.parseRSquare().failed() || parser.parseComma().failed())
3828 return expected(
"]");
3829 operandsGroupSizes.push_back(size);
3830 return mlir::success();
3833 if (parseOperands(
"out").failed() || parseOperands(
"in").failed() ||
3834 parseOperands(
"in_out").failed())
3835 return error(
"failed to parse operands");
3837 if (parser.parseLBrace())
3838 return expected(
"{");
3839 if (parser.parseString(&asmString))
3840 return error(
"asm string parsing failed");
3841 if (parser.parseString(&constraints))
3842 return error(
"constraints string parsing failed");
3843 if (parser.parseRBrace())
3844 return expected(
"}");
3845 if (parser.parseRParen())
3846 return expected(
")");
3848 if (parser.parseOptionalKeyword(
"side_effects").succeeded())
3849 result.attributes.set(
"side_effects", UnitAttr::get(ctxt));
3851 if (parser.parseOptionalAttrDict(result.attributes).failed())
3852 return mlir::failure();
3854 if (parser.parseOptionalArrow().succeeded() &&
3855 parser.parseType(resType).failed())
3856 return mlir::failure();
3858 result.attributes.set(
"asm_flavor", AsmFlavorAttr::get(ctxt, *flavor));
3859 result.attributes.set(
"asm_string", StringAttr::get(ctxt, asmString));
3860 result.attributes.set(
"constraints", StringAttr::get(ctxt, constraints));
3861 result.attributes.set(
"operand_attrs", ArrayAttr::get(ctxt, operandAttrs));
3862 result.getOrAddProperties<InlineAsmOp::Properties>().operands_segments =
3863 parser.getBuilder().getDenseI32ArrayAttr(operandsGroupSizes);
3865 result.addTypes(TypeRange{resType});
3867 return mlir::success();
3874mlir::LogicalResult cir::ThrowOp::verify() {
3879 if (getNumOperands() != 0) {
3882 return emitOpError() <<
"'type_info' symbol attribute missing";
3892LogicalResult cir::AtomicFetchOp::verify() {
3893 if (getBinop() != cir::AtomicFetchKind::Add &&
3894 getBinop() != cir::AtomicFetchKind::Sub &&
3895 getBinop() != cir::AtomicFetchKind::Max &&
3896 getBinop() != cir::AtomicFetchKind::Min &&
3897 !mlir::isa<cir::IntType>(getVal().
getType()))
3898 return emitError(
"only atomic add, sub, max, and min operation could "
3899 "operate on floating-point values");
3907LogicalResult cir::TypeInfoAttr::verify(
3908 ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError,
3909 ::mlir::Type type, ::mlir::ArrayAttr typeInfoData) {
3911 if (cir::ConstRecordAttr::verify(emitError, type, typeInfoData).failed())
3921void cir::TryOp::getSuccessorRegions(
3922 mlir::RegionBranchPoint point,
3925 if (!point.isParent()) {
3926 regions.push_back(RegionSuccessor::parent());
3930 regions.push_back(mlir::RegionSuccessor(&getTryRegion()));
3934 for (mlir::Region &handlerRegion : this->getHandlerRegions())
3935 regions.push_back(mlir::RegionSuccessor(&handlerRegion));
3938mlir::ValueRange cir::TryOp::getSuccessorInputs(RegionSuccessor successor) {
3939 return successor.isParent() ? ValueRange(getOperation()->getResults())
3943LogicalResult cir::TryOp::verify() {
3944 mlir::ArrayAttr handlerTypes = getHandlerTypes();
3945 if (!handlerTypes) {
3946 if (!getHandlerRegions().empty())
3948 "handler regions must be empty when no handler types are present");
3952 mlir::MutableArrayRef<mlir::Region> handlerRegions = getHandlerRegions();
3956 if (handlerRegions.size() != handlerTypes.size())
3958 "number of handler regions and handler types must match");
3960 for (
const auto &[typeAttr, handlerRegion] :
3961 llvm::zip(handlerTypes, handlerRegions)) {
3963 mlir::Block &entryBlock = handlerRegion.front();
3964 if (entryBlock.getNumArguments() != 1 ||
3965 !mlir::isa<cir::EhTokenType>(entryBlock.getArgument(0).getType()))
3967 "handler region must have a single '!cir.eh_token' argument");
3970 if (mlir::isa<cir::UnwindAttr>(typeAttr))
3973 if (entryBlock.empty() || !mlir::isa<cir::BeginCatchOp>(entryBlock.front()))
3975 "catch handler region must start with 'cir.begin_catch'");
3983 mlir::MutableArrayRef<mlir::Region> handlerRegions,
3984 mlir::ArrayAttr handlerTypes) {
3988 for (
const auto [typeIdx, typeAttr] : llvm::enumerate(handlerTypes)) {
3992 if (mlir::isa<cir::CatchAllAttr>(typeAttr)) {
3993 printer <<
"catch all ";
3994 }
else if (mlir::isa<cir::UnwindAttr>(typeAttr)) {
3995 printer <<
"unwind ";
3997 printer <<
"catch [type ";
3998 printer.printAttribute(typeAttr);
4003 mlir::Region ®ion = handlerRegions[typeIdx];
4004 if (!region.empty() && region.front().getNumArguments() > 0) {
4006 printer.printRegionArgument(region.front().getArgument(0));
4010 printer.printRegion(region,
4017 mlir::OpAsmParser &parser,
4019 mlir::ArrayAttr &handlerTypes) {
4021 auto parseCheckedCatcherRegion = [&]() -> mlir::ParseResult {
4022 handlerRegions.emplace_back(
new mlir::Region);
4024 mlir::Region &currRegion = *handlerRegions.back();
4028 if (parser.parseLParen())
4030 mlir::OpAsmParser::Argument arg;
4031 if (parser.parseArgument(arg,
true))
4033 regionArgs.push_back(arg);
4034 if (parser.parseRParen())
4037 mlir::SMLoc regionLoc = parser.getCurrentLocation();
4038 if (parser.parseRegion(currRegion, regionArgs)) {
4039 handlerRegions.clear();
4043 if (currRegion.empty())
4044 return parser.emitError(regionLoc,
"handler region shall not be empty");
4046 if (!(currRegion.back().mightHaveTerminator() &&
4047 currRegion.back().getTerminator()))
4048 return parser.emitError(
4049 regionLoc,
"blocks are expected to be explicitly terminated");
4054 bool hasCatchAll =
false;
4056 while (parser.parseOptionalKeyword(
"catch").succeeded()) {
4057 bool hasLSquare = parser.parseOptionalLSquare().succeeded();
4059 llvm::StringRef attrStr;
4060 if (parser.parseOptionalKeyword(&attrStr, {
"all",
"type"}).failed())
4061 return parser.emitError(parser.getCurrentLocation(),
4062 "expected 'all' or 'type' keyword");
4064 bool isCatchAll = attrStr ==
"all";
4067 return parser.emitError(parser.getCurrentLocation(),
4068 "can't have more than one catch all");
4072 mlir::Attribute exceptionRTTIAttr;
4073 if (!isCatchAll && parser.parseAttribute(exceptionRTTIAttr).failed())
4074 return parser.emitError(parser.getCurrentLocation(),
4075 "expected valid RTTI info attribute");
4077 catcherAttrs.push_back(isCatchAll
4078 ? cir::CatchAllAttr::get(parser.getContext())
4079 : exceptionRTTIAttr);
4081 if (hasLSquare && isCatchAll)
4082 return parser.emitError(parser.getCurrentLocation(),
4083 "catch all dosen't need RTTI info attribute");
4085 if (hasLSquare && parser.parseRSquare().failed())
4086 return parser.emitError(parser.getCurrentLocation(),
4087 "expected `]` after RTTI info attribute");
4089 if (parseCheckedCatcherRegion().failed())
4090 return mlir::failure();
4093 if (parser.parseOptionalKeyword(
"unwind").succeeded()) {
4095 return parser.emitError(parser.getCurrentLocation(),
4096 "unwind can't be used with catch all");
4098 catcherAttrs.push_back(cir::UnwindAttr::get(parser.getContext()));
4099 if (parseCheckedCatcherRegion().failed())
4100 return mlir::failure();
4103 handlerTypes = parser.getBuilder().getArrayAttr(catcherAttrs);
4104 return mlir::success();
4112cir::EhTypeIdOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
4113 Operation *op = symbolTable.lookupNearestSymbolFrom(*
this, getTypeSymAttr());
4114 if (!isa_and_nonnull<GlobalOp>(op))
4115 return emitOpError(
"'")
4116 << getTypeSym() <<
"' does not reference a valid cir.global";
4126 SmallVectorImpl<Block *> &catchDestinations,
4127 Block *&defaultDestination,
4128 mlir::UnitAttr &defaultIsCatchAll) {
4130 if (parser.parseLSquare())
4134 bool hasCatchAll =
false;
4135 bool hasUnwind =
false;
4138 auto parseHandler = [&]() -> ParseResult {
4140 if (succeeded(parser.parseOptionalKeyword(
"catch_all"))) {
4142 return parser.emitError(parser.getCurrentLocation(),
4143 "duplicate 'catch_all' handler");
4145 return parser.emitError(parser.getCurrentLocation(),
4146 "cannot have both 'catch_all' and 'unwind'");
4149 if (parser.parseColon().failed())
4152 if (parser.parseSuccessor(defaultDestination).failed())
4158 if (succeeded(parser.parseOptionalKeyword(
"unwind"))) {
4160 return parser.emitError(parser.getCurrentLocation(),
4161 "duplicate 'unwind' handler");
4163 return parser.emitError(parser.getCurrentLocation(),
4164 "cannot have both 'catch_all' and 'unwind'");
4167 if (parser.parseColon().failed())
4170 if (parser.parseSuccessor(defaultDestination).failed())
4178 if (parser.parseKeyword(
"catch").failed())
4181 if (parser.parseLParen().failed())
4184 mlir::Attribute catchTypeAttr;
4185 if (parser.parseAttribute(catchTypeAttr).failed())
4187 handlerTypes.push_back(catchTypeAttr);
4189 if (parser.parseRParen().failed())
4192 if (parser.parseColon().failed())
4196 if (parser.parseSuccessor(dest).failed())
4198 catchDestinations.push_back(dest);
4202 if (parser.parseCommaSeparatedList(parseHandler).failed())
4205 if (parser.parseRSquare().failed())
4209 if (!hasCatchAll && !hasUnwind)
4210 return parser.emitError(parser.getCurrentLocation(),
4211 "must have either 'catch_all' or 'unwind' handler");
4214 if (!handlerTypes.empty())
4215 catchTypes = parser.getBuilder().getArrayAttr(handlerTypes);
4218 defaultIsCatchAll = parser.getBuilder().getUnitAttr();
4224 mlir::ArrayAttr catchTypes,
4225 SuccessorRange catchDestinations,
4226 Block *defaultDestination,
4227 mlir::UnitAttr defaultIsCatchAll) {
4235 llvm::zip(catchTypes, catchDestinations),
4238 p.printAttribute(std::get<0>(i));
4240 p.printSuccessor(std::get<1>(i));
4252 if (defaultIsCatchAll)
4253 p <<
" catch_all : ";
4256 p.printSuccessor(defaultDestination);
4266#define GET_OP_CLASSES
4267#include "clang/CIR/Dialect/IR/CIROps.cpp.inc"
static const MemRegion * getRegion(const CallEvent &Call, const MutexDescriptor &Descriptor, bool IsLock)
static void printEhDispatchDestinations(OpAsmPrinter &p, cir::EhDispatchOp op, mlir::ArrayAttr catchTypes, SuccessorRange catchDestinations, Block *defaultDestination, mlir::UnitAttr defaultIsCatchAll)
static mlir::LogicalResult checkReturnAndFunction(cir::ReturnOp op, cir::FuncOp function)
static LogicalResult verifyMemberPtrCast(Operation *op, mlir::Value src, mlir::Type resultTy)
static mlir::ParseResult parseCallCommon(mlir::OpAsmParser &parser, mlir::OperationState &result, bool hasDestinationBlocks=false)
static bool isIntOrBoolCast(cir::CastOp op)
static ParseResult parseEhDispatchDestinations(OpAsmParser &parser, mlir::ArrayAttr &catchTypes, SmallVectorImpl< Block * > &catchDestinations, Block *&defaultDestination, mlir::UnitAttr &defaultIsCatchAll)
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)
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 )* )?
void printGlobalAddressSpaceValue(mlir::AsmPrinter &printer, cir::GlobalOp op, mlir::ptr::MemorySpaceAttrInterface attr)
static void printCallCommon(mlir::Operation *op, mlir::FlatSymbolRefAttr calleeSym, mlir::Value indirectCallee, mlir::OpAsmPrinter &printer, bool isNothrow, cir::SideEffect sideEffect, ArrayAttr argAttrs, ArrayAttr resAttrs, mlir::Block *normalDest=nullptr, mlir::Block *unwindDest=nullptr)
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.
mlir::OptionalParseResult parseGlobalAddressSpaceValue(mlir::AsmParser &p, mlir::ptr::MemorySpaceAttrInterface &attr)
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)
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 LogicalResult verifyBinaryOverflowOp(mlir::Operation *op, bool noSignedWrap, bool noUnsignedWrap, bool saturated, bool hasSat)
static void printOmittedTerminatorRegion(mlir::OpAsmPrinter &printer, cir::ScopeOp &op, mlir::Region ®ion)
static ParseResult parseConstantValue(OpAsmParser &parser, mlir::Attribute &valueAttr)
static LogicalResult verifyArrayCtorDtor(Op op)
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)
*collection of selector each with an associated kind and an ordered *collection of selectors A selector has a an optional score condition
*collection of selector each with an associated kind and an ordered *collection of selectors A selector has a kind
__device__ __2f16 float c
void buildTerminatedBody(mlir::OpBuilder &builder, mlir::Location loc)
mlir::ptr::MemorySpaceAttrInterface normalizeDefaultAddressSpace(mlir::ptr::MemorySpaceAttrInterface addrSpace)
Normalize LangAddressSpace::Default to null (empty attribute).
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 memberFuncPtrCast()
static bool opCallCallConv()
static bool opScopeCleanupRegion()
static bool supportIFuncAttr()