Skip to content

[CIR] Introduce IntTypeInterface to allow uniform integer types handling #146660

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion clang/include/clang/CIR/Dialect/IR/CIRTypes.td
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class CIR_Type<string name, string typeMnemonic, list<Trait> traits = [],

def CIR_IntType : CIR_Type<"Int", "int", [
DeclareTypeInterfaceMethods<DataLayoutTypeInterface>,
DeclareTypeInterfaceMethods<CIR_SizedTypeInterface>
DeclareTypeInterfaceMethods<CIR_SizedTypeInterface>,
DeclareTypeInterfaceMethods<CIR_IntTypeInterface>,
]> {
let summary = "Integer type with arbitrary precision up to a fixed limit";
let description = [{
Expand Down
42 changes: 42 additions & 0 deletions clang/include/clang/CIR/Interfaces/CIRTypeInterfaces.td
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,48 @@

include "mlir/IR/OpBase.td"

def CIR_IntTypeInterface : TypeInterface<"IntTypeInterface"> {
let description = [{
Contains helper functions to query properties about an integer type.
}];
let cppNamespace = "::cir";
let methods = [
InterfaceMethod<[{
Returns true if this is a signed integer type.
}],
/*retTy=*/"bool",
/*methodName=*/"isSigned",
/*args=*/(ins),
/*methodBody=*/"",
/*defaultImplementation=*/[{
return $_type.isSigned();
}]
>,
InterfaceMethod<[{
Returns true if this is an unsigned integer type.
}],
/*retTy=*/"bool",
/*methodName=*/"isUnsigned",
/*args=*/(ins),
/*methodBody=*/"",
/*defaultImplementation=*/[{
return $_type.isUnsigned();
}]
>,
InterfaceMethod<[{
Returns the bit width of this integer type.
}],
/*retTy=*/"unsigned",
/*methodName=*/"getWidth",
/*args=*/(ins),
/*methodBody=*/"",
/*defaultImplementation=*/[{
return $_type.getWidth();
}]
>
];
}

def CIR_FPTypeInterface : TypeInterface<"FPTypeInterface"> {
let description = [{
Contains helper functions to query properties about a floating-point type.
Expand Down
Loading