Skip to content

Commit 2d4adfe

Browse files
Lancernlanza
authored andcommitted
[CIR] Replace AnyType with CIR_AnyType (#371)
This PR addresses #90. It introduces a new type constraint `CIR_AnyType` which allows CIR types and MLIR floating-point types. Present `AnyType` constraints are replaced with the new `CIR_AnyType` constraint.
1 parent 361ed3d commit 2d4adfe

File tree

2 files changed

+78
-66
lines changed

2 files changed

+78
-66
lines changed

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 66 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ def CastOp : CIR_Op<"cast", [Pure]> {
9898
```
9999
}];
100100

101-
let arguments = (ins CastKind:$kind, AnyType:$src);
102-
let results = (outs AnyType:$result);
101+
let arguments = (ins CastKind:$kind, CIR_AnyType:$src);
102+
let results = (outs CIR_AnyType:$result);
103103

104104
let assemblyFormat = [{
105105
`(` $kind `,` $src `:` type($src) `)`
@@ -168,10 +168,10 @@ def PtrDiffOp : CIR_Op<"ptr_diff", [Pure, SameTypeOperands]> {
168168
}];
169169

170170
let results = (outs CIR_IntType:$result);
171-
let arguments = (ins AnyType:$lhs, AnyType:$rhs);
171+
let arguments = (ins CIR_PointerType:$lhs, CIR_PointerType:$rhs);
172172

173173
let assemblyFormat = [{
174-
`(` $lhs `,` $rhs `)` `:` type($lhs) `->` type($result) attr-dict
174+
`(` $lhs `,` $rhs `)` `:` qualified(type($lhs)) `->` qualified(type($result)) attr-dict
175175
}];
176176

177177
// Already covered by the traits
@@ -198,12 +198,12 @@ def PtrStrideOp : CIR_Op<"ptr_stride",
198198
```
199199
}];
200200

201-
let arguments = (ins AnyType:$base, CIR_IntType:$stride);
202-
let results = (outs AnyType:$result);
201+
let arguments = (ins CIR_PointerType:$base, CIR_IntType:$stride);
202+
let results = (outs CIR_PointerType:$result);
203203

204204
let assemblyFormat = [{
205-
`(` $base `:` type($base) `,` $stride `:` qualified(type($stride)) `)`
206-
`,` type($result) attr-dict
205+
`(` $base `:` qualified(type($base)) `,` $stride `:` qualified(type($stride)) `)`
206+
`,` qualified(type($result)) attr-dict
207207
}];
208208

