Skip to content

Commit 7527508

Browse files
authored
[CIR] Introduce IntTypeInterface to allow uniform integer types handling (#1724)
This will in future allow to use builtin integer types within cir operations
1 parent 56b5111 commit 7527508

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class CIR_Type<string name, string typeMnemonic, list<Trait> traits = [],
3838
def CIR_IntType : CIR_Type<"Int", "int", [
3939
DeclareTypeInterfaceMethods<DataLayoutTypeInterface>,
4040
DeclareTypeInterfaceMethods<CIR_SizedTypeInterface>,
41+
DeclareTypeInterfaceMethods<CIR_IntTypeInterface>,
4142
]> {
4243
let summary = "Integer type with arbitrary precision up to a fixed limit";
4344
let description = [{

clang/include/clang/CIR/Interfaces/CIRTypeInterfaces.td

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,50 @@
1515

1616
include "mlir/IR/OpBase.td"
1717

18+
def CIR_IntTypeInterface : TypeInterface<"IntTypeInterface"> {
19+
let description = [{
20+
Contains helper functions to query properties about an integer type.
21+
}];
22+
23+
let cppNamespace = "::cir";
24+
25+
let methods = [
26+
InterfaceMethod<[{
27+
Returns true if this is a signed integer type.
28+
}],
29+
/*retTy=*/"bool",
30+
/*methodName=*/"isSigned",
31+
/*args=*/(ins),
32+
/*methodBody=*/"",
33+
/*defaultImplementation=*/[{
34+
return $_type.isSigned();
35+
}]
36+
>,
37+
InterfaceMethod<[{
38+
Returns true if this is an unsigned integer type.
39+
}],
40+
/*retTy=*/"bool",
41+
/*methodName=*/"isUnsigned",
42+
/*args=*/(ins),
43+
/*methodBody=*/"",
44+
/*defaultImplementation=*/[{
45+
return $_type.isUnsigned();
46+
}]
47+
>,
48+
InterfaceMethod<[{
49+
Returns the bit width of this integer type.
50+
}],
51+
/*retTy=*/"unsigned",
52+
/*methodName=*/"getWidth",
53+
/*args=*/(ins),
54+
/*methodBody=*/"",
55+
/*defaultImplementation=*/[{
56+
return $_type.getWidth();
57+
}]
58+
>
59+
];
60+
}
61+
1862
def CIR_FPTypeInterface : TypeInterface<"FPTypeInterface"> {
1963
let description = [{
2064
Contains helper functions to query properties about a floating-point type.

0 commit comments

Comments
 (0)