19#include "mlir/IR/Attributes.h"
20#include "mlir/IR/DialectImplementation.h"
21#include "mlir/Interfaces/ControlFlowInterfaces.h"
22#include "mlir/Interfaces/FunctionImplementation.h"
23#include "mlir/Support/LLVM.h"
25#include "clang/CIR/Dialect/IR/CIROpsDialect.cpp.inc"
26#include "clang/CIR/Dialect/IR/CIROpsEnums.cpp.inc"
28#include "llvm/ADT/SetOperations.h"
29#include "llvm/ADT/SmallSet.h"
30#include "llvm/Support/LogicalResult.h"
39struct CIROpAsmDialectInterface :
public OpAsmDialectInterface {
40 using OpAsmDialectInterface::OpAsmDialectInterface;
42 AliasResult getAlias(Type type, raw_ostream &os)
const final {
43 if (
auto recordType = dyn_cast<cir::RecordType>(type)) {
46 os <<
"rec_anon_" <<
recordType.getKindAsStr();
48 os <<
"rec_" << nameAttr.getValue();
49 return AliasResult::OverridableAlias;
51 if (
auto intType = dyn_cast<cir::IntType>(type)) {
54 unsigned width = intType.getWidth();
55 if (width < 8 || !llvm::isPowerOf2_32(width))
56 return AliasResult::NoAlias;
57 os << intType.getAlias();
58 return AliasResult::OverridableAlias;
60 if (
auto voidType = dyn_cast<cir::VoidType>(type)) {
61 os << voidType.getAlias();
62 return AliasResult::OverridableAlias;
65 return AliasResult::NoAlias;
68 AliasResult getAlias(Attribute attr, raw_ostream &os)
const final {
69 if (
auto boolAttr = mlir::dyn_cast<cir::BoolAttr>(attr)) {
70 os << (boolAttr.getValue() ?
"true" :
"false");
71 return AliasResult::FinalAlias;
73 if (
auto bitfield = mlir::dyn_cast<cir::BitfieldInfoAttr>(attr)) {
74 os <<
"bfi_" << bitfield.getName().str();
75 return AliasResult::FinalAlias;
77 if (
auto dynCastInfoAttr = mlir::dyn_cast<cir::DynamicCastInfoAttr>(attr)) {
78 os << dynCastInfoAttr.getAlias();
79 return AliasResult::FinalAlias;
81 return AliasResult::NoAlias;
86void cir::CIRDialect::initialize() {
91#include "clang/CIR/Dialect/IR/CIROps.cpp.inc"
93 addInterfaces<CIROpAsmDialectInterface>();
96Operation *cir::CIRDialect::materializeConstant(mlir::OpBuilder &builder,
97 mlir::Attribute value,
100 return cir::ConstantOp::create(builder, loc, type,
101 mlir::cast<mlir::TypedAttr>(value));
113 for (
auto en : llvm::enumerate(keywords)) {
114 if (succeeded(parser.parseOptionalKeyword(en.value())))
121template <
typename Ty>
struct EnumTraits {};
123#define REGISTER_ENUM_TYPE(Ty) \
124 template <> struct EnumTraits<cir::Ty> { \
125 static llvm::StringRef stringify(cir::Ty value) { \
126 return stringify##Ty(value); \
128 static unsigned getMaxEnumVal() { return cir::getMaxEnumValFor##Ty(); } \
139template <
typename EnumTy,
typename RetTy = EnumTy>
142 for (
unsigned i = 0, e = EnumTraits<EnumTy>::getMaxEnumVal(); i <= e; ++i)
143 names.push_back(EnumTraits<EnumTy>::stringify(
static_cast<EnumTy
>(i)));
147 return static_cast<RetTy
>(defaultValue);
148 return static_cast<RetTy
>(index);
152template <
typename EnumTy,
typename RetTy = EnumTy>
155 for (
unsigned i = 0, e = EnumTraits<EnumTy>::getMaxEnumVal(); i <= e; ++i)
156 names.push_back(EnumTraits<EnumTy>::stringify(
static_cast<EnumTy
>(i)));
161 result =
static_cast<RetTy
>(index);
169 Location eLoc = parser.getEncodedSourceLoc(parser.getCurrentLocation());
170 OpBuilder builder(parser.getBuilder().getContext());
175 builder.createBlock(®ion);
177 Block &block = region.back();
179 if (!block.empty() && block.back().hasTrait<OpTrait::IsTerminator>())
183 if (!region.hasOneBlock())
184 return parser.emitError(errLoc,
185 "multi-block region must not omit terminator");
188 builder.setInsertionPointToEnd(&block);
189 cir::YieldOp::create(builder, eLoc);
195 const auto singleNonEmptyBlock = r.hasOneBlock() && !r.back().empty();
196 const auto yieldsNothing = [&r]() {
197 auto y = dyn_cast<cir::YieldOp>(r.back().getTerminator());
198 return y && y.getArgs().empty();
200 return singleNonEmptyBlock && yieldsNothing();
204 cir::VisibilityAttr &visibility) {
205 switch (visibility.getValue()) {
206 case cir::VisibilityKind::Hidden:
209 case cir::VisibilityKind::Protected:
210 printer <<
"protected";
212 case cir::VisibilityKind::Default:
218 cir::VisibilityKind visibilityKind =
220 visibility = cir::VisibilityAttr::get(parser.getContext(), visibilityKind);
228 mlir::Region ®ion) {
229 auto regionLoc = parser.getCurrentLocation();
230 if (parser.parseRegion(region))
239 mlir::Region ®ion) {
240 printer.printRegion(region,
249void cir::AllocaOp::build(mlir::OpBuilder &odsBuilder,
250 mlir::OperationState &odsState, mlir::Type addr,
251 mlir::Type allocaType, llvm::StringRef name,
252 mlir::IntegerAttr alignment) {
253 odsState.addAttribute(getAllocaTypeAttrName(odsState.name),
254 mlir::TypeAttr::get(allocaType));
255 odsState.addAttribute(getNameAttrName(odsState.name),
256 odsBuilder.getStringAttr(name));
258 odsState.addAttribute(getAlignmentAttrName(odsState.name), alignment);
260 odsState.addTypes(addr);
267LogicalResult cir::BreakOp::verify() {
269 if (!getOperation()->getParentOfType<LoopOpInterface>() &&
270 !getOperation()->getParentOfType<SwitchOp>())
271 return emitOpError(
"must be within a loop");
283void cir::ConditionOp::getSuccessorRegions(
289 if (
auto loopOp = dyn_cast<LoopOpInterface>(getOperation()->getParentOp())) {
290 regions.emplace_back(&loopOp.getBody(), loopOp.getBody().getArguments());
291 regions.emplace_back(getOperation(), loopOp->getResults());
295 auto await = cast<AwaitOp>(getOperation()->getParentOp());
296 regions.emplace_back(&await.getResume(), await.getResume().getArguments());
297 regions.emplace_back(&await.getSuspend(), await.getSuspend().getArguments());
301cir::ConditionOp::getMutableSuccessorOperands(RegionSuccessor point) {
303 return MutableOperandRange(getOperation(), 0, 0);
306LogicalResult cir::ConditionOp::verify() {
307 if (!isa<LoopOpInterface, AwaitOp>(getOperation()->getParentOp()))
308 return emitOpError(
"condition must be within a conditional region");
317 mlir::Attribute attrType) {
318 if (isa<cir::ConstPtrAttr>(attrType)) {
319 if (!mlir::isa<cir::PointerType>(opType))
320 return op->emitOpError(
321 "pointer constant initializing a non-pointer type");
325 if (isa<cir::ZeroAttr>(attrType)) {
326 if (isa<cir::RecordType, cir::ArrayType, cir::VectorType, cir::ComplexType>(
329 return op->emitOpError(
330 "zero expects struct, array, vector, or complex type");
333 if (mlir::isa<cir::UndefAttr>(attrType)) {
334 if (!mlir::isa<cir::VoidType>(opType))
336 return op->emitOpError(
"undef expects non-void type");
339 if (mlir::isa<cir::BoolAttr>(attrType)) {
340 if (!mlir::isa<cir::BoolType>(opType))
341 return op->emitOpError(
"result type (")
342 << opType <<
") must be '!cir.bool' for '" << attrType <<
"'";
346 if (mlir::isa<cir::IntAttr, cir::FPAttr>(attrType)) {
347 auto at = cast<TypedAttr>(attrType);
348 if (at.getType() != opType) {
349 return op->emitOpError(
"result type (")
350 << opType <<
") does not match value type (" << at.getType()
356 if (mlir::isa<cir::ConstArrayAttr, cir::ConstVectorAttr,
357 cir::ConstComplexAttr, cir::ConstRecordAttr,
358 cir::GlobalViewAttr, cir::PoisonAttr, cir::TypeInfoAttr,
359 cir::VTableAttr>(attrType))
362 assert(isa<TypedAttr>(attrType) &&
"What else could we be looking at here?");
363 return op->emitOpError(
"global with type ")
364 << cast<TypedAttr>(attrType).getType() <<
" not yet supported";
367LogicalResult cir::ConstantOp::verify() {
374OpFoldResult cir::ConstantOp::fold(FoldAdaptor ) {
382LogicalResult cir::ContinueOp::verify() {
383 if (!getOperation()->getParentOfType<LoopOpInterface>())
384 return emitOpError(
"must be within a loop");
392LogicalResult cir::CastOp::verify() {
393 mlir::Type resType =
getType();
394 mlir::Type srcType = getSrc().getType();
398 auto srcPtrTy = mlir::dyn_cast<cir::PointerType>(srcType);
399 auto resPtrTy = mlir::dyn_cast<cir::PointerType>(resType);
400 if (srcPtrTy && resPtrTy && (
getKind() != cir::CastKind::address_space))
401 if (srcPtrTy.getAddrSpace() != resPtrTy.getAddrSpace()) {
402 return emitOpError() <<
"result type address space does not match the "
403 "address space of the operand";
406 if (mlir::isa<cir::VectorType>(srcType) &&
407 mlir::isa<cir::VectorType>(resType)) {
410 srcType = mlir::dyn_cast<cir::VectorType>(srcType).getElementType();
411 resType = mlir::dyn_cast<cir::VectorType>(resType).getElementType();
415 case cir::CastKind::int_to_bool: {
416 if (!mlir::isa<cir::BoolType>(resType))
417 return emitOpError() <<
"requires !cir.bool type for result";
418 if (!mlir::isa<cir::IntType>(srcType))
419 return emitOpError() <<
"requires !cir.int type for source";
422 case cir::CastKind::ptr_to_bool: {
423 if (!mlir::isa<cir::BoolType>(resType))
424 return emitOpError() <<
"requires !cir.bool type for result";
425 if (!mlir::isa<cir::PointerType>(srcType))
426 return emitOpError() <<
"requires !cir.ptr type for source";
429 case cir::CastKind::integral: {
430 if (!mlir::isa<cir::IntType>(resType))
431 return emitOpError() <<
"requires !cir.int type for result";
432 if (!mlir::isa<cir::IntType>(srcType))
433 return emitOpError() <<
"requires !cir.int type for source";
436 case cir::CastKind::array_to_ptrdecay: {
437 const auto arrayPtrTy = mlir::dyn_cast<cir::PointerType>(srcType);
438 const auto flatPtrTy = mlir::dyn_cast<cir::PointerType>(resType);
439 if (!arrayPtrTy || !flatPtrTy)
440 return emitOpError() <<
"requires !cir.ptr type for source and result";
445 case cir::CastKind::bitcast: {
447 auto srcPtrTy = mlir::dyn_cast<cir::PointerType>(srcType);
448 auto resPtrTy = mlir::dyn_cast<cir::PointerType>(resType);
450 if (srcPtrTy && resPtrTy) {
456 case cir::CastKind::floating: {
457 if (!mlir::isa<cir::FPTypeInterface>(srcType) ||
458 !mlir::isa<cir::FPTypeInterface>(resType))
459 return emitOpError() <<
"requires !cir.float type for source and result";
462 case cir::CastKind::float_to_int: {
463 if (!mlir::isa<cir::FPTypeInterface>(srcType))
464 return emitOpError() <<
"requires !cir.float type for source";
465 if (!mlir::dyn_cast<cir::IntType>(resType))
466 return emitOpError() <<
"requires !cir.int type for result";
469 case cir::CastKind::int_to_ptr: {
470 if (!mlir::dyn_cast<cir::IntType>(srcType))
471 return emitOpError() <<
"requires !cir.int type for source";
472 if (!mlir::dyn_cast<cir::PointerType>(resType))
473 return emitOpError() <<
"requires !cir.ptr type for result";
476 case cir::CastKind::ptr_to_int: {
477 if (!mlir::dyn_cast<cir::PointerType>(srcType))
478 return emitOpError() <<
"requires !cir.ptr type for source";
479 if (!mlir::dyn_cast<cir::IntType>(resType))
480 return emitOpError() <<
"requires !cir.int type for result";
483 case cir::CastKind::float_to_bool: {
484 if (!mlir::isa<cir::FPTypeInterface>(srcType))
485 return emitOpError() <<
"requires !cir.float type for source";
486 if (!mlir::isa<cir::BoolType>(resType))
487 return emitOpError() <<
"requires !cir.bool type for result";
490 case cir::CastKind::bool_to_int: {
491 if (!mlir::isa<cir::BoolType>(srcType))
492 return emitOpError() <<
"requires !cir.bool type for source";
493 if (!mlir::isa<cir::IntType>(resType))
494 return emitOpError() <<
"requires !cir.int type for result";
497 case cir::CastKind::int_to_float: {
498 if (!mlir::isa<cir::IntType>(srcType))
499 return emitOpError() <<
"requires !cir.int type for source";
500 if (!mlir::isa<cir::FPTypeInterface>(resType))
501 return emitOpError() <<
"requires !cir.float type for result";
504 case cir::CastKind::bool_to_float: {
505 if (!mlir::isa<cir::BoolType>(srcType))
506 return emitOpError() <<
"requires !cir.bool type for source";
507 if (!mlir::isa<cir::FPTypeInterface>(resType))
508 return emitOpError() <<
"requires !cir.float type for result";
511 case cir::CastKind::address_space: {
512 auto srcPtrTy = mlir::dyn_cast<cir::PointerType>(srcType);
513 auto resPtrTy = mlir::dyn_cast<cir::PointerType>(resType);
514 if (!srcPtrTy || !resPtrTy)
515 return emitOpError() <<
"requires !cir.ptr type for source and result";
516 if (srcPtrTy.getPointee() != resPtrTy.getPointee())
517 return emitOpError() <<
"requires two types differ in addrspace only";
520 case cir::CastKind::float_to_complex: {
521 if (!mlir::isa<cir::FPTypeInterface>(srcType))
522 return emitOpError() <<
"requires !cir.float type for source";
523 auto resComplexTy = mlir::dyn_cast<cir::ComplexType>(resType);
525 return emitOpError() <<
"requires !cir.complex type for result";
526 if (srcType != resComplexTy.getElementType())
527 return emitOpError() <<
"requires source type match result element type";
530 case cir::CastKind::int_to_complex: {
531 if (!mlir::isa<cir::IntType>(srcType))
532 return emitOpError() <<
"requires !cir.int type for source";
533 auto resComplexTy = mlir::dyn_cast<cir::ComplexType>(resType);
535 return emitOpError() <<
"requires !cir.complex type for result";
536 if (srcType != resComplexTy.getElementType())
537 return emitOpError() <<
"requires source type match result element type";
540 case cir::CastKind::float_complex_to_real: {
541 auto srcComplexTy = mlir::dyn_cast<cir::ComplexType>(srcType);
543 return emitOpError() <<
"requires !cir.complex type for source";
544 if (!mlir::isa<cir::FPTypeInterface>(resType))
545 return emitOpError() <<
"requires !cir.float type for result";
546 if (srcComplexTy.getElementType() != resType)
547 return emitOpError() <<
"requires source element type match result type";
550 case cir::CastKind::int_complex_to_real: {
551 auto srcComplexTy = mlir::dyn_cast<cir::ComplexType>(srcType);
553 return emitOpError() <<
"requires !cir.complex type for source";
554 if (!mlir::isa<cir::IntType>(resType))
555 return emitOpError() <<
"requires !cir.int type for result";
556 if (srcComplexTy.getElementType() != resType)
557 return emitOpError() <<
"requires source element type match result type";
560 case cir::CastKind::float_complex_to_bool: {
561 auto srcComplexTy = mlir::dyn_cast<cir::ComplexType>(srcType);
562 if (!srcComplexTy || !srcComplexTy.isFloatingPointComplex())
564 <<
"requires floating point !cir.complex type for source";
565 if (!mlir::isa<cir::BoolType>(resType))
566 return emitOpError() <<
"requires !cir.bool type for result";
569 case cir::CastKind::int_complex_to_bool: {
570 auto srcComplexTy = mlir::dyn_cast<cir::ComplexType>(srcType);
571 if (!srcComplexTy || !srcComplexTy.isIntegerComplex())
573 <<
"requires floating point !cir.complex type for source";
574 if (!mlir::isa<cir::BoolType>(resType))
575 return emitOpError() <<
"requires !cir.bool type for result";
578 case cir::CastKind::float_complex: {
579 auto srcComplexTy = mlir::dyn_cast<cir::ComplexType>(srcType);
580 if (!srcComplexTy || !srcComplexTy.isFloatingPointComplex())
582 <<
"requires floating point !cir.complex type for source";
583 auto resComplexTy = mlir::dyn_cast<cir::ComplexType>(resType);
584 if (!resComplexTy || !resComplexTy.isFloatingPointComplex())
586 <<
"requires floating point !cir.complex type for result";
589 case cir::CastKind::float_complex_to_int_complex: {
590 auto srcComplexTy = mlir::dyn_cast<cir::ComplexType>(srcType);
591 if (!srcComplexTy || !srcComplexTy.isFloatingPointComplex())
593 <<
"requires floating point !cir.complex type for source";
594 auto resComplexTy = mlir::dyn_cast<cir::ComplexType>(resType);
595 if (!resComplexTy || !resComplexTy.isIntegerComplex())
596 return emitOpError() <<
"requires integer !cir.complex type for result";
599 case cir::CastKind::int_complex: {
600 auto srcComplexTy = mlir::dyn_cast<cir::ComplexType>(srcType);
601 if (!srcComplexTy || !srcComplexTy.isIntegerComplex())
602 return emitOpError() <<
"requires integer !cir.complex type for source";
603 auto resComplexTy = mlir::dyn_cast<cir::ComplexType>(resType);
604 if (!resComplexTy || !resComplexTy.isIntegerComplex())
605 return emitOpError() <<
"requires integer !cir.complex type for result";
608 case cir::CastKind::int_complex_to_float_complex: {
609 auto srcComplexTy = mlir::dyn_cast<cir::ComplexType>(srcType);
610 if (!srcComplexTy || !srcComplexTy.isIntegerComplex())
611 return emitOpError() <<
"requires integer !cir.complex type for source";
612 auto resComplexTy = mlir::dyn_cast<cir::ComplexType>(resType);
613 if (!resComplexTy || !resComplexTy.isFloatingPointComplex())
615 <<
"requires floating point !cir.complex type for result";
619 llvm_unreachable(
"Unknown CastOp kind?");
624 auto kind = op.getKind();
625 return kind == cir::CastKind::bool_to_int ||
626 kind == cir::CastKind::int_to_bool || kind == cir::CastKind::integral;
630 cir::CastOp head = op, tail = op;
636 op = head.getSrc().getDefiningOp<cir::CastOp>();
644 if (head.getKind() == cir::CastKind::bool_to_int &&
645 tail.getKind() == cir::CastKind::int_to_bool)
646 return head.getSrc();
651 if (head.getKind() == cir::CastKind::int_to_bool &&
652 tail.getKind() == cir::CastKind::int_to_bool)
653 return head.getResult();
658OpFoldResult cir::CastOp::fold(FoldAdaptor adaptor) {
659 if (mlir::isa_and_present<cir::PoisonAttr>(adaptor.getSrc())) {
661 return cir::PoisonAttr::get(getContext(),
getType());
666 case cir::CastKind::integral: {
670 auto foldOrder = getSrc().getDefiningOp()->fold(foldResults);
671 if (foldOrder.succeeded() && mlir::isa<mlir::Attribute>(foldResults[0]))
672 return mlir::cast<mlir::Attribute>(foldResults[0]);
675 case cir::CastKind::bitcast:
676 case cir::CastKind::address_space:
677 case cir::CastKind::float_complex:
678 case cir::CastKind::int_complex: {
692mlir::OperandRange cir::CallOp::getArgOperands() {
694 return getArgs().drop_front(1);
698mlir::MutableOperandRange cir::CallOp::getArgOperandsMutable() {
699 mlir::MutableOperandRange args = getArgsMutable();
701 return args.slice(1, args.size() - 1);
705mlir::Value cir::CallOp::getIndirectCall() {
706 assert(isIndirect());
707 return getOperand(0);
711Value cir::CallOp::getArgOperand(
unsigned i) {
714 return getOperand(i);
718unsigned cir::CallOp::getNumArgOperands() {
720 return this->getOperation()->getNumOperands() - 1;
721 return this->getOperation()->getNumOperands();
725 mlir::OperationState &result) {
728 mlir::FlatSymbolRefAttr calleeAttr;
733 .parseOptionalAttribute(calleeAttr, CIRDialect::getCalleeAttrName(),
736 OpAsmParser::UnresolvedOperand indirectVal;
738 if (parser.parseOperand(indirectVal).failed())
740 ops.push_back(indirectVal);
743 if (parser.parseLParen())
744 return mlir::failure();
746 opsLoc = parser.getCurrentLocation();
747 if (parser.parseOperandList(ops))
748 return mlir::failure();
749 if (parser.parseRParen())
750 return mlir::failure();
752 if (parser.parseOptionalKeyword(
"nothrow").succeeded())
753 result.addAttribute(CIRDialect::getNoThrowAttrName(),
754 mlir::UnitAttr::get(parser.getContext()));
756 if (parser.parseOptionalKeyword(
"side_effect").succeeded()) {
757 if (parser.parseLParen().failed())
759 cir::SideEffect sideEffect;
762 if (parser.parseRParen().failed())
764 auto attr = cir::SideEffectAttr::get(parser.getContext(), sideEffect);
765 result.addAttribute(CIRDialect::getSideEffectAttrName(), attr);
768 if (parser.parseOptionalAttrDict(result.attributes))
769 return ::mlir::failure();
771 if (parser.parseColon())
772 return ::mlir::failure();
774 mlir::FunctionType opsFnTy;
775 if (parser.parseType(opsFnTy))
776 return mlir::failure();
778 allResultTypes = opsFnTy.getResults();
779 result.addTypes(allResultTypes);
781 if (parser.resolveOperands(ops, opsFnTy.getInputs(), opsLoc, result.operands))
782 return mlir::failure();
784 return mlir::success();
788 mlir::FlatSymbolRefAttr calleeSym,
789 mlir::Value indirectCallee,
790 mlir::OpAsmPrinter &printer,
bool isNothrow,
791 cir::SideEffect sideEffect) {
794 auto callLikeOp = mlir::cast<cir::CIRCallOpInterface>(op);
795 auto ops = callLikeOp.getArgOperands();
799 printer.printAttributeWithoutType(calleeSym);
802 assert(indirectCallee);
803 printer << indirectCallee;
805 printer <<
"(" << ops <<
")";
808 printer <<
" nothrow";
810 if (sideEffect != cir::SideEffect::All) {
811 printer <<
" side_effect(";
812 printer << stringifySideEffect(sideEffect);
816 printer.printOptionalAttrDict(op->getAttrs(),
817 {CIRDialect::getCalleeAttrName(),
818 CIRDialect::getNoThrowAttrName(),
819 CIRDialect::getSideEffectAttrName()});
822 printer.printFunctionalType(op->getOperands().getTypes(),
823 op->getResultTypes());
826mlir::ParseResult cir::CallOp::parse(mlir::OpAsmParser &parser,
827 mlir::OperationState &result) {
831void cir::CallOp::print(mlir::OpAsmPrinter &p) {
832 mlir::Value indirectCallee = isIndirect() ? getIndirectCall() :
nullptr;
833 cir::SideEffect sideEffect = getSideEffect();
834 printCallCommon(*
this, getCalleeAttr(), indirectCallee, p, getNothrow(),
840 SymbolTableCollection &symbolTable) {
842 op->getAttrOfType<FlatSymbolRefAttr>(CIRDialect::getCalleeAttrName());
845 return mlir::success();
848 auto fn = symbolTable.lookupNearestSymbolFrom<cir::FuncOp>(op, fnAttr);
850 return op->emitOpError() <<
"'" << fnAttr.getValue()
851 <<
"' does not reference a valid function";
853 auto callIf = dyn_cast<cir::CIRCallOpInterface>(op);
854 assert(callIf &&
"expected CIR call interface to be always available");
858 auto fnType = fn.getFunctionType();
859 if (!fn.getNoProto()) {
860 unsigned numCallOperands = callIf.getNumArgOperands();
861 unsigned numFnOpOperands = fnType.getNumInputs();
863 if (!fnType.isVarArg() && numCallOperands != numFnOpOperands)
864 return op->emitOpError(
"incorrect number of operands for callee");
865 if (fnType.isVarArg() && numCallOperands < numFnOpOperands)
866 return op->emitOpError(
"too few operands for callee");
868 for (
unsigned i = 0, e = numFnOpOperands; i != e; ++i)
869 if (callIf.getArgOperand(i).getType() != fnType.getInput(i))
870 return op->emitOpError(
"operand type mismatch: expected operand type ")
871 << fnType.getInput(i) <<
", but provided "
872 << op->getOperand(i).getType() <<
" for operand number " << i;
878 if (fnType.hasVoidReturn() && op->getNumResults() != 0)
879 return op->emitOpError(
"callee returns void but call has results");
882 if (!fnType.hasVoidReturn() && op->getNumResults() != 1)
883 return op->emitOpError(
"incorrect number of results for callee");
886 if (!fnType.hasVoidReturn() &&
887 op->getResultTypes().front() != fnType.getReturnType()) {
888 return op->emitOpError(
"result type mismatch: expected ")
889 << fnType.getReturnType() <<
", but provided "
890 << op->getResult(0).getType();
893 return mlir::success();
897cir::CallOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
906 cir::FuncOp function) {
908 if (op.getNumOperands() > 1)
909 return op.emitOpError() <<
"expects at most 1 return operand";
912 auto expectedTy = function.getFunctionType().getReturnType();
914 (op.getNumOperands() == 0 ? cir::VoidType::get(op.getContext())
915 : op.getOperand(0).getType());
916 if (actualTy != expectedTy)
917 return op.emitOpError() <<
"returns " << actualTy
918 <<
" but enclosing function returns " << expectedTy;
920 return mlir::success();
923mlir::LogicalResult cir::ReturnOp::verify() {
926 auto *fnOp = getOperation()->getParentOp();
927 while (!isa<cir::FuncOp>(fnOp))
928 fnOp = fnOp->getParentOp();
941ParseResult cir::IfOp::parse(OpAsmParser &parser, OperationState &result) {
943 result.regions.reserve(2);
944 Region *thenRegion = result.addRegion();
945 Region *elseRegion = result.addRegion();
947 mlir::Builder &builder = parser.getBuilder();
948 OpAsmParser::UnresolvedOperand cond;
949 Type boolType = cir::BoolType::get(builder.getContext());
951 if (parser.parseOperand(cond) ||
952 parser.resolveOperand(cond, boolType, result.operands))
956 mlir::SMLoc parseThenLoc = parser.getCurrentLocation();
957 if (parser.parseRegion(*thenRegion, {}, {}))
964 if (!parser.parseOptionalKeyword(
"else")) {
965 mlir::SMLoc parseElseLoc = parser.getCurrentLocation();
966 if (parser.parseRegion(*elseRegion, {}, {}))
973 if (parser.parseOptionalAttrDict(result.attributes))
978void cir::IfOp::print(OpAsmPrinter &p) {
979 p <<
" " << getCondition() <<
" ";
980 mlir::Region &thenRegion = this->getThenRegion();
981 p.printRegion(thenRegion,
986 mlir::Region &elseRegion = this->getElseRegion();
987 if (!elseRegion.empty()) {
989 p.printRegion(elseRegion,
994 p.printOptionalAttrDict(getOperation()->getAttrs());
1000 cir::YieldOp::create(builder, loc);
1008void cir::IfOp::getSuccessorRegions(mlir::RegionBranchPoint point,
1009 SmallVectorImpl<RegionSuccessor> ®ions) {
1011 if (!point.isParent()) {
1013 RegionSuccessor(getOperation(), getOperation()->getResults()));
1018 Region *elseRegion = &this->getElseRegion();
1019 if (elseRegion->empty())
1020 elseRegion =
nullptr;
1023 regions.push_back(RegionSuccessor(&getThenRegion()));
1026 regions.push_back(RegionSuccessor(elseRegion));
1031void cir::IfOp::build(OpBuilder &builder, OperationState &result,
Value cond,
1034 assert(thenBuilder &&
"the builder callback for 'then' must be present");
1035 result.addOperands(cond);
1037 OpBuilder::InsertionGuard guard(builder);
1038 Region *thenRegion = result.addRegion();
1039 builder.createBlock(thenRegion);
1040 thenBuilder(builder, result.location);
1042 Region *elseRegion = result.addRegion();
1043 if (!withElseRegion)
1046 builder.createBlock(elseRegion);
1047 elseBuilder(builder, result.location);
1059void cir::ScopeOp::getSuccessorRegions(
1060 mlir::RegionBranchPoint point, SmallVectorImpl<RegionSuccessor> ®ions) {
1062 if (!point.isParent()) {
1063 regions.push_back(RegionSuccessor(getOperation(), getODSResults(0)));
1068 regions.push_back(RegionSuccessor(&getScopeRegion()));
1071void cir::ScopeOp::build(
1072 OpBuilder &builder, OperationState &result,
1073 function_ref<
void(OpBuilder &, Type &, Location)> scopeBuilder) {
1074 assert(scopeBuilder &&
"the builder callback for 'then' must be present");
1076 OpBuilder::InsertionGuard guard(builder);
1077 Region *scopeRegion = result.addRegion();
1078 builder.createBlock(scopeRegion);
1082 scopeBuilder(builder, yieldTy, result.location);
1085 result.addTypes(TypeRange{yieldTy});
1088void cir::ScopeOp::build(
1089 OpBuilder &builder, OperationState &result,
1090 function_ref<
void(OpBuilder &, Location)> scopeBuilder) {
1091 assert(scopeBuilder &&
"the builder callback for 'then' must be present");
1092 OpBuilder::InsertionGuard guard(builder);
1093 Region *scopeRegion = result.addRegion();
1094 builder.createBlock(scopeRegion);
1096 scopeBuilder(builder, result.location);
1099LogicalResult cir::ScopeOp::verify() {
1101 return emitOpError() <<
"cir.scope must not be empty since it should "
1102 "include at least an implicit cir.yield ";
1105 mlir::Block &lastBlock =
getRegion().back();
1106 if (lastBlock.empty() || !lastBlock.mightHaveTerminator() ||
1107 !lastBlock.getTerminator()->hasTrait<OpTrait::IsTerminator>())
1108 return emitOpError() <<
"last block of cir.scope must be terminated";
1116mlir::SuccessorOperands cir::BrOp::getSuccessorOperands(
unsigned index) {
1117 assert(index == 0 &&
"invalid successor index");
1118 return mlir::SuccessorOperands(getDestOperandsMutable());
1129mlir::SuccessorOperands cir::BrCondOp::getSuccessorOperands(
unsigned index) {
1130 assert(index < getNumSuccessors() &&
"invalid successor index");
1131 return SuccessorOperands(index == 0 ? getDestOperandsTrueMutable()
1132 : getDestOperandsFalseMutable());
1136 if (IntegerAttr condAttr = dyn_cast_if_present<IntegerAttr>(operands.front()))
1137 return condAttr.getValue().isOne() ? getDestTrue() : getDestFalse();
1145void cir::CaseOp::getSuccessorRegions(
1146 mlir::RegionBranchPoint point, SmallVectorImpl<RegionSuccessor> ®ions) {
1147 if (!point.isParent()) {
1149 RegionSuccessor(getOperation(), getOperation()->getResults()));
1152 regions.push_back(RegionSuccessor(&getCaseRegion()));
1155void cir::CaseOp::build(OpBuilder &builder, OperationState &result,
1156 ArrayAttr value, CaseOpKind kind,
1157 OpBuilder::InsertPoint &insertPoint) {
1158 OpBuilder::InsertionGuard guardSwitch(builder);
1159 result.addAttribute(
"value", value);
1160 result.getOrAddProperties<Properties>().kind =
1161 cir::CaseOpKindAttr::get(builder.getContext(), kind);
1162 Region *caseRegion = result.addRegion();
1163 builder.createBlock(caseRegion);
1165 insertPoint = builder.saveInsertionPoint();
1173 mlir::OpAsmParser::UnresolvedOperand &cond,
1174 mlir::Type &condType) {
1175 cir::IntType intCondType;
1177 if (parser.parseLParen())
1178 return mlir::failure();
1180 if (parser.parseOperand(cond))
1181 return mlir::failure();
1182 if (parser.parseColon())
1183 return mlir::failure();
1184 if (parser.parseCustomTypeWithFallback(intCondType))
1185 return mlir::failure();
1186 condType = intCondType;
1188 if (parser.parseRParen())
1189 return mlir::failure();
1190 if (parser.parseRegion(regions, {}, {}))
1193 return mlir::success();
1197 mlir::Region &bodyRegion, mlir::Value condition,
1198 mlir::Type condType) {
1202 p.printStrippedAttrOrType(condType);
1206 p.printRegion(bodyRegion,
false,
1210void cir::SwitchOp::getSuccessorRegions(
1211 mlir::RegionBranchPoint point, SmallVectorImpl<RegionSuccessor> ®ion) {
1212 if (!point.isParent()) {
1214 RegionSuccessor(getOperation(), getOperation()->getResults()));
1218 region.push_back(RegionSuccessor(&getBody()));
1221void cir::SwitchOp::build(OpBuilder &builder, OperationState &result,
1223 assert(switchBuilder &&
"the builder callback for regions must be present");
1224 OpBuilder::InsertionGuard guardSwitch(builder);
1225 Region *switchRegion = result.addRegion();
1226 builder.createBlock(switchRegion);
1227 result.addOperands({cond});
1228 switchBuilder(builder, result.location, result);
1232 walk<mlir::WalkOrder::PreOrder>([&](mlir::Operation *op) {
1234 if (isa<cir::SwitchOp>(op) && op != *
this)
1235 return WalkResult::skip();
1237 if (
auto caseOp = dyn_cast<cir::CaseOp>(op))
1238 cases.push_back(caseOp);
1240 return WalkResult::advance();
1245 collectCases(cases);
1247 if (getBody().empty())
1250 if (!isa<YieldOp>(getBody().front().back()))
1253 if (!llvm::all_of(getBody().front(),
1254 [](Operation &op) {
return isa<CaseOp, YieldOp>(op); }))
1257 return llvm::all_of(cases, [
this](CaseOp op) {
1258 return op->getParentOfType<SwitchOp>() == *
this;
1266void cir::SwitchFlatOp::build(OpBuilder &builder, OperationState &result,
1267 Value value, Block *defaultDestination,
1268 ValueRange defaultOperands,
1270 BlockRange caseDestinations,
1273 std::vector<mlir::Attribute> caseValuesAttrs;
1274 for (
const APInt &val : caseValues)
1275 caseValuesAttrs.push_back(cir::IntAttr::get(value.getType(), val));
1276 mlir::ArrayAttr attrs = ArrayAttr::get(builder.getContext(), caseValuesAttrs);
1278 build(builder, result, value, defaultOperands, caseOperands, attrs,
1279 defaultDestination, caseDestinations);
1285 OpAsmParser &parser, Type flagType, mlir::ArrayAttr &caseValues,
1286 SmallVectorImpl<Block *> &caseDestinations,
1290 if (failed(parser.parseLSquare()))
1292 if (succeeded(parser.parseOptionalRSquare()))
1296 auto parseCase = [&]() {
1298 if (failed(parser.parseInteger(value)))
1301 values.push_back(cir::IntAttr::get(flagType, value));
1306 if (parser.parseColon() || parser.parseSuccessor(destination))
1308 if (!parser.parseOptionalLParen()) {
1309 if (parser.parseOperandList(operands, OpAsmParser::Delimiter::None,
1311 parser.parseColonTypeList(operandTypes) || parser.parseRParen())
1314 caseDestinations.push_back(destination);
1315 caseOperands.emplace_back(operands);
1316 caseOperandTypes.emplace_back(operandTypes);
1319 if (failed(parser.parseCommaSeparatedList(parseCase)))
1322 caseValues = ArrayAttr::get(flagType.getContext(), values);
1324 return parser.parseRSquare();
1328 Type flagType, mlir::ArrayAttr caseValues,
1329 SuccessorRange caseDestinations,
1330 OperandRangeRange caseOperands,
1331 const TypeRangeRange &caseOperandTypes) {
1341 llvm::zip(caseValues, caseDestinations),
1344 mlir::Attribute a = std::get<0>(i);
1345 p << mlir::cast<cir::IntAttr>(a).getValue();
1347 p.printSuccessorAndUseList(std::get<1>(i), caseOperands[index++]);
1362 mlir::Attribute &valueAttr) {
1364 return parser.parseAttribute(valueAttr,
"value", attr);
1368 p.printAttribute(value);
1371mlir::LogicalResult cir::GlobalOp::verify() {
1374 if (getInitialValue().has_value()) {
1386void cir::GlobalOp::build(
1387 OpBuilder &odsBuilder, OperationState &odsState, llvm::StringRef sym_name,
1388 mlir::Type sym_type,
bool isConstant, cir::GlobalLinkageKind linkage,
1389 function_ref<
void(OpBuilder &, Location)> ctorBuilder,
1390 function_ref<
void(OpBuilder &, Location)> dtorBuilder) {
1391 odsState.addAttribute(getSymNameAttrName(odsState.name),
1392 odsBuilder.getStringAttr(sym_name));
1393 odsState.addAttribute(getSymTypeAttrName(odsState.name),
1394 mlir::TypeAttr::get(sym_type));
1396 odsState.addAttribute(getConstantAttrName(odsState.name),
1397 odsBuilder.getUnitAttr());
1399 cir::GlobalLinkageKindAttr linkageAttr =
1400 cir::GlobalLinkageKindAttr::get(odsBuilder.getContext(), linkage);
1401 odsState.addAttribute(getLinkageAttrName(odsState.name), linkageAttr);
1403 Region *ctorRegion = odsState.addRegion();
1405 odsBuilder.createBlock(ctorRegion);
1406 ctorBuilder(odsBuilder, odsState.location);
1409 Region *dtorRegion = odsState.addRegion();
1411 odsBuilder.createBlock(dtorRegion);
1412 dtorBuilder(odsBuilder, odsState.location);
1415 odsState.addAttribute(getGlobalVisibilityAttrName(odsState.name),
1416 cir::VisibilityAttr::get(odsBuilder.getContext()));
1424void cir::GlobalOp::getSuccessorRegions(
1425 mlir::RegionBranchPoint point, SmallVectorImpl<RegionSuccessor> ®ions) {
1427 if (!point.isParent()) {
1429 RegionSuccessor(getOperation(), getOperation()->getResults()));
1434 Region *ctorRegion = &this->getCtorRegion();
1435 if (ctorRegion->empty())
1436 ctorRegion =
nullptr;
1439 Region *dtorRegion = &this->getCtorRegion();
1440 if (dtorRegion->empty())
1441 dtorRegion =
nullptr;
1445 regions.push_back(RegionSuccessor(ctorRegion));
1447 regions.push_back(RegionSuccessor(dtorRegion));
1451 TypeAttr type, Attribute initAttr,
1452 mlir::Region &ctorRegion,
1453 mlir::Region &dtorRegion) {
1454 auto printType = [&]() { p <<
": " << type; };
1455 if (!op.isDeclaration()) {
1457 if (!ctorRegion.empty()) {
1461 p.printRegion(ctorRegion,
1470 if (!dtorRegion.empty()) {
1472 p.printRegion(dtorRegion,
1483 Attribute &initialValueAttr,
1484 mlir::Region &ctorRegion,
1485 mlir::Region &dtorRegion) {
1487 if (parser.parseOptionalEqual().failed()) {
1490 if (parser.parseColonType(opTy))
1495 if (!parser.parseOptionalKeyword(
"ctor")) {
1496 if (parser.parseColonType(opTy))
1498 auto parseLoc = parser.getCurrentLocation();
1499 if (parser.parseRegion(ctorRegion, {}, {}))
1510 assert(mlir::isa<mlir::TypedAttr>(initialValueAttr) &&
1511 "Non-typed attrs shouldn't appear here.");
1512 auto typedAttr = mlir::cast<mlir::TypedAttr>(initialValueAttr);
1513 opTy = typedAttr.getType();
1518 if (!parser.parseOptionalKeyword(
"dtor")) {
1519 auto parseLoc = parser.getCurrentLocation();
1520 if (parser.parseRegion(dtorRegion, {}, {}))
1527 typeAttr = TypeAttr::get(opTy);
1536cir::GetGlobalOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
1539 mlir::Operation *op =
1540 symbolTable.lookupNearestSymbolFrom(*
this, getNameAttr());
1541 if (op ==
nullptr || !(isa<GlobalOp>(op) || isa<FuncOp>(op)))
1542 return emitOpError(
"'")
1544 <<
"' does not reference a valid cir.global or cir.func";
1547 if (
auto g = dyn_cast<GlobalOp>(op)) {
1548 symTy = g.getSymType();
1551 }
else if (
auto f = dyn_cast<FuncOp>(op)) {
1552 symTy = f.getFunctionType();
1554 llvm_unreachable(
"Unexpected operation for GetGlobalOp");
1557 auto resultType = dyn_cast<PointerType>(getAddr().
getType());
1558 if (!resultType || symTy != resultType.getPointee())
1559 return emitOpError(
"result type pointee type '")
1560 << resultType.getPointee() <<
"' does not match type " << symTy
1561 <<
" of the global @" <<
getName();
1571cir::VTableAddrPointOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
1577 symbolTable.lookupNearestSymbolFrom<cir::GlobalOp>(*
this, getNameAttr());
1579 return emitOpError(
"'")
1580 <<
name <<
"' does not reference a valid cir.global";
1581 std::optional<mlir::Attribute> init = op.getInitialValue();
1584 if (!isa<cir::VTableAttr>(*init))
1585 return emitOpError(
"Expected #cir.vtable in initializer for global '")
1595cir::VTTAddrPointOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
1604 symbolTable.lookupNearestSymbolFrom<cir::GlobalOp>(*
this, getNameAttr());
1606 return emitOpError(
"'")
1607 <<
name <<
"' does not reference a valid cir.global";
1608 std::optional<mlir::Attribute> init = op.getInitialValue();
1611 if (!isa<cir::ConstArrayAttr>(*init))
1613 "Expected constant array in initializer for global VTT '")
1618LogicalResult cir::VTTAddrPointOp::verify() {
1620 if (
getName() && getSymAddr())
1621 return emitOpError(
"should use either a symbol or value, but not both");
1627 mlir::Type resultType = getAddr().getType();
1628 mlir::Type resTy = cir::PointerType::get(
1629 cir::PointerType::get(cir::VoidType::get(getContext())));
1631 if (resultType != resTy)
1632 return emitOpError(
"result type must be ")
1633 << resTy <<
", but provided result type is " << resultType;
1645void cir::FuncOp::build(OpBuilder &builder, OperationState &result,
1646 StringRef name, FuncType type,
1647 GlobalLinkageKind linkage) {
1649 result.addAttribute(SymbolTable::getSymbolAttrName(),
1650 builder.getStringAttr(name));
1651 result.addAttribute(getFunctionTypeAttrName(result.name),
1652 TypeAttr::get(type));
1653 result.addAttribute(
1655 GlobalLinkageKindAttr::get(builder.getContext(), linkage));
1656 result.addAttribute(getGlobalVisibilityAttrName(result.name),
1657 cir::VisibilityAttr::get(builder.getContext()));
1660ParseResult cir::FuncOp::parse(OpAsmParser &parser, OperationState &state) {
1661 llvm::SMLoc loc = parser.getCurrentLocation();
1662 mlir::Builder &builder = parser.getBuilder();
1664 mlir::StringAttr builtinNameAttr = getBuiltinAttrName(state.name);
1665 mlir::StringAttr coroutineNameAttr = getCoroutineAttrName(state.name);
1666 mlir::StringAttr lambdaNameAttr = getLambdaAttrName(state.name);
1667 mlir::StringAttr noProtoNameAttr = getNoProtoAttrName(state.name);
1668 mlir::StringAttr visNameAttr = getSymVisibilityAttrName(state.name);
1669 mlir::StringAttr visibilityNameAttr = getGlobalVisibilityAttrName(state.name);
1670 mlir::StringAttr dsoLocalNameAttr = getDsoLocalAttrName(state.name);
1671 mlir::StringAttr specialMemberAttr = getCxxSpecialMemberAttrName(state.name);
1673 if (::mlir::succeeded(parser.parseOptionalKeyword(builtinNameAttr.strref())))
1674 state.addAttribute(builtinNameAttr, parser.getBuilder().getUnitAttr());
1675 if (::mlir::succeeded(
1676 parser.parseOptionalKeyword(coroutineNameAttr.strref())))
1677 state.addAttribute(coroutineNameAttr, parser.getBuilder().getUnitAttr());
1678 if (::mlir::succeeded(parser.parseOptionalKeyword(lambdaNameAttr.strref())))
1679 state.addAttribute(lambdaNameAttr, parser.getBuilder().getUnitAttr());
1680 if (parser.parseOptionalKeyword(noProtoNameAttr).succeeded())
1681 state.addAttribute(noProtoNameAttr, parser.getBuilder().getUnitAttr());
1685 GlobalLinkageKindAttr::get(
1686 parser.getContext(),
1688 parser, GlobalLinkageKind::ExternalLinkage)));
1690 ::llvm::StringRef visAttrStr;
1691 if (parser.parseOptionalKeyword(&visAttrStr, {
"private",
"public",
"nested"})
1693 state.addAttribute(visNameAttr,
1694 parser.getBuilder().getStringAttr(visAttrStr));
1697 cir::VisibilityAttr cirVisibilityAttr;
1699 state.addAttribute(visibilityNameAttr, cirVisibilityAttr);
1701 if (parser.parseOptionalKeyword(dsoLocalNameAttr).succeeded())
1702 state.addAttribute(dsoLocalNameAttr, parser.getBuilder().getUnitAttr());
1704 StringAttr nameAttr;
1705 if (parser.parseSymbolName(nameAttr, SymbolTable::getSymbolAttrName(),
1711 bool isVariadic =
false;
1712 if (function_interface_impl::parseFunctionSignatureWithArguments(
1713 parser,
true, arguments, isVariadic, resultTypes,
1717 for (OpAsmParser::Argument &arg : arguments)
1718 argTypes.push_back(
arg.type);
1720 if (resultTypes.size() > 1) {
1721 return parser.emitError(
1722 loc,
"functions with multiple return types are not supported");
1725 mlir::Type returnType =
1726 (resultTypes.empty() ? cir::VoidType::get(builder.getContext())
1727 : resultTypes.front());
1729 cir::FuncType fnType = cir::FuncType::get(argTypes, returnType, isVariadic);
1732 state.addAttribute(getFunctionTypeAttrName(state.name),
1733 TypeAttr::get(fnType));
1735 bool hasAlias =
false;
1736 mlir::StringAttr aliaseeNameAttr = getAliaseeAttrName(state.name);
1737 if (parser.parseOptionalKeyword(
"alias").succeeded()) {
1738 if (parser.parseLParen().failed())
1740 mlir::StringAttr aliaseeAttr;
1741 if (parser.parseOptionalSymbolName(aliaseeAttr).failed())
1743 state.addAttribute(aliaseeNameAttr, FlatSymbolRefAttr::get(aliaseeAttr));
1744 if (parser.parseRParen().failed())
1749 auto parseGlobalDtorCtor =
1750 [&](StringRef keyword,
1751 llvm::function_ref<void(std::optional<int> prio)> createAttr)
1752 -> mlir::LogicalResult {
1753 if (mlir::succeeded(parser.parseOptionalKeyword(keyword))) {
1754 std::optional<int> priority;
1755 if (mlir::succeeded(parser.parseOptionalLParen())) {
1756 auto parsedPriority = mlir::FieldParser<int>::parse(parser);
1757 if (mlir::failed(parsedPriority))
1758 return parser.emitError(parser.getCurrentLocation(),
1759 "failed to parse 'priority', of type 'int'");
1760 priority = parsedPriority.value_or(
int());
1762 if (parser.parseRParen())
1765 createAttr(priority);
1771 if (parser.parseOptionalKeyword(
"special_member").succeeded()) {
1772 cir::CXXCtorAttr ctorAttr;
1773 cir::CXXDtorAttr dtorAttr;
1774 cir::CXXAssignAttr assignAttr;
1775 if (parser.parseLess().failed())
1777 if (parser.parseOptionalAttribute(ctorAttr).has_value())
1778 state.addAttribute(specialMemberAttr, ctorAttr);
1779 else if (parser.parseOptionalAttribute(dtorAttr).has_value())
1780 state.addAttribute(specialMemberAttr, dtorAttr);
1781 else if (parser.parseOptionalAttribute(assignAttr).has_value())
1782 state.addAttribute(specialMemberAttr, assignAttr);
1783 if (parser.parseGreater().failed())
1787 if (parseGlobalDtorCtor(
"global_ctor", [&](std::optional<int> priority) {
1788 mlir::IntegerAttr globalCtorPriorityAttr =
1789 builder.getI32IntegerAttr(priority.value_or(65535));
1790 state.addAttribute(getGlobalCtorPriorityAttrName(state.name),
1791 globalCtorPriorityAttr);
1795 if (parseGlobalDtorCtor(
"global_dtor", [&](std::optional<int> priority) {
1796 mlir::IntegerAttr globalDtorPriorityAttr =
1797 builder.getI32IntegerAttr(priority.value_or(65535));
1798 state.addAttribute(getGlobalDtorPriorityAttrName(state.name),
1799 globalDtorPriorityAttr);
1804 if (parser.parseOptionalKeyword(
"inline").succeeded()) {
1805 if (parser.parseLParen().failed())
1808 llvm::StringRef inlineKindStr;
1809 const std::array<llvm::StringRef, cir::getMaxEnumValForInlineKind()>
1810 allowedInlineKindStrs{
1811 cir::stringifyInlineKind(cir::InlineKind::NoInline),
1812 cir::stringifyInlineKind(cir::InlineKind::AlwaysInline),
1813 cir::stringifyInlineKind(cir::InlineKind::InlineHint),
1815 if (parser.parseOptionalKeyword(&inlineKindStr, allowedInlineKindStrs)
1817 return parser.emitError(parser.getCurrentLocation(),
1818 "expected 'never', 'always', or 'hint'");
1820 std::optional<InlineKind> inlineKind =
1821 cir::symbolizeInlineKind(inlineKindStr);
1823 return parser.emitError(parser.getCurrentLocation(),
1824 "invalid inline kind");
1826 state.addAttribute(getInlineKindAttrName(state.name),
1827 cir::InlineAttr::get(builder.getContext(), *inlineKind));
1829 if (parser.parseRParen().failed())
1834 auto *body = state.addRegion();
1835 OptionalParseResult parseResult = parser.parseOptionalRegion(
1836 *body, arguments,
false);
1837 if (parseResult.has_value()) {
1839 return parser.emitError(loc,
"function alias shall not have a body");
1840 if (failed(*parseResult))
1844 return parser.emitError(loc,
"expected non-empty function body");
1853bool cir::FuncOp::isDeclaration() {
1856 std::optional<StringRef> aliasee = getAliasee();
1858 return getFunctionBody().empty();
1864bool cir::FuncOp::isCXXSpecialMemberFunction() {
1865 return getCxxSpecialMemberAttr() !=
nullptr;
1868bool cir::FuncOp::isCxxConstructor() {
1869 auto attr = getCxxSpecialMemberAttr();
1870 return attr && dyn_cast<CXXCtorAttr>(attr);
1873bool cir::FuncOp::isCxxDestructor() {
1874 auto attr = getCxxSpecialMemberAttr();
1875 return attr && dyn_cast<CXXDtorAttr>(attr);
1878bool cir::FuncOp::isCxxSpecialAssignment() {
1879 auto attr = getCxxSpecialMemberAttr();
1880 return attr && dyn_cast<CXXAssignAttr>(attr);
1883std::optional<CtorKind> cir::FuncOp::getCxxConstructorKind() {
1884 mlir::Attribute
attr = getCxxSpecialMemberAttr();
1886 if (
auto ctor = dyn_cast<CXXCtorAttr>(attr))
1887 return ctor.getCtorKind();
1889 return std::nullopt;
1892std::optional<AssignKind> cir::FuncOp::getCxxSpecialAssignKind() {
1893 mlir::Attribute
attr = getCxxSpecialMemberAttr();
1895 if (
auto assign = dyn_cast<CXXAssignAttr>(attr))
1896 return assign.getAssignKind();
1898 return std::nullopt;
1901bool cir::FuncOp::isCxxTrivialMemberFunction() {
1902 mlir::Attribute
attr = getCxxSpecialMemberAttr();
1904 if (
auto ctor = dyn_cast<CXXCtorAttr>(attr))
1905 return ctor.getIsTrivial();
1906 if (
auto dtor = dyn_cast<CXXDtorAttr>(attr))
1907 return dtor.getIsTrivial();
1908 if (
auto assign = dyn_cast<CXXAssignAttr>(attr))
1909 return assign.getIsTrivial();
1914mlir::Region *cir::FuncOp::getCallableRegion() {
1920void cir::FuncOp::print(OpAsmPrinter &p) {
1936 if (getLinkage() != GlobalLinkageKind::ExternalLinkage)
1937 p <<
' ' << stringifyGlobalLinkageKind(getLinkage());
1939 mlir::SymbolTable::Visibility vis = getVisibility();
1940 if (vis != mlir::SymbolTable::Visibility::Public)
1943 cir::VisibilityAttr cirVisibilityAttr = getGlobalVisibilityAttr();
1944 if (!cirVisibilityAttr.isDefault()) {
1953 p.printSymbolName(getSymName());
1954 cir::FuncType fnType = getFunctionType();
1955 function_interface_impl::printFunctionSignature(
1956 p, *
this, fnType.getInputs(), fnType.isVarArg(), fnType.getReturnTypes());
1958 if (std::optional<StringRef> aliaseeName = getAliasee()) {
1960 p.printSymbolName(*aliaseeName);
1964 if (
auto specialMemberAttr = getCxxSpecialMember()) {
1965 p <<
" special_member<";
1966 p.printAttribute(*specialMemberAttr);
1970 if (
auto globalCtorPriority = getGlobalCtorPriority()) {
1971 p <<
" global_ctor";
1972 if (globalCtorPriority.value() != 65535)
1973 p <<
"(" << globalCtorPriority.value() <<
")";
1976 if (
auto globalDtorPriority = getGlobalDtorPriority()) {
1977 p <<
" global_dtor";
1978 if (globalDtorPriority.value() != 65535)
1979 p <<
"(" << globalDtorPriority.value() <<
")";
1982 if (cir::InlineAttr inlineAttr = getInlineKindAttr()) {
1983 p <<
" inline(" << cir::stringifyInlineKind(inlineAttr.getValue()) <<
")";
1987 Region &body = getOperation()->getRegion(0);
1988 if (!body.empty()) {
1990 p.printRegion(body,
false,
1995mlir::LogicalResult cir::FuncOp::verify() {
1997 if (!isDeclaration() && getCoroutine()) {
1998 bool foundAwait =
false;
1999 this->walk([&](Operation *op) {
2000 if (
auto await = dyn_cast<AwaitOp>(op)) {
2006 return emitOpError()
2007 <<
"coroutine body must use at least one cir.await op";
2010 llvm::SmallSet<llvm::StringRef, 16> labels;
2011 llvm::SmallSet<llvm::StringRef, 16> gotos;
2012 llvm::SmallSet<llvm::StringRef, 16> blockAddresses;
2013 bool invalidBlockAddress =
false;
2014 getOperation()->walk([&](mlir::Operation *op) {
2015 if (
auto lab = dyn_cast<cir::LabelOp>(op)) {
2016 labels.insert(lab.getLabel());
2017 }
else if (
auto goTo = dyn_cast<cir::GotoOp>(op)) {
2018 gotos.insert(goTo.getLabel());
2019 }
else if (
auto blkAdd = dyn_cast<cir::BlockAddressOp>(op)) {
2020 if (blkAdd.getBlockAddrInfoAttr().getFunc().getAttr() != getSymName()) {
2022 invalidBlockAddress =
true;
2023 return mlir::WalkResult::interrupt();
2025 blockAddresses.insert(blkAdd.getBlockAddrInfoAttr().getLabel());
2027 return mlir::WalkResult::advance();
2030 if (invalidBlockAddress)
2031 return emitOpError() <<
"blockaddress references a different function";
2033 llvm::SmallSet<llvm::StringRef, 16> mismatched;
2034 if (!labels.empty() || !gotos.empty()) {
2035 mismatched = llvm::set_difference(gotos, labels);
2037 if (!mismatched.empty())
2038 return emitOpError() <<
"goto/label mismatch";
2043 if (!labels.empty() || !blockAddresses.empty()) {
2044 mismatched = llvm::set_difference(blockAddresses, labels);
2046 if (!mismatched.empty())
2047 return emitOpError()
2048 <<
"expects an existing label target in the referenced function";
2057LogicalResult cir::BinOp::verify() {
2058 bool noWrap = getNoUnsignedWrap() || getNoSignedWrap();
2059 bool saturated = getSaturated();
2061 if (!isa<cir::IntType>(
getType()) && noWrap)
2063 <<
"only operations on integer values may have nsw/nuw flags";
2065 bool noWrapOps =
getKind() == cir::BinOpKind::Add ||
2066 getKind() == cir::BinOpKind::Sub ||
2067 getKind() == cir::BinOpKind::Mul;
2070 getKind() == cir::BinOpKind::Add ||
getKind() == cir::BinOpKind::Sub;
2072 if (noWrap && !noWrapOps)
2073 return emitError() <<
"The nsw/nuw flags are applicable to opcodes: 'add', "
2075 if (saturated && !saturatedOps)
2076 return emitError() <<
"The saturated flag is applicable to opcodes: 'add' "
2078 if (noWrap && saturated)
2079 return emitError() <<
"The nsw/nuw flags and the saturated flag are "
2080 "mutually exclusive";
2082 return mlir::success();
2094void cir::TernaryOp::getSuccessorRegions(
2095 mlir::RegionBranchPoint point, SmallVectorImpl<RegionSuccessor> ®ions) {
2097 if (!point.isParent()) {
2098 regions.push_back(RegionSuccessor(getOperation(), this->getODSResults(0)));
2104 regions.push_back(RegionSuccessor(&getTrueRegion()));
2105 regions.push_back(RegionSuccessor(&getFalseRegion()));
2108void cir::TernaryOp::build(
2109 OpBuilder &builder, OperationState &result,
Value cond,
2110 function_ref<
void(OpBuilder &, Location)> trueBuilder,
2111 function_ref<
void(OpBuilder &, Location)> falseBuilder) {
2112 result.addOperands(cond);
2113 OpBuilder::InsertionGuard guard(builder);
2114 Region *trueRegion = result.addRegion();
2115 builder.createBlock(trueRegion);
2116 trueBuilder(builder, result.location);
2117 Region *falseRegion = result.addRegion();
2118 builder.createBlock(falseRegion);
2119 falseBuilder(builder, result.location);
2124 dyn_cast_or_null<cir::YieldOp>(trueRegion->back().getTerminator());
2126 yield = dyn_cast_or_null<cir::YieldOp>(falseRegion->back().getTerminator());
2128 assert((yield && yield.getNumOperands() <= 1) &&
2129 "expected zero or one result type");
2130 if (yield.getNumOperands() == 1)
2131 result.addTypes(TypeRange{yield.getOperandTypes().front()});
2138OpFoldResult cir::SelectOp::fold(FoldAdaptor adaptor) {
2139 mlir::Attribute condition = adaptor.getCondition();
2141 bool conditionValue = mlir::cast<cir::BoolAttr>(condition).getValue();
2142 return conditionValue ? getTrueValue() : getFalseValue();
2146 mlir::Attribute trueValue = adaptor.getTrueValue();
2147 mlir::Attribute falseValue = adaptor.getFalseValue();
2148 if (trueValue == falseValue)
2150 if (getTrueValue() == getFalseValue())
2151 return getTrueValue();
2159LogicalResult cir::ShiftOp::verify() {
2160 mlir::Operation *op = getOperation();
2161 auto op0VecTy = mlir::dyn_cast<cir::VectorType>(op->getOperand(0).getType());
2162 auto op1VecTy = mlir::dyn_cast<cir::VectorType>(op->getOperand(1).getType());
2163 if (!op0VecTy ^ !op1VecTy)
2164 return emitOpError() <<
"input types cannot be one vector and one scalar";
2167 if (op0VecTy.getSize() != op1VecTy.getSize())
2168 return emitOpError() <<
"input vector types must have the same size";
2170 auto opResultTy = mlir::dyn_cast<cir::VectorType>(
getType());
2172 return emitOpError() <<
"the type of the result must be a vector "
2173 <<
"if it is vector shift";
2175 auto op0VecEleTy = mlir::cast<cir::IntType>(op0VecTy.getElementType());
2176 auto op1VecEleTy = mlir::cast<cir::IntType>(op1VecTy.getElementType());
2177 if (op0VecEleTy.getWidth() != op1VecEleTy.getWidth())
2178 return emitOpError()
2179 <<
"vector operands do not have the same elements sizes";
2181 auto resVecEleTy = mlir::cast<cir::IntType>(opResultTy.getElementType());
2182 if (op0VecEleTy.getWidth() != resVecEleTy.getWidth())
2183 return emitOpError() <<
"vector operands and result type do not have the "
2184 "same elements sizes";
2187 return mlir::success();
2194LogicalResult cir::LabelOp::verify() {
2195 mlir::Operation *op = getOperation();
2196 mlir::Block *blk = op->getBlock();
2197 if (&blk->front() != op)
2198 return emitError() <<
"must be the first operation in a block";
2200 return mlir::success();
2207LogicalResult cir::UnaryOp::verify() {
2209 case cir::UnaryOpKind::Inc:
2210 case cir::UnaryOpKind::Dec:
2211 case cir::UnaryOpKind::Plus:
2212 case cir::UnaryOpKind::Minus:
2213 case cir::UnaryOpKind::Not:
2218 llvm_unreachable(
"Unknown UnaryOp kind?");
2222 return isa<cir::BoolType>(op.getInput().getType()) &&
2223 op.getKind() == cir::UnaryOpKind::Not;
2235OpFoldResult cir::UnaryOp::fold(FoldAdaptor adaptor) {
2237 mlir::dyn_cast_if_present<cir::PoisonAttr>(adaptor.getInput())) {
2243 if (
auto previous = getInput().getDefiningOp<cir::UnaryOp>())
2245 return previous.getInput();
2253void cir::AwaitOp::build(OpBuilder &builder, OperationState &result,
2257 result.addAttribute(getKindAttrName(result.name),
2258 cir::AwaitKindAttr::get(builder.getContext(), kind));
2260 OpBuilder::InsertionGuard guard(builder);
2261 Region *readyRegion = result.addRegion();
2262 builder.createBlock(readyRegion);
2263 readyBuilder(builder, result.location);
2267 OpBuilder::InsertionGuard guard(builder);
2268 Region *suspendRegion = result.addRegion();
2269 builder.createBlock(suspendRegion);
2270 suspendBuilder(builder, result.location);
2274 OpBuilder::InsertionGuard guard(builder);
2275 Region *resumeRegion = result.addRegion();
2276 builder.createBlock(resumeRegion);
2277 resumeBuilder(builder, result.location);
2281void cir::AwaitOp::getSuccessorRegions(
2282 mlir::RegionBranchPoint point, SmallVectorImpl<RegionSuccessor> ®ions) {
2285 if (!point.isParent()) {
2287 RegionSuccessor(getOperation(), getOperation()->getResults()));
2294 regions.push_back(RegionSuccessor(&this->getReady()));
2295 regions.push_back(RegionSuccessor(&this->getSuspend()));
2296 regions.push_back(RegionSuccessor(&this->getResume()));
2299LogicalResult cir::AwaitOp::verify() {
2300 if (!isa<ConditionOp>(this->getReady().back().getTerminator()))
2301 return emitOpError(
"ready region must end with cir.condition");
2309LogicalResult cir::CopyOp::verify() {
2311 if (!
getType().getPointee().hasTrait<DataLayoutTypeInterface::Trait>())
2312 return emitError() <<
"missing data layout for pointee type";
2314 if (getSrc() == getDst())
2315 return emitError() <<
"source and destination are the same";
2317 return mlir::success();
2324LogicalResult cir::GetMemberOp::verify() {
2325 const auto recordTy = dyn_cast<RecordType>(getAddrTy().getPointee());
2327 return emitError() <<
"expected pointer to a record type";
2329 if (recordTy.getMembers().size() <=
getIndex())
2330 return emitError() <<
"member index out of bounds";
2333 return emitError() <<
"member type mismatch";
2335 return mlir::success();
2342OpFoldResult cir::VecCreateOp::fold(FoldAdaptor adaptor) {
2343 if (llvm::any_of(getElements(), [](mlir::Value value) {
2344 return !value.getDefiningOp<cir::ConstantOp>();
2348 return cir::ConstVectorAttr::get(
2349 getType(), mlir::ArrayAttr::get(getContext(), adaptor.getElements()));
2352LogicalResult cir::VecCreateOp::verify() {
2356 const cir::VectorType vecTy =
getType();
2357 if (getElements().size() != vecTy.getSize()) {
2358 return emitOpError() <<
"operand count of " << getElements().size()
2359 <<
" doesn't match vector type " << vecTy
2360 <<
" element count of " << vecTy.getSize();
2363 const mlir::Type elementType = vecTy.getElementType();
2364 for (
const mlir::Value element : getElements()) {
2365 if (element.getType() != elementType) {
2366 return emitOpError() <<
"operand type " << element.getType()
2367 <<
" doesn't match vector element type "
2379OpFoldResult cir::VecExtractOp::fold(FoldAdaptor adaptor) {
2380 const auto vectorAttr =
2381 llvm::dyn_cast_if_present<cir::ConstVectorAttr>(adaptor.getVec());
2385 const auto indexAttr =
2386 llvm::dyn_cast_if_present<cir::IntAttr>(adaptor.getIndex());
2390 const mlir::ArrayAttr elements = vectorAttr.getElts();
2391 const uint64_t index = indexAttr.getUInt();
2392 if (index >= elements.size())
2395 return elements[index];
2402OpFoldResult cir::VecCmpOp::fold(FoldAdaptor adaptor) {
2404 mlir::dyn_cast_if_present<cir::ConstVectorAttr>(adaptor.getLhs());
2406 mlir::dyn_cast_if_present<cir::ConstVectorAttr>(adaptor.getRhs());
2407 if (!lhsVecAttr || !rhsVecAttr)
2410 mlir::Type inputElemTy =
2411 mlir::cast<cir::VectorType>(lhsVecAttr.getType()).getElementType();
2412 if (!isAnyIntegerOrFloatingPointType(inputElemTy))
2415 cir::CmpOpKind opKind = adaptor.getKind();
2416 mlir::ArrayAttr lhsVecElhs = lhsVecAttr.getElts();
2417 mlir::ArrayAttr rhsVecElhs = rhsVecAttr.getElts();
2418 uint64_t vecSize = lhsVecElhs.size();
2421 bool isIntAttr = vecSize && mlir::isa<cir::IntAttr>(lhsVecElhs[0]);
2422 for (uint64_t i = 0; i < vecSize; i++) {
2423 mlir::Attribute lhsAttr = lhsVecElhs[i];
2424 mlir::Attribute rhsAttr = rhsVecElhs[i];
2427 case cir::CmpOpKind::lt: {
2429 cmpResult = mlir::cast<cir::IntAttr>(lhsAttr).getSInt() <
2430 mlir::cast<cir::IntAttr>(rhsAttr).getSInt();
2432 cmpResult = mlir::cast<cir::FPAttr>(lhsAttr).getValue() <
2433 mlir::cast<cir::FPAttr>(rhsAttr).getValue();
2437 case cir::CmpOpKind::le: {
2439 cmpResult = mlir::cast<cir::IntAttr>(lhsAttr).getSInt() <=
2440 mlir::cast<cir::IntAttr>(rhsAttr).getSInt();
2442 cmpResult = mlir::cast<cir::FPAttr>(lhsAttr).getValue() <=
2443 mlir::cast<cir::FPAttr>(rhsAttr).getValue();
2447 case cir::CmpOpKind::gt: {
2449 cmpResult = mlir::cast<cir::IntAttr>(lhsAttr).getSInt() >
2450 mlir::cast<cir::IntAttr>(rhsAttr).getSInt();
2452 cmpResult = mlir::cast<cir::FPAttr>(lhsAttr).getValue() >
2453 mlir::cast<cir::FPAttr>(rhsAttr).getValue();
2457 case cir::CmpOpKind::ge: {
2459 cmpResult = mlir::cast<cir::IntAttr>(lhsAttr).getSInt() >=
2460 mlir::cast<cir::IntAttr>(rhsAttr).getSInt();
2462 cmpResult = mlir::cast<cir::FPAttr>(lhsAttr).getValue() >=
2463 mlir::cast<cir::FPAttr>(rhsAttr).getValue();
2467 case cir::CmpOpKind::eq: {
2469 cmpResult = mlir::cast<cir::IntAttr>(lhsAttr).getSInt() ==
2470 mlir::cast<cir::IntAttr>(rhsAttr).getSInt();
2472 cmpResult = mlir::cast<cir::FPAttr>(lhsAttr).getValue() ==
2473 mlir::cast<cir::FPAttr>(rhsAttr).getValue();
2477 case cir::CmpOpKind::ne: {
2479 cmpResult = mlir::cast<cir::IntAttr>(lhsAttr).getSInt() !=
2480 mlir::cast<cir::IntAttr>(rhsAttr).getSInt();
2482 cmpResult = mlir::cast<cir::FPAttr>(lhsAttr).getValue() !=
2483 mlir::cast<cir::FPAttr>(rhsAttr).getValue();
2489 elements[i] = cir::IntAttr::get(
getType().getElementType(), cmpResult);
2492 return cir::ConstVectorAttr::get(
2493 getType(), mlir::ArrayAttr::get(getContext(), elements));
2500OpFoldResult cir::VecShuffleOp::fold(FoldAdaptor adaptor) {
2502 mlir::dyn_cast_if_present<cir::ConstVectorAttr>(adaptor.getVec1());
2504 mlir::dyn_cast_if_present<cir::ConstVectorAttr>(adaptor.getVec2());
2505 if (!vec1Attr || !vec2Attr)
2508 mlir::Type vec1ElemTy =
2509 mlir::cast<cir::VectorType>(vec1Attr.getType()).getElementType();
2511 mlir::ArrayAttr vec1Elts = vec1Attr.getElts();
2512 mlir::ArrayAttr vec2Elts = vec2Attr.getElts();
2513 mlir::ArrayAttr indicesElts = adaptor.getIndices();
2516 elements.reserve(indicesElts.size());
2518 uint64_t vec1Size = vec1Elts.size();
2519 for (
const auto &idxAttr : indicesElts.getAsRange<cir::IntAttr>()) {
2520 if (idxAttr.getSInt() == -1) {
2521 elements.push_back(cir::UndefAttr::get(vec1ElemTy));
2525 uint64_t idxValue = idxAttr.getUInt();
2526 elements.push_back(idxValue < vec1Size ? vec1Elts[idxValue]
2527 : vec2Elts[idxValue - vec1Size]);
2530 return cir::ConstVectorAttr::get(
2531 getType(), mlir::ArrayAttr::get(getContext(), elements));
2534LogicalResult cir::VecShuffleOp::verify() {
2537 if (getIndices().size() != getResult().
getType().getSize()) {
2538 return emitOpError() <<
": the number of elements in " << getIndices()
2539 <<
" and " << getResult().getType() <<
" don't match";
2544 if (getVec1().
getType().getElementType() !=
2545 getResult().
getType().getElementType()) {
2546 return emitOpError() <<
": element types of " << getVec1().getType()
2547 <<
" and " << getResult().getType() <<
" don't match";
2550 const uint64_t maxValidIndex =
2551 getVec1().getType().getSize() + getVec2().getType().getSize() - 1;
2553 getIndices().getAsRange<cir::IntAttr>(), [&](cir::IntAttr idxAttr) {
2554 return idxAttr.getSInt() != -1 && idxAttr.getUInt() > maxValidIndex;
2556 return emitOpError() <<
": index for __builtin_shufflevector must be "
2557 "less than the total number of vector elements";
2566OpFoldResult cir::VecShuffleDynamicOp::fold(FoldAdaptor adaptor) {
2567 mlir::Attribute vec = adaptor.getVec();
2568 mlir::Attribute indices = adaptor.getIndices();
2569 if (mlir::isa_and_nonnull<cir::ConstVectorAttr>(vec) &&
2570 mlir::isa_and_nonnull<cir::ConstVectorAttr>(indices)) {
2571 auto vecAttr = mlir::cast<cir::ConstVectorAttr>(vec);
2572 auto indicesAttr = mlir::cast<cir::ConstVectorAttr>(indices);
2574 mlir::ArrayAttr vecElts = vecAttr.getElts();
2575 mlir::ArrayAttr indicesElts = indicesAttr.getElts();
2577 const uint64_t numElements = vecElts.size();
2580 elements.reserve(numElements);
2582 const uint64_t maskBits = llvm::NextPowerOf2(numElements - 1) - 1;
2583 for (
const auto &idxAttr : indicesElts.getAsRange<cir::IntAttr>()) {
2584 uint64_t idxValue = idxAttr.getUInt();
2585 uint64_t newIdx = idxValue & maskBits;
2586 elements.push_back(vecElts[newIdx]);
2589 return cir::ConstVectorAttr::get(
2590 getType(), mlir::ArrayAttr::get(getContext(), elements));
2596LogicalResult cir::VecShuffleDynamicOp::verify() {
2598 if (getVec().
getType().getSize() !=
2599 mlir::cast<cir::VectorType>(getIndices().
getType()).getSize()) {
2600 return emitOpError() <<
": the number of elements in " << getVec().getType()
2601 <<
" and " << getIndices().getType() <<
" don't match";
2610LogicalResult cir::VecTernaryOp::verify() {
2615 if (getCond().
getType().getSize() != getLhs().
getType().getSize()) {
2616 return emitOpError() <<
": the number of elements in "
2617 << getCond().getType() <<
" and " << getLhs().getType()
2623OpFoldResult cir::VecTernaryOp::fold(FoldAdaptor adaptor) {
2624 mlir::Attribute cond = adaptor.getCond();
2625 mlir::Attribute lhs = adaptor.getLhs();
2626 mlir::Attribute rhs = adaptor.getRhs();
2628 if (!mlir::isa_and_nonnull<cir::ConstVectorAttr>(cond) ||
2629 !mlir::isa_and_nonnull<cir::ConstVectorAttr>(lhs) ||
2630 !mlir::isa_and_nonnull<cir::ConstVectorAttr>(rhs))
2632 auto condVec = mlir::cast<cir::ConstVectorAttr>(cond);
2633 auto lhsVec = mlir::cast<cir::ConstVectorAttr>(lhs);
2634 auto rhsVec = mlir::cast<cir::ConstVectorAttr>(rhs);
2636 mlir::ArrayAttr condElts = condVec.getElts();
2639 elements.reserve(condElts.size());
2641 for (
const auto &[idx, condAttr] :
2642 llvm::enumerate(condElts.getAsRange<cir::IntAttr>())) {
2643 if (condAttr.getSInt()) {
2644 elements.push_back(lhsVec.getElts()[idx]);
2646 elements.push_back(rhsVec.getElts()[idx]);
2650 cir::VectorType vecTy = getLhs().getType();
2651 return cir::ConstVectorAttr::get(
2652 vecTy, mlir::ArrayAttr::get(getContext(), elements));
2659LogicalResult cir::ComplexCreateOp::verify() {
2662 <<
"operand type of cir.complex.create does not match its result type";
2669OpFoldResult cir::ComplexCreateOp::fold(FoldAdaptor adaptor) {
2670 mlir::Attribute real = adaptor.getReal();
2671 mlir::Attribute imag = adaptor.getImag();
2677 auto realAttr = mlir::cast<mlir::TypedAttr>(real);
2678 auto imagAttr = mlir::cast<mlir::TypedAttr>(imag);
2679 return cir::ConstComplexAttr::get(realAttr, imagAttr);
2686LogicalResult cir::ComplexRealOp::verify() {
2687 mlir::Type operandTy = getOperand().getType();
2688 if (
auto complexOperandTy = mlir::dyn_cast<cir::ComplexType>(operandTy))
2689 operandTy = complexOperandTy.getElementType();
2692 emitOpError() <<
": result type does not match operand type";
2699OpFoldResult cir::ComplexRealOp::fold(FoldAdaptor adaptor) {
2700 if (!mlir::isa<cir::ComplexType>(getOperand().
getType()))
2703 if (
auto complexCreateOp = getOperand().getDefiningOp<cir::ComplexCreateOp>())
2704 return complexCreateOp.getOperand(0);
2707 mlir::cast_if_present<cir::ConstComplexAttr>(adaptor.getOperand());
2708 return complex ? complex.getReal() :
nullptr;
2715LogicalResult cir::ComplexImagOp::verify() {
2716 mlir::Type operandTy = getOperand().getType();
2717 if (
auto complexOperandTy = mlir::dyn_cast<cir::ComplexType>(operandTy))
2718 operandTy = complexOperandTy.getElementType();
2721 emitOpError() <<
": result type does not match operand type";
2728OpFoldResult cir::ComplexImagOp::fold(FoldAdaptor adaptor) {
2729 if (!mlir::isa<cir::ComplexType>(getOperand().
getType()))
2732 if (
auto complexCreateOp = getOperand().getDefiningOp<cir::ComplexCreateOp>())
2733 return complexCreateOp.getOperand(1);
2736 mlir::cast_if_present<cir::ConstComplexAttr>(adaptor.getOperand());
2737 return complex ? complex.getImag() :
nullptr;
2744LogicalResult cir::ComplexRealPtrOp::verify() {
2745 mlir::Type resultPointeeTy =
getType().getPointee();
2746 cir::PointerType operandPtrTy = getOperand().getType();
2747 auto operandPointeeTy =
2748 mlir::cast<cir::ComplexType>(operandPtrTy.getPointee());
2750 if (resultPointeeTy != operandPointeeTy.getElementType()) {
2751 return emitOpError() <<
": result type does not match operand type";
2761LogicalResult cir::ComplexImagPtrOp::verify() {
2762 mlir::Type resultPointeeTy =
getType().getPointee();
2763 cir::PointerType operandPtrTy = getOperand().getType();
2764 auto operandPointeeTy =
2765 mlir::cast<cir::ComplexType>(operandPtrTy.getPointee());
2767 if (resultPointeeTy != operandPointeeTy.getElementType()) {
2768 return emitOpError()
2769 <<
"cir.complex.imag_ptr result type does not match operand type";
2780 llvm::function_ref<llvm::APInt(
const llvm::APInt &)> func,
2781 bool poisonZero =
false) {
2782 if (mlir::isa_and_present<cir::PoisonAttr>(inputAttr)) {
2787 auto input = mlir::dyn_cast_if_present<IntAttr>(inputAttr);
2791 llvm::APInt inputValue = input.getValue();
2792 if (poisonZero && inputValue.isZero())
2793 return cir::PoisonAttr::get(input.getType());
2795 llvm::APInt resultValue = func(inputValue);
2796 return IntAttr::get(input.getType(), resultValue);
2799OpFoldResult BitClrsbOp::fold(FoldAdaptor adaptor) {
2800 return foldUnaryBitOp(adaptor.getInput(), [](
const llvm::APInt &inputValue) {
2801 unsigned resultValue =
2802 inputValue.getBitWidth() - inputValue.getSignificantBits();
2803 return llvm::APInt(inputValue.getBitWidth(), resultValue);
2807OpFoldResult BitClzOp::fold(FoldAdaptor adaptor) {
2810 [](
const llvm::APInt &inputValue) {
2811 unsigned resultValue = inputValue.countLeadingZeros();
2812 return llvm::APInt(inputValue.getBitWidth(), resultValue);
2817OpFoldResult BitCtzOp::fold(FoldAdaptor adaptor) {
2820 [](
const llvm::APInt &inputValue) {
2821 return llvm::APInt(inputValue.getBitWidth(),
2822 inputValue.countTrailingZeros());
2827OpFoldResult BitFfsOp::fold(FoldAdaptor adaptor) {
2828 return foldUnaryBitOp(adaptor.getInput(), [](
const llvm::APInt &inputValue) {
2829 unsigned trailingZeros = inputValue.countTrailingZeros();
2831 trailingZeros == inputValue.getBitWidth() ? 0 : trailingZeros + 1;
2832 return llvm::APInt(inputValue.getBitWidth(), result);
2836OpFoldResult BitParityOp::fold(FoldAdaptor adaptor) {
2837 return foldUnaryBitOp(adaptor.getInput(), [](
const llvm::APInt &inputValue) {
2838 return llvm::APInt(inputValue.getBitWidth(), inputValue.popcount() % 2);
2842OpFoldResult BitPopcountOp::fold(FoldAdaptor adaptor) {
2843 return foldUnaryBitOp(adaptor.getInput(), [](
const llvm::APInt &inputValue) {
2844 return llvm::APInt(inputValue.getBitWidth(), inputValue.popcount());
2848OpFoldResult BitReverseOp::fold(FoldAdaptor adaptor) {
2849 return foldUnaryBitOp(adaptor.getInput(), [](
const llvm::APInt &inputValue) {
2850 return inputValue.reverseBits();
2854OpFoldResult ByteSwapOp::fold(FoldAdaptor adaptor) {
2855 return foldUnaryBitOp(adaptor.getInput(), [](
const llvm::APInt &inputValue) {
2856 return inputValue.byteSwap();
2860OpFoldResult RotateOp::fold(FoldAdaptor adaptor) {
2861 if (mlir::isa_and_present<cir::PoisonAttr>(adaptor.getInput()) ||
2862 mlir::isa_and_present<cir::PoisonAttr>(adaptor.getAmount())) {
2864 return cir::PoisonAttr::get(
getType());
2867 auto input = mlir::dyn_cast_if_present<IntAttr>(adaptor.getInput());
2868 auto amount = mlir::dyn_cast_if_present<IntAttr>(adaptor.getAmount());
2869 if (!input && !amount)
2878 llvm::APInt inputValue;
2880 inputValue = input.getValue();
2881 if (inputValue.isZero() || inputValue.isAllOnes()) {
2887 uint64_t amountValue;
2889 amountValue = amount.getValue().urem(getInput().
getType().getWidth());
2890 if (amountValue == 0) {
2896 if (!input || !amount)
2899 assert(inputValue.getBitWidth() == getInput().
getType().getWidth() &&
2900 "input value must have the same bit width as the input type");
2902 llvm::APInt resultValue;
2904 resultValue = inputValue.rotl(amountValue);
2906 resultValue = inputValue.rotr(amountValue);
2908 return IntAttr::get(input.getContext(), input.getType(), resultValue);
2915void cir::InlineAsmOp::print(OpAsmPrinter &p) {
2916 p <<
'(' << getAsmFlavor() <<
", ";
2921 auto *nameIt = names.begin();
2922 auto *attrIt = getOperandAttrs().begin();
2924 for (mlir::OperandRange ops : getAsmOperands()) {
2925 p << *nameIt <<
" = ";
2928 llvm::interleaveComma(llvm::make_range(ops.begin(), ops.end()), p,
2930 p.printOperand(value);
2931 p <<
" : " << value.getType();
2933 p <<
" (maybe_memory)";
2942 p.printString(getAsmString());
2944 p.printString(getConstraints());
2948 if (getSideEffects())
2949 p <<
" side_effects";
2951 std::array elidedAttrs{
2952 llvm::StringRef(
"asm_flavor"), llvm::StringRef(
"asm_string"),
2953 llvm::StringRef(
"constraints"), llvm::StringRef(
"operand_attrs"),
2954 llvm::StringRef(
"operands_segments"), llvm::StringRef(
"side_effects")};
2955 p.printOptionalAttrDict(getOperation()->getAttrs(), elidedAttrs);
2957 if (
auto v = getRes())
2958 p <<
" -> " << v.getType();
2961void cir::InlineAsmOp::build(OpBuilder &odsBuilder, OperationState &odsState,
2963 StringRef asmString, StringRef constraints,
2964 bool sideEffects, cir::AsmFlavor asmFlavor,
2968 for (
auto operandRange : asmOperands) {
2969 segments.push_back(operandRange.size());
2970 odsState.addOperands(operandRange);
2973 odsState.addAttribute(
2974 "operands_segments",
2975 DenseI32ArrayAttr::get(odsBuilder.getContext(), segments));
2976 odsState.addAttribute(
"asm_string", odsBuilder.getStringAttr(asmString));
2977 odsState.addAttribute(
"constraints", odsBuilder.getStringAttr(constraints));
2978 odsState.addAttribute(
"asm_flavor",
2979 AsmFlavorAttr::get(odsBuilder.getContext(), asmFlavor));
2982 odsState.addAttribute(
"side_effects", odsBuilder.getUnitAttr());
2984 odsState.addAttribute(
"operand_attrs", odsBuilder.getArrayAttr(operandAttrs));
2987ParseResult cir::InlineAsmOp::parse(OpAsmParser &parser,
2988 OperationState &result) {
2991 std::string asmString, constraints;
2993 MLIRContext *ctxt = parser.getBuilder().getContext();
2995 auto error = [&](
const Twine &msg) -> LogicalResult {
2996 return parser.emitError(parser.getCurrentLocation(), msg);
2999 auto expected = [&](
const std::string &
c) {
3000 return error(
"expected '" +
c +
"'");
3003 if (parser.parseLParen().failed())
3004 return expected(
"(");
3006 auto flavor = FieldParser<AsmFlavor, AsmFlavor>::parse(parser);
3008 return error(
"Unknown AsmFlavor");
3010 if (parser.parseComma().failed())
3011 return expected(
",");
3013 auto parseValue = [&](
Value &v) {
3014 OpAsmParser::UnresolvedOperand op;
3016 if (parser.parseOperand(op) || parser.parseColon())
3017 return error(
"can't parse operand");
3020 if (parser.parseType(typ).failed())
3021 return error(
"can't parse operand type");
3023 if (parser.resolveOperand(op, typ, tmp))
3024 return error(
"can't resolve operand");
3026 return mlir::success();
3029 auto parseOperands = [&](llvm::StringRef
name) {
3030 if (parser.parseKeyword(name).failed())
3031 return error(
"expected " + name +
" operands here");
3032 if (parser.parseEqual().failed())
3033 return expected(
"=");
3034 if (parser.parseLSquare().failed())
3035 return expected(
"[");
3038 if (parser.parseOptionalRSquare().succeeded()) {
3039 operandsGroupSizes.push_back(size);
3040 if (parser.parseComma())
3041 return expected(
",");
3042 return mlir::success();
3045 auto parseOperand = [&]() {
3047 if (parseValue(val).succeeded()) {
3048 result.operands.push_back(val);
3051 if (parser.parseOptionalLParen().failed()) {
3052 operandAttrs.push_back(mlir::Attribute());
3053 return mlir::success();
3056 if (parser.parseKeyword(
"maybe_memory").succeeded()) {
3057 operandAttrs.push_back(mlir::UnitAttr::get(ctxt));
3058 if (parser.parseRParen())
3059 return expected(
")");
3060 return mlir::success();
3062 return expected(
"maybe_memory");
3065 return mlir::failure();
3068 if (parser.parseCommaSeparatedList(parseOperand).failed())
3069 return mlir::failure();
3071 if (parser.parseRSquare().failed() || parser.parseComma().failed())
3072 return expected(
"]");
3073 operandsGroupSizes.push_back(size);
3074 return mlir::success();
3077 if (parseOperands(
"out").failed() || parseOperands(
"in").failed() ||
3078 parseOperands(
"in_out").failed())
3079 return error(
"failed to parse operands");
3081 if (parser.parseLBrace())
3082 return expected(
"{");
3083 if (parser.parseString(&asmString))
3084 return error(
"asm string parsing failed");
3085 if (parser.parseString(&constraints))
3086 return error(
"constraints string parsing failed");
3087 if (parser.parseRBrace())
3088 return expected(
"}");
3089 if (parser.parseRParen())
3090 return expected(
")");
3092 if (parser.parseOptionalKeyword(
"side_effects").succeeded())
3093 result.attributes.set(
"side_effects", UnitAttr::get(ctxt));
3095 if (parser.parseOptionalArrow().succeeded() &&
3096 parser.parseType(resType).failed())
3097 return mlir::failure();
3099 if (parser.parseOptionalAttrDict(result.attributes).failed())
3100 return mlir::failure();
3102 result.attributes.set(
"asm_flavor", AsmFlavorAttr::get(ctxt, *flavor));
3103 result.attributes.set(
"asm_string", StringAttr::get(ctxt, asmString));
3104 result.attributes.set(
"constraints", StringAttr::get(ctxt, constraints));
3105 result.attributes.set(
"operand_attrs", ArrayAttr::get(ctxt, operandAttrs));
3106 result.getOrAddProperties<InlineAsmOp::Properties>().operands_segments =
3107 parser.getBuilder().getDenseI32ArrayAttr(operandsGroupSizes);
3109 result.addTypes(TypeRange{resType});
3111 return mlir::success();
3118mlir::LogicalResult cir::ThrowOp::verify() {
3123 if (getNumOperands() != 0) {
3126 return emitOpError() <<
"'type_info' symbol attribute missing";
3136LogicalResult cir::AtomicFetchOp::verify() {
3137 if (getBinop() != cir::AtomicFetchKind::Add &&
3138 getBinop() != cir::AtomicFetchKind::Sub &&
3139 getBinop() != cir::AtomicFetchKind::Max &&
3140 getBinop() != cir::AtomicFetchKind::Min &&
3141 !mlir::isa<cir::IntType>(getVal().
getType()))
3142 return emitError(
"only atomic add, sub, max, and min operation could "
3143 "operate on floating-point values");
3151LogicalResult cir::TypeInfoAttr::verify(
3152 ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError,
3153 ::mlir::Type type, ::mlir::ArrayAttr typeInfoData) {
3155 if (cir::ConstRecordAttr::verify(emitError, type, typeInfoData).failed())
3165void cir::TryOp::getSuccessorRegions(
3166 mlir::RegionBranchPoint point,
3169 if (!point.isParent()) {
3171 RegionSuccessor(getOperation(), getOperation()->getResults()));
3175 regions.push_back(mlir::RegionSuccessor(&getTryRegion()));
3179 for (mlir::Region &handlerRegion : this->getHandlerRegions())
3180 regions.push_back(mlir::RegionSuccessor(&handlerRegion));
3185 mlir::MutableArrayRef<mlir::Region> handlerRegions,
3186 mlir::ArrayAttr handlerTypes) {
3190 for (
const auto [typeIdx, typeAttr] : llvm::enumerate(handlerTypes)) {
3194 if (mlir::isa<cir::CatchAllAttr>(typeAttr)) {
3195 printer <<
"catch all ";
3196 }
else if (mlir::isa<cir::UnwindAttr>(typeAttr)) {
3197 printer <<
"unwind ";
3199 printer <<
"catch [type ";
3200 printer.printAttribute(typeAttr);
3204 printer.printRegion(handlerRegions[typeIdx],
3211 mlir::OpAsmParser &parser,
3213 mlir::ArrayAttr &handlerTypes) {
3215 auto parseCheckedCatcherRegion = [&]() -> mlir::ParseResult {
3216 handlerRegions.emplace_back(
new mlir::Region);
3218 mlir::Region &currRegion = *handlerRegions.back();
3219 mlir::SMLoc regionLoc = parser.getCurrentLocation();
3220 if (parser.parseRegion(currRegion)) {
3221 handlerRegions.clear();
3225 if (currRegion.empty())
3226 return parser.emitError(regionLoc,
"handler region shall not be empty");
3228 if (!(currRegion.back().mightHaveTerminator() &&
3229 currRegion.back().getTerminator()))
3230 return parser.emitError(
3231 regionLoc,
"blocks are expected to be explicitly terminated");
3236 bool hasCatchAll =
false;
3238 while (parser.parseOptionalKeyword(
"catch").succeeded()) {
3239 bool hasLSquare = parser.parseOptionalLSquare().succeeded();
3241 llvm::StringRef attrStr;
3242 if (parser.parseOptionalKeyword(&attrStr, {
"all",
"type"}).failed())
3243 return parser.emitError(parser.getCurrentLocation(),
3244 "expected 'all' or 'type' keyword");
3246 bool isCatchAll = attrStr ==
"all";
3249 return parser.emitError(parser.getCurrentLocation(),
3250 "can't have more than one catch all");
3254 mlir::Attribute exceptionRTTIAttr;
3255 if (!isCatchAll && parser.parseAttribute(exceptionRTTIAttr).failed())
3256 return parser.emitError(parser.getCurrentLocation(),
3257 "expected valid RTTI info attribute");
3259 catcherAttrs.push_back(isCatchAll
3260 ? cir::CatchAllAttr::get(parser.getContext())
3261 : exceptionRTTIAttr);
3263 if (hasLSquare && isCatchAll)
3264 return parser.emitError(parser.getCurrentLocation(),
3265 "catch all dosen't need RTTI info attribute");
3267 if (hasLSquare && parser.parseRSquare().failed())
3268 return parser.emitError(parser.getCurrentLocation(),
3269 "expected `]` after RTTI info attribute");
3271 if (parseCheckedCatcherRegion().failed())
3272 return mlir::failure();
3275 if (parser.parseOptionalKeyword(
"unwind").succeeded()) {
3277 return parser.emitError(parser.getCurrentLocation(),
3278 "unwind can't be used with catch all");
3280 catcherAttrs.push_back(cir::UnwindAttr::get(parser.getContext()));
3281 if (parseCheckedCatcherRegion().failed())
3282 return mlir::failure();
3285 handlerTypes = parser.getBuilder().getArrayAttr(catcherAttrs);
3286 return mlir::success();
3293#define GET_OP_CLASSES
3294#include "clang/CIR/Dialect/IR/CIROps.cpp.inc"
static const MemRegion * getRegion(const CallEvent &Call, const MutexDescriptor &Descriptor, bool IsLock)
static mlir::LogicalResult checkReturnAndFunction(cir::ReturnOp op, cir::FuncOp function)
static bool isBoolNot(cir::UnaryOp op)
static bool isIntOrBoolCast(cir::CastOp op)
static void printConstant(OpAsmPrinter &p, Attribute value)
static mlir::ParseResult parseOmittedTerminatorRegion(mlir::OpAsmParser &parser, mlir::Region ®ion)
void printVisibilityAttr(OpAsmPrinter &printer, cir::VisibilityAttr &visibility)
static ParseResult parseSwitchFlatOpCases(OpAsmParser &parser, Type flagType, mlir::ArrayAttr &caseValues, SmallVectorImpl< Block * > &caseDestinations, SmallVectorImpl< llvm::SmallVector< OpAsmParser::UnresolvedOperand > > &caseOperands, SmallVectorImpl< llvm::SmallVector< Type > > &caseOperandTypes)
<cases> ::= [ (case (, case )* )?
static LogicalResult verifyCallCommInSymbolUses(mlir::Operation *op, SymbolTableCollection &symbolTable)
static LogicalResult ensureRegionTerm(OpAsmParser &parser, Region ®ion, SMLoc errLoc)
static ParseResult parseGlobalOpTypeAndInitialValue(OpAsmParser &parser, TypeAttr &typeAttr, Attribute &initialValueAttr, mlir::Region &ctorRegion, mlir::Region &dtorRegion)
static OpFoldResult foldUnaryBitOp(mlir::Attribute inputAttr, llvm::function_ref< llvm::APInt(const llvm::APInt &)> func, bool poisonZero=false)
static llvm::StringRef getLinkageAttrNameString()
Returns the name used for the linkage attribute.
static RetTy parseOptionalCIRKeyword(AsmParser &parser, EnumTy defaultValue)
Parse an enum from the keyword, or default to the provided default value.
static void printSwitchFlatOpCases(OpAsmPrinter &p, cir::SwitchFlatOp op, Type flagType, mlir::ArrayAttr caseValues, SuccessorRange caseDestinations, OperandRangeRange caseOperands, const TypeRangeRange &caseOperandTypes)
static void printSwitchOp(OpAsmPrinter &p, cir::SwitchOp op, mlir::Region &bodyRegion, mlir::Value condition, mlir::Type condType)
static void printGlobalOpTypeAndInitialValue(OpAsmPrinter &p, cir::GlobalOp op, TypeAttr type, Attribute initAttr, mlir::Region &ctorRegion, mlir::Region &dtorRegion)
static ParseResult parseCIRKeyword(AsmParser &parser, RetTy &result)
Parse an enum from the keyword, return failure if the keyword is not found.
static Value tryFoldCastChain(cir::CastOp op)
void parseVisibilityAttr(OpAsmParser &parser, cir::VisibilityAttr &visibility)
static void printTryHandlerRegions(mlir::OpAsmPrinter &printer, cir::TryOp op, mlir::MutableArrayRef< mlir::Region > handlerRegions, mlir::ArrayAttr handlerTypes)
static bool omitRegionTerm(mlir::Region &r)
static void printOmittedTerminatorRegion(mlir::OpAsmPrinter &printer, cir::ScopeOp &op, mlir::Region ®ion)
static ParseResult parseConstantValue(OpAsmParser &parser, mlir::Attribute &valueAttr)
static void printCallCommon(mlir::Operation *op, mlir::FlatSymbolRefAttr calleeSym, mlir::Value indirectCallee, mlir::OpAsmPrinter &printer, bool isNothrow, cir::SideEffect sideEffect)
static LogicalResult checkConstantTypes(mlir::Operation *op, mlir::Type opType, mlir::Attribute attrType)
static ParseResult parseSwitchOp(OpAsmParser &parser, mlir::Region ®ions, mlir::OpAsmParser::UnresolvedOperand &cond, mlir::Type &condType)
static mlir::ParseResult parseCallCommon(mlir::OpAsmParser &parser, mlir::OperationState &result)
static mlir::ParseResult parseTryHandlerRegions(mlir::OpAsmParser &parser, llvm::SmallVectorImpl< std::unique_ptr< mlir::Region > > &handlerRegions, mlir::ArrayAttr &handlerTypes)
#define REGISTER_ENUM_TYPE(Ty)
static int parseOptionalKeywordAlternative(AsmParser &parser, ArrayRef< llvm::StringRef > keywords)
llvm::function_ref< void(mlir::OpBuilder &, mlir::Location)> BuilderCallbackRef
llvm::function_ref< void( mlir::OpBuilder &, mlir::Location, mlir::OperationState &)> BuilderOpStateCallbackRef
static std::optional< NonLoc > getIndex(ProgramStateRef State, const ElementRegion *ER, CharKind CK)
static Decl::Kind getKind(const Decl *D)
__device__ __2f16 float c
void buildTerminatedBody(mlir::OpBuilder &builder, mlir::Location loc)
const internal::VariadicAllOfMatcher< Attr > attr
const AstTypeMatcher< RecordType > recordType
StringRef getName(const HeaderType T)
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
__DEVICE__ _Tp arg(const std::complex< _Tp > &__c)
static bool addressSpace()
static bool opGlobalThreadLocal()
static bool opCallCallConv()
static bool opScopeCleanupRegion()
static bool supportIFuncAttr()