209209
let extraClassDeclaration = [{
@@ -241,8 +241,8 @@ def ConstantOp : CIR_Op<"const",
241241
// The constant operation takes an attribute as the only input.
242242
let arguments = (ins TypedAttrInterface:$value);
243243

244-
// The constant operation returns a single value of AnyType.
245-
let results = (outs AnyType:$res);
244+
// The constant operation returns a single value of CIR_AnyType.
245+
let results = (outs CIR_AnyType:$res);
246246

247247
let assemblyFormat = [{
248248
`(` custom<ConstantValue>($value) `)` attr-dict `:` type($res)
@@ -389,7 +389,7 @@ def LoadOp : CIR_Op<"load", [
389389

390390
let arguments = (ins Arg<CIR_PointerType, "the address to load from",
391391
[MemRead]>:$addr, UnitAttr:$isDeref);
392-
let results = (outs AnyType:$result);
392+
let results = (outs CIR_AnyType:$result);
393393

394394
// FIXME: we should not be printing `cir.ptr` below, that should come
395395
// from the pointer type directly.
@@ -423,7 +423,7 @@ def StoreOp : CIR_Op<"store", [
423423
```
424424
}];
425425

426-
let arguments = (ins AnyType:$value,
426+
let arguments = (ins CIR_AnyType:$value,
427427
Arg<CIR_PointerType, "the address to store the value",
428428
[MemWrite]>:$addr);
429429

@@ -458,7 +458,7 @@ def ReturnOp : CIR_Op<"return", [HasParent<"FuncOp, ScopeOp, IfOp, SwitchOp, Loo
458458

459459
// The return operation takes an optional input operand to return. This
460460
// value must match the return type of the enclosing function.
461-
let arguments = (ins Variadic<AnyType>:$input);
461+
let arguments = (ins Variadic<CIR_AnyType>:$input);
462462

463463
// The return operation only emits the input in the format if it is present.
464464
let assemblyFormat = "($input^ `:` type($input))? attr-dict ";
@@ -561,7 +561,7 @@ def TernaryOp : CIR_Op<"ternary",
561561
let arguments = (ins CIR_BoolType:$cond);
562562
let regions = (region SizedRegion<1>:$trueRegion,
563563
SizedRegion<1>:$falseRegion);
564-
let results = (outs Optional<AnyType>:$result);
564+
let results = (outs Optional<CIR_AnyType>:$result);
565565

566566
let skipDefaultBuilders = 1;
567567
let builders = [
@@ -671,7 +671,7 @@ def YieldOp : CIR_Op<"yield", [ReturnLike, Terminator,
671671
}];
672672

673673
let arguments = (ins OptionalAttr<YieldOpKind>:$kind,
674-
Variadic<AnyType>:$args);
674+
Variadic<CIR_AnyType>:$args);
675675
let builders = [
676676
OpBuilder<(ins), [{ /* nothing to do */ }]>,
677677
OpBuilder<(ins "YieldOpKind":$kind), [{
@@ -739,7 +739,7 @@ def ScopeOp : CIR_Op<"scope", [
739739
will be inserted implicitly.
740740
}];
741741

742-
let results = (outs Optional<AnyType>:$results);
742+
let results = (outs Optional<CIR_AnyType>:$results);
743743
let regions = (region AnyRegion:$scopeRegion);
744744

745745
let hasVerifier = 1;
@@ -799,8 +799,8 @@ def UnaryOp : CIR_Op<"unary", [Pure, SameOperandsAndResultType]> {
799799
```
800800
}];
801801

802-
let results = (outs AnyType:$result);
803-
let arguments = (ins Arg<UnaryOpKind, "unary op kind">:$kind, Arg<AnyType>:$input);
802+
let results = (outs CIR_AnyType:$result);
803+
let arguments = (ins Arg<UnaryOpKind, "unary op kind">:$kind, Arg<CIR_AnyType>:$input);
804804

805805
let assemblyFormat = [{
806806
`(` $kind `,` $input `)` `:` type($input) `,` type($result) attr-dict
@@ -852,10 +852,10 @@ def BinOp : CIR_Op<"binop", [Pure,
852852
```
853853
}];
854854

855-
// TODO: get more accurate than AnyType
856-
let results = (outs AnyType:$result);
855+
// TODO: get more accurate than CIR_AnyType
856+
let results = (outs CIR_AnyType:$result);
857857
let arguments = (ins Arg<BinOpKind, "binop kind">:$kind,
858-
AnyType:$lhs, AnyType:$rhs);
858+
CIR_AnyType:$lhs, CIR_AnyType:$rhs);
859859

860860
let assemblyFormat = [{
861861
`(` $kind `,` $lhs `,` $rhs `)` `:` type($lhs) attr-dict
@@ -929,10 +929,10 @@ def CmpOp : CIR_Op<"cmp", [Pure, SameTypeOperands]> {
929929
```
930930
}];
931931

932-
// TODO: get more accurate than AnyType
933-
let results = (outs AnyType:$result);
932+
// TODO: get more accurate than CIR_AnyType
933+
let results = (outs CIR_AnyType:$result);
934934
let arguments = (ins Arg<CmpOpKind, "cmp kind">:$kind,
935-
AnyType:$lhs, AnyType:$rhs);
935+
CIR_AnyType:$lhs, CIR_AnyType:$rhs);
936936

937937
let assemblyFormat = [{
938938
`(` $kind `,` $lhs `,` $rhs `)` `:` type($lhs) `,` type($result) attr-dict
@@ -1066,7 +1066,7 @@ def BrOp : CIR_Op<"br",
10661066
}]>
10671067
];
10681068

1069-
let arguments = (ins Variadic<AnyType>:$destOperands);
1069+
let arguments = (ins Variadic<CIR_AnyType>:$destOperands);
10701070
let successors = (successor AnySuccessor:$dest);
10711071
let assemblyFormat = [{
10721072
$dest (`(` $destOperands^ `:` type($destOperands) `)`)? attr-dict
@@ -1111,8 +1111,8 @@ def BrCondOp : CIR_Op<"brcond",
11111111
];
11121112

11131113
let arguments = (ins CIR_BoolType:$cond,
1114-
Variadic<AnyType>:$destOperandsTrue,
1115-
Variadic<AnyType>:$destOperandsFalse);
1114+
Variadic<CIR_AnyType>:$destOperandsTrue,
1115+
Variadic<CIR_AnyType>:$destOperandsFalse);
11161116
let successors = (successor AnySuccessor:$destTrue, AnySuccessor:$destFalse);
11171117
let assemblyFormat = [{
11181118
$cond
@@ -1420,7 +1420,7 @@ def VTableAddrPointOp : CIR_Op<"vtable.address_point",
14201420
}];
14211421

14221422
let arguments = (ins OptionalAttr<FlatSymbolRefAttr>:$name,
1423-
Optional<AnyType>:$sym_addr,
1423+
Optional<CIR_AnyType>:$sym_addr,
14241424
I32Attr:$vtable_index,
14251425
I32Attr:$address_point_index);
14261426
let results = (outs Res<CIR_PointerType, "", []>:$addr);
@@ -1447,13 +1447,13 @@ def VTableAddrPointOp : CIR_Op<"vtable.address_point",
14471447

14481448
def SetBitfieldOp : CIR_Op<"set_bitfield"> {
14491449
let summary = "Set a bitfield";
1450-
let description = [{
1451-
The `cir.set_bitfield` operation provides a store-like access to
1450+
let description = [{
1451+
The `cir.set_bitfield` operation provides a store-like access to
14521452
a bit field of a record.
14531453

14541454
It expects an address of a storage where to store, a type of the storage,
14551455
a value being stored, a name of a bit field, a pointer to the storage in the
1456-
base record, a size of the storage, a size the bit field, an offset
1456+
base record, a size of the storage, a size the bit field, an offset
14571457
of the bit field and a sign. Returns a value being stored.
14581458

14591459
Example.
@@ -1487,29 +1487,29 @@ def SetBitfieldOp : CIR_Op<"set_bitfield"> {
14871487
}];
14881488

14891489
let arguments = (ins
1490-
AnyType:$dst,
1491-
AnyType:$src,
1490+
CIR_PointerType:$dst,
1491+
CIR_AnyType:$src,
14921492
BitfieldInfoAttr:$bitfield_info
14931493
);
14941494

14951495
let results = (outs CIR_IntType:$result);
14961496

1497-
let assemblyFormat = [{ `(`$bitfield_info`,` $dst`:`type($dst)`,`
1497+
let assemblyFormat = [{ `(`$bitfield_info`,` $dst`:`qualified(type($dst))`,`
14981498
$src`:`type($src) `)` attr-dict `->` type($result) }];
1499-
1499+
15001500
let builders = [
15011501
OpBuilder<(ins "Type":$type,
15021502
"Value":$dst,
15031503
"Type":$storage_type,
15041504
"Value":$src,
15051505
"StringRef":$name,
1506-
"unsigned":$size,
1506+
"unsigned":$size,
15071507
"unsigned":$offset,
15081508
"bool":$is_signed
15091509
),
1510-
[{
1511-
BitfieldInfoAttr info =
1512-
BitfieldInfoAttr::get($_builder.getContext(),
1510+
[{
1511+
BitfieldInfoAttr info =
1512+
BitfieldInfoAttr::get($_builder.getContext(),
15131513
name, storage_type,
15141514
size, offset, is_signed);
15151515
build($_builder, $_state, type, dst, src, info);
@@ -1523,7 +1523,7 @@ def SetBitfieldOp : CIR_Op<"set_bitfield"> {
15231523

15241524
def GetBitfieldOp : CIR_Op<"get_bitfield"> {
15251525
let summary = "Get a bitfield";
1526-
let description = [{
1526+
let description = [{
15271527
The `cir.get_bitfield` operation provides a load-like access to
15281528
a bit field of a record.
15291529

@@ -1561,14 +1561,14 @@ def GetBitfieldOp : CIR_Op<"get_bitfield"> {
15611561
}];
15621562

15631563
let arguments = (ins
1564-
AnyType:$addr,
1564+
CIR_PointerType:$addr,
15651565
BitfieldInfoAttr:$bitfield_info
15661566
);
15671567

15681568
let results = (outs CIR_IntType:$result);
15691569

1570-
let assemblyFormat = [{ `(`$bitfield_info `,` $addr attr-dict `:`
1571-
type($addr) `)` `->` type($result) }];
1570+
let assemblyFormat = [{ `(`$bitfield_info `,` $addr attr-dict `:`
1571+
qualified(type($addr)) `)` `->` type($result) }];
15721572

15731573
let builders = [
15741574
OpBuilder<(ins "Type":$type,
@@ -1580,8 +1580,8 @@ def GetBitfieldOp : CIR_Op<"get_bitfield"> {
15801580
"bool":$is_signed
15811581
),
15821582
[{
1583-
BitfieldInfoAttr info =
1584-
BitfieldInfoAttr::get($_builder.getContext(),
1583+
BitfieldInfoAttr info =
1584+
BitfieldInfoAttr::get($_builder.getContext(),
15851585
name, storage_type,
15861586
size, offset, is_signed);
15871587
build($_builder, $_state, type, addr, info);
@@ -1669,7 +1669,7 @@ def VecExtractOp : CIR_Op<"vec.extract", [Pure,
16691669
}];
16701670

16711671
let arguments = (ins CIR_VectorType:$vec, CIR_IntType:$index);
1672-
let results = (outs AnyType:$result);
1672+
let results = (outs CIR_AnyType:$result);
16731673

16741674
let assemblyFormat = [{
16751675
$vec `[` $index `:` type($index) `]` type($vec) `->` type($result) attr-dict
@@ -1691,7 +1691,7 @@ def VecCreateOp : CIR_Op<"vec.create", [Pure]> {
16911691
in the vector type.
16921692
}];
16931693

1694-
let arguments = (ins Variadic<AnyType>:$elements);
1694+
let arguments = (ins Variadic<CIR_AnyType>:$elements);
16951695
let results = (outs CIR_VectorType:$result);
16961696

16971697
let assemblyFormat = [{
@@ -1922,9 +1922,9 @@ def CallOp : CIR_Op<"call",
19221922
}];
19231923

19241924
let arguments = (ins OptionalAttr<FlatSymbolRefAttr>:$callee,
1925-
Variadic<AnyType>:$operands,
1925+
Variadic<CIR_AnyType>:$operands,
19261926
OptionalAttr<ASTCallExprInterface>:$ast);
1927-
let results = (outs Variadic<AnyType>);
1927+
let results = (outs Variadic<CIR_AnyType>);
19281928

19291929
let builders = [
19301930
OpBuilder<(ins "FuncOp":$callee, CArg<"ValueRange", "{}">:$operands), [{
@@ -2125,7 +2125,7 @@ def TryOp : CIR_Op<"try",
21252125

21262126
let regions = (region SizedRegion<1>:$body);
21272127
// FIXME: should be exception type.
2128-
let results = (outs AnyType:$result);
2128+
let results = (outs CIR_AnyType:$result);
21292129

21302130
let assemblyFormat = [{
21312131
`{`
@@ -2161,7 +2161,7 @@ def CatchOp : CIR_Op<"catch",
21612161
let description = [{
21622162
}];
21632163

2164-
let arguments = (ins AnyType:$exception_info,
2164+
let arguments = (ins CIR_AnyType:$exception_info,
21652165
OptionalAttr<CatchArrayAttr>:$catchers);
21662166
let regions = (region VariadicRegion<AnyRegion>:$regions);
21672167

@@ -2306,11 +2306,11 @@ def SameFirstSecondOperandAndResultType :
23062306

23072307
def StdFindOp : CIR_Op<"std.find", [SameFirstSecondOperandAndResultType]> {
23082308
let arguments = (ins FlatSymbolRefAttr:$original_fn,
2309-
AnyType:$first,
2310-
AnyType:$last,
2311-
AnyType:$pattern);
2309+
CIR_AnyType:$first,
2310+
CIR_AnyType:$last,
2311+
CIR_AnyType:$pattern);
23122312
let summary = "std:find()";
2313-
let results = (outs AnyType:$result);
2313+
let results = (outs CIR_AnyType:$result);
23142314

23152315
let description = [{
23162316
Search for `pattern` in data range from `first` to `last`. This currently
@@ -2342,9 +2342,9 @@ def StdFindOp : CIR_Op<"std.find", [SameFirstSecondOperandAndResultType]> {
23422342
//===----------------------------------------------------------------------===//
23432343

23442344
def IterBeginOp : CIR_Op<"iterator_begin"> {
2345-
let arguments = (ins FlatSymbolRefAttr:$original_fn, AnyType:$container);
2345+
let arguments = (ins FlatSymbolRefAttr:$original_fn, CIR_AnyType:$container);
23462346
let summary = "Returns an iterator to the first element of a container";
2347-
let results = (outs AnyType:$result);
2347+
let results = (outs CIR_AnyType:$result);
23482348
let assemblyFormat = [{
23492349
`(`
23502350
$original_fn `,` $container `:` type($container)
@@ -2354,10 +2354,10 @@ def IterBeginOp : CIR_Op<"iterator_begin"> {
23542354
}
23552355

23562356
def IterEndOp : CIR_Op<"iterator_end"> {
2357-
let arguments = (ins FlatSymbolRefAttr:$original_fn, AnyType:$container);
2357+
let arguments = (ins FlatSymbolRefAttr:$original_fn, CIR_AnyType:$container);
23582358
let summary = "Returns an iterator to the element following the last element"
23592359
" of a container";
2360-
let results = (outs AnyType:$result);
2360+
let results = (outs CIR_AnyType:$result);
23612361
let assemblyFormat = [{
23622362
`(`
23632363
$original_fn `,` $container `:` type($container)
@@ -2416,7 +2416,7 @@ def VACopyOp : CIR_Op<"va.copy">,
24162416
}
24172417

24182418
def VAArgOp : CIR_Op<"va.arg">,
2419-
Results<(outs AnyType:$result)>,
2419+
Results<(outs CIR_AnyType:$result)>,
24202420
Arguments<(ins CIR_PointerType:$arg_list)> {
24212421
let summary = "Fetches next variadic element as a given type";
24222422
let assemblyFormat = "$arg_list attr-dict `:` functional-type(operands, $result)";
@@ -2498,7 +2498,7 @@ def ThrowOp : CIR_Op<"throw",
24982498
```
24992499
}];
25002500

2501-
let arguments = (ins Optional<AnyType>:$exception_ptr,
2501+
let arguments = (ins Optional<CIR_AnyType>:$exception_ptr,
25022502
OptionalAttr<FlatSymbolRefAttr>:$type_info,
25032503
OptionalAttr<FlatSymbolRefAttr>:$dtor);
25042504

@@ -2593,19 +2593,19 @@ def CIR_InlineAsmOp : CIR_Op<"asm", [RecursiveMemoryEffects]> {
25932593

25942594
```
25952595
```mlir
2596-
cir.asm(x86_att, {"xyz"}) -> !void
2596+
cir.asm(x86_att, {"xyz"}) -> !void
25972597
```
25982598
}];
25992599

2600-
let results = (outs Optional<AnyType>:$res);
2600+
let results = (outs Optional<CIR_AnyType>:$res);
26012601

26022602
let arguments = (
26032603
ins StrAttr:$asm_string,
2604-
AsmFlavor:$asm_flavor);
2604+
AsmFlavor:$asm_flavor);
26052605

26062606
let assemblyFormat = [{
26072607
`(`$asm_flavor`,` `{` $asm_string `}` `)` attr-dict `:` type($res)
2608-
}];
2608+
}];
26092609
}
26102610

2611-
#endif // MLIR_CIR_DIALECT_CIR_OPS
2611+
#endif // MLIR_CIR_DIALECT_CIR_OPS

0 commit comments

Comments
 (0)