[go: nahoru, domu]

Skip to content

Commit

Permalink
[CIR] Replace AnyType with CIR_AnyType (#371)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Lancern authored and lanza committed Mar 23, 2024
1 parent 361ed3d commit 2d4adfe
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 66 deletions.
132 changes: 66 additions & 66 deletions clang/include/clang/CIR/Dialect/IR/CIROps.td
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ def CastOp : CIR_Op<"cast", [Pure]> {
```
}];

let arguments = (ins CastKind:$kind, AnyType:$src);
let results = (outs AnyType:$result);
let arguments = (ins CastKind:$kind, CIR_AnyType:$src);
let results = (outs CIR_AnyType:$result);

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

let results = (outs CIR_IntType:$result);
let arguments = (ins AnyType:$lhs, AnyType:$rhs);
let arguments = (ins CIR_PointerType:$lhs, CIR_PointerType:$rhs);

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

// Already covered by the traits
Expand All @@ -198,12 +198,12 @@ def PtrStrideOp : CIR_Op<"ptr_stride",
```
}];

let arguments = (ins AnyType:$base, CIR_IntType:$stride);
let results = (outs AnyType:$result);
let arguments = (ins CIR_PointerType:$base, CIR_IntType:$stride);
let results = (outs CIR_PointerType:$result);

let assemblyFormat = [{
`(` $base `:` type($base) `,` $stride `:` qualified(type($stride)) `)`
`,` type($result) attr-dict
`(` $base `:` qualified(type($base)) `,` $stride `:` qualified(type($stride)) `)`
`,` qualified(type($result)) attr-dict
}];

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

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

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

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

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

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

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

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

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

let skipDefaultBuilders = 1;
let builders = [
Expand Down Expand Up @@ -671,7 +671,7 @@ def YieldOp : CIR_Op<"yield", [ReturnLike, Terminator,
}];

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

let results = (outs Optional<AnyType>:$results);
let results = (outs Optional<CIR_AnyType>:$results);
let regions = (region AnyRegion:$scopeRegion);

let hasVerifier = 1;
Expand Down Expand Up @@ -799,8 +799,8 @@ def UnaryOp : CIR_Op<"unary", [Pure, SameOperandsAndResultType]> {
```
}];

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

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

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

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

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

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

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

let arguments = (ins CIR_BoolType:$cond,
Variadic<AnyType>:$destOperandsTrue,
Variadic<AnyType>:$destOperandsFalse);
Variadic<CIR_AnyType>:$destOperandsTrue,
Variadic<CIR_AnyType>:$destOperandsFalse);
let successors = (successor AnySuccessor:$destTrue, AnySuccessor:$destFalse);
let assemblyFormat = [{
$cond
Expand Down Expand Up @@ -1420,7 +1420,7 @@ def VTableAddrPointOp : CIR_Op<"vtable.address_point",
}];

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

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

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

Example.
Expand Down Expand Up @@ -1487,29 +1487,29 @@ def SetBitfieldOp : CIR_Op<"set_bitfield"> {
}];

let arguments = (ins
AnyType:$dst,
AnyType:$src,
CIR_PointerType:$dst,
CIR_AnyType:$src,
BitfieldInfoAttr:$bitfield_info
);

let results = (outs CIR_IntType:$result);

let assemblyFormat = [{ `(`$bitfield_info`,` $dst`:`type($dst)`,`
let assemblyFormat = [{ `(`$bitfield_info`,` $dst`:`qualified(type($dst))`,`
$src`:`type($src) `)` attr-dict `->` type($result) }];

let builders = [
OpBuilder<(ins "Type":$type,
"Value":$dst,
"Type":$storage_type,
"Value":$src,
"StringRef":$name,
"unsigned":$size,
"unsigned":$size,
"unsigned":$offset,
"bool":$is_signed
),
[{
BitfieldInfoAttr info =
BitfieldInfoAttr::get($_builder.getContext(),
[{
BitfieldInfoAttr info =
BitfieldInfoAttr::get($_builder.getContext(),
name, storage_type,
size, offset, is_signed);
build($_builder, $_state, type, dst, src, info);
Expand All @@ -1523,7 +1523,7 @@ def SetBitfieldOp : CIR_Op<"set_bitfield"> {

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

Expand Down Expand Up @@ -1561,14 +1561,14 @@ def GetBitfieldOp : CIR_Op<"get_bitfield"> {
}];

let arguments = (ins
AnyType:$addr,
CIR_PointerType:$addr,
BitfieldInfoAttr:$bitfield_info
);

let results = (outs CIR_IntType:$result);

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

let builders = [
OpBuilder<(ins "Type":$type,
Expand All @@ -1580,8 +1580,8 @@ def GetBitfieldOp : CIR_Op<"get_bitfield"> {
"bool":$is_signed
),
[{
BitfieldInfoAttr info =
BitfieldInfoAttr::get($_builder.getContext(),
BitfieldInfoAttr info =
BitfieldInfoAttr::get($_builder.getContext(),
name, storage_type,
size, offset, is_signed);
build($_builder, $_state, type, addr, info);
Expand Down Expand Up @@ -1669,7 +1669,7 @@ def VecExtractOp : CIR_Op<"vec.extract", [Pure,
}];

let arguments = (ins CIR_VectorType:$vec, CIR_IntType:$index);
let results = (outs AnyType:$result);
let results = (outs CIR_AnyType:$result);

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

let arguments = (ins Variadic<AnyType>:$elements);
let arguments = (ins Variadic<CIR_AnyType>:$elements);
let results = (outs CIR_VectorType:$result);

let assemblyFormat = [{
Expand Down Expand Up @@ -1922,9 +1922,9 @@ def CallOp : CIR_Op<"call",
}];

let arguments = (ins OptionalAttr<FlatSymbolRefAttr>:$callee,
Variadic<AnyType>:$operands,
Variadic<CIR_AnyType>:$operands,
OptionalAttr<ASTCallExprInterface>:$ast);
let results = (outs Variadic<AnyType>);
let results = (outs Variadic<CIR_AnyType>);

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

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

let assemblyFormat = [{
`{`
Expand Down Expand Up @@ -2161,7 +2161,7 @@ def CatchOp : CIR_Op<"catch",
let description = [{
}];

let arguments = (ins AnyType:$exception_info,
let arguments = (ins CIR_AnyType:$exception_info,
OptionalAttr<CatchArrayAttr>:$catchers);
let regions = (region VariadicRegion<AnyRegion>:$regions);

Expand Down Expand Up @@ -2306,11 +2306,11 @@ def SameFirstSecondOperandAndResultType :

def StdFindOp : CIR_Op<"std.find", [SameFirstSecondOperandAndResultType]> {
let arguments = (ins FlatSymbolRefAttr:$original_fn,
AnyType:$first,
AnyType:$last,
AnyType:$pattern);
CIR_AnyType:$first,
CIR_AnyType:$last,
CIR_AnyType:$pattern);
let summary = "std:find()";
let results = (outs AnyType:$result);
let results = (outs CIR_AnyType:$result);

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

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

def IterEndOp : CIR_Op<"iterator_end"> {
let arguments = (ins FlatSymbolRefAttr:$original_fn, AnyType:$container);
let arguments = (ins FlatSymbolRefAttr:$original_fn, CIR_AnyType:$container);
let summary = "Returns an iterator to the element following the last element"
" of a container";
let results = (outs AnyType:$result);
let results = (outs CIR_AnyType:$result);
let assemblyFormat = [{
`(`
$original_fn `,` $container `:` type($container)
Expand Down Expand Up @@ -2416,7 +2416,7 @@ def VACopyOp : CIR_Op<"va.copy">,
}

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

let arguments = (ins Optional<AnyType>:$exception_ptr,
let arguments = (ins Optional<CIR_AnyType>:$exception_ptr,
OptionalAttr<FlatSymbolRefAttr>:$type_info,
OptionalAttr<FlatSymbolRefAttr>:$dtor);

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

```
```mlir
cir.asm(x86_att, {"xyz"}) -> !void
cir.asm(x86_att, {"xyz"}) -> !void
```
}];

let results = (outs Optional<AnyType>:$res);
let results = (outs Optional<CIR_AnyType>:$res);

let arguments = (
ins StrAttr:$asm_string,
AsmFlavor:$asm_flavor);
AsmFlavor:$asm_flavor);

let assemblyFormat = [{
`(`$asm_flavor`,` `{` $asm_string `}` `)` attr-dict `:` type($res)
}];
}];
}

#endif // MLIR_CIR_DIALECT_CIR_OPS
#endif // MLIR_CIR_DIALECT_CIR_OPS
Loading

0 comments on commit 2d4adfe

Please sign in to comment.