Skip to content

Commit e58602d

Browse files
committed
[π˜€π—½π—Ώ] initial version
Created using spr 1.3.5
1 parent c76c138 commit e58602d

File tree

2 files changed

+74
-52
lines changed

2 files changed

+74
-52
lines changed

β€Žclang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,10 @@ def LoadOp : CIR_Op<"load", [
599599
$addr `:` qualified(type($addr)) `,` type($result) attr-dict
600600
}];
601601

602+
let extraClassDeclaration = [{
603+
void setAtomic(mlir::cir::MemOrder order);
604+
}];
605+
602606
// FIXME: add verifier.
603607
}
604608

@@ -2295,8 +2299,12 @@ def GlobalOp : CIR_Op<"global",
22952299
bool hasAvailableExternallyLinkage() {
22962300
return mlir::cir::isAvailableExternallyLinkage(getLinkage());
22972301
}
2302+
bool hasInternalLinkage() {
2303+
return mlir::cir::isInternalLinkage(getLinkage());
2304+
}
22982305
/// Whether the definition of this global may be replaced at link time.
22992306
bool isWeakForLinker() { return cir::isWeakForLinker(getLinkage()); }
2307+
bool isDSOLocal() { return getDsolocal(); }
23002308
}];
23012309

23022310
let skipDefaultBuilders = 1;

β€Žclang/lib/CIR/Dialect/IR/CIRDialect.cpp

Lines changed: 66 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ using namespace mlir;
4949
#include "clang/CIR/Dialect/IR/CIROpsDialect.cpp.inc"
5050
#include "clang/CIR/Interfaces/ASTAttrInterfaces.h"
5151
#include "clang/CIR/Interfaces/CIROpInterfaces.h"
52+
#include <clang/CIR/MissingFeatures.h>
5253

5354
//===----------------------------------------------------------------------===//
5455
// CIR Dialect
@@ -470,28 +471,28 @@ LogicalResult mlir::cir::CastOp::verify() {
470471
}
471472

472473
switch (getKind()) {
473-
case cir::CastKind::int_to_bool: {
474+
case mlir::cir::CastKind::int_to_bool: {
474475
if (!mlir::isa<mlir::cir::BoolType>(resType))
475476
return emitOpError() << "requires !cir.bool type for result";
476477
if (!mlir::isa<mlir::cir::IntType>(srcType))
477478
return emitOpError() << "requires !cir.int type for source";
478479
return success();
479480
}
480-
case cir::CastKind::ptr_to_bool: {
481+
case mlir::cir::CastKind::ptr_to_bool: {
481482
if (!mlir::isa<mlir::cir::BoolType>(resType))
482483
return emitOpError() << "requires !cir.bool type for result";
483484
if (!mlir::isa<mlir::cir::PointerType>(srcType))
484485
return emitOpError() << "requires !cir.ptr type for source";
485486
return success();
486487
}
487-
case cir::CastKind::integral: {
488+
case mlir::cir::CastKind::integral: {
488489
if (!mlir::isa<mlir::cir::IntType>(resType))
489490
return emitOpError() << "requires !cir.int type for result";
490491
if (!mlir::isa<mlir::cir::IntType>(srcType))
491492
return emitOpError() << "requires !cir.int type for source";
492493
return success();
493494
}
494-
case cir::CastKind::array_to_ptrdecay: {
495+
case mlir::cir::CastKind::array_to_ptrdecay: {
495496
auto arrayPtrTy = mlir::dyn_cast<mlir::cir::PointerType>(srcType);
496497
auto flatPtrTy = mlir::dyn_cast<mlir::cir::PointerType>(resType);
497498
if (!arrayPtrTy || !flatPtrTy)
@@ -512,7 +513,7 @@ LogicalResult mlir::cir::CastOp::verify() {
512513
<< "requires same type for array element and pointee result";
513514
return success();
514515
}
515-
case cir::CastKind::bitcast: {
516+
case mlir::cir::CastKind::bitcast: {
516517
// Allow bitcast of structs for calling conventions.
517518
if (isa<StructType>(srcType) || isa<StructType>(resType))
518519
return success();
@@ -537,62 +538,62 @@ LogicalResult mlir::cir::CastOp::verify() {
537538
<< "requires !cir.ptr or !cir.vector type for source and result";
538539
return success();
539540
}
540-
case cir::CastKind::floating: {
541+
case mlir::cir::CastKind::floating: {
541542
if (!mlir::isa<mlir::cir::CIRFPTypeInterface>(srcType) ||
542543
!mlir::isa<mlir::cir::CIRFPTypeInterface>(resType))
543544
return emitOpError() << "requires !cir.float type for source and result";
544545
return success();
545546
}
546-
case cir::CastKind::float_to_int: {
547+
case mlir::cir::CastKind::float_to_int: {
547548
if (!mlir::isa<mlir::cir::CIRFPTypeInterface>(srcType))
548549
return emitOpError() << "requires !cir.float type for source";
549550
if (!mlir::dyn_cast<mlir::cir::IntType>(resType))
550551
return emitOpError() << "requires !cir.int type for result";
551552
return success();
552553
}
553-
case cir::CastKind::int_to_ptr: {
554+
case mlir::cir::CastKind::int_to_ptr: {
554555
if (!mlir::dyn_cast<mlir::cir::IntType>(srcType))
555556
return emitOpError() << "requires !cir.int type for source";
556557
if (!mlir::dyn_cast<mlir::cir::PointerType>(resType))
557558
return emitOpError() << "requires !cir.ptr type for result";
558559
return success();
559560
}
560-
case cir::CastKind::ptr_to_int: {
561+
case mlir::cir::CastKind::ptr_to_int: {
561562
if (!mlir::dyn_cast<mlir::cir::PointerType>(srcType))
562563
return emitOpError() << "requires !cir.ptr type for source";
563564
if (!mlir::dyn_cast<mlir::cir::IntType>(resType))
564565
return emitOpError() << "requires !cir.int type for result";
565566
return success();
566567
}
567-
case cir::CastKind::float_to_bool: {
568+
case mlir::cir::CastKind::float_to_bool: {
568569
if (!mlir::isa<mlir::cir::CIRFPTypeInterface>(srcType))
569570
return emitOpError() << "requires !cir.float type for source";
570571
if (!mlir::isa<mlir::cir::BoolType>(resType))
571572
return emitOpError() << "requires !cir.bool type for result";
572573
return success();
573574
}
574-
case cir::CastKind::bool_to_int: {
575+
case mlir::cir::CastKind::bool_to_int: {
575576
if (!mlir::isa<mlir::cir::BoolType>(srcType))
576577
return emitOpError() << "requires !cir.bool type for source";
577578
if (!mlir::isa<mlir::cir::IntType>(resType))
578579
return emitOpError() << "requires !cir.int type for result";
579580
return success();
580581
}
581-
case cir::CastKind::int_to_float: {
582+
case mlir::cir::CastKind::int_to_float: {
582583
if (!mlir::isa<mlir::cir::IntType>(srcType))
583584
return emitOpError() << "requires !cir.int type for source";
584585
if (!mlir::isa<mlir::cir::CIRFPTypeInterface>(resType))
585586
return emitOpError() << "requires !cir.float type for result";
586587
return success();
587588
}
588-
case cir::CastKind::bool_to_float: {
589+
case mlir::cir::CastKind::bool_to_float: {
589590
if (!mlir::isa<mlir::cir::BoolType>(srcType))
590591
return emitOpError() << "requires !cir.bool type for source";
591592
if (!mlir::isa<mlir::cir::CIRFPTypeInterface>(resType))
592593
return emitOpError() << "requires !cir.float type for result";
593594
return success();
594595
}
595-
case cir::CastKind::address_space: {
596+
case mlir::cir::CastKind::address_space: {
596597
auto srcPtrTy = mlir::dyn_cast<mlir::cir::PointerType>(srcType);
597598
auto resPtrTy = mlir::dyn_cast<mlir::cir::PointerType>(resType);
598599
if (!srcPtrTy || !resPtrTy)
@@ -601,7 +602,7 @@ LogicalResult mlir::cir::CastOp::verify() {
601602
return emitOpError() << "requires two types differ in addrspace only";
602603
return success();
603604
}
604-
case cir::CastKind::float_to_complex: {
605+
case mlir::cir::CastKind::float_to_complex: {
605606
if (!mlir::isa<mlir::cir::CIRFPTypeInterface>(srcType))
606607
return emitOpError() << "requires !cir.float type for source";
607608
auto resComplexTy = mlir::dyn_cast<mlir::cir::ComplexType>(resType);
@@ -611,7 +612,7 @@ LogicalResult mlir::cir::CastOp::verify() {
611612
return emitOpError() << "requires source type match result element type";
612613
return success();
613614
}
614-
case cir::CastKind::int_to_complex: {
615+
case mlir::cir::CastKind::int_to_complex: {
615616
if (!mlir::isa<mlir::cir::IntType>(srcType))
616617
return emitOpError() << "requires !cir.int type for source";
617618
auto resComplexTy = mlir::dyn_cast<mlir::cir::ComplexType>(resType);
@@ -621,7 +622,7 @@ LogicalResult mlir::cir::CastOp::verify() {
621622
return emitOpError() << "requires source type match result element type";
622623
return success();
623624
}
624-
case cir::CastKind::float_complex_to_real: {
625+
case mlir::cir::CastKind::float_complex_to_real: {
625626
auto srcComplexTy = mlir::dyn_cast<mlir::cir::ComplexType>(srcType);
626627
if (!srcComplexTy)
627628
return emitOpError() << "requires !cir.complex type for source";
@@ -631,7 +632,7 @@ LogicalResult mlir::cir::CastOp::verify() {
631632
return emitOpError() << "requires source element type match result type";
632633
return success();
633634
}
634-
case cir::CastKind::int_complex_to_real: {
635+
case mlir::cir::CastKind::int_complex_to_real: {
635636
auto srcComplexTy = mlir::dyn_cast<mlir::cir::ComplexType>(srcType);
636637
if (!srcComplexTy)
637638
return emitOpError() << "requires !cir.complex type for source";
@@ -641,7 +642,7 @@ LogicalResult mlir::cir::CastOp::verify() {
641642
return emitOpError() << "requires source element type match result type";
642643
return success();
643644
}
644-
case cir::CastKind::float_complex_to_bool: {
645+
case mlir::cir::CastKind::float_complex_to_bool: {
645646
auto srcComplexTy = mlir::dyn_cast<mlir::cir::ComplexType>(srcType);
646647
if (!srcComplexTy ||
647648
!mlir::isa<mlir::cir::CIRFPTypeInterface>(srcComplexTy.getElementTy()))
@@ -651,7 +652,7 @@ LogicalResult mlir::cir::CastOp::verify() {
651652
return emitOpError() << "requires !cir.bool type for result";
652653
return success();
653654
}
654-
case cir::CastKind::int_complex_to_bool: {
655+
case mlir::cir::CastKind::int_complex_to_bool: {
655656
auto srcComplexTy = mlir::dyn_cast<mlir::cir::ComplexType>(srcType);
656657
if (!srcComplexTy ||
657658
!mlir::isa<mlir::cir::IntType>(srcComplexTy.getElementTy()))
@@ -661,7 +662,7 @@ LogicalResult mlir::cir::CastOp::verify() {
661662
return emitOpError() << "requires !cir.bool type for result";
662663
return success();
663664
}
664-
case cir::CastKind::float_complex: {
665+
case mlir::cir::CastKind::float_complex: {
665666
auto srcComplexTy = mlir::dyn_cast<mlir::cir::ComplexType>(srcType);
666667
if (!srcComplexTy ||
667668
!mlir::isa<mlir::cir::CIRFPTypeInterface>(srcComplexTy.getElementTy()))
@@ -674,7 +675,7 @@ LogicalResult mlir::cir::CastOp::verify() {
674675
<< "requires !cir.complex<!cir.float> type for result";
675676
return success();
676677
}
677-
case cir::CastKind::float_complex_to_int_complex: {
678+
case mlir::cir::CastKind::float_complex_to_int_complex: {
678679
auto srcComplexTy = mlir::dyn_cast<mlir::cir::ComplexType>(srcType);
679680
if (!srcComplexTy ||
680681
!mlir::isa<mlir::cir::CIRFPTypeInterface>(srcComplexTy.getElementTy()))
@@ -686,7 +687,7 @@ LogicalResult mlir::cir::CastOp::verify() {
686687
return emitOpError() << "requires !cir.complex<!cir.int> type for result";
687688
return success();
688689
}
689-
case cir::CastKind::int_complex: {
690+
case mlir::cir::CastKind::int_complex: {
690691
auto srcComplexTy = mlir::dyn_cast<mlir::cir::ComplexType>(srcType);
691692
if (!srcComplexTy ||
692693
!mlir::isa<mlir::cir::IntType>(srcComplexTy.getElementTy()))
@@ -697,7 +698,7 @@ LogicalResult mlir::cir::CastOp::verify() {
697698
return emitOpError() << "requires !cir.complex<!cir.int> type for result";
698699
return success();
699700
}
700-
case cir::CastKind::int_complex_to_float_complex: {
701+
case mlir::cir::CastKind::int_complex_to_float_complex: {
701702
auto srcComplexTy = mlir::dyn_cast<mlir::cir::ComplexType>(srcType);
702703
if (!srcComplexTy ||
703704
!mlir::isa<mlir::cir::IntType>(srcComplexTy.getElementTy()))
@@ -920,6 +921,16 @@ LogicalResult mlir::cir::ComplexImagPtrOp::verify() {
920921
return success();
921922
}
922923

924+
//===----------------------------------------------------------------------===//
925+
// LoadOp
926+
//===----------------------------------------------------------------------===//
927+
928+
void mlir::cir::LoadOp::setAtomic(mlir::cir::MemOrder order) {
929+
setMemOrder(order);
930+
if (::cir::MissingFeatures::syncScopeID())
931+
llvm_unreachable("NYI");
932+
}
933+
923934
//===----------------------------------------------------------------------===//
924935
// VecCreateOp
925936
//===----------------------------------------------------------------------===//
@@ -1030,11 +1041,11 @@ mlir::LogicalResult mlir::cir::ReturnOp::verify() {
10301041
// Returns can be present in multiple different scopes, get the
10311042
// wrapping function and start from there.
10321043
auto *fnOp = getOperation()->getParentOp();
1033-
while (!isa<cir::FuncOp>(fnOp))
1044+
while (!isa<mlir::cir::FuncOp>(fnOp))
10341045
fnOp = fnOp->getParentOp();
10351046

10361047
// Make sure return types match function return type.
1037-
if (checkReturnAndFunction(*this, cast<cir::FuncOp>(fnOp)).failed())
1048+
if (checkReturnAndFunction(*this, cast<mlir::cir::FuncOp>(fnOp)).failed())
10381049
return failure();
10391050

10401051
return success();
@@ -2095,8 +2106,8 @@ LogicalResult mlir::cir::GlobalOp::verify() {
20952106

20962107
void mlir::cir::GlobalOp::build(
20972108
OpBuilder &odsBuilder, OperationState &odsState, StringRef sym_name,
2098-
Type sym_type, bool isConstant, cir::GlobalLinkageKind linkage,
2099-
cir::AddressSpaceAttr addrSpace,
2109+
Type sym_type, bool isConstant, mlir::cir::GlobalLinkageKind linkage,
2110+
mlir::cir::AddressSpaceAttr addrSpace,
21002111
function_ref<void(OpBuilder &, Location)> ctorBuilder,
21012112
function_ref<void(OpBuilder &, Location)> dtorBuilder) {
21022113
odsState.addAttribute(getSymNameAttrName(odsState.name),
@@ -2108,7 +2119,7 @@ void mlir::cir::GlobalOp::build(
21082119
odsBuilder.getUnitAttr());
21092120

21102121
::mlir::cir::GlobalLinkageKindAttr linkageAttr =
2111-
cir::GlobalLinkageKindAttr::get(odsBuilder.getContext(), linkage);
2122+
mlir::cir::GlobalLinkageKindAttr::get(odsBuilder.getContext(), linkage);
21122123
odsState.addAttribute(getLinkageAttrName(odsState.name), linkageAttr);
21132124

21142125
if (addrSpace)
@@ -2681,7 +2692,7 @@ void mlir::cir::FuncOp::print(OpAsmPrinter &p) {
26812692
// getNumArguments hook not failing.
26822693
LogicalResult mlir::cir::FuncOp::verifyType() {
26832694
auto type = getFunctionType();
2684-
if (!isa<cir::FuncType>(type))
2695+
if (!isa<mlir::cir::FuncType>(type))
26852696
return emitOpError("requires '" + getFunctionTypeAttrName().str() +
26862697
"' attribute of function type");
26872698
if (!getNoProto() && type.isVarArg() && type.getNumInputs() == 0)
@@ -2704,19 +2715,20 @@ LogicalResult mlir::cir::FuncOp::verify() {
27042715
if (getLinkage() == cir::GlobalLinkageKind::CommonLinkage)
27052716
return emitOpError() << "functions cannot have '"
27062717
<< stringifyGlobalLinkageKind(
2707-
cir::GlobalLinkageKind::CommonLinkage)
2718+
mlir::cir::GlobalLinkageKind::CommonLinkage)
27082719
<< "' linkage";
27092720

27102721
if (isExternal()) {
2711-
if (getLinkage() != cir::GlobalLinkageKind::ExternalLinkage &&
2712-
getLinkage() != cir::GlobalLinkageKind::ExternalWeakLinkage)
2713-
return emitOpError() << "external functions must have '"
2714-
<< stringifyGlobalLinkageKind(
2715-
cir::GlobalLinkageKind::ExternalLinkage)
2716-
<< "' or '"
2717-
<< stringifyGlobalLinkageKind(
2718-
cir::GlobalLinkageKind::ExternalWeakLinkage)
2719-
<< "' linkage";
2722+
if (getLinkage() != mlir::cir::GlobalLinkageKind::ExternalLinkage &&
2723+
getLinkage() != mlir::cir::GlobalLinkageKind::ExternalWeakLinkage)
2724+
return emitOpError()
2725+
<< "external functions must have '"
2726+
<< stringifyGlobalLinkageKind(
2727+
mlir::cir::GlobalLinkageKind::ExternalLinkage)
2728+
<< "' or '"
2729+
<< stringifyGlobalLinkageKind(
2730+
mlir::cir::GlobalLinkageKind::ExternalWeakLinkage)
2731+
<< "' linkage";
27202732
return success();
27212733
}
27222734

@@ -3212,11 +3224,11 @@ mlir::cir::TryCallOp::getSuccessorOperands(unsigned index) {
32123224

32133225
LogicalResult mlir::cir::UnaryOp::verify() {
32143226
switch (getKind()) {
3215-
case cir::UnaryOpKind::Inc:
3216-
case cir::UnaryOpKind::Dec:
3217-
case cir::UnaryOpKind::Plus:
3218-
case cir::UnaryOpKind::Minus:
3219-
case cir::UnaryOpKind::Not:
3227+
case mlir::cir::UnaryOpKind::Inc:
3228+
case mlir::cir::UnaryOpKind::Dec:
3229+
case mlir::cir::UnaryOpKind::Plus:
3230+
case mlir::cir::UnaryOpKind::Minus:
3231+
case mlir::cir::UnaryOpKind::Not:
32203232
// Nothing to verify.
32213233
return success();
32223234
}
@@ -3233,8 +3245,9 @@ void mlir::cir::AwaitOp::build(
32333245
function_ref<void(OpBuilder &, Location)> readyBuilder,
32343246
function_ref<void(OpBuilder &, Location)> suspendBuilder,
32353247
function_ref<void(OpBuilder &, Location)> resumeBuilder) {
3236-
result.addAttribute(getKindAttrName(result.name),
3237-
cir::AwaitKindAttr::get(builder.getContext(), kind));
3248+
result.addAttribute(
3249+
getKindAttrName(result.name),
3250+
mlir::cir::AwaitKindAttr::get(builder.getContext(), kind));
32383251
{
32393252
OpBuilder::InsertionGuard guard(builder);
32403253
Region *readyRegion = result.addRegion();
@@ -3346,7 +3359,7 @@ LogicalResult mlir::cir::ConstArrayAttr::verify(
33463359

33473360
if (auto strAttr = mlir::dyn_cast<mlir::StringAttr>(attr)) {
33483361
mlir::cir::ArrayType at = mlir::cast<mlir::cir::ArrayType>(type);
3349-
auto intTy = mlir::dyn_cast<cir::IntType>(at.getEltType());
3362+
auto intTy = mlir::dyn_cast<mlir::cir::IntType>(at.getEltType());
33503363

33513364
// TODO: add CIR type for char.
33523365
if (!intTy || intTy.getWidth() != 8) {
@@ -3463,8 +3476,9 @@ LogicalResult mlir::cir::ConstVectorAttr::verify(
34633476
::mlir::Type type, mlir::ArrayAttr arrayAttr) {
34643477

34653478
if (!mlir::isa<mlir::cir::VectorType>(type)) {
3466-
return emitError()
3467-
<< "type of cir::ConstVectorAttr is not a cir::VectorType: " << type;
3479+
return emitError() << "type of mlir::cir::ConstVectorAttr is not a "
3480+
"mlir::cir::VectorType: "
3481+
<< type;
34683482
}
34693483
auto vecType = mlir::cast<mlir::cir::VectorType>(type);
34703484

@@ -3654,8 +3668,8 @@ LogicalResult mlir::cir::CopyOp::verify() {
36543668
//===----------------------------------------------------------------------===//
36553669

36563670
LogicalResult mlir::cir::MemCpyOp::verify() {
3657-
auto voidPtr =
3658-
cir::PointerType::get(getContext(), cir::VoidType::get(getContext()));
3671+
auto voidPtr = mlir::cir::PointerType::get(
3672+
getContext(), mlir::cir::VoidType::get(getContext()));
36593673

36603674
if (!getLenTy().isUnsigned())
36613675
return emitError() << "memcpy length must be an unsigned integer";

0 commit comments

Comments
Β (0)