-
Notifications
You must be signed in to change notification settings - Fork 103
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][CIRGen][TBAA] Add support for TBAA #1076
base: main
Are you sure you want to change the base?
Conversation
✅ With the latest revision this PR passed the C/C++ code formatter. |
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.
This is amazing @PikachuHyA, very happy to have TBAA support in ClangIR.
This is the first patch to support TBAA, following the discussion at #1076 (comment) - add skeleton for CIRGen, utilizing `decorateOperationWithTBAA` - add empty implementation in `CIRGenTBAA` - introduce `CIR_TBAAAttr` with empty body - attach `CIR_TBAAAttr` to `LoadOp` and `StoreOp` - no handling of vtable pointer - no LLVM lowering
4aca8d4
to
a04cf10
Compare
49c5933
to
22fa1cb
Compare
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.
Thanks for continuing this work! I'd prefer if we start small, perhaps just scalars or whatever is smaller, I'd like to help you trim off unnecessary information we might not need, but the scope is still a bit bigger than necessary. Also please update the title to convey the incremental work happening.
def CIR_TBAAMemberAttr : CIR_Attr<"TBAAMember", "tbaa_member", []> { | ||
let summary = "Attribute representing a member of a TBAA structured type."; | ||
|
||
let parameters = (ins "TBAAAttr":$typeDesc, |
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.
typeDesc
-> type_desc
, please fix all camelcase on tablegen params and related
//===----------------------------------------------------------------------===// | ||
|
||
def CIR_TBAAMemberAttr : CIR_Attr<"TBAAMember", "tbaa_member", []> { | ||
let summary = "Attribute representing a member of a TBAA structured type."; |
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.
Add a description and an example. Same for the others
} | ||
|
||
def CIR_TBAAScalarTypeDescriptorAttr : CIR_TBAATypeDescriptorAttr<"TBAAScalarTypeDescriptor", | ||
"tbaa_scalar_type_desc"> { |
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.
indentation feels odd here, same for other some other ones
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.
Are there any tools available to format .td
files? For example, just as we can use clang-format
to format .cpp
files:
clang-format -i /path/to/cpp_file
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.
Maybe? Last I followed was https://discourse.llvm.org/t/formating-mlir-tablegen-code/60767, but I'm not sure there has been any development.
} | ||
|
||
class CIR_TBAATypeDescriptorAttr<string name, string attrMnemonic>: CIR_Attr<name, attrMnemonic, [], "TBAAAttr"> { | ||
let summary = "Base class for TBAA type descriptor attributes."; |
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.
Why do you need this base class and what's the intent to compose on top of it? Same for CIR_TBAAAttr, can you elaborate?
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.
Still waiting for an answer for this since it affects my review of #1220
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 apologize for overlooking this question.
I make a distinction between scalar types and struct types. The use of class CIR_TBAATypeDescriptorAttr
serves to constrain both CIR_TBAAScalarTypeDescriptorAttr
and CIR_TBAAStructTypeDescriptorAttr
as TBAA type descriptor attributes. If CIR_TBAATypeDescriptorAttr
is redundant, we can remove it.
The purpose of using CIR_TBAAAttr
as a base class in C++ is to provide a unified way to handle both CIR_TBAAScalarTypeDescriptorAttr
and CIR_TBAAStructTypeDescriptorAttr
.
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 haven't seen them get used in the PR though, hence the question. If are actually using it then fine, otherwise best wait until it's used to introduce. Let's move any discussion over the actual patches that might get landed, thanks for the reply!
|
||
let parameters = (ins "TBAAAttr":$typeDesc, | ||
"int64_t":$offset, | ||
"int64_t":$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.
Seems like offset and size is something that can be obtained by looking at the type.
General question for this PR: why do we need to re-encode the same information CIR already has? The requirement is to lower to identical LLVM TBAA information, that shouldn't mean we have to replicate all of it in CIR - how can we reuse more of what we already have?
Thank you for your suggestion. I prefer to submit the code in a new PR while keeping the current PR open until it's fully completed. sent #1220 |
This patch introduces support for TBAA, following the structure of
clang/lib/CodeGen/CodeGenTBAA.h
. The key function implemented isCIRGenModule::decorateOperationWithTBAA
, which works similarly toCodeGenModule::DecorateInstructionWithTBAA
.Note: Support for
vtable pointer
andtbaa.struct
is not yet included.For further details, please refer to: