-
Notifications
You must be signed in to change notification settings - Fork 128
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
[CIR] Track size_t and int size with module attributes #1389
base: main
Are you sure you want to change the base?
Conversation
A small question here: would it be better to provide all these type-layout related information within a single attribute, instead of spreading them into separate attributes? For example, would it be better if we update this PR to instead provide a single attribute like this: module attributes {
cir.type_sizes = #cir.type_sizes<
int = 32,
size_t = 64,
>,
} {} |
That makes sense! Now I just changed it to be exactly like this. |
@AdUhTkJm thanks for working on this - really good point @Lancern. My suggestion is that we do this for all types in
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment above
// TypeSizeAttr | ||
//===----------------------------------------------------------------------===// | ||
|
||
def CIR_TypeSizesAttr : CIR_Attr<"TypeSizes", "type_sizes"> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest renaming this to TypeSizeInfo
``` | ||
}]; | ||
|
||
let parameters = (ins "unsigned":$intSize, "unsigned":$sizeTypeSize); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add extraClassDeclaration
with static methods that return the full type, example: static mlir::Type getPtrDiffTy() { ... }
|
||
mlir::Type CIRDataLayout::getPtrDiffType(mlir::MLIRContext *ctx) const { | ||
return cir::IntType::get(ctx, sizeTypeSize, /*signed=*/true); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you do that above you don't need to add these.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, one more round of review
@@ -1,4 +1,5 @@ | |||
#include "clang/CIR/Dialect/IR/CIRDataLayout.h" | |||
#include "clang/CIR/Dialect/IR/CIRDialect.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this include really needed?
// TypeSizesInfoAttr | ||
//===----------------------------------------------------------------------===// | ||
|
||
def CIR_TypeSizesInfoAttr : CIR_Attr<"TypeSizesInfo", "type_sizes_info"> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CIR_TypeSizesInfoAttr -> CIR_TypeSizeInfoAttr
TypeSizesInfo -> TypeSizeInfo
type_sizes_info -> type_size_info
def CIR_TypeSizesInfoAttr : CIR_Attr<"TypeSizesInfo", "type_sizes_info"> { | ||
let summary = "the size of types in bits"; | ||
let description = [{ | ||
The `cir.type_sizes` attribute is attached to a module, recording lengths |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update the description and example to match the new names
|
||
let parameters = (ins "unsigned":$char_size, | ||
"unsigned":$int_size, | ||
"unsigned":$size_type_size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
size_type_size -> size_t_size
To give LoweringPrepare type information from
CIRGenTypeCache
, this PR adds two attributes to ModuleOp:The
CIRDataLayout
class is also extended to havegetPtrDiffTy
and so on.Some tests that only expects
cir.lang
andcir.sob
are also changed to take this into account.