Skip to content

Commit 5491576

Browse files
authored
[CIR] Introduce IntTypeInterface to allow uniform integer types handling (llvm#146660)
This will in future allow to use builtin integer types within cir operations This mirrors incubat changes from llvm/clangir#1724
1 parent 24828c8 commit 5491576

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ class CIR_Type<string name, string typeMnemonic, list<Trait> traits = [],
3535

3636
def CIR_IntType : CIR_Type<"Int", "int", [
3737
DeclareTypeInterfaceMethods<DataLayoutTypeInterface>,
38-
DeclareTypeInterfaceMethods<CIR_SizedTypeInterface>
38+
DeclareTypeInterfaceMethods<CIR_SizedTypeInterface>,
39+
DeclareTypeInterfaceMethods<CIR_IntTypeInterface>,
3940
]> {
4041
let summary = "Integer type with arbitrary precision up to a fixed limit";
4142
let description = [{

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,48 @@
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+
let cppNamespace = "::cir";
23+
let methods = [
24+
InterfaceMethod<[{
25+
Returns true if this is a signed integer type.
26+
}],
27+
/*retTy=*/"bool",
28+
/*methodName=*/"isSigned",
29+
/*args=*/(ins),
30+
/*methodBody=*/"",
31+
/*defaultImplementation=*/[{
32+
return $_type.isSigned();
33+
}]
34+
>,
35+
InterfaceMethod<[{
36+
Returns true if this is an unsigned integer type.
37+
}],
38+
/*retTy=*/"bool",
39+
/*methodName=*/"isUnsigned",
40+
/*args=*/(ins),
41+
/*methodBody=*/"",
42+
/*defaultImplementation=*/[{
43+
return $_type.isUnsigned();
44+
}]
45+
>,
46+
InterfaceMethod<[{
47+
Returns the bit width of this integer type.
48+
}],
49+
/*retTy=*/"unsigned",
50+
/*methodName=*/"getWidth",
51+
/*args=*/(ins),
52+
/*methodBody=*/"",
53+
/*defaultImplementation=*/[{
54+
return $_type.getWidth();
55+
}]
56+
>
57+
];
58+
}
59+
1860
def CIR_FPTypeInterface : TypeInterface<"FPTypeInterface"> {
1961
let description = [{
2062
Contains helper functions to query properties about a floating-point type.

0 commit comments

Comments
 (0)