-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[mlir][llvm] support -new-struct-path-tbaa #119698
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -1084,8 +1084,79 @@ def LLVM_TBAATagAttr : LLVM_Attr<"TBAATag", "tbaa_tag"> { | |||
let assemblyFormat = "`<` struct(params) `>`"; | ||||
} | ||||
|
||||
def LLVM_TBAAStructFieldAttr : LLVM_Attr<"TBAAStructField", "tbaa_struct_field"> { | ||||
let parameters = (ins | ||||
"TBAANodeAttr":$typeDesc, | ||||
"int64_t":$offset, | ||||
"int64_t":$size | ||||
); | ||||
let assemblyFormat = "`<` struct(params) `>`"; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you use let description / let summary to provide some doc/examples for the relevant attributes. |
||||
} | ||||
|
||||
|
||||
def LLVM_TBAAStructFieldAttrArray : ArrayRefParameter<"TBAAStructFieldAttr"> { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder why we implemented our own array attributes at the time. @vzakhari do you remember? Potentially we could just use: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I do not remember. It would probably work either way. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @PikachuHyA It is quite a lot of custom printing / parsing that could be saved with |
||||
let printer = [{ | ||||
$_printer << '{'; | ||||
llvm::interleaveComma($_self, $_printer, [&](TBAAStructFieldAttr attr) { | ||||
$_printer.printStrippedAttrOrType(attr); | ||||
}); | ||||
$_printer << '}'; | ||||
}]; | ||||
|
||||
let parser = [{ | ||||
[&]() -> FailureOr<SmallVector<TBAAStructFieldAttr>> { | ||||
using Result = SmallVector<TBAAStructFieldAttr>; | ||||
if ($_parser.parseLBrace()) | ||||
return failure(); | ||||
FailureOr<Result> result = FieldParser<Result>::parse($_parser); | ||||
if (failed(result)) | ||||
return failure(); | ||||
if ($_parser.parseRBrace()) | ||||
return failure(); | ||||
return result; | ||||
}() | ||||
}]; | ||||
} | ||||
|
||||
def LLVM_TBAATypeNodeAttr : LLVM_Attr<"TBAATypeNode", "tbaa_type_node", [], "TBAANodeAttr"> { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe if the class should derive from
|
||||
let parameters = (ins | ||||
"TBAANodeAttr":$parent, | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are new and old format mixed? Or in other words can this be a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
No. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense. If we want to verify this we have sort of two options:
I do not have a clear preference. |
||||
"int64_t":$size, | ||||
StringRefParameter<>:$id, | ||||
LLVM_TBAAStructFieldAttrArray:$fields | ||||
); | ||||
let assemblyFormat = "`<` struct(params) `>`"; | ||||
} | ||||
|
||||
def LLVM_TBAAAccessTagAttr : LLVM_Attr<"TBAAAccessTag", "tbaa_access_tag"> { | ||||
let parameters = (ins | ||||
"TBAATypeNodeAttr":$base_type, | ||||
"TBAATypeNodeAttr":$access_type, | ||||
"int64_t":$offset, | ||||
"int64_t":$size | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It feels like the difference to TBAATagAttr is minimal (i.e mainly the size). However, I guess it still makes sense to separate them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another option is to add an optional There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think given LLVM proper has a counter part and since the two TBAA variants cannot be mixed, I am actually in favor of having a separate LLVM_TBAAAccessTagAttr! |
||||
); | ||||
let builders = [ | ||||
AttrBuilderWithInferredContext<(ins "TBAATypeNodeAttr":$baseType, | ||||
"TBAATypeNodeAttr":$accessType, | ||||
"int64_t":$offset, | ||||
"int64_t":$size), [{ | ||||
return $_get(baseType.getContext(), baseType, accessType, offset, size); | ||||
}]> | ||||
]; | ||||
let assemblyFormat = "`<` struct(params) `>`"; | ||||
} | ||||
|
||||
def LLVM_TBAAAccessTagArrayAttr | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this used? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no. The array of def LLVM_TBAATagArrayAttr
: TypedArrayAttrBase<AnyAttrOf<[
LLVM_TBAATagAttr,
LLVM_TBAAAccessTagAttr
]> Therefore, the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed. |
||||
: TypedArrayAttrBase<LLVM_TBAAAccessTagAttr, | ||||
LLVM_TBAAAccessTagAttr.summary # " array"> { | ||||
let constBuilderCall = ?; | ||||
} | ||||
|
||||
def LLVM_TBAATagArrayAttr | ||||
: TypedArrayAttrBase<LLVM_TBAATagAttr, | ||||
: TypedArrayAttrBase<AnyAttrOf<[ | ||||
LLVM_TBAATagAttr, | ||||
LLVM_TBAAAccessTagAttr | ||||
]>, | ||||
LLVM_TBAATagAttr.summary # " array"> { | ||||
let constBuilderCall = ?; | ||||
} | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,7 +58,15 @@ mlir::LLVM::detail::verifyAliasAnalysisOpInterface(Operation *op) { | |
ArrayAttr tags = iface.getTBAATagsOrNull(); | ||
if (!tags) | ||
return success(); | ||
|
||
if (tags.size() > 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't it just be: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
see There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok I understand. I would suggest to extend the AliasAnalysisOpInterface. It currently has one function that returns the TBAA tags. How about implementing two functions:
and
This could potentially be implemented by having two arrays stored on the alias operations. Or by checking if the array contains the old or the new kind of TBAA attributes. That way the verifier can use the existing logic for the two cases separately. And to users of the exiting TBAA attributes don't need to understand the new kind of TBAA metadata. WDYT? |
||
if (mlir::isa<TBAATagAttr>(tags[0])) { | ||
return isArrayOf<TBAATagAttr>(op, tags); | ||
} | ||
|
||
if (mlir::isa<TBAAAccessTagAttr>(tags[0])) { | ||
return isArrayOf<TBAAAccessTagAttr>(op, tags); | ||
} | ||
} | ||
return isArrayOf<TBAATagAttr>(op, tags); | ||
} | ||
|
||
|
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.
nit: let's use banners to structure the file a bit.