Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

PikachuHyA
Copy link
Collaborator

This patch introduces support for TBAA, following the structure ofclang/lib/CodeGen/CodeGenTBAA.h. The key function implemented is CIRGenModule::decorateOperationWithTBAA, which works similarly to CodeGenModule::DecorateInstructionWithTBAA.

Note: Support for vtable pointer and tbaa.struct is not yet included.

For further details, please refer to:

@PikachuHyA PikachuHyA changed the title [CIR][CIRGen] Add support for TBAA [CIR][CIRGen][TBAA] Add support for TBAA Nov 7, 2024
Copy link

github-actions bot commented Nov 7, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Member

@bcardosolopes bcardosolopes left a 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.

clang/test/CIR/CodeGen/tbaa.cpp Outdated Show resolved Hide resolved
clang/test/CIR/CodeGen/tbaa.c Outdated Show resolved Hide resolved
clang/test/CIR/CodeGen/tbaa.c Outdated Show resolved Hide resolved
clang/test/CIR/CodeGen/tbaa.c Outdated Show resolved Hide resolved
clang/lib/CIR/CodeGen/CIRGenTBAA.h Outdated Show resolved Hide resolved
clang/lib/CIR/CodeGen/CIRGenModule.cpp Outdated Show resolved Hide resolved
clang/test/CIR/CodeGen/tbaa.c Outdated Show resolved Hide resolved
clang/test/CIR/CodeGen/tbaa3.c Outdated Show resolved Hide resolved
bcardosolopes pushed a commit that referenced this pull request Nov 19, 2024
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
@smeenai smeenai force-pushed the main branch 2 times, most recently from 4aca8d4 to a04cf10 Compare November 23, 2024 06:11
Copy link
Member

@bcardosolopes bcardosolopes left a 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,
Copy link
Member

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.";
Copy link
Member

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"> {
Copy link
Member

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

Copy link
Collaborator Author

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

Copy link
Member

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.";
Copy link
Member

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?

Copy link
Member

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

Copy link
Collaborator Author

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.

Copy link
Member

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);
Copy link
Member

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?

@PikachuHyA
Copy link
Collaborator Author

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.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